Received: from mailman by lists.gnu.org with archive (Exim 4.33) id 1CX2nP-0001yS-Nt for mharc-grub-devel@gnu.org; Wed, 24 Nov 2004 14:27:19 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CX2nO-0001yK-3C for grub-devel@gnu.org; Wed, 24 Nov 2004 14:27:18 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CX2nL-0001xD-Da for grub-devel@gnu.org; Wed, 24 Nov 2004 14:27:17 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CX2nL-0001x4-Ak for grub-devel@gnu.org; Wed, 24 Nov 2004 14:27:15 -0500 Received: from [145.74.66.11] (helo=mail-cn.han.nl) by monty-python.gnu.org with esmtp (Exim 4.34) id 1CX2dW-0003Wo-MS for grub-devel@gnu.org; Wed, 24 Nov 2004 14:17:07 -0500 Received: from localhost (charlie.han.nl [145.74.66.9]) by mail-cn.han.nl (Postfix) with ESMTP id 624E688A0 for ; Wed, 24 Nov 2004 20:17:05 +0100 (CET) Received: from mail-cn.han.nl ([145.74.66.11]) by localhost (charlie.han.nl [145.74.66.9]) (amavisd-new, port 10024) with ESMTP id 18610-03; Wed, 24 Nov 2004 20:16:58 +0100 (CET) Received: from mail1.han.nl (mail1.han.nl [145.74.103.11]) by mail-cn.han.nl (Postfix) with ESMTP id 878348E70; Wed, 24 Nov 2004 20:16:53 +0100 (CET) Received: from marco.marco-g.com (mgerards.xs4all.nl [82.92.27.129]) by mail1.han.nl (Postfix) with ESMTP id 4E419C072; Wed, 24 Nov 2004 20:16:51 +0100 (CET) Mail-Copies-To: metgerards@student.han.nl To: The development of GRUB 2 References: <87actg8ehq.fsf@marco.marco-g.com> From: Marco Gerards Date: Wed, 24 Nov 2004 19:15:35 +0000 In-Reply-To: <87actg8ehq.fsf@marco.marco-g.com> (Marco Gerards's message of "Wed, 17 Nov 2004 19:25:21 +0000") Message-ID: <87oehn5a94.fsf@marco.marco-g.com> User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new@vscan-cn.han.nl Cc: Subject: Re: Partition modules X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Nov 2004 19:27:18 -0000 Marco Gerards 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 * commands/ls.c: Include instead of . * 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 instead of . (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 ' and `include ' instead of `'. * 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 ' and `include ' instead of `'. (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 #include #include -#include +#include #include 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 -#include -#include -#include - -/* 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 -#include -#include -#include - -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 + +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 + +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 +#include +#include + +/* 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)); + + +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 -#include -#include - -/* 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 -#include -#include - -#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); - - -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 #include #include -#include +#include #include #include #include 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 +#include + +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 #include #include -#include +#include #include #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 #include #include -#include +#include #include #include #include @@ -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 #include #include -#include +#include #include #include #include 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 #include #include -#include +#include #include #include #include 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 +#include +#include +#include +#include + +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 + +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; +} + + +/* 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 +#include +#include +#include + +#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 + + +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; +} + + +/* 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 +#include +#include +#include +#include +#include + +static struct grub_partition_map grub_pc_partition_map; + +#ifndef GRUB_UTIL +static grub_dl_t my_mod; +#endif + + +/* 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; +} + + +/* 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 #include #include +#include #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 #include -#include +#include +#include #include #include #include @@ -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 #include #include -#include +#include +#include #include #include #include @@ -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);