/trunk/uspace/app/tester/vfs/vfs1.c |
---|
38,6 → 38,9 |
#include <sys/stat.h> |
#include "../tester.h" |
char text[] = "O xein', angellein Lakedaimoniois hoti teide " |
"keimetha tois keinon rhemasi peithomenoi."; |
char *test_vfs1(bool quiet) |
{ |
if (mount("tmpfs", "/", "nulldev0") != EOK) |
45,7 → 48,25 |
if (mkdir("/mydir", 0) != 0) |
return "mkdir() failed.\n"; |
if (!quiet) |
printf("Created directory /mydir\n"); |
int fd0 = open("/mydir/myfile", O_CREAT); |
if (fd0 < 0) |
return "open() failed.\n"; |
if (!quiet) |
printf("Created /mydir/myfile, handle=%d\n", fd0); |
ssize_t cnt; |
size_t size = sizeof(text); |
cnt = write(fd0, text, size); |
if (cnt < 0) |
return "write() failed.\n"; |
if (!quiet) |
printf("Written %d btyes to handle %d.\n", cnt, fd0); |
if (lseek(fd0, 0, SEEK_SET) != 0) |
return "lseek() failed.\n"; |
DIR *dirp; |
struct dirent *dp; |
56,8 → 77,8 |
printf("Discovered %s\n", dp->d_name); |
closedir(dirp); |
int fd1 = open("/dir1/file1", 0); |
int fd2 = open("/dir2/file2", 0); |
int fd1 = open("/dir1/file1", O_RDONLY); |
int fd2 = open("/dir2/file2", O_RDONLY); |
if (fd1 < 0) |
return "open() failed.\n"; |
69,13 → 90,22 |
char buf[10]; |
ssize_t cnt = read(fd1, buf, sizeof(buf)); |
cnt = read(fd0, buf, sizeof(buf)); |
if (cnt < 0) |
return "read() failed.\n"; |
if (!quiet) |
printf("Read %d bytes: %.*s\n", cnt, cnt, buf); |
printf("Read %d bytes from handle %d: %.*s\n", cnt, fd0, cnt, |
buf); |
cnt = read(fd1, buf, sizeof(buf)); |
if (cnt < 0) |
return "read() failed.\n"; |
if (!quiet) |
printf("Read %d bytes from handle %d: %.*s\n", cnt, fd1, cnt, |
buf); |
return NULL; |
} |
/trunk/uspace/lib/libc/generic/vfs.c |
---|
165,7 → 165,10 |
async_wait_for(req, &rc); |
async_serialize_end(); |
futex_up(&vfs_phone_futex); |
if (rc == EOK) |
return (ssize_t) IPC_GET_ARG1(answer); |
else |
return -1; |
} |
ssize_t write(int fildes, const void *buf, size_t nbyte) |
195,7 → 198,10 |
async_wait_for(req, &rc); |
async_serialize_end(); |
futex_up(&vfs_phone_futex); |
if (rc == EOK) |
return (ssize_t) IPC_GET_ARG1(answer); |
else |
return -1; |
} |
off_t lseek(int fildes, off_t offset, int whence) |
/trunk/uspace/srv/fs/tmpfs/tmpfs.c |
---|
115,6 → 115,9 |
case VFS_READ: |
tmpfs_read(callid, &call); |
break; |
case VFS_WRITE: |
tmpfs_write(callid, &call); |
break; |
default: |
ipc_answer_0(callid, ENOTSUP); |
break; |
/trunk/uspace/srv/fs/tmpfs/tmpfs_ops.c |
---|
497,7 → 497,7 |
if (pos + len <= dentry->size) { |
/* The file size is not changing. */ |
(void) ipc_data_write_finalize(callid, dentry->data + pos, len); |
ipc_answer_1(rid, EOK, len); |
ipc_answer_2(rid, EOK, len, dentry->size); |
return; |
} |
size_t delta = (pos + len) - dentry->size; |
511,7 → 511,7 |
void *newdata = realloc(dentry->data, dentry->size + delta); |
if (!newdata) { |
ipc_answer_0(callid, ENOMEM); |
ipc_answer_1(rid, EOK, 0); |
ipc_answer_2(rid, EOK, 0, dentry->size); |
return; |
} |
/* Clear any newly allocated memory in order to emulate gaps. */ |
/trunk/uspace/srv/vfs/vfs_ops.c |
---|
470,11 → 470,13 |
rwlock_read_unlock(&file->node->contents_rwlock); |
else { |
/* Update the cached version of node's size. */ |
if (rc == EOK) |
file->node->size = IPC_GET_ARG2(answer); |
rwlock_write_unlock(&file->node->contents_rwlock); |
} |
/* Update the position pointer and unlock the open file. */ |
if (rc == EOK) |
file->pos += bytes; |
futex_up(&file->lock); |