vfs.h revision e6bd90c5
152a38012Sejakowatz/*
2a32a4683SAxel Dörfler * Copyright 2002-2008, Axel D��rfler, axeld@pinc-software.de. All rights reserved.
3d12de920SAxel Dörfler * Distributed under the terms of the MIT License.
4d12de920SAxel Dörfler *
5d12de920SAxel Dörfler * Copyright 2001-2002, Travis Geiselbrecht. All rights reserved.
6d12de920SAxel Dörfler * Distributed under the terms of the NewOS License.
7d12de920SAxel Dörfler */
852a38012Sejakowatz#ifndef _KERNEL_VFS_H
952a38012Sejakowatz#define _KERNEL_VFS_H
1052a38012Sejakowatz
11606e0d36SAxel Dörfler
1252a38012Sejakowatz#include <kernel.h>
13f9bdcca5SAxel Dörfler#include <lock.h>
14c7a03dadSAxel Dörfler#include <util/list.h>
1552a38012Sejakowatz
16606e0d36SAxel Dörfler#include <fs_interface.h>
17606e0d36SAxel Dörfler
18606e0d36SAxel Dörfler#include <dirent.h>
19606e0d36SAxel Dörfler#include <signal.h>
20df50f7a9SIngo Weinhold#include <sys/socket.h>
21606e0d36SAxel Dörfler#include <sys/stat.h>
22606e0d36SAxel Dörfler#include <sys/select.h>
23606e0d36SAxel Dörfler
246b202f4eSIngo Weinhold#include <vfs_defs.h>
256b202f4eSIngo Weinhold
26606e0d36SAxel Dörfler
27245aecdaSAxel Dörfler#define DEFAULT_FD_TABLE_SIZE	256
282dedc014SFrançois Revol#define MAX_FD_TABLE_SIZE		8192
29e6bd90c5SIngo Weinhold#define DEFAULT_NODE_MONITORS	4096
302dedc014SFrançois Revol#define MAX_NODE_MONITORS		65536
3152a38012Sejakowatz
326e122bd9SIngo Weinhold#define B_UNMOUNT_BUSY_PARTITION	0x80000000
336e122bd9SIngo Weinhold
34f9bdcca5SAxel Dörflerstruct file_descriptor;
35df50f7a9SIngo Weinholdstruct kernel_args;
36df50f7a9SIngo Weinholdstruct net_stat;
37df50f7a9SIngo Weinholdstruct pollfd;
38f9bdcca5SAxel Dörflerstruct selectsync;
3966c03dc3SIngo Weinholdstruct select_info;
405c99d639SIngo Weinholdstruct VMCache;
416d4aea47SAxel Dörflerstruct vnode;
42f9bdcca5SAxel Dörfler
43f9bdcca5SAxel Dörfler
44f9bdcca5SAxel Dörfler/** The I/O context of a process/team, holds the fd array among others */
45f9bdcca5SAxel Dörflertypedef struct io_context {
46360be1fcSIngo Weinhold	struct vnode *root;
47f9bdcca5SAxel Dörfler	struct vnode *cwd;
48f9bdcca5SAxel Dörfler	mutex		io_mutex;
49f9bdcca5SAxel Dörfler	uint32		table_size;
50f9bdcca5SAxel Dörfler	uint32		num_used_fds;
51f9bdcca5SAxel Dörfler	struct file_descriptor **fds;
5266c03dc3SIngo Weinhold	struct select_info **select_infos;
53681779f1SAxel Dörfler	uint8		*fds_close_on_exec;
54f9bdcca5SAxel Dörfler	struct list node_monitors;
55f9bdcca5SAxel Dörfler	uint32		num_monitors;
56f9bdcca5SAxel Dörfler	uint32		max_monitors;
57f9bdcca5SAxel Dörfler} io_context;
58f9bdcca5SAxel Dörfler
5952a38012Sejakowatz/* macro to allocate a iovec array on the stack */
6052a38012Sejakowatz#define IOVECS(name, size) \
6152a38012Sejakowatz	uint8 _##name[sizeof(iovecs) + (size)*sizeof(iovec)]; \
6252a38012Sejakowatz	iovecs *name = (iovecs *)_##name
6352a38012Sejakowatz
643aaee8e5SAxel Dörfler
6552a38012Sejakowatz#ifdef __cplusplus
6652a38012Sejakowatzextern "C" {
67e6bd90c5SIngo Weinhold#endif
6852a38012Sejakowatz
6906db2509SAxel Dörflerstatus_t vfs_init(struct kernel_args *args);
70cdbef380SAxel Dörflerstatus_t vfs_bootstrap_file_systems(void);
71f5fa54f7SMarcus Overhagenvoid vfs_mount_boot_file_system(struct kernel_args *args);
7276dede71SAxel Dörflervoid vfs_exec_io_context(void *context);
7376dede71SAxel Dörflervoid *vfs_new_io_context(void *parentContext);
749391dd21SAxel Dörflerstatus_t vfs_free_io_context(void *context);
7552a38012Sejakowatz
7652a38012Sejakowatzstruct rlimit;
7752a38012Sejakowatzint vfs_getrlimit(int resource, struct rlimit * rlp);
7852a38012Sejakowatzint vfs_setrlimit(int resource, const struct rlimit * rlp);
7952a38012Sejakowatz
80cfd8ea78SAxel Dörfler/* calls needed by the VM for paging and by the file cache */
8180f54692SAxel Dörflerint vfs_get_vnode_from_fd(int fd, bool kernel, struct vnode **_vnode);
8280f54692SAxel Dörflerstatus_t vfs_get_vnode_from_path(const char *path, bool kernel,
8380f54692SAxel Dörfler			struct vnode **_vnode);
840710d59cSAxel Dörflerstatus_t vfs_get_vnode(dev_t mountID, ino_t vnodeID, bool canWait,
850710d59cSAxel Dörfler			struct vnode **_vnode);
86245aecdaSAxel Dörflerstatus_t vfs_entry_ref_to_vnode(dev_t mountID, ino_t directoryID,
8780f54692SAxel Dörfler			const char *name, struct vnode **_vnode);
8880f54692SAxel Dörflervoid vfs_vnode_to_node_ref(struct vnode *vnode, dev_t *_mountID,
8980f54692SAxel Dörfler			ino_t *_vnodeID);
909a63d903SAxel Dörfler
9180f54692SAxel Dörflerstatus_t vfs_lookup_vnode(dev_t mountID, ino_t vnodeID, struct vnode **_vnode);
9280f54692SAxel Dörflervoid vfs_put_vnode(struct vnode *vnode);
9380f54692SAxel Dörflervoid vfs_acquire_vnode(struct vnode *vnode);
94cfd8ea78SAxel Dörflerstatus_t vfs_get_cookie_from_fd(int fd, void **_cookie);
9580f54692SAxel Dörflerbool vfs_can_page(struct vnode *vnode, void *cookie);
9680f54692SAxel Dörflerstatus_t vfs_read_pages(struct vnode *vnode, void *cookie, off_t pos,
97e6bd90c5SIngo Weinhold			const iovec *vecs, size_t count, size_t *_numBytes);
9880f54692SAxel Dörflerstatus_t vfs_write_pages(struct vnode *vnode, void *cookie, off_t pos,
99e6bd90c5SIngo Weinhold			const iovec *vecs, size_t count, size_t *_numBytes);
1005c99d639SIngo Weinholdstatus_t vfs_get_vnode_cache(struct vnode *vnode, struct VMCache **_cache,
1013e9513aaSAxel Dörfler			bool allocate);
10280f54692SAxel Dörflerstatus_t vfs_get_file_map(struct vnode *vnode, off_t offset, size_t size,
1039a63d903SAxel Dörfler			struct file_io_vec *vecs, size_t *_count);
1047ffafac8SIngo Weinholdstatus_t vfs_get_fs_node_from_path(fs_volume *volume, const char *path,
1059a63d903SAxel Dörfler			bool kernel, void **_node);
10680f54692SAxel Dörflerstatus_t vfs_stat_vnode(struct vnode *vnode, struct stat *stat);
107fc380199SMichael Lotzstatus_t vfs_stat_node_ref(dev_t device, ino_t inode, struct stat *stat);
10880f54692SAxel Dörflerstatus_t vfs_get_vnode_name(struct vnode *vnode, char *name, size_t nameSize);
1094f26630dSAxel Dörflerstatus_t vfs_entry_ref_to_path(dev_t device, ino_t inode, const char *leaf,
1104f26630dSAxel Dörfler	char *path, size_t pathLength);
111245aecdaSAxel Dörflerstatus_t vfs_get_cwd(dev_t *_mountID, ino_t *_vnodeID);
1128265e121SAxel Dörflervoid vfs_unlock_vnode_if_locked(struct file_descriptor *descriptor);
1136e122bd9SIngo Weinholdstatus_t vfs_unmount(dev_t mountID, uint32 flags);
114245aecdaSAxel Dörflerstatus_t vfs_disconnect_vnode(dev_t mountID, ino_t vnodeID);
1159f6376a0SAxel Dörflervoid vfs_free_unused_vnodes(int32 level);
11652a38012Sejakowatz
1178c117a6dSIngo Weinholdstatus_t vfs_read_stat(int fd, const char *path, bool traverseLeafLink,
1188c117a6dSIngo Weinhold			struct stat *stat, bool kernel);
1198c117a6dSIngo Weinhold
1205306fba3SAxel Dörfler/* special module convenience call */
1219a63d903SAxel Dörflerstatus_t vfs_get_module_path(const char *basePath, const char *moduleName,
1229a63d903SAxel Dörfler			char *pathBuffer, size_t bufferSize);
1235306fba3SAxel Dörfler
1247fb2963aSIngo Weinhold/* service call for whoever needs a normalized path */
1257fb2963aSIngo Weinholdstatus_t vfs_normalize_path(const char *path, char *buffer, size_t bufferSize,
1267fb2963aSIngo Weinhold			bool kernel);
1277fb2963aSIngo Weinhold
128f8b4d83fSIngo Weinhold/* service call for whoever wants to create a special node */
129f8b4d83fSIngo Weinholdstatus_t vfs_create_special_node(const char *path, fs_vnode *subVnode,
130f8b4d83fSIngo Weinhold			mode_t mode, uint32 flags, bool kernel, fs_vnode *_superVnode,
131f8b4d83fSIngo Weinhold			struct vnode **_createdVnode);
132f8b4d83fSIngo Weinhold
133244f03dcSIngo Weinhold/* service call for the node monitor */
134245aecdaSAxel Dörflerstatus_t resolve_mount_point_to_volume_root(dev_t mountID, ino_t nodeID,
135245aecdaSAxel Dörfler			dev_t *resolvedMountID, ino_t *resolvedNodeID);
136244f03dcSIngo Weinhold
13752a38012Sejakowatz/* calls the syscall dispatcher should use for user file I/O */
1382db3fcedSAxel Dörflerdev_t _user_mount(const char *path, const char *device, const char *fs_name,
1395a2ad00cSJérôme Duval			uint32 flags, const char *args, size_t argsLength);
1404c8e8f2fSAxel Dörflerstatus_t _user_unmount(const char *path, uint32 flags);
141318ea28bSAxel Dörflerstatus_t _user_read_fs_info(dev_t device, struct fs_info *info);
142318ea28bSAxel Dörflerstatus_t _user_write_fs_info(dev_t device, const struct fs_info *info, int mask);
143c28c0592SAxel Dörflerdev_t _user_next_device(int32 *_cookie);
144734893f6SAxel Dörflerstatus_t _user_sync(void);
1450e382a46SAxel Dörflerstatus_t _user_get_next_fd_info(team_id team, uint32 *cookie, struct fd_info *info,
1460e382a46SAxel Dörfler			size_t infoSize);
1479955b99aSIngo Weinholdstatus_t _user_entry_ref_to_path(dev_t device, ino_t inode, const char *leaf,
1489955b99aSIngo Weinhold			char *userPath, size_t pathLength);
1492c986936SIngo Weinholdstatus_t _user_normalize_path(const char* userPath, bool traverseLink,
1502c986936SIngo Weinhold			char* buffer);
151d12de920SAxel Dörflerint _user_open_entry_ref(dev_t device, ino_t inode, const char *name, int openMode, int perms);
152d12de920SAxel Dörflerint _user_open(int fd, const char *path, int openMode, int perms);
153734893f6SAxel Dörflerint _user_open_dir_node_ref(dev_t device, ino_t inode);
154734893f6SAxel Dörflerint _user_open_dir_entry_ref(dev_t device, ino_t inode, const char *uname);
1559955b99aSIngo Weinholdint _user_open_dir(int fd, const char *path);
1569955b99aSIngo Weinholdint _user_open_parent_dir(int fd, char *name, size_t nameLength);
1576acb6724SAxel Dörflerstatus_t _user_fcntl(int fd, int op, uint32 argument);
158734893f6SAxel Dörflerstatus_t _user_fsync(int fd);
159a32a4683SAxel Dörflerstatus_t _user_flock(int fd, int op);
1609955b99aSIngo Weinholdstatus_t _user_read_stat(int fd, const char *path, bool traverseLink,
1619955b99aSIngo Weinhold			struct stat *stat, size_t statSize);
1629955b99aSIngo Weinholdstatus_t _user_write_stat(int fd, const char *path, bool traverseLink,
1639955b99aSIngo Weinhold			const struct stat *stat, size_t statSize, int statMask);
164734893f6SAxel Dörfleroff_t _user_seek(int fd, off_t pos, int seekType);
165734893f6SAxel Dörflerstatus_t _user_create_dir_entry_ref(dev_t device, ino_t inode, const char *name, int perms);
1669955b99aSIngo Weinholdstatus_t _user_create_dir(int fd, const char *path, int perms);
167979aeaf7SAxel Dörflerstatus_t _user_remove_dir(int fd, const char *path);
168219dacabSAxel Dörflerstatus_t _user_read_link(int fd, const char *path, char *buffer, size_t *_bufferSize);
169734893f6SAxel Dörflerstatus_t _user_write_link(const char *path, const char *toPath);
1709955b99aSIngo Weinholdstatus_t _user_create_symlink(int fd, const char *path, const char *toPath,
1719955b99aSIngo Weinhold			int mode);
172734893f6SAxel Dörflerstatus_t _user_create_link(const char *path, const char *toPath);
1739955b99aSIngo Weinholdstatus_t _user_unlink(int fd, const char *path);
1749955b99aSIngo Weinholdstatus_t _user_rename(int oldFD, const char *oldpath, int newFD,
1759955b99aSIngo Weinhold			const char *newpath);
1767ffafac8SIngo Weinholdstatus_t _user_create_fifo(const char *path, mode_t perms);
1776e36a49eSIngo Weinholdstatus_t _user_create_pipe(int *fds);
178734893f6SAxel Dörflerstatus_t _user_access(const char *path, int mode);
179734893f6SAxel Dörflerssize_t _user_select(int numfds, fd_set *readSet, fd_set *writeSet, fd_set *errorSet,
180734893f6SAxel Dörfler			bigtime_t timeout, const sigset_t *sigMask);
181734893f6SAxel Dörflerssize_t _user_poll(struct pollfd *fds, int numfds, bigtime_t timeout);
182734893f6SAxel Dörflerint _user_open_attr_dir(int fd, const char *path);
183734893f6SAxel Dörflerint _user_create_attr(int fd, const char *name, uint32 type, int openMode);
184734893f6SAxel Dörflerint _user_open_attr(int fd, const char *name, int openMode);
185734893f6SAxel Dörflerstatus_t _user_remove_attr(int fd, const char *name);
186734893f6SAxel Dörflerstatus_t _user_rename_attr(int fromFile, const char *fromName, int toFile, const char *toName);
187734893f6SAxel Dörflerint _user_open_index_dir(dev_t device);
188734893f6SAxel Dörflerstatus_t _user_create_index(dev_t device, const char *name, uint32 type, uint32 flags);
189734893f6SAxel Dörflerstatus_t _user_read_index_stat(dev_t device, const char *name, struct stat *stat);
190734893f6SAxel Dörflerstatus_t _user_remove_index(dev_t device, const char *name);
191734893f6SAxel Dörflerstatus_t _user_getcwd(char *buffer, size_t size);
192734893f6SAxel Dörflerstatus_t _user_setcwd(int fd, const char *path);
193360be1fcSIngo Weinholdstatus_t _user_change_root(const char *path);
194dfb71e04SAxel Dörflerint _user_open_query(dev_t device, const char *query, size_t queryLength, uint32 flags,
1959955b99aSIngo Weinhold			port_id port, int32 token);
19652a38012Sejakowatz
197df50f7a9SIngo Weinhold/* fd user prototypes (implementation located in fd.cpp)  */
198734893f6SAxel Dörflerextern ssize_t _user_read(int fd, off_t pos, void *buffer, size_t bufferSize);
199424f90afSAxel Dörflerextern ssize_t _user_readv(int fd, off_t pos, const iovec *vecs, size_t count);
200734893f6SAxel Dörflerextern ssize_t _user_write(int fd, off_t pos, const void *buffer, size_t bufferSize);
201424f90afSAxel Dörflerextern ssize_t _user_writev(int fd, off_t pos, const iovec *vecs, size_t count);
202734893f6SAxel Dörflerextern status_t _user_ioctl(int fd, ulong cmd, void *data, size_t length);
203734893f6SAxel Dörflerextern ssize_t _user_read_dir(int fd, struct dirent *buffer, size_t bufferSize, uint32 maxCount);
204734893f6SAxel Dörflerextern status_t _user_rewind_dir(int fd);
205734893f6SAxel Dörflerextern status_t _user_close(int fd);
206734893f6SAxel Dörflerextern int _user_dup(int fd);
207734893f6SAxel Dörflerextern int _user_dup2(int ofd, int nfd);
2089955b99aSIngo Weinholdextern status_t _user_lock_node(int fd);
2099955b99aSIngo Weinholdextern status_t _user_unlock_node(int fd);
21052a38012Sejakowatz
211df50f7a9SIngo Weinhold/* socket user prototypes (implementation in socket.cpp) */
212df50f7a9SIngo Weinholdextern int			_user_socket(int family, int type, int protocol);
213df50f7a9SIngo Weinholdextern status_t		_user_bind(int socket, const struct sockaddr *address,
214df50f7a9SIngo Weinhold						socklen_t addressLength);
215df50f7a9SIngo Weinholdextern status_t		_user_shutdown_socket(int socket, int how);
216df50f7a9SIngo Weinholdextern status_t		_user_connect(int socket, const struct sockaddr *address,
217df50f7a9SIngo Weinhold						socklen_t addressLength);
218df50f7a9SIngo Weinholdextern status_t		_user_listen(int socket, int backlog);
219df50f7a9SIngo Weinholdextern int			_user_accept(int socket, struct sockaddr *address,
220df50f7a9SIngo Weinhold						socklen_t *_addressLength);
221df50f7a9SIngo Weinholdextern ssize_t		_user_recv(int socket, void *data, size_t length,
222df50f7a9SIngo Weinhold						int flags);
223df50f7a9SIngo Weinholdextern ssize_t		_user_recvfrom(int socket, void *data, size_t length,
224df50f7a9SIngo Weinhold						int flags, struct sockaddr *address,
225df50f7a9SIngo Weinhold						socklen_t *_addressLength);
226df50f7a9SIngo Weinholdextern ssize_t		_user_recvmsg(int socket, struct msghdr *message,
227df50f7a9SIngo Weinhold						int flags);
228df50f7a9SIngo Weinholdextern ssize_t		_user_send(int socket, const void *data, size_t length,
229df50f7a9SIngo Weinhold						int flags);
230df50f7a9SIngo Weinholdextern ssize_t		_user_sendto(int socket, const void *data, size_t length,
231df50f7a9SIngo Weinhold						int flags, const struct sockaddr *address,
232df50f7a9SIngo Weinhold						socklen_t addressLength);
233df50f7a9SIngo Weinholdextern ssize_t		_user_sendmsg(int socket, const struct msghdr *message,
234df50f7a9SIngo Weinhold						int flags);
235df50f7a9SIngo Weinholdextern status_t		_user_getsockopt(int socket, int level, int option,
236df50f7a9SIngo Weinhold						void *value, socklen_t *_length);
237df50f7a9SIngo Weinholdextern status_t		_user_setsockopt(int socket, int level, int option,
238df50f7a9SIngo Weinhold						const void *value, socklen_t length);
239df50f7a9SIngo Weinholdextern status_t		_user_getpeername(int socket, struct sockaddr *address,
240df50f7a9SIngo Weinhold						socklen_t *_addressLength);
241df50f7a9SIngo Weinholdextern status_t		_user_getsockname(int socket, struct sockaddr *address,
242df50f7a9SIngo Weinhold						socklen_t *_addressLength);
243df50f7a9SIngo Weinholdextern int			_user_sockatmark(int socket);
244df50f7a9SIngo Weinholdextern status_t		_user_socketpair(int family, int type, int protocol,
245df50f7a9SIngo Weinhold						int *socketVector);
246df50f7a9SIngo Weinholdextern status_t		_user_get_next_socket_stat(int family, uint32 *cookie,
247df50f7a9SIngo Weinhold						struct net_stat *stat);
248df50f7a9SIngo Weinhold
24952a38012Sejakowatz/* vfs entry points... */
25052a38012Sejakowatz
25152a38012Sejakowatz#ifdef __cplusplus
25252a38012Sejakowatz}
253e6bd90c5SIngo Weinhold#endif
25452a38012Sejakowatz
255071f62bcSAxel Dörfler#endif	/* _KERNEL_VFS_H */
256