From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1Vd8Lt-0000Ar-9Z for mharc-grub-devel@gnu.org; Sun, 03 Nov 2013 19:49:09 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59779) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vd8Ll-0000AK-AC for grub-devel@gnu.org; Sun, 03 Nov 2013 19:49:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vd8Lf-0003K5-RX for grub-devel@gnu.org; Sun, 03 Nov 2013 19:49:01 -0500 Received: from mail-ee0-x232.google.com ([2a00:1450:4013:c00::232]:42446) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vd8Lf-0003J3-GP for grub-devel@gnu.org; Sun, 03 Nov 2013 19:48:55 -0500 Received: by mail-ee0-f50.google.com with SMTP id b45so28732eek.37 for ; Sun, 03 Nov 2013 16:48:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type; bh=EPnUKEOrQMppgiPtau4csFDBHEl5xBuMMhg9UWpi+6w=; b=JzDi9PAX5L5SwW2e5mBNI40TdBl8MmrQGNjwEIGKg1Pyj3XrlbVfAt+BLSIaUldExN e8/eiFOS4JMIQ5DIO3Eec+4NJeoEVRDW688kR3co6ptRxnoVRtaimN49x2m8erNNFl45 ++Wng+TfGEnVqND0iFCeJz09qpfhwlpXC1eYosuWo8Vb5KUOPXUlGLQwUDcPkVkj2aHo OusYBe38F+zNho9t1hGMtgUcTYnxMcSqkZV9plLaiVvJUmh2cDvBpNG32dZ/vdsunllL hV7vO0cKxDAOtnuCSMrqirJu7vCGO9LJIvG9ditNzSasJ8qrGpwbwVxCDY4nORpYXoyx Qlmg== X-Received: by 10.14.224.132 with SMTP id x4mr15619046eep.5.1383526134421; Sun, 03 Nov 2013 16:48:54 -0800 (PST) Received: from [192.168.1.16] (31-249.1-85.cust.bluewin.ch. [85.1.249.31]) by mx.google.com with ESMTPSA id u46sm39623838eep.17.2013.11.03.16.48.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 03 Nov 2013 16:48:53 -0800 (PST) Message-ID: <5276EEF3.1030904@gmail.com> Date: Mon, 04 Nov 2013 01:48:51 +0100 From: =?UTF-8?B?VmxhZGltaXIgJ8+GLWNvZGVyL3BoY29kZXInIFNlcmJpbmVua28=?= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131005 Icedove/17.0.9 MIME-Version: 1.0 To: grub-devel@gnu.org Subject: Re: New command to check NT's hibernation state References: <4EED5B22.1090904@gmail.com> In-Reply-To: <4EED5B22.1090904@gmail.com> X-Enigmail-Version: 1.5.1 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="----enig2CDFTNFXPNJKENSONMHNI" X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c00::232 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: Mon, 04 Nov 2013 00:49:07 -0000 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) ------enig2CDFTNFXPNJKENSONMHNI Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Going through e-mail archives found this one, looks like it got forgotten. Fixed problems with it and simplified greatly and committed. On 18.12.2011 04:16, Peter Lustig wrote: > On 17.12.2011 00:41, Vladimir 'phcoder' Serbinenko wrote: >=20 >> /* nthibr.c - tests whether an MS Windows system partition is >> hibernated */ >> /* >> * GRUB -- GRand Unified Bootloader >> * Copyright (C) 2007,2008,2009,2011 Free Software Foundation, Inc= =2E >> * >> * 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, o= r >> * (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 Licens= e >> * along with GRUB. If not, see. >> */ >> >> #include >> #include >> #include >> #include >> #include >> #include >> #include >> #include >> #include >> #include >> >> GRUB_MOD_LICENSE("GPLv3+"); >> >> /* Define this 'empty' array to let the '-h' and '-u' switches be >> processed */ >> static const struct grub_arg_option options[] =3D { >> {0, 0, 0, 0, 0, 0} >> }; >> Please remove this and use grub_command_t >> I understand now. What threw me off was seeing the 'hello' module use= >> 'extcmd.' >>>> static grub_err_t >>>> grub_cmd_nthibr (grub_extcmd_context_t ctxt __attribute__ ((unused))= , >>>> int argc, char **args) >>>> { >>>> char *partition_name =3D 0, *hibr_file_path =3D 0, hibr_file_mag= ic[5]; >>>> grub_size_t name_length; >>>> grub_ssize_t magic_size; >>>> grub_disk_t partition; >>>> grub_file_t hibr_file =3D 0; >>>> >>>> /* Check argument count */ >>>> if (!argc) >>>> return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("too few >>>> arguments")); >>>> else if (argc> 1) >>>> return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("too many >>>> arguments")); >>>> >>> Either ignore trailing argument or put both in one check !=3D 1 >>>> /* Make copy of partition specifier, so it can be modified (if >>>> needed) */ >>>> name_length =3D grub_strlen (args[0]); >>>> partition_name =3D grub_zalloc (name_length + 3); >>>> if (!partition_name) >>>> goto exit; >>>> grub_strcpy (partition_name, args[0]); >>>> >>>> /* Ensure partition specifier start with a '(' */ >>>> if (partition_name[0] !=3D '(') >>>> { >>>> grub_memmove (partition_name + 1, partition_name, >>>> name_length++); >>>> partition_name[0] =3D '('; >>>> } >>>> >>>> /* Ensure partition specifier ends with a ')' */ >>>> if (partition_name[name_length - 1] !=3D ')') >>>> partition_name[(++name_length) - 1] =3D ')'; >>>> >>>> /* Check if partition actually exists */ >>>> partition_name[name_length - 1] =3D '\0'; >>>> partition =3D grub_disk_open (partition_name + 1); >>>> if (!partition) >>>> goto exit; >>>> grub_disk_close (partition); >>>> partition_name[name_length - 1] =3D ')'; >>>> >>>> /* Build path to 'hiberfil.sys' */ >>>> hibr_file_path =3D grub_malloc ((grub_strlen (partition_name) >>>> + grub_strlen ("/hiberfil.sys") += >>>> 1)); >>>> if (!hibr_file_path) >>>> goto exit; >>>> grub_strcpy (hibr_file_path, partition_name); >>>> grub_strcat (hibr_file_path, "/hiberfil.sys"); >>>> >>> It would be more efficient if you just try to open file and see what >>> error you get. Actually you don't even need to distinguish between >>> error cases here since you return the error you encountered. This wil= l >>> also save one useless alloc. >>>> /* Try to open 'hiberfil.sys' */ >>>> hibr_file =3D grub_file_open (hibr_file_path); >>>> if (!hibr_file) >>>> { >>>> if (grub_errno =3D=3D GRUB_ERR_FILE_NOT_FOUND) >>>> grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("'hiberfil.sys' no= t >>>> found")); >>> This overriding is unnecessary. FS code already provides this message= >> This was intentional: the default message ('file not found') is not >> particularly helpful in this case since the >> command's description nowhere mentions what file it's looking for (let= >> alone that any file is needed for it to >> function). I've updated this section to pop the first error off the >> stack to eliminate the duplication (and added >> a descriptive comment). >>>> goto exit; >>>> } >>>> >>>> /* Try to read magic number of 'hiberfil.sys' */ >>>> magic_size =3D sizeof (hibr_file_magic) - 1; >>>> grub_memset (hibr_file_magic, 0, sizeof (hibr_file_magic)); >>>> if (grub_file_read (hibr_file, hibr_file_magic, magic_size)< >>>> magic_size) >>>> { >>>> if (!grub_errno) >>>> grub_error (GRUB_ERR_BAD_FILE_TYPE, N_("'hiberfil.sys' too= >>>> small")); >>>> goto exit; >>>> } >>>> >>>> /* Return SUCCESS if magic indicates file is active; else return= >>>> FAILURE */ >>>> if (!grub_strncasecmp ("hibr", hibr_file_magic, magic_size)) >>>> grub_error (GRUB_ERR_NONE, "true"); >>>> else >>>> grub_error (GRUB_ERR_TEST_FAILURE, "false"); >>>> >>>> exit: >>>> /* Ensure unmanaged resources are cleaned up */ >>>> if (partition_name) >>>> grub_free (partition_name); >>>> if (hibr_file_path) >>>> grub_free (hibr_file_path); >>> No need to check that argument to free is non-NULL. >>>> if (hibr_file) >>>> grub_file_close (hibr_file); >>>> >>>> return grub_errno; >>>> } >>>> >>>> static grub_extcmd_t cmd; >>>> >>>> GRUB_MOD_INIT (nthibr) >>>> { >>>> cmd =3D grub_register_extcmd ("nthibr", grub_cmd_nthibr, 0, >>>> N_("DEVICE"), >>>> N_("Test whether an NT system >>>> partition " >>>> "is hibernated."), >>>> options); >>>> } >>>> >>>> GRUB_MOD_FINI (nthibr) >>>> { >>>> grub_unregister_extcmd (cmd); >>>> } >>>> >> ~Peter Lustig >> -------------- next part -------------- >> An HTML attachment was scrubbed... >> URL: >> >> -------------- next part -------------- >> An embedded and charset-unspecified text was scrubbed... >> Name: nthibr.c >> URL: >> >> >> ------------------------------ >> >> Message: 2 >> Date: Sat, 17 Dec 2011 12:39:41 +0100 >> From: Vladimir '?-coder/phcoder' Serbinenko >> To:grub-devel@gnu.org >> Subject: Re: New command to check NT's hibernation state >> Message-ID:<4EEC7F7D.2050900@gmail.com> >> Content-Type: text/plain; charset=3DUTF-8; format=3Dflowed >> >> >>>>> /* Try to open 'hiberfil.sys' */ >>>>> hibr_file =3D grub_file_open (hibr_file_path); >>>>> if (!hibr_file) >>>>> { >>>>> if (grub_errno =3D=3D GRUB_ERR_FILE_NOT_FOUND) >>>>> grub_error (GRUB_ERR_FILE_NOT_FOUND, N_("'hiberfil.sys' n= ot >>>>> found")); >>>> This overriding is unnecessary. FS code already provides this messag= e >>> This was intentional: the default message ('file not found') is not >>> particularly helpful in this case since the >>> command's description nowhere mentions what file it's looking for (le= t >>> alone that any file is needed for it to >>> function). I've updated this section to pop the first error off the >>> stack to eliminate the duplication (and added >>> a descriptive comment). >> This means that your copy of GRUB is old. Newer ones do have the >> descriptive message. And even if it wasn't the case it's something to = be >> fixed in FS code, not by replacing error message here. > I've been using the latest release (1.99), so this fix must still be on= > the development branch. But I do appreciate > the idea of fixing something once at the source instead of at multiple > points of consumption. >=20 >=20 > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel >=20 ------enig2CDFTNFXPNJKENSONMHNI 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.15 (GNU/Linux) Comment: Using GnuPG with Icedove - http://www.enigmail.net/ iF4EAREKAAYFAlJ27vMACgkQmBXlbbo5nOty0AEAj/UlT6nJDxoxMnnyAbisO3k+ QHcg6C9xcC++aB/dVJgA/Axk90FaRF/is1iecPXKsjx8GbXy21SUQFGeNhqMhMZq =fm7I -----END PGP SIGNATURE----- ------enig2CDFTNFXPNJKENSONMHNI--