Reorganised sys_open.

vfs_create and mknod now returns the newly created vnode.
(which might be used by upper layers).
This commit is contained in:
Bahadir Balban
2008-04-19 00:40:48 +01:00
parent f7163b7e93
commit 8c4c436925
5 changed files with 77 additions and 33 deletions

View File

@@ -12,22 +12,51 @@ int fileio(void)
int fd;
ssize_t cnt;
int err;
char buf[128];
off_t offset;
char *str = "I WROTE TO THIS FILE\n";
if ((fd = open("/home/bahadir/newfile.txt", O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) < 0) {
perror("OPEN");
return 0;
return -1;
}
if ((int)(cnt = write(fd, str, strlen(str))) < 0) {
perror("WRITE");
return 0;
return -1;
}
if ((err = close(fd)) < 0)
if ((int)(offset = lseek(fd, 0, SEEK_SET)) < 0) {
perror("LSEEK");
return -1;
}
if ((int)(cnt = read(fd, buf, strlen(str))) < 0) {
perror("WRITE");
return -1;
}
printf("Read: %d bytes from file.\n", cnt);
if (cnt) {
printf("Read string: %s\n", buf);
}
if ((err = close(fd)) < 0) {
perror("CLOSE");
return -1;
}
return 0;
}
#if defined(HOST_TESTS)
int main(void)
{
printf("File IO test:\n");
if (fileio() == 0)
printf("-- PASSED --\n");
return 0;
}
#endif