On Linux, FreeBSD, and friends print the partition map, if we could parse it,
but failed to get the specified partition. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32662 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
/*
|
||||
* Copyright 2005-2008, Ingo Weinhold, [email protected].
|
||||
* Copyright 2005-2009, Ingo Weinhold, [email protected].
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
@@ -25,23 +26,20 @@
|
||||
# include <linux/hdreg.h>
|
||||
# include <sys/ioctl.h>
|
||||
|
||||
# include "PartitionMap.h"
|
||||
# include "PartitionMapParser.h"
|
||||
# define USE_PARTITION_MAP 1
|
||||
#elif HAIKU_HOST_PLATFORM_FREEBSD
|
||||
# include <ctype.h>
|
||||
# include <sys/disklabel.h>
|
||||
# include <sys/disk.h>
|
||||
# include <sys/ioctl.h>
|
||||
|
||||
# include "PartitionMap.h"
|
||||
# include "PartitionMapParser.h"
|
||||
# define USE_PARTITION_MAP 1
|
||||
#elif HAIKU_HOST_PLATFORM_DARWIN
|
||||
# include <ctype.h>
|
||||
# include <sys/disk.h>
|
||||
# include <sys/ioctl.h>
|
||||
|
||||
# include "PartitionMap.h"
|
||||
# include "PartitionMapParser.h"
|
||||
# define USE_PARTITION_MAP 1
|
||||
#endif
|
||||
|
||||
#ifdef __HAIKU__
|
||||
@@ -55,6 +53,11 @@
|
||||
# include "bfs_control.h"
|
||||
#endif
|
||||
|
||||
#if USE_PARTITION_MAP
|
||||
# include "PartitionMap.h"
|
||||
# include "PartitionMapParser.h"
|
||||
#endif
|
||||
|
||||
|
||||
static const char *kCommandName = "makebootable";
|
||||
|
||||
@@ -194,6 +197,7 @@ write_boot_code_part(const char *fileName, int fd, off_t imageOffset,
|
||||
|
||||
|
||||
#ifdef __HAIKU__
|
||||
|
||||
static status_t
|
||||
find_own_image(image_info *info)
|
||||
{
|
||||
@@ -208,6 +212,36 @@ find_own_image(image_info *info)
|
||||
|
||||
return B_NAME_NOT_FOUND;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if USE_PARTITION_MAP
|
||||
|
||||
static void
|
||||
dump_partition_map(const PartitionMap& map)
|
||||
{
|
||||
fprintf(stderr, "partitions:\n");
|
||||
int32 count = map.CountPartitions();
|
||||
for (int i = 0; i < count; i++) {
|
||||
const Partition* partition = map.PartitionAt(i);
|
||||
fprintf(stderr, "%2d: ", i);
|
||||
if (partition == NULL) {
|
||||
fprintf(stderr, "<null>\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (partition->IsEmpty()) {
|
||||
fprintf(stderr, "<empty>\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
fprintf(stderr, "offset: %16lld, size: %16lld, type: %x%s\n",
|
||||
(int64)partition->Offset(), (int64)partition->Size(),
|
||||
partition->Type(), partition->IsExtended() ? " (extended)" : "");
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -299,7 +333,7 @@ main(int argc, const char *const *argv)
|
||||
int64 partitionOffset = 0;
|
||||
fs_info info; // needs to be here (we use the device name later)
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
#if defined(__BEOS__) || defined(__HAIKU__)
|
||||
#if defined(__BEOS__) || defined(__HAIKU__)
|
||||
|
||||
// a directory: get the device
|
||||
error = fs_stat_dev(st.st_dev, &info);
|
||||
@@ -400,12 +434,14 @@ main(int argc, const char *const *argv)
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -483,17 +519,18 @@ main(int argc, const char *const *argv)
|
||||
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 {
|
||||
// The given device is the base device. We'll write at
|
||||
// offset 0.
|
||||
@@ -554,13 +591,15 @@ main(int argc, const char *const *argv)
|
||||
Partition *partition = map.PartitionAt(partitionIndex - 1);
|
||||
if (!partition || partition->IsEmpty()) {
|
||||
fprintf(stderr, "Error: Invalid partition index %d.\n",
|
||||
partitionIndex);
|
||||
partitionIndex);
|
||||
dump_partition_map(map);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (partition->IsExtended()) {
|
||||
fprintf(stderr, "Error: Partition %d is an extended "
|
||||
"partition.\n", partitionIndex);
|
||||
"partition.\n", partitionIndex);
|
||||
dump_partition_map(map);
|
||||
exit(1);
|
||||
}
|
||||
partitionOffset = partition->Offset();
|
||||
|
||||
Reference in New Issue
Block a user