Changeset 2e37308 in mainline for uspace/srv/fs/tmpfs/tmpfs_ops.c
- Timestamp:
- 2009-09-25T11:50:12Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6d4c549
- Parents:
- d27ed12 (diff), 12bdc942 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/tmpfs/tmpfs_ops.c
rd27ed12 r2e37308 67 67 68 68 /* Forward declarations of static functions. */ 69 static fs_node_t *tmpfs_match(fs_node_t *, const char *); 70 static fs_node_t *tmpfs_node_get(dev_handle_t, fs_index_t); 71 static void tmpfs_node_put(fs_node_t *); 72 static fs_node_t *tmpfs_create_node(dev_handle_t, int); 69 static int tmpfs_match(fs_node_t **, fs_node_t *, const char *); 70 static int tmpfs_node_get(fs_node_t **, dev_handle_t, fs_index_t); 71 static int tmpfs_node_put(fs_node_t *); 72 static int tmpfs_create_node(fs_node_t **, dev_handle_t, int); 73 static int tmpfs_destroy_node(fs_node_t *); 73 74 static int tmpfs_link_node(fs_node_t *, fs_node_t *, const char *); 74 75 static int tmpfs_unlink_node(fs_node_t *, fs_node_t *, const char *); 75 static int tmpfs_destroy_node(fs_node_t *);76 76 77 77 /* Implementation of helper functions. */ 78 static int tmpfs_root_get(fs_node_t **rfn, dev_handle_t dev_handle) 79 { 80 return tmpfs_node_get(rfn, dev_handle, TMPFS_SOME_ROOT); 81 } 82 83 static int tmpfs_has_children(bool *has_children, fs_node_t *fn) 84 { 85 *has_children = !list_empty(&TMPFS_NODE(fn)->cs_head); 86 return EOK; 87 } 88 78 89 static fs_index_t tmpfs_index_get(fs_node_t *fn) 79 90 { … … 89 100 { 90 101 return TMPFS_NODE(fn)->lnkcnt; 91 }92 93 static bool tmpfs_has_children(fs_node_t *fn)94 {95 return !list_empty(&TMPFS_NODE(fn)->cs_head);96 }97 98 static fs_node_t *tmpfs_root_get(dev_handle_t dev_handle)99 {100 return tmpfs_node_get(dev_handle, TMPFS_SOME_ROOT);101 102 } 102 103 … … 118 119 /** libfs operations */ 119 120 libfs_ops_t tmpfs_libfs_ops = { 121 .root_get = tmpfs_root_get, 120 122 .match = tmpfs_match, 121 123 .node_get = tmpfs_node_get, … … 125 127 .link = tmpfs_link_node, 126 128 .unlink = tmpfs_unlink_node, 129 .has_children = tmpfs_has_children, 127 130 .index_get = tmpfs_index_get, 128 131 .size_get = tmpfs_size_get, 129 132 .lnkcnt_get = tmpfs_lnkcnt_get, 130 .has_children = tmpfs_has_children,131 .root_get = tmpfs_root_get,132 133 .plb_get_char = tmpfs_plb_get_char, 133 134 .is_directory = tmpfs_is_directory, … … 197 198 { 198 199 fs_node_t *rfn; 200 int rc; 199 201 200 r fn = tmpfs_create_node(dev_handle, L_DIRECTORY);201 if ( !rfn)202 rc = tmpfs_create_node(&rfn, dev_handle, L_DIRECTORY); 203 if (rc != EOK || !rfn) 202 204 return false; 203 205 TMPFS_NODE(rfn)->lnkcnt = 0; /* FS root is not linked */ … … 205 207 } 206 208 207 fs_node_t *tmpfs_match(fs_node_t *pfn, const char *component)209 int tmpfs_match(fs_node_t **rfn, fs_node_t *pfn, const char *component) 208 210 { 209 211 tmpfs_node_t *parentp = TMPFS_NODE(pfn); … … 212 214 for (lnk = parentp->cs_head.next; lnk != &parentp->cs_head; 213 215 lnk = lnk->next) { 214 tmpfs_dentry_t *dentryp = list_get_instance(lnk, tmpfs_dentry_t, 215 link); 216 if (!str_cmp(dentryp->name, component)) 217 return FS_NODE(dentryp->node); 218 } 219 220 return NULL; 221 } 222 223 fs_node_t *tmpfs_node_get(dev_handle_t dev_handle, fs_index_t index) 216 tmpfs_dentry_t *dentryp; 217 dentryp = list_get_instance(lnk, tmpfs_dentry_t, link); 218 if (!str_cmp(dentryp->name, component)) { 219 *rfn = FS_NODE(dentryp->node); 220 return EOK; 221 } 222 } 223 224 *rfn = NULL; 225 return EOK; 226 } 227 228 int tmpfs_node_get(fs_node_t **rfn, dev_handle_t dev_handle, fs_index_t index) 224 229 { 225 230 unsigned long key[] = { … … 228 233 }; 229 234 link_t *lnk = hash_table_find(&nodes, key); 230 if (!lnk) 231 return NULL; 232 return FS_NODE(hash_table_get_instance(lnk, tmpfs_node_t, nh_link)); 233 } 234 235 void tmpfs_node_put(fs_node_t *fn) 235 if (lnk) { 236 tmpfs_node_t *nodep; 237 nodep = hash_table_get_instance(lnk, tmpfs_node_t, nh_link); 238 *rfn = FS_NODE(nodep); 239 } else { 240 *rfn = NULL; 241 } 242 return EOK; 243 } 244 245 int tmpfs_node_put(fs_node_t *fn) 236 246 { 237 247 /* nothing to do */ 238 } 239 240 fs_node_t *tmpfs_create_node(dev_handle_t dev_handle, int lflag) 241 { 248 return EOK; 249 } 250 251 int tmpfs_create_node(fs_node_t **rfn, dev_handle_t dev_handle, int lflag) 252 { 253 fs_node_t *rootfn; 254 int rc; 255 242 256 assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY)); 243 257 244 258 tmpfs_node_t *nodep = malloc(sizeof(tmpfs_node_t)); 245 259 if (!nodep) 246 return NULL;260 return ENOMEM; 247 261 tmpfs_node_initialize(nodep); 248 262 nodep->bp = malloc(sizeof(fs_node_t)); 249 263 if (!nodep->bp) { 250 264 free(nodep); 251 return NULL;265 return ENOMEM; 252 266 } 253 267 fs_node_initialize(nodep->bp); 254 268 nodep->bp->data = nodep; /* link the FS and TMPFS nodes */ 255 if (!tmpfs_root_get(dev_handle)) 269 270 rc = tmpfs_root_get(&rootfn, dev_handle); 271 assert(rc == EOK); 272 if (!rootfn) 256 273 nodep->index = TMPFS_SOME_ROOT; 257 274 else … … 269 286 }; 270 287 hash_table_insert(&nodes, key, &nodep->nh_link); 271 return FS_NODE(nodep); 288 *rfn = FS_NODE(nodep); 289 return EOK; 290 } 291 292 int tmpfs_destroy_node(fs_node_t *fn) 293 { 294 tmpfs_node_t *nodep = TMPFS_NODE(fn); 295 296 assert(!nodep->lnkcnt); 297 assert(list_empty(&nodep->cs_head)); 298 299 unsigned long key[] = { 300 [NODES_KEY_INDEX] = nodep->index, 301 [NODES_KEY_DEV] = nodep->dev_handle 302 }; 303 hash_table_remove(&nodes, key, 2); 304 305 if (nodep->type == TMPFS_FILE) 306 free(nodep->data); 307 free(nodep->bp); 308 free(nodep); 309 return EOK; 272 310 } 273 311 … … 343 381 } 344 382 345 int tmpfs_destroy_node(fs_node_t *fn)346 {347 tmpfs_node_t *nodep = TMPFS_NODE(fn);348 349 assert(!nodep->lnkcnt);350 assert(list_empty(&nodep->cs_head));351 352 unsigned long key[] = {353 [NODES_KEY_INDEX] = nodep->index,354 [NODES_KEY_DEV] = nodep->dev_handle355 };356 hash_table_remove(&nodes, key, 2);357 358 if (nodep->type == TMPFS_FILE)359 free(nodep->data);360 free(nodep->bp);361 free(nodep);362 return EOK;363 }364 365 383 void tmpfs_mounted(ipc_callid_t rid, ipc_call_t *request) 366 384 { 367 385 dev_handle_t dev_handle = (dev_handle_t) IPC_GET_ARG1(*request); 386 int rc; 368 387 369 388 /* accept the mount options */ … … 395 414 } 396 415 397 tmpfs_node_t *rootp = TMPFS_NODE(tmpfs_root_get(dev_handle)); 416 fs_node_t *rootfn; 417 rc = tmpfs_root_get(&rootfn, dev_handle); 418 assert(rc == EOK); 419 tmpfs_node_t *rootp = TMPFS_NODE(rootfn); 398 420 if (str_cmp(opts, "restore") == 0) { 399 421 if (tmpfs_restore(dev_handle))
Note:
See TracChangeset
for help on using the changeset viewer.