xref: /haiku/headers/private/kernel/vfs.h (revision d67f94ca9dc693a2734456fa13111d2036bc7297)
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 	struct list node_monitors;
41 	uint32		num_monitors;
42 	uint32		max_monitors;
43 } io_context;
44 
45 
46 /* macro to allocate a iovec array on the stack */
47 #define IOVECS(name, size) \
48 	uint8 _##name[sizeof(iovecs) + (size)*sizeof(iovec)]; \
49 	iovecs *name = (iovecs *)_##name
50 
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 status_t vfs_init(struct kernel_args *args);
57 status_t vfs_bootstrap_file_systems(void);
58 status_t vfs_mount_boot_file_system(struct kernel_args *args);
59 void vfs_exec_io_context(void *context);
60 void *vfs_new_io_context(void *parentContext);
61 int vfs_free_io_context(void *context);
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 /* calls needed by the VM for paging and by the file cache */
68 int vfs_get_vnode_from_fd(int fd, bool kernel, void **vnode);
69 status_t vfs_get_vnode_from_path(const char *path, bool kernel, void **vnode);
70 status_t vfs_get_vnode(mount_id mountID, vnode_id vnodeID, void **_vnode);
71 status_t vfs_lookup_vnode(mount_id mountID, vnode_id vnodeID, void **_vnode);
72 int vfs_put_vnode_ptr(void *vnode);
73 void vfs_vnode_acquire_ref(void *vnode);
74 void vfs_vnode_release_ref(void *vnode);
75 status_t vfs_get_cookie_from_fd(int fd, void **_cookie);
76 bool vfs_can_page(void *vnode, void *cookie);
77 status_t vfs_read_pages(void *vnode, void *cookie, off_t pos, const iovec *vecs, size_t count, size_t *_numBytes);
78 status_t vfs_write_pages(void *vnode, void *cookie, off_t pos, const iovec *vecs, size_t count, size_t *_numBytes);
79 status_t vfs_get_vnode_cache(void *vnode, struct vm_cache_ref **_cache);
80 status_t vfs_get_file_map( void *_vnode, off_t offset, size_t size, struct file_io_vec *vecs, size_t *_count);
81 status_t vfs_get_fs_node_from_path(mount_id mountID, const char *path, bool kernel, void **_node);
82 status_t vfs_stat_vnode(void *_vnode, struct stat *stat);
83 status_t vfs_get_vnode_name(void *vnode, char *name, size_t nameSize);
84 
85 /* special module convenience call */
86 status_t vfs_get_module_path(const char *basePath, const char *moduleName, char *pathBuffer, size_t bufferSize);
87 
88 /* service call for whoever needs a normalized path */
89 status_t vfs_normalize_path(const char *path, char *buffer, size_t bufferSize,
90 			bool kernel);
91 
92 /* service call for the node monitor */
93 status_t resolve_mount_point_to_volume_root(mount_id mountID, vnode_id nodeID,
94 	mount_id *resolvedMountID, vnode_id *resolvedNodeID);
95 
96 /* calls the syscall dispatcher should use for user file I/O */
97 status_t _user_mount(const char *path, const char *device, const char *fs_name,
98 			uint32 flags, const char *args);
99 status_t _user_unmount(const char *path, uint32 flags);
100 status_t _user_read_fs_info(dev_t device, struct fs_info *info);
101 status_t _user_write_fs_info(dev_t device, const struct fs_info *info, int mask);
102 dev_t _user_next_device(int32 *_cookie);
103 status_t _user_sync(void);
104 status_t _user_entry_ref_to_path(dev_t device, ino_t inode, const char *leaf,
105 			char *userPath, size_t pathLength);
106 int _user_open_entry_ref(dev_t device, ino_t inode, const char *name, int openMode, int perms);
107 int _user_open(int fd, const char *path, int openMode, int perms);
108 int _user_open_dir_node_ref(dev_t device, ino_t inode);
109 int _user_open_dir_entry_ref(dev_t device, ino_t inode, const char *uname);
110 int _user_open_dir(int fd, const char *path);
111 int _user_open_parent_dir(int fd, char *name, size_t nameLength);
112 status_t _user_fcntl(int fd, int op, uint32 argument);
113 status_t _user_fsync(int fd);
114 status_t _user_read_stat(int fd, const char *path, bool traverseLink,
115 			struct stat *stat, size_t statSize);
116 status_t _user_write_stat(int fd, const char *path, bool traverseLink,
117 			const struct stat *stat, size_t statSize, int statMask);
118 off_t _user_seek(int fd, off_t pos, int seekType);
119 status_t _user_create_dir_entry_ref(dev_t device, ino_t inode, const char *name, int perms);
120 status_t _user_create_dir(int fd, const char *path, int perms);
121 status_t _user_remove_dir(const char *path);
122 ssize_t _user_read_link(int fd, const char *path, char *buffer, size_t bufferSize);
123 status_t _user_write_link(const char *path, const char *toPath);
124 status_t _user_create_symlink(int fd, const char *path, const char *toPath,
125 			int mode);
126 status_t _user_create_link(const char *path, const char *toPath);
127 status_t _user_unlink(int fd, const char *path);
128 status_t _user_rename(int oldFD, const char *oldpath, int newFD,
129 			const char *newpath);
130 status_t _user_access(const char *path, int mode);
131 ssize_t _user_select(int numfds, fd_set *readSet, fd_set *writeSet, fd_set *errorSet,
132 			bigtime_t timeout, const sigset_t *sigMask);
133 ssize_t _user_poll(struct pollfd *fds, int numfds, bigtime_t timeout);
134 int _user_open_attr_dir(int fd, const char *path);
135 int _user_create_attr(int fd, const char *name, uint32 type, int openMode);
136 int _user_open_attr(int fd, const char *name, int openMode);
137 status_t _user_remove_attr(int fd, const char *name);
138 status_t _user_rename_attr(int fromFile, const char *fromName, int toFile, const char *toName);
139 int _user_open_index_dir(dev_t device);
140 status_t _user_create_index(dev_t device, const char *name, uint32 type, uint32 flags);
141 status_t _user_read_index_stat(dev_t device, const char *name, struct stat *stat);
142 status_t _user_remove_index(dev_t device, const char *name);
143 status_t _user_getcwd(char *buffer, size_t size);
144 status_t _user_setcwd(int fd, const char *path);
145 int _user_open_query(dev_t device, const char *query, size_t queryLength, uint32 flags,
146 			port_id port, int32 token);
147 
148 /* fd user prototypes (implementation located in fd.c)  */
149 extern ssize_t _user_read(int fd, off_t pos, void *buffer, size_t bufferSize);
150 extern ssize_t _user_readv(int fd, off_t pos, const iovec *vecs, size_t count);
151 extern ssize_t _user_write(int fd, off_t pos, const void *buffer, size_t bufferSize);
152 extern ssize_t _user_writev(int fd, off_t pos, const iovec *vecs, size_t count);
153 extern status_t _user_ioctl(int fd, ulong cmd, void *data, size_t length);
154 extern ssize_t _user_read_dir(int fd, struct dirent *buffer, size_t bufferSize, uint32 maxCount);
155 extern status_t _user_rewind_dir(int fd);
156 extern status_t _user_close(int fd);
157 extern int _user_dup(int fd);
158 extern int _user_dup2(int ofd, int nfd);
159 extern status_t _user_lock_node(int fd);
160 extern status_t _user_unlock_node(int fd);
161 
162 /* vfs entry points... */
163 
164 #ifdef __cplusplus
165 }
166 #endif
167 
168 #endif	/* _KERNEL_VFS_H */
169