Changeset 97bc3ee in mainline for uspace/srv/fs/fat/fat_ops.c
- Timestamp:
- 2011-04-09T19:23:12Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d260a95
- Parents:
- fc35e98
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_ops.c
rfc35e98 r97bc3ee 29 29 /** @addtogroup fs 30 30 * @{ 31 */ 31 */ 32 32 33 33 /** … … 116 116 fat_dentry_t *d; 117 117 int rc; 118 118 119 119 assert(node->dirty); 120 120 121 121 bs = block_bb_get(node->idx->devmap_handle); 122 122 123 123 /* Read the block that contains the dentry of interest. */ 124 124 rc = _fat_block_get(&b, bs, node->idx->devmap_handle, node->idx->pfc, … … 136 136 d->attr = FAT_ATTR_SUBDIR; 137 137 } 138 138 139 139 /* TODO: update other fields? (e.g time fields) */ 140 140 141 141 b->dirty = true; /* need to sync block */ 142 142 rc = block_put(b); … … 255 255 fn->data = nodep; 256 256 nodep->bp = fn; 257 257 258 258 *nodepp = nodep; 259 259 return EOK; … … 291 291 * We must instantiate the node from the file system. 292 292 */ 293 293 294 294 assert(idxp->pfc); 295 295 … … 310 310 d = ((fat_dentry_t *)b->data) + (idxp->pdi % DPS(bs)); 311 311 if (d->attr & FAT_ATTR_SUBDIR) { 312 /* 312 /* 313 313 * The only directory which does not have this bit set is the 314 314 * root directory itself. The root directory node is handled … … 316 316 */ 317 317 nodep->type = FAT_DIRECTORY; 318 /* 318 319 /* 319 320 * Unfortunately, the 'size' field of the FAT dentry is not 320 321 * defined for the directory entry type. We must determine the … … 334 335 nodep->size = uint32_t_le2host(d->size); 335 336 } 336 nodep->firstc = uint16_t_le2host(d->firstc); 337 338 nodep->firstc = uint16_t_le2host(d->firstc); 337 339 nodep->lnkcnt = 1; 338 340 nodep->refcnt = 1; … … 383 385 if (rc != EOK) 384 386 return rc; 385 for (j = 0; j < DPS(bs); j++) { 387 for (j = 0; j < DPS(bs); j++) { 386 388 d = ((fat_dentry_t *)b->data) + j; 387 389 switch (fat_classify_dentry(d)) { … … 521 523 rc = fat_idx_get_new(&idxp, devmap_handle); 522 524 if (rc != EOK) { 523 (void) fat_free_clusters(bs, devmap_handle, mcl); 525 (void) fat_free_clusters(bs, devmap_handle, mcl); 524 526 (void) fat_node_put(FS_NODE(nodep)); 525 527 return rc; … … 618 620 * a new one. 619 621 */ 620 622 621 623 fibril_mutex_lock(&parentp->idx->lock); 622 624 bs = block_bb_get(parentp->idx->devmap_handle); … … 650 652 } 651 653 j = 0; 652 654 653 655 /* 654 656 * We need to grow the parent in order to create a new unused dentry. … … 697 699 rc = block_put(b); 698 700 fibril_mutex_unlock(&parentp->idx->lock); 699 if (rc != EOK) 701 if (rc != EOK) 700 702 return rc; 701 703 702 704 fibril_mutex_lock(&childp->idx->lock); 703 705 704 706 if (childp->type == FAT_DIRECTORY) { 705 707 /* … … 778 780 if (!parentp) 779 781 return EBUSY; 780 782 781 783 rc = fat_has_children(&has_children, cfn); 782 784 if (rc != EOK) … … 794 796 NULL, (childp->idx->pdi * sizeof(fat_dentry_t)) / BPS(bs), 795 797 BLOCK_FLAGS_NONE); 796 if (rc != EOK) 798 if (rc != EOK) 797 799 goto error; 798 800 d = (fat_dentry_t *)b->data + … … 839 841 return EOK; 840 842 } 841 843 842 844 fibril_mutex_lock(&nodep->idx->lock); 843 845 bs = block_bb_get(nodep->idx->devmap_handle); … … 847 849 for (i = 0; i < blocks; i++) { 848 850 fat_dentry_t *d; 849 851 850 852 rc = fat_block_get(&b, bs, nodep, i, BLOCK_FLAGS_NONE); 851 853 if (rc != EOK) { … … 875 877 if (rc != EOK) { 876 878 fibril_mutex_unlock(&nodep->idx->lock); 877 return rc; 879 return rc; 878 880 } 879 881 } … … 945 947 */ 946 948 947 948 #define RootDirSectors(bs) (((RDE(bs)*32) + (BPS(bs)-1)) / BPS(bs))949 #define FATSz(bs) SF(bs) != 0 ? SF(bs) : uint32_t_le2host((bs)->fat32.sectors_per_fat)950 #define DataSec(bs) (TS(bs) - (RSCNT(bs) + (FATCNT(bs) * FATSz(bs)) + RootDirSectors(bs)))951 #define CountOfClusters(bs) (DataSec(bs) / SPC(bs))952 953 949 void fat_mounted(ipc_callid_t rid, ipc_call_t *request) 954 950 { … … 956 952 enum cache_mode cmode; 957 953 fat_bs_t *bs; 958 954 959 955 /* Accept the mount options */ 960 956 char *opts; 961 957 int rc = async_data_write_accept((void **) &opts, true, 0, 0, 0, NULL); 962 958 963 959 if (rc != EOK) { 964 960 async_answer_0(rid, rc); … … 991 987 /* get the buffer with the boot sector */ 992 988 bs = block_bb_get(devmap_handle); 993 989 994 990 if (BPS(bs) != BS_SIZE) { 995 991 block_fini(devmap_handle); … … 1007 1003 1008 1004 /* Storing FAT type (12, 16, 32) in reserved field (bs->reserved) */ 1009 if (C ountOfClusters(bs) < 4085) {1005 if (CC(bs) < 4085) { 1010 1006 /* Volume is FAT12 */ 1011 1007 printf("Found FAT12 filesystem\n"); 1012 1008 (bs)->reserved = 12; 1013 } else if (C ountOfClusters(bs) < 65525) {1009 } else if (CC(bs) < 65525) { 1014 1010 /* Volume is FAT16 */ 1015 1011 printf("Found FAT16 filesystem\n"); … … 1017 1013 } else { 1018 1014 /* Volume is FAT32 */ 1019 printf("FAT32 is not supported by FAT driver. Sorry\n");1015 printf("FAT32 filesystem is not supported by FAT server. Sorry.\n"); 1020 1016 block_fini(devmap_handle); 1021 1017 async_answer_0(rid, ENOTSUP); … … 1085 1081 rootp->bp = rfn; 1086 1082 rfn->data = rootp; 1087 1083 1088 1084 fibril_mutex_unlock(&ridxp->lock); 1089 1085 … … 1119 1115 return; 1120 1116 } 1121 1117 1122 1118 /* 1123 1119 * Put the root node and force it to the FAT free node list. … … 1300 1296 int flags = BLOCK_FLAGS_NONE; 1301 1297 int rc; 1302 1298 1303 1299 rc = fat_node_get(&fn, devmap_handle, index); 1304 1300 if (rc != EOK) { … … 1311 1307 } 1312 1308 nodep = FAT_NODE(fn); 1313 1309 1314 1310 ipc_callid_t callid; 1315 1311 size_t len; … … 1328 1324 * but this one greatly simplifies fat_write(). Note that we can afford 1329 1325 * to do this because the client must be ready to handle the return 1330 * value signalizing a smaller number of bytes written. 1331 */ 1326 * value signalizing a smaller number of bytes written. 1327 */ 1332 1328 bytes = min(len, BPS(bs) - pos % BPS(bs)); 1333 1329 if (bytes == BPS(bs)) 1334 1330 flags |= BLOCK_FLAGS_NOREAD; 1335 1331 1336 1332 boundary = ROUND_UP(nodep->size, BPC(bs)); 1337 1333 if (pos < boundary) { … … 1379 1375 */ 1380 1376 unsigned nclsts; 1381 fat_cluster_t mcl, lcl; 1382 1377 fat_cluster_t mcl, lcl; 1378 1383 1379 nclsts = (ROUND_UP(pos + bytes, BPC(bs)) - boundary) / BPC(bs); 1384 1380 /* create an independent chain of nclsts clusters in all FATs */ … … 1476 1472 nodep->size = size; 1477 1473 nodep->dirty = true; /* need to sync node */ 1478 rc = EOK; 1474 rc = EOK; 1479 1475 } else { 1480 1476 /* … … 1497 1493 nodep->size = size; 1498 1494 nodep->dirty = true; /* need to sync node */ 1499 rc = EOK; 1495 rc = EOK; 1500 1496 } 1501 1497 out: … … 1553 1549 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1554 1550 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1555 1551 1556 1552 fs_node_t *fn; 1557 1553 int rc = fat_node_get(&fn, devmap_handle, index); … … 1564 1560 return; 1565 1561 } 1566 1562 1567 1563 fat_node_t *nodep = FAT_NODE(fn); 1568 1564 1569 1565 nodep->dirty = true; 1570 1566 rc = fat_node_sync(nodep); 1571 1567 1572 1568 fat_node_put(fn); 1573 1569 async_answer_0(rid, rc);
Note:
See TracChangeset
for help on using the changeset viewer.