xref: /haiku/src/tools/fs_shell/vfs.h (revision 5115ca085884f7b604a3d607688f0ca20fb7cf57)
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 _FSSH_VFS_H
9 #define _FSSH_VFS_H
10 
11 
12 #include "fssh_fs_interface.h"
13 #include "list.h"
14 #include "lock.h"
15 
16 
17 namespace FSShell {
18 
19 
20 /* R5 figures, but we don't use a table for monitors anyway */
21 #define DEFAULT_FD_TABLE_SIZE	128
22 #define MAX_FD_TABLE_SIZE		8192
23 #define DEFAULT_NODE_MONITORS	4096
24 #define MAX_NODE_MONITORS		65536
25 
26 struct kernel_args;
27 struct vm_cache_ref;
28 struct file_descriptor;
29 
30 
31 /** The I/O context of a process/team, holds the fd array among others */
32 typedef struct io_context {
33 	struct vnode 			*cwd;
34 	mutex					io_mutex;
35 	uint32_t				table_size;
36 	uint32_t				num_used_fds;
37 	struct file_descriptor	**fds;
38 	uint8_t					*fds_close_on_exec;
39 } io_context;
40 
41 struct fd_info {
42 	int			number;
43 	int32_t		open_mode;
44 	fssh_dev_t	device;
45 	fssh_ino_t	node;
46 };
47 
48 /* macro to allocate a iovec array on the stack */
49 #define IOVECS(name, size) \
50 	uint8_t _##name[sizeof(fssh_iovecs) + (size)*sizeof(fssh_iovec)]; \
51 	fssh_iovecs *name = (fssh_iovecs *)_##name
52 
53 
54 fssh_status_t	vfs_init(struct kernel_args *args);
55 fssh_status_t	vfs_bootstrap_file_systems(void);
56 void			vfs_mount_boot_file_system(struct kernel_args *args);
57 void			vfs_exec_io_context(void *context);
58 void*			vfs_new_io_context(void *parentContext);
59 fssh_status_t	vfs_free_io_context(void *context);
60 
61 /* calls needed by the VM for paging and by the file cache */
62 int				vfs_get_vnode_from_fd(int fd, bool kernel, void **vnode);
63 fssh_status_t	vfs_get_vnode_from_path(const char *path, bool kernel, void **vnode);
64 fssh_status_t	vfs_get_vnode(fssh_mount_id mountID, fssh_vnode_id vnodeID,
65 					void **_vnode);
66 fssh_status_t	vfs_entry_ref_to_vnode(fssh_mount_id mountID,
67 					fssh_vnode_id directoryID, const char *name, void **_vnode);
68 void			vfs_vnode_to_node_ref(void *_vnode, fssh_mount_id *_mountID,
69 					fssh_vnode_id *_vnodeID);
70 
71 fssh_status_t	vfs_lookup_vnode(fssh_mount_id mountID, fssh_vnode_id vnodeID,
72 					void **_vnode);
73 void			vfs_put_vnode(void *vnode);
74 void			vfs_acquire_vnode(void *vnode);
75 fssh_status_t	vfs_get_cookie_from_fd(int fd, void **_cookie);
76 fssh_status_t	vfs_get_file_map(void *_vnode, fssh_off_t offset,
77 					fssh_size_t size, fssh_file_io_vec *vecs,
78 					fssh_size_t *_count);
79 fssh_status_t	vfs_get_fs_node_from_path(fssh_mount_id mountID,
80 					const char *path, bool kernel, void **_node);
81 fssh_status_t	vfs_stat_vnode(void *_vnode, struct fssh_stat *stat);
82 fssh_status_t	vfs_get_vnode_name(void *vnode, char *name,
83 					fssh_size_t nameSize);
84 fssh_status_t	vfs_get_cwd(fssh_mount_id *_mountID, fssh_vnode_id *_vnodeID);
85 void			vfs_unlock_vnode_if_locked(struct file_descriptor *descriptor);
86 fssh_status_t	vfs_disconnect_vnode(fssh_mount_id mountID,
87 					fssh_vnode_id vnodeID);
88 void			vfs_free_unused_vnodes(int32_t level);
89 
90 /* special module convenience call */
91 fssh_status_t	vfs_get_module_path(const char *basePath,
92 					const char *moduleName, char *pathBuffer,
93 					fssh_size_t bufferSize);
94 
95 /* service call for whoever needs a normalized path */
96 fssh_status_t	vfs_normalize_path(const char *path, char *buffer,
97 					fssh_size_t bufferSize, bool kernel);
98 
99 /* service call for the node monitor */
100 fssh_status_t	resolve_mount_point_to_volume_root(fssh_mount_id mountID,
101 					fssh_vnode_id nodeID, fssh_mount_id *resolvedMountID,
102 					fssh_vnode_id *resolvedNodeID);
103 
104 // cache initialization functions defined in the respective cache implementation
105 extern fssh_status_t block_cache_init();
106 extern fssh_status_t file_cache_init();
107 
108 }	// namespace FSShell
109 
110 
111 #endif	/* _FSSH_VFS_H */
112