2009-04-06 09:51:01 +00:00
|
|
|
/* pcpart.c - manipulate fdisk partitions */
|
|
|
|
/*
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
|
|
|
* Copyright (C) 2009 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <grub/types.h>
|
|
|
|
#include <grub/misc.h>
|
|
|
|
#include <grub/mm.h>
|
|
|
|
#include <grub/err.h>
|
2009-08-23 Robert Millan <rmh.grub@aybabtu.com>
* partmap/pc.c: Rename to ...
* partmap/msdos.c: ... this. Update all users.
(grub_pc_partition_map): Rename to ...
(grub_msdos_partition_map): ... this. Update all users.
* parttool/pcpart.c: Rename to ...
* parttool/msdospart.c: ... this. Update all users.
* include/grub/pc_partition.h: Rename to ...
* include/grub/msdos_partition.h: ... this. Update all users.
(grub_pc_partition_bsd_entry): Rename to ...
(grub_msdos_partition_bsd_entry): ... this. Update all users.
(grub_pc_partition_disk_label): Rename to ...
(grub_msdos_partition_disk_label): ... this. Update all users.
(grub_pc_partition_entry): Rename to ...
(grub_msdos_partition_entry): ... this. Update all users.
(grub_pc_partition_mbr): Rename to ...
(grub_msdos_partition_mbr): ... this. Update all users.
(grub_pc_partition): Rename to ...
(grub_msdos_partition): ... this. Update all users.
(grub_pc_partition_is_empty): Rename to ...
(grub_msdos_partition_is_empty): ... this. Update all users.
(grub_pc_partition_is_extended): Rename to ...
(grub_msdos_partition_is_extended): ... this. Update all users.
(grub_pc_partition_is_bsd): Rename to ...
(grub_msdos_partition_is_bsd): ... this. Update all users.
* conf/common.rmk (amiga_mod_SOURCES, amiga_mod_CFLAGS)
(amiga_mod_LDFLAGS, apple_mod_SOURCES, apple_mod_CFLAGS)
(apple_mod_LDFLAGS, msdos_mod_SOURCES, msdos_mod_CFLAGS)
(msdos_mod_LDFLAGS, sun_mod_SOURCES, sun_mod_CFLAGS)
(sun_mod_LDFLAGS, acorn_mod_SOURCES, acorn_mod_CFLAGS)
(acorn_mod_LDFLAGS, gpt_mod_SOURCES, gpt_mod_CFLAGS)
(gpt_mod_LDFLAGS): Rename to ...
(part_amiga_mod_SOURCES, part_amiga_mod_CFLAGS, part_amiga_mod_LDFLAGS)
(part_apple_mod_SOURCES, part_apple_mod_CFLAGS, part_apple_mod_LDFLAGS)
(part_msdos_mod_SOURCES, part_msdos_mod_CFLAGS, part_msdos_mod_LDFLAGS)
(part_sun_mod_SOURCES, part_sun_mod_CFLAGS, part_sun_mod_LDFLAGS)
(part_acorn_mod_SOURCES, part_acorn_mod_CFLAGS, part_acorn_mod_LDFLAGS)
(part_gpt_mod_SOURCES, part_gpt_mod_CFLAGS)
(part_gpt_mod_LDFLAGS): ... this.
(pkglib_MODULES): Prefix partition modules with `part_'. Rename
`pcpart.mod' to `msdospart.mod'.
(pcpart_mod_SOURCES, pcpart_mod_CFLAGS, pcpart_mod_LDFLAGS): Rename
to ...
(msdospart_mod_SOURCES, msdospart_mod_CFLAGS)
(msdospart_mod_LDFLAGS): ... this.
2009-08-23 12:00:57 +00:00
|
|
|
#include <grub/msdos_partition.h>
|
2009-04-06 09:51:01 +00:00
|
|
|
#include <grub/device.h>
|
|
|
|
#include <grub/disk.h>
|
|
|
|
#include <grub/partition.h>
|
|
|
|
#include <grub/parttool.h>
|
|
|
|
|
2011-04-11 21:01:51 +00:00
|
|
|
GRUB_MOD_LICENSE ("GPLv2+");
|
|
|
|
|
2009-04-06 09:51:01 +00:00
|
|
|
static int activate_table_handle = -1;
|
|
|
|
static int type_table_handle = -1;
|
|
|
|
|
|
|
|
static struct grub_parttool_argdesc grub_pcpart_bootargs[] =
|
|
|
|
{
|
|
|
|
{"boot", "Make partition active", GRUB_PARTTOOL_ARG_BOOL},
|
|
|
|
{0, 0, 0}
|
|
|
|
};
|
|
|
|
|
2009-06-10 21:04:23 +00:00
|
|
|
static grub_err_t grub_pcpart_boot (const grub_device_t dev,
|
2009-04-06 09:51:01 +00:00
|
|
|
const struct grub_parttool_args *args)
|
|
|
|
{
|
|
|
|
int i, index;
|
|
|
|
grub_partition_t part;
|
2009-08-23 Robert Millan <rmh.grub@aybabtu.com>
* partmap/pc.c: Rename to ...
* partmap/msdos.c: ... this. Update all users.
(grub_pc_partition_map): Rename to ...
(grub_msdos_partition_map): ... this. Update all users.
* parttool/pcpart.c: Rename to ...
* parttool/msdospart.c: ... this. Update all users.
* include/grub/pc_partition.h: Rename to ...
* include/grub/msdos_partition.h: ... this. Update all users.
(grub_pc_partition_bsd_entry): Rename to ...
(grub_msdos_partition_bsd_entry): ... this. Update all users.
(grub_pc_partition_disk_label): Rename to ...
(grub_msdos_partition_disk_label): ... this. Update all users.
(grub_pc_partition_entry): Rename to ...
(grub_msdos_partition_entry): ... this. Update all users.
(grub_pc_partition_mbr): Rename to ...
(grub_msdos_partition_mbr): ... this. Update all users.
(grub_pc_partition): Rename to ...
(grub_msdos_partition): ... this. Update all users.
(grub_pc_partition_is_empty): Rename to ...
(grub_msdos_partition_is_empty): ... this. Update all users.
(grub_pc_partition_is_extended): Rename to ...
(grub_msdos_partition_is_extended): ... this. Update all users.
(grub_pc_partition_is_bsd): Rename to ...
(grub_msdos_partition_is_bsd): ... this. Update all users.
* conf/common.rmk (amiga_mod_SOURCES, amiga_mod_CFLAGS)
(amiga_mod_LDFLAGS, apple_mod_SOURCES, apple_mod_CFLAGS)
(apple_mod_LDFLAGS, msdos_mod_SOURCES, msdos_mod_CFLAGS)
(msdos_mod_LDFLAGS, sun_mod_SOURCES, sun_mod_CFLAGS)
(sun_mod_LDFLAGS, acorn_mod_SOURCES, acorn_mod_CFLAGS)
(acorn_mod_LDFLAGS, gpt_mod_SOURCES, gpt_mod_CFLAGS)
(gpt_mod_LDFLAGS): Rename to ...
(part_amiga_mod_SOURCES, part_amiga_mod_CFLAGS, part_amiga_mod_LDFLAGS)
(part_apple_mod_SOURCES, part_apple_mod_CFLAGS, part_apple_mod_LDFLAGS)
(part_msdos_mod_SOURCES, part_msdos_mod_CFLAGS, part_msdos_mod_LDFLAGS)
(part_sun_mod_SOURCES, part_sun_mod_CFLAGS, part_sun_mod_LDFLAGS)
(part_acorn_mod_SOURCES, part_acorn_mod_CFLAGS, part_acorn_mod_LDFLAGS)
(part_gpt_mod_SOURCES, part_gpt_mod_CFLAGS)
(part_gpt_mod_LDFLAGS): ... this.
(pkglib_MODULES): Prefix partition modules with `part_'. Rename
`pcpart.mod' to `msdospart.mod'.
(pcpart_mod_SOURCES, pcpart_mod_CFLAGS, pcpart_mod_LDFLAGS): Rename
to ...
(msdospart_mod_SOURCES, msdospart_mod_CFLAGS)
(msdospart_mod_LDFLAGS): ... this.
2009-08-23 12:00:57 +00:00
|
|
|
struct grub_msdos_partition_mbr mbr;
|
2009-04-06 09:51:01 +00:00
|
|
|
|
|
|
|
if (dev->disk->partition->offset)
|
|
|
|
return grub_error (GRUB_ERR_BAD_ARGUMENT, "not a primary partition");
|
|
|
|
|
|
|
|
index = dev->disk->partition->index;
|
|
|
|
part = dev->disk->partition;
|
2010-02-06 17:43:37 +00:00
|
|
|
dev->disk->partition = part->parent;
|
2009-04-06 09:51:01 +00:00
|
|
|
|
|
|
|
/* Read the MBR. */
|
2009-05-13 18:58:38 +00:00
|
|
|
if (grub_disk_read (dev->disk, 0, 0, sizeof (mbr), &mbr))
|
2009-04-06 09:51:01 +00:00
|
|
|
{
|
|
|
|
dev->disk->partition = part;
|
|
|
|
return grub_errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args[0].set && args[0].bool)
|
|
|
|
{
|
|
|
|
for (i = 0; i < 4; i++)
|
|
|
|
mbr.entries[i].flag = 0x0;
|
|
|
|
mbr.entries[index].flag = 0x80;
|
2009-04-25 12:18:25 +00:00
|
|
|
grub_printf ("Partition %d is active now. \n", index);
|
2009-04-06 09:51:01 +00:00
|
|
|
}
|
|
|
|
else
|
2009-04-25 12:18:25 +00:00
|
|
|
{
|
|
|
|
mbr.entries[index].flag = 0x0;
|
|
|
|
grub_printf ("Cleared active flag on %d. \n", index);
|
|
|
|
}
|
2009-04-06 09:51:01 +00:00
|
|
|
|
|
|
|
/* Write the MBR. */
|
2009-05-13 18:58:38 +00:00
|
|
|
grub_disk_write (dev->disk, 0, 0, sizeof (mbr), &mbr);
|
2009-04-06 09:51:01 +00:00
|
|
|
|
|
|
|
dev->disk->partition = part;
|
|
|
|
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct grub_parttool_argdesc grub_pcpart_typeargs[] =
|
|
|
|
{
|
|
|
|
{"type", "Change partition type", GRUB_PARTTOOL_ARG_VAL},
|
|
|
|
{"hidden", "Make partition hidden", GRUB_PARTTOOL_ARG_BOOL},
|
|
|
|
{0, 0, 0}
|
|
|
|
};
|
|
|
|
|
2009-06-10 21:04:23 +00:00
|
|
|
static grub_err_t grub_pcpart_type (const grub_device_t dev,
|
2009-04-06 09:51:01 +00:00
|
|
|
const struct grub_parttool_args *args)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
grub_uint8_t type;
|
|
|
|
grub_partition_t part;
|
2009-08-23 Robert Millan <rmh.grub@aybabtu.com>
* partmap/pc.c: Rename to ...
* partmap/msdos.c: ... this. Update all users.
(grub_pc_partition_map): Rename to ...
(grub_msdos_partition_map): ... this. Update all users.
* parttool/pcpart.c: Rename to ...
* parttool/msdospart.c: ... this. Update all users.
* include/grub/pc_partition.h: Rename to ...
* include/grub/msdos_partition.h: ... this. Update all users.
(grub_pc_partition_bsd_entry): Rename to ...
(grub_msdos_partition_bsd_entry): ... this. Update all users.
(grub_pc_partition_disk_label): Rename to ...
(grub_msdos_partition_disk_label): ... this. Update all users.
(grub_pc_partition_entry): Rename to ...
(grub_msdos_partition_entry): ... this. Update all users.
(grub_pc_partition_mbr): Rename to ...
(grub_msdos_partition_mbr): ... this. Update all users.
(grub_pc_partition): Rename to ...
(grub_msdos_partition): ... this. Update all users.
(grub_pc_partition_is_empty): Rename to ...
(grub_msdos_partition_is_empty): ... this. Update all users.
(grub_pc_partition_is_extended): Rename to ...
(grub_msdos_partition_is_extended): ... this. Update all users.
(grub_pc_partition_is_bsd): Rename to ...
(grub_msdos_partition_is_bsd): ... this. Update all users.
* conf/common.rmk (amiga_mod_SOURCES, amiga_mod_CFLAGS)
(amiga_mod_LDFLAGS, apple_mod_SOURCES, apple_mod_CFLAGS)
(apple_mod_LDFLAGS, msdos_mod_SOURCES, msdos_mod_CFLAGS)
(msdos_mod_LDFLAGS, sun_mod_SOURCES, sun_mod_CFLAGS)
(sun_mod_LDFLAGS, acorn_mod_SOURCES, acorn_mod_CFLAGS)
(acorn_mod_LDFLAGS, gpt_mod_SOURCES, gpt_mod_CFLAGS)
(gpt_mod_LDFLAGS): Rename to ...
(part_amiga_mod_SOURCES, part_amiga_mod_CFLAGS, part_amiga_mod_LDFLAGS)
(part_apple_mod_SOURCES, part_apple_mod_CFLAGS, part_apple_mod_LDFLAGS)
(part_msdos_mod_SOURCES, part_msdos_mod_CFLAGS, part_msdos_mod_LDFLAGS)
(part_sun_mod_SOURCES, part_sun_mod_CFLAGS, part_sun_mod_LDFLAGS)
(part_acorn_mod_SOURCES, part_acorn_mod_CFLAGS, part_acorn_mod_LDFLAGS)
(part_gpt_mod_SOURCES, part_gpt_mod_CFLAGS)
(part_gpt_mod_LDFLAGS): ... this.
(pkglib_MODULES): Prefix partition modules with `part_'. Rename
`pcpart.mod' to `msdospart.mod'.
(pcpart_mod_SOURCES, pcpart_mod_CFLAGS, pcpart_mod_LDFLAGS): Rename
to ...
(msdospart_mod_SOURCES, msdospart_mod_CFLAGS)
(msdospart_mod_LDFLAGS): ... this.
2009-08-23 12:00:57 +00:00
|
|
|
struct grub_msdos_partition_mbr mbr;
|
2009-04-06 09:51:01 +00:00
|
|
|
|
|
|
|
index = dev->disk->partition->index;
|
|
|
|
part = dev->disk->partition;
|
2010-02-06 17:43:37 +00:00
|
|
|
dev->disk->partition = part->parent;
|
2009-04-06 09:51:01 +00:00
|
|
|
|
|
|
|
/* Read the parttable. */
|
2009-06-10 21:04:23 +00:00
|
|
|
if (grub_disk_read (dev->disk, part->offset, 0,
|
2009-05-13 18:58:38 +00:00
|
|
|
sizeof (mbr), &mbr))
|
2009-04-06 09:51:01 +00:00
|
|
|
{
|
|
|
|
dev->disk->partition = part;
|
|
|
|
return grub_errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args[0].set)
|
|
|
|
type = grub_strtoul (args[0].str, 0, 0);
|
|
|
|
else
|
|
|
|
type = mbr.entries[index].type;
|
|
|
|
|
|
|
|
if (args[1].set)
|
|
|
|
{
|
|
|
|
if (args[1].bool)
|
|
|
|
type |= GRUB_PC_PARTITION_TYPE_HIDDEN_FLAG;
|
|
|
|
else
|
|
|
|
type &= ~GRUB_PC_PARTITION_TYPE_HIDDEN_FLAG;
|
|
|
|
}
|
|
|
|
|
2009-08-23 Robert Millan <rmh.grub@aybabtu.com>
* partmap/pc.c: Rename to ...
* partmap/msdos.c: ... this. Update all users.
(grub_pc_partition_map): Rename to ...
(grub_msdos_partition_map): ... this. Update all users.
* parttool/pcpart.c: Rename to ...
* parttool/msdospart.c: ... this. Update all users.
* include/grub/pc_partition.h: Rename to ...
* include/grub/msdos_partition.h: ... this. Update all users.
(grub_pc_partition_bsd_entry): Rename to ...
(grub_msdos_partition_bsd_entry): ... this. Update all users.
(grub_pc_partition_disk_label): Rename to ...
(grub_msdos_partition_disk_label): ... this. Update all users.
(grub_pc_partition_entry): Rename to ...
(grub_msdos_partition_entry): ... this. Update all users.
(grub_pc_partition_mbr): Rename to ...
(grub_msdos_partition_mbr): ... this. Update all users.
(grub_pc_partition): Rename to ...
(grub_msdos_partition): ... this. Update all users.
(grub_pc_partition_is_empty): Rename to ...
(grub_msdos_partition_is_empty): ... this. Update all users.
(grub_pc_partition_is_extended): Rename to ...
(grub_msdos_partition_is_extended): ... this. Update all users.
(grub_pc_partition_is_bsd): Rename to ...
(grub_msdos_partition_is_bsd): ... this. Update all users.
* conf/common.rmk (amiga_mod_SOURCES, amiga_mod_CFLAGS)
(amiga_mod_LDFLAGS, apple_mod_SOURCES, apple_mod_CFLAGS)
(apple_mod_LDFLAGS, msdos_mod_SOURCES, msdos_mod_CFLAGS)
(msdos_mod_LDFLAGS, sun_mod_SOURCES, sun_mod_CFLAGS)
(sun_mod_LDFLAGS, acorn_mod_SOURCES, acorn_mod_CFLAGS)
(acorn_mod_LDFLAGS, gpt_mod_SOURCES, gpt_mod_CFLAGS)
(gpt_mod_LDFLAGS): Rename to ...
(part_amiga_mod_SOURCES, part_amiga_mod_CFLAGS, part_amiga_mod_LDFLAGS)
(part_apple_mod_SOURCES, part_apple_mod_CFLAGS, part_apple_mod_LDFLAGS)
(part_msdos_mod_SOURCES, part_msdos_mod_CFLAGS, part_msdos_mod_LDFLAGS)
(part_sun_mod_SOURCES, part_sun_mod_CFLAGS, part_sun_mod_LDFLAGS)
(part_acorn_mod_SOURCES, part_acorn_mod_CFLAGS, part_acorn_mod_LDFLAGS)
(part_gpt_mod_SOURCES, part_gpt_mod_CFLAGS)
(part_gpt_mod_LDFLAGS): ... this.
(pkglib_MODULES): Prefix partition modules with `part_'. Rename
`pcpart.mod' to `msdospart.mod'.
(pcpart_mod_SOURCES, pcpart_mod_CFLAGS, pcpart_mod_LDFLAGS): Rename
to ...
(msdospart_mod_SOURCES, msdospart_mod_CFLAGS)
(msdospart_mod_LDFLAGS): ... this.
2009-08-23 12:00:57 +00:00
|
|
|
if (grub_msdos_partition_is_empty (type)
|
|
|
|
|| grub_msdos_partition_is_extended (type))
|
2009-04-06 09:51:01 +00:00
|
|
|
{
|
|
|
|
dev->disk->partition = part;
|
|
|
|
return grub_error (GRUB_ERR_BAD_ARGUMENT, "invalid type");
|
|
|
|
}
|
|
|
|
|
|
|
|
mbr.entries[index].type = type;
|
2009-04-25 12:18:25 +00:00
|
|
|
grub_printf ("Setting partition type to 0x%x\n", type);
|
2009-04-06 09:51:01 +00:00
|
|
|
|
|
|
|
/* Write the parttable. */
|
2009-06-10 21:04:23 +00:00
|
|
|
grub_disk_write (dev->disk, part->offset, 0,
|
2009-05-13 18:58:38 +00:00
|
|
|
sizeof (mbr), &mbr);
|
2009-04-06 09:51:01 +00:00
|
|
|
|
|
|
|
dev->disk->partition = part;
|
|
|
|
|
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
}
|
|
|
|
|
2010-02-07 01:07:35 +00:00
|
|
|
GRUB_MOD_INIT (msdospart)
|
2009-04-06 09:51:01 +00:00
|
|
|
{
|
2010-02-06 18:33:53 +00:00
|
|
|
activate_table_handle = grub_parttool_register ("msdos",
|
2009-04-06 09:51:01 +00:00
|
|
|
grub_pcpart_boot,
|
|
|
|
grub_pcpart_bootargs);
|
2010-02-06 18:33:53 +00:00
|
|
|
type_table_handle = grub_parttool_register ("msdos",
|
2009-04-06 09:51:01 +00:00
|
|
|
grub_pcpart_type,
|
|
|
|
grub_pcpart_typeargs);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-04-06 09:51:01 +00:00
|
|
|
}
|
2010-02-07 01:07:35 +00:00
|
|
|
GRUB_MOD_FINI(msdospart)
|
2009-04-06 09:51:01 +00:00
|
|
|
{
|
|
|
|
grub_parttool_unregister (activate_table_handle);
|
|
|
|
grub_parttool_unregister (type_table_handle);
|
|
|
|
}
|