summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorKarel Zak2009-03-12 13:00:27 +0100
committerKarel Zak2009-03-12 13:00:27 +0100
commit8f898c578ac72abb65eef50e82382c2ef66a549e (patch)
treebf40660f900ede7dd083021e1842453c8a984dfd /lib
parentinclude: add missing files to Makefile.am (diff)
downloadkernel-qcow2-util-linux-8f898c578ac72abb65eef50e82382c2ef66a549e.tar.gz
kernel-qcow2-util-linux-8f898c578ac72abb65eef50e82382c2ef66a549e.tar.xz
kernel-qcow2-util-linux-8f898c578ac72abb65eef50e82382c2ef66a549e.zip
lib: pttype: add BSD subpartitions support
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/pttype.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/pttype.c b/lib/pttype.c
index 429b47551..23070b9ad 100644
--- a/lib/pttype.c
+++ b/lib/pttype.c
@@ -13,6 +13,9 @@
#include "blkdev.h"
+/* we need to read two sectors, beacuse BSD label offset is 512 */
+#define PTTYPE_BUFSIZ (2 * DEFAULT_SECTOR_SIZE) /* 1024 */
+
/*
* SGI
*/
@@ -212,16 +215,35 @@ mac_parttable(char *base)
ntohs(maclabel(base)->magic) == MAC_OLD_PARTITION_MAGIC);
}
+/*
+ * BSD subpartitions listed in a disklabel, under a dos-like partition.
+ */
+#define BSD_DISKMAGIC 0x82564557UL /* The disk magic number */
+#define BSD_DISKMAGIC_SWAPED 0x57455682UL
+struct bsd_disklabel {
+ uint32_t magic; /* the magic number */
+ /* ... */
+};
+
+static int
+bsd_parttable(char *base)
+{
+ struct bsd_disklabel *l = (struct bsd_disklabel *)
+ (base + (DEFAULT_SECTOR_SIZE * 1));
+
+ return (l->magic == BSD_DISKMAGIC || l->magic == BSD_DISKMAGIC_SWAPED);
+}
+
const char *
get_pt_type(const char *device)
{
int fd;
char *type = NULL;
- char buf[DEFAULT_SECTOR_SIZE];
+ char buf[PTTYPE_BUFSIZ];
if ((fd = open(device, O_RDONLY)) < 0)
;
- else if (read(fd, buf, DEFAULT_SECTOR_SIZE) != DEFAULT_SECTOR_SIZE)
+ else if (read(fd, buf, PTTYPE_BUFSIZ) != PTTYPE_BUFSIZ)
;
else {
if (sgi_parttable(buf))
@@ -234,6 +256,8 @@ get_pt_type(const char *device)
type = "DOS";
else if (mac_parttable(buf))
type = "Mac";
+ else if (bsd_parttable(buf))
+ type = "BSD";
}
if (fd >= 0)