xref: /haiku/headers/os/drivers/fs_interface.h (revision 4f00613311d0bd6b70fa82ce19931c41f071ea4e)
1 /* File System Interface Layer Definition
2  *
3  * Copyright 2004-2005, 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, uint32 mask);
78 	status_t (*sync)(fs_volume fs);
79 
80 	/* vnode operations */
81 	status_t (*lookup)(fs_volume fs, fs_vnode dir, const char *name, vnode_id *_id, int *_type);
82 	status_t (*get_vnode_name)(fs_volume fs, fs_vnode vnode, char *buffer, size_t bufferSize);
83 
84 	status_t (*get_vnode)(fs_volume fs, vnode_id id, fs_vnode *_vnode, bool reenter);
85 	status_t (*put_vnode)(fs_volume fs, fs_vnode vnode, bool reenter);
86 	status_t (*remove_vnode)(fs_volume fs, fs_vnode vnode, bool reenter);
87 
88 	/* VM file access */
89 	bool (*can_page)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
90 	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);
91 	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);
92 
93 	/* cache file access */
94 	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);
95 
96 	/* common operations */
97 	status_t (*ioctl)(fs_volume fs, fs_vnode v, fs_cookie cookie, ulong op, void *buffer, size_t length);
98 	status_t (*set_flags)(fs_volume fs, fs_vnode v, fs_cookie cookie, int flags);
99 	status_t (*select)(fs_volume fs, fs_vnode v, fs_cookie cookie, uint8 event,
100 				uint32 ref, selectsync *sync);
101 	status_t (*deselect)(fs_volume fs, fs_vnode v, fs_cookie cookie,
102 				uint8 event, selectsync *sync);
103 	status_t (*fsync)(fs_volume fs, fs_vnode v);
104 
105 	status_t (*read_link)(fs_volume fs, fs_vnode link, char *buffer, size_t *_bufferSize);
106 	status_t (*write_link)(fs_volume fs, fs_vnode link, char *toPath);
107 	status_t (*create_symlink)(fs_volume fs, fs_vnode dir, const char *name, const char *path, int mode);
108 
109 	status_t (*link)(fs_volume fs, fs_vnode dir, const char *name, fs_vnode vnode);
110 	status_t (*unlink)(fs_volume fs, fs_vnode dir, const char *name);
111 	status_t (*rename)(fs_volume fs, fs_vnode fromDir, const char *fromName, fs_vnode toDir, const char *toName);
112 
113 	status_t (*access)(fs_volume fs, fs_vnode vnode, int mode);
114 	status_t (*read_stat)(fs_volume fs, fs_vnode vnode, struct stat *stat);
115 	status_t (*write_stat)(fs_volume fs, fs_vnode vnode, const struct stat *stat, uint32 statMask);
116 
117 	/* file operations */
118 	status_t (*create)(fs_volume fs, fs_vnode dir, const char *name, int openMode, int perms, fs_cookie *_cookie, vnode_id *_newVnodeID);
119 	status_t (*open)(fs_volume fs, fs_vnode v, int openMode, fs_cookie *_cookie);
120 	status_t (*close)(fs_volume fs, fs_vnode v, fs_cookie cookie);
121 	status_t (*free_cookie)(fs_volume fs, fs_vnode v, fs_cookie cookie);
122 	status_t (*read)(fs_volume fs, fs_vnode v, fs_cookie cookie, off_t pos, void *buffer, size_t *length);
123 	status_t (*write)(fs_volume fs, fs_vnode v, fs_cookie cookie, off_t pos, const void *buffer, size_t *length);
124 
125 	/* directory operations */
126 	status_t (*create_dir)(fs_volume fs, fs_vnode parent, const char *name, int perms, vnode_id *_newVnodeID);
127 	status_t (*remove_dir)(fs_volume fs, fs_vnode parent, const char *name);
128 	status_t (*open_dir)(fs_volume fs, fs_vnode vnode, fs_cookie *_cookie);
129 	status_t (*close_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
130 	status_t (*free_dir_cookie)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
131 	status_t (*read_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, struct dirent *buffer, size_t bufferSize, uint32 *_num);
132 	status_t (*rewind_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
133 
134 	/* attribute directory operations */
135 	status_t (*open_attr_dir)(fs_volume fs, fs_vnode vnode, fs_cookie *_cookie);
136 	status_t (*close_attr_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
137 	status_t (*free_attr_dir_cookie)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
138 	status_t (*read_attr_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie, struct dirent *buffer, size_t bufferSize, uint32 *_num);
139 	status_t (*rewind_attr_dir)(fs_volume fs, fs_vnode vnode, fs_cookie cookie);
140 
141 	/* attribute operations */
142 	status_t (*create_attr)(fs_volume fs, fs_vnode file, const char *name, uint32 type, int openMode, fs_cookie *_cookie);
143 	status_t (*open_attr)(fs_volume fs, fs_vnode file, const char *name, int openMode, fs_cookie *_cookie);
144 	status_t (*close_attr)(fs_volume fs, fs_vnode file, fs_cookie cookie);
145 	status_t (*free_attr_cookie)(fs_volume fs, fs_vnode file, fs_cookie cookie);
146 	status_t (*read_attr)(fs_volume fs, fs_vnode file, fs_cookie cookie, off_t pos, void *buffer, size_t *length);
147 	status_t (*write_attr)(fs_volume fs, fs_vnode file, fs_cookie cookie, off_t pos, const void *buffer, size_t *length);
148 
149 	status_t (*read_attr_stat)(fs_volume fs, fs_vnode file, fs_cookie cookie, struct stat *stat);
150 	status_t (*write_attr_stat)(fs_volume fs, fs_vnode file, fs_cookie cookie, const struct stat *stat, int statMask);
151 	status_t (*rename_attr)(fs_volume fs, fs_vnode fromFile, const char *fromName, fs_vnode toFile, const char *toName);
152 	status_t (*remove_attr)(fs_volume fs, fs_vnode file, const char *name);
153 
154 	/* index directory & index operations */
155 	status_t (*open_index_dir)(fs_volume fs, fs_cookie *cookie);
156 	status_t (*close_index_dir)(fs_volume fs, fs_cookie cookie);
157 	status_t (*free_index_dir_cookie)(fs_volume fs, fs_cookie cookie);
158 	status_t (*read_index_dir)(fs_volume fs, fs_cookie cookie, struct dirent *buffer, size_t bufferSize, uint32 *_num);
159 	status_t (*rewind_index_dir)(fs_volume fs, fs_cookie cookie);
160 
161 	status_t (*create_index)(fs_volume fs, const char *name, uint32 type, uint32 flags);
162 	status_t (*remove_index)(fs_volume fs, const char *name);
163 	status_t (*read_index_stat)(fs_volume fs, const char *name, struct stat *stat);
164 
165 	/* query operations */
166 	status_t (*open_query)(fs_volume fs, const char *query, uint32 flags, port_id port, uint32 token, fs_cookie *_cookie);
167 	status_t (*close_query)(fs_volume fs, fs_cookie cookie);
168 	status_t (*free_query_cookie)(fs_volume fs, fs_cookie cookie);
169 	status_t (*read_query)(fs_volume fs, fs_cookie cookie,
170 				struct dirent *buffer, size_t bufferSize, uint32 *_num);
171 	status_t (*rewind_query)(fs_volume fs, fs_cookie cookie);
172 
173 	/* capability querying (the device is read locked) */
174 	// ToDo: this will probably be combined to a single call
175 	bool (*supports_defragmenting)(partition_data *partition,
176 				bool *whileMounted);
177 	bool (*supports_repairing)(partition_data *partition,
178 				bool checkOnly, bool *whileMounted);
179 	bool (*supports_resizing)(partition_data *partition,
180 				bool *whileMounted);
181 	bool (*supports_moving)(partition_data *partition, bool *isNoOp);
182 	bool (*supports_setting_content_name)(partition_data *partition,
183 				bool *whileMounted);
184 	bool (*supports_setting_content_parameters)(partition_data *partition,
185 				bool *whileMounted);
186 	bool (*supports_initializing)(partition_data *partition);
187 
188 	bool (*validate_resize)(partition_data *partition, off_t *size);
189 	bool (*validate_move)(partition_data *partition, off_t *start);
190 	bool (*validate_set_content_name)(partition_data *partition,
191 				char *name);
192 	bool (*validate_set_content_parameters)(partition_data *partition,
193 				const char *parameters);
194 	bool (*validate_initialize)(partition_data *partition, char *name,
195 				const char *parameters);
196 
197 	/* shadow partition modification (device is write locked) */
198 	status_t (*shadow_changed)(partition_data *partition,
199 				uint32 operation);
200 
201 	/* writing (the device is NOT locked) */
202 	status_t (*defragment)(int fd, partition_id partition,
203 				disk_job_id job);
204 	status_t (*repair)(int fd, partition_id partition, bool checkOnly,
205 				disk_job_id job);
206 	status_t (*resize)(int fd, partition_id partition, off_t size,
207 				disk_job_id job);
208 	status_t (*move)(int fd, partition_id partition, off_t offset,
209 				disk_job_id job);
210 	status_t (*set_content_name)(int fd, partition_id partition,
211 				const char *name, disk_job_id job);
212 	status_t (*set_content_parameters)(int fd, partition_id partition,
213 				const char *parameters, disk_job_id job);
214 	status_t (*initialize)(const char *partition, const char *name,
215 				const char *parameters, disk_job_id job);
216 		// This is pretty close to how the hook in R5 looked. Save the job ID, of
217 		// course and that the parameters were given as (void*, size_t) pair.
218 } file_system_module_info;
219 
220 
221 /* file system add-ons only prototypes */
222 extern status_t new_vnode(mount_id mountID, vnode_id vnodeID, fs_vnode privateNode);
223 extern status_t publish_vnode(mount_id mountID, vnode_id vnodeID, fs_vnode privateNode);
224 extern status_t get_vnode(mount_id mountID, vnode_id vnodeID, fs_vnode *_privateNode);
225 extern status_t put_vnode(mount_id mountID, vnode_id vnodeID);
226 extern status_t remove_vnode(mount_id mountID, vnode_id vnodeID);
227 extern status_t unremove_vnode(mount_id mountID, vnode_id vnodeID);
228 
229 extern status_t notify_listener(int op, mount_id device, vnode_id parentNode,
230 					vnode_id toParentNode, vnode_id node, const char *name);
231 extern status_t send_notification(port_id port, long token, ulong what, long op,
232 					mount_id device, mount_id toDevice, vnode_id parentNode,
233 					vnode_id toParentNode, vnode_id node, const char *name);
234 
235 extern status_t notify_entry_created(mount_id device, vnode_id directory,
236 					const char *name, vnode_id node);
237 extern status_t notify_entry_removed(mount_id device, vnode_id directory,
238 					const char *name, vnode_id node);
239 extern status_t notify_entry_moved(mount_id device, vnode_id fromDirectory,
240 					const char *fromName, vnode_id toDirectory,
241 					const char *toName, vnode_id node);
242 extern status_t notify_stat_changed(mount_id device, vnode_id node,
243 					uint32 statFields);
244 extern status_t notify_attribute_changed(mount_id device, vnode_id node,
245 					const char *attribute, int32 cause);
246 
247 extern status_t notify_query_entry_created(port_id port, int32 token,
248 					mount_id device, vnode_id directory, const char *name,
249 					vnode_id node);
250 extern status_t notify_query_entry_removed(port_id port, int32 token,
251 					mount_id device, vnode_id directory, const char *name,
252 					vnode_id node);
253 
254 #ifdef __cplusplus
255 }
256 #endif
257 
258 #endif	/* _FS_INTERFACE_H */
259