From 42ddb0b34b664ef9328fad50a65f7bb9f6d13d16 Mon Sep 17 00:00:00 2001 From: SuhelMehta9 Date: Sat, 14 Mar 2020 00:04:22 +0530 Subject: [PATCH] Making of UFS file system System dependencies and kernel interface code has been added. Change-Id: I770ad6b906ca41d4d84d374cea209e22149fd727 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2344 Reviewed-by: Adrien Destugues --- src/add-ons/kernel/file_systems/Jamfile | 1 + src/add-ons/kernel/file_systems/ufs2/Jamfile | 35 ++ .../file_systems/ufs2/kernel_interface.cpp | 560 ++++++++++++++++++ .../file_systems/ufs2/system_dependencies.h | 41 ++ src/tests/add-ons/kernel/file_systems/Jamfile | 1 + .../add-ons/kernel/file_systems/ufs2/Jamfile | 3 + .../file_systems/ufs2/ufs2_shell/Jamfile | 64 ++ 7 files changed, 705 insertions(+) create mode 100644 src/add-ons/kernel/file_systems/ufs2/Jamfile create mode 100644 src/add-ons/kernel/file_systems/ufs2/kernel_interface.cpp create mode 100644 src/add-ons/kernel/file_systems/ufs2/system_dependencies.h create mode 100644 src/tests/add-ons/kernel/file_systems/ufs2/Jamfile create mode 100644 src/tests/add-ons/kernel/file_systems/ufs2/ufs2_shell/Jamfile diff --git a/src/add-ons/kernel/file_systems/Jamfile b/src/add-ons/kernel/file_systems/Jamfile index 7ac800a7f9..135aeb44f2 100644 --- a/src/add-ons/kernel/file_systems/Jamfile +++ b/src/add-ons/kernel/file_systems/Jamfile @@ -18,6 +18,7 @@ SubInclude HAIKU_TOP src add-ons kernel file_systems packagefs ; SubInclude HAIKU_TOP src add-ons kernel file_systems ramfs ; SubInclude HAIKU_TOP src add-ons kernel file_systems reiserfs ; SubInclude HAIKU_TOP src add-ons kernel file_systems udf ; +SubInclude HAIKU_TOP src add-ons kernel file_systems ufs2 ; SubInclude HAIKU_TOP src add-ons kernel file_systems userlandfs ; SubInclude HAIKU_TOP src add-ons kernel file_systems xfs ; diff --git a/src/add-ons/kernel/file_systems/ufs2/Jamfile b/src/add-ons/kernel/file_systems/ufs2/Jamfile new file mode 100644 index 0000000000..34791f4261 --- /dev/null +++ b/src/add-ons/kernel/file_systems/ufs2/Jamfile @@ -0,0 +1,35 @@ +SubDir HAIKU_TOP src add-ons kernel file_systems ufs2 ; + +# set some additional defines +{ + local defines = + UFS2_DEBUGGER_COMMANDS + ; + + defines = [ FDefines $(defines) ] ; + SubDirCcFlags $(defines) ; + SubDirC++Flags $(defines) ; +} + +UsePrivateHeaders [ FDirName kernel util ] ; +UsePrivateHeaders shared storage file_systems ; +UsePrivateKernelHeaders ; + +DEFINES += DEBUG_APP="\\\"ufs2\\\"" ; + +local ufs2Sources = + kernel_cpp.cpp + kernel_interface.cpp + ; +KernelAddon ufs2 : + $(ufs2Sources) + : +; + + +SEARCH on [ FGristFiles $(ufs2Sources) ] + = [ FDirName $(HAIKU_TOP) src add-ons kernel file_systems ufs2 ] ; + +SEARCH on [ FGristFiles kernel_cpp.cpp ] + = [ FDirName $(HAIKU_TOP src system kernel util ] ; + diff --git a/src/add-ons/kernel/file_systems/ufs2/kernel_interface.cpp b/src/add-ons/kernel/file_systems/ufs2/kernel_interface.cpp new file mode 100644 index 0000000000..e53d93d826 --- /dev/null +++ b/src/add-ons/kernel/file_systems/ufs2/kernel_interface.cpp @@ -0,0 +1,560 @@ +/* + * Copyright 2020 Suhel Mehta, mehtasuhel@gmail.com + * All rights reserved. Distributed under the terms of the MIT License. + */ +#include "system_dependencies.h" + +#ifdef TRACE_ufs2 +#define TRACE(x...) dprintf("\33[34mufs2:\33[0m " x) +#else +#define TRACE(x...) ; +#endif + + +struct identify_cookie +{ + /* super_block_struct super_block; + * No structure yet implemented. + */ + int cookie; +}; + + +//! ufs2_io() callback hook +static status_t +iterative_io_get_vecs_hook(void *cookie, io_request *request, off_t offset, + size_t size, struct file_io_vec *vecs, size_t *_count) +{ + return B_NOT_SUPPORTED; +} + + +//! ufs2_io() callback hook +static status_t +iterative_io_finished_hook(void *cookie, io_request *request, status_t status, + bool partialTransfer, size_t bytesTransferred) +{ + return B_NOT_SUPPORTED; +} + + +// #pragma mark - Scanning +static float +ufs2_identify_partition(int fd, partition_data *partition, void **_cookie) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_scan_partition(int fd, partition_data *partition, void *_cookie) +{ + return B_NOT_SUPPORTED; +} + + +static void +ufs2_free_identify_partition_cookie(partition_data *partition, void *_cookie) +{ + dprintf("Unsupported in ufs2 currently.\n"); + return; +} + + +// #pragma mark - +static status_t +ufs2_mount(fs_volume *_volume, const char *device, uint32 flags, + const char *args, ino_t *_rootID) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_unmount(fs_volume *_volume) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_read_fs_info(fs_volume *_volume, struct fs_info *info) +{ + return B_NOT_SUPPORTED; +} + + +// #pragma mark - + +static status_t +ufs2_get_vnode(fs_volume *_volume, ino_t id, fs_vnode *_node, int *_type, + uint32 *_flags, bool reenter) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_put_vnode(fs_volume *_volume, fs_vnode *_node, bool reenter) +{ + return B_NOT_SUPPORTED; +} + + +static bool +ufs2_can_page(fs_volume *_volume, fs_vnode *_node, void *_cookie) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_read_pages(fs_volume *_volume, fs_vnode *_node, void *_cookie, + off_t pos, const iovec *vecs, size_t count, size_t *_numBytes) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_io(fs_volume *_volume, fs_vnode *_node, void *_cookie, + io_request *request) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_get_file_map(fs_volume *_volume, fs_vnode *_node, off_t offset, + size_t size, struct file_io_vec *vecs, size_t *_count) +{ + return B_NOT_SUPPORTED; +} + + +// #pragma mark - + +static status_t +ufs2_lookup(fs_volume *_volume, fs_vnode *_directory, const char *name, + ino_t *_vnodeID) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_ioctl(fs_volume *_volume, fs_vnode *_node, void *_cookie, uint32 cmd, + void *buffer, size_t bufferLength) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_read_stat(fs_volume *_volume, fs_vnode *_node, struct stat *stat) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_open(fs_volume * /*_volume*/, fs_vnode *_node, int openMode, + void **_cookie) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_read(fs_volume *_volume, fs_vnode *_node, void *_cookie, off_t pos, + void *buffer, size_t *_length) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_close(fs_volume *_volume, fs_vnode *_node, void *_cookie) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_free_cookie(fs_volume *_volume, fs_vnode *_node, void *_cookie) +{ + return B_NOT_SUPPORTED; +} + +static status_t +ufs2_access(fs_volume *_volume, fs_vnode *_node, int accessMode) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_read_link(fs_volume *_volume, fs_vnode *_node, char *buffer, + size_t *_bufferSize) +{ + return B_NOT_SUPPORTED; +} + + +status_t +ufs2_unlink(fs_volume *_volume, fs_vnode *_directory, const char *name) +{ + return B_NOT_SUPPORTED; +} + + +// #pragma mark - Directory functions + +static status_t +ufs2_create_dir(fs_volume *_volume, fs_vnode *_directory, const char *name, + int mode) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_remove_dir(fs_volume *_volume, fs_vnode *_directory, const char *name) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_open_dir(fs_volume * /*_volume*/, fs_vnode *_node, void **_cookie) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_read_dir(fs_volume *_volume, fs_vnode *_node, void *_cookie, + struct dirent *dirent, size_t bufferSize, uint32 *_num) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_rewind_dir(fs_volume * /*_volume*/, fs_vnode * /*node*/, void *_cookie) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_close_dir(fs_volume * /*_volume*/, fs_vnode * /*node*/, + void * /*_cookie*/) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_free_dir_cookie(fs_volume *_volume, fs_vnode *_node, void *_cookie) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_open_attr_dir(fs_volume *_volume, fs_vnode *_node, void **_cookie) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_close_attr_dir(fs_volume *_volume, fs_vnode *_node, void *cookie) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_free_attr_dir_cookie(fs_volume *_volume, fs_vnode *_node, void *_cookie) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_read_attr_dir(fs_volume *_volume, fs_vnode *_node, + void *_cookie, struct dirent *dirent, size_t bufferSize, uint32 *_num) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_rewind_attr_dir(fs_volume *_volume, fs_vnode *_node, void *_cookie) +{ + return B_NOT_SUPPORTED; +} + + +/* attribute operations */ +static status_t +ufs2_create_attr(fs_volume *_volume, fs_vnode *_node, + const char *name, uint32 type, int openMode, void **_cookie) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_open_attr(fs_volume *_volume, fs_vnode *_node, const char *name, + int openMode, void **_cookie) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_close_attr(fs_volume *_volume, fs_vnode *_node, + void *cookie) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_free_attr_cookie(fs_volume *_volume, fs_vnode *_node, + void *cookie) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_read_attr(fs_volume *_volume, fs_vnode *_node, void *_cookie, + off_t pos, void *buffer, size_t *_length) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_write_attr(fs_volume *_volume, fs_vnode *_node, void *cookie, + off_t pos, const void *buffer, size_t *length) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_read_attr_stat(fs_volume *_volume, fs_vnode *_node, + void *_cookie, struct stat *stat) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_write_attr_stat(fs_volume *_volume, fs_vnode *_node, + void *cookie, const struct stat *stat, int statMask) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_rename_attr(fs_volume *_volume, fs_vnode *fromVnode, + const char *fromName, fs_vnode *toVnode, const char *toName) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_remove_attr(fs_volume *_volume, fs_vnode *vnode, + const char *name) +{ + return B_NOT_SUPPORTED; +} + + +static uint32 +ufs2_get_supported_operations(partition_data *partition, uint32 mask) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_initialize(int fd, partition_id partitionID, const char *name, + const char *parameterString, off_t partitionSize, disk_job_id job) +{ + return B_NOT_SUPPORTED; +} + + +static status_t +ufs2_uninitialize(int fd, partition_id partitionID, off_t partitionSize, + uint32 blockSize, disk_job_id job) +{ + return B_NOT_SUPPORTED; +} + + +// #pragma mark - + +static status_t +ufs2_std_ops(int32 op, ...) +{ + switch (op) + { + case B_MODULE_INIT: +#ifdef ufs2_DEBUGGER_COMMANDS + // Perform nothing at the moment + // add_debugger_commands(); +#endif + return B_OK; + case B_MODULE_UNINIT: +#ifdef ufs2_DEBUGGER_COMMANDS + // Perform nothing at the moment + // remove_debugger_commands(); +#endif + return B_OK; + + default: + return B_ERROR; + } +} + +fs_volume_ops gufs2VolumeOps = { + &ufs2_unmount, + &ufs2_read_fs_info, + NULL, // write_fs_info() + NULL, // fs_sync, + &ufs2_get_vnode, +}; + +fs_vnode_ops gufs2VnodeOps = { + /* vnode operations */ + &ufs2_lookup, + NULL, // ufs2_get_vnode_name - optional, and we can't do better than the + // fallback implementation, so leave as NULL. + &ufs2_put_vnode, + NULL, // ufs2_remove_vnode, + + /* VM file access */ + &ufs2_can_page, + &ufs2_read_pages, + NULL, // ufs2_write_pages, + + &ufs2_io, // io() + NULL, // cancel_io() + + &ufs2_get_file_map, + + &ufs2_ioctl, + NULL, + NULL, // fs_select + NULL, // fs_deselect + NULL, // fs_fsync, + + &ufs2_read_link, + NULL, // fs_create_symlink, + + NULL, // fs_link, + &ufs2_unlink, + NULL, // fs_rename, + + &ufs2_access, + &ufs2_read_stat, + NULL, // fs_write_stat, + NULL, // fs_preallocate + + /* file operations */ + NULL, // fs_create, + &ufs2_open, + &ufs2_close, + &ufs2_free_cookie, + &ufs2_read, + NULL, // fs_write, + + /* directory operations */ + &ufs2_create_dir, + &ufs2_remove_dir, + &ufs2_open_dir, + &ufs2_close_dir, + &ufs2_free_dir_cookie, + &ufs2_read_dir, + &ufs2_rewind_dir, + + /* attribute directory operations */ + &ufs2_open_attr_dir, + &ufs2_close_attr_dir, + &ufs2_free_attr_dir_cookie, + &ufs2_read_attr_dir, + &ufs2_rewind_attr_dir, + + /* attribute operations */ + &ufs2_create_attr, + &ufs2_open_attr, + &ufs2_close_attr, + &ufs2_free_attr_cookie, + &ufs2_read_attr, + &ufs2_write_attr, + &ufs2_read_attr_stat, + &ufs2_write_attr_stat, + &ufs2_rename_attr, + &ufs2_remove_attr, +}; + + +static file_system_module_info sufs2FileSystem = { + { + "file_systems/ufs2" B_CURRENT_FS_API_VERSION, + 0, + ufs2_std_ops, + }, + + "ufs2", // short_name + "Unix Filesystem 2", // pretty_name + + // DDM flags + 0| B_DISK_SYSTEM_SUPPORTS_INITIALIZING |B_DISK_SYSTEM_SUPPORTS_CONTENT_NAME + // | B_DISK_SYSTEM_SUPPORTS_WRITING + , + + // scanning + ufs2_identify_partition, + ufs2_scan_partition, + ufs2_free_identify_partition_cookie, + NULL, // free_partition_content_cookie() + + &ufs2_mount, + + /* capability querying operations */ + &ufs2_get_supported_operations, + + NULL, // validate_resize + NULL, // validate_move + NULL, // validate_set_content_name + NULL, // validate_set_content_parameters + NULL, // validate_initialize, + + /* shadow partition modification */ + NULL, // shadow_changed + + /* writing */ + NULL, // defragment + NULL, // repair + NULL, // resize + NULL, // move + NULL, // set_content_name + NULL, // set_content_parameters + ufs2_initialize, + ufs2_uninitialize}; + +module_info *modules[] = { + (module_info *)&sufs2FileSystem, + NULL, +}; diff --git a/src/add-ons/kernel/file_systems/ufs2/system_dependencies.h b/src/add-ons/kernel/file_systems/ufs2/system_dependencies.h new file mode 100644 index 0000000000..99980e14a5 --- /dev/null +++ b/src/add-ons/kernel/file_systems/ufs2/system_dependencies.h @@ -0,0 +1,41 @@ +/* + * Copyright 2020 Suhel Mehta, mehtasuhel@gmail.com + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef _SYSTEM_DEPENDENCIES_H +#define _SYSTEM_DEPENDENCIES_H + +#ifdef FS_SHELL +// This needs to be included before the fs_shell wrapper + +#include "fssh_api_wrapper.h" +#include "fssh_auto_deleter.h" +//#include + +#else // !FS_SHELL + +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#endif // !FS_SHELL + +#endif // _SYSTEM_DEPENDENCIES diff --git a/src/tests/add-ons/kernel/file_systems/Jamfile b/src/tests/add-ons/kernel/file_systems/Jamfile index ff5e501201..e4f07a758b 100644 --- a/src/tests/add-ons/kernel/file_systems/Jamfile +++ b/src/tests/add-ons/kernel/file_systems/Jamfile @@ -9,5 +9,6 @@ HaikuSubInclude iso9660 ; HaikuSubInclude random_file_actions ; HaikuSubInclude random_read ; HaikuSubInclude udf ; +HaikuSubInclude ufs2 ; HaikuSubInclude userlandfs ; HaikuSubInclude xfs ; diff --git a/src/tests/add-ons/kernel/file_systems/ufs2/Jamfile b/src/tests/add-ons/kernel/file_systems/ufs2/Jamfile new file mode 100644 index 0000000000..faec536dd8 --- /dev/null +++ b/src/tests/add-ons/kernel/file_systems/ufs2/Jamfile @@ -0,0 +1,3 @@ +SubDir HAIKU_TOP src tests add-ons kernel file_systems ufs2 ; + +SubInclude HAIKU_TOP src tests add-ons kernel file_systems ufs2 ufs2_shell ; diff --git a/src/tests/add-ons/kernel/file_systems/ufs2/ufs2_shell/Jamfile b/src/tests/add-ons/kernel/file_systems/ufs2/ufs2_shell/Jamfile new file mode 100644 index 0000000000..fe7873bbf4 --- /dev/null +++ b/src/tests/add-ons/kernel/file_systems/ufs2/ufs2_shell/Jamfile @@ -0,0 +1,64 @@ +SubDir HAIKU_TOP src tests add-ons kernel file_systems ufs2 ufs2_shell ; + +SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src add-ons kernel file_systems ufs2 ] ; + +# prevent inclusion of HaikuBuildCompatibility.h +DEFINES += HAIKU_BUILD_COMPATIBILITY_H ; + +# set some additional defines +{ + local defines = + FS_SHELL + ; + + defines = [ FDefines $(defines) ] ; + + local c++flags = ; + + SubDirCcFlags $(defines) -Wno-multichar ; + SubDirC++Flags $(defines) $(c++flags) -Wno-multichar -fno-rtti ; +} + +# platform specific libraries +local fsShellCommandLibs ; +if ! $(HOST_PLATFORM_HAIKU_COMPATIBLE) { + fsShellCommandLibs = $(HOST_NETWORK_LIBS) ; +} + +UseHeaders [ FDirName $(HAIKU_TOP) headers build ] : true ; + +if ! $(HOST_PLATFORM_HAIKU_COMPATIBLE) { + UseHeaders [ FDirName $(HAIKU_TOP) headers build os ] : true ; + UseHeaders [ FDirName $(HAIKU_TOP) headers build os support ] : true ; +} + +UsePrivateHeaders shared storage ; +UsePrivateHeaders fs_shell ; +UseHeaders [ FDirName $(HAIKU_TOP) headers private ] : true ; +UseHeaders [ FDirName $(HAIKU_TOP) src tools fs_shell ] ; + +local ufs2Source = + kernel_interface.cpp +; + +BuildPlatformMergeObject ufs2.o : $(ufs2Source) ; + +BuildPlatformMain ufs2_shell + : + : + ufs2.o + fs_shell.a $(HOST_LIBSUPC++) $(HOST_LIBSTDC++) + $(HOST_LIBROOT) $(fsShellCommandLibs) +; + +BuildPlatformMain ufs2_fuse + : + : + ufs2.o + fuse_module.a + $(HOST_LIBSUPC++) $(HOST_LIBSTDC++) + $(HOST_STATIC_LIBROOT) $(fsShellCommandLibs) fuse +; + +SEARCH on [ FGristFiles QueryParserUtils.cpp ] + += [ FDirName $(HAIKU_TOP) src add-ons kernel file_systems shared ] ;