Moved the Partition class declaration to the source file.
Refactored the code a bit (moved the scan algorithm to the Partition class, ...). Implemented get_parent_partition() and added a stub for get_child_partition() as needed by the intel partition module. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@4550 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -19,7 +19,8 @@ static partition_module_info *sPartitionModules[] = {
|
|||||||
&gAmigaPartitionModule,
|
&gAmigaPartitionModule,
|
||||||
#endif
|
#endif
|
||||||
#ifdef BOOT_SUPPORT_PARTITION_INTEL
|
#ifdef BOOT_SUPPORT_PARTITION_INTEL
|
||||||
&gIntelPartitionModule,
|
&gIntelPartitionMapModule,
|
||||||
|
&gIntelExtendedPartitionModule,
|
||||||
#endif
|
#endif
|
||||||
#ifdef BOOT_SUPPORT_PARTITION_APPLE
|
#ifdef BOOT_SUPPORT_PARTITION_APPLE
|
||||||
&gApplePartitionModule,
|
&gApplePartitionModule,
|
||||||
@@ -30,8 +31,34 @@ static const int32 sNumPartitionModules = sizeof(sPartitionModules) / sizeof(par
|
|||||||
extern list gPartitions;
|
extern list gPartitions;
|
||||||
|
|
||||||
|
|
||||||
|
class Partition : public partition_data, 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() { return fParent; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void SetParent(Partition *parent) { fParent = parent; }
|
||||||
|
|
||||||
|
int fFD;
|
||||||
|
Partition *fParent;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
Partition::Partition(int fd)
|
Partition::Partition(int fd)
|
||||||
|
:
|
||||||
|
fParent(NULL)
|
||||||
{
|
{
|
||||||
|
memset(this, 0, sizeof(partition_data));
|
||||||
|
id = (partition_id)this;
|
||||||
|
|
||||||
// it's safe to close the file
|
// it's safe to close the file
|
||||||
fFD = dup(fd);
|
fFD = dup(fd);
|
||||||
}
|
}
|
||||||
@@ -73,52 +100,94 @@ Partition::WriteAt(void *cookie, off_t position, const void *buffer, size_t buff
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark -
|
Partition *
|
||||||
|
Partition::AddChild()
|
||||||
|
|
||||||
status_t
|
|
||||||
add_partitions_for(int fd)
|
|
||||||
{
|
{
|
||||||
struct partition_data partition;
|
Partition *child = new Partition(volume);
|
||||||
memset(&partition, 0, sizeof(partition_data));
|
if (child == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
// set some magic/default values
|
child->SetParent(this);
|
||||||
partition.id = (partition_id)&partition;
|
child_count++;
|
||||||
partition.block_size = 512;
|
|
||||||
partition.size = 1024*1024*1024; // ToDo: fix this!
|
return child;
|
||||||
partition.volume = (dev_t)fd;
|
}
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
Partition::Scan()
|
||||||
|
{
|
||||||
|
// ToDo: the scan algorithm should be recursive
|
||||||
|
|
||||||
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];
|
||||||
void *cookie;
|
void *cookie;
|
||||||
|
|
||||||
puts(module->pretty_name);
|
puts(module->pretty_name);
|
||||||
if (module->identify_partition(fd, &partition, &cookie) <= 0.0)
|
if (module->identify_partition(fFD, this, &cookie) <= 0.0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
status_t status = module->scan_partition(fd, &partition, cookie);
|
status_t status = module->scan_partition(fFD, this, cookie);
|
||||||
module->free_identify_partition_cookie(&partition, cookie);
|
module->free_identify_partition_cookie(this, cookie);
|
||||||
|
|
||||||
if (status == B_OK)
|
if (status == B_OK)
|
||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
return B_ENTRY_NOT_FOUND;
|
return B_ENTRY_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark -
|
||||||
|
|
||||||
|
|
||||||
|
status_t
|
||||||
|
add_partitions_for(int fd)
|
||||||
|
{
|
||||||
|
Partition partition(fd);
|
||||||
|
|
||||||
|
// set some magic/default values
|
||||||
|
partition.block_size = 512;
|
||||||
|
partition.size = 1024*1024*1024; // ToDo: fix this!
|
||||||
|
|
||||||
|
return partition.Scan();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
partition_data *
|
partition_data *
|
||||||
create_child_partition(partition_id id, int32 index, partition_id childID)
|
create_child_partition(partition_id id, int32 index, partition_id childID)
|
||||||
{
|
{
|
||||||
partition_data &partition = *(partition_data *)id;
|
Partition &partition = *(Partition *)id;
|
||||||
Partition *child = new Partition(partition.volume);
|
Partition *child = partition.AddChild();
|
||||||
if (child == NULL) {
|
if (child == NULL) {
|
||||||
printf("creating partition failed: no memory\n");
|
printf("creating partition failed: no memory\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ToDo: only add file systems
|
||||||
list_add_item(&gPartitions, (void *)child);
|
list_add_item(&gPartitions, (void *)child);
|
||||||
|
|
||||||
return child;
|
return child;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
partition_data *
|
||||||
|
get_child_partition(partition_id id, int32 index)
|
||||||
|
{
|
||||||
|
//Partition &partition = *(Partition *)id;
|
||||||
|
|
||||||
|
// ToDo: do we really have to implement this?
|
||||||
|
// The intel partition module doesn't really needs this for our mission...
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
partition_data *
|
||||||
|
get_parent_partition(partition_id id)
|
||||||
|
{
|
||||||
|
Partition &partition = *(Partition *)id;
|
||||||
|
|
||||||
|
return partition.Parent();
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user