Moved the definition of the Partition class in a separate private header file.
Implemented recursive child content scanning. Added support for file systems, and the root file system. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4589 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
** Copyright 2003, Axel Dörfler, [email protected]. All rights reserved.
|
||||||
|
** Distributed under the terms of the OpenBeOS License.
|
||||||
|
*/
|
||||||
|
#ifndef PARTITION_H
|
||||||
|
#define PARTITION_H
|
||||||
|
|
||||||
|
|
||||||
|
#include <boot/vfs.h>
|
||||||
|
#include <ddm_modules.h>
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
|
||||||
|
class Partition : public partition_data, public Node {
|
||||||
|
public:
|
||||||
|
Partition(int deviceFD);
|
||||||
|
virtual ~Partition();
|
||||||
|
|
||||||
|
virtual ssize_t ReadAt(void *cookie, off_t offset, void *buffer, size_t bufferSize);
|
||||||
|
virtual ssize_t WriteAt(void *cookie, off_t offset, const void *buffer, size_t bufferSize);
|
||||||
|
|
||||||
|
Partition *AddChild();
|
||||||
|
status_t Scan();
|
||||||
|
|
||||||
|
Partition *Parent() const { return fParent; }
|
||||||
|
bool IsFileSystem() const { return fIsFileSystem; }
|
||||||
|
|
||||||
|
static int32 NextOffset() { return offsetof(Partition, fNext); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void SetParent(Partition *parent) { fParent = parent; }
|
||||||
|
|
||||||
|
Partition *fNext;
|
||||||
|
int fFD;
|
||||||
|
list fChildren;
|
||||||
|
Partition *fParent;
|
||||||
|
bool fIsFileSystem;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* PARTITION_H */
|
||||||
@@ -4,6 +4,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "Partition.h"
|
||||||
|
|
||||||
#include <boot/partitions.h>
|
#include <boot/partitions.h>
|
||||||
#include <boot/vfs.h>
|
#include <boot/vfs.h>
|
||||||
#include <boot/stdio.h>
|
#include <boot/stdio.h>
|
||||||
@@ -14,6 +16,8 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
|
/* supported partition modules */
|
||||||
|
|
||||||
static partition_module_info *sPartitionModules[] = {
|
static partition_module_info *sPartitionModules[] = {
|
||||||
#ifdef BOOT_SUPPORT_PARTITION_AMIGA
|
#ifdef BOOT_SUPPORT_PARTITION_AMIGA
|
||||||
&gAmigaPartitionModule,
|
&gAmigaPartitionModule,
|
||||||
@@ -28,39 +32,35 @@ static partition_module_info *sPartitionModules[] = {
|
|||||||
};
|
};
|
||||||
static const int32 sNumPartitionModules = sizeof(sPartitionModules) / sizeof(partition_module_info *);
|
static const int32 sNumPartitionModules = sizeof(sPartitionModules) / sizeof(partition_module_info *);
|
||||||
|
|
||||||
extern list gPartitions;
|
/* supported file system modules */
|
||||||
|
|
||||||
|
static file_system_module_info *sFileSystemModules[] = {
|
||||||
class Partition : public partition_data, Node {
|
#ifdef BOOT_SUPPORT_FILE_SYSTEM_BFS
|
||||||
public:
|
&gBFSFileSystemModule,
|
||||||
Partition(int deviceFD);
|
#endif
|
||||||
virtual ~Partition();
|
#ifdef BOOT_SUPPORT_FILE_SYSTEM_AMIGA_FFS
|
||||||
|
&gAmigaFFSFileSystemModule,
|
||||||
virtual ssize_t ReadAt(void *cookie, off_t offset, void *buffer, size_t bufferSize);
|
#endif
|
||||||
virtual ssize_t WriteAt(void *cookie, off_t offset, const void *buffer, size_t bufferSize);
|
#ifdef BOOT_SUPPORT_FILE_SYSTEM_FAT
|
||||||
|
&gFATFileSystemModule,
|
||||||
Partition *AddChild();
|
#endif
|
||||||
status_t Scan();
|
|
||||||
|
|
||||||
Partition *Parent() { return fParent; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
void SetParent(Partition *parent) { fParent = parent; }
|
|
||||||
|
|
||||||
int fFD;
|
|
||||||
Partition *fParent;
|
|
||||||
};
|
};
|
||||||
|
static const int32 sNumFileSystemModules = sizeof(sFileSystemModules) / sizeof(file_system_module_info *);
|
||||||
|
|
||||||
|
extern list gPartitions;
|
||||||
|
|
||||||
|
|
||||||
Partition::Partition(int fd)
|
Partition::Partition(int fd)
|
||||||
:
|
:
|
||||||
fParent(NULL)
|
fParent(NULL),
|
||||||
|
fIsFileSystem(false)
|
||||||
{
|
{
|
||||||
memset(this, 0, sizeof(partition_data));
|
memset(this, 0, sizeof(partition_data));
|
||||||
id = (partition_id)this;
|
id = (partition_id)this;
|
||||||
|
|
||||||
// it's safe to close the file
|
// it's safe to close the file
|
||||||
fFD = dup(fd);
|
fFD = dup(fd);
|
||||||
|
list_init_etc(&fChildren, Partition::NextOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -109,6 +109,7 @@ Partition::AddChild()
|
|||||||
|
|
||||||
child->SetParent(this);
|
child->SetParent(this);
|
||||||
child_count++;
|
child_count++;
|
||||||
|
list_add_item(&fChildren, (void *)child);
|
||||||
|
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
@@ -117,7 +118,7 @@ Partition::AddChild()
|
|||||||
status_t
|
status_t
|
||||||
Partition::Scan()
|
Partition::Scan()
|
||||||
{
|
{
|
||||||
// ToDo: the scan algorithm should be recursive
|
// scan for partitions first (recursively all eventual children as well)
|
||||||
|
|
||||||
for (int32 i = 0; i < sNumPartitionModules; i++) {
|
for (int32 i = 0; i < sNumPartitionModules; i++) {
|
||||||
partition_module_info *module = sPartitionModules[i];
|
partition_module_info *module = sPartitionModules[i];
|
||||||
@@ -130,8 +131,50 @@ Partition::Scan()
|
|||||||
status_t status = module->scan_partition(fFD, this, cookie);
|
status_t status = module->scan_partition(fFD, this, cookie);
|
||||||
module->free_identify_partition_cookie(this, cookie);
|
module->free_identify_partition_cookie(this, cookie);
|
||||||
|
|
||||||
if (status == B_OK)
|
if (status == B_OK) {
|
||||||
|
// now that we've found something, check our children
|
||||||
|
// out as well!
|
||||||
|
|
||||||
|
Partition *child = NULL, *last = NULL;
|
||||||
|
|
||||||
|
while ((child = (Partition *)list_get_next_item(&fChildren, child)) != NULL) {
|
||||||
|
child->Scan();
|
||||||
|
|
||||||
|
if (child->IsFileSystem()) {
|
||||||
|
// move the file systems to the partition list
|
||||||
|
list_remove_item(&fChildren, child);
|
||||||
|
list_add_item(&gPartitions, child);
|
||||||
|
|
||||||
|
child = last;
|
||||||
|
// skip this item
|
||||||
|
}
|
||||||
|
|
||||||
|
last = child;
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove all unused children (we keep only file systems)
|
||||||
|
|
||||||
|
while ((child = (Partition *)list_remove_head_item(&fChildren)) != NULL)
|
||||||
|
delete child;
|
||||||
|
|
||||||
return B_OK;
|
return B_OK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// scan for file systems
|
||||||
|
|
||||||
|
for (int32 i = 0; i < sNumFileSystemModules; i++) {
|
||||||
|
file_system_module_info *module = sFileSystemModules[i];
|
||||||
|
|
||||||
|
puts(module->pretty_name);
|
||||||
|
|
||||||
|
Directory *fileSystem;
|
||||||
|
if (module->get_file_system(this, &fileSystem) == B_OK) {
|
||||||
|
gRoot->AddNode(fileSystem);
|
||||||
|
|
||||||
|
fIsFileSystem = true;
|
||||||
|
return B_OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_ENTRY_NOT_FOUND;
|
return B_ENTRY_NOT_FOUND;
|
||||||
@@ -148,7 +191,7 @@ add_partitions_for(int fd)
|
|||||||
|
|
||||||
// set some magic/default values
|
// set some magic/default values
|
||||||
partition.block_size = 512;
|
partition.block_size = 512;
|
||||||
partition.size = 1024*1024*1024; // ToDo: fix this!
|
partition.size = partition.Size();
|
||||||
|
|
||||||
return partition.Scan();
|
return partition.Scan();
|
||||||
}
|
}
|
||||||
@@ -164,8 +207,8 @@ create_child_partition(partition_id id, int32 index, partition_id childID)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToDo: only add file systems
|
// we cannot do anything with the child here, because it was not
|
||||||
list_add_item(&gPartitions, (void *)child);
|
// yet initialized by the partition module.
|
||||||
|
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user