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
This commit is contained in:
Axel Dörfler 2004-10-25 14:19:23 +00:00
parent ad2a2999a9
commit ec3d3e05fe
5 changed files with 139 additions and 21 deletions

View File

@ -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
;

View File

@ -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

View File

@ -115,6 +115,8 @@ class Volume {
uint32 GetUniqueID();
static status_t Identify(int fd, disk_super_block *superBlock);
protected:
mount_id fID;
int fDevice;

View File

@ -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 <disk_device_manager/ddm_modules.h>
#include <util/kernel_cpp.h>
#include <string.h>
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
};

View File

@ -2124,8 +2124,10 @@ static file_system_info sBeFileSystem = {
NULL,
};
extern module_info gDiskDeviceInfo;
module_info *modules[] = {
(module_info *)&sBeFileSystem,
&gDiskDeviceInfo,
NULL,
};