From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1THdWp-0001AK-TX for mharc-grub-devel@gnu.org; Fri, 28 Sep 2012 12:35:03 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38701) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1THdWa-0000wI-Ar for grub-devel@gnu.org; Fri, 28 Sep 2012 12:35:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1THdWO-0000Gx-Qq for grub-devel@gnu.org; Fri, 28 Sep 2012 12:34:48 -0400 Received: from mail-wi0-f177.google.com ([209.85.212.177]:56836) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1THdWO-0000G6-H2 for grub-devel@gnu.org; Fri, 28 Sep 2012 12:34:36 -0400 Received: by wibhj13 with SMTP id hj13so22254wib.12 for ; Fri, 28 Sep 2012 09:34:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:x-enigmail-version:content-type; bh=2tHTioyu1Lm9iXQQGebdXn4khI7qtD5BBJMcMXmwOXM=; b=Uxh2jdiM7PBNmL21qNlyTzL5pBQU1QXTphUc6v37yzDnjgnl4qrloiJEZcWAV2LJQE JhOUC7JV0vfsaoN6QL1KMXDKCZiHdE/Qc6JX2iOEqTWHmL/5lYDPNV2w3UgrHoT0VE8b zRTevN8SMsdLBkha8v5745Jxv8rUrRCVymEBUUdek98r8jZ8YvjmfpIPdE+2bPH9CRvU Ez6u/i6SzX8/OIBtheXpVlwMLlbyoF2OiAsJjNPJ202+uRO0048KSLgvAQeP7nRTldgl gYR77kz1n06FiJNwhFQ5OxlhYMStTN1oeA5cUuVGF2EDL4H3pc2fU7iFboxvpmsO2VIT tqqQ== Received: by 10.217.2.133 with SMTP id p5mr3816188wes.143.1348850075571; Fri, 28 Sep 2012 09:34:35 -0700 (PDT) Received: from debian.x201.phnet (27-232.197-178.cust.bluewin.ch. [178.197.232.27]) by mx.google.com with ESMTPS id ct3sm157344wib.5.2012.09.28.09.34.30 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 28 Sep 2012 09:34:34 -0700 (PDT) Message-ID: <5065D17D.9000502@gmail.com> Date: Fri, 28 Sep 2012 18:34:05 +0200 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.7) Gecko/20120922 Icedove/10.0.7 MIME-Version: 1.0 To: grub-devel@gnu.org Subject: Re: [PATCH] Add testpci command References: <20120927214211.GS2289@earth.li> In-Reply-To: <20120927214211.GS2289@earth.li> X-Enigmail-Version: 1.4.1 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="------------enigBEE70B32F1729B590DEA6174" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.212.177 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Sep 2012 16:35:02 -0000 This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigBEE70B32F1729B590DEA6174 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 27.09.2012 23:42, Jonathan McDowell wrote: > I have a machine with both Linux and Windows installed on the hard > drive. Linux runs on the bare metal and I occasionally run the Windows > install in a VM using KVM pointed at /dev/sda. However if I'm not quick= > enough, or Windows decides to reboot when I'm not around to notice, the= > grub running under KVM will decide to boot Linux and much confusion > ensues. >=20 > I couldn't find an easy way to test what the running environment was, s= o > I knocked up a simple testpci command that allows me to test for the > existence of a PCI device and change the default boot option based on This problem may be better solved by smbios tables or specific checker for qemu since this same ID is actually a real chipset AFAIR. > that. I have: >=20 > | if testpci 8086:1237; then > | set default=3D"2" > | fi I'd prefer the syntax proposed by Andrey. > =3D=3D=3D added file 'grub-core/commands/testpci.c' > --- grub-core/commands/testpci.c 1970-01-01 00:00:00 +0000 > +++ grub-core/commands/testpci.c 2012-09-27 21:15:02 +0000 > @@ -0,0 +1,75 @@ > +/* testpci.c - Test for PCI device existence. */ > +/* > + * GRUB -- GRand Unified Bootloader > + * Copyright (C) 2012 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 3 of the License, or > + * (at your option) any later version. > + * > + * GRUB 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, see . > + */ > + > +#include > +#include > +#include > +#include > +#include > + > +GRUB_MOD_LICENSE ("GPLv3+"); > + > +static int pcifound; > +static grub_pci_id_t pcisearch; > + > +static int NESTED_FUNC_ATTR > +grub_testpci_iter (grub_pci_device_t dev __attribute__ ((unused)), > + grub_pci_id_t pciid) > +{ > + if (pciid =3D=3D pcisearch) { > + pcifound =3D 1; > + return 1; > + } > + > + return 0; > +} > + > +static grub_err_t > +grub_cmd_testpci (grub_command_t ctxt __attribute__ ((unused)), > + int argc, > + char **args) > +{ > + pcifound =3D 0; > + > + if (argc !=3D 1) > + return grub_error (GRUB_ERR_BAD_ARGUMENT, "Device to search for re= quired"); Please use the common message "obe argument expected" and add N_(...) so it gets translated > + > + if ((grub_strlen(args[0]) !=3D 9) || args[0][4] !=3D ':') > + return grub_error (GRUB_ERR_BAD_ARGUMENT, "Device ID must be xxxx:= yyyy"); > + > + pcisearch =3D grub_strtoul(args[0], 0, 16) + > + (grub_strtoul(&args[0][5], 0, 16) << 16); > + This is slightly wrong. But I skip this part since with the other parameter proposition this code part will disappear anyway. > + grub_pci_iterate (grub_testpci_iter); > + > + return pcifound ? GRUB_ERR_NONE : grub_error (GRUB_ERR_TEST_FAILURE,= "false"); > +} > + > +static grub_command_t cmd; > + > +GRUB_MOD_INIT(testpci) > +{ > + cmd =3D grub_register_command ("testpci", grub_cmd_testpci, "xxxx:yy= yy", It should be N_("VENDOR:DEVICE"), not undescriptive xxxx --=20 Regards Vladimir '=CF=86-coder/phcoder' Serbinenko --------------enigBEE70B32F1729B590DEA6174 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iF4EAREKAAYFAlBl0X0ACgkQNak7dOguQgnMMwEAhC4PbLqRrOAfN/3FJbmg3PGo m5RmRysZfe4Hm5rSaa8A/iSEiSwtZADuMVwYwQt4nXQxeMYPxXhrHyB35ZuQ4Gr/ =3q/n -----END PGP SIGNATURE----- --------------enigBEE70B32F1729B590DEA6174--