Changeset 5973fd0 in mainline
- Timestamp:
- 2008-01-18T23:45:16Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ae78b53
- Parents:
- 62da45a
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/tester/vfs/vfs1.c
r62da45a r5973fd0 1 1 /* 2 * Copyright (c) 200 7Jakub Jermar2 * Copyright (c) 2008 Jakub Jermar 3 3 * All rights reserved. 4 4 * … … 35 35 #include <unistd.h> 36 36 #include <fcntl.h> 37 #include <dirent.h> 37 38 #include "../tester.h" 38 39 … … 41 42 if (mount("tmpfs", "/", "nulldev0") != EOK) 42 43 return "Mount failed.\n"; 44 45 46 DIR *dirp; 47 struct dirent *dp; 48 49 dirp = opendir("/"); 50 if (!dirp) 51 return "opendir() failed."; 52 while ((dp = readdir(dirp))) 53 printf("Discovered %s\n", dp->d_name); 54 closedir(dirp); 55 43 56 int fd1 = open("/dir1/file1", 0); 44 57 int fd2 = open("/dir2/file2", 0); 45 58 46 59 if (fd1 < 0) 47 return " Openfailed.\n";60 return "open() failed.\n"; 48 61 if (fd2 < 0) 49 return " Openfailed.\n";62 return "open() failed.\n"; 50 63 51 64 if (!quiet) … … 56 69 ssize_t cnt = read(fd1, buf, sizeof(buf)); 57 70 if (cnt < 0) 58 return " Readfailed.\n";71 return "read() failed.\n"; 59 72 60 73 if (!quiet) -
uspace/lib/libc/generic/vfs.c
r62da45a r5973fd0 244 244 return NULL; 245 245 dirp->fd = open(dirname, 0); /* TODO: must be a directory */ 246 if ( !dirp->fd) {246 if (dirp->fd < 0) { 247 247 free(dirp); 248 248 return NULL; 249 249 } 250 dirp->pos = 0;251 250 return dirp; 252 251 } … … 254 253 struct dirent *readdir(DIR *dirp) 255 254 { 256 return NULL; /* TODO */ 255 ssize_t len = read(dirp->fd, &dirp->res.d_name[0], NAME_MAX + 1); 256 if (len <= 0) 257 return NULL; 258 return &dirp->res; 257 259 } 258 260 259 261 void rewinddir(DIR *dirp) 260 262 { 261 dirp->pos = 0;263 (void) lseek(dirp->fd, 0, SEEK_SET); 262 264 } 263 265 -
uspace/lib/libc/include/dirent.h
r62da45a r5973fd0 44 44 typedef struct { 45 45 int fd; 46 unsigned pos;47 46 struct dirent res; 48 47 } DIR; -
uspace/srv/fs/tmpfs/tmpfs_ops.c
r62da45a r5973fd0 46 46 #include <string.h> 47 47 #include <stdio.h> 48 #include <assert.h> 48 49 #include <sys/types.h> 49 50 #include <libadt/hash_table.h> … … 308 309 } 309 310 310 size_t bytes = max(0, min(dentry->size - pos, len)); 311 (void) ipc_data_read_finalize(callid, dentry->data + pos, bytes); 311 size_t bytes; 312 if (dentry->type == TMPFS_FILE) { 313 bytes = max(0, min(dentry->size - pos, len)); 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 /*
Note:
See TracChangeset
for help on using the changeset viewer.