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