[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] make partition active
From: |
phcoder |
Subject: |
[PATCH] make partition active |
Date: |
Wed, 11 Feb 2009 14:43:31 +0100 |
User-agent: |
Thunderbird 2.0.0.19 (X11/20090105) |
Here's the patch to add a replacement for old "makeactive" command
New syntax is
activate PARTITION
E.g.
activate hd0,1
Regards
Vladimir 'phcoder' Serbinenko
Index: ChangeLog
===================================================================
--- ChangeLog (revision 1989)
+++ ChangeLog (working copy)
@@ -1,3 +1,11 @@
+2009-02-11 Vladimir Serbinenko <address@hidden>
+
+ New command: "activate" replacement for makeactive of grub1
+
+ * commands/i386/pc/activate.c: new file
+ * conf/i386-pc.rmk: new module activate.mod
+ add commands/i386/pc/activate.c to grub-emu sources
+
2009-02-11 Robert Millan <address@hidden>
* util/grub.d/00_header.in: Update old reference to `font' command.
Index: conf/i386-pc.rmk
===================================================================
--- conf/i386-pc.rmk (revision 1989)
+++ conf/i386-pc.rmk (working copy)
@@ -145,4 +145,4 @@
\
disk/raid.c disk/raid5_recover.c disk/raid6_recover.c \
disk/mdraid_linux.c disk/dmraid_nvidia.c disk/lvm.c \
- grub_emu_init.c
+ grub_emu_init.c commands/i386/pc/activate.c
grub_emu_LDFLAGS = $(LIBCURSES)
ifeq ($(enable_grub_emu_usb), yes)
@@ -171,3 +170,3 @@
vbe.mod vbetest.mod vbeinfo.mod play.mod serial.mod \
ata.mod vga.mod memdisk.mod pci.mod lspci.mod \
aout.mod _bsd.mod bsd.mod pxe.mod pxecmd.mod datetime.mod date.mod \
datehook.mod lsmmap.mod \
- usb.mod uhci.mod ohci.mod usbtest.mod usbms.mod
+ usb.mod uhci.mod ohci.mod usbtest.mod usbms.mod activate.mod
+# For activate.mod.
+activate_mod_SOURCES = commands/i386/pc/activate.c
+activate_mod_CFLAGS = $(COMMON_CFLAGS)
+activate_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
# For biosdisk.mod.
biosdisk_mod_SOURCES = disk/i386/pc/biosdisk.c
biosdisk_mod_CFLAGS = $(COMMON_CFLAGS)
Index: commands/i386/pc/activate.c
===================================================================
--- commands/i386/pc/activate.c (revision 0)
+++ commands/i386/pc/activate.c (revision 0)
@@ -0,0 +1,114 @@
+/* activate.c - activate pc partition */
+/*
+ * GRUB -- GRand Unified Bootloader
+ * Copyright (C) 2003 Free Software Foundation, Inc.
+ * Copyright (C) 2003 NIIBE Yutaka <address@hidden>
+ *
+ * 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>
+#include <grub/dl.h>
+#include <grub/normal.h>
+#include <grub/pc_partition.h>
+#include <grub/device.h>
+#include <grub/disk.h>
+#include <grub/partition.h>
+
+static grub_err_t
+grub_cmd_activate (struct grub_arg_list *state __attribute__ ((unused)),
+ int argc, char **args)
+{
+
+ grub_device_t dev;
+ struct grub_pc_partition_mbr mbr;
+ grub_partition_t part;
+
+ int i, index;
+
+ if (argc > 1)
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, "too many arguments");
+
+ if (!argc)
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, "too few arguments");
+
+ dev = grub_device_open (args[0]);
+
+ if (!dev)
+ return grub_errno;
+
+ if (!dev->disk)
+ {
+ grub_device_close (dev);
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, "not a disk");
+ }
+
+ if (!dev->disk->partition)
+ {
+ grub_device_close (dev);
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, "not a partition");
+ }
+
+ if (grub_strcmp (dev->disk->partition->partmap->name, "pc_partition_map"))
+ {
+ grub_device_close (dev);
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, "not a pc partition");
+ }
+
+ if (dev->disk->partition->offset)
+ {
+ grub_device_close (dev);
+ return grub_error (GRUB_ERR_BAD_ARGUMENT, "not a primary partition");
+ }
+
+ index = dev->disk->partition->index;
+ part = dev->disk->partition;
+ dev->disk->partition = 0;
+
+ /* Read the MBR. */
+ if (grub_disk_read (dev->disk, 0, 0, sizeof (mbr), (char *) &mbr))
+ {
+ dev->disk->partition = part;
+ grub_device_close (dev);
+ return grub_errno;
+ }
+
+ for (i = 0; i < 4; i++)
+ mbr.entries[i].flag = 0x0;
+
+ mbr.entries[index].flag = 0x80;
+
+ /* Write the MBR. */
+ grub_disk_write (dev->disk, 0, 0, sizeof (mbr), (char *) &mbr);
+ dev->disk->partition = part;
+ grub_device_close (dev);
+ return grub_errno;
+
+}
+
+GRUB_MOD_INIT(activate)
+{
+ (void)mod; /* To stop warning. */
+ grub_register_command ("activate", grub_cmd_activate, GRUB_COMMAND_FLAG_BOTH,
+ "activate PARTITION", "set active flag to PARTITION",
0);
+}
+
+GRUB_MOD_FINI(activate)
+{
+ grub_unregister_command ("activate");
+}
- [PATCH] make partition active,
phcoder <=