From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Hzbvf-00016g-05 for mharc-grub-devel@gnu.org; Sat, 16 Jun 2007 13:19:15 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Hzbvc-00014H-NR for grub-devel@gnu.org; Sat, 16 Jun 2007 13:19:12 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Hzbvb-000131-EB for grub-devel@gnu.org; Sat, 16 Jun 2007 13:19:12 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Hzbvb-00012t-Ak for grub-devel@gnu.org; Sat, 16 Jun 2007 13:19:11 -0400 Received: from 245.red-80-24-127.staticip.rima-tde.net ([80.24.127.245] helo=manazas.ensanjose.net) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1HzbvZ-0000qQ-OR for grub-devel@gnu.org; Sat, 16 Jun 2007 13:19:11 -0400 Received: from localhost (manazas.ensanjose.net [127.0.0.1]) by manazas.ensanjose.net (Postfix) with ESMTP id 07505D32AE for ; Sat, 16 Jun 2007 19:19:06 +0200 (CEST) Received: from manazas.ensanjose.net ([127.0.0.1]) by localhost (manazas.ensanjose.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 00716-07 for ; Sat, 16 Jun 2007 19:19:05 +0200 (CEST) Received: from [192.168.1.8] (188.Red-83-38-191.dynamicIP.rima-tde.net [83.38.191.188]) by manazas.ensanjose.net (Postfix) with ESMTP id 1AFB9D321B for ; Sat, 16 Jun 2007 19:19:04 +0200 (CEST) Message-ID: <46741B86.1070409@raulete.net> Date: Sat, 16 Jun 2007 19:19:02 +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 References: <4668259D.9090701@raulete.net> <466D6014.7090205@raulete.net> In-Reply-To: <466D6014.7090205@raulete.net> Content-Type: multipart/mixed; boundary="------------090704010101040804060806" X-detected-kernel: Linux 2.4-2.6 Subject: Re: map command for grub2 draft 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: Sat, 16 Jun 2007 17:19:12 -0000 This is a multi-part message in MIME format. --------------090704010101040804060806 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Here I am again with another question... How do I check that a given string: (hd0), (hd1,0), (hd1) is an existent drive? I supposed that I had to use grub_disk_open because I did not want to use grub_device_open can open (hd1,0) and (hd1,0) is not a drive but a partition. Here there is my map.c source code (which does compile) and some more doubts that I have: I attach a patch that contains an unfinished and untested pause command too. > #include > #include > #include > #include > #include > #include > #include Is there any include that I do not need at all? > > /* 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]; I've finally decided to put this here. I will put the other commands: mapboot (the bios hook) and usbshift (A complex map command that maps many drives) in this same file. > > 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; > > > } Copy-Pasted from grub legacy. :) Should I improve it, removing the break or not ? > > > > 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; I want to check disks not devices this is why I use grub_disk_t. > > if (argc != 2) > return grub_error (GRUB_ERR_BAD_ARGUMENT, "Two devices required"); > > map_disk_to = grub_disk_open (args[0]); > /* TODO: Check map arguments from grub2 engine */ This means that in a future the grub2 engine should be able to read an string like: and check itself if the strings are disks or not thus I would not have to write the checks inside this file. > if (! map_disk_to) > return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Unknown TO disk"); > map_disk_from = grub_disk_open (args[1]); > if (! map_disk_from) > return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Unknown FROM disk"); > > return (real_map_func(map_disk_to->id,map_disk_from->id)); Do you want me to merge the two functions in one maybe? > > } > > > 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"); > } One more question marco_g told me that I had to check the field "name" from grub_disk_t struct. If it read: "biosdisk" then it was ok for the map command. If it did not read this then it was an error. I am sorry about the noob question but how should I compare two strings on grub2? And why isn't there an enum type for grub_disk_t name field (as the grub2 errors)? Do we have a new name for disk everyday ? adrian15 --------------090704010101040804060806 Content-Type: text/x-patch; name="map_draft_1.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="map_draft_1.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-16 12:09:28.000000000 +0200 @@ -0,0 +1,98 @@ +/* map.c - Define map vector */ +/* + * 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 + +/* 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; + + if (argc != 2) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "Two devices required"); + + map_disk_to = grub_disk_open (args[0]); +/* TODO: Check map arguments from grub2 engine */ + if (! map_disk_to) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Unknown TO disk"); + map_disk_from = grub_disk_open (args[1]); + if (! map_disk_from) + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "Unknown FROM 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/commands/pause.c grub2_2007_05_31_map/commands/pause.c --- grub2_2007_05_31_original/commands/pause.c 1970-01-01 01:00:00.000000000 +0100 +++ grub2_2007_05_31_map/commands/pause.c 2007-06-12 12:02:37.000000000 +0200 @@ -0,0 +1,52 @@ +/* pause.c - command to pause and show a message. */ +/* + * GRUB -- GRand Unified Bootloader + * Copyright (C) 2003,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 + +static grub_err_t +grub_cmd_pause (struct grub_arg_list *state __attribute__ ((unused)), + int argc, char **args) + +{ + + char key; + if (argc!=0) + grub_cmd_echo(state,argc,args); + key = grub_getkey (); + + return 0; +} + + +GRUB_MOD_INIT(pause) +{ + (void) mod; /* To stop warning. */ + grub_register_command ("pause", grub_cmd_pause, GRUB_COMMAND_FLAG_BOTH, + "pause [MESSAGE]", "Pause and optionally show a message with echo command.", 0); +} + +GRUB_MOD_FINI(pause) +{ + grub_unregister_command ("pause"); +} diff -urN grub2_2007_05_31_original/conf/i386-pc.mk grub2_2007_05_31_map/conf/i386-pc.mk --- grub2_2007_05_31_original/conf/i386-pc.mk 2007-06-11 11:53:27.000000000 +0200 +++ grub2_2007_05_31_map/conf/i386-pc.mk 2007-06-14 12:50:57.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 @@ -813,7 +815,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 @@ -1691,6 +1693,58 @@ vbetest_mod_CFLAGS = $(COMMON_CFLAGS) vbetest_mod_LDFLAGS = $(COMMON_LDFLAGS) +# For map.mod. +map_mod_SOURCES = commands/i386/pc/map.c +CLEANFILES += map.mod mod-map.o mod-map.c pre-map.o map_mod-commands_i386_pc_map.o und-map.lst +ifneq ($(map_mod_EXPORTS),no) +CLEANFILES += def-map.lst +DEFSYMFILES += def-map.lst +endif +MOSTLYCLEANFILES += map_mod-commands_i386_pc_map.d +UNDSYMFILES += und-map.lst + +map.mod: pre-map.o mod-map.o + -rm -f $@ + $(TARGET_CC) $(map_mod_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o $@ $^ + $(STRIP) --strip-unneeded -K grub_mod_init -K grub_mod_fini -R .note -R .comment $@ + +pre-map.o: $(map_mod_DEPENDENCIES) map_mod-commands_i386_pc_map.o + -rm -f $@ + $(TARGET_CC) $(map_mod_LDFLAGS) $(TARGET_LDFLAGS) -Wl,-r,-d -o $@ map_mod-commands_i386_pc_map.o + +mod-map.o: mod-map.c + $(TARGET_CC) $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(map_mod_CFLAGS) -c -o $@ $< + +mod-map.c: moddep.lst genmodsrc.sh + sh $(srcdir)/genmodsrc.sh 'map' $< > $@ || (rm -f $@; exit 1) + +ifneq ($(map_mod_EXPORTS),no) +def-map.lst: pre-map.o + $(NM) -g --defined-only -P -p $< | sed 's/^\([^ ]*\).*/\1 map/' > $@ +endif + +und-map.lst: pre-map.o + echo 'map' > $@ + $(NM) -u -P -p $< | cut -f1 -d' ' >> $@ + +map_mod-commands_i386_pc_map.o: commands/i386/pc/map.c + $(TARGET_CC) -Icommands/i386/pc -I$(srcdir)/commands/i386/pc $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(map_mod_CFLAGS) -MD -c -o $@ $< +-include map_mod-commands_i386_pc_map.d + +CLEANFILES += cmd-map_mod-commands_i386_pc_map.lst fs-map_mod-commands_i386_pc_map.lst +COMMANDFILES += cmd-map_mod-commands_i386_pc_map.lst +FSFILES += fs-map_mod-commands_i386_pc_map.lst + +cmd-map_mod-commands_i386_pc_map.lst: commands/i386/pc/map.c gencmdlist.sh + set -e; $(TARGET_CC) -Icommands/i386/pc -I$(srcdir)/commands/i386/pc $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(map_mod_CFLAGS) -E $< | sh $(srcdir)/gencmdlist.sh map > $@ || (rm -f $@; exit 1) + +fs-map_mod-commands_i386_pc_map.lst: commands/i386/pc/map.c genfslist.sh + set -e; $(TARGET_CC) -Icommands/i386/pc -I$(srcdir)/commands/i386/pc $(TARGET_CPPFLAGS) $(TARGET_CFLAGS) $(map_mod_CFLAGS) -E $< | sh $(srcdir)/genfslist.sh map > $@ || (rm -f $@; exit 1) + + +map_mod_CFLAGS = $(COMMON_CFLAGS) +map_mod_LDFLAGS = $(COMMON_LDFLAGS) + # For play.mod. play_mod_SOURCES = commands/i386/pc/play.c CLEANFILES += play.mod mod-play.o mod-play.c pre-play.o play_mod-commands_i386_pc_play.o und-play.lst 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) diff -urN grub2_2007_05_31_original/gendistlist grub2_2007_05_31_map/gendistlist --- grub2_2007_05_31_original/gendistlist 1970-01-01 01:00:00.000000000 +0100 +++ grub2_2007_05_31_map/gendistlist 2007-06-14 12:09:39.000000000 +0200 @@ -0,0 +1,38 @@ +#! /bin/sh +# +# Copyright (C) 2005 Free Software Foundation, Inc. +# +# This gendistlist.sh is free software; the author +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +# Generate a list of distributed files. + +EXTRA_DISTFILES="AUTHORS COPYING ChangeLog DISTLIST INSTALL NEWS README \ + THANKS TODO Makefile.in aclocal.m4 autogen.sh config.guess \ + config.h.in config.sub configure configure.ac gencmdlist.sh \ + gendistlist.sh genfslist.sh genkernsyms.sh genmk.rb \ + genmodsrc.sh gensymlist.sh install-sh mkinstalldirs stamp-h.in" + +DISTDIRS="boot commands conf disk font fs hello include io kern loader \ + normal partmap term util video" + +for f in $EXTRA_DISTFILES; do + echo $f +done + +dir=`dirname $0` +cd $dir + +for dir in $DISTDIRS; do + for d in `find $dir -type d | sort`; do + find $d -maxdepth 1 -name '*.[chS]' -o -name '*.mk' -o -name '*.rmk' \ + -o -name '*.rb' -o -name '*.in' \ + | sort + done +done --------------090704010101040804060806--