msdos_fs.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. #ifndef _UAPI_LINUX_MSDOS_FS_H
  3. #define _UAPI_LINUX_MSDOS_FS_H
  4. #include <linux/types.h>
  5. #include <linux/magic.h>
  6. #include <asm/byteorder.h>
  7. /*
  8. * The MS-DOS filesystem constants/structures
  9. */
  10. #ifndef SECTOR_SIZE
  11. #define SECTOR_SIZE 512 /* sector size (bytes) */
  12. #endif
  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) */
  18. #define MSDOS_LONGNAME 256 /* maximum name length */
  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. #define MSDOS_ROOT_INO 1 /* The root inode number */
  24. #define MSDOS_FSINFO_INO 2 /* Used for managing the FSINFO block */
  25. #define MSDOS_DIR_BITS 5 /* log2(sizeof(struct msdos_dir_entry)) */
  26. /* directory limit */
  27. #define FAT_MAX_DIR_ENTRIES (65536)
  28. #define FAT_MAX_DIR_SIZE (FAT_MAX_DIR_ENTRIES << MSDOS_DIR_BITS)
  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. /* attribute bits that are copied "as is" */
  37. #define ATTR_UNUSED (ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN)
  38. /* bits that are used by the Windows 95/Windows NT extended FAT */
  39. #define ATTR_EXT (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
  40. #define CASE_LOWER_BASE 8 /* base is lower case */
  41. #define CASE_LOWER_EXT 16 /* extension is lower case */
  42. #define DELETED_FLAG 0xe5 /* marks file as deleted when in name[0] */
  43. #define IS_FREE(n) (!*(n) || *(n) == DELETED_FLAG)
  44. #define FAT_LFN_LEN 255 /* maximum long name length */
  45. #define MSDOS_NAME 11 /* maximum name length */
  46. #define MSDOS_SLOTS 21 /* max # of slots for short and long names */
  47. #define MSDOS_DOT ". " /* ".", padded to MSDOS_NAME chars */
  48. #define MSDOS_DOTDOT ".. " /* "..", padded to MSDOS_NAME chars */
  49. #define FAT_FIRST_ENT(s, x) ((MSDOS_SB(s)->fat_bits == 32 ? 0x0FFFFF00 : \
  50. MSDOS_SB(s)->fat_bits == 16 ? 0xFF00 : 0xF00) | (x))
  51. /* start of data cluster's entry (number of reserved clusters) */
  52. #define FAT_START_ENT 2
  53. /* maximum number of clusters */
  54. #define MAX_FAT12 0xFF4
  55. #define MAX_FAT16 0xFFF4
  56. #define MAX_FAT32 0x0FFFFFF6
  57. #define MAX_FAT(s) (MSDOS_SB(s)->fat_bits == 32 ? MAX_FAT32 : \
  58. MSDOS_SB(s)->fat_bits == 16 ? MAX_FAT16 : MAX_FAT12)
  59. /* bad cluster mark */
  60. #define BAD_FAT12 0xFF7
  61. #define BAD_FAT16 0xFFF7
  62. #define BAD_FAT32 0x0FFFFFF7
  63. /* standard EOF */
  64. #define EOF_FAT12 0xFFF
  65. #define EOF_FAT16 0xFFFF
  66. #define EOF_FAT32 0x0FFFFFFF
  67. #define FAT_ENT_FREE (0)
  68. #define FAT_ENT_BAD (BAD_FAT32)
  69. #define FAT_ENT_EOF (EOF_FAT32)
  70. #define FAT_FSINFO_SIG1 0x41615252
  71. #define FAT_FSINFO_SIG2 0x61417272
  72. #define IS_FSINFO(x) (le32_to_cpu((x)->signature1) == FAT_FSINFO_SIG1 \
  73. && le32_to_cpu((x)->signature2) == FAT_FSINFO_SIG2)
  74. #define FAT_STATE_DIRTY 0x01
  75. struct __fat_dirent {
  76. long d_ino;
  77. __kernel_off_t d_off;
  78. unsigned short d_reclen;
  79. char d_name[256]; /* We must not include limits.h! */
  80. };
  81. /*
  82. * ioctl commands
  83. */
  84. #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct __fat_dirent[2])
  85. #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct __fat_dirent[2])
  86. /* <linux/videotext.h> has used 0x72 ('r') in collision, so skip a few */
  87. #define FAT_IOCTL_GET_ATTRIBUTES _IOR('r', 0x10, __u32)
  88. #define FAT_IOCTL_SET_ATTRIBUTES _IOW('r', 0x11, __u32)
  89. /*Android kernel has used 0x12, so we use 0x13*/
  90. #define FAT_IOCTL_GET_VOLUME_ID _IOR('r', 0x13, __u32)
  91. struct fat_boot_sector {
  92. __u8 ignored[3]; /* Boot strap short or near jump */
  93. __u8 system_id[8]; /* Name - can be used to special case
  94. partition manager volumes */
  95. __u8 sector_size[2]; /* bytes per logical sector */
  96. __u8 sec_per_clus; /* sectors/cluster */
  97. __le16 reserved; /* reserved sectors */
  98. __u8 fats; /* number of FATs */
  99. __u8 dir_entries[2]; /* root directory entries */
  100. __u8 sectors[2]; /* number of sectors */
  101. __u8 media; /* media code */
  102. __le16 fat_length; /* sectors/FAT */
  103. __le16 secs_track; /* sectors per track */
  104. __le16 heads; /* number of heads */
  105. __le32 hidden; /* hidden sectors (unused) */
  106. __le32 total_sect; /* number of sectors (if sectors == 0) */
  107. union {
  108. struct {
  109. /* Extended BPB Fields for FAT16 */
  110. __u8 drive_number; /* Physical drive number */
  111. __u8 state; /* undocumented, but used
  112. for mount state. */
  113. __u8 signature; /* extended boot signature */
  114. __u8 vol_id[4]; /* volume ID */
  115. __u8 vol_label[11]; /* volume label */
  116. __u8 fs_type[8]; /* file system type */
  117. /* other fields are not added here */
  118. } fat16;
  119. struct {
  120. /* only used by FAT32 */
  121. __le32 length; /* sectors/FAT */
  122. __le16 flags; /* bit 8: fat mirroring,
  123. low 4: active fat */
  124. __u8 version[2]; /* major, minor filesystem
  125. version */
  126. __le32 root_cluster; /* first cluster in
  127. root directory */
  128. __le16 info_sector; /* filesystem info sector */
  129. __le16 backup_boot; /* backup boot sector */
  130. __le16 reserved2[6]; /* Unused */
  131. /* Extended BPB Fields for FAT32 */
  132. __u8 drive_number; /* Physical drive number */
  133. __u8 state; /* undocumented, but used
  134. for mount state. */
  135. __u8 signature; /* extended boot signature */
  136. __u8 vol_id[4]; /* volume ID */
  137. __u8 vol_label[11]; /* volume label */
  138. __u8 fs_type[8]; /* file system type */
  139. /* other fields are not added here */
  140. } fat32;
  141. };
  142. };
  143. struct fat_boot_fsinfo {
  144. __le32 signature1; /* 0x41615252L */
  145. __le32 reserved1[120]; /* Nothing as far as I can tell */
  146. __le32 signature2; /* 0x61417272L */
  147. __le32 free_clusters; /* Free cluster count. -1 if unknown */
  148. __le32 next_cluster; /* Most recently allocated cluster */
  149. __le32 reserved2[4];
  150. };
  151. struct msdos_dir_entry {
  152. __u8 name[MSDOS_NAME];/* name and extension */
  153. __u8 attr; /* attribute bits */
  154. __u8 lcase; /* Case for base and extension */
  155. __u8 ctime_cs; /* Creation time, centiseconds (0-199) */
  156. __le16 ctime; /* Creation time */
  157. __le16 cdate; /* Creation date */
  158. __le16 adate; /* Last access date */
  159. __le16 starthi; /* High 16 bits of cluster in FAT32 */
  160. __le16 time,date,start;/* time, date and first cluster */
  161. __le32 size; /* file size (in bytes) */
  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. #endif /* _UAPI_LINUX_MSDOS_FS_H */