Changeset 0b749a3 in mainline for uspace/srv/fs/fat/fat_ops.c
- Timestamp:
- 2010-11-22T15:39:53Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0eddb76, aae339e9
- Parents:
- 9a1d8ab (diff), 8cd1aa5e (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
r9a1d8ab r0b749a3 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 devmap_handle_t devmap_handle; 371 372 block_t *b; 372 373 int rc; 373 374 374 375 fibril_mutex_lock(&parentp->idx->lock); 375 bs = block_bb_get(parentp->idx->dev_handle); 376 devmap_handle = parentp->idx->devmap_handle; 377 fibril_mutex_unlock(&parentp->idx->lock); 378 379 bs = block_bb_get(devmap_handle); 376 380 blocks = parentp->size / BPS(bs); 377 381 for (i = 0; i < blocks; i++) { 378 382 rc = fat_block_get(&b, bs, parentp, i, BLOCK_FLAGS_NONE); 379 if (rc != EOK) { 380 fibril_mutex_unlock(&parentp->idx->lock); 383 if (rc != EOK) 381 384 return rc; 382 }383 385 for (j = 0; j < DPS(bs); j++) { 384 386 d = ((fat_dentry_t *)b->data) + j; … … 390 392 /* miss */ 391 393 rc = block_put(b); 392 fibril_mutex_unlock(&parentp->idx->lock);393 394 *rfn = NULL; 394 395 return rc; … … 401 402 /* hit */ 402 403 fat_node_t *nodep; 403 /* 404 * Assume tree hierarchy for locking. We 405 * already have the parent and now we are going 406 * to lock the child. Never lock in the oposite 407 * order. 408 */ 409 fat_idx_t *idx = fat_idx_get_by_pos( 410 parentp->idx->dev_handle, parentp->firstc, 411 i * DPS(bs) + j); 412 fibril_mutex_unlock(&parentp->idx->lock); 404 fat_idx_t *idx = fat_idx_get_by_pos(devmap_handle, 405 parentp->firstc, i * DPS(bs) + j); 413 406 if (!idx) { 414 407 /* … … 433 426 } 434 427 rc = block_put(b); 435 if (rc != EOK) { 436 fibril_mutex_unlock(&parentp->idx->lock); 428 if (rc != EOK) 437 429 return rc; 438 } 439 } 440 441 fibril_mutex_unlock(&parentp->idx->lock); 430 } 431 442 432 *rfn = NULL; 443 433 return EOK; … … 445 435 446 436 /** Instantiate a FAT in-core node. */ 447 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) 448 438 { 449 439 fat_node_t *nodep; … … 451 441 int rc; 452 442 453 idxp = fat_idx_get_by_index(dev _handle, index);443 idxp = fat_idx_get_by_index(devmap_handle, index); 454 444 if (!idxp) { 455 445 *rfn = NULL; … … 502 492 } 503 493 504 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) 505 495 { 506 496 fat_idx_t *idxp; … … 510 500 int rc; 511 501 512 bs = block_bb_get(dev _handle);502 bs = block_bb_get(devmap_handle); 513 503 if (flags & L_DIRECTORY) { 514 504 /* allocate a cluster */ 515 rc = fat_alloc_clusters(bs, dev _handle, 1, &mcl, &lcl);505 rc = fat_alloc_clusters(bs, devmap_handle, 1, &mcl, &lcl); 516 506 if (rc != EOK) 517 507 return rc; 518 508 /* populate the new cluster with unused dentries */ 519 rc = fat_zero_cluster(bs, dev _handle, mcl);509 rc = fat_zero_cluster(bs, devmap_handle, mcl); 520 510 if (rc != EOK) { 521 (void) fat_free_clusters(bs, dev _handle, mcl);511 (void) fat_free_clusters(bs, devmap_handle, mcl); 522 512 return rc; 523 513 } … … 526 516 rc = fat_node_get_new(&nodep); 527 517 if (rc != EOK) { 528 (void) fat_free_clusters(bs, dev _handle, mcl);518 (void) fat_free_clusters(bs, devmap_handle, mcl); 529 519 return rc; 530 520 } 531 rc = fat_idx_get_new(&idxp, dev _handle);532 if (rc != EOK) { 533 (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); 534 524 (void) fat_node_put(FS_NODE(nodep)); 535 525 return rc; … … 580 570 assert(!has_children); 581 571 582 bs = block_bb_get(nodep->idx->dev _handle);572 bs = block_bb_get(nodep->idx->devmap_handle); 583 573 if (nodep->firstc != FAT_CLST_RES0) { 584 574 assert(nodep->size); 585 575 /* Free all clusters allocated to the node. */ 586 rc = fat_free_clusters(bs, nodep->idx->dev _handle,576 rc = fat_free_clusters(bs, nodep->idx->devmap_handle, 587 577 nodep->firstc); 588 578 } … … 630 620 631 621 fibril_mutex_lock(&parentp->idx->lock); 632 bs = block_bb_get(parentp->idx->dev _handle);622 bs = block_bb_get(parentp->idx->devmap_handle); 633 623 634 624 blocks = parentp->size / BPS(bs); … … 669 659 return ENOSPC; 670 660 } 671 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); 672 662 if (rc != EOK) { 673 663 fibril_mutex_unlock(&parentp->idx->lock); 674 664 return rc; 675 665 } 676 rc = fat_zero_cluster(bs, parentp->idx->dev _handle, mcl);677 if (rc != EOK) { 678 (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); 679 669 fibril_mutex_unlock(&parentp->idx->lock); 680 670 return rc; … … 682 672 rc = fat_append_clusters(bs, parentp, mcl, lcl); 683 673 if (rc != EOK) { 684 (void) fat_free_clusters(bs, parentp->idx->dev _handle, mcl);674 (void) fat_free_clusters(bs, parentp->idx->devmap_handle, mcl); 685 675 fibril_mutex_unlock(&parentp->idx->lock); 686 676 return rc; … … 799 789 assert(childp->lnkcnt == 1); 800 790 fibril_mutex_lock(&childp->idx->lock); 801 bs = block_bb_get(childp->idx->dev _handle);802 803 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, 804 794 NULL, (childp->idx->pdi * sizeof(fat_dentry_t)) / BPS(bs), 805 795 BLOCK_FLAGS_NONE); … … 850 840 851 841 fibril_mutex_lock(&nodep->idx->lock); 852 bs = block_bb_get(nodep->idx->dev _handle);842 bs = block_bb_get(nodep->idx->devmap_handle); 853 843 854 844 blocks = nodep->size / BPS(bs); … … 924 914 } 925 915 926 dev _handle_t fat_device_get(fs_node_t *node)916 devmap_handle_t fat_device_get(fs_node_t *node) 927 917 { 928 918 return 0; … … 956 946 void fat_mounted(ipc_callid_t rid, ipc_call_t *request) 957 947 { 958 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); 959 949 enum cache_mode cmode; 960 950 fat_bs_t *bs; … … 978 968 979 969 /* initialize libblock */ 980 rc = block_init(dev _handle, BS_SIZE);970 rc = block_init(devmap_handle, BS_SIZE); 981 971 if (rc != EOK) { 982 972 ipc_answer_0(rid, rc); … … 985 975 986 976 /* prepare the boot block */ 987 rc = block_bb_read(dev _handle, BS_BLOCK);988 if (rc != EOK) { 989 block_fini(dev _handle);977 rc = block_bb_read(devmap_handle, BS_BLOCK); 978 if (rc != EOK) { 979 block_fini(devmap_handle); 990 980 ipc_answer_0(rid, rc); 991 981 return; … … 993 983 994 984 /* get the buffer with the boot sector */ 995 bs = block_bb_get(dev _handle);985 bs = block_bb_get(devmap_handle); 996 986 997 987 if (BPS(bs) != BS_SIZE) { 998 block_fini(dev _handle);988 block_fini(devmap_handle); 999 989 ipc_answer_0(rid, ENOTSUP); 1000 990 return; … … 1002 992 1003 993 /* Initialize the block cache */ 1004 rc = block_cache_init(dev _handle, BPS(bs), 0 /* XXX */, cmode);1005 if (rc != EOK) { 1006 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); 1007 997 ipc_answer_0(rid, rc); 1008 998 return; … … 1010 1000 1011 1001 /* Do some simple sanity checks on the file system. */ 1012 rc = fat_sanity_check(bs, dev _handle);1013 if (rc != EOK) { 1014 (void) block_cache_fini(dev _handle);1015 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); 1016 1006 ipc_answer_0(rid, rc); 1017 1007 return; 1018 1008 } 1019 1009 1020 rc = fat_idx_init_by_dev _handle(dev_handle);1021 if (rc != EOK) { 1022 (void) block_cache_fini(dev _handle);1023 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); 1024 1014 ipc_answer_0(rid, rc); 1025 1015 return; … … 1029 1019 fs_node_t *rfn = (fs_node_t *)malloc(sizeof(fs_node_t)); 1030 1020 if (!rfn) { 1031 (void) block_cache_fini(dev _handle);1032 block_fini(dev _handle);1033 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); 1034 1024 ipc_answer_0(rid, ENOMEM); 1035 1025 return; … … 1039 1029 if (!rootp) { 1040 1030 free(rfn); 1041 (void) block_cache_fini(dev _handle);1042 block_fini(dev _handle);1043 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); 1044 1034 ipc_answer_0(rid, ENOMEM); 1045 1035 return; … … 1047 1037 fat_node_initialize(rootp); 1048 1038 1049 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); 1050 1040 if (!ridxp) { 1051 1041 free(rfn); 1052 1042 free(rootp); 1053 (void) block_cache_fini(dev _handle);1054 block_fini(dev _handle);1055 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); 1056 1046 ipc_answer_0(rid, ENOMEM); 1057 1047 return; … … 1082 1072 void fat_unmounted(ipc_callid_t rid, ipc_call_t *request) 1083 1073 { 1084 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); 1085 1075 fs_node_t *fn; 1086 1076 fat_node_t *nodep; 1087 1077 int rc; 1088 1078 1089 rc = fat_root_get(&fn, dev _handle);1079 rc = fat_root_get(&fn, devmap_handle); 1090 1080 if (rc != EOK) { 1091 1081 ipc_answer_0(rid, rc); … … 1115 1105 * stop using libblock for this instance. 1116 1106 */ 1117 (void) fat_node_fini_by_dev _handle(dev_handle);1118 fat_idx_fini_by_dev _handle(dev_handle);1119 (void) block_cache_fini(dev _handle);1120 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); 1121 1111 1122 1112 ipc_answer_0(rid, EOK); … … 1135 1125 void fat_read(ipc_callid_t rid, ipc_call_t *request) 1136 1126 { 1137 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); 1138 1128 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1139 1129 aoff64_t pos = … … 1146 1136 int rc; 1147 1137 1148 rc = fat_node_get(&fn, dev _handle, index);1138 rc = fat_node_get(&fn, devmap_handle, index); 1149 1139 if (rc != EOK) { 1150 1140 ipc_answer_0(rid, rc); … … 1166 1156 } 1167 1157 1168 bs = block_bb_get(dev _handle);1158 bs = block_bb_get(devmap_handle); 1169 1159 1170 1160 if (nodep->type == FAT_FILE) { … … 1272 1262 void fat_write(ipc_callid_t rid, ipc_call_t *request) 1273 1263 { 1274 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); 1275 1265 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1276 1266 aoff64_t pos = … … 1285 1275 int rc; 1286 1276 1287 rc = fat_node_get(&fn, dev _handle, index);1277 rc = fat_node_get(&fn, devmap_handle, index); 1288 1278 if (rc != EOK) { 1289 1279 ipc_answer_0(rid, rc); … … 1305 1295 } 1306 1296 1307 bs = block_bb_get(dev _handle);1297 bs = block_bb_get(devmap_handle); 1308 1298 1309 1299 /* … … 1367 1357 nclsts = (ROUND_UP(pos + bytes, BPC(bs)) - boundary) / BPC(bs); 1368 1358 /* create an independent chain of nclsts clusters in all FATs */ 1369 rc = fat_alloc_clusters(bs, dev _handle, nclsts, &mcl, &lcl);1359 rc = fat_alloc_clusters(bs, devmap_handle, nclsts, &mcl, &lcl); 1370 1360 if (rc != EOK) { 1371 1361 /* could not allocate a chain of nclsts clusters */ … … 1378 1368 rc = fat_fill_gap(bs, nodep, mcl, pos); 1379 1369 if (rc != EOK) { 1380 (void) fat_free_clusters(bs, dev _handle, mcl);1370 (void) fat_free_clusters(bs, devmap_handle, mcl); 1381 1371 (void) fat_node_put(fn); 1382 1372 ipc_answer_0(callid, rc); … … 1384 1374 return; 1385 1375 } 1386 rc = _fat_block_get(&b, bs, dev _handle, lcl, NULL,1376 rc = _fat_block_get(&b, bs, devmap_handle, lcl, NULL, 1387 1377 (pos / BPS(bs)) % SPC(bs), flags); 1388 1378 if (rc != EOK) { 1389 (void) fat_free_clusters(bs, dev _handle, mcl);1379 (void) fat_free_clusters(bs, devmap_handle, mcl); 1390 1380 (void) fat_node_put(fn); 1391 1381 ipc_answer_0(callid, rc); … … 1398 1388 rc = block_put(b); 1399 1389 if (rc != EOK) { 1400 (void) fat_free_clusters(bs, dev _handle, mcl);1390 (void) fat_free_clusters(bs, devmap_handle, mcl); 1401 1391 (void) fat_node_put(fn); 1402 1392 ipc_answer_0(rid, rc); … … 1409 1399 rc = fat_append_clusters(bs, nodep, mcl, lcl); 1410 1400 if (rc != EOK) { 1411 (void) fat_free_clusters(bs, dev _handle, mcl);1401 (void) fat_free_clusters(bs, devmap_handle, mcl); 1412 1402 (void) fat_node_put(fn); 1413 1403 ipc_answer_0(rid, rc); … … 1424 1414 void fat_truncate(ipc_callid_t rid, ipc_call_t *request) 1425 1415 { 1426 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); 1427 1417 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1428 1418 aoff64_t size = … … 1433 1423 int rc; 1434 1424 1435 rc = fat_node_get(&fn, dev _handle, index);1425 rc = fat_node_get(&fn, devmap_handle, index); 1436 1426 if (rc != EOK) { 1437 1427 ipc_answer_0(rid, rc); … … 1444 1434 nodep = FAT_NODE(fn); 1445 1435 1446 bs = block_bb_get(dev _handle);1436 bs = block_bb_get(devmap_handle); 1447 1437 1448 1438 if (nodep->size == size) { … … 1471 1461 } else { 1472 1462 fat_cluster_t lastc; 1473 rc = fat_cluster_walk(bs, dev _handle, nodep->firstc,1463 rc = fat_cluster_walk(bs, devmap_handle, nodep->firstc, 1474 1464 &lastc, NULL, (size - 1) / BPC(bs)); 1475 1465 if (rc != EOK) … … 1496 1486 void fat_destroy(ipc_callid_t rid, ipc_call_t *request) 1497 1487 { 1498 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); 1499 1489 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 1500 1490 fs_node_t *fn; 1501 1491 int rc; 1502 1492 1503 rc = fat_node_get(&fn, dev _handle, index);1493 rc = fat_node_get(&fn, devmap_handle, index); 1504 1494 if (rc != EOK) { 1505 1495 ipc_answer_0(rid, rc); … … 1527 1517 void fat_sync(ipc_callid_t rid, ipc_call_t *request) 1528 1518 { 1529 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); 1530 1520 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1531 1521 1532 1522 fs_node_t *fn; 1533 int rc = fat_node_get(&fn, dev _handle, index);1523 int rc = fat_node_get(&fn, devmap_handle, index); 1534 1524 if (rc != EOK) { 1535 1525 ipc_answer_0(rid, rc);
Note:
See TracChangeset
for help on using the changeset viewer.