Added a new write_stat() call to the file descriptor operations (plus syscall).

Renamed sys_read_stat() to sys_read_path_stat() - sys_read_stat() is now
the fd operation (same for the corresponding write call).
Removed the sys_write_attr_stat() call because it is no longer needed.
Added stat(), fstat(), and other POSIX calls to the kernel - many are still
missing (mainly from stdio).
Added symbols (but no implementation) for unistd.h's process id functions.
Adapted libroot calls that used sys_read_stat() before to the new architecture.
module.c and bus_man.c now use stat() directly instead of the sys_read_path_stat()
call.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1555 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2002-10-17 03:09:25 +00:00
parent 8e5ca65bc9
commit f4e51a2dfb
17 changed files with 315 additions and 197 deletions

View File

@ -1,6 +1,8 @@
SubDir OBOS_TOP src kernel ;
KernelStaticLibraryObjects libkern.a :
<$(SOURCE_GRIST)!libroot!posix>errno.o
<$(SOURCE_GRIST)!libroot!posix!locale>ctype.o
<$(SOURCE_GRIST)!libroot!posix!stdio>kvsprintf.o
@ -15,6 +17,31 @@ KernelStaticLibraryObjects libkern.a :
<$(SOURCE_GRIST)!libroot!posix!stdlib>rand.o
<$(SOURCE_GRIST)!libroot!posix!stdlib>random.o
<$(SOURCE_GRIST)!libroot!posix!sys>chmod.o
<$(SOURCE_GRIST)!libroot!posix!sys>stat.o
<$(SOURCE_GRIST)!libroot!posix!sys>mkdir.o
<$(SOURCE_GRIST)!libroot!posix!unistd>access.o
<$(SOURCE_GRIST)!libroot!posix!unistd>chown.o
<$(SOURCE_GRIST)!libroot!posix!unistd>close.o
<$(SOURCE_GRIST)!libroot!posix!unistd>conf.o
<$(SOURCE_GRIST)!libroot!posix!unistd>directory.o
<$(SOURCE_GRIST)!libroot!posix!unistd>dup.o
<$(SOURCE_GRIST)!libroot!posix!unistd>dup2.o
<$(SOURCE_GRIST)!libroot!posix!unistd>getopt.o
<$(SOURCE_GRIST)!libroot!posix!unistd>hostname.o
<$(SOURCE_GRIST)!libroot!posix!unistd>ioctl.o
<$(SOURCE_GRIST)!libroot!posix!unistd>link.o
<$(SOURCE_GRIST)!libroot!posix!unistd>lseek.o
<$(SOURCE_GRIST)!libroot!posix!unistd>mount.o
<$(SOURCE_GRIST)!libroot!posix!unistd>open.o
<$(SOURCE_GRIST)!libroot!posix!unistd>read.o
<$(SOURCE_GRIST)!libroot!posix!unistd>sleep.o
<$(SOURCE_GRIST)!libroot!posix!unistd>truncate.o
<$(SOURCE_GRIST)!libroot!posix!unistd>usergroup.o
<$(SOURCE_GRIST)!libroot!posix!unistd>usleep.o
<$(SOURCE_GRIST)!libroot!posix!unistd>write.o
<$(SOURCE_GRIST)!libroot!posix!string>memchr.o
<$(SOURCE_GRIST)!libroot!posix!string>memcmp.o
<$(SOURCE_GRIST)!libroot!posix!string>memcpy.o

View File

@ -166,22 +166,22 @@ int cmd_pwd(int argc, char *argv[])
int cmd_stat(int argc, char *argv[])
{
int rc;
struct stat stat;
struct stat st;
if (argc < 2) {
printf("not enough arguments to stat\n");
return 0;
}
rc = sys_read_stat(argv[1], true, &stat);
rc = stat(argv[1], &st);
if (rc >= 0) {
printf("stat of file '%s': \n", argv[1]);
printf("vnid 0x%x\n", (unsigned int)stat.st_ino);
// printf("type %d\n", stat.type);
printf("size %d\n", (int)stat.st_size);
} else {
printf("vnid 0x%x\n", (unsigned int)st.st_ino);
printf("type %d\n", st.st_type);
printf("size %d\n", (int)st.st_size);
} else
printf("stat failed for file '%s'\n", argv[1]);
}
return 0;
}

View File

@ -26,7 +26,8 @@ static bus *bus_list;
static mutex bus_lock;
int bus_man_init(kernel_args *ka)
int
bus_man_init(kernel_args *ka)
{
mutex_init(&bus_lock, "bus_lock");
@ -35,7 +36,9 @@ int bus_man_init(kernel_args *ka)
return 0;
}
static bus *find_bus(const char *path)
static bus *
find_bus(const char *path)
{
bus *b;
@ -46,7 +49,9 @@ static bus *find_bus(const char *path)
return b;
}
int bus_register_bus(const char *path)
int
bus_register_bus(const char *path)
{
bus *b;
int err = 0;
@ -74,6 +79,7 @@ int bus_register_bus(const char *path)
bus_list = b;
} else {
err = ENODEV;
goto err;
}
err = 0;
@ -82,16 +88,18 @@ err:
return err;
}
static int bus_find_device_recurse(int *n, char *base_path, int max_path_len, int base_fd, id_list *vendor_ids, id_list *device_ids)
static int
bus_find_device_recurse(int *n, char *base_path, int max_path_len, int base_fd, id_list *vendor_ids, id_list *device_ids)
{
char buffer[sizeof(struct dirent) + SYS_MAX_NAME_LEN + 1];
struct dirent *dirent = (struct dirent *)buffer;
int base_path_len = strlen(base_path);
ssize_t len;
int err;
struct stat stat;
while ((len = sys_read_dir(base_fd, dirent, sizeof(buffer), 1)) > 0) {
struct stat st;
int fd;
// reset the base_path to the original string passed in
@ -99,11 +107,11 @@ static int bus_find_device_recurse(int *n, char *base_path, int max_path_len, in
dirent->d_name[dirent->d_reclen] = '\0';
strlcat(base_path, dirent->d_name, max_path_len);
err = sys_read_stat(base_path, true, &stat);
err = stat(base_path, &st);
if (err < 0)
continue;
if (S_ISDIR(stat.st_mode)) {
if (S_ISDIR(st.st_mode)) {
fd = sys_open_dir(base_path);
if (fd < 0)
continue;
@ -114,7 +122,7 @@ static int bus_find_device_recurse(int *n, char *base_path, int max_path_len, in
if (err >= 0)
return err;
continue;
} else if (S_ISREG(stat.st_mode)) {
} else if (S_ISREG(st.st_mode)) {
// we opened the device
// XXX assumes PCI
struct pci_cfg cfg;
@ -146,7 +154,9 @@ static int bus_find_device_recurse(int *n, char *base_path, int max_path_len, in
return ENODEV;
}
int bus_find_device(int n, id_list *vendor_ids, id_list *device_ids, device *dev)
int
bus_find_device(int n, id_list *vendor_ids, id_list *device_ids, device *dev)
{
int base_fd;
int fd;
@ -189,4 +199,3 @@ int bus_find_device(int n, id_list *vendor_ids, id_list *device_ids, device *dev
return err;
}

View File

@ -382,28 +382,57 @@ user_rewind_dir(int fd)
int
user_fstat(int fd, struct stat *stat)
user_read_stat(int fd, struct stat *userStat)
{
struct file_descriptor *descriptor;
status_t status;
/* This is a user_function, so abort if we have a kernel address */
CHECK_USER_ADDR(stat)
CHECK_USER_ADDR(userStat)
descriptor = get_fd(get_current_io_context(false), fd);
if (descriptor == NULL)
return B_FILE_ERROR;
TRACE(("user_fstat(descriptor = %p)\n",descriptor));
TRACE(("user_read_stat(descriptor = %p)\n",descriptor));
if (descriptor->ops->fd_stat) {
if (descriptor->ops->fd_read_stat) {
// we're using the stat buffer on the stack to not have to
// lock the given stat buffer in memory
struct stat kstat;
struct stat stat;
status = descriptor->ops->fd_stat(descriptor, &kstat);
status = descriptor->ops->fd_read_stat(descriptor, &stat);
if (status >= 0)
status = user_memcpy(stat, &kstat, sizeof(*stat));
status = user_memcpy(userStat, &stat, sizeof(stat));
} else
status = EOPNOTSUPP;
put_fd(descriptor);
return status;
}
int
user_write_stat(int fd, const struct stat *userStat, int statMask)
{
struct file_descriptor *descriptor;
status_t status;
CHECK_USER_ADDR(userStat)
descriptor = get_fd(get_current_io_context(false), fd);
if (descriptor == NULL)
return B_FILE_ERROR;
TRACE(("user_write_stat(descriptor = %p)\n", descriptor));
if (descriptor->ops->fd_write_stat) {
// we're using the stat buffer on the stack to not have to
// lock the given stat buffer in memory
struct stat stat;
status = user_memcpy(&stat, userStat, sizeof(stat));
if (status == B_OK)
status = descriptor->ops->fd_write_stat(descriptor, &stat, statMask);
} else
status = EOPNOTSUPP;
@ -583,7 +612,7 @@ sys_rewind_dir(int fd)
int
sys_fstat(int fd, struct stat *stat)
sys_read_stat(int fd, struct stat *stat)
{
struct file_descriptor *descriptor;
status_t status;
@ -592,10 +621,32 @@ sys_fstat(int fd, struct stat *stat)
if (descriptor == NULL)
return B_FILE_ERROR;
TRACE(("sys_fstat(descriptor = %p)\n",descriptor));
TRACE(("sys_read_stat(descriptor = %p)\n",descriptor));
if (descriptor->ops->fd_stat)
status = descriptor->ops->fd_stat(descriptor, stat);
if (descriptor->ops->fd_read_stat)
status = descriptor->ops->fd_read_stat(descriptor, stat);
else
status = EOPNOTSUPP;
put_fd(descriptor);
return status;
}
int
sys_write_stat(int fd, const struct stat *stat, int statMask)
{
struct file_descriptor *descriptor;
status_t status;
descriptor = get_fd(get_current_io_context(true), fd);
if (descriptor == NULL)
return B_FILE_ERROR;
TRACE(("sys_write_stat(descriptor = %p)\n", descriptor));
if (descriptor->ops->fd_write_stat)
status = descriptor->ops->fd_write_stat(descriptor, stat, statMask);
else
status = EOPNOTSUPP;

View File

@ -23,7 +23,7 @@
#include "bootfs.h"
#define BOOTFS_TRACE 1
#define BOOTFS_TRACE 0
#if BOOTFS_TRACE
#define TRACE(x) dprintf x

View File

@ -3,8 +3,6 @@
** Distributed under the terms of the NewOS License.
*/
// 280202 TK: added partition support
#include <kernel.h>
#include <vfs.h>
#include <debug.h>
@ -24,7 +22,7 @@
#include <stdio.h>
#define DEVFS_TRACE 1
#define DEVFS_TRACE 0
#if DEVFS_TRACE
# define TRACE(x) dprintf x

View File

@ -20,7 +20,7 @@
#include "rootfs.h"
#define ROOTFS_TRACE 1
#define ROOTFS_TRACE 0
#if ROOTFS_TRACE
#define TRACE(x) dprintf x

View File

@ -46,7 +46,7 @@
#include <fs_info.h>
#ifndef TRACE_VFS
# define TRACE_VFS 1
# define TRACE_VFS 0
#endif
#if TRACE_VFS
# define PRINT(x) dprintf x
@ -141,11 +141,11 @@ static ssize_t file_write(struct file_descriptor *, off_t pos, const void *buffe
static off_t file_seek(struct file_descriptor *, off_t pos, int seek_type);
static void file_free_fd(struct file_descriptor *);
static status_t file_close(struct file_descriptor *);
static status_t dir_read(struct file_descriptor *,struct dirent *buffer,size_t bufferSize,uint32 *_count);
static status_t dir_read(struct file_descriptor *, struct dirent *buffer, size_t bufferSize, uint32 *_count);
static status_t dir_rewind(struct file_descriptor *);
static void dir_free_fd(struct file_descriptor *);
static status_t dir_close(struct file_descriptor *);
static status_t attr_dir_read(struct file_descriptor *,struct dirent *buffer,size_t bufferSize,uint32 *_count);
static status_t attr_dir_read(struct file_descriptor *, struct dirent *buffer, size_t bufferSize, uint32 *_count);
static status_t attr_dir_rewind(struct file_descriptor *);
static void attr_dir_free_fd(struct file_descriptor *);
static status_t attr_dir_close(struct file_descriptor *);
@ -155,13 +155,15 @@ static off_t attr_seek(struct file_descriptor *, off_t pos, int seek_type);
static void attr_free_fd(struct file_descriptor *);
static status_t attr_close(struct file_descriptor *);
static status_t attr_read_stat(struct file_descriptor *, struct stat *);
static status_t index_dir_read(struct file_descriptor *,struct dirent *buffer,size_t bufferSize,uint32 *_count);
static status_t attr_write_stat(struct file_descriptor *, const struct stat *, int statMask);
static status_t index_dir_read(struct file_descriptor *, struct dirent *buffer, size_t bufferSize, uint32 *_count);
static status_t index_dir_rewind(struct file_descriptor *);
static void index_dir_free_fd(struct file_descriptor *);
static status_t index_dir_close(struct file_descriptor *);
static status_t common_ioctl(struct file_descriptor *, ulong, void *buf, size_t len);
static status_t common_read_stat(struct file_descriptor *, struct stat *);
static status_t common_write_stat(struct file_descriptor *, const struct stat *, int statMask);
static int vfs_open(char *path, int omode, bool kernel);
static int vfs_open_dir(char *path, bool kernel);
@ -178,6 +180,7 @@ struct fd_ops gFileOps = {
NULL,
NULL,
common_read_stat,
common_write_stat,
file_close,
file_free_fd
};
@ -190,6 +193,7 @@ struct fd_ops gDirectoryOps = {
dir_read,
dir_rewind,
common_read_stat,
common_write_stat,
dir_close,
dir_free_fd
};
@ -202,6 +206,7 @@ struct fd_ops gAttributeDirectoryOps = {
attr_dir_read,
attr_dir_rewind,
common_read_stat,
common_write_stat,
attr_dir_close,
attr_dir_free_fd
};
@ -214,18 +219,20 @@ struct fd_ops gAttributeOps = {
NULL,
NULL,
attr_read_stat,
attr_write_stat,
attr_close,
attr_free_fd
};
struct fd_ops gIndexDirectoryOps = {
NULL,
NULL,
NULL,
NULL,
NULL, // read()
NULL, // write()
NULL, // seek()
NULL, // ioctl()
index_dir_read,
index_dir_rewind,
NULL,
NULL, // read_stat()
NULL, // write_stat()
index_dir_close,
index_dir_free_fd
};
@ -2462,20 +2469,52 @@ common_read_stat(struct file_descriptor *descriptor, struct stat *stat)
{
struct vnode *vnode = descriptor->u.vnode;
FUNCTION(("common_read_stat: stat 0x%p\n", stat));
FUNCTION(("common_read_stat: stat %p\n", stat));
return FS_CALL(vnode, read_stat)(vnode->mount->cookie, vnode->private_node, stat);
}
static status_t
common_write_stat(int fd, char *path, bool traverseLeafLink, const struct stat *stat, int statMask, bool kernel)
common_write_stat(struct file_descriptor *descriptor, const struct stat *stat, int statMask)
{
struct vnode *vnode = descriptor->u.vnode;
FUNCTION(("common_write_stat(vnode = %p, stat = %p, statMask = %d)\n", vnode, stat, statMask));
if (!FS_CALL(vnode, write_stat))
return EROFS;
return FS_CALL(vnode, write_stat)(vnode->mount->cookie, vnode->private_node, stat, statMask);
}
static status_t
common_path_read_stat(char *path, bool traverseLeafLink, struct stat *stat, bool kernel)
{
struct vnode *vnode;
status_t status;
FUNCTION(("common_path_read_stat: path '%s', stat %p,\n", path, stat));
status = path_to_vnode(path, traverseLeafLink, &vnode, kernel);
if (status < 0)
return status;
status = FS_CALL(vnode, read_stat)(vnode->mount->cookie, vnode->private_node, stat);
put_vnode(vnode);
return status;
}
static status_t
common_path_write_stat(char *path, bool traverseLeafLink, const struct stat *stat, int statMask, bool kernel)
{
struct vnode *vnode;
int status;
FUNCTION(("common_write_stat: path '%s', stat %p, stat_mask %d, kernel %d\n", path, stat, statMask, kernel));
status = fd_and_path_to_vnode(fd, path, traverseLeafLink, &vnode, kernel);
status = path_to_vnode(path, traverseLeafLink, &vnode, kernel);
if (status < 0)
return status;
@ -2746,26 +2785,16 @@ attr_read_stat(struct file_descriptor *descriptor, struct stat *stat)
static status_t
attr_write_stat(int fd, const struct stat *stat, int statMask, bool kernel)
attr_write_stat(struct file_descriptor *descriptor, const struct stat *stat, int statMask)
{
struct file_descriptor *descriptor;
struct vnode *vnode;
int status;
struct vnode *vnode = descriptor->u.vnode;
FUNCTION(("attr_write_stat: fd = %d, stat = %p, statMask %d, kernel %d\n", fd, stat, statMask, kernel));
FUNCTION(("attr_write_stat: stat = %p, statMask %d\n", stat, statMask));
descriptor = get_fd_and_vnode(fd, &vnode, kernel);
if (descriptor == NULL)
return B_FILE_ERROR;
if (!FS_CALL(vnode, write_attr_stat))
return EROFS;
if (FS_CALL(vnode, write_attr_stat))
status = FS_CALL(vnode, write_attr_stat)(vnode->mount->cookie, vnode->private_node, descriptor->cookie, stat, statMask);
else
status = EROFS;
put_vnode(vnode);
return status;
return FS_CALL(vnode, write_attr_stat)(vnode->mount->cookie, vnode->private_node, descriptor->cookie, stat, statMask);
}
@ -3514,36 +3543,22 @@ sys_access(const char *path, int mode)
int
sys_read_stat(const char *path, bool traverseLeafLink, struct stat *stat)
sys_read_path_stat(const char *path, bool traverseLeafLink, struct stat *stat)
{
char pathBuffer[SYS_MAX_PATH_LEN + 1];
struct vnode *vnode;
int status;
strlcpy(pathBuffer, path, SYS_MAX_PATH_LEN - 1);
FUNCTION(("sys_read_stat: path '%s', stat %p,\n", path, stat));
status = path_to_vnode(pathBuffer, traverseLeafLink, &vnode, true);
if (status < 0)
return status;
status = FS_CALL(vnode, read_stat)(vnode->mount->cookie, vnode->private_node, stat);
put_vnode(vnode);
return status;
return common_path_read_stat(pathBuffer, traverseLeafLink, stat, true);
}
int
sys_write_stat(int fd, const char *path, bool traverseLeafLink, struct stat *stat, int statMask)
sys_write_path_stat(const char *path, bool traverseLeafLink, const struct stat *stat, int statMask)
{
char pathBuffer[SYS_MAX_PATH_LEN + 1];
strlcpy(pathBuffer, path, SYS_MAX_PATH_LEN - 1);
if (fd == -1)
strlcpy(pathBuffer, path, SYS_MAX_PATH_LEN - 1);
return common_write_stat(fd, pathBuffer, traverseLeafLink, stat, statMask, true);
return common_path_write_stat(pathBuffer, traverseLeafLink, stat, statMask, true);
}
@ -3573,13 +3588,6 @@ sys_open_attr(int fd, const char *name, int openMode)
}
int
sys_write_attr_stat(int fd, const struct stat *stat, int statMask)
{
return attr_write_stat(fd, stat, statMask, true);
}
int
sys_remove_attr(int fd, const char *name)
{
@ -4015,58 +4023,38 @@ user_access(const char *userPath, int mode)
int
user_read_stat(const char *userPath, bool traverseLink, struct stat *userStat)
user_read_path_stat(const char *userPath, bool traverseLink, struct stat *userStat)
{
char path[SYS_MAX_PATH_LEN + 1];
struct vnode *vnode = NULL;
struct stat stat;
int rc;
int status;
if (!CHECK_USER_ADDRESS(userPath)
|| !CHECK_USER_ADDRESS(userStat))
|| !CHECK_USER_ADDRESS(userStat)
|| user_strlcpy(path, userPath, SYS_MAX_PATH_LEN) < B_OK)
return B_BAD_ADDRESS;
rc = user_strlcpy(path, userPath, SYS_MAX_PATH_LEN);
if (rc < 0)
return rc;
FUNCTION(("user_read_stat(path = %s, traverseLeafLink = %d)\n", path, traverseLink));
rc = path_to_vnode(path, traverseLink, &vnode, false);
if (rc < 0)
return rc;
if (FS_CALL(vnode, read_stat))
rc = FS_CALL(vnode, read_stat)(vnode->mount->cookie, vnode->private_node, &stat);
put_vnode(vnode);
if (rc < 0)
return rc;
status = common_path_read_stat(path, traverseLink, &stat, false);
if (status < 0)
return status;
return user_memcpy(userStat, &stat, sizeof(struct stat));
}
int
user_write_stat(int fd, const char *userPath, bool traverseLeafLink, struct stat *userStat, int statMask)
user_write_path_stat(const char *userPath, bool traverseLeafLink, const struct stat *userStat, int statMask)
{
char path[SYS_MAX_PATH_LEN + 1];
struct stat stat;
if (!CHECK_USER_ADDRESS(userStat))
if (!CHECK_USER_ADDRESS(userStat)
|| !CHECK_USER_ADDRESS(userPath)
|| user_strlcpy(path, userPath, SYS_MAX_PATH_LEN) < B_OK
|| user_memcpy(&stat, userStat, sizeof(struct stat)) < B_OK)
return B_BAD_ADDRESS;
if (fd == -1) {
if (!CHECK_USER_ADDRESS(userPath)
|| user_strlcpy(path, userPath, SYS_MAX_PATH_LEN) < B_OK)
return B_BAD_ADDRESS;
}
if (user_memcpy(&stat, userStat, sizeof(struct stat)) < B_OK)
return B_BAD_ADDRESS;
return common_write_stat(fd, path, traverseLeafLink, &stat, statMask, false);
return common_path_write_stat(path, traverseLeafLink, &stat, statMask, false);
}
@ -4112,19 +4100,6 @@ user_open_attr(int fd, const char *userName, int openMode)
}
int
user_write_attr_stat(int fd, const struct stat *userStat, int statMask)
{
struct stat stat;
if (!CHECK_USER_ADDRESS(userStat)
|| user_memcpy(&stat, userStat, sizeof(struct stat)) < B_OK)
return B_BAD_ADDRESS;
return attr_write_stat(fd, &stat, statMask, false);
}
int
user_remove_attr(int fd, const char *userName)
{

View File

@ -398,7 +398,6 @@ static int
recurse_directory(const char *path, const char *match)
{
/* ToDo: should just use opendir(), readdir(), ... */
struct stat stat;
int res = 0, dir;
int bufferSize = sizeof(struct dirent) + SYS_MAX_NAME_LEN + 1;
struct dirent *dirent;
@ -414,6 +413,7 @@ recurse_directory(const char *path, const char *match)
/* loop until we have a match or we run out of entries */
while (res <= 0) {
struct stat st;
char *newpath;
size_t slen = 0;
SHOW_FLOW(3, "scanning %s\n", path);
@ -429,7 +429,7 @@ recurse_directory(const char *path, const char *match)
strlcat(newpath, "/", slen);
strlcat(newpath, dirent->d_name, slen);
if ((res = sys_read_stat(newpath, true, &stat)) != B_NO_ERROR) {
if ((res = stat(newpath, &st)) != B_NO_ERROR) {
kfree(newpath);
break;
}
@ -439,7 +439,7 @@ recurse_directory(const char *path, const char *match)
* If we don't, then load the file and record it's details.
* If it matches our search path we'll return afterwards.
*/
if (S_ISREG(stat.st_mode)) {
if (S_ISREG(st.st_mode)) {
/* do we already know about this file?
* If we do res = 0 and we'll just carry on, if
* not, it's a new file so we need to read in the
@ -450,7 +450,7 @@ recurse_directory(const char *path, const char *match)
else
res = recurse_check_file(newpath, match);
} else if (S_ISDIR(stat.st_mode)) {
} else if (S_ISDIR(st.st_mode)) {
res = recurse_directory(newpath, match);
}
kfree(newpath);
@ -746,21 +746,21 @@ static void compose_path( char *path, module_iterator *iter, const char *name, b
static inline int
module_traverse_dir(module_iterator *iter)
{
int res;
struct stat stat;
struct stat st;
char buffer[SYS_MAX_NAME_LEN + sizeof(struct dirent)];
struct dirent *dirent = (struct dirent *)buffer;
char path[SYS_MAX_PATH_LEN];
int res;
/* If (*iter->cur_header) != NULL we have another module within
* the existing file to return, so just return.
* Otherwise, actually find the next file to read.
*/
if (iter->cur_header) {
if (*iter->cur_header == NULL)
unload_module_file(iter->cur_path);
else
return B_NO_ERROR;
if (*iter->cur_header != NULL)
return B_OK;
unload_module_file(iter->cur_path);
}
SHOW_FLOW( 3, "scanning %s\n", iter->cur_dir->name);
@ -772,8 +772,8 @@ module_traverse_dir(module_iterator *iter)
SHOW_FLOW(3, "got %s\n", dirent->d_name);
if (strcmp(dirent->d_name, ".") == 0 ||
strcmp(dirent->d_name, "..") == 0 )
if (strcmp(dirent->d_name, ".") == 0
|| strcmp(dirent->d_name, "..") == 0 )
return B_NO_ERROR;
compose_path(path, iter, dirent->d_name, true);
@ -784,10 +784,10 @@ module_traverse_dir(module_iterator *iter)
iter->cur_header = NULL;
iter->module_pos = 0;
if ((res = sys_read_stat(path, true, &stat)) != B_NO_ERROR)
if ((res = stat(path, &st)) != B_NO_ERROR)
return res;
if (S_ISREG(stat.st_mode)) {
if (S_ISREG(st.st_mode)) {
module_info **hdrs = NULL;
if ((hdrs = load_module_file(path)) != NULL) {
iter->cur_header = hdrs;
@ -797,7 +797,7 @@ module_traverse_dir(module_iterator *iter)
return EINVAL; /* not sure what we should return here */
}
if (S_ISDIR(stat.st_mode))
if (S_ISDIR(st.st_mode))
return module_enter_dir(iter, path);
SHOW_FLOW(3, "entry %s not a file nor a directory - ignored\n", dirent->d_name);

View File

@ -129,14 +129,17 @@ int syscall_dispatcher(unsigned long call_num, void *arg_buffer, uint64 *call_re
case SYSCALL_RENAME:
*call_ret = user_rename((const char *)arg0, (const char *)arg1);
break;
case SYSCALL_READ_STAT:
*call_ret = user_read_stat((const char *)arg0, (bool)arg1, (struct stat *)arg2);
case SYSCALL_READ_PATH_STAT:
*call_ret = user_read_path_stat((const char *)arg0, (bool)arg1, (struct stat *)arg2);
break;
case SYSCALL_READ_STAT_FD:
*call_ret = user_fstat((int)arg0, (struct stat*)arg1);
case SYSCALL_WRITE_PATH_STAT:
*call_ret = user_write_path_stat((const char *)arg0, (bool)arg1, (const struct stat *)arg2, (int)arg3);
break;
case SYSCALL_READ_STAT:
*call_ret = user_read_stat((int)arg0, (struct stat*)arg1);
break;
case SYSCALL_WRITE_STAT:
*call_ret = user_write_stat((int)arg0, (const char *)arg1, (bool)arg2, (struct stat *)arg3, (int)arg4);
*call_ret = user_write_stat((int)arg0, (const struct stat *)arg1, (int)arg2);
break;
case SYSCALL_ACCESS:
*call_ret = user_access((const char *)arg0, (int)arg1);
@ -150,9 +153,6 @@ int syscall_dispatcher(unsigned long call_num, void *arg_buffer, uint64 *call_re
case SYSCALL_OPEN_ATTR:
*call_ret = user_open_attr((int)arg0, (const char *)arg1, (int)arg2);
break;
case SYSCALL_WRITE_ATTR_STAT:
*call_ret = user_write_attr_stat((int)arg0, (const struct stat *)arg1, (int)arg2);
break;
case SYSCALL_REMOVE_ATTR:
*call_ret = user_remove_attr((int)arg0, (const char *)arg1);
break;

View File

@ -69,7 +69,7 @@ fs_stat_attr(int fd, const char *attribute, struct attr_info *attrInfo)
if (attr < 0)
return attr;
status = sys_fstat(attr, &stat);
status = sys_read_stat(attr, &stat);
if (status == B_OK) {
attrInfo->type = stat.st_type;
attrInfo->size = stat.st_size;

View File

@ -27,6 +27,8 @@
/* or make it more intelligent... it's really boring to maintain this one. */
SYSCALL0(sys_null, 0)
/* VFS calls */
SYSCALL4(sys_mount, 1)
SYSCALL1(sys_unmount, 2)
SYSCALL0(sys_sync, 3)
@ -53,40 +55,55 @@ SYSCALL3(sys_create, 11)
SYSCALL6(sys_create_entry_ref, 84)
SYSCALL1(sys_unlink, 12)
SYSCALL2(sys_rename, 13)
SYSCALL3(sys_read_stat, 14)
SYSCALL5(sys_write_stat, 15)
SYSCALL0(sys_system_time, 16)
SYSCALL2(sys_snooze, 17)
SYSCALL2(sys_access, 73);
SYSCALL2(sys_read_stat, 74)
SYSCALL3(sys_write_stat, 100)
SYSCALL3(sys_read_path_stat, 14)
SYSCALL4(sys_write_path_stat, 15)
SYSCALL2(sys_getcwd, 41)
SYSCALL2(sys_setcwd, 42)
SYSCALL1(sys_dup, 61)
SYSCALL2(sys_dup2, 62)
/* VFS attribute calls */
SYSCALL2(sys_open_attr_dir, 97)
SYSCALL4(sys_create_attr, 98)
SYSCALL3(sys_open_attr, 99)
SYSCALL2(sys_remove_attr, 101)
SYSCALL4(sys_rename_attr, 102)
/* semaphore calls */
SYSCALL2(sys_create_sem, 18)
SYSCALL1(sys_delete_sem, 19)
SYSCALL1(sys_acquire_sem, 20)
SYSCALL4(sys_acquire_sem_etc, 21)
SYSCALL1(sys_release_sem, 22)
SYSCALL3(sys_release_sem_etc, 23)
SYSCALL2(sys_sem_get_count, 57)
SYSCALL3(sys_get_sem_info, 58)
SYSCALL4(sys_get_next_sem_info, 59)
SYSCALL2(sys_set_sem_owner, 60)
/* 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 */
/* thread/team calls */
SYSCALL0(sys_get_current_thread_id, 24)
SYSCALL4(sys_spawn_thread, 35)
SYSCALL1(sys_kill_thread, 36)
SYSCALL1(sys_suspend_thread, 37)
SYSCALL1(sys_resume_thread, 38)
SYSCALL2(sys_snooze, 17)
SYSCALL4(send_data, 94)
SYSCALL3(receive_data, 95)
SYSCALL1(has_data, 96)
SYSCALL1(sys_exit, 25)
SYSCALL5(sys_create_team, 26)
SYSCALL2(sys_wait_on_thread, 27)
SYSCALL2(sys_wait_on_team, 28)
SYSCALL2(sys_get_thread_info, 88)
SYSCALL3(sys_get_next_thread_info, 89)
SYSCALL2(sys_get_team_info, 90)
SYSCALL2(sys_get_next_team_info, 91)
/* VM calls */
SYSCALL6(sys_vm_create_anonymous_region, 29)
SYSCALL6(sys_vm_clone_region, 30)
SYSCALL9(sys_vm_map_file, 31)
@ -95,8 +112,8 @@ SYSCALL2(sys_vm_get_region_info, 33)
SYSCALL1(sys_find_region_by_name, 34)
SYSCALL1(sys_kill_team, 39)
SYSCALL0(sys_get_current_team_id, 40)
SYSCALL2(sys_getcwd, 41)
SYSCALL2(sys_setcwd, 42)
/* port syscalls */
SYSCALL2(sys_port_create, 43)
SYSCALL1(sys_port_close, 44)
SYSCALL1(sys_port_delete, 45)
@ -111,12 +128,9 @@ SYSCALL7(sys_port_read_etc, 53)
SYSCALL2(sys_port_set_owner, 54)
SYSCALL4(sys_port_write, 55)
SYSCALL7(sys_port_write_etc, 56)
SYSCALL2(sys_sem_get_count, 57)
SYSCALL3(sys_get_sem_info, 58)
SYSCALL4(sys_get_next_sem_info, 59)
SYSCALL2(sys_set_sem_owner, 60)
SYSCALL1(sys_dup, 61)
SYSCALL2(sys_dup2, 62)
/* misc calls */
SYSCALL0(sys_system_time, 16)
//SYSCALL2(sys_team_get_table, 63)
SYSCALL2(sys_getrlimit, 64)
SYSCALL2(sys_setrlimit, 65)
@ -127,12 +141,6 @@ SYSCALL2(sys_atomic_set, 69)
SYSCALL3(sys_test_and_set, 70)
SYSCALL6(sys_sysctl, 71)
//SYSCALL3(sys_socket, 72)
SYSCALL2(sys_access, 73);
SYSCALL2(sys_fstat, 74)
SYSCALL3(sys_setenv, 79)
SYSCALL2(sys_getenv, 80)
SYSCALL2(sys_get_thread_info, 88)
SYSCALL3(sys_get_next_thread_info, 89)
SYSCALL2(sys_get_team_info, 90)
SYSCALL2(sys_get_next_team_info, 91)

View File

@ -24,7 +24,7 @@ chmod(const char *path, mode_t mode)
status_t status;
stat.st_mode = mode;
status = sys_write_stat(-1, path, true, &stat, FS_WRITE_STAT_MODE);
status = sys_write_path_stat(path, true, &stat, FS_WRITE_STAT_MODE);
RETURN_AND_SET_ERRNO(status);
}
@ -37,7 +37,7 @@ fchmod(int fd, mode_t mode)
status_t status;
stat.st_mode = mode;
status = sys_write_stat(fd, NULL, true, &stat, FS_WRITE_STAT_MODE);
status = sys_write_stat(fd, &stat, FS_WRITE_STAT_MODE);
RETURN_AND_SET_ERRNO(status);
}

View File

@ -20,7 +20,7 @@
int
stat(const char *path, struct stat *stat)
{
int status = sys_read_stat(path, true, stat);
int status = sys_read_path_stat(path, true, stat);
RETURN_AND_SET_ERRNO(status);
}
@ -29,7 +29,7 @@ stat(const char *path, struct stat *stat)
int
lstat(const char *path, struct stat *stat)
{
int status = sys_read_stat(path, false, stat);
int status = sys_read_path_stat(path, false, stat);
RETURN_AND_SET_ERRNO(status);
}
@ -38,7 +38,7 @@ lstat(const char *path, struct stat *stat)
int
fstat(int fd, struct stat *stat)
{
int status = sys_fstat(fd, stat);
int status = sys_read_stat(fd, stat);
RETURN_AND_SET_ERRNO(status);
}

View File

@ -25,7 +25,7 @@ chown(const char *path, uid_t owner, gid_t group)
stat.st_uid = owner;
stat.st_gid = group;
status = sys_write_stat(-1, path, true, &stat, FS_WRITE_STAT_UID | FS_WRITE_STAT_GID);
status = sys_write_path_stat(path, true, &stat, FS_WRITE_STAT_UID | FS_WRITE_STAT_GID);
RETURN_AND_SET_ERRNO(status);
}
@ -39,7 +39,7 @@ lchown(const char *path, uid_t owner, gid_t group)
stat.st_uid = owner;
stat.st_gid = group;
status = sys_write_stat(-1, path, false, &stat, FS_WRITE_STAT_UID | FS_WRITE_STAT_GID);
status = sys_write_path_stat(path, false, &stat, FS_WRITE_STAT_UID | FS_WRITE_STAT_GID);
RETURN_AND_SET_ERRNO(status);
}
@ -53,7 +53,7 @@ fchown(int fd, uid_t owner, gid_t group)
stat.st_uid = owner;
stat.st_gid = group;
status = sys_write_stat(fd, NULL, true, &stat, FS_WRITE_STAT_UID | FS_WRITE_STAT_GID);
status = sys_write_stat(fd, &stat, FS_WRITE_STAT_UID | FS_WRITE_STAT_GID);
RETURN_AND_SET_ERRNO(status);
}

View File

@ -0,0 +1,50 @@
/*
** Copyright 2002, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
#include <unistd.h>
#include <syscalls.h>
#include <string.h>
#include <errno.h>
// ToDo: implement the process ID functions for real!
pid_t
getpgrp(void)
{
return 0;
}
pid_t
getpid(void)
{
return 0;
}
pid_t
getppid(void)
{
return 0;
}
int
setpgid(pid_t pid, pid_t pgid)
{
return 0;
}
pid_t
setsid(void)
{
return EPERM;
}

View File

@ -24,7 +24,7 @@ truncate(const char *path, off_t newSize)
status_t status;
stat.st_size = newSize;
status = sys_write_stat(-1, path, true, &stat, FS_WRITE_STAT_SIZE);
status = sys_write_path_stat(path, true, &stat, FS_WRITE_STAT_SIZE);
RETURN_AND_SET_ERRNO(status);
}
@ -37,7 +37,7 @@ ftruncate(int fd, off_t newSize)
status_t status;
stat.st_size = newSize;
status = sys_write_stat(fd, NULL, true, &stat, FS_WRITE_STAT_SIZE);
status = sys_write_stat(fd, &stat, FS_WRITE_STAT_SIZE);
RETURN_AND_SET_ERRNO(status);
}