Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef _LINUX_MSDOS_FS_H |
| 2 | #define _LINUX_MSDOS_FS_H |
| 3 | |
Jaswinder Singh Rajput | 8ef3420 | 2009-01-30 21:56:32 +0530 | [diff] [blame] | 4 | #include <linux/types.h> |
Jeff Garzik | e18fa70 | 2006-09-24 11:13:19 -0400 | [diff] [blame] | 5 | #include <linux/magic.h> |
OGAWA Hirofumi | 4596c8a | 2008-07-25 01:46:42 -0700 | [diff] [blame] | 6 | #include <asm/byteorder.h> |
Jeff Garzik | e18fa70 | 2006-09-24 11:13:19 -0400 | [diff] [blame] | 7 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | /* |
| 9 | * The MS-DOS filesystem constants/structures |
| 10 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
| 12 | #define SECTOR_SIZE 512 /* sector size (bytes) */ |
| 13 | #define SECTOR_BITS 9 /* log2(SECTOR_SIZE) */ |
| 14 | #define MSDOS_DPB (MSDOS_DPS) /* dir entries per block */ |
| 15 | #define MSDOS_DPB_BITS 4 /* log2(MSDOS_DPB) */ |
| 16 | #define MSDOS_DPS (SECTOR_SIZE / sizeof(struct msdos_dir_entry)) |
| 17 | #define MSDOS_DPS_BITS 4 /* log2(MSDOS_DPS) */ |
Kevin Dankwardt | eeb5b4a | 2010-02-10 23:43:40 +0900 | [diff] [blame] | 18 | #define MSDOS_LONGNAME 256 /* maximum name length */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #define CF_LE_W(v) le16_to_cpu(v) |
| 20 | #define CF_LE_L(v) le32_to_cpu(v) |
| 21 | #define CT_LE_W(v) cpu_to_le16(v) |
| 22 | #define CT_LE_L(v) cpu_to_le32(v) |
| 23 | |
| 24 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #define MSDOS_ROOT_INO 1 /* == MINIX_ROOT_INO */ |
| 26 | #define MSDOS_DIR_BITS 5 /* log2(sizeof(struct msdos_dir_entry)) */ |
| 27 | |
| 28 | /* directory limit */ |
| 29 | #define FAT_MAX_DIR_ENTRIES (65536) |
| 30 | #define FAT_MAX_DIR_SIZE (FAT_MAX_DIR_ENTRIES << MSDOS_DIR_BITS) |
| 31 | |
| 32 | #define ATTR_NONE 0 /* no attribute bits */ |
| 33 | #define ATTR_RO 1 /* read-only */ |
| 34 | #define ATTR_HIDDEN 2 /* hidden */ |
| 35 | #define ATTR_SYS 4 /* system */ |
| 36 | #define ATTR_VOLUME 8 /* volume label */ |
| 37 | #define ATTR_DIR 16 /* directory */ |
| 38 | #define ATTR_ARCH 32 /* archived */ |
| 39 | |
| 40 | /* attribute bits that are copied "as is" */ |
| 41 | #define ATTR_UNUSED (ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN) |
| 42 | /* bits that are used by the Windows 95/Windows NT extended FAT */ |
| 43 | #define ATTR_EXT (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME) |
| 44 | |
| 45 | #define CASE_LOWER_BASE 8 /* base is lower case */ |
| 46 | #define CASE_LOWER_EXT 16 /* extension is lower case */ |
| 47 | |
| 48 | #define DELETED_FLAG 0xe5 /* marks file as deleted when in name[0] */ |
| 49 | #define IS_FREE(n) (!*(n) || *(n) == DELETED_FLAG) |
| 50 | |
Kevin Dankwardt | eeb5b4a | 2010-02-10 23:43:40 +0900 | [diff] [blame] | 51 | #define FAT_LFN_LEN 255 /* maximum long name length */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #define MSDOS_NAME 11 /* maximum name length */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #define MSDOS_SLOTS 21 /* max # of slots for short and long names */ |
| 54 | #define MSDOS_DOT ". " /* ".", padded to MSDOS_NAME chars */ |
| 55 | #define MSDOS_DOTDOT ".. " /* "..", padded to MSDOS_NAME chars */ |
| 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #define FAT_FIRST_ENT(s, x) ((MSDOS_SB(s)->fat_bits == 32 ? 0x0FFFFF00 : \ |
| 58 | MSDOS_SB(s)->fat_bits == 16 ? 0xFF00 : 0xF00) | (x)) |
| 59 | |
| 60 | /* start of data cluster's entry (number of reserved clusters) */ |
| 61 | #define FAT_START_ENT 2 |
| 62 | |
| 63 | /* maximum number of clusters */ |
| 64 | #define MAX_FAT12 0xFF4 |
| 65 | #define MAX_FAT16 0xFFF4 |
| 66 | #define MAX_FAT32 0x0FFFFFF6 |
| 67 | #define MAX_FAT(s) (MSDOS_SB(s)->fat_bits == 32 ? MAX_FAT32 : \ |
| 68 | MSDOS_SB(s)->fat_bits == 16 ? MAX_FAT16 : MAX_FAT12) |
| 69 | |
| 70 | /* bad cluster mark */ |
| 71 | #define BAD_FAT12 0xFF7 |
| 72 | #define BAD_FAT16 0xFFF7 |
| 73 | #define BAD_FAT32 0x0FFFFFF7 |
| 74 | |
| 75 | /* standard EOF */ |
| 76 | #define EOF_FAT12 0xFFF |
| 77 | #define EOF_FAT16 0xFFFF |
| 78 | #define EOF_FAT32 0x0FFFFFFF |
| 79 | |
| 80 | #define FAT_ENT_FREE (0) |
| 81 | #define FAT_ENT_BAD (BAD_FAT32) |
| 82 | #define FAT_ENT_EOF (EOF_FAT32) |
| 83 | |
| 84 | #define FAT_FSINFO_SIG1 0x41615252 |
| 85 | #define FAT_FSINFO_SIG2 0x61417272 |
| 86 | #define IS_FSINFO(x) (le32_to_cpu((x)->signature1) == FAT_FSINFO_SIG1 \ |
| 87 | && le32_to_cpu((x)->signature2) == FAT_FSINFO_SIG2) |
| 88 | |
OGAWA Hirofumi | 4596c8a | 2008-07-25 01:46:42 -0700 | [diff] [blame] | 89 | struct __fat_dirent { |
| 90 | long d_ino; |
| 91 | __kernel_off_t d_off; |
| 92 | unsigned short d_reclen; |
| 93 | char d_name[256]; /* We must not include limits.h! */ |
| 94 | }; |
| 95 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | /* |
| 97 | * ioctl commands |
| 98 | */ |
OGAWA Hirofumi | 4596c8a | 2008-07-25 01:46:42 -0700 | [diff] [blame] | 99 | #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct __fat_dirent[2]) |
| 100 | #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct __fat_dirent[2]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | /* <linux/videotext.h> has used 0x72 ('r') in collision, so skip a few */ |
| 102 | #define FAT_IOCTL_GET_ATTRIBUTES _IOR('r', 0x10, __u32) |
| 103 | #define FAT_IOCTL_SET_ATTRIBUTES _IOW('r', 0x11, __u32) |
Mike Lockwood | b1042b9 | 2008-03-15 13:29:36 -0400 | [diff] [blame] | 104 | #define VFAT_IOCTL_GET_VOLUME_ID _IOR('r', 0x12, __u32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | struct fat_boot_sector { |
| 107 | __u8 ignored[3]; /* Boot strap short or near jump */ |
| 108 | __u8 system_id[8]; /* Name - can be used to special case |
| 109 | partition manager volumes */ |
| 110 | __u8 sector_size[2]; /* bytes per logical sector */ |
| 111 | __u8 sec_per_clus; /* sectors/cluster */ |
| 112 | __le16 reserved; /* reserved sectors */ |
| 113 | __u8 fats; /* number of FATs */ |
| 114 | __u8 dir_entries[2]; /* root directory entries */ |
| 115 | __u8 sectors[2]; /* number of sectors */ |
| 116 | __u8 media; /* media code */ |
| 117 | __le16 fat_length; /* sectors/FAT */ |
| 118 | __le16 secs_track; /* sectors per track */ |
| 119 | __le16 heads; /* number of heads */ |
| 120 | __le32 hidden; /* hidden sectors (unused) */ |
| 121 | __le32 total_sect; /* number of sectors (if sectors == 0) */ |
| 122 | |
| 123 | /* The following fields are only used by FAT32 */ |
| 124 | __le32 fat32_length; /* sectors/FAT */ |
| 125 | __le16 flags; /* bit 8: fat mirroring, low 4: active fat */ |
| 126 | __u8 version[2]; /* major, minor filesystem version */ |
| 127 | __le32 root_cluster; /* first cluster in root directory */ |
| 128 | __le16 info_sector; /* filesystem info sector */ |
| 129 | __le16 backup_boot; /* backup boot sector */ |
| 130 | __le16 reserved2[6]; /* Unused */ |
| 131 | }; |
| 132 | |
| 133 | struct fat_boot_fsinfo { |
| 134 | __le32 signature1; /* 0x41615252L */ |
| 135 | __le32 reserved1[120]; /* Nothing as far as I can tell */ |
| 136 | __le32 signature2; /* 0x61417272L */ |
| 137 | __le32 free_clusters; /* Free cluster count. -1 if unknown */ |
| 138 | __le32 next_cluster; /* Most recently allocated cluster */ |
| 139 | __le32 reserved2[4]; |
| 140 | }; |
| 141 | |
Mike Lockwood | b1042b9 | 2008-03-15 13:29:36 -0400 | [diff] [blame] | 142 | struct fat_boot_bsx { |
| 143 | __u8 drive; /* drive number */ |
| 144 | __u8 reserved1; |
| 145 | __u8 signature; /* extended boot signature */ |
| 146 | __u8 vol_id[4]; /* volume ID */ |
| 147 | __u8 vol_label[11]; /* volume label */ |
| 148 | __u8 type[8]; /* file system type */ |
| 149 | }; |
| 150 | #define FAT16_BSX_OFFSET 36 /* offset of fat_boot_bsx in FAT12 and FAT16 */ |
| 151 | #define FAT32_BSX_OFFSET 64 /* offset of fat_boot_bsx in FAT32 */ |
| 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | struct msdos_dir_entry { |
OGAWA Hirofumi | 9aacd59 | 2007-07-15 23:39:56 -0700 | [diff] [blame] | 154 | __u8 name[MSDOS_NAME];/* name and extension */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | __u8 attr; /* attribute bits */ |
| 156 | __u8 lcase; /* Case for base and extension */ |
| 157 | __u8 ctime_cs; /* Creation time, centiseconds (0-199) */ |
| 158 | __le16 ctime; /* Creation time */ |
| 159 | __le16 cdate; /* Creation date */ |
| 160 | __le16 adate; /* Last access date */ |
| 161 | __le16 starthi; /* High 16 bits of cluster in FAT32 */ |
| 162 | __le16 time,date,start;/* time, date and first cluster */ |
| 163 | __le32 size; /* file size (in bytes) */ |
| 164 | }; |
| 165 | |
| 166 | /* Up to 13 characters of the name */ |
| 167 | struct msdos_dir_slot { |
| 168 | __u8 id; /* sequence number for slot */ |
| 169 | __u8 name0_4[10]; /* first 5 characters in name */ |
| 170 | __u8 attr; /* attribute byte */ |
| 171 | __u8 reserved; /* always 0 */ |
| 172 | __u8 alias_checksum; /* checksum for 8.3 alias */ |
| 173 | __u8 name5_10[12]; /* 6 more characters in name */ |
| 174 | __le16 start; /* starting cluster number, 0 in long slots */ |
| 175 | __u8 name11_12[4]; /* last 2 characters in name */ |
| 176 | }; |
| 177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | #ifdef __KERNEL__ |
Adrian Bunk | f751aa1 | 2008-06-08 21:43:10 +0300 | [diff] [blame] | 179 | /* media of boot sector */ |
| 180 | static inline int fat_valid_media(u8 media) |
| 181 | { |
| 182 | return 0xf8 <= media || media == 0xf0; |
| 183 | } |
OGAWA Hirofumi | 9e975da | 2008-11-06 12:53:46 -0800 | [diff] [blame] | 184 | #endif /* !__KERNEL__ */ |
| 185 | #endif /* !_LINUX_MSDOS_FS_H */ |