2002-07-09 16:24:59 +04:00
|
|
|
/*
|
|
|
|
** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
|
|
|
|
** Distributed under the terms of the NewOS License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _KERNEL_VFS_H
|
|
|
|
#define _KERNEL_VFS_H
|
|
|
|
|
|
|
|
#include <kernel.h>
|
|
|
|
#include <sys/stat.h>
|
2002-10-29 06:49:57 +03:00
|
|
|
#include <sys/select.h>
|
|
|
|
#include <signal.h>
|
2002-07-09 16:24:59 +04:00
|
|
|
#include <dirent.h>
|
2002-08-13 17:51:36 +04:00
|
|
|
#include <fs_interface.h>
|
2003-01-18 17:04:22 +03:00
|
|
|
#include <lock.h>
|
|
|
|
#include <list.h>
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
#define DEFAULT_FD_TABLE_SIZE 128
|
|
|
|
#define MAX_FD_TABLE_SIZE 2048
|
2003-01-18 17:04:22 +03:00
|
|
|
#define MAX_NODE_MONITORS 4096
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
#include <vfs_types.h>
|
|
|
|
|
2003-01-18 17:04:22 +03:00
|
|
|
|
2003-05-03 20:03:26 +04:00
|
|
|
struct kernel_args;
|
2003-01-18 17:04:22 +03:00
|
|
|
struct file_descriptor;
|
|
|
|
struct selectsync;
|
|
|
|
struct pollfd;
|
|
|
|
|
|
|
|
|
|
|
|
/** The I/O context of a process/team, holds the fd array among others */
|
|
|
|
typedef struct io_context {
|
|
|
|
struct vnode *cwd;
|
|
|
|
mutex io_mutex;
|
|
|
|
uint32 table_size;
|
|
|
|
uint32 num_used_fds;
|
|
|
|
struct file_descriptor **fds;
|
|
|
|
struct list node_monitors;
|
|
|
|
uint32 num_monitors;
|
|
|
|
uint32 max_monitors;
|
|
|
|
} io_context;
|
|
|
|
|
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
/* macro to allocate a iovec array on the stack */
|
|
|
|
#define IOVECS(name, size) \
|
|
|
|
uint8 _##name[sizeof(iovecs) + (size)*sizeof(iovec)]; \
|
|
|
|
iovecs *name = (iovecs *)_##name
|
|
|
|
|
2002-07-28 22:36:23 +04:00
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2003-05-03 20:03:26 +04:00
|
|
|
int vfs_init(struct kernel_args *ka);
|
2002-07-09 16:24:59 +04:00
|
|
|
int vfs_bootstrap_all_filesystems(void);
|
2002-09-25 20:36:38 +04:00
|
|
|
int vfs_register_filesystem(const char *name, struct fs_ops *calls);
|
2002-07-09 16:24:59 +04:00
|
|
|
void *vfs_new_io_context(void *parent_ioctx);
|
|
|
|
int vfs_free_io_context(void *ioctx);
|
|
|
|
int vfs_test(void);
|
|
|
|
|
|
|
|
struct rlimit;
|
|
|
|
int vfs_getrlimit(int resource, struct rlimit * rlp);
|
|
|
|
int vfs_setrlimit(int resource, const struct rlimit * rlp);
|
|
|
|
|
2002-10-29 06:49:57 +03:00
|
|
|
// ToDo: for now; this prototype should be in os/drivers/Drivers.h
|
|
|
|
// or similar places.
|
2002-11-03 06:14:05 +03:00
|
|
|
extern status_t notify_select_event(struct selectsync *sync, uint32 ref, uint8 event);
|
2002-10-29 06:49:57 +03:00
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
/* calls needed by fs internals */
|
2003-02-21 16:44:53 +03:00
|
|
|
extern status_t vfs_new_vnode(mount_id mountID, vnode_id vnodeID, fs_vnode privateNode);
|
|
|
|
extern status_t vfs_get_vnode(mount_id mountID, vnode_id vnodeID, fs_vnode *_privateNode);
|
|
|
|
extern status_t vfs_put_vnode(mount_id mountID, vnode_id vnodeID);
|
|
|
|
extern status_t vfs_remove_vnode(mount_id mountID, vnode_id vnodeID);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
/* calls needed by the VM for paging */
|
|
|
|
int vfs_get_vnode_from_fd(int fd, bool kernel, void **vnode);
|
|
|
|
int vfs_get_vnode_from_path(const char *path, bool kernel, void **vnode);
|
|
|
|
int vfs_put_vnode_ptr(void *vnode);
|
|
|
|
void vfs_vnode_acquire_ref(void *vnode);
|
|
|
|
void vfs_vnode_release_ref(void *vnode);
|
2002-07-14 09:08:26 +04:00
|
|
|
ssize_t vfs_can_page(void *vnode);
|
|
|
|
ssize_t vfs_read_page(void *vnode, iovecs *vecs, off_t pos);
|
|
|
|
ssize_t vfs_write_page(void *vnode, iovecs *vecs, off_t pos);
|
2002-07-09 16:24:59 +04:00
|
|
|
void *vfs_get_cache_ptr(void *vnode);
|
|
|
|
int vfs_set_cache_ptr(void *vnode, void *cache);
|
|
|
|
|
|
|
|
/* calls kernel code should make for file I/O */
|
|
|
|
int sys_mount(const char *path, const char *device, const char *fs_name, void *args);
|
|
|
|
int sys_unmount(const char *path);
|
|
|
|
int sys_sync(void);
|
2002-07-23 18:05:18 +04:00
|
|
|
int sys_open_entry_ref(dev_t device, ino_t inode, const char *name, int omode);
|
2002-07-14 09:08:26 +04:00
|
|
|
int sys_open(const char *path, int omode);
|
2002-07-23 18:05:18 +04:00
|
|
|
int sys_open_dir_node_ref(dev_t device, ino_t inode);
|
|
|
|
int sys_open_dir_entry_ref(dev_t device, ino_t inode, const char *name);
|
2002-07-14 09:08:26 +04:00
|
|
|
int sys_open_dir(const char *path);
|
2002-07-09 16:24:59 +04:00
|
|
|
int sys_fsync(int fd);
|
2002-07-17 12:01:40 +04:00
|
|
|
off_t sys_seek(int fd, off_t pos, int seekType);
|
2002-07-23 18:05:18 +04:00
|
|
|
int sys_create_entry_ref(dev_t device, ino_t inode, const char *uname, int omode, int perms);
|
2002-07-14 09:08:26 +04:00
|
|
|
int sys_create(const char *path, int omode, int perms);
|
2002-07-23 18:05:18 +04:00
|
|
|
int sys_create_dir_entry_ref(dev_t device, ino_t inode, const char *name, int perms);
|
2002-07-14 09:08:26 +04:00
|
|
|
int sys_create_dir(const char *path, int perms);
|
2002-08-14 00:39:25 +04:00
|
|
|
int sys_remove_dir(const char *path);
|
2002-08-03 06:03:27 +04:00
|
|
|
int sys_read_link(const char *path, char *buffer, size_t bufferSize);
|
2002-08-05 21:22:19 +04:00
|
|
|
int sys_write_link(const char *path, const char *toPath);
|
2002-08-05 09:31:32 +04:00
|
|
|
int sys_create_symlink(const char *path, const char *toPath, int mode);
|
2002-08-14 00:39:25 +04:00
|
|
|
int sys_create_link(const char *path, const char *toPath);
|
2002-07-09 16:24:59 +04:00
|
|
|
int sys_unlink(const char *path);
|
|
|
|
int sys_rename(const char *oldpath, const char *newpath);
|
2002-08-13 17:51:36 +04:00
|
|
|
int sys_access(const char *path, int mode);
|
2002-10-17 07:04:19 +04:00
|
|
|
int sys_read_path_stat(const char *path, bool traverseLink, struct stat *stat);
|
|
|
|
int sys_write_path_stat(const char *path, bool traverseLink, const struct stat *stat, int statMask);
|
2002-10-29 06:49:57 +03:00
|
|
|
int sys_select(int numfds, fd_set *readSet, fd_set *writeSet, fd_set *errorSet,
|
2002-11-03 06:14:05 +03:00
|
|
|
bigtime_t timeout, const sigset_t *sigMask);
|
2002-10-29 06:49:57 +03:00
|
|
|
int sys_poll(struct pollfd *fds, int numfds, bigtime_t timeout);
|
2002-10-08 07:19:57 +04:00
|
|
|
int sys_open_attr_dir(int fd, const char *path);
|
|
|
|
int sys_create_attr(int fd, const char *name, uint32 type, int openMode);
|
|
|
|
int sys_open_attr(int fd, const char *name, int openMode);
|
|
|
|
int sys_remove_attr(int fd, const char *name);
|
|
|
|
int sys_rename_attr(int fromFile, const char *fromName, int toFile, const char *toName);
|
2002-10-17 22:52:04 +04:00
|
|
|
int sys_open_index_dir(dev_t device);
|
|
|
|
int sys_create_index(dev_t device, const char *name, uint32 type, uint32 flags);
|
|
|
|
int sys_read_index_stat(dev_t device, const char *name, struct stat *stat);
|
|
|
|
int sys_remove_index(dev_t device, const char *name);
|
2002-08-10 00:20:28 +04:00
|
|
|
int sys_getcwd(char *buffer, size_t size);
|
|
|
|
int sys_setcwd(int fd, const char *path);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
/* calls the syscall dispatcher should use for user file I/O */
|
|
|
|
int user_mount(const char *path, const char *device, const char *fs_name, void *args);
|
|
|
|
int user_unmount(const char *path);
|
|
|
|
int user_sync(void);
|
2002-07-23 18:05:18 +04:00
|
|
|
int user_open_entry_ref(dev_t device, ino_t inode, const char *name, int omode);
|
2002-07-14 09:08:26 +04:00
|
|
|
int user_open(const char *path, int omode);
|
2002-07-23 18:05:18 +04:00
|
|
|
int user_open_dir_node_ref(dev_t device, ino_t inode);
|
|
|
|
int user_open_dir_entry_ref(dev_t device, ino_t inode, const char *uname);
|
2002-07-14 09:08:26 +04:00
|
|
|
int user_open_dir(const char *path);
|
2002-07-09 16:24:59 +04:00
|
|
|
int user_fsync(int fd);
|
2002-07-17 12:01:40 +04:00
|
|
|
off_t user_seek(int fd, off_t pos, int seekType);
|
2002-07-23 18:05:18 +04:00
|
|
|
int user_create_entry_ref(dev_t device, ino_t inode, const char *uname, int omode, int perms);
|
2002-07-14 09:08:26 +04:00
|
|
|
int user_create(const char *path, int omode, int perms);
|
2002-07-23 18:05:18 +04:00
|
|
|
int user_create_dir_entry_ref(dev_t device, ino_t inode, const char *name, int perms);
|
2002-07-14 09:08:26 +04:00
|
|
|
int user_create_dir(const char *path, int perms);
|
2002-08-14 00:39:25 +04:00
|
|
|
int user_remove_dir(const char *path);
|
2002-08-03 06:03:27 +04:00
|
|
|
int user_read_link(const char *path, char *buffer, size_t bufferSize);
|
2002-08-05 21:22:19 +04:00
|
|
|
int user_write_link(const char *path, const char *toPath);
|
2002-08-05 09:31:32 +04:00
|
|
|
int user_create_symlink(const char *path, const char *toPath, int mode);
|
2002-08-14 00:39:25 +04:00
|
|
|
int user_create_link(const char *path, const char *toPath);
|
2002-07-09 16:24:59 +04:00
|
|
|
int user_unlink(const char *path);
|
|
|
|
int user_rename(const char *oldpath, const char *newpath);
|
2002-08-13 17:51:36 +04:00
|
|
|
int user_access(const char *path, int mode);
|
2002-10-17 07:04:19 +04:00
|
|
|
int user_read_path_stat(const char *path, bool traverseLink, struct stat *stat);
|
|
|
|
int user_write_path_stat(const char *path, bool traverseLink, const struct stat *stat, int statMask);
|
2002-10-29 06:49:57 +03:00
|
|
|
int user_select(int numfds, fd_set *readSet, fd_set *writeSet, fd_set *errorSet,
|
2002-11-03 06:14:05 +03:00
|
|
|
bigtime_t timeout, const sigset_t *sigMask);
|
2002-10-29 06:49:57 +03:00
|
|
|
int user_poll(struct pollfd *fds, int numfds, bigtime_t timeout);
|
2002-10-08 07:19:57 +04:00
|
|
|
int user_open_attr_dir(int fd, const char *path);
|
|
|
|
int user_create_attr(int fd, const char *name, uint32 type, int openMode);
|
|
|
|
int user_open_attr(int fd, const char *name, int openMode);
|
|
|
|
int user_remove_attr(int fd, const char *name);
|
|
|
|
int user_rename_attr(int fromFile, const char *fromName, int toFile, const char *toName);
|
2002-10-17 22:52:04 +04:00
|
|
|
int user_open_index_dir(dev_t device);
|
|
|
|
int user_create_index(dev_t device, const char *name, uint32 type, uint32 flags);
|
|
|
|
int user_read_index_stat(dev_t device, const char *name, struct stat *stat);
|
|
|
|
int user_remove_index(dev_t device, const char *name);
|
2002-08-10 00:20:28 +04:00
|
|
|
int user_getcwd(char *buffer, size_t size);
|
|
|
|
int user_setcwd(int fd, const char *path);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
/* fd kernel prototypes (implementation located in fd.c) */
|
2002-08-09 20:57:25 +04:00
|
|
|
extern ssize_t sys_read(int fd, off_t pos, void *buffer, size_t bufferSize);
|
|
|
|
extern ssize_t sys_write(int fd, off_t pos, const void *buffer, size_t bufferSize);
|
2002-07-09 16:24:59 +04:00
|
|
|
extern int sys_ioctl(int fd, ulong cmd, void *data, size_t length);
|
2002-07-11 01:46:34 +04:00
|
|
|
extern ssize_t sys_read_dir(int fd, struct dirent *buffer, size_t bufferSize, uint32 maxCount);
|
2002-07-09 16:24:59 +04:00
|
|
|
extern status_t sys_rewind_dir(int fd);
|
2002-10-17 07:04:19 +04:00
|
|
|
extern int sys_read_stat(int fd, struct stat *stat);
|
|
|
|
extern int sys_write_stat(int fd, const struct stat *stat, int statMask);
|
2002-07-09 16:24:59 +04:00
|
|
|
extern int sys_close(int fd);
|
2002-07-20 04:16:12 +04:00
|
|
|
extern int sys_dup(int fd);
|
|
|
|
extern int sys_dup2(int ofd, int nfd);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
/* fd user prototypes (implementation located in fd.c) */
|
2002-08-09 20:57:25 +04:00
|
|
|
extern ssize_t user_read(int fd, off_t pos, void *buffer, size_t bufferSize);
|
|
|
|
extern ssize_t user_write(int fd, off_t pos, const void *buffer, size_t bufferSize);
|
2002-07-09 16:24:59 +04:00
|
|
|
extern int user_ioctl(int fd, ulong cmd, void *data, size_t length);
|
2002-07-11 01:46:34 +04:00
|
|
|
extern ssize_t user_read_dir(int fd, struct dirent *buffer, size_t bufferSize, uint32 maxCount);
|
2002-07-09 16:24:59 +04:00
|
|
|
extern status_t user_rewind_dir(int fd);
|
2002-10-17 07:04:19 +04:00
|
|
|
extern int user_read_stat(int fd, struct stat *stat);
|
|
|
|
extern int user_write_stat(int fd, const struct stat *stat, int statMask);
|
2002-07-09 16:24:59 +04:00
|
|
|
extern int user_close(int fd);
|
2002-07-20 04:16:12 +04:00
|
|
|
extern int user_dup(int fd);
|
|
|
|
extern int user_dup2(int ofd, int nfd);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
/* vfs entry points... */
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-07-20 04:16:12 +04:00
|
|
|
#endif /* _KERNEL_VFS_H */
|