Added offset and size parameters to create_child_partition() and

KPartition::CreateChild(). CreateChild() calls AddChild(), which publishes
the new partition, though at that point offset and size were not set, so that
the published devices would not be usable.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31463 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2009-07-08 20:26:43 +00:00
parent 967294dbd8
commit 1cc5e46925
12 changed files with 74 additions and 63 deletions
+1 -1
View File
@@ -104,7 +104,7 @@ partition_data *get_child_partition(partition_id partitionID, int32 index);
// partition write access // partition write access
// (write lock required) // (write lock required)
partition_data *create_child_partition(partition_id partitionID, int32 index, partition_data *create_child_partition(partition_id partitionID, int32 index,
partition_id childID); off_t offset, off_t size, partition_id childID);
// childID is an optional input parameter -- -1 to be ignored // childID is an optional input parameter -- -1 to be ignored
bool delete_partition(partition_id partitionID); bool delete_partition(partition_id partitionID);
void partition_modified(partition_id partitionID); void partition_modified(partition_id partitionID);
@@ -135,7 +135,7 @@ public:
KPartition *Parent() const; KPartition *Parent() const;
status_t AddChild(KPartition *partition, int32 index = -1); status_t AddChild(KPartition *partition, int32 index = -1);
virtual status_t CreateChild(partition_id id, int32 index, status_t CreateChild(partition_id id, int32 index, off_t offset, off_t size,
KPartition **child = NULL); KPartition **child = NULL);
bool RemoveChild(int32 index); bool RemoveChild(int32 index);
bool RemoveChild(KPartition *child); bool RemoveChild(KPartition *child);
@@ -183,14 +183,13 @@ amiga_rdb_scan_partition(int fd, partition_data *partition, void *_cookie)
continue; continue;
} }
partition_data *child = create_child_partition(partition->id, index++, -1); partition_data *child = create_child_partition(partition->id, index++,
partition->offset + environment.Start(), environment.Size(), -1);
if (child == NULL) { if (child == NULL) {
TRACE(("amiga_rdb: Creating child at index %ld failed\n", index - 1)); TRACE(("amiga_rdb: Creating child at index %ld failed\n", index - 1));
return B_ERROR; return B_ERROR;
} }
child->offset = partition->offset + environment.Start();
child->size = environment.Size();
child->block_size = environment.BlockSize(); child->block_size = environment.BlockSize();
} }
@@ -168,14 +168,14 @@ apple_scan_partition(int fd, partition_data *partition, void *_cookie)
continue; continue;
} }
partition_data *child = create_child_partition(partition->id, index++, -1); partition_data *child = create_child_partition(partition->id, index++,
partition->offset + partitionMap.Start(descriptor),
partitionMap.Size(descriptor), -1);
if (child == NULL) { if (child == NULL) {
TRACE(("apple: Creating child at index %ld failed\n", index - 1)); TRACE(("apple: Creating child at index %ld failed\n", index - 1));
return B_ERROR; return B_ERROR;
} }
child->offset = partition->offset + partitionMap.Start(descriptor);
child->size = partitionMap.Size(descriptor);
child->block_size = partition->block_size; child->block_size = partition->block_size;
} }
@@ -183,7 +183,9 @@ atari_scan_partition(int fd, partition_data *partition, void *_cookie)
if (!isalnum(p->id[2])) if (!isalnum(p->id[2]))
continue; continue;
partition_data *child = create_child_partition(partition->id, index, -1); partition_data *child = create_child_partition(partition->id, index,
partition->offset + p->Start() * (uint64)SECTSZ,
p->Size() * (uint64)SECTSZ, -1);
if (child == NULL) { if (child == NULL) {
TRACE(("atari: Creating child at index %ld failed\n", index - 1)); TRACE(("atari: Creating child at index %ld failed\n", index - 1));
return B_ERROR; return B_ERROR;
@@ -192,8 +194,6 @@ atari_scan_partition(int fd, partition_data *partition, void *_cookie)
char type[] = "??? Partition"; char type[] = "??? Partition";
memcpy(type, p->id, 3); memcpy(type, p->id, 3);
child->type = strdup(type); child->type = strdup(type);
child->offset = partition->offset + p->Start() * (uint64)SECTSZ;
child->size = p->Size() * (uint64)SECTSZ;
child->block_size = SECTSZ; child->block_size = SECTSZ;
status = B_OK; status = B_OK;
} }
@@ -483,7 +483,8 @@ efi_gpt_scan_partition(int fd, partition_data *partition, void *_cookie)
} }
partition_data *child = create_child_partition(partition->id, index++, partition_data *child = create_child_partition(partition->id, index++,
-1); partition->offset + entry.StartBlock() * partition->block_size,
entry.BlockCount() * partition->block_size, -1);
if (child == NULL) { if (child == NULL) {
TRACE(("efi_gpt: Creating child at index %ld failed\n", index - 1)); TRACE(("efi_gpt: Creating child at index %ld failed\n", index - 1));
return B_ERROR; return B_ERROR;
@@ -493,10 +494,6 @@ efi_gpt_scan_partition(int fd, partition_data *partition, void *_cookie)
to_utf8(entry.name, EFI_PARTITION_NAME_LENGTH, name, sizeof(name)); to_utf8(entry.name, EFI_PARTITION_NAME_LENGTH, name, sizeof(name));
child->name = strdup(name); child->name = strdup(name);
child->type = strdup(get_partition_type(entry.partition_type)); child->type = strdup(get_partition_type(entry.partition_type));
child->offset = partition->offset + entry.StartBlock()
* partition->block_size;
child->size = entry.BlockCount() * partition->block_size;
child->block_size = partition->block_size; child->block_size = partition->block_size;
child->cookie = (void *)i; child->cookie = (void *)i;
} }
@@ -1119,7 +1116,7 @@ efi_gpt_create_child(int fd, partition_id partitionID, off_t offset,
update_disk_device_job_progress(job, 0.0); update_disk_device_job_progress(job, 0.0);
partition_data *child = create_child_partition(partition->id, entryIndex, partition_data *child = create_child_partition(partition->id, entryIndex,
*childID); validatedOffset, validatedSize, *childID);
if (child == NULL) if (child == NULL)
return B_ERROR; return B_ERROR;
@@ -1137,8 +1134,6 @@ efi_gpt_create_child(int fd, partition_id partitionID, off_t offset,
} }
*childID = child->id; *childID = child->id;
child->offset = validatedOffset;
child->size = validatedSize;
child->block_size = partition->block_size; child->block_size = partition->block_size;
child->type = strdup(type); child->type = strdup(type);
child->parameters = strdup(parameters); child->parameters = strdup(parameters);
@@ -202,7 +202,8 @@ pm_scan_partition(int fd, partition_data *partition, void *cookie)
PrimaryPartition *primary = map->PrimaryPartitionAt(i); PrimaryPartition *primary = map->PrimaryPartitionAt(i);
if (!primary->IsEmpty()) { if (!primary->IsEmpty()) {
partition_data *child = create_child_partition(partition->id, partition_data *child = create_child_partition(partition->id,
index, -1); index, partition->offset + primary->Offset(), primary->Size(),
-1);
index++; index++;
if (!child) { if (!child) {
// something went wrong // something went wrong
@@ -210,8 +211,6 @@ pm_scan_partition(int fd, partition_data *partition, void *cookie)
break; break;
} }
child->offset = partition->offset + primary->Offset();
child->size = primary->Size();
child->block_size = partition->block_size; child->block_size = partition->block_size;
// (no name) // (no name)
@@ -354,7 +353,8 @@ ep_scan_partition(int fd, partition_data *partition, void *cookie)
int32 index = 0; int32 index = 0;
for (int32 i = 0; i < primary->CountLogicalPartitions(); i++) { for (int32 i = 0; i < primary->CountLogicalPartitions(); i++) {
LogicalPartition *logical = primary->LogicalPartitionAt(i); LogicalPartition *logical = primary->LogicalPartitionAt(i);
partition_data *child = create_child_partition(partition->id, index, -1); partition_data *child = create_child_partition(partition->id, index,
parent->offset + logical->Offset(), logical->Size(), -1);
index++; index++;
if (!child) { if (!child) {
// something went wrong // something went wrong
@@ -363,8 +363,6 @@ ep_scan_partition(int fd, partition_data *partition, void *cookie)
error = B_ERROR; error = B_ERROR;
break; break;
} }
child->offset = parent->offset + logical->Offset();
child->size = logical->Size();
child->block_size = partition->block_size; child->block_size = partition->block_size;
// (no name) // (no name)
@@ -1329,7 +1329,7 @@ pm_create_child(int fd, partition_id partitionID, off_t offset, off_t size,
// creating partition // creating partition
update_disk_device_job_progress(job, 0.0); update_disk_device_job_progress(job, 0.0);
partition_data *child = create_child_partition(partition->id, index, partition_data *child = create_child_partition(partition->id, index,
*childID); validatedOffset, validatedSize, *childID);
if (!child) if (!child)
return B_ERROR; return B_ERROR;
@@ -1357,8 +1357,6 @@ pm_create_child(int fd, partition_id partitionID, off_t offset, off_t size,
*childID = child->id; *childID = child->id;
child->offset = partition->offset + primary->Offset();
child->size = primary->Size();
child->block_size = SECTOR_SIZE; child->block_size = SECTOR_SIZE;
// (no name) // (no name)
child->type = strdup(type); child->type = strdup(type);
@@ -2088,7 +2086,7 @@ ep_create_child(int fd, partition_id partitionID, off_t offset, off_t size,
// creating partition // creating partition
update_disk_device_job_progress(job, 0.0); update_disk_device_job_progress(job, 0.0);
partition_data *child = create_child_partition(partition->id, index, partition_data *child = create_child_partition(partition->id, index,
*childID); validatedOffset, validatedSize, *childID);
if (!child) { if (!child) {
delete logical; delete logical;
return B_ERROR; return B_ERROR;
@@ -2136,8 +2134,6 @@ ep_create_child(int fd, partition_id partitionID, off_t offset, off_t size,
*childID = child->id; *childID = child->id;
child->offset = partition->offset + logical->Offset();
child->size = logical->Size();
child->block_size = SECTOR_SIZE; child->block_size = SECTOR_SIZE;
// (no name) // (no name)
child->type = strdup(type); child->type = strdup(type);
@@ -78,15 +78,13 @@ scan_partition(int fd, partition_data *partition, void *cookie)
status_t error = B_OK; status_t error = B_OK;
for (int i = 0; (session = disc->GetSession(i)); i++) { for (int i = 0; (session = disc->GetSession(i)); i++) {
partition_data *child = create_child_partition(partition->id, partition_data *child = create_child_partition(partition->id,
i, -1); i, partition->offset + session->Offset(), session->Size(), -1);
if (!child) { if (!child) {
PRINT(("Unable to create child at index %d.\n", i)); PRINT(("Unable to create child at index %d.\n", i));
// something went wrong // something went wrong
error = B_ERROR; error = B_ERROR;
break; break;
} }
child->offset = partition->offset + session->Offset();
child->size = session->Size();
child->block_size = session->BlockSize(); child->block_size = session->BlockSize();
child->flags |= session->Flags(); child->flags |= session->Flags();
child->type = strdup(session->Type()); child->type = strdup(session->Type());
+5 -1
View File
@@ -458,7 +458,8 @@ add_partitions_for(Node *device, bool mountFileSystems, bool isBootDevice)
partition_data * partition_data *
create_child_partition(partition_id id, int32 index, partition_id childID) create_child_partition(partition_id id, int32 index, off_t offset, off_t size,
partition_id childID)
{ {
Partition &partition = *(Partition *)id; Partition &partition = *(Partition *)id;
Partition *child = partition.AddChild(); Partition *child = partition.AddChild();
@@ -467,6 +468,9 @@ create_child_partition(partition_id id, int32 index, partition_id childID)
return NULL; return NULL;
} }
child->offset = offset;
child->size = size;
// we cannot do anything with the child here, because it was not // we cannot do anything with the child here, because it was not
// yet initialized by the partition module. // yet initialized by the partition module.
TRACE(("new child partition!\n")); TRACE(("new child partition!\n"));
@@ -185,8 +185,11 @@ KPartition::PublishDevice()
// get the path // get the path
KPath path; KPath path;
status_t error = GetPath(&path); status_t error = GetPath(&path);
if (error != B_OK) if (error != B_OK) {
dprintf("KPartition::PublishDevice(): Failed to get path for partition "
"%ld: %s\n", ID(), strerror(error));
return error; return error;
}
// prepare a partition_info // prepare a partition_info
partition_info info; partition_info info;
@@ -202,8 +205,11 @@ KPartition::PublishDevice()
error = devfs_publish_partition(path.Path() + 5, &info); error = devfs_publish_partition(path.Path() + 5, &info);
// we need to remove the "/dev/" part from the path // we need to remove the "/dev/" part from the path
if (error != B_OK) if (error != B_OK) {
dprintf("KPartition::PublishDevice(): Failed to publish partition "
"%ld: %s\n", ID(), strerror(error));
return error; return error;
}
fPublished = true; fPublished = true;
@@ -220,13 +226,21 @@ KPartition::UnpublishDevice()
// get the path // get the path
KPath path; KPath path;
status_t error = GetPath(&path); status_t error = GetPath(&path);
if (error != B_OK) if (error != B_OK) {
dprintf("KPartition::UnpublishDevice(): Failed to get path for "
"partition %ld: %s\n", ID(), strerror(error));
return error; return error;
}
fPublished = false; fPublished = false;
return devfs_unpublish_partition(path.Path() + 5); error = devfs_unpublish_partition(path.Path() + 5);
// we need to remove the "/dev/" part from the path // we need to remove the "/dev/" part from the path
if (error != B_OK) {
dprintf("KPartition::UnpublishDevice(): Failed to unpublish "
"partition %ld: %s\n", ID(), strerror(error));
}
return error;
} }
@@ -785,7 +799,8 @@ KPartition::AddChild(KPartition *partition, int32 index)
// CreateChild // CreateChild
status_t status_t
KPartition::CreateChild(partition_id id, int32 index, KPartition **_child) KPartition::CreateChild(partition_id id, int32 index, off_t offset, off_t size,
KPartition **_child)
{ {
// check parameters // check parameters
int32 count = fPartitionData.child_count; int32 count = fPartitionData.child_count;
@@ -799,6 +814,9 @@ KPartition::CreateChild(partition_id id, int32 index, KPartition **_child)
if (!child) if (!child)
return B_NO_MEMORY; return B_NO_MEMORY;
child->SetOffset(offset);
child->SetSize(size);
status_t error = AddChild(child, index); status_t error = AddChild(child, index);
// cleanup / set result // cleanup / set result
@@ -156,19 +156,22 @@ get_child_partition(partition_id partitionID, int32 index)
// create_child_partition // create_child_partition
partition_data * partition_data *
create_child_partition(partition_id partitionID, int32 index, create_child_partition(partition_id partitionID, int32 index, off_t offset,
partition_id childID) off_t size, partition_id childID)
{ {
KDiskDeviceManager *manager = KDiskDeviceManager::Default(); KDiskDeviceManager *manager = KDiskDeviceManager::Default();
if (KPartition *partition = manager->FindPartition(partitionID)) { if (KPartition *partition = manager->FindPartition(partitionID)) {
KPartition *child = NULL; KPartition *child = NULL;
if (partition->CreateChild(childID, index, &child) == B_OK) if (partition->CreateChild(childID, index, offset, size, &child)
== B_OK) {
return child->PartitionData(); return child->PartitionData();
else } else {
DBG(OUT(" creating child (%ld, %ld) failed\n", partitionID, index)); DBG(OUT(" creating child (%ld, %ld) failed\n", partitionID,
index));
} }
else } else
DBG(OUT(" partition %ld not found\n", partitionID)); DBG(OUT(" partition %ld not found\n", partitionID));
return NULL; return NULL;
} }