From b4dabf60632ad1a7b8a0fe64cb38723867bb64ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 16 Oct 2002 16:14:14 +0000 Subject: [PATCH] Implemented all calls in fs_attr.h. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1544 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/libroot/os/Jamfile | 1 + src/kernel/libroot/os/fs_attr.c | 173 +++++++++++++++++++++++++++++++ src/kernel/libroot/os/syscalls.S | 8 ++ 3 files changed, 182 insertions(+) create mode 100644 src/kernel/libroot/os/fs_attr.c diff --git a/src/kernel/libroot/os/Jamfile b/src/kernel/libroot/os/Jamfile index c7ba613eaf..1dc2b3ea66 100644 --- a/src/kernel/libroot/os/Jamfile +++ b/src/kernel/libroot/os/Jamfile @@ -3,6 +3,7 @@ SubDir OBOS_TOP src kernel libroot os ; KernelObjects <$(SOURCE_GRIST)>area.c <$(SOURCE_GRIST)>debug.c + <$(SOURCE_GRIST)>fs_attr.c <$(SOURCE_GRIST)>port.c <$(SOURCE_GRIST)>sem.c <$(SOURCE_GRIST)>systeminfo.c diff --git a/src/kernel/libroot/os/fs_attr.c b/src/kernel/libroot/os/fs_attr.c new file mode 100644 index 0000000000..4d9455e209 --- /dev/null +++ b/src/kernel/libroot/os/fs_attr.c @@ -0,0 +1,173 @@ +/* +** 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" + + +// for the DIR structure +#define BUFFER_SIZE 2048 + + +ssize_t +fs_read_attr(int fd, const char *attribute, uint32 type, off_t pos, void *buffer, size_t readBytes) +{ + ssize_t bytes; + + int attr = sys_open_attr(fd, attribute, O_RDONLY); + if (attr < 0) + return attr; + + // type is not used at all + (void)type; + + bytes = sys_read(fd, pos, buffer, readBytes); + sys_close(attr); + + return bytes; +} + + +ssize_t +fs_write_attr(int fd, const char *attribute, uint32 type, off_t pos, const void *buffer, size_t readBytes) +{ + ssize_t bytes; + + int attr = sys_create_attr(fd, attribute, type, O_WRONLY); + if (attr < 0) + return attr; + + bytes = sys_write(fd, pos, buffer, readBytes); + sys_close(attr); + + return bytes; +} + + +int +fs_remove_attr(int fd, const char *attribute) +{ + return sys_remove_attr(fd, attribute); +} + + +int +fs_stat_attr(int fd, const char *attribute, struct attr_info *attrInfo) +{ + struct stat stat; + status_t status; + + int attr = sys_open_attr(fd, attribute, O_RDONLY); + if (attr < 0) + return attr; + + status = sys_fstat(attr, &stat); + if (status == B_OK) { + attrInfo->type = stat.st_type; + attrInfo->size = stat.st_size; + } + sys_close(attr); + + return status; +} + + +/* +int +fs_open_attr(const char *path, const char *attribute, uint32 type, int openMode) +{ + // ToDo: implement fs_open_attr() - or remove it completely + // if it will be implemented, rename the current fs_open_attr() to fs_fopen_attr() + return B_ERROR; +} +*/ + + +int +fs_open_attr(int fd, const char *attribute, uint32 type, int openMode) +{ + if (openMode & O_CREAT) + return sys_create_attr(fd, attribute, type, openMode); + + return sys_open_attr(fd, attribute, openMode); +} + + +int +fs_close_attr(int fd) +{ + return sys_close(fd); +} + + +static DIR * +open_attr_dir(int file, const char *path) +{ + DIR *dir; + + int fd = sys_open_attr_dir(file, path); + if (fd < 0) + return NULL; + + /* allocate the memory for the DIR structure */ + if ((dir = (DIR *)malloc(sizeof(DIR) + BUFFER_SIZE)) == NULL) + return NULL; + + dir->fd = fd; + + return dir; +} + + +DIR * +fs_open_attr_dir(const char *path) +{ + return open_attr_dir(-1, path); +} + + +DIR * +fs_fopen_attr_dir(int fd) +{ + return open_attr_dir(fd, NULL); +} + + +int +fs_close_attr_dir(DIR *dir) +{ + int status = sys_close(dir->fd); + + free(dir); + + return status; +} + + +struct dirent * +fs_read_attr_dir(DIR *dir) +{ + ssize_t count = sys_read_dir(dir->fd, &dir->ent, BUFFER_SIZE, 1); + if (count <= 0) + return NULL; + + return &dir->ent; +} + + +void +fs_rewind_attr_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 1d537b1da2..f42fb34755 100644 --- a/src/kernel/libroot/os/syscalls.S +++ b/src/kernel/libroot/os/syscalls.S @@ -64,6 +64,14 @@ SYSCALL4(sys_acquire_sem_etc, 21) SYSCALL1(sys_release_sem, 22) SYSCALL3(sys_release_sem_etc, 23) +/* VFS attribute calls */ +SYSCALL2(sys_open_attr_dir, 97) +SYSCALL4(sys_create_attr, 98) +SYSCALL3(sys_open_attr, 99) +SYSCALL3(sys_write_attr_stat, 100) +SYSCALL2(sys_remove_attr, 101) +SYSCALL4(sys_rename_attr, 102) + /* Thread calls */ SYSCALL0(sys_get_current_thread_id, 24) SYSCALL4(sys_spawn_thread, 35)