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