Changeset b6035ba in mainline
- Timestamp:
- 2009-05-05T22:09:13Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 770d281
- Parents:
- c852f4be
- Location:
- uspace
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libfs/libfs.c
rc852f4be rb6035ba 149 149 last += PLB_SIZE; 150 150 151 void*par = NULL;152 void*cur = ops->root_get(dev_handle);153 void*tmp = NULL;151 fs_node_t *par = NULL; 152 fs_node_t *cur = ops->root_get(dev_handle); 153 fs_node_t *tmp = NULL; 154 154 155 155 if (ops->plb_get_char(next) == '/') … … 190 190 goto out; 191 191 } 192 void *nodep;192 fs_node_t *fn; 193 193 if (lflag & L_CREATE) 194 nodep= ops->create(dev_handle, lflag);194 fn = ops->create(dev_handle, lflag); 195 195 else 196 nodep= ops->node_get(dev_handle,196 fn = ops->node_get(dev_handle, 197 197 index); 198 if ( nodep) {198 if (fn) { 199 199 int rc; 200 200 201 rc = ops->link(cur, nodep, component);201 rc = ops->link(cur, fn, component); 202 202 if (rc != EOK) { 203 203 if (lflag & L_CREATE) { 204 (void)ops->destroy( 205 nodep); 204 (void)ops->destroy(fn); 206 205 } 207 206 ipc_answer_0(rid, rc); … … 209 208 ipc_answer_5(rid, EOK, 210 209 fs_handle, dev_handle, 211 ops->index_get( nodep),212 ops->size_get( nodep),213 ops->lnkcnt_get( nodep));214 ops->node_put( nodep);210 ops->index_get(fn), 211 ops->size_get(fn), 212 ops->lnkcnt_get(fn)); 213 ops->node_put(fn); 215 214 } 216 215 } else { … … 264 263 component[len] = '\0'; 265 264 266 void *nodep;265 fs_node_t *fn; 267 266 if (lflag & L_CREATE) 268 nodep= ops->create(dev_handle, lflag);267 fn = ops->create(dev_handle, lflag); 269 268 else 270 nodep= ops->node_get(dev_handle, index);271 if ( nodep) {269 fn = ops->node_get(dev_handle, index); 270 if (fn) { 272 271 int rc; 273 272 274 rc = ops->link(cur, nodep, component);273 rc = ops->link(cur, fn, component); 275 274 if (rc != EOK) { 276 275 if (lflag & L_CREATE) 277 (void)ops->destroy( nodep);276 (void)ops->destroy(fn); 278 277 ipc_answer_0(rid, rc); 279 278 } else { 280 279 ipc_answer_5(rid, EOK, 281 280 fs_handle, dev_handle, 282 ops->index_get( nodep),283 ops->size_get( nodep),284 ops->lnkcnt_get( nodep));285 ops->node_put( nodep);281 ops->index_get(fn), 282 ops->size_get(fn), 283 ops->lnkcnt_get(fn)); 284 ops->node_put(fn); 286 285 } 287 286 } else { -
uspace/lib/libfs/libfs.h
rc852f4be rb6035ba 43 43 44 44 typedef struct { 45 void * (* match)(void *, const char *); 46 void * (* node_get)(dev_handle_t, fs_index_t); 47 void (* node_put)(void *); 48 void * (* create)(dev_handle_t, int); 49 int (* destroy)(void *); 50 int (* link)(void *, void *, const char *); 51 int (* unlink)(void *, void *); 52 fs_index_t (* index_get)(void *); 53 size_t (* size_get)(void *); 54 unsigned (* lnkcnt_get)(void *); 55 bool (* has_children)(void *); 56 void *(* root_get)(dev_handle_t); 45 void *data; /**< Data of the file system implementation. */ 46 } fs_node_t; 47 48 typedef struct { 49 fs_node_t * (* match)(fs_node_t *, const char *); 50 fs_node_t * (* node_get)(dev_handle_t, fs_index_t); 51 void (* node_put)(fs_node_t *); 52 fs_node_t * (* create)(dev_handle_t, int); 53 int (* destroy)(fs_node_t *); 54 int (* link)(fs_node_t *, fs_node_t *, const char *); 55 int (* unlink)(fs_node_t *, fs_node_t *); 56 fs_index_t (* index_get)(fs_node_t *); 57 size_t (* size_get)(fs_node_t *); 58 unsigned (* lnkcnt_get)(fs_node_t *); 59 bool (* has_children)(fs_node_t *); 60 fs_node_t *(* root_get)(dev_handle_t); 57 61 char (* plb_get_char)(unsigned pos); 58 bool (* is_directory)( void*);59 bool (* is_file)( void*);62 bool (* is_directory)(fs_node_t *); 63 bool (* is_file)(fs_node_t *); 60 64 } libfs_ops_t; 61 65 -
uspace/srv/fs/fat/fat.h
rc852f4be rb6035ba 179 179 /** FAT in-core node. */ 180 180 typedef struct fat_node { 181 /** Back pointer to the FS node. */ 182 fs_node_t *bp; 183 181 184 futex_t lock; 182 185 fat_node_type_t type; -
uspace/srv/fs/fat/fat_ops.c
rc852f4be rb6035ba 56 56 #include <align.h> 57 57 58 #define FAT_NODE(node) ((node) ? (fat_node_t *) (node)->data : NULL) 59 #define FS_NODE(node) ((node) ? (node)->bp : NULL) 60 58 61 /** Futex protecting the list of cached free FAT nodes. */ 59 62 static futex_t ffn_futex = FUTEX_INITIALIZER; … … 65 68 { 66 69 futex_initialize(&node->lock, 1); 70 node->bp = NULL; 67 71 node->idx = NULL; 68 72 node->type = 0; … … 109 113 static fat_node_t *fat_node_get_new(void) 110 114 { 115 fs_node_t *fn; 111 116 fat_node_t *nodep; 112 117 … … 130 135 futex_up(&nodep->lock); 131 136 futex_up(&idxp_tmp->lock); 137 fn = FS_NODE(nodep); 132 138 } else { 133 139 skip_cache: 134 140 /* Try to allocate a new node structure. */ 135 141 futex_up(&ffn_futex); 142 fn = (fs_node_t *)malloc(sizeof(fs_node_t)); 143 if (!fn) 144 return NULL; 136 145 nodep = (fat_node_t *)malloc(sizeof(fat_node_t)); 137 if (!nodep) 146 if (!nodep) { 147 free(fn); 138 148 return NULL; 149 } 139 150 } 140 151 fat_node_initialize(nodep); 152 fn->data = nodep; 153 nodep->bp = fn; 141 154 142 155 return nodep; … … 147 160 * @param idxp Locked index structure. 148 161 */ 149 static void*fat_node_get_core(fat_idx_t *idxp)162 static fat_node_t *fat_node_get_core(fat_idx_t *idxp) 150 163 { 151 164 block_t *b; … … 224 237 * Forward declarations of FAT libfs operations. 225 238 */ 226 static void*fat_node_get(dev_handle_t, fs_index_t);227 static void fat_node_put( void*);228 static void*fat_create_node(dev_handle_t, int);229 static int fat_destroy_node( void*);230 static int fat_link( void *, void*, const char *);231 static int fat_unlink( void *, void*);232 static void *fat_match(void*, const char *);233 static fs_index_t fat_index_get( void*);234 static size_t fat_size_get( void*);235 static unsigned fat_lnkcnt_get( void*);236 static bool fat_has_children( void*);237 static void*fat_root_get(dev_handle_t);239 static fs_node_t *fat_node_get(dev_handle_t, fs_index_t); 240 static void fat_node_put(fs_node_t *); 241 static fs_node_t *fat_create_node(dev_handle_t, int); 242 static int fat_destroy_node(fs_node_t *); 243 static int fat_link(fs_node_t *, fs_node_t *, const char *); 244 static int fat_unlink(fs_node_t *, fs_node_t *); 245 static fs_node_t *fat_match(fs_node_t *, const char *); 246 static fs_index_t fat_index_get(fs_node_t *); 247 static size_t fat_size_get(fs_node_t *); 248 static unsigned fat_lnkcnt_get(fs_node_t *); 249 static bool fat_has_children(fs_node_t *); 250 static fs_node_t *fat_root_get(dev_handle_t); 238 251 static char fat_plb_get_char(unsigned); 239 static bool fat_is_directory( void*);240 static bool fat_is_file( void*node);252 static bool fat_is_directory(fs_node_t *); 253 static bool fat_is_file(fs_node_t *node); 241 254 242 255 /* … … 245 258 246 259 /** Instantiate a FAT in-core node. */ 247 void*fat_node_get(dev_handle_t dev_handle, fs_index_t index)248 { 249 void *node;260 fs_node_t *fat_node_get(dev_handle_t dev_handle, fs_index_t index) 261 { 262 fat_node_t *nodep; 250 263 fat_idx_t *idxp; 251 264 … … 254 267 return NULL; 255 268 /* idxp->lock held */ 256 node = fat_node_get_core(idxp);269 nodep = fat_node_get_core(idxp); 257 270 futex_up(&idxp->lock); 258 return node;259 } 260 261 void fat_node_put( void *node)262 { 263 fat_node_t *nodep = (fat_node_t *)node;271 return FS_NODE(nodep); 272 } 273 274 void fat_node_put(fs_node_t *fn) 275 { 276 fat_node_t *nodep = FAT_NODE(fn); 264 277 bool destroy = false; 265 278 … … 281 294 } 282 295 futex_up(&nodep->lock); 283 if (destroy) 284 free(node); 285 } 286 287 void *fat_create_node(dev_handle_t dev_handle, int flags) 296 if (destroy) { 297 free(nodep->bp); 298 free(nodep); 299 } 300 } 301 302 fs_node_t *fat_create_node(dev_handle_t dev_handle, int flags) 288 303 { 289 304 fat_idx_t *idxp; … … 311 326 if (!idxp) { 312 327 fat_free_clusters(bs, dev_handle, mcl); 313 fat_node_put( nodep);328 fat_node_put(FS_NODE(nodep)); 314 329 return NULL; 315 330 } … … 346 361 347 362 futex_up(&idxp->lock); 348 return nodep;349 } 350 351 int fat_destroy_node( void *node)352 { 353 fat_node_t *nodep = (fat_node_t *)node;363 return FS_NODE(nodep); 364 } 365 366 int fat_destroy_node(fs_node_t *fn) 367 { 368 fat_node_t *nodep = FAT_NODE(fn); 354 369 fat_bs_t *bs; 355 370 … … 365 380 * The node may not have any children. 366 381 */ 367 assert(fat_has_children( node) == false);382 assert(fat_has_children(fn) == false); 368 383 369 384 bs = block_bb_get(nodep->idx->dev_handle); … … 375 390 376 391 fat_idx_destroy(nodep->idx); 392 free(nodep->bp); 377 393 free(nodep); 378 394 return EOK; 379 395 } 380 396 381 int fat_link( void *prnt, void *chld, const char *name)382 { 383 fat_node_t *parentp = (fat_node_t *)prnt;384 fat_node_t *childp = (fat_node_t *)chld;397 int fat_link(fs_node_t *pfn, fs_node_t *cfn, const char *name) 398 { 399 fat_node_t *parentp = FAT_NODE(pfn); 400 fat_node_t *childp = FAT_NODE(cfn); 385 401 fat_dentry_t *d; 386 402 fat_bs_t *bs; … … 528 544 } 529 545 530 int fat_unlink( void *prnt, void *chld)531 { 532 fat_node_t *parentp = (fat_node_t *)prnt;533 fat_node_t *childp = (fat_node_t *)chld;546 int fat_unlink(fs_node_t *pfn, fs_node_t *cfn) 547 { 548 fat_node_t *parentp = FAT_NODE(pfn); 549 fat_node_t *childp = FAT_NODE(cfn); 534 550 fat_bs_t *bs; 535 551 fat_dentry_t *d; … … 568 584 } 569 585 570 void *fat_match(void *prnt, const char *component)586 fs_node_t *fat_match(fs_node_t *pfn, const char *component) 571 587 { 572 588 fat_bs_t *bs; 573 fat_node_t *parentp = (fat_node_t *)prnt;589 fat_node_t *parentp = FAT_NODE(pfn); 574 590 char name[FAT_NAME_LEN + 1 + FAT_EXT_LEN + 1]; 575 591 unsigned i, j; … … 604 620 if (fat_dentry_namecmp(name, component) == 0) { 605 621 /* hit */ 606 void *node;622 fat_node_t *nodep; 607 623 /* 608 624 * Assume tree hierarchy for locking. We … … 623 639 return NULL; 624 640 } 625 node = fat_node_get_core(idx);641 nodep = fat_node_get_core(idx); 626 642 futex_up(&idx->lock); 627 643 block_put(b); 628 return node;644 return FS_NODE(nodep); 629 645 } 630 646 } … … 636 652 } 637 653 638 fs_index_t fat_index_get(void *node) 639 { 640 fat_node_t *fnodep = (fat_node_t *)node; 641 if (!fnodep) 642 return 0; 643 return fnodep->idx->index; 644 } 645 646 size_t fat_size_get(void *node) 647 { 648 return ((fat_node_t *)node)->size; 649 } 650 651 unsigned fat_lnkcnt_get(void *node) 652 { 653 return ((fat_node_t *)node)->lnkcnt; 654 } 655 656 bool fat_has_children(void *node) 654 fs_index_t fat_index_get(fs_node_t *fn) 655 { 656 return FAT_NODE(fn)->idx->index; 657 } 658 659 size_t fat_size_get(fs_node_t *fn) 660 { 661 return FAT_NODE(fn)->size; 662 } 663 664 unsigned fat_lnkcnt_get(fs_node_t *fn) 665 { 666 return FAT_NODE(fn)->lnkcnt; 667 } 668 669 bool fat_has_children(fs_node_t *fn) 657 670 { 658 671 fat_bs_t *bs; 659 fat_node_t *nodep = (fat_node_t *)node;672 fat_node_t *nodep = FAT_NODE(fn); 660 673 unsigned bps; 661 674 unsigned dps; … … 705 718 } 706 719 707 void*fat_root_get(dev_handle_t dev_handle)720 fs_node_t *fat_root_get(dev_handle_t dev_handle) 708 721 { 709 722 return fat_node_get(dev_handle, 0); … … 715 728 } 716 729 717 bool fat_is_directory( void *node)718 { 719 return ((fat_node_t *)node)->type == FAT_DIRECTORY;720 } 721 722 bool fat_is_file( void *node)723 { 724 return ((fat_node_t *)node)->type == FAT_FILE;730 bool fat_is_directory(fs_node_t *fn) 731 { 732 return FAT_NODE(fn)->type == FAT_DIRECTORY; 733 } 734 735 bool fat_is_file(fs_node_t *fn) 736 { 737 return FAT_NODE(fn)->type == FAT_FILE; 725 738 } 726 739 … … 822 835 823 836 /* Initialize the root node. */ 824 f at_node_t *rootp = (fat_node_t *)malloc(sizeof(fat_node_t));825 if (!r ootp) {837 fs_node_t *rfn = (fs_node_t *)malloc(sizeof(fs_node_t)); 838 if (!rfn) { 826 839 block_fini(dev_handle); 827 840 fat_idx_fini_by_dev_handle(dev_handle); … … 829 842 return; 830 843 } 844 fat_node_t *rootp = (fat_node_t *)malloc(sizeof(fat_node_t)); 845 if (!rootp) { 846 free(rfn); 847 block_fini(dev_handle); 848 fat_idx_fini_by_dev_handle(dev_handle); 849 ipc_answer_0(rid, ENOMEM); 850 return; 851 } 831 852 fat_node_initialize(rootp); 832 853 833 854 fat_idx_t *ridxp = fat_idx_get_by_pos(dev_handle, FAT_CLST_ROOTPAR, 0); 834 855 if (!ridxp) { 856 free(rfn); 857 free(rootp); 835 858 block_fini(dev_handle); 836 free(rootp);837 859 fat_idx_fini_by_dev_handle(dev_handle); 838 860 ipc_answer_0(rid, ENOMEM); … … 849 871 rootp->idx = ridxp; 850 872 ridxp->nodep = rootp; 873 rootp->bp = rfn; 874 rfn->data = rootp; 851 875 852 876 futex_up(&ridxp->lock); … … 870 894 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 871 895 off_t pos = (off_t)IPC_GET_ARG3(*request); 872 fat_node_t *nodep = (fat_node_t *)fat_node_get(dev_handle, index); 896 fs_node_t *fn = fat_node_get(dev_handle, index); 897 fat_node_t *nodep; 873 898 fat_bs_t *bs; 874 899 uint16_t bps; … … 876 901 block_t *b; 877 902 878 if (! nodep) {903 if (!fn) { 879 904 ipc_answer_0(rid, ENOENT); 880 905 return; 881 906 } 907 nodep = FAT_NODE(fn); 882 908 883 909 ipc_callid_t callid; 884 910 size_t len; 885 911 if (!ipc_data_read_receive(&callid, &len)) { 886 fat_node_put( nodep);912 fat_node_put(fn); 887 913 ipc_answer_0(callid, EINVAL); 888 914 ipc_answer_0(rid, EINVAL); … … 955 981 } 956 982 miss: 957 fat_node_put( nodep);983 fat_node_put(fn); 958 984 ipc_answer_0(callid, ENOENT); 959 985 ipc_answer_1(rid, ENOENT, 0); … … 964 990 } 965 991 966 fat_node_put( nodep);992 fat_node_put(fn); 967 993 ipc_answer_1(rid, EOK, (ipcarg_t)bytes); 968 994 } … … 973 999 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 974 1000 off_t pos = (off_t)IPC_GET_ARG3(*request); 975 fat_node_t *nodep = (fat_node_t *)fat_node_get(dev_handle, index); 1001 fs_node_t *fn = fat_node_get(dev_handle, index); 1002 fat_node_t *nodep; 976 1003 fat_bs_t *bs; 977 1004 size_t bytes; … … 983 1010 int flags = BLOCK_FLAGS_NONE; 984 1011 985 if (! nodep) {1012 if (!fn) { 986 1013 ipc_answer_0(rid, ENOENT); 987 1014 return; 988 1015 } 1016 nodep = FAT_NODE(fn); 989 1017 990 1018 ipc_callid_t callid; 991 1019 size_t len; 992 1020 if (!ipc_data_write_receive(&callid, &len)) { 993 fat_node_put( nodep);1021 fat_node_put(fn); 994 1022 ipc_answer_0(callid, EINVAL); 995 1023 ipc_answer_0(rid, EINVAL); … … 1032 1060 } 1033 1061 ipc_answer_2(rid, EOK, bytes, nodep->size); 1034 fat_node_put( nodep);1062 fat_node_put(fn); 1035 1063 return; 1036 1064 } else { … … 1048 1076 if (status != EOK) { 1049 1077 /* could not allocate a chain of nclsts clusters */ 1050 fat_node_put( nodep);1078 fat_node_put(fn); 1051 1079 ipc_answer_0(callid, status); 1052 1080 ipc_answer_0(rid, status); … … 1069 1097 nodep->dirty = true; /* need to sync node */ 1070 1098 ipc_answer_2(rid, EOK, bytes, nodep->size); 1071 fat_node_put( nodep);1099 fat_node_put(fn); 1072 1100 return; 1073 1101 } … … 1079 1107 fs_index_t index = (fs_index_t)IPC_GET_ARG2(*request); 1080 1108 size_t size = (off_t)IPC_GET_ARG3(*request); 1081 fat_node_t *nodep = (fat_node_t *)fat_node_get(dev_handle, index); 1109 fs_node_t *fn = fat_node_get(dev_handle, index); 1110 fat_node_t *nodep; 1082 1111 fat_bs_t *bs; 1083 1112 uint16_t bps; … … 1086 1115 int rc; 1087 1116 1088 if (! nodep) {1117 if (!fn) { 1089 1118 ipc_answer_0(rid, ENOENT); 1090 1119 return; 1091 1120 } 1121 nodep = FAT_NODE(fn); 1092 1122 1093 1123 bs = block_bb_get(dev_handle); … … 1127 1157 rc = EOK; 1128 1158 } 1129 fat_node_put( nodep);1159 fat_node_put(fn); 1130 1160 ipc_answer_0(rid, rc); 1131 1161 return; … … 1138 1168 int rc; 1139 1169 1140 f at_node_t *nodep= fat_node_get(dev_handle, index);1141 if (! nodep) {1170 fs_node_t *fn = fat_node_get(dev_handle, index); 1171 if (!fn) { 1142 1172 ipc_answer_0(rid, ENOENT); 1143 1173 return; 1144 1174 } 1145 1175 1146 rc = fat_destroy_node( nodep);1176 rc = fat_destroy_node(fn); 1147 1177 ipc_answer_0(rid, rc); 1148 1178 } -
uspace/srv/fs/tmpfs/tmpfs.h
rc852f4be rb6035ba 45 45 #endif 46 46 47 #define TMPFS_NODE(node) ((node) ? (tmpfs_dentry_t *)(node)->data : NULL) 48 #define FS_NODE(node) ((node) ? (node)->bp : NULL) 49 47 50 typedef enum { 48 51 TMPFS_NONE, … … 52 55 53 56 typedef struct tmpfs_dentry { 57 fs_node_t *bp; /**< Back pointer to the FS node. */ 54 58 fs_index_t index; /**< TMPFS node index. */ 55 59 dev_handle_t dev_handle;/**< Device handle. */ -
uspace/srv/fs/tmpfs/tmpfs_dump.c
rc852f4be rb6035ba 56 56 static bool 57 57 tmpfs_restore_recursion(int dev, off_t *bufpos, size_t *buflen, off_t *pos, 58 tmpfs_dentry_t *parent)58 fs_node_t *pfn) 59 59 { 60 60 struct rdentry entry; … … 64 64 do { 65 65 char *fname; 66 tmpfs_dentry_t *node; 66 fs_node_t *fn; 67 tmpfs_dentry_t *nodep; 67 68 uint32_t size; 68 69 … … 81 82 return false; 82 83 83 node = (tmpfs_dentry_t *)ops->create(dev, L_FILE);84 if ( node== NULL) {84 fn = ops->create(dev, L_FILE); 85 if (fn == NULL) { 85 86 free(fname); 86 87 return false; … … 89 90 if (block_read(dev, bufpos, buflen, pos, fname, 90 91 entry.len, TMPFS_BLOCK_SIZE) != EOK) { 91 ops->destroy( (void *) node);92 ops->destroy(fn); 92 93 free(fname); 93 94 return false; … … 95 96 fname[entry.len] = 0; 96 97 97 rc = ops->link( (void *) parent, (void *) node, fname);98 rc = ops->link(pfn, fn, fname); 98 99 if (rc != EOK) { 99 ops->destroy( (void *) node);100 ops->destroy(fn); 100 101 free(fname); 101 102 return false; … … 109 110 size = uint32_t_le2host(size); 110 111 111 node->data = malloc(size); 112 if (node->data == NULL) 112 nodep = TMPFS_NODE(fn); 113 nodep->data = malloc(size); 114 if (nodep->data == NULL) 113 115 return false; 114 116 115 node ->size = size;116 if (block_read(dev, bufpos, buflen, pos, node ->data,117 nodep->size = size; 118 if (block_read(dev, bufpos, buflen, pos, nodep->data, 117 119 size, TMPFS_BLOCK_SIZE) != EOK) 118 120 return false; … … 124 126 return false; 125 127 126 node = (tmpfs_dentry_t *)ops->create(dev, L_DIRECTORY);127 if ( node== NULL) {128 fn = ops->create(dev, L_DIRECTORY); 129 if (fn == NULL) { 128 130 free(fname); 129 131 return false; … … 132 134 if (block_read(dev, bufpos, buflen, pos, fname, 133 135 entry.len, TMPFS_BLOCK_SIZE) != EOK) { 134 ops->destroy( (void *) node);136 ops->destroy(fn); 135 137 free(fname); 136 138 return false; … … 138 140 fname[entry.len] = 0; 139 141 140 rc = ops->link( (void *) parent, (void *) node, fname);142 rc = ops->link(pfn, fn, fname); 141 143 if (rc != EOK) { 142 ops->destroy( (void *) node);144 ops->destroy(fn); 143 145 free(fname); 144 146 return false; … … 147 149 148 150 if (!tmpfs_restore_recursion(dev, bufpos, buflen, pos, 149 node))151 fn)) 150 152 return false; 151 153 -
uspace/srv/fs/tmpfs/tmpfs_ops.c
rc852f4be rb6035ba 69 69 70 70 /* Forward declarations of static functions. */ 71 static void *tmpfs_match(void*, const char *);72 static void*tmpfs_node_get(dev_handle_t, fs_index_t);73 static void tmpfs_node_put( void*);74 static void*tmpfs_create_node(dev_handle_t, int);75 static int tmpfs_link_node( void *, void*, const char *);76 static int tmpfs_unlink_node( void *, void*);77 static int tmpfs_destroy_node( void*);71 static fs_node_t *tmpfs_match(fs_node_t *, const char *); 72 static fs_node_t *tmpfs_node_get(dev_handle_t, fs_index_t); 73 static void tmpfs_node_put(fs_node_t *); 74 static fs_node_t *tmpfs_create_node(dev_handle_t, int); 75 static int tmpfs_link_node(fs_node_t *, fs_node_t *, const char *); 76 static int tmpfs_unlink_node(fs_node_t *, fs_node_t *); 77 static int tmpfs_destroy_node(fs_node_t *); 78 78 79 79 /* Implementation of helper functions. */ 80 static fs_index_t tmpfs_index_get( void *nodep)81 { 82 return ((tmpfs_dentry_t *) nodep)->index;83 } 84 85 static size_t tmpfs_size_get( void *nodep)86 { 87 return ((tmpfs_dentry_t *) nodep)->size;88 } 89 90 static unsigned tmpfs_lnkcnt_get( void *nodep)91 { 92 return ((tmpfs_dentry_t *) nodep)->lnkcnt;93 } 94 95 static bool tmpfs_has_children( void *nodep)96 { 97 return ((tmpfs_dentry_t *) nodep)->child != NULL;98 } 99 100 static void*tmpfs_root_get(dev_handle_t dev_handle)80 static fs_index_t tmpfs_index_get(fs_node_t *fn) 81 { 82 return TMPFS_NODE(fn)->index; 83 } 84 85 static size_t tmpfs_size_get(fs_node_t *fn) 86 { 87 return TMPFS_NODE(fn)->size; 88 } 89 90 static unsigned tmpfs_lnkcnt_get(fs_node_t *fn) 91 { 92 return TMPFS_NODE(fn)->lnkcnt; 93 } 94 95 static bool tmpfs_has_children(fs_node_t *fn) 96 { 97 return TMPFS_NODE(fn)->child != NULL; 98 } 99 100 static fs_node_t *tmpfs_root_get(dev_handle_t dev_handle) 101 101 { 102 102 return tmpfs_node_get(dev_handle, TMPFS_SOME_ROOT); … … 108 108 } 109 109 110 static bool tmpfs_is_directory( void *nodep)111 { 112 return ((tmpfs_dentry_t *) nodep)->type == TMPFS_DIRECTORY;113 } 114 115 static bool tmpfs_is_file( void *nodep)116 { 117 return ((tmpfs_dentry_t *) nodep)->type == TMPFS_FILE;110 static bool tmpfs_is_directory(fs_node_t *fn) 111 { 112 return TMPFS_NODE(fn)->type == TMPFS_DIRECTORY; 113 } 114 115 static bool tmpfs_is_file(fs_node_t *fn) 116 { 117 return TMPFS_NODE(fn)->type == TMPFS_FILE; 118 118 } 119 119 … … 214 214 static bool tmpfs_dentry_initialize(tmpfs_dentry_t *dentry) 215 215 { 216 dentry->bp = NULL; 216 217 dentry->index = 0; 217 218 dentry->dev_handle = 0; … … 237 238 static bool tmpfs_instance_init(dev_handle_t dev_handle) 238 239 { 239 tmpfs_dentry_t *root;240 fs_node_t *rfn; 240 241 241 r oot = (tmpfs_dentry_t *)tmpfs_create_node(dev_handle, L_DIRECTORY);242 if (!r oot)242 rfn = tmpfs_create_node(dev_handle, L_DIRECTORY); 243 if (!rfn) 243 244 return false; 244 root->lnkcnt = 0; /* FS root is not linked */245 TMPFS_NODE(rfn)->lnkcnt = 0; /* FS root is not linked */ 245 246 return true; 246 247 } … … 265 266 } 266 267 267 void *tmpfs_match(void *prnt, const char *component)268 { 269 tmpfs_dentry_t *parentp = (tmpfs_dentry_t *) prnt;268 fs_node_t *tmpfs_match(fs_node_t *pfn, const char *component) 269 { 270 tmpfs_dentry_t *parentp = TMPFS_NODE(pfn); 270 271 tmpfs_dentry_t *childp = parentp->child; 271 272 … … 273 274 childp = childp->sibling; 274 275 275 return (void *) childp; 276 } 277 278 void * 279 tmpfs_node_get(dev_handle_t dev_handle, fs_index_t index) 276 return FS_NODE(childp); 277 } 278 279 fs_node_t *tmpfs_node_get(dev_handle_t dev_handle, fs_index_t index) 280 280 { 281 281 unsigned long key[] = { … … 286 286 if (!lnk) 287 287 return NULL; 288 return hash_table_get_instance(lnk, tmpfs_dentry_t, dh_link);289 } 290 291 void tmpfs_node_put( void *node)288 return FS_NODE(hash_table_get_instance(lnk, tmpfs_dentry_t, dh_link)); 289 } 290 291 void tmpfs_node_put(fs_node_t *fn) 292 292 { 293 293 /* nothing to do */ 294 294 } 295 295 296 void*tmpfs_create_node(dev_handle_t dev_handle, int lflag)296 fs_node_t *tmpfs_create_node(dev_handle_t dev_handle, int lflag) 297 297 { 298 298 assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY)); 299 299 300 fs_node_t *fn = malloc(sizeof(fs_node_t)); 301 if (!fn) 302 return NULL; 303 300 304 tmpfs_dentry_t *node = malloc(sizeof(tmpfs_dentry_t)); 301 if (!node) 305 if (!node) { 306 free(fn); 302 307 return NULL; 303 308 } 304 309 if (!tmpfs_dentry_initialize(node)) { 310 free(fn); 305 311 free(node); 306 312 return NULL; 307 313 } 314 fn->data = node; 315 node->bp = fn; /* establish the back pointer */ 308 316 if (!tmpfs_root_get(dev_handle)) 309 317 node->index = TMPFS_SOME_ROOT; … … 322 330 }; 323 331 hash_table_insert(&dentries, key, &node->dh_link); 324 return (void *) node;325 } 326 327 int tmpfs_link_node( void *prnt, void *chld, const char *nm)328 { 329 tmpfs_dentry_t *parentp = (tmpfs_dentry_t *) prnt;330 tmpfs_dentry_t *childp = (tmpfs_dentry_t *) chld;332 return fn; 333 } 334 335 int tmpfs_link_node(fs_node_t *pfn, fs_node_t *cfn, const char *nm) 336 { 337 tmpfs_dentry_t *parentp = TMPFS_NODE(pfn); 338 tmpfs_dentry_t *childp = TMPFS_NODE(cfn); 331 339 332 340 assert(parentp->type == TMPFS_DIRECTORY); … … 363 371 } 364 372 365 int tmpfs_unlink_node( void *prnt, void *chld)366 { 367 tmpfs_dentry_t *parentp = (tmpfs_dentry_t *)prnt;368 tmpfs_dentry_t *childp = (tmpfs_dentry_t *)chld;373 int tmpfs_unlink_node(fs_node_t *pfn, fs_node_t *cfn) 374 { 375 tmpfs_dentry_t *parentp = TMPFS_NODE(pfn); 376 tmpfs_dentry_t *childp = TMPFS_NODE(cfn); 369 377 370 378 if (!parentp) … … 393 401 } 394 402 395 int tmpfs_destroy_node( void *nodep)396 { 397 tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) nodep;403 int tmpfs_destroy_node(fs_node_t *fn) 404 { 405 tmpfs_dentry_t *dentry = TMPFS_NODE(fn); 398 406 399 407 assert(!dentry->lnkcnt); … … 411 419 if (dentry->type == TMPFS_FILE) 412 420 free(dentry->data); 421 free(dentry->bp); 413 422 free(dentry); 414 423 return EOK; … … 447 456 } 448 457 449 tmpfs_dentry_t *root = tmpfs_root_get(dev_handle);458 tmpfs_dentry_t *root = TMPFS_NODE(tmpfs_root_get(dev_handle)); 450 459 if (str_cmp(opts, "restore") == 0) { 451 460 if (tmpfs_restore(dev_handle)) … … 673 682 tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t, 674 683 dh_link); 675 rc = tmpfs_destroy_node( dentry);684 rc = tmpfs_destroy_node(FS_NODE(dentry)); 676 685 ipc_answer_0(rid, rc); 677 686 }
Note:
See TracChangeset
for help on using the changeset viewer.