[haiku-commits] BRANCH jessicah-github.makebootable [1ad65c46e334] src/bin/makebootable/platform/bios_ia32

  • From: jessicah-github.makebootable <community@xxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 4 Jun 2015 11:32:05 +0200 (CEST)

added 1 changeset to branch 'refs/remotes/jessicah-github/makebootable'
old head: 0000000000000000000000000000000000000000
new head: 1ad65c46e334dadb8bba730786aedcedfc60feee
overview: https://github.com/jessicah/haiku/compare/1ad65c46e334

----------------------------------------------------------------------------

1ad65c46e334: makebootable: add support for GPT partition tables

* with #4028 implemented, we can now use makebootable on
GPT formatted disks as well.

[ Jessica Hamilton <jessica.l.hamilton@xxxxxxxxx> ]

----------------------------------------------------------------------------

Commit: 1ad65c46e334dadb8bba730786aedcedfc60feee
Author: Jessica Hamilton <jessica.l.hamilton@xxxxxxxxx>
Date: Thu Jun 4 09:26:52 2015 UTC

Ticket: https://dev.haiku-os.org/ticket/4028

----------------------------------------------------------------------------

1 file changed, 59 insertions(+), 88 deletions(-)
.../platform/bios_ia32/makebootable.cpp | 147 ++++++++-----------

----------------------------------------------------------------------------

diff --git a/src/bin/makebootable/platform/bios_ia32/makebootable.cpp
b/src/bin/makebootable/platform/bios_ia32/makebootable.cpp
index 125bab6..be76fc5 100644
--- a/src/bin/makebootable/platform/bios_ia32/makebootable.cpp
+++ b/src/bin/makebootable/platform/bios_ia32/makebootable.cpp
@@ -55,6 +55,7 @@
#endif

#if USE_PARTITION_MAP
+# include "Header.h"
# include "PartitionMap.h"
# include "PartitionMapParser.h"
#endif
@@ -238,6 +239,57 @@ dump_partition_map(const PartitionMap& map)
}
}

+
+static void
+get_partition_offset(int deviceFD, off_t deviceStart, off_t deviceSize,
+ int blockSize, int partitionIndex, char *deviceName,
+ int64 &_partitionOffset)
+{
+ PartitionMapParser parser(deviceFD, deviceStart, deviceSize, blockSize);
+ PartitionMap map;
+ status_t error = parser.Parse(NULL, &map);
+ if (error == B_OK) {
+ Partition *partition = map.PartitionAt(partitionIndex - 1);
+ if (!partition || partition->IsEmpty()) {
+ fprintf(stderr, "Error: Invalid partition index %d.\n",
+ partitionIndex);
+ dump_partition_map(map);
+ exit(1);
+ }
+
+ if (partition->IsExtended()) {
+ fprintf(stderr, "Error: Partition %d is an extended "
+ "partition.\n", partitionIndex);
+ dump_partition_map(map);
+ exit(1);
+ }
+
+ _partitionOffset = partition->Offset();
+ } else {
+ // try again using GPT instead
+ EFI::Header gptHeader(baseFD, deviceSize, blockSize);
+ error = gptHeader.InitCheck();
+ if (error == B_OK && partitionIndex < gptHeader.EntryCount()) {
+ efi_partition_entry partition =
gptHeader.EntryAt(partitionIndex - 1);
+
+ if (partition.partition_type != {0x42465331, 0x3BA3,
0x10F1,
+ 0x802A4861696B7521LL}) {
+ fprintf(stderr, "Error: Partition %d does not
have the "
+ "BFS UUID.\n", partitionIndex);
+ exit(1);
+ }
+
+ _partitionOffset = partition.StartBlock();
+ } else {
+ fprintf(stderr, "Error: Parsing partition table on
device "
+ "\"%s\" failed: %s\n", deviceName,
strerror(error));
+ exit(1);
+ }
+ }
+
+ close(deviceFD);
+}
+
#endif


@@ -404,39 +456,11 @@ main(int argc, const char *const *argv)
strerror(errno));
exit(1);
}
-
+
// parse the partition map
// TODO: block size!
- PartitionMapParser parser(baseFD, 0,
deviceSize, 512);
- PartitionMap map;
- error = parser.Parse(NULL, &map);
- if (error != B_OK) {
- fprintf(stderr, "Error: Parsing
partition table on "
- "device \"%s\" failed:
%s\n", baseDeviceName,
- strerror(error));
- exit(1);
- }
-
- close(baseFD);
-
- // check the partition we are supposed
to write at
- Partition *partition =
map.PartitionAt(partitionIndex - 1);
- if (!partition || partition->IsEmpty())
{
- fprintf(stderr, "Error: Invalid
partition index %d.\n",
- partitionIndex);
- dump_partition_map(map);
- exit(1);
- }
-
- if (partition->IsExtended()) {
- fprintf(stderr, "Error:
Partition %d is an extended "
- "partition.\n",
partitionIndex);
- dump_partition_map(map);
- exit(1);
- }
-
- partitionOffset = partition->Offset();
-
+ get_partition_offset(baseFD, 0,
deviceSize, 512,
+ partitionIndex, baseDeviceName,
&partitionOffset);
} else {
// The given device is the base device.
We'll write at
// offset 0.
@@ -498,35 +522,8 @@ main(int argc, const char *const *argv)

// parse the partition map
// TODO: block size!
- PartitionMapParser parser(baseFD, 0,
deviceSize, 512);
- PartitionMap map;
- error = parser.Parse(NULL, &map);
- if (error != B_OK) {
- fprintf(stderr, "Error: Parsing
partition table on "
- "device \"%s\" failed:
%s\n", baseDeviceName,
- strerror(error));
- exit(1);
- }
-
- close(baseFD);
-
- // check the partition we are supposed
to write at
- Partition *partition =
map.PartitionAt(partitionIndex - 1);
- if (!partition || partition->IsEmpty())
{
- fprintf(stderr, "Error: Invalid
partition index %d.\n",
- partitionIndex);
- dump_partition_map(map);
- exit(1);
- }
-
- if (partition->IsExtended()) {
- fprintf(stderr, "Error:
Partition %d is an extended "
- "partition.\n",
partitionIndex);
- dump_partition_map(map);
- exit(1);
- }
-
- partitionOffset = partition->Offset();
+ get_partition_offset(baseFD, 0,
deviceSize, 512,
+ partitionIndex, baseDeviceName,
&partitionOffset);
} else {
// The given device is the base device.
We'll write at
// offset 0.
@@ -571,34 +568,8 @@ main(int argc, const char *const *argv)
deviceSize = blockSize * blockCount;

// parse the partition map
- PartitionMapParser parser(baseFD, 0,
deviceSize, blockSize);
- PartitionMap map;
- error = parser.Parse(NULL, &map);
- if (error != B_OK) {
- fprintf(stderr, "Error: Parsing
partition table on "
- "device \"%s\" failed:
%s\n", baseDeviceName,
- strerror(error));
- exit(1);
- }
-
- close(baseFD);
-
- // check the partition we are supposed to write
at
- Partition *partition =
map.PartitionAt(partitionIndex - 1);
- if (!partition || partition->IsEmpty()) {
- fprintf(stderr, "Error: Invalid
partition index %d.\n",
- partitionIndex);
- dump_partition_map(map);
- exit(1);
- }
-
- if (partition->IsExtended()) {
- fprintf(stderr, "Error: Partition %d is
an extended "
- "partition.\n", partitionIndex);
- dump_partition_map(map);
- exit(1);
- }
- partitionOffset = partition->Offset();
+ get_partition_offset(baseFD, 0, deviceSize, 512,
+ partitionIndex, baseDeviceName,
&partitionOffset);
#else
// partitions are block devices under Haiku, but not
under BeOS
#ifdef HAIKU_TARGET_PLATFORM_HAIKU


Other related posts:

  • » [haiku-commits] BRANCH jessicah-github.makebootable [1ad65c46e334] src/bin/makebootable/platform/bios_ia32 - jessicah-github . makebootable