]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
split search
authorphcoder <phcoder@debian.bg45.phnet>
Tue, 22 Sep 2009 07:27:59 +0000 (09:27 +0200)
committerphcoder <phcoder@debian.bg45.phnet>
Tue, 22 Sep 2009 07:27:59 +0000 (09:27 +0200)
commands/search.c
conf/common.rmk
conf/i386-coreboot.rmk
conf/i386-efi.rmk
conf/i386-ieee1275.rmk
conf/i386-pc.rmk
conf/powerpc-ieee1275.rmk
conf/sparc64-ieee1275.rmk
conf/x86_64-efi.rmk

index 0cfd0ebbc732216a057d20b77c9d660689fa3407..60b5bbf04d128e82d7f382779ce31dcc5abfb6ec 100644 (file)
 #include <grub/env.h>
 #include <grub/extcmd.h>
 
-static const struct grub_arg_option options[] =
-  {
-    {"file",           'f', 0, "search devices by a file", 0, 0},
-    {"label",          'l', 0, "search devices by a filesystem label", 0, 0},
-    {"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},
-    {0, 0, 0, 0, 0, 0}
-  };
-
-enum options
-  {
-    SEARCH_FILE,
-    SEARCH_LABEL,
-    SEARCH_FS_UUID,
-    SEARCH_SET,
-    SEARCH_NO_FLOPPY,
- };
-
-static void
-search_fs (const char *key, const char *var, int no_floppy, enum options type)
+void
+FUNC_NAME (const char *key, const char *var, int no_floppy)
 {
   int count = 0;
   char *buf = NULL;
@@ -63,7 +44,7 @@ search_fs (const char *key, const char *var, int no_floppy, enum options type)
        name[0] == 'f' && name[1] == 'd' && name[2] >= '0' && name[2] <= '9')
       return 0;
 
-    if (type == SEARCH_FILE)
+#ifdef DO_SEARCH_FILE
       {
        grub_size_t len;
        char *p;
@@ -84,27 +65,29 @@ search_fs (const char *key, const char *var, int no_floppy, enum options type)
            grub_file_close (file);
          }
       }
-    else
+#else
       {
-       /* type is SEARCH_FS_UUID or SEARCH_LABEL */
+       /* SEARCH_FS_UUID or SEARCH_LABEL */
        grub_device_t dev;
        grub_fs_t fs;
-       int (*compare_fn) (const char *, const char *);
        char *quid;
 
        dev = grub_device_open (name);
        if (dev)
          {
            fs = grub_fs_probe (dev);
-           compare_fn =
-             (type == SEARCH_FS_UUID) ? grub_strcasecmp : grub_strcmp;
 
-           if (fs && ((type == SEARCH_FS_UUID) ? fs->uuid : fs->label))
+#ifdef DO_SEARCH_FS_UUID
+#define compare_fn grub_strcasecmp
+#define read_fn uuid
+#else
+#define compare_fn grub_strcmp
+#define read_fn label
+#endif
+
+           if (fs && fs->read_fn)
              {
-               if (type == SEARCH_FS_UUID)
-                 fs->uuid (dev, &quid);
-               else
-                 fs->label (dev, &quid);
+               fs->read_fn (dev, &quid);
 
                if (grub_errno == GRUB_ERR_NONE && quid)
                  {
@@ -118,6 +101,7 @@ search_fs (const char *key, const char *var, int no_floppy, enum options type)
            grub_device_close (dev);
          }
       }
+#endif
 
     if (found)
       {
@@ -156,45 +140,42 @@ search_fs (const char *key, const char *var, int no_floppy, enum options type)
 }
 
 static grub_err_t
-grub_cmd_search (grub_extcmd_t cmd, int argc, char **args)
+grub_cmd_do_search (grub_command_t cmd __attribute__ ((unused)), int argc,
+                   char **args)
 {
-  struct grub_arg_list *state = cmd->state;
-  const char *var = 0;
-
   if (argc == 0)
-    return grub_error (GRUB_ERR_INVALID_COMMAND, "no argument specified");
-
-  if (state[SEARCH_SET].set)
-    var = state[SEARCH_SET].arg ? state[SEARCH_SET].arg : "root";
+    return grub_error (GRUB_ERR_BAD_ARGUMENT, "no argument specified");
 
-  if (state[SEARCH_LABEL].set)
-    search_fs (args[0], var, state[SEARCH_NO_FLOPPY].set, SEARCH_LABEL);
-  else if (state[SEARCH_FS_UUID].set)
-    search_fs (args[0], var, state[SEARCH_NO_FLOPPY].set, SEARCH_FS_UUID);
-  else if (state[SEARCH_FILE].set)
-    search_fs (args[0], var, state[SEARCH_NO_FLOPPY].set, SEARCH_FILE);
-  else
-    return grub_error (GRUB_ERR_INVALID_COMMAND, "unspecified search type");
+  FUNC_NAME (args[0], argc == 1 ? 0 : args[1], 0);
 
   return grub_errno;
 }
 
-static grub_extcmd_t cmd;
+static grub_command_t cmd;
 
-GRUB_MOD_INIT(search)
+#ifdef SEARCH_FILE
+GRUB_MOD_INIT(search_file)
+#elif defined (SEARCH_FS_UUID)
+GRUB_MOD_INIT(search_fs_uuid)
+#else
+GRUB_MOD_INIT(search_fs_label)
+#endif
 {
   cmd =
-    grub_register_extcmd ("search", grub_cmd_search,
-                         GRUB_COMMAND_FLAG_BOTH,
-                         "search [-f|-l|-u|-s|-n] 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"
-                         " specified, \"root\" is used.",
-                         options);
+    grub_register_command (COMMAND_NAME, grub_cmd_do_search,
+                          COMMAND_NAME " NAME [VARIABLE]",
+                          "Search devices by " SEARCH_TARGET "."
+                         " If VARIABLE is specified, the first device found is"
+                         " set to a variable.");
 }
 
-GRUB_MOD_FINI(search)
+#ifdef SEARCH_FILE
+GRUB_MOD_FINI(search_file)
+#elif defined (SEARCH_FS_UUID)
+GRUB_MOD_FINI(search_fs_uuid)
+#else
+GRUB_MOD_FINI(search_fs_label)
+#endif
 {
-  grub_unregister_extcmd (cmd);
+  grub_unregister_command (cmd);
 }
index e18dd10520ca241df2064246aa5c39de21a5e822..9c8ac078db2bdffa775757343040560146a752eb 100644 (file)
@@ -363,7 +363,8 @@ scsi_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # Commands.
 pkglib_MODULES += minicmd.mod extcmd.mod hello.mod handler.mod \
-       ls.mod cmp.mod cat.mod help.mod search.mod loopback.mod \
+       ls.mod cmp.mod cat.mod help.mod search_file.mod \
+       search_fs_uuid.mod search_fs_label.mod search.mod loopback.mod  \
        fs_file.mod fs_uuid.mod configfile.mod echo.mod         \
        terminfo.mod test.mod blocklist.mod hexdump.mod         \
        read.mod sleep.mod loadenv.mod crc.mod parttool.mod     \
@@ -437,10 +438,25 @@ help_mod_CFLAGS = $(COMMON_CFLAGS)
 help_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
 # For search.mod.
-search_mod_SOURCES = commands/search.c
+search_mod_SOURCES = commands/search_wrap.c
 search_mod_CFLAGS = $(COMMON_CFLAGS)
 search_mod_LDFLAGS = $(COMMON_LDFLAGS)
 
+# For search.mod.
+search_file_mod_SOURCES = commands/search_file.c
+search_file_mod_CFLAGS = $(COMMON_CFLAGS)
+search_file_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For search.mod.
+search_label_mod_SOURCES = commands/search_label.c
+search_label_mod_CFLAGS = $(COMMON_CFLAGS)
+search_label_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
+# For search.mod.
+search_uuid_mod_SOURCES = commands/search_uuid.c
+search_uuid_mod_CFLAGS = $(COMMON_CFLAGS)
+search_uuid_mod_LDFLAGS = $(COMMON_LDFLAGS)
+
 # For test.mod.
 test_mod_SOURCES = commands/test.c
 test_mod_CFLAGS = $(COMMON_CFLAGS)
index 09ec7787c4ebdbcd412288d881070009a135062e..79c36eec135925324cd5fe5551c66be76784a2b2 100644 (file)
@@ -108,7 +108,7 @@ util/grub-emu.c_DEPENDENCIES = grub_emu_init.h
 grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c    \
        commands/configfile.c commands/echo.c commands/help.c           \
        commands/handler.c commands/ls.c commands/test.c                \
-       commands/search.c commands/blocklist.c commands/hexdump.c       \
+       commands/search_file.c commands/search_label.c commands/search_uuid.c commands/search_wrap.c commands/blocklist.c commands/hexdump.c    \
        commands/gptsync.c commands/probe.c commands/xnu_uuid.c         \
        commands/password.c commands/keystatus.c                        \
        lib/hexdump.c commands/i386/cpuid.c                             \
index 99ab06f6428177d9ebbfaf8777a2488695cf7a53..c9a412aafbd8ca3664b42b3b5d5f6ee6cac8dcab 100644 (file)
@@ -36,7 +36,7 @@ util/grub-emu.c_DEPENDENCIES = grub_emu_init.h
 grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c    \
        commands/configfile.c commands/help.c                           \
        commands/handler.c commands/ls.c commands/test.c                \
-       commands/search.c commands/hexdump.c lib/hexdump.c              \
+       commands/search_file.c commands/search_label.c commands/search_uuid.c commands/search_wrap.c commands/hexdump.c lib/hexdump.c           \
        commands/halt.c commands/reboot.c commands/keystatus.c          \
        commands/i386/cpuid.c                                           \
        commands/password.c                                             \
index 4b640de499d59cbfaaf5f7d33efa4144386570a6..6b15b147338b46e2ecee4cd2398cf5831694d250 100644 (file)
@@ -62,7 +62,7 @@ util/grub-emu.c_DEPENDENCIES = grub_emu_init.h
 grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c    \
        commands/configfile.c commands/echo.c commands/help.c           \
        commands/handler.c commands/ls.c commands/test.c                \
-       commands/search.c commands/blocklist.c commands/hexdump.c       \
+       commands/search_file.c commands/search_label.c commands/search_uuid.c commands/search_wrap.c commands/blocklist.c commands/hexdump.c    \
        lib/hexdump.c commands/halt.c commands/reboot.c                 \
        lib/envblk.c commands/loadenv.c                                 \
        commands/gptsync.c commands/probe.c  commands/xnu_uuid.c        \
index bf8fbfb9d765c334acabae0b5e7404ecd7fd0852..87364223cf5b09aeab54a01bd7581db5f7e0a6d5 100644 (file)
@@ -120,7 +120,7 @@ util/grub-emu.c_DEPENDENCIES = grub_emu_init.h
 grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c    \
        commands/configfile.c commands/echo.c commands/help.c           \
        commands/handler.c commands/ls.c commands/test.c                \
-       commands/search.c commands/blocklist.c commands/hexdump.c       \
+       commands/search_file.c commands/search_label.c commands/search_uuid.c commands/search_wrap.c commands/blocklist.c commands/hexdump.c    \
        lib/hexdump.c commands/i386/pc/halt.c commands/reboot.c         \
        lib/envblk.c commands/loadenv.c                                 \
        commands/gptsync.c commands/probe.c commands/xnu_uuid.c         \
index ee7f9ec27e65b0648dca4c3f9a86168332cbc5aa..df594cfd0a8127a6ed19b61b7d779bc20d2880f1 100644 (file)
@@ -42,7 +42,7 @@ grub_mkdevicemap_SOURCES = util/grub-mkdevicemap.c util/deviceiter.c \
 util/grub-emu.c_DEPENDENCIES = grub_emu_init.h
 grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c    \
        commands/configfile.c commands/help.c                           \
-       commands/search.c commands/handler.c commands/test.c            \
+       commands/search_file.c commands/search_label.c commands/search_uuid.c commands/search_wrap.c commands/handler.c commands/test.c                 \
        commands/ls.c commands/blocklist.c commands/hexdump.c           \
        lib/hexdump.c commands/halt.c commands/reboot.c                 \
        lib/envblk.c commands/loadenv.c                                 \
index 62e951a5e5843d6026f88673462921f8ddc2a061..936d4818aaf6dbd1905f41c2bc2faa7f802f81af 100644 (file)
@@ -100,7 +100,7 @@ grub_ofpathname_SOURCES = util/sparc64/ieee1275/grub-ofpathname.c \
 util/grub-emu.c_DEPENDENCIES = grub_emu_init.h
 grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c    \
        commands/configfile.c commands/help.c                           \
-       commands/search.c commands/handler.c commands/test.c            \
+       commands/search_file.c commands/search_label.c commands/search_uuid.c commands/search_wrap.c commands/handler.c commands/test.c                 \
        commands/ls.c commands/blocklist.c commands/hexdump.c           \
        lib/hexdump.c commands/halt.c commands/reboot.c                 \
        lib/envblk.c commands/loadenv.c                                 \
index 934cd7284b343a2be6bf940e60322a7d2f929a43..a17cd5928ba7fb306f1587a1fb0ed3b7ac9de906 100644 (file)
@@ -34,7 +34,7 @@ util/grub-emu.c_DEPENDENCIES = grub_emu_init.h
 grub_emu_SOURCES = commands/minicmd.c commands/cat.c commands/cmp.c    \
        commands/configfile.c commands/help.c                           \
        commands/handler.c commands/ls.c commands/test.c                \
-       commands/search.c commands/hexdump.c lib/hexdump.c              \
+       commands/search_file.c commands/search_label.c commands/search_uuid.c commands/search_wrap.c commands/hexdump.c lib/hexdump.c           \
        commands/halt.c commands/reboot.c                               \
        commands/i386/cpuid.c                                           \
        commands/password.c commands/keystatus.c                        \