Use (hd0,msdos1) syntax. Eliminate partmap_iterate
This commit is contained in:
parent
85f90358b1
commit
f3e309ad7d
6 changed files with 92 additions and 128 deletions
|
@ -34,7 +34,7 @@ grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c \
|
|||
script/main.c script/execute.c script/function.c \
|
||||
script/lexer.c script/script.c grub_script.tab.c \
|
||||
partmap/amiga.c partmap/apple.c partmap/msdos.c partmap/sun.c \
|
||||
partmap/acorn.c partmap/gpt.c partmap/bsd.c \
|
||||
partmap/acorn.c partmap/gpt.c partmap/bsdlabel.c \
|
||||
\
|
||||
fs/affs.c fs/cpio.c fs/fat.c fs/ext2.c fs/hfs.c \
|
||||
fs/hfsplus.c fs/iso9660.c fs/udf.c fs/jfs.c fs/minix.c \
|
||||
|
|
|
@ -24,7 +24,7 @@ util/grub-probe.c_DEPENDENCIES = grub_probe_init.h
|
|||
grub_probe_SOURCES = gnulib/progname.c util/grub-probe.c \
|
||||
util/hostdisk.c util/misc.c util/getroot.c \
|
||||
kern/device.c kern/disk.c kern/err.c kern/misc.c \
|
||||
kern/parser.c kern/partition.c kern/file.c \
|
||||
kern/parser.c kern/partition.c kern/file.c kern/list.c \
|
||||
\
|
||||
fs/affs.c fs/cpio.c fs/fat.c fs/ext2.c fs/hfs.c \
|
||||
fs/hfsplus.c fs/iso9660.c fs/udf.c fs/jfs.c fs/minix.c \
|
||||
|
|
|
@ -94,14 +94,14 @@ util/grub-mkrawimage.c_DEPENDENCIES = Makefile
|
|||
util/i386/pc/grub-setup.c_DEPENDENCIES = grub_setup_init.h
|
||||
grub_setup_SOURCES = gnulib/progname.c \
|
||||
util/i386/pc/grub-setup.c util/hostdisk.c \
|
||||
util/misc.c util/getroot.c kern/device.c kern/disk.c \
|
||||
kern/err.c kern/misc.c kern/parser.c kern/partition.c \
|
||||
kern/file.c kern/fs.c kern/env.c fs/fshelp.c \
|
||||
util/misc.c util/getroot.c kern/device.c kern/disk.c \
|
||||
kern/err.c kern/misc.c kern/parser.c kern/partition.c \
|
||||
kern/file.c kern/list.c kern/fs.c kern/env.c fs/fshelp.c \
|
||||
\
|
||||
fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \
|
||||
fs/hfsplus.c fs/iso9660.c fs/udf.c fs/jfs.c fs/minix.c \
|
||||
fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c fs/sfs.c \
|
||||
fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c fs/afs_be.c \
|
||||
fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \
|
||||
fs/hfsplus.c fs/iso9660.c fs/udf.c fs/jfs.c fs/minix.c \
|
||||
fs/ntfs.c fs/ntfscomp.c fs/reiserfs.c fs/sfs.c \
|
||||
fs/ufs.c fs/ufs2.c fs/xfs.c fs/afs.c fs/afs_be.c \
|
||||
fs/befs.c fs/befs_be.c fs/tar.c \
|
||||
\
|
||||
partmap/msdos.c partmap/bsdlabel.c partmap/gpt.c \
|
||||
|
|
|
@ -68,9 +68,9 @@ grub_mkimage_SOURCES = util/sparc64/ieee1275/grub-mkimage.c util/misc.c \
|
|||
# For grub-setup.
|
||||
util/sparc64/ieee1275/grub-setup.c_DEPENDENCIES = grub_setup_init.h
|
||||
grub_setup_SOURCES = util/sparc64/ieee1275/grub-setup.c util/hostdisk.c \
|
||||
util/misc.c util/getroot.c kern/device.c kern/disk.c \
|
||||
kern/err.c kern/misc.c kern/parser.c kern/partition.c \
|
||||
kern/file.c kern/fs.c kern/env.c fs/fshelp.c \
|
||||
util/misc.c util/getroot.c kern/device.c kern/disk.c \
|
||||
kern/err.c kern/misc.c kern/parser.c kern/partition.c \
|
||||
kern/file.c kern/fs.c kern/env.c kern/list.c fs/fshelp.c \
|
||||
\
|
||||
fs/affs.c fs/cpio.c fs/ext2.c fs/fat.c fs/hfs.c \
|
||||
fs/hfsplus.c fs/iso9660.c fs/udf.c fs/jfs.c fs/minix.c \
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#define GRUB_PART_HEADER 1
|
||||
|
||||
#include <grub/dl.h>
|
||||
#include <grub/list.h>
|
||||
|
||||
struct grub_disk;
|
||||
|
||||
|
@ -28,6 +29,9 @@ typedef struct grub_partition *grub_partition_t;
|
|||
/* Partition map type. */
|
||||
struct grub_partition_map
|
||||
{
|
||||
/* The next partition map type. */
|
||||
struct grub_partition_map *next;
|
||||
|
||||
/* The name of the partition map type. */
|
||||
const char *name;
|
||||
|
||||
|
@ -35,9 +39,6 @@ struct grub_partition_map
|
|||
grub_err_t (*iterate) (struct grub_disk *disk,
|
||||
int (*hook) (struct grub_disk *disk,
|
||||
const grub_partition_t partition));
|
||||
|
||||
/* The next partition map type. */
|
||||
struct grub_partition_map *next;
|
||||
};
|
||||
typedef struct grub_partition_map *grub_partition_map_t;
|
||||
|
||||
|
@ -76,11 +77,24 @@ int EXPORT_FUNC(grub_partition_iterate) (struct grub_disk *disk,
|
|||
const grub_partition_t partition));
|
||||
char *EXPORT_FUNC(grub_partition_get_name) (const grub_partition_t partition);
|
||||
|
||||
int 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);
|
||||
extern grub_partition_map_t EXPORT_VAR(grub_partition_map_list);
|
||||
|
||||
void EXPORT_FUNC(grub_partition_map_unregister) (grub_partition_map_t partmap);
|
||||
static inline void
|
||||
grub_partition_map_register (grub_partition_map_t partmap)
|
||||
{
|
||||
grub_list_push (GRUB_AS_LIST_P (&grub_partition_map_list),
|
||||
GRUB_AS_LIST (partmap));
|
||||
}
|
||||
|
||||
static inline void
|
||||
grub_partition_map_unregister (grub_partition_map_t partmap)
|
||||
{
|
||||
grub_list_remove (GRUB_AS_LIST_P (&grub_partition_map_list),
|
||||
GRUB_AS_LIST (partmap));
|
||||
}
|
||||
|
||||
#define FOR_PARTITION_MAPS(var) for (var = grub_partition_map_list; var; var = var->next)
|
||||
|
||||
#ifdef GRUB_UTIL
|
||||
void grub_msdos_partition_map_init (void);
|
||||
|
|
170
kern/partition.c
170
kern/partition.c
|
@ -21,39 +21,7 @@
|
|||
#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;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
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))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
grub_partition_map_t grub_partition_map_list;
|
||||
|
||||
static grub_partition_t
|
||||
grub_partition_map_probe (const grub_partition_map_t partmap,
|
||||
|
@ -97,41 +65,45 @@ grub_partition_probe (struct grub_disk *disk, const char *str)
|
|||
grub_partition_t curpart = 0;
|
||||
grub_partition_t tail;
|
||||
const char *ptr;
|
||||
int num;
|
||||
|
||||
auto int part_map_probe (const grub_partition_map_t partmap);
|
||||
|
||||
int part_map_probe (const grub_partition_map_t partmap)
|
||||
{
|
||||
disk->partition = part;
|
||||
curpart = grub_partition_map_probe (partmap, disk, num);
|
||||
disk->partition = tail;
|
||||
if (curpart)
|
||||
return 1;
|
||||
|
||||
if (grub_errno == GRUB_ERR_BAD_PART_TABLE)
|
||||
{
|
||||
/* Continue to next partition map type. */
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
part = tail = disk->partition;
|
||||
|
||||
for (ptr = str; *ptr;)
|
||||
{
|
||||
/* BSD-like partition specification. */
|
||||
if (*ptr >= 'a' && *ptr <= 'z')
|
||||
num = *(ptr++) - 'a';
|
||||
else
|
||||
num = grub_strtoul (ptr, (char **) &ptr, 0) - 1;
|
||||
grub_partition_map_t partmap;
|
||||
int num;
|
||||
const char *partname, *partname_end;
|
||||
|
||||
partname = ptr;
|
||||
while (*ptr && grub_isalpha (*ptr))
|
||||
ptr++;
|
||||
partname_end = ptr;
|
||||
num = grub_strtoul (ptr, (char **) &ptr, 0) - 1;
|
||||
|
||||
curpart = 0;
|
||||
/* Use the first partition map type found. */
|
||||
grub_partition_map_iterate (part_map_probe);
|
||||
FOR_PARTITION_MAPS(partmap)
|
||||
{
|
||||
if (partname_end != partname &&
|
||||
(grub_strncmp (partmap->name, partname, partname_end - partname)
|
||||
!= 0 || partmap->name[partname_end - partname] != 0))
|
||||
continue;
|
||||
|
||||
disk->partition = part;
|
||||
curpart = grub_partition_map_probe (partmap, disk, num);
|
||||
disk->partition = tail;
|
||||
if (curpart)
|
||||
break;
|
||||
|
||||
if (grub_errno == GRUB_ERR_BAD_PART_TABLE)
|
||||
{
|
||||
/* Continue to next partition map type. */
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (! curpart)
|
||||
{
|
||||
|
@ -153,45 +125,6 @@ grub_partition_probe (struct grub_disk *disk, const char *str)
|
|||
return part;
|
||||
}
|
||||
|
||||
static grub_partition_map_t
|
||||
get_partmap (struct grub_disk *disk)
|
||||
{
|
||||
grub_partition_map_t partmap = 0;
|
||||
struct grub_partition part;
|
||||
int found = 0;
|
||||
auto int part_map_iterate (const grub_partition_map_t p);
|
||||
auto int part_map_iterate_hook (grub_disk_t d,
|
||||
const grub_partition_t partition);
|
||||
int part_map_iterate_hook (grub_disk_t d __attribute__ ((unused)),
|
||||
const grub_partition_t partition)
|
||||
{
|
||||
found = 1;
|
||||
part = *partition;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int part_map_iterate (const grub_partition_map_t p)
|
||||
{
|
||||
grub_dprintf ("partition", "Detecting %s...\n", p->name);
|
||||
p->iterate (disk, part_map_iterate_hook);
|
||||
|
||||
if (grub_errno != GRUB_ERR_NONE || ! found)
|
||||
{
|
||||
/* Continue to next partition map type. */
|
||||
grub_dprintf ("partition", "%s detection failed.\n", p->name);
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
return 0;
|
||||
}
|
||||
grub_free (part.data);
|
||||
|
||||
grub_dprintf ("partition", "%s detection succeeded.\n", p->name);
|
||||
partmap = p;
|
||||
return 1;
|
||||
}
|
||||
grub_partition_map_iterate (part_map_iterate);
|
||||
return partmap;
|
||||
}
|
||||
|
||||
int
|
||||
grub_partition_iterate (struct grub_disk *disk,
|
||||
int (*hook) (grub_disk_t disk,
|
||||
|
@ -205,27 +138,42 @@ grub_partition_iterate (struct grub_disk *disk,
|
|||
const grub_partition_t partition)
|
||||
{
|
||||
struct grub_partition p = *partition;
|
||||
grub_partition_map_t partmap = 0;
|
||||
p.parent = dsk->partition;
|
||||
dsk->partition = 0;
|
||||
if (hook (dsk, &p))
|
||||
{
|
||||
ret = 1;
|
||||
return 1;
|
||||
}
|
||||
if (p.start != 0)
|
||||
{
|
||||
const struct grub_partition_map *partmap;
|
||||
dsk->partition = &p;
|
||||
partmap = get_partmap (dsk);
|
||||
if (partmap)
|
||||
ret = partmap->iterate (dsk, part_iterate);
|
||||
FOR_PARTITION_MAPS(partmap)
|
||||
{
|
||||
grub_err_t err;
|
||||
err = partmap->iterate (dsk, part_iterate);
|
||||
if (err)
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
if (ret)
|
||||
break;
|
||||
}
|
||||
}
|
||||
dsk->partition = p.parent;
|
||||
return ret;
|
||||
}
|
||||
|
||||
{
|
||||
grub_partition_map_t partmap = 0;
|
||||
partmap = get_partmap (disk);
|
||||
if (partmap)
|
||||
ret = partmap->iterate (disk, part_iterate);
|
||||
const struct grub_partition_map *partmap;
|
||||
FOR_PARTITION_MAPS(partmap)
|
||||
{
|
||||
grub_err_t err;
|
||||
err = partmap->iterate (disk, part_iterate);
|
||||
if (err)
|
||||
grub_errno = GRUB_ERR_NONE;
|
||||
if (ret)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -235,14 +183,16 @@ char *
|
|||
grub_partition_get_name (const grub_partition_t partition)
|
||||
{
|
||||
char *out = 0;
|
||||
/* Even on 64-bit machines this buffer is enough to hold longest number. */
|
||||
char buf[25];
|
||||
int curlen = 0;
|
||||
grub_partition_t part;
|
||||
for (part = partition; part; part = part->parent)
|
||||
{
|
||||
/* Even on 64-bit machines this buffer is enough to hold
|
||||
longest number. */
|
||||
char buf[grub_strlen (part->partmap->name) + 25];
|
||||
int strl;
|
||||
grub_snprintf (buf, sizeof (buf), "%d", part->number + 1);
|
||||
grub_snprintf (buf, sizeof (buf), "%s%d", part->partmap->name,
|
||||
part->number + 1);
|
||||
strl = grub_strlen (buf);
|
||||
if (curlen)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue