xref: /haiku/headers/os/drivers/fs_interface.h (revision 752c2e981efb830325921f02aef01d990db73b1a)
1 /* File System Interface Layer Definition
2 **
3 ** Distributed under the terms of the Haiku License.
4 */
5 #ifndef _FS_INTERFACE_H
6 #define _FS_INTERFACE_H
7 
8 
9 #include <OS.h>
10 #include <Select.h>
11 #include <module.h>
12 
13 #include <sys/uio.h>
14 
15 
16 struct dirent;
17 struct stat;
18 struct fs_info;
19 
20 typedef dev_t mount_id;
21 typedef ino_t vnode_id;
22 
23 /* the file system's private data structures */
24 typedef void *fs_volume;
25 typedef void *fs_cookie;
26 typedef void *fs_vnode;
27 
28 /* passed to write_stat() */
29 enum write_stat_mask {
30 	FS_WRITE_STAT_MODE		= 0x0001,
31 	FS_WRITE_STAT_UID		= 0x0002,
32 	FS_WRITE_STAT_GID		= 0x0004,
33 	FS_WRITE_STAT_SIZE		= 0x0008,
34 	FS_WRITE_STAT_ATIME		= 0x0010,
35 	FS_WRITE_STAT_MTIME		= 0x0020,
36 	FS_WRITE_STAT_CRTIME	= 0x0040
37 	// NOTE: Changing these constants will break
38 	// src/kits/storage/LibBeAdapter.cpp:_kern_write_stat().
39 };
40 
41 /* passed to write_fs_info() */
42 #define	FS_WRITE_FSINFO_NAME	0x0001
43 
44 struct file_io_vec {
45 	off_t	offset;
46 	off_t	length;
47 };
48 
49 #define	B_CURRENT_FS_API_VERSION "/v1"
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 typedef struct file_system_info {
56 	struct module_info	module_info;
57 
58 	/* general operations */
59 	status_t (*mount)(mount_id id, const char *device, void *args, fs_volume *_fs, vnode_id *_rootVnodeID);
60 	status_t (*unmount)(fs_volume fs);
61 
62 	status_t (*read_fs_info)(fs_volume fs, struct fs_info *info);
63 	status_t (*write_fs_info)(fs_volume fs, const struct fs_info *info, uint32 mask);
64 	status_t (*sync)(fs_volume fs);
65 
66 	/* vnode operations */
67 	status_t (*lookup)(fs_volume fs, fs_vnode dir, const char *name, vnode_id *_id, int *_type);
68 	status_t (*get_vnode_name)(fs_volume fs, fs_vnode vnode, char *buffer, size_t bufferSize);
69 
70 	status_t (*get_vnode)(fs_volume fs, vnode_id id, fs_vnode *_vnode, bool reenter);
71 	status_t (*put_vnode)(fs_volume fs, fs_vnode vnode, bool reenter);
72 	status_t (*remove_vnode)(fs_volume fs, fs_vnode vnode, bool reenter);
73 
74 	/* VM file access */
75 	bool (*can_page)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
76 	status_t (*read_pages)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, off_t pos, const iovec *vecs, size_t count, size_t *_numBytes);
77 	status_t (*write_pages)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, off_t pos, const iovec *vecs, size_t count, size_t *_numBytes);
78 
79 	/* cache file access */
80 	status_t (*get_file_map)(fs_volume fs, fs_vnode vnode, off_t offset, size_t size, struct file_io_vec *vecs, size_t *_count);
81 
82 	/* common operations */
83 	status_t (*ioctl)(fs_volume fs, fs_vnode v, fs_cookie cookie, ulong op, void *buffer, size_t length);
84 	status_t (*set_flags)(fs_volume fs, fs_vnode v, fs_cookie cookie, int flags);
85 	status_t (*fsync)(fs_volume fs, fs_vnode v);
86 
87 	ssize_t (*read_link)(fs_volume fs, fs_vnode link, char *buffer, size_t bufferSize);
88 	status_t (*write_link)(fs_volume fs, fs_vnode link, char *toPath);
89 	status_t (*create_symlink)(fs_volume fs, fs_vnode dir, const char *name, const char *path, int mode);
90 
91 	status_t (*link)(fs_volume fs, fs_vnode dir, const char *name, fs_vnode vnode);
92 	status_t (*unlink)(fs_volume fs, fs_vnode dir, const char *name);
93 	status_t (*rename)(fs_volume fs, fs_vnode fromDir, const char *fromName, fs_vnode toDir, const char *toName);
94 
95 	status_t (*access)(fs_volume fs, fs_vnode vnode, int mode);
96 	status_t (*read_stat)(fs_volume fs, fs_vnode vnode, struct stat *stat);
97 	status_t (*write_stat)(fs_volume fs, fs_vnode vnode, const struct stat *stat, uint32 statMask);
98 
99 	/* file operations */
100 	status_t (*create)(fs_volume fs, fs_vnode dir, const char *name, int openMode, int perms, fs_cookie *_cookie, vnode_id *_newVnodeID);
101 	status_t (*open)(fs_volume fs, fs_vnode v, int openMode, fs_cookie *_cookie);
102 	status_t (*close)(fs_volume fs, fs_vnode v, fs_cookie cookie);
103 	status_t (*free_cookie)(fs_volume fs, fs_vnode v, fs_cookie cookie);
104 	status_t (*read)(fs_volume fs, fs_vnode v, fs_cookie cookie, off_t pos, void *buffer, size_t *length);
105 	status_t (*write)(fs_volume fs, fs_vnode v, fs_cookie cookie, off_t pos, const void *buffer, size_t *length);
106 
107 	/* directory operations */
108 	status_t (*create_dir)(fs_volume fs, fs_vnode parent, const char *name, int perms, vnode_id *_newVnodeID);
109 	status_t (*remove_dir)(fs_volume fs, fs_vnode parent, const char *name);
110 	status_t (*open_dir)(fs_volume fs, fs_vnode vnode, fs_cookie *_cookie);
111 	status_t (*close_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
112 	status_t (*free_dir_cookie)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
113 	status_t (*read_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, struct dirent *buffer, size_t bufferSize, uint32 *_num);
114 	status_t (*rewind_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
115 
116 	/* attribute directory operations */
117 	status_t (*open_attr_dir)(fs_volume fs, fs_vnode vnode, fs_cookie *_cookie);
118 	status_t (*close_attr_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
119 	status_t (*free_attr_dir_cookie)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
120 	status_t (*read_attr_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, struct dirent *buffer, size_t bufferSize, uint32 *_num);
121 	status_t (*rewind_attr_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
122 
123 	/* attribute operations */
124 	status_t (*create_attr)(fs_volume fs, fs_vnode file, const char *name, uint32 type, int openMode, fs_cookie *_cookie);
125 	status_t (*open_attr)(fs_volume fs, fs_vnode file, const char *name, int openMode, fs_cookie *_cookie);
126 	status_t (*close_attr)(fs_volume fs, fs_vnode file, fs_cookie cookie);
127 	status_t (*free_attr_cookie)(fs_volume fs, fs_vnode file, fs_cookie cookie);
128 	status_t (*read_attr)(fs_volume fs, fs_vnode file, fs_cookie cookie, off_t pos, void *buffer, size_t *length);
129 	status_t (*write_attr)(fs_volume fs, fs_vnode file, fs_cookie cookie, off_t pos, const void *buffer, size_t *length);
130 
131 	status_t (*read_attr_stat)(fs_volume fs, fs_vnode file, fs_cookie cookie, struct stat *stat);
132 	status_t (*write_attr_stat)(fs_volume fs, fs_vnode file, fs_cookie cookie, const struct stat *stat, int statMask);
133 	status_t (*rename_attr)(fs_volume fs, fs_vnode fromFile, const char *fromName, fs_vnode toFile, const char *toName);
134 	status_t (*remove_attr)(fs_volume fs, fs_vnode file, const char *name);
135 
136 	/* index directory & index operations */
137 	status_t (*open_index_dir)(fs_volume fs, fs_cookie *cookie);
138 	status_t (*close_index_dir)(fs_volume fs, fs_cookie cookie);
139 	status_t (*free_index_dir_cookie)(fs_volume fs, fs_cookie cookie);
140 	status_t (*read_index_dir)(fs_volume fs, fs_cookie cookie, struct dirent *buffer, size_t bufferSize, uint32 *_num);
141 	status_t (*rewind_index_dir)(fs_volume fs, fs_cookie cookie);
142 
143 	status_t (*create_index)(fs_volume fs, const char *name, uint32 type, uint32 flags);
144 	status_t (*remove_index)(fs_volume fs, const char *name);
145 	status_t (*read_index_stat)(fs_volume fs, const char *name, struct stat *stat);
146 
147 	/* query operations */
148 	status_t (*open_query)(fs_volume fs, const char *query, uint32 flags, port_id port, uint32 token, fs_cookie *_cookie);
149 	status_t (*close_query)(fs_volume fs, fs_cookie cookie);
150 	status_t (*free_query_cookie)(fs_volume fs, fs_cookie cookie);
151 	status_t (*read_query)(fs_volume fs, fs_cookie cookie, struct dirent *buffer, size_t bufferSize, uint32 *_num);
152 	status_t (*rewind_query)(fs_volume fs, fs_cookie cookie);
153 } file_system_info;
154 
155 
156 /* file system add-ons only prototypes */
157 extern status_t new_vnode(mount_id mountID, vnode_id vnodeID, fs_vnode privateNode);
158 extern status_t get_vnode(mount_id mountID, vnode_id vnodeID, fs_vnode *_privateNode);
159 extern status_t put_vnode(mount_id mountID, vnode_id vnodeID);
160 extern status_t remove_vnode(mount_id mountID, vnode_id vnodeID);
161 extern status_t unremove_vnode(mount_id mountID, vnode_id vnodeID);
162 
163 extern status_t notify_listener(int op, mount_id device, vnode_id parentNode,
164 					vnode_id toParentNode, vnode_id node, const char *name);
165 extern status_t send_notification(port_id port, long token, ulong what, long op,
166 					mount_id device, mount_id toDevice, vnode_id parentNode,
167 					vnode_id toParentNode, vnode_id node, const char *name);
168 
169 #ifdef __cplusplus
170 }
171 #endif
172 
173 #endif	/* _FS_INTERFACE_H */
174