Changeset 7a23d60 in mainline
- Timestamp:
- 2010-07-26T20:10:21Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6da81e0
- Parents:
- ed6cf34b
- Location:
- uspace/srv/fs/fat
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/fat/fat.h
red6cf34b r7a23d60 48 48 49 49 #define min(a, b) ((a) < (b) ? (a) : (b)) 50 51 /* 52 * Convenience macros for accessing some frequently used boot sector members. 53 */ 54 #define BPS(bs) uint16_t_le2host((bs)->bps) 55 #define SPC(bs) (bs)->spc 56 #define RSCNT(bs) uint16_t_le2host((bs)->rscnt) 57 #define FATCNT(bs) (bs)->fatcnt 58 #define SF(bs) uint16_t_le2host((bs)->sec_per_fat) 59 #define RDE(bs) uint16_t_le2host((bs)->root_ent_max) 60 #define TS(bs) (uint16_t_le2host((bs)->totsec16) != 0 ? \ 61 uint16_t_le2host((bs)->totsec16) : \ 62 uint32_t_le2host(bs->totsec32)) 50 63 51 64 #define BS_BLOCK 0 -
uspace/srv/fs/fat/fat_fat.c
red6cf34b r7a23d60 50 50 51 51 /* 52 * Convenience macros for accessing some frequently used boot sector members.53 */54 #define BPS(bs) uint16_t_le2host((bs)->bps)55 #define SPC(bs) (bs)->spc56 #define RSCNT(bs) uint16_t_le2host((bs)->rscnt)57 #define FATCNT(bs) (bs)->fatcnt58 #define SF(bs) uint16_t_le2host((bs)->sec_per_fat)59 #define RDE(bs) uint16_t_le2host((bs)->root_ent_max)60 #define TS(bs) (uint16_t_le2host((bs)->totsec16) != 0 ? \61 uint16_t_le2host((bs)->totsec16) : \62 uint32_t_le2host(bs->totsec32))63 64 /*65 52 * Convenience macros for computing some frequently used values from the 66 53 * primitive boot sector members. … … 72 59 #define CLBN2PBN(bs, cl, bn) \ 73 60 (SSA((bs)) + ((cl) - FAT_CLST_FIRST) * SPC((bs)) + (bn) % SPC((bs))) 74 75 61 76 62 /** -
uspace/srv/fs/fat/fat_ops.c
red6cf34b r7a23d60 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); … … 110 113 fat_bs_t *bs; 111 114 fat_dentry_t *d; 112 uint16_t bps;113 unsigned dps;114 115 int rc; 115 116 … … 117 118 118 119 bs = block_bb_get(node->idx->dev_handle); 119 bps = uint16_t_le2host(bs->bps);120 dps = bps / sizeof(fat_dentry_t);121 120 122 121 /* Read the block that contains the dentry of interest. */ 123 122 rc = _fat_block_get(&b, bs, node->idx->dev_handle, node->idx->pfc, 124 (node->idx->pdi * sizeof(fat_dentry_t)) / bps, BLOCK_FLAGS_NONE); 123 (node->idx->pdi * sizeof(fat_dentry_t)) / BPS(bs), 124 BLOCK_FLAGS_NONE); 125 125 if (rc != EOK) 126 126 return rc; 127 127 128 d = ((fat_dentry_t *)b->data) + (node->idx->pdi % dps);128 d = ((fat_dentry_t *)b->data) + (node->idx->pdi % DPS(bs)); 129 129 130 130 d->firstc = host2uint16_t_le(node->firstc); … … 268 268 fat_dentry_t *d; 269 269 fat_node_t *nodep = NULL; 270 unsigned bps;271 unsigned spc;272 unsigned dps;273 270 int rc; 274 271 … … 300 297 301 298 bs = block_bb_get(idxp->dev_handle); 302 bps = uint16_t_le2host(bs->bps);303 spc = bs->spc;304 dps = bps / sizeof(fat_dentry_t);305 299 306 300 /* Read the block that contains the dentry of interest. */ 307 301 rc = _fat_block_get(&b, bs, idxp->dev_handle, idxp->pfc, 308 (idxp->pdi * sizeof(fat_dentry_t)) / bps, BLOCK_FLAGS_NONE);302 (idxp->pdi * sizeof(fat_dentry_t)) / BPS(bs), BLOCK_FLAGS_NONE); 309 303 if (rc != EOK) { 310 304 (void) fat_node_put(FS_NODE(nodep)); … … 312 306 } 313 307 314 d = ((fat_dentry_t *)b->data) + (idxp->pdi % dps);308 d = ((fat_dentry_t *)b->data) + (idxp->pdi % DPS(bs)); 315 309 if (d->attr & FAT_ATTR_SUBDIR) { 316 310 /* … … 332 326 return rc; 333 327 } 334 nodep->size = bps * spc* clusters;328 nodep->size = BPS(bs) * SPC(bs) * clusters; 335 329 } else { 336 330 nodep->type = FAT_FILE; … … 370 364 char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1]; 371 365 unsigned i, j; 372 unsigned bps; /* bytes per sector */373 unsigned dps; /* dentries per sector */374 366 unsigned blocks; 375 367 fat_dentry_t *d; … … 379 371 fibril_mutex_lock(&parentp->idx->lock); 380 372 bs = block_bb_get(parentp->idx->dev_handle); 381 bps = uint16_t_le2host(bs->bps); 382 dps = bps / sizeof(fat_dentry_t); 383 blocks = parentp->size / bps; 373 blocks = parentp->size / BPS(bs); 384 374 for (i = 0; i < blocks; i++) { 385 375 rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE); … … 388 378 return rc; 389 379 } 390 for (j = 0; j < dps; j++) {380 for (j = 0; j < DPS(bs); j++) { 391 381 d = ((fat_dentry_t *)b->data) + j; 392 382 switch (fat_classify_dentry(d)) { … … 416 406 fat_idx_t *idx = fat_idx_get_by_pos( 417 407 parentp->idx->dev_handle, parentp->firstc, 418 i * dps+ j);408 i * DPS(bs) + j); 419 409 fibril_mutex_unlock(&parentp->idx->lock); 420 410 if (!idx) { … … 515 505 fat_bs_t *bs; 516 506 fat_cluster_t mcl, lcl; 517 uint16_t bps;518 507 int rc; 519 508 520 509 bs = block_bb_get(dev_handle); 521 bps = uint16_t_le2host(bs->bps);522 510 if (flags & L_DIRECTORY) { 523 511 /* allocate a cluster */ … … 548 536 nodep->type = FAT_DIRECTORY; 549 537 nodep->firstc = mcl; 550 nodep->size = bps * bs->spc;538 nodep->size = BPS(bs) * SPC(bs); 551 539 } else { 552 540 nodep->type = FAT_FILE; … … 611 599 block_t *b; 612 600 unsigned i, j; 613 uint16_t bps;614 unsigned dps;615 601 unsigned blocks; 616 602 fat_cluster_t mcl, lcl; … … 642 628 fibril_mutex_lock(&parentp->idx->lock); 643 629 bs = block_bb_get(parentp->idx->dev_handle); 644 bps = uint16_t_le2host(bs->bps); 645 dps = bps / sizeof(fat_dentry_t); 646 647 blocks = parentp->size / bps; 630 631 blocks = parentp->size / BPS(bs); 648 632 649 633 for (i = 0; i < blocks; i++) { … … 653 637 return rc; 654 638 } 655 for (j = 0; j < dps; j++) {639 for (j = 0; j < DPS(bs); j++) { 656 640 d = ((fat_dentry_t *)b->data) + j; 657 641 switch (fat_classify_dentry(d)) { … … 699 683 return rc; 700 684 } 701 parentp->size += bps * bs->spc;685 parentp->size += BPS(bs) * SPC(bs); 702 686 parentp->dirty = true; /* need to sync node */ 703 687 rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE); … … 773 757 774 758 childp->idx->pfc = parentp->firstc; 775 childp->idx->pdi = i * dps+ j;759 childp->idx->pdi = i * DPS(bs) + j; 776 760 fibril_mutex_unlock(&childp->idx->lock); 777 761 … … 795 779 fat_bs_t *bs; 796 780 fat_dentry_t *d; 797 uint16_t bps;798 781 block_t *b; 799 782 bool has_children; … … 814 797 fibril_mutex_lock(&childp->idx->lock); 815 798 bs = block_bb_get(childp->idx->dev_handle); 816 bps = uint16_t_le2host(bs->bps);817 799 818 800 rc = _fat_block_get(&b, bs, childp->idx->dev_handle, childp->idx->pfc, 819 (childp->idx->pdi * sizeof(fat_dentry_t)) / bps,801 (childp->idx->pdi * sizeof(fat_dentry_t)) / BPS(bs), 820 802 BLOCK_FLAGS_NONE); 821 803 if (rc != EOK) 822 804 goto error; 823 805 d = (fat_dentry_t *)b->data + 824 (childp->idx->pdi % ( bps/ sizeof(fat_dentry_t)));806 (childp->idx->pdi % (BPS(bs) / sizeof(fat_dentry_t))); 825 807 /* mark the dentry as not-currently-used */ 826 808 d->name[0] = FAT_DENTRY_ERASED; … … 854 836 fat_bs_t *bs; 855 837 fat_node_t *nodep = FAT_NODE(fn); 856 unsigned bps;857 unsigned dps;858 838 unsigned blocks; 859 839 block_t *b; … … 868 848 fibril_mutex_lock(&nodep->idx->lock); 869 849 bs = block_bb_get(nodep->idx->dev_handle); 870 bps = uint16_t_le2host(bs->bps); 871 dps = bps / sizeof(fat_dentry_t); 872 873 blocks = nodep->size / bps; 850 851 blocks = nodep->size / BPS(bs); 874 852 875 853 for (i = 0; i < blocks; i++) { … … 881 859 return rc; 882 860 } 883 for (j = 0; j < dps; j++) {861 for (j = 0; j < DPS(bs); j++) { 884 862 d = ((fat_dentry_t *)b->data) + j; 885 863 switch (fat_classify_dentry(d)) { … … 978 956 enum cache_mode cmode; 979 957 fat_bs_t *bs; 980 uint16_t bps;981 uint16_t rde;982 958 983 959 /* Accept the mount options */ … … 1016 992 bs = block_bb_get(dev_handle); 1017 993 1018 /* Read the number of root directory entries. */ 1019 bps = uint16_t_le2host(bs->bps); 1020 rde = uint16_t_le2host(bs->root_ent_max); 1021 1022 if (bps != BS_SIZE) { 994 if (BPS(bs) != BS_SIZE) { 1023 995 block_fini(dev_handle); 1024 996 ipc_answer_0(rid, ENOTSUP); … … 1027 999 1028 1000 /* Initialize the block cache */ 1029 rc = block_cache_init(dev_handle, bps, 0 /* XXX */, cmode);1001 rc = block_cache_init(dev_handle, BPS(bs), 0 /* XXX */, cmode); 1030 1002 if (rc != EOK) { 1031 1003 block_fini(dev_handle); … … 1089 1061 rootp->refcnt = 1; 1090 1062 rootp->lnkcnt = 0; /* FS root is not linked */ 1091 rootp->size = rde* sizeof(fat_dentry_t);1063 rootp->size = RDE(bs) * sizeof(fat_dentry_t); 1092 1064 rootp->idx = ridxp; 1093 1065 ridxp->nodep = rootp; … … 1167 1139 fat_node_t *nodep; 1168 1140 fat_bs_t *bs; 1169 uint16_t bps;1170 1141 size_t bytes; 1171 1142 block_t *b; … … 1193 1164 1194 1165 bs = block_bb_get(dev_handle); 1195 bps = uint16_t_le2host(bs->bps);1196 1166 1197 1167 if (nodep->type == FAT_FILE) { … … 1206 1176 (void) async_data_read_finalize(callid, NULL, 0); 1207 1177 } else { 1208 bytes = min(len, bps - pos % bps);1178 bytes = min(len, BPS(bs) - pos % BPS(bs)); 1209 1179 bytes = min(bytes, nodep->size - pos); 1210 rc = fat_block_get(&b, bs, nodep, pos / bps,1180 rc = fat_block_get(&b, bs, nodep, pos / BPS(bs), 1211 1181 BLOCK_FLAGS_NONE); 1212 1182 if (rc != EOK) { … … 1216 1186 return; 1217 1187 } 1218 (void) async_data_read_finalize(callid, b->data + pos % bps,1219 b ytes);1188 (void) async_data_read_finalize(callid, 1189 b->data + pos % BPS(bs), bytes); 1220 1190 rc = block_put(b); 1221 1191 if (rc != EOK) { … … 1232 1202 1233 1203 assert(nodep->type == FAT_DIRECTORY); 1234 assert(nodep->size % bps== 0);1235 assert( bps% sizeof(fat_dentry_t) == 0);1204 assert(nodep->size % BPS(bs) == 0); 1205 assert(BPS(bs) % sizeof(fat_dentry_t) == 0); 1236 1206 1237 1207 /* … … 1241 1211 * the position pointer accordingly. 1242 1212 */ 1243 bnum = (pos * sizeof(fat_dentry_t)) / bps;1244 while (bnum < nodep->size / bps) {1213 bnum = (pos * sizeof(fat_dentry_t)) / BPS(bs); 1214 while (bnum < nodep->size / BPS(bs)) { 1245 1215 aoff64_t o; 1246 1216 … … 1249 1219 if (rc != EOK) 1250 1220 goto err; 1251 for (o = pos % ( bps/ sizeof(fat_dentry_t));1252 o < bps/ sizeof(fat_dentry_t);1221 for (o = pos % (BPS(bs) / sizeof(fat_dentry_t)); 1222 o < BPS(bs) / sizeof(fat_dentry_t); 1253 1223 o++, pos++) { 1254 1224 d = ((fat_dentry_t *)b->data) + o; … … 1308 1278 size_t bytes, size; 1309 1279 block_t *b; 1310 uint16_t bps;1311 unsigned spc;1312 unsigned bpc; /* bytes per cluster */1313 1280 aoff64_t boundary; 1314 1281 int flags = BLOCK_FLAGS_NONE; … … 1336 1303 1337 1304 bs = block_bb_get(dev_handle); 1338 bps = uint16_t_le2host(bs->bps);1339 spc = bs->spc;1340 bpc = bps * spc;1341 1305 1342 1306 /* … … 1347 1311 * value signalizing a smaller number of bytes written. 1348 1312 */ 1349 bytes = min(len, bps - pos % bps);1350 if (bytes == bps)1313 bytes = min(len, BPS(bs) - pos % BPS(bs)); 1314 if (bytes == BPS(bs)) 1351 1315 flags |= BLOCK_FLAGS_NOREAD; 1352 1316 1353 boundary = ROUND_UP(nodep->size, bpc);1317 boundary = ROUND_UP(nodep->size, BPC(bs)); 1354 1318 if (pos < boundary) { 1355 1319 /* … … 1366 1330 return; 1367 1331 } 1368 rc = fat_block_get(&b, bs, nodep, pos / bps, flags);1332 rc = fat_block_get(&b, bs, nodep, pos / BPS(bs), flags); 1369 1333 if (rc != EOK) { 1370 1334 (void) fat_node_put(fn); … … 1373 1337 return; 1374 1338 } 1375 (void) async_data_write_finalize(callid, b->data + pos % bps,1376 b ytes);1339 (void) async_data_write_finalize(callid, 1340 b->data + pos % BPS(bs), bytes); 1377 1341 b->dirty = true; /* need to sync block */ 1378 1342 rc = block_put(b); … … 1398 1362 fat_cluster_t mcl, lcl; 1399 1363 1400 nclsts = (ROUND_UP(pos + bytes, bpc) - boundary) / bpc;1364 nclsts = (ROUND_UP(pos + bytes, BPC(bs)) - boundary) / BPC(bs); 1401 1365 /* create an independent chain of nclsts clusters in all FATs */ 1402 1366 rc = fat_alloc_clusters(bs, dev_handle, nclsts, &mcl, &lcl); … … 1417 1381 return; 1418 1382 } 1419 rc = _fat_block_get(&b, bs, dev_handle, lcl, (pos / bps) % spc,1420 flags);1383 rc = _fat_block_get(&b, bs, dev_handle, lcl, 1384 (pos / BPS(bs)) % SPC(bs), flags); 1421 1385 if (rc != EOK) { 1422 1386 (void) fat_free_clusters(bs, dev_handle, mcl); … … 1426 1390 return; 1427 1391 } 1428 (void) async_data_write_finalize(callid, b->data + pos % bps,1429 b ytes);1392 (void) async_data_write_finalize(callid, 1393 b->data + pos % BPS(bs), bytes); 1430 1394 b->dirty = true; /* need to sync block */ 1431 1395 rc = block_put(b); … … 1464 1428 fat_node_t *nodep; 1465 1429 fat_bs_t *bs; 1466 uint16_t bps;1467 uint8_t spc;1468 unsigned bpc; /* bytes per cluster */1469 1430 int rc; 1470 1431 … … 1481 1442 1482 1443 bs = block_bb_get(dev_handle); 1483 bps = uint16_t_le2host(bs->bps);1484 spc = bs->spc;1485 bpc = bps * spc;1486 1444 1487 1445 if (nodep->size == size) { … … 1493 1451 */ 1494 1452 rc = EINVAL; 1495 } else if (ROUND_UP(nodep->size, bpc) == ROUND_UP(size, bpc)) {1453 } else if (ROUND_UP(nodep->size, BPC(bs)) == ROUND_UP(size, BPC(bs))) { 1496 1454 /* 1497 1455 * The node will be shrunk, but no clusters will be deallocated. … … 1511 1469 fat_cluster_t lastc; 1512 1470 rc = fat_cluster_walk(bs, dev_handle, nodep->firstc, 1513 &lastc, NULL, (size - 1) / bpc);1471 &lastc, NULL, (size - 1) / BPC(bs)); 1514 1472 if (rc != EOK) 1515 1473 goto out;
Note:
See TracChangeset
for help on using the changeset viewer.