Changeset 3f0a7971 in mainline for uspace/srv/fs/fat/fat_ops.c
- Timestamp:
- 2010-11-18T22:34:23Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 63b4f90
- Parents:
- c7137738 (diff), 45f04f8 (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
rc7137738 r3f0a7971 72 72 * Forward declarations of FAT libfs operations. 73 73 */ 74 static int fat_root_get(fs_node_t **, dev _handle_t);74 static int fat_root_get(fs_node_t **, devmap_handle_t); 75 75 static int fat_match(fs_node_t **, fs_node_t *, const char *); 76 static int fat_node_get(fs_node_t **, dev _handle_t, fs_index_t);76 static int fat_node_get(fs_node_t **, devmap_handle_t, fs_index_t); 77 77 static int fat_node_open(fs_node_t *); 78 78 static int fat_node_put(fs_node_t *); 79 static int fat_create_node(fs_node_t **, dev _handle_t, int);79 static int fat_create_node(fs_node_t **, devmap_handle_t, int); 80 80 static int fat_destroy_node(fs_node_t *); 81 81 static int fat_link(fs_node_t *, fs_node_t *, const char *); … … 88 88 static bool fat_is_directory(fs_node_t *); 89 89 static bool fat_is_file(fs_node_t *node); 90 static dev _handle_t fat_device_get(fs_node_t *node);90 static devmap_handle_t fat_device_get(fs_node_t *node); 91 91 92 92 /* … … 120 120 assert(node->dirty); 121 121 122 bs = block_bb_get(node->idx->dev _handle);122 bs = block_bb_get(node->idx->devmap_handle); 123 123 124 124 /* Read the block that contains the dentry of interest. */ 125 rc = _fat_block_get(&b, bs, node->idx->dev _handle, node->idx->pfc,125 rc = _fat_block_get(&b, bs, node->idx->devmap_handle, node->idx->pfc, 126 126 NULL, (node->idx->pdi * sizeof(fat_dentry_t)) / BPS(bs), 127 127 BLOCK_FLAGS_NONE); … … 145 145 } 146 146 147 static int fat_node_fini_by_dev _handle(dev_handle_t dev_handle)147 static int fat_node_fini_by_devmap_handle(devmap_handle_t devmap_handle) 148 148 { 149 149 link_t *lnk; … … 170 170 goto restart; 171 171 } 172 if (nodep->idx->dev _handle != dev_handle) {172 if (nodep->idx->devmap_handle != devmap_handle) { 173 173 fibril_mutex_unlock(&nodep->idx->lock); 174 174 fibril_mutex_unlock(&nodep->lock); … … 299 299 return rc; 300 300 301 bs = block_bb_get(idxp->dev _handle);301 bs = block_bb_get(idxp->devmap_handle); 302 302 303 303 /* Read the block that contains the dentry of interest. */ 304 rc = _fat_block_get(&b, bs, idxp->dev _handle, idxp->pfc, NULL,304 rc = _fat_block_get(&b, bs, idxp->devmap_handle, idxp->pfc, NULL, 305 305 (idxp->pdi * sizeof(fat_dentry_t)) / BPS(bs), BLOCK_FLAGS_NONE); 306 306 if (rc != EOK) { … … 323 323 */ 324 324 uint16_t clusters; 325 rc = fat_clusters_get(&clusters, bs, idxp->dev _handle,325 rc = fat_clusters_get(&clusters, bs, idxp->devmap_handle, 326 326 uint16_t_le2host(d->firstc)); 327 327 if (rc != EOK) { … … 356 356 */ 357 357 358 int fat_root_get(fs_node_t **rfn, dev _handle_t dev_handle)359 { 360 return fat_node_get(rfn, dev _handle, 0);358 int fat_root_get(fs_node_t **rfn, devmap_handle_t devmap_handle) 359 { 360 return fat_node_get(rfn, devmap_handle, 0); 361 361 } 362 362 … … 369 369 unsigned blocks; 370 370 fat_dentry_t *d; 371 dev _handle_t dev_handle;371 devmap_handle_t devmap_handle; 372 372 block_t *b; 373 373 int rc; 374 374 375 375 fibril_mutex_lock(&parentp->idx->lock); 376 dev _handle = parentp->idx->dev_handle;376 devmap_handle = parentp->idx->devmap_handle; 377 377 fibril_mutex_unlock(&parentp->idx->lock); 378 378 379 bs = block_bb_get(dev _handle);379 bs = block_bb_get(devmap_handle); 380 380 blocks = parentp->size / BPS(bs); 381 381 for (i = 0; i < blocks; i++) { … … 402 402 /* hit */ 403 403 fat_node_t *nodep; 404 fat_idx_t *idx = fat_idx_get_by_pos(dev _handle,404 fat_idx_t *idx = fat_idx_get_by_pos(devmap_handle, 405 405 parentp->firstc, i * DPS(bs) + j); 406 406 if (!idx) { … … 435 435 436 436 /** Instantiate a FAT in-core node. */ 437 int fat_node_get(fs_node_t **rfn, dev _handle_t dev_handle, fs_index_t index)437 int fat_node_get(fs_node_t **rfn, devmap_handle_t devmap_handle, fs_index_t index) 438 438 { 439 439 fat_node_t *nodep; … … 441 441 int rc; 442 442 443 idxp = fat_idx_get_by_index(dev _handle, index);443 idxp = fat_idx_get_by_index(devmap_handle, index); 444 444 if (!idxp) { 445 445 *rfn = NULL; … … 492 492 } 493 493 494 int fat_create_node(fs_node_t **rfn, dev _handle_t dev_handle, int flags)494 int fat_create_node(fs_node_t **rfn, devmap_handle_t devmap_handle, int flags) 495 495 { 496 496 fat_idx_t *idxp; … … 500 500 int rc; 501 501 502 bs = block_bb_get(dev _handle);502 bs = block_bb_get(devmap_handle); 503 503 if (flags & L_DIRECTORY) { 504 504 /* allocate a cluster */ 505 rc = fat_alloc_clusters(bs, dev _handle, 1, &mcl, &lcl);505 rc = fat_alloc_clusters(bs, devmap_handle, 1, &mcl, &lcl); 506 506 if (rc != EOK) 507 507 return rc; 508 508 /* populate the new cluster with unused dentries */ 509 rc = fat_zero_cluster(bs, dev _handle, mcl);509 rc = fat_zero_cluster(bs, devmap_handle, mcl); 510 510 if (rc != EOK) { 511 (void) fat_free_clusters(bs, dev _handle, mcl);511 (void) fat_free_clusters(bs, devmap_handle, mcl); 512 512 return rc; 513 513 } … … 516 516 rc = fat_node_get_new(&nodep); 517 517 if (rc != EOK) { 518 (void) fat_free_clusters(bs, dev _handle, mcl);518 (void) fat_free_clusters(bs, devmap_handle, mcl); 519 519 return rc; 520 520 } 521 rc = fat_idx_get_new(&idxp, dev _handle);522 if (rc != EOK) { 523 (void) fat_free_clusters(bs, dev _handle, mcl);521 rc = fat_idx_get_new(&idxp, devmap_handle); 522 if (rc != EOK) { 523 (void) fat_free_clusters(bs, devmap_handle, mcl); 524 524 (void) fat_node_put(FS_NODE(nodep)); 525 525 return rc; … … 570 570 assert(!has_children); 571 571 572 bs = block_bb_get(nodep->idx->dev _handle);572 bs = block_bb_get(nodep->idx->devmap_handle); 573 573 if (nodep->firstc != FAT_CLST_RES0) { 574 574 assert(nodep->size); 575 575 /* Free all clusters allocated to the node. */ 576 rc = fat_free_clusters(bs, nodep->idx->dev _handle,576 rc = fat_free_clusters(bs, nodep->idx->devmap_handle, 577 577 nodep->firstc); 578 578 } … … 620 620 621 621 fibril_mutex_lock(&parentp->idx->lock); 622 bs = block_bb_get(parentp->idx->dev _handle);622 bs = block_bb_get(parentp->idx->devmap_handle); 623 623 624 624 blocks = parentp->size / BPS(bs); … … 659 659 return ENOSPC; 660 660 } 661 rc = fat_alloc_clusters(bs, parentp->idx->dev _handle, 1, &mcl, &lcl);661 rc = fat_alloc_clusters(bs, parentp->idx->devmap_handle, 1, &mcl, &lcl); 662 662 if (rc != EOK) { 663 663 fibril_mutex_unlock(&parentp->idx->lock); 664 664 return rc; 665 665 } 666 rc = fat_zero_cluster(bs, parentp->idx->dev _handle, mcl);667 if (rc != EOK) { 668 (void) fat_free_clusters(bs, parentp->idx->dev _handle, mcl);666 rc = fat_zero_cluster(bs, parentp->idx->devmap_handle, mcl); 667 if (rc != EOK) { 668 (void) fat_free_clusters(bs, parentp->idx->devmap_handle, mcl); 669 669 fibril_mutex_unlock(&parentp->idx->lock); 670 670 return rc; … … 672 672 rc = fat_append_clusters(bs, parentp, mcl, lcl); 673 673 if (rc != EOK) { 674 (void) fat_free_clusters(bs, parentp->idx->dev _handle, mcl);674 (void) fat_free_clusters(bs, parentp->idx->devmap_handle, mcl); 675 675 fibril_mutex_unlock(&parentp->idx->lock); 676 676 return rc; … … 789 789 assert(childp->lnkcnt == 1); 790 790 fibril_mutex_lock(&childp->idx->lock); 791 bs = block_bb_get(childp->idx->dev _handle);792 793 rc = _fat_block_get(&b, bs, childp->idx->dev _handle, childp->idx->pfc,791 bs = block_bb_get(childp->idx->devmap_handle); 792 793 rc = _fat_block_get(&b, bs, childp->idx->devmap_handle, childp->idx->pfc, 794 794 NULL, (childp->idx->pdi * sizeof(fat_dentry_t)) / BPS(bs), 795 795 BLOCK_FLAGS_NONE); … … 840 840 841 841 fibril_mutex_lock(&nodep->idx->lock); 842 bs = block_bb_get(nodep->idx->dev _handle);842 bs = block_bb_get(nodep->idx->devmap_handle); 843 843 844 844 blocks = nodep->size / BPS(bs); … … 914 914 } 915 915 916 dev _handle_t fat_device_get(fs_node_t *node)916 devmap_handle_t fat_device_get(fs_node_t *node) 917 917 { 918 918 return 0; … … 946 946 void fat_mounted(ipc_callid_t rid, ipc_call_t *request) 947 947 { 948 dev _handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);948 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 949 949 enum cache_mode cmode; 950 950 fat_bs_t *bs; … … 968 968 969 969 /* initialize libblock */ 970 rc = block_init(dev _handle, BS_SIZE);970 rc = block_init(devmap_handle, BS_SIZE); 971 971 if (rc != EOK) { 972 972 ipc_answer_0(rid, rc); … … 975 975 976 976 /* prepare the boot block */ 977 rc = block_bb_read(dev _handle, BS_BLOCK);978 if (rc != EOK) { 979 block_fini(dev _handle);977 rc = block_bb_read(devmap_handle, BS_BLOCK); 978 if (rc != EOK) { 979 block_fini(devmap_handle); 980 980 ipc_answer_0(rid, rc); 981 981 return; … … 983 983 984 984 /* get the buffer with the boot sector */ 985 bs = block_bb_get(dev _handle);985 bs = block_bb_get(devmap_handle); 986 986 987 987 if (BPS(bs) != BS_SIZE) { 988 block_fini(dev _handle);988 block_fini(devmap_handle); 989 989 ipc_answer_0(rid, ENOTSUP); 990 990 return; … … 992 992 993 993 /* Initialize the block cache */ 994 rc = block_cache_init(dev _handle, BPS(bs), 0 /* XXX */, cmode);995 if (rc != EOK) { 996 block_fini(dev _handle);994 rc = block_cache_init(devmap_handle, BPS(bs), 0 /* XXX */, cmode); 995 if (rc != EOK) { 996 block_fini(devmap_handle); 997 997 ipc_answer_0(rid, rc); 998 998 return; … … 1000 1000 1001 1001 /* Do some simple sanity checks on the file system. */ 1002 rc = fat_sanity_check(bs, dev _handle);1003 if (rc != EOK) { 1004 (void) block_cache_fini(dev _handle);1005 block_fini(dev _handle);1002 rc = fat_sanity_check(bs, devmap_handle); 1003 if (rc != EOK) { 1004 (void) block_cache_fini(devmap_handle); 1005 block_fini(devmap_handle); 1006 1006 ipc_answer_0(rid, rc); 1007 1007 return; 1008 1008 } 1009 1009 1010 rc = fat_idx_init_by_dev _handle(dev_handle);1011 if (rc != EOK) { 1012 (void) block_cache_fini(dev _handle);1013 block_fini(dev _handle);1010 rc = fat_idx_init_by_devmap_handle(devmap_handle); 1011 if (rc != EOK) { 1012 (void) block_cache_fini(devmap_handle); 1013 block_fini(devmap_handle); 1014 1014 ipc_answer_0(rid, rc); 1015 1015 return; … … 1019 1019 fs_node_t *rfn = (fs_node_t *)malloc(sizeof(fs_node_t)); 1020 1020 if (!rfn) { 1021 (void) block_cache_fini(dev _handle);1022 block_fini(dev _handle);1023 fat_idx_fini_by_dev _handle(dev_handle);1021 (void) block_cache_fini(devmap_handle); 1022 block_fini(devmap_handle); 1023 fat_idx_fini_by_devmap_handle(devmap_handle); 1024 1024 ipc_answer_0(rid, ENOMEM); 1025 1025 return; … … 1029 1029 if (!rootp) { 1030 1030 free(rfn); 1031 (void) block_cache_fini(dev _handle);1032 block_fini(dev _handle);1033 fat_idx_fini_by_dev _handle(dev_handle);1031 (void) block_cache_fini(devmap_handle); 1032 block_fini(devmap_handle); 1033 fat_idx_fini_by_devmap_handle(devmap_handle); 1034 1034 ipc_answer_0(rid, ENOMEM); 1035 1035 return; … … 1037 1037 fat_node_initialize(rootp); 1038 1038 1039 fat_idx_t *ridxp = fat_idx_get_by_pos(dev _handle, FAT_CLST_ROOTPAR, 0);1039 fat_idx_t *ridxp = fat_idx_get_by_pos(devmap_handle, FAT_CLST_ROOTPAR, 0); 1040 1040 if (!ridxp) { 1041 1041 free(rfn); 1042 1042 free(rootp); 1043 (void) block_cache_fini(dev _handle);1044 block_fini(dev _handle);1045 fat_idx_fini_by_dev _handle(dev_handle);1043 (void) block_cache_fini(devmap_handle); 1044 block_fini(devmap_handle); 1045 fat_idx_fini_by_devmap_handle(devmap_handle); 1046 1046 ipc_answer_0(rid, ENOMEM); 1047 1047 return; … … 1072 1072 void fat_unmounted(ipc_callid_t rid, ipc_call_t *request) 1073 1073 { 1074 dev _handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);1074 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1075 1075 fs_node_t *fn; 1076 1076 fat_node_t *nodep; 1077 1077 int rc; 1078 1078 1079 rc = fat_root_get(&fn, dev _handle);1079 rc = fat_root_get(&fn, devmap_handle); 1080 1080 if (rc != EOK) { 1081 1081 ipc_answer_0(rid, rc); … … 1105 1105 * stop using libblock for this instance. 1106 1106 */ 1107 (void) fat_node_fini_by_dev _handle(dev_handle);1108 fat_idx_fini_by_dev _handle(dev_handle);1109 (void) block_cache_fini(dev _handle);1110 block_fini(dev _handle);1107 (void) fat_node_fini_by_devmap_handle(devmap_handle); 1108 fat_idx_fini_by_devmap_handle(devmap_handle); 1109 (void) block_cache_fini(devmap_handle); 1110 block_fini(devmap_handle); 1111 1111 1112 1112 ipc_answer_0(rid, EOK); … … 1125 1125 void fat_read(ipc_callid_t rid, ipc_call_t *request) 1126 1126 { 1127 dev _handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);1127 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1128 1128 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1129 1129 aoff64_t pos = … … 1136 1136 int rc; 1137 1137 1138 rc = fat_node_get(&fn, dev _handle, index);1138 rc = fat_node_get(&fn, devmap_handle, index); 1139 1139 if (rc != EOK) { 1140 1140 ipc_answer_0(rid, rc); … … 1156 1156 } 1157 1157 1158 bs = block_bb_get(dev _handle);1158 bs = block_bb_get(devmap_handle); 1159 1159 1160 1160 if (nodep->type == FAT_FILE) { … … 1262 1262 void fat_write(ipc_callid_t rid, ipc_call_t *request) 1263 1263 { 1264 dev _handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);1264 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1265 1265 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1266 1266 aoff64_t pos = … … 1275 1275 int rc; 1276 1276 1277 rc = fat_node_get(&fn, dev _handle, index);1277 rc = fat_node_get(&fn, devmap_handle, index); 1278 1278 if (rc != EOK) { 1279 1279 ipc_answer_0(rid, rc); … … 1295 1295 } 1296 1296 1297 bs = block_bb_get(dev _handle);1297 bs = block_bb_get(devmap_handle); 1298 1298 1299 1299 /* … … 1357 1357 nclsts = (ROUND_UP(pos + bytes, BPC(bs)) - boundary) / BPC(bs); 1358 1358 /* create an independent chain of nclsts clusters in all FATs */ 1359 rc = fat_alloc_clusters(bs, dev _handle, nclsts, &mcl, &lcl);1359 rc = fat_alloc_clusters(bs, devmap_handle, nclsts, &mcl, &lcl); 1360 1360 if (rc != EOK) { 1361 1361 /* could not allocate a chain of nclsts clusters */ … … 1368 1368 rc = fat_fill_gap(bs, nodep, mcl, pos); 1369 1369 if (rc != EOK) { 1370 (void) fat_free_clusters(bs, dev _handle, mcl);1370 (void) fat_free_clusters(bs, devmap_handle, mcl); 1371 1371 (void) fat_node_put(fn); 1372 1372 ipc_answer_0(callid, rc); … … 1374 1374 return; 1375 1375 } 1376 rc = _fat_block_get(&b, bs, dev _handle, lcl, NULL,1376 rc = _fat_block_get(&b, bs, devmap_handle, lcl, NULL, 1377 1377 (pos / BPS(bs)) % SPC(bs), flags); 1378 1378 if (rc != EOK) { 1379 (void) fat_free_clusters(bs, dev _handle, mcl);1379 (void) fat_free_clusters(bs, devmap_handle, mcl); 1380 1380 (void) fat_node_put(fn); 1381 1381 ipc_answer_0(callid, rc); … … 1388 1388 rc = block_put(b); 1389 1389 if (rc != EOK) { 1390 (void) fat_free_clusters(bs, dev _handle, mcl);1390 (void) fat_free_clusters(bs, devmap_handle, mcl); 1391 1391 (void) fat_node_put(fn); 1392 1392 ipc_answer_0(rid, rc); … … 1399 1399 rc = fat_append_clusters(bs, nodep, mcl, lcl); 1400 1400 if (rc != EOK) { 1401 (void) fat_free_clusters(bs, dev _handle, mcl);1401 (void) fat_free_clusters(bs, devmap_handle, mcl); 1402 1402 (void) fat_node_put(fn); 1403 1403 ipc_answer_0(rid, rc); … … 1414 1414 void fat_truncate(ipc_callid_t rid, ipc_call_t *request) 1415 1415 { 1416 dev _handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);1416 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1417 1417 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1418 1418 aoff64_t size = … … 1423 1423 int rc; 1424 1424 1425 rc = fat_node_get(&fn, dev _handle, index);1425 rc = fat_node_get(&fn, devmap_handle, index); 1426 1426 if (rc != EOK) { 1427 1427 ipc_answer_0(rid, rc); … … 1434 1434 nodep = FAT_NODE(fn); 1435 1435 1436 bs = block_bb_get(dev _handle);1436 bs = block_bb_get(devmap_handle); 1437 1437 1438 1438 if (nodep->size == size) { … … 1461 1461 } else { 1462 1462 fat_cluster_t lastc; 1463 rc = fat_cluster_walk(bs, dev _handle, nodep->firstc,1463 rc = fat_cluster_walk(bs, devmap_handle, nodep->firstc, 1464 1464 &lastc, NULL, (size - 1) / BPC(bs)); 1465 1465 if (rc != EOK) … … 1486 1486 void fat_destroy(ipc_callid_t rid, ipc_call_t *request) 1487 1487 { 1488 dev _handle_t dev_handle = (dev_handle_t)IPC_GET_ARG1(*request);1488 devmap_handle_t devmap_handle = (devmap_handle_t)IPC_GET_ARG1(*request); 1489 1489 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 1490 1490 fs_node_t *fn; 1491 1491 int rc; 1492 1492 1493 rc = fat_node_get(&fn, dev _handle, index);1493 rc = fat_node_get(&fn, devmap_handle, index); 1494 1494 if (rc != EOK) { 1495 1495 ipc_answer_0(rid, rc); … … 1517 1517 void fat_sync(ipc_callid_t rid, ipc_call_t *request) 1518 1518 { 1519 dev _handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request);1519 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request); 1520 1520 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1521 1521 1522 1522 fs_node_t *fn; 1523 int rc = fat_node_get(&fn, dev _handle, index);1523 int rc = fat_node_get(&fn, devmap_handle, index); 1524 1524 if (rc != EOK) { 1525 1525 ipc_answer_0(rid, rc);
Note:
See TracChangeset
for help on using the changeset viewer.