xref: /haiku/src/add-ons/kernel/file_systems/xfs/kernel_interface.cpp (revision adcf5b05a8ca9e17407aa4640675c3873c9f0a6c)
1 /*
2  * Copyright 2020 Shubham Bhagat, shubhambhagat111@yahoo.com
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 #include "system_dependencies.h"
6 
7 #ifdef TRACE_XFS
8 #define TRACE(x...) dprintf("\33[34mxfs:\33[0m " x)
9 #else
10 #define TRACE(x...) ;
11 #endif
12 
13 
14 struct identify_cookie
15 {
16 	/*	super_block_struct super_block;
17 	 *	No structure yet implemented.
18 	 */
19 	int cookie;
20 };
21 
22 
23 //!	xfs_io() callback hook
24 static status_t
25 iterative_io_get_vecs_hook(void *cookie, io_request *request, off_t offset,
26 						size_t size, struct file_io_vec *vecs, size_t *_count)
27 {
28 	return B_NOT_SUPPORTED;
29 }
30 
31 
32 //!	xfs_io() callback hook
33 static status_t
34 iterative_io_finished_hook(void *cookie, io_request *request, status_t status,
35 						   bool partialTransfer, size_t bytesTransferred)
36 {
37 	return B_NOT_SUPPORTED;
38 }
39 
40 
41 //	#pragma mark - Scanning
42 static float
43 xfs_identify_partition(int fd, partition_data *partition, void **_cookie)
44 {
45 	return B_NOT_SUPPORTED;
46 }
47 
48 
49 static status_t
50 xfs_scan_partition(int fd, partition_data *partition, void *_cookie)
51 {
52 	return B_NOT_SUPPORTED;
53 }
54 
55 
56 static void
57 xfs_free_identify_partition_cookie(partition_data *partition, void *_cookie)
58 {
59 	dprintf("Unsupported in XFS currently.\n");
60 	return;
61 }
62 
63 
64 //	#pragma mark -
65 static status_t
66 xfs_mount(fs_volume *_volume, const char *device, uint32 flags,
67 		  const char *args, ino_t *_rootID)
68 {
69 	return B_NOT_SUPPORTED;
70 }
71 
72 
73 static status_t
74 xfs_unmount(fs_volume *_volume)
75 {
76 	return B_NOT_SUPPORTED;
77 }
78 
79 
80 static status_t
81 xfs_read_fs_info(fs_volume *_volume, struct fs_info *info)
82 {
83 	return B_NOT_SUPPORTED;
84 }
85 
86 
87 //	#pragma mark -
88 
89 static status_t
90 xfs_get_vnode(fs_volume *_volume, ino_t id, fs_vnode *_node, int *_type,
91 			  uint32 *_flags, bool reenter)
92 {
93 	return B_NOT_SUPPORTED;
94 }
95 
96 
97 static status_t
98 xfs_put_vnode(fs_volume *_volume, fs_vnode *_node, bool reenter)
99 {
100 	return B_NOT_SUPPORTED;
101 }
102 
103 
104 static bool
105 xfs_can_page(fs_volume *_volume, fs_vnode *_node, void *_cookie)
106 {
107 	return B_NOT_SUPPORTED;
108 }
109 
110 
111 static status_t
112 xfs_read_pages(fs_volume *_volume, fs_vnode *_node, void *_cookie,
113 			   off_t pos, const iovec *vecs, size_t count, size_t *_numBytes)
114 {
115 	return B_NOT_SUPPORTED;
116 }
117 
118 
119 static status_t
120 xfs_io(fs_volume *_volume, fs_vnode *_node, void *_cookie,
121 	   io_request *request)
122 {
123 	return B_NOT_SUPPORTED;
124 }
125 
126 
127 static status_t
128 xfs_get_file_map(fs_volume *_volume, fs_vnode *_node, off_t offset,
129 				 size_t size, struct file_io_vec *vecs, size_t *_count)
130 {
131 	return B_NOT_SUPPORTED;
132 }
133 
134 
135 //	#pragma mark -
136 
137 static status_t
138 xfs_lookup(fs_volume *_volume, fs_vnode *_directory, const char *name,
139 		   ino_t *_vnodeID)
140 {
141 	return B_NOT_SUPPORTED;
142 }
143 
144 
145 static status_t
146 xfs_ioctl(fs_volume *_volume, fs_vnode *_node, void *_cookie, uint32 cmd,
147 		  void *buffer, size_t bufferLength)
148 {
149 	return B_NOT_SUPPORTED;
150 }
151 
152 
153 static status_t
154 xfs_read_stat(fs_volume *_volume, fs_vnode *_node, struct stat *stat)
155 {
156 	return B_NOT_SUPPORTED;
157 }
158 
159 
160 static status_t
161 xfs_open(fs_volume * /*_volume*/, fs_vnode *_node, int openMode,
162 		 void **_cookie)
163 {
164 	return B_NOT_SUPPORTED;
165 }
166 
167 
168 static status_t
169 xfs_read(fs_volume *_volume, fs_vnode *_node, void *_cookie, off_t pos,
170 		 void *buffer, size_t *_length)
171 {
172 	return B_NOT_SUPPORTED;
173 }
174 
175 
176 static status_t
177 xfs_close(fs_volume *_volume, fs_vnode *_node, void *_cookie)
178 {
179 	return B_NOT_SUPPORTED;
180 }
181 
182 
183 static status_t
184 xfs_free_cookie(fs_volume *_volume, fs_vnode *_node, void *_cookie)
185 {
186 	return B_NOT_SUPPORTED;
187 }
188 
189 static status_t
190 xfs_access(fs_volume *_volume, fs_vnode *_node, int accessMode)
191 {
192 	return B_NOT_SUPPORTED;
193 }
194 
195 
196 static status_t
197 xfs_read_link(fs_volume *_volume, fs_vnode *_node, char *buffer,
198 			  size_t *_bufferSize)
199 {
200 	return B_NOT_SUPPORTED;
201 }
202 
203 
204 status_t
205 xfs_unlink(fs_volume *_volume, fs_vnode *_directory, const char *name)
206 {
207 	return B_NOT_SUPPORTED;
208 }
209 
210 
211 //	#pragma mark - Directory functions
212 
213 static status_t
214 xfs_create_dir(fs_volume *_volume, fs_vnode *_directory, const char *name,
215 			   int mode)
216 {
217 	return B_NOT_SUPPORTED;
218 }
219 
220 
221 static status_t
222 xfs_remove_dir(fs_volume *_volume, fs_vnode *_directory, const char *name)
223 {
224 	return B_NOT_SUPPORTED;
225 }
226 
227 
228 static status_t
229 xfs_open_dir(fs_volume * /*_volume*/, fs_vnode *_node, void **_cookie)
230 {
231 	return B_NOT_SUPPORTED;
232 }
233 
234 
235 static status_t
236 xfs_read_dir(fs_volume *_volume, fs_vnode *_node, void *_cookie,
237 			 struct dirent *dirent, size_t bufferSize, uint32 *_num)
238 {
239 	return B_NOT_SUPPORTED;
240 }
241 
242 
243 static status_t
244 xfs_rewind_dir(fs_volume * /*_volume*/, fs_vnode * /*node*/, void *_cookie)
245 {
246 	return B_NOT_SUPPORTED;
247 }
248 
249 
250 static status_t
251 xfs_close_dir(fs_volume * /*_volume*/, fs_vnode * /*node*/,
252 			  void * /*_cookie*/)
253 {
254 	return B_NOT_SUPPORTED;
255 }
256 
257 
258 static status_t
259 xfs_free_dir_cookie(fs_volume *_volume, fs_vnode *_node, void *_cookie)
260 {
261 	return B_NOT_SUPPORTED;
262 }
263 
264 
265 static status_t
266 xfs_open_attr_dir(fs_volume *_volume, fs_vnode *_node, void **_cookie)
267 {
268 	return B_NOT_SUPPORTED;
269 }
270 
271 
272 static status_t
273 xfs_close_attr_dir(fs_volume *_volume, fs_vnode *_node, void *cookie)
274 {
275 	return B_NOT_SUPPORTED;
276 }
277 
278 
279 static status_t
280 xfs_free_attr_dir_cookie(fs_volume *_volume, fs_vnode *_node, void *_cookie)
281 {
282 	return B_NOT_SUPPORTED;
283 }
284 
285 
286 static status_t
287 xfs_read_attr_dir(fs_volume *_volume, fs_vnode *_node,
288 				  void *_cookie, struct dirent *dirent, size_t bufferSize, uint32 *_num)
289 {
290 	return B_NOT_SUPPORTED;
291 }
292 
293 
294 static status_t
295 xfs_rewind_attr_dir(fs_volume *_volume, fs_vnode *_node, void *_cookie)
296 {
297 	return B_NOT_SUPPORTED;
298 }
299 
300 
301 /* attribute operations */
302 static status_t
303 xfs_create_attr(fs_volume *_volume, fs_vnode *_node,
304 				const char *name, uint32 type, int openMode, void **_cookie)
305 {
306 	return B_NOT_SUPPORTED;
307 }
308 
309 
310 static status_t
311 xfs_open_attr(fs_volume *_volume, fs_vnode *_node, const char *name,
312 			  int openMode, void **_cookie)
313 {
314 	return B_NOT_SUPPORTED;
315 }
316 
317 
318 static status_t
319 xfs_close_attr(fs_volume *_volume, fs_vnode *_node,
320 			   void *cookie)
321 {
322 	return B_NOT_SUPPORTED;
323 }
324 
325 
326 static status_t
327 xfs_free_attr_cookie(fs_volume *_volume, fs_vnode *_node,
328 					 void *cookie)
329 {
330 	return B_NOT_SUPPORTED;
331 }
332 
333 
334 static status_t
335 xfs_read_attr(fs_volume *_volume, fs_vnode *_node, void *_cookie,
336 			  off_t pos, void *buffer, size_t *_length)
337 {
338 	return B_NOT_SUPPORTED;
339 }
340 
341 
342 static status_t
343 xfs_write_attr(fs_volume *_volume, fs_vnode *_node, void *cookie,
344 			   off_t pos, const void *buffer, size_t *length)
345 {
346 	return B_NOT_SUPPORTED;
347 }
348 
349 
350 static status_t
351 xfs_read_attr_stat(fs_volume *_volume, fs_vnode *_node,
352 				   void *_cookie, struct stat *stat)
353 {
354 	return B_NOT_SUPPORTED;
355 }
356 
357 
358 static status_t
359 xfs_write_attr_stat(fs_volume *_volume, fs_vnode *_node,
360 					void *cookie, const struct stat *stat, int statMask)
361 {
362 	return B_NOT_SUPPORTED;
363 }
364 
365 
366 static status_t
367 xfs_rename_attr(fs_volume *_volume, fs_vnode *fromVnode,
368 				const char *fromName, fs_vnode *toVnode, const char *toName)
369 {
370 	return B_NOT_SUPPORTED;
371 }
372 
373 
374 static status_t
375 xfs_remove_attr(fs_volume *_volume, fs_vnode *vnode,
376 				const char *name)
377 {
378 	return B_NOT_SUPPORTED;
379 }
380 
381 
382 static uint32
383 xfs_get_supported_operations(partition_data *partition, uint32 mask)
384 {
385 	return B_NOT_SUPPORTED;
386 }
387 
388 
389 static status_t
390 xfs_initialize(int fd, partition_id partitionID, const char *name,
391 			const char *parameterString, off_t partitionSize, disk_job_id job)
392 {
393 	return B_NOT_SUPPORTED;
394 }
395 
396 
397 static status_t
398 xfs_uninitialize(int fd, partition_id partitionID, off_t partitionSize,
399 				 uint32 blockSize, disk_job_id job)
400 {
401 	return B_NOT_SUPPORTED;
402 }
403 
404 
405 //	#pragma mark -
406 
407 static status_t
408 xfs_std_ops(int32 op, ...)
409 {
410 	switch (op)
411 	{
412 	case B_MODULE_INIT:
413 #ifdef XFS_DEBUGGER_COMMANDS
414 		// Perform nothing at the moment
415 		// add_debugger_commands();
416 #endif
417 		return B_OK;
418 	case B_MODULE_UNINIT:
419 #ifdef XFS_DEBUGGER_COMMANDS
420 		// Perform nothing at the moment
421 		// remove_debugger_commands();
422 #endif
423 		return B_OK;
424 
425 	default:
426 		return B_ERROR;
427 	}
428 }
429 
430 fs_volume_ops gxfsVolumeOps = {
431 	&xfs_unmount,
432 	&xfs_read_fs_info,
433 	NULL, // write_fs_info()
434 	NULL, // fs_sync,
435 	&xfs_get_vnode,
436 };
437 
438 fs_vnode_ops gxfsVnodeOps = {
439 	/* vnode operations */
440 	&xfs_lookup,
441 	NULL, // xfs_get_vnode_name - optional, and we can't do better than the
442 		  // fallback implementation, so leave as NULL.
443 	&xfs_put_vnode,
444 	NULL, // xfs_remove_vnode,
445 
446 	/* VM file access */
447 	&xfs_can_page,
448 	&xfs_read_pages,
449 	NULL, // xfs_write_pages,
450 
451 	&xfs_io, // io()
452 	NULL,	// cancel_io()
453 
454 	&xfs_get_file_map,
455 
456 	&xfs_ioctl,
457 	NULL,
458 	NULL, // fs_select
459 	NULL, // fs_deselect
460 	NULL, // fs_fsync,
461 
462 	&xfs_read_link,
463 	NULL, // fs_create_symlink,
464 
465 	NULL, // fs_link,
466 	&xfs_unlink,
467 	NULL, // fs_rename,
468 
469 	&xfs_access,
470 	&xfs_read_stat,
471 	NULL, // fs_write_stat,
472 	NULL, // fs_preallocate
473 
474 	/* file operations */
475 	NULL, // fs_create,
476 	&xfs_open,
477 	&xfs_close,
478 	&xfs_free_cookie,
479 	&xfs_read,
480 	NULL, //	fs_write,
481 
482 	/* directory operations */
483 	&xfs_create_dir,
484 	&xfs_remove_dir,
485 	&xfs_open_dir,
486 	&xfs_close_dir,
487 	&xfs_free_dir_cookie,
488 	&xfs_read_dir,
489 	&xfs_rewind_dir,
490 
491 	/* attribute directory operations */
492 	&xfs_open_attr_dir,
493 	&xfs_close_attr_dir,
494 	&xfs_free_attr_dir_cookie,
495 	&xfs_read_attr_dir,
496 	&xfs_rewind_attr_dir,
497 
498 	/* attribute operations */
499 	&xfs_create_attr,
500 	&xfs_open_attr,
501 	&xfs_close_attr,
502 	&xfs_free_attr_cookie,
503 	&xfs_read_attr,
504 	&xfs_write_attr,
505 	&xfs_read_attr_stat,
506 	&xfs_write_attr_stat,
507 	&xfs_rename_attr,
508 	&xfs_remove_attr,
509 };
510 
511 
512 static file_system_module_info sxfsFileSystem = {
513 	{
514 		"file_systems/xfs" B_CURRENT_FS_API_VERSION,
515 		0,
516 		xfs_std_ops,
517 	},
518 
519 	"xfs",			   // short_name
520 	"XFS File System", // pretty_name
521 
522 	// DDM flags
523 	0| B_DISK_SYSTEM_SUPPORTS_INITIALIZING |B_DISK_SYSTEM_SUPPORTS_CONTENT_NAME
524 	//	| B_DISK_SYSTEM_SUPPORTS_WRITING
525 	,
526 
527 	// scanning
528 	xfs_identify_partition,
529 	xfs_scan_partition,
530 	xfs_free_identify_partition_cookie,
531 	NULL, // free_partition_content_cookie()
532 
533 	&xfs_mount,
534 
535 	/* capability querying operations */
536 	&xfs_get_supported_operations,
537 
538 	NULL, // validate_resize
539 	NULL, // validate_move
540 	NULL, // validate_set_content_name
541 	NULL, // validate_set_content_parameters
542 	NULL, // validate_initialize,
543 
544 	/* shadow partition modification */
545 	NULL, // shadow_changed
546 
547 	/* writing */
548 	NULL, // defragment
549 	NULL, // repair
550 	NULL, // resize
551 	NULL, // move
552 	NULL, // set_content_name
553 	NULL, // set_content_parameters
554 	xfs_initialize,
555 	xfs_uninitialize};
556 
557 module_info *modules[] = {
558 	(module_info *)&sxfsFileSystem,
559 	NULL,
560 };
561