Changes in uspace/srv/fs/fat/fat_fat.c [3f93cdbe:50f9c3a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_fat.c
r3f93cdbe r50f9c3a 46 46 #include <align.h> 47 47 #include <assert.h> 48 #include <fibril_sync h.h>48 #include <fibril_sync.h> 49 49 #include <mem.h> 50 50 … … 247 247 */ 248 248 int 249 fat_get_cluster(fat_bs_t *bs, dev_handle_t dev_handle, unsigned fatno,250 fat_cluster_t clst, fat_cluster_t*value)249 fat_get_cluster(fat_bs_t *bs, dev_handle_t dev_handle, fat_cluster_t clst, 250 fat_cluster_t *value) 251 251 { 252 252 block_t *b; 253 253 uint16_t bps; 254 254 uint16_t rscnt; 255 uint16_t sf;256 255 fat_cluster_t *cp; 257 256 int rc; … … 259 258 bps = uint16_t_le2host(bs->bps); 260 259 rscnt = uint16_t_le2host(bs->rscnt); 261 sf = uint16_t_le2host(bs->sec_per_fat); 262 263 rc = block_get(&b, dev_handle, rscnt + sf * fatno + 260 261 rc = block_get(&b, dev_handle, rscnt + 264 262 (clst * sizeof(fat_cluster_t)) / bps, BLOCK_FLAGS_NONE); 265 263 if (rc != EOK) … … 361 359 uint16_t rscnt; 362 360 uint16_t sf; 363 uint 32_t ts;361 uint16_t ts; 364 362 unsigned rde; 365 363 unsigned rds; … … 379 377 sf = uint16_t_le2host(bs->sec_per_fat); 380 378 rde = uint16_t_le2host(bs->root_ent_max); 381 ts = (uint32_t) uint16_t_le2host(bs->totsec16); 382 if (ts == 0) 383 ts = uint32_t_le2host(bs->totsec32); 379 ts = uint16_t_le2host(bs->totsec16); 384 380 385 381 rds = (sizeof(fat_dentry_t) * rde) / bps; … … 484 480 while (firstc < FAT_CLST_LAST1) { 485 481 assert(firstc >= FAT_CLST_FIRST && firstc < FAT_CLST_BAD); 486 rc = fat_get_cluster(bs, dev_handle, FAT1,firstc, &nextc);482 rc = fat_get_cluster(bs, dev_handle, firstc, &nextc); 487 483 if (rc != EOK) 488 484 return rc; … … 564 560 unsigned fatno; 565 561 566 rc = fat_get_cluster(bs, dev_handle, FAT1,lastc, &nextc);562 rc = fat_get_cluster(bs, dev_handle, lastc, &nextc); 567 563 if (rc != EOK) 568 564 return rc; … … 610 606 } 611 607 612 /** Perform basic sanity checks on the file system.613 *614 * Verify if values of boot sector fields are sane. Also verify media615 * descriptor. This is used to rule out cases when a device obviously616 * does not contain a fat file system.617 */618 int fat_sanity_check(fat_bs_t *bs, dev_handle_t dev_handle)619 {620 fat_cluster_t e0, e1;621 unsigned fat_no;622 int rc;623 624 /* Check number of FATs. */625 if (bs->fatcnt == 0)626 return ENOTSUP;627 628 /* Check total number of sectors. */629 630 if (bs->totsec16 == 0 && bs->totsec32 == 0)631 return ENOTSUP;632 633 if (bs->totsec16 != 0 && bs->totsec32 != 0 &&634 bs->totsec16 != bs->totsec32)635 return ENOTSUP;636 637 /* Check media descriptor. Must be between 0xf0 and 0xff. */638 if ((bs->mdesc & 0xf0) != 0xf0)639 return ENOTSUP;640 641 /* Check number of sectors per FAT. */642 if (bs->sec_per_fat == 0)643 return ENOTSUP;644 645 /*646 * Check that the root directory entries take up whole blocks.647 * This check is rather strict, but it allows us to treat the root648 * directory and non-root directories uniformly in some places.649 * It can be removed provided that functions such as fat_read() are650 * sanitized to support file systems with this property.651 */652 if ((uint16_t_le2host(bs->root_ent_max) * sizeof(fat_dentry_t)) %653 uint16_t_le2host(bs->bps) != 0)654 return ENOTSUP;655 656 /* Check signature of each FAT. */657 658 for (fat_no = 0; fat_no < bs->fatcnt; fat_no++) {659 rc = fat_get_cluster(bs, dev_handle, fat_no, 0, &e0);660 if (rc != EOK)661 return EIO;662 663 rc = fat_get_cluster(bs, dev_handle, fat_no, 1, &e1);664 if (rc != EOK)665 return EIO;666 667 /* Check that first byte of FAT contains the media descriptor. */668 if ((e0 & 0xff) != bs->mdesc)669 return ENOTSUP;670 671 /*672 * Check that remaining bits of the first two entries are673 * set to one.674 */675 if ((e0 >> 8) != 0xff || e1 != 0xffff)676 return ENOTSUP;677 }678 679 return EOK;680 }681 682 608 /** 683 609 * @}
Note:
See TracChangeset
for help on using the changeset viewer.