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