/trunk/uspace/app/tester/vfs/vfs1.c |
---|
1,5 → 1,5 |
/* |
* Copyright (c) 2007 Jakub Jermar |
* Copyright (c) 2008 Jakub Jermar |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
34,6 → 34,7 |
#include <vfs.h> |
#include <unistd.h> |
#include <fcntl.h> |
#include <dirent.h> |
#include "../tester.h" |
char *test_vfs1(bool quiet) |
40,13 → 41,25 |
{ |
if (mount("tmpfs", "/", "nulldev0") != EOK) |
return "Mount failed.\n"; |
DIR *dirp; |
struct dirent *dp; |
dirp = opendir("/"); |
if (!dirp) |
return "opendir() failed."; |
while ((dp = readdir(dirp))) |
printf("Discovered %s\n", dp->d_name); |
closedir(dirp); |
int fd1 = open("/dir1/file1", 0); |
int fd2 = open("/dir2/file2", 0); |
if (fd1 < 0) |
return "Open failed.\n"; |
return "open() failed.\n"; |
if (fd2 < 0) |
return "Open failed.\n"; |
return "open() failed.\n"; |
if (!quiet) |
printf("Opened file descriptors %d and %d.\n", fd1, fd2); |
55,7 → 68,7 |
ssize_t cnt = read(fd1, buf, sizeof(buf)); |
if (cnt < 0) |
return "Read failed.\n"; |
return "read() failed.\n"; |
if (!quiet) |
printf("Read %d bytes: %.*s\n", cnt, cnt, buf); |
/trunk/uspace/lib/libc/include/dirent.h |
---|
43,7 → 43,6 |
typedef struct { |
int fd; |
unsigned pos; |
struct dirent res; |
} DIR; |
/trunk/uspace/lib/libc/generic/vfs.c |
---|
243,22 → 243,24 |
if (!dirp) |
return NULL; |
dirp->fd = open(dirname, 0); /* TODO: must be a directory */ |
if (!dirp->fd) { |
if (dirp->fd < 0) { |
free(dirp); |
return NULL; |
} |
dirp->pos = 0; |
return dirp; |
} |
struct dirent *readdir(DIR *dirp) |
{ |
return NULL; /* TODO */ |
ssize_t len = read(dirp->fd, &dirp->res.d_name[0], NAME_MAX + 1); |
if (len <= 0) |
return NULL; |
return &dirp->res; |
} |
void rewinddir(DIR *dirp) |
{ |
dirp->pos = 0; |
(void) lseek(dirp->fd, 0, SEEK_SET); |
} |
int closedir(DIR *dirp) |
/trunk/uspace/srv/fs/tmpfs/tmpfs_ops.c |
---|
45,6 → 45,7 |
#include <stdlib.h> |
#include <string.h> |
#include <stdio.h> |
#include <assert.h> |
#include <sys/types.h> |
#include <libadt/hash_table.h> |
#include <as.h> |
307,9 → 308,37 |
return; |
} |
size_t bytes = max(0, min(dentry->size - pos, len)); |
(void) ipc_data_read_finalize(callid, dentry->data + pos, bytes); |
size_t bytes; |
if (dentry->type == TMPFS_FILE) { |
bytes = max(0, min(dentry->size - pos, len)); |
(void) ipc_data_read_finalize(callid, dentry->data + pos, |
bytes); |
} else { |
int i; |
tmpfs_dentry_t *cur = dentry->child; |
assert(dentry->type == TMPFS_DIRECTORY); |
/* |
* Yes, we really use O(n) algorithm here. |
* If it bothers someone, it could be fixed by introducing a |
* hash table. |
*/ |
for (i = 0, cur = dentry->child; i < pos && cur; i++, |
cur = cur->sibling) |
; |
if (!cur) { |
ipc_answer_0(callid, ENOENT); |
ipc_answer_1(rid, ENOENT, 0); |
return; |
} |
(void) ipc_data_read_finalize(callid, cur->name, |
strlen(cur->name) + 1); |
bytes = 1; |
} |
/* |
* Answer the VFS_READ call. |
*/ |