/* pc.c - Read PC style partition tables. */
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2002,2004,2005,2006,2007,2008,2009 Free Software Foundation, Inc.
*
* 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/msdos_partition.h>
GRUB_MOD_LICENSE ("GPLv3+");
const grub_partition_t partition))
{
struct grub_partition p;
int labeln = 0;
{
else
}
p.offset = 0;
ext_offset = 0;
p.number = -1;
/* Any value different than `p.offset' will satisfy the check during
first loop. */
while (1)
{
int i;
struct grub_msdos_partition_entry *e;
/* Read the MBR. */
goto finish;
/* This is our loop-detection algorithm. It works the following way:
It saves last position which was a power of two. Then it compares the
saved value with a current one. This way it's guaranteed that the loop
will be broken by at most third walk.
*/
labeln++;
/* Check if it is valid. */
for (i = 0; i < 4; i++)
/* Analyze DOS partitions. */
{
+ (grub_le_to_cpu32 (e->start)
grub_dprintf ("partition",
"partition %d: flag 0x%x, type 0x%x, start 0x%llx, len 0x%llx\n",
(unsigned long long) p.start,
(unsigned long long) p.len);
/* If this is a GPT partition, this MBR is just a dummy. */
/* If this partition is a normal one, call the hook. */
if (! grub_msdos_partition_is_empty (e->type)
&& ! grub_msdos_partition_is_extended (e->type))
{
p.number++;
return grub_errno;
}
else if (p.number < 4)
/* If this partition is a logical one, shouldn't increase the
partition number. */
p.number++;
}
/* Find an extended partition. */
for (i = 0; i < 4; i++)
{
if (grub_msdos_partition_is_extended (e->type))
{
p.offset = ext_offset
+ (grub_le_to_cpu32 (e->start)
if (! ext_offset)
ext_offset = p.offset;
break;
}
}
/* If no extended partition, the end. */
if (i == 4)
break;
}
return grub_errno;
}
#ifdef GRUB_UTIL
static grub_err_t
{
int labeln = 0;
/* Any value different than `p.offset' will satisfy the check during
first loop. */
if (embed_type != GRUB_EMBED_PCBIOS)
return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
"PC-style partitions curently support "
"only PC-BIOS embedding");
return grub_error (GRUB_ERR_OUT_OF_RANGE,
"Embedding on MSDOS subpartition isn't supported");
while (1)
{
int i;
struct grub_msdos_partition_entry *e;
/* Read the MBR. */
if (err)
return err;
/* This is our loop-detection algorithm. It works the following way:
It saves last position which was a power of two. Then it compares the
saved value with a current one. This way it's guaranteed that the loop
will be broken by at most third walk.
*/
labeln++;
/* Check if it is valid. */
for (i = 0; i < 4; i++)
/* Analyze DOS partitions. */
for (i = 0; i < 4; i++)
{
if (!grub_msdos_partition_is_empty (e->type)
+ (grub_le_to_cpu32 (e->start)
/* If this is a GPT partition, this MBR is just a dummy. */
if (e->type == GRUB_PC_PARTITION_TYPE_GPT_DISK && i == 0)
}
/* Find an extended partition. */
for (i = 0; i < 4; i++)
{
if (grub_msdos_partition_is_extended (e->type))
{
+ (grub_le_to_cpu32 (e->start)
if (! ext_offset)
ext_offset = offset;
break;
}
}
/* If no extended partition, the end. */
if (i == 4)
break;
}
{
unsigned i;
if (!*sectors)
return grub_errno;
for (i = 0; i < *nsectors; i++)
(*sectors)[i] = 1 + i;
return GRUB_ERR_NONE;
}
if (end <= 1)
return grub_error (GRUB_ERR_FILE_NOT_FOUND,
"This msdos-style partition label has no "
"post-MBR gap; embedding won't be possible!");
if (*nsectors > 62)
return grub_error (GRUB_ERR_OUT_OF_RANGE,
"Your core.img is unusually large. "
"It won't fit in the embedding area.");
return grub_error (GRUB_ERR_OUT_OF_RANGE,
"Your embedding area is unusually small. "
"core.img won't fit in it.");
}
#endif
/* Partition map type. */
{
.name = "msdos",
#ifdef GRUB_UTIL
#endif
};
{
}
{
}