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