Changeset fdb7795 in mainline
- Timestamp:
- 2008-02-25T22:22:57Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6c441cf8
- Parents:
- 07e01e6
- Location:
- uspace/srv
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/tmpfs/tmpfs.c
r07e01e6 rfdb7795 61 61 [IPC_METHOD_TO_VFS_OP(VFS_MOUNT)] = VFS_OP_NULL, 62 62 [IPC_METHOD_TO_VFS_OP(VFS_UNMOUNT)] = VFS_OP_NULL, 63 [IPC_METHOD_TO_VFS_OP(VFS_ FREE)] = VFS_OP_DEFINED,63 [IPC_METHOD_TO_VFS_OP(VFS_DESTROY)] = VFS_OP_DEFINED, 64 64 } 65 65 }; … … 116 116 tmpfs_truncate(callid, &call); 117 117 break; 118 case VFS_ FREE:119 tmpfs_ free(callid, &call);118 case VFS_DESTROY: 119 tmpfs_destroy(callid, &call); 120 120 break; 121 121 default: -
uspace/srv/fs/tmpfs/tmpfs.h
r07e01e6 rfdb7795 65 65 extern void tmpfs_write(ipc_callid_t, ipc_call_t *); 66 66 extern void tmpfs_truncate(ipc_callid_t, ipc_call_t *); 67 extern void tmpfs_ free(ipc_callid_t, ipc_call_t *);67 extern void tmpfs_destroy(ipc_callid_t, ipc_call_t *); 68 68 69 69 #endif -
uspace/srv/fs/tmpfs/tmpfs_ops.c
r07e01e6 rfdb7795 62 62 #define TMPFS_GET_LNKCNT(x) 1 63 63 64 /* 65 * Hash table of all directory entries. 66 */ 64 /* Forward declarations of static functions. */ 65 static void *create_node(int); 66 static bool link_node(void *, void *, const char *); 67 static int unlink_node(void *); 68 static void destroy_node(void *); 69 70 /** Hash table of all directory entries. */ 67 71 hash_table_t dentries; 68 72 … … 116 120 if (!hash_table_create(&dentries, DENTRIES_BUCKETS, 1, &dentries_ops)) 117 121 return false; 118 119 root = (tmpfs_dentry_t *) malloc(sizeof(tmpfs_dentry_t)); 120 if (!root) 121 return false; 122 tmpfs_dentry_initialize(root); 123 root->index = tmpfs_next_index++; 124 root->name = ""; 125 root->type = TMPFS_DIRECTORY; 126 hash_table_insert(&dentries, &root->index, &root->dh_link); 127 128 return true; 122 root = (tmpfs_dentry_t *) create_node(L_DIRECTORY); 123 return root != NULL; 129 124 } 130 125 … … 143 138 } 144 139 145 static void *create_node(void *nodep, 146 const char *component, int lflag) 147 { 148 tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) nodep; 149 150 assert(dentry->type == TMPFS_DIRECTORY); 140 void *create_node(int lflag) 141 { 151 142 assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY)); 152 143 … … 154 145 if (!node) 155 146 return NULL; 156 size_t len = strlen(component);157 char *name = malloc(len + 1);158 if (!name) {159 free(node);160 return NULL;161 }162 strcpy(name, component);163 147 164 148 tmpfs_dentry_initialize(node); 165 149 node->index = tmpfs_next_index++; 166 node->name = name;167 node->parent = dentry;168 150 if (lflag & L_DIRECTORY) 169 151 node->type = TMPFS_DIRECTORY; … … 171 153 node->type = TMPFS_FILE; 172 154 173 /* Insert the new node into the namespace. */174 if (dentry->child) {175 tmpfs_dentry_t *tmp = dentry->child;176 while (tmp->sibling)177 tmp = tmp->sibling;178 tmp->sibling = node;179 } else {180 dentry->child = node;181 }182 183 155 /* Insert the new node into the dentry hash table. */ 184 156 hash_table_insert(&dentries, &node->index, &node->dh_link); … … 186 158 } 187 159 188 static int destroy_component(void *nodeptr) 160 bool link_node(void *prnt, void *chld, const char *nm) 161 { 162 tmpfs_dentry_t *parentp = (tmpfs_dentry_t *) prnt; 163 tmpfs_dentry_t *childp = (tmpfs_dentry_t *) chld; 164 165 assert(parentp->type == TMPFS_DIRECTORY); 166 167 size_t len = strlen(nm); 168 char *name = malloc(len + 1); 169 if (!name) 170 return false; 171 strcpy(name, nm); 172 childp->name = name; 173 174 /* Insert the new node into the namespace. */ 175 if (parentp->child) { 176 tmpfs_dentry_t *tmp = parentp->child; 177 while (tmp->sibling) 178 tmp = tmp->sibling; 179 tmp->sibling = childp; 180 } else { 181 parentp->child = childp; 182 } 183 childp->parent = parentp; 184 185 return true; 186 } 187 188 int unlink_node(void *nodeptr) 189 189 { 190 190 tmpfs_dentry_t *dentry = (tmpfs_dentry_t *)nodeptr; … … 208 208 dentry->parent = NULL; 209 209 210 free(dentry->name); 211 dentry->name = NULL; 212 210 213 return EOK; 214 } 215 216 void destroy_node(void *nodep) 217 { 218 tmpfs_dentry_t *dentry = (tmpfs_dentry_t *) nodep; 219 220 assert(!dentry->child); 221 assert(!dentry->sibling); 222 223 unsigned long index = dentry->index; 224 hash_table_remove(&dentries, &index, 1); 225 226 if (dentry->type == TMPFS_FILE) 227 free(dentry->data); 228 free(dentry); 211 229 } 212 230 … … 269 287 return; 270 288 } 271 void *nodep = create_node(dcur, 272 component, lflag); 289 void *nodep = create_node(lflag); 273 290 if (nodep) { 274 ipc_answer_5(rid, EOK, 275 tmpfs_reg.fs_handle, dev_handle, 276 TMPFS_GET_INDEX(nodep), 0, 277 TMPFS_GET_LNKCNT(nodep)); 291 if (!link_node(dcur, nodep, 292 component)) { 293 destroy_node(nodep); 294 ipc_answer_0(rid, ENOSPC); 295 } else { 296 ipc_answer_5(rid, EOK, 297 tmpfs_reg.fs_handle, 298 dev_handle, 299 TMPFS_GET_INDEX(nodep), 0, 300 TMPFS_GET_LNKCNT(nodep)); 301 } 278 302 } else { 279 303 ipc_answer_0(rid, ENOSPC); … … 317 341 len = 0; 318 342 319 void *nodep = create_node( dcur, component,lflag);343 void *nodep = create_node(lflag); 320 344 if (nodep) { 321 ipc_answer_5(rid, EOK, tmpfs_reg.fs_handle, 322 dev_handle, TMPFS_GET_INDEX(nodep), 0, 323 TMPFS_GET_LNKCNT(nodep)); 345 if (!link_node(dcur, nodep, component)) { 346 destroy_node(nodep); 347 ipc_answer_0(rid, ENOSPC); 348 } else { 349 ipc_answer_5(rid, EOK, 350 tmpfs_reg.fs_handle, 351 dev_handle, TMPFS_GET_INDEX(nodep), 352 0, TMPFS_GET_LNKCNT(nodep)); 353 } 324 354 } else { 325 355 ipc_answer_0(rid, ENOSPC); … … 334 364 if (lflag & L_DESTROY) { 335 365 unsigned old_lnkcnt = TMPFS_GET_LNKCNT(dcur); 336 int res = destroy_component(dcur);366 int res = unlink_node(dcur); 337 367 ipc_answer_5(rid, (ipcarg_t)res, tmpfs_reg.fs_handle, 338 368 dev_handle, dcur->index, dcur->size, old_lnkcnt); … … 519 549 } 520 550 521 void tmpfs_ free(ipc_callid_t rid, ipc_call_t *request)551 void tmpfs_destroy(ipc_callid_t rid, ipc_call_t *request) 522 552 { 523 553 int dev_handle = IPC_GET_ARG1(*request); … … 532 562 tmpfs_dentry_t *dentry = hash_table_get_instance(hlp, tmpfs_dentry_t, 533 563 dh_link); 534 535 assert(!dentry->parent); 536 assert(!dentry->child); 537 assert(!dentry->sibling); 538 539 hash_table_remove(&dentries, &index, 1); 540 541 if (dentry->type == TMPFS_FILE) 542 free(dentry->data); 543 free(dentry->name); 544 free(dentry); 545 564 destroy_node(dentry); 546 565 ipc_answer_0(rid, EOK); 547 566 } -
uspace/srv/vfs/vfs.h
r07e01e6 rfdb7795 58 58 typedef enum { 59 59 VFS_LOOKUP = VFS_LAST_CMN, 60 VFS_ FREE,60 VFS_DESTROY, 61 61 VFS_LAST_CLNT, /* keep this the last member of this enum */ 62 62 } vfs_request_clnt_t; -
uspace/srv/vfs/vfs_node.c
r07e01e6 rfdb7795 132 132 int phone = vfs_grab_phone(node->fs_handle); 133 133 ipcarg_t rc; 134 rc = async_req_2_0(phone, VFS_ FREE, (ipcarg_t)node->dev_handle,135 (ipcarg_t)node-> index);134 rc = async_req_2_0(phone, VFS_DESTROY, 135 (ipcarg_t)node->dev_handle, (ipcarg_t)node->index); 136 136 assert(rc == EOK); 137 137 vfs_release_phone(phone); -
uspace/srv/vfs/vfs_ops.c
r07e01e6 rfdb7795 678 678 * The name has already been unlinked by vfs_lookup_internal(). 679 679 * We have to get and put the VFS node to ensure that it is 680 * VFS_ FREE'd after the last reference to it is dropped.680 * VFS_DESTROY'ed after the last reference to it is dropped. 681 681 */ 682 682 vfs_node_t *node = vfs_node_get(&lr);
Note:
See TracChangeset
for help on using the changeset viewer.