From ec3d3e05fe484c061ea1fe1b4aa59d8f679b66cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Mon, 25 Oct 2004 14:19:23 +0000 Subject: [PATCH] Implemented the Disk Device Manager Scanning API. It's currently exported as a separate module, but might be merged with the standard FS API. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9504 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/file_systems/bfs/Jamfile | 3 + .../kernel/file_systems/bfs/Volume.cpp | 49 +++++---- src/add-ons/kernel/file_systems/bfs/Volume.h | 2 + .../bfs/disk_device_interface.cpp | 104 ++++++++++++++++++ .../file_systems/bfs/kernel_interface.cpp | 2 + 5 files changed, 139 insertions(+), 21 deletions(-) create mode 100644 src/add-ons/kernel/file_systems/bfs/disk_device_interface.cpp diff --git a/src/add-ons/kernel/file_systems/bfs/Jamfile b/src/add-ons/kernel/file_systems/bfs/Jamfile index 3275f790a8..525c8fb3a9 100644 --- a/src/add-ons/kernel/file_systems/bfs/Jamfile +++ b/src/add-ons/kernel/file_systems/bfs/Jamfile @@ -36,6 +36,8 @@ oldOPTIM = $(OPTIM) ; } UsePrivateHeaders [ FDirName kernel ] ; # For kernel_cpp.cpp +UsePrivateHeaders [ FDirName kernel disk_device_manager ] ; +UsePrivateHeaders [ FDirName storage ] ; KernelStaticLibrary libbfs : BlockAllocator.cpp @@ -53,6 +55,7 @@ KernelStaticLibrary libbfs : KernelAddon bfs : kernel file_systems : kernel_interface.cpp + disk_device_interface.cpp : libbfs.a ; diff --git a/src/add-ons/kernel/file_systems/bfs/Volume.cpp b/src/add-ons/kernel/file_systems/bfs/Volume.cpp index 7750dcd7f2..799a0f8c83 100644 --- a/src/add-ons/kernel/file_systems/bfs/Volume.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Volume.cpp @@ -304,26 +304,7 @@ Volume::Mount(const char *deviceName, uint32 flags) #endif // read the super block - char buffer[1024]; - if (read_pos(fDevice, 0, buffer, sizeof(buffer)) != sizeof(buffer)) - return B_IO_ERROR; - - status_t status = B_OK; - - // Note: that does work only for x86, for PowerPC, the super block - // is located at offset 0! - memcpy(&fSuperBlock, buffer + 512, sizeof(disk_super_block)); - if (!IsValidSuperBlock()) { -#ifndef BFS_LITTLE_ENDIAN_ONLY - memcpy(&fSuperBlock, buffer, sizeof(disk_super_block)); - if (!IsValidSuperBlock()) - return B_BAD_VALUE; -#else - return B_BAD_VALUE; -#endif - } - - if (!IsValidSuperBlock()) { + if (Identify(fDevice, &fSuperBlock) != B_OK) { FATAL(("invalid super block!\n")); return B_BAD_VALUE; } @@ -356,6 +337,8 @@ Volume::Mount(const char *deviceName, uint32 flags) return B_NO_MEMORY; } + status_t status = B_OK; + fRootNode = new Inode(this, ToVnode(Root())); if (fRootNode && fRootNode->InitCheck() == B_OK) { status = new_vnode(fID, ToVnode(Root()), (void *)fRootNode); @@ -534,7 +517,31 @@ Volume::RemoveQuery(Query *query) // #pragma mark - -// Disk initialization +// Disk scanning and initialization + + +status_t +Volume::Identify(int fd, disk_super_block *superBlock) +{ + char buffer[1024]; + if (read_pos(fd, 0, buffer, sizeof(buffer)) != sizeof(buffer)) + return B_IO_ERROR; + + // Note: that does work only for x86, for PowerPC, the super block + // may be located at offset 0! + memcpy(superBlock, buffer + 512, sizeof(disk_super_block)); + if (!superBlock->IsValid()) { +#ifndef BFS_LITTLE_ENDIAN_ONLY + memcpy(superBlock, buffer, sizeof(disk_super_block)); + if (!superBlock->IsValid()) + return B_BAD_VALUE; +#else + return B_BAD_VALUE; +#endif + } + + return B_OK; +} #ifdef USER diff --git a/src/add-ons/kernel/file_systems/bfs/Volume.h b/src/add-ons/kernel/file_systems/bfs/Volume.h index 54b79ea397..ae74bba412 100644 --- a/src/add-ons/kernel/file_systems/bfs/Volume.h +++ b/src/add-ons/kernel/file_systems/bfs/Volume.h @@ -115,6 +115,8 @@ class Volume { uint32 GetUniqueID(); + static status_t Identify(int fd, disk_super_block *superBlock); + protected: mount_id fID; int fDevice; diff --git a/src/add-ons/kernel/file_systems/bfs/disk_device_interface.cpp b/src/add-ons/kernel/file_systems/bfs/disk_device_interface.cpp new file mode 100644 index 0000000000..cbf52db07d --- /dev/null +++ b/src/add-ons/kernel/file_systems/bfs/disk_device_interface.cpp @@ -0,0 +1,104 @@ +/* +** Copyright 2004, Axel Dörfler, axeld@pinc-software.de +** This file may be used under the terms of the Haiku License. +*/ + +/* This file contains the module interface to the disk device manager. + * Currently, only the part for identifying and scanning a volume is implemented. + */ + + +#include "Volume.h" + +#include +#include + +#include + + +struct identify_cookie { + disk_super_block super_block; +}; + + +// Scanning + + +static float +bfs_identify_partition(int fd, partition_data *partition, void **_cookie) +{ + disk_super_block superBlock; + if (Volume::Identify(fd, &superBlock) != B_OK) + return 0.0f; + + identify_cookie *cookie = new identify_cookie; + memcpy(&cookie->super_block, &superBlock, sizeof(disk_super_block)); + + *_cookie = cookie; + return 0.8f; +} + + +static status_t +bfs_scan_partition(int fd, partition_data *partition, void *_cookie) +{ + identify_cookie *cookie = (identify_cookie *)_cookie; + + partition->status = B_PARTITION_VALID; + partition->flags |= B_PARTITION_FILE_SYSTEM; + partition->content_size = cookie->super_block.NumBlocks() * cookie->super_block.BlockSize(); + partition->block_size = cookie->super_block.BlockSize(); + + partition->content_name = strdup(cookie->super_block.name); + + return B_OK; +} + + +static void +bfs_free_identify_partition_cookie(partition_data *partition, void *_cookie) +{ + identify_cookie *cookie = (identify_cookie *)_cookie; + + delete cookie; +} + + +// #pragma mark - + + +static status_t +bfs_std_ops(int32 op, ...) +{ + switch (op) { + case B_MODULE_INIT: + case B_MODULE_UNINIT: + return B_OK; + } + + return B_BAD_VALUE; +} + + +struct fs_module_info gDiskDeviceInfo = { + { + "file_systems/bfs/disk_device/v1", + 0, + bfs_std_ops, + }, + + "Be File System", + 0, /* flags ? */ + + // scanning + bfs_identify_partition, + bfs_scan_partition, + bfs_free_identify_partition_cookie, + NULL, + + // querying + // shadow partition modification + // writing + NULL +}; + diff --git a/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp b/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp index 33055c826d..f10a30791a 100644 --- a/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp +++ b/src/add-ons/kernel/file_systems/bfs/kernel_interface.cpp @@ -2124,8 +2124,10 @@ static file_system_info sBeFileSystem = { NULL, }; +extern module_info gDiskDeviceInfo; module_info *modules[] = { (module_info *)&sBeFileSystem, + &gDiskDeviceInfo, NULL, };