All of lore.kernel.org
 help / color / mirror / Atom feed
From: phcoder <phcoder@gmail.com>
To: The development of GRUB 2 <grub-devel@gnu.org>
Subject: [PATCH] make partition active
Date: Wed, 11 Feb 2009 14:43:31 +0100	[thread overview]
Message-ID: <4992D603.9030105@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 159 bytes --]

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

[-- Attachment #2: activate.patch --]
[-- Type: text/x-diff, Size: 4990 bytes --]

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 1989)
+++ ChangeLog	(working copy)
@@ -1,3 +1,11 @@
+2009-02-11  Vladimir Serbinenko  <phcoder@gmail.com>
+
+	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  <rmh@aybabtu.com>
 
 	* 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 <gniibe@m17n.org>
+ *
+ *  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");
+}

             reply	other threads:[~2009-02-11 13:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-11 13:43 phcoder [this message]
2009-02-11 16:26 ` [PATCH] make partition active Pavel Roskin
2009-02-11 18:28   ` phcoder
2009-03-01 18:58     ` Bean
2009-03-01 21:20       ` phcoder
2009-03-02  3:52         ` Bean
2009-03-04 20:54           ` Robert Millan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4992D603.9030105@gmail.com \
    --to=phcoder@gmail.com \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.