From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1HzsiC-0004xL-8d for mharc-grub-devel@gnu.org; Sun, 17 Jun 2007 07:14:28 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HzsiA-0004wx-12 for grub-devel@gnu.org; Sun, 17 Jun 2007 07:14:26 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Hzsi8-0004w4-5l for grub-devel@gnu.org; Sun, 17 Jun 2007 07:14:25 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Hzsi7-0004vx-SM for grub-devel@gnu.org; Sun, 17 Jun 2007 07:14:23 -0400 Received: from mu-out-0910.google.com ([209.85.134.186]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Hzsi7-0006gq-7C for grub-devel@gnu.org; Sun, 17 Jun 2007 07:14:23 -0400 Received: by mu-out-0910.google.com with SMTP id g7so1510610muf for ; Sun, 17 Jun 2007 04:14:22 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:user-agent:x-accept-language:mime-version:to:subject:content-type; b=fBk+zZHkZu5o0THTjYQet3cCXU7kouDLOiPtDAIrNKOtk+/5NW8O3GPpvFpgEqQzLlrV+TpPSnXvdzF9cLok5fmERJPeOyrNriJOZcQ4sRFP/a4y1UOpf4FJdti2uw768aBNmi10SFEzThVFWP9CXbL7WP0lqm5XcGVIWm/D/XI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:user-agent:x-accept-language:mime-version:to:subject:content-type; b=gvbHMEMGNbSTl2RThTM0d7A/S1AMl1BtzZmwuuk6r67QVVGdeVf9x69Y2W3JtrVdNhToxmfrB8G+rn8N53ETGlLA16md1C+6/lVbta+rBjr8JZ91xLqJjI3UzzCtrRGUnmrpmpv9HIb/qCrV/IPbGf97erVIVzY8fQ6QrKC3ZUQ= Received: by 10.82.146.14 with SMTP id t14mr9230268bud.1182078862659; Sun, 17 Jun 2007 04:14:22 -0700 (PDT) Received: from ?192.168.1.8? ( [88.9.199.48]) by mx.google.com with ESMTP id d24sm9807670nfh.2007.06.17.04.14.21 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 17 Jun 2007 04:14:22 -0700 (PDT) Message-ID: <46751788.8020706@gmail.com> Date: Sun, 17 Jun 2007 13:14:16 +0200 From: adrian15 User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923) X-Accept-Language: en-us, en MIME-Version: 1.0 To: The development of GRUB 2 Content-Type: multipart/mixed; boundary="------------090504030606020306000005" X-detected-kernel: Linux 2.6 (newer, 2) Subject: map command draft #2 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Jun 2007 11:14:26 -0000 This is a multi-part message in MIME format. --------------090504030606020306000005 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit I attach the patch that makes grub2 to have a map command. The map command only modifies a vector. If we want true map in grub2 we need to hook some functions so that some bios calls ocurr. Meanwhile I think how to do it... here there is my patch and some questions and suggestions. > diff -urN grub2_2007_05_31_original/commands/i386/pc/map.c grub2_2007_05_31_map/commands/i386/pc/map.c > --- grub2_2007_05_31_original/commands/i386/pc/map.c 1970-01-01 01:00:00.000000000 +0100 > +++ grub2_2007_05_31_map/commands/i386/pc/map.c 2007-06-17 05:40:39.000000000 +0200 > @@ -0,0 +1,108 @@ > +/* map.c - Define map array */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include I am including file.h because it includes the function: grub_file_get_device_name I think an equivalent function such as: grub_disk_get_device_name should be defined in disk.h and implemented where it corresponds to be implemented. > + > +/* The size of the drive map. */ > +#define DRIVE_MAP_SIZE 16 Is there any bios that supports more than 16 hard disks? > +/* The BIOS drive map. */ > +static unsigned short bios_drive_map[DRIVE_MAP_SIZE + 1]; > + > +int real_map_func (unsigned long to, unsigned long from) { > +int i; > + /* Search for an empty slot in BIOS_DRIVE_MAP. */ > + for (i = 0; i < DRIVE_MAP_SIZE; i++) > + { > + /* Perhaps the user wants to override the map. */ > + if ((bios_drive_map[i] & 0xff) == from) > + break; > + > + if (! bios_drive_map[i]) > + break; > + } > + > + if (i == DRIVE_MAP_SIZE) > + { > + return GRUB_ERR_OUT_OF_RANGE; > + } > + > + if (to == from) > + /* If TO is equal to FROM, delete the entry. */ > + grub_memmove ((char *) &bios_drive_map[i], (char *) &bios_drive_map[i + 1], > + sizeof (unsigned short) * (DRIVE_MAP_SIZE - i)); > + else > + bios_drive_map[i] = from | (to << 8); > + > + return 0; > + > + > +} The above code was copy-pasted from grub legacy. Do you think it can be improved? > + > + > + > +static grub_err_t > +grub_cmd_map (struct grub_arg_list *state __attribute__ ((unused)), > + int argc, char **args) > +{ > + grub_disk_t map_disk_to,map_disk_from; > + > +/* TODO: Check map arguments from grub2 engine */ > + if (argc != 2) > + return grub_error (GRUB_ERR_BAD_ARGUMENT, "Two devices required"); > + map_disk_to = grub_disk_open (grub_file_get_device_name(args[0])); > + if (! map_disk_to) > + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Unknown TO disk"); > +/* This was a marco_g suggestion but it does not make sense to me. > + if (grub_strcmp(map_disk_to->name,"biosdisk")) > + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "TO disk is not a bios disk."); > +*/ marco_g ... if I try to grub_printf the disk_to-> name it says hd0. It does not say "biosdisk" as you have told me. I am bit confused. > + map_disk_from = grub_disk_open (grub_file_get_device_name(args[1])); > + if (! map_disk_from) > + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Unknown FROM disk"); > +/* This was a marco_g suggestion but it does not make sense to me. > + if (grub_strcmp(map_disk_from->name,"biosdisk")) > + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "FROM disk is not a bios disk."); > +*/ Idem for marco_g. Should I add a function that checks the validity of a hard disk and asignts it to a grub_disk_t variable and call it twice in order to make the code smaller ? > + > + > + return (real_map_func(map_disk_to->id,map_disk_from->id)); > + > +} > + > + > +GRUB_MOD_INIT(map) > +{ > + (void)mod; /* To stop warning. */ > + grub_register_command ("map", grub_cmd_map, GRUB_COMMAND_FLAG_BOTH, > + "map TODEVICE FROMDEVICE", "Map a drive to another", 0); > +} > + > +GRUB_MOD_FINI(map) > +{ > + grub_unregister_command ("map"); > +} > diff -urN grub2_2007_05_31_original/conf/i386-pc.rmk grub2_2007_05_31_map/conf/i386-pc.rmk > --- grub2_2007_05_31_original/conf/i386-pc.rmk 2007-06-11 11:53:27.000000000 +0200 > +++ grub2_2007_05_31_map/conf/i386-pc.rmk 2007-06-14 12:38:00.000000000 +0200 > @@ -1,5 +1,7 @@ > # -*- makefile -*- > > + > + > COMMON_ASFLAGS = -nostdinc -fno-builtin -m32 > COMMON_CFLAGS = -fno-builtin -mrtd -mregparm=3 -m32 > COMMON_LDFLAGS = -m32 -nostdlib > @@ -121,7 +123,7 @@ > pkgdata_MODULES = _chain.mod _linux.mod linux.mod normal.mod \ > _multiboot.mod chain.mod multiboot.mod reboot.mod halt.mod \ > vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \ > - videotest.mod play.mod bitmap.mod tga.mod cpuid.mod > + videotest.mod map.mod play.mod bitmap.mod tga.mod cpuid.mod > > # For _chain.mod. > _chain_mod_SOURCES = loader/i386/pc/chainloader.c > @@ -195,6 +197,11 @@ > vbetest_mod_CFLAGS = $(COMMON_CFLAGS) > vbetest_mod_LDFLAGS = $(COMMON_LDFLAGS) > > +# For map.mod. > +map_mod_SOURCES = commands/i386/pc/map.c > +map_mod_CFLAGS = $(COMMON_CFLAGS) > +map_mod_LDFLAGS = $(COMMON_LDFLAGS) > + > # For play.mod. > play_mod_SOURCES = commands/i386/pc/play.c > play_mod_CFLAGS = $(COMMON_CFLAGS) Is it important that I also copy-paste the rmk files modifications or not? adrian15 --------------090504030606020306000005 Content-Type: text/x-patch; name="map_draft_2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="map_draft_2.patch" diff -urN grub2_2007_05_31_original/commands/i386/pc/map.c grub2_2007_05_31_map/commands/i386/pc/map.c --- grub2_2007_05_31_original/commands/i386/pc/map.c 1970-01-01 01:00:00.000000000 +0100 +++ grub2_2007_05_31_map/commands/i386/pc/map.c 2007-06-17 05:56:15.000000000 +0200 @@ -0,0 +1,107 @@ +/* map.c - Define drives map array */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2005 Free Software Foundation, Inc. + * + * GRUB 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 GRUB; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* The size of the drive map. */ +#define DRIVE_MAP_SIZE 16 +/* The BIOS drive map. */ +static unsigned short bios_drive_map[DRIVE_MAP_SIZE + 1]; + +int real_map_func (unsigned long to, unsigned long from) { +int i; + /* Search for an empty slot in BIOS_DRIVE_MAP. */ + for (i = 0; i < DRIVE_MAP_SIZE; i++) + { + /* Perhaps the user wants to override the map. */ + if ((bios_drive_map[i] & 0xff) == from) + break; + + if (! bios_drive_map[i]) + break; + } + + if (i == DRIVE_MAP_SIZE) + { + return GRUB_ERR_OUT_OF_RANGE; + } + + if (to == from) + /* If TO is equal to FROM, delete the entry. */ + grub_memmove ((char *) &bios_drive_map[i], (char *) &bios_drive_map[i + 1], + sizeof (unsigned short) * (DRIVE_MAP_SIZE - i)); + else + bios_drive_map[i] = from | (to << 8); + + return 0; + + +} + + + +static grub_err_t +grub_cmd_map (struct grub_arg_list *state __attribute__ ((unused)), + int argc, char **args) +{ + grub_disk_t map_disk_to,map_disk_from; + +/* TODO: Check map arguments from grub2 engine */ + if (argc != 2) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "Two devices required"); + map_disk_to = grub_disk_open (grub_file_get_device_name(args[0])); + if (! map_disk_to) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Unknown TO disk"); +/* This was a marco_g suggestion but it does not make sense to me. + if (grub_strcmp(map_disk_to->name,"biosdisk")) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "TO disk is not a bios disk."); +*/ + map_disk_from = grub_disk_open (grub_file_get_device_name(args[1])); + if (! map_disk_from) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Unknown FROM disk"); +/* This was a marco_g suggestion but it does not make sense to me. + if (grub_strcmp(map_disk_from->name,"biosdisk")) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "FROM disk is not a bios disk."); +*/ + + + return (real_map_func(map_disk_to->id,map_disk_from->id)); + +} + + +GRUB_MOD_INIT(map) +{ + (void)mod; /* To stop warning. */ + grub_register_command ("map", grub_cmd_map, GRUB_COMMAND_FLAG_BOTH, + "map TODEVICE FROMDEVICE", "Map a drive to another", 0); +} + +GRUB_MOD_FINI(map) +{ + grub_unregister_command ("map"); +} diff -urN grub2_2007_05_31_original/conf/i386-pc.rmk grub2_2007_05_31_map/conf/i386-pc.rmk --- grub2_2007_05_31_original/conf/i386-pc.rmk 2007-06-11 11:53:27.000000000 +0200 +++ grub2_2007_05_31_map/conf/i386-pc.rmk 2007-06-14 12:38:00.000000000 +0200 @@ -1,5 +1,7 @@ # -*- makefile -*- + + COMMON_ASFLAGS = -nostdinc -fno-builtin -m32 COMMON_CFLAGS = -fno-builtin -mrtd -mregparm=3 -m32 COMMON_LDFLAGS = -m32 -nostdlib @@ -121,7 +123,7 @@ pkgdata_MODULES = _chain.mod _linux.mod linux.mod normal.mod \ _multiboot.mod chain.mod multiboot.mod reboot.mod halt.mod \ vbe.mod vbetest.mod vbeinfo.mod video.mod gfxterm.mod \ - videotest.mod play.mod bitmap.mod tga.mod cpuid.mod + videotest.mod map.mod play.mod bitmap.mod tga.mod cpuid.mod # For _chain.mod. _chain_mod_SOURCES = loader/i386/pc/chainloader.c @@ -195,6 +197,11 @@ vbetest_mod_CFLAGS = $(COMMON_CFLAGS) vbetest_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For map.mod. +map_mod_SOURCES = commands/i386/pc/map.c +map_mod_CFLAGS = $(COMMON_CFLAGS) +map_mod_LDFLAGS = $(COMMON_LDFLAGS) + # For play.mod. play_mod_SOURCES = commands/i386/pc/play.c play_mod_CFLAGS = $(COMMON_CFLAGS) --------------090504030606020306000005--