Changeset 875edff6 in mainline
- Timestamp:
- 2011-04-30T11:22:28Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- aa2ea13
- Parents:
- cb052b4
- Location:
- uspace/srv/fs/fat
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat.h
rcb052b4 r875edff6 55 55 #define RSCNT(bs) uint16_t_le2host((bs)->rscnt) 56 56 #define FATCNT(bs) (bs)->fatcnt 57 #define SF(bs) uint16_t_le2host((bs)->sec_per_fat) 57 #define SF(bs) (uint16_t_le2host((bs)->sec_per_fat) !=0 ? \ 58 uint16_t_le2host((bs)->sec_per_fat) : \ 59 uint32_t_le2host(bs->fat32.sectors_per_fat)) 58 60 #define RDE(bs) uint16_t_le2host((bs)->root_ent_max) 59 61 #define TS(bs) (uint16_t_le2host((bs)->totsec16) != 0 ? \ -
uspace/srv/fs/fat/fat_fat.c
rcb052b4 r875edff6 301 301 302 302 assert(fatno < FATCNT(bs)); 303 304 *value = 0; 303 305 304 306 if (FAT_IS_FAT12(bs)) 305 307 offset = (clst + clst/2); 306 308 else 307 offset = (clst * sizeof(fat_cluster_t));309 offset = (clst * FAT_CLST_SIZE(bs)); 308 310 309 311 rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno + … … 313 315 314 316 /* This cluster access spans a sector boundary. Check only for FAT12 */ 315 if (FAT_IS_FAT12(bs) && (offset % BPS(bs)+1 == BPS(bs))) { 316 /* Is it last sector of FAT? */ 317 if (offset / BPS(bs) < SF(bs)) { 318 /* No. Reading next sector */ 319 rc = block_get(&b1, devmap_handle, 1 + RSCNT(bs) + 320 SF(bs)*fatno + offset / BPS(bs), BLOCK_FLAGS_NONE); 321 if (rc != EOK) { 317 if (FAT_IS_FAT12(bs)) { 318 if ((offset % BPS(bs) + 1 == BPS(bs))) { 319 /* Is it last sector of FAT? */ 320 if (offset / BPS(bs) < SF(bs)) { 321 /* No. Reading next sector */ 322 rc = block_get(&b1, devmap_handle, 1 + RSCNT(bs) + 323 SF(bs)*fatno + offset / BPS(bs), BLOCK_FLAGS_NONE); 324 if (rc != EOK) { 325 block_put(b); 326 return rc; 327 } 328 /* 329 * Combining value with last byte of current sector and 330 * first byte of next sector 331 */ 332 *value = *(uint8_t *)(b->data + BPS(bs) - 1); 333 *value |= *(uint8_t *)(b1->data); 334 335 rc = block_put(b1); 336 if (rc != EOK) { 337 block_put(b); 338 return rc; 339 } 340 } 341 else { 342 /* Yes. It is last sector of FAT */ 322 343 block_put(b); 323 return rc;344 return ERANGE; 324 345 } 325 /* 326 * Combining value with last byte of current sector and 327 * first byte of next sector 328 */ 329 *value = *(uint8_t *)(b->data + BPS(bs) - 1); 330 *value |= *(uint8_t *)(b1->data); 331 332 rc = block_put(b1); 333 if (rc != EOK) { 334 block_put(b); 335 return rc; 336 } 337 } 338 else { 339 /* Yes. It is last sector of FAT */ 340 block_put(b); 341 return ERANGE; 342 } 343 } 344 else 345 *value = *(fat_cluster_t *)(b->data + offset % BPS(bs)); 346 347 if (FAT_IS_FAT12(bs)) { 346 } 347 348 348 if (clst & 0x0001) 349 *value = (*value) >> 4;349 *value = (*value) >> 4; 350 350 else 351 *value = (*value) & 0x0fff; 351 *value = (*value) & FAT12_MASK; 352 } 353 else { 354 if (FAT_IS_FAT32(bs)) 355 *value = *(uint32_t *)(b->data + offset % BPS(bs)) & FAT32_MASK; 356 else 357 *value = *(uint16_t *)(b->data + offset % BPS(bs)); 352 358 } 353 359 … … 383 389 offset = (clst + clst/2); 384 390 else 385 offset = (clst * sizeof(fat_cluster_t));391 offset = (clst * FAT_CLST_SIZE(bs)); 386 392 387 393 rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno + … … 734 740 735 741 /* Check number of FATs. */ 736 if ( bs->fatcnt== 0)742 if (FATCNT(bs) == 0) 737 743 return ENOTSUP; 738 744 739 745 /* Check total number of sectors. */ 740 if ( bs->totsec16 == 0 && bs->totsec32== 0)746 if (TS(bs) == 0) 741 747 return ENOTSUP; 742 748 … … 750 756 751 757 /* Check number of sectors per FAT. */ 752 if ( bs->sec_per_fat== 0)758 if (SF(bs) == 0) 753 759 return ENOTSUP; 754 760 … … 760 766 * sanitized to support file systems with this property. 761 767 */ 762 if ((uint16_t_le2host(bs->root_ent_max) * sizeof(fat_dentry_t)) % 763 uint16_t_le2host(bs->bps) != 0) 768 if (!FAT_IS_FAT32(bs) && (RDE(bs) * sizeof(fat_dentry_t)) % BPS(bs) != 0) 764 769 return ENOTSUP; 765 770 766 771 /* Check signature of each FAT. */ 767 for (fat_no = 0; fat_no < bs->fatcnt; fat_no++) {772 for (fat_no = 0; fat_no < FATCNT(bs); fat_no++) { 768 773 rc = fat_get_cluster(bs, devmap_handle, fat_no, 0, &e0); 769 774 if (rc != EOK) … … 782 787 * set to one. 783 788 */ 784 if (!FAT_IS_FAT12(bs) && ((e0 >> 8) != 0xff || e1 != 0xffff))789 if (!FAT_IS_FAT12(bs) && ((e0 >> 8) != (FAT_MASK(bs) >> 8) || e1 != FAT_MASK(bs))) 785 790 return ENOTSUP; 786 791 } -
uspace/srv/fs/fat/fat_fat.h
rcb052b4 r875edff6 54 54 #define FAT32_CLST_LAST8 0x0fffffff 55 55 56 #define FAT12_MASK 0x0fff 57 #define FAT16_MASK 0xffff 58 #define FAT32_MASK 0x0fffffff 59 56 60 #define FAT12_CLST_MAX 4085 57 61 #define FAT16_CLST_MAX 65525 62 63 /* Size in bytes for cluster value of FAT */ 64 #define FAT12_CLST_SIZE 2 65 #define FAT16_CLST_SIZE 2 66 #define FAT32_CLST_SIZE 4 58 67 59 68 /* internally used to mark root directory's parent */ … … 84 93 (FAT_IS_FAT12(bs) ? FAT12_CLST_BAD : (FAT_IS_FAT32(bs) ? FAT32_CLST_BAD : FAT16_CLST_BAD)) 85 94 95 #define FAT_CLST_SIZE(bs) (FAT_IS_FAT32(bs) ? FAT32_CLST_SIZE : FAT16_CLST_SIZE) 96 97 #define FAT_MASK(bs) \ 98 (FAT_IS_FAT12(bs) ? FAT12_MASK : (FAT_IS_FAT32(bs) ? FAT32_MASK : FAT16_MASK)) 99 86 100 /* forward declarations */ 87 101 struct block; … … 89 103 struct fat_bs; 90 104 91 typedef uint 16_t fat_cluster_t;105 typedef uint32_t fat_cluster_t; 92 106 93 107 #define fat_clusters_get(numc, bs, dh, fc) \
Note:
See TracChangeset
for help on using the changeset viewer.