Changeset be39fc6 in mainline
- Timestamp:
- 2017-05-11T22:26:39Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- de5b708
- Parents:
- 4bfad34
- Location:
- uspace
- Files:
-
- 5 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ext4/include/ext4/filesystem.h
r4bfad34 rbe39fc6 39 39 #include "ext4/types.h" 40 40 41 extern int ext4_filesystem_init(ext4_filesystem_t *, ext4 fs_instance_t *,41 extern int ext4_filesystem_init(ext4_filesystem_t *, ext4_instance_t *, 42 42 service_id_t, enum cache_mode, aoff64_t *); 43 43 extern int ext4_filesystem_fini(ext4_filesystem_t *); -
uspace/lib/ext4/include/ext4/fstypes.h
r4bfad34 rbe39fc6 1 1 /* 2 * Copyright (c) 2011 Martin Sucha 2 3 * Copyright (c) 2012 Frantisek Princ 3 4 * All rights reserved. … … 31 32 */ 32 33 33 #ifndef LIBEXT4_ H_34 #define LIBEXT4_ H_34 #ifndef LIBEXT4_FSTYPES_H_ 35 #define LIBEXT4_FSTYPES_H_ 35 36 36 #include "ext4/balloc.h" 37 #include "ext4/bitmap.h" 38 #include "ext4/block_group.h" 39 #include "ext4/directory.h" 40 #include "ext4/directory_index.h" 41 #include "ext4/extent.h" 42 #include "ext4/filesystem.h" 43 #include "ext4/hash.h" 44 #include "ext4/ialloc.h" 45 #include "ext4/inode.h" 46 #include "ext4/superblock.h" 37 #include <adt/list.h> 38 #include <libfs.h> 39 #include <loc.h> 47 40 #include "ext4/types.h" 48 41 49 #include <stdio.h> 50 #define EXT4FS_DBG(format, ...) \ 51 printf("ext4fs: %s: " format "\n", \ 52 __FUNCTION__, ##__VA_ARGS__) \ 42 /** 43 * Type for holding an instance of mounted partition. 44 */ 45 typedef struct ext4_instance { 46 link_t link; 47 service_id_t service_id; 48 ext4_filesystem_t *filesystem; 49 unsigned int open_nodes_count; 50 } ext4_instance_t; 51 52 /** 53 * Type for wrapping common fs_node and add some useful pointers. 54 */ 55 typedef struct ext4_node { 56 ext4_instance_t *instance; 57 ext4_inode_ref_t *inode_ref; 58 fs_node_t *fs_node; 59 ht_link_t link; 60 unsigned int references; 61 } ext4_node_t; 62 63 #define EXT4_NODE(node) \ 64 ((node) ? (ext4_node_t *) (node)->data : NULL) 53 65 54 66 #endif -
uspace/lib/ext4/include/ext4/ops.h
r4bfad34 rbe39fc6 37 37 #include "ext4/fstypes.h" 38 38 39 extern vfs_out_ops_t ext4 fs_ops;40 extern libfs_ops_t ext4 fs_libfs_ops;39 extern vfs_out_ops_t ext4_ops; 40 extern libfs_ops_t ext4_libfs_ops; 41 41 42 extern int ext4 fs_global_init(void);43 extern int ext4 fs_global_fini(void);42 extern int ext4_global_init(void); 43 extern int ext4_global_fini(void); 44 44 45 extern int ext4 fs_node_get_core(fs_node_t **, ext4fs_instance_t *, fs_index_t);46 extern int ext4 fs_node_put(fs_node_t *);45 extern int ext4_node_get_core(fs_node_t **, ext4_instance_t *, fs_index_t); 46 extern int ext4_node_put(fs_node_t *); 47 47 48 48 -
uspace/lib/ext4/src/filesystem.c
r4bfad34 rbe39fc6 69 69 * 70 70 */ 71 int ext4_filesystem_init(ext4_filesystem_t *fs, ext4 fs_instance_t *inst,71 int ext4_filesystem_init(ext4_filesystem_t *fs, ext4_instance_t *inst, 72 72 service_id_t service_id, enum cache_mode cmode, aoff64_t *size) 73 73 { … … 135 135 /* Read root node */ 136 136 fs_node_t *root_node; 137 rc = ext4 fs_node_get_core(&root_node, inst, EXT4_INODE_ROOT_INDEX);137 rc = ext4_node_get_core(&root_node, inst, EXT4_INODE_ROOT_INDEX); 138 138 if (rc != EOK) 139 139 goto err_2; … … 148 148 ext4_superblock_set_mount_count(fs->superblock, mnt_count + 1); 149 149 150 ext4 fs_node_t *enode = EXT4FS_NODE(root_node);150 ext4_node_t *enode = EXT4_NODE(root_node); 151 151 152 152 *size = ext4_inode_get_size(fs->superblock, enode->inode_ref->inode); 153 153 154 ext4 fs_node_put(root_node);154 ext4_node_put(root_node); 155 155 return EOK; 156 156 err_3: 157 ext4 fs_node_put(root_node);157 ext4_node_put(root_node); 158 158 err_2: 159 159 block_cache_fini(fs->device); -
uspace/lib/ext4/src/ops.c
r4bfad34 rbe39fc6 36 36 */ 37 37 38 #include <adt/hash_table.h> 39 #include <adt/hash.h> 38 40 #include <errno.h> 39 #include <ext4/libext4.h>40 41 #include <fibril_synch.h> 41 42 #include <libfs.h> 42 43 #include <macros.h> 43 44 #include <malloc.h> 44 #include < adt/hash_table.h>45 #include < adt/hash.h>45 #include <mem.h> 46 #include <str.h> 46 47 #include <ipc/loc.h> 48 #include "ext4/balloc.h" 49 #include "ext4/directory.h" 50 #include "ext4/directory_index.h" 51 #include "ext4/extent.h" 52 #include "ext4/inode.h" 47 53 #include "ext4/ops.h" 54 #include "ext4/filesystem.h" 48 55 #include "ext4/fstypes.h" 56 #include "ext4/superblock.h" 49 57 50 58 /* Forward declarations of auxiliary functions */ 51 59 52 static int ext4 fs_read_directory(ipc_callid_t, aoff64_t, size_t,53 ext4 fs_instance_t *, ext4_inode_ref_t *, size_t *);54 static int ext4 fs_read_file(ipc_callid_t, aoff64_t, size_t, ext4fs_instance_t *,60 static int ext4_read_directory(ipc_callid_t, aoff64_t, size_t, 61 ext4_instance_t *, ext4_inode_ref_t *, size_t *); 62 static int ext4_read_file(ipc_callid_t, aoff64_t, size_t, ext4_instance_t *, 55 63 ext4_inode_ref_t *, size_t *); 56 static bool ext4 fs_is_dots(const uint8_t *, size_t);57 static int ext4 fs_instance_get(service_id_t, ext4fs_instance_t **);64 static bool ext4_is_dots(const uint8_t *, size_t); 65 static int ext4_instance_get(service_id_t, ext4_instance_t **); 58 66 59 67 /* Forward declarations of ext4 libfs operations. */ 60 68 61 static int ext4 fs_root_get(fs_node_t **, service_id_t);62 static int ext4 fs_match(fs_node_t **, fs_node_t *, const char *);63 static int ext4 fs_node_get(fs_node_t **, service_id_t, fs_index_t);64 static int ext4 fs_node_open(fs_node_t *);65 int ext4 fs_node_put(fs_node_t *);66 static int ext4 fs_create_node(fs_node_t **, service_id_t, int);67 static int ext4 fs_destroy_node(fs_node_t *);68 static int ext4 fs_link(fs_node_t *, fs_node_t *, const char *);69 static int ext4 fs_unlink(fs_node_t *, fs_node_t *, const char *);70 static int ext4 fs_has_children(bool *, fs_node_t *);71 static fs_index_t ext4 fs_index_get(fs_node_t *);72 static aoff64_t ext4 fs_size_get(fs_node_t *);73 static unsigned ext4 fs_lnkcnt_get(fs_node_t *);74 static bool ext4 fs_is_directory(fs_node_t *);75 static bool ext4 fs_is_file(fs_node_t *node);76 static service_id_t ext4 fs_service_get(fs_node_t *node);77 static int ext4 fs_size_block(service_id_t, uint32_t *);78 static int ext4 fs_total_block_count(service_id_t, uint64_t *);79 static int ext4 fs_free_block_count(service_id_t, uint64_t *);69 static int ext4_root_get(fs_node_t **, service_id_t); 70 static int ext4_match(fs_node_t **, fs_node_t *, const char *); 71 static int ext4_node_get(fs_node_t **, service_id_t, fs_index_t); 72 static int ext4_node_open(fs_node_t *); 73 int ext4_node_put(fs_node_t *); 74 static int ext4_create_node(fs_node_t **, service_id_t, int); 75 static int ext4_destroy_node(fs_node_t *); 76 static int ext4_link(fs_node_t *, fs_node_t *, const char *); 77 static int ext4_unlink(fs_node_t *, fs_node_t *, const char *); 78 static int ext4_has_children(bool *, fs_node_t *); 79 static fs_index_t ext4_index_get(fs_node_t *); 80 static aoff64_t ext4_size_get(fs_node_t *); 81 static unsigned ext4_lnkcnt_get(fs_node_t *); 82 static bool ext4_is_directory(fs_node_t *); 83 static bool ext4_is_file(fs_node_t *node); 84 static service_id_t ext4_service_get(fs_node_t *node); 85 static int ext4_size_block(service_id_t, uint32_t *); 86 static int ext4_total_block_count(service_id_t, uint64_t *); 87 static int ext4_free_block_count(service_id_t, uint64_t *); 80 88 81 89 /* Static variables */ … … 101 109 static size_t open_nodes_hash(const ht_link_t *item) 102 110 { 103 ext4 fs_node_t *enode = hash_table_get_inst(item, ext4fs_node_t, link);111 ext4_node_t *enode = hash_table_get_inst(item, ext4_node_t, link); 104 112 return hash_combine(enode->instance->service_id, enode->inode_ref->index); 105 113 } … … 108 116 { 109 117 node_key_t *key = (node_key_t *)key_arg; 110 ext4 fs_node_t *enode = hash_table_get_inst(item, ext4fs_node_t, link);118 ext4_node_t *enode = hash_table_get_inst(item, ext4_node_t, link); 111 119 112 120 return key->service_id == enode->instance->service_id … … 130 138 * 131 139 */ 132 int ext4 fs_global_init(void)140 int ext4_global_init(void) 133 141 { 134 142 if (!hash_table_create(&open_nodes, 0, 0, &open_nodes_ops)) … … 144 152 * @return Error code 145 153 */ 146 int ext4 fs_global_fini(void)154 int ext4_global_fini(void) 147 155 { 148 156 hash_table_destroy(&open_nodes); … … 162 170 * 163 171 */ 164 int ext4 fs_instance_get(service_id_t service_id, ext4fs_instance_t **inst)172 int ext4_instance_get(service_id_t service_id, ext4_instance_t **inst) 165 173 { 166 174 fibril_mutex_lock(&instance_list_mutex); … … 171 179 } 172 180 173 list_foreach(instance_list, link, ext4 fs_instance_t, tmp) {181 list_foreach(instance_list, link, ext4_instance_t, tmp) { 174 182 if (tmp->service_id == service_id) { 175 183 *inst = tmp; … … 191 199 * 192 200 */ 193 int ext4 fs_root_get(fs_node_t **rfn, service_id_t service_id)194 { 195 return ext4 fs_node_get(rfn, service_id, EXT4_INODE_ROOT_INDEX);201 int ext4_root_get(fs_node_t **rfn, service_id_t service_id) 202 { 203 return ext4_node_get(rfn, service_id, EXT4_INODE_ROOT_INDEX); 196 204 } 197 205 … … 207 215 * 208 216 */ 209 int ext4 fs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component)210 { 211 ext4 fs_node_t *eparent = EXT4FS_NODE(pfn);217 int ext4_match(fs_node_t **rfn, fs_node_t *pfn, const char *component) 218 { 219 ext4_node_t *eparent = EXT4_NODE(pfn); 212 220 ext4_filesystem_t *fs = eparent->instance->filesystem; 213 221 … … 231 239 /* Load node from search result */ 232 240 uint32_t inode = ext4_directory_entry_ll_get_inode(result.dentry); 233 rc = ext4 fs_node_get_core(rfn, eparent->instance, inode);241 rc = ext4_node_get_core(rfn, eparent->instance, inode); 234 242 if (rc != EOK) 235 243 goto exit; … … 254 262 * 255 263 */ 256 int ext4 fs_node_get(fs_node_t **rfn, service_id_t service_id, fs_index_t index)257 { 258 ext4 fs_instance_t *inst;259 int rc = ext4 fs_instance_get(service_id, &inst);260 if (rc != EOK) 261 return rc; 262 263 return ext4 fs_node_get_core(rfn, inst, index);264 int ext4_node_get(fs_node_t **rfn, service_id_t service_id, fs_index_t index) 265 { 266 ext4_instance_t *inst; 267 int rc = ext4_instance_get(service_id, &inst); 268 if (rc != EOK) 269 return rc; 270 271 return ext4_node_get_core(rfn, inst, index); 264 272 } 265 273 … … 273 281 * 274 282 */ 275 int ext4 fs_node_get_core(fs_node_t **rfn, ext4fs_instance_t *inst,283 int ext4_node_get_core(fs_node_t **rfn, ext4_instance_t *inst, 276 284 fs_index_t index) 277 285 { … … 285 293 286 294 ht_link_t *already_open = hash_table_find(&open_nodes, &key); 287 ext4 fs_node_t *enode = NULL;295 ext4_node_t *enode = NULL; 288 296 if (already_open) { 289 enode = hash_table_get_inst(already_open, ext4 fs_node_t, link);297 enode = hash_table_get_inst(already_open, ext4_node_t, link); 290 298 *rfn = enode->fs_node; 291 299 enode->references++; … … 296 304 297 305 /* Prepare new enode */ 298 enode = malloc(sizeof(ext4 fs_node_t));306 enode = malloc(sizeof(ext4_node_t)); 299 307 if (enode == NULL) { 300 308 fibril_mutex_unlock(&open_nodes_lock); … … 347 355 * 348 356 */ 349 static int ext4 fs_node_put_core(ext4fs_node_t *enode)357 static int ext4_node_put_core(ext4_node_t *enode) 350 358 { 351 359 hash_table_remove_item(&open_nodes, &enode->link); … … 374 382 * 375 383 */ 376 int ext4 fs_node_open(fs_node_t *fn)384 int ext4_node_open(fs_node_t *fn) 377 385 { 378 386 /* Stateless operation */ … … 388 396 * 389 397 */ 390 int ext4 fs_node_put(fs_node_t *fn)398 int ext4_node_put(fs_node_t *fn) 391 399 { 392 400 fibril_mutex_lock(&open_nodes_lock); 393 401 394 ext4 fs_node_t *enode = EXT4FS_NODE(fn);402 ext4_node_t *enode = EXT4_NODE(fn); 395 403 assert(enode->references > 0); 396 404 enode->references--; 397 405 if (enode->references == 0) { 398 int rc = ext4 fs_node_put_core(enode);406 int rc = ext4_node_put_core(enode); 399 407 if (rc != EOK) { 400 408 fibril_mutex_unlock(&open_nodes_lock); … … 417 425 * 418 426 */ 419 int ext4 fs_create_node(fs_node_t **rfn, service_id_t service_id, int flags)427 int ext4_create_node(fs_node_t **rfn, service_id_t service_id, int flags) 420 428 { 421 429 /* Allocate enode */ 422 ext4 fs_node_t *enode;423 enode = malloc(sizeof(ext4 fs_node_t));430 ext4_node_t *enode; 431 enode = malloc(sizeof(ext4_node_t)); 424 432 if (enode == NULL) 425 433 return ENOMEM; … … 434 442 435 443 /* Load instance */ 436 ext4 fs_instance_t *inst;437 int rc = ext4 fs_instance_get(service_id, &inst);444 ext4_instance_t *inst; 445 int rc = ext4_instance_get(service_id, &inst); 438 446 if (rc != EOK) { 439 447 free(enode); … … 478 486 * 479 487 */ 480 int ext4 fs_destroy_node(fs_node_t *fn)488 int ext4_destroy_node(fs_node_t *fn) 481 489 { 482 490 /* If directory, check for children */ 483 491 bool has_children; 484 int rc = ext4 fs_has_children(&has_children, fn);485 if (rc != EOK) { 486 ext4 fs_node_put(fn);492 int rc = ext4_has_children(&has_children, fn); 493 if (rc != EOK) { 494 ext4_node_put(fn); 487 495 return rc; 488 496 } 489 497 490 498 if (has_children) { 491 ext4 fs_node_put(fn);499 ext4_node_put(fn); 492 500 return EINVAL; 493 501 } 494 502 495 ext4 fs_node_t *enode = EXT4FS_NODE(fn);503 ext4_node_t *enode = EXT4_NODE(fn); 496 504 ext4_inode_ref_t *inode_ref = enode->inode_ref; 497 505 … … 499 507 rc = ext4_filesystem_truncate_inode(inode_ref, 0); 500 508 if (rc != EOK) { 501 ext4 fs_node_put(fn);509 ext4_node_put(fn); 502 510 return rc; 503 511 } … … 513 521 rc = ext4_filesystem_free_inode(inode_ref); 514 522 if (rc != EOK) { 515 ext4 fs_node_put(fn);516 return rc; 517 } 518 519 return ext4 fs_node_put(fn);523 ext4_node_put(fn); 524 return rc; 525 } 526 527 return ext4_node_put(fn); 520 528 } 521 529 … … 529 537 * 530 538 */ 531 int ext4 fs_link(fs_node_t *pfn, fs_node_t *cfn, const char *name)539 int ext4_link(fs_node_t *pfn, fs_node_t *cfn, const char *name) 532 540 { 533 541 /* Check maximum name length */ … … 535 543 return ENAMETOOLONG; 536 544 537 ext4 fs_node_t *parent = EXT4FS_NODE(pfn);538 ext4 fs_node_t *child = EXT4FS_NODE(cfn);545 ext4_node_t *parent = EXT4_NODE(pfn); 546 ext4_node_t *child = EXT4_NODE(cfn); 539 547 ext4_filesystem_t *fs = parent->instance->filesystem; 540 548 … … 602 610 * 603 611 */ 604 int ext4 fs_unlink(fs_node_t *pfn, fs_node_t *cfn, const char *name)612 int ext4_unlink(fs_node_t *pfn, fs_node_t *cfn, const char *name) 605 613 { 606 614 bool has_children; 607 int rc = ext4 fs_has_children(&has_children, cfn);615 int rc = ext4_has_children(&has_children, cfn); 608 616 if (rc != EOK) 609 617 return rc; … … 614 622 615 623 /* Remove entry from parent directory */ 616 ext4_inode_ref_t *parent = EXT4 FS_NODE(pfn)->inode_ref;624 ext4_inode_ref_t *parent = EXT4_NODE(pfn)->inode_ref; 617 625 rc = ext4_directory_remove_entry(parent, name); 618 626 if (rc != EOK) … … 620 628 621 629 /* Decrement links count */ 622 ext4_inode_ref_t *child_inode_ref = EXT4 FS_NODE(cfn)->inode_ref;630 ext4_inode_ref_t *child_inode_ref = EXT4_NODE(cfn)->inode_ref; 623 631 624 632 uint32_t lnk_count = … … 627 635 628 636 /* If directory - handle links from parent */ 629 if ((lnk_count <= 1) && (ext4 fs_is_directory(cfn))) {637 if ((lnk_count <= 1) && (ext4_is_directory(cfn))) { 630 638 assert(lnk_count == 1); 631 639 632 640 lnk_count--; 633 641 634 ext4_inode_ref_t *parent_inode_ref = EXT4 FS_NODE(pfn)->inode_ref;642 ext4_inode_ref_t *parent_inode_ref = EXT4_NODE(pfn)->inode_ref; 635 643 636 644 uint32_t parent_lnk_count = ext4_inode_get_links_count( … … 675 683 * 676 684 */ 677 int ext4 fs_has_children(bool *has_children, fs_node_t *fn)678 { 679 ext4 fs_node_t *enode = EXT4FS_NODE(fn);685 int ext4_has_children(bool *has_children, fs_node_t *fn) 686 { 687 ext4_node_t *enode = EXT4_NODE(fn); 680 688 ext4_filesystem_t *fs = enode->instance->filesystem; 681 689 … … 699 707 ext4_directory_entry_ll_get_name_length(fs->superblock, 700 708 it.current); 701 if (!ext4 fs_is_dots(it.current->name, name_size)) {709 if (!ext4_is_dots(it.current->name, name_size)) { 702 710 found = true; 703 711 break; … … 728 736 * 729 737 */ 730 fs_index_t ext4 fs_index_get(fs_node_t *fn)731 { 732 ext4 fs_node_t *enode = EXT4FS_NODE(fn);738 fs_index_t ext4_index_get(fs_node_t *fn) 739 { 740 ext4_node_t *enode = EXT4_NODE(fn); 733 741 return enode->inode_ref->index; 734 742 } … … 741 749 * 742 750 */ 743 aoff64_t ext4 fs_size_get(fs_node_t *fn)744 { 745 ext4 fs_node_t *enode = EXT4FS_NODE(fn);751 aoff64_t ext4_size_get(fs_node_t *fn) 752 { 753 ext4_node_t *enode = EXT4_NODE(fn); 746 754 ext4_superblock_t *sb = enode->instance->filesystem->superblock; 747 755 return ext4_inode_get_size(sb, enode->inode_ref->inode); … … 755 763 * 756 764 */ 757 unsigned ext4 fs_lnkcnt_get(fs_node_t *fn)758 { 759 ext4 fs_node_t *enode = EXT4FS_NODE(fn);765 unsigned ext4_lnkcnt_get(fs_node_t *fn) 766 { 767 ext4_node_t *enode = EXT4_NODE(fn); 760 768 uint32_t lnkcnt = ext4_inode_get_links_count(enode->inode_ref->inode); 761 769 762 if (ext4 fs_is_directory(fn)) {770 if (ext4_is_directory(fn)) { 763 771 if (lnkcnt > 1) 764 772 return 1; … … 778 786 * 779 787 */ 780 bool ext4 fs_is_directory(fs_node_t *fn)781 { 782 ext4 fs_node_t *enode = EXT4FS_NODE(fn);788 bool ext4_is_directory(fs_node_t *fn) 789 { 790 ext4_node_t *enode = EXT4_NODE(fn); 783 791 ext4_superblock_t *sb = enode->instance->filesystem->superblock; 784 792 … … 794 802 * 795 803 */ 796 bool ext4 fs_is_file(fs_node_t *fn)797 { 798 ext4 fs_node_t *enode = EXT4FS_NODE(fn);804 bool ext4_is_file(fs_node_t *fn) 805 { 806 ext4_node_t *enode = EXT4_NODE(fn); 799 807 ext4_superblock_t *sb = enode->instance->filesystem->superblock; 800 808 … … 810 818 * 811 819 */ 812 service_id_t ext4 fs_service_get(fs_node_t *fn)813 { 814 ext4 fs_node_t *enode = EXT4FS_NODE(fn);820 service_id_t ext4_service_get(fs_node_t *fn) 821 { 822 ext4_node_t *enode = EXT4_NODE(fn); 815 823 return enode->instance->service_id; 816 824 } 817 825 818 int ext4 fs_size_block(service_id_t service_id, uint32_t *size)819 { 820 ext4 fs_instance_t *inst;821 int rc = ext4 fs_instance_get(service_id, &inst);826 int ext4_size_block(service_id_t service_id, uint32_t *size) 827 { 828 ext4_instance_t *inst; 829 int rc = ext4_instance_get(service_id, &inst); 822 830 if (rc != EOK) 823 831 return rc; … … 832 840 } 833 841 834 int ext4 fs_total_block_count(service_id_t service_id, uint64_t *count)835 { 836 ext4 fs_instance_t *inst;837 int rc = ext4 fs_instance_get(service_id, &inst);842 int ext4_total_block_count(service_id_t service_id, uint64_t *count) 843 { 844 ext4_instance_t *inst; 845 int rc = ext4_instance_get(service_id, &inst); 838 846 if (rc != EOK) 839 847 return rc; … … 848 856 } 849 857 850 int ext4 fs_free_block_count(service_id_t service_id, uint64_t *count)851 { 852 ext4 fs_instance_t *inst;853 int rc = ext4 fs_instance_get(service_id, &inst);858 int ext4_free_block_count(service_id_t service_id, uint64_t *count) 859 { 860 ext4_instance_t *inst; 861 int rc = ext4_instance_get(service_id, &inst); 854 862 if (rc != EOK) 855 863 return rc; … … 864 872 * libfs operations. 865 873 */ 866 libfs_ops_t ext4 fs_libfs_ops = {867 .root_get = ext4 fs_root_get,868 .match = ext4 fs_match,869 .node_get = ext4 fs_node_get,870 .node_open = ext4 fs_node_open,871 .node_put = ext4 fs_node_put,872 .create = ext4 fs_create_node,873 .destroy = ext4 fs_destroy_node,874 .link = ext4 fs_link,875 .unlink = ext4 fs_unlink,876 .has_children = ext4 fs_has_children,877 .index_get = ext4 fs_index_get,878 .size_get = ext4 fs_size_get,879 .lnkcnt_get = ext4 fs_lnkcnt_get,880 .is_directory = ext4 fs_is_directory,881 .is_file = ext4 fs_is_file,882 .service_get = ext4 fs_service_get,883 .size_block = ext4 fs_size_block,884 .total_block_count = ext4 fs_total_block_count,885 .free_block_count = ext4 fs_free_block_count874 libfs_ops_t ext4_libfs_ops = { 875 .root_get = ext4_root_get, 876 .match = ext4_match, 877 .node_get = ext4_node_get, 878 .node_open = ext4_node_open, 879 .node_put = ext4_node_put, 880 .create = ext4_create_node, 881 .destroy = ext4_destroy_node, 882 .link = ext4_link, 883 .unlink = ext4_unlink, 884 .has_children = ext4_has_children, 885 .index_get = ext4_index_get, 886 .size_get = ext4_size_get, 887 .lnkcnt_get = ext4_lnkcnt_get, 888 .is_directory = ext4_is_directory, 889 .is_file = ext4_is_file, 890 .service_get = ext4_service_get, 891 .size_block = ext4_size_block, 892 .total_block_count = ext4_total_block_count, 893 .free_block_count = ext4_free_block_count 886 894 }; 887 895 … … 899 907 * @return Error code 900 908 */ 901 static int ext4 fs_fsprobe(service_id_t service_id, vfs_fs_probe_info_t *info)909 static int ext4_fsprobe(service_id_t service_id, vfs_fs_probe_info_t *info) 902 910 { 903 911 return ENOTSUP; … … 917 925 * 918 926 */ 919 static int ext4 fs_mounted(service_id_t service_id, const char *opts,927 static int ext4_mounted(service_id_t service_id, const char *opts, 920 928 fs_index_t *index, aoff64_t *size, unsigned *lnkcnt) 921 929 { … … 927 935 928 936 /* Allocate instance structure */ 929 ext4 fs_instance_t *inst = (ext4fs_instance_t *)930 malloc(sizeof(ext4 fs_instance_t));937 ext4_instance_t *inst = (ext4_instance_t *) 938 malloc(sizeof(ext4_instance_t)); 931 939 if (inst == NULL) { 932 940 free(fs); … … 976 984 * 977 985 */ 978 static int ext4 fs_unmounted(service_id_t service_id)979 { 980 ext4 fs_instance_t *inst;981 int rc = ext4 fs_instance_get(service_id, &inst);986 static int ext4_unmounted(service_id_t service_id) 987 { 988 ext4_instance_t *inst; 989 int rc = ext4_instance_get(service_id, &inst); 982 990 if (rc != EOK) 983 991 return rc; … … 1010 1018 * 1011 1019 */ 1012 static int ext4 fs_read(service_id_t service_id, fs_index_t index, aoff64_t pos,1020 static int ext4_read(service_id_t service_id, fs_index_t index, aoff64_t pos, 1013 1021 size_t *rbytes) 1014 1022 { … … 1023 1031 } 1024 1032 1025 ext4 fs_instance_t *inst;1026 int rc = ext4 fs_instance_get(service_id, &inst);1033 ext4_instance_t *inst; 1034 int rc = ext4_instance_get(service_id, &inst); 1027 1035 if (rc != EOK) { 1028 1036 async_answer_0(callid, rc); … … 1041 1049 if (ext4_inode_is_type(inst->filesystem->superblock, inode_ref->inode, 1042 1050 EXT4_INODE_MODE_FILE)) { 1043 rc = ext4 fs_read_file(callid, pos, size, inst, inode_ref,1051 rc = ext4_read_file(callid, pos, size, inst, inode_ref, 1044 1052 rbytes); 1045 1053 } else if (ext4_inode_is_type(inst->filesystem->superblock, 1046 1054 inode_ref->inode, EXT4_INODE_MODE_DIRECTORY)) { 1047 rc = ext4 fs_read_directory(callid, pos, size, inst, inode_ref,1055 rc = ext4_read_directory(callid, pos, size, inst, inode_ref, 1048 1056 rbytes); 1049 1057 } else { … … 1066 1074 * 1067 1075 */ 1068 bool ext4 fs_is_dots(const uint8_t *name, size_t name_size)1076 bool ext4_is_dots(const uint8_t *name, size_t name_size) 1069 1077 { 1070 1078 if ((name_size == 1) && (name[0] == '.')) … … 1089 1097 * 1090 1098 */ 1091 int ext4 fs_read_directory(ipc_callid_t callid, aoff64_t pos, size_t size,1092 ext4 fs_instance_t *inst, ext4_inode_ref_t *inode_ref, size_t *rbytes)1099 int ext4_read_directory(ipc_callid_t callid, aoff64_t pos, size_t size, 1100 ext4_instance_t *inst, ext4_inode_ref_t *inode_ref, size_t *rbytes) 1093 1101 { 1094 1102 ext4_directory_iterator_t it; … … 1113 1121 1114 1122 /* Skip . and .. */ 1115 if (ext4 fs_is_dots(it.current->name, name_size))1123 if (ext4_is_dots(it.current->name, name_size)) 1116 1124 goto skip; 1117 1125 … … 1180 1188 * 1181 1189 */ 1182 int ext4 fs_read_file(ipc_callid_t callid, aoff64_t pos, size_t size,1183 ext4 fs_instance_t *inst, ext4_inode_ref_t *inode_ref, size_t *rbytes)1190 int ext4_read_file(ipc_callid_t callid, aoff64_t pos, size_t size, 1191 ext4_instance_t *inst, ext4_inode_ref_t *inode_ref, size_t *rbytes) 1184 1192 { 1185 1193 ext4_superblock_t *sb = inst->filesystem->superblock; … … 1269 1277 * 1270 1278 */ 1271 static int ext4 fs_write(service_id_t service_id, fs_index_t index, aoff64_t pos,1279 static int ext4_write(service_id_t service_id, fs_index_t index, aoff64_t pos, 1272 1280 size_t *wbytes, aoff64_t *nsize) 1273 1281 { 1274 1282 fs_node_t *fn; 1275 int rc = ext4 fs_node_get(&fn, service_id, index);1283 int rc = ext4_node_get(&fn, service_id, index); 1276 1284 if (rc != EOK) 1277 1285 return rc; … … 1285 1293 } 1286 1294 1287 ext4 fs_node_t *enode = EXT4FS_NODE(fn);1295 ext4_node_t *enode = EXT4_NODE(fn); 1288 1296 ext4_filesystem_t *fs = enode->instance->filesystem; 1289 1297 … … 1391 1399 ; 1392 1400 1393 int const rc2 = ext4 fs_node_put(fn);1401 int const rc2 = ext4_node_put(fn); 1394 1402 return rc == EOK ? rc2 : rc; 1395 1403 } … … 1406 1414 * 1407 1415 */ 1408 static int ext4 fs_truncate(service_id_t service_id, fs_index_t index,1416 static int ext4_truncate(service_id_t service_id, fs_index_t index, 1409 1417 aoff64_t new_size) 1410 1418 { 1411 1419 fs_node_t *fn; 1412 int rc = ext4 fs_node_get(&fn, service_id, index);1413 if (rc != EOK) 1414 return rc; 1415 1416 ext4 fs_node_t *enode = EXT4FS_NODE(fn);1420 int rc = ext4_node_get(&fn, service_id, index); 1421 if (rc != EOK) 1422 return rc; 1423 1424 ext4_node_t *enode = EXT4_NODE(fn); 1417 1425 ext4_inode_ref_t *inode_ref = enode->inode_ref; 1418 1426 1419 1427 rc = ext4_filesystem_truncate_inode(inode_ref, new_size); 1420 int const rc2 = ext4 fs_node_put(fn);1428 int const rc2 = ext4_node_put(fn); 1421 1429 1422 1430 return rc == EOK ? rc2 : rc; … … 1431 1439 * 1432 1440 */ 1433 static int ext4 fs_close(service_id_t service_id, fs_index_t index)1441 static int ext4_close(service_id_t service_id, fs_index_t index) 1434 1442 { 1435 1443 return EOK; … … 1444 1452 * 1445 1453 */ 1446 static int ext4 fs_destroy(service_id_t service_id, fs_index_t index)1454 static int ext4_destroy(service_id_t service_id, fs_index_t index) 1447 1455 { 1448 1456 fs_node_t *fn; 1449 int rc = ext4 fs_node_get(&fn, service_id, index);1457 int rc = ext4_node_get(&fn, service_id, index); 1450 1458 if (rc != EOK) 1451 1459 return rc; 1452 1460 1453 1461 /* Destroy the inode */ 1454 return ext4 fs_destroy_node(fn);1462 return ext4_destroy_node(fn); 1455 1463 } 1456 1464 … … 1461 1469 * 1462 1470 */ 1463 static int ext4 fs_sync(service_id_t service_id, fs_index_t index)1471 static int ext4_sync(service_id_t service_id, fs_index_t index) 1464 1472 { 1465 1473 fs_node_t *fn; 1466 int rc = ext4 fs_node_get(&fn, service_id, index);1467 if (rc != EOK) 1468 return rc; 1469 1470 ext4 fs_node_t *enode = EXT4FS_NODE(fn);1474 int rc = ext4_node_get(&fn, service_id, index); 1475 if (rc != EOK) 1476 return rc; 1477 1478 ext4_node_t *enode = EXT4_NODE(fn); 1471 1479 enode->inode_ref->dirty = true; 1472 1480 1473 return ext4 fs_node_put(fn);1481 return ext4_node_put(fn); 1474 1482 } 1475 1483 … … 1477 1485 * 1478 1486 */ 1479 vfs_out_ops_t ext4 fs_ops = {1480 .fsprobe = ext4 fs_fsprobe,1481 .mounted = ext4 fs_mounted,1482 .unmounted = ext4 fs_unmounted,1483 .read = ext4 fs_read,1484 .write = ext4 fs_write,1485 .truncate = ext4 fs_truncate,1486 .close = ext4 fs_close,1487 .destroy = ext4 fs_destroy,1488 .sync = ext4 fs_sync1487 vfs_out_ops_t ext4_ops = { 1488 .fsprobe = ext4_fsprobe, 1489 .mounted = ext4_mounted, 1490 .unmounted = ext4_unmounted, 1491 .read = ext4_read, 1492 .write = ext4_write, 1493 .truncate = ext4_truncate, 1494 .close = ext4_close, 1495 .destroy = ext4_destroy, 1496 .sync = ext4_sync 1489 1497 }; 1490 1498 -
uspace/srv/fs/ext4fs/ext4fs.c
r4bfad34 rbe39fc6 72 72 } 73 73 74 int rc = ext4 fs_global_init();74 int rc = ext4_global_init(); 75 75 if (rc != EOK) { 76 76 printf("%s: Global initialization failed\n", NAME); … … 78 78 } 79 79 80 rc = fs_register(vfs_sess, &ext4fs_vfs_info, &ext4 fs_ops,81 &ext4 fs_libfs_ops);80 rc = fs_register(vfs_sess, &ext4fs_vfs_info, &ext4_ops, 81 &ext4_libfs_ops); 82 82 if (rc != EOK) { 83 83 printf("%s: Failed to register file system\n", NAME);
Note:
See TracChangeset
for help on using the changeset viewer.