source: mainline/uspace/srv/fs/fat/fat_dentry.h@ bba3d90

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since bba3d90 was 7194a60, checked in by Oleg Romanenko <romanenko.oleg@…>, 14 years ago

Modifications in fat_dentry.h and fat_dentry.c:

  1. Using wchar_t for wide string
  2. Using standart string functions when it possible.
  3. Add function for convesion unicode character to ascii:

wstr_to_ascii

  1. Renaming few functions.
  • Property mode set to 100644
File size: 4.9 KB
Line 
1/*
2 * Copyright (c) 2008 Jakub Jermar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup fs
30 * @{
31 */
32
33#ifndef FAT_FAT_DENTRY_H_
34#define FAT_FAT_DENTRY_H_
35
36#include <stdint.h>
37#include <bool.h>
38
39#define FAT_NAME_LEN 8
40#define FAT_EXT_LEN 3
41
42#define FAT_NAME_DOT ". "
43#define FAT_NAME_DOT_DOT ".. "
44#define FAT_EXT_PAD " "
45
46#define FAT_ATTR_RDONLY 0x01
47#define FAT_ATTR_HIDDEN 0x02
48#define FAT_ATTR_SYSTEM 0x04
49#define FAT_ATTR_VOLLABEL 0x08
50#define FAT_ATTR_SUBDIR 0x10
51#define FAT_ATTR_ARCHIVE 0x20
52#define FAT_ATTR_LFN \
53 (FAT_ATTR_RDONLY | FAT_ATTR_HIDDEN | FAT_ATTR_SYSTEM | FAT_ATTR_VOLLABEL)
54
55#define FAT_LCASE_LOWER_NAME 0x08
56#define FAT_LCASE_LOWER_EXT 0x10
57
58#define FAT_PAD ' '
59#define FAT_LFN_PAD 0xffff
60#define FAT_SFN_CHAR '_'
61
62#define FAT_DENTRY_UNUSED 0x00
63#define FAT_DENTRY_E5_ESC 0x05
64#define FAT_DENTRY_DOT 0x2e
65#define FAT_DENTRY_ERASED 0xe5
66#define FAT_LFN_LAST 0x40
67#define FAT_LFN_ERASED 0x80
68
69#define FAT_LFN_ORDER(d) (d->lfn.order)
70#define FAT_IS_LFN(d) \
71 ((FAT_LFN_ORDER(d) & FAT_LFN_LAST) == FAT_LFN_LAST)
72#define FAT_LFN_COUNT(d) \
73 (FAT_LFN_ORDER(d) ^ FAT_LFN_LAST)
74#define FAT_LFN_PART1(d) (d->lfn.part1)
75#define FAT_LFN_PART2(d) (d->lfn.part2)
76#define FAT_LFN_PART3(d) (d->lfn.part3)
77#define FAT_LFN_ATTR(d) (d->lfn.attr)
78#define FAT_LFN_CHKSUM(d) (d->lfn.check_sum)
79
80#define FAT_LFN_NAME_SIZE 260
81#define FAT_LFN_MAX_COUNT 20
82#define FAT_LFN_PART1_SIZE 5
83#define FAT_LFN_PART2_SIZE 6
84#define FAT_LFN_PART3_SIZE 2
85#define FAT_LFN_ENTRY_SIZE \
86 (FAT_LFN_PART1_SIZE + FAT_LFN_PART2_SIZE + FAT_LFN_PART3_SIZE)
87
88typedef enum {
89 FAT_DENTRY_SKIP,
90 FAT_DENTRY_LAST,
91 FAT_DENTRY_FREE,
92 FAT_DENTRY_VALID,
93 FAT_DENTRY_LFN
94} fat_dentry_clsf_t;
95
96typedef struct {
97 union {
98 struct {
99 uint8_t name[8];
100 uint8_t ext[3];
101 uint8_t attr;
102 uint8_t lcase;
103 uint8_t ctime_fine;
104 uint16_t ctime;
105 uint16_t cdate;
106 uint16_t adate;
107 union {
108 uint16_t eaidx; /* FAT12/FAT16 */
109 uint16_t firstc_hi; /* FAT32 */
110 } __attribute__ ((packed));
111 uint16_t mtime;
112 uint16_t mdate;
113 union {
114 uint16_t firstc; /* FAT12/FAT16 */
115 uint16_t firstc_lo; /* FAT32 */
116 } __attribute__ ((packed));
117 uint32_t size;
118 } __attribute__ ((packed));
119 struct {
120 uint8_t order;
121 uint16_t part1[FAT_LFN_PART1_SIZE];
122 uint8_t attr;
123 uint8_t type;
124 uint8_t check_sum;
125 uint16_t part2[FAT_LFN_PART2_SIZE];
126 uint16_t firstc_lo; /* MUST be 0 */
127 uint16_t part3[FAT_LFN_PART3_SIZE];
128 } __attribute__ ((packed)) lfn;
129 };
130} __attribute__ ((packed)) fat_dentry_t;
131
132
133extern int fat_dentry_namecmp(char *, const char *);
134extern void fat_dentry_name_get(const fat_dentry_t *, char *);
135extern void fat_dentry_name_set(fat_dentry_t *, const char *);
136extern fat_dentry_clsf_t fat_classify_dentry(const fat_dentry_t *);
137extern uint8_t fat_dentry_chksum(uint8_t *);
138
139extern size_t fat_lfn_str_nlength(const uint16_t *, size_t);
140extern size_t fat_lfn_size(const fat_dentry_t *);
141extern size_t fat_lfn_get_part(const uint16_t *, size_t, wchar_t *, size_t *);
142extern size_t fat_lfn_get_entry(const fat_dentry_t *, wchar_t *, size_t *);
143extern size_t fat_lfn_set_part(const wchar_t *, size_t *, size_t, uint16_t *, size_t);
144extern size_t fat_lfn_set_entry(const wchar_t *, size_t *, size_t, fat_dentry_t *);
145
146extern void wstr_to_ascii(char *dst, const wchar_t *src, size_t count, uint8_t pad);
147
148extern bool fat_sfn_valid_char(wchar_t);
149extern bool fat_sfn_valid(const wchar_t *);
150extern bool fat_lfn_valid(const wchar_t *wstr);
151extern bool fat_dentry_is_sfn(const wchar_t *);
152
153
154#endif
155
156/**
157 * @}
158 */
Note: See TracBrowser for help on using the repository browser.