Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1M2ih4-00078d-W6 for mharc-grub-devel@gnu.org; Sat, 09 May 2009 05:18:07 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1M2ih1-00078N-Rj for grub-devel@gnu.org; Sat, 09 May 2009 05:18:03 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1M2igw-00077v-F8 for grub-devel@gnu.org; Sat, 09 May 2009 05:18:02 -0400 Received: from [199.232.76.173] (port=34522 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1M2igw-00077q-9p for grub-devel@gnu.org; Sat, 09 May 2009 05:17:58 -0400 Received: from mail-ew0-f162.google.com ([209.85.219.162]:51011) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1M2igv-0004wk-Ng for grub-devel@gnu.org; Sat, 09 May 2009 05:17:58 -0400 Received: by ewy6 with SMTP id 6so2474884ewy.42 for ; Sat, 09 May 2009 02:17:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=ozbNNi95OtpVbxtrTCcO0bW1qRmnBjRgEJkxBsrrCto=; b=oOFo6+A+c8lBElAmCJ0heF2iuRHq2xW43m6jk3lBATb9546jnvsS96Xvk83d3ITawk Fc94VlB3l9QGDPOPhougHy3EAwA7yaUMlD/3AHHxCbwP1Inoj7FuakYPWAAsZ1U1dbYh SQWS2HRxTj0RWgt3Wa+ECDRecrvrQFAvHHMU4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=q5dTkwwdH9cTLtDSZCnUmO+34OpubE2Y2pQVUv4bNYI1UBdIPzZRevQOClVMS6lh7e AIQB8qKjQY36hyVSdfzBItZdXA7FkT6TlkfgYRsNlK7tTweh/kHl+3kBrzgHcDQLsOBv y3A4NnjYI8pJn1sN4UxE8jQH9i9kcB/geUJUY= MIME-Version: 1.0 Received: by 10.210.127.13 with SMTP id z13mr5669107ebc.98.1241860676295; Sat, 09 May 2009 02:17:56 -0700 (PDT) In-Reply-To: <1241635288.4535.6.camel@accesodirecto.casa> References: <49E3E0FB.1070907@verizon.net> <49E91862.9090103@verizon.net> <1240021094.19677.29.camel@accesodirecto.casa> <1241308934.4290.79.camel@accesodirecto.casa> <1241384352.2442.133.camel@ct> <1241393832.6586.35.camel@accesodirecto.casa> <1241409431.26483.33.camel@mj> <1241635288.4535.6.camel@accesodirecto.casa> Date: Sat, 9 May 2009 11:17:56 +0200 Message-ID: From: "Vladimir 'phcoder' Serbinenko" To: The development of GRUB 2 Content-Type: multipart/alternative; boundary=0015174c10a0789c50046977383c X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: Re: status grub2 port of grub-legasy map command 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, 09 May 2009 09:18:04 -0000 --0015174c10a0789c50046977383c Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable +/* Realmode far ptr (2 * 16b) to the previous INT13h handler. */ +extern grub_uint32_t grub_drivemap_int13_oldhandler; I prefer it to be 2 variables because of the way they interract so nobody would do something like (char *) grub_drivemap_int13_oldhandler; +/* The type "void" is used for imported assembly labels, takes no storage and + serves just to take the address with &label. Do NOT put void* here. *= / +/* Start of the handler bundle. */ +extern void grub_drivemap_int13_handler_base; The common practice is to use declarations like extern char grub_drivemap_int13_handler_base[]; it makes pointer arithmetics easy +typedef struct drivemap_node +{ + grub_uint8_t newdrive; + grub_uint8_t redirto; + struct drivemap_node *next; +} drivemap_node_t; Here you could reuse Bean's list functions + if (!mapping) Put a space after !. I know GCS can be PITA but grub has chosen to follow it. Not my decision + else /* Entry was head of list. */ + map_head =3D mapping->next; put the comment on a separate line + if (!name || *name =3D=3D 0) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name empty"); This check is unnecessary since your function is static and calling functio= n already ensured that name isn't empty + /* Skip the first ( in (hd0) - disk_open wants just the name. */ + if (*name =3D=3D '(') + name++; AFAIK you need to remove ')' as well It's not necessary to try to open the disk actually because for some reason biosdisk module may be not loaded (e.g. grub may use ata) and loading it ma= y cause nasty effects (e.g. conflict between ata and biosdisk) Same applies for revparse_biosdisk. And if user wants to map to unexistant disk it's ok. So just use tryparse_diskstring + if ((str[0] =3D=3D 'f' || str[0] =3D=3D 'h') && str[1] =3D=3D 'd') change this to something like if (! ((str[0] =3D=3D 'f' || str[0] =3D=3D 'h') && str[1] =3D=3D 'd')) return ... It makes code nicer by avoiding unnecessary long else + grub_errno =3D GRUB_ERR_NONE; No need to set grub_errno explicitely unless you want to ignore an error + unsigned long drivenum =3D grub_strtoul (str + 2, 0, 0); + if (grub_errno !=3D GRUB_ERR_NONE || drivenum > 127) I think it's enough to just check the range + { + /* N not a number or out of range. */ + goto fail; Since at fail you have just a return, just put a return here with informative error message + } + else else is unnecessary, just continue with the code + if (cmd->state[OPTIDX_LIST].set || 0 =3D=3D argc) argc =3D=3D 0 sounds better. Also moving list function to a separate functi= on is a good idea + return grub_error (err, "invalid mapping: non-existent disk" + "or not managed by the BIOS"); If you change error message change error number too. Use either return err; or return grub_error (GRUB_ERR_..., message); + map_head =3D 0; + } + else Use return rather then else + return GRUB_ERR_NONE; + } + else no need for "else" + for (i =3D 0; i < entries && curentry; ++i, curentry =3D curentry->n= ext) You don't need to test for both conditions since theirequivalencyis ensured by preceding code + if (0 !=3D grub_drivemap_int13_oldhandler) Better swap the parts + MODNAME + " -l | -r | [-s] grubdev biosdisk", Here MODNAME doesn't save any space and makes code less readable. Just writ= e the command name explicitely + push %bp + mov %sp, %bp You don't need to change bp. Just use sp. In this case it makes code easier + lcall *%cs:GRUB_DRIVEMAP_INT13H_OFFSET(grub_drivemap_int13_oldhandler) + pop %bp /* The pushed flags were removed by iret. */ Use rather: pushf lcall *%cs:GRUB_DRIVEMAP_INT13H_OFFSET(grub_drivemap_int13_oldhandler) Also remember to restore original %dl after the call I'm looking forward for your improved patch Thank you for your effort Could you also prepare a changelog entry for it? 2009/5/6 Javier Mart=EDn > Here is a new version of the patch. As you suggested, "grub_symbol_t" > was replaced with "void". Also, drivemap.h no longer exists, its little > content integrated into drivemap.c. Last but not least, I've mostly > adopted your version of the assembly file (indenting, labels, etc.) > > -- > -- Lazy, Oblivious, Recurrent Disaster -- Habbit > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > http://lists.gnu.org/mailman/listinfo/grub-devel > > --=20 Regards Vladimir 'phcoder' Serbinenko --0015174c10a0789c50046977383c Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable +/* Realmode far ptr (2 * 16b) to the previous INT13h handler.=A0 */
+extern grub_uint32_t grub_drivemap_int13_oldhandler;
I prefer it to= be 2 variables because of the way they interract so nobody would do someth= ing like (char *) grub_drivemap_int13_oldhandler;
+/* The type "voi= d" is used for imported assembly labels, takes no storage and
+=A0=A0 serves just to take the address with &label.=A0 Do NOT put = void* here.=A0 */
+/* Start of the handler bundle.=A0 */
+extern void grub_drivemap_int13_handler_base;
The common practice i= s to use declarations like
extern char grub_drivemap_int13_handler_base[= ];
it makes pointer arithmetics easy
+typedef struct drivemap_node
+{
+=A0 grub_uint8_t newdrive;
+=A0 grub_uint8_t redirto;
+=A0 struct drivemap_node *next;
+} drivemap_node_t;
Here you could reuse Bean's list functions
+=A0=A0=A0=A0=A0 if (= !mapping)
Put a space after !. I know GCS can be PITA but grub has chose= n to follow it. Not my decision
+=A0=A0=A0=A0=A0 else=A0=A0 =A0=A0=A0 = =A0=A0=A0 =A0/* Entry was head of list.=A0 */
+=A0=A0 =A0map_head =3D mapping->next;
put the comment on a separate= line
+=A0 if (!name || *name =3D=3D 0)
+=A0=A0=A0 return grub_error (GRUB_ERR_BAD_ARGUMENT, "device name = empty");
This check is unnecessary since your function is static an= d calling function already ensured that name isn't empty
+=A0 /* Ski= p the first ( in (hd0) - disk_open wants just the name.=A0 */
+=A0 if (*name =3D=3D '(')
+=A0=A0=A0 name++;
AFAIK you need to remove ')' as well
I= t's not necessary to try to open the disk actually because for some rea= son biosdisk module may be not loaded (e.g. grub may use ata) and loading i= t may cause nasty effects (e.g. conflict between ata and biosdisk)
Same applies for revparse_biosdisk. And if user wants to map to unexistant = disk it's ok. So just use tryparse_diskstring
+=A0 if ((str[0] =3D= =3D 'f' || str[0] =3D=3D 'h') && str[1] =3D=3D '= ;d')
change this to something like
if (! ((str[0] =3D=3D 'f' || s= tr[0] =3D=3D 'h') && str[1] =3D=3D 'd'))
=A0=A0 = return ...
It makes code nicer by avoiding unnecessary long else
+=A0= =A0=A0=A0=A0 grub_errno =3D GRUB_ERR_NONE;
No need to set grub_errno explicitely unless you want to ignore an erro= r
+=A0=A0=A0=A0=A0 unsigned long drivenum =3D grub_strtoul (str + 2, 0, = 0);
+=A0=A0=A0=A0=A0 if (grub_errno !=3D GRUB_ERR_NONE || drivenum > 127= )
I think it's enough to just check the range
+=A0=A0 =A0{
+= =A0=A0 =A0=A0 /* N not a number or out of range.=A0 */
+=A0=A0 =A0=A0 g= oto fail;
Since at fail you have just a return, just put a return here = with informative error message
+=A0=A0 =A0}
+=A0=A0=A0=A0=A0 else
else is unnecessary, just continue with the code
+=A0 if (cmd->st= ate[OPTIDX_LIST].set || 0 =3D=3D argc)
argc =3D=3D 0 sounds better. Also moving list function to a separate fu= nction is a good idea
+=A0=A0=A0 =A0=A0=A0 return grub_error (err, "= ;invalid mapping: non-existent disk"
+=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0 "or not managed by= the BIOS");
If you change error message change error number too. U= se either
return err;
or
return grub_error (GRUB_ERR_..., message= );
+=A0=A0=A0=A0=A0 map_head =3D 0;
+=A0=A0=A0 }
+=A0 else
Use return rather then else
+=A0=A0=A0=A0=A0 return GRU= B_ERR_NONE;
+=A0=A0=A0 }
+=A0 else
no need for "else"
+=A0=A0=A0=A0=A0 for (i =3D 0; i < e= ntries && curentry; ++i, curentry =3D curentry->next)
You don= 't need to test for both conditions since theirequivalencyis ensured by= preceding code
+=A0 if (0 !=3D grub_drivemap_int13_oldhandler)
Better swap the parts+=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 MODNAME
+=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 " -l | -r | [-s= ] grubdev biosdisk",
Here MODNAME doesn't save any space and makes code less readable. J= ust write the command name explicitely
+=A0=A0=A0=A0=A0=A0 push=A0=A0= =A0 %bp
+=A0=A0=A0=A0=A0=A0 mov=A0=A0=A0=A0 %sp, %bp
You don't need to change bp. Just use sp. In this case it makes cod= e easier
+=A0=A0=A0=A0=A0=A0 lcall=A0=A0 *%cs:GRUB_DRIVEMAP_INT13H_OFFSE= T(grub_drivemap_int13_oldhandler)
+=A0=A0=A0=A0=A0=A0 pop=A0=A0=A0=A0 %bp /* The pushed flags were remove= d by iret.=A0 */
Use rather:
pushf
lcall =A0 *%cs:GRUB_= DRIVEMAP_INT13H_OFFSET(grub_drivemap_int13_oldhandler)
Also remember to restore original %dl after the call
I'm looking for= ward for your improved patch
Thank you for your effort
Could you also= prepare a changelog entry for it?
2009/5/6 Javier Mart=EDn <lordhabbit@gmail.com&= gt;
Here is a new ver= sion of the patch. As you suggested, "grub_symbol_t"
was replaced with "void". Also, drivemap.h no longer exists, its = little
content integrated into drivemap.c. Last but not least, I've mostly
adopted your version of the assembly file (indenting, labels, etc.)

--
-- Lazy, Oblivious, Recurrent Disaster -- Habbit

_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel




--
Regards
Vladimir= 'phcoder' Serbinenko
--0015174c10a0789c50046977383c--