Changeset ee24574 in mainline for uspace/srv/fs/fat/fat_ops.c
- Timestamp:
- 2011-08-18T08:00:42Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a92cf94f
- Parents:
- 0f963cb (diff), c53a705 (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
r0f963cb ree24574 43 43 #include <libblock.h> 44 44 #include <ipc/services.h> 45 #include <ipc/ devmap.h>45 #include <ipc/loc.h> 46 46 #include <macros.h> 47 47 #include <async.h> … … 72 72 * Forward declarations of FAT libfs operations. 73 73 */ 74 static int fat_root_get(fs_node_t **, devmap_handle_t);74 static int fat_root_get(fs_node_t **, service_id_t); 75 75 static int fat_match(fs_node_t **, fs_node_t *, const char *); 76 static int fat_node_get(fs_node_t **, devmap_handle_t, fs_index_t);76 static int fat_node_get(fs_node_t **, service_id_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 **, devmap_handle_t, int);79 static int fat_create_node(fs_node_t **, service_id_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 *); … … 87 87 static bool fat_is_directory(fs_node_t *); 88 88 static bool fat_is_file(fs_node_t *node); 89 static devmap_handle_t fat_device_get(fs_node_t *node);89 static service_id_t fat_device_get(fs_node_t *node); 90 90 91 91 /* … … 119 119 assert(node->dirty); 120 120 121 bs = block_bb_get(node->idx-> devmap_handle);121 bs = block_bb_get(node->idx->service_id); 122 122 123 123 /* Read the block that contains the dentry of interest. */ 124 rc = _fat_block_get(&b, bs, node->idx-> devmap_handle, node->idx->pfc,124 rc = _fat_block_get(&b, bs, node->idx->service_id, node->idx->pfc, 125 125 NULL, (node->idx->pdi * sizeof(fat_dentry_t)) / BPS(bs), 126 126 BLOCK_FLAGS_NONE); … … 144 144 } 145 145 146 static int fat_node_fini_by_ devmap_handle(devmap_handle_t devmap_handle)146 static int fat_node_fini_by_service_id(service_id_t service_id) 147 147 { 148 148 fat_node_t *nodep; … … 168 168 goto restart; 169 169 } 170 if (nodep->idx-> devmap_handle != devmap_handle) {170 if (nodep->idx->service_id != service_id) { 171 171 fibril_mutex_unlock(&nodep->idx->lock); 172 172 fibril_mutex_unlock(&nodep->lock); … … 298 298 return rc; 299 299 300 bs = block_bb_get(idxp-> devmap_handle);300 bs = block_bb_get(idxp->service_id); 301 301 302 302 /* Read the block that contains the dentry of interest. */ 303 rc = _fat_block_get(&b, bs, idxp-> devmap_handle, idxp->pfc, NULL,303 rc = _fat_block_get(&b, bs, idxp->service_id, idxp->pfc, NULL, 304 304 (idxp->pdi * sizeof(fat_dentry_t)) / BPS(bs), BLOCK_FLAGS_NONE); 305 305 if (rc != EOK) { … … 322 322 */ 323 323 uint16_t clusters; 324 rc = fat_clusters_get(&clusters, bs, idxp-> devmap_handle,324 rc = fat_clusters_get(&clusters, bs, idxp->service_id, 325 325 uint16_t_le2host(d->firstc)); 326 326 if (rc != EOK) { … … 356 356 */ 357 357 358 int fat_root_get(fs_node_t **rfn, devmap_handle_t devmap_handle)359 { 360 return fat_node_get(rfn, devmap_handle, 0);358 int fat_root_get(fs_node_t **rfn, service_id_t service_id) 359 { 360 return fat_node_get(rfn, service_id, 0); 361 361 } 362 362 … … 369 369 unsigned blocks; 370 370 fat_dentry_t *d; 371 devmap_handle_t devmap_handle;371 service_id_t service_id; 372 372 block_t *b; 373 373 int rc; 374 374 375 375 fibril_mutex_lock(&parentp->idx->lock); 376 devmap_handle = parentp->idx->devmap_handle;376 service_id = parentp->idx->service_id; 377 377 fibril_mutex_unlock(&parentp->idx->lock); 378 378 379 bs = block_bb_get( devmap_handle);379 bs = block_bb_get(service_id); 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( devmap_handle,404 fat_idx_t *idx = fat_idx_get_by_pos(service_id, 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, devmap_handle_t devmap_handle, fs_index_t index)437 int fat_node_get(fs_node_t **rfn, service_id_t service_id, 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( devmap_handle, index);443 idxp = fat_idx_get_by_index(service_id, index); 444 444 if (!idxp) { 445 445 *rfn = NULL; … … 492 492 } 493 493 494 int fat_create_node(fs_node_t **rfn, devmap_handle_t devmap_handle, int flags)494 int fat_create_node(fs_node_t **rfn, service_id_t service_id, int flags) 495 495 { 496 496 fat_idx_t *idxp; … … 500 500 int rc; 501 501 502 bs = block_bb_get( devmap_handle);502 bs = block_bb_get(service_id); 503 503 if (flags & L_DIRECTORY) { 504 504 /* allocate a cluster */ 505 rc = fat_alloc_clusters(bs, devmap_handle, 1, &mcl, &lcl);505 rc = fat_alloc_clusters(bs, service_id, 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, devmap_handle, mcl);509 rc = fat_zero_cluster(bs, service_id, mcl); 510 510 if (rc != EOK) { 511 (void) fat_free_clusters(bs, devmap_handle, mcl);511 (void) fat_free_clusters(bs, service_id, 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, devmap_handle, mcl);519 return rc; 520 } 521 rc = fat_idx_get_new(&idxp, devmap_handle);518 (void) fat_free_clusters(bs, service_id, mcl); 519 return rc; 520 } 521 rc = fat_idx_get_new(&idxp, service_id); 522 522 if (rc != EOK) { 523 (void) fat_free_clusters(bs, devmap_handle, mcl);523 (void) fat_free_clusters(bs, service_id, 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-> devmap_handle);572 bs = block_bb_get(nodep->idx->service_id); 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-> devmap_handle,576 rc = fat_free_clusters(bs, nodep->idx->service_id, 577 577 nodep->firstc); 578 578 } … … 620 620 621 621 fibril_mutex_lock(&parentp->idx->lock); 622 bs = block_bb_get(parentp->idx-> devmap_handle);622 bs = block_bb_get(parentp->idx->service_id); 623 623 624 624 blocks = parentp->size / BPS(bs); … … 659 659 return ENOSPC; 660 660 } 661 rc = fat_alloc_clusters(bs, parentp->idx-> devmap_handle, 1, &mcl, &lcl);661 rc = fat_alloc_clusters(bs, parentp->idx->service_id, 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-> devmap_handle, mcl);666 rc = fat_zero_cluster(bs, parentp->idx->service_id, mcl); 667 667 if (rc != EOK) { 668 (void) fat_free_clusters(bs, parentp->idx-> devmap_handle, mcl);668 (void) fat_free_clusters(bs, parentp->idx->service_id, 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-> devmap_handle, mcl);674 (void) fat_free_clusters(bs, parentp->idx->service_id, 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-> devmap_handle);792 793 rc = _fat_block_get(&b, bs, childp->idx-> devmap_handle, childp->idx->pfc,791 bs = block_bb_get(childp->idx->service_id); 792 793 rc = _fat_block_get(&b, bs, childp->idx->service_id, childp->idx->pfc, 794 794 NULL, (childp->idx->pdi * sizeof(fat_dentry_t)) / BPS(bs), 795 795 BLOCK_FLAGS_NONE); … … 841 841 842 842 fibril_mutex_lock(&nodep->idx->lock); 843 bs = block_bb_get(nodep->idx-> devmap_handle);843 bs = block_bb_get(nodep->idx->service_id); 844 844 845 845 blocks = nodep->size / BPS(bs); … … 910 910 } 911 911 912 devmap_handle_t fat_device_get(fs_node_t *node)912 service_id_t fat_device_get(fs_node_t *node) 913 913 { 914 914 return 0; … … 940 940 941 941 static int 942 fat_mounted( devmap_handle_t devmap_handle, const char *opts, fs_index_t *index,942 fat_mounted(service_id_t service_id, const char *opts, fs_index_t *index, 943 943 aoff64_t *size, unsigned *linkcnt) 944 944 { … … 954 954 955 955 /* initialize libblock */ 956 rc = block_init(EXCHANGE_SERIALIZE, devmap_handle, BS_SIZE);956 rc = block_init(EXCHANGE_SERIALIZE, service_id, BS_SIZE); 957 957 if (rc != EOK) 958 958 return rc; 959 959 960 960 /* prepare the boot block */ 961 rc = block_bb_read( devmap_handle, BS_BLOCK);961 rc = block_bb_read(service_id, BS_BLOCK); 962 962 if (rc != EOK) { 963 block_fini( devmap_handle);963 block_fini(service_id); 964 964 return rc; 965 965 } 966 966 967 967 /* get the buffer with the boot sector */ 968 bs = block_bb_get( devmap_handle);968 bs = block_bb_get(service_id); 969 969 970 970 if (BPS(bs) != BS_SIZE) { 971 block_fini( devmap_handle);971 block_fini(service_id); 972 972 return ENOTSUP; 973 973 } 974 974 975 975 /* Initialize the block cache */ 976 rc = block_cache_init( devmap_handle, BPS(bs), 0 /* XXX */, cmode);976 rc = block_cache_init(service_id, BPS(bs), 0 /* XXX */, cmode); 977 977 if (rc != EOK) { 978 block_fini( devmap_handle);978 block_fini(service_id); 979 979 return rc; 980 980 } 981 981 982 982 /* Do some simple sanity checks on the file system. */ 983 rc = fat_sanity_check(bs, devmap_handle);983 rc = fat_sanity_check(bs, service_id); 984 984 if (rc != EOK) { 985 (void) block_cache_fini( devmap_handle);986 block_fini( devmap_handle);987 return rc; 988 } 989 990 rc = fat_idx_init_by_ devmap_handle(devmap_handle);985 (void) block_cache_fini(service_id); 986 block_fini(service_id); 987 return rc; 988 } 989 990 rc = fat_idx_init_by_service_id(service_id); 991 991 if (rc != EOK) { 992 (void) block_cache_fini( devmap_handle);993 block_fini( devmap_handle);992 (void) block_cache_fini(service_id); 993 block_fini(service_id); 994 994 return rc; 995 995 } … … 998 998 fs_node_t *rfn = (fs_node_t *)malloc(sizeof(fs_node_t)); 999 999 if (!rfn) { 1000 (void) block_cache_fini( devmap_handle);1001 block_fini( devmap_handle);1002 fat_idx_fini_by_ devmap_handle(devmap_handle);1000 (void) block_cache_fini(service_id); 1001 block_fini(service_id); 1002 fat_idx_fini_by_service_id(service_id); 1003 1003 return ENOMEM; 1004 1004 } … … 1007 1007 if (!rootp) { 1008 1008 free(rfn); 1009 (void) block_cache_fini( devmap_handle);1010 block_fini( devmap_handle);1011 fat_idx_fini_by_ devmap_handle(devmap_handle);1009 (void) block_cache_fini(service_id); 1010 block_fini(service_id); 1011 fat_idx_fini_by_service_id(service_id); 1012 1012 return ENOMEM; 1013 1013 } 1014 1014 fat_node_initialize(rootp); 1015 1015 1016 fat_idx_t *ridxp = fat_idx_get_by_pos( devmap_handle, FAT_CLST_ROOTPAR, 0);1016 fat_idx_t *ridxp = fat_idx_get_by_pos(service_id, FAT_CLST_ROOTPAR, 0); 1017 1017 if (!ridxp) { 1018 1018 free(rfn); 1019 1019 free(rootp); 1020 (void) block_cache_fini( devmap_handle);1021 block_fini( devmap_handle);1022 fat_idx_fini_by_ devmap_handle(devmap_handle);1020 (void) block_cache_fini(service_id); 1021 block_fini(service_id); 1022 fat_idx_fini_by_service_id(service_id); 1023 1023 return ENOMEM; 1024 1024 } … … 1045 1045 } 1046 1046 1047 static int fat_unmounted( devmap_handle_t devmap_handle)1047 static int fat_unmounted(service_id_t service_id) 1048 1048 { 1049 1049 fs_node_t *fn; … … 1051 1051 int rc; 1052 1052 1053 rc = fat_root_get(&fn, devmap_handle);1053 rc = fat_root_get(&fn, service_id); 1054 1054 if (rc != EOK) 1055 1055 return rc; … … 1076 1076 * stop using libblock for this instance. 1077 1077 */ 1078 (void) fat_node_fini_by_ devmap_handle(devmap_handle);1079 fat_idx_fini_by_ devmap_handle(devmap_handle);1080 (void) block_cache_fini( devmap_handle);1081 block_fini( devmap_handle);1078 (void) fat_node_fini_by_service_id(service_id); 1079 fat_idx_fini_by_service_id(service_id); 1080 (void) block_cache_fini(service_id); 1081 block_fini(service_id); 1082 1082 1083 1083 return EOK; … … 1085 1085 1086 1086 static int 1087 fat_read( devmap_handle_t devmap_handle, fs_index_t index, aoff64_t pos,1087 fat_read(service_id_t service_id, fs_index_t index, aoff64_t pos, 1088 1088 size_t *rbytes) 1089 1089 { … … 1095 1095 int rc; 1096 1096 1097 rc = fat_node_get(&fn, devmap_handle, index);1097 rc = fat_node_get(&fn, service_id, index); 1098 1098 if (rc != EOK) 1099 1099 return rc; … … 1110 1110 } 1111 1111 1112 bs = block_bb_get( devmap_handle);1112 bs = block_bb_get(service_id); 1113 1113 1114 1114 if (nodep->type == FAT_FILE) { … … 1213 1213 1214 1214 static int 1215 fat_write( devmap_handle_t devmap_handle, fs_index_t index, aoff64_t pos,1215 fat_write(service_id_t service_id, fs_index_t index, aoff64_t pos, 1216 1216 size_t *wbytes, aoff64_t *nsize) 1217 1217 { … … 1225 1225 int rc; 1226 1226 1227 rc = fat_node_get(&fn, devmap_handle, index);1227 rc = fat_node_get(&fn, service_id, index); 1228 1228 if (rc != EOK) 1229 1229 return rc; … … 1240 1240 } 1241 1241 1242 bs = block_bb_get( devmap_handle);1242 bs = block_bb_get(service_id); 1243 1243 1244 1244 /* … … 1299 1299 nclsts = (ROUND_UP(pos + bytes, BPC(bs)) - boundary) / BPC(bs); 1300 1300 /* create an independent chain of nclsts clusters in all FATs */ 1301 rc = fat_alloc_clusters(bs, devmap_handle, nclsts, &mcl, &lcl);1301 rc = fat_alloc_clusters(bs, service_id, nclsts, &mcl, &lcl); 1302 1302 if (rc != EOK) { 1303 1303 /* could not allocate a chain of nclsts clusters */ … … 1309 1309 rc = fat_fill_gap(bs, nodep, mcl, pos); 1310 1310 if (rc != EOK) { 1311 (void) fat_free_clusters(bs, devmap_handle, mcl);1311 (void) fat_free_clusters(bs, service_id, mcl); 1312 1312 (void) fat_node_put(fn); 1313 1313 async_answer_0(callid, rc); 1314 1314 return rc; 1315 1315 } 1316 rc = _fat_block_get(&b, bs, devmap_handle, lcl, NULL,1316 rc = _fat_block_get(&b, bs, service_id, lcl, NULL, 1317 1317 (pos / BPS(bs)) % SPC(bs), flags); 1318 1318 if (rc != EOK) { 1319 (void) fat_free_clusters(bs, devmap_handle, mcl);1319 (void) fat_free_clusters(bs, service_id, mcl); 1320 1320 (void) fat_node_put(fn); 1321 1321 async_answer_0(callid, rc); … … 1327 1327 rc = block_put(b); 1328 1328 if (rc != EOK) { 1329 (void) fat_free_clusters(bs, devmap_handle, mcl);1329 (void) fat_free_clusters(bs, service_id, mcl); 1330 1330 (void) fat_node_put(fn); 1331 1331 return rc; … … 1337 1337 rc = fat_append_clusters(bs, nodep, mcl, lcl); 1338 1338 if (rc != EOK) { 1339 (void) fat_free_clusters(bs, devmap_handle, mcl);1339 (void) fat_free_clusters(bs, service_id, mcl); 1340 1340 (void) fat_node_put(fn); 1341 1341 return rc; … … 1350 1350 1351 1351 static int 1352 fat_truncate( devmap_handle_t devmap_handle, fs_index_t index, aoff64_t size)1352 fat_truncate(service_id_t service_id, fs_index_t index, aoff64_t size) 1353 1353 { 1354 1354 fs_node_t *fn; … … 1357 1357 int rc; 1358 1358 1359 rc = fat_node_get(&fn, devmap_handle, index);1359 rc = fat_node_get(&fn, service_id, index); 1360 1360 if (rc != EOK) 1361 1361 return rc; … … 1364 1364 nodep = FAT_NODE(fn); 1365 1365 1366 bs = block_bb_get( devmap_handle);1366 bs = block_bb_get(service_id); 1367 1367 1368 1368 if (nodep->size == size) { … … 1391 1391 } else { 1392 1392 fat_cluster_t lastc; 1393 rc = fat_cluster_walk(bs, devmap_handle, nodep->firstc,1393 rc = fat_cluster_walk(bs, service_id, nodep->firstc, 1394 1394 &lastc, NULL, (size - 1) / BPC(bs)); 1395 1395 if (rc != EOK) … … 1408 1408 } 1409 1409 1410 static int fat_close( devmap_handle_t devmap_handle, fs_index_t index)1410 static int fat_close(service_id_t service_id, fs_index_t index) 1411 1411 { 1412 1412 return EOK; 1413 1413 } 1414 1414 1415 static int fat_destroy( devmap_handle_t devmap_handle, fs_index_t index)1415 static int fat_destroy(service_id_t service_id, fs_index_t index) 1416 1416 { 1417 1417 fs_node_t *fn; … … 1419 1419 int rc; 1420 1420 1421 rc = fat_node_get(&fn, devmap_handle, index);1421 rc = fat_node_get(&fn, service_id, index); 1422 1422 if (rc != EOK) 1423 1423 return rc; … … 1436 1436 } 1437 1437 1438 static int fat_sync( devmap_handle_t devmap_handle, fs_index_t index)1438 static int fat_sync(service_id_t service_id, fs_index_t index) 1439 1439 { 1440 1440 fs_node_t *fn; 1441 int rc = fat_node_get(&fn, devmap_handle, index);1441 int rc = fat_node_get(&fn, service_id, index); 1442 1442 if (rc != EOK) 1443 1443 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.