Changeset 15f3c3f in mainline for uspace/srv/fs
- Timestamp:
- 2011-06-22T22:00:52Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 86ffa27f
- Parents:
- ef09a7a
- Location:
- uspace/srv/fs
- Files:
-
- 9 edited
- 5 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/ext2fs/ext2fs_ops.c
ref09a7a r15f3c3f 43 43 #include <libext2.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> … … 70 70 typedef struct ext2fs_instance { 71 71 link_t link; 72 devmap_handle_t devmap_handle;72 service_id_t service_id; 73 73 ext2_filesystem_t *filesystem; 74 74 unsigned int open_nodes_count; … … 86 86 * Forward declarations of auxiliary functions 87 87 */ 88 static int ext2fs_instance_get( devmap_handle_t, ext2fs_instance_t **);88 static int ext2fs_instance_get(service_id_t, ext2fs_instance_t **); 89 89 static void ext2fs_read_directory(ipc_callid_t, ipc_callid_t, aoff64_t, 90 90 size_t, ext2fs_instance_t *, ext2_inode_ref_t *); … … 98 98 * Forward declarations of EXT2 libfs operations. 99 99 */ 100 static int ext2fs_root_get(fs_node_t **, devmap_handle_t);100 static int ext2fs_root_get(fs_node_t **, service_id_t); 101 101 static int ext2fs_match(fs_node_t **, fs_node_t *, const char *); 102 static int ext2fs_node_get(fs_node_t **, devmap_handle_t, fs_index_t);102 static int ext2fs_node_get(fs_node_t **, service_id_t, fs_index_t); 103 103 static int ext2fs_node_open(fs_node_t *); 104 104 static int ext2fs_node_put(fs_node_t *); 105 static int ext2fs_create_node(fs_node_t **, devmap_handle_t, int);105 static int ext2fs_create_node(fs_node_t **, service_id_t, int); 106 106 static int ext2fs_destroy_node(fs_node_t *); 107 107 static int ext2fs_link(fs_node_t *, fs_node_t *, const char *); … … 114 114 static bool ext2fs_is_directory(fs_node_t *); 115 115 static bool ext2fs_is_file(fs_node_t *node); 116 static devmap_handle_t ext2fs_device_get(fs_node_t *node);116 static service_id_t ext2fs_device_get(fs_node_t *node); 117 117 118 118 /* … … 136 136 ext2fs_node_t *enode = hash_table_get_instance(item, ext2fs_node_t, link); 137 137 assert(keys > 0); 138 if (enode->instance-> devmap_handle!=139 (( devmap_handle_t) key[OPEN_NODES_DEV_HANDLE_KEY])) {138 if (enode->instance->service_id != 139 ((service_id_t) key[OPEN_NODES_DEV_HANDLE_KEY])) { 140 140 return false; 141 141 } … … 182 182 183 183 /** 184 * Find an instance of filesystem for the given devmap_handle184 * Find an instance of filesystem for the given service_id 185 185 */ 186 int ext2fs_instance_get( devmap_handle_t devmap_handle, ext2fs_instance_t **inst)187 { 188 EXT2FS_DBG("(%" PRIun ", -)", devmap_handle);186 int ext2fs_instance_get(service_id_t service_id, ext2fs_instance_t **inst) 187 { 188 EXT2FS_DBG("(%" PRIun ", -)", service_id); 189 189 ext2fs_instance_t *tmp; 190 190 … … 200 200 tmp = list_get_instance(link, ext2fs_instance_t, link); 201 201 202 if (tmp-> devmap_handle == devmap_handle) {202 if (tmp->service_id == service_id) { 203 203 *inst = tmp; 204 204 fibril_mutex_unlock(&instance_list_mutex); … … 215 215 216 216 217 int ext2fs_root_get(fs_node_t **rfn, devmap_handle_t devmap_handle)218 { 219 EXT2FS_DBG("(-, %" PRIun ")", devmap_handle);220 return ext2fs_node_get(rfn, devmap_handle, EXT2_INODE_ROOT_INDEX);217 int ext2fs_root_get(fs_node_t **rfn, service_id_t service_id) 218 { 219 EXT2FS_DBG("(-, %" PRIun ")", service_id); 220 return ext2fs_node_get(rfn, service_id, EXT2_INODE_ROOT_INDEX); 221 221 } 222 222 … … 291 291 292 292 /** Instantiate a EXT2 in-core node. */ 293 int ext2fs_node_get(fs_node_t **rfn, devmap_handle_t devmap_handle, fs_index_t index)294 { 295 EXT2FS_DBG("(-,%" PRIun ",%u)", devmap_handle, index);293 int ext2fs_node_get(fs_node_t **rfn, service_id_t service_id, fs_index_t index) 294 { 295 EXT2FS_DBG("(-,%" PRIun ",%u)", service_id, index); 296 296 297 297 ext2fs_instance_t *inst = NULL; 298 298 int rc; 299 299 300 rc = ext2fs_instance_get( devmap_handle, &inst);300 rc = ext2fs_instance_get(service_id, &inst); 301 301 if (rc != EOK) { 302 302 return rc; … … 319 319 /* Check if the node is not already open */ 320 320 unsigned long key[] = { 321 [OPEN_NODES_DEV_HANDLE_KEY] = inst-> devmap_handle,321 [OPEN_NODES_DEV_HANDLE_KEY] = inst->service_id, 322 322 [OPEN_NODES_INODE_KEY] = index, 323 323 }; … … 413 413 414 414 unsigned long key[] = { 415 [OPEN_NODES_DEV_HANDLE_KEY] = enode->instance-> devmap_handle,415 [OPEN_NODES_DEV_HANDLE_KEY] = enode->instance->service_id, 416 416 [OPEN_NODES_INODE_KEY] = enode->inode_ref->index, 417 417 }; … … 431 431 } 432 432 433 int ext2fs_create_node(fs_node_t **rfn, devmap_handle_t devmap_handle, int flags)433 int ext2fs_create_node(fs_node_t **rfn, service_id_t service_id, int flags) 434 434 { 435 435 EXT2FS_DBG(""); … … 564 564 } 565 565 566 devmap_handle_t ext2fs_device_get(fs_node_t *fn)566 service_id_t ext2fs_device_get(fs_node_t *fn) 567 567 { 568 568 EXT2FS_DBG(""); 569 569 ext2fs_node_t *enode = EXT2FS_NODE(fn); 570 return enode->instance-> devmap_handle;570 return enode->instance->service_id; 571 571 } 572 572 … … 600 600 EXT2FS_DBG(""); 601 601 int rc; 602 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);602 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request); 603 603 ext2_filesystem_t *fs; 604 604 ext2fs_instance_t *inst; … … 632 632 633 633 /* Initialize the filesystem */ 634 rc = ext2_filesystem_init(fs, devmap_handle);634 rc = ext2_filesystem_init(fs, service_id); 635 635 if (rc != EOK) { 636 636 free(fs); … … 662 662 /* Initialize instance */ 663 663 link_initialize(&inst->link); 664 inst-> devmap_handle = devmap_handle;664 inst->service_id = service_id; 665 665 inst->filesystem = fs; 666 666 inst->open_nodes_count = 0; … … 700 700 { 701 701 EXT2FS_DBG(""); 702 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);702 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request); 703 703 ext2fs_instance_t *inst; 704 704 int rc; 705 705 706 rc = ext2fs_instance_get( devmap_handle, &inst);706 rc = ext2fs_instance_get(service_id, &inst); 707 707 708 708 if (rc != EOK) { … … 747 747 { 748 748 EXT2FS_DBG(""); 749 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);749 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request); 750 750 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 751 751 aoff64_t pos = … … 767 767 } 768 768 769 rc = ext2fs_instance_get( devmap_handle, &inst);769 rc = ext2fs_instance_get(service_id, &inst); 770 770 if (rc != EOK) { 771 771 async_answer_0(callid, rc); … … 965 965 966 966 /* Usual case - we need to read a block from device */ 967 rc = block_get(&block, inst-> devmap_handle, fs_block, BLOCK_FLAGS_NONE);967 rc = block_get(&block, inst->service_id, fs_block, BLOCK_FLAGS_NONE); 968 968 if (rc != EOK) { 969 969 async_answer_0(callid, rc); … … 987 987 { 988 988 EXT2FS_DBG(""); 989 // devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);989 // service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request); 990 990 // fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 991 991 // aoff64_t pos = … … 999 999 { 1000 1000 EXT2FS_DBG(""); 1001 // devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);1001 // service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request); 1002 1002 // fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1003 1003 // aoff64_t size = … … 1017 1017 { 1018 1018 EXT2FS_DBG(""); 1019 // devmap_handle_t devmap_handle = (devmap_handle_t)IPC_GET_ARG1(*request);1019 // service_id_t service_id = (service_id_t)IPC_GET_ARG1(*request); 1020 1020 // fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 1021 1021 … … 1039 1039 { 1040 1040 EXT2FS_DBG(""); 1041 // devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);1041 // service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request); 1042 1042 // fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1043 1043 -
uspace/srv/fs/fat/fat.h
ref09a7a r15f3c3f 175 175 176 176 fibril_mutex_t lock; 177 devmap_handle_t devmap_handle;177 service_id_t service_id; 178 178 fs_index_t index; 179 179 /** … … 241 241 extern void fat_sync(ipc_callid_t, ipc_call_t *); 242 242 243 extern int fat_idx_get_new(fat_idx_t **, devmap_handle_t);244 extern fat_idx_t *fat_idx_get_by_pos( devmap_handle_t, fat_cluster_t, unsigned);245 extern fat_idx_t *fat_idx_get_by_index( devmap_handle_t, fs_index_t);243 extern int fat_idx_get_new(fat_idx_t **, service_id_t); 244 extern fat_idx_t *fat_idx_get_by_pos(service_id_t, fat_cluster_t, unsigned); 245 extern fat_idx_t *fat_idx_get_by_index(service_id_t, fs_index_t); 246 246 extern void fat_idx_destroy(fat_idx_t *); 247 247 extern void fat_idx_hashin(fat_idx_t *); … … 250 250 extern int fat_idx_init(void); 251 251 extern void fat_idx_fini(void); 252 extern int fat_idx_init_by_ devmap_handle(devmap_handle_t);253 extern void fat_idx_fini_by_ devmap_handle(devmap_handle_t);252 extern int fat_idx_init_by_service_id(service_id_t); 253 extern void fat_idx_fini_by_service_id(service_id_t); 254 254 255 255 #endif -
uspace/srv/fs/fat/fat_fat.c
ref09a7a r15f3c3f 71 71 * 72 72 * @param bs Buffer holding the boot sector for the file. 73 * @param devmap_handle Device handleof the device with the file.73 * @param service_id Service ID of the device with the file. 74 74 * @param firstc First cluster to start the walk with. 75 75 * @param lastc If non-NULL, output argument hodling the last cluster … … 82 82 */ 83 83 int 84 fat_cluster_walk(fat_bs_t *bs, devmap_handle_t devmap_handle, fat_cluster_t firstc,84 fat_cluster_walk(fat_bs_t *bs, service_id_t service_id, fat_cluster_t firstc, 85 85 fat_cluster_t *lastc, uint16_t *numc, uint16_t max_clusters) 86 86 { … … 109 109 fidx = clst % (BPS(bs) / sizeof(fat_cluster_t)); 110 110 /* read FAT1 */ 111 rc = block_get(&b, devmap_handle, RSCNT(bs) + fsec,111 rc = block_get(&b, service_id, RSCNT(bs) + fsec, 112 112 BLOCK_FLAGS_NONE); 113 113 if (rc != EOK) … … 160 160 * when fortunately we have the last cluster number cached. 161 161 */ 162 return block_get(block, nodep->idx-> devmap_handle,162 return block_get(block, nodep->idx->service_id, 163 163 CLBN2PBN(bs, nodep->lastc_cached_value, bn), flags); 164 164 } … … 174 174 175 175 fall_through: 176 rc = _fat_block_get(block, bs, nodep->idx-> devmap_handle, firstc,176 rc = _fat_block_get(block, bs, nodep->idx->service_id, firstc, 177 177 &currc, relbn, flags); 178 178 if (rc != EOK) … … 193 193 * @param block Pointer to a block pointer for storing result. 194 194 * @param bs Buffer holding the boot sector of the file system. 195 * @param devmap_handle Devicehandle of the file system.195 * @param service_id Service ID handle of the file system. 196 196 * @param fcl First cluster used by the file. Can be zero if the file 197 197 * is empty. … … 205 205 */ 206 206 int 207 _fat_block_get(block_t **block, fat_bs_t *bs, devmap_handle_t devmap_handle,207 _fat_block_get(block_t **block, fat_bs_t *bs, service_id_t service_id, 208 208 fat_cluster_t fcl, fat_cluster_t *clp, aoff64_t bn, int flags) 209 209 { … … 222 222 /* root directory special case */ 223 223 assert(bn < RDS(bs)); 224 rc = block_get(block, devmap_handle,224 rc = block_get(block, service_id, 225 225 RSCNT(bs) + FATCNT(bs) * SF(bs) + bn, flags); 226 226 return rc; … … 228 228 229 229 max_clusters = bn / SPC(bs); 230 rc = fat_cluster_walk(bs, devmap_handle, fcl, &c, &clusters, max_clusters);230 rc = fat_cluster_walk(bs, service_id, fcl, &c, &clusters, max_clusters); 231 231 if (rc != EOK) 232 232 return rc; 233 233 assert(clusters == max_clusters); 234 234 235 rc = block_get(block, devmap_handle, CLBN2PBN(bs, c, bn), flags);235 rc = block_get(block, service_id, CLBN2PBN(bs, c, bn), flags); 236 236 237 237 if (clp) … … 281 281 /* zero out the initial part of the new cluster chain */ 282 282 for (o = boundary; o < pos; o += BPS(bs)) { 283 rc = _fat_block_get(&b, bs, nodep->idx-> devmap_handle, mcl,283 rc = _fat_block_get(&b, bs, nodep->idx->service_id, mcl, 284 284 NULL, (o - boundary) / BPS(bs), BLOCK_FLAGS_NOREAD); 285 285 if (rc != EOK) … … 298 298 * 299 299 * @param bs Buffer holding the boot sector for the file system. 300 * @param devmap_handle Device handlefor the file system.300 * @param service_id Service ID for the file system. 301 301 * @param clst Cluster which to get. 302 302 * @param value Output argument holding the value of the cluster. … … 305 305 */ 306 306 int 307 fat_get_cluster(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned fatno,307 fat_get_cluster(fat_bs_t *bs, service_id_t service_id, unsigned fatno, 308 308 fat_cluster_t clst, fat_cluster_t *value) 309 309 { … … 312 312 int rc; 313 313 314 rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno +314 rc = block_get(&b, service_id, RSCNT(bs) + SF(bs) * fatno + 315 315 (clst * sizeof(fat_cluster_t)) / BPS(bs), BLOCK_FLAGS_NONE); 316 316 if (rc != EOK) … … 327 327 * 328 328 * @param bs Buffer holding the boot sector for the file system. 329 * @param devmap_handle Device handlefor the file system.329 * @param service_id Device service ID for the file system. 330 330 * @param fatno Number of the FAT instance where to make the change. 331 331 * @param clst Cluster which is to be set. … … 335 335 */ 336 336 int 337 fat_set_cluster(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned fatno,337 fat_set_cluster(fat_bs_t *bs, service_id_t service_id, unsigned fatno, 338 338 fat_cluster_t clst, fat_cluster_t value) 339 339 { … … 343 343 344 344 assert(fatno < FATCNT(bs)); 345 rc = block_get(&b, devmap_handle, RSCNT(bs) + SF(bs) * fatno +345 rc = block_get(&b, service_id, RSCNT(bs) + SF(bs) * fatno + 346 346 (clst * sizeof(fat_cluster_t)) / BPS(bs), BLOCK_FLAGS_NONE); 347 347 if (rc != EOK) … … 358 358 * 359 359 * @param bs Buffer holding the boot sector of the file system. 360 * @param devmap_handle Device handleof the file system.360 * @param service_id Service ID of the file system. 361 361 * @param lifo Chain of allocated clusters. 362 362 * @param nclsts Number of clusters in the lifo chain. … … 364 364 * @return EOK on success or a negative error code. 365 365 */ 366 int fat_alloc_shadow_clusters(fat_bs_t *bs, devmap_handle_t devmap_handle,366 int fat_alloc_shadow_clusters(fat_bs_t *bs, service_id_t service_id, 367 367 fat_cluster_t *lifo, unsigned nclsts) 368 368 { … … 373 373 for (fatno = FAT1 + 1; fatno < bs->fatcnt; fatno++) { 374 374 for (c = 0; c < nclsts; c++) { 375 rc = fat_set_cluster(bs, devmap_handle, fatno, lifo[c],375 rc = fat_set_cluster(bs, service_id, fatno, lifo[c], 376 376 c == 0 ? FAT_CLST_LAST1 : lifo[c - 1]); 377 377 if (rc != EOK) … … 391 391 * 392 392 * @param bs Buffer holding the boot sector of the file system. 393 * @param devmap_handle Device handleof the file system.393 * @param service_id Device service ID of the file system. 394 394 * @param nclsts Number of clusters to allocate. 395 395 * @param mcl Output parameter where the first cluster in the chain … … 401 401 */ 402 402 int 403 fat_alloc_clusters(fat_bs_t *bs, devmap_handle_t devmap_handle, unsigned nclsts,403 fat_alloc_clusters(fat_bs_t *bs, service_id_t service_id, unsigned nclsts, 404 404 fat_cluster_t *mcl, fat_cluster_t *lcl) 405 405 { … … 419 419 fibril_mutex_lock(&fat_alloc_lock); 420 420 for (b = 0, cl = 0; b < SF(bs); b++) { 421 rc = block_get(&blk, devmap_handle, RSCNT(bs) + b,421 rc = block_get(&blk, service_id, RSCNT(bs) + b, 422 422 BLOCK_FLAGS_NONE); 423 423 if (rc != EOK) … … 458 458 /* update the shadow copies of FAT */ 459 459 rc = fat_alloc_shadow_clusters(bs, 460 devmap_handle, lifo, nclsts);460 service_id, lifo, nclsts); 461 461 if (rc != EOK) 462 462 goto error; … … 485 485 */ 486 486 while (found--) { 487 rc = fat_set_cluster(bs, devmap_handle, FAT1, lifo[found],487 rc = fat_set_cluster(bs, service_id, FAT1, lifo[found], 488 488 FAT_CLST_RES0); 489 489 if (rc != EOK) { … … 500 500 * 501 501 * @param bs Buffer hodling the boot sector of the file system. 502 * @param devmap_handle Device handleof the file system.502 * @param service_id Device service ID of the file system. 503 503 * @param firstc First cluster in the chain which is to be freed. 504 504 * … … 506 506 */ 507 507 int 508 fat_free_clusters(fat_bs_t *bs, devmap_handle_t devmap_handle, fat_cluster_t firstc)508 fat_free_clusters(fat_bs_t *bs, service_id_t service_id, fat_cluster_t firstc) 509 509 { 510 510 unsigned fatno; … … 515 515 while (firstc < FAT_CLST_LAST1) { 516 516 assert(firstc >= FAT_CLST_FIRST && firstc < FAT_CLST_BAD); 517 rc = fat_get_cluster(bs, devmap_handle, FAT1, firstc, &nextc);517 rc = fat_get_cluster(bs, service_id, FAT1, firstc, &nextc); 518 518 if (rc != EOK) 519 519 return rc; 520 520 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) { 521 rc = fat_set_cluster(bs, devmap_handle, fatno, firstc,521 rc = fat_set_cluster(bs, service_id, fatno, firstc, 522 522 FAT_CLST_RES0); 523 523 if (rc != EOK) … … 544 544 fat_cluster_t lcl) 545 545 { 546 devmap_handle_t devmap_handle = nodep->idx->devmap_handle;546 service_id_t service_id = nodep->idx->service_id; 547 547 fat_cluster_t lastc; 548 548 uint8_t fatno; … … 558 558 nodep->lastc_cached_valid = false; 559 559 } else { 560 rc = fat_cluster_walk(bs, devmap_handle, nodep->firstc,560 rc = fat_cluster_walk(bs, service_id, nodep->firstc, 561 561 &lastc, NULL, (uint16_t) -1); 562 562 if (rc != EOK) … … 565 565 566 566 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) { 567 rc = fat_set_cluster(bs, nodep->idx-> devmap_handle, fatno,567 rc = fat_set_cluster(bs, nodep->idx->service_id, fatno, 568 568 lastc, mcl); 569 569 if (rc != EOK) … … 591 591 { 592 592 int rc; 593 devmap_handle_t devmap_handle = nodep->idx->devmap_handle;593 service_id_t service_id = nodep->idx->service_id; 594 594 595 595 /* … … 602 602 if (lcl == FAT_CLST_RES0) { 603 603 /* The node will have zero size and no clusters allocated. */ 604 rc = fat_free_clusters(bs, devmap_handle, nodep->firstc);604 rc = fat_free_clusters(bs, service_id, nodep->firstc); 605 605 if (rc != EOK) 606 606 return rc; … … 611 611 unsigned fatno; 612 612 613 rc = fat_get_cluster(bs, devmap_handle, FAT1, lcl, &nextc);613 rc = fat_get_cluster(bs, service_id, FAT1, lcl, &nextc); 614 614 if (rc != EOK) 615 615 return rc; … … 617 617 /* Terminate the cluster chain in all copies of FAT. */ 618 618 for (fatno = FAT1; fatno < bs->fatcnt; fatno++) { 619 rc = fat_set_cluster(bs, devmap_handle, fatno, lcl,619 rc = fat_set_cluster(bs, service_id, fatno, lcl, 620 620 FAT_CLST_LAST1); 621 621 if (rc != EOK) … … 624 624 625 625 /* Free all following clusters. */ 626 rc = fat_free_clusters(bs, devmap_handle, nextc);626 rc = fat_free_clusters(bs, service_id, nextc); 627 627 if (rc != EOK) 628 628 return rc; … … 639 639 640 640 int 641 fat_zero_cluster(struct fat_bs *bs, devmap_handle_t devmap_handle, fat_cluster_t c)641 fat_zero_cluster(struct fat_bs *bs, service_id_t service_id, fat_cluster_t c) 642 642 { 643 643 int i; … … 646 646 647 647 for (i = 0; i < SPC(bs); i++) { 648 rc = _fat_block_get(&b, bs, devmap_handle, c, NULL, i,648 rc = _fat_block_get(&b, bs, service_id, c, NULL, i, 649 649 BLOCK_FLAGS_NOREAD); 650 650 if (rc != EOK) … … 666 666 * does not contain a fat file system. 667 667 */ 668 int fat_sanity_check(fat_bs_t *bs, devmap_handle_t devmap_handle)668 int fat_sanity_check(fat_bs_t *bs, service_id_t service_id) 669 669 { 670 670 fat_cluster_t e0, e1; … … 707 707 708 708 for (fat_no = 0; fat_no < bs->fatcnt; fat_no++) { 709 rc = fat_get_cluster(bs, devmap_handle, fat_no, 0, &e0);709 rc = fat_get_cluster(bs, service_id, fat_no, 0, &e0); 710 710 if (rc != EOK) 711 711 return EIO; 712 712 713 rc = fat_get_cluster(bs, devmap_handle, fat_no, 1, &e1);713 rc = fat_get_cluster(bs, service_id, fat_no, 1, &e1); 714 714 if (rc != EOK) 715 715 return EIO; -
uspace/srv/fs/fat/fat_fat.h
ref09a7a r15f3c3f 61 61 #define fat_clusters_get(numc, bs, dh, fc) \ 62 62 fat_cluster_walk((bs), (dh), (fc), NULL, (numc), (uint16_t) -1) 63 extern int fat_cluster_walk(struct fat_bs *, devmap_handle_t, fat_cluster_t,63 extern int fat_cluster_walk(struct fat_bs *, service_id_t, fat_cluster_t, 64 64 fat_cluster_t *, uint16_t *, uint16_t); 65 65 66 66 extern int fat_block_get(block_t **, struct fat_bs *, struct fat_node *, 67 67 aoff64_t, int); 68 extern int _fat_block_get(block_t **, struct fat_bs *, devmap_handle_t,68 extern int _fat_block_get(block_t **, struct fat_bs *, service_id_t, 69 69 fat_cluster_t, fat_cluster_t *, aoff64_t, int); 70 70 … … 73 73 extern int fat_chop_clusters(struct fat_bs *, struct fat_node *, 74 74 fat_cluster_t); 75 extern int fat_alloc_clusters(struct fat_bs *, devmap_handle_t, unsigned,75 extern int fat_alloc_clusters(struct fat_bs *, service_id_t, unsigned, 76 76 fat_cluster_t *, fat_cluster_t *); 77 extern int fat_free_clusters(struct fat_bs *, devmap_handle_t, fat_cluster_t);78 extern int fat_alloc_shadow_clusters(struct fat_bs *, devmap_handle_t,77 extern int fat_free_clusters(struct fat_bs *, service_id_t, fat_cluster_t); 78 extern int fat_alloc_shadow_clusters(struct fat_bs *, service_id_t, 79 79 fat_cluster_t *, unsigned); 80 extern int fat_get_cluster(struct fat_bs *, devmap_handle_t, unsigned,80 extern int fat_get_cluster(struct fat_bs *, service_id_t, unsigned, 81 81 fat_cluster_t, fat_cluster_t *); 82 extern int fat_set_cluster(struct fat_bs *, devmap_handle_t, unsigned,82 extern int fat_set_cluster(struct fat_bs *, service_id_t, unsigned, 83 83 fat_cluster_t, fat_cluster_t); 84 84 extern int fat_fill_gap(struct fat_bs *, struct fat_node *, fat_cluster_t, 85 85 aoff64_t); 86 extern int fat_zero_cluster(struct fat_bs *, devmap_handle_t, fat_cluster_t);87 extern int fat_sanity_check(struct fat_bs *, devmap_handle_t);86 extern int fat_zero_cluster(struct fat_bs *, service_id_t, fat_cluster_t); 87 extern int fat_sanity_check(struct fat_bs *, service_id_t); 88 88 89 89 #endif -
uspace/srv/fs/fat/fat_idx.c
ref09a7a r15f3c3f 59 59 typedef struct { 60 60 link_t link; 61 devmap_handle_t devmap_handle;61 service_id_t service_id; 62 62 63 63 /** Next unassigned index. */ … … 76 76 static LIST_INITIALIZE(unused_list); 77 77 78 static void unused_initialize(unused_t *u, devmap_handle_t devmap_handle)78 static void unused_initialize(unused_t *u, service_id_t service_id) 79 79 { 80 80 link_initialize(&u->link); 81 u-> devmap_handle = devmap_handle;81 u->service_id = service_id; 82 82 u->next = 0; 83 83 u->remaining = ((uint64_t)((fs_index_t)-1)) + 1; … … 85 85 } 86 86 87 static unused_t *unused_find( devmap_handle_t devmap_handle, bool lock)87 static unused_t *unused_find(service_id_t service_id, bool lock) 88 88 { 89 89 unused_t *u; … … 94 94 list_foreach(unused_list, l) { 95 95 u = list_get_instance(l, unused_t, link); 96 if (u-> devmap_handle == devmap_handle)96 if (u->service_id == service_id) 97 97 return u; 98 98 } … … 108 108 /** 109 109 * Global hash table of all used fat_idx_t structures. 110 * The index structures are hashed by the devmap_handle, parent node's first110 * The index structures are hashed by the service_id, parent node's first 111 111 * cluster and index within the parent directory. 112 112 */ … … 122 122 static hash_index_t pos_hash(unsigned long key[]) 123 123 { 124 devmap_handle_t devmap_handle = (devmap_handle_t)key[UPH_DH_KEY];124 service_id_t service_id = (service_id_t)key[UPH_DH_KEY]; 125 125 fat_cluster_t pfc = (fat_cluster_t)key[UPH_PFC_KEY]; 126 126 unsigned pdi = (unsigned)key[UPH_PDI_KEY]; … … 142 142 h |= (pdi & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) << 143 143 (UPH_BUCKETS_LOG / 2); 144 h |= ( devmap_handle& ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) <<144 h |= (service_id & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) << 145 145 (3 * (UPH_BUCKETS_LOG / 4)); 146 146 … … 150 150 static int pos_compare(unsigned long key[], hash_count_t keys, link_t *item) 151 151 { 152 devmap_handle_t devmap_handle = (devmap_handle_t)key[UPH_DH_KEY];152 service_id_t service_id = (service_id_t)key[UPH_DH_KEY]; 153 153 fat_cluster_t pfc; 154 154 unsigned pdi; … … 157 157 switch (keys) { 158 158 case 1: 159 return ( devmap_handle == fidx->devmap_handle);159 return (service_id == fidx->service_id); 160 160 case 3: 161 161 pfc = (fat_cluster_t) key[UPH_PFC_KEY]; 162 162 pdi = (unsigned) key[UPH_PDI_KEY]; 163 return ( devmap_handle == fidx->devmap_handle) && (pfc == fidx->pfc) &&163 return (service_id == fidx->service_id) && (pfc == fidx->pfc) && 164 164 (pdi == fidx->pdi); 165 165 default: … … 183 183 /** 184 184 * Global hash table of all used fat_idx_t structures. 185 * The index structures are hashed by the devmap_handleand index.185 * The index structures are hashed by the service_id and index. 186 186 */ 187 187 static hash_table_t ui_hash; … … 195 195 static hash_index_t idx_hash(unsigned long key[]) 196 196 { 197 devmap_handle_t devmap_handle = (devmap_handle_t)key[UIH_DH_KEY];197 service_id_t service_id = (service_id_t)key[UIH_DH_KEY]; 198 198 fs_index_t index = (fs_index_t)key[UIH_INDEX_KEY]; 199 199 200 200 hash_index_t h; 201 201 202 h = devmap_handle& ((1 << (UIH_BUCKETS_LOG / 2)) - 1);202 h = service_id & ((1 << (UIH_BUCKETS_LOG / 2)) - 1); 203 203 h |= (index & ((1 << (UIH_BUCKETS_LOG / 2)) - 1)) << 204 204 (UIH_BUCKETS_LOG / 2); … … 209 209 static int idx_compare(unsigned long key[], hash_count_t keys, link_t *item) 210 210 { 211 devmap_handle_t devmap_handle = (devmap_handle_t)key[UIH_DH_KEY];211 service_id_t service_id = (service_id_t)key[UIH_DH_KEY]; 212 212 fs_index_t index; 213 213 fat_idx_t *fidx = list_get_instance(item, fat_idx_t, uih_link); … … 215 215 switch (keys) { 216 216 case 1: 217 return ( devmap_handle == fidx->devmap_handle);217 return (service_id == fidx->service_id); 218 218 case 2: 219 219 index = (fs_index_t) key[UIH_INDEX_KEY]; 220 return ( devmap_handle == fidx->devmap_handle) &&220 return (service_id == fidx->service_id) && 221 221 (index == fidx->index); 222 222 default: … … 241 241 242 242 /** Allocate a VFS index which is not currently in use. */ 243 static bool fat_index_alloc( devmap_handle_t devmap_handle, fs_index_t *index)243 static bool fat_index_alloc(service_id_t service_id, fs_index_t *index) 244 244 { 245 245 unused_t *u; 246 246 247 247 assert(index); 248 u = unused_find( devmap_handle, true);248 u = unused_find(service_id, true); 249 249 if (!u) 250 250 return false; … … 303 303 304 304 /** Free a VFS index, which is no longer in use. */ 305 static void fat_index_free( devmap_handle_t devmap_handle, fs_index_t index)305 static void fat_index_free(service_id_t service_id, fs_index_t index) 306 306 { 307 307 unused_t *u; 308 308 309 u = unused_find( devmap_handle, true);309 u = unused_find(service_id, true); 310 310 assert(u); 311 311 … … 365 365 } 366 366 367 static int fat_idx_create(fat_idx_t **fidxp, devmap_handle_t devmap_handle)367 static int fat_idx_create(fat_idx_t **fidxp, service_id_t service_id) 368 368 { 369 369 fat_idx_t *fidx; … … 372 372 if (!fidx) 373 373 return ENOMEM; 374 if (!fat_index_alloc( devmap_handle, &fidx->index)) {374 if (!fat_index_alloc(service_id, &fidx->index)) { 375 375 free(fidx); 376 376 return ENOSPC; … … 380 380 link_initialize(&fidx->uih_link); 381 381 fibril_mutex_initialize(&fidx->lock); 382 fidx-> devmap_handle = devmap_handle;382 fidx->service_id = service_id; 383 383 fidx->pfc = FAT_CLST_RES0; /* no parent yet */ 384 384 fidx->pdi = 0; … … 389 389 } 390 390 391 int fat_idx_get_new(fat_idx_t **fidxp, devmap_handle_t devmap_handle)391 int fat_idx_get_new(fat_idx_t **fidxp, service_id_t service_id) 392 392 { 393 393 fat_idx_t *fidx; … … 395 395 396 396 fibril_mutex_lock(&used_lock); 397 rc = fat_idx_create(&fidx, devmap_handle);397 rc = fat_idx_create(&fidx, service_id); 398 398 if (rc != EOK) { 399 399 fibril_mutex_unlock(&used_lock); … … 402 402 403 403 unsigned long ikey[] = { 404 [UIH_DH_KEY] = devmap_handle,404 [UIH_DH_KEY] = service_id, 405 405 [UIH_INDEX_KEY] = fidx->index, 406 406 }; … … 415 415 416 416 fat_idx_t * 417 fat_idx_get_by_pos( devmap_handle_t devmap_handle, fat_cluster_t pfc, unsigned pdi)417 fat_idx_get_by_pos(service_id_t service_id, fat_cluster_t pfc, unsigned pdi) 418 418 { 419 419 fat_idx_t *fidx; 420 420 link_t *l; 421 421 unsigned long pkey[] = { 422 [UPH_DH_KEY] = devmap_handle,422 [UPH_DH_KEY] = service_id, 423 423 [UPH_PFC_KEY] = pfc, 424 424 [UPH_PDI_KEY] = pdi, … … 432 432 int rc; 433 433 434 rc = fat_idx_create(&fidx, devmap_handle);434 rc = fat_idx_create(&fidx, service_id); 435 435 if (rc != EOK) { 436 436 fibril_mutex_unlock(&used_lock); … … 439 439 440 440 unsigned long ikey[] = { 441 [UIH_DH_KEY] = devmap_handle,441 [UIH_DH_KEY] = service_id, 442 442 [UIH_INDEX_KEY] = fidx->index, 443 443 }; … … 458 458 { 459 459 unsigned long pkey[] = { 460 [UPH_DH_KEY] = idx-> devmap_handle,460 [UPH_DH_KEY] = idx->service_id, 461 461 [UPH_PFC_KEY] = idx->pfc, 462 462 [UPH_PDI_KEY] = idx->pdi, … … 471 471 { 472 472 unsigned long pkey[] = { 473 [UPH_DH_KEY] = idx-> devmap_handle,473 [UPH_DH_KEY] = idx->service_id, 474 474 [UPH_PFC_KEY] = idx->pfc, 475 475 [UPH_PDI_KEY] = idx->pdi, … … 482 482 483 483 fat_idx_t * 484 fat_idx_get_by_index( devmap_handle_t devmap_handle, fs_index_t index)484 fat_idx_get_by_index(service_id_t service_id, fs_index_t index) 485 485 { 486 486 fat_idx_t *fidx = NULL; 487 487 link_t *l; 488 488 unsigned long ikey[] = { 489 [UIH_DH_KEY] = devmap_handle,489 [UIH_DH_KEY] = service_id, 490 490 [UIH_INDEX_KEY] = index, 491 491 }; … … 509 509 { 510 510 unsigned long ikey[] = { 511 [UIH_DH_KEY] = idx-> devmap_handle,511 [UIH_DH_KEY] = idx->service_id, 512 512 [UIH_INDEX_KEY] = idx->index, 513 513 }; 514 devmap_handle_t devmap_handle = idx->devmap_handle;514 service_id_t service_id = idx->service_id; 515 515 fs_index_t index = idx->index; 516 516 … … 526 526 fibril_mutex_unlock(&used_lock); 527 527 /* Release the VFS index. */ 528 fat_index_free( devmap_handle, index);528 fat_index_free(service_id, index); 529 529 /* The index structure itself is freed in idx_remove_callback(). */ 530 530 } … … 548 548 } 549 549 550 int fat_idx_init_by_ devmap_handle(devmap_handle_t devmap_handle)550 int fat_idx_init_by_service_id(service_id_t service_id) 551 551 { 552 552 unused_t *u; … … 556 556 if (!u) 557 557 return ENOMEM; 558 unused_initialize(u, devmap_handle);558 unused_initialize(u, service_id); 559 559 fibril_mutex_lock(&unused_lock); 560 if (!unused_find( devmap_handle, false)) {560 if (!unused_find(service_id, false)) { 561 561 list_append(&u->link, &unused_list); 562 562 } else { … … 568 568 } 569 569 570 void fat_idx_fini_by_ devmap_handle(devmap_handle_t devmap_handle)570 void fat_idx_fini_by_service_id(service_id_t service_id) 571 571 { 572 572 unsigned long ikey[] = { 573 [UIH_DH_KEY] = devmap_handle573 [UIH_DH_KEY] = service_id 574 574 }; 575 575 unsigned long pkey[] = { 576 [UPH_DH_KEY] = devmap_handle576 [UPH_DH_KEY] = service_id 577 577 }; 578 578 … … 590 590 * Free the unused and freed structures for this instance. 591 591 */ 592 unused_t *u = unused_find( devmap_handle, true);592 unused_t *u = unused_find(service_id, true); 593 593 assert(u); 594 594 list_remove(&u->link); -
uspace/srv/fs/fat/fat_ops.c
ref09a7a r15f3c3f 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 *); … … 88 88 static bool fat_is_directory(fs_node_t *); 89 89 static bool fat_is_file(fs_node_t *node); 90 static devmap_handle_t fat_device_get(fs_node_t *node);90 static service_id_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-> devmap_handle);122 bs = block_bb_get(node->idx->service_id); 123 123 124 124 /* Read the block that contains the dentry of interest. */ 125 rc = _fat_block_get(&b, bs, node->idx-> devmap_handle, node->idx->pfc,125 rc = _fat_block_get(&b, bs, node->idx->service_id, 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_ devmap_handle(devmap_handle_t devmap_handle)147 static int fat_node_fini_by_service_id(service_id_t service_id) 148 148 { 149 149 fat_node_t *nodep; … … 169 169 goto restart; 170 170 } 171 if (nodep->idx-> devmap_handle != devmap_handle) {171 if (nodep->idx->service_id != service_id) { 172 172 fibril_mutex_unlock(&nodep->idx->lock); 173 173 fibril_mutex_unlock(&nodep->lock); … … 299 299 return rc; 300 300 301 bs = block_bb_get(idxp-> devmap_handle);301 bs = block_bb_get(idxp->service_id); 302 302 303 303 /* Read the block that contains the dentry of interest. */ 304 rc = _fat_block_get(&b, bs, idxp-> devmap_handle, idxp->pfc, NULL,304 rc = _fat_block_get(&b, bs, idxp->service_id, 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-> devmap_handle,325 rc = fat_clusters_get(&clusters, bs, idxp->service_id, 326 326 uint16_t_le2host(d->firstc)); 327 327 if (rc != EOK) { … … 357 357 */ 358 358 359 int fat_root_get(fs_node_t **rfn, devmap_handle_t devmap_handle)360 { 361 return fat_node_get(rfn, devmap_handle, 0);359 int fat_root_get(fs_node_t **rfn, service_id_t service_id) 360 { 361 return fat_node_get(rfn, service_id, 0); 362 362 } 363 363 … … 370 370 unsigned blocks; 371 371 fat_dentry_t *d; 372 devmap_handle_t devmap_handle;372 service_id_t service_id; 373 373 block_t *b; 374 374 int rc; 375 375 376 376 fibril_mutex_lock(&parentp->idx->lock); 377 devmap_handle = parentp->idx->devmap_handle;377 service_id = parentp->idx->service_id; 378 378 fibril_mutex_unlock(&parentp->idx->lock); 379 379 380 bs = block_bb_get( devmap_handle);380 bs = block_bb_get(service_id); 381 381 blocks = parentp->size / BPS(bs); 382 382 for (i = 0; i < blocks; i++) { … … 403 403 /* hit */ 404 404 fat_node_t *nodep; 405 fat_idx_t *idx = fat_idx_get_by_pos( devmap_handle,405 fat_idx_t *idx = fat_idx_get_by_pos(service_id, 406 406 parentp->firstc, i * DPS(bs) + j); 407 407 if (!idx) { … … 436 436 437 437 /** Instantiate a FAT in-core node. */ 438 int fat_node_get(fs_node_t **rfn, devmap_handle_t devmap_handle, fs_index_t index)438 int fat_node_get(fs_node_t **rfn, service_id_t service_id, fs_index_t index) 439 439 { 440 440 fat_node_t *nodep; … … 442 442 int rc; 443 443 444 idxp = fat_idx_get_by_index( devmap_handle, index);444 idxp = fat_idx_get_by_index(service_id, index); 445 445 if (!idxp) { 446 446 *rfn = NULL; … … 493 493 } 494 494 495 int fat_create_node(fs_node_t **rfn, devmap_handle_t devmap_handle, int flags)495 int fat_create_node(fs_node_t **rfn, service_id_t service_id, int flags) 496 496 { 497 497 fat_idx_t *idxp; … … 501 501 int rc; 502 502 503 bs = block_bb_get( devmap_handle);503 bs = block_bb_get(service_id); 504 504 if (flags & L_DIRECTORY) { 505 505 /* allocate a cluster */ 506 rc = fat_alloc_clusters(bs, devmap_handle, 1, &mcl, &lcl);506 rc = fat_alloc_clusters(bs, service_id, 1, &mcl, &lcl); 507 507 if (rc != EOK) 508 508 return rc; 509 509 /* populate the new cluster with unused dentries */ 510 rc = fat_zero_cluster(bs, devmap_handle, mcl);510 rc = fat_zero_cluster(bs, service_id, mcl); 511 511 if (rc != EOK) { 512 (void) fat_free_clusters(bs, devmap_handle, mcl);512 (void) fat_free_clusters(bs, service_id, mcl); 513 513 return rc; 514 514 } … … 517 517 rc = fat_node_get_new(&nodep); 518 518 if (rc != EOK) { 519 (void) fat_free_clusters(bs, devmap_handle, mcl);519 (void) fat_free_clusters(bs, service_id, mcl); 520 520 return rc; 521 521 } 522 rc = fat_idx_get_new(&idxp, devmap_handle);523 if (rc != EOK) { 524 (void) fat_free_clusters(bs, devmap_handle, mcl);522 rc = fat_idx_get_new(&idxp, service_id); 523 if (rc != EOK) { 524 (void) fat_free_clusters(bs, service_id, mcl); 525 525 (void) fat_node_put(FS_NODE(nodep)); 526 526 return rc; … … 571 571 assert(!has_children); 572 572 573 bs = block_bb_get(nodep->idx-> devmap_handle);573 bs = block_bb_get(nodep->idx->service_id); 574 574 if (nodep->firstc != FAT_CLST_RES0) { 575 575 assert(nodep->size); 576 576 /* Free all clusters allocated to the node. */ 577 rc = fat_free_clusters(bs, nodep->idx-> devmap_handle,577 rc = fat_free_clusters(bs, nodep->idx->service_id, 578 578 nodep->firstc); 579 579 } … … 621 621 622 622 fibril_mutex_lock(&parentp->idx->lock); 623 bs = block_bb_get(parentp->idx-> devmap_handle);623 bs = block_bb_get(parentp->idx->service_id); 624 624 625 625 blocks = parentp->size / BPS(bs); … … 660 660 return ENOSPC; 661 661 } 662 rc = fat_alloc_clusters(bs, parentp->idx-> devmap_handle, 1, &mcl, &lcl);662 rc = fat_alloc_clusters(bs, parentp->idx->service_id, 1, &mcl, &lcl); 663 663 if (rc != EOK) { 664 664 fibril_mutex_unlock(&parentp->idx->lock); 665 665 return rc; 666 666 } 667 rc = fat_zero_cluster(bs, parentp->idx-> devmap_handle, mcl);668 if (rc != EOK) { 669 (void) fat_free_clusters(bs, parentp->idx-> devmap_handle, mcl);667 rc = fat_zero_cluster(bs, parentp->idx->service_id, mcl); 668 if (rc != EOK) { 669 (void) fat_free_clusters(bs, parentp->idx->service_id, mcl); 670 670 fibril_mutex_unlock(&parentp->idx->lock); 671 671 return rc; … … 673 673 rc = fat_append_clusters(bs, parentp, mcl, lcl); 674 674 if (rc != EOK) { 675 (void) fat_free_clusters(bs, parentp->idx-> devmap_handle, mcl);675 (void) fat_free_clusters(bs, parentp->idx->service_id, mcl); 676 676 fibril_mutex_unlock(&parentp->idx->lock); 677 677 return rc; … … 790 790 assert(childp->lnkcnt == 1); 791 791 fibril_mutex_lock(&childp->idx->lock); 792 bs = block_bb_get(childp->idx-> devmap_handle);793 794 rc = _fat_block_get(&b, bs, childp->idx-> devmap_handle, childp->idx->pfc,792 bs = block_bb_get(childp->idx->service_id); 793 794 rc = _fat_block_get(&b, bs, childp->idx->service_id, childp->idx->pfc, 795 795 NULL, (childp->idx->pdi * sizeof(fat_dentry_t)) / BPS(bs), 796 796 BLOCK_FLAGS_NONE); … … 842 842 843 843 fibril_mutex_lock(&nodep->idx->lock); 844 bs = block_bb_get(nodep->idx-> devmap_handle);844 bs = block_bb_get(nodep->idx->service_id); 845 845 846 846 blocks = nodep->size / BPS(bs); … … 916 916 } 917 917 918 devmap_handle_t fat_device_get(fs_node_t *node)918 service_id_t fat_device_get(fs_node_t *node) 919 919 { 920 920 return 0; … … 948 948 void fat_mounted(ipc_callid_t rid, ipc_call_t *request) 949 949 { 950 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);950 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request); 951 951 enum cache_mode cmode; 952 952 fat_bs_t *bs; … … 970 970 971 971 /* initialize libblock */ 972 rc = block_init(EXCHANGE_SERIALIZE, devmap_handle, BS_SIZE);972 rc = block_init(EXCHANGE_SERIALIZE, service_id, BS_SIZE); 973 973 if (rc != EOK) { 974 974 async_answer_0(rid, rc); … … 977 977 978 978 /* prepare the boot block */ 979 rc = block_bb_read( devmap_handle, BS_BLOCK);980 if (rc != EOK) { 981 block_fini( devmap_handle);979 rc = block_bb_read(service_id, BS_BLOCK); 980 if (rc != EOK) { 981 block_fini(service_id); 982 982 async_answer_0(rid, rc); 983 983 return; … … 985 985 986 986 /* get the buffer with the boot sector */ 987 bs = block_bb_get( devmap_handle);987 bs = block_bb_get(service_id); 988 988 989 989 if (BPS(bs) != BS_SIZE) { 990 block_fini( devmap_handle);990 block_fini(service_id); 991 991 async_answer_0(rid, ENOTSUP); 992 992 return; … … 994 994 995 995 /* Initialize the block cache */ 996 rc = block_cache_init( devmap_handle, BPS(bs), 0 /* XXX */, cmode);997 if (rc != EOK) { 998 block_fini( devmap_handle);996 rc = block_cache_init(service_id, BPS(bs), 0 /* XXX */, cmode); 997 if (rc != EOK) { 998 block_fini(service_id); 999 999 async_answer_0(rid, rc); 1000 1000 return; … … 1002 1002 1003 1003 /* Do some simple sanity checks on the file system. */ 1004 rc = fat_sanity_check(bs, devmap_handle);1005 if (rc != EOK) { 1006 (void) block_cache_fini( devmap_handle);1007 block_fini( devmap_handle);1004 rc = fat_sanity_check(bs, service_id); 1005 if (rc != EOK) { 1006 (void) block_cache_fini(service_id); 1007 block_fini(service_id); 1008 1008 async_answer_0(rid, rc); 1009 1009 return; 1010 1010 } 1011 1011 1012 rc = fat_idx_init_by_ devmap_handle(devmap_handle);1013 if (rc != EOK) { 1014 (void) block_cache_fini( devmap_handle);1015 block_fini( devmap_handle);1012 rc = fat_idx_init_by_service_id(service_id); 1013 if (rc != EOK) { 1014 (void) block_cache_fini(service_id); 1015 block_fini(service_id); 1016 1016 async_answer_0(rid, rc); 1017 1017 return; … … 1021 1021 fs_node_t *rfn = (fs_node_t *)malloc(sizeof(fs_node_t)); 1022 1022 if (!rfn) { 1023 (void) block_cache_fini( devmap_handle);1024 block_fini( devmap_handle);1025 fat_idx_fini_by_ devmap_handle(devmap_handle);1023 (void) block_cache_fini(service_id); 1024 block_fini(service_id); 1025 fat_idx_fini_by_service_id(service_id); 1026 1026 async_answer_0(rid, ENOMEM); 1027 1027 return; … … 1031 1031 if (!rootp) { 1032 1032 free(rfn); 1033 (void) block_cache_fini( devmap_handle);1034 block_fini( devmap_handle);1035 fat_idx_fini_by_ devmap_handle(devmap_handle);1033 (void) block_cache_fini(service_id); 1034 block_fini(service_id); 1035 fat_idx_fini_by_service_id(service_id); 1036 1036 async_answer_0(rid, ENOMEM); 1037 1037 return; … … 1039 1039 fat_node_initialize(rootp); 1040 1040 1041 fat_idx_t *ridxp = fat_idx_get_by_pos( devmap_handle, FAT_CLST_ROOTPAR, 0);1041 fat_idx_t *ridxp = fat_idx_get_by_pos(service_id, FAT_CLST_ROOTPAR, 0); 1042 1042 if (!ridxp) { 1043 1043 free(rfn); 1044 1044 free(rootp); 1045 (void) block_cache_fini( devmap_handle);1046 block_fini( devmap_handle);1047 fat_idx_fini_by_ devmap_handle(devmap_handle);1045 (void) block_cache_fini(service_id); 1046 block_fini(service_id); 1047 fat_idx_fini_by_service_id(service_id); 1048 1048 async_answer_0(rid, ENOMEM); 1049 1049 return; … … 1074 1074 void fat_unmounted(ipc_callid_t rid, ipc_call_t *request) 1075 1075 { 1076 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);1076 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request); 1077 1077 fs_node_t *fn; 1078 1078 fat_node_t *nodep; 1079 1079 int rc; 1080 1080 1081 rc = fat_root_get(&fn, devmap_handle);1081 rc = fat_root_get(&fn, service_id); 1082 1082 if (rc != EOK) { 1083 1083 async_answer_0(rid, rc); … … 1107 1107 * stop using libblock for this instance. 1108 1108 */ 1109 (void) fat_node_fini_by_ devmap_handle(devmap_handle);1110 fat_idx_fini_by_ devmap_handle(devmap_handle);1111 (void) block_cache_fini( devmap_handle);1112 block_fini( devmap_handle);1109 (void) fat_node_fini_by_service_id(service_id); 1110 fat_idx_fini_by_service_id(service_id); 1111 (void) block_cache_fini(service_id); 1112 block_fini(service_id); 1113 1113 1114 1114 async_answer_0(rid, EOK); … … 1127 1127 void fat_read(ipc_callid_t rid, ipc_call_t *request) 1128 1128 { 1129 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);1129 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request); 1130 1130 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1131 1131 aoff64_t pos = … … 1138 1138 int rc; 1139 1139 1140 rc = fat_node_get(&fn, devmap_handle, index);1140 rc = fat_node_get(&fn, service_id, index); 1141 1141 if (rc != EOK) { 1142 1142 async_answer_0(rid, rc); … … 1158 1158 } 1159 1159 1160 bs = block_bb_get( devmap_handle);1160 bs = block_bb_get(service_id); 1161 1161 1162 1162 if (nodep->type == FAT_FILE) { … … 1264 1264 void fat_write(ipc_callid_t rid, ipc_call_t *request) 1265 1265 { 1266 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);1266 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request); 1267 1267 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1268 1268 aoff64_t pos = … … 1277 1277 int rc; 1278 1278 1279 rc = fat_node_get(&fn, devmap_handle, index);1279 rc = fat_node_get(&fn, service_id, index); 1280 1280 if (rc != EOK) { 1281 1281 async_answer_0(rid, rc); … … 1297 1297 } 1298 1298 1299 bs = block_bb_get( devmap_handle);1299 bs = block_bb_get(service_id); 1300 1300 1301 1301 /* … … 1359 1359 nclsts = (ROUND_UP(pos + bytes, BPC(bs)) - boundary) / BPC(bs); 1360 1360 /* create an independent chain of nclsts clusters in all FATs */ 1361 rc = fat_alloc_clusters(bs, devmap_handle, nclsts, &mcl, &lcl);1361 rc = fat_alloc_clusters(bs, service_id, nclsts, &mcl, &lcl); 1362 1362 if (rc != EOK) { 1363 1363 /* could not allocate a chain of nclsts clusters */ … … 1370 1370 rc = fat_fill_gap(bs, nodep, mcl, pos); 1371 1371 if (rc != EOK) { 1372 (void) fat_free_clusters(bs, devmap_handle, mcl);1372 (void) fat_free_clusters(bs, service_id, mcl); 1373 1373 (void) fat_node_put(fn); 1374 1374 async_answer_0(callid, rc); … … 1376 1376 return; 1377 1377 } 1378 rc = _fat_block_get(&b, bs, devmap_handle, lcl, NULL,1378 rc = _fat_block_get(&b, bs, service_id, lcl, NULL, 1379 1379 (pos / BPS(bs)) % SPC(bs), flags); 1380 1380 if (rc != EOK) { 1381 (void) fat_free_clusters(bs, devmap_handle, mcl);1381 (void) fat_free_clusters(bs, service_id, mcl); 1382 1382 (void) fat_node_put(fn); 1383 1383 async_answer_0(callid, rc); … … 1390 1390 rc = block_put(b); 1391 1391 if (rc != EOK) { 1392 (void) fat_free_clusters(bs, devmap_handle, mcl);1392 (void) fat_free_clusters(bs, service_id, mcl); 1393 1393 (void) fat_node_put(fn); 1394 1394 async_answer_0(rid, rc); … … 1401 1401 rc = fat_append_clusters(bs, nodep, mcl, lcl); 1402 1402 if (rc != EOK) { 1403 (void) fat_free_clusters(bs, devmap_handle, mcl);1403 (void) fat_free_clusters(bs, service_id, mcl); 1404 1404 (void) fat_node_put(fn); 1405 1405 async_answer_0(rid, rc); … … 1416 1416 void fat_truncate(ipc_callid_t rid, ipc_call_t *request) 1417 1417 { 1418 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);1418 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request); 1419 1419 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1420 1420 aoff64_t size = … … 1425 1425 int rc; 1426 1426 1427 rc = fat_node_get(&fn, devmap_handle, index);1427 rc = fat_node_get(&fn, service_id, index); 1428 1428 if (rc != EOK) { 1429 1429 async_answer_0(rid, rc); … … 1436 1436 nodep = FAT_NODE(fn); 1437 1437 1438 bs = block_bb_get( devmap_handle);1438 bs = block_bb_get(service_id); 1439 1439 1440 1440 if (nodep->size == size) { … … 1463 1463 } else { 1464 1464 fat_cluster_t lastc; 1465 rc = fat_cluster_walk(bs, devmap_handle, nodep->firstc,1465 rc = fat_cluster_walk(bs, service_id, nodep->firstc, 1466 1466 &lastc, NULL, (size - 1) / BPC(bs)); 1467 1467 if (rc != EOK) … … 1488 1488 void fat_destroy(ipc_callid_t rid, ipc_call_t *request) 1489 1489 { 1490 devmap_handle_t devmap_handle = (devmap_handle_t)IPC_GET_ARG1(*request);1490 service_id_t service_id = (service_id_t)IPC_GET_ARG1(*request); 1491 1491 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 1492 1492 fs_node_t *fn; … … 1494 1494 int rc; 1495 1495 1496 rc = fat_node_get(&fn, devmap_handle, index);1496 rc = fat_node_get(&fn, service_id, index); 1497 1497 if (rc != EOK) { 1498 1498 async_answer_0(rid, rc); … … 1527 1527 void fat_sync(ipc_callid_t rid, ipc_call_t *request) 1528 1528 { 1529 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);1529 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request); 1530 1530 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 1531 1531 1532 1532 fs_node_t *fn; 1533 int rc = fat_node_get(&fn, devmap_handle, index);1533 int rc = fat_node_get(&fn, service_id, index); 1534 1534 if (rc != EOK) { 1535 1535 async_answer_0(rid, rc); -
uspace/srv/fs/locfs/Makefile
ref09a7a r15f3c3f 31 31 LIBS = $(LIBFS_PREFIX)/libfs.a 32 32 EXTRA_CFLAGS += -I$(LIBFS_PREFIX) 33 BINARY = devfs33 BINARY = locfs 34 34 STATIC_NEEDED = y 35 35 36 36 SOURCES = \ 37 devfs.c \38 devfs_ops.c37 locfs.c \ 38 locfs_ops.c 39 39 40 40 include $(USPACE_PREFIX)/Makefile.common -
uspace/srv/fs/locfs/locfs.c
ref09a7a r15f3c3f 32 32 33 33 /** 34 * @file devfs.c35 * @brief Devicesfile system.34 * @file locfs.c 35 * @brief Location-service file system. 36 36 * 37 * Every device registered to device mapperis represented as a file in this37 * Every service registered with location service is represented as a file in this 38 38 * file system. 39 39 */ … … 46 46 #include <task.h> 47 47 #include <libfs.h> 48 #include " devfs.h"49 #include " devfs_ops.h"48 #include "locfs.h" 49 #include "locfs_ops.h" 50 50 51 #define NAME " devfs"51 #define NAME "locfs" 52 52 53 static vfs_info_t devfs_vfs_info = {53 static vfs_info_t locfs_vfs_info = { 54 54 .name = NAME, 55 55 .concurrent_read_write = false, … … 57 57 }; 58 58 59 fs_reg_t devfs_reg;59 fs_reg_t locfs_reg; 60 60 61 static void devfs_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg)61 static void locfs_connection(ipc_callid_t iid, ipc_call_t *icall, void *arg) 62 62 { 63 63 if (iid) … … 73 73 switch (IPC_GET_IMETHOD(call)) { 74 74 case VFS_OUT_MOUNTED: 75 devfs_mounted(callid, &call);75 locfs_mounted(callid, &call); 76 76 break; 77 77 case VFS_OUT_MOUNT: 78 devfs_mount(callid, &call);78 locfs_mount(callid, &call); 79 79 break; 80 80 case VFS_OUT_UNMOUNTED: 81 devfs_unmounted(callid, &call);81 locfs_unmounted(callid, &call); 82 82 break; 83 83 case VFS_OUT_UNMOUNT: 84 devfs_unmount(callid, &call);84 locfs_unmount(callid, &call); 85 85 break; 86 86 case VFS_OUT_LOOKUP: 87 devfs_lookup(callid, &call);87 locfs_lookup(callid, &call); 88 88 break; 89 89 case VFS_OUT_OPEN_NODE: 90 devfs_open_node(callid, &call);90 locfs_open_node(callid, &call); 91 91 break; 92 92 case VFS_OUT_STAT: 93 devfs_stat(callid, &call);93 locfs_stat(callid, &call); 94 94 break; 95 95 case VFS_OUT_READ: 96 devfs_read(callid, &call);96 locfs_read(callid, &call); 97 97 break; 98 98 case VFS_OUT_WRITE: 99 devfs_write(callid, &call);99 locfs_write(callid, &call); 100 100 break; 101 101 case VFS_OUT_TRUNCATE: 102 devfs_truncate(callid, &call);102 locfs_truncate(callid, &call); 103 103 break; 104 104 case VFS_OUT_CLOSE: 105 devfs_close(callid, &call);105 locfs_close(callid, &call); 106 106 break; 107 107 case VFS_OUT_SYNC: 108 devfs_sync(callid, &call);108 locfs_sync(callid, &call); 109 109 break; 110 110 case VFS_OUT_DESTROY: 111 devfs_destroy(callid, &call);111 locfs_destroy(callid, &call); 112 112 break; 113 113 default: … … 122 122 printf("%s: HelenOS Device Filesystem\n", NAME); 123 123 124 if (! devfs_init()) {125 printf("%s: failed to initialize devfs\n", NAME);124 if (!locfs_init()) { 125 printf("%s: failed to initialize locfs\n", NAME); 126 126 return -1; 127 127 } … … 134 134 } 135 135 136 int rc = fs_register(vfs_sess, & devfs_reg, &devfs_vfs_info,137 devfs_connection);136 int rc = fs_register(vfs_sess, &locfs_reg, &locfs_vfs_info, 137 locfs_connection); 138 138 if (rc != EOK) { 139 139 printf("%s: Failed to register file system (%d)\n", NAME, rc); -
uspace/srv/fs/locfs/locfs.h
ref09a7a r15f3c3f 31 31 */ 32 32 33 #ifndef DEVFS_DEVFS_H_34 #define DEVFS_DEVFS_H_33 #ifndef LOCFS_LOCFS_H_ 34 #define LOCFS_LOCFS_H_ 35 35 36 36 #include <libfs.h> 37 37 38 extern fs_reg_t devfs_reg;38 extern fs_reg_t locfs_reg; 39 39 40 40 #endif -
uspace/srv/fs/locfs/locfs_ops.c
ref09a7a r15f3c3f 32 32 33 33 /** 34 * @file devfs_ops.c35 * @brief Implementation of VFS operations for the devfs file system server.34 * @file locfs_ops.c 35 * @brief Implementation of VFS operations for the locfs file system server. 36 36 */ 37 37 … … 44 44 #include <fibril_synch.h> 45 45 #include <adt/hash_table.h> 46 #include <ipc/ devmap.h>46 #include <ipc/loc.h> 47 47 #include <sys/stat.h> 48 48 #include <libfs.h> 49 49 #include <assert.h> 50 #include " devfs.h"51 #include " devfs_ops.h"50 #include "locfs.h" 51 #include "locfs_ops.h" 52 52 53 53 typedef struct { 54 devmap_handle_type_t type;55 devmap_handle_t handle;56 } devfs_node_t;57 58 /** Opened devices structure */54 loc_object_type_t type; 55 service_id_t service_id; 56 } locfs_node_t; 57 58 /** Opened services structure */ 59 59 typedef struct { 60 devmap_handle_t handle;60 service_id_t service_id; 61 61 async_sess_t *sess; /**< If NULL, the structure is incomplete. */ 62 62 size_t refcount; 63 63 link_t link; 64 64 fibril_condvar_t cv; /**< Broadcast when completed. */ 65 } device_t;66 67 /** Hash table of opened devices */68 static hash_table_t devices;65 } service_t; 66 67 /** Hash table of opened services */ 68 static hash_table_t services; 69 69 70 70 /** Hash table mutex */ 71 static FIBRIL_MUTEX_INITIALIZE( devices_mutex);72 73 #define DEVICES_KEYS 174 #define DEVICES_KEY_HANDLE 075 #define DEVICES_BUCKETS 25671 static FIBRIL_MUTEX_INITIALIZE(services_mutex); 72 73 #define SERVICES_KEYS 1 74 #define SERVICES_KEY_HANDLE 0 75 #define SERVICES_BUCKETS 256 76 76 77 77 /* Implementation of hash table interface for the nodes hash table. */ 78 static hash_index_t devices_hash(unsigned long key[])79 { 80 return key[ DEVICES_KEY_HANDLE] % DEVICES_BUCKETS;81 } 82 83 static int devices_compare(unsigned long key[], hash_count_t keys, link_t *item)84 { 85 device_t *dev = hash_table_get_instance(item, device_t, link);86 return (dev-> handle == (devmap_handle_t) key[DEVICES_KEY_HANDLE]);87 } 88 89 static void devices_remove_callback(link_t *item)90 { 91 free(hash_table_get_instance(item, device_t, link));92 } 93 94 static hash_table_operations_t devices_ops = {95 .hash = devices_hash,96 .compare = devices_compare,97 .remove_callback = devices_remove_callback78 static hash_index_t services_hash(unsigned long key[]) 79 { 80 return key[SERVICES_KEY_HANDLE] % SERVICES_BUCKETS; 81 } 82 83 static int services_compare(unsigned long key[], hash_count_t keys, link_t *item) 84 { 85 service_t *dev = hash_table_get_instance(item, service_t, link); 86 return (dev->service_id == (service_id_t) key[SERVICES_KEY_HANDLE]); 87 } 88 89 static void services_remove_callback(link_t *item) 90 { 91 free(hash_table_get_instance(item, service_t, link)); 92 } 93 94 static hash_table_operations_t services_ops = { 95 .hash = services_hash, 96 .compare = services_compare, 97 .remove_callback = services_remove_callback 98 98 }; 99 99 100 static int devfs_node_get_internal(fs_node_t **rfn, devmap_handle_type_t type,101 devmap_handle_t handle)102 { 103 devfs_node_t *node = (devfs_node_t *) malloc(sizeof(devfs_node_t));100 static int locfs_node_get_internal(fs_node_t **rfn, loc_object_type_t type, 101 service_id_t service_id) 102 { 103 locfs_node_t *node = (locfs_node_t *) malloc(sizeof(locfs_node_t)); 104 104 if (node == NULL) { 105 105 *rfn = NULL; … … 116 116 fs_node_initialize(*rfn); 117 117 node->type = type; 118 node-> handle = handle;118 node->service_id = service_id; 119 119 120 120 (*rfn)->data = node; … … 122 122 } 123 123 124 static int devfs_root_get(fs_node_t **rfn, devmap_handle_t devmap_handle)125 { 126 return devfs_node_get_internal(rfn, DEV_HANDLE_NONE, 0);127 } 128 129 static int devfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component)130 { 131 devfs_node_t *node = (devfs_node_t *) pfn->data;124 static int locfs_root_get(fs_node_t **rfn, service_id_t service_id) 125 { 126 return locfs_node_get_internal(rfn, LOC_OBJECT_NONE, 0); 127 } 128 129 static int locfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component) 130 { 131 locfs_node_t *node = (locfs_node_t *) pfn->data; 132 132 int ret; 133 133 134 if (node-> handle== 0) {134 if (node->service_id == 0) { 135 135 /* Root directory */ 136 136 137 dev_desc_t *devs;138 size_t count = devmap_get_namespaces(&devs);137 loc_sdesc_t *nspaces; 138 size_t count = loc_get_namespaces(&nspaces); 139 139 140 140 if (count > 0) { … … 142 142 for (pos = 0; pos < count; pos++) { 143 143 /* Ignore root namespace */ 144 if (str_cmp( devs[pos].name, "") == 0)144 if (str_cmp(nspaces[pos].name, "") == 0) 145 145 continue; 146 146 147 if (str_cmp( devs[pos].name, component) == 0) {148 ret = devfs_node_get_internal(rfn, DEV_HANDLE_NAMESPACE, devs[pos].handle);149 free( devs);147 if (str_cmp(nspaces[pos].name, component) == 0) { 148 ret = locfs_node_get_internal(rfn, LOC_OBJECT_NAMESPACE, nspaces[pos].id); 149 free(nspaces); 150 150 return ret; 151 151 } 152 152 } 153 153 154 free( devs);154 free(nspaces); 155 155 } 156 156 157 157 /* Search root namespace */ 158 devmap_handle_t namespace; 159 if (devmap_namespace_get_handle("", &namespace, 0) == EOK) { 160 count = devmap_get_devices(namespace, &devs); 158 service_id_t namespace; 159 loc_sdesc_t *svcs; 160 if (loc_namespace_get_id("", &namespace, 0) == EOK) { 161 count = loc_get_services(namespace, &svcs); 161 162 162 163 if (count > 0) { 163 164 size_t pos; 164 165 for (pos = 0; pos < count; pos++) { 165 if (str_cmp( devs[pos].name, component) == 0) {166 ret = devfs_node_get_internal(rfn, DEV_HANDLE_DEVICE, devs[pos].handle);167 free( devs);166 if (str_cmp(svcs[pos].name, component) == 0) { 167 ret = locfs_node_get_internal(rfn, LOC_OBJECT_SERVICE, svcs[pos].id); 168 free(svcs); 168 169 return ret; 169 170 } 170 171 } 171 172 172 free( devs);173 free(svcs); 173 174 } 174 175 } … … 178 179 } 179 180 180 if (node->type == DEV_HANDLE_NAMESPACE) {181 if (node->type == LOC_OBJECT_NAMESPACE) { 181 182 /* Namespace directory */ 182 183 183 dev_desc_t *devs;184 size_t count = devmap_get_devices(node->handle, &devs);184 loc_sdesc_t *svcs; 185 size_t count = loc_get_services(node->service_id, &svcs); 185 186 if (count > 0) { 186 187 size_t pos; 187 188 for (pos = 0; pos < count; pos++) { 188 if (str_cmp( devs[pos].name, component) == 0) {189 ret = devfs_node_get_internal(rfn, DEV_HANDLE_DEVICE, devs[pos].handle);190 free( devs);189 if (str_cmp(svcs[pos].name, component) == 0) { 190 ret = locfs_node_get_internal(rfn, LOC_OBJECT_SERVICE, svcs[pos].id); 191 free(svcs); 191 192 return ret; 192 193 } 193 194 } 194 195 195 free( devs);196 free(svcs); 196 197 } 197 198 … … 204 205 } 205 206 206 static int devfs_node_get(fs_node_t **rfn, devmap_handle_t devmap_handle, fs_index_t index)207 { 208 return devfs_node_get_internal(rfn, devmap_handle_probe(index), index);209 } 210 211 static int devfs_node_open(fs_node_t *fn)212 { 213 devfs_node_t *node = (devfs_node_t *) fn->data;214 215 if (node-> handle== 0) {207 static int locfs_node_get(fs_node_t **rfn, service_id_t service_id, fs_index_t index) 208 { 209 return locfs_node_get_internal(rfn, loc_id_probe(index), index); 210 } 211 212 static int locfs_node_open(fs_node_t *fn) 213 { 214 locfs_node_t *node = (locfs_node_t *) fn->data; 215 216 if (node->service_id == 0) { 216 217 /* Root directory */ 217 218 return EOK; 218 219 } 219 220 220 devmap_handle_type_t type = devmap_handle_probe(node->handle);221 222 if (type == DEV_HANDLE_NAMESPACE) {221 loc_object_type_t type = loc_id_probe(node->service_id); 222 223 if (type == LOC_OBJECT_NAMESPACE) { 223 224 /* Namespace directory */ 224 225 return EOK; 225 226 } 226 227 227 if (type == DEV_HANDLE_DEVICE) {228 if (type == LOC_OBJECT_SERVICE) { 228 229 /* Device node */ 229 230 230 231 unsigned long key[] = { 231 [ DEVICES_KEY_HANDLE] = (unsigned long) node->handle232 [SERVICES_KEY_HANDLE] = (unsigned long) node->service_id 232 233 }; 233 234 link_t *lnk; 234 235 235 fibril_mutex_lock(& devices_mutex);236 fibril_mutex_lock(&services_mutex); 236 237 restart: 237 lnk = hash_table_find(& devices, key);238 lnk = hash_table_find(&services, key); 238 239 if (lnk == NULL) { 239 device_t *dev = (device_t *) malloc(sizeof(device_t));240 service_t *dev = (service_t *) malloc(sizeof(service_t)); 240 241 if (dev == NULL) { 241 fibril_mutex_unlock(& devices_mutex);242 fibril_mutex_unlock(&services_mutex); 242 243 return ENOMEM; 243 244 } 244 245 245 dev-> handle = node->handle;246 dev->service_id = node->service_id; 246 247 247 248 /* Mark as incomplete */ … … 255 256 * below. 256 257 */ 257 hash_table_insert(& devices, key, &dev->link);258 hash_table_insert(&services, key, &dev->link); 258 259 259 260 /* 260 * Drop the mutex to allow recursive devfs requests.261 * Drop the mutex to allow recursive locfs requests. 261 262 */ 262 fibril_mutex_unlock(& devices_mutex);263 264 async_sess_t *sess = devmap_device_connect(EXCHANGE_SERIALIZE,265 node->handle, 0);266 267 fibril_mutex_lock(& devices_mutex);263 fibril_mutex_unlock(&services_mutex); 264 265 async_sess_t *sess = loc_service_connect( 266 EXCHANGE_SERIALIZE, node->service_id, 0); 267 268 fibril_mutex_lock(&services_mutex); 268 269 269 270 /* … … 278 279 * entry and free the device structure. 279 280 */ 280 hash_table_remove(& devices, key, DEVICES_KEYS);281 fibril_mutex_unlock(& devices_mutex);281 hash_table_remove(&services, key, SERVICES_KEYS); 282 fibril_mutex_unlock(&services_mutex); 282 283 283 284 return ENOENT; … … 287 288 dev->sess = sess; 288 289 } else { 289 device_t *dev = hash_table_get_instance(lnk, device_t, link);290 service_t *dev = hash_table_get_instance(lnk, service_t, link); 290 291 291 292 if (!dev->sess) { … … 297 298 * fibril_condvar_wait(). 298 299 */ 299 fibril_condvar_wait(&dev->cv, & devices_mutex);300 fibril_condvar_wait(&dev->cv, &services_mutex); 300 301 goto restart; 301 302 } … … 304 305 } 305 306 306 fibril_mutex_unlock(& devices_mutex);307 fibril_mutex_unlock(&services_mutex); 307 308 308 309 return EOK; … … 312 313 } 313 314 314 static int devfs_node_put(fs_node_t *fn)315 static int locfs_node_put(fs_node_t *fn) 315 316 { 316 317 free(fn->data); … … 319 320 } 320 321 321 static int devfs_create_node(fs_node_t **rfn, devmap_handle_t devmap_handle, int lflag)322 static int locfs_create_node(fs_node_t **rfn, service_id_t service_id, int lflag) 322 323 { 323 324 assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY)); … … 327 328 } 328 329 329 static int devfs_destroy_node(fs_node_t *fn)330 static int locfs_destroy_node(fs_node_t *fn) 330 331 { 331 332 return ENOTSUP; 332 333 } 333 334 334 static int devfs_link_node(fs_node_t *pfn, fs_node_t *cfn, const char *nm)335 static int locfs_link_node(fs_node_t *pfn, fs_node_t *cfn, const char *nm) 335 336 { 336 337 return ENOTSUP; 337 338 } 338 339 339 static int devfs_unlink_node(fs_node_t *pfn, fs_node_t *cfn, const char *nm)340 static int locfs_unlink_node(fs_node_t *pfn, fs_node_t *cfn, const char *nm) 340 341 { 341 342 return ENOTSUP; 342 343 } 343 344 344 static int devfs_has_children(bool *has_children, fs_node_t *fn)345 { 346 devfs_node_t *node = (devfs_node_t *) fn->data;347 348 if (node-> handle== 0) {349 size_t count = devmap_count_namespaces();345 static int locfs_has_children(bool *has_children, fs_node_t *fn) 346 { 347 locfs_node_t *node = (locfs_node_t *) fn->data; 348 349 if (node->service_id == 0) { 350 size_t count = loc_count_namespaces(); 350 351 if (count > 0) { 351 352 *has_children = true; … … 354 355 355 356 /* Root namespace */ 356 devmap_handle_t namespace;357 if ( devmap_namespace_get_handle("", &namespace, 0) == EOK) {358 count = devmap_count_devices(namespace);357 service_id_t namespace; 358 if (loc_namespace_get_id("", &namespace, 0) == EOK) { 359 count = loc_count_services(namespace); 359 360 if (count > 0) { 360 361 *has_children = true; … … 367 368 } 368 369 369 if (node->type == DEV_HANDLE_NAMESPACE) {370 size_t count = devmap_count_devices(node->handle);370 if (node->type == LOC_OBJECT_NAMESPACE) { 371 size_t count = loc_count_services(node->service_id); 371 372 if (count > 0) { 372 373 *has_children = true; … … 382 383 } 383 384 384 static fs_index_t devfs_index_get(fs_node_t *fn)385 { 386 devfs_node_t *node = (devfs_node_t *) fn->data;387 return node-> handle;388 } 389 390 static aoff64_t devfs_size_get(fs_node_t *fn)385 static fs_index_t locfs_index_get(fs_node_t *fn) 386 { 387 locfs_node_t *node = (locfs_node_t *) fn->data; 388 return node->service_id; 389 } 390 391 static aoff64_t locfs_size_get(fs_node_t *fn) 391 392 { 392 393 return 0; 393 394 } 394 395 395 static unsigned int devfs_lnkcnt_get(fs_node_t *fn)396 { 397 devfs_node_t *node = (devfs_node_t *) fn->data;398 399 if (node-> handle== 0)396 static unsigned int locfs_lnkcnt_get(fs_node_t *fn) 397 { 398 locfs_node_t *node = (locfs_node_t *) fn->data; 399 400 if (node->service_id == 0) 400 401 return 0; 401 402 … … 403 404 } 404 405 405 static char devfs_plb_get_char(unsigned pos)406 { 407 return devfs_reg.plb_ro[pos % PLB_SIZE];408 } 409 410 static bool devfs_is_directory(fs_node_t *fn)411 { 412 devfs_node_t *node = (devfs_node_t *) fn->data;413 414 return ((node->type == DEV_HANDLE_NONE) || (node->type == DEV_HANDLE_NAMESPACE));415 } 416 417 static bool devfs_is_file(fs_node_t *fn)418 { 419 devfs_node_t *node = (devfs_node_t *) fn->data;420 421 return (node->type == DEV_HANDLE_DEVICE);422 } 423 424 static devmap_handle_t devfs_device_get(fs_node_t *fn)425 { 426 devfs_node_t *node = (devfs_node_t *) fn->data;427 428 if (node->type == DEV_HANDLE_DEVICE)429 return node-> handle;406 static char locfs_plb_get_char(unsigned pos) 407 { 408 return locfs_reg.plb_ro[pos % PLB_SIZE]; 409 } 410 411 static bool locfs_is_directory(fs_node_t *fn) 412 { 413 locfs_node_t *node = (locfs_node_t *) fn->data; 414 415 return ((node->type == LOC_OBJECT_NONE) || (node->type == LOC_OBJECT_NAMESPACE)); 416 } 417 418 static bool locfs_is_file(fs_node_t *fn) 419 { 420 locfs_node_t *node = (locfs_node_t *) fn->data; 421 422 return (node->type == LOC_OBJECT_SERVICE); 423 } 424 425 static service_id_t locfs_device_get(fs_node_t *fn) 426 { 427 locfs_node_t *node = (locfs_node_t *) fn->data; 428 429 if (node->type == LOC_OBJECT_SERVICE) 430 return node->service_id; 430 431 431 432 return 0; … … 433 434 434 435 /** libfs operations */ 435 libfs_ops_t devfs_libfs_ops = {436 .root_get = devfs_root_get,437 .match = devfs_match,438 .node_get = devfs_node_get,439 .node_open = devfs_node_open,440 .node_put = devfs_node_put,441 .create = devfs_create_node,442 .destroy = devfs_destroy_node,443 .link = devfs_link_node,444 .unlink = devfs_unlink_node,445 .has_children = devfs_has_children,446 .index_get = devfs_index_get,447 .size_get = devfs_size_get,448 .lnkcnt_get = devfs_lnkcnt_get,449 .plb_get_char = devfs_plb_get_char,450 .is_directory = devfs_is_directory,451 .is_file = devfs_is_file,452 .device_get = devfs_device_get436 libfs_ops_t locfs_libfs_ops = { 437 .root_get = locfs_root_get, 438 .match = locfs_match, 439 .node_get = locfs_node_get, 440 .node_open = locfs_node_open, 441 .node_put = locfs_node_put, 442 .create = locfs_create_node, 443 .destroy = locfs_destroy_node, 444 .link = locfs_link_node, 445 .unlink = locfs_unlink_node, 446 .has_children = locfs_has_children, 447 .index_get = locfs_index_get, 448 .size_get = locfs_size_get, 449 .lnkcnt_get = locfs_lnkcnt_get, 450 .plb_get_char = locfs_plb_get_char, 451 .is_directory = locfs_is_directory, 452 .is_file = locfs_is_file, 453 .device_get = locfs_device_get 453 454 }; 454 455 455 bool devfs_init(void)456 { 457 if (!hash_table_create(& devices, DEVICES_BUCKETS,458 DEVICES_KEYS, &devices_ops))456 bool locfs_init(void) 457 { 458 if (!hash_table_create(&services, SERVICES_BUCKETS, 459 SERVICES_KEYS, &services_ops)) 459 460 return false; 460 461 … … 462 463 } 463 464 464 void devfs_mounted(ipc_callid_t rid, ipc_call_t *request)465 void locfs_mounted(ipc_callid_t rid, ipc_call_t *request) 465 466 { 466 467 char *opts; … … 478 479 } 479 480 480 void devfs_mount(ipc_callid_t rid, ipc_call_t *request)481 { 482 libfs_mount(& devfs_libfs_ops, devfs_reg.fs_handle, rid, request);483 } 484 485 void devfs_unmounted(ipc_callid_t rid, ipc_call_t *request)481 void locfs_mount(ipc_callid_t rid, ipc_call_t *request) 482 { 483 libfs_mount(&locfs_libfs_ops, locfs_reg.fs_handle, rid, request); 484 } 485 486 void locfs_unmounted(ipc_callid_t rid, ipc_call_t *request) 486 487 { 487 488 async_answer_0(rid, ENOTSUP); 488 489 } 489 490 490 void devfs_unmount(ipc_callid_t rid, ipc_call_t *request)491 { 492 libfs_unmount(& devfs_libfs_ops, rid, request);493 } 494 495 void devfs_lookup(ipc_callid_t rid, ipc_call_t *request)496 { 497 libfs_lookup(& devfs_libfs_ops, devfs_reg.fs_handle, rid, request);498 } 499 500 void devfs_open_node(ipc_callid_t rid, ipc_call_t *request)501 { 502 libfs_open_node(& devfs_libfs_ops, devfs_reg.fs_handle, rid, request);503 } 504 505 void devfs_stat(ipc_callid_t rid, ipc_call_t *request)506 { 507 libfs_stat(& devfs_libfs_ops, devfs_reg.fs_handle, rid, request);508 } 509 510 void devfs_read(ipc_callid_t rid, ipc_call_t *request)491 void locfs_unmount(ipc_callid_t rid, ipc_call_t *request) 492 { 493 libfs_unmount(&locfs_libfs_ops, rid, request); 494 } 495 496 void locfs_lookup(ipc_callid_t rid, ipc_call_t *request) 497 { 498 libfs_lookup(&locfs_libfs_ops, locfs_reg.fs_handle, rid, request); 499 } 500 501 void locfs_open_node(ipc_callid_t rid, ipc_call_t *request) 502 { 503 libfs_open_node(&locfs_libfs_ops, locfs_reg.fs_handle, rid, request); 504 } 505 506 void locfs_stat(ipc_callid_t rid, ipc_call_t *request) 507 { 508 libfs_stat(&locfs_libfs_ops, locfs_reg.fs_handle, rid, request); 509 } 510 511 void locfs_read(ipc_callid_t rid, ipc_call_t *request) 511 512 { 512 513 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); … … 523 524 } 524 525 525 dev_desc_t *desc;526 size_t count = devmap_get_namespaces(&desc);526 loc_sdesc_t *desc; 527 size_t count = loc_get_namespaces(&desc); 527 528 528 529 /* Get rid of root namespace */ … … 548 549 549 550 /* Search root namespace */ 550 devmap_handle_t namespace;551 if ( devmap_namespace_get_handle("", &namespace, 0) == EOK) {552 count = devmap_get_devices(namespace, &desc);551 service_id_t namespace; 552 if (loc_namespace_get_id("", &namespace, 0) == EOK) { 553 count = loc_get_services(namespace, &desc); 553 554 554 555 if (pos < count) { … … 567 568 } 568 569 569 devmap_handle_type_t type = devmap_handle_probe(index);570 571 if (type == DEV_HANDLE_NAMESPACE) {570 loc_object_type_t type = loc_id_probe(index); 571 572 if (type == LOC_OBJECT_NAMESPACE) { 572 573 /* Namespace directory */ 573 574 ipc_callid_t callid; … … 579 580 } 580 581 581 dev_desc_t *desc;582 size_t count = devmap_get_devices(index, &desc);582 loc_sdesc_t *desc; 583 size_t count = loc_get_services(index, &desc); 583 584 584 585 if (pos < count) { … … 595 596 } 596 597 597 if (type == DEV_HANDLE_DEVICE) {598 if (type == LOC_OBJECT_SERVICE) { 598 599 /* Device node */ 599 600 600 601 unsigned long key[] = { 601 [ DEVICES_KEY_HANDLE] = (unsigned long) index602 [SERVICES_KEY_HANDLE] = (unsigned long) index 602 603 }; 603 604 604 fibril_mutex_lock(& devices_mutex);605 link_t *lnk = hash_table_find(& devices, key);605 fibril_mutex_lock(&services_mutex); 606 link_t *lnk = hash_table_find(&services, key); 606 607 if (lnk == NULL) { 607 fibril_mutex_unlock(& devices_mutex);608 fibril_mutex_unlock(&services_mutex); 608 609 async_answer_0(rid, ENOENT); 609 610 return; 610 611 } 611 612 612 device_t *dev = hash_table_get_instance(lnk, device_t, link);613 service_t *dev = hash_table_get_instance(lnk, service_t, link); 613 614 assert(dev->sess); 614 615 615 616 ipc_callid_t callid; 616 617 if (!async_data_read_receive(&callid, NULL)) { 617 fibril_mutex_unlock(& devices_mutex);618 fibril_mutex_unlock(&services_mutex); 618 619 async_answer_0(callid, EINVAL); 619 620 async_answer_0(rid, EINVAL); … … 634 635 async_exchange_end(exch); 635 636 636 fibril_mutex_unlock(& devices_mutex);637 fibril_mutex_unlock(&services_mutex); 637 638 638 639 /* Wait for reply from the driver. */ … … 649 650 } 650 651 651 void devfs_write(ipc_callid_t rid, ipc_call_t *request)652 void locfs_write(ipc_callid_t rid, ipc_call_t *request) 652 653 { 653 654 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); … … 657 658 } 658 659 659 devmap_handle_type_t type = devmap_handle_probe(index);660 661 if (type == DEV_HANDLE_NAMESPACE) {660 loc_object_type_t type = loc_id_probe(index); 661 662 if (type == LOC_OBJECT_NAMESPACE) { 662 663 /* Namespace directory */ 663 664 async_answer_0(rid, ENOTSUP); … … 665 666 } 666 667 667 if (type == DEV_HANDLE_DEVICE) {668 if (type == LOC_OBJECT_SERVICE) { 668 669 /* Device node */ 669 670 unsigned long key[] = { 670 [ DEVICES_KEY_HANDLE] = (unsigned long) index671 [SERVICES_KEY_HANDLE] = (unsigned long) index 671 672 }; 672 673 673 fibril_mutex_lock(& devices_mutex);674 link_t *lnk = hash_table_find(& devices, key);674 fibril_mutex_lock(&services_mutex); 675 link_t *lnk = hash_table_find(&services, key); 675 676 if (lnk == NULL) { 676 fibril_mutex_unlock(& devices_mutex);677 fibril_mutex_unlock(&services_mutex); 677 678 async_answer_0(rid, ENOENT); 678 679 return; 679 680 } 680 681 681 device_t *dev = hash_table_get_instance(lnk, device_t, link);682 service_t *dev = hash_table_get_instance(lnk, service_t, link); 682 683 assert(dev->sess); 683 684 684 685 ipc_callid_t callid; 685 686 if (!async_data_write_receive(&callid, NULL)) { 686 fibril_mutex_unlock(& devices_mutex);687 fibril_mutex_unlock(&services_mutex); 687 688 async_answer_0(callid, EINVAL); 688 689 async_answer_0(rid, EINVAL); … … 703 704 async_exchange_end(exch); 704 705 705 fibril_mutex_unlock(& devices_mutex);706 fibril_mutex_unlock(&services_mutex); 706 707 707 708 /* Wait for reply from the driver. */ … … 718 719 } 719 720 720 void devfs_truncate(ipc_callid_t rid, ipc_call_t *request)721 void locfs_truncate(ipc_callid_t rid, ipc_call_t *request) 721 722 { 722 723 async_answer_0(rid, ENOTSUP); 723 724 } 724 725 725 void devfs_close(ipc_callid_t rid, ipc_call_t *request)726 void locfs_close(ipc_callid_t rid, ipc_call_t *request) 726 727 { 727 728 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); … … 732 733 } 733 734 734 devmap_handle_type_t type = devmap_handle_probe(index);735 736 if (type == DEV_HANDLE_NAMESPACE) {735 loc_object_type_t type = loc_id_probe(index); 736 737 if (type == LOC_OBJECT_NAMESPACE) { 737 738 /* Namespace directory */ 738 739 async_answer_0(rid, EOK); … … 740 741 } 741 742 742 if (type == DEV_HANDLE_DEVICE) {743 if (type == LOC_OBJECT_SERVICE) { 743 744 unsigned long key[] = { 744 [ DEVICES_KEY_HANDLE] = (unsigned long) index745 [SERVICES_KEY_HANDLE] = (unsigned long) index 745 746 }; 746 747 747 fibril_mutex_lock(& devices_mutex);748 link_t *lnk = hash_table_find(& devices, key);748 fibril_mutex_lock(&services_mutex); 749 link_t *lnk = hash_table_find(&services, key); 749 750 if (lnk == NULL) { 750 fibril_mutex_unlock(& devices_mutex);751 fibril_mutex_unlock(&services_mutex); 751 752 async_answer_0(rid, ENOENT); 752 753 return; 753 754 } 754 755 755 device_t *dev = hash_table_get_instance(lnk, device_t, link);756 service_t *dev = hash_table_get_instance(lnk, service_t, link); 756 757 assert(dev->sess); 757 758 dev->refcount--; … … 759 760 if (dev->refcount == 0) { 760 761 async_hangup(dev->sess); 761 hash_table_remove(& devices, key, DEVICES_KEYS);762 } 763 764 fibril_mutex_unlock(& devices_mutex);762 hash_table_remove(&services, key, SERVICES_KEYS); 763 } 764 765 fibril_mutex_unlock(&services_mutex); 765 766 766 767 async_answer_0(rid, EOK); … … 771 772 } 772 773 773 void devfs_sync(ipc_callid_t rid, ipc_call_t *request)774 void locfs_sync(ipc_callid_t rid, ipc_call_t *request) 774 775 { 775 776 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); … … 780 781 } 781 782 782 devmap_handle_type_t type = devmap_handle_probe(index);783 784 if (type == DEV_HANDLE_NAMESPACE) {783 loc_object_type_t type = loc_id_probe(index); 784 785 if (type == LOC_OBJECT_NAMESPACE) { 785 786 /* Namespace directory */ 786 787 async_answer_0(rid, EOK); … … 788 789 } 789 790 790 if (type == DEV_HANDLE_DEVICE) {791 if (type == LOC_OBJECT_SERVICE) { 791 792 unsigned long key[] = { 792 [ DEVICES_KEY_HANDLE] = (unsigned long) index793 [SERVICES_KEY_HANDLE] = (unsigned long) index 793 794 }; 794 795 795 fibril_mutex_lock(& devices_mutex);796 link_t *lnk = hash_table_find(& devices, key);796 fibril_mutex_lock(&services_mutex); 797 link_t *lnk = hash_table_find(&services, key); 797 798 if (lnk == NULL) { 798 fibril_mutex_unlock(& devices_mutex);799 fibril_mutex_unlock(&services_mutex); 799 800 async_answer_0(rid, ENOENT); 800 801 return; 801 802 } 802 803 803 device_t *dev = hash_table_get_instance(lnk, device_t, link);804 service_t *dev = hash_table_get_instance(lnk, service_t, link); 804 805 assert(dev->sess); 805 806 … … 813 814 async_exchange_end(exch); 814 815 815 fibril_mutex_unlock(& devices_mutex);816 fibril_mutex_unlock(&services_mutex); 816 817 817 818 /* Wait for reply from the driver */ … … 827 828 } 828 829 829 void devfs_destroy(ipc_callid_t rid, ipc_call_t *request)830 void locfs_destroy(ipc_callid_t rid, ipc_call_t *request) 830 831 { 831 832 async_answer_0(rid, ENOTSUP); -
uspace/srv/fs/locfs/locfs_ops.h
ref09a7a r15f3c3f 31 31 */ 32 32 33 #ifndef DEVFS_DEVFS_OPS_H_34 #define DEVFS_DEVFS_OPS_H_33 #ifndef LOCFS_LOCFS_OPS_H_ 34 #define LOCFS_LOCFS_OPS_H_ 35 35 36 36 #include <ipc/common.h> 37 37 #include <bool.h> 38 38 39 extern bool devfs_init(void);39 extern bool locfs_init(void); 40 40 41 extern void devfs_mounted(ipc_callid_t, ipc_call_t *);42 extern void devfs_mount(ipc_callid_t, ipc_call_t *);43 extern void devfs_unmounted(ipc_callid_t, ipc_call_t *);44 extern void devfs_unmount(ipc_callid_t, ipc_call_t *);45 extern void devfs_lookup(ipc_callid_t, ipc_call_t *);46 extern void devfs_open_node(ipc_callid_t, ipc_call_t *);47 extern void devfs_stat(ipc_callid_t, ipc_call_t *);48 extern void devfs_sync(ipc_callid_t, ipc_call_t *);49 extern void devfs_read(ipc_callid_t, ipc_call_t *);50 extern void devfs_write(ipc_callid_t, ipc_call_t *);51 extern void devfs_truncate(ipc_callid_t, ipc_call_t *);52 extern void devfs_close(ipc_callid_t, ipc_call_t *);53 extern void devfs_destroy(ipc_callid_t, ipc_call_t *);41 extern void locfs_mounted(ipc_callid_t, ipc_call_t *); 42 extern void locfs_mount(ipc_callid_t, ipc_call_t *); 43 extern void locfs_unmounted(ipc_callid_t, ipc_call_t *); 44 extern void locfs_unmount(ipc_callid_t, ipc_call_t *); 45 extern void locfs_lookup(ipc_callid_t, ipc_call_t *); 46 extern void locfs_open_node(ipc_callid_t, ipc_call_t *); 47 extern void locfs_stat(ipc_callid_t, ipc_call_t *); 48 extern void locfs_sync(ipc_callid_t, ipc_call_t *); 49 extern void locfs_read(ipc_callid_t, ipc_call_t *); 50 extern void locfs_write(ipc_callid_t, ipc_call_t *); 51 extern void locfs_truncate(ipc_callid_t, ipc_call_t *); 52 extern void locfs_close(ipc_callid_t, ipc_call_t *); 53 extern void locfs_destroy(ipc_callid_t, ipc_call_t *); 54 54 55 55 #endif -
uspace/srv/fs/tmpfs/tmpfs.h
ref09a7a r15f3c3f 61 61 fs_node_t *bp; /**< Back pointer to the FS node. */ 62 62 fs_index_t index; /**< TMPFS node index. */ 63 devmap_handle_t devmap_handle;/**< Device handle. */63 service_id_t service_id;/**< Service ID of block device. */ 64 64 link_t nh_link; /**< Nodes hash table link. */ 65 65 tmpfs_dentry_type_t type; … … 90 90 extern void tmpfs_sync(ipc_callid_t, ipc_call_t *); 91 91 92 extern bool tmpfs_restore( devmap_handle_t);92 extern bool tmpfs_restore(service_id_t); 93 93 94 94 #endif -
uspace/srv/fs/tmpfs/tmpfs_dump.c
ref09a7a r15f3c3f 55 55 56 56 static bool 57 tmpfs_restore_recursion( devmap_handle_t dev, size_t *bufpos, size_t *buflen,57 tmpfs_restore_recursion(service_id_t dsid, size_t *bufpos, size_t *buflen, 58 58 aoff64_t *pos, fs_node_t *pfn) 59 59 { … … 68 68 uint32_t size; 69 69 70 if (block_seqread(d ev, bufpos, buflen, pos, &entry,70 if (block_seqread(dsid, bufpos, buflen, pos, &entry, 71 71 sizeof(entry)) != EOK) 72 72 return false; … … 82 82 return false; 83 83 84 rc = ops->create(&fn, d ev, L_FILE);84 rc = ops->create(&fn, dsid, L_FILE); 85 85 if (rc != EOK || fn == NULL) { 86 86 free(fname); … … 88 88 } 89 89 90 if (block_seqread(d ev, bufpos, buflen, pos, fname,90 if (block_seqread(dsid, bufpos, buflen, pos, fname, 91 91 entry.len) != EOK) { 92 92 (void) ops->destroy(fn); … … 104 104 free(fname); 105 105 106 if (block_seqread(d ev, bufpos, buflen, pos, &size,106 if (block_seqread(dsid, bufpos, buflen, pos, &size, 107 107 sizeof(size)) != EOK) 108 108 return false; … … 116 116 117 117 nodep->size = size; 118 if (block_seqread(d ev, bufpos, buflen, pos, nodep->data,118 if (block_seqread(dsid, bufpos, buflen, pos, nodep->data, 119 119 size) != EOK) 120 120 return false; … … 126 126 return false; 127 127 128 rc = ops->create(&fn, d ev, L_DIRECTORY);128 rc = ops->create(&fn, dsid, L_DIRECTORY); 129 129 if (rc != EOK || fn == NULL) { 130 130 free(fname); … … 132 132 } 133 133 134 if (block_seqread(d ev, bufpos, buflen, pos, fname,134 if (block_seqread(dsid, bufpos, buflen, pos, fname, 135 135 entry.len) != EOK) { 136 136 (void) ops->destroy(fn); … … 148 148 free(fname); 149 149 150 if (!tmpfs_restore_recursion(d ev, bufpos, buflen, pos,150 if (!tmpfs_restore_recursion(dsid, bufpos, buflen, pos, 151 151 fn)) 152 152 return false; … … 161 161 } 162 162 163 bool tmpfs_restore( devmap_handle_t dev)163 bool tmpfs_restore(service_id_t dsid) 164 164 { 165 165 libfs_ops_t *ops = &tmpfs_libfs_ops; … … 167 167 int rc; 168 168 169 rc = block_init(EXCHANGE_SERIALIZE, d ev, TMPFS_COMM_SIZE);169 rc = block_init(EXCHANGE_SERIALIZE, dsid, TMPFS_COMM_SIZE); 170 170 if (rc != EOK) 171 171 return false; … … 176 176 177 177 char tag[6]; 178 if (block_seqread(d ev, &bufpos, &buflen, &pos, tag, 5) != EOK)178 if (block_seqread(dsid, &bufpos, &buflen, &pos, tag, 5) != EOK) 179 179 goto error; 180 180 … … 183 183 goto error; 184 184 185 rc = ops->root_get(&fn, d ev);185 rc = ops->root_get(&fn, dsid); 186 186 if (rc != EOK) 187 187 goto error; 188 188 189 if (!tmpfs_restore_recursion(d ev, &bufpos, &buflen, &pos, fn))190 goto error; 191 192 block_fini(d ev);189 if (!tmpfs_restore_recursion(dsid, &bufpos, &buflen, &pos, fn)) 190 goto error; 191 192 block_fini(dsid); 193 193 return true; 194 194 195 195 error: 196 block_fini(d ev);196 block_fini(dsid); 197 197 return false; 198 198 } -
uspace/srv/fs/tmpfs/tmpfs_ops.c
ref09a7a r15f3c3f 69 69 /* Forward declarations of static functions. */ 70 70 static int tmpfs_match(fs_node_t **, fs_node_t *, const char *); 71 static int tmpfs_node_get(fs_node_t **, devmap_handle_t, fs_index_t);71 static int tmpfs_node_get(fs_node_t **, service_id_t, fs_index_t); 72 72 static int tmpfs_node_open(fs_node_t *); 73 73 static int tmpfs_node_put(fs_node_t *); 74 static int tmpfs_create_node(fs_node_t **, devmap_handle_t, int);74 static int tmpfs_create_node(fs_node_t **, service_id_t, int); 75 75 static int tmpfs_destroy_node(fs_node_t *); 76 76 static int tmpfs_link_node(fs_node_t *, fs_node_t *, const char *); … … 78 78 79 79 /* Implementation of helper functions. */ 80 static int tmpfs_root_get(fs_node_t **rfn, devmap_handle_t devmap_handle)81 { 82 return tmpfs_node_get(rfn, devmap_handle, TMPFS_SOME_ROOT);80 static int tmpfs_root_get(fs_node_t **rfn, service_id_t service_id) 81 { 82 return tmpfs_node_get(rfn, service_id, TMPFS_SOME_ROOT); 83 83 } 84 84 … … 119 119 } 120 120 121 static devmap_handle_t tmpfs_device_get(fs_node_t *fn)121 static service_id_t tmpfs_device_get(fs_node_t *fn) 122 122 { 123 123 return 0; … … 164 164 switch (keys) { 165 165 case 1: 166 return (nodep-> devmap_handle== key[NODES_KEY_DEV]);166 return (nodep->service_id == key[NODES_KEY_DEV]); 167 167 case 2: 168 return ((nodep-> devmap_handle== key[NODES_KEY_DEV]) &&168 return ((nodep->service_id == key[NODES_KEY_DEV]) && 169 169 (nodep->index == key[NODES_KEY_INDEX])); 170 170 default: … … 208 208 nodep->bp = NULL; 209 209 nodep->index = 0; 210 nodep-> devmap_handle= 0;210 nodep->service_id = 0; 211 211 nodep->type = TMPFS_NONE; 212 212 nodep->lnkcnt = 0; … … 232 232 } 233 233 234 static bool tmpfs_instance_init( devmap_handle_t devmap_handle)234 static bool tmpfs_instance_init(service_id_t service_id) 235 235 { 236 236 fs_node_t *rfn; 237 237 int rc; 238 238 239 rc = tmpfs_create_node(&rfn, devmap_handle, L_DIRECTORY);239 rc = tmpfs_create_node(&rfn, service_id, L_DIRECTORY); 240 240 if (rc != EOK || !rfn) 241 241 return false; … … 244 244 } 245 245 246 static void tmpfs_instance_done( devmap_handle_t devmap_handle)246 static void tmpfs_instance_done(service_id_t service_id) 247 247 { 248 248 unsigned long key[] = { 249 [NODES_KEY_DEV] = devmap_handle249 [NODES_KEY_DEV] = service_id 250 250 }; 251 251 /* … … 276 276 } 277 277 278 int tmpfs_node_get(fs_node_t **rfn, devmap_handle_t devmap_handle, fs_index_t index)278 int tmpfs_node_get(fs_node_t **rfn, service_id_t service_id, fs_index_t index) 279 279 { 280 280 unsigned long key[] = { 281 [NODES_KEY_DEV] = devmap_handle,281 [NODES_KEY_DEV] = service_id, 282 282 [NODES_KEY_INDEX] = index 283 283 }; … … 305 305 } 306 306 307 int tmpfs_create_node(fs_node_t **rfn, devmap_handle_t devmap_handle, int lflag)307 int tmpfs_create_node(fs_node_t **rfn, service_id_t service_id, int lflag) 308 308 { 309 309 fs_node_t *rootfn; … … 324 324 nodep->bp->data = nodep; /* link the FS and TMPFS nodes */ 325 325 326 rc = tmpfs_root_get(&rootfn, devmap_handle);326 rc = tmpfs_root_get(&rootfn, service_id); 327 327 assert(rc == EOK); 328 328 if (!rootfn) … … 330 330 else 331 331 nodep->index = tmpfs_next_index++; 332 nodep-> devmap_handle = devmap_handle;332 nodep->service_id = service_id; 333 333 if (lflag & L_DIRECTORY) 334 334 nodep->type = TMPFS_DIRECTORY; … … 338 338 /* Insert the new node into the nodes hash table. */ 339 339 unsigned long key[] = { 340 [NODES_KEY_DEV] = nodep-> devmap_handle,340 [NODES_KEY_DEV] = nodep->service_id, 341 341 [NODES_KEY_INDEX] = nodep->index 342 342 }; … … 354 354 355 355 unsigned long key[] = { 356 [NODES_KEY_DEV] = nodep-> devmap_handle,356 [NODES_KEY_DEV] = nodep->service_id, 357 357 [NODES_KEY_INDEX] = nodep->index 358 358 }; … … 435 435 void tmpfs_mounted(ipc_callid_t rid, ipc_call_t *request) 436 436 { 437 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);437 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request); 438 438 fs_node_t *rootfn; 439 439 int rc; … … 448 448 449 449 /* Check if this device is not already mounted. */ 450 rc = tmpfs_root_get(&rootfn, devmap_handle);450 rc = tmpfs_root_get(&rootfn, service_id); 451 451 if ((rc == EOK) && (rootfn)) { 452 452 (void) tmpfs_node_put(rootfn); … … 457 457 458 458 /* Initialize TMPFS instance. */ 459 if (!tmpfs_instance_init( devmap_handle)) {459 if (!tmpfs_instance_init(service_id)) { 460 460 free(opts); 461 461 async_answer_0(rid, ENOMEM); … … 463 463 } 464 464 465 rc = tmpfs_root_get(&rootfn, devmap_handle);465 rc = tmpfs_root_get(&rootfn, service_id); 466 466 assert(rc == EOK); 467 467 tmpfs_node_t *rootp = TMPFS_NODE(rootfn); 468 468 if (str_cmp(opts, "restore") == 0) { 469 if (tmpfs_restore( devmap_handle))469 if (tmpfs_restore(service_id)) 470 470 async_answer_3(rid, EOK, rootp->index, rootp->size, 471 471 rootp->lnkcnt); … … 486 486 void tmpfs_unmounted(ipc_callid_t rid, ipc_call_t *request) 487 487 { 488 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);489 490 tmpfs_instance_done( devmap_handle);488 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request); 489 490 tmpfs_instance_done(service_id); 491 491 async_answer_0(rid, EOK); 492 492 } … … 504 504 void tmpfs_read(ipc_callid_t rid, ipc_call_t *request) 505 505 { 506 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);506 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request); 507 507 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 508 508 aoff64_t pos = … … 514 514 link_t *hlp; 515 515 unsigned long key[] = { 516 [NODES_KEY_DEV] = devmap_handle,516 [NODES_KEY_DEV] = service_id, 517 517 [NODES_KEY_INDEX] = index 518 518 }; … … 575 575 void tmpfs_write(ipc_callid_t rid, ipc_call_t *request) 576 576 { 577 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);577 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request); 578 578 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 579 579 aoff64_t pos = … … 585 585 link_t *hlp; 586 586 unsigned long key[] = { 587 [NODES_KEY_DEV] = devmap_handle,587 [NODES_KEY_DEV] = service_id, 588 588 [NODES_KEY_INDEX] = index 589 589 }; … … 640 640 void tmpfs_truncate(ipc_callid_t rid, ipc_call_t *request) 641 641 { 642 devmap_handle_t devmap_handle = (devmap_handle_t) IPC_GET_ARG1(*request);642 service_id_t service_id = (service_id_t) IPC_GET_ARG1(*request); 643 643 fs_index_t index = (fs_index_t) IPC_GET_ARG2(*request); 644 644 aoff64_t size = … … 649 649 */ 650 650 unsigned long key[] = { 651 [NODES_KEY_DEV] = devmap_handle,651 [NODES_KEY_DEV] = service_id, 652 652 [NODES_KEY_INDEX] = index 653 653 }; … … 693 693 void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request) 694 694 { 695 devmap_handle_t devmap_handle = (devmap_handle_t)IPC_GET_ARG1(*request);695 service_id_t service_id = (service_id_t)IPC_GET_ARG1(*request); 696 696 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 697 697 int rc; … … 699 699 link_t *hlp; 700 700 unsigned long key[] = { 701 [NODES_KEY_DEV] = devmap_handle,701 [NODES_KEY_DEV] = service_id, 702 702 [NODES_KEY_INDEX] = index 703 703 };
Note:
See TracChangeset
for help on using the changeset viewer.