some cleanups and I hope closer to making it work
[reactos.git] / rosapps / sysutils / dosfsck / msdos_fs.h
1 #ifndef _LINUX_MSDOS_FS_H
2 #define _LINUX_MSDOS_FS_H
3
4 /*
5 * The MS-DOS filesystem constants/structures
6 */
7 #include "byteorder.h"
8
9 #define SECTOR_SIZE 512 /* sector size (bytes) */
10 #define SECTOR_BITS 9 /* log2(SECTOR_SIZE) */
11 #define MSDOS_DPB (MSDOS_DPS) /* dir entries per block */
12 #define MSDOS_DPB_BITS 4 /* log2(MSDOS_DPB) */
13 #define MSDOS_DPS (SECTOR_SIZE / sizeof(struct msdos_dir_entry))
14 #define MSDOS_DPS_BITS 4 /* log2(MSDOS_DPS) */
15 #if 0
16 #define CF_LE_W(v) le16_to_cpu(v)
17 #define CF_LE_L(v) le32_to_cpu(v)
18 #define CT_LE_W(v) cpu_to_le16(v)
19 #define CT_LE_L(v) cpu_to_le32(v)
20 #endif
21
22 #define MSDOS_SUPER_MAGIC 0x4d44 /* MD */
23
24 #define MSDOS_ROOT_INO 1 /* == MINIX_ROOT_INO */
25 #define MSDOS_DIR_BITS 5 /* log2(sizeof(struct msdos_dir_entry)) */
26
27 /* directory limit */
28 #define FAT_MAX_DIR_ENTRIES (65536)
29 #define FAT_MAX_DIR_SIZE (FAT_MAX_DIR_ENTRIES << MSDOS_DIR_BITS)
30
31 #define ATTR_NONE 0 /* no attribute bits */
32 #define ATTR_RO 1 /* read-only */
33 #define ATTR_HIDDEN 2 /* hidden */
34 #define ATTR_SYS 4 /* system */
35 #define ATTR_VOLUME 8 /* volume label */
36 #define ATTR_DIR 16 /* directory */
37 #define ATTR_ARCH 32 /* archived */
38
39 /* attribute bits that are copied "as is" */
40 #define ATTR_UNUSED (ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN)
41 /* bits that are used by the Windows 95/Windows NT extended FAT */
42 #define ATTR_EXT (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
43
44 #define CASE_LOWER_BASE 8 /* base is lower case */
45 #define CASE_LOWER_EXT 16 /* extension is lower case */
46
47 #define DELETED_FLAG 0xe5 /* marks file as deleted when in name[0] */
48 #define IS_FREE(n) (!*(n) || *(n) == DELETED_FLAG)
49
50 /* valid file mode bits */
51 #define MSDOS_VALID_MODE (S_IFREG | S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO)
52 /* Convert attribute bits and a mask to the UNIX mode. */
53 #define MSDOS_MKMODE(a, m) (m & (a & ATTR_RO ? S_IRUGO|S_IXUGO : S_IRWXUGO))
54
55 #define MSDOS_NAME 11 /* maximum name length */
56 #define MSDOS_LONGNAME 256 /* maximum name length */
57 #define MSDOS_SLOTS 21 /* max # of slots for short and long names */
58 #define MSDOS_DOT ". " /* ".", padded to MSDOS_NAME chars */
59 #define MSDOS_DOTDOT ".. " /* "..", padded to MSDOS_NAME chars */
60
61 /* media of boot sector */
62 #define FAT_VALID_MEDIA(x) ((0xF8 <= (x) && (x) <= 0xFF) || (x) == 0xF0)
63 #define FAT_FIRST_ENT(s, x) ((MSDOS_SB(s)->fat_bits == 32 ? 0x0FFFFF00 : \
64 MSDOS_SB(s)->fat_bits == 16 ? 0xFF00 : 0xF00) | (x))
65
66 /* start of data cluster's entry (number of reserved clusters) */
67 #define FAT_START_ENT 2
68
69 /* maximum number of clusters */
70 #define MAX_FAT12 0xFF4
71 #define MAX_FAT16 0xFFF4
72 #define MAX_FAT32 0x0FFFFFF6
73 #define MAX_FAT(s) (MSDOS_SB(s)->fat_bits == 32 ? MAX_FAT32 : \
74 MSDOS_SB(s)->fat_bits == 16 ? MAX_FAT16 : MAX_FAT12)
75
76 /* bad cluster mark */
77 #define BAD_FAT12 0xFF7
78 #define BAD_FAT16 0xFFF7
79 #define BAD_FAT32 0x0FFFFFF7
80
81 /* standard EOF */
82 #define EOF_FAT12 0xFFF
83 #define EOF_FAT16 0xFFFF
84 #define EOF_FAT32 0x0FFFFFFF
85
86 #define FAT_ENT_FREE (0)
87 #define FAT_ENT_BAD (BAD_FAT32)
88 #define FAT_ENT_EOF (EOF_FAT32)
89
90 #define FAT_FSINFO_SIG1 0x41615252
91 #define FAT_FSINFO_SIG2 0x61417272
92 #define IS_FSINFO(x) (le32_to_cpu((x)->signature1) == FAT_FSINFO_SIG1 \
93 && le32_to_cpu((x)->signature2) == FAT_FSINFO_SIG2)
94
95 /*
96 * ioctl commands
97 */
98 #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct dirent [2])
99 #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct dirent [2])
100 /* <linux/videotext.h> has used 0x72 ('r') in collision, so skip a few */
101 #define FAT_IOCTL_GET_ATTRIBUTES _IOR('r', 0x10, __u32)
102 #define FAT_IOCTL_SET_ATTRIBUTES _IOW('r', 0x11, __u32)
103
104 /*
105 * vfat shortname flags
106 */
107 #define VFAT_SFN_DISPLAY_LOWER 0x0001 /* convert to lowercase for display */
108 #define VFAT_SFN_DISPLAY_WIN95 0x0002 /* emulate win95 rule for display */
109 #define VFAT_SFN_DISPLAY_WINNT 0x0004 /* emulate winnt rule for display */
110 #define VFAT_SFN_CREATE_WIN95 0x0100 /* emulate win95 rule for create */
111 #define VFAT_SFN_CREATE_WINNT 0x0200 /* emulate winnt rule for create */
112
113 struct fat_boot_sector {
114 __u8 ignored[3]; /* Boot strap short or near jump */
115 __u8 system_id[8]; /* Name - can be used to special case
116 partition manager volumes */
117 __u8 sector_size[2]; /* bytes per logical sector */
118 __u8 sec_per_clus; /* sectors/cluster */
119 __le16 reserved; /* reserved sectors */
120 __u8 fats; /* number of FATs */
121 __u8 dir_entries[2]; /* root directory entries */
122 __u8 sectors[2]; /* number of sectors */
123 __u8 media; /* media code */
124 __le16 fat_length; /* sectors/FAT */
125 __le16 secs_track; /* sectors per track */
126 __le16 heads; /* number of heads */
127 __le32 hidden; /* hidden sectors (unused) */
128 __le32 total_sect; /* number of sectors (if sectors == 0) */
129
130 /* The following fields are only used by FAT32 */
131 __le32 fat32_length; /* sectors/FAT */
132 __le16 flags; /* bit 8: fat mirroring, low 4: active fat */
133 __u8 version[2]; /* major, minor filesystem version */
134 __le32 root_cluster; /* first cluster in root directory */
135 __le16 info_sector; /* filesystem info sector */
136 __le16 backup_boot; /* backup boot sector */
137 __le16 reserved2[6]; /* Unused */
138 };
139
140 struct fat_boot_fsinfo {
141 __le32 signature1; /* 0x41615252L */
142 __le32 reserved1[120]; /* Nothing as far as I can tell */
143 __le32 signature2; /* 0x61417272L */
144 __le32 free_clusters; /* Free cluster count. -1 if unknown */
145 __le32 next_cluster; /* Most recently allocated cluster */
146 __le32 reserved2[4];
147 };
148
149 struct msdos_dir_entry {
150 __u8 name[8],ext[3]; /* name and extension */
151 __u8 attr; /* attribute bits */
152 __u8 lcase; /* Case for base and extension */
153 __u8 ctime_cs; /* Creation time, centiseconds (0-199) */
154 __le16 ctime; /* Creation time */
155 __le16 cdate; /* Creation date */
156 __le16 adate; /* Last access date */
157 __le16 starthi; /* High 16 bits of cluster in FAT32 */
158 __le16 time,date,start;/* time, date and first cluster */
159 __le32 size; /* file size (in bytes) */
160 };
161
162 /* Up to 13 characters of the name */
163 struct msdos_dir_slot {
164 __u8 id; /* sequence number for slot */
165 __u8 name0_4[10]; /* first 5 characters in name */
166 __u8 attr; /* attribute byte */
167 __u8 reserved; /* always 0 */
168 __u8 alias_checksum; /* checksum for 8.3 alias */
169 __u8 name5_10[12]; /* 6 more characters in name */
170 __le16 start; /* starting cluster number, 0 in long slots */
171 __u8 name11_12[4]; /* last 2 characters in name */
172 };
173
174 struct fat_slot_info {
175 loff_t i_pos; /* on-disk position of directory entry */
176 loff_t slot_off; /* offset for slot or de start */
177 int nr_slots; /* number of slots + 1(de) in filename */
178 struct msdos_dir_entry *de;
179 struct buffer_head *bh;
180 };
181
182 #endif