* Partition modules
@ 2004-11-17 19:25 Marco Gerards
2004-11-18 3:50 ` Hollis Blanchard
` (3 more replies)
0 siblings, 4 replies; 19+ messages in thread
From: Marco Gerards @ 2004-11-17 19:25 UTC (permalink / raw)
To: grub-devel
Hi,
Here is a patch to modulize partition support. At the moment it will
create pc.mod, amiga.mod and apple.mod. Loading one of these modules
will give support for that specific partition map.
The names are not that clear at the moment, but that is because I plan
to put the modules in directories. So you will have partmap/pc.mod,
partmap/amiga.mod, but also fs/ext2.mod. But I will do this later,
this patch is big enough already.
There is one new partition map that is supported, the one that is used
on the amiga (RDB). If this patch is applied you can use GRUB 2 to
access files on the pegasos.
Can someone please this patch on the PC for me to see if it works? I
don't know when I can do that, I just tried if it compiles correctly
on the PC.
If there are no problems with this patch I will commit it Sunday, but
only if I am sure it works on the PC. I hope someone can comment on
my patch if there is something wrong with it.
Thanks,
Marco
2004-11-17 Marco Gerards <metgerards@student.han.nl>
* commands/ls.c: Include <grub/partition.h> instead of
<grub/machine/partition.h>.
* kern/disk.c: Likewise.
* kern/rescue.c: Likewise.
* loader/i386/pc/chainloader.c: Likewise.
* normal/cmdline.c: Likewise.
* kern/powerpc/ieee1275/init.c: Likewise.
(grub_machine_init): Call `grub_pc_partition_map_init',
`grub_amiga_partition_map_init' and
`grub_apple_partition_map_init'.
* conf/i386-pc.rmk (kernel_img_SOURCES): Remove
`disk/i386/pc/partition.c'. Add `kern/partition.c'.
(kernel_img_HEADERS): Remove `machine/partition.h'. Add
`partition.h' and `pc_partition.h'.
(grub_setup_SOURCES): Remove
`disk/i386/pc/partition.c'. Add `kern/partition.c',
`partmap/amiga.c', `partmap/apple.c' and `partmap/pc.c'.
(grub_emu_SOURCES): Likewise.
(pkgdata_MODULES): Add `amiga.mod', `apple.mod' and `pc.mod'.
(amiga_mod_SOURCES, amiga_mod_CFLAGS, apple_mod_SOURCES)
(apple_mod_CFLAGS, pc_mod_SOURCES, pc_mod_CFLAGS): New variables.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Remove
`disk/powerpc/ieee1275/partition.c'. Add `kern/partition.c',
`partmap/amiga.c', `partmap/apple.c' and `partmap/pc.c'.
(grubof_SOURCES): Likewise.
* disk/i386/pc/partition.c: Removed.
* disk/powerpc/ieee1275/partition.c: Likewise.
* include/grub/partition.h: Removed.
* include/grub/pc_partition.h: Likewise.
* include/grub/powerpc/ieee1275/partition.h: Likewise.
* kern/partition.c: New file.
* partmap/amiga.c: Likewise.
* partmap/apple.c: Likewise.
* partmap/pc.c: Likewise.
* util/grub-emu.c: Include <grub/partition.h> instead of
<grub/machine/partition.h>.
(main): Call `grub_pc_partition_map_init',
`grub_amiga_partition_map_init' and
`grub_apple_partition_map_init' and deinitialize afterwards.
* util/i386/pc/biosdisk.c: Include `#include
<grub/partition.h>' and `include <grub/pc_partition.h>' instead of
`<grub/machine/partition.h>'.
* util/i386/pc/grub-setup.c: Likewise.
Index: commands/ls.c
===================================================================
RCS file: /cvsroot/grub/grub2/commands/ls.c,v
retrieving revision 1.3
diff -u -p -u -p -r1.3 ls.c
--- commands/ls.c 22 Sep 2004 18:26:16 -0000 1.3
+++ commands/ls.c 17 Nov 2004 19:12:22 -0000
@@ -28,7 +28,7 @@
#include <grub/disk.h>
#include <grub/device.h>
#include <grub/term.h>
-#include <grub/machine/partition.h>
+#include <grub/partition.h>
#include <grub/file.h>
static const struct grub_arg_option options[] =
Index: conf/i386-pc.rmk
===================================================================
RCS file: /cvsroot/grub/grub2/conf/i386-pc.rmk,v
retrieving revision 1.22
diff -u -p -u -p -r1.22 i386-pc.rmk
--- conf/i386-pc.rmk 1 Nov 2004 16:14:15 -0000 1.22
+++ conf/i386-pc.rmk 17 Nov 2004 19:12:22 -0000
@@ -25,7 +25,7 @@ diskboot_img_LDFLAGS = -nostdlib -Wl,-N,
kernel_img_SOURCES = kern/i386/pc/startup.S kern/main.c kern/device.c \
kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \
- kern/i386/dl.c kern/i386/pc/init.c disk/i386/pc/partition.c \
+ kern/i386/dl.c kern/i386/pc/init.c kern/partition.c \
kern/env.c disk/i386/pc/biosdisk.c \
term/i386/pc/console.c \
symlist.c
@@ -33,7 +33,7 @@ kernel_img_HEADERS = arg.h boot.h device
file.h fs.h kernel.h loader.h misc.h mm.h net.h rescue.h symbol.h \
term.h types.h machine/biosdisk.h machine/boot.h \
machine/console.h machine/init.h machine/memory.h \
- machine/loader.h machine/partition.h machine/time.h machine/vga.h
+ machine/loader.h partition.h pc_partition.h machine/time.h machine/vga.h
kernel_img_CFLAGS = $(COMMON_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS = -nostdlib -Wl,-N,-Ttext,8200
@@ -60,14 +60,16 @@ grub_mkimage_LDFLAGS = -llzo
# For grub-setup.
grub_setup_SOURCES = util/i386/pc/grub-setup.c util/i386/pc/biosdisk.c \
util/misc.c util/i386/pc/getroot.c kern/device.c kern/disk.c \
- kern/err.c kern/misc.c disk/i386/pc/partition.c fs/fat.c fs/ext2.c \
+ kern/err.c kern/misc.c fs/fat.c fs/ext2.c \
+ kern/partition.c partmap/amiga.c partmap/apple.c partmap/pc.c \
fs/ufs.c fs/minix.c fs/hfs.c fs/jfs.c kern/file.c kern/fs.c kern/env.c fs/fshelp.c
# For grub
grub_emu_SOURCES = kern/main.c kern/device.c fs/fshelp.c \
kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
kern/misc.c kern/loader.c kern/rescue.c kern/term.c \
- disk/i386/pc/partition.c kern/env.c commands/ls.c \
+ kern/partition.c kern/env.c commands/ls.c partmap/amiga.c \
+ partmap/pc.c partmap/apple.c \
commands/terminal.c commands/boot.c commands/cmp.c commands/cat.c \
util/i386/pc/biosdisk.c fs/fat.c fs/ext2.c fs/ufs.c fs/minix.c fs/hfs.c fs/jfs.c fs/iso9660.c \
normal/cmdline.c normal/command.c normal/main.c normal/menu.c normal/arg.c \
@@ -80,7 +82,8 @@ genmoddep_SOURCES = util/genmoddep.c
# Modules.
pkgdata_MODULES = _chain.mod _linux.mod linux.mod fat.mod ufs.mod ext2.mod minix.mod \
hfs.mod jfs.mod normal.mod hello.mod vga.mod font.mod _multiboot.mod ls.mod \
- boot.mod cmp.mod cat.mod terminal.mod fshelp.mod chain.mod multiboot.mod
+ boot.mod cmp.mod cat.mod terminal.mod fshelp.mod chain.mod multiboot.mod \
+ amiga.mod apple.mod pc.mod
# For _chain.mod.
_chain_mod_SOURCES = loader/i386/pc/chainloader.c
@@ -175,3 +178,15 @@ _multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
# For multiboot.mod.
multiboot_mod_SOURCES = loader/i386/pc/multiboot_normal.c
multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
+
+# For amiga.mod
+amiga_mod_SOURCES = partmap/amiga.c
+amiga_mod_CFLAGS = $(COMMON_CFLAGS)
+
+# For apple.mod
+apple_mod_SOURCES = partmap/apple.c
+apple_mod_CFLAGS = $(COMMON_CFLAGS)
+
+# For pc.mod
+pc_mod_SOURCES = partmap/pc.c
+pc_mod_CFLAGS = $(COMMON_CFLAGS)
Index: conf/powerpc-ieee1275.rmk
===================================================================
RCS file: /cvsroot/grub/grub2/conf/powerpc-ieee1275.rmk,v
retrieving revision 1.14
diff -u -p -u -p -r1.14 powerpc-ieee1275.rmk
--- conf/powerpc-ieee1275.rmk 16 Nov 2004 23:34:44 -0000 1.14
+++ conf/powerpc-ieee1275.rmk 17 Nov 2004 19:12:22 -0000
@@ -24,11 +24,11 @@ noinst_UTILITIES = genmoddep
grub_emu_SOURCES = kern/main.c kern/device.c \
kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
kern/misc.c kern/loader.c kern/rescue.c kern/term.c \
- disk/powerpc/ieee1275/partition.c fs/fshelp.c \
+ partmap/amiga.c partmap/pc.c partmap/apple.c fs/fshelp.c \
util/i386/pc/biosdisk.c fs/fat.c fs/ext2.c fs/ufs.c fs/minix.c fs/hfs.c \
fs/jfs.c fs/iso9660.c \
normal/cmdline.c normal/command.c normal/main.c normal/menu.c \
- normal/arg.c \
+ normal/arg.c kern/partition.c \
util/console.c util/grub-emu.c util/misc.c util/i386/pc/getroot.c \
kern/env.c commands/ls.c \
commands/terminal.c commands/boot.c commands/cmp.c commands/cat.c
@@ -41,10 +41,12 @@ grubof_SOURCES = boot/powerpc/ieee1275/c
kern/powerpc/ieee1275/init.c term/powerpc/ieee1275/ofconsole.c \
kern/powerpc/ieee1275/openfw.c fs/ext2.c fs/ufs.c fs/minix.c fs/hfs.c \
fs/jfs.c normal/cmdline.c normal/command.c normal/main.c normal/menu.c \
- disk/powerpc/ieee1275/ofdisk.c disk/powerpc/ieee1275/partition.c \
+ disk/powerpc/ieee1275/ofdisk.c partmap/amiga.c partmap/pc.c \
+ partmap/apple.c kern/partition.c \
kern/env.c normal/arg.c loader/powerpc/ieee1275/linux.c \
loader/powerpc/ieee1275/linux_normal.c commands/boot.c \
normal/powerpc/setjmp.S
+
grubof_HEADERS = grub/powerpc/ieee1275/ieee1275.h
grubof_CFLAGS = $(COMMON_CFLAGS) -DGRUBOF
grubof_ASFLAGS = $(COMMON_ASFLAGS)
Index: disk/i386/pc/partition.c
===================================================================
RCS file: disk/i386/pc/partition.c
diff -N disk/i386/pc/partition.c
--- disk/i386/pc/partition.c 4 Apr 2004 13:46:00 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,248 +0,0 @@
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2002 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 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <grub/machine/partition.h>
-#include <grub/disk.h>
-#include <grub/mm.h>
-#include <grub/misc.h>
-
-/* Parse the partition representation in STR and return a partition. */
-static grub_partition_t
-grub_partition_parse (const char *str)
-{
- grub_partition_t p;
- char *s = (char *) str;
-
- p = (grub_partition_t) grub_malloc (sizeof (*p));
- if (! p)
- return 0;
-
- /* Initialize some of the fields with invalid values. */
- p->bsd_part = p->dos_type = p->bsd_type = p->index = -1;
-
- /* Get the DOS partition number. */
- p->dos_part = grub_strtoul (s, &s, 0);
-
- if (grub_errno)
- {
- /* Not found. Maybe only a BSD label is specified. */
- p->dos_part = -1;
- grub_errno = GRUB_ERR_NONE;
- }
- else if (*s == ',')
- s++;
-
- if (*s)
- {
- if (*s >= 'a' && *s <= 'h')
- {
- p->bsd_part = *s - 'a';
- s++;
- }
-
- if (*s)
- goto fail;
- }
-
- if (p->dos_part == -1 && p->bsd_part == -1)
- goto fail;
-
- return p;
-
- fail:
- grub_free (p);
- grub_error (GRUB_ERR_BAD_FILENAME, "invalid partition");
- return 0;
-}
-
-grub_err_t
-grub_partition_iterate (grub_disk_t disk,
- int (*hook) (const grub_partition_t partition))
-{
- struct grub_partition p;
- struct grub_partition_mbr mbr;
- struct grub_partition_disk_label label;
- struct grub_disk raw;
-
- /* Enforce raw disk access. */
- raw = *disk;
- raw.partition = 0;
-
- p.offset = 0;
- p.ext_offset = 0;
- p.dos_part = -1;
-
- while (1)
- {
- int i;
- struct grub_partition_entry *e;
-
- /* Read the MBR. */
- if (grub_disk_read (&raw, p.offset, 0, sizeof (mbr), (char *) &mbr))
- goto finish;
-
- /* Check if it is valid. */
- if (mbr.signature != grub_cpu_to_le16 (GRUB_PARTITION_SIGNATURE))
- return grub_error (GRUB_ERR_BAD_PART_TABLE, "no signature");
-
- /* Analyze DOS partitions. */
- for (p.index = 0; p.index < 4; p.index++)
- {
- e = mbr.entries + p.index;
-
- p.start = p.offset + grub_le_to_cpu32 (e->start);
- p.len = grub_le_to_cpu32 (e->length);
- p.bsd_part = -1;
- p.dos_type = e->type;
- p.bsd_type = -1;
-
- /* If this partition is a normal one, call the hook. */
- if (! grub_partition_is_empty (e->type)
- && ! grub_partition_is_extended (e->type))
- {
- p.dos_part++;
-
- if (hook (&p))
- goto finish;
-
- /* Check if this is a BSD partition. */
- if (grub_partition_is_bsd (e->type))
- {
- /* Check if the BSD label is within the DOS partition. */
- if (p.len <= GRUB_PARTITION_BSD_LABEL_SECTOR)
- return grub_error (GRUB_ERR_BAD_PART_TABLE,
- "no space for disk label");
-
- /* Read the BSD label. */
- if (grub_disk_read (&raw,
- (p.start
- + GRUB_PARTITION_BSD_LABEL_SECTOR),
- 0,
- sizeof (label),
- (char *) &label))
- goto finish;
-
- /* Check if it is valid. */
- if (label.magic
- != grub_cpu_to_le32 (GRUB_PARTITION_BSD_LABEL_MAGIC))
- return grub_error (GRUB_ERR_BAD_PART_TABLE,
- "invalid disk label magic");
-
- for (p.bsd_part = 0;
- p.bsd_part < grub_cpu_to_le16 (label.num_partitions);
- p.bsd_part++)
- {
- struct grub_partition_bsd_entry *be
- = label.entries + p.bsd_part;
-
- p.start = grub_le_to_cpu32 (be->offset);
- p.len = grub_le_to_cpu32 (be->size);
- p.bsd_type = be->fs_type;
-
- if (be->fs_type != GRUB_PARTITION_BSD_TYPE_UNUSED)
- if (hook (&p))
- goto finish;
- }
- }
- }
- else if (p.dos_part < 4)
- /* If this partition is a logical one, shouldn't increase the
- partition number. */
- p.dos_part++;
- }
-
- /* Find an extended partition. */
- for (i = 0; i < 4; i++)
- {
- e = mbr.entries + i;
-
- if (grub_partition_is_extended (e->type))
- {
- p.offset = p.ext_offset + grub_le_to_cpu32 (e->start);
- if (! p.ext_offset)
- p.ext_offset = p.offset;
-
- break;
- }
- }
-
- /* If no extended partition, the end. */
- if (i == 4)
- break;
- }
-
- finish:
- return grub_errno;
-}
-
-grub_partition_t
-grub_partition_probe (grub_disk_t disk, const char *str)
-{
- grub_partition_t p;
- auto int find_func (const grub_partition_t partition);
-
- int find_func (const grub_partition_t partition)
- {
- if ((p->dos_part == partition->dos_part || p->dos_part == -1)
- && p->bsd_part == partition->bsd_part)
- {
- grub_memcpy (p, partition, sizeof (*p));
- return 1;
- }
-
- return 0;
- }
-
- p = grub_partition_parse (str);
- if (! p)
- return 0;
-
-
- if (grub_partition_iterate (disk, find_func))
- goto fail;
-
- if (p->index < 0)
- {
- grub_error (GRUB_ERR_BAD_DEVICE, "no such partition");
- goto fail;
- }
-
- return p;
-
- fail:
- grub_free (p);
- return 0;
-}
-
-char *
-grub_partition_get_name (const grub_partition_t p)
-{
- char *name;
-
- name = grub_malloc (13);
- if (! name)
- return 0;
-
- if (p->bsd_part < 0)
- grub_sprintf (name, "%d", p->dos_part);
- else
- grub_sprintf (name, "%d,%c", p->dos_part, p->bsd_part + 'a');
-
- return name;
-}
Index: disk/powerpc/ieee1275/partition.c
===================================================================
RCS file: disk/powerpc/ieee1275/partition.c
diff -N disk/powerpc/ieee1275/partition.c
--- disk/powerpc/ieee1275/partition.c 11 Jul 2004 14:24:54 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,120 +0,0 @@
-/* partiton.c - Read macintosh partition tables. */
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2004 Free Software Foundation, Inc.
- *
- * This program 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 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <grub/disk.h>
-#include <grub/misc.h>
-#include <grub/mm.h>
-#include <grub/machine/partition.h>
-
-grub_err_t
-grub_partition_iterate (grub_disk_t disk,
- int (*hook) (const grub_partition_t partition))
-{
- struct grub_partition part;
- struct grub_apple_part apart;
- struct grub_disk raw;
- int partno = 0;
- int pos = GRUB_DISK_SECTOR_SIZE;
-
- /* Enforce raw disk access. */
- raw = *disk;
- raw.partition = 0;
-
- for (;;)
- {
- if (grub_disk_read (&raw, pos / GRUB_DISK_SECTOR_SIZE,
- pos % GRUB_DISK_SECTOR_SIZE,
- sizeof (struct grub_apple_part), (char *) &apart))
- return grub_errno;
-
- if (apart.magic != GRUB_APPLE_PART_MAGIC)
- break;
-
- part.start = apart.first_phys_block;
- part.len = apart.blockcnt;
- part.offset = pos;
- part.index = partno;
-
- if (hook (&part))
- return grub_errno;
-
- if (apart.first_phys_block == GRUB_DISK_SECTOR_SIZE * 2)
- return 0;
-
- pos += sizeof (struct grub_apple_part);
- partno++;
- }
-
- return 0;
-}
-
-grub_partition_t
-grub_partition_probe (grub_disk_t disk, const char *str)
-{
- grub_partition_t p = 0;
- int partnum = 0;
- char *s = (char *) str;
-
- int find_func (const grub_partition_t partition)
- {
- if (partnum == partition->index)
- {
- p = (grub_partition_t) grub_malloc (sizeof (*p));
- if (! p)
- return 1;
-
- grub_memcpy (p, partition, sizeof (*p));
- return 1;
- }
-
- return 0;
- }
-
- /* Get the partition number. */
- partnum = grub_strtoul (s, 0, 10);
- if (grub_errno)
- {
- grub_error (GRUB_ERR_BAD_FILENAME, "invalid partition");
- return 0;
- }
-
- if (grub_partition_iterate (disk, find_func))
- goto fail;
-
- return p;
-
- fail:
- grub_free (p);
- return 0;
-
-}
-
-char *
-grub_partition_get_name (const grub_partition_t p)
-{
- char *name;
-
- name = grub_malloc (13);
- if (! name)
- return 0;
-
- grub_sprintf (name, "%d", p->index);
- return name;
-}
Index: include/grub/partition.h
===================================================================
RCS file: include/grub/partition.h
diff -N include/grub/partition.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ include/grub/partition.h 17 Nov 2004 19:12:22 -0000
@@ -0,0 +1,118 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2004 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef GRUB_PART_HEADER
+#define GRUB_PART_HEADER 1
+
+#include <grub/dl.h>
+
+struct grub_disk;
+
+typedef struct grub_partition *grub_partition_t;
+
+/* Partition map type. */
+struct grub_partition_map
+{
+ /* The name of the partition map type. */
+ const char *name;
+
+ /* Call HOOK with each partition, until HOOK returns non-zero. */
+ grub_err_t (*iterate) (struct grub_disk *disk,
+ int (*hook) (const grub_partition_t partition));
+
+ /* Return the partition named STR on the disk DISK. */
+ grub_partition_t (*probe) (struct grub_disk *disk,
+ const char *str);
+
+ /* Return the name of the partition PARTITION. */
+ char *(*get_name) (const grub_partition_t partition);
+
+ /* The next partition map type. */
+ struct grub_partition_map *next;
+};
+typedef struct grub_partition_map *grub_partition_map_t;
+
+/* Partition description. */
+struct grub_partition
+{
+ /* The start sector. */
+ unsigned long start;
+
+ /* The length in sector units. */
+ unsigned long len;
+
+ /* The offset of the partition table. */
+ unsigned long offset;
+
+ /* The index of this partition in the partition table. */
+ int index;
+
+ /* The DOS partition number. */
+ int dos_part;
+
+ /* The BSD partition number (a == 0). */
+ int bsd_part;
+
+ /* The DOS partition type. */
+ int dos_type;
+
+ /* The BSD partition type. */
+ int bsd_type;
+
+ /* The offset of the extended partition. */
+ unsigned long ext_offset;
+
+ /* The type partition map. */
+ grub_partition_map_t partmap;
+};
+
+grub_partition_t EXPORT_FUNC(grub_partition_probe) (struct grub_disk *disk,
+ const char *str);
+grub_err_t EXPORT_FUNC(grub_partition_iterate) (struct grub_disk *disk,
+ int (*hook) (const grub_partition_t partition));
+char *EXPORT_FUNC(grub_partition_get_name) (const grub_partition_t partition);
+
+void EXPORT_FUNC(grub_partition_map_iterate) (int (*hook) (const grub_partition_map_t partmap));
+
+void EXPORT_FUNC(grub_partition_map_register) (grub_partition_map_t partmap);
+
+void EXPORT_FUNC(grub_partition_map_unregister) (grub_partition_map_t partmap);
+
+#ifdef GRUB_UTIL
+void grub_pc_partition_map_init (void);
+void grub_pc_partition_map_fini (void);
+void grub_amiga_partition_map_init (void);
+void grub_amiga_partition_map_fini (void);
+void grub_apple_partition_map_init (void);
+void grub_apple_partition_map_fini (void);
+#endif
+\f
+static inline unsigned long
+grub_partition_get_start (const grub_partition_t p)
+{
+ return p->start;
+}
+
+static inline unsigned long
+grub_partition_get_len (const grub_partition_t p)
+{
+ return p->len;
+}
+
+#endif /* ! GRUB_PART_HEADER */
Index: include/grub/pc_partition.h
===================================================================
RCS file: include/grub/pc_partition.h
diff -N include/grub/pc_partition.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ include/grub/pc_partition.h 17 Nov 2004 19:12:22 -0000
@@ -0,0 +1,190 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef GRUB_PC_PARTITION_HEADER
+#define GRUB_PC_PARTITION_HEADER 1
+
+#include <grub/symbol.h>
+#include <grub/types.h>
+#include <grub/err.h>
+
+/* The signature. */
+#define GRUB_PARTITION_SIGNATURE 0xaa55
+
+/* This is not a flag actually, but used as if it were a flag. */
+#define GRUB_PARTITION_TYPE_HIDDEN_FLAG 0x10
+
+/* DOS partition types. */
+#define GRUB_PARTITION_TYPE_NONE 0
+#define GRUB_PARTITION_TYPE_FAT12 1
+#define GRUB_PARTITION_TYPE_FAT16_LT32M 4
+#define GRUB_PARTITION_TYPE_EXTENDED 5
+#define GRUB_PARTITION_TYPE_FAT16_GT32M 6
+#define GRUB_PARTITION_TYPE_FAT32 0xb
+#define GRUB_PARTITION_TYPE_FAT32_LBA 0xc
+#define GRUB_PARTITION_TYPE_FAT16_LBA 0xe
+#define GRUB_PARTITION_TYPE_WIN95_EXTENDED 0xf
+#define GRUB_PARTITION_TYPE_EZD 0x55
+#define GRUB_PARTITION_TYPE_MINIX 0x80
+#define GRUB_PARTITION_TYPE_LINUX_MINIX 0x81
+#define GRUB_PARTITION_TYPE_EXT2FS 0x83
+#define GRUB_PARTITION_TYPE_LINUX_EXTENDED 0x85
+#define GRUB_PARTITION_TYPE_VSTAFS 0x9e
+#define GRUB_PARTITION_TYPE_FREEBSD 0xa5
+#define GRUB_PARTITION_TYPE_OPENBSD 0xa6
+#define GRUB_PARTITION_TYPE_NETBSD 0xa9
+#define GRUB_PARTITION_TYPE_LINUX_RAID 0xfd
+
+/* Constants for BSD disk label. */
+#define GRUB_PARTITION_BSD_LABEL_SECTOR 1
+#define GRUB_PARTITION_BSD_LABEL_MAGIC 0x82564557
+#define GRUB_PARTITION_BSD_MAX_ENTRIES 8
+
+/* BSD partition types. */
+#define GRUB_PARTITION_BSD_TYPE_UNUSED 0
+#define GRUB_PARTITION_BSD_TYPE_SWAP 1
+#define GRUB_PARTITION_BSD_TYPE_V6 2
+#define GRUB_PARTITION_BSD_TYPE_V7 3
+#define GRUB_PARTITION_BSD_TYPE_SYSV 4
+#define GRUB_PARTITION_BSD_TYPE_V71K 5
+#define GRUB_PARTITION_BSD_TYPE_V8 6
+#define GRUB_PARTITION_BSD_TYPE_BSDFFS 7
+#define GRUB_PARTITION_BSD_TYPE_MSDOS 8
+#define GRUB_PARTITION_BSD_TYPE_BSDLFS 9
+#define GRUB_PARTITION_BSD_TYPE_OTHER 10
+#define GRUB_PARTITION_BSD_TYPE_HPFS 11
+#define GRUB_PARTITION_BSD_TYPE_ISO9660 12
+#define GRUB_PARTITION_BSD_TYPE_BOOT 13
+
+/* FreeBSD-specific types. */
+#define GRUB_PARTITION_FREEBSD_TYPE_VINUM 14
+#define GRUB_PARTITION_FREEBSD_TYPE_RAID 15
+#define GRUB_PARTITION_FREEBSD_TYPE_JFS2 21
+
+/* NetBSD-specific types. */
+#define GRUB_PARTITION_NETBSD_TYPE_ADOS 14
+#define GRUB_PARTITION_NETBSD_TYPE_HFS 15
+#define GRUB_PARTITION_NETBSD_TYPE_FILECORE 16
+#define GRUB_PARTITION_NETBSD_TYPE_EXT2FS 17
+#define GRUB_PARTITION_NETBSD_TYPE_NTFS 18
+#define GRUB_PARTITION_NETBSD_TYPE_RAID 19
+#define GRUB_PARTITION_NETBSD_TYPE_CCD 20
+#define GRUB_PARTITION_NETBSD_TYPE_JFS2 21
+#define GRUB_PARTITION_NETBSD_TYPE_APPLEUFS 22
+
+/* OpenBSD-specific types. */
+#define GRUB_PARTITION_OPENBSD_TYPE_ADOS 14
+#define GRUB_PARTITION_OPENBSD_TYPE_HFS 15
+#define GRUB_PARTITION_OPENBSD_TYPE_FILECORE 16
+#define GRUB_PARTITION_OPENBSD_TYPE_EXT2FS 17
+#define GRUB_PARTITION_OPENBSD_TYPE_NTFS 18
+#define GRUB_PARTITION_OPENBSD_TYPE_RAID 19
+
+/* The BSD partition entry. */
+struct grub_partition_bsd_entry
+{
+ grub_uint32_t size;
+ grub_uint32_t offset;
+ grub_uint32_t fragment_size;
+ grub_uint8_t fs_type;
+ grub_uint8_t fs_fragments;
+ grub_uint16_t fs_cylinders;
+} __attribute__ ((packed));
+
+/* The BSD disk label. Only define members useful for GRUB. */
+struct grub_partition_disk_label
+{
+ grub_uint32_t magic;
+ grub_uint8_t padding[128];
+ grub_uint32_t magic2;
+ grub_uint16_t checksum;
+ grub_uint16_t num_partitions;
+ grub_uint32_t boot_size;
+ grub_uint32_t superblock_size;
+ struct grub_partition_bsd_entry entries[GRUB_PARTITION_BSD_MAX_ENTRIES];
+} __attribute__ ((packed));
+
+/* The partition entry. */
+struct grub_partition_entry
+{
+ /* If active, 0x80, otherwise, 0x00. */
+ grub_uint8_t flag;
+
+ /* The head of the start. */
+ grub_uint8_t start_head;
+
+ /* (S | ((C >> 2) & 0xC0)) where S is the sector of the start and C
+ is the cylinder of the start. Note that S is counted from one. */
+ grub_uint8_t start_sector;
+
+ /* (C & 0xFF) where C is the cylinder of the start. */
+ grub_uint8_t start_cylinder;
+
+ /* The partition type. */
+ grub_uint8_t type;
+
+ /* The end versions of start_head, start_sector and start_cylinder,
+ respectively. */
+ grub_uint8_t end_head;
+ grub_uint8_t end_sector;
+ grub_uint8_t end_cylinder;
+
+ /* The start sector. Note that this is counted from zero. */
+ grub_uint32_t start;
+
+ /* The length in sector units. */
+ grub_uint32_t length;
+} __attribute__ ((packed));
+
+/* The structure of MBR. */
+struct grub_partition_mbr
+{
+ /* The code area (actually, including BPB). */
+ grub_uint8_t code[446];
+
+ /* Four partition entries. */
+ struct grub_partition_entry entries[4];
+
+ /* The signature 0xaa55. */
+ grub_uint16_t signature;
+} __attribute__ ((packed));
+
+static inline int
+grub_partition_is_empty (int type)
+{
+ return (type == GRUB_PARTITION_TYPE_NONE);
+}
+
+static inline int
+grub_partition_is_extended (int type)
+{
+ return (type == GRUB_PARTITION_TYPE_EXTENDED
+ || type == GRUB_PARTITION_TYPE_WIN95_EXTENDED
+ || type == GRUB_PARTITION_TYPE_LINUX_EXTENDED);
+}
+
+static inline int
+grub_partition_is_bsd (int type)
+{
+ return (type == GRUB_PARTITION_TYPE_FREEBSD
+ || type == GRUB_PARTITION_TYPE_OPENBSD
+ || type == GRUB_PARTITION_TYPE_NETBSD);
+}
+
+#endif /* ! GRUB_PC_PARTITION_HEADER */
Index: include/grub/i386/pc/partition.h
===================================================================
RCS file: include/grub/i386/pc/partition.h
diff -N include/grub/i386/pc/partition.h
--- include/grub/i386/pc/partition.h 4 Apr 2004 13:46:01 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,242 +0,0 @@
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 1999,2000,2001,2002 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 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef GRUB_PARTITION_HEADER
-#define GRUB_PARTITION_HEADER 1
-
-#include <grub/symbol.h>
-#include <grub/types.h>
-#include <grub/err.h>
-
-/* The signature. */
-#define GRUB_PARTITION_SIGNATURE 0xaa55
-
-/* This is not a flag actually, but used as if it were a flag. */
-#define GRUB_PARTITION_TYPE_HIDDEN_FLAG 0x10
-
-/* DOS partition types. */
-#define GRUB_PARTITION_TYPE_NONE 0
-#define GRUB_PARTITION_TYPE_FAT12 1
-#define GRUB_PARTITION_TYPE_FAT16_LT32M 4
-#define GRUB_PARTITION_TYPE_EXTENDED 5
-#define GRUB_PARTITION_TYPE_FAT16_GT32M 6
-#define GRUB_PARTITION_TYPE_FAT32 0xb
-#define GRUB_PARTITION_TYPE_FAT32_LBA 0xc
-#define GRUB_PARTITION_TYPE_FAT16_LBA 0xe
-#define GRUB_PARTITION_TYPE_WIN95_EXTENDED 0xf
-#define GRUB_PARTITION_TYPE_EZD 0x55
-#define GRUB_PARTITION_TYPE_MINIX 0x80
-#define GRUB_PARTITION_TYPE_LINUX_MINIX 0x81
-#define GRUB_PARTITION_TYPE_EXT2FS 0x83
-#define GRUB_PARTITION_TYPE_LINUX_EXTENDED 0x85
-#define GRUB_PARTITION_TYPE_VSTAFS 0x9e
-#define GRUB_PARTITION_TYPE_FREEBSD 0xa5
-#define GRUB_PARTITION_TYPE_OPENBSD 0xa6
-#define GRUB_PARTITION_TYPE_NETBSD 0xa9
-#define GRUB_PARTITION_TYPE_LINUX_RAID 0xfd
-
-/* Constants for BSD disk label. */
-#define GRUB_PARTITION_BSD_LABEL_SECTOR 1
-#define GRUB_PARTITION_BSD_LABEL_MAGIC 0x82564557
-#define GRUB_PARTITION_BSD_MAX_ENTRIES 8
-
-/* BSD partition types. */
-#define GRUB_PARTITION_BSD_TYPE_UNUSED 0
-#define GRUB_PARTITION_BSD_TYPE_SWAP 1
-#define GRUB_PARTITION_BSD_TYPE_V6 2
-#define GRUB_PARTITION_BSD_TYPE_V7 3
-#define GRUB_PARTITION_BSD_TYPE_SYSV 4
-#define GRUB_PARTITION_BSD_TYPE_V71K 5
-#define GRUB_PARTITION_BSD_TYPE_V8 6
-#define GRUB_PARTITION_BSD_TYPE_BSDFFS 7
-#define GRUB_PARTITION_BSD_TYPE_MSDOS 8
-#define GRUB_PARTITION_BSD_TYPE_BSDLFS 9
-#define GRUB_PARTITION_BSD_TYPE_OTHER 10
-#define GRUB_PARTITION_BSD_TYPE_HPFS 11
-#define GRUB_PARTITION_BSD_TYPE_ISO9660 12
-#define GRUB_PARTITION_BSD_TYPE_BOOT 13
-
-/* FreeBSD-specific types. */
-#define GRUB_PARTITION_FREEBSD_TYPE_VINUM 14
-#define GRUB_PARTITION_FREEBSD_TYPE_RAID 15
-#define GRUB_PARTITION_FREEBSD_TYPE_JFS2 21
-
-/* NetBSD-specific types. */
-#define GRUB_PARTITION_NETBSD_TYPE_ADOS 14
-#define GRUB_PARTITION_NETBSD_TYPE_HFS 15
-#define GRUB_PARTITION_NETBSD_TYPE_FILECORE 16
-#define GRUB_PARTITION_NETBSD_TYPE_EXT2FS 17
-#define GRUB_PARTITION_NETBSD_TYPE_NTFS 18
-#define GRUB_PARTITION_NETBSD_TYPE_RAID 19
-#define GRUB_PARTITION_NETBSD_TYPE_CCD 20
-#define GRUB_PARTITION_NETBSD_TYPE_JFS2 21
-#define GRUB_PARTITION_NETBSD_TYPE_APPLEUFS 22
-
-/* OpenBSD-specific types. */
-#define GRUB_PARTITION_OPENBSD_TYPE_ADOS 14
-#define GRUB_PARTITION_OPENBSD_TYPE_HFS 15
-#define GRUB_PARTITION_OPENBSD_TYPE_FILECORE 16
-#define GRUB_PARTITION_OPENBSD_TYPE_EXT2FS 17
-#define GRUB_PARTITION_OPENBSD_TYPE_NTFS 18
-#define GRUB_PARTITION_OPENBSD_TYPE_RAID 19
-
-/* The BSD partition entry. */
-struct grub_partition_bsd_entry
-{
- grub_uint32_t size;
- grub_uint32_t offset;
- grub_uint32_t fragment_size;
- grub_uint8_t fs_type;
- grub_uint8_t fs_fragments;
- grub_uint16_t fs_cylinders;
-} __attribute__ ((packed));
-
-/* The BSD disk label. Only define members useful for GRUB. */
-struct grub_partition_disk_label
-{
- grub_uint32_t magic;
- grub_uint8_t padding[128];
- grub_uint32_t magic2;
- grub_uint16_t checksum;
- grub_uint16_t num_partitions;
- grub_uint32_t boot_size;
- grub_uint32_t superblock_size;
- struct grub_partition_bsd_entry entries[GRUB_PARTITION_BSD_MAX_ENTRIES];
-} __attribute__ ((packed));
-
-/* The partition entry. */
-struct grub_partition_entry
-{
- /* If active, 0x80, otherwise, 0x00. */
- grub_uint8_t flag;
-
- /* The head of the start. */
- grub_uint8_t start_head;
-
- /* (S | ((C >> 2) & 0xC0)) where S is the sector of the start and C
- is the cylinder of the start. Note that S is counted from one. */
- grub_uint8_t start_sector;
-
- /* (C & 0xFF) where C is the cylinder of the start. */
- grub_uint8_t start_cylinder;
-
- /* The partition type. */
- grub_uint8_t type;
-
- /* The end versions of start_head, start_sector and start_cylinder,
- respectively. */
- grub_uint8_t end_head;
- grub_uint8_t end_sector;
- grub_uint8_t end_cylinder;
-
- /* The start sector. Note that this is counted from zero. */
- grub_uint32_t start;
-
- /* The length in sector units. */
- grub_uint32_t length;
-} __attribute__ ((packed));
-
-/* The structure of MBR. */
-struct grub_partition_mbr
-{
- /* The code area (actually, including BPB). */
- grub_uint8_t code[446];
-
- /* Four partition entries. */
- struct grub_partition_entry entries[4];
-
- /* The signature 0xaa55. */
- grub_uint16_t signature;
-} __attribute__ ((packed));
-
-/* Partition description. */
-struct grub_partition
-{
- /* The start sector. */
- unsigned long start;
-
- /* The length in sector units. */
- unsigned long len;
-
- /* The offset of the partition table. */
- unsigned long offset;
-
- /* The offset of the extended partition. */
- unsigned long ext_offset;
-
- /* The index of this partition in the partition table. */
- int index;
-
- /* The DOS partition number. */
- int dos_part;
-
- /* The BSD partition number (a == 0). */
- int bsd_part;
-
- /* The DOS partition type. */
- int dos_type;
-
- /* The BSD partition type. */
- int bsd_type;
-};
-typedef struct grub_partition *grub_partition_t;
-
-struct grub_disk;
-
-grub_partition_t EXPORT_FUNC(grub_partition_probe) (struct grub_disk *disk,
- const char *str);
-grub_err_t EXPORT_FUNC(grub_partition_iterate) (struct grub_disk *disk,
- int (*hook) (const grub_partition_t partition));
-char *EXPORT_FUNC(grub_partition_get_name) (const grub_partition_t partition);
-
-static inline unsigned long
-grub_partition_get_start (const grub_partition_t p)
-{
- return p->start;
-}
-
-static inline unsigned long
-grub_partition_get_len (const grub_partition_t p)
-{
- return p->len;
-}
-
-static inline int
-grub_partition_is_empty (int type)
-{
- return (type == GRUB_PARTITION_TYPE_NONE);
-}
-
-static inline int
-grub_partition_is_extended (int type)
-{
- return (type == GRUB_PARTITION_TYPE_EXTENDED
- || type == GRUB_PARTITION_TYPE_WIN95_EXTENDED
- || type == GRUB_PARTITION_TYPE_LINUX_EXTENDED);
-}
-
-static inline int
-grub_partition_is_bsd (int type)
-{
- return (type == GRUB_PARTITION_TYPE_FREEBSD
- || type == GRUB_PARTITION_TYPE_OPENBSD
- || type == GRUB_PARTITION_TYPE_NETBSD);
-}
-
-#endif /* ! GRUB_PARTITION_HEADER */
Index: include/grub/powerpc/ieee1275/partition.h
===================================================================
RCS file: include/grub/powerpc/ieee1275/partition.h
diff -N include/grub/powerpc/ieee1275/partition.h
--- include/grub/powerpc/ieee1275/partition.h 4 Apr 2004 13:46:01 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,140 +0,0 @@
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 1999,2000,2001,2002,2004 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 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef GRUB_PARTITION_HEADER
-#define GRUB_PARTITION_HEADER 1
-
-#include <grub/symbol.h>
-#include <grub/types.h>
-#include <grub/err.h>
-
-#define GRUB_APPLE_PART_MAGIC 0x504D
-
-struct grub_apple_part
-{
- /* The magic number to idenify this as a partition, it should have
- the value `0x504D'. */
- grub_uint16_t magic;
-
- /* Reserved. */
- grub_uint16_t reserved;
-
- /* The size of the partition map in blocks. */
- grub_uint32_t partmap_size;
-
- /* The first physical block of the partition. */
- grub_uint32_t first_phys_block;
-
- /* The amount of blocks. */
- grub_uint32_t blockcnt;
-
- /* The partition name. */
- char partname[32];
-
- /* The partition type. */
- char parttype[32];
-
- /* The first datablock of the partition. */
- grub_uint32_t datablocks_first;
-
- /* The amount datablocks. */
- grub_uint32_t datablocks_count;
-
- /* The status of the partition. (???) */
- grub_uint32_t status;
-
- /* The first block on which the bootcode can be found. */
- grub_uint32_t bootcode_pos;
-
- /* The size of the bootcode in bytes. */
- grub_uint32_t bootcode_size;
-
- /* The load address of the bootcode. */
- grub_uint32_t bootcode_loadaddr;
-
- /* Reserved. */
- grub_uint32_t reserved2;
-
- /* The entrypoint of the bootcode. */
- grub_uint32_t bootcode_entrypoint;
-
- /* Reserved. */
- grub_uint32_t reserved3;
-
- /* A checksum of the bootcode. */
- grub_uint32_t bootcode_checksum;
-
- /* The processor type. */
- char processor[16];
-
- /* Padding. */
- grub_uint16_t pad[187];
-};
-
-/* Partition description. */
-struct grub_partition
-{
- /* The start sector. */
- unsigned long start;
-
- /* The length in sector units. */
- unsigned long len;
-
- /* The offset of the partition table. */
- unsigned long offset;
-
- /* The index of this partition in the partition table. */
- int index;
-
- /* The DOS partition number. */
- int dos_part;
-
- /* The BSD partition number (a == 0). */
- int bsd_part;
-
- /* The DOS partition type. */
- int dos_type;
-
- /* The BSD partition type. */
- int bsd_type;
-};
-typedef struct grub_partition *grub_partition_t;
-
-struct grub_disk;
-
-grub_partition_t EXPORT_FUNC(grub_partition_probe) (struct grub_disk *disk,
- const char *str);
-grub_err_t EXPORT_FUNC(grub_partition_iterate) (struct grub_disk *disk,
- int (*hook) (const grub_partition_t partition));
-char *EXPORT_FUNC(grub_partition_get_name) (const grub_partition_t partition);
-
-\f
-static inline unsigned long
-grub_partition_get_start (const grub_partition_t p)
-{
- return p->start;
-}
-
-static inline unsigned long
-grub_partition_get_len (const grub_partition_t p)
-{
- return p->len;
-}
-
-#endif /* ! GRUB_PARTITION_HEADER */
Index: kern/disk.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/disk.c,v
retrieving revision 1.8
diff -u -p -u -p -r1.8 disk.c
--- kern/disk.c 21 Aug 2004 13:54:22 -0000 1.8
+++ kern/disk.c 17 Nov 2004 19:12:22 -0000
@@ -21,7 +21,7 @@
#include <grub/err.h>
#include <grub/mm.h>
#include <grub/types.h>
-#include <grub/machine/partition.h>
+#include <grub/partition.h>
#include <grub/misc.h>
#include <grub/machine/time.h>
#include <grub/file.h>
Index: kern/partition.c
===================================================================
RCS file: kern/partition.c
diff -N kern/partition.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ kern/partition.c 17 Nov 2004 19:12:22 -0000
@@ -0,0 +1,95 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2004 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <grub/partition.h>
+#include <grub/disk.h>
+
+static grub_partition_map_t grub_partition_map_list;
+
+void
+grub_partition_map_register (grub_partition_map_t partmap)
+{
+ partmap->next = grub_partition_map_list;
+ grub_partition_map_list = partmap;
+}
+
+void
+grub_partition_map_unregister (grub_partition_map_t partmap)
+{
+ grub_partition_map_t *p, q;
+
+ for (p = &grub_partition_map_list, q = *p; q; p = &(q->next), q = q->next)
+ if (q == partmap)
+ {
+ *p = q->next;
+ break;
+ }
+}
+
+void
+grub_partition_map_iterate (int (*hook) (const grub_partition_map_t partmap))
+{
+ grub_partition_map_t p;
+
+ for (p = grub_partition_map_list; p; p = p->next)
+ if (hook (p))
+ break;
+}
+
+grub_partition_t
+grub_partition_probe (struct grub_disk *disk, const char *str)
+{
+ grub_partition_t part;
+
+ auto int part_map_probe (const grub_partition_map_t partmap);
+
+ int part_map_probe (const grub_partition_map_t partmap)
+ {
+ part = partmap->probe (disk, str);
+ if (part)
+ return 1;
+ return 0;
+ }
+
+ /* Use the first partition map type found. */
+ grub_partition_map_iterate (part_map_probe);
+
+ return part;
+}
+
+grub_err_t
+grub_partition_iterate (struct grub_disk *disk,
+ int (*hook) (const grub_partition_t partition))
+{
+ auto int part_map_iterate (const grub_partition_map_t partmap);
+
+ int part_map_iterate (const grub_partition_map_t partmap)
+ {
+ return partmap->iterate (disk, hook);
+ }
+
+ grub_partition_map_iterate (part_map_iterate);
+ return grub_errno;
+}
+
+char *
+grub_partition_get_name (const grub_partition_t partition)
+{
+ return partition->partmap->get_name (partition);
+}
Index: kern/rescue.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/rescue.c,v
retrieving revision 1.10
diff -u -p -u -p -r1.10 rescue.c
--- kern/rescue.c 22 Sep 2004 18:26:16 -0000 1.10
+++ kern/rescue.c 17 Nov 2004 19:12:22 -0000
@@ -28,7 +28,7 @@
#include <grub/err.h>
#include <grub/loader.h>
#include <grub/dl.h>
-#include <grub/machine/partition.h>
+#include <grub/partition.h>
#include <grub/env.h>
#define GRUB_RESCUE_BUF_SIZE 256
Index: kern/powerpc/ieee1275/init.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/powerpc/ieee1275/init.c,v
retrieving revision 1.8
diff -u -p -u -p -r1.8 init.c
--- kern/powerpc/ieee1275/init.c 16 Nov 2004 23:34:44 -0000 1.8
+++ kern/powerpc/ieee1275/init.c 17 Nov 2004 19:12:22 -0000
@@ -22,7 +22,7 @@
#include <grub/dl.h>
#include <grub/disk.h>
#include <grub/mm.h>
-#include <grub/machine/partition.h>
+#include <grub/partition.h>
#include <grub/machine/ieee1275.h>
#include <grub/normal.h>
#include <grub/fs.h>
@@ -78,6 +78,9 @@ grub_machine_init (void)
grub_boot_init ();
grub_linux_init ();
grub_linux_normal_init ();
+ grub_pc_partition_map_init ();
+ grub_amiga_partition_map_init ();
+ grub_apple_partition_map_init ();
grub_ofdisk_init ();
}
Index: loader/i386/pc/chainloader.c
===================================================================
RCS file: /cvsroot/grub/grub2/loader/i386/pc/chainloader.c,v
retrieving revision 1.7
diff -u -p -u -p -r1.7 chainloader.c
--- loader/i386/pc/chainloader.c 12 Sep 2004 12:20:52 -0000 1.7
+++ loader/i386/pc/chainloader.c 17 Nov 2004 19:12:22 -0000
@@ -28,7 +28,7 @@
#include <grub/misc.h>
#include <grub/types.h>
#include <grub/machine/init.h>
-#include <grub/machine/partition.h>
+#include <grub/partition.h>
#include <grub/machine/memory.h>
#include <grub/rescue.h>
#include <grub/dl.h>
Index: normal/cmdline.c
===================================================================
RCS file: /cvsroot/grub/grub2/normal/cmdline.c,v
retrieving revision 1.8
diff -u -p -u -p -r1.8 cmdline.c
--- normal/cmdline.c 27 Jun 2004 11:03:24 -0000 1.8
+++ normal/cmdline.c 17 Nov 2004 19:12:22 -0000
@@ -23,7 +23,7 @@
#include <grub/err.h>
#include <grub/types.h>
#include <grub/mm.h>
-#include <grub/machine/partition.h>
+#include <grub/partition.h>
#include <grub/disk.h>
#include <grub/file.h>
#include <grub/env.h>
Index: partmap/amiga.c
===================================================================
RCS file: partmap/amiga.c
diff -N partmap/amiga.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ partmap/amiga.c 17 Nov 2004 19:12:22 -0000
@@ -0,0 +1,229 @@
+/* amiga.c - Read amiga partition tables (RDB). */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2004 Free Software Foundation, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <grub/disk.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+#include <grub/partition.h>
+#include <grub/dl.h>
+
+struct grub_amiga_rdsk
+{
+ /* "RDSK". */
+ grub_uint8_t magic[4];
+ grub_uint32_t size;
+ grub_int32_t checksum;
+ grub_uint32_t scsihost;
+ grub_uint32_t blksz;
+ grub_uint32_t flags;
+ grub_uint32_t badblcklst;
+ grub_uint32_t partitionlst;
+ grub_uint32_t fslst;
+
+ /* The other information is not important for us. */
+} __attribute__ ((packed));
+
+struct grub_amiga_partition
+{
+ /* "PART". */
+ grub_uint8_t magic[4];
+ grub_int32_t size;
+ grub_int32_t checksum;
+ grub_uint32_t scsihost;
+ grub_uint32_t next;
+ grub_uint32_t flags;
+ grub_uint32_t unused1[2];
+ grub_uint32_t devflags;
+ grub_uint8_t namelen;
+ grub_uint8_t name[31];
+ grub_uint32_t unused2[15];
+
+ grub_uint32_t unused3[3];
+ grub_uint32_t heads;
+ grub_uint32_t unused4;
+ grub_uint32_t block_per_track;
+ grub_uint32_t unused5[3];
+ grub_uint32_t lowcyl;
+ grub_uint32_t highcyl;
+
+ grub_uint32_t firstcyl;
+} __attribute__ ((packed));
+
+static struct grub_partition_map grub_amiga_partition_map;
+
+#ifndef GRUB_UTIL
+static grub_dl_t my_mod;
+#endif
+\f
+static grub_err_t
+amiga_partition_map_iterate (grub_disk_t disk,
+ int (*hook) (const grub_partition_t partition))
+{
+ struct grub_partition part;
+ struct grub_amiga_rdsk rdsk;
+ struct grub_disk raw;
+ int partno = 0;
+ int next = -1;
+ int pos;
+
+ /* Enforce raw disk access. */
+ raw = *disk;
+ raw.partition = 0;
+
+ /* The RDSK block is one of the first 15 blocks. */
+ for (pos = 0; pos < 15; pos++)
+ {
+ /* Read the RDSK block which is a descriptor for the entire disk. */
+ if (grub_disk_read (&raw, pos, 0,
+ sizeof (rdsk), (char *) &rdsk))
+ return grub_errno;
+
+ if (!grub_strcmp (rdsk.magic, "RDSK"))
+ {
+ /* Found the first PART block. */
+ next = grub_be_to_cpu32 (rdsk.partitionlst);
+ break;
+ }
+ }
+
+ /* The end of the partition list is marked using "-1". */
+ while (next != -1)
+ {
+ struct grub_amiga_partition apart;
+
+ /* Read the RDSK block which is a descriptor for the entire disk. */
+ if (grub_disk_read (&raw, next, 0,
+ sizeof (apart), (char *) &apart))
+ return grub_errno;
+
+ /* Calculate the first block and the size of the partition. */
+ part.start = (grub_be_to_cpu32 (apart.lowcyl)
+ * grub_be_to_cpu32 (apart.heads)
+ * grub_be_to_cpu32 (apart.block_per_track));
+ part.len = ((grub_be_to_cpu32 (apart.highcyl)
+ - grub_be_to_cpu32 (apart.lowcyl) + 1)
+ * grub_be_to_cpu32 (apart.heads)
+ * grub_be_to_cpu32 (apart.block_per_track));
+
+ part.offset = next * 512;
+ part.index = partno;
+ part.partmap = &grub_amiga_partition_map;
+
+ if (hook (&part))
+ return grub_errno;
+
+ next = grub_be_to_cpu32 (apart.next);
+ partno++;
+ }
+
+ return 0;
+}
+
+
+static grub_partition_t
+amiga_partition_map_probe (grub_disk_t disk, const char *str)
+{
+ grub_partition_t p = 0;
+ int partnum = 0;
+ char *s = (char *) str;
+
+ auto int find_func (const grub_partition_t partition);
+
+ int find_func (const grub_partition_t partition)
+ {
+ if (partnum == partition->index)
+ {
+ p = (grub_partition_t) grub_malloc (sizeof (*p));
+ if (! p)
+ return 1;
+
+ grub_memcpy (p, partition, sizeof (*p));
+ return 1;
+ }
+
+ return 0;
+ }
+
+ /* Get the partition number. */
+ partnum = grub_strtoul (s, 0, 10);
+ if (grub_errno)
+ {
+ grub_error (GRUB_ERR_BAD_FILENAME, "invalid partition");
+ return 0;
+ }
+
+ if (amiga_partition_map_iterate (disk, find_func))
+ goto fail;
+
+ return p;
+
+ fail:
+ grub_free (p);
+ return 0;
+}
+
+
+static char *
+amiga_partition_map_get_name (const grub_partition_t p)
+{
+ char *name;
+
+ name = grub_malloc (13);
+ if (! name)
+ return 0;
+
+ grub_sprintf (name, "%d", p->index);
+ return name;
+}
+
+\f
+/* Partition map type. */
+static struct grub_partition_map grub_amiga_partition_map =
+ {
+ .name = "amiga_partition_map",
+ .iterate = amiga_partition_map_iterate,
+ .probe = amiga_partition_map_probe,
+ .get_name = amiga_partition_map_get_name
+ };
+
+#ifdef GRUB_UTIL
+void
+grub_amiga_partition_map_init (void)
+{
+ grub_partition_map_register (&grub_amiga_partition_map);
+}
+
+void
+grub_amiga_partition_map_fini (void)
+{
+ grub_partition_map_unregister (&grub_amiga_partition_map);
+}
+#else
+GRUB_MOD_INIT
+{
+ grub_partition_map_register (&grub_amiga_partition_map);
+ my_mod = mod;
+}
+
+GRUB_MOD_FINI
+{
+ grub_partition_map_unregister (&grub_amiga_partition_map);
+}
+#endif
Index: partmap/apple.c
===================================================================
RCS file: partmap/apple.c
diff -N partmap/apple.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ partmap/apple.c 17 Nov 2004 19:12:22 -0000
@@ -0,0 +1,227 @@
+/* apple.c - Read macintosh partition tables. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2004 Free Software Foundation, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <grub/disk.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+#include <grub/partition.h>
+
+#define GRUB_APPLE_PART_MAGIC 0x504D
+
+struct grub_apple_part
+{
+ /* The magic number to idenify this as a partition, it should have
+ the value `0x504D'. */
+ grub_uint16_t magic;
+
+ /* Reserved. */
+ grub_uint16_t reserved;
+
+ /* The size of the partition map in blocks. */
+ grub_uint32_t partmap_size;
+
+ /* The first physical block of the partition. */
+ grub_uint32_t first_phys_block;
+
+ /* The amount of blocks. */
+ grub_uint32_t blockcnt;
+
+ /* The partition name. */
+ char partname[32];
+
+ /* The partition type. */
+ char parttype[32];
+
+ /* The first datablock of the partition. */
+ grub_uint32_t datablocks_first;
+
+ /* The amount datablocks. */
+ grub_uint32_t datablocks_count;
+
+ /* The status of the partition. (???) */
+ grub_uint32_t status;
+
+ /* The first block on which the bootcode can be found. */
+ grub_uint32_t bootcode_pos;
+
+ /* The size of the bootcode in bytes. */
+ grub_uint32_t bootcode_size;
+
+ /* The load address of the bootcode. */
+ grub_uint32_t bootcode_loadaddr;
+
+ /* Reserved. */
+ grub_uint32_t reserved2;
+
+ /* The entrypoint of the bootcode. */
+ grub_uint32_t bootcode_entrypoint;
+
+ /* Reserved. */
+ grub_uint32_t reserved3;
+
+ /* A checksum of the bootcode. */
+ grub_uint32_t bootcode_checksum;
+
+ /* The processor type. */
+ char processor[16];
+
+ /* Padding. */
+ grub_uint16_t pad[187];
+};
+
+#ifndef GRUB_UTIL
+static grub_dl_t my_mod;
+#endif
+\f
+
+static grub_err_t
+apple_partition_map_iterate (grub_disk_t disk,
+ int (*hook) (const grub_partition_t partition))
+{
+ struct grub_partition part;
+ struct grub_apple_part apart;
+ struct grub_disk raw;
+ int partno = 0;
+ int pos = GRUB_DISK_SECTOR_SIZE;
+
+ /* Enforce raw disk access. */
+ raw = *disk;
+ raw.partition = 0;
+
+ for (;;)
+ {
+ if (grub_disk_read (&raw, pos / GRUB_DISK_SECTOR_SIZE,
+ pos % GRUB_DISK_SECTOR_SIZE,
+ sizeof (struct grub_apple_part), (char *) &apart))
+ return grub_errno;
+
+ if (apart.magic != GRUB_APPLE_PART_MAGIC)
+ break;
+
+ part.start = apart.first_phys_block;
+ part.len = apart.blockcnt;
+ part.offset = pos;
+ part.index = partno;
+
+ if (hook (&part))
+ return grub_errno;
+
+ if (apart.first_phys_block == GRUB_DISK_SECTOR_SIZE * 2)
+ return 0;
+
+ pos += sizeof (struct grub_apple_part);
+ partno++;
+ }
+
+ return 0;
+}
+
+
+static grub_partition_t
+apple_partition_map_probe (grub_disk_t disk, const char *str)
+{
+ grub_partition_t p = 0;
+ int partnum = 0;
+ char *s = (char *) str;
+
+ auto int find_func (const grub_partition_t partition);
+
+ int find_func (const grub_partition_t partition)
+ {
+ if (partnum == partition->index)
+ {
+ p = (grub_partition_t) grub_malloc (sizeof (*p));
+ if (! p)
+ return 1;
+
+ grub_memcpy (p, partition, sizeof (*p));
+ return 1;
+ }
+
+ return 0;
+ }
+
+ /* Get the partition number. */
+ partnum = grub_strtoul (s, 0, 10);
+ if (grub_errno)
+ {
+ grub_error (GRUB_ERR_BAD_FILENAME, "invalid partition");
+ return 0;
+ }
+
+ if (apple_partition_map_iterate (disk, find_func))
+ goto fail;
+
+ return p;
+
+ fail:
+ grub_free (p);
+ return 0;
+
+}
+
+
+static char *
+apple_partition_map_get_name (const grub_partition_t p)
+{
+ char *name;
+
+ name = grub_malloc (13);
+ if (! name)
+ return 0;
+
+ grub_sprintf (name, "%d", p->index);
+ return name;
+}
+
+\f
+/* Partition map type. */
+static struct grub_partition_map grub_apple_partition_map =
+ {
+ .name = "apple_partition_map",
+ .iterate = apple_partition_map_iterate,
+ .probe = apple_partition_map_probe,
+ .get_name = apple_partition_map_get_name
+ };
+
+#ifdef GRUB_UTIL
+void
+grub_apple_partition_map_init (void)
+{
+ grub_partition_map_register (&grub_apple_partition_map);
+}
+
+void
+grub_apple_partition_map_fini (void)
+{
+ grub_partition_map_unregister (&grub_apple_partition_map);
+}
+#else
+GRUB_MOD_INIT
+{
+ grub_partition_map_register (&grub_apple_partition_map);
+ my_mod = mod;
+}
+
+GRUB_MOD_FINI
+{
+ grub_partition_map_unregister (&grub_apple_partition_map);
+}
+#endif
Index: partmap/pc.c
===================================================================
RCS file: partmap/pc.c
diff -N partmap/pc.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ partmap/pc.c 17 Nov 2004 19:12:22 -0000
@@ -0,0 +1,293 @@
+/* pc.c - Read PC style partition tables. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002, 2004 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <grub/partition.h>
+#include <grub/pc_partition.h>
+#include <grub/disk.h>
+#include <grub/mm.h>
+#include <grub/misc.h>
+#include <grub/dl.h>
+
+#ifndef GRUB_UTIL
+static grub_dl_t my_mod;
+#endif
+\f
+
+/* Parse the partition representation in STR and return a partition. */
+static grub_partition_t
+grub_partition_parse (const char *str)
+{
+ grub_partition_t p;
+ char *s = (char *) str;
+
+ p = (grub_partition_t) grub_malloc (sizeof (*p));
+ if (! p)
+ return 0;
+
+ /* Initialize some of the fields with invalid values. */
+ p->bsd_part = p->dos_type = p->bsd_type = p->index = -1;
+
+ /* Get the DOS partition number. */
+ p->dos_part = grub_strtoul (s, &s, 0);
+
+ if (grub_errno)
+ {
+ /* Not found. Maybe only a BSD label is specified. */
+ p->dos_part = -1;
+ grub_errno = GRUB_ERR_NONE;
+ }
+ else if (*s == ',')
+ s++;
+
+ if (*s)
+ {
+ if (*s >= 'a' && *s <= 'h')
+ {
+ p->bsd_part = *s - 'a';
+ s++;
+ }
+
+ if (*s)
+ goto fail;
+ }
+
+ if (p->dos_part == -1 && p->bsd_part == -1)
+ goto fail;
+
+ return p;
+
+ fail:
+ grub_free (p);
+ grub_error (GRUB_ERR_BAD_FILENAME, "invalid partition");
+ return 0;
+}
+
+static grub_err_t
+pc_partition_map_iterate (grub_disk_t disk,
+ int (*hook) (const grub_partition_t partition))
+{
+ struct grub_partition p;
+ struct grub_partition_mbr mbr;
+ struct grub_partition_disk_label label;
+ struct grub_disk raw;
+
+ /* Enforce raw disk access. */
+ raw = *disk;
+ raw.partition = 0;
+
+ p.offset = 0;
+ p.ext_offset = 0;
+ p.dos_part = -1;
+
+ while (1)
+ {
+ int i;
+ struct grub_partition_entry *e;
+
+ /* Read the MBR. */
+ if (grub_disk_read (&raw, p.offset, 0, sizeof (mbr), (char *) &mbr))
+ goto finish;
+
+ /* Check if it is valid. */
+ if (mbr.signature != grub_cpu_to_le16 (GRUB_PARTITION_SIGNATURE))
+ return grub_error (GRUB_ERR_BAD_PART_TABLE, "no signature");
+
+ /* Analyze DOS partitions. */
+ for (p.index = 0; p.index < 4; p.index++)
+ {
+ e = mbr.entries + p.index;
+
+ p.start = p.offset + grub_le_to_cpu32 (e->start);
+ p.len = grub_le_to_cpu32 (e->length);
+ p.bsd_part = -1;
+ p.dos_type = e->type;
+ p.bsd_type = -1;
+
+ /* If this partition is a normal one, call the hook. */
+ if (! grub_partition_is_empty (e->type)
+ && ! grub_partition_is_extended (e->type))
+ {
+ p.dos_part++;
+
+ if (hook (&p))
+ goto finish;
+
+ /* Check if this is a BSD partition. */
+ if (grub_partition_is_bsd (e->type))
+ {
+ /* Check if the BSD label is within the DOS partition. */
+ if (p.len <= GRUB_PARTITION_BSD_LABEL_SECTOR)
+ return grub_error (GRUB_ERR_BAD_PART_TABLE,
+ "no space for disk label");
+
+ /* Read the BSD label. */
+ if (grub_disk_read (&raw,
+ (p.start
+ + GRUB_PARTITION_BSD_LABEL_SECTOR),
+ 0,
+ sizeof (label),
+ (char *) &label))
+ goto finish;
+
+ /* Check if it is valid. */
+ if (label.magic
+ != grub_cpu_to_le32 (GRUB_PARTITION_BSD_LABEL_MAGIC))
+ return grub_error (GRUB_ERR_BAD_PART_TABLE,
+ "invalid disk label magic");
+
+ for (p.bsd_part = 0;
+ p.bsd_part < grub_cpu_to_le16 (label.num_partitions);
+ p.bsd_part++)
+ {
+ struct grub_partition_bsd_entry *be
+ = label.entries + p.bsd_part;
+
+ p.start = grub_le_to_cpu32 (be->offset);
+ p.len = grub_le_to_cpu32 (be->size);
+ p.bsd_type = be->fs_type;
+
+ if (be->fs_type != GRUB_PARTITION_BSD_TYPE_UNUSED)
+ if (hook (&p))
+ goto finish;
+ }
+ }
+ }
+ else if (p.dos_part < 4)
+ /* If this partition is a logical one, shouldn't increase the
+ partition number. */
+ p.dos_part++;
+ }
+
+ /* Find an extended partition. */
+ for (i = 0; i < 4; i++)
+ {
+ e = mbr.entries + i;
+
+ if (grub_partition_is_extended (e->type))
+ {
+ p.offset = p.ext_offset + grub_le_to_cpu32 (e->start);
+ if (! p.ext_offset)
+ p.ext_offset = p.offset;
+
+ break;
+ }
+ }
+
+ /* If no extended partition, the end. */
+ if (i == 4)
+ break;
+ }
+
+ finish:
+ return grub_errno;
+}
+
+
+static grub_partition_t
+pc_partition_map_probe (grub_disk_t disk, const char *str)
+{
+ grub_partition_t p;
+ auto int find_func (const grub_partition_t partition);
+
+ int find_func (const grub_partition_t partition)
+ {
+ if ((p->dos_part == partition->dos_part || p->dos_part == -1)
+ && p->bsd_part == partition->bsd_part)
+ {
+ grub_memcpy (p, partition, sizeof (*p));
+ return 1;
+ }
+
+ return 0;
+ }
+
+ p = grub_partition_parse (str);
+ if (! p)
+ return 0;
+
+
+ if (pc_partition_map_iterate (disk, find_func))
+ goto fail;
+
+ if (p->index < 0)
+ {
+ grub_error (GRUB_ERR_BAD_DEVICE, "no such partition");
+ goto fail;
+ }
+
+ return p;
+
+ fail:
+ grub_free (p);
+ return 0;
+}
+
+
+static char *
+pc_partition_map_get_name (const grub_partition_t p)
+{
+ char *name;
+
+ name = grub_malloc (13);
+ if (! name)
+ return 0;
+
+ if (p->bsd_part < 0)
+ grub_sprintf (name, "%d", p->dos_part);
+ else
+ grub_sprintf (name, "%d,%c", p->dos_part, p->bsd_part + 'a');
+
+ return name;
+}
+
+\f
+/* Partition map type. */
+static struct grub_partition_map grub_pc_partition_map =
+ {
+ .name = "pc_partition_map",
+ .iterate = pc_partition_map_iterate,
+ .probe = pc_partition_map_probe,
+ .get_name = pc_partition_map_get_name
+ };
+
+#ifdef GRUB_UTIL
+void
+grub_pc_partition_map_init (void)
+{
+ grub_partition_map_register (&grub_pc_partition_map);
+}
+
+void
+grub_pc_partition_map_fini (void)
+{
+ grub_partition_map_unregister (&grub_pc_partition_map);
+}
+#else
+GRUB_MOD_INIT
+{
+ grub_partition_map_register (&grub_pc_partition_map);
+ my_mod = mod;
+}
+
+GRUB_MOD_FINI
+{
+ grub_partition_map_unregister (&grub_pc_partition_map);
+}
+#endif
Index: util/grub-emu.c
===================================================================
RCS file: /cvsroot/grub/grub2/util/grub-emu.c,v
retrieving revision 1.8
diff -u -p -u -p -r1.8 grub-emu.c
--- util/grub-emu.c 1 Nov 2004 16:14:16 -0000 1.8
+++ util/grub-emu.c 17 Nov 2004 19:12:22 -0000
@@ -34,6 +34,7 @@
#include <grub/normal.h>
#include <grub/util/getroot.h>
#include <grub/env.h>
+#include <grub/partition.h>
#ifdef __NetBSD__
/* NetBSD uses /boot for its boot block. */
@@ -154,6 +155,9 @@ main (int argc, char *argv[])
/* XXX: This is a bit unportable. */
grub_util_biosdisk_init (args.dev_map);
+ grub_pc_partition_map_init ();
+ grub_amiga_partition_map_init ();
+ grub_apple_partition_map_init ();
/* Initialize the default modules. */
grub_iso9660_init ();
@@ -187,6 +191,9 @@ main (int argc, char *argv[])
grub_cmp_fini ();
grub_cat_fini ();
grub_terminal_fini ();
-
+ grub_amiga_partition_map_fini ();
+ grub_pc_partition_map_fini ();
+ grub_apple_partition_map_fini ();
+
return 0;
}
Index: util/i386/pc/biosdisk.c
===================================================================
RCS file: /cvsroot/grub/grub2/util/i386/pc/biosdisk.c,v
retrieving revision 1.8
diff -u -p -u -p -r1.8 biosdisk.c
--- util/i386/pc/biosdisk.c 21 Aug 2004 13:54:22 -0000 1.8
+++ util/i386/pc/biosdisk.c 17 Nov 2004 19:12:22 -0000
@@ -20,7 +20,8 @@
#include <grub/machine/biosdisk.h>
#include <grub/disk.h>
-#include <grub/machine/partition.h>
+#include <grub/partition.h>
+#include <grub/pc_partition.h>
#include <grub/types.h>
#include <grub/err.h>
#include <grub/util/misc.h>
Index: util/i386/pc/grub-setup.c
===================================================================
RCS file: /cvsroot/grub/grub2/util/i386/pc/grub-setup.c,v
retrieving revision 1.8
diff -u -p -u -p -r1.8 grub-setup.c
--- util/i386/pc/grub-setup.c 4 Apr 2004 13:46:03 -0000 1.8
+++ util/i386/pc/grub-setup.c 17 Nov 2004 19:12:22 -0000
@@ -25,7 +25,8 @@
#include <grub/disk.h>
#include <grub/file.h>
#include <grub/fs.h>
-#include <grub/machine/partition.h>
+#include <grub/partition.h>
+#include <grub/pc_partition.h>
#include <grub/machine/util/biosdisk.h>
#include <grub/machine/boot.h>
#include <grub/machine/kernel.h>
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Partition modules
2004-11-17 19:25 Partition modules Marco Gerards
@ 2004-11-18 3:50 ` Hollis Blanchard
2004-11-18 5:09 ` Hollis Blanchard
` (2 more replies)
2004-11-18 9:28 ` Yoshinori K. Okuji
` (2 subsequent siblings)
3 siblings, 3 replies; 19+ messages in thread
From: Hollis Blanchard @ 2004-11-18 3:50 UTC (permalink / raw)
To: The development of GRUB 2
On Nov 17, 2004, at 1:25 PM, Marco Gerards wrote:
>
> Here is a patch to modulize partition support. At the moment it will
> create pc.mod, amiga.mod and apple.mod. Loading one of these modules
> will give support for that specific partition map.
Thanks Marco!
> +/* Partition description. */
> +struct grub_partition
> +{
> + /* The start sector. */
> + unsigned long start;
> +
> + /* The length in sector units. */
> + unsigned long len;
> +
> + /* The offset of the partition table. */
> + unsigned long offset;
> +
> + /* The index of this partition in the partition table. */
> + int index;
> +
> + /* The DOS partition number. */
> + int dos_part;
> +
> + /* The BSD partition number (a == 0). */
> + int bsd_part;
> +
> + /* The DOS partition type. */
> + int dos_type;
> +
> + /* The BSD partition type. */
> + int bsd_type;
> +
> + /* The offset of the extended partition. */
> + unsigned long ext_offset;
> +
> + /* The type partition map. */
> + grub_partition_map_t partmap;
> +};
I do have an objection here: members like "bsd_type" don't belong in a
generic struct, but rather in grub_partition_bsd_type. I believe
grub_partition should be the abstraction, i.e. what defines a partition
in the general sense. start, len, and index are obviously good; offset
is compensating for a DOS issue, though at least it has (irrelevant)
meaning for an Apple map... but ext_offset and these dos_ and bsd_
things don't belong here IMHO.
Also, there were a number of whitespace-only lines in your patch; a
simple regex should show you where.
I'm seeing a crash on both briQ and my G3, so I'm sprinkling printfs
now...
-Hollis
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Partition modules
2004-11-18 3:50 ` Hollis Blanchard
@ 2004-11-18 5:09 ` Hollis Blanchard
2004-11-18 8:13 ` Marco Gerards
2004-11-18 8:16 ` Marco Gerards
2004-11-18 9:32 ` Yoshinori K. Okuji
2 siblings, 1 reply; 19+ messages in thread
From: Hollis Blanchard @ 2004-11-18 5:09 UTC (permalink / raw)
To: The development of GRUB 2
On Nov 17, 2004, at 9:50 PM, Hollis Blanchard wrote:
>
> I'm seeing a crash on both briQ and my G3, so I'm sprinkling printfs
> now...
This incremental patch fixes rescue mode "ls" on both systems. I guess
the patch you sent works on Amiga... pffft. :)
-Hollis
--- partmap/apple.c.orig 2004-11-17 22:30:14.731262376 -0600
+++ partmap/apple.c 2004-11-17 22:32:41.988875816 -0600
@@ -86,6 +86,8 @@ struct grub_apple_part
grub_uint16_t pad[187];
};
+static struct grub_partition_map grub_apple_partition_map;
+
#ifndef GRUB_UTIL
static grub_dl_t my_mod;
#endif
@@ -119,6 +121,7 @@ apple_partition_map_iterate (grub_disk_t
part.len = apart.blockcnt;
part.offset = pos;
part.index = partno;
+ part.partmap = &grub_apple_partition_map;
if (hook (&part))
return grub_errno;
--- partmap/pc.c.orig 2004-11-17 22:29:24.891839120 -0600
+++ partmap/pc.c 2004-11-17 22:29:39.966547416 -0600
@@ -25,6 +25,8 @@
#include <grub/misc.h>
#include <grub/dl.h>
+static struct grub_partition_map grub_pc_partition_map;
+
#ifndef GRUB_UTIL
static grub_dl_t my_mod;
#endif
@@ -97,6 +97,7 @@ pc_partition_map_iterate (grub_disk_t di
p.offset = 0;
p.ext_offset = 0;
p.dos_part = -1;
+ p.partmap = &grub_pc_partition_map;
while (1)
{
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Partition modules
2004-11-18 5:09 ` Hollis Blanchard
@ 2004-11-18 8:13 ` Marco Gerards
0 siblings, 0 replies; 19+ messages in thread
From: Marco Gerards @ 2004-11-18 8:13 UTC (permalink / raw)
To: The development of GRUB 2
Hollis Blanchard <hollis@penguinppc.org> writes:
> On Nov 17, 2004, at 9:50 PM, Hollis Blanchard wrote:
>>
>> I'm seeing a crash on both briQ and my G3, so I'm sprinkling printfs
>> now...
>
> This incremental patch fixes rescue mode "ls" on both systems. I guess
> the patch you sent works on Amiga... pffft. :)
I will fix this in my tree.
Thanks,
Marco
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Partition modules
2004-11-18 3:50 ` Hollis Blanchard
2004-11-18 5:09 ` Hollis Blanchard
@ 2004-11-18 8:16 ` Marco Gerards
2004-11-18 9:32 ` Yoshinori K. Okuji
2 siblings, 0 replies; 19+ messages in thread
From: Marco Gerards @ 2004-11-18 8:16 UTC (permalink / raw)
To: The development of GRUB 2
Hollis Blanchard <hollis@penguinppc.org> writes:
> I do have an objection here: members like "bsd_type" don't belong in a
> generic struct, but rather in grub_partition_bsd_type. I believe
> grub_partition should be the abstraction, i.e. what defines a
> partition in the general sense. start, len, and index are obviously
> good; offset is compensating for a DOS issue, though at least it has
> (irrelevant) meaning for an Apple map... but ext_offset and these dos_
> and bsd_ things don't belong here IMHO.
Ok.
> Also, there were a number of whitespace-only lines in your patch; a
> simple regex should show you where.
Ok.
> I'm seeing a crash on both briQ and my G3, so I'm sprinkling printfs
> now...
Does the PC partition map work on the briQ now?
Thanks,
Marco
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Partition modules
2004-11-17 19:25 Partition modules Marco Gerards
2004-11-18 3:50 ` Hollis Blanchard
@ 2004-11-18 9:28 ` Yoshinori K. Okuji
2004-11-18 10:40 ` Marco Gerards
2004-11-23 1:29 ` Timothy Baldwin
2004-11-24 19:15 ` Marco Gerards
3 siblings, 1 reply; 19+ messages in thread
From: Yoshinori K. Okuji @ 2004-11-18 9:28 UTC (permalink / raw)
To: The development of GRUB 2
On Wednesday 17 November 2004 20:25, Marco Gerards wrote:
> Can someone please this patch on the PC for me to see if it works? I
> don't know when I can do that, I just tried if it compiles correctly
> on the PC.
Don't expect me to test it... I might be able to have time in this
weekend, but no guarantee.
> Index: include/grub/pc_partition.h
> ===================================================================
> RCS file: include/grub/pc_partition.h
> diff -N include/grub/pc_partition.h
> --- /dev/null 1 Jan 1970 00:00:00 -0000
> +++ include/grub/pc_partition.h 17 Nov 2004 19:12:22 -0000
> @@ -0,0 +1,190 @@
[snip]
The macros defined in this header should use different names, because
GRUB_PARTITION_FOO is too generic. Maybe GRUB_PC_PARTITION_FOO?
The other parts look good for me.
Thanks,
Okuji
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Partition modules
2004-11-18 3:50 ` Hollis Blanchard
2004-11-18 5:09 ` Hollis Blanchard
2004-11-18 8:16 ` Marco Gerards
@ 2004-11-18 9:32 ` Yoshinori K. Okuji
2004-11-18 10:46 ` Marco Gerards
2 siblings, 1 reply; 19+ messages in thread
From: Yoshinori K. Okuji @ 2004-11-18 9:32 UTC (permalink / raw)
To: The development of GRUB 2
On Thursday 18 November 2004 04:50, Hollis Blanchard wrote:
> I do have an objection here: members like "bsd_type" don't belong in
> a generic struct, but rather in grub_partition_bsd_type. I believe
> grub_partition should be the abstraction, i.e. what defines a
> partition in the general sense. start, len, and index are obviously
> good; offset is compensating for a DOS issue, though at least it has
> (irrelevant) meaning for an Apple map... but ext_offset and these
> dos_ and bsd_ things don't belong here IMHO.
I agree with you in theory... but I guess it is a bit difficult to make
BSD disklabel independent, because it is sometimes used alone and it is
sometimes nested in other partition types. I hope Marco will find out a
good solution here.
Okuji
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Partition modules
2004-11-18 9:28 ` Yoshinori K. Okuji
@ 2004-11-18 10:40 ` Marco Gerards
0 siblings, 0 replies; 19+ messages in thread
From: Marco Gerards @ 2004-11-18 10:40 UTC (permalink / raw)
To: The development of GRUB 2
"Yoshinori K. Okuji" <okuji@enbug.org> writes:
> On Wednesday 17 November 2004 20:25, Marco Gerards wrote:
>> Can someone please this patch on the PC for me to see if it works? I
>> don't know when I can do that, I just tried if it compiles correctly
>> on the PC.
>
> Don't expect me to test it... I might be able to have time in this
> weekend, but no guarantee.
Ok, otherwise I will just have to wait until I have a PC available.
>> Index: include/grub/pc_partition.h
>> ===================================================================
>> RCS file: include/grub/pc_partition.h
>> diff -N include/grub/pc_partition.h
>> --- /dev/null 1 Jan 1970 00:00:00 -0000
>> +++ include/grub/pc_partition.h 17 Nov 2004 19:12:22 -0000
>> @@ -0,0 +1,190 @@
> [snip]
>
> The macros defined in this header should use different names, because
> GRUB_PARTITION_FOO is too generic. Maybe GRUB_PC_PARTITION_FOO?
Sure. I will make the change.
Thanks.
Marco
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Partition modules
2004-11-18 9:32 ` Yoshinori K. Okuji
@ 2004-11-18 10:46 ` Marco Gerards
2004-11-18 11:20 ` Yoshinori K. Okuji
0 siblings, 1 reply; 19+ messages in thread
From: Marco Gerards @ 2004-11-18 10:46 UTC (permalink / raw)
To: The development of GRUB 2
"Yoshinori K. Okuji" <okuji@enbug.org> writes:
> On Thursday 18 November 2004 04:50, Hollis Blanchard wrote:
>> I do have an objection here: members like "bsd_type" don't belong in
>> a generic struct, but rather in grub_partition_bsd_type. I believe
>> grub_partition should be the abstraction, i.e. what defines a
>> partition in the general sense. start, len, and index are obviously
>> good; offset is compensating for a DOS issue, though at least it has
>> (irrelevant) meaning for an Apple map... but ext_offset and these
>> dos_ and bsd_ things don't belong here IMHO.
>
> I agree with you in theory... but I guess it is a bit difficult to make
> BSD disklabel independent, because it is sometimes used alone and it is
> sometimes nested in other partition types. I hope Marco will find out a
> good solution here.
It should not be too hard. The extra members are only used in
specific parts of the code, mainly in the i386/pc directories.
Perhaps I could add a member which points to a user defined data
structure. In that datastructure the extra information can be stored.
The BSD disklabel is a weird special case. Perhaps we need some kind
of nested partitions or so. I don't know if that will make sense
because I have no knowledge about BSD slices and how they are used.
Thanks,
Marco
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Partition modules
2004-11-18 10:46 ` Marco Gerards
@ 2004-11-18 11:20 ` Yoshinori K. Okuji
2004-11-18 13:58 ` Marco Gerards
0 siblings, 1 reply; 19+ messages in thread
From: Yoshinori K. Okuji @ 2004-11-18 11:20 UTC (permalink / raw)
To: The development of GRUB 2
On Thursday 18 November 2004 11:46, Marco Gerards wrote:
> The BSD disklabel is a weird special case. Perhaps we need some kind
> of nested partitions or so. I don't know if that will make sense
> because I have no knowledge about BSD slices and how they are used.
Take a look at this:
http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/disk-organization.html
Note that you can make a BSD disklabel without any PC partition, if you
wish. This is not supported by GRUB legacy (except for floppies).
Okuji
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Partition modules
2004-11-18 11:20 ` Yoshinori K. Okuji
@ 2004-11-18 13:58 ` Marco Gerards
0 siblings, 0 replies; 19+ messages in thread
From: Marco Gerards @ 2004-11-18 13:58 UTC (permalink / raw)
To: The development of GRUB 2
"Yoshinori K. Okuji" <okuji@enbug.org> writes:
> On Thursday 18 November 2004 11:46, Marco Gerards wrote:
>> The BSD disklabel is a weird special case. Perhaps we need some kind
>> of nested partitions or so. I don't know if that will make sense
>> because I have no knowledge about BSD slices and how they are used.
>
> Take a look at this:
>
> http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/disk-organization.html
>
> Note that you can make a BSD disklabel without any PC partition, if you
> wish. This is not supported by GRUB legacy (except for floppies).
Thanks a lot for this information.
If I understand the GRUB 2 partition code correctly, such partition is
identified with only a command, right? For example: (hd0,,a). Am I
right about this?
At the moment the partition (slice) type is checked to figure out if
there is a BSD partition. If so, the BSD partitions are iterated.
How about the apple, amiga, etc? Does it work the same? Otherwise
code might be shared.
Because I do not have *BSD installed on any system I can not work on
this, but it might be worthwhile to think about this and make it a
todo item related to the PPC port.
Thanks,
Marco
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Partition modules
2004-11-17 19:25 Partition modules Marco Gerards
2004-11-18 3:50 ` Hollis Blanchard
2004-11-18 9:28 ` Yoshinori K. Okuji
@ 2004-11-23 1:29 ` Timothy Baldwin
2004-11-23 15:12 ` Marco Gerards
2004-11-24 19:15 ` Marco Gerards
3 siblings, 1 reply; 19+ messages in thread
From: Timothy Baldwin @ 2004-11-23 1:29 UTC (permalink / raw)
To: The development of GRUB 2
[-- Attachment #1: Type: text/plain, Size: 435 bytes --]
On Wednesday 17 Nov 2004 19:25, Marco Gerards wrote:
> If there are no problems with this patch I will commit it Sunday, but
> only if I am sure it works on the PC.
I have tried it on 2 PCs and can confirm that it works, with PC partitions,
after Hollis's changes are applied.
--
Member AFFS, WYLUG, SWP (UK), ANL, RESPECT, Leeds SA, Leeds Anti-war coalition
No to software patents! Victory to the iraqi resistance!
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Partition modules
2004-11-23 1:29 ` Timothy Baldwin
@ 2004-11-23 15:12 ` Marco Gerards
0 siblings, 0 replies; 19+ messages in thread
From: Marco Gerards @ 2004-11-23 15:12 UTC (permalink / raw)
To: The development of GRUB 2
Timothy Baldwin <tim.lists@majoroak.f2s.com> writes:
> On Wednesday 17 Nov 2004 19:25, Marco Gerards wrote:
>
>> If there are no problems with this patch I will commit it Sunday, but
>> only if I am sure it works on the PC.
>
> I have tried it on 2 PCs and can confirm that it works, with PC partitions,
> after Hollis's changes are applied.
Thanks a lot for testing it! I will make the required changes and
send in a new patch.
Thanks,
Marco
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Partition modules
2004-11-17 19:25 Partition modules Marco Gerards
` (2 preceding siblings ...)
2004-11-23 1:29 ` Timothy Baldwin
@ 2004-11-24 19:15 ` Marco Gerards
2004-11-30 17:55 ` Marco Gerards
3 siblings, 1 reply; 19+ messages in thread
From: Marco Gerards @ 2004-11-24 19:15 UTC (permalink / raw)
To: The development of GRUB 2
Marco Gerards <metgerards@student.han.nl> writes:
> Here is a patch to modulize partition support. At the moment it will
> create pc.mod, amiga.mod and apple.mod. Loading one of these modules
> will give support for that specific partition map.
And here is version 2 of the patch. I have made the requested
changes.
The grub_partition structure was split up. I've added a member `data'
so per partition map type additional information can be added. This
is used in biosdisk.c and in grub-setup.c, for example. Although I
have tested this patch as much as I can, the grub-setup changes were
not tested. I've just added a test to check if the right partition
map type is used and the installer fails if this is not the case.
Can I check in this patch?
Thanks,
Marco
2004-11-24 Marco Gerards <metgerards@student.han.nl>
* commands/ls.c: Include <grub/partition.h> instead of
<grub/machine/partition.h>.
* kern/disk.c: Likewise.
* kern/rescue.c: Likewise.
* loader/i386/pc/chainloader.c: Likewise.
* normal/cmdline.c: Likewise.
* kern/powerpc/ieee1275/init.c: Likewise.
(grub_machine_init): Call `grub_pc_partition_map_init',
`grub_amiga_partition_map_init' and
`grub_apple_partition_map_init'.
* conf/i386-pc.rmk (kernel_img_SOURCES): Remove
`disk/i386/pc/partition.c'. Add `kern/partition.c'.
(kernel_img_HEADERS): Remove `machine/partition.h'. Add
`partition.h' and `pc_partition.h'.
(grub_setup_SOURCES): Remove
`disk/i386/pc/partition.c'. Add `kern/partition.c',
`partmap/amiga.c', `partmap/apple.c' and `partmap/pc.c'.
(grub_emu_SOURCES): Likewise.
(pkgdata_MODULES): Add `amiga.mod', `apple.mod' and `pc.mod'.
(amiga_mod_SOURCES, amiga_mod_CFLAGS, apple_mod_SOURCES)
(apple_mod_CFLAGS, pc_mod_SOURCES, pc_mod_CFLAGS): New variables.
* conf/powerpc-ieee1275.rmk (grub_emu_SOURCES): Remove
`disk/powerpc/ieee1275/partition.c'. Add `kern/partition.c',
`partmap/amiga.c', `partmap/apple.c' and `partmap/pc.c'.
(grubof_SOURCES): Likewise.
* disk/i386/pc/partition.c: Removed.
* disk/powerpc/ieee1275/partition.c: Likewise.
* include/grub/partition.h: Removed.
* include/grub/pc_partition.h: Likewise.
* include/grub/powerpc/ieee1275/partition.h: Likewise.
* kern/partition.c: New file.
* partmap/amiga.c: Likewise.
* partmap/apple.c: Likewise.
* partmap/pc.c: Likewise.
* util/grub-emu.c: Include <grub/partition.h> instead of
<grub/machine/partition.h>.
(main): Call `grub_pc_partition_map_init',
`grub_amiga_partition_map_init' and
`grub_apple_partition_map_init' and deinitialize afterwards.
* util/i386/pc/biosdisk.c: Include `#include
<grub/partition.h>' and `include <grub/pc_partition.h>' instead of
`<grub/machine/partition.h>'.
* util/i386/pc/grub-setup.c: Likewise.
* util/i386/pc/biosdisk.c: Likewise.
(grub_util_biosdisk_get_grub_dev): Only access the PC specific
partition information in case of a PC partition.
* util/i386/pc/grub-setup.c: Include `#include
<grub/partition.h>' and `include <grub/pc_partition.h>' instead of
`<grub/machine/partition.h>'.
(setup): Only access the PC specific partition information in case
of a PC partition.
Index: commands/ls.c
===================================================================
RCS file: /cvsroot/grub/grub2/commands/ls.c,v
retrieving revision 1.3
diff -u -p -u -p -r1.3 ls.c
--- commands/ls.c 22 Sep 2004 18:26:16 -0000 1.3
+++ commands/ls.c 24 Nov 2004 19:02:48 -0000
@@ -28,7 +28,7 @@
#include <grub/disk.h>
#include <grub/device.h>
#include <grub/term.h>
-#include <grub/machine/partition.h>
+#include <grub/partition.h>
#include <grub/file.h>
static const struct grub_arg_option options[] =
Index: conf/i386-pc.rmk
===================================================================
RCS file: /cvsroot/grub/grub2/conf/i386-pc.rmk,v
retrieving revision 1.22
diff -u -p -u -p -r1.22 i386-pc.rmk
--- conf/i386-pc.rmk 1 Nov 2004 16:14:15 -0000 1.22
+++ conf/i386-pc.rmk 24 Nov 2004 19:02:48 -0000
@@ -25,7 +25,7 @@ diskboot_img_LDFLAGS = -nostdlib -Wl,-N,
kernel_img_SOURCES = kern/i386/pc/startup.S kern/main.c kern/device.c \
kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
kern/misc.c kern/mm.c kern/loader.c kern/rescue.c kern/term.c \
- kern/i386/dl.c kern/i386/pc/init.c disk/i386/pc/partition.c \
+ kern/i386/dl.c kern/i386/pc/init.c kern/partition.c \
kern/env.c disk/i386/pc/biosdisk.c \
term/i386/pc/console.c \
symlist.c
@@ -33,7 +33,7 @@ kernel_img_HEADERS = arg.h boot.h device
file.h fs.h kernel.h loader.h misc.h mm.h net.h rescue.h symbol.h \
term.h types.h machine/biosdisk.h machine/boot.h \
machine/console.h machine/init.h machine/memory.h \
- machine/loader.h machine/partition.h machine/time.h machine/vga.h
+ machine/loader.h partition.h pc_partition.h machine/time.h machine/vga.h
kernel_img_CFLAGS = $(COMMON_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS = -nostdlib -Wl,-N,-Ttext,8200
@@ -60,14 +60,16 @@ grub_mkimage_LDFLAGS = -llzo
# For grub-setup.
grub_setup_SOURCES = util/i386/pc/grub-setup.c util/i386/pc/biosdisk.c \
util/misc.c util/i386/pc/getroot.c kern/device.c kern/disk.c \
- kern/err.c kern/misc.c disk/i386/pc/partition.c fs/fat.c fs/ext2.c \
+ kern/err.c kern/misc.c fs/fat.c fs/ext2.c \
+ kern/partition.c partmap/amiga.c partmap/apple.c partmap/pc.c \
fs/ufs.c fs/minix.c fs/hfs.c fs/jfs.c kern/file.c kern/fs.c kern/env.c fs/fshelp.c
# For grub
grub_emu_SOURCES = kern/main.c kern/device.c fs/fshelp.c \
kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
kern/misc.c kern/loader.c kern/rescue.c kern/term.c \
- disk/i386/pc/partition.c kern/env.c commands/ls.c \
+ kern/partition.c kern/env.c commands/ls.c partmap/amiga.c \
+ partmap/pc.c partmap/apple.c \
commands/terminal.c commands/boot.c commands/cmp.c commands/cat.c \
util/i386/pc/biosdisk.c fs/fat.c fs/ext2.c fs/ufs.c fs/minix.c fs/hfs.c fs/jfs.c fs/iso9660.c \
normal/cmdline.c normal/command.c normal/main.c normal/menu.c normal/arg.c \
@@ -80,7 +82,8 @@ genmoddep_SOURCES = util/genmoddep.c
# Modules.
pkgdata_MODULES = _chain.mod _linux.mod linux.mod fat.mod ufs.mod ext2.mod minix.mod \
hfs.mod jfs.mod normal.mod hello.mod vga.mod font.mod _multiboot.mod ls.mod \
- boot.mod cmp.mod cat.mod terminal.mod fshelp.mod chain.mod multiboot.mod
+ boot.mod cmp.mod cat.mod terminal.mod fshelp.mod chain.mod multiboot.mod \
+ amiga.mod apple.mod pc.mod
# For _chain.mod.
_chain_mod_SOURCES = loader/i386/pc/chainloader.c
@@ -175,3 +178,15 @@ _multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
# For multiboot.mod.
multiboot_mod_SOURCES = loader/i386/pc/multiboot_normal.c
multiboot_mod_CFLAGS = $(COMMON_CFLAGS)
+
+# For amiga.mod
+amiga_mod_SOURCES = partmap/amiga.c
+amiga_mod_CFLAGS = $(COMMON_CFLAGS)
+
+# For apple.mod
+apple_mod_SOURCES = partmap/apple.c
+apple_mod_CFLAGS = $(COMMON_CFLAGS)
+
+# For pc.mod
+pc_mod_SOURCES = partmap/pc.c
+pc_mod_CFLAGS = $(COMMON_CFLAGS)
Index: conf/powerpc-ieee1275.rmk
===================================================================
RCS file: /cvsroot/grub/grub2/conf/powerpc-ieee1275.rmk,v
retrieving revision 1.14
diff -u -p -u -p -r1.14 powerpc-ieee1275.rmk
--- conf/powerpc-ieee1275.rmk 16 Nov 2004 23:34:44 -0000 1.14
+++ conf/powerpc-ieee1275.rmk 24 Nov 2004 19:02:48 -0000
@@ -24,11 +24,11 @@ noinst_UTILITIES = genmoddep
grub_emu_SOURCES = kern/main.c kern/device.c \
kern/disk.c kern/dl.c kern/file.c kern/fs.c kern/err.c \
kern/misc.c kern/loader.c kern/rescue.c kern/term.c \
- disk/powerpc/ieee1275/partition.c fs/fshelp.c \
+ partmap/amiga.c partmap/pc.c partmap/apple.c fs/fshelp.c \
util/i386/pc/biosdisk.c fs/fat.c fs/ext2.c fs/ufs.c fs/minix.c fs/hfs.c \
fs/jfs.c fs/iso9660.c \
normal/cmdline.c normal/command.c normal/main.c normal/menu.c \
- normal/arg.c \
+ normal/arg.c kern/partition.c \
util/console.c util/grub-emu.c util/misc.c util/i386/pc/getroot.c \
kern/env.c commands/ls.c \
commands/terminal.c commands/boot.c commands/cmp.c commands/cat.c
@@ -41,7 +41,8 @@ grubof_SOURCES = boot/powerpc/ieee1275/c
kern/powerpc/ieee1275/init.c term/powerpc/ieee1275/ofconsole.c \
kern/powerpc/ieee1275/openfw.c fs/ext2.c fs/ufs.c fs/minix.c fs/hfs.c \
fs/jfs.c normal/cmdline.c normal/command.c normal/main.c normal/menu.c \
- disk/powerpc/ieee1275/ofdisk.c disk/powerpc/ieee1275/partition.c \
+ disk/powerpc/ieee1275/ofdisk.c partmap/amiga.c partmap/pc.c \
+ partmap/apple.c kern/partition.c \
kern/env.c normal/arg.c loader/powerpc/ieee1275/linux.c \
loader/powerpc/ieee1275/linux_normal.c commands/boot.c \
normal/powerpc/setjmp.S
Index: disk/i386/pc/partition.c
===================================================================
RCS file: disk/i386/pc/partition.c
diff -N disk/i386/pc/partition.c
--- disk/i386/pc/partition.c 4 Apr 2004 13:46:00 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,248 +0,0 @@
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2002 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 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <grub/machine/partition.h>
-#include <grub/disk.h>
-#include <grub/mm.h>
-#include <grub/misc.h>
-
-/* Parse the partition representation in STR and return a partition. */
-static grub_partition_t
-grub_partition_parse (const char *str)
-{
- grub_partition_t p;
- char *s = (char *) str;
-
- p = (grub_partition_t) grub_malloc (sizeof (*p));
- if (! p)
- return 0;
-
- /* Initialize some of the fields with invalid values. */
- p->bsd_part = p->dos_type = p->bsd_type = p->index = -1;
-
- /* Get the DOS partition number. */
- p->dos_part = grub_strtoul (s, &s, 0);
-
- if (grub_errno)
- {
- /* Not found. Maybe only a BSD label is specified. */
- p->dos_part = -1;
- grub_errno = GRUB_ERR_NONE;
- }
- else if (*s == ',')
- s++;
-
- if (*s)
- {
- if (*s >= 'a' && *s <= 'h')
- {
- p->bsd_part = *s - 'a';
- s++;
- }
-
- if (*s)
- goto fail;
- }
-
- if (p->dos_part == -1 && p->bsd_part == -1)
- goto fail;
-
- return p;
-
- fail:
- grub_free (p);
- grub_error (GRUB_ERR_BAD_FILENAME, "invalid partition");
- return 0;
-}
-
-grub_err_t
-grub_partition_iterate (grub_disk_t disk,
- int (*hook) (const grub_partition_t partition))
-{
- struct grub_partition p;
- struct grub_partition_mbr mbr;
- struct grub_partition_disk_label label;
- struct grub_disk raw;
-
- /* Enforce raw disk access. */
- raw = *disk;
- raw.partition = 0;
-
- p.offset = 0;
- p.ext_offset = 0;
- p.dos_part = -1;
-
- while (1)
- {
- int i;
- struct grub_partition_entry *e;
-
- /* Read the MBR. */
- if (grub_disk_read (&raw, p.offset, 0, sizeof (mbr), (char *) &mbr))
- goto finish;
-
- /* Check if it is valid. */
- if (mbr.signature != grub_cpu_to_le16 (GRUB_PARTITION_SIGNATURE))
- return grub_error (GRUB_ERR_BAD_PART_TABLE, "no signature");
-
- /* Analyze DOS partitions. */
- for (p.index = 0; p.index < 4; p.index++)
- {
- e = mbr.entries + p.index;
-
- p.start = p.offset + grub_le_to_cpu32 (e->start);
- p.len = grub_le_to_cpu32 (e->length);
- p.bsd_part = -1;
- p.dos_type = e->type;
- p.bsd_type = -1;
-
- /* If this partition is a normal one, call the hook. */
- if (! grub_partition_is_empty (e->type)
- && ! grub_partition_is_extended (e->type))
- {
- p.dos_part++;
-
- if (hook (&p))
- goto finish;
-
- /* Check if this is a BSD partition. */
- if (grub_partition_is_bsd (e->type))
- {
- /* Check if the BSD label is within the DOS partition. */
- if (p.len <= GRUB_PARTITION_BSD_LABEL_SECTOR)
- return grub_error (GRUB_ERR_BAD_PART_TABLE,
- "no space for disk label");
-
- /* Read the BSD label. */
- if (grub_disk_read (&raw,
- (p.start
- + GRUB_PARTITION_BSD_LABEL_SECTOR),
- 0,
- sizeof (label),
- (char *) &label))
- goto finish;
-
- /* Check if it is valid. */
- if (label.magic
- != grub_cpu_to_le32 (GRUB_PARTITION_BSD_LABEL_MAGIC))
- return grub_error (GRUB_ERR_BAD_PART_TABLE,
- "invalid disk label magic");
-
- for (p.bsd_part = 0;
- p.bsd_part < grub_cpu_to_le16 (label.num_partitions);
- p.bsd_part++)
- {
- struct grub_partition_bsd_entry *be
- = label.entries + p.bsd_part;
-
- p.start = grub_le_to_cpu32 (be->offset);
- p.len = grub_le_to_cpu32 (be->size);
- p.bsd_type = be->fs_type;
-
- if (be->fs_type != GRUB_PARTITION_BSD_TYPE_UNUSED)
- if (hook (&p))
- goto finish;
- }
- }
- }
- else if (p.dos_part < 4)
- /* If this partition is a logical one, shouldn't increase the
- partition number. */
- p.dos_part++;
- }
-
- /* Find an extended partition. */
- for (i = 0; i < 4; i++)
- {
- e = mbr.entries + i;
-
- if (grub_partition_is_extended (e->type))
- {
- p.offset = p.ext_offset + grub_le_to_cpu32 (e->start);
- if (! p.ext_offset)
- p.ext_offset = p.offset;
-
- break;
- }
- }
-
- /* If no extended partition, the end. */
- if (i == 4)
- break;
- }
-
- finish:
- return grub_errno;
-}
-
-grub_partition_t
-grub_partition_probe (grub_disk_t disk, const char *str)
-{
- grub_partition_t p;
- auto int find_func (const grub_partition_t partition);
-
- int find_func (const grub_partition_t partition)
- {
- if ((p->dos_part == partition->dos_part || p->dos_part == -1)
- && p->bsd_part == partition->bsd_part)
- {
- grub_memcpy (p, partition, sizeof (*p));
- return 1;
- }
-
- return 0;
- }
-
- p = grub_partition_parse (str);
- if (! p)
- return 0;
-
-
- if (grub_partition_iterate (disk, find_func))
- goto fail;
-
- if (p->index < 0)
- {
- grub_error (GRUB_ERR_BAD_DEVICE, "no such partition");
- goto fail;
- }
-
- return p;
-
- fail:
- grub_free (p);
- return 0;
-}
-
-char *
-grub_partition_get_name (const grub_partition_t p)
-{
- char *name;
-
- name = grub_malloc (13);
- if (! name)
- return 0;
-
- if (p->bsd_part < 0)
- grub_sprintf (name, "%d", p->dos_part);
- else
- grub_sprintf (name, "%d,%c", p->dos_part, p->bsd_part + 'a');
-
- return name;
-}
Index: disk/powerpc/ieee1275/partition.c
===================================================================
RCS file: disk/powerpc/ieee1275/partition.c
diff -N disk/powerpc/ieee1275/partition.c
--- disk/powerpc/ieee1275/partition.c 11 Jul 2004 14:24:54 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,120 +0,0 @@
-/* partiton.c - Read macintosh partition tables. */
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 2004 Free Software Foundation, Inc.
- *
- * This program 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 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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 this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <grub/disk.h>
-#include <grub/misc.h>
-#include <grub/mm.h>
-#include <grub/machine/partition.h>
-
-grub_err_t
-grub_partition_iterate (grub_disk_t disk,
- int (*hook) (const grub_partition_t partition))
-{
- struct grub_partition part;
- struct grub_apple_part apart;
- struct grub_disk raw;
- int partno = 0;
- int pos = GRUB_DISK_SECTOR_SIZE;
-
- /* Enforce raw disk access. */
- raw = *disk;
- raw.partition = 0;
-
- for (;;)
- {
- if (grub_disk_read (&raw, pos / GRUB_DISK_SECTOR_SIZE,
- pos % GRUB_DISK_SECTOR_SIZE,
- sizeof (struct grub_apple_part), (char *) &apart))
- return grub_errno;
-
- if (apart.magic != GRUB_APPLE_PART_MAGIC)
- break;
-
- part.start = apart.first_phys_block;
- part.len = apart.blockcnt;
- part.offset = pos;
- part.index = partno;
-
- if (hook (&part))
- return grub_errno;
-
- if (apart.first_phys_block == GRUB_DISK_SECTOR_SIZE * 2)
- return 0;
-
- pos += sizeof (struct grub_apple_part);
- partno++;
- }
-
- return 0;
-}
-
-grub_partition_t
-grub_partition_probe (grub_disk_t disk, const char *str)
-{
- grub_partition_t p = 0;
- int partnum = 0;
- char *s = (char *) str;
-
- int find_func (const grub_partition_t partition)
- {
- if (partnum == partition->index)
- {
- p = (grub_partition_t) grub_malloc (sizeof (*p));
- if (! p)
- return 1;
-
- grub_memcpy (p, partition, sizeof (*p));
- return 1;
- }
-
- return 0;
- }
-
- /* Get the partition number. */
- partnum = grub_strtoul (s, 0, 10);
- if (grub_errno)
- {
- grub_error (GRUB_ERR_BAD_FILENAME, "invalid partition");
- return 0;
- }
-
- if (grub_partition_iterate (disk, find_func))
- goto fail;
-
- return p;
-
- fail:
- grub_free (p);
- return 0;
-
-}
-
-char *
-grub_partition_get_name (const grub_partition_t p)
-{
- char *name;
-
- name = grub_malloc (13);
- if (! name)
- return 0;
-
- grub_sprintf (name, "%d", p->index);
- return name;
-}
Index: include/grub/partition.h
===================================================================
RCS file: include/grub/partition.h
diff -N include/grub/partition.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ include/grub/partition.h 24 Nov 2004 19:02:48 -0000
@@ -0,0 +1,106 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2004 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef GRUB_PART_HEADER
+#define GRUB_PART_HEADER 1
+
+#include <grub/dl.h>
+
+struct grub_disk;
+
+typedef struct grub_partition *grub_partition_t;
+
+/* Partition map type. */
+struct grub_partition_map
+{
+ /* The name of the partition map type. */
+ const char *name;
+
+ /* Call HOOK with each partition, until HOOK returns non-zero. */
+ grub_err_t (*iterate) (struct grub_disk *disk,
+ int (*hook) (const grub_partition_t partition));
+
+ /* Return the partition named STR on the disk DISK. */
+ grub_partition_t (*probe) (struct grub_disk *disk,
+ const char *str);
+
+ /* Return the name of the partition PARTITION. */
+ char *(*get_name) (const grub_partition_t partition);
+
+ /* The next partition map type. */
+ struct grub_partition_map *next;
+};
+typedef struct grub_partition_map *grub_partition_map_t;
+
+/* Partition description. */
+struct grub_partition
+{
+ /* The start sector. */
+ unsigned long start;
+
+ /* The length in sector units. */
+ unsigned long len;
+
+ /* The offset of the partition table. */
+ unsigned long offset;
+
+ /* The index of this partition in the partition table. */
+ int index;
+
+ /* Partition map type specific data. */
+ void *data;
+
+ /* The type partition map. */
+ grub_partition_map_t partmap;
+};
+
+grub_partition_t EXPORT_FUNC(grub_partition_probe) (struct grub_disk *disk,
+ const char *str);
+grub_err_t EXPORT_FUNC(grub_partition_iterate) (struct grub_disk *disk,
+ int (*hook) (const grub_partition_t partition));
+char *EXPORT_FUNC(grub_partition_get_name) (const grub_partition_t partition);
+
+void EXPORT_FUNC(grub_partition_map_iterate) (int (*hook) (const grub_partition_map_t partmap));
+
+void EXPORT_FUNC(grub_partition_map_register) (grub_partition_map_t partmap);
+
+void EXPORT_FUNC(grub_partition_map_unregister) (grub_partition_map_t partmap);
+
+#ifdef GRUB_UTIL
+void grub_pc_partition_map_init (void);
+void grub_pc_partition_map_fini (void);
+void grub_amiga_partition_map_init (void);
+void grub_amiga_partition_map_fini (void);
+void grub_apple_partition_map_init (void);
+void grub_apple_partition_map_fini (void);
+#endif
+\f
+static inline unsigned long
+grub_partition_get_start (const grub_partition_t p)
+{
+ return p->start;
+}
+
+static inline unsigned long
+grub_partition_get_len (const grub_partition_t p)
+{
+ return p->len;
+}
+
+#endif /* ! GRUB_PART_HEADER */
Index: include/grub/pc_partition.h
===================================================================
RCS file: include/grub/pc_partition.h
diff -N include/grub/pc_partition.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ include/grub/pc_partition.h 24 Nov 2004 19:02:48 -0000
@@ -0,0 +1,209 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 1999,2000,2001,2002 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef GRUB_PC_PARTITION_HEADER
+#define GRUB_PC_PARTITION_HEADER 1
+
+#include <grub/symbol.h>
+#include <grub/types.h>
+#include <grub/err.h>
+
+/* The signature. */
+#define GRUB_PC_PARTITION_SIGNATURE 0xaa55
+
+/* This is not a flag actually, but used as if it were a flag. */
+#define GRUB_PC_PARTITION_TYPE_HIDDEN_FLAG 0x10
+
+/* DOS partition types. */
+#define GRUB_PC_PARTITION_TYPE_NONE 0
+#define GRUB_PC_PARTITION_TYPE_FAT12 1
+#define GRUB_PC_PARTITION_TYPE_FAT16_LT32M 4
+#define GRUB_PC_PARTITION_TYPE_EXTENDED 5
+#define GRUB_PC_PARTITION_TYPE_FAT16_GT32M 6
+#define GRUB_PC_PARTITION_TYPE_FAT32 0xb
+#define GRUB_PC_PARTITION_TYPE_FAT32_LBA 0xc
+#define GRUB_PC_PARTITION_TYPE_FAT16_LBA 0xe
+#define GRUB_PC_PARTITION_TYPE_WIN95_EXTENDED 0xf
+#define GRUB_PC_PARTITION_TYPE_EZD 0x55
+#define GRUB_PC_PARTITION_TYPE_MINIX 0x80
+#define GRUB_PC_PARTITION_TYPE_LINUX_MINIX 0x81
+#define GRUB_PC_PARTITION_TYPE_EXT2FS 0x83
+#define GRUB_PC_PARTITION_TYPE_LINUX_EXTENDED 0x85
+#define GRUB_PC_PARTITION_TYPE_VSTAFS 0x9e
+#define GRUB_PC_PARTITION_TYPE_FREEBSD 0xa5
+#define GRUB_PC_PARTITION_TYPE_OPENBSD 0xa6
+#define GRUB_PC_PARTITION_TYPE_NETBSD 0xa9
+#define GRUB_PC_PARTITION_TYPE_LINUX_RAID 0xfd
+
+/* Constants for BSD disk label. */
+#define GRUB_PC_PARTITION_BSD_LABEL_SECTOR 1
+#define GRUB_PC_PARTITION_BSD_LABEL_MAGIC 0x82564557
+#define GRUB_PC_PARTITION_BSD_MAX_ENTRIES 8
+
+/* BSD partition types. */
+#define GRUB_PC_PARTITION_BSD_TYPE_UNUSED 0
+#define GRUB_PC_PARTITION_BSD_TYPE_SWAP 1
+#define GRUB_PC_PARTITION_BSD_TYPE_V6 2
+#define GRUB_PC_PARTITION_BSD_TYPE_V7 3
+#define GRUB_PC_PARTITION_BSD_TYPE_SYSV 4
+#define GRUB_PC_PARTITION_BSD_TYPE_V71K 5
+#define GRUB_PC_PARTITION_BSD_TYPE_V8 6
+#define GRUB_PC_PARTITION_BSD_TYPE_BSDFFS 7
+#define GRUB_PC_PARTITION_BSD_TYPE_MSDOS 8
+#define GRUB_PC_PARTITION_BSD_TYPE_BSDLFS 9
+#define GRUB_PC_PARTITION_BSD_TYPE_OTHER 10
+#define GRUB_PC_PARTITION_BSD_TYPE_HPFS 11
+#define GRUB_PC_PARTITION_BSD_TYPE_ISO9660 12
+#define GRUB_PC_PARTITION_BSD_TYPE_BOOT 13
+
+/* FreeBSD-specific types. */
+#define GRUB_PC_PARTITION_FREEBSD_TYPE_VINUM 14
+#define GRUB_PC_PARTITION_FREEBSD_TYPE_RAID 15
+#define GRUB_PC_PARTITION_FREEBSD_TYPE_JFS2 21
+
+/* NetBSD-specific types. */
+#define GRUB_PC_PARTITION_NETBSD_TYPE_ADOS 14
+#define GRUB_PC_PARTITION_NETBSD_TYPE_HFS 15
+#define GRUB_PC_PARTITION_NETBSD_TYPE_FILECORE 16
+#define GRUB_PC_PARTITION_NETBSD_TYPE_EXT2FS 17
+#define GRUB_PC_PARTITION_NETBSD_TYPE_NTFS 18
+#define GRUB_PC_PARTITION_NETBSD_TYPE_RAID 19
+#define GRUB_PC_PARTITION_NETBSD_TYPE_CCD 20
+#define GRUB_PC_PARTITION_NETBSD_TYPE_JFS2 21
+#define GRUB_PC_PARTITION_NETBSD_TYPE_APPLEUFS 22
+
+/* OpenBSD-specific types. */
+#define GRUB_PC_PARTITION_OPENBSD_TYPE_ADOS 14
+#define GRUB_PC_PARTITION_OPENBSD_TYPE_HFS 15
+#define GRUB_PC_PARTITION_OPENBSD_TYPE_FILECORE 16
+#define GRUB_PC_PARTITION_OPENBSD_TYPE_EXT2FS 17
+#define GRUB_PC_PARTITION_OPENBSD_TYPE_NTFS 18
+#define GRUB_PC_PARTITION_OPENBSD_TYPE_RAID 19
+
+/* The BSD partition entry. */
+struct grub_pc_partition_bsd_entry
+{
+ grub_uint32_t size;
+ grub_uint32_t offset;
+ grub_uint32_t fragment_size;
+ grub_uint8_t fs_type;
+ grub_uint8_t fs_fragments;
+ grub_uint16_t fs_cylinders;
+} __attribute__ ((packed));
+
+/* The BSD disk label. Only define members useful for GRUB. */
+struct grub_pc_partition_disk_label
+{
+ grub_uint32_t magic;
+ grub_uint8_t padding[128];
+ grub_uint32_t magic2;
+ grub_uint16_t checksum;
+ grub_uint16_t num_partitions;
+ grub_uint32_t boot_size;
+ grub_uint32_t superblock_size;
+ struct grub_pc_partition_bsd_entry entries[GRUB_PC_PARTITION_BSD_MAX_ENTRIES];
+} __attribute__ ((packed));
+
+/* The partition entry. */
+struct grub_pc_partition_entry
+{
+ /* If active, 0x80, otherwise, 0x00. */
+ grub_uint8_t flag;
+
+ /* The head of the start. */
+ grub_uint8_t start_head;
+
+ /* (S | ((C >> 2) & 0xC0)) where S is the sector of the start and C
+ is the cylinder of the start. Note that S is counted from one. */
+ grub_uint8_t start_sector;
+
+ /* (C & 0xFF) where C is the cylinder of the start. */
+ grub_uint8_t start_cylinder;
+
+ /* The partition type. */
+ grub_uint8_t type;
+
+ /* The end versions of start_head, start_sector and start_cylinder,
+ respectively. */
+ grub_uint8_t end_head;
+ grub_uint8_t end_sector;
+ grub_uint8_t end_cylinder;
+
+ /* The start sector. Note that this is counted from zero. */
+ grub_uint32_t start;
+
+ /* The length in sector units. */
+ grub_uint32_t length;
+} __attribute__ ((packed));
+
+/* The structure of MBR. */
+struct grub_pc_partition_mbr
+{
+ /* The code area (actually, including BPB). */
+ grub_uint8_t code[446];
+
+ /* Four partition entries. */
+ struct grub_pc_partition_entry entries[4];
+
+ /* The signature 0xaa55. */
+ grub_uint16_t signature;
+} __attribute__ ((packed));
+
+\f
+struct grub_pc_partition
+{
+ /* The DOS partition number. */
+ int dos_part;
+
+ /* The BSD partition number (a == 0). */
+ int bsd_part;
+
+ /* The DOS partition type. */
+ int dos_type;
+
+ /* The BSD partition type. */
+ int bsd_type;
+
+ /* The offset of the extended partition. */
+ unsigned long ext_offset;
+};
+
+static inline int
+grub_pc_partition_is_empty (int type)
+{
+ return (type == GRUB_PC_PARTITION_TYPE_NONE);
+}
+
+static inline int
+grub_pc_partition_is_extended (int type)
+{
+ return (type == GRUB_PC_PARTITION_TYPE_EXTENDED
+ || type == GRUB_PC_PARTITION_TYPE_WIN95_EXTENDED
+ || type == GRUB_PC_PARTITION_TYPE_LINUX_EXTENDED);
+}
+
+static inline int
+grub_pc_partition_is_bsd (int type)
+{
+ return (type == GRUB_PC_PARTITION_TYPE_FREEBSD
+ || type == GRUB_PC_PARTITION_TYPE_OPENBSD
+ || type == GRUB_PC_PARTITION_TYPE_NETBSD);
+}
+
+#endif /* ! GRUB_PC_PARTITION_HEADER */
Index: include/grub/i386/pc/partition.h
===================================================================
RCS file: include/grub/i386/pc/partition.h
diff -N include/grub/i386/pc/partition.h
--- include/grub/i386/pc/partition.h 4 Apr 2004 13:46:01 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,242 +0,0 @@
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 1999,2000,2001,2002 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 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef GRUB_PARTITION_HEADER
-#define GRUB_PARTITION_HEADER 1
-
-#include <grub/symbol.h>
-#include <grub/types.h>
-#include <grub/err.h>
-
-/* The signature. */
-#define GRUB_PARTITION_SIGNATURE 0xaa55
-
-/* This is not a flag actually, but used as if it were a flag. */
-#define GRUB_PARTITION_TYPE_HIDDEN_FLAG 0x10
-
-/* DOS partition types. */
-#define GRUB_PARTITION_TYPE_NONE 0
-#define GRUB_PARTITION_TYPE_FAT12 1
-#define GRUB_PARTITION_TYPE_FAT16_LT32M 4
-#define GRUB_PARTITION_TYPE_EXTENDED 5
-#define GRUB_PARTITION_TYPE_FAT16_GT32M 6
-#define GRUB_PARTITION_TYPE_FAT32 0xb
-#define GRUB_PARTITION_TYPE_FAT32_LBA 0xc
-#define GRUB_PARTITION_TYPE_FAT16_LBA 0xe
-#define GRUB_PARTITION_TYPE_WIN95_EXTENDED 0xf
-#define GRUB_PARTITION_TYPE_EZD 0x55
-#define GRUB_PARTITION_TYPE_MINIX 0x80
-#define GRUB_PARTITION_TYPE_LINUX_MINIX 0x81
-#define GRUB_PARTITION_TYPE_EXT2FS 0x83
-#define GRUB_PARTITION_TYPE_LINUX_EXTENDED 0x85
-#define GRUB_PARTITION_TYPE_VSTAFS 0x9e
-#define GRUB_PARTITION_TYPE_FREEBSD 0xa5
-#define GRUB_PARTITION_TYPE_OPENBSD 0xa6
-#define GRUB_PARTITION_TYPE_NETBSD 0xa9
-#define GRUB_PARTITION_TYPE_LINUX_RAID 0xfd
-
-/* Constants for BSD disk label. */
-#define GRUB_PARTITION_BSD_LABEL_SECTOR 1
-#define GRUB_PARTITION_BSD_LABEL_MAGIC 0x82564557
-#define GRUB_PARTITION_BSD_MAX_ENTRIES 8
-
-/* BSD partition types. */
-#define GRUB_PARTITION_BSD_TYPE_UNUSED 0
-#define GRUB_PARTITION_BSD_TYPE_SWAP 1
-#define GRUB_PARTITION_BSD_TYPE_V6 2
-#define GRUB_PARTITION_BSD_TYPE_V7 3
-#define GRUB_PARTITION_BSD_TYPE_SYSV 4
-#define GRUB_PARTITION_BSD_TYPE_V71K 5
-#define GRUB_PARTITION_BSD_TYPE_V8 6
-#define GRUB_PARTITION_BSD_TYPE_BSDFFS 7
-#define GRUB_PARTITION_BSD_TYPE_MSDOS 8
-#define GRUB_PARTITION_BSD_TYPE_BSDLFS 9
-#define GRUB_PARTITION_BSD_TYPE_OTHER 10
-#define GRUB_PARTITION_BSD_TYPE_HPFS 11
-#define GRUB_PARTITION_BSD_TYPE_ISO9660 12
-#define GRUB_PARTITION_BSD_TYPE_BOOT 13
-
-/* FreeBSD-specific types. */
-#define GRUB_PARTITION_FREEBSD_TYPE_VINUM 14
-#define GRUB_PARTITION_FREEBSD_TYPE_RAID 15
-#define GRUB_PARTITION_FREEBSD_TYPE_JFS2 21
-
-/* NetBSD-specific types. */
-#define GRUB_PARTITION_NETBSD_TYPE_ADOS 14
-#define GRUB_PARTITION_NETBSD_TYPE_HFS 15
-#define GRUB_PARTITION_NETBSD_TYPE_FILECORE 16
-#define GRUB_PARTITION_NETBSD_TYPE_EXT2FS 17
-#define GRUB_PARTITION_NETBSD_TYPE_NTFS 18
-#define GRUB_PARTITION_NETBSD_TYPE_RAID 19
-#define GRUB_PARTITION_NETBSD_TYPE_CCD 20
-#define GRUB_PARTITION_NETBSD_TYPE_JFS2 21
-#define GRUB_PARTITION_NETBSD_TYPE_APPLEUFS 22
-
-/* OpenBSD-specific types. */
-#define GRUB_PARTITION_OPENBSD_TYPE_ADOS 14
-#define GRUB_PARTITION_OPENBSD_TYPE_HFS 15
-#define GRUB_PARTITION_OPENBSD_TYPE_FILECORE 16
-#define GRUB_PARTITION_OPENBSD_TYPE_EXT2FS 17
-#define GRUB_PARTITION_OPENBSD_TYPE_NTFS 18
-#define GRUB_PARTITION_OPENBSD_TYPE_RAID 19
-
-/* The BSD partition entry. */
-struct grub_partition_bsd_entry
-{
- grub_uint32_t size;
- grub_uint32_t offset;
- grub_uint32_t fragment_size;
- grub_uint8_t fs_type;
- grub_uint8_t fs_fragments;
- grub_uint16_t fs_cylinders;
-} __attribute__ ((packed));
-
-/* The BSD disk label. Only define members useful for GRUB. */
-struct grub_partition_disk_label
-{
- grub_uint32_t magic;
- grub_uint8_t padding[128];
- grub_uint32_t magic2;
- grub_uint16_t checksum;
- grub_uint16_t num_partitions;
- grub_uint32_t boot_size;
- grub_uint32_t superblock_size;
- struct grub_partition_bsd_entry entries[GRUB_PARTITION_BSD_MAX_ENTRIES];
-} __attribute__ ((packed));
-
-/* The partition entry. */
-struct grub_partition_entry
-{
- /* If active, 0x80, otherwise, 0x00. */
- grub_uint8_t flag;
-
- /* The head of the start. */
- grub_uint8_t start_head;
-
- /* (S | ((C >> 2) & 0xC0)) where S is the sector of the start and C
- is the cylinder of the start. Note that S is counted from one. */
- grub_uint8_t start_sector;
-
- /* (C & 0xFF) where C is the cylinder of the start. */
- grub_uint8_t start_cylinder;
-
- /* The partition type. */
- grub_uint8_t type;
-
- /* The end versions of start_head, start_sector and start_cylinder,
- respectively. */
- grub_uint8_t end_head;
- grub_uint8_t end_sector;
- grub_uint8_t end_cylinder;
-
- /* The start sector. Note that this is counted from zero. */
- grub_uint32_t start;
-
- /* The length in sector units. */
- grub_uint32_t length;
-} __attribute__ ((packed));
-
-/* The structure of MBR. */
-struct grub_partition_mbr
-{
- /* The code area (actually, including BPB). */
- grub_uint8_t code[446];
-
- /* Four partition entries. */
- struct grub_partition_entry entries[4];
-
- /* The signature 0xaa55. */
- grub_uint16_t signature;
-} __attribute__ ((packed));
-
-/* Partition description. */
-struct grub_partition
-{
- /* The start sector. */
- unsigned long start;
-
- /* The length in sector units. */
- unsigned long len;
-
- /* The offset of the partition table. */
- unsigned long offset;
-
- /* The offset of the extended partition. */
- unsigned long ext_offset;
-
- /* The index of this partition in the partition table. */
- int index;
-
- /* The DOS partition number. */
- int dos_part;
-
- /* The BSD partition number (a == 0). */
- int bsd_part;
-
- /* The DOS partition type. */
- int dos_type;
-
- /* The BSD partition type. */
- int bsd_type;
-};
-typedef struct grub_partition *grub_partition_t;
-
-struct grub_disk;
-
-grub_partition_t EXPORT_FUNC(grub_partition_probe) (struct grub_disk *disk,
- const char *str);
-grub_err_t EXPORT_FUNC(grub_partition_iterate) (struct grub_disk *disk,
- int (*hook) (const grub_partition_t partition));
-char *EXPORT_FUNC(grub_partition_get_name) (const grub_partition_t partition);
-
-static inline unsigned long
-grub_partition_get_start (const grub_partition_t p)
-{
- return p->start;
-}
-
-static inline unsigned long
-grub_partition_get_len (const grub_partition_t p)
-{
- return p->len;
-}
-
-static inline int
-grub_partition_is_empty (int type)
-{
- return (type == GRUB_PARTITION_TYPE_NONE);
-}
-
-static inline int
-grub_partition_is_extended (int type)
-{
- return (type == GRUB_PARTITION_TYPE_EXTENDED
- || type == GRUB_PARTITION_TYPE_WIN95_EXTENDED
- || type == GRUB_PARTITION_TYPE_LINUX_EXTENDED);
-}
-
-static inline int
-grub_partition_is_bsd (int type)
-{
- return (type == GRUB_PARTITION_TYPE_FREEBSD
- || type == GRUB_PARTITION_TYPE_OPENBSD
- || type == GRUB_PARTITION_TYPE_NETBSD);
-}
-
-#endif /* ! GRUB_PARTITION_HEADER */
Index: include/grub/powerpc/ieee1275/partition.h
===================================================================
RCS file: include/grub/powerpc/ieee1275/partition.h
diff -N include/grub/powerpc/ieee1275/partition.h
--- include/grub/powerpc/ieee1275/partition.h 4 Apr 2004 13:46:01 -0000 1.2
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,140 +0,0 @@
-/*
- * GRUB -- GRand Unified Bootloader
- * Copyright (C) 1999,2000,2001,2002,2004 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 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef GRUB_PARTITION_HEADER
-#define GRUB_PARTITION_HEADER 1
-
-#include <grub/symbol.h>
-#include <grub/types.h>
-#include <grub/err.h>
-
-#define GRUB_APPLE_PART_MAGIC 0x504D
-
-struct grub_apple_part
-{
- /* The magic number to idenify this as a partition, it should have
- the value `0x504D'. */
- grub_uint16_t magic;
-
- /* Reserved. */
- grub_uint16_t reserved;
-
- /* The size of the partition map in blocks. */
- grub_uint32_t partmap_size;
-
- /* The first physical block of the partition. */
- grub_uint32_t first_phys_block;
-
- /* The amount of blocks. */
- grub_uint32_t blockcnt;
-
- /* The partition name. */
- char partname[32];
-
- /* The partition type. */
- char parttype[32];
-
- /* The first datablock of the partition. */
- grub_uint32_t datablocks_first;
-
- /* The amount datablocks. */
- grub_uint32_t datablocks_count;
-
- /* The status of the partition. (???) */
- grub_uint32_t status;
-
- /* The first block on which the bootcode can be found. */
- grub_uint32_t bootcode_pos;
-
- /* The size of the bootcode in bytes. */
- grub_uint32_t bootcode_size;
-
- /* The load address of the bootcode. */
- grub_uint32_t bootcode_loadaddr;
-
- /* Reserved. */
- grub_uint32_t reserved2;
-
- /* The entrypoint of the bootcode. */
- grub_uint32_t bootcode_entrypoint;
-
- /* Reserved. */
- grub_uint32_t reserved3;
-
- /* A checksum of the bootcode. */
- grub_uint32_t bootcode_checksum;
-
- /* The processor type. */
- char processor[16];
-
- /* Padding. */
- grub_uint16_t pad[187];
-};
-
-/* Partition description. */
-struct grub_partition
-{
- /* The start sector. */
- unsigned long start;
-
- /* The length in sector units. */
- unsigned long len;
-
- /* The offset of the partition table. */
- unsigned long offset;
-
- /* The index of this partition in the partition table. */
- int index;
-
- /* The DOS partition number. */
- int dos_part;
-
- /* The BSD partition number (a == 0). */
- int bsd_part;
-
- /* The DOS partition type. */
- int dos_type;
-
- /* The BSD partition type. */
- int bsd_type;
-};
-typedef struct grub_partition *grub_partition_t;
-
-struct grub_disk;
-
-grub_partition_t EXPORT_FUNC(grub_partition_probe) (struct grub_disk *disk,
- const char *str);
-grub_err_t EXPORT_FUNC(grub_partition_iterate) (struct grub_disk *disk,
- int (*hook) (const grub_partition_t partition));
-char *EXPORT_FUNC(grub_partition_get_name) (const grub_partition_t partition);
-
-\f
-static inline unsigned long
-grub_partition_get_start (const grub_partition_t p)
-{
- return p->start;
-}
-
-static inline unsigned long
-grub_partition_get_len (const grub_partition_t p)
-{
- return p->len;
-}
-
-#endif /* ! GRUB_PARTITION_HEADER */
Index: kern/disk.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/disk.c,v
retrieving revision 1.8
diff -u -p -u -p -r1.8 disk.c
--- kern/disk.c 21 Aug 2004 13:54:22 -0000 1.8
+++ kern/disk.c 24 Nov 2004 19:02:48 -0000
@@ -21,7 +21,7 @@
#include <grub/err.h>
#include <grub/mm.h>
#include <grub/types.h>
-#include <grub/machine/partition.h>
+#include <grub/partition.h>
#include <grub/misc.h>
#include <grub/machine/time.h>
#include <grub/file.h>
Index: kern/partition.c
===================================================================
RCS file: kern/partition.c
diff -N kern/partition.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ kern/partition.c 24 Nov 2004 19:02:48 -0000
@@ -0,0 +1,95 @@
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2004 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <grub/partition.h>
+#include <grub/disk.h>
+
+static grub_partition_map_t grub_partition_map_list;
+
+void
+grub_partition_map_register (grub_partition_map_t partmap)
+{
+ partmap->next = grub_partition_map_list;
+ grub_partition_map_list = partmap;
+}
+
+void
+grub_partition_map_unregister (grub_partition_map_t partmap)
+{
+ grub_partition_map_t *p, q;
+
+ for (p = &grub_partition_map_list, q = *p; q; p = &(q->next), q = q->next)
+ if (q == partmap)
+ {
+ *p = q->next;
+ break;
+ }
+}
+
+void
+grub_partition_map_iterate (int (*hook) (const grub_partition_map_t partmap))
+{
+ grub_partition_map_t p;
+
+ for (p = grub_partition_map_list; p; p = p->next)
+ if (hook (p))
+ break;
+}
+
+grub_partition_t
+grub_partition_probe (struct grub_disk *disk, const char *str)
+{
+ grub_partition_t part;
+
+ auto int part_map_probe (const grub_partition_map_t partmap);
+
+ int part_map_probe (const grub_partition_map_t partmap)
+ {
+ part = partmap->probe (disk, str);
+ if (part)
+ return 1;
+ return 0;
+ }
+
+ /* Use the first partition map type found. */
+ grub_partition_map_iterate (part_map_probe);
+
+ return part;
+}
+
+grub_err_t
+grub_partition_iterate (struct grub_disk *disk,
+ int (*hook) (const grub_partition_t partition))
+{
+ auto int part_map_iterate (const grub_partition_map_t partmap);
+
+ int part_map_iterate (const grub_partition_map_t partmap)
+ {
+ return partmap->iterate (disk, hook);
+ }
+
+ grub_partition_map_iterate (part_map_iterate);
+ return grub_errno;
+}
+
+char *
+grub_partition_get_name (const grub_partition_t partition)
+{
+ return partition->partmap->get_name (partition);
+}
Index: kern/rescue.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/rescue.c,v
retrieving revision 1.10
diff -u -p -u -p -r1.10 rescue.c
--- kern/rescue.c 22 Sep 2004 18:26:16 -0000 1.10
+++ kern/rescue.c 24 Nov 2004 19:02:48 -0000
@@ -28,7 +28,7 @@
#include <grub/err.h>
#include <grub/loader.h>
#include <grub/dl.h>
-#include <grub/machine/partition.h>
+#include <grub/partition.h>
#include <grub/env.h>
#define GRUB_RESCUE_BUF_SIZE 256
Index: kern/powerpc/ieee1275/init.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/powerpc/ieee1275/init.c,v
retrieving revision 1.8
diff -u -p -u -p -r1.8 init.c
--- kern/powerpc/ieee1275/init.c 16 Nov 2004 23:34:44 -0000 1.8
+++ kern/powerpc/ieee1275/init.c 24 Nov 2004 19:02:48 -0000
@@ -22,7 +22,7 @@
#include <grub/dl.h>
#include <grub/disk.h>
#include <grub/mm.h>
-#include <grub/machine/partition.h>
+#include <grub/partition.h>
#include <grub/machine/ieee1275.h>
#include <grub/normal.h>
#include <grub/fs.h>
@@ -78,6 +78,9 @@ grub_machine_init (void)
grub_boot_init ();
grub_linux_init ();
grub_linux_normal_init ();
+ grub_pc_partition_map_init ();
+ grub_amiga_partition_map_init ();
+ grub_apple_partition_map_init ();
grub_ofdisk_init ();
}
Index: loader/i386/pc/chainloader.c
===================================================================
RCS file: /cvsroot/grub/grub2/loader/i386/pc/chainloader.c,v
retrieving revision 1.7
diff -u -p -u -p -r1.7 chainloader.c
--- loader/i386/pc/chainloader.c 12 Sep 2004 12:20:52 -0000 1.7
+++ loader/i386/pc/chainloader.c 24 Nov 2004 19:02:48 -0000
@@ -28,7 +28,7 @@
#include <grub/misc.h>
#include <grub/types.h>
#include <grub/machine/init.h>
-#include <grub/machine/partition.h>
+#include <grub/partition.h>
#include <grub/machine/memory.h>
#include <grub/rescue.h>
#include <grub/dl.h>
Index: normal/cmdline.c
===================================================================
RCS file: /cvsroot/grub/grub2/normal/cmdline.c,v
retrieving revision 1.8
diff -u -p -u -p -r1.8 cmdline.c
--- normal/cmdline.c 27 Jun 2004 11:03:24 -0000 1.8
+++ normal/cmdline.c 24 Nov 2004 19:02:48 -0000
@@ -23,7 +23,7 @@
#include <grub/err.h>
#include <grub/types.h>
#include <grub/mm.h>
-#include <grub/machine/partition.h>
+#include <grub/partition.h>
#include <grub/disk.h>
#include <grub/file.h>
#include <grub/env.h>
Index: partmap/amiga.c
===================================================================
RCS file: partmap/amiga.c
diff -N partmap/amiga.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ partmap/amiga.c 24 Nov 2004 19:02:48 -0000
@@ -0,0 +1,229 @@
+/* amiga.c - Read amiga partition tables (RDB). */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2004 Free Software Foundation, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <grub/disk.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+#include <grub/partition.h>
+#include <grub/dl.h>
+
+struct grub_amiga_rdsk
+{
+ /* "RDSK". */
+ grub_uint8_t magic[4];
+ grub_uint32_t size;
+ grub_int32_t checksum;
+ grub_uint32_t scsihost;
+ grub_uint32_t blksz;
+ grub_uint32_t flags;
+ grub_uint32_t badblcklst;
+ grub_uint32_t partitionlst;
+ grub_uint32_t fslst;
+
+ /* The other information is not important for us. */
+} __attribute__ ((packed));
+
+struct grub_amiga_partition
+{
+ /* "PART". */
+ grub_uint8_t magic[4];
+ grub_int32_t size;
+ grub_int32_t checksum;
+ grub_uint32_t scsihost;
+ grub_uint32_t next;
+ grub_uint32_t flags;
+ grub_uint32_t unused1[2];
+ grub_uint32_t devflags;
+ grub_uint8_t namelen;
+ grub_uint8_t name[31];
+ grub_uint32_t unused2[15];
+
+ grub_uint32_t unused3[3];
+ grub_uint32_t heads;
+ grub_uint32_t unused4;
+ grub_uint32_t block_per_track;
+ grub_uint32_t unused5[3];
+ grub_uint32_t lowcyl;
+ grub_uint32_t highcyl;
+
+ grub_uint32_t firstcyl;
+} __attribute__ ((packed));
+
+static struct grub_partition_map grub_amiga_partition_map;
+
+#ifndef GRUB_UTIL
+static grub_dl_t my_mod;
+#endif
+\f
+static grub_err_t
+amiga_partition_map_iterate (grub_disk_t disk,
+ int (*hook) (const grub_partition_t partition))
+{
+ struct grub_partition part;
+ struct grub_amiga_rdsk rdsk;
+ struct grub_disk raw;
+ int partno = 0;
+ int next = -1;
+ int pos;
+
+ /* Enforce raw disk access. */
+ raw = *disk;
+ raw.partition = 0;
+
+ /* The RDSK block is one of the first 15 blocks. */
+ for (pos = 0; pos < 15; pos++)
+ {
+ /* Read the RDSK block which is a descriptor for the entire disk. */
+ if (grub_disk_read (&raw, pos, 0,
+ sizeof (rdsk), (char *) &rdsk))
+ return grub_errno;
+
+ if (!grub_strcmp (rdsk.magic, "RDSK"))
+ {
+ /* Found the first PART block. */
+ next = grub_be_to_cpu32 (rdsk.partitionlst);
+ break;
+ }
+ }
+
+ /* The end of the partition list is marked using "-1". */
+ while (next != -1)
+ {
+ struct grub_amiga_partition apart;
+
+ /* Read the RDSK block which is a descriptor for the entire disk. */
+ if (grub_disk_read (&raw, next, 0,
+ sizeof (apart), (char *) &apart))
+ return grub_errno;
+
+ /* Calculate the first block and the size of the partition. */
+ part.start = (grub_be_to_cpu32 (apart.lowcyl)
+ * grub_be_to_cpu32 (apart.heads)
+ * grub_be_to_cpu32 (apart.block_per_track));
+ part.len = ((grub_be_to_cpu32 (apart.highcyl)
+ - grub_be_to_cpu32 (apart.lowcyl) + 1)
+ * grub_be_to_cpu32 (apart.heads)
+ * grub_be_to_cpu32 (apart.block_per_track));
+
+ part.offset = next * 512;
+ part.index = partno;
+ part.partmap = &grub_amiga_partition_map;
+
+ if (hook (&part))
+ return grub_errno;
+
+ next = grub_be_to_cpu32 (apart.next);
+ partno++;
+ }
+
+ return 0;
+}
+
+
+static grub_partition_t
+amiga_partition_map_probe (grub_disk_t disk, const char *str)
+{
+ grub_partition_t p = 0;
+ int partnum = 0;
+ char *s = (char *) str;
+
+ auto int find_func (const grub_partition_t partition);
+
+ int find_func (const grub_partition_t partition)
+ {
+ if (partnum == partition->index)
+ {
+ p = (grub_partition_t) grub_malloc (sizeof (*p));
+ if (! p)
+ return 1;
+
+ grub_memcpy (p, partition, sizeof (*p));
+ return 1;
+ }
+
+ return 0;
+ }
+
+ /* Get the partition number. */
+ partnum = grub_strtoul (s, 0, 10);
+ if (grub_errno)
+ {
+ grub_error (GRUB_ERR_BAD_FILENAME, "invalid partition");
+ return 0;
+ }
+
+ if (amiga_partition_map_iterate (disk, find_func))
+ goto fail;
+
+ return p;
+
+ fail:
+ grub_free (p);
+ return 0;
+}
+
+
+static char *
+amiga_partition_map_get_name (const grub_partition_t p)
+{
+ char *name;
+
+ name = grub_malloc (13);
+ if (! name)
+ return 0;
+
+ grub_sprintf (name, "%d", p->index);
+ return name;
+}
+
+\f
+/* Partition map type. */
+static struct grub_partition_map grub_amiga_partition_map =
+ {
+ .name = "amiga_partition_map",
+ .iterate = amiga_partition_map_iterate,
+ .probe = amiga_partition_map_probe,
+ .get_name = amiga_partition_map_get_name
+ };
+
+#ifdef GRUB_UTIL
+void
+grub_amiga_partition_map_init (void)
+{
+ grub_partition_map_register (&grub_amiga_partition_map);
+}
+
+void
+grub_amiga_partition_map_fini (void)
+{
+ grub_partition_map_unregister (&grub_amiga_partition_map);
+}
+#else
+GRUB_MOD_INIT
+{
+ grub_partition_map_register (&grub_amiga_partition_map);
+ my_mod = mod;
+}
+
+GRUB_MOD_FINI
+{
+ grub_partition_map_unregister (&grub_amiga_partition_map);
+}
+#endif
Index: partmap/apple.c
===================================================================
RCS file: partmap/apple.c
diff -N partmap/apple.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ partmap/apple.c 24 Nov 2004 19:02:48 -0000
@@ -0,0 +1,231 @@
+/* apple.c - Read macintosh partition tables. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2004 Free Software Foundation, Inc.
+ *
+ * This program 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <grub/disk.h>
+#include <grub/misc.h>
+#include <grub/mm.h>
+#include <grub/partition.h>
+
+#define GRUB_APPLE_PART_MAGIC 0x504D
+
+struct grub_apple_part
+{
+ /* The magic number to idenify this as a partition, it should have
+ the value `0x504D'. */
+ grub_uint16_t magic;
+
+ /* Reserved. */
+ grub_uint16_t reserved;
+
+ /* The size of the partition map in blocks. */
+ grub_uint32_t partmap_size;
+
+ /* The first physical block of the partition. */
+ grub_uint32_t first_phys_block;
+
+ /* The amount of blocks. */
+ grub_uint32_t blockcnt;
+
+ /* The partition name. */
+ char partname[32];
+
+ /* The partition type. */
+ char parttype[32];
+
+ /* The first datablock of the partition. */
+ grub_uint32_t datablocks_first;
+
+ /* The amount datablocks. */
+ grub_uint32_t datablocks_count;
+
+ /* The status of the partition. (???) */
+ grub_uint32_t status;
+
+ /* The first block on which the bootcode can be found. */
+ grub_uint32_t bootcode_pos;
+
+ /* The size of the bootcode in bytes. */
+ grub_uint32_t bootcode_size;
+
+ /* The load address of the bootcode. */
+ grub_uint32_t bootcode_loadaddr;
+
+ /* Reserved. */
+ grub_uint32_t reserved2;
+
+ /* The entrypoint of the bootcode. */
+ grub_uint32_t bootcode_entrypoint;
+
+ /* Reserved. */
+ grub_uint32_t reserved3;
+
+ /* A checksum of the bootcode. */
+ grub_uint32_t bootcode_checksum;
+
+ /* The processor type. */
+ char processor[16];
+
+ /* Padding. */
+ grub_uint16_t pad[187];
+};
+
+static struct grub_partition_map grub_apple_partition_map;
+
+#ifndef GRUB_UTIL
+static grub_dl_t my_mod;
+#endif
+\f
+
+static grub_err_t
+apple_partition_map_iterate (grub_disk_t disk,
+ int (*hook) (const grub_partition_t partition))
+{
+ struct grub_partition part;
+ struct grub_apple_part apart;
+ struct grub_disk raw;
+ int partno = 0;
+ int pos = GRUB_DISK_SECTOR_SIZE;
+
+ /* Enforce raw disk access. */
+ raw = *disk;
+ raw.partition = 0;
+
+ part.partmap = &grub_apple_partition_map;
+
+ for (;;)
+ {
+ if (grub_disk_read (&raw, pos / GRUB_DISK_SECTOR_SIZE,
+ pos % GRUB_DISK_SECTOR_SIZE,
+ sizeof (struct grub_apple_part), (char *) &apart))
+ return grub_errno;
+
+ if (apart.magic != GRUB_APPLE_PART_MAGIC)
+ break;
+
+ part.start = apart.first_phys_block;
+ part.len = apart.blockcnt;
+ part.offset = pos;
+ part.index = partno;
+
+ if (hook (&part))
+ return grub_errno;
+
+ if (apart.first_phys_block == GRUB_DISK_SECTOR_SIZE * 2)
+ return 0;
+
+ pos += sizeof (struct grub_apple_part);
+ partno++;
+ }
+
+ return 0;
+}
+
+
+static grub_partition_t
+apple_partition_map_probe (grub_disk_t disk, const char *str)
+{
+ grub_partition_t p = 0;
+ int partnum = 0;
+ char *s = (char *) str;
+
+ auto int find_func (const grub_partition_t partition);
+
+ int find_func (const grub_partition_t partition)
+ {
+ if (partnum == partition->index)
+ {
+ p = (grub_partition_t) grub_malloc (sizeof (*p));
+ if (! p)
+ return 1;
+
+ grub_memcpy (p, partition, sizeof (*p));
+ return 1;
+ }
+
+ return 0;
+ }
+
+ /* Get the partition number. */
+ partnum = grub_strtoul (s, 0, 10);
+ if (grub_errno)
+ {
+ grub_error (GRUB_ERR_BAD_FILENAME, "invalid partition");
+ return 0;
+ }
+
+ if (apple_partition_map_iterate (disk, find_func))
+ goto fail;
+
+ return p;
+
+ fail:
+ grub_free (p);
+ return 0;
+
+}
+
+
+static char *
+apple_partition_map_get_name (const grub_partition_t p)
+{
+ char *name;
+
+ name = grub_malloc (13);
+ if (! name)
+ return 0;
+
+ grub_sprintf (name, "%d", p->index);
+ return name;
+}
+
+\f
+/* Partition map type. */
+static struct grub_partition_map grub_apple_partition_map =
+ {
+ .name = "apple_partition_map",
+ .iterate = apple_partition_map_iterate,
+ .probe = apple_partition_map_probe,
+ .get_name = apple_partition_map_get_name
+ };
+
+#ifdef GRUB_UTIL
+void
+grub_apple_partition_map_init (void)
+{
+ grub_partition_map_register (&grub_apple_partition_map);
+}
+
+void
+grub_apple_partition_map_fini (void)
+{
+ grub_partition_map_unregister (&grub_apple_partition_map);
+}
+#else
+GRUB_MOD_INIT
+{
+ grub_partition_map_register (&grub_apple_partition_map);
+ my_mod = mod;
+}
+
+GRUB_MOD_FINI
+{
+ grub_partition_map_unregister (&grub_apple_partition_map);
+}
+#endif
Index: partmap/pc.c
===================================================================
RCS file: partmap/pc.c
diff -N partmap/pc.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ partmap/pc.c 24 Nov 2004 19:02:48 -0000
@@ -0,0 +1,314 @@
+/* pc.c - Read PC style partition tables. */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2002, 2004 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 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <grub/partition.h>
+#include <grub/pc_partition.h>
+#include <grub/disk.h>
+#include <grub/mm.h>
+#include <grub/misc.h>
+#include <grub/dl.h>
+
+static struct grub_partition_map grub_pc_partition_map;
+
+#ifndef GRUB_UTIL
+static grub_dl_t my_mod;
+#endif
+\f
+
+/* Parse the partition representation in STR and return a partition. */
+static grub_partition_t
+grub_partition_parse (const char *str)
+{
+ grub_partition_t p;
+ struct grub_pc_partition *pcdata;
+
+ char *s = (char *) str;
+
+ p = (grub_partition_t) grub_malloc (sizeof (*p));
+ if (! p)
+ return 0;
+
+ pcdata = (struct grub_pc_partition *) grub_malloc (sizeof (*pcdata));
+ if (! pcdata)
+ goto fail;
+
+ p->data = pcdata;
+ p->partmap = &grub_pc_partition_map;
+
+ /* Initialize some of the fields with invalid values. */
+ pcdata->bsd_part = pcdata->dos_type = pcdata->bsd_type = p->index = -1;
+
+ /* Get the DOS partition number. */
+ pcdata->dos_part = grub_strtoul (s, &s, 0);
+
+ if (grub_errno)
+ {
+ /* Not found. Maybe only a BSD label is specified. */
+ pcdata->dos_part = -1;
+ grub_errno = GRUB_ERR_NONE;
+ }
+ else if (*s == ',')
+ s++;
+
+ if (*s)
+ {
+ if (*s >= 'a' && *s <= 'h')
+ {
+ pcdata->bsd_part = *s - 'a';
+ s++;
+ }
+
+ if (*s)
+ goto fail;
+ }
+
+ if (pcdata->dos_part == -1 && pcdata->bsd_part == -1)
+ goto fail;
+
+ return p;
+
+ fail:
+ grub_free (p);
+ grub_free (pcdata);
+ grub_error (GRUB_ERR_BAD_FILENAME, "invalid partition");
+ return 0;
+}
+
+static grub_err_t
+pc_partition_map_iterate (grub_disk_t disk,
+ int (*hook) (const grub_partition_t partition))
+{
+ struct grub_partition p;
+ struct grub_pc_partition pcdata;
+ struct grub_pc_partition_mbr mbr;
+ struct grub_pc_partition_disk_label label;
+ struct grub_disk raw;
+
+ /* Enforce raw disk access. */
+ raw = *disk;
+ raw.partition = 0;
+
+ p.offset = 0;
+ pcdata.ext_offset = 0;
+ pcdata.dos_part = -1;
+ p.data = &pcdata;
+ p.partmap = &grub_pc_partition_map;
+
+ while (1)
+ {
+ int i;
+ struct grub_pc_partition_entry *e;
+
+ /* Read the MBR. */
+ if (grub_disk_read (&raw, p.offset, 0, sizeof (mbr), (char *) &mbr))
+ goto finish;
+
+ /* Check if it is valid. */
+ if (mbr.signature != grub_cpu_to_le16 (GRUB_PC_PARTITION_SIGNATURE))
+ return grub_error (GRUB_ERR_BAD_PART_TABLE, "no signature");
+
+ /* Analyze DOS partitions. */
+ for (p.index = 0; p.index < 4; p.index++)
+ {
+ e = mbr.entries + p.index;
+
+ p.start = p.offset + grub_le_to_cpu32 (e->start);
+ p.len = grub_le_to_cpu32 (e->length);
+ pcdata.bsd_part = -1;
+ pcdata.dos_type = e->type;
+ pcdata.bsd_type = -1;
+
+ /* If this partition is a normal one, call the hook. */
+ if (! grub_pc_partition_is_empty (e->type)
+ && ! grub_pc_partition_is_extended (e->type))
+ {
+ pcdata.dos_part++;
+
+ if (hook (&p))
+ goto finish;
+
+ /* Check if this is a BSD partition. */
+ if (grub_pc_partition_is_bsd (e->type))
+ {
+ /* Check if the BSD label is within the DOS partition. */
+ if (p.len <= GRUB_PC_PARTITION_BSD_LABEL_SECTOR)
+ return grub_error (GRUB_ERR_BAD_PART_TABLE,
+ "no space for disk label");
+
+ /* Read the BSD label. */
+ if (grub_disk_read (&raw,
+ (p.start
+ + GRUB_PC_PARTITION_BSD_LABEL_SECTOR),
+ 0,
+ sizeof (label),
+ (char *) &label))
+ goto finish;
+
+ /* Check if it is valid. */
+ if (label.magic
+ != grub_cpu_to_le32 (GRUB_PC_PARTITION_BSD_LABEL_MAGIC))
+ return grub_error (GRUB_ERR_BAD_PART_TABLE,
+ "invalid disk label magic");
+
+ for (pcdata.bsd_part = 0;
+ pcdata.bsd_part < grub_cpu_to_le16 (label.num_partitions);
+ pcdata.bsd_part++)
+ {
+ struct grub_pc_partition_bsd_entry *be
+ = label.entries + pcdata.bsd_part;
+
+ p.start = grub_le_to_cpu32 (be->offset);
+ p.len = grub_le_to_cpu32 (be->size);
+ pcdata.bsd_type = be->fs_type;
+
+ if (be->fs_type != GRUB_PC_PARTITION_BSD_TYPE_UNUSED)
+ if (hook (&p))
+ goto finish;
+ }
+ }
+ }
+ else if (pcdata.dos_part < 4)
+ /* If this partition is a logical one, shouldn't increase the
+ partition number. */
+ pcdata.dos_part++;
+ }
+
+ /* Find an extended partition. */
+ for (i = 0; i < 4; i++)
+ {
+ e = mbr.entries + i;
+
+ if (grub_pc_partition_is_extended (e->type))
+ {
+ p.offset = pcdata.ext_offset + grub_le_to_cpu32 (e->start);
+ if (! pcdata.ext_offset)
+ pcdata.ext_offset = p.offset;
+
+ break;
+ }
+ }
+
+ /* If no extended partition, the end. */
+ if (i == 4)
+ break;
+ }
+
+ finish:
+ return grub_errno;
+}
+
+
+static grub_partition_t
+pc_partition_map_probe (grub_disk_t disk, const char *str)
+{
+ grub_partition_t p;
+ struct grub_pc_partition *pcdata;
+
+ auto int find_func (const grub_partition_t partition);
+
+ int find_func (const grub_partition_t partition)
+ {
+ struct grub_pc_partition *partdata = partition->data;
+ if ((pcdata->dos_part == partdata->dos_part || pcdata->dos_part == -1)
+ && pcdata->bsd_part == partdata->bsd_part)
+ {
+ grub_memcpy (p, partition, sizeof (*p));
+ grub_memcpy (pcdata, partdata, sizeof (*pcdata));
+ return 1;
+ }
+
+ return 0;
+ }
+
+ p = grub_partition_parse (str);
+ if (! p)
+ return 0;
+
+ pcdata = p->data;
+ if (pc_partition_map_iterate (disk, find_func))
+ goto fail;
+
+ if (p->index < 0)
+ {
+ grub_error (GRUB_ERR_BAD_DEVICE, "no such partition");
+ goto fail;
+ }
+
+ return p;
+
+ fail:
+ grub_free (p);
+ grub_free (pcdata);
+ return 0;
+}
+
+
+static char *
+pc_partition_map_get_name (const grub_partition_t p)
+{
+ char *name;
+ struct grub_pc_partition *pcdata = p->data;
+
+ name = grub_malloc (13);
+ if (! name)
+ return 0;
+
+ if (pcdata->bsd_part < 0)
+ grub_sprintf (name, "%d", pcdata->dos_part);
+ else
+ grub_sprintf (name, "%d,%c", pcdata->dos_part, pcdata->bsd_part + 'a');
+
+ return name;
+}
+
+\f
+/* Partition map type. */
+static struct grub_partition_map grub_pc_partition_map =
+ {
+ .name = "pc_partition_map",
+ .iterate = pc_partition_map_iterate,
+ .probe = pc_partition_map_probe,
+ .get_name = pc_partition_map_get_name
+ };
+
+#ifdef GRUB_UTIL
+void
+grub_pc_partition_map_init (void)
+{
+ grub_partition_map_register (&grub_pc_partition_map);
+}
+
+void
+grub_pc_partition_map_fini (void)
+{
+ grub_partition_map_unregister (&grub_pc_partition_map);
+}
+#else
+GRUB_MOD_INIT
+{
+ grub_partition_map_register (&grub_pc_partition_map);
+ my_mod = mod;
+}
+
+GRUB_MOD_FINI
+{
+ grub_partition_map_unregister (&grub_pc_partition_map);
+}
+#endif
Index: util/grub-emu.c
===================================================================
RCS file: /cvsroot/grub/grub2/util/grub-emu.c,v
retrieving revision 1.8
diff -u -p -u -p -r1.8 grub-emu.c
--- util/grub-emu.c 1 Nov 2004 16:14:16 -0000 1.8
+++ util/grub-emu.c 24 Nov 2004 19:02:49 -0000
@@ -34,6 +34,7 @@
#include <grub/normal.h>
#include <grub/util/getroot.h>
#include <grub/env.h>
+#include <grub/partition.h>
#ifdef __NetBSD__
/* NetBSD uses /boot for its boot block. */
@@ -154,6 +155,9 @@ main (int argc, char *argv[])
/* XXX: This is a bit unportable. */
grub_util_biosdisk_init (args.dev_map);
+ grub_pc_partition_map_init ();
+ grub_amiga_partition_map_init ();
+ grub_apple_partition_map_init ();
/* Initialize the default modules. */
grub_iso9660_init ();
@@ -187,6 +191,9 @@ main (int argc, char *argv[])
grub_cmp_fini ();
grub_cat_fini ();
grub_terminal_fini ();
-
+ grub_amiga_partition_map_fini ();
+ grub_pc_partition_map_fini ();
+ grub_apple_partition_map_fini ();
+
return 0;
}
Index: util/i386/pc/biosdisk.c
===================================================================
RCS file: /cvsroot/grub/grub2/util/i386/pc/biosdisk.c,v
retrieving revision 1.8
diff -u -p -u -p -r1.8 biosdisk.c
--- util/i386/pc/biosdisk.c 21 Aug 2004 13:54:22 -0000 1.8
+++ util/i386/pc/biosdisk.c 24 Nov 2004 19:02:49 -0000
@@ -20,7 +20,8 @@
#include <grub/machine/biosdisk.h>
#include <grub/disk.h>
-#include <grub/machine/partition.h>
+#include <grub/partition.h>
+#include <grub/pc_partition.h>
#include <grub/types.h>
#include <grub/err.h>
#include <grub/util/misc.h>
@@ -736,18 +737,34 @@ grub_util_biosdisk_get_grub_dev (const c
int find_partition (const grub_partition_t partition)
{
- if (partition->bsd_part < 0)
- grub_util_info ("DOS partition %d starts from %lu",
- partition->dos_part, partition->start);
- else
- grub_util_info ("BSD partition %d,%c starts from %lu",
- partition->dos_part, partition->bsd_part + 'a',
- partition->start);
+ struct grub_pc_partition *pcdata = 0;
+
+ if (!strcmp (partition->partmap->name, "pc"))
+ pcdata = partition->data;
+
+ if (pcdata)
+ {
+ if (pcdata->bsd_part < 0)
+ grub_util_info ("DOS partition %d starts from %lu",
+ pcdata->dos_part, partition->start);
+ else
+ grub_util_info ("BSD partition %d,%c starts from %lu",
+ pcdata->dos_part, pcdata->bsd_part + 'a',
+ partition->start);
+ }
if (hdg.start == partition->start)
{
- dos_part = partition->dos_part;
- bsd_part = partition->bsd_part;
+ if (pcdata)
+ {
+ dos_part = pcdata->dos_part;
+ bsd_part = pcdata->bsd_part;
+ }
+ else
+ {
+ dos_part = 0;
+ bsd_part = 0;
+ }
return 1;
}
Index: util/i386/pc/grub-setup.c
===================================================================
RCS file: /cvsroot/grub/grub2/util/i386/pc/grub-setup.c,v
retrieving revision 1.8
diff -u -p -u -p -r1.8 grub-setup.c
--- util/i386/pc/grub-setup.c 4 Apr 2004 13:46:03 -0000 1.8
+++ util/i386/pc/grub-setup.c 24 Nov 2004 19:02:49 -0000
@@ -25,7 +25,8 @@
#include <grub/disk.h>
#include <grub/file.h>
#include <grub/fs.h>
-#include <grub/machine/partition.h>
+#include <grub/partition.h>
+#include <grub/pc_partition.h>
#include <grub/machine/util/biosdisk.h>
#include <grub/machine/boot.h>
#include <grub/machine/kernel.h>
@@ -107,8 +108,10 @@ setup (const char *prefix, const char *d
int find_first_partition_start (const grub_partition_t p)
{
- if (! grub_partition_is_empty (p->dos_type)
- && ! grub_partition_is_bsd (p->dos_type)
+ struct grub_pc_partition *pcdata = p->data;
+
+ if (! grub_pc_partition_is_empty (pcdata->dos_type)
+ && ! grub_pc_partition_is_bsd (pcdata->dos_type)
&& first_start > p->start)
first_start = p->start;
@@ -252,10 +255,16 @@ setup (const char *prefix, const char *d
/* Embed information about the installed location. */
if (root_dev->disk->partition)
{
+ struct grub_pc_partition *pcdata =
+ root_dev->disk->partition->data;
+
+ if (strcmp (root_dev->disk->partition->partmap->name, "pc"))
+ grub_util_error ("No PC style partitions found");
+
*install_dos_part
- = grub_cpu_to_le32 (root_dev->disk->partition->dos_part);
+ = grub_cpu_to_le32 (pcdata->dos_part);
*install_bsd_part
- = grub_cpu_to_le32 (root_dev->disk->partition->bsd_part);
+ = grub_cpu_to_le32 (pcdata->bsd_part);
}
else
*install_dos_part = *install_bsd_part = grub_cpu_to_le32 (-1);
@@ -400,10 +409,16 @@ setup (const char *prefix, const char *d
/* Embed information about the installed location. */
if (root_dev->disk->partition)
{
+ struct grub_pc_partition *pcdata =
+ root_dev->disk->partition->data;
+
+ if (strcmp (root_dev->disk->partition->partmap->name, "pc"))
+ grub_util_error ("No PC style partitions found");
+
*install_dos_part
- = grub_cpu_to_le32 (root_dev->disk->partition->dos_part);
+ = grub_cpu_to_le32 (pcdata->dos_part);
*install_bsd_part
- = grub_cpu_to_le32 (root_dev->disk->partition->bsd_part);
+ = grub_cpu_to_le32 (pcdata->bsd_part);
}
else
*install_dos_part = *install_bsd_part = grub_cpu_to_le32 (-1);
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Partition modules
2004-11-24 19:15 ` Marco Gerards
@ 2004-11-30 17:55 ` Marco Gerards
2004-12-03 17:18 ` Yoshinori K. Okuji
0 siblings, 1 reply; 19+ messages in thread
From: Marco Gerards @ 2004-11-30 17:55 UTC (permalink / raw)
To: The development of GRUB 2
Marco Gerards <metgerards@student.han.nl> writes:
> Marco Gerards <metgerards@student.han.nl> writes:
>
>> Here is a patch to modulize partition support. At the moment it will
>> create pc.mod, amiga.mod and apple.mod. Loading one of these modules
>> will give support for that specific partition map.
>
> And here is version 2 of the patch. I have made the requested
> changes.
[...]
> Can I check in this patch?
Until now no-one replied. I will apply this patch next Thursday if no
one reports a problem with it.
Thanks,
Marco
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Partition modules
2004-11-30 17:55 ` Marco Gerards
@ 2004-12-03 17:18 ` Yoshinori K. Okuji
2004-12-04 15:39 ` Marco Gerards
0 siblings, 1 reply; 19+ messages in thread
From: Yoshinori K. Okuji @ 2004-12-03 17:18 UTC (permalink / raw)
To: The development of GRUB 2
On Tuesday 30 November 2004 18:55, Marco Gerards wrote:
> Until now no-one replied. I will apply this patch next Thursday if
> no one reports a problem with it.
Sorry. I just forgot to reply. Your patch is ok for me.
Okuji
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Partition modules
2004-12-03 17:18 ` Yoshinori K. Okuji
@ 2004-12-04 15:39 ` Marco Gerards
2004-12-04 17:03 ` Yoshinori K. Okuji
[not found] ` <200412041230.17136.mjflick@gnu.org>
0 siblings, 2 replies; 19+ messages in thread
From: Marco Gerards @ 2004-12-04 15:39 UTC (permalink / raw)
To: The development of GRUB 2; +Cc: savannah-hackers
"Yoshinori K. Okuji" <okuji@enbug.org> writes:
> On Tuesday 30 November 2004 18:55, Marco Gerards wrote:
>> Until now no-one replied. I will apply this patch next Thursday if
>> no one reports a problem with it.
>
> Sorry. I just forgot to reply. Your patch is ok for me.
For some reason I can not commit this patch. I get the following
message:
cvs commit: [15:39:54] waiting for uid65534's lock in /cvsroot/grub/grub2/disk/powerpc/ieee1275
Can someone please help me with this problem?
Thanks,
Marco
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Partition modules
2004-12-04 15:39 ` Marco Gerards
@ 2004-12-04 17:03 ` Yoshinori K. Okuji
[not found] ` <200412041230.17136.mjflick@gnu.org>
1 sibling, 0 replies; 19+ messages in thread
From: Yoshinori K. Okuji @ 2004-12-04 17:03 UTC (permalink / raw)
To: The development of GRUB 2
On Saturday 04 December 2004 16:39, Marco Gerards wrote:
> For some reason I can not commit this patch. I get the following
> message:
>
> cvs commit: [15:39:54] waiting for uid65534's lock in
> /cvsroot/grub/grub2/disk/powerpc/ieee1275
>
> Can someone please help me with this problem?
It is a so-called cvs lock. Ask savannah-hackers.
Okuji
^ permalink raw reply [flat|nested] 19+ messages in thread
* Re: Partition modules
[not found] ` <200412041230.17136.mjflick@gnu.org>
@ 2004-12-04 18:41 ` Marco Gerards
0 siblings, 0 replies; 19+ messages in thread
From: Marco Gerards @ 2004-12-04 18:41 UTC (permalink / raw)
To: Michael J. Flickinger; +Cc: The development of GRUB 2, savannah-hackers
"Michael J. Flickinger" <mjflick@gnu.org> writes:
>> cvs commit: [15:39:54] waiting for uid65534's lock in
>> /cvsroot/grub/grub2/disk/powerpc/ieee1275
>>
>> Can someone please help me with this problem?
>>
> This should be fixed now.
It is, thanks a lot. The patch is applied now.
Thanks,
Marco
^ permalink raw reply [flat|nested] 19+ messages in thread
end of thread, other threads:[~2004-12-04 19:08 UTC | newest]
Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-11-17 19:25 Partition modules Marco Gerards
2004-11-18 3:50 ` Hollis Blanchard
2004-11-18 5:09 ` Hollis Blanchard
2004-11-18 8:13 ` Marco Gerards
2004-11-18 8:16 ` Marco Gerards
2004-11-18 9:32 ` Yoshinori K. Okuji
2004-11-18 10:46 ` Marco Gerards
2004-11-18 11:20 ` Yoshinori K. Okuji
2004-11-18 13:58 ` Marco Gerards
2004-11-18 9:28 ` Yoshinori K. Okuji
2004-11-18 10:40 ` Marco Gerards
2004-11-23 1:29 ` Timothy Baldwin
2004-11-23 15:12 ` Marco Gerards
2004-11-24 19:15 ` Marco Gerards
2004-11-30 17:55 ` Marco Gerards
2004-12-03 17:18 ` Yoshinori K. Okuji
2004-12-04 15:39 ` Marco Gerards
2004-12-04 17:03 ` Yoshinori K. Okuji
[not found] ` <200412041230.17136.mjflick@gnu.org>
2004-12-04 18:41 ` Marco Gerards
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.