xref: /haiku/headers/private/kernel/vfs.h (revision db10640de90f7f9519ba2da9577b7c1af3c64f6b)
1 /*
2 ** Copyright 2002-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 ** Distributed under the terms of the OpenBeOS License.
4 **
5 ** Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
6 ** Distributed under the terms of the NewOS License.
7 */
8 
9 #ifndef _KERNEL_VFS_H
10 #define _KERNEL_VFS_H
11 
12 #include <kernel.h>
13 #include <sys/stat.h>
14 #include <sys/select.h>
15 #include <signal.h>
16 #include <dirent.h>
17 #include <fs_interface.h>
18 #include <lock.h>
19 #include <util/list.h>
20 
21 #define DEFAULT_FD_TABLE_SIZE	128
22 #define MAX_FD_TABLE_SIZE		2048
23 #define MAX_NODE_MONITORS		4096
24 
25 #include <vfs_types.h>
26 
27 
28 struct kernel_args;
29 struct file_descriptor;
30 struct selectsync;
31 struct pollfd;
32 
33 
34 /** The I/O context of a process/team, holds the fd array among others */
35 typedef struct io_context {
36 	struct vnode *cwd;
37 	mutex		io_mutex;
38 	uint32		table_size;
39 	uint32		num_used_fds;
40 	struct file_descriptor **fds;
41 	struct list node_monitors;
42 	uint32		num_monitors;
43 	uint32		max_monitors;
44 } io_context;
45 
46 
47 /* macro to allocate a iovec array on the stack */
48 #define IOVECS(name, size) \
49 	uint8 _##name[sizeof(iovecs) + (size)*sizeof(iovec)]; \
50 	iovecs *name = (iovecs *)_##name
51 
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 status_t vfs_init(struct kernel_args *ka);
58 status_t vfs_bootstrap_file_systems(void);
59 status_t vfs_mount_boot_file_system(void);
60 void *vfs_new_io_context(void *parent_ioctx);
61 int vfs_free_io_context(void *ioctx);
62 
63 struct rlimit;
64 int vfs_getrlimit(int resource, struct rlimit * rlp);
65 int vfs_setrlimit(int resource, const struct rlimit * rlp);
66 
67 // ToDo: for now; this prototype should be in os/drivers/Drivers.h
68 //	or similar places.
69 extern status_t notify_select_event(struct selectsync *sync, uint32 ref, uint8 event);
70 
71 /* calls needed by the VM for paging */
72 int vfs_get_vnode_from_fd(int fd, bool kernel, void **vnode);
73 status_t vfs_get_vnode_from_path(const char *path, bool kernel, void **vnode);
74 int vfs_put_vnode_ptr(void *vnode);
75 void vfs_vnode_acquire_ref(void *vnode);
76 void vfs_vnode_release_ref(void *vnode);
77 ssize_t vfs_can_page(void *vnode);
78 ssize_t vfs_read_page(void *vnode, iovecs *vecs, off_t pos);
79 ssize_t vfs_write_page(void *vnode, iovecs *vecs, off_t pos);
80 void *vfs_get_cache_ptr(void *vnode);
81 int vfs_set_cache_ptr(void *vnode, void *cache);
82 
83 /* special module convenience call */
84 status_t vfs_get_module_path(const char *basePath, const char *moduleName, char *pathBuffer, size_t bufferSize);
85 
86 /* calls the syscall dispatcher should use for user file I/O */
87 status_t _user_mount(const char *path, const char *device, const char *fs_name, void *args);
88 status_t _user_unmount(const char *path);
89 status_t _user_read_fs_info(dev_t device, struct fs_info *info);
90 status_t _user_write_fs_info(dev_t device, const struct fs_info *info, int mask);
91 dev_t _user_next_device(int32 *_cookie);
92 status_t _user_sync(void);
93 status_t _user_dir_node_ref_to_path(dev_t device, ino_t inode, char *userPath, size_t pathLength);
94 int _user_open_entry_ref(dev_t device, ino_t inode, const char *name, int omode);
95 int _user_open(const char *path, int omode);
96 int _user_open_dir_node_ref(dev_t device, ino_t inode);
97 int _user_open_dir_entry_ref(dev_t device, ino_t inode, const char *uname);
98 int _user_open_dir(const char *path);
99 status_t _user_fsync(int fd);
100 off_t _user_seek(int fd, off_t pos, int seekType);
101 int _user_create_entry_ref(dev_t device, ino_t inode, const char *uname, int omode, int perms);
102 int _user_create(const char *path, int omode, int perms);
103 status_t _user_create_dir_entry_ref(dev_t device, ino_t inode, const char *name, int perms);
104 status_t _user_create_dir(const char *path, int perms);
105 status_t _user_remove_dir(const char *path);
106 ssize_t _user_read_link(const char *path, char *buffer, size_t bufferSize);
107 status_t _user_write_link(const char *path, const char *toPath);
108 status_t _user_create_symlink(const char *path, const char *toPath, int mode);
109 status_t _user_create_link(const char *path, const char *toPath);
110 status_t _user_unlink(const char *path);
111 status_t _user_rename(const char *oldpath, const char *newpath);
112 status_t _user_access(const char *path, int mode);
113 status_t _user_read_path_stat(const char *path, bool traverseLink, struct stat *stat, size_t statSize);
114 status_t _user_write_path_stat(const char *path, bool traverseLink, const struct stat *stat, size_t statSize, int statMask);
115 ssize_t _user_select(int numfds, fd_set *readSet, fd_set *writeSet, fd_set *errorSet,
116 			bigtime_t timeout, const sigset_t *sigMask);
117 ssize_t _user_poll(struct pollfd *fds, int numfds, bigtime_t timeout);
118 int _user_open_attr_dir(int fd, const char *path);
119 int _user_create_attr(int fd, const char *name, uint32 type, int openMode);
120 int _user_open_attr(int fd, const char *name, int openMode);
121 status_t _user_remove_attr(int fd, const char *name);
122 status_t _user_rename_attr(int fromFile, const char *fromName, int toFile, const char *toName);
123 int _user_open_index_dir(dev_t device);
124 status_t _user_create_index(dev_t device, const char *name, uint32 type, uint32 flags);
125 status_t _user_read_index_stat(dev_t device, const char *name, struct stat *stat);
126 status_t _user_remove_index(dev_t device, const char *name);
127 status_t _user_getcwd(char *buffer, size_t size);
128 status_t _user_setcwd(int fd, const char *path);
129 
130 /* fd user prototypes (implementation located in fd.c)  */
131 extern ssize_t _user_read(int fd, off_t pos, void *buffer, size_t bufferSize);
132 extern ssize_t _user_write(int fd, off_t pos, const void *buffer, size_t bufferSize);
133 extern status_t _user_ioctl(int fd, ulong cmd, void *data, size_t length);
134 extern ssize_t _user_read_dir(int fd, struct dirent *buffer, size_t bufferSize, uint32 maxCount);
135 extern status_t _user_rewind_dir(int fd);
136 extern status_t _user_read_stat(int fd, struct stat *stat, size_t statSize);
137 extern status_t _user_write_stat(int fd, const struct stat *stat, size_t statSize, int statMask);
138 extern status_t _user_close(int fd);
139 extern int _user_dup(int fd);
140 extern int _user_dup2(int ofd, int nfd);
141 
142 /* vfs entry points... */
143 
144 #ifdef __cplusplus
145 }
146 #endif
147 
148 #endif	/* _KERNEL_VFS_H */
149