* [PATCH] Add DragonFly BSD disklabel64 support
@ 2013-03-26 14:44 Radosław Szymczyszyn
2013-04-01 0:10 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-04-03 9:08 ` Vladimir 'φ-coder/phcoder' Serbinenko
0 siblings, 2 replies; 8+ messages in thread
From: Radosław Szymczyszyn @ 2013-03-26 14:44 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1: Type: text/plain, Size: 745 bytes --]
Hi,
2013/1/22 Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com>:
> On 21.01.2013 22:17, Radosław Szymczyszyn wrote:
>> I've written a
>> similar test, but as Parted can't create disklabel64 tables, I had to
>> include an exemplar image to test against.
>
> I think this is an issue to be taken to parted guys. If we can't have
> dragonfly label handling in it, we'll look for other solutions but first
> we have to try.
The second attached file is the test disk image mentioned in the ChangeLog.
I tried contacting the Parted team, but there're no plans for
introducing disklabel64 support to Parted on their side and I can't
spend time on it myself. I hope this solution will suffice.
Regards,
Radek Szymczyszyn
[-- Attachment #2: part-dfly.patch --]
[-- Type: application/octet-stream, Size: 10608 bytes --]
diff --git a/Makefile.util.def b/Makefile.util.def
index 1ccf390..32b0d3d 100644
--- a/Makefile.util.def
+++ b/Makefile.util.def
@@ -116,6 +116,7 @@ library = {
common = grub-core/partmap/dvh.c;
common = grub-core/partmap/sunpc.c;
common = grub-core/partmap/bsdlabel.c;
+ common = grub-core/partmap/dfly.c;
common = grub-core/script/function.c;
common = grub-core/script/lexer.c;
common = grub-core/script/main.c;
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 3bcf662..fc5680d 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -1581,6 +1581,11 @@ module = {
};
module = {
+ name = part_dfly;
+ common = partmap/dfly.c;
+};
+
+module = {
name = msdospart;
common = parttool/msdospart.c;
};
diff --git a/grub-core/partmap/dfly.c b/grub-core/partmap/dfly.c
new file mode 100644
index 0000000..7145791
--- /dev/null
+++ b/grub-core/partmap/dfly.c
@@ -0,0 +1,112 @@
+/* dfly.c - Read DragonFly BSD disklabel64. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/disk.h>
+#include <grub/disklabel64.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+#include <grub/partition.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+static struct grub_partition_map grub_dfly_partition_map;
+
+static grub_err_t
+dfly_partition_map_iterate (grub_disk_t disk,
+ grub_partition_iterate_hook_t hook,
+ void *hook_data)
+{
+ struct grub_partition part;
+ struct grub_partition_disklabel64 label;
+ struct grub_partition_disklabel64_entry dpart;
+ unsigned partno, pos;
+
+ part.partmap = &grub_dfly_partition_map;
+
+ if (grub_disk_read (disk, 0, 0, sizeof (label), &label))
+ return grub_errno;
+
+ if (label.magic != grub_cpu_to_le32_compile_time (GRUB_DISKLABEL64_MAGIC))
+ {
+ grub_dprintf ("partition",
+ "bad magic (found 0x%" PRIxGRUB_UINT32_T "; "
+ "wanted 0x%" PRIxGRUB_UINT32_T ")\n",
+ grub_le_to_cpu32 (label.magic),
+ GRUB_DISKLABEL64_MAGIC);
+ goto fail;
+ }
+
+ pos = sizeof (label);
+
+ for (partno = 0;
+ partno < grub_le_to_cpu32 (label.npartitions); ++partno)
+ {
+ grub_disk_addr_t sector = pos >> GRUB_DISK_SECTOR_BITS;
+ grub_off_t offset = pos & (GRUB_DISK_SECTOR_SIZE - 1);
+ pos += sizeof (dpart);
+ if (grub_disk_read (disk, sector, offset, sizeof (dpart), &dpart))
+ return grub_errno;
+
+ grub_dprintf ("partition",
+ "partition %2d: offset 0x%" PRIxGRUB_UINT64_T ", "
+ "size 0x%" PRIxGRUB_UINT64_T "\n",
+ partno,
+ grub_le_to_cpu64 (dpart.boffset),
+ grub_le_to_cpu64 (dpart.bsize));
+
+ /* Is partition initialized? */
+ if (! (dpart.boffset && dpart.bsize))
+ continue;
+
+ part.number = partno;
+ part.start = grub_le_to_cpu64 (dpart.boffset) >> GRUB_DISK_SECTOR_BITS;
+ part.len = grub_le_to_cpu64 (dpart.bsize) >> GRUB_DISK_SECTOR_BITS;
+
+ /* This is counter-intuitive, but part.offset and sector have
+ * the same type, and offset (NOT part.offset) is guaranteed
+ * to fit into part.index. */
+ part.offset = sector;
+ part.index = offset;
+
+ if (hook (disk, &part, hook_data))
+ return grub_errno;
+ }
+
+ return GRUB_ERR_NONE;
+
+fail:
+ return grub_error (GRUB_ERR_BAD_PART_TABLE, "disklabel64 not found");
+}
+
+/* Partition map type. */
+static struct grub_partition_map grub_dfly_partition_map =
+{
+ .name = "dfly",
+ .iterate = dfly_partition_map_iterate,
+};
+
+GRUB_MOD_INIT(part_dfly)
+{
+ grub_partition_map_register (&grub_dfly_partition_map);
+}
+
+GRUB_MOD_FINI(part_dfly)
+{
+ grub_partition_map_unregister (&grub_dfly_partition_map);
+}
diff --git a/include/grub/disklabel64.h b/include/grub/disklabel64.h
new file mode 100644
index 0000000..0105b96
--- /dev/null
+++ b/include/grub/disklabel64.h
@@ -0,0 +1,127 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ * Copyright (c) 2007 The DragonFly Project. All rights reserved.
+ *
+ * This code is derived from software contributed to The DragonFly Project
+ * by Matthew Dillon <dillon@backplane.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name of The DragonFly Project nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific, prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $DragonFly: src/sys/sys/disklabel64.h,v 1.4 2007/06/19 06:39:10 dillon Exp $
+ */
+
+#ifndef GRUB_DISKLABEL64_PARTITION_HEADER
+#define GRUB_DISKLABEL64_PARTITION_HEADER 1
+
+#define GRUB_DISKLABEL64_MAGIC ((grub_uint32_t)0xc4464c59)
+#define GRUB_DISKLABEL64_MAX_PARTITIONS 16
+
+/*
+ * Note: offsets are relative to the base of the slice, NOT to
+ * pbase. Unlike 32 bit disklabels the on-disk format for
+ * a 64 bit disklabel remains slice-relative.
+ *
+ * An uninitialized partition has a boffset and bsize of 0.
+ *
+ * If fstype is not supported for a live partition it is set
+ * to FS_OTHER. This is typically the case when the filesystem
+ * is identified by its uuid.
+ */
+struct grub_partition_disklabel64_entry
+{
+ /* slice relative offset, in bytes */
+ grub_uint64_t boffset;
+ /* size of partition, in bytes */
+ grub_uint64_t bsize;
+ grub_uint8_t fstype;
+ /* reserved, all must be 0 */
+ grub_uint8_t unused01;
+ grub_uint8_t unused02;
+ grub_uint8_t unused03;
+ grub_uint32_t unused04;
+ grub_uint32_t unused05;
+ grub_uint32_t unused06;
+ /* unused by GRUB struct uuid type_uuid */
+ grub_uint8_t unused07[16];
+ /* unused by GRUB struct uuid stor_uuid */
+ grub_uint8_t unused08[16];
+} __attribute__ ((packed));
+
+/*
+ * A disklabel64 starts at slice relative offset 0, NOT SECTOR 1. In
+ * otherwords, magic is at byte offset 512 within the slice, regardless
+ * of the sector size.
+ *
+ * The reserved0 area is not included in the crc and any kernel writeback
+ * of the label will not change the reserved area on-disk. It is purely
+ * a shim to allow us to avoid sector calculations when reading or
+ * writing the label. Since byte offsets are used in our 64 bit disklabel,
+ * the entire disklabel and the I/O required to access it becomes
+ * sector-agnostic.
+ */
+struct grub_partition_disklabel64
+{
+ /* reserved or unused */
+ grub_int8_t reserved0[512];
+ /* the magic number */
+ grub_uint32_t magic;
+ /* crc32() magic thru last part */
+ grub_uint32_t crc;
+ /* partition alignment requirement */
+ grub_uint32_t align;
+ /* number of partitions */
+ grub_uint32_t npartitions;
+ /* unused by GRUB struct uuid stor_uuid */
+ grub_uint8_t unused01[16];
+
+ /* total size incl everything (bytes) */
+ grub_uint64_t total_size;
+ /* boot area base offset (bytes) */
+ /* boot area is pbase - bbase */
+ grub_uint64_t bbase;
+
+ /* first allocatable offset (bytes) */
+ grub_uint64_t pbase;
+ /* last allocatable offset+1 (bytes) */
+ grub_uint64_t pstop;
+ /* location of backup copy if not 0 */
+ grub_uint64_t abase;
+
+ grub_uint8_t packname[64];
+ grub_uint8_t reserved[64];
+
+ /*
+ * Partition table entries follow. In original struct definition
+ * they were declared as part of this structure like:
+ * struct grub_partition_disklabel64_entry
+ * partitions[GRUB_DISKLABEL64_MAX_PARTITIONS];
+ */
+} __attribute__ ((packed));
+
+#endif /* ! GRUB_DISKLABEL64_PARTITION_HEADER */
diff --git a/tests/partmap_test.in b/tests/partmap_test.in
index 1507220..6875547 100644
--- a/tests/partmap_test.in
+++ b/tests/partmap_test.in
@@ -28,6 +28,12 @@ create_disk_image () {
dd if=/dev/zero of="${name}" bs=512 count=1 seek=$((size * 2048 - 1)) status=noxfer > /dev/null
}
+create_dfly_image () {
+ name="$1"
+ rm -f ${name}
+ dd if="@builddir@/tests/dfly-mbr-mbexample.img" of=${name} > /dev/null
+}
+
check_output () {
outfile=$1
shift
@@ -289,3 +295,13 @@ create_disk_image "${imgfile}" 128
${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M mkpart b 10M 20M mkpart c 20M 30M mkpart d 30M 40M mkpart e 40M 50M mkpart f 50M 60M
list_parts part_apple "${imgfile}" "${outfile}"
check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5 $disk,apple6 $disk,apple7 $disk,apple8
+
+#
+# DragonFly BSD disklabel64
+#
+
+echo "Checking DragonFly BSD disklabel64..."
+
+create_dfly_image "${imgfile}"
+list_parts part_dfly "${imgfile}" "${outfile}"
+check_output "${outfile}" $disk $disk,msdos1 $disk,msdos1,dfly1 $disk,msdos1,dfly2 $disk,msdos1,dfly3
[-- Attachment #3: dfly-mbr-mbexample.img.gz --]
[-- Type: application/x-gzip, Size: 35685 bytes --]
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] Add DragonFly BSD disklabel64 support
2013-03-26 14:44 [PATCH] Add DragonFly BSD disklabel64 support Radosław Szymczyszyn
@ 2013-04-01 0:10 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-04-01 11:43 ` Radosław Szymczyszyn
2013-04-03 9:08 ` Vladimir 'φ-coder/phcoder' Serbinenko
1 sibling, 1 reply; 8+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-04-01 0:10 UTC (permalink / raw)
To: The development of GNU GRUB
[-- Attachment #1: Type: text/plain, Size: 166 bytes --]
On 26.03.2013 15:44, Radosław Szymczyszyn wrote:
> + if (! (dpart.boffset && dpart.bsize))
> + continue;
Why do you exclude partitions starting at 0?
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] Add DragonFly BSD disklabel64 support
2013-04-01 0:10 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2013-04-01 11:43 ` Radosław Szymczyszyn
2013-04-01 12:25 ` Radosław Szymczyszyn
0 siblings, 1 reply; 8+ messages in thread
From: Radosław Szymczyszyn @ 2013-04-01 11:43 UTC (permalink / raw)
To: The development of GNU GRUB
[-- Attachment #1: Type: text/plain, Size: 526 bytes --]
2013/4/1 Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com>
> On 26.03.2013 15:44, Radosław Szymczyszyn wrote:
>
> > + if (! (dpart.boffset && dpart.bsize))
> > + continue;
>
> Why do you exclude partitions starting at 0?
>
Sorry, my mistake. The contract says that "an uninitialized partition has a
boffset and bsize of 0." So the correct condition would be (!
(dpart.boffset || dpart.bsize)), but given that a zero-sized partition is
of little use it's best to just use (dpart.bsize == 0).
[-- Attachment #2: Type: text/html, Size: 876 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] Add DragonFly BSD disklabel64 support
2013-04-01 11:43 ` Radosław Szymczyszyn
@ 2013-04-01 12:25 ` Radosław Szymczyszyn
0 siblings, 0 replies; 8+ messages in thread
From: Radosław Szymczyszyn @ 2013-04-01 12:25 UTC (permalink / raw)
To: The development of GNU GRUB
[-- Attachment #1.1: Type: text/plain, Size: 650 bytes --]
2013/4/1 Radosław Szymczyszyn <lavrin@gmail.com>
> 2013/4/1 Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com>
>
>> On 26.03.2013 15:44, Radosław Szymczyszyn wrote:
>>
>> > + if (! (dpart.boffset && dpart.bsize))
>> > + continue;
>>
>> Why do you exclude partitions starting at 0?
>>
>
> Sorry, my mistake. The contract says that "an uninitialized partition has
> a boffset and bsize of 0." So the correct condition would be (!
> (dpart.boffset || dpart.bsize)), but given that a zero-sized partition is
> of little use it's best to just use (dpart.bsize == 0).
>
Here's the patch with the condition adjusted.
[-- Attachment #1.2: Type: text/html, Size: 1313 bytes --]
[-- Attachment #2: part-dfly.2.patch --]
[-- Type: application/octet-stream, Size: 10592 bytes --]
diff --git a/Makefile.util.def b/Makefile.util.def
index 1ccf390..32b0d3d 100644
--- a/Makefile.util.def
+++ b/Makefile.util.def
@@ -116,6 +116,7 @@ library = {
common = grub-core/partmap/dvh.c;
common = grub-core/partmap/sunpc.c;
common = grub-core/partmap/bsdlabel.c;
+ common = grub-core/partmap/dfly.c;
common = grub-core/script/function.c;
common = grub-core/script/lexer.c;
common = grub-core/script/main.c;
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 3bcf662..fc5680d 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -1581,6 +1581,11 @@ module = {
};
module = {
+ name = part_dfly;
+ common = partmap/dfly.c;
+};
+
+module = {
name = msdospart;
common = parttool/msdospart.c;
};
diff --git a/grub-core/partmap/dfly.c b/grub-core/partmap/dfly.c
new file mode 100644
index 0000000..d28ffcd
--- /dev/null
+++ b/grub-core/partmap/dfly.c
@@ -0,0 +1,112 @@
+/* dfly.c - Read DragonFly BSD disklabel64. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/disk.h>
+#include <grub/disklabel64.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+#include <grub/partition.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+static struct grub_partition_map grub_dfly_partition_map;
+
+static grub_err_t
+dfly_partition_map_iterate (grub_disk_t disk,
+ grub_partition_iterate_hook_t hook,
+ void *hook_data)
+{
+ struct grub_partition part;
+ struct grub_partition_disklabel64 label;
+ struct grub_partition_disklabel64_entry dpart;
+ unsigned partno, pos;
+
+ part.partmap = &grub_dfly_partition_map;
+
+ if (grub_disk_read (disk, 0, 0, sizeof (label), &label))
+ return grub_errno;
+
+ if (label.magic != grub_cpu_to_le32_compile_time (GRUB_DISKLABEL64_MAGIC))
+ {
+ grub_dprintf ("partition",
+ "bad magic (found 0x%" PRIxGRUB_UINT32_T "; "
+ "wanted 0x%" PRIxGRUB_UINT32_T ")\n",
+ grub_le_to_cpu32 (label.magic),
+ GRUB_DISKLABEL64_MAGIC);
+ goto fail;
+ }
+
+ pos = sizeof (label);
+
+ for (partno = 0;
+ partno < grub_le_to_cpu32 (label.npartitions); ++partno)
+ {
+ grub_disk_addr_t sector = pos >> GRUB_DISK_SECTOR_BITS;
+ grub_off_t offset = pos & (GRUB_DISK_SECTOR_SIZE - 1);
+ pos += sizeof (dpart);
+ if (grub_disk_read (disk, sector, offset, sizeof (dpart), &dpart))
+ return grub_errno;
+
+ grub_dprintf ("partition",
+ "partition %2d: offset 0x%" PRIxGRUB_UINT64_T ", "
+ "size 0x%" PRIxGRUB_UINT64_T "\n",
+ partno,
+ grub_le_to_cpu64 (dpart.boffset),
+ grub_le_to_cpu64 (dpart.bsize));
+
+ /* Is partition initialized? */
+ if (dpart.bsize == 0)
+ continue;
+
+ part.number = partno;
+ part.start = grub_le_to_cpu64 (dpart.boffset) >> GRUB_DISK_SECTOR_BITS;
+ part.len = grub_le_to_cpu64 (dpart.bsize) >> GRUB_DISK_SECTOR_BITS;
+
+ /* This is counter-intuitive, but part.offset and sector have
+ * the same type, and offset (NOT part.offset) is guaranteed
+ * to fit into part.index. */
+ part.offset = sector;
+ part.index = offset;
+
+ if (hook (disk, &part, hook_data))
+ return grub_errno;
+ }
+
+ return GRUB_ERR_NONE;
+
+fail:
+ return grub_error (GRUB_ERR_BAD_PART_TABLE, "disklabel64 not found");
+}
+
+/* Partition map type. */
+static struct grub_partition_map grub_dfly_partition_map =
+{
+ .name = "dfly",
+ .iterate = dfly_partition_map_iterate,
+};
+
+GRUB_MOD_INIT(part_dfly)
+{
+ grub_partition_map_register (&grub_dfly_partition_map);
+}
+
+GRUB_MOD_FINI(part_dfly)
+{
+ grub_partition_map_unregister (&grub_dfly_partition_map);
+}
diff --git a/include/grub/disklabel64.h b/include/grub/disklabel64.h
new file mode 100644
index 0000000..0105b96
--- /dev/null
+++ b/include/grub/disklabel64.h
@@ -0,0 +1,127 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ * Copyright (c) 2007 The DragonFly Project. All rights reserved.
+ *
+ * This code is derived from software contributed to The DragonFly Project
+ * by Matthew Dillon <dillon@backplane.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name of The DragonFly Project nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific, prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $DragonFly: src/sys/sys/disklabel64.h,v 1.4 2007/06/19 06:39:10 dillon Exp $
+ */
+
+#ifndef GRUB_DISKLABEL64_PARTITION_HEADER
+#define GRUB_DISKLABEL64_PARTITION_HEADER 1
+
+#define GRUB_DISKLABEL64_MAGIC ((grub_uint32_t)0xc4464c59)
+#define GRUB_DISKLABEL64_MAX_PARTITIONS 16
+
+/*
+ * Note: offsets are relative to the base of the slice, NOT to
+ * pbase. Unlike 32 bit disklabels the on-disk format for
+ * a 64 bit disklabel remains slice-relative.
+ *
+ * An uninitialized partition has a boffset and bsize of 0.
+ *
+ * If fstype is not supported for a live partition it is set
+ * to FS_OTHER. This is typically the case when the filesystem
+ * is identified by its uuid.
+ */
+struct grub_partition_disklabel64_entry
+{
+ /* slice relative offset, in bytes */
+ grub_uint64_t boffset;
+ /* size of partition, in bytes */
+ grub_uint64_t bsize;
+ grub_uint8_t fstype;
+ /* reserved, all must be 0 */
+ grub_uint8_t unused01;
+ grub_uint8_t unused02;
+ grub_uint8_t unused03;
+ grub_uint32_t unused04;
+ grub_uint32_t unused05;
+ grub_uint32_t unused06;
+ /* unused by GRUB struct uuid type_uuid */
+ grub_uint8_t unused07[16];
+ /* unused by GRUB struct uuid stor_uuid */
+ grub_uint8_t unused08[16];
+} __attribute__ ((packed));
+
+/*
+ * A disklabel64 starts at slice relative offset 0, NOT SECTOR 1. In
+ * otherwords, magic is at byte offset 512 within the slice, regardless
+ * of the sector size.
+ *
+ * The reserved0 area is not included in the crc and any kernel writeback
+ * of the label will not change the reserved area on-disk. It is purely
+ * a shim to allow us to avoid sector calculations when reading or
+ * writing the label. Since byte offsets are used in our 64 bit disklabel,
+ * the entire disklabel and the I/O required to access it becomes
+ * sector-agnostic.
+ */
+struct grub_partition_disklabel64
+{
+ /* reserved or unused */
+ grub_int8_t reserved0[512];
+ /* the magic number */
+ grub_uint32_t magic;
+ /* crc32() magic thru last part */
+ grub_uint32_t crc;
+ /* partition alignment requirement */
+ grub_uint32_t align;
+ /* number of partitions */
+ grub_uint32_t npartitions;
+ /* unused by GRUB struct uuid stor_uuid */
+ grub_uint8_t unused01[16];
+
+ /* total size incl everything (bytes) */
+ grub_uint64_t total_size;
+ /* boot area base offset (bytes) */
+ /* boot area is pbase - bbase */
+ grub_uint64_t bbase;
+
+ /* first allocatable offset (bytes) */
+ grub_uint64_t pbase;
+ /* last allocatable offset+1 (bytes) */
+ grub_uint64_t pstop;
+ /* location of backup copy if not 0 */
+ grub_uint64_t abase;
+
+ grub_uint8_t packname[64];
+ grub_uint8_t reserved[64];
+
+ /*
+ * Partition table entries follow. In original struct definition
+ * they were declared as part of this structure like:
+ * struct grub_partition_disklabel64_entry
+ * partitions[GRUB_DISKLABEL64_MAX_PARTITIONS];
+ */
+} __attribute__ ((packed));
+
+#endif /* ! GRUB_DISKLABEL64_PARTITION_HEADER */
diff --git a/tests/partmap_test.in b/tests/partmap_test.in
index 1507220..6875547 100644
--- a/tests/partmap_test.in
+++ b/tests/partmap_test.in
@@ -28,6 +28,12 @@ create_disk_image () {
dd if=/dev/zero of="${name}" bs=512 count=1 seek=$((size * 2048 - 1)) status=noxfer > /dev/null
}
+create_dfly_image () {
+ name="$1"
+ rm -f ${name}
+ dd if="@builddir@/tests/dfly-mbr-mbexample.img" of=${name} > /dev/null
+}
+
check_output () {
outfile=$1
shift
@@ -289,3 +295,13 @@ create_disk_image "${imgfile}" 128
${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M mkpart b 10M 20M mkpart c 20M 30M mkpart d 30M 40M mkpart e 40M 50M mkpart f 50M 60M
list_parts part_apple "${imgfile}" "${outfile}"
check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5 $disk,apple6 $disk,apple7 $disk,apple8
+
+#
+# DragonFly BSD disklabel64
+#
+
+echo "Checking DragonFly BSD disklabel64..."
+
+create_dfly_image "${imgfile}"
+list_parts part_dfly "${imgfile}" "${outfile}"
+check_output "${outfile}" $disk $disk,msdos1 $disk,msdos1,dfly1 $disk,msdos1,dfly2 $disk,msdos1,dfly3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] Add DragonFly BSD disklabel64 support
2013-03-26 14:44 [PATCH] Add DragonFly BSD disklabel64 support Radosław Szymczyszyn
2013-04-01 0:10 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2013-04-03 9:08 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-04-03 17:59 ` Radosław Szymczyszyn
1 sibling, 1 reply; 8+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-04-03 9:08 UTC (permalink / raw)
To: The development of GNU GRUB
[-- Attachment #1: Type: text/plain, Size: 239 bytes --]
On 26.03.2013 15:44, Radosław Szymczyszyn wrote:
> +fail:
> + return grub_error (GRUB_ERR_BAD_PART_TABLE, "disklabel64 not found");
> +}
There is only one user for this label. Please put this part directly at
where it's used
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] Add DragonFly BSD disklabel64 support
2013-04-03 9:08 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2013-04-03 17:59 ` Radosław Szymczyszyn
2013-05-15 15:52 ` Vladimir 'φ-coder/phcoder' Serbinenko
0 siblings, 1 reply; 8+ messages in thread
From: Radosław Szymczyszyn @ 2013-04-03 17:59 UTC (permalink / raw)
To: The development of GNU GRUB
[-- Attachment #1: Type: text/plain, Size: 248 bytes --]
> Please email the following information [...]
Done.
>> +fail:
>> + return grub_error (GRUB_ERR_BAD_PART_TABLE, "disklabel64 not found");
>> +}
> There is only one user for this label. Please put this part directly at
> where it's used
Fixed.
[-- Attachment #2: part-dfly.3.patch --]
[-- Type: application/octet-stream, Size: 10569 bytes --]
diff --git a/Makefile.util.def b/Makefile.util.def
index 1ccf390..32b0d3d 100644
--- a/Makefile.util.def
+++ b/Makefile.util.def
@@ -116,6 +116,7 @@ library = {
common = grub-core/partmap/dvh.c;
common = grub-core/partmap/sunpc.c;
common = grub-core/partmap/bsdlabel.c;
+ common = grub-core/partmap/dfly.c;
common = grub-core/script/function.c;
common = grub-core/script/lexer.c;
common = grub-core/script/main.c;
diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def
index 3bcf662..fc5680d 100644
--- a/grub-core/Makefile.core.def
+++ b/grub-core/Makefile.core.def
@@ -1581,6 +1581,11 @@ module = {
};
module = {
+ name = part_dfly;
+ common = partmap/dfly.c;
+};
+
+module = {
name = msdospart;
common = parttool/msdospart.c;
};
diff --git a/grub-core/partmap/dfly.c b/grub-core/partmap/dfly.c
new file mode 100644
index 0000000..49a887f
--- /dev/null
+++ b/grub-core/partmap/dfly.c
@@ -0,0 +1,109 @@
+/* dfly.c - Read DragonFly BSD disklabel64. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ *
+ * GRUB is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GRUB is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/disk.h>
+#include <grub/disklabel64.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+#include <grub/partition.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+static struct grub_partition_map grub_dfly_partition_map;
+
+static grub_err_t
+dfly_partition_map_iterate (grub_disk_t disk,
+ grub_partition_iterate_hook_t hook,
+ void *hook_data)
+{
+ struct grub_partition part;
+ struct grub_partition_disklabel64 label;
+ struct grub_partition_disklabel64_entry dpart;
+ unsigned partno, pos;
+
+ part.partmap = &grub_dfly_partition_map;
+
+ if (grub_disk_read (disk, 0, 0, sizeof (label), &label))
+ return grub_errno;
+
+ if (label.magic != grub_cpu_to_le32_compile_time (GRUB_DISKLABEL64_MAGIC))
+ {
+ grub_dprintf ("partition",
+ "bad magic (found 0x%" PRIxGRUB_UINT32_T "; "
+ "wanted 0x%" PRIxGRUB_UINT32_T ")\n",
+ grub_le_to_cpu32 (label.magic),
+ GRUB_DISKLABEL64_MAGIC);
+ return grub_error (GRUB_ERR_BAD_PART_TABLE, "disklabel64 not found");
+ }
+
+ pos = sizeof (label);
+
+ for (partno = 0;
+ partno < grub_le_to_cpu32 (label.npartitions); ++partno)
+ {
+ grub_disk_addr_t sector = pos >> GRUB_DISK_SECTOR_BITS;
+ grub_off_t offset = pos & (GRUB_DISK_SECTOR_SIZE - 1);
+ pos += sizeof (dpart);
+ if (grub_disk_read (disk, sector, offset, sizeof (dpart), &dpart))
+ return grub_errno;
+
+ grub_dprintf ("partition",
+ "partition %2d: offset 0x%" PRIxGRUB_UINT64_T ", "
+ "size 0x%" PRIxGRUB_UINT64_T "\n",
+ partno,
+ grub_le_to_cpu64 (dpart.boffset),
+ grub_le_to_cpu64 (dpart.bsize));
+
+ /* Is partition initialized? */
+ if (dpart.bsize == 0)
+ continue;
+
+ part.number = partno;
+ part.start = grub_le_to_cpu64 (dpart.boffset) >> GRUB_DISK_SECTOR_BITS;
+ part.len = grub_le_to_cpu64 (dpart.bsize) >> GRUB_DISK_SECTOR_BITS;
+
+ /* This is counter-intuitive, but part.offset and sector have
+ * the same type, and offset (NOT part.offset) is guaranteed
+ * to fit into part.index. */
+ part.offset = sector;
+ part.index = offset;
+
+ if (hook (disk, &part, hook_data))
+ return grub_errno;
+ }
+
+ return GRUB_ERR_NONE;
+}
+
+/* Partition map type. */
+static struct grub_partition_map grub_dfly_partition_map =
+{
+ .name = "dfly",
+ .iterate = dfly_partition_map_iterate,
+};
+
+GRUB_MOD_INIT(part_dfly)
+{
+ grub_partition_map_register (&grub_dfly_partition_map);
+}
+
+GRUB_MOD_FINI(part_dfly)
+{
+ grub_partition_map_unregister (&grub_dfly_partition_map);
+}
diff --git a/include/grub/disklabel64.h b/include/grub/disklabel64.h
new file mode 100644
index 0000000..0105b96
--- /dev/null
+++ b/include/grub/disklabel64.h
@@ -0,0 +1,127 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2013 Free Software Foundation, Inc.
+ * Copyright (c) 2007 The DragonFly Project. All rights reserved.
+ *
+ * This code is derived from software contributed to The DragonFly Project
+ * by Matthew Dillon <dillon@backplane.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name of The DragonFly Project nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific, prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $DragonFly: src/sys/sys/disklabel64.h,v 1.4 2007/06/19 06:39:10 dillon Exp $
+ */
+
+#ifndef GRUB_DISKLABEL64_PARTITION_HEADER
+#define GRUB_DISKLABEL64_PARTITION_HEADER 1
+
+#define GRUB_DISKLABEL64_MAGIC ((grub_uint32_t)0xc4464c59)
+#define GRUB_DISKLABEL64_MAX_PARTITIONS 16
+
+/*
+ * Note: offsets are relative to the base of the slice, NOT to
+ * pbase. Unlike 32 bit disklabels the on-disk format for
+ * a 64 bit disklabel remains slice-relative.
+ *
+ * An uninitialized partition has a boffset and bsize of 0.
+ *
+ * If fstype is not supported for a live partition it is set
+ * to FS_OTHER. This is typically the case when the filesystem
+ * is identified by its uuid.
+ */
+struct grub_partition_disklabel64_entry
+{
+ /* slice relative offset, in bytes */
+ grub_uint64_t boffset;
+ /* size of partition, in bytes */
+ grub_uint64_t bsize;
+ grub_uint8_t fstype;
+ /* reserved, all must be 0 */
+ grub_uint8_t unused01;
+ grub_uint8_t unused02;
+ grub_uint8_t unused03;
+ grub_uint32_t unused04;
+ grub_uint32_t unused05;
+ grub_uint32_t unused06;
+ /* unused by GRUB struct uuid type_uuid */
+ grub_uint8_t unused07[16];
+ /* unused by GRUB struct uuid stor_uuid */
+ grub_uint8_t unused08[16];
+} __attribute__ ((packed));
+
+/*
+ * A disklabel64 starts at slice relative offset 0, NOT SECTOR 1. In
+ * otherwords, magic is at byte offset 512 within the slice, regardless
+ * of the sector size.
+ *
+ * The reserved0 area is not included in the crc and any kernel writeback
+ * of the label will not change the reserved area on-disk. It is purely
+ * a shim to allow us to avoid sector calculations when reading or
+ * writing the label. Since byte offsets are used in our 64 bit disklabel,
+ * the entire disklabel and the I/O required to access it becomes
+ * sector-agnostic.
+ */
+struct grub_partition_disklabel64
+{
+ /* reserved or unused */
+ grub_int8_t reserved0[512];
+ /* the magic number */
+ grub_uint32_t magic;
+ /* crc32() magic thru last part */
+ grub_uint32_t crc;
+ /* partition alignment requirement */
+ grub_uint32_t align;
+ /* number of partitions */
+ grub_uint32_t npartitions;
+ /* unused by GRUB struct uuid stor_uuid */
+ grub_uint8_t unused01[16];
+
+ /* total size incl everything (bytes) */
+ grub_uint64_t total_size;
+ /* boot area base offset (bytes) */
+ /* boot area is pbase - bbase */
+ grub_uint64_t bbase;
+
+ /* first allocatable offset (bytes) */
+ grub_uint64_t pbase;
+ /* last allocatable offset+1 (bytes) */
+ grub_uint64_t pstop;
+ /* location of backup copy if not 0 */
+ grub_uint64_t abase;
+
+ grub_uint8_t packname[64];
+ grub_uint8_t reserved[64];
+
+ /*
+ * Partition table entries follow. In original struct definition
+ * they were declared as part of this structure like:
+ * struct grub_partition_disklabel64_entry
+ * partitions[GRUB_DISKLABEL64_MAX_PARTITIONS];
+ */
+} __attribute__ ((packed));
+
+#endif /* ! GRUB_DISKLABEL64_PARTITION_HEADER */
diff --git a/tests/partmap_test.in b/tests/partmap_test.in
index 1507220..6875547 100644
--- a/tests/partmap_test.in
+++ b/tests/partmap_test.in
@@ -28,6 +28,12 @@ create_disk_image () {
dd if=/dev/zero of="${name}" bs=512 count=1 seek=$((size * 2048 - 1)) status=noxfer > /dev/null
}
+create_dfly_image () {
+ name="$1"
+ rm -f ${name}
+ dd if="@builddir@/tests/dfly-mbr-mbexample.img" of=${name} > /dev/null
+}
+
check_output () {
outfile=$1
shift
@@ -289,3 +295,13 @@ create_disk_image "${imgfile}" 128
${parted} -a none -s "${imgfile}" mklabel mac mkpart a 1M 10M mkpart b 10M 20M mkpart c 20M 30M mkpart d 30M 40M mkpart e 40M 50M mkpart f 50M 60M
list_parts part_apple "${imgfile}" "${outfile}"
check_output "${outfile}" $disk $disk,apple1 $disk,apple2 $disk,apple4 $disk,apple5 $disk,apple6 $disk,apple7 $disk,apple8
+
+#
+# DragonFly BSD disklabel64
+#
+
+echo "Checking DragonFly BSD disklabel64..."
+
+create_dfly_image "${imgfile}"
+list_parts part_dfly "${imgfile}" "${outfile}"
+check_output "${outfile}" $disk $disk,msdos1 $disk,msdos1,dfly1 $disk,msdos1,dfly2 $disk,msdos1,dfly3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] Add DragonFly BSD disklabel64 support
2013-04-03 17:59 ` Radosław Szymczyszyn
@ 2013-05-15 15:52 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-05-18 14:31 ` Radosław Szymczyszyn
0 siblings, 1 reply; 8+ messages in thread
From: Vladimir 'φ-coder/phcoder' Serbinenko @ 2013-05-15 15:52 UTC (permalink / raw)
To: grub-devel
[-- Attachment #1: Type: text/plain, Size: 612 bytes --]
Comitted after correcting several problems including the fact that image
you provided contained bootloader.
On 03.04.2013 19:59, Radosław Szymczyszyn wrote:
>> Please email the following information [...]
>
> Done.
>
>>> +fail:
>>> + return grub_error (GRUB_ERR_BAD_PART_TABLE, "disklabel64 not found");
>>> +}
>
>> There is only one user for this label. Please put this part directly at
>> where it's used
>
> Fixed.
>
>
>
> _______________________________________________
> Grub-devel mailing list
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] Add DragonFly BSD disklabel64 support
2013-05-15 15:52 ` Vladimir 'φ-coder/phcoder' Serbinenko
@ 2013-05-18 14:31 ` Radosław Szymczyszyn
0 siblings, 0 replies; 8+ messages in thread
From: Radosław Szymczyszyn @ 2013-05-18 14:31 UTC (permalink / raw)
To: The development of GNU GRUB
2013/5/15 Vladimir 'φ-coder/phcoder' Serbinenko <phcoder@gmail.com>:
> Comitted after correcting several problems including the fact that image
> you provided contained bootloader.
Great to "hear" that!
I'm not sure about a bootloader right now (DragonFly's fdisk might
place one by default when creating a partition table), but the UFS
filesystem contained the Multiboot example kernel. I should've told
you about that in the first place, sorry.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2013-05-18 14:31 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-26 14:44 [PATCH] Add DragonFly BSD disklabel64 support Radosław Szymczyszyn
2013-04-01 0:10 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-04-01 11:43 ` Radosław Szymczyszyn
2013-04-01 12:25 ` Radosław Szymczyszyn
2013-04-03 9:08 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-04-03 17:59 ` Radosław Szymczyszyn
2013-05-15 15:52 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-05-18 14:31 ` Radosław Szymczyszyn
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.