From c46de31dea61c70f3767079894e9f527833f3c22 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sat, 28 Aug 2004 20:36:53 +0000 Subject: [PATCH] Renamed fs_query.c to fs_query.cpp and implemented the function. They don't work yet as the kernel part is not implemented yet. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8700 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/libroot/os/fs_query.c | 64 --------------- src/kernel/libroot/os/fs_query.cpp | 124 +++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 64 deletions(-) delete mode 100644 src/kernel/libroot/os/fs_query.c create mode 100644 src/kernel/libroot/os/fs_query.cpp diff --git a/src/kernel/libroot/os/fs_query.c b/src/kernel/libroot/os/fs_query.c deleted file mode 100644 index dd7e2114f3..0000000000 --- a/src/kernel/libroot/os/fs_query.c +++ /dev/null @@ -1,64 +0,0 @@ -/* -** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. -** Distributed under the terms of the Haiku License. -*/ - - -#include - -#include -#include -#include - -#include "syscalls.h" - -// ToDo: implement these for real - the VFS functions are still missing! - -#define RETURN_AND_SET_ERRNO(status) \ - { \ - if (status < 0) { \ - errno = status; \ - return -1; \ - } \ - return status; \ - } - -// for the DIR structure -#define BUFFER_SIZE 2048 - - -DIR * -fs_open_query(dev_t device, const char *query, uint32 flags) -{ - return NULL; -} - - -DIR * -fs_open_live_query(dev_t device, const char *query, - uint32 flags, port_id port, int32 token) -{ - return NULL; -} - - -int -fs_close_query(DIR *d) -{ - return 0; -} - - -struct dirent * -fs_read_query(DIR *d) -{ - return NULL; -} - - -status_t -get_path_for_dirent(struct dirent *dent, char *buf, size_t len) -{ - return B_ERROR; -} - diff --git a/src/kernel/libroot/os/fs_query.cpp b/src/kernel/libroot/os/fs_query.cpp new file mode 100644 index 0000000000..596f8fbd84 --- /dev/null +++ b/src/kernel/libroot/os/fs_query.cpp @@ -0,0 +1,124 @@ +/* +** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the Haiku 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 + + +DIR * +fs_open_query(dev_t device, const char *query, uint32 flags) +{ + // check parameters + if (device < 0 || !query) { + errno = B_BAD_VALUE; + return NULL; + } + // open + int fd = _kern_open_query(device, query, flags, -1, -1); + if (fd < 0) { + errno = fd; + return NULL; + } + // allocate a DIR + DIR *dir = (DIR*)malloc(BUFFER_SIZE); + if (!dir) { + _kern_close(fd); + errno = B_NO_MEMORY; + return NULL; + } + dir->fd = fd; + return dir; +} + + +DIR * +fs_open_live_query(dev_t device, const char *query, + uint32 flags, port_id port, int32 token) +{ + // check parameters + if (device < 0 || !query || port < 0) { + errno = B_BAD_VALUE; + return NULL; + } + flags |= B_LIVE_QUERY; + // open + int fd = _kern_open_query(device, query, flags, port, token); + if (fd < 0) { + errno = fd; + return NULL; + } + // allocate a DIR + DIR *dir = (DIR*)malloc(BUFFER_SIZE); + if (!dir) { + _kern_close(fd); + errno = B_NO_MEMORY; + return NULL; + } + dir->fd = fd; + return dir; +} + + +int +fs_close_query(DIR *d) +{ + if (!d) + RETURN_AND_SET_ERRNO(B_BAD_VALUE); + int fd = d->fd; + free(d); + return _kern_close(fd); +} + + +struct dirent * +fs_read_query(DIR *d) +{ + // check parameters + if (!d) { + errno = B_BAD_VALUE; + return NULL; + } + // read + int32 bufferSize = BUFFER_SIZE - ((uint8*)&d->ent - (uint8*)d); + ssize_t result = _kern_read_dir(d->fd, &d->ent, bufferSize, 1); + if (result < 0) { + errno = result; + return NULL; + } + if (result == 0) { + errno = B_ENTRY_NOT_FOUND; + return NULL; + } + return &d->ent; +} + + +status_t +get_path_for_dirent(struct dirent *dent, char *buf, size_t len) +{ + if (!dent || !buf) + return B_BAD_VALUE; + return _kern_entry_ref_to_path(dent->d_pdev, dent->d_pino, dent->d_name, + buf, len); +} +