All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] make partition active
@ 2009-02-11 13:43 phcoder
  2009-02-11 16:26 ` Pavel Roskin
  0 siblings, 1 reply; 7+ messages in thread
From: phcoder @ 2009-02-11 13:43 UTC (permalink / raw)
  To: The development of GRUB 2

[-- 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");
+}

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] make partition active
  2009-02-11 13:43 [PATCH] make partition active phcoder
@ 2009-02-11 16:26 ` Pavel Roskin
  2009-02-11 18:28   ` phcoder
  0 siblings, 1 reply; 7+ messages in thread
From: Pavel Roskin @ 2009-02-11 16:26 UTC (permalink / raw)
  To: The development of GRUB 2

On Wed, 2009-02-11 at 14:43 +0100, phcoder wrote:
> Here's the patch to add a replacement for old "makeactive" command
> New syntax is
> activate PARTITION
> E.g.
> activate hd0,1

Is it necessary to change the name?  I think "makeactive" is a better
name for what it does.

Maybe we could use a more generic solution, e.g. a command for setting
different flags (or "attributes" in GPT terminology), such as bootable,
read-only, hidden (that would apply only to some partition types in the
PC partition table) and so on.

-- 
Regards,
Pavel Roskin



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] make partition active
  2009-02-11 16:26 ` Pavel Roskin
@ 2009-02-11 18:28   ` phcoder
  2009-03-01 18:58     ` Bean
  0 siblings, 1 reply; 7+ messages in thread
From: phcoder @ 2009-02-11 18:28 UTC (permalink / raw)
  To: The development of GRUB 2

Pavel Roskin wrote:
> On Wed, 2009-02-11 at 14:43 +0100, phcoder wrote:
>> Here's the patch to add a replacement for old "makeactive" command
>> New syntax is
>> activate PARTITION
>> E.g.
>> activate hd0,1
> 
> Is it necessary to change the name?  I think "makeactive" is a better
> name for what it does.
Actually I don't really care but on http://grub.enbug.org/CommandList it 
was suggested to change the name. But what I dislike is having this 
command without argument which always activates current root partition
> 
> Maybe we could use a more generic solution, e.g. a command for setting
> different flags (or "attributes" in GPT terminology), such as bootable,
> read-only, hidden (that would apply only to some partition types in the
> PC partition table) and so on.

It's a good possibility but I don't want to encumber the partition 
module with non-essential functions since they're often integrated into 
core.img. But it's possible to have something like

pctool hd0,1 boot+ hidden-
gpttool hd0,1 ro+

(Actually I find the name "pc" unfortunate, IMO "fdisk" would be much 
better)
It's also possible to write a wrapper
parttool hd0,1 boot+

Which chooses the correct tool and launches it (a tool can be easily 
registered as a pair of partition style name and a function). In this 
case we wouldn't even need separate command for different partition 
style. We have however to find a way to list all available flags in

help parttool

Regards
Vladimir 'phcoder' Serbinenko





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] make partition active
  2009-02-11 18:28   ` phcoder
@ 2009-03-01 18:58     ` Bean
  2009-03-01 21:20       ` phcoder
  0 siblings, 1 reply; 7+ messages in thread
From: Bean @ 2009-03-01 18:58 UTC (permalink / raw)
  To: The development of GRUB 2

On Thu, Feb 12, 2009 at 2:28 AM, phcoder <phcoder@gmail.com> wrote:
> Pavel Roskin wrote:
>>
>> On Wed, 2009-02-11 at 14:43 +0100, phcoder wrote:
>>>
>>> Here's the patch to add a replacement for old "makeactive" command
>>> New syntax is
>>> activate PARTITION
>>> E.g.
>>> activate hd0,1
>>
>> Is it necessary to change the name?  I think "makeactive" is a better
>> name for what it does.
>
> Actually I don't really care but on http://grub.enbug.org/CommandList it was
> suggested to change the name. But what I dislike is having this command
> without argument which always activates current root partition
>>
>> Maybe we could use a more generic solution, e.g. a command for setting
>> different flags (or "attributes" in GPT terminology), such as bootable,
>> read-only, hidden (that would apply only to some partition types in the
>> PC partition table) and so on.
>
> It's a good possibility but I don't want to encumber the partition module
> with non-essential functions since they're often integrated into core.img.
> But it's possible to have something like
>
> pctool hd0,1 boot+ hidden-
> gpttool hd0,1 ro+
>
> (Actually I find the name "pc" unfortunate, IMO "fdisk" would be much
> better)
> It's also possible to write a wrapper
> parttool hd0,1 boot+
>
> Which chooses the correct tool and launches it (a tool can be easily
> registered as a pair of partition style name and a function). In this case
> we wouldn't even need separate command for different partition style. We
> have however to find a way to list all available flags in
>
> help parttool

Hi,

The patch looks fine to me, except for perhaps the name. activate
doesn't seems to suggest its function. Frankly, makeactive doesn't
make much sense as well, but at least it's already widely used in grub
legacy, old user could easily guess its function by name.

-- 
Bean



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] make partition active
  2009-03-01 18:58     ` Bean
@ 2009-03-01 21:20       ` phcoder
  2009-03-02  3:52         ` Bean
  0 siblings, 1 reply; 7+ messages in thread
From: phcoder @ 2009-03-01 21:20 UTC (permalink / raw)
  To: The development of GRUB 2

Hello
>> It's also possible to write a wrapper
>> parttool hd0,1 boot+
>>
>> Which chooses the correct tool and launches it (a tool can be easily
>> registered as a pair of partition style name and a function). In this case
>> we wouldn't even need separate command for different partition style. We
>> have however to find a way to list all available flags in
>>
>> help parttool
> 
> Hi,
> 
> The patch looks fine to me, except for perhaps the name. activate
> doesn't seems to suggest its function. Frankly, makeactive doesn't
> make much sense as well, but at least it's already widely used in grub
> legacy, old user could easily guess its function by name.
> 
Then we could use parttool syntax. Then parttype can be implemented like
grub> parttool hd0,1 type=7
makeactive like:
grub> parttool hd0,1 boot+
And it can even be done by one command
grub> parttool hd0,1 boot+ type=7

Thank you for your attention to my patches



-- 

Regards
Vladimir 'phcoder' Serbinenko



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] make partition active
  2009-03-01 21:20       ` phcoder
@ 2009-03-02  3:52         ` Bean
  2009-03-04 20:54           ` Robert Millan
  0 siblings, 1 reply; 7+ messages in thread
From: Bean @ 2009-03-02  3:52 UTC (permalink / raw)
  To: The development of GRUB 2

On Mon, Mar 2, 2009 at 5:20 AM, phcoder <phcoder@gmail.com> wrote:
> Hello
>>>
>>> It's also possible to write a wrapper
>>> parttool hd0,1 boot+
>>>
>>> Which chooses the correct tool and launches it (a tool can be easily
>>> registered as a pair of partition style name and a function). In this
>>> case
>>> we wouldn't even need separate command for different partition style. We
>>> have however to find a way to list all available flags in
>>>
>>> help parttool
>>
>> Hi,
>>
>> The patch looks fine to me, except for perhaps the name. activate
>> doesn't seems to suggest its function. Frankly, makeactive doesn't
>> make much sense as well, but at least it's already widely used in grub
>> legacy, old user could easily guess its function by name.
>>
> Then we could use parttool syntax. Then parttype can be implemented like
> grub> parttool hd0,1 type=7
> makeactive like:
> grub> parttool hd0,1 boot+
> And it can even be done by one command
> grub> parttool hd0,1 boot+ type=7
>
> Thank you for your attention to my patches

Hi,

In that case, you might want to use options, which save you the
trouble of parsing parameters yourself, for example:

parttool [--boot] [--type N] partition

-- 
Bean



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] make partition active
  2009-03-02  3:52         ` Bean
@ 2009-03-04 20:54           ` Robert Millan
  0 siblings, 0 replies; 7+ messages in thread
From: Robert Millan @ 2009-03-04 20:54 UTC (permalink / raw)
  To: The development of GRUB 2

On Mon, Mar 02, 2009 at 11:52:13AM +0800, Bean wrote:
> > Then we could use parttool syntax. Then parttype can be implemented like
> > grub> parttool hd0,1 type=7
> > makeactive like:
> > grub> parttool hd0,1 boot+
> > And it can even be done by one command
> > grub> parttool hd0,1 boot+ type=7
> >
> > Thank you for your attention to my patches
> 
> Hi,
> 
> In that case, you might want to use options, which save you the
> trouble of parsing parameters yourself, for example:
> 
> parttool [--boot] [--type N] partition

Why don't we make the syntax compatible with Parted?  It supports
non-interactive mode, and is also a GNU project.  Some consistency
between it and GRUB would be nice IMO.

(besides, there's also that project to integrate Parted with GRUB directly,
it used to be in gsoc)

-- 
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-03-04 20:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-11 13:43 [PATCH] make partition active phcoder
2009-02-11 16:26 ` 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

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.