xref: /haiku/headers/os/drivers/fs_interface.h (revision 079eccf655ba39812b421ae1b87a727d41b50354)
1 /*
2  * Copyright 2004-2008, Haiku Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _FS_INTERFACE_H
6 #define _FS_INTERFACE_H
7 
8 /*! File System Interface Layer Definition */
9 
10 
11 #include <OS.h>
12 #include <Select.h>
13 #include <module.h>
14 #include <disk_device_manager.h>
15 
16 #include <sys/uio.h>
17 
18 
19 struct dirent;
20 struct stat;
21 struct fs_info;
22 struct select_sync;
23 
24 /* additional flags passed to write_stat() (see NodeMonitor.h for the others) */
25 // NOTE: Changing the constants here or in NodeMonitor.h will break
26 // src/kits/storage/LibBeAdapter.cpp:_kern_write_stat().
27 #define B_STAT_SIZE_INSECURE	0x2000
28 	// TODO: this should be faded out once BFS supports sparse files
29 
30 /* passed to write_fs_info() */
31 #define	FS_WRITE_FSINFO_NAME	0x0001
32 
33 struct file_io_vec {
34 	off_t	offset;
35 	off_t	length;
36 };
37 
38 #define	B_CURRENT_FS_API_VERSION "/v1"
39 
40 // flags for publish_vnode() and fs_volume_ops::get_vnode()
41 #define B_VNODE_PUBLISH_REMOVED					0x01
42 #define B_VNODE_DONT_CREATE_SPECIAL_SUB_NODE	0x02
43 
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 typedef struct fs_volume fs_volume;
50 typedef struct fs_volume_ops fs_volume_ops;
51 typedef struct fs_vnode fs_vnode;
52 typedef struct fs_vnode_ops fs_vnode_ops;
53 
54 
55 struct fs_volume {
56 	dev_t			id;
57 	int32			layer;
58 	void*			private_volume;
59 	fs_volume_ops*	ops;
60 	fs_volume*		sub_volume;
61 	fs_volume*		super_volume;
62 };
63 
64 struct fs_vnode {
65 	void*			private_node;
66 	fs_vnode_ops*	ops;
67 };
68 
69 struct fs_volume_ops {
70 	status_t (*unmount)(fs_volume *volume);
71 
72 	status_t (*read_fs_info)(fs_volume *volume, struct fs_info *info);
73 	status_t (*write_fs_info)(fs_volume *volume, const struct fs_info *info,
74 				uint32 mask);
75 	status_t (*sync)(fs_volume *volume);
76 
77 	status_t (*get_vnode)(fs_volume *volume, ino_t id, fs_vnode *vnode,
78 				int *_type, uint32 *_flags, bool reenter);
79 
80 	/* index directory & index operations */
81 	status_t (*open_index_dir)(fs_volume *volume, void **cookie);
82 	status_t (*close_index_dir)(fs_volume *volume, void *cookie);
83 	status_t (*free_index_dir_cookie)(fs_volume *volume, void *cookie);
84 	status_t (*read_index_dir)(fs_volume *volume, void *cookie,
85 				struct dirent *buffer, size_t bufferSize, uint32 *_num);
86 	status_t (*rewind_index_dir)(fs_volume *volume, void *cookie);
87 
88 	status_t (*create_index)(fs_volume *volume, const char *name, uint32 type,
89 				uint32 flags);
90 	status_t (*remove_index)(fs_volume *volume, const char *name);
91 	status_t (*read_index_stat)(fs_volume *volume, const char *name,
92 				struct stat *stat);
93 
94 	/* query operations */
95 	status_t (*open_query)(fs_volume *volume, const char *query, uint32 flags,
96 				port_id port, uint32 token, void **_cookie);
97 	status_t (*close_query)(fs_volume *volume, void *cookie);
98 	status_t (*free_query_cookie)(fs_volume *volume, void *cookie);
99 	status_t (*read_query)(fs_volume *volume, void *cookie,
100 				struct dirent *buffer, size_t bufferSize, uint32 *_num);
101 	status_t (*rewind_query)(fs_volume *volume, void *cookie);
102 
103 	/* support for FS layers */
104 	status_t (*create_sub_vnode)(fs_volume *volume, ino_t id, fs_vnode *vnode);
105 	status_t (*delete_sub_vnode)(fs_volume *volume, fs_vnode *vnode);
106 };
107 
108 struct fs_vnode_ops {
109 	/* vnode operations */
110 	status_t (*lookup)(fs_volume *volume, fs_vnode *dir, const char *name,
111 				ino_t *_id);
112 	status_t (*get_vnode_name)(fs_volume *volume, fs_vnode *vnode, char *buffer,
113 				size_t bufferSize);
114 
115 	status_t (*put_vnode)(fs_volume *volume, fs_vnode *vnode, bool reenter);
116 	status_t (*remove_vnode)(fs_volume *volume, fs_vnode *vnode, bool reenter);
117 
118 	/* VM file access */
119 	bool (*can_page)(fs_volume *volume, fs_vnode *vnode, void *cookie);
120 	status_t (*read_pages)(fs_volume *volume, fs_vnode *vnode, void *cookie,
121 				off_t pos, const iovec *vecs, size_t count, size_t *_numBytes,
122 				bool reenter);
123 	status_t (*write_pages)(fs_volume *volume, fs_vnode *vnode,
124 				void *cookie, off_t pos, const iovec *vecs, size_t count,
125 				size_t *_numBytes, bool reenter);
126 
127 	/* cache file access */
128 	status_t (*get_file_map)(fs_volume *volume, fs_vnode *vnode, off_t offset,
129 				size_t size, struct file_io_vec *vecs, size_t *_count);
130 
131 	/* common operations */
132 	status_t (*ioctl)(fs_volume *volume, fs_vnode *vnode, void *cookie,
133 				ulong op, void *buffer, size_t length);
134 	status_t (*set_flags)(fs_volume *volume, fs_vnode *vnode, void *cookie,
135 				int flags);
136 	status_t (*select)(fs_volume *volume, fs_vnode *vnode, void *cookie,
137 				uint8 event, selectsync *sync);
138 	status_t (*deselect)(fs_volume *volume, fs_vnode *vnode, void *cookie,
139 				uint8 event, selectsync *sync);
140 	status_t (*fsync)(fs_volume *volume, fs_vnode *vnode);
141 
142 	status_t (*read_symlink)(fs_volume *volume, fs_vnode *link, char *buffer,
143 				size_t *_bufferSize);
144 	status_t (*create_symlink)(fs_volume *volume, fs_vnode *dir,
145 				const char *name, const char *path, int mode);
146 
147 	status_t (*link)(fs_volume *volume, fs_vnode *dir, const char *name,
148 				fs_vnode *vnode);
149 	status_t (*unlink)(fs_volume *volume, fs_vnode *dir, const char *name);
150 	status_t (*rename)(fs_volume *volume, fs_vnode *fromDir,
151 				const char *fromName, fs_vnode *toDir, const char *toName);
152 
153 	status_t (*access)(fs_volume *volume, fs_vnode *vnode, int mode);
154 	status_t (*read_stat)(fs_volume *volume, fs_vnode *vnode,
155 				struct stat *stat);
156 	status_t (*write_stat)(fs_volume *volume, fs_vnode *vnode,
157 				const struct stat *stat, uint32 statMask);
158 
159 	/* file operations */
160 	status_t (*create)(fs_volume *volume, fs_vnode *dir, const char *name,
161 				int openMode, int perms, void **_cookie,
162 				ino_t *_newVnodeID);
163 	status_t (*open)(fs_volume *volume, fs_vnode *vnode, int openMode,
164 				void **_cookie);
165 	status_t (*close)(fs_volume *volume, fs_vnode *vnode, void *cookie);
166 	status_t (*free_cookie)(fs_volume *volume, fs_vnode *vnode,
167 				void *cookie);
168 	status_t (*read)(fs_volume *volume, fs_vnode *vnode, void *cookie,
169 				off_t pos, void *buffer, size_t *length);
170 	status_t (*write)(fs_volume *volume, fs_vnode *vnode, void *cookie,
171 				off_t pos, const void *buffer, size_t *length);
172 
173 	/* directory operations */
174 	status_t (*create_dir)(fs_volume *volume, fs_vnode *parent,
175 				const char *name, int perms, ino_t *_newVnodeID);
176 	status_t (*remove_dir)(fs_volume *volume, fs_vnode *parent,
177 				const char *name);
178 	status_t (*open_dir)(fs_volume *volume, fs_vnode *vnode,
179 				void **_cookie);
180 	status_t (*close_dir)(fs_volume *volume, fs_vnode *vnode, void *cookie);
181 	status_t (*free_dir_cookie)(fs_volume *volume, fs_vnode *vnode,
182 				void *cookie);
183 	status_t (*read_dir)(fs_volume *volume, fs_vnode *vnode, void *cookie,
184 				struct dirent *buffer, size_t bufferSize, uint32 *_num);
185 	status_t (*rewind_dir)(fs_volume *volume, fs_vnode *vnode,
186 				void *cookie);
187 
188 	/* attribute directory operations */
189 	status_t (*open_attr_dir)(fs_volume *volume, fs_vnode *vnode,
190 				void **_cookie);
191 	status_t (*close_attr_dir)(fs_volume *volume, fs_vnode *vnode,
192 				void *cookie);
193 	status_t (*free_attr_dir_cookie)(fs_volume *volume, fs_vnode *vnode,
194 				void *cookie);
195 	status_t (*read_attr_dir)(fs_volume *volume, fs_vnode *vnode,
196 				void *cookie, struct dirent *buffer, size_t bufferSize,
197 				uint32 *_num);
198 	status_t (*rewind_attr_dir)(fs_volume *volume, fs_vnode *vnode,
199 				void *cookie);
200 
201 	/* attribute operations */
202 	status_t (*create_attr)(fs_volume *volume, fs_vnode *vnode,
203 				const char *name, uint32 type, int openMode,
204 				void **_cookie);
205 	status_t (*open_attr)(fs_volume *volume, fs_vnode *vnode, const char *name,
206 				int openMode, void **_cookie);
207 	status_t (*close_attr)(fs_volume *volume, fs_vnode *vnode,
208 				void *cookie);
209 	status_t (*free_attr_cookie)(fs_volume *volume, fs_vnode *vnode,
210 				void *cookie);
211 	status_t (*read_attr)(fs_volume *volume, fs_vnode *vnode, void *cookie,
212 				off_t pos, void *buffer, size_t *length);
213 	status_t (*write_attr)(fs_volume *volume, fs_vnode *vnode, void *cookie,
214 				off_t pos, const void *buffer, size_t *length);
215 
216 	status_t (*read_attr_stat)(fs_volume *volume, fs_vnode *vnode,
217 				void *cookie, struct stat *stat);
218 	status_t (*write_attr_stat)(fs_volume *volume, fs_vnode *vnode,
219 				void *cookie, const struct stat *stat, int statMask);
220 	status_t (*rename_attr)(fs_volume *volume, fs_vnode *fromVnode,
221 				const char *fromName, fs_vnode *toVnode, const char *toName);
222 	status_t (*remove_attr)(fs_volume *volume, fs_vnode *vnode,
223 				const char *name);
224 
225 	/* support for node and FS layers */
226 	status_t (*create_special_node)(fs_volume *volume, fs_vnode *dir,
227 				const char *name, fs_vnode *subVnode, mode_t mode, uint32 flags,
228 				fs_vnode *_superVnode, ino_t *_nodeID);
229 	status_t (*get_super_vnode)(fs_volume *volume, fs_vnode *vnode,
230 				fs_volume *superVolume, fs_vnode *superVnode);
231 };
232 
233 typedef struct file_system_module_info {
234 	struct module_info	info;
235 	const char*			short_name;
236 	const char*			pretty_name;
237 	uint32				flags;	// DDM flags
238 
239 	/* scanning (the device is write locked) */
240 	float (*identify_partition)(int fd, partition_data *partition,
241 				void **cookie);
242 	status_t (*scan_partition)(int fd, partition_data *partition,
243 				void *cookie);
244 	void (*free_identify_partition_cookie)(partition_data *partition,
245 				void *cookie);
246 	void (*free_partition_content_cookie)(partition_data *partition);
247 
248 	/* general operations */
249 	status_t (*mount)(fs_volume *volume, const char *device, uint32 flags,
250 				const char *args, ino_t *_rootVnodeID);
251 
252 	/* capability querying (the device is read locked) */
253 	uint32 (*get_supported_operations)(partition_data* partition, uint32 mask);
254 
255 	bool (*validate_resize)(partition_data *partition, off_t *size);
256 	bool (*validate_move)(partition_data *partition, off_t *start);
257 	bool (*validate_set_content_name)(partition_data *partition,
258 				char *name);
259 	bool (*validate_set_content_parameters)(partition_data *partition,
260 				const char *parameters);
261 	bool (*validate_initialize)(partition_data *partition, char *name,
262 				const char *parameters);
263 
264 	/* shadow partition modification (device is write locked) */
265 	status_t (*shadow_changed)(partition_data *partition,
266 				partition_data *child, uint32 operation);
267 
268 	/* writing (the device is NOT locked) */
269 	status_t (*defragment)(int fd, partition_id partition,
270 				disk_job_id job);
271 	status_t (*repair)(int fd, partition_id partition, bool checkOnly,
272 				disk_job_id job);
273 	status_t (*resize)(int fd, partition_id partition, off_t size,
274 				disk_job_id job);
275 	status_t (*move)(int fd, partition_id partition, off_t offset,
276 				disk_job_id job);
277 	status_t (*set_content_name)(int fd, partition_id partition,
278 				const char *name, disk_job_id job);
279 	status_t (*set_content_parameters)(int fd, partition_id partition,
280 				const char *parameters, disk_job_id job);
281 	status_t (*initialize)(int fd, partition_id partition, const char *name,
282 				const char *parameters, off_t partitionSize, disk_job_id job);
283 } file_system_module_info;
284 
285 
286 /* file system add-ons only prototypes */
287 extern status_t new_vnode(fs_volume *volume, ino_t vnodeID, void *privateNode,
288 					fs_vnode_ops *ops);
289 extern status_t publish_vnode(fs_volume *volume, ino_t vnodeID,
290 					void *privateNode, fs_vnode_ops *ops, int type,
291 					uint32 flags);
292 extern status_t get_vnode(fs_volume *volume, ino_t vnodeID,
293 					void **_privateNode);
294 extern status_t put_vnode(fs_volume *volume, ino_t vnodeID);
295 extern status_t remove_vnode(fs_volume *volume, ino_t vnodeID);
296 extern status_t unremove_vnode(fs_volume *volume, ino_t vnodeID);
297 extern status_t get_vnode_removed(fs_volume *volume, ino_t vnodeID,
298 					bool *removed);
299 
300 extern status_t read_pages(int fd, off_t pos, const struct iovec *vecs,
301 					size_t count, size_t *_numBytes, bool fsReenter);
302 extern status_t write_pages(int fd, off_t pos, const struct iovec *vecs,
303 					size_t count, size_t *_numBytes, bool fsReenter);
304 extern status_t read_file_io_vec_pages(int fd,
305 					const struct file_io_vec *fileVecs, size_t fileVecCount,
306 					const struct iovec *vecs, size_t vecCount,
307 					uint32 *_vecIndex, size_t *_vecOffset, size_t *_bytes);
308 extern status_t write_file_io_vec_pages(int fd,
309 					const struct file_io_vec *fileVecs, size_t fileVecCount,
310 					const struct iovec *vecs, size_t vecCount,
311 					uint32 *_vecIndex, size_t *_vecOffset, size_t *_bytes);
312 
313 extern status_t notify_entry_created(dev_t device, ino_t directory,
314 					const char *name, ino_t node);
315 extern status_t notify_entry_removed(dev_t device, ino_t directory,
316 					const char *name, ino_t node);
317 extern status_t notify_entry_moved(dev_t device, ino_t fromDirectory,
318 					const char *fromName, ino_t toDirectory,
319 					const char *toName, ino_t node);
320 extern status_t notify_stat_changed(dev_t device, ino_t node,
321 					uint32 statFields);
322 extern status_t notify_attribute_changed(dev_t device, ino_t node,
323 					const char *attribute, int32 cause);
324 
325 extern status_t notify_query_entry_created(port_id port, int32 token,
326 					dev_t device, ino_t directory, const char *name,
327 					ino_t node);
328 extern status_t notify_query_entry_removed(port_id port, int32 token,
329 					dev_t device, ino_t directory, const char *name,
330 					ino_t node);
331 
332 #ifdef __cplusplus
333 }
334 #endif
335 
336 #endif	/* _FS_INTERFACE_H */
337