Changeset 20235a3 in mainline for uspace/srv/fs/fat/fat_ops.c
- Timestamp:
- 2010-09-02T20:55:28Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0c39b96
- Parents:
- 0c61955 (diff), 3249673 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat_ops.c
r0c61955 r20235a3 60 60 #define FS_NODE(node) ((node) ? (node)->bp : NULL) 61 61 62 #define DPS(bs) (BPS((bs)) / sizeof(fat_dentry_t)) 63 #define BPC(bs) (BPS((bs)) * SPC((bs))) 64 62 65 /** Mutex protecting the list of cached free FAT nodes. */ 63 66 static FIBRIL_MUTEX_INITIALIZE(ffn_mutex); … … 101 104 node->refcnt = 0; 102 105 node->dirty = false; 106 node->lastc_cached_valid = false; 107 node->lastc_cached_value = FAT_CLST_LAST1; 108 node->currc_cached_valid = false; 109 node->currc_cached_bn = 0; 110 node->currc_cached_value = FAT_CLST_LAST1; 103 111 } 104 112 … … 108 116 fat_bs_t *bs; 109 117 fat_dentry_t *d; 110 uint16_t bps;111 unsigned dps;112 118 int rc; 113 119 … … 115 121 116 122 bs = block_bb_get(node->idx->dev_handle); 117 bps = uint16_t_le2host(bs->bps);118 dps = bps / sizeof(fat_dentry_t);119 123 120 124 /* Read the block that contains the dentry of interest. */ 121 125 rc = _fat_block_get(&b, bs, node->idx->dev_handle, node->idx->pfc, 122 (node->idx->pdi * sizeof(fat_dentry_t)) / bps, BLOCK_FLAGS_NONE); 126 NULL, (node->idx->pdi * sizeof(fat_dentry_t)) / BPS(bs), 127 BLOCK_FLAGS_NONE); 123 128 if (rc != EOK) 124 129 return rc; 125 130 126 d = ((fat_dentry_t *)b->data) + (node->idx->pdi % dps);131 d = ((fat_dentry_t *)b->data) + (node->idx->pdi % DPS(bs)); 127 132 128 133 d->firstc = host2uint16_t_le(node->firstc); … … 266 271 fat_dentry_t *d; 267 272 fat_node_t *nodep = NULL; 268 unsigned bps;269 unsigned spc;270 unsigned dps;271 273 int rc; 272 274 … … 298 300 299 301 bs = block_bb_get(idxp->dev_handle); 300 bps = uint16_t_le2host(bs->bps);301 spc = bs->spc;302 dps = bps / sizeof(fat_dentry_t);303 302 304 303 /* Read the block that contains the dentry of interest. */ 305 rc = _fat_block_get(&b, bs, idxp->dev_handle, idxp->pfc, 306 (idxp->pdi * sizeof(fat_dentry_t)) / bps, BLOCK_FLAGS_NONE);304 rc = _fat_block_get(&b, bs, idxp->dev_handle, idxp->pfc, NULL, 305 (idxp->pdi * sizeof(fat_dentry_t)) / BPS(bs), BLOCK_FLAGS_NONE); 307 306 if (rc != EOK) { 308 307 (void) fat_node_put(FS_NODE(nodep)); … … 310 309 } 311 310 312 d = ((fat_dentry_t *)b->data) + (idxp->pdi % dps);311 d = ((fat_dentry_t *)b->data) + (idxp->pdi % DPS(bs)); 313 312 if (d->attr & FAT_ATTR_SUBDIR) { 314 313 /* … … 330 329 return rc; 331 330 } 332 nodep->size = bps * spc* clusters;331 nodep->size = BPS(bs) * SPC(bs) * clusters; 333 332 } else { 334 333 nodep->type = FAT_FILE; … … 368 367 char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1]; 369 368 unsigned i, j; 370 unsigned bps; /* bytes per sector */371 unsigned dps; /* dentries per sector */372 369 unsigned blocks; 373 370 fat_dentry_t *d; … … 377 374 fibril_mutex_lock(&parentp->idx->lock); 378 375 bs = block_bb_get(parentp->idx->dev_handle); 379 bps = uint16_t_le2host(bs->bps); 380 dps = bps / sizeof(fat_dentry_t); 381 blocks = parentp->size / bps; 376 blocks = parentp->size / BPS(bs); 382 377 for (i = 0; i < blocks; i++) { 383 378 rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE); … … 386 381 return rc; 387 382 } 388 for (j = 0; j < dps; j++) {383 for (j = 0; j < DPS(bs); j++) { 389 384 d = ((fat_dentry_t *)b->data) + j; 390 385 switch (fat_classify_dentry(d)) { … … 414 409 fat_idx_t *idx = fat_idx_get_by_pos( 415 410 parentp->idx->dev_handle, parentp->firstc, 416 i * dps+ j);411 i * DPS(bs) + j); 417 412 fibril_mutex_unlock(&parentp->idx->lock); 418 413 if (!idx) { … … 513 508 fat_bs_t *bs; 514 509 fat_cluster_t mcl, lcl; 515 uint16_t bps;516 510 int rc; 517 511 518 512 bs = block_bb_get(dev_handle); 519 bps = uint16_t_le2host(bs->bps);520 513 if (flags & L_DIRECTORY) { 521 514 /* allocate a cluster */ … … 546 539 nodep->type = FAT_DIRECTORY; 547 540 nodep->firstc = mcl; 548 nodep->size = bps * bs->spc;541 nodep->size = BPS(bs) * SPC(bs); 549 542 } else { 550 543 nodep->type = FAT_FILE; … … 609 602 block_t *b; 610 603 unsigned i, j; 611 uint16_t bps;612 unsigned dps;613 604 unsigned blocks; 614 605 fat_cluster_t mcl, lcl; … … 640 631 fibril_mutex_lock(&parentp->idx->lock); 641 632 bs = block_bb_get(parentp->idx->dev_handle); 642 bps = uint16_t_le2host(bs->bps); 643 dps = bps / sizeof(fat_dentry_t); 644 645 blocks = parentp->size / bps; 633 634 blocks = parentp->size / BPS(bs); 646 635 647 636 for (i = 0; i < blocks; i++) { … … 651 640 return rc; 652 641 } 653 for (j = 0; j < dps; j++) {642 for (j = 0; j < DPS(bs); j++) { 654 643 d = ((fat_dentry_t *)b->data) + j; 655 644 switch (fat_classify_dentry(d)) { … … 691 680 return rc; 692 681 } 693 rc = fat_append_clusters(bs, parentp, mcl );682 rc = fat_append_clusters(bs, parentp, mcl, lcl); 694 683 if (rc != EOK) { 695 684 (void) fat_free_clusters(bs, parentp->idx->dev_handle, mcl); … … 697 686 return rc; 698 687 } 699 parentp->size += bps * bs->spc;688 parentp->size += BPS(bs) * SPC(bs); 700 689 parentp->dirty = true; /* need to sync node */ 701 690 rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE); … … 771 760 772 761 childp->idx->pfc = parentp->firstc; 773 childp->idx->pdi = i * dps+ j;762 childp->idx->pdi = i * DPS(bs) + j; 774 763 fibril_mutex_unlock(&childp->idx->lock); 775 764 … … 793 782 fat_bs_t *bs; 794 783 fat_dentry_t *d; 795 uint16_t bps;796 784 block_t *b; 797 785 bool has_children; … … 812 800 fibril_mutex_lock(&childp->idx->lock); 813 801 bs = block_bb_get(childp->idx->dev_handle); 814 bps = uint16_t_le2host(bs->bps);815 802 816 803 rc = _fat_block_get(&b, bs, childp->idx->dev_handle, childp->idx->pfc, 817 (childp->idx->pdi * sizeof(fat_dentry_t)) / bps,804 NULL, (childp->idx->pdi * sizeof(fat_dentry_t)) / BPS(bs), 818 805 BLOCK_FLAGS_NONE); 819 806 if (rc != EOK) 820 807 goto error; 821 808 d = (fat_dentry_t *)b->data + 822 (childp->idx->pdi % ( bps/ sizeof(fat_dentry_t)));809 (childp->idx->pdi % (BPS(bs) / sizeof(fat_dentry_t))); 823 810 /* mark the dentry as not-currently-used */ 824 811 d->name[0] = FAT_DENTRY_ERASED; … … 852 839 fat_bs_t *bs; 853 840 fat_node_t *nodep = FAT_NODE(fn); 854 unsigned bps;855 unsigned dps;856 841 unsigned blocks; 857 842 block_t *b; … … 866 851 fibril_mutex_lock(&nodep->idx->lock); 867 852 bs = block_bb_get(nodep->idx->dev_handle); 868 bps = uint16_t_le2host(bs->bps); 869 dps = bps / sizeof(fat_dentry_t); 870 871 blocks = nodep->size / bps; 853 854 blocks = nodep->size / BPS(bs); 872 855 873 856 for (i = 0; i < blocks; i++) { … … 879 862 return rc; 880 863 } 881 for (j = 0; j < dps; j++) {864 for (j = 0; j < DPS(bs); j++) { 882 865 d = ((fat_dentry_t *)b->data) + j; 883 866 switch (fat_classify_dentry(d)) { … … 976 959 enum cache_mode cmode; 977 960 fat_bs_t *bs; 978 uint16_t bps;979 uint16_t rde;980 961 981 962 /* Accept the mount options */ … … 1014 995 bs = block_bb_get(dev_handle); 1015 996 1016 /* Read the number of root directory entries. */ 1017 bps = uint16_t_le2host(bs->bps); 1018 rde = uint16_t_le2host(bs->root_ent_max); 1019 1020 if (bps != BS_SIZE) { 997 if (BPS(bs) != BS_SIZE) { 1021 998 block_fini(dev_handle); 1022 999 ipc_answer_0(rid, ENOTSUP); … … 1025 1002 1026 1003 /* Initialize the block cache */ 1027 rc = block_cache_init(dev_handle, bps, 0 /* XXX */, cmode);1004 rc = block_cache_init(dev_handle, BPS(bs), 0 /* XXX */, cmode); 1028 1005 if (rc != EOK) { 1029 1006 block_fini(dev_handle); … … 1087 1064 rootp->refcnt = 1; 1088 1065 rootp->lnkcnt = 0; /* FS root is not linked */ 1089 rootp->size = rde* sizeof(fat_dentry_t);1066 rootp->size = RDE(bs) * sizeof(fat_dentry_t); 1090 1067 rootp->idx = ridxp; 1091 1068 ridxp->nodep = rootp; … … 1165 1142 fat_node_t *nodep; 1166 1143 fat_bs_t *bs; 1167 uint16_t bps;1168 1144 size_t bytes; 1169 1145 block_t *b; … … 1191 1167 1192 1168 bs = block_bb_get(dev_handle); 1193 bps = uint16_t_le2host(bs->bps);1194 1169 1195 1170 if (nodep->type == FAT_FILE) { … … 1204 1179 (void) async_data_read_finalize(callid, NULL, 0); 1205 1180 } else { 1206 bytes = min(len, bps - pos % bps);1181 bytes = min(len, BPS(bs) - pos % BPS(bs)); 1207 1182 bytes = min(bytes, nodep->size - pos); 1208 rc = fat_block_get(&b, bs, nodep, pos / bps,1183 rc = fat_block_get(&b, bs, nodep, pos / BPS(bs), 1209 1184 BLOCK_FLAGS_NONE); 1210 1185 if (rc != EOK) { … … 1214 1189 return; 1215 1190 } 1216 (void) async_data_read_finalize(callid, b->data + pos % bps,1217 b ytes);1191 (void) async_data_read_finalize(callid, 1192 b->data + pos % BPS(bs), bytes); 1218 1193 rc = block_put(b); 1219 1194 if (rc != EOK) { … … 1230 1205 1231 1206 assert(nodep->type == FAT_DIRECTORY); 1232 assert(nodep->size % bps== 0);1233 assert( bps% sizeof(fat_dentry_t) == 0);1207 assert(nodep->size % BPS(bs) == 0); 1208 assert(BPS(bs) % sizeof(fat_dentry_t) == 0); 1234 1209 1235 1210 /* … … 1239 1214 * the position pointer accordingly. 1240 1215 */ 1241 bnum = (pos * sizeof(fat_dentry_t)) / bps;1242 while (bnum < nodep->size / bps) {1216 bnum = (pos * sizeof(fat_dentry_t)) / BPS(bs); 1217 while (bnum < nodep->size / BPS(bs)) { 1243 1218 aoff64_t o; 1244 1219 … … 1247 1222 if (rc != EOK) 1248 1223 goto err; 1249 for (o = pos % ( bps/ sizeof(fat_dentry_t));1250 o < bps/ sizeof(fat_dentry_t);1224 for (o = pos % (BPS(bs) / sizeof(fat_dentry_t)); 1225 o < BPS(bs) / sizeof(fat_dentry_t); 1251 1226 o++, pos++) { 1252 1227 d = ((fat_dentry_t *)b->data) + o; … … 1306 1281 size_t bytes, size; 1307 1282 block_t *b; 1308 uint16_t bps;1309 unsigned spc;1310 unsigned bpc; /* bytes per cluster */1311 1283 aoff64_t boundary; 1312 1284 int flags = BLOCK_FLAGS_NONE; … … 1334 1306 1335 1307 bs = block_bb_get(dev_handle); 1336 bps = uint16_t_le2host(bs->bps);1337 spc = bs->spc;1338 bpc = bps * spc;1339 1308 1340 1309 /* … … 1345 1314 * value signalizing a smaller number of bytes written. 1346 1315 */ 1347 bytes = min(len, bps - pos % bps);1348 if (bytes == bps)1316 bytes = min(len, BPS(bs) - pos % BPS(bs)); 1317 if (bytes == BPS(bs)) 1349 1318 flags |= BLOCK_FLAGS_NOREAD; 1350 1319 1351 boundary = ROUND_UP(nodep->size, bpc);1320 boundary = ROUND_UP(nodep->size, BPC(bs)); 1352 1321 if (pos < boundary) { 1353 1322 /* … … 1364 1333 return; 1365 1334 } 1366 rc = fat_block_get(&b, bs, nodep, pos / bps, flags);1335 rc = fat_block_get(&b, bs, nodep, pos / BPS(bs), flags); 1367 1336 if (rc != EOK) { 1368 1337 (void) fat_node_put(fn); … … 1371 1340 return; 1372 1341 } 1373 (void) async_data_write_finalize(callid, b->data + pos % bps,1374 b ytes);1342 (void) async_data_write_finalize(callid, 1343 b->data + pos % BPS(bs), bytes); 1375 1344 b->dirty = true; /* need to sync block */ 1376 1345 rc = block_put(b); … … 1396 1365 fat_cluster_t mcl, lcl; 1397 1366 1398 nclsts = (ROUND_UP(pos + bytes, bpc) - boundary) / bpc;1367 nclsts = (ROUND_UP(pos + bytes, BPC(bs)) - boundary) / BPC(bs); 1399 1368 /* create an independent chain of nclsts clusters in all FATs */ 1400 1369 rc = fat_alloc_clusters(bs, dev_handle, nclsts, &mcl, &lcl); … … 1415 1384 return; 1416 1385 } 1417 rc = _fat_block_get(&b, bs, dev_handle, lcl, (pos / bps) % spc,1418 flags);1386 rc = _fat_block_get(&b, bs, dev_handle, lcl, NULL, 1387 (pos / BPS(bs)) % SPC(bs), flags); 1419 1388 if (rc != EOK) { 1420 1389 (void) fat_free_clusters(bs, dev_handle, mcl); … … 1424 1393 return; 1425 1394 } 1426 (void) async_data_write_finalize(callid, b->data + pos % bps,1427 b ytes);1395 (void) async_data_write_finalize(callid, 1396 b->data + pos % BPS(bs), bytes); 1428 1397 b->dirty = true; /* need to sync block */ 1429 1398 rc = block_put(b); … … 1438 1407 * node's cluster chain. 1439 1408 */ 1440 rc = fat_append_clusters(bs, nodep, mcl );1409 rc = fat_append_clusters(bs, nodep, mcl, lcl); 1441 1410 if (rc != EOK) { 1442 1411 (void) fat_free_clusters(bs, dev_handle, mcl); … … 1462 1431 fat_node_t *nodep; 1463 1432 fat_bs_t *bs; 1464 uint16_t bps;1465 uint8_t spc;1466 unsigned bpc; /* bytes per cluster */1467 1433 int rc; 1468 1434 … … 1479 1445 1480 1446 bs = block_bb_get(dev_handle); 1481 bps = uint16_t_le2host(bs->bps);1482 spc = bs->spc;1483 bpc = bps * spc;1484 1447 1485 1448 if (nodep->size == size) { … … 1491 1454 */ 1492 1455 rc = EINVAL; 1493 } else if (ROUND_UP(nodep->size, bpc) == ROUND_UP(size, bpc)) {1456 } else if (ROUND_UP(nodep->size, BPC(bs)) == ROUND_UP(size, BPC(bs))) { 1494 1457 /* 1495 1458 * The node will be shrunk, but no clusters will be deallocated. … … 1509 1472 fat_cluster_t lastc; 1510 1473 rc = fat_cluster_walk(bs, dev_handle, nodep->firstc, 1511 &lastc, NULL, (size - 1) / bpc);1474 &lastc, NULL, (size - 1) / BPC(bs)); 1512 1475 if (rc != EOK) 1513 1476 goto out; … … 1564 1527 void fat_sync(ipc_callid_t rid, ipc_call_t *request) 1565 1528 { 1566 /* Dummy implementation */ 1567 ipc_answer_0(rid, EOK); 1529 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 1530 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1531 1532 fs_node_t *fn; 1533 int rc = fat_node_get(&fn, dev_handle, index); 1534 if (rc != EOK) { 1535 ipc_answer_0(rid, rc); 1536 return; 1537 } 1538 if (!fn) { 1539 ipc_answer_0(rid, ENOENT); 1540 return; 1541 } 1542 1543 fat_node_t *nodep = FAT_NODE(fn); 1544 1545 nodep->dirty = true; 1546 rc = fat_node_sync(nodep); 1547 1548 fat_node_put(fn); 1549 ipc_answer_0(rid, rc); 1568 1550 } 1569 1551
Note:
See TracChangeset
for help on using the changeset viewer.