Changeset cf95bc0 in mainline
- Timestamp:
- 2009-05-09T21:56:50Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d4a172b
- Parents:
- 4f46695e
- Location:
- uspace
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libfs/libfs.c
r4f46695e rcf95bc0 291 291 if (lflag & L_UNLINK) { 292 292 unsigned old_lnkcnt = ops->lnkcnt_get(cur); 293 int res = ops->unlink(par, cur );293 int res = ops->unlink(par, cur, component); 294 294 ipc_answer_5(rid, (ipcarg_t)res, fs_handle, dev_handle, 295 295 ops->index_get(cur), ops->size_get(cur), old_lnkcnt); -
uspace/lib/libfs/libfs.h
r4f46695e rcf95bc0 53 53 int (* destroy)(fs_node_t *); 54 54 int (* link)(fs_node_t *, fs_node_t *, const char *); 55 int (* unlink)(fs_node_t *, fs_node_t * );55 int (* unlink)(fs_node_t *, fs_node_t *, const char *); 56 56 fs_index_t (* index_get)(fs_node_t *); 57 57 size_t (* size_get)(fs_node_t *); -
uspace/srv/fs/fat/fat_ops.c
r4f46695e rcf95bc0 242 242 static int fat_destroy_node(fs_node_t *); 243 243 static int fat_link(fs_node_t *, fs_node_t *, const char *); 244 static int fat_unlink(fs_node_t *, fs_node_t * );244 static int fat_unlink(fs_node_t *, fs_node_t *, const char *); 245 245 static fs_node_t *fat_match(fs_node_t *, const char *); 246 246 static fs_index_t fat_index_get(fs_node_t *); … … 544 544 } 545 545 546 int fat_unlink(fs_node_t *pfn, fs_node_t *cfn )546 int fat_unlink(fs_node_t *pfn, fs_node_t *cfn, const char *nm) 547 547 { 548 548 fat_node_t *parentp = FAT_NODE(pfn); -
uspace/srv/fs/tmpfs/tmpfs.h
r4f46695e rcf95bc0 45 45 #endif 46 46 47 #define TMPFS_NODE(node) ((node) ? (tmpfs_ dentry_t *)(node)->data : NULL)47 #define TMPFS_NODE(node) ((node) ? (tmpfs_node_t *)(node)->data : NULL) 48 48 #define FS_NODE(node) ((node) ? (node)->bp : NULL) 49 49 … … 54 54 } tmpfs_dentry_type_t; 55 55 56 /* forward declaration */ 57 struct tmpfs_node; 58 56 59 typedef struct tmpfs_dentry { 60 link_t link; /**< Linkage for the list of siblings. */ 61 struct tmpfs_node *node;/**< Back pointer to TMPFS node. */ 62 char *name; /**< Name of dentry. */ 63 } tmpfs_dentry_t; 64 65 typedef struct tmpfs_node { 57 66 fs_node_t *bp; /**< Back pointer to the FS node. */ 58 67 fs_index_t index; /**< TMPFS node index. */ 59 68 dev_handle_t dev_handle;/**< Device handle. */ 60 link_t dh_link; /**< Dentries hash table link. */ 61 struct tmpfs_dentry *sibling; 62 struct tmpfs_dentry *child; 63 hash_table_t names; /**< All names linking to this TMPFS node. */ 69 link_t nh_link; /**< Nodes hash table link. */ 64 70 tmpfs_dentry_type_t type; 65 71 unsigned lnkcnt; /**< Link count. */ 66 72 size_t size; /**< File size if type is TMPFS_FILE. */ 67 73 void *data; /**< File content's if type is TMPFS_FILE. */ 68 } tmpfs_dentry_t; 74 link_t cs_head; /**< Head of child's siblings list. */ 75 } tmpfs_node_t; 69 76 70 77 extern fs_reg_t tmpfs_reg; -
uspace/srv/fs/tmpfs/tmpfs_dump.c
r4f46695e rcf95bc0 65 65 char *fname; 66 66 fs_node_t *fn; 67 tmpfs_ dentry_t *nodep;67 tmpfs_node_t *nodep; 68 68 uint32_t size; 69 69 -
uspace/srv/fs/tmpfs/tmpfs_ops.c
r4f46695e rcf95bc0 55 55 #define max(a, b) ((a) > (b) ? (a) : (b)) 56 56 57 #define DENTRIES_BUCKETS 256 58 59 #define NAMES_BUCKETS 4 57 #define NODES_BUCKETS 256 60 58 61 59 /** All root nodes have index 0. */ … … 74 72 static fs_node_t *tmpfs_create_node(dev_handle_t, int); 75 73 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 * );74 static int tmpfs_unlink_node(fs_node_t *, fs_node_t *, const char *); 77 75 static int tmpfs_destroy_node(fs_node_t *); 78 76 … … 95 93 static bool tmpfs_has_children(fs_node_t *fn) 96 94 { 97 return TMPFS_NODE(fn)->child != NULL;95 return !list_empty(&TMPFS_NODE(fn)->cs_head); 98 96 } 99 97 … … 137 135 }; 138 136 139 /** Hash table of all directory entries. */ 140 hash_table_t dentries; 141 142 #define DENTRIES_KEY_INDEX 0 143 #define DENTRIES_KEY_DEV 1 144 145 /* Implementation of hash table interface for the dentries hash table. */ 146 static hash_index_t dentries_hash(unsigned long key[]) 147 { 148 return key[DENTRIES_KEY_INDEX] % DENTRIES_BUCKETS; 149 } 150 151 static int dentries_compare(unsigned long key[], hash_count_t keys, 152 link_t *item) 153 { 154 tmpfs_dentry_t *dentry = hash_table_get_instance(item, tmpfs_dentry_t, 155 dh_link); 156 return (dentry->index == key[DENTRIES_KEY_INDEX] && 157 dentry->dev_handle == key[DENTRIES_KEY_DEV]); 158 } 159 160 static void dentries_remove_callback(link_t *item) 161 { 162 } 163 164 /** TMPFS dentries hash table operations. */ 165 hash_table_operations_t dentries_ops = { 166 .hash = dentries_hash, 167 .compare = dentries_compare, 168 .remove_callback = dentries_remove_callback 137 /** Hash table of all TMPFS nodes. */ 138 hash_table_t nodes; 139 140 #define NODES_KEY_INDEX 0 141 #define NODES_KEY_DEV 1 142 143 /* Implementation of hash table interface for the nodes hash table. */ 144 static hash_index_t nodes_hash(unsigned long key[]) 145 { 146 return key[NODES_KEY_INDEX] % NODES_BUCKETS; 147 } 148 149 static int nodes_compare(unsigned long key[], hash_count_t keys, link_t *item) 150 { 151 tmpfs_node_t *nodep = hash_table_get_instance(item, tmpfs_node_t, 152 nh_link); 153 return (nodep->index == key[NODES_KEY_INDEX] && 154 nodep->dev_handle == key[NODES_KEY_DEV]); 155 } 156 157 static void nodes_remove_callback(link_t *item) 158 { 159 } 160 161 /** TMPFS nodes hash table operations. */ 162 hash_table_operations_t nodes_ops = { 163 .hash = nodes_hash, 164 .compare = nodes_compare, 165 .remove_callback = nodes_remove_callback 169 166 }; 170 167 171 typedef struct { 172 char *name; 173 tmpfs_dentry_t *parent; 174 link_t link; 175 } tmpfs_name_t; 176 177 /* Implementation of hash table interface for the names hash table. */ 178 static hash_index_t names_hash(unsigned long *key) 179 { 180 tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) *key; 181 return dentry->index % NAMES_BUCKETS; 182 } 183 184 static int names_compare(unsigned long *key, hash_count_t keys, link_t *item) 185 { 186 tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) *key; 187 tmpfs_name_t *namep = hash_table_get_instance(item, tmpfs_name_t, 188 link); 189 return dentry == namep->parent; 190 } 191 192 static void names_remove_callback(link_t *item) 193 { 194 tmpfs_name_t *namep = hash_table_get_instance(item, tmpfs_name_t, 195 link); 196 free(namep->name); 197 free(namep); 198 } 199 200 /** TMPFS node names hash table operations. */ 201 static hash_table_operations_t names_ops = { 202 .hash = names_hash, 203 .compare = names_compare, 204 .remove_callback = names_remove_callback 205 }; 206 207 static void tmpfs_name_initialize(tmpfs_name_t *namep) 208 { 209 namep->name = NULL; 210 namep->parent = NULL; 211 link_initialize(&namep->link); 212 } 213 214 static bool tmpfs_dentry_initialize(tmpfs_dentry_t *dentry) 215 { 216 dentry->bp = NULL; 217 dentry->index = 0; 218 dentry->dev_handle = 0; 219 dentry->sibling = NULL; 220 dentry->child = NULL; 221 dentry->type = TMPFS_NONE; 222 dentry->lnkcnt = 0; 223 dentry->size = 0; 224 dentry->data = NULL; 225 link_initialize(&dentry->dh_link); 226 return (bool)hash_table_create(&dentry->names, NAMES_BUCKETS, 1, 227 &names_ops); 168 static void tmpfs_node_initialize(tmpfs_node_t *nodep) 169 { 170 nodep->bp = NULL; 171 nodep->index = 0; 172 nodep->dev_handle = 0; 173 nodep->type = TMPFS_NONE; 174 nodep->lnkcnt = 0; 175 nodep->size = 0; 176 nodep->data = NULL; 177 link_initialize(&nodep->nh_link); 178 list_initialize(&nodep->cs_head); 179 } 180 181 static void tmpfs_dentry_initialize(tmpfs_dentry_t *dentryp) 182 { 183 link_initialize(&dentryp->link); 184 dentryp->name = NULL; 185 dentryp->node = NULL; 228 186 } 229 187 230 188 bool tmpfs_init(void) 231 189 { 232 if (!hash_table_create(& dentries, DENTRIES_BUCKETS, 2, &dentries_ops))190 if (!hash_table_create(&nodes, NODES_BUCKETS, 2, &nodes_ops)) 233 191 return false; 234 192 … … 247 205 } 248 206 249 /** Compare one component of path to a directory entry.250 *251 * @param parentp Pointer to node from which we descended.252 * @param childp Pointer to node to compare the path component with.253 * @param component Array of characters holding component name.254 *255 * @return True on match, false otherwise.256 */257 static bool258 tmpfs_match_one(tmpfs_dentry_t *parentp, tmpfs_dentry_t *childp,259 const char *component)260 {261 unsigned long key = (unsigned long) parentp;262 link_t *hlp = hash_table_find(&childp->names, &key);263 assert(hlp);264 tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t, link);265 return !str_cmp(namep->name, component);266 }267 268 207 fs_node_t *tmpfs_match(fs_node_t *pfn, const char *component) 269 208 { 270 tmpfs_dentry_t *parentp = TMPFS_NODE(pfn); 271 tmpfs_dentry_t *childp = parentp->child; 272 273 while (childp && !tmpfs_match_one(parentp, childp, component)) 274 childp = childp->sibling; 275 276 return FS_NODE(childp); 209 tmpfs_node_t *parentp = TMPFS_NODE(pfn); 210 link_t *lnk; 211 212 for (lnk = parentp->cs_head.next; lnk != &parentp->cs_head; 213 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; 277 221 } 278 222 … … 280 224 { 281 225 unsigned long key[] = { 282 [ DENTRIES_KEY_INDEX] = index,283 [ DENTRIES_KEY_DEV] = dev_handle226 [NODES_KEY_INDEX] = index, 227 [NODES_KEY_DEV] = dev_handle 284 228 }; 285 link_t *lnk = hash_table_find(& dentries, key);229 link_t *lnk = hash_table_find(&nodes, key); 286 230 if (!lnk) 287 231 return NULL; 288 return FS_NODE(hash_table_get_instance(lnk, tmpfs_ dentry_t, dh_link));232 return FS_NODE(hash_table_get_instance(lnk, tmpfs_node_t, nh_link)); 289 233 } 290 234 … … 298 242 assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY)); 299 243 300 fs_node_t *fn = malloc(sizeof(fs_node_t));301 if (! fn)244 tmpfs_node_t *nodep = malloc(sizeof(tmpfs_node_t)); 245 if (!nodep) 302 246 return NULL; 303 304 tmpfs_dentry_t *node = malloc(sizeof(tmpfs_dentry_t));305 if (!node ) {306 free( fn);247 tmpfs_node_initialize(nodep); 248 nodep->bp = malloc(sizeof(fs_node_t)); 249 if (!nodep->bp) { 250 free(nodep); 307 251 return NULL; 308 252 } 309 if (!tmpfs_dentry_initialize(node)) { 310 free(fn); 311 free(node); 312 return NULL; 313 } 314 fn->data = node; 315 node->bp = fn; /* establish the back pointer */ 253 nodep->bp->data = nodep; /* link the FS and TMPFS nodes */ 316 254 if (!tmpfs_root_get(dev_handle)) 317 node ->index = TMPFS_SOME_ROOT;255 nodep->index = TMPFS_SOME_ROOT; 318 256 else 319 node ->index = tmpfs_next_index++;320 node ->dev_handle = dev_handle;257 nodep->index = tmpfs_next_index++; 258 nodep->dev_handle = dev_handle; 321 259 if (lflag & L_DIRECTORY) 322 node ->type = TMPFS_DIRECTORY;260 nodep->type = TMPFS_DIRECTORY; 323 261 else 324 node ->type = TMPFS_FILE;325 326 /* Insert the new node into the dentryhash table. */262 nodep->type = TMPFS_FILE; 263 264 /* Insert the new node into the nodes hash table. */ 327 265 unsigned long key[] = { 328 [ DENTRIES_KEY_INDEX] = node->index,329 [ DENTRIES_KEY_DEV] = node->dev_handle266 [NODES_KEY_INDEX] = nodep->index, 267 [NODES_KEY_DEV] = nodep->dev_handle 330 268 }; 331 hash_table_insert(& dentries, key, &node->dh_link);332 return fn;269 hash_table_insert(&nodes, key, &nodep->nh_link); 270 return FS_NODE(nodep); 333 271 } 334 272 335 273 int tmpfs_link_node(fs_node_t *pfn, fs_node_t *cfn, const char *nm) 336 274 { 337 tmpfs_dentry_t *parentp = TMPFS_NODE(pfn); 338 tmpfs_dentry_t *childp = TMPFS_NODE(cfn); 275 tmpfs_node_t *parentp = TMPFS_NODE(pfn); 276 tmpfs_node_t *childp = TMPFS_NODE(cfn); 277 tmpfs_dentry_t *dentryp; 278 link_t *lnk; 339 279 340 280 assert(parentp->type == TMPFS_DIRECTORY); 341 281 342 tmpfs_name_t *namep = malloc(sizeof(tmpfs_name_t)); 343 if (!namep) 282 /* Check for duplicit entries. */ 283 for (lnk = parentp->cs_head.next; lnk != &parentp->cs_head; 284 lnk = lnk->next) { 285 dentryp = list_get_instance(lnk, tmpfs_dentry_t, link); 286 if (!str_cmp(dentryp->name, nm)) 287 return EEXIST; 288 } 289 290 /* Allocate and initialize the dentry. */ 291 dentryp = malloc(sizeof(tmpfs_dentry_t)); 292 if (!dentryp) 344 293 return ENOMEM; 345 tmpfs_name_initialize(namep); 294 tmpfs_dentry_initialize(dentryp); 295 296 /* Populate and link the new dentry. */ 346 297 size_t size = str_size(nm); 347 namep->name = malloc(size + 1);348 if (! namep->name) {349 free( namep);298 dentryp->name = malloc(size + 1); 299 if (!dentryp->name) { 300 free(dentryp); 350 301 return ENOMEM; 351 302 } 352 str_cpy(namep->name, size + 1, nm); 353 namep->parent = parentp; 354 303 str_cpy(dentryp->name, size + 1, nm); 304 dentryp->node = childp; 355 305 childp->lnkcnt++; 356 357 unsigned long key = (unsigned long) parentp; 358 hash_table_insert(&childp->names, &key, &namep->link); 359 360 /* Insert the new node into the namespace. */ 361 if (parentp->child) { 362 tmpfs_dentry_t *tmp = parentp->child; 363 while (tmp->sibling) 364 tmp = tmp->sibling; 365 tmp->sibling = childp; 366 } else { 367 parentp->child = childp; 368 } 306 list_append(&dentryp->link, &parentp->cs_head); 369 307 370 308 return EOK; 371 309 } 372 310 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); 311 int tmpfs_unlink_node(fs_node_t *pfn, fs_node_t *cfn, const char *nm) 312 { 313 tmpfs_node_t *parentp = TMPFS_NODE(pfn); 314 tmpfs_node_t *childp = NULL; 315 tmpfs_dentry_t *dentryp; 316 link_t *lnk; 377 317 378 318 if (!parentp) 379 319 return EBUSY; 380 381 if (childp->child) 320 321 for (lnk = parentp->cs_head.next; lnk != &parentp->cs_head; 322 lnk = lnk->next) { 323 dentryp = list_get_instance(lnk, tmpfs_dentry_t, link); 324 if (!str_cmp(dentryp->name, nm)) { 325 childp = dentryp->node; 326 assert(FS_NODE(childp) == cfn); 327 break; 328 } 329 } 330 331 if (!childp) 332 return ENOENT; 333 334 if ((childp->lnkcnt == 1) && !list_empty(&childp->cs_head)) 382 335 return ENOTEMPTY; 383 336 384 if (parentp->child == childp) { 385 parentp->child = childp->sibling; 386 } else { 387 /* TODO: consider doubly linked list for organizing siblings. */ 388 tmpfs_dentry_t *tmp = parentp->child; 389 while (tmp->sibling != childp) 390 tmp = tmp->sibling; 391 tmp->sibling = childp->sibling; 392 } 393 childp->sibling = NULL; 394 395 unsigned long key = (unsigned long) parentp; 396 hash_table_remove(&childp->names, &key, 1); 397 337 list_remove(&dentryp->link); 338 free(dentryp); 398 339 childp->lnkcnt--; 399 340 … … 403 344 int tmpfs_destroy_node(fs_node_t *fn) 404 345 { 405 tmpfs_ dentry_t *dentry= TMPFS_NODE(fn);346 tmpfs_node_t *nodep = TMPFS_NODE(fn); 406 347 407 assert(!dentry->lnkcnt); 408 assert(!dentry->child); 409 assert(!dentry->sibling); 348 assert(!nodep->lnkcnt); 349 assert(list_empty(&nodep->cs_head)); 410 350 411 351 unsigned long key[] = { 412 [ DENTRIES_KEY_INDEX] = dentry->index,413 [ DENTRIES_KEY_DEV] = dentry->dev_handle352 [NODES_KEY_INDEX] = nodep->index, 353 [NODES_KEY_DEV] = nodep->dev_handle 414 354 }; 415 hash_table_remove(&dentries, key, 2); 416 417 hash_table_destroy(&dentry->names); 418 419 if (dentry->type == TMPFS_FILE) 420 free(dentry->data); 421 free(dentry->bp); 422 free(dentry); 355 hash_table_remove(&nodes, key, 2); 356 357 if (nodep->type == TMPFS_FILE) 358 free(nodep->data); 359 free(nodep->bp); 360 free(nodep); 423 361 return EOK; 424 362 } … … 456 394 } 457 395 458 tmpfs_ dentry_t *root= TMPFS_NODE(tmpfs_root_get(dev_handle));396 tmpfs_node_t *rootp = TMPFS_NODE(tmpfs_root_get(dev_handle)); 459 397 if (str_cmp(opts, "restore") == 0) { 460 398 if (tmpfs_restore(dev_handle)) 461 ipc_answer_3(rid, EOK, root ->index, root->size,462 root ->lnkcnt);399 ipc_answer_3(rid, EOK, rootp->index, rootp->size, 400 rootp->lnkcnt); 463 401 else 464 402 ipc_answer_0(rid, ELIMIT); 465 403 } else { 466 ipc_answer_3(rid, EOK, root->index, root->size, root->lnkcnt); 404 ipc_answer_3(rid, EOK, rootp->index, rootp->size, 405 rootp->lnkcnt); 467 406 } 468 407 } … … 490 429 491 430 /* 492 * Lookup the respective dentry.431 * Lookup the respective TMPFS node. 493 432 */ 494 433 link_t *hlp; 495 434 unsigned long key[] = { 496 [ DENTRIES_KEY_INDEX] = index,497 [ DENTRIES_KEY_DEV] = dev_handle,435 [NODES_KEY_INDEX] = index, 436 [NODES_KEY_DEV] = dev_handle, 498 437 }; 499 hlp = hash_table_find(& dentries, key);438 hlp = hash_table_find(&nodes, key); 500 439 if (!hlp) { 501 440 ipc_answer_0(rid, ENOENT); 502 441 return; 503 442 } 504 tmpfs_ dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t,505 dh_link);443 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, 444 nh_link); 506 445 507 446 /* … … 517 456 518 457 size_t bytes; 519 if ( dentry->type == TMPFS_FILE) {520 bytes = max(0, min( dentry->size - pos, size));521 (void) ipc_data_read_finalize(callid, dentry->data + pos,458 if (nodep->type == TMPFS_FILE) { 459 bytes = max(0, min(nodep->size - pos, size)); 460 (void) ipc_data_read_finalize(callid, nodep->data + pos, 522 461 bytes); 523 462 } else { 463 tmpfs_dentry_t *dentryp; 464 link_t *lnk; 524 465 int i; 525 tmpfs_dentry_t *cur;526 466 527 assert( dentry->type == TMPFS_DIRECTORY);467 assert(nodep->type == TMPFS_DIRECTORY); 528 468 529 469 /* … … 532 472 * hash table. 533 473 */ 534 for (i = 0, cur = dentry->child; i < pos && cur; i++, 535 cur = cur->sibling) 474 for (i = 0, lnk = nodep->cs_head.next; 475 i < pos && lnk != &nodep->cs_head; 476 i++, lnk = lnk->next) 536 477 ; 537 478 538 if ( !cur) {479 if (lnk == &nodep->cs_head) { 539 480 ipc_answer_0(callid, ENOENT); 540 481 ipc_answer_1(rid, ENOENT, 0); … … 542 483 } 543 484 544 unsigned long key = (unsigned long) dentry; 545 link_t *hlp = hash_table_find(&cur->names, &key); 546 assert(hlp); 547 tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t, 548 link); 549 550 (void) ipc_data_read_finalize(callid, namep->name, 551 str_size(namep->name) + 1); 485 dentryp = list_get_instance(lnk, tmpfs_dentry_t, link); 486 487 (void) ipc_data_read_finalize(callid, dentryp->name, 488 str_size(dentryp->name) + 1); 552 489 bytes = 1; 553 490 } … … 566 503 567 504 /* 568 * Lookup the respective dentry.505 * Lookup the respective TMPFS node. 569 506 */ 570 507 link_t *hlp; 571 508 unsigned long key[] = { 572 [ DENTRIES_KEY_INDEX] = index,573 [ DENTRIES_KEY_DEV] = dev_handle509 [NODES_KEY_INDEX] = index, 510 [NODES_KEY_DEV] = dev_handle 574 511 }; 575 hlp = hash_table_find(& dentries, key);512 hlp = hash_table_find(&nodes, key); 576 513 if (!hlp) { 577 514 ipc_answer_0(rid, ENOENT); 578 515 return; 579 516 } 580 tmpfs_ dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t,581 dh_link);517 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, 518 nh_link); 582 519 583 520 /* … … 595 532 * Check whether the file needs to grow. 596 533 */ 597 if (pos + size <= dentry->size) {534 if (pos + size <= nodep->size) { 598 535 /* The file size is not changing. */ 599 (void) ipc_data_write_finalize(callid, dentry->data + pos, size);600 ipc_answer_2(rid, EOK, size, dentry->size);601 return; 602 } 603 size_t delta = (pos + size) - dentry->size;536 (void) ipc_data_write_finalize(callid, nodep->data + pos, size); 537 ipc_answer_2(rid, EOK, size, nodep->size); 538 return; 539 } 540 size_t delta = (pos + size) - nodep->size; 604 541 /* 605 542 * At this point, we are deliberately extremely straightforward and … … 609 546 * possible. 610 547 */ 611 void *newdata = realloc( dentry->data, dentry->size + delta);548 void *newdata = realloc(nodep->data, nodep->size + delta); 612 549 if (!newdata) { 613 550 ipc_answer_0(callid, ENOMEM); 614 ipc_answer_2(rid, EOK, 0, dentry->size);551 ipc_answer_2(rid, EOK, 0, nodep->size); 615 552 return; 616 553 } 617 554 /* Clear any newly allocated memory in order to emulate gaps. */ 618 memset(newdata + dentry->size, 0, delta);619 dentry->size += delta;620 dentry->data = newdata;621 (void) ipc_data_write_finalize(callid, dentry->data + pos, size);622 ipc_answer_2(rid, EOK, size, dentry->size);555 memset(newdata + nodep->size, 0, delta); 556 nodep->size += delta; 557 nodep->data = newdata; 558 (void) ipc_data_write_finalize(callid, nodep->data + pos, size); 559 ipc_answer_2(rid, EOK, size, nodep->size); 623 560 } 624 561 … … 630 567 631 568 /* 632 * Lookup the respective dentry.569 * Lookup the respective TMPFS node. 633 570 */ 634 571 link_t *hlp; 635 572 unsigned long key[] = { 636 [ DENTRIES_KEY_INDEX] = index,637 [ DENTRIES_KEY_DEV] = dev_handle573 [NODES_KEY_INDEX] = index, 574 [NODES_KEY_DEV] = dev_handle 638 575 }; 639 hlp = hash_table_find(& dentries, key);576 hlp = hash_table_find(&nodes, key); 640 577 if (!hlp) { 641 578 ipc_answer_0(rid, ENOENT); 642 579 return; 643 580 } 644 tmpfs_ dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t,645 dh_link);646 647 if (size == dentry->size) {581 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, 582 nh_link); 583 584 if (size == nodep->size) { 648 585 ipc_answer_0(rid, EOK); 649 586 return; 650 587 } 651 588 652 void *newdata = realloc( dentry->data, size);589 void *newdata = realloc(nodep->data, size); 653 590 if (!newdata) { 654 591 ipc_answer_0(rid, ENOMEM); 655 592 return; 656 593 } 657 if (size > dentry->size) {658 size_t delta = size - dentry->size;659 memset(newdata + dentry->size, 0, delta);660 } 661 dentry->size = size;662 dentry->data = newdata;594 if (size > nodep->size) { 595 size_t delta = size - nodep->size; 596 memset(newdata + nodep->size, 0, delta); 597 } 598 nodep->size = size; 599 nodep->data = newdata; 663 600 ipc_answer_0(rid, EOK); 664 601 } … … 672 609 link_t *hlp; 673 610 unsigned long key[] = { 674 [ DENTRIES_KEY_INDEX] = index,675 [ DENTRIES_KEY_DEV] = dev_handle611 [NODES_KEY_INDEX] = index, 612 [NODES_KEY_DEV] = dev_handle 676 613 }; 677 hlp = hash_table_find(& dentries, key);614 hlp = hash_table_find(&nodes, key); 678 615 if (!hlp) { 679 616 ipc_answer_0(rid, ENOENT); 680 617 return; 681 618 } 682 tmpfs_ dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t,683 dh_link);684 rc = tmpfs_destroy_node(FS_NODE( dentry));619 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, 620 nh_link); 621 rc = tmpfs_destroy_node(FS_NODE(nodep)); 685 622 ipc_answer_0(rid, rc); 686 623 }
Note:
See TracChangeset
for help on using the changeset viewer.