From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1MItG9-0002re-H4 for mharc-grub-devel@gnu.org; Mon, 22 Jun 2009 19:49:09 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MItG8-0002rR-Dv for grub-devel@gnu.org; Mon, 22 Jun 2009 19:49:08 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MItG2-0002oT-VT for grub-devel@gnu.org; Mon, 22 Jun 2009 19:49:07 -0400 Received: from [199.232.76.173] (port=60362 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MItG2-0002oN-SQ for grub-devel@gnu.org; Mon, 22 Jun 2009 19:49:02 -0400 Received: from aybabtu.com ([69.60.117.155]:54664) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MItG2-0001jZ-FE for grub-devel@gnu.org; Mon, 22 Jun 2009 19:49:02 -0400 Received: from [192.168.10.10] (helo=thorin) by aybabtu.com with esmtp (Exim 4.69) (envelope-from ) id 1MIsD0-0002aN-DA for grub-devel@gnu.org; Tue, 23 Jun 2009 00:41:50 +0200 Received: from rmh by thorin with local (Exim 4.69) (envelope-from ) id 1MItFz-0004N0-9L for grub-devel@gnu.org; Tue, 23 Jun 2009 01:48:59 +0200 Date: Tue, 23 Jun 2009 01:48:59 +0200 From: Robert Millan To: grub-devel@gnu.org Message-ID: <20090622234859.GA16795@thorin> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="6c2NcOVqGQ03X4Wi" Content-Disposition: inline Organization: free as in freedom X-Message-Flag: Worried about Outlook viruses? Switch to Thunderbird! www.mozilla.com/thunderbird X-Debbugs-No-Ack: true User-Agent: Mutt/1.5.18 (2008-05-17) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 1) Subject: [PATCH] search -d|--disk 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: Mon, 22 Jun 2009 23:49:08 -0000 --6c2NcOVqGQ03X4Wi Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, This patch adds an option to the search command to restrict the search of a file to a given disk. It will then probe for the file in each of its partitions, but not in other disks. -- Robert Millan The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and how) you may access your data; but nobody's threatening your freedom: we still allow you to remove your data and not access it at all." --6c2NcOVqGQ03X4Wi Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="disk.diff" 2009-06-22 Robert Millan * commands/search.c: Include `' and `'. (struct grub_arg_option options): Add "disk" option. (enum options): Add `SEARCH_DISK' key. (search_file): Add a new parameter, `restrict_to', which when set will restrict the search to a given disk. (grub_cmd_search): Recognize -d|--disk option, and pass it as parameter to search_file(). Index: commands/search.c =================================================================== --- commands/search.c (revision 2362) +++ commands/search.c (working copy) @@ -23,6 +23,8 @@ #include #include #include +#include +#include #include #include #include @@ -34,6 +36,7 @@ static const struct grub_arg_option opti {"fs-uuid", 'u', 0, "search devices by a filesystem UUID", 0, 0}, {"set", 's', GRUB_ARG_OPTION_OPTIONAL, "set a variable to the first device found", "VAR", ARG_TYPE_STRING}, {"no-floppy", 'n', 0, "do not probe any floppy drive", 0, 0}, + {"disk", 'd', 0, "only search a file in this disk and its partitions", "VAR", ARG_TYPE_DEVICE}, {0, 0, 0, 0, 0, 0} }; @@ -44,6 +47,7 @@ enum options SEARCH_FS_UUID, SEARCH_SET, SEARCH_NO_FLOPPY, + SEARCH_DISK, }; static void @@ -110,7 +114,7 @@ search_fs (const char *key, const char * } static void -search_file (const char *key, const char *var, int no_floppy) +search_file (const char *key, const char *var, int no_floppy, grub_disk_t restrict_to) { int count = 0; char *buf = 0; @@ -157,7 +161,37 @@ search_file (const char *key, const char return abort; } - grub_device_iterate (iterate_device); + if (restrict_to) + { + unsigned int partcount = 0, i; + grub_size_t len; + char *partname; + int ret; + + auto int hook (struct grub_disk *disk, const grub_partition_t partition); + int hook (struct grub_disk *disk __attribute__ ((unused)), + const grub_partition_t partition __attribute__ ((unused))) + { + partcount++; + return 0; + } + + grub_partition_iterate (restrict_to, hook); + + if (! iterate_device (restrict_to->name)) + for (i = 1; i <= partcount; i++) + { + len = grub_strlen (restrict_to->name); + partname = grub_malloc (len + 4); + grub_sprintf (partname, "%s,%u", restrict_to->name, i); + ret = iterate_device (partname); + grub_free (partname); + if (ret) + break; + } + } + else + grub_device_iterate (iterate_device); grub_free (buf); @@ -170,6 +204,7 @@ grub_cmd_search (grub_extcmd_t cmd, int { struct grub_arg_list *state = cmd->state; const char *var = 0; + grub_disk_t disk = NULL; if (argc == 0) return grub_error (GRUB_ERR_INVALID_COMMAND, "no argument specified"); @@ -177,12 +212,20 @@ grub_cmd_search (grub_extcmd_t cmd, int if (state[SEARCH_SET].set) var = state[SEARCH_SET].arg ? state[SEARCH_SET].arg : "root"; + if (state[SEARCH_DISK].set) + { + if (state[SEARCH_DISK].arg) + disk = grub_disk_open (state[SEARCH_DISK].arg); + else + return grub_error (GRUB_ERR_INVALID_COMMAND, "unspecified disk"); + } + if (state[SEARCH_LABEL].set) search_fs (args[0], var, state[SEARCH_NO_FLOPPY].set, 0); else if (state[SEARCH_FS_UUID].set) search_fs (args[0], var, state[SEARCH_NO_FLOPPY].set, 1); else if (state[SEARCH_FILE].set) - search_file (args[0], var, state[SEARCH_NO_FLOPPY].set); + search_file (args[0], var, state[SEARCH_NO_FLOPPY].set, disk); else return grub_error (GRUB_ERR_INVALID_COMMAND, "unspecified search type"); @@ -196,7 +239,7 @@ GRUB_MOD_INIT(search) cmd = grub_register_extcmd ("search", grub_cmd_search, GRUB_COMMAND_FLAG_BOTH, - "search [-f|-l|-u|-s|-n] NAME", + "search [-f|-l|-u|-s|-n|-d] NAME", "Search devices by file, filesystem label or filesystem UUID." " If --set is specified, the first device found is" " set to a variable. If no variable name is" --6c2NcOVqGQ03X4Wi--