Reimport nestpart

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-02-06 18:43:37 +01:00
parent bf7fcba2d7
commit 15cb7d433f
26 changed files with 561 additions and 720 deletions

View file

@ -96,21 +96,17 @@ acorn_partition_map_iterate (grub_disk_t disk,
const grub_partition_t partition))
{
struct grub_partition part;
struct grub_disk raw;
struct linux_part map[LINUX_MAP_ENTRIES];
int i;
grub_disk_addr_t sector;
grub_disk_addr_t sector = 0;
grub_err_t err;
/* Enforce raw disk access. */
raw = *disk;
raw.partition = 0;
err = acorn_partition_map_find (&raw, map, &sector);
err = acorn_partition_map_find (disk, map, &sector);
if (err)
return err;
part.partmap = &grub_acorn_partition_map;
part.data = 0;
for (i = 0; i != LINUX_MAP_ENTRIES; ++i)
{
@ -121,7 +117,7 @@ acorn_partition_map_iterate (grub_disk_t disk,
part.start = sector + map[i].start;
part.len = map[i].size;
part.offset = 6;
part.index = i;
part.number = part.index = i;
if (hook (disk, &part))
return grub_errno;
@ -130,53 +126,6 @@ acorn_partition_map_iterate (grub_disk_t disk,
return GRUB_ERR_NONE;
}
static grub_partition_t
acorn_partition_map_probe (grub_disk_t disk, const char *str)
{
struct linux_part map[LINUX_MAP_ENTRIES];
struct grub_disk raw = *disk;
unsigned long partnum = grub_strtoul (str, 0, 10) - 1;
grub_disk_addr_t sector;
grub_err_t err;
grub_partition_t p;
/* Enforce raw disk access. */
raw.partition = 0;
/* Get the partition number. */
if (partnum > LINUX_MAP_ENTRIES)
goto fail;
err = acorn_partition_map_find (&raw, map, &sector);
if (err)
return 0;
if (map[partnum].magic != LINUX_NATIVE_MAGIC
&& map[partnum].magic != LINUX_SWAP_MAGIC)
goto fail;
p = grub_malloc (sizeof (struct grub_partition));
if (! p)
return 0;
p->start = sector + map[partnum].start;
p->len = map[partnum].size;
p->offset = 6;
p->index = partnum;
return p;
fail:
grub_error (GRUB_ERR_BAD_FILENAME, "invalid partition");
return 0;
}
static char *
acorn_partition_map_get_name (const grub_partition_t p)
{
return grub_xasprintf ("%d", p->index + 1);
}
/* Partition map type. */
@ -184,8 +133,6 @@ static struct grub_partition_map grub_acorn_partition_map =
{
.name = "part_acorn",
.iterate = acorn_partition_map_iterate,
.probe = acorn_partition_map_probe,
.get_name = acorn_partition_map_get_name
};
GRUB_MOD_INIT(acorn_partition_map)

View file

@ -76,20 +76,15 @@ amiga_partition_map_iterate (grub_disk_t disk,
{
struct grub_partition part;
struct grub_amiga_rdsk rdsk;
struct grub_disk raw;
int partno = 0;
int next = -1;
unsigned 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), &rdsk))
if (grub_disk_read (disk, pos, 0, sizeof (rdsk), &rdsk))
return grub_errno;
if (grub_strcmp ((char *) rdsk.magic, "RDSK") == 0)
@ -104,13 +99,15 @@ amiga_partition_map_iterate (grub_disk_t disk,
return grub_error (GRUB_ERR_BAD_PART_TABLE,
"Amiga partition map not found");
part.data = 0;
/* 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), &apart))
if (grub_disk_read (disk, next, 0, sizeof (apart), &apart))
return grub_errno;
/* Calculate the first block and the size of the partition. */
@ -123,7 +120,8 @@ amiga_partition_map_iterate (grub_disk_t disk,
* grub_be_to_cpu32 (apart.block_per_track));
part.offset = (grub_off_t) next * 512;
part.index = partno;
part.number = partno;
part.index = 0;
part.partmap = &grub_amiga_partition_map;
if (hook (disk, &part))
@ -136,65 +134,12 @@ amiga_partition_map_iterate (grub_disk_t disk,
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 (grub_disk_t d, const grub_partition_t partition);
int find_func (grub_disk_t d __attribute__ ((unused)),
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) - 1;
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)
{
return grub_xasprintf ("%d", p->index + 1);
}
/* Partition map type. */
static struct grub_partition_map grub_amiga_partition_map =
{
.name = "part_amiga",
.iterate = amiga_partition_map_iterate,
.probe = amiga_partition_map_probe,
.get_name = amiga_partition_map_get_name
};
GRUB_MOD_INIT(amiga_partition_map)

View file

@ -105,17 +105,12 @@ apple_partition_map_iterate (grub_disk_t disk,
struct grub_partition part;
struct grub_apple_header aheader;
struct grub_apple_part apart;
struct grub_disk raw;
int partno = 0, partnum = 0;
unsigned pos;
/* Enforce raw disk access. */
raw = *disk;
raw.partition = 0;
part.partmap = &grub_apple_partition_map;
if (grub_disk_read (&raw, 0, 0, sizeof (aheader), &aheader))
if (grub_disk_read (disk, 0, 0, sizeof (aheader), &aheader))
return grub_errno;
if (grub_be_to_cpu16 (aheader.magic) != GRUB_APPLE_HEADER_MAGIC)
@ -127,14 +122,17 @@ apple_partition_map_iterate (grub_disk_t disk,
goto fail;
}
part.data = 0;
pos = grub_be_to_cpu16 (aheader.blocksize);
do
{
if (grub_disk_read (&raw, pos / GRUB_DISK_SECTOR_SIZE,
pos % GRUB_DISK_SECTOR_SIZE,
sizeof (struct grub_apple_part), &apart))
return grub_errno;
part.offset = pos / GRUB_DISK_SECTOR_SIZE;
part.index = pos % GRUB_DISK_SECTOR_SIZE;
if (grub_disk_read (disk, part.offset, part.index,
sizeof (struct grub_apple_part), &apart))
return grub_errno;
if (grub_be_to_cpu16 (apart.magic) != GRUB_APPLE_PART_MAGIC)
{
@ -156,6 +154,7 @@ apple_partition_map_iterate (grub_disk_t disk,
/ GRUB_DISK_SECTOR_SIZE;
part.offset = pos;
part.index = partno;
part.number = partno;
grub_dprintf ("partition",
"partition %d: name %s, type %s, start 0x%x, len 0x%x\n",
@ -179,65 +178,12 @@ apple_partition_map_iterate (grub_disk_t disk,
"Apple partition map not found");
}
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 (grub_disk_t d, const grub_partition_t partition);
int find_func (grub_disk_t d __attribute__ ((unused)),
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) - 1;
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)
{
return grub_xasprintf ("%d", p->index + 1);
}
/* Partition map type. */
static struct grub_partition_map grub_apple_partition_map =
{
.name = "part_apple",
.iterate = apple_partition_map_iterate,
.probe = apple_partition_map_probe,
.get_name = apple_partition_map_get_name
};
GRUB_MOD_INIT(apple_partition_map)

97
partmap/bsdlabel.c Normal file
View file

@ -0,0 +1,97 @@
/* bsdlabel.c - Read BSD style partition tables. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/partition.h>
#include <grub/bsdlabel.h>
#include <grub/disk.h>
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/dl.h>
static struct grub_partition_map grub_bsdlabel_partition_map;
static grub_err_t
bsdlabel_partition_map_iterate (grub_disk_t disk,
int (*hook) (grub_disk_t disk,
const grub_partition_t partition))
{
struct grub_partition_bsd_disk_label label;
struct grub_partition p;
grub_disk_addr_t delta = 0;
unsigned pos;
/* BSDLabel offsets are absolute even when it's embed inside partition. */
delta = grub_partition_get_start (disk->partition);
/* Read the BSD label. */
if (grub_disk_read (disk, GRUB_PC_PARTITION_BSD_LABEL_SECTOR,
0, sizeof (label), &label))
return grub_errno;
/* 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, "no signature");
pos = sizeof (label) + GRUB_PC_PARTITION_BSD_LABEL_SECTOR
* GRUB_DISK_SECTOR_SIZE;
for (p.number = 0;
p.number < grub_cpu_to_le16 (label.num_partitions);
p.number++)
{
struct grub_partition_bsd_entry be;
p.offset = pos / GRUB_DISK_SECTOR_SIZE;
p.index = pos % GRUB_DISK_SECTOR_SIZE;
if (grub_disk_read (disk, p.offset, p.index, sizeof (be), &be))
return grub_errno;
p.start = grub_le_to_cpu32 (be.offset) - delta;
p.len = grub_le_to_cpu32 (be.size);
p.partmap = &grub_bsdlabel_partition_map;
if (be.fs_type != GRUB_PC_PARTITION_BSD_TYPE_UNUSED)
if (hook (disk, &p))
return grub_errno;
pos += sizeof (struct grub_partition_bsd_entry);
}
return GRUB_ERR_NONE;
}
/* Partition map type. */
static struct grub_partition_map grub_bsdlabel_partition_map =
{
.name = "part_bsd",
.iterate = bsdlabel_partition_map_iterate,
};
GRUB_MOD_INIT(bsd_partition_map)
{
grub_partition_map_register (&grub_bsdlabel_partition_map);
}
GRUB_MOD_FINI(bsd_partition_map)
{
grub_partition_map_unregister (&grub_bsdlabel_partition_map);
}

View file

@ -44,18 +44,13 @@ gpt_partition_map_iterate (grub_disk_t disk,
struct grub_partition part;
struct grub_gpt_header gpt;
struct grub_gpt_partentry entry;
struct grub_disk raw;
struct grub_msdos_partition_mbr mbr;
grub_uint64_t entries;
unsigned int i;
int last_offset = 0;
/* Enforce raw disk access. */
raw = *disk;
raw.partition = 0;
/* Read the protective MBR. */
if (grub_disk_read (&raw, 0, 0, sizeof (mbr), &mbr))
if (grub_disk_read (disk, 0, 0, sizeof (mbr), &mbr))
return grub_errno;
/* Check if it is valid. */
@ -67,7 +62,7 @@ gpt_partition_map_iterate (grub_disk_t disk,
return grub_error (GRUB_ERR_BAD_PART_TABLE, "no GPT partition map found");
/* Read the GPT header. */
if (grub_disk_read (&raw, 1, 0, sizeof (gpt), &gpt))
if (grub_disk_read (disk, 1, 0, sizeof (gpt), &gpt))
return grub_errno;
if (grub_memcmp (gpt.magic, grub_gpt_magic, sizeof (grub_gpt_magic)))
@ -76,11 +71,15 @@ gpt_partition_map_iterate (grub_disk_t disk,
grub_dprintf ("gpt", "Read a valid GPT header\n");
entries = grub_le_to_cpu64 (gpt.partitions);
part.data = grub_malloc (sizeof (entry));
for (i = 0; i < grub_le_to_cpu32 (gpt.maxpart); i++)
{
if (grub_disk_read (&raw, entries, last_offset,
if (grub_disk_read (disk, entries, last_offset,
sizeof (entry), &entry))
return grub_errno;
{
grub_free (part.data);
return grub_errno;
}
if (grub_memcmp (&grub_gpt_partition_type_empty, &entry.type,
sizeof (grub_gpt_partition_type_empty)))
@ -90,16 +89,17 @@ gpt_partition_map_iterate (grub_disk_t disk,
part.len = (grub_le_to_cpu64 (entry.end)
- grub_le_to_cpu64 (entry.start) + 1);
part.offset = entries;
part.index = i;
part.number = i;
part.index = last_offset;
part.partmap = &grub_gpt_partition_map;
part.data = &entry;
grub_memcpy (part.data, &entry, sizeof (entry));
grub_dprintf ("gpt", "GPT entry %d: start=%lld, length=%lld\n", i,
(unsigned long long) part.start,
(unsigned long long) part.len);
if (hook (disk, &part))
return 1;
return grub_errno;
}
last_offset += grub_le_to_cpu32 (gpt.partentry_size);
@ -110,59 +110,9 @@ gpt_partition_map_iterate (grub_disk_t disk,
}
}
return 0;
}
grub_free (part.data);
static grub_partition_t
gpt_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 (grub_disk_t d, const grub_partition_t partition);
int find_func (grub_disk_t d __attribute__ ((unused)),
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) - 1;
if (grub_errno)
{
grub_error (GRUB_ERR_BAD_FILENAME, "invalid partition");
return 0;
}
gpt_partition_map_iterate (disk, find_func);
if (grub_errno)
goto fail;
return p;
fail:
grub_free (p);
return 0;
}
static char *
gpt_partition_map_get_name (const grub_partition_t p)
{
return grub_xasprintf ("%d", p->index + 1);
return GRUB_ERR_NONE;
}
@ -171,8 +121,6 @@ static struct grub_partition_map grub_gpt_partition_map =
{
.name = "part_gpt",
.iterate = gpt_partition_map_iterate,
.probe = gpt_partition_map_probe,
.get_name = gpt_partition_map_get_name
};
GRUB_MOD_INIT(gpt_partition_map)

View file

@ -27,87 +27,21 @@
static struct grub_partition_map grub_msdos_partition_map;
/* 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_msdos_partition *pcdata;
char *s = (char *) str;
p = (grub_partition_t) grub_malloc (sizeof (*p));
if (! p)
return 0;
pcdata = (struct grub_msdos_partition *) grub_malloc (sizeof (*pcdata));
if (! pcdata)
goto fail;
p->data = pcdata;
p->partmap = &grub_msdos_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. The number is counted from one for
the user interface, and from zero internally. */
pcdata->dos_part = grub_strtoul (s, &s, 0) - 1;
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) (grub_disk_t disk,
const grub_partition_t partition))
{
struct grub_partition p;
struct grub_msdos_partition pcdata;
struct grub_msdos_partition_mbr mbr;
struct grub_msdos_partition_disk_label label;
struct grub_disk raw;
int labeln = 0;
grub_disk_addr_t lastaddr;
/* Enforce raw disk access. */
raw = *disk;
raw.partition = 0;
grub_disk_addr_t ext_offset;
p.offset = 0;
pcdata.ext_offset = 0;
pcdata.dos_part = -1;
p.data = &pcdata;
ext_offset = 0;
p.data = 0;
p.number = -1;
p.partmap = &grub_msdos_partition_map;
/* Any value different than `p.offset' will satisfy the check during
@ -120,7 +54,7 @@ pc_partition_map_iterate (grub_disk_t disk,
struct grub_msdos_partition_entry *e;
/* Read the MBR. */
if (grub_disk_read (&raw, p.offset, 0, sizeof (mbr), &mbr))
if (grub_disk_read (disk, p.offset, 0, sizeof (mbr), &mbr))
goto finish;
/* This is our loop-detection algorithm. It works the following way:
@ -150,13 +84,10 @@ pc_partition_map_iterate (grub_disk_t disk,
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;
grub_dprintf ("partition",
"partition %d: flag 0x%x, type 0x%x, start 0x%llx, len 0x%llx\n",
p.index, e->flag, pcdata.dos_type,
p.index, e->flag, e->type,
(unsigned long long) p.start,
(unsigned long long) p.len);
@ -168,59 +99,15 @@ pc_partition_map_iterate (grub_disk_t disk,
if (! grub_msdos_partition_is_empty (e->type)
&& ! grub_msdos_partition_is_extended (e->type))
{
pcdata.dos_part++;
p.number++;
if (hook (disk, &p))
return 1;
/* Check if this is a BSD partition. */
if (grub_msdos_partition_is_bsd (e->type))
{
/* Check if the BSD label is within the DOS partition. */
if (p.len <= GRUB_PC_PARTITION_BSD_LABEL_SECTOR)
{
grub_dprintf ("partition", "no space for disk label\n");
continue;
}
/* Read the BSD label. */
if (grub_disk_read (&raw,
(p.start
+ GRUB_PC_PARTITION_BSD_LABEL_SECTOR),
0,
sizeof (label),
&label))
goto finish;
/* Check if it is valid. */
if (label.magic
!= grub_cpu_to_le32 (GRUB_PC_PARTITION_BSD_LABEL_MAGIC))
{
grub_dprintf ("partition",
"invalid disk label magic 0x%x on partition %d\n",
label.magic, p.index);
continue;
}
for (pcdata.bsd_part = 0;
pcdata.bsd_part < grub_cpu_to_le16 (label.num_partitions);
pcdata.bsd_part++)
{
struct grub_msdos_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 (disk, &p))
return 1;
}
}
return grub_errno;
}
else if (pcdata.dos_part < 4)
else if (p.number < 4)
/* If this partition is a logical one, shouldn't increase the
partition number. */
pcdata.dos_part++;
p.number++;
}
/* Find an extended partition. */
@ -230,9 +117,9 @@ pc_partition_map_iterate (grub_disk_t disk,
if (grub_msdos_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;
p.offset = ext_offset + grub_le_to_cpu32 (e->start);
if (! ext_offset)
ext_offset = p.offset;
break;
}
@ -247,78 +134,12 @@ pc_partition_map_iterate (grub_disk_t disk,
return grub_errno;
}
static grub_partition_t
pc_partition_map_probe (grub_disk_t disk, const char *str)
{
grub_partition_t p;
struct grub_msdos_partition *pcdata;
auto int find_func (grub_disk_t d, const grub_partition_t partition);
int find_func (grub_disk_t d __attribute__ ((unused)),
const grub_partition_t partition)
{
struct grub_msdos_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));
p->data = pcdata;
grub_memcpy (pcdata, partdata, sizeof (*pcdata));
return 1;
}
return 0;
}
p = grub_partition_parse (str);
if (! p)
return 0;
pcdata = p->data;
pc_partition_map_iterate (disk, find_func);
if (grub_errno)
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)
{
struct grub_msdos_partition *pcdata = p->data;
if (pcdata->bsd_part < 0)
return grub_xasprintf ("%d", pcdata->dos_part + 1);
else if (pcdata->dos_part < 0)
return grub_xasprintf ("%c", pcdata->bsd_part + 'a');
else
return grub_xasprintf ("%d,%c", pcdata->dos_part + 1,
pcdata->bsd_part + 'a');
}
/* Partition map type. */
static struct grub_partition_map grub_msdos_partition_map =
{
.name = "part_msdos",
.iterate = pc_partition_map_iterate,
.probe = pc_partition_map_probe,
.get_name = pc_partition_map_get_name
};
GRUB_MOD_INIT(pc_partition_map)

View file

@ -88,19 +88,15 @@ sun_partition_map_iterate (grub_disk_t disk,
const grub_partition_t partition))
{
grub_partition_t p;
struct grub_disk raw;
struct grub_sun_block block;
int partnum;
raw = *disk;
raw.partition = 0;
p = (grub_partition_t) grub_zalloc (sizeof (struct grub_partition));
if (! p)
return grub_errno;
p->partmap = &grub_sun_partition_map;
if (grub_disk_read (&raw, 0, 0, sizeof (struct grub_sun_block),
if (grub_disk_read (disk, 0, 0, sizeof (struct grub_sun_block),
&block) == GRUB_ERR_NONE)
{
if (GRUB_PARTMAP_SUN_MAGIC != grub_be_to_cpu16 (block.magic))
@ -124,7 +120,7 @@ sun_partition_map_iterate (grub_disk_t disk,
* grub_be_to_cpu16 (block.ntrks)
* grub_be_to_cpu16 (block.nsect));
p->len = grub_be_to_cpu32 (desc->num_sectors);
p->index = partnum;
p->number = p->index = partnum;
if (p->len)
{
if (hook (disk, p))
@ -138,62 +134,11 @@ sun_partition_map_iterate (grub_disk_t disk,
return grub_errno;
}
static grub_partition_t
sun_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 (grub_disk_t d, const grub_partition_t partition);
int find_func (grub_disk_t d __attribute__ ((unused)),
const grub_partition_t partition)
{
if (partnum == partition->index)
{
p = (grub_partition_t) grub_malloc (sizeof (*p));
if (p)
grub_memcpy (p, partition, sizeof (*p));
return 1;
}
return 0;
}
grub_errno = GRUB_ERR_NONE;
partnum = grub_strtoul (s, 0, 10) - 1;
if (grub_errno == GRUB_ERR_NONE)
{
if (sun_partition_map_iterate (disk, find_func))
{
grub_free (p);
p = 0;
}
}
else
{
grub_error (GRUB_ERR_BAD_FILENAME, "invalid partition");
p = 0;
}
return p;
}
static char *
sun_partition_map_get_name (const grub_partition_t p)
{
return grub_xasprintf ("%d", p->index + 1);
}
/* Partition map type. */
static struct grub_partition_map grub_sun_partition_map =
{
.name = "part_sun",
.iterate = sun_partition_map_iterate,
.probe = sun_partition_map_probe,
.get_name = sun_partition_map_get_name
};
GRUB_MOD_INIT(sun_partition_map)