xref: /haiku/headers/os/drivers/fs_interface.h (revision 1e36cfc2721ef13a187c6f7354dc9cbc485e89d3)
1 /* File System Interface Layer Definition
2  *
3  * Copyright 2004-2006, Haiku Inc. All Rights Reserved.
4  * Distributed under the terms of the MIT License.
5  */
6 #ifndef _FS_INTERFACE_H
7 #define _FS_INTERFACE_H
8 
9 
10 #include <OS.h>
11 #include <Select.h>
12 #include <module.h>
13 #include <disk_device_manager.h>
14 
15 #include <sys/uio.h>
16 
17 
18 struct dirent;
19 struct stat;
20 struct fs_info;
21 struct select_sync;
22 
23 typedef dev_t mount_id;
24 typedef ino_t vnode_id;
25 
26 /* the file system's private data structures */
27 typedef void *fs_volume;
28 typedef void *fs_cookie;
29 typedef void *fs_vnode;
30 
31 /* passed to write_stat() */
32 enum write_stat_mask {
33 	FS_WRITE_STAT_MODE		= 0x0001,
34 	FS_WRITE_STAT_UID		= 0x0002,
35 	FS_WRITE_STAT_GID		= 0x0004,
36 	FS_WRITE_STAT_SIZE		= 0x0008,
37 	FS_WRITE_STAT_ATIME		= 0x0010,
38 	FS_WRITE_STAT_MTIME		= 0x0020,
39 	FS_WRITE_STAT_CRTIME	= 0x0040
40 	// NOTE: Changing these constants will break
41 	// src/kits/storage/LibBeAdapter.cpp:_kern_write_stat().
42 };
43 
44 /* passed to write_fs_info() */
45 #define	FS_WRITE_FSINFO_NAME	0x0001
46 
47 struct file_io_vec {
48 	off_t	offset;
49 	off_t	length;
50 };
51 
52 #define	B_CURRENT_FS_API_VERSION "/v1"
53 
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57 
58 typedef struct file_system_module_info {
59 	struct module_info	info;
60 	const char			*pretty_name;
61 
62 	/* scanning (the device is write locked) */
63 	float (*identify_partition)(int fd, partition_data *partition,
64 				void **cookie);
65 	status_t (*scan_partition)(int fd, partition_data *partition,
66 				void *cookie);
67 	void (*free_identify_partition_cookie)(partition_data *partition,
68 				void *cookie);
69 	void (*free_partition_content_cookie)(partition_data *partition);
70 
71 	/* general operations */
72 	status_t (*mount)(mount_id id, const char *device, uint32 flags,
73 				const char *args, fs_volume *_fs, vnode_id *_rootVnodeID);
74 	status_t (*unmount)(fs_volume fs);
75 
76 	status_t (*read_fs_info)(fs_volume fs, struct fs_info *info);
77 	status_t (*write_fs_info)(fs_volume fs, const struct fs_info *info,
78 				uint32 mask);
79 	status_t (*sync)(fs_volume fs);
80 
81 	/* vnode operations */
82 	status_t (*lookup)(fs_volume fs, fs_vnode dir, const char *name,
83 				vnode_id *_id, int *_type);
84 	status_t (*get_vnode_name)(fs_volume fs, fs_vnode vnode, char *buffer,
85 				size_t bufferSize);
86 
87 	status_t (*get_vnode)(fs_volume fs, vnode_id id, fs_vnode *_vnode,
88 				bool reenter);
89 	status_t (*put_vnode)(fs_volume fs, fs_vnode vnode, bool reenter);
90 	status_t (*remove_vnode)(fs_volume fs, fs_vnode vnode, bool reenter);
91 
92 	/* VM file access */
93 	bool (*can_page)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
94 	status_t (*read_pages)(fs_volume fs, fs_vnode vnode, fs_cookie cookie,
95 				off_t pos, const iovec *vecs, size_t count, size_t *_numBytes,
96 				bool reenter);
97 	status_t (*write_pages)(fs_volume fs, fs_vnode vnode, fs_cookie cookie,
98 				off_t pos, const iovec *vecs, size_t count, size_t *_numBytes,
99 				bool reenter);
100 
101 	/* cache file access */
102 	status_t (*get_file_map)(fs_volume fs, fs_vnode vnode, off_t offset,
103 				size_t size, struct file_io_vec *vecs, size_t *_count);
104 
105 	/* common operations */
106 	status_t (*ioctl)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, ulong op,
107 				void *buffer, size_t length);
108 	status_t (*set_flags)(fs_volume fs, fs_vnode vnode, fs_cookie cookie,
109 				int flags);
110 	status_t (*select)(fs_volume fs, fs_vnode vnode, fs_cookie cookie,
111 				uint8 event, uint32 ref, selectsync *sync);
112 	status_t (*deselect)(fs_volume fs, fs_vnode vnode, fs_cookie cookie,
113 				uint8 event, selectsync *sync);
114 	status_t (*fsync)(fs_volume fs, fs_vnode vnode);
115 
116 	status_t (*read_symlink)(fs_volume fs, fs_vnode link, char *buffer,
117 				size_t *_bufferSize);
118 	status_t (*create_symlink)(fs_volume fs, fs_vnode dir, const char *name,
119 				const char *path, int mode);
120 
121 	status_t (*link)(fs_volume fs, fs_vnode dir, const char *name,
122 				fs_vnode vnode);
123 	status_t (*unlink)(fs_volume fs, fs_vnode dir, const char *name);
124 	status_t (*rename)(fs_volume fs, fs_vnode fromDir, const char *fromName,
125 				fs_vnode toDir, const char *toName);
126 
127 	status_t (*access)(fs_volume fs, fs_vnode vnode, int mode);
128 	status_t (*read_stat)(fs_volume fs, fs_vnode vnode, struct stat *stat);
129 	status_t (*write_stat)(fs_volume fs, fs_vnode vnode,
130 				const struct stat *stat, uint32 statMask);
131 
132 	/* file operations */
133 	status_t (*create)(fs_volume fs, fs_vnode dir, const char *name,
134 				int openMode, int perms, fs_cookie *_cookie,
135 				vnode_id *_newVnodeID);
136 	status_t (*open)(fs_volume fs, fs_vnode vnode, int openMode,
137 				fs_cookie *_cookie);
138 	status_t (*close)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
139 	status_t (*free_cookie)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
140 	status_t (*read)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, off_t pos,
141 				void *buffer, size_t *length);
142 	status_t (*write)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, off_t pos,
143 				const void *buffer, size_t *length);
144 
145 	/* directory operations */
146 	status_t (*create_dir)(fs_volume fs, fs_vnode parent, const char *name,
147 				int perms, vnode_id *_newVnodeID);
148 	status_t (*remove_dir)(fs_volume fs, fs_vnode parent, const char *name);
149 	status_t (*open_dir)(fs_volume fs, fs_vnode vnode, fs_cookie *_cookie);
150 	status_t (*close_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
151 	status_t (*free_dir_cookie)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
152 	status_t (*read_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie,
153 				struct dirent *buffer, size_t bufferSize, uint32 *_num);
154 	status_t (*rewind_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
155 
156 	/* attribute directory operations */
157 	status_t (*open_attr_dir)(fs_volume fs, fs_vnode vnode, fs_cookie *_cookie);
158 	status_t (*close_attr_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
159 	status_t (*free_attr_dir_cookie)(fs_volume fs, fs_vnode vnode,
160 				fs_cookie cookie);
161 	status_t (*read_attr_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie,
162 				struct dirent *buffer, size_t bufferSize, uint32 *_num);
163 	status_t (*rewind_attr_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
164 
165 	/* attribute operations */
166 	status_t (*create_attr)(fs_volume fs, fs_vnode vnode, const char *name,
167 				uint32 type, int openMode, fs_cookie *_cookie);
168 	status_t (*open_attr)(fs_volume fs, fs_vnode vnode, const char *name,
169 				int openMode, fs_cookie *_cookie);
170 	status_t (*close_attr)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
171 	status_t (*free_attr_cookie)(fs_volume fs, fs_vnode vnode,
172 				fs_cookie cookie);
173 	status_t (*read_attr)(fs_volume fs, fs_vnode vnode, fs_cookie cookie,
174 				off_t pos, void *buffer, size_t *length);
175 	status_t (*write_attr)(fs_volume fs, fs_vnode vnode, fs_cookie cookie,
176 				off_t pos, const void *buffer, size_t *length);
177 
178 	status_t (*read_attr_stat)(fs_volume fs, fs_vnode vnode, fs_cookie cookie,
179 				struct stat *stat);
180 	status_t (*write_attr_stat)(fs_volume fs, fs_vnode vnode, fs_cookie cookie,
181 				const struct stat *stat, int statMask);
182 	status_t (*rename_attr)(fs_volume fs, fs_vnode fromVnode,
183 				const char *fromName, fs_vnode toVnode, const char *toName);
184 	status_t (*remove_attr)(fs_volume fs, fs_vnode vnode, const char *name);
185 
186 	/* index directory & index operations */
187 	status_t (*open_index_dir)(fs_volume fs, fs_cookie *cookie);
188 	status_t (*close_index_dir)(fs_volume fs, fs_cookie cookie);
189 	status_t (*free_index_dir_cookie)(fs_volume fs, fs_cookie cookie);
190 	status_t (*read_index_dir)(fs_volume fs, fs_cookie cookie,
191 				struct dirent *buffer, size_t bufferSize, uint32 *_num);
192 	status_t (*rewind_index_dir)(fs_volume fs, fs_cookie cookie);
193 
194 	status_t (*create_index)(fs_volume fs, const char *name, uint32 type,
195 				uint32 flags);
196 	status_t (*remove_index)(fs_volume fs, const char *name);
197 	status_t (*read_index_stat)(fs_volume fs, const char *name,
198 				struct stat *stat);
199 
200 	/* query operations */
201 	status_t (*open_query)(fs_volume fs, const char *query, uint32 flags,
202 				port_id port, uint32 token, fs_cookie *_cookie);
203 	status_t (*close_query)(fs_volume fs, fs_cookie cookie);
204 	status_t (*free_query_cookie)(fs_volume fs, fs_cookie cookie);
205 	status_t (*read_query)(fs_volume fs, fs_cookie cookie,
206 				struct dirent *buffer, size_t bufferSize, uint32 *_num);
207 	status_t (*rewind_query)(fs_volume fs, fs_cookie cookie);
208 
209 	/* capability querying (the device is read locked) */
210 	// ToDo: this will probably be combined to a single call
211 	bool (*supports_defragmenting)(partition_data *partition,
212 				bool *whileMounted);
213 	bool (*supports_repairing)(partition_data *partition,
214 				bool checkOnly, bool *whileMounted);
215 	bool (*supports_resizing)(partition_data *partition,
216 				bool *whileMounted);
217 	bool (*supports_moving)(partition_data *partition, bool *isNoOp);
218 	bool (*supports_setting_content_name)(partition_data *partition,
219 				bool *whileMounted);
220 	bool (*supports_setting_content_parameters)(partition_data *partition,
221 				bool *whileMounted);
222 	bool (*supports_initializing)(partition_data *partition);
223 
224 	bool (*validate_resize)(partition_data *partition, off_t *size);
225 	bool (*validate_move)(partition_data *partition, off_t *start);
226 	bool (*validate_set_content_name)(partition_data *partition,
227 				char *name);
228 	bool (*validate_set_content_parameters)(partition_data *partition,
229 				const char *parameters);
230 	bool (*validate_initialize)(partition_data *partition, char *name,
231 				const char *parameters);
232 
233 	/* shadow partition modification (device is write locked) */
234 	status_t (*shadow_changed)(partition_data *partition,
235 				uint32 operation);
236 
237 	/* writing (the device is NOT locked) */
238 	status_t (*defragment)(int fd, partition_id partition,
239 				disk_job_id job);
240 	status_t (*repair)(int fd, partition_id partition, bool checkOnly,
241 				disk_job_id job);
242 	status_t (*resize)(int fd, partition_id partition, off_t size,
243 				disk_job_id job);
244 	status_t (*move)(int fd, partition_id partition, off_t offset,
245 				disk_job_id job);
246 	status_t (*set_content_name)(int fd, partition_id partition,
247 				const char *name, disk_job_id job);
248 	status_t (*set_content_parameters)(int fd, partition_id partition,
249 				const char *parameters, disk_job_id job);
250 	status_t (*initialize)(const char *partition, const char *name,
251 				const char *parameters, disk_job_id job);
252 		// This is pretty close to how the hook in R5 looked. Save the job ID,
253 		// of course and that the parameters were given as (void*, size_t) pair.
254 } file_system_module_info;
255 
256 
257 /* file system add-ons only prototypes */
258 extern status_t new_vnode(mount_id mountID, vnode_id vnodeID,
259 					fs_vnode privateNode);
260 extern status_t publish_vnode(mount_id mountID, vnode_id vnodeID,
261 					fs_vnode privateNode);
262 extern status_t get_vnode(mount_id mountID, vnode_id vnodeID,
263 					fs_vnode *_privateNode);
264 extern status_t put_vnode(mount_id mountID, vnode_id vnodeID);
265 extern status_t remove_vnode(mount_id mountID, vnode_id vnodeID);
266 extern status_t unremove_vnode(mount_id mountID, vnode_id vnodeID);
267 extern status_t get_vnode_removed(mount_id mountID, vnode_id vnodeID,
268 					bool* removed);
269 
270 // Deprecated! Will disappear soon!
271 extern status_t notify_listener(int op, mount_id device, vnode_id parentNode,
272 					vnode_id toParentNode, vnode_id node, const char *name);
273 
274 extern status_t notify_entry_created(mount_id device, vnode_id directory,
275 					const char *name, vnode_id node);
276 extern status_t notify_entry_removed(mount_id device, vnode_id directory,
277 					const char *name, vnode_id node);
278 extern status_t notify_entry_moved(mount_id device, vnode_id fromDirectory,
279 					const char *fromName, vnode_id toDirectory,
280 					const char *toName, vnode_id node);
281 extern status_t notify_stat_changed(mount_id device, vnode_id node,
282 					uint32 statFields);
283 extern status_t notify_attribute_changed(mount_id device, vnode_id node,
284 					const char *attribute, int32 cause);
285 
286 extern status_t notify_query_entry_created(port_id port, int32 token,
287 					mount_id device, vnode_id directory, const char *name,
288 					vnode_id node);
289 extern status_t notify_query_entry_removed(port_id port, int32 token,
290 					mount_id device, vnode_id directory, const char *name,
291 					vnode_id node);
292 
293 #ifdef __cplusplus
294 }
295 #endif
296 
297 #endif	/* _FS_INTERFACE_H */
298