aboutsummaryrefslogtreecommitdiffstats
path: root/com32/modules
diff options
context:
space:
mode:
authorShao Miller <sha0.miller@gmail.com>2012-10-25 02:17:36 -0400
committerShao Miller <sha0.miller@gmail.com>2012-11-03 01:02:14 -0400
commit5d7c2cdf73c3d901637d8e9f0a612f2cd8624cd0 (patch)
tree9027f1fa336e10a76187ea33c3ad5ad6909a6140 /com32/modules
parent8eaa4ebbe2a6999bd58aa68054dd48ec26cabd28 (diff)
downloadsyslinux-5d7c2cdf73c3d901637d8e9f0a612f2cd8624cd0.tar.gz
syslinux-5d7c2cdf73c3d901637d8e9f0a612f2cd8624cd0.tar.xz
syslinux-5d7c2cdf73c3d901637d8e9f0a612f2cd8624cd0.zip
linux.c32: Move some initrd=x,y,z code out of main
In handling an "initrd=x,y,z" option, it seems reasonable to be able to handle similar options in a similar fashion, so some of the code has been moved out of 'main' and into a new 'process_initramfs_args' function. Signed-off-by: Shao Miller <sha0.miller@gmail.com>
Diffstat (limited to 'com32/modules')
-rw-r--r--com32/modules/linux.c82
1 files changed, 61 insertions, 21 deletions
diff --git a/com32/modules/linux.c b/com32/modules/linux.c
index 0d9e962e..3ff50076 100644
--- a/com32/modules/linux.c
+++ b/com32/modules/linux.c
@@ -48,6 +48,13 @@
#include <syslinux/linux.h>
#include <syslinux/pxe.h>
+enum ldmode {
+ ldmode_raw,
+ ldmodes
+};
+
+typedef int f_ldinitramfs(struct initramfs *, char *);
+
const char *progname = "linux.c32";
/* Find the last instance of a particular command line argument
@@ -130,6 +137,55 @@ static char *make_cmdline(char **argv)
return cmdline;
}
+static f_ldinitramfs ldinitramfs_raw;
+static int ldinitramfs_raw(struct initramfs *initramfs, char *fname)
+{
+ return initramfs_load_archive(initramfs, fname);
+}
+
+/* It only makes sense to call this function from main */
+static int process_initramfs_args(char *arg, struct initramfs *initramfs,
+ const char *kernel_name, enum ldmode mode,
+ bool opt_quiet)
+{
+ const char *mode_msg;
+ f_ldinitramfs *ldinitramfs;
+ char *p;
+
+ switch (mode) {
+ case ldmode_raw:
+ mode_msg = "Loading";
+ ldinitramfs = ldinitramfs_raw;
+ break;
+ case ldmodes:
+ default:
+ return 1;
+ }
+
+ do {
+ p = strchr(arg, ',');
+ if (p)
+ *p = '\0';
+
+ if (!opt_quiet)
+ printf("%s %s... ", mode_msg, arg);
+ errno = 0;
+ if (ldinitramfs(initramfs, arg)) {
+ if (opt_quiet)
+ printf("Loading %s ", kernel_name);
+ printf("failed: ");
+ return 1;
+ }
+ if (!opt_quiet)
+ printf("ok\n");
+
+ if (p)
+ *p++ = ',';
+ } while ((arg = p));
+
+ return 0;
+}
+
static int setup_data_file(struct setup_data *setup_data,
uint32_t type, const char *filename,
bool opt_quiet)
@@ -163,7 +219,7 @@ int main(int argc, char *argv[])
bool opt_quiet = false;
void *dhcpdata;
size_t dhcplen;
- char **argp, **argl, *arg, *p;
+ char **argp, **argl, *arg;
(void)argc;
argp = argv + 1;
@@ -228,27 +284,11 @@ int main(int argc, char *argv[])
goto bail;
}
+ /* Process initramfs arguments */
if ((arg = find_argument(argp, "initrd="))) {
- do {
- p = strchr(arg, ',');
- if (p)
- *p = '\0';
-
- if (!opt_quiet)
- printf("Loading %s... ", arg);
- errno = 0;
- if (initramfs_load_archive(initramfs, arg)) {
- if (opt_quiet)
- printf("Loading %s ", kernel_name);
- printf("failed: ");
- goto bail;
- }
- if (!opt_quiet)
- printf("ok\n");
-
- if (p)
- *p++ = ',';
- } while ((arg = p));
+ if (process_initramfs_args(arg, initramfs, kernel_name, ldmode_raw,
+ opt_quiet))
+ goto bail;
}
/* Append the DHCP info */