xref: /haiku/headers/private/kernel/vfs.h (revision 43711de9d2e6df4f0270c4b531d7b93c36e9b5fc)
1 /*
2  * Copyright 2002-2008, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
6  * Distributed under the terms of the NewOS License.
7  */
8 #ifndef _KERNEL_VFS_H
9 #define _KERNEL_VFS_H
10 
11 
12 #include <kernel.h>
13 #include <lock.h>
14 #include <util/list.h>
15 
16 #include <fs_interface.h>
17 
18 #include <dirent.h>
19 #include <signal.h>
20 #include <sys/stat.h>
21 #include <sys/select.h>
22 
23 
24 #define DEFAULT_FD_TABLE_SIZE	256
25 #define MAX_FD_TABLE_SIZE		8192
26 #define DEFAULT_NODE_MONITORS	4096
27 #define MAX_NODE_MONITORS		65536
28 
29 #define B_UNMOUNT_BUSY_PARTITION	0x80000000
30 
31 struct kernel_args;
32 struct vm_cache;
33 struct file_descriptor;
34 struct selectsync;
35 struct select_info;
36 struct pollfd;
37 struct vnode;
38 
39 
40 /** The I/O context of a process/team, holds the fd array among others */
41 typedef struct io_context {
42 	struct vnode *cwd;
43 	mutex		io_mutex;
44 	uint32		table_size;
45 	uint32		num_used_fds;
46 	struct file_descriptor **fds;
47 	struct select_info **select_infos;
48 	uint8		*fds_close_on_exec;
49 	struct list node_monitors;
50 	uint32		num_monitors;
51 	uint32		max_monitors;
52 } io_context;
53 
54 struct fd_info {
55 	int		number;
56 	int32	open_mode;
57 	dev_t	device;
58 	ino_t	node;
59 };
60 
61 /* macro to allocate a iovec array on the stack */
62 #define IOVECS(name, size) \
63 	uint8 _##name[sizeof(iovecs) + (size)*sizeof(iovec)]; \
64 	iovecs *name = (iovecs *)_##name
65 
66 
67 #ifdef __cplusplus
68 extern "C" {
69 #endif
70 
71 status_t vfs_init(struct kernel_args *args);
72 status_t vfs_bootstrap_file_systems(void);
73 void vfs_mount_boot_file_system(struct kernel_args *args);
74 void vfs_exec_io_context(void *context);
75 void *vfs_new_io_context(void *parentContext);
76 status_t vfs_free_io_context(void *context);
77 
78 struct rlimit;
79 int vfs_getrlimit(int resource, struct rlimit * rlp);
80 int vfs_setrlimit(int resource, const struct rlimit * rlp);
81 
82 /* calls needed by the VM for paging and by the file cache */
83 int vfs_get_vnode_from_fd(int fd, bool kernel, struct vnode **_vnode);
84 status_t vfs_get_vnode_from_path(const char *path, bool kernel,
85 			struct vnode **_vnode);
86 status_t vfs_get_vnode(dev_t mountID, ino_t vnodeID, bool canWait,
87 			struct vnode **_vnode);
88 status_t vfs_entry_ref_to_vnode(dev_t mountID, ino_t directoryID,
89 			const char *name, struct vnode **_vnode);
90 void vfs_vnode_to_node_ref(struct vnode *vnode, dev_t *_mountID,
91 			ino_t *_vnodeID);
92 
93 status_t vfs_lookup_vnode(dev_t mountID, ino_t vnodeID, struct vnode **_vnode);
94 void vfs_put_vnode(struct vnode *vnode);
95 void vfs_acquire_vnode(struct vnode *vnode);
96 status_t vfs_get_cookie_from_fd(int fd, void **_cookie);
97 bool vfs_can_page(struct vnode *vnode, void *cookie);
98 status_t vfs_read_pages(struct vnode *vnode, void *cookie, off_t pos,
99 			const iovec *vecs, size_t count, size_t *_numBytes, bool fsReenter);
100 status_t vfs_write_pages(struct vnode *vnode, void *cookie, off_t pos,
101 			const iovec *vecs, size_t count, size_t *_numBytes, bool fsReenter);
102 status_t vfs_get_vnode_cache(struct vnode *vnode, struct vm_cache **_cache,
103 			bool allocate);
104 status_t vfs_get_file_map(struct vnode *vnode, off_t offset, size_t size,
105 			struct file_io_vec *vecs, size_t *_count);
106 status_t vfs_get_fs_node_from_path(dev_t mountID, const char *path,
107 			bool kernel, void **_node);
108 status_t vfs_stat_vnode(struct vnode *vnode, struct stat *stat);
109 status_t vfs_get_vnode_name(struct vnode *vnode, char *name, size_t nameSize);
110 status_t vfs_get_cwd(dev_t *_mountID, ino_t *_vnodeID);
111 void vfs_unlock_vnode_if_locked(struct file_descriptor *descriptor);
112 status_t vfs_unmount(dev_t mountID, uint32 flags);
113 status_t vfs_disconnect_vnode(dev_t mountID, ino_t vnodeID);
114 void vfs_free_unused_vnodes(int32 level);
115 
116 /* special module convenience call */
117 status_t vfs_get_module_path(const char *basePath, const char *moduleName,
118 			char *pathBuffer, size_t bufferSize);
119 
120 /* service call for whoever needs a normalized path */
121 status_t vfs_normalize_path(const char *path, char *buffer, size_t bufferSize,
122 			bool kernel);
123 
124 /* service call for the node monitor */
125 status_t resolve_mount_point_to_volume_root(dev_t mountID, ino_t nodeID,
126 			dev_t *resolvedMountID, ino_t *resolvedNodeID);
127 
128 /* calls the syscall dispatcher should use for user file I/O */
129 dev_t _user_mount(const char *path, const char *device, const char *fs_name,
130 			uint32 flags, const char *args, size_t argsLength);
131 status_t _user_unmount(const char *path, uint32 flags);
132 status_t _user_read_fs_info(dev_t device, struct fs_info *info);
133 status_t _user_write_fs_info(dev_t device, const struct fs_info *info, int mask);
134 dev_t _user_next_device(int32 *_cookie);
135 status_t _user_sync(void);
136 status_t _user_get_next_fd_info(team_id team, uint32 *cookie, struct fd_info *info,
137 			size_t infoSize);
138 status_t _user_entry_ref_to_path(dev_t device, ino_t inode, const char *leaf,
139 			char *userPath, size_t pathLength);
140 int _user_open_entry_ref(dev_t device, ino_t inode, const char *name, int openMode, int perms);
141 int _user_open(int fd, const char *path, int openMode, int perms);
142 int _user_open_dir_node_ref(dev_t device, ino_t inode);
143 int _user_open_dir_entry_ref(dev_t device, ino_t inode, const char *uname);
144 int _user_open_dir(int fd, const char *path);
145 int _user_open_parent_dir(int fd, char *name, size_t nameLength);
146 status_t _user_fcntl(int fd, int op, uint32 argument);
147 status_t _user_fsync(int fd);
148 status_t _user_flock(int fd, int op);
149 status_t _user_read_stat(int fd, const char *path, bool traverseLink,
150 			struct stat *stat, size_t statSize);
151 status_t _user_write_stat(int fd, const char *path, bool traverseLink,
152 			const struct stat *stat, size_t statSize, int statMask);
153 off_t _user_seek(int fd, off_t pos, int seekType);
154 status_t _user_create_dir_entry_ref(dev_t device, ino_t inode, const char *name, int perms);
155 status_t _user_create_dir(int fd, const char *path, int perms);
156 status_t _user_remove_dir(int fd, const char *path);
157 status_t _user_read_link(int fd, const char *path, char *buffer, size_t *_bufferSize);
158 status_t _user_write_link(const char *path, const char *toPath);
159 status_t _user_create_symlink(int fd, const char *path, const char *toPath,
160 			int mode);
161 status_t _user_create_link(const char *path, const char *toPath);
162 status_t _user_unlink(int fd, const char *path);
163 status_t _user_rename(int oldFD, const char *oldpath, int newFD,
164 			const char *newpath);
165 status_t _user_access(const char *path, int mode);
166 ssize_t _user_select(int numfds, fd_set *readSet, fd_set *writeSet, fd_set *errorSet,
167 			bigtime_t timeout, const sigset_t *sigMask);
168 ssize_t _user_poll(struct pollfd *fds, int numfds, bigtime_t timeout);
169 int _user_open_attr_dir(int fd, const char *path);
170 int _user_create_attr(int fd, const char *name, uint32 type, int openMode);
171 int _user_open_attr(int fd, const char *name, int openMode);
172 status_t _user_remove_attr(int fd, const char *name);
173 status_t _user_rename_attr(int fromFile, const char *fromName, int toFile, const char *toName);
174 int _user_open_index_dir(dev_t device);
175 status_t _user_create_index(dev_t device, const char *name, uint32 type, uint32 flags);
176 status_t _user_read_index_stat(dev_t device, const char *name, struct stat *stat);
177 status_t _user_remove_index(dev_t device, const char *name);
178 status_t _user_getcwd(char *buffer, size_t size);
179 status_t _user_setcwd(int fd, const char *path);
180 int _user_open_query(dev_t device, const char *query, size_t queryLength, uint32 flags,
181 			port_id port, int32 token);
182 
183 /* fd user prototypes (implementation located in fd.c)  */
184 extern ssize_t _user_read(int fd, off_t pos, void *buffer, size_t bufferSize);
185 extern ssize_t _user_readv(int fd, off_t pos, const iovec *vecs, size_t count);
186 extern ssize_t _user_write(int fd, off_t pos, const void *buffer, size_t bufferSize);
187 extern ssize_t _user_writev(int fd, off_t pos, const iovec *vecs, size_t count);
188 extern status_t _user_ioctl(int fd, ulong cmd, void *data, size_t length);
189 extern ssize_t _user_read_dir(int fd, struct dirent *buffer, size_t bufferSize, uint32 maxCount);
190 extern status_t _user_rewind_dir(int fd);
191 extern status_t _user_close(int fd);
192 extern int _user_dup(int fd);
193 extern int _user_dup2(int ofd, int nfd);
194 extern status_t _user_lock_node(int fd);
195 extern status_t _user_unlock_node(int fd);
196 
197 /* vfs entry points... */
198 
199 #ifdef __cplusplus
200 }
201 #endif
202 
203 #endif	/* _KERNEL_VFS_H */
204