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