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