Rev 2706 | Rev 2710 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2706 | Rev 2707 | ||
---|---|---|---|
Line 209... | Line 209... | ||
209 | } |
209 | } |
210 | 210 | ||
211 | static unsigned long create_node(tmpfs_dentry_t *dentry, |
211 | static unsigned long create_node(tmpfs_dentry_t *dentry, |
212 | const char *component, int lflag) |
212 | const char *component, int lflag) |
213 | { |
213 | { |
- | 214 | assert(dentry->type == TMPFS_DIRECTORY); |
|
- | 215 | assert((lflag & L_FILE) ^ (lflag & L_DIRECTORY)); |
|
- | 216 | ||
- | 217 | tmpfs_dentry_t *node = malloc(sizeof(tmpfs_dentry_t)); |
|
- | 218 | if (!node) |
|
214 | return 0; |
219 | return 0; |
- | 220 | size_t len = strlen(component); |
|
- | 221 | char *name = malloc(len + 1); |
|
- | 222 | if (!name) { |
|
- | 223 | free(node); |
|
- | 224 | return 0; |
|
- | 225 | } |
|
- | 226 | strcpy(name, component); |
|
- | 227 | ||
- | 228 | tmpfs_dentry_initialize(node); |
|
- | 229 | node->index = tmpfs_next_index++; |
|
- | 230 | node->name = name; |
|
- | 231 | node->parent = dentry; |
|
- | 232 | if (lflag & L_DIRECTORY) |
|
- | 233 | node->type = TMPFS_DIRECTORY; |
|
- | 234 | else |
|
- | 235 | node->type = TMPFS_FILE; |
|
- | 236 | ||
- | 237 | /* Insert the new node into the namespace. */ |
|
- | 238 | if (dentry->child) { |
|
- | 239 | tmpfs_dentry_t *tmp = dentry->child; |
|
- | 240 | while (tmp->sibling) |
|
- | 241 | tmp = tmp->sibling; |
|
- | 242 | tmp->sibling = node; |
|
- | 243 | } else { |
|
- | 244 | dentry->child = node; |
|
- | 245 | } |
|
- | 246 | ||
- | 247 | /* Insert the new node into the dentry hash table. */ |
|
- | 248 | hash_table_insert(&dentries, &node->index, &node->dh_link); |
|
- | 249 | return node->index; |
|
215 | } |
250 | } |
216 | 251 | ||
217 | static int destroy_component(tmpfs_dentry_t *dentry) |
252 | static int destroy_component(tmpfs_dentry_t *dentry) |
218 | { |
253 | { |
219 | return EPERM; |
254 | return EPERM; |
Line 254... | Line 289... | ||
254 | ipc_answer_0(rid, ENAMETOOLONG); |
289 | ipc_answer_0(rid, ENAMETOOLONG); |
255 | return; |
290 | return; |
256 | } |
291 | } |
257 | component[len++] = PLB_GET_CHAR(next); |
292 | component[len++] = PLB_GET_CHAR(next); |
258 | next++; /* process next character */ |
293 | next++; /* process next character */ |
259 | if (next <= last) |
294 | if (next <= last) |
260 | continue; |
295 | continue; |
261 | } |
296 | } |
262 | 297 | ||
263 | assert(len); |
298 | assert(len); |
264 | component[len] = '\0'; |
299 | component[len] = '\0'; |
Line 277... | Line 312... | ||
277 | ipc_answer_0(rid, ENOTDIR); |
312 | ipc_answer_0(rid, ENOTDIR); |
278 | return; |
313 | return; |
279 | } |
314 | } |
280 | unsigned long index = create_node(dcur, |
315 | unsigned long index = create_node(dcur, |
281 | component, lflag); |
316 | component, lflag); |
282 | if (index) { |
317 | if (index > 0) { |
283 | ipc_answer_4(rid, EOK, |
318 | ipc_answer_4(rid, EOK, |
284 | tmpfs_reg.fs_handle, dev_handle, |
319 | tmpfs_reg.fs_handle, dev_handle, |
285 | index, 0); |
320 | index, 0); |
286 | } else { |
321 | } else { |
287 | ipc_answer_0(rid, ENOSPC); |
322 | ipc_answer_0(rid, ENOSPC); |