Rev 2693 | Rev 2700 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2693 | Rev 2699 | ||
|---|---|---|---|
| Line 43... | Line 43... | ||
| 43 | #include <errno.h> |
43 | #include <errno.h> |
| 44 | #include <atomic.h> |
44 | #include <atomic.h> |
| 45 | #include <stdlib.h> |
45 | #include <stdlib.h> |
| 46 | #include <string.h> |
46 | #include <string.h> |
| 47 | #include <stdio.h> |
47 | #include <stdio.h> |
| - | 48 | #include <assert.h> |
|
| 48 | #include <sys/types.h> |
49 | #include <sys/types.h> |
| 49 | #include <libadt/hash_table.h> |
50 | #include <libadt/hash_table.h> |
| 50 | #include <as.h> |
51 | #include <as.h> |
| 51 | 52 | ||
| 52 | #define min(a, b) ((a) < (b) ? (a) : (b)) |
53 | #define min(a, b) ((a) < (b) ? (a) : (b)) |
| Line 305... | Line 306... | ||
| 305 | ipc_answer_0(callid, EINVAL); |
306 | ipc_answer_0(callid, EINVAL); |
| 306 | ipc_answer_0(rid, EINVAL); |
307 | ipc_answer_0(rid, EINVAL); |
| 307 | return; |
308 | return; |
| 308 | } |
309 | } |
| 309 | 310 | ||
| - | 311 | size_t bytes; |
|
| - | 312 | if (dentry->type == TMPFS_FILE) { |
|
| 310 | size_t bytes = max(0, min(dentry->size - pos, len)); |
313 | bytes = max(0, min(dentry->size - pos, len)); |
| 311 | (void) ipc_data_read_finalize(callid, dentry->data + pos, bytes); |
314 | (void) ipc_data_read_finalize(callid, dentry->data + pos, |
| - | 315 | bytes); |
|
| - | 316 | } else { |
|
| - | 317 | int i; |
|
| - | 318 | tmpfs_dentry_t *cur = dentry->child; |
|
| - | 319 | ||
| - | 320 | assert(dentry->type == TMPFS_DIRECTORY); |
|
| - | 321 | ||
| - | 322 | /* |
|
| - | 323 | * Yes, we really use O(n) algorithm here. |
|
| - | 324 | * If it bothers someone, it could be fixed by introducing a |
|
| - | 325 | * hash table. |
|
| - | 326 | */ |
|
| - | 327 | for (i = 0, cur = dentry->child; i < pos && cur; i++, |
|
| - | 328 | cur = cur->sibling) |
|
| - | 329 | ; |
|
| - | 330 | ||
| - | 331 | if (!cur) { |
|
| - | 332 | ipc_answer_0(callid, ENOENT); |
|
| - | 333 | ipc_answer_1(rid, ENOENT, 0); |
|
| - | 334 | return; |
|
| - | 335 | } |
|
| - | 336 | ||
| - | 337 | (void) ipc_data_read_finalize(callid, cur->name, |
|
| - | 338 | strlen(cur->name) + 1); |
|
| - | 339 | bytes = 1; |
|
| - | 340 | } |
|
| 312 | 341 | ||
| 313 | /* |
342 | /* |
| 314 | * Answer the VFS_READ call. |
343 | * Answer the VFS_READ call. |
| 315 | */ |
344 | */ |
| 316 | ipc_answer_1(rid, EOK, bytes); |
345 | ipc_answer_1(rid, EOK, bytes); |