22 #ifndef __DOSFS_FAT_H__ 23 #define __DOSFS_FAT_H__ 25 #include <sys/param.h> 26 #include <sys/endian.h> 59 #define CF_LE_W(v) le16toh(v) 60 #define CF_LE_L(v) le32toh(v) 61 #define CT_LE_W(v) htole16(v) 62 #define CT_LE_L(v) htole32(v) 64 #define FAT_HASH_SIZE 2 65 #define FAT_HASH_MODULE FAT_HASH_SIZE 68 #define FAT_SECTOR512_SIZE 512 69 #define FAT_SECTOR512_BITS 9 72 #define FAT_FAT12_MAX_CLN 4085 75 #define FAT_FAT16_MAX_CLN 65525 77 #define FAT_FAT12 0x01 78 #define FAT_FAT16 0x02 79 #define FAT_FAT32 0x04 81 #define FAT_UNDEFINED_VALUE (uint32_t)0xFFFFFFFF 83 #define FAT_FAT12_EOC 0x0FF8 84 #define FAT_FAT16_EOC 0xFFF8 85 #define FAT_FAT32_EOC (uint32_t)0x0FFFFFF8 87 #define FAT_FAT12_FREE 0x0000 88 #define FAT_FAT16_FREE 0x0000 89 #define FAT_FAT32_FREE 0x00000000 91 #define FAT_GENFAT_EOC (uint32_t)0xFFFFFFFF 92 #define FAT_GENFAT_FREE (uint32_t)0x00000000 94 #define FAT_FAT12_SHIFT 0x04 96 #define FAT_FAT12_MASK 0x00000FFF 97 #define FAT_FAT16_MASK 0x0000FFFF 98 #define FAT_FAT32_MASK (uint32_t)0x0FFFFFFF 100 #define FAT_MAX_BPB_SIZE 90 101 #define FAT_TOTAL_MBR_SIZE 512 104 #define FAT_USEFUL_INFO_SIZE 12 106 #define FAT_GET_ADDR(x, ofs) ((uint8_t *)(x) + (ofs)) 108 #define FAT_GET_VAL8(x, ofs) (uint8_t)(*((uint8_t *)(x) + (ofs))) 110 #define FAT_GET_VAL16(x, ofs) \ 111 (uint16_t)( (*((uint8_t *)(x) + (ofs))) | \ 112 ((*((uint8_t *)(x) + (ofs) + 1)) << 8) ) 114 #define FAT_GET_VAL32(x, ofs) \ 115 (uint32_t)( (uint32_t)(*((uint8_t *)(x) + (ofs))) | \ 116 ((uint32_t)(*((uint8_t *)(x) + (ofs) + 1)) << 8) | \ 117 ((uint32_t)(*((uint8_t *)(x) + (ofs) + 2)) << 16) | \ 118 ((uint32_t)(*((uint8_t *)(x) + (ofs) + 3)) << 24) ) 120 #define FAT_SET_VAL8(x, ofs,val) \ 121 (*((uint8_t *)(x)+(ofs))=(uint8_t)(val)) 123 #define FAT_SET_VAL16(x, ofs,val) do { \ 124 FAT_SET_VAL8((x),(ofs),(val)); \ 125 FAT_SET_VAL8((x),(ofs)+1,(val)>>8);\ 128 #define FAT_SET_VAL32(x, ofs,val) do { \ 129 uint32_t val1 = val; \ 130 FAT_SET_VAL16((x),(ofs),(val1)&0xffff);\ 131 FAT_SET_VAL16((x),(ofs)+2,(val1)>>16);\ 135 #define FAT_GET_BR_JMPBOOT(x) FAT_GET_VAL8( x, 0) 136 #define FAT_SET_BR_JMPBOOT(x,val) FAT_SET_VAL8( x, 0,val) 138 #define FAT_GET_ADDR_BR_OEMNAME(x) FAT_GET_ADDR( x, 3) 139 #define FAT_BR_OEMNAME_SIZE (8) 141 #define FAT_GET_BR_BYTES_PER_SECTOR(x) FAT_GET_VAL16(x, 11) 142 #define FAT_SET_BR_BYTES_PER_SECTOR(x,val) FAT_SET_VAL16(x, 11,val) 144 #define FAT_GET_BR_SECTORS_PER_CLUSTER(x) FAT_GET_VAL8( x, 13) 145 #define FAT_SET_BR_SECTORS_PER_CLUSTER(x,val)FAT_SET_VAL8( x, 13,val) 147 #define FAT_GET_BR_RESERVED_SECTORS_NUM(x) FAT_GET_VAL16(x, 14) 148 #define FAT_SET_BR_RESERVED_SECTORS_NUM(x,val) FAT_SET_VAL16(x, 14,val) 150 #define FAT_GET_BR_FAT_NUM(x) FAT_GET_VAL8( x, 16) 151 #define FAT_SET_BR_FAT_NUM(x,val) FAT_SET_VAL8( x, 16,val) 153 #define FAT_GET_BR_FILES_PER_ROOT_DIR(x) FAT_GET_VAL16(x, 17) 154 #define FAT_SET_BR_FILES_PER_ROOT_DIR(x,val) FAT_SET_VAL16(x, 17,val) 156 #define FAT_GET_BR_TOTAL_SECTORS_NUM16(x) FAT_GET_VAL16(x, 19) 157 #define FAT_SET_BR_TOTAL_SECTORS_NUM16(x,val)FAT_SET_VAL16(x, 19,val) 159 #define FAT_GET_BR_MEDIA(x) FAT_GET_VAL8( x, 21) 160 #define FAT_SET_BR_MEDIA(x,val) FAT_SET_VAL8( x, 21,val) 162 #define FAT_GET_BR_SECTORS_PER_FAT(x) FAT_GET_VAL16(x, 22) 163 #define FAT_SET_BR_SECTORS_PER_FAT(x,val) FAT_SET_VAL16(x, 22,val) 165 #define FAT_GET_BR_SECTORS_PER_TRACK(x) FAT_GET_VAL16(x, 24) 166 #define FAT_SET_BR_SECTORS_PER_TRACK(x,val) FAT_SET_VAL16(x, 24,val) 168 #define FAT_GET_BR_NUMBER_OF_HEADS(x) FAT_GET_VAL16(x, 26) 169 #define FAT_SET_BR_NUMBER_OF_HEADS(x,val) FAT_SET_VAL16(x, 26,val) 171 #define FAT_GET_BR_HIDDEN_SECTORS(x) FAT_GET_VAL32(x, 28) 172 #define FAT_SET_BR_HIDDEN_SECTORS(x,val) FAT_SET_VAL32(x, 28,val) 174 #define FAT_GET_BR_TOTAL_SECTORS_NUM32(x) FAT_GET_VAL32(x, 32) 175 #define FAT_SET_BR_TOTAL_SECTORS_NUM32(x,val) FAT_SET_VAL32(x, 32,val) 177 #define FAT_GET_BR_DRVNUM(x) FAT_GET_VAL8( x, 36) 178 #define FAT_SET_BR_DRVNUM(x,val) FAT_SET_VAL8( x, 36,val) 180 #define FAT_GET_BR_RSVD1(x) FAT_GET_VAL8( x, 37) 181 #define FAT_SET_BR_RSVD1(x,val) FAT_SET_VAL8( x, 37,val) 183 #define FAT_GET_BR_BOOTSIG(x) FAT_GET_VAL8( x, 38) 184 #define FAT_SET_BR_BOOTSIG(x,val) FAT_SET_VAL8( x, 38,val) 185 #define FAT_BR_BOOTSIG_VAL (0x29) 187 #define FAT_GET_BR_VOLID(x) FAT_GET_VAL32(x, 39) 188 #define FAT_SET_BR_VOLID(x,val) FAT_SET_VAL32(x, 39,val) 190 #define FAT_GET_ADDR_BR_VOLLAB(x) FAT_GET_ADDR (x, 43) 191 #define FAT_BR_VOLLAB_SIZE (11) 193 #define FAT_GET_ADDR_BR_FILSYSTYPE(x) FAT_GET_ADDR (x, 54) 194 #define FAT_BR_FILSYSTYPE_SIZE (8) 197 #define FAT_GET_BR_SECTORS_PER_FAT32(x) FAT_GET_VAL32(x, 36) 198 #define FAT_SET_BR_SECTORS_PER_FAT32(x,val) FAT_SET_VAL32(x, 36,val) 200 #define FAT_GET_BR_EXT_FLAGS(x) FAT_GET_VAL16(x, 40) 201 #define FAT_SET_BR_EXT_FLAGS(x,val) FAT_SET_VAL16(x, 40,val) 203 #define FAT_GET_BR_FSVER(x) FAT_GET_VAL16(x, 42) 204 #define FAT_SET_BR_FSVER(x,val) FAT_SET_VAL16(x, 42,val) 206 #define FAT_GET_BR_FAT32_ROOT_CLUSTER(x) FAT_GET_VAL32(x, 44) 207 #define FAT_SET_BR_FAT32_ROOT_CLUSTER(x,val) FAT_SET_VAL32(x, 44,val) 209 #define FAT_GET_BR_FAT32_FS_INFO_SECTOR(x) FAT_GET_VAL16(x, 48) 210 #define FAT_SET_BR_FAT32_FS_INFO_SECTOR(x,val) FAT_SET_VAL16(x, 48,val) 212 #define FAT_GET_BR_FAT32_BK_BOOT_SECTOR(x) FAT_GET_VAL16(x, 50) 213 #define FAT_SET_BR_FAT32_BK_BOOT_SECTOR(x,val) FAT_SET_VAL16(x, 50,val) 215 #define FAT_GET_ADDR_BR_FAT32_RESERVED(x) FAT_GET_ADDR (x, 52) 216 #define FAT_BR_FAT32_RESERVED_SIZE (12) 218 #define FAT_GET_BR_FAT32_DRVNUM(x) FAT_GET_VAL8( x, 64) 219 #define FAT_SET_BR_FAT32_DRVNUM(x,val) FAT_SET_VAL8( x, 64,val) 221 #define FAT_GET_BR_FAT32_RSVD1(x) FAT_GET_VAL8( x, 65) 222 #define FAT_SET_BR_FAT32_RSVD1(x,val) FAT_SET_VAL8( x, 65,val) 224 #define FAT_GET_BR_FAT32_BOOTSIG(x) FAT_GET_VAL8( x, 66) 225 #define FAT_SET_BR_FAT32_BOOTSIG(x,val) FAT_SET_VAL8( x, 66,val) 226 #define FAT_BR_FAT32_BOOTSIG_VAL (0x29) 228 #define FAT_GET_BR_FAT32_VOLID(x) FAT_GET_VAL32(x, 67) 229 #define FAT_SET_BR_FAT32_VOLID(x,val) FAT_SET_VAL32(x, 67,val) 231 #define FAT_GET_ADDR_BR_FAT32_VOLLAB(x) FAT_GET_ADDR (x, 71) 232 #define FAT_BR_FAT32_VOLLAB_SIZE (11) 234 #define FAT_GET_ADDR_BR_FAT32_FILSYSTYPE(x) FAT_GET_ADDR (x, 82) 235 #define FAT_BR_FAT32_FILSYSTYPE_SIZE (8) 238 #define FAT_GET_BR_SIGNATURE(x) FAT_GET_VAL16(x,510) 239 #define FAT_SET_BR_SIGNATURE(x,val) FAT_SET_VAL16(x,510,val) 240 #define FAT_BR_SIGNATURE_VAL (0xAA55) 245 #define FAT_GET_FSINFO_LEAD_SIGNATURE(x) FAT_GET_VAL32(x, 0) 246 #define FAT_SET_FSINFO_LEAD_SIGNATURE(x,val) FAT_SET_VAL32(x, 0,val) 247 #define FAT_FSINFO_LEAD_SIGNATURE_VALUE (0x41615252) 249 #define FAT_GET_FSINFO_STRUC_SIGNATURE(x) FAT_GET_VAL32(x,484) 250 #define FAT_SET_FSINFO_STRUC_SIGNATURE(x,val) FAT_SET_VAL32(x,484,val) 251 #define FAT_FSINFO_STRUC_SIGNATURE_VALUE (0x61417272) 253 #define FAT_GET_FSINFO_TRAIL_SIGNATURE(x) FAT_GET_VAL32(x,508) 254 #define FAT_SET_FSINFO_TRAIL_SIGNATURE(x,val) FAT_SET_VAL32(x,508,val) 255 #define FAT_FSINFO_TRAIL_SIGNATURE_VALUE (0xAA550000) 260 #define FAT_GET_FSINFO_FREE_CLUSTER_COUNT(x) FAT_GET_VAL32(x, 4) 261 #define FAT_SET_FSINFO_FREE_CLUSTER_COUNT(x,val) FAT_SET_VAL32(x, 4,val) 262 #define FAT_GET_FSINFO_NEXT_FREE_CLUSTER(x) FAT_GET_VAL32(x, 8) 263 #define FAT_SET_FSINFO_NEXT_FREE_CLUSTER(x,val) FAT_SET_VAL32(x, 8,val) 265 #define FAT_FSI_INFO 484 266 #define FAT_FSINFO_STRUCT_OFFSET 488 267 #define FAT_FSINFO_FREE_CLUSTER_COUNT_OFFSET (FAT_FSINFO_STRUCT_OFFSET+0) 269 #define FAT_FSINFO_NEXT_FREE_CLUSTER_OFFSET (FAT_FSINFO_STRUCT_OFFSET+4) 271 #define FAT_RSRVD_CLN 0x02 273 #define FAT_FSI_LEADSIG_SIZE 0x04 275 #define FAT_TOTAL_FSINFO_SIZE 512 277 #define MS_BYTES_PER_CLUSTER_LIMIT 0x10000 278 #define MS_BYTES_PER_CLUSTER_LIMIT_FAT12 0x1000 280 #define FAT_BR_EXT_FLAGS_MIRROR 0x0080 282 #define FAT_BR_EXT_FLAGS_FAT_NUM 0x000F 284 #define FAT_BR_MEDIA_FIXED 0xf8 286 #define FAT_DIRENTRY_SIZE 32 288 #define FAT_DIRENTRIES_PER_SEC512 16 305 uint8_t sectors_per_block;
306 uint32_t bytes_per_block;
307 uint8_t bytes_per_block_log2;
324 uint32_t free_cls_in_fs_info;
327 uint32_t next_cl_in_fs_info;
358 uint32_t uino_pool_size;
389 #define FAT_FILE_SHORT_NAME (0xffffffff) 391 #define FAT_FAT_OFFSET(fat_type, cln) \ 392 ((fat_type) & FAT_FAT12 ? ((cln) + ((cln) >> 1)) : \ 393 (fat_type) & FAT_FAT16 ? ((cln) << 1) : \ 396 #define FAT_CLUSTER_IS_ODD(n) ((n) & 0x0001) 398 #define FAT12_SHIFT 0x4 401 #define FAT_UINO_POOL_INIT_SIZE 0x100 404 #define FAT_CACHE_EMPTY 0x0 405 #define FAT_CACHE_ACTUAL 0x1 407 #define FAT_OP_TYPE_READ 0x1 408 #define FAT_OP_TYPE_GET 0x2 415 dir_pos->sname.cln = 0;
416 dir_pos->sname.ofs = 0;
417 dir_pos->lname.cln = FAT_FILE_SHORT_NAME;
418 dir_pos->lname.ofs = FAT_FILE_SHORT_NAME;
421 static inline uint32_t
422 fat_cluster_num_to_sector_num(
427 if ( (cln == 0) && (fs_info->vol.type & (FAT_FAT12 | FAT_FAT16)) )
428 return fs_info->vol.rdir_loc;
430 return (((cln - FAT_RSRVD_CLN) << fs_info->vol.spc_log2) +
431 fs_info->vol.data_fsec);
434 static inline uint32_t
435 fat_cluster_num_to_sector512_num(
443 return (fat_cluster_num_to_sector_num(fs_info, cln) <<
444 fs_info->vol.sec_mul);
447 static inline uint32_t
449 const uint32_t block_number)
451 return block_number >> (fs_info->vol.bpc_log2 - fs_info->vol.bytes_per_block_log2);
454 static inline uint32_t
456 const uint32_t block_number)
458 return block_number << (fs_info->vol.bytes_per_block_log2 - fs_info->vol.sec_log2);
461 static inline uint32_t
463 const uint32_t sector_number)
465 return sector_number >> (fs_info->vol.bytes_per_block_log2 - fs_info->vol.sec_log2);
468 static inline uint32_t
469 fat_sector_offset_to_block_offset (
const fat_fs_info_t *fs_info,
470 const uint32_t sector,
471 const uint32_t sector_offset)
473 return sector_offset +
475 fat_block_num_to_sector_num (fs_info,
476 fat_sector_num_to_block_num (fs_info, sector)))
477 << fs_info->vol.sec_log2);
483 fs_info->c.modified =
true;
Data which Ease the Burden of Consistently Setting Errno.
Definition: rtemscompat1.h:15
Description of a disk device (logical and physical disks).
Definition: diskdevs.h:157
Block Device Buffer Management.