1/*
2 * Copyright 2002-2008, 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 "fssh_lock.h"
14#include "list.h"
15
16
17namespace 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
26struct kernel_args;
27struct vm_cache_ref;
28struct file_descriptor;
29
30
31/** The I/O context of a process/team, holds the fd array among others */
32typedef struct io_context {
33	struct vnode 			*cwd;
34	fssh_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
41struct fd_info {
42	int			number;
43	int32_t		open_mode;
44	fssh_dev_t	device;
45	fssh_ino_t	node;
46};
47
48struct vnode;
49
50/* macro to allocate a iovec array on the stack */
51#define IOVECS(name, size) \
52	uint8_t _##name[sizeof(fssh_iovecs) + (size)*sizeof(fssh_iovec)]; \
53	fssh_iovecs *name = (fssh_iovecs *)_##name
54
55
56fssh_status_t	vfs_init(struct kernel_args *args);
57fssh_status_t	vfs_bootstrap_file_systems(void);
58void			vfs_mount_boot_file_system(struct kernel_args *args);
59void			vfs_exec_io_context(void *context);
60void*			vfs_new_io_context(void *parentContext);
61fssh_status_t	vfs_free_io_context(void *context);
62
63/* calls needed by the VM for paging and by the file cache */
64int				vfs_get_vnode_from_fd(int fd, bool kernel, void **vnode);
65fssh_status_t	vfs_get_vnode_from_path(const char *path, bool kernel, void **vnode);
66fssh_status_t	vfs_get_vnode(fssh_mount_id mountID, fssh_vnode_id vnodeID,
67					void **_vnode);
68fssh_status_t	vfs_entry_ref_to_vnode(fssh_mount_id mountID,
69					fssh_vnode_id directoryID, const char *name, void **_vnode);
70void			vfs_vnode_to_node_ref(void *_vnode, fssh_mount_id *_mountID,
71					fssh_vnode_id *_vnodeID);
72
73fssh_status_t	vfs_lookup_vnode(fssh_mount_id mountID, fssh_vnode_id vnodeID,
74					struct vnode **_vnode);
75void			vfs_put_vnode(void *vnode);
76void			vfs_acquire_vnode(void *vnode);
77fssh_status_t	vfs_get_cookie_from_fd(int fd, void **_cookie);
78fssh_status_t	vfs_read_pages(void *vnode, void *cookie, fssh_off_t pos,
79					const fssh_iovec *vecs, fssh_size_t count,
80					fssh_size_t *_numBytes);
81fssh_status_t	vfs_write_pages(void *vnode, void *cookie,
82					fssh_off_t pos, const fssh_iovec *vecs, fssh_size_t count,
83					fssh_size_t *_numBytes);
84fssh_status_t	vfs_get_file_map(void *_vnode, fssh_off_t offset,
85					fssh_size_t size, fssh_file_io_vec *vecs,
86					fssh_size_t *_count);
87fssh_status_t	vfs_get_fs_node_from_path(fssh_mount_id mountID,
88					const char *path, bool kernel, void **_node);
89fssh_status_t	vfs_stat_vnode(void *_vnode, struct fssh_stat *stat);
90fssh_status_t	vfs_get_vnode_name(void *vnode, char *name,
91					fssh_size_t nameSize);
92fssh_status_t	vfs_get_cwd(fssh_mount_id *_mountID, fssh_vnode_id *_vnodeID);
93void			vfs_unlock_vnode_if_locked(struct file_descriptor *descriptor);
94fssh_status_t	vfs_disconnect_vnode(fssh_mount_id mountID,
95					fssh_vnode_id vnodeID);
96void			vfs_free_unused_vnodes(int32_t level);
97
98/* special module convenience call */
99fssh_status_t	vfs_get_module_path(const char *basePath,
100					const char *moduleName, char *pathBuffer,
101					fssh_size_t bufferSize);
102
103/* service call for whoever needs a normalized path */
104fssh_status_t	vfs_normalize_path(const char *path, char *buffer,
105					fssh_size_t bufferSize, bool kernel);
106
107/* service call for the node monitor */
108fssh_status_t	resolve_mount_point_to_volume_root(fssh_mount_id mountID,
109					fssh_vnode_id nodeID, fssh_mount_id *resolvedMountID,
110					fssh_vnode_id *resolvedNodeID);
111
112// cache initialization functions defined in the respective cache implementation
113extern fssh_status_t block_cache_init();
114extern fssh_status_t file_cache_init();
115
116}	// namespace FSShell
117
118
119#endif	/* _FSSH_VFS_H */
120