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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
+62
-11
@@ -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;
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
#include "bootfs.h"
|
||||
|
||||
|
||||
#define BOOTFS_TRACE 1
|
||||
#define BOOTFS_TRACE 0
|
||||
|
||||
#if BOOTFS_TRACE
|
||||
#define TRACE(x) dprintf x
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "rootfs.h"
|
||||
|
||||
|
||||
#define ROOTFS_TRACE 1
|
||||
#define ROOTFS_TRACE 0
|
||||
|
||||
#if ROOTFS_TRACE
|
||||
#define TRACE(x) dprintf x
|
||||
|
||||
+75
-100
@@ -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)
|
||||
{
|
||||
|
||||
+16
-16
@@ -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);
|
||||
@@ -783,11 +783,11 @@ 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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user