From 64b00573d261f8f92e16f5a3920393e3d1a1eed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 17 Oct 2002 19:30:59 +0000 Subject: [PATCH] Added implementation of the functions in fs_index.h. Commented system_time() in time.c - it's already implemented in atomic.S (not that it would belong there). Fixed linking of rewind.c Added syscalls for the index functions. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1565 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/libroot/os/Jamfile | 1 + src/kernel/libroot/os/fs_index.c | 122 ++++++++++++++++++++++++ src/kernel/libroot/os/syscalls.S | 6 ++ src/kernel/libroot/os/time.c | 5 +- src/kernel/libroot/posix/stdio/rewind.c | 7 +- 5 files changed, 135 insertions(+), 6 deletions(-) create mode 100644 src/kernel/libroot/os/fs_index.c diff --git a/src/kernel/libroot/os/Jamfile b/src/kernel/libroot/os/Jamfile index 1dc2b3ea66..bcbea8fc56 100644 --- a/src/kernel/libroot/os/Jamfile +++ b/src/kernel/libroot/os/Jamfile @@ -4,6 +4,7 @@ KernelObjects <$(SOURCE_GRIST)>area.c <$(SOURCE_GRIST)>debug.c <$(SOURCE_GRIST)>fs_attr.c + <$(SOURCE_GRIST)>fs_index.c <$(SOURCE_GRIST)>port.c <$(SOURCE_GRIST)>sem.c <$(SOURCE_GRIST)>systeminfo.c diff --git a/src/kernel/libroot/os/fs_index.c b/src/kernel/libroot/os/fs_index.c new file mode 100644 index 0000000000..e15cfc162e --- /dev/null +++ b/src/kernel/libroot/os/fs_index.c @@ -0,0 +1,122 @@ +/* +** Copyright 2002, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ + + +#include + +#include +#include +#include + +#include "syscalls.h" + + +#define RETURN_AND_SET_ERRNO(status) \ + { \ + if (status < 0) { \ + errno = status; \ + return -1; \ + } \ + return status; \ + } + +// for the DIR structure +#define BUFFER_SIZE 2048 + + +int +fs_create_index(dev_t device, const char *name, uint32 type, uint32 flags) +{ + status_t status = sys_create_index(device, name, type, flags); + + RETURN_AND_SET_ERRNO(status); +} + + +int +fs_remove_index(dev_t device, const char *name) +{ + status_t status = sys_remove_index(device, name); + + RETURN_AND_SET_ERRNO(status); +} + + +int +fs_stat_index(dev_t device, const char *name, struct index_info *indexInfo) +{ + struct stat stat; + + status_t status = sys_read_index_stat(device, name, &stat); + if (status == B_OK) { + indexInfo->type = stat.st_type; + indexInfo->size = stat.st_size; + indexInfo->modification_time = stat.st_mtime; + indexInfo->creation_time = stat.st_crtime; + indexInfo->uid = stat.st_uid; + indexInfo->gid = stat.st_gid; + } + + RETURN_AND_SET_ERRNO(status); +} + + +DIR * +fs_open_index_dir(dev_t device) +{ + DIR *dir; + + int fd = sys_open_index_dir(device); + if (fd < 0) { + errno = fd; + return NULL; + } + + /* allocate the memory for the DIR structure */ + if ((dir = (DIR *)malloc(sizeof(DIR) + BUFFER_SIZE)) == NULL) { + errno = B_NO_MEMORY; + sys_close(fd); + return NULL; + } + + dir->fd = fd; + + return dir; +} + + +int +fs_close_index_dir(DIR *dir) +{ + int status = sys_close(dir->fd); + + free(dir); + + RETURN_AND_SET_ERRNO(status); +} + + +struct dirent * +fs_read_index_dir(DIR *dir) +{ + ssize_t count = sys_read_dir(dir->fd, &dir->ent, BUFFER_SIZE, 1); + if (count <= 0) { + if (count < 0) + errno = count; + return NULL; + } + + return &dir->ent; +} + + +void +fs_rewind_index_dir(DIR *dir) +{ + int status = sys_rewind_dir(dir->fd); + if (status < 0) + errno = status; +} + diff --git a/src/kernel/libroot/os/syscalls.S b/src/kernel/libroot/os/syscalls.S index dc7c60b269..6fa029c76b 100644 --- a/src/kernel/libroot/os/syscalls.S +++ b/src/kernel/libroot/os/syscalls.S @@ -72,6 +72,12 @@ SYSCALL3(sys_open_attr, 99) SYSCALL2(sys_remove_attr, 101) SYSCALL4(sys_rename_attr, 102) +/* VFS index calls */ +SYSCALL1(sys_open_index_dir, 106) +SYSCALL4(sys_create_index, 107) +SYSCALL3(sys_read_index_stat, 108) +SYSCALL2(sys_remove_index, 109) + /* semaphore calls */ SYSCALL2(sys_create_sem, 18) SYSCALL1(sys_delete_sem, 19) diff --git a/src/kernel/libroot/os/time.c b/src/kernel/libroot/os/time.c index 5192d71f48..cd8e643548 100644 --- a/src/kernel/libroot/os/time.c +++ b/src/kernel/libroot/os/time.c @@ -39,12 +39,15 @@ set_timezone(char *timezone) } +/* +// ToDo: currently defined in atomic.S - but should be in its own file time.S bigtime_t system_time(void) { - /* time since booting in microseconds */ + // time since booting in microseconds return sys_system_time(); } +*/ bigtime_t diff --git a/src/kernel/libroot/posix/stdio/rewind.c b/src/kernel/libroot/posix/stdio/rewind.c index 75d28d1bba..1ed3c3188a 100644 --- a/src/kernel/libroot/posix/stdio/rewind.c +++ b/src/kernel/libroot/posix/stdio/rewind.c @@ -34,18 +34,15 @@ * SUCH DAMAGE. */ -#if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: rewind.c,v 1.2 1996/08/19 08:33:02 tholo Exp $"; -#endif /* LIBC_SCCS and not lint */ - #include #include + void rewind(fp) register FILE *fp; { (void) fseek(fp, 0L, SEEK_SET); - clearerr(fp); + //clearerr(fp); errno = 0; /* not required, but seems reasonable */ }