From: Robert Millan <rmh@aybabtu.com>
To: grub-devel@gnu.org
Subject: [PATCH] search -d|--disk
Date: Tue, 23 Jun 2009 01:48:59 +0200 [thread overview]
Message-ID: <20090622234859.GA16795@thorin> (raw)
[-- Attachment #1: Type: text/plain, Size: 425 bytes --]
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."
[-- Attachment #2: disk.diff --]
[-- Type: text/x-diff, Size: 4111 bytes --]
2009-06-22 Robert Millan <rmh.grub@aybabtu.com>
* commands/search.c: Include `<grub/disk.h>' and
`<grub/partition.h>'.
(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 <grub/err.h>
#include <grub/dl.h>
#include <grub/device.h>
+#include <grub/disk.h>
+#include <grub/partition.h>
#include <grub/file.h>
#include <grub/env.h>
#include <grub/extcmd.h>
@@ -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"
next reply other threads:[~2009-06-22 23:49 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-22 23:48 Robert Millan [this message]
2009-06-23 1:51 ` [PATCH] search -d|--disk Pavel Roskin
2009-06-23 11:50 ` Robert Millan
2009-06-23 21:17 ` Pavel Roskin
2009-06-23 21:55 ` Robert Millan
2009-06-24 3:03 ` Arthur Marsh
2009-06-24 12:04 ` Robert Millan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090622234859.GA16795@thorin \
--to=rmh@aybabtu.com \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.