]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
* grub-core/partmap/dfly.c: New partition map.
authorRadosław Szymczyszyn <lavrin@gmail.com>
Wed, 15 May 2013 15:26:49 +0000 (17:26 +0200)
committerVladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Wed, 15 May 2013 15:26:49 +0000 (17:26 +0200)
ChangeLog
Makefile.util.def
grub-core/Makefile.core.def
grub-core/partmap/dfly.c [new file with mode: 0644]
tests/dfly-mbr-mbexample.dfly.img.gz [new file with mode: 0644]
tests/dfly-mbr-mbexample.mbr.img.gz [new file with mode: 0644]
tests/partmap_test.in

index b59e311348d2ac880efc9af28ccccc4c12c9500b..e2e38f307df635dfad5d16c6b7dc069f58dd02db 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2013-05-15  Radosław Szymczyszyn  <lavrin@gmail.com>
+
+       * grub-core/partmap/dfly.c: New partition map.
+
 2013-05-15  Vladimir Serbinenko  <phcoder@gmail.com>
 
        * grub-core/kern/corecmd.c (grub_core_cmd_ls): Fix empty path
index 6cc15cbf2fafc53f904e6c001e680015000fa118..17fdfa5694e0b9d76f8a609d054f4699451ae17d 100644 (file)
@@ -130,6 +130,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;
index 602b49765cf3c6aba2515c53e981e3e3622d8514..b63d33d0f24678c5436b9ad257081c4df934719d 100644 (file)
@@ -1652,6 +1652,11 @@ module = {
   common = partmap/sunpc.c;
 };
 
+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 (file)
index 0000000..e72b799
--- /dev/null
@@ -0,0 +1,133 @@
+/* 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/misc.h>
+#include <grub/mm.h>
+#include <grub/partition.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+static struct grub_partition_map grub_dfly_partition_map;
+
+#define GRUB_PARTITION_DISKLABEL64_HEADER_SIZE 200
+
+/* Full entry is 64 bytes however we really care only
+   about offset and size which are in first 16 bytes.
+   Avoid using too much stack.  */
+#define GRUB_PARTITION_DISKLABEL64_ENTRY_SIZE 64
+struct grub_partition_disklabel64_entry
+{
+  grub_uint64_t boffset;
+  grub_uint64_t bsize;
+};
+
+/* Full entry is 200 bytes however we really care only
+   about magic and number of partitions which are in first 16 bytes.
+   Avoid using too much stack.  */
+struct grub_partition_disklabel64
+{
+  grub_uint32_t   magic;
+#define GRUB_DISKLABEL64_MAGIC           ((grub_uint32_t)0xc4464c59)
+  grub_uint32_t   crc;
+  grub_uint32_t   unused;
+  grub_uint32_t   npartitions;
+};
+
+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;
+  unsigned partno, pos;
+  struct grub_partition_disklabel64 label;
+
+  part.partmap = &grub_dfly_partition_map;
+
+  if (grub_disk_read (disk, 1, 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 = GRUB_PARTITION_DISKLABEL64_HEADER_SIZE + GRUB_DISK_SECTOR_SIZE;
+
+  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);
+      struct grub_partition_disklabel64_entry dpart;
+
+      pos += GRUB_PARTITION_DISKLABEL64_ENTRY_SIZE;
+      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/tests/dfly-mbr-mbexample.dfly.img.gz b/tests/dfly-mbr-mbexample.dfly.img.gz
new file mode 100644 (file)
index 0000000..b63595d
Binary files /dev/null and b/tests/dfly-mbr-mbexample.dfly.img.gz differ
diff --git a/tests/dfly-mbr-mbexample.mbr.img.gz b/tests/dfly-mbr-mbexample.mbr.img.gz
new file mode 100644 (file)
index 0000000..add2b13
Binary files /dev/null and b/tests/dfly-mbr-mbexample.mbr.img.gz differ
index 5be7b9dfb541f7b4cafbe6841e104f6f10d8bd3b..7786ccfbc0e86398577c0edec1bb944dae6ef8c5 100644 (file)
@@ -28,6 +28,14 @@ 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}
+    
+    gunzip < "@srcdir@/tests/dfly-mbr-mbexample.mbr.img.gz" | dd of=${name} bs=1 seek=440 count=72 conv=notrunc > /dev/null
+    gunzip < "@srcdir@/tests/dfly-mbr-mbexample.dfly.img.gz" | dd of=${name} bs=512 seek=33 count=1 conv=notrunc > /dev/null
+}
+
 check_output () {
     outfile=$1
     shift
@@ -461,3 +469,12 @@ ${parted} -a none -s "${imgfile}" mklabel amiga mkpart x 0 10M mkpart x 10M 20M
 list_parts part_amiga "${imgfile}" "${outfile}"
 check_output "${outfile}" $disk $disk,amiga1 $disk,amiga2 $disk,amiga3 $disk,amiga4 $disk,amiga5 $disk,amiga6 $disk,amiga7
 
+#
+# 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