From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.71) id 1RWLUp-0002c3-OL for mharc-grub-devel@gnu.org; Fri, 02 Dec 2011 00:17:15 -0500 Received: from eggs.gnu.org ([140.186.70.92]:44143) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RWLUn-0002aQ-3D for grub-devel@gnu.org; Fri, 02 Dec 2011 00:17:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RWLUl-00048u-Jk for grub-devel@gnu.org; Fri, 02 Dec 2011 00:17:13 -0500 Received: from mail-qw0-f41.google.com ([209.85.216.41]:47890) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RWLUl-00048k-Gg for grub-devel@gnu.org; Fri, 02 Dec 2011 00:17:11 -0500 Received: by qabg14 with SMTP id g14so144555qab.0 for ; Thu, 01 Dec 2011 21:17:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject :content-type; bh=Kp+gDJe0gPSibgGJyCbNWaqTAgbHZJeq5ng+z7axDh8=; b=O6MzT/iXal5yOS5F1mtnVvRSjNBcHjJ+UaVXKypErTZwXHWDYNAZLVIAv/I18NdUDq rAzMHTu3+Hn6HnQtDZS1+god7f13dMtaOrRVwH/99QWT/YT6H3GhOGGmeGNEv8YEv1Or fi1sNMlayXq4g3OjwvWwsRKh80aKi+iNKcmhM= Received: by 10.229.62.227 with SMTP id y35mr2021325qch.54.1322803030577; Thu, 01 Dec 2011 21:17:10 -0800 (PST) Received: from [127.0.0.1] (pool-74-104-23-109.bstnma.east.verizon.net. [74.104.23.109]) by mx.google.com with ESMTPS id cd3sm3420555qab.5.2011.12.01.21.17.09 (version=SSLv3 cipher=OTHER); Thu, 01 Dec 2011 21:17:09 -0800 (PST) Message-ID: <4ED85F41.5070605@gmail.com> Date: Fri, 02 Dec 2011 00:16:49 -0500 From: Peter Lustig User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 MIME-Version: 1.0 To: grub-devel@gnu.org Subject: Re: Re: New command to check NT's hibernation state Content-Type: multipart/mixed; boundary="------------080105020404030700040907" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.216.41 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, 02 Dec 2011 05:17:14 -0000 This is a multi-part message in MIME format. --------------080105020404030700040907 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit > Thanks for this. However the coding style isn't according to our > standards. Could you adjust to the standard? I recommend looking at > other code and reading GNU Coding Standard. E.g. we don't use {0} > initialiser, return value of commands, C++ comments or M$-$tyle > variables. Sorry about that. I've reviewed the standard and perused the source tree, as you suggested, to determine the best style. Attached is my updated file. Glad to be of help, Peter Lustig P.S. Do you know if there are any plans in the future to implement write operations for filesystems? (I noticed raw disk writing is currently supported.) If not, is the reason due to the technical challenges (e.g. NTFS only had read-only access in GNU/Linux for quite a while) or just a general lack of interest? --------------080105020404030700040907 Content-Type: text/plain; name="nthibr.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="nthibr.c" /* 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. * * 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 #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[] = { {0, 0, 0, 0, 0, 0} }; static grub_err_t grub_cmd_nthibr (grub_extcmd_context_t ctxt __attribute__ ((unused)), int argc, char **args) { grub_err_t status = GRUB_ERR_NONE; char *partition_name, hibr_file_path[32], hibr_file_magic[5]; grub_ssize_t length; grub_disk_t partition; grub_file_t hibr_file = 0; # define ABORT(_code, _message) \ do \ { \ status = grub_error ((_code), (_message)); \ goto exit; \ } \ while (0) /* Check argument count */ if (!argc) ABORT( GRUB_ERR_BAD_ARGUMENT, N_("too few arguments specified") ); else if (argc > 1) ABORT( GRUB_ERR_BAD_ARGUMENT, N_("too many arguments specified") ); partition_name = args[0]; length = (grub_ssize_t) grub_strlen (partition_name); /* Check if partition specifier 'looks right' */ if (partition_name[0] != '(' || partition_name[length - 1] != ')') ABORT( GRUB_ERR_BAD_FILENAME, N_("invalid partition specifier") ); /* Check if partition actually exists */ partition_name[length - 1] = '\0'; partition = grub_disk_open (partition_name + 1); if (!partition) ABORT( GRUB_ERR_UNKNOWN_DEVICE, N_("partition not found") ); else { grub_disk_close (partition); partition_name[length - 1] = ')'; } /* Build path to 'hiberfil.sys' */ grub_strncpy (hibr_file_path, partition_name, sizeof (hibr_file_path) - 1); grub_strncat (hibr_file_path, "/hiberfil.sys", sizeof (hibr_file_path) - grub_strlen (hibr_file_path) - 1); /* Try to open 'hiberfil.sys' */ hibr_file = grub_file_open (hibr_file_path); if (!hibr_file) ABORT( GRUB_ERR_FILE_NOT_FOUND, N_("'hiberfil.sys' not found") ); /* Try to read magic number of 'hiberfil.sys' */ length = (grub_ssize_t) (sizeof (hibr_file_magic) - 1); grub_memset (hibr_file_magic, 0, sizeof (hibr_file_magic)); if (grub_file_read (hibr_file, hibr_file_magic, length) < length) ABORT( GRUB_ERR_BAD_FILE_TYPE, N_("'hiberfil.sys' too small") ); /* Return SUCCESS if magic indicates file is active; else return FAILURE */ if (!grub_strncasecmp ("hibr", hibr_file_magic, length)) grub_puts (N_("The system is hibernated.")); else { grub_puts (N_("The system is NOT hibernated.")); status = GRUB_ERR_TEST_FAILURE; } exit: /* Ensure 'hiberfil.sys' is closed */ if (hibr_file) grub_file_close (hibr_file); # undef ABORT return status; } static grub_extcmd_t cmd; GRUB_MOD_INIT (nthibr) { cmd = 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); } --------------080105020404030700040907--