2002-07-09 16:24:59 +04:00
|
|
|
/*
|
2008-02-03 18:37:31 +03:00
|
|
|
* Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
|
2005-02-02 09:20:00 +03:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*
|
|
|
|
* Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
|
|
|
|
* Distributed under the terms of the NewOS License.
|
|
|
|
*/
|
2002-07-09 16:24:59 +04:00
|
|
|
#ifndef _KERNEL_VFS_H
|
|
|
|
#define _KERNEL_VFS_H
|
|
|
|
|
2006-03-28 05:13:12 +04:00
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
#include <kernel.h>
|
2003-01-18 17:04:22 +03:00
|
|
|
#include <lock.h>
|
2003-09-09 06:31:25 +04:00
|
|
|
#include <util/list.h>
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2006-03-28 05:13:12 +04:00
|
|
|
#include <fs_interface.h>
|
|
|
|
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
|
|
|
|
|
2007-06-21 23:50:57 +04:00
|
|
|
#define DEFAULT_FD_TABLE_SIZE 256
|
2007-02-19 18:43:20 +03:00
|
|
|
#define MAX_FD_TABLE_SIZE 8192
|
2007-06-21 23:50:57 +04:00
|
|
|
#define DEFAULT_NODE_MONITORS 4096
|
2007-02-19 18:43:20 +03:00
|
|
|
#define MAX_NODE_MONITORS 65536
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2007-11-12 23:54:17 +03:00
|
|
|
#define B_UNMOUNT_BUSY_PARTITION 0x80000000
|
|
|
|
|
2003-05-03 20:03:26 +04:00
|
|
|
struct kernel_args;
|
2007-07-18 04:16:27 +04:00
|
|
|
struct vm_cache;
|
2003-01-18 17:04:22 +03:00
|
|
|
struct file_descriptor;
|
|
|
|
struct selectsync;
|
2007-10-01 05:37:28 +04:00
|
|
|
struct select_info;
|
2003-01-18 17:04:22 +03:00
|
|
|
struct pollfd;
|
2007-09-26 04:20:23 +04:00
|
|
|
struct vnode;
|
2003-01-18 17:04:22 +03:00
|
|
|
|
|
|
|
|
|
|
|
/** 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;
|
2007-10-01 05:37:28 +04:00
|
|
|
struct select_info **select_infos;
|
2005-10-06 13:02:59 +04:00
|
|
|
uint8 *fds_close_on_exec;
|
2003-01-18 17:04:22 +03:00
|
|
|
struct list node_monitors;
|
|
|
|
uint32 num_monitors;
|
|
|
|
uint32 max_monitors;
|
|
|
|
} io_context;
|
|
|
|
|
2006-01-17 04:29:18 +03:00
|
|
|
struct fd_info {
|
|
|
|
int number;
|
|
|
|
int32 open_mode;
|
|
|
|
dev_t device;
|
|
|
|
ino_t node;
|
|
|
|
};
|
2003-01-18 17:04:22 +03:00
|
|
|
|
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
|
|
|
|
|
2004-11-15 23:00:49 +03:00
|
|
|
status_t vfs_init(struct kernel_args *args);
|
2004-05-06 05:20:41 +04:00
|
|
|
status_t vfs_bootstrap_file_systems(void);
|
2007-01-12 21:09:15 +03:00
|
|
|
void vfs_mount_boot_file_system(struct kernel_args *args);
|
2004-10-07 18:46:32 +04:00
|
|
|
void vfs_exec_io_context(void *context);
|
|
|
|
void *vfs_new_io_context(void *parentContext);
|
2005-03-18 04:24:11 +03:00
|
|
|
status_t vfs_free_io_context(void *context);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
struct rlimit;
|
|
|
|
int vfs_getrlimit(int resource, struct rlimit * rlp);
|
|
|
|
int vfs_setrlimit(int resource, const struct rlimit * rlp);
|
|
|
|
|
2004-09-07 01:52:28 +04:00
|
|
|
/* calls needed by the VM for paging and by the file cache */
|
2007-10-06 19:33:12 +04:00
|
|
|
int vfs_get_vnode_from_fd(int fd, bool kernel, struct vnode **_vnode);
|
|
|
|
status_t vfs_get_vnode_from_path(const char *path, bool kernel,
|
|
|
|
struct vnode **_vnode);
|
2007-10-08 20:06:32 +04:00
|
|
|
status_t vfs_get_vnode(dev_t mountID, ino_t vnodeID, bool canWait,
|
|
|
|
struct vnode **_vnode);
|
2007-06-21 23:50:57 +04:00
|
|
|
status_t vfs_entry_ref_to_vnode(dev_t mountID, ino_t directoryID,
|
2007-10-06 19:33:12 +04:00
|
|
|
const char *name, struct vnode **_vnode);
|
|
|
|
void vfs_vnode_to_node_ref(struct vnode *vnode, dev_t *_mountID,
|
|
|
|
ino_t *_vnodeID);
|
2005-10-06 13:26:27 +04:00
|
|
|
|
2007-10-06 19:33:12 +04:00
|
|
|
status_t vfs_lookup_vnode(dev_t mountID, ino_t vnodeID, struct vnode **_vnode);
|
|
|
|
void vfs_put_vnode(struct vnode *vnode);
|
|
|
|
void vfs_acquire_vnode(struct vnode *vnode);
|
2004-09-07 01:52:28 +04:00
|
|
|
status_t vfs_get_cookie_from_fd(int fd, void **_cookie);
|
2007-10-06 19:33:12 +04:00
|
|
|
bool vfs_can_page(struct vnode *vnode, void *cookie);
|
|
|
|
status_t vfs_read_pages(struct vnode *vnode, void *cookie, off_t pos,
|
* Extracted file_map API out of the file cache - it's now an optional service
that can be used by file systems.
* Changed the way the file cache works: instead of reading/writing to the
underlying device directly, it can now be used for any data source, ie.
also network file systems.
* As a result, the former pages_io() moved to the VFS layer, and can now be
called by a file system via {read|write}_file_io_vec_pages() (naming
suggestions are always welcomed :-)). It now gets an FD, and uses that to
communicate with the device (via its fs_{read|write}_pages() hooks).
* The file_cache_{read|write}() functions must now be called without holding
an I/O relevant file system lock. That allows the file cache to prepare the
pages without colliding with the page writer, IOW the "mayBlock" flag can
go into the attic again (yay!).
* This also results in a much better performance when the system does I/O and
is low on memory, as the page writer can now finally write back some pages,
and that even without maxing out the CPU :)
* The API changes put slightly more burden on the fs_{read|write}_pages()
hooks, but in combination with the file_map it's still pretty straight
forward. It just will have to dispatch the call to the underlying device
directly, usually it will just call its fs_{read|write}_pages() hooks
via the above mentioned calls.
* Ported BFS and FAT to the new API, the latter has not been tested, though.
* Also ported the API changes to the fs_shell. I also completely removed its
file cache level page handling - the downside is that device access is no
longer cached (ie. depends on the host OS now), the upside is that the code
is greatly simplified.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22886 a95241bf-73f2-0310-859d-f6bbb57e9c96
2007-11-11 00:19:52 +03:00
|
|
|
const iovec *vecs, size_t count, size_t *_numBytes, bool fsReenter);
|
2007-10-06 19:33:12 +04:00
|
|
|
status_t vfs_write_pages(struct vnode *vnode, void *cookie, off_t pos,
|
* Extracted file_map API out of the file cache - it's now an optional service
that can be used by file systems.
* Changed the way the file cache works: instead of reading/writing to the
underlying device directly, it can now be used for any data source, ie.
also network file systems.
* As a result, the former pages_io() moved to the VFS layer, and can now be
called by a file system via {read|write}_file_io_vec_pages() (naming
suggestions are always welcomed :-)). It now gets an FD, and uses that to
communicate with the device (via its fs_{read|write}_pages() hooks).
* The file_cache_{read|write}() functions must now be called without holding
an I/O relevant file system lock. That allows the file cache to prepare the
pages without colliding with the page writer, IOW the "mayBlock" flag can
go into the attic again (yay!).
* This also results in a much better performance when the system does I/O and
is low on memory, as the page writer can now finally write back some pages,
and that even without maxing out the CPU :)
* The API changes put slightly more burden on the fs_{read|write}_pages()
hooks, but in combination with the file_map it's still pretty straight
forward. It just will have to dispatch the call to the underlying device
directly, usually it will just call its fs_{read|write}_pages() hooks
via the above mentioned calls.
* Ported BFS and FAT to the new API, the latter has not been tested, though.
* Also ported the API changes to the fs_shell. I also completely removed its
file cache level page handling - the downside is that device access is no
longer cached (ie. depends on the host OS now), the upside is that the code
is greatly simplified.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22886 a95241bf-73f2-0310-859d-f6bbb57e9c96
2007-11-11 00:19:52 +03:00
|
|
|
const iovec *vecs, size_t count, size_t *_numBytes, bool fsReenter);
|
2007-10-06 19:33:12 +04:00
|
|
|
status_t vfs_get_vnode_cache(struct vnode *vnode, struct vm_cache **_cache,
|
2007-10-04 16:45:15 +04:00
|
|
|
bool allocate);
|
2007-10-06 19:33:12 +04:00
|
|
|
status_t vfs_get_file_map(struct vnode *vnode, off_t offset, size_t size,
|
2005-10-06 13:26:27 +04:00
|
|
|
struct file_io_vec *vecs, size_t *_count);
|
2007-06-21 23:50:57 +04:00
|
|
|
status_t vfs_get_fs_node_from_path(dev_t mountID, const char *path,
|
2005-10-06 13:26:27 +04:00
|
|
|
bool kernel, void **_node);
|
2007-10-06 19:33:12 +04:00
|
|
|
status_t vfs_stat_vnode(struct vnode *vnode, struct stat *stat);
|
|
|
|
status_t vfs_get_vnode_name(struct vnode *vnode, char *name, size_t nameSize);
|
2008-02-27 19:39:32 +03:00
|
|
|
status_t vfs_entry_ref_to_path(dev_t device, ino_t inode, const char *leaf,
|
|
|
|
char *path, size_t pathLength);
|
2007-06-21 23:50:57 +04:00
|
|
|
status_t vfs_get_cwd(dev_t *_mountID, ino_t *_vnodeID);
|
2006-06-02 18:16:13 +04:00
|
|
|
void vfs_unlock_vnode_if_locked(struct file_descriptor *descriptor);
|
2007-11-12 23:54:17 +03:00
|
|
|
status_t vfs_unmount(dev_t mountID, uint32 flags);
|
2007-06-21 23:50:57 +04:00
|
|
|
status_t vfs_disconnect_vnode(dev_t mountID, ino_t vnodeID);
|
2006-03-06 19:18:52 +03:00
|
|
|
void vfs_free_unused_vnodes(int32 level);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
2003-09-08 08:01:07 +04:00
|
|
|
/* special module convenience call */
|
2005-10-06 13:26:27 +04:00
|
|
|
status_t vfs_get_module_path(const char *basePath, const char *moduleName,
|
|
|
|
char *pathBuffer, size_t bufferSize);
|
2003-09-08 08:01:07 +04:00
|
|
|
|
2004-10-29 02:31:43 +04:00
|
|
|
/* service call for whoever needs a normalized path */
|
|
|
|
status_t vfs_normalize_path(const char *path, char *buffer, size_t bufferSize,
|
|
|
|
bool kernel);
|
|
|
|
|
2005-01-30 19:11:46 +03:00
|
|
|
/* service call for the node monitor */
|
2007-06-21 23:50:57 +04:00
|
|
|
status_t resolve_mount_point_to_volume_root(dev_t mountID, ino_t nodeID,
|
|
|
|
dev_t *resolvedMountID, ino_t *resolvedNodeID);
|
2005-01-30 19:11:46 +03:00
|
|
|
|
2002-07-09 16:24:59 +04:00
|
|
|
/* calls the syscall dispatcher should use for user file I/O */
|
2005-10-17 18:01:04 +04:00
|
|
|
dev_t _user_mount(const char *path, const char *device, const char *fs_name,
|
2006-02-20 21:04:27 +03:00
|
|
|
uint32 flags, const char *args, size_t argsLength);
|
2004-11-30 01:42:01 +03:00
|
|
|
status_t _user_unmount(const char *path, uint32 flags);
|
2003-09-04 08:18:48 +04:00
|
|
|
status_t _user_read_fs_info(dev_t device, struct fs_info *info);
|
|
|
|
status_t _user_write_fs_info(dev_t device, const struct fs_info *info, int mask);
|
2004-07-07 20:07:25 +04:00
|
|
|
dev_t _user_next_device(int32 *_cookie);
|
2004-06-15 19:18:04 +04:00
|
|
|
status_t _user_sync(void);
|
2006-01-17 04:29:18 +03:00
|
|
|
status_t _user_get_next_fd_info(team_id team, uint32 *cookie, struct fd_info *info,
|
|
|
|
size_t infoSize);
|
2004-08-29 00:38:39 +04:00
|
|
|
status_t _user_entry_ref_to_path(dev_t device, ino_t inode, const char *leaf,
|
|
|
|
char *userPath, size_t pathLength);
|
2008-02-08 06:06:14 +03:00
|
|
|
status_t _user_normalize_path(const char* userPath, bool traverseLink,
|
|
|
|
char* buffer);
|
2005-02-02 09:20:00 +03:00
|
|
|
int _user_open_entry_ref(dev_t device, ino_t inode, const char *name, int openMode, int perms);
|
|
|
|
int _user_open(int fd, const char *path, int openMode, int perms);
|
2004-06-15 19:18:04 +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);
|
2004-08-29 00:38:39 +04:00
|
|
|
int _user_open_dir(int fd, const char *path);
|
|
|
|
int _user_open_parent_dir(int fd, char *name, size_t nameLength);
|
2004-10-05 17:28:48 +04:00
|
|
|
status_t _user_fcntl(int fd, int op, uint32 argument);
|
2004-06-15 19:18:04 +04:00
|
|
|
status_t _user_fsync(int fd);
|
2008-02-03 18:37:31 +03:00
|
|
|
status_t _user_flock(int fd, int op);
|
2004-08-29 00:38:39 +04:00
|
|
|
status_t _user_read_stat(int fd, const char *path, bool traverseLink,
|
|
|
|
struct stat *stat, size_t statSize);
|
|
|
|
status_t _user_write_stat(int fd, const char *path, bool traverseLink,
|
|
|
|
const struct stat *stat, size_t statSize, int statMask);
|
2004-06-15 19:18:04 +04:00
|
|
|
off_t _user_seek(int fd, off_t pos, int seekType);
|
|
|
|
status_t _user_create_dir_entry_ref(dev_t device, ino_t inode, const char *name, int perms);
|
2004-08-29 00:38:39 +04:00
|
|
|
status_t _user_create_dir(int fd, const char *path, int perms);
|
2006-01-25 14:12:21 +03:00
|
|
|
status_t _user_remove_dir(int fd, const char *path);
|
2005-04-06 20:07:10 +04:00
|
|
|
status_t _user_read_link(int fd, const char *path, char *buffer, size_t *_bufferSize);
|
2004-06-15 19:18:04 +04:00
|
|
|
status_t _user_write_link(const char *path, const char *toPath);
|
2004-08-29 00:38:39 +04:00
|
|
|
status_t _user_create_symlink(int fd, const char *path, const char *toPath,
|
|
|
|
int mode);
|
2004-06-15 19:18:04 +04:00
|
|
|
status_t _user_create_link(const char *path, const char *toPath);
|
2004-08-29 00:38:39 +04:00
|
|
|
status_t _user_unlink(int fd, const char *path);
|
|
|
|
status_t _user_rename(int oldFD, const char *oldpath, int newFD,
|
|
|
|
const char *newpath);
|
2004-06-15 19:18:04 +04:00
|
|
|
status_t _user_access(const char *path, int mode);
|
|
|
|
ssize_t _user_select(int numfds, fd_set *readSet, fd_set *writeSet, fd_set *errorSet,
|
|
|
|
bigtime_t timeout, const sigset_t *sigMask);
|
|
|
|
ssize_t _user_poll(struct pollfd *fds, int numfds, bigtime_t timeout);
|
|
|
|
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);
|
|
|
|
status_t _user_remove_attr(int fd, const char *name);
|
|
|
|
status_t _user_rename_attr(int fromFile, const char *fromName, int toFile, const char *toName);
|
|
|
|
int _user_open_index_dir(dev_t device);
|
|
|
|
status_t _user_create_index(dev_t device, const char *name, uint32 type, uint32 flags);
|
|
|
|
status_t _user_read_index_stat(dev_t device, const char *name, struct stat *stat);
|
|
|
|
status_t _user_remove_index(dev_t device, const char *name);
|
|
|
|
status_t _user_getcwd(char *buffer, size_t size);
|
|
|
|
status_t _user_setcwd(int fd, const char *path);
|
2004-12-12 23:33:58 +03:00
|
|
|
int _user_open_query(dev_t device, const char *query, size_t queryLength, uint32 flags,
|
2004-08-29 00:38:39 +04:00
|
|
|
port_id port, int32 token);
|
2002-07-09 16:24:59 +04:00
|
|
|
|
|
|
|
/* fd user prototypes (implementation located in fd.c) */
|
2004-06-15 19:18:04 +04:00
|
|
|
extern ssize_t _user_read(int fd, off_t pos, void *buffer, size_t bufferSize);
|
2004-11-03 17:55:44 +03:00
|
|
|
extern ssize_t _user_readv(int fd, off_t pos, const iovec *vecs, size_t count);
|
2004-06-15 19:18:04 +04:00
|
|
|
extern ssize_t _user_write(int fd, off_t pos, const void *buffer, size_t bufferSize);
|
2004-11-03 17:55:44 +03:00
|
|
|
extern ssize_t _user_writev(int fd, off_t pos, const iovec *vecs, size_t count);
|
2004-06-15 19:18:04 +04:00
|
|
|
extern status_t _user_ioctl(int fd, ulong cmd, void *data, size_t length);
|
|
|
|
extern ssize_t _user_read_dir(int fd, struct dirent *buffer, size_t bufferSize, uint32 maxCount);
|
|
|
|
extern status_t _user_rewind_dir(int fd);
|
|
|
|
extern status_t _user_close(int fd);
|
|
|
|
extern int _user_dup(int fd);
|
|
|
|
extern int _user_dup2(int ofd, int nfd);
|
2004-08-29 00:38:39 +04:00
|
|
|
extern status_t _user_lock_node(int fd);
|
|
|
|
extern status_t _user_unlock_node(int fd);
|
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 */
|