1
2#ifndef _UAPI_LINUX_MSDOS_FS_H
3#define _UAPI_LINUX_MSDOS_FS_H
4
5#include <linux/types.h>
6#include <linux/magic.h>
7#include <asm/byteorder.h>
8
9
10
11
12
13#ifndef SECTOR_SIZE
14#define SECTOR_SIZE 512
15#endif
16#define SECTOR_BITS 9
17#define MSDOS_DPB (MSDOS_DPS)
18#define MSDOS_DPB_BITS 4
19#define MSDOS_DPS (SECTOR_SIZE / sizeof(struct msdos_dir_entry))
20#define MSDOS_DPS_BITS 4
21#define MSDOS_LONGNAME 256
22#define CF_LE_W(v) le16_to_cpu(v)
23#define CF_LE_L(v) le32_to_cpu(v)
24#define CT_LE_W(v) cpu_to_le16(v)
25#define CT_LE_L(v) cpu_to_le32(v)
26
27#define MSDOS_ROOT_INO 1
28#define MSDOS_FSINFO_INO 2
29
30#define MSDOS_DIR_BITS 5
31
32
33#define FAT_MAX_DIR_ENTRIES (65536)
34#define FAT_MAX_DIR_SIZE (FAT_MAX_DIR_ENTRIES << MSDOS_DIR_BITS)
35
36#define ATTR_NONE 0
37#define ATTR_RO 1
38#define ATTR_HIDDEN 2
39#define ATTR_SYS 4
40#define ATTR_VOLUME 8
41#define ATTR_DIR 16
42#define ATTR_ARCH 32
43
44
45#define ATTR_UNUSED (ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN)
46
47#define ATTR_EXT (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
48
49#define CASE_LOWER_BASE 8
50#define CASE_LOWER_EXT 16
51
52#define DELETED_FLAG 0xe5
53#define IS_FREE(n) (!*(n) || *(n) == DELETED_FLAG)
54
55#define FAT_LFN_LEN 255
56#define MSDOS_NAME 11
57#define MSDOS_SLOTS 21
58#define MSDOS_DOT ". "
59#define MSDOS_DOTDOT ".. "
60
61#define FAT_FIRST_ENT(s, x) ((MSDOS_SB(s)->fat_bits == 32 ? 0x0FFFFF00 : \
62 MSDOS_SB(s)->fat_bits == 16 ? 0xFF00 : 0xF00) | (x))
63
64
65#define FAT_START_ENT 2
66
67
68#define MAX_FAT12 0xFF4
69#define MAX_FAT16 0xFFF4
70#define MAX_FAT32 0x0FFFFFF6
71#define MAX_FAT(s) (MSDOS_SB(s)->fat_bits == 32 ? MAX_FAT32 : \
72 MSDOS_SB(s)->fat_bits == 16 ? MAX_FAT16 : MAX_FAT12)
73
74
75#define BAD_FAT12 0xFF7
76#define BAD_FAT16 0xFFF7
77#define BAD_FAT32 0x0FFFFFF7
78
79
80#define EOF_FAT12 0xFFF
81#define EOF_FAT16 0xFFFF
82#define EOF_FAT32 0x0FFFFFFF
83
84#define FAT_ENT_FREE (0)
85#define FAT_ENT_BAD (BAD_FAT32)
86#define FAT_ENT_EOF (EOF_FAT32)
87
88#define FAT_FSINFO_SIG1 0x41615252
89#define FAT_FSINFO_SIG2 0x61417272
90#define IS_FSINFO(x) (le32_to_cpu((x)->signature1) == FAT_FSINFO_SIG1 \
91 && le32_to_cpu((x)->signature2) == FAT_FSINFO_SIG2)
92
93#define FAT_STATE_DIRTY 0x01
94
95struct __fat_dirent {
96 long d_ino;
97 __kernel_off_t d_off;
98 unsigned short d_reclen;
99 char d_name[256];
100};
101
102
103
104
105#define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct __fat_dirent[2])
106#define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct __fat_dirent[2])
107
108#define FAT_IOCTL_GET_ATTRIBUTES _IOR('r', 0x10, __u32)
109#define FAT_IOCTL_SET_ATTRIBUTES _IOW('r', 0x11, __u32)
110
111#define FAT_IOCTL_GET_VOLUME_ID _IOR('r', 0x13, __u32)
112
113struct fat_boot_sector {
114 __u8 ignored[3];
115 __u8 system_id[8];
116
117 __u8 sector_size[2];
118 __u8 sec_per_clus;
119 __le16 reserved;
120 __u8 fats;
121 __u8 dir_entries[2];
122 __u8 sectors[2];
123 __u8 media;
124 __le16 fat_length;
125 __le16 secs_track;
126 __le16 heads;
127 __le32 hidden;
128 __le32 total_sect;
129
130 union {
131 struct {
132
133 __u8 drive_number;
134 __u8 state;
135
136 __u8 signature;
137 __u8 vol_id[4];
138 __u8 vol_label[11];
139 __u8 fs_type[8];
140
141 } fat16;
142
143 struct {
144
145 __le32 length;
146 __le16 flags;
147
148 __u8 version[2];
149
150 __le32 root_cluster;
151
152 __le16 info_sector;
153 __le16 backup_boot;
154 __le16 reserved2[6];
155
156 __u8 drive_number;
157 __u8 state;
158
159 __u8 signature;
160 __u8 vol_id[4];
161 __u8 vol_label[11];
162 __u8 fs_type[8];
163
164 } fat32;
165 };
166};
167
168struct fat_boot_fsinfo {
169 __le32 signature1;
170 __le32 reserved1[120];
171 __le32 signature2;
172 __le32 free_clusters;
173 __le32 next_cluster;
174 __le32 reserved2[4];
175};
176
177struct msdos_dir_entry {
178 __u8 name[MSDOS_NAME];
179 __u8 attr;
180 __u8 lcase;
181 __u8 ctime_cs;
182 __le16 ctime;
183 __le16 cdate;
184 __le16 adate;
185 __le16 starthi;
186 __le16 time,date,start;
187 __le32 size;
188};
189
190
191struct msdos_dir_slot {
192 __u8 id;
193 __u8 name0_4[10];
194 __u8 attr;
195 __u8 reserved;
196 __u8 alias_checksum;
197 __u8 name5_10[12];
198 __le16 start;
199 __u8 name11_12[4];
200};
201
202#endif
203