]> git.ozlabs.org Git - petitboot/commitdiff
Move path maniuplation functions to devices/paths.c
authorJeremy Kerr <jk@ozlabs.org>
Thu, 3 Jan 2008 03:46:06 +0000 (14:46 +1100)
committerJeremy Kerr <jk@ozlabs.org>
Thu, 3 Jan 2008 03:46:06 +0000 (14:46 +1100)
This allows us to include the real functions in the parser testsuite,
instead of using fakes.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
12 files changed:
Makefile
devices/parser-test.c
devices/parser-test.sh
devices/parser-tests/001/etc/kboot.conf [deleted file]
devices/parser-tests/001/expected-output
devices/parser-tests/001/ps3da1/etc/kboot.conf [new file with mode: 0644]
devices/parser-tests/002/etc/yaboot.conf [deleted file]
devices/parser-tests/002/expected-output
devices/parser-tests/002/ps3da1/etc/yaboot.conf [new file with mode: 0644]
devices/paths.c [new file with mode: 0644]
devices/paths.h [new file with mode: 0644]
devices/udev-helper.c

index 6fb27cfe29db1fdae2e36bff16bbf66c012cb294..2759a45ea4d3997ee24ca08db88e7cf00412593d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -21,12 +21,12 @@ petitboot: LDFLAGS+=$(TWIN_LDFLAGS)
 petitboot: CFLAGS+=$(TWIN_CFLAGS)
 
 udev-helper: devices/udev-helper.o devices/params.o devices/parser.o \
-               devices/yaboot-cfg.o \
+               devices/paths.o devices/yaboot-cfg.o \
                $(foreach p,$(PARSERS),devices/$(p)-parser.o)
        $(CC) $(LDFLAGS) -o $@ $^
 
 parser-test: devices/parser-test.o devices/params.o devices/parser.o \
-               devices/yaboot-cfg.o \
+               devices/paths.o devices/yaboot-cfg.o \
                $(foreach p,$(PARSERS),devices/$(p)-parser.o)
        $(CC) $(LDFLAGS) -o $@ $^
 
index 12348b8991f680bb3c0683f257ff58c823a9165b..8c94d3f899d4c2f43ea4945ae006ccd619a05065 100644 (file)
@@ -7,6 +7,7 @@
 #include <string.h>
 
 #include "parser.h"
+#include "paths.h"
 
 void pb_log(const char *fmt, ...)
 {
@@ -63,45 +64,22 @@ enum generic_icon_type guess_device_type(void)
        return ICON_TYPE_UNKNOWN;
 }
 
-static char *mountpoint;
-
-/* pretend that all devices are mounted at our original mountpoint */
-const char *mountpoint_for_device(const char *dev_path)
-{
-       return mountpoint;
-}
-
-char *resolve_path(const char *path, const char *default_mountpoint)
-{
-       char *sep, *ret;
-       const char *devpath;
-
-       sep = strchr(path, ':');
-       if (!sep) {
-               devpath = default_mountpoint;
-               asprintf(&ret, "%s/%s", devpath, path);
-       } else {
-               char *tmp = strndup(path, sep - path);
-               devpath = mountpoint_for_device(path);
-               asprintf(&ret, "%s/%s", devpath, sep + 1);
-               free(tmp);
-       }
-
-       return ret;
-}
-
 int main(int argc, char **argv)
 {
-       const char *dev = "sda1";
+       char *mountpoint, *dev;
 
-       if (argc != 2) {
-               fprintf(stderr, "usage: %s <fake-mountpoint>\n", argv[0]);
+       if (argc != 3) {
+               fprintf(stderr, "usage: %s <basedir> <devname>\n", argv[0]);
                return EXIT_FAILURE;
        }
 
        mountpoint = argv[1];
+       dev = argv[2];
+
+       set_mount_base(mountpoint);
 
        iterate_parsers(dev, mountpoint);
 
+
        return EXIT_SUCCESS;
 }
index 351dc75a5bab3e9c0571255f3388e3f13529edb1..cdd814b7c13b53fe35e91fe42cde9b9600f508ff 100755 (executable)
@@ -1,11 +1,17 @@
 #!/bin/bash
 
 testdir=devices/parser-tests
+default_rootdev=ps3da1
 
 function test_dir()
 {
        dir="$1"
-       ./parser-test "$dir" 2>/dev/null |
+       rootdev=$default_rootdev
+       if [ -e "$dir/rootdev" ]
+       then
+               rootdev=$(cat "$dir/rootdev")
+       fi
+       ./parser-test "$dir" $rootdev 2>/dev/null |
                diff -u "$dir/expected-output" -
 }
 
diff --git a/devices/parser-tests/001/etc/kboot.conf b/devices/parser-tests/001/etc/kboot.conf
deleted file mode 100644 (file)
index 591c51b..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-# Ubuntu feisty kboot.conf
-message=/etc/kboot.msg
-timeout=300
-default=live
-live='/casper/vmlinux initrd=/casper/initrd.gz  file=/cdrom/preseed/ubuntu.seed boot=casper quiet splash --'
-live_nosplash='/casper/vmlinux initrd=/casper/initrd.gz  file=/cdrom/preseed/ubuntu.seed boot=casper quiet --'
-driverupdates='/casper/vmlinux initrd=/casper/initrd.gz  file=/cdrom/preseed/ubuntu.seed boot=casper debian-installer/driver-update=true quiet splash --'
-check='/casper/vmlinux initrd=/casper/initrd.gz  boot=casper integrity-check quiet splash --'
-
index 6e686714a4452e700b3e1c3a6eb74aae45b210d3..9d2d0ecc8c7181f4b055b236fec0f99078e35799 100644 (file)
@@ -1,24 +1,24 @@
-[dev  0] id: sda1
+[dev  0] id: ps3da1
 [dev  0] name: (null)
 [dev  0] description: (null)
 [dev  0] boot_image: /usr/share/petitboot/artwork/hdd.png
 [opt  0] name: live
 [opt  0] description: /casper/vmlinux root=/dev/ram0 initrd=/casper/initrd.gz   file=/cdrom/preseed/ubuntu.seed boot=casper quiet splash --
-[opt  0] boot_image: devices/parser-tests/001//casper/vmlinux
-[opt  0] initrd: devices/parser-tests/001//casper/initrd.gz
+[opt  0] boot_image: devices/parser-tests/001/ps3da1//casper/vmlinux
+[opt  0] initrd: devices/parser-tests/001/ps3da1//casper/initrd.gz
 [opt  0] boot_args: root=/dev/ram0 initrd=/casper/initrd.gz   file=/cdrom/preseed/ubuntu.seed boot=casper quiet splash --
 [opt  1] name: live_nosplash
 [opt  1] description: /casper/vmlinux root=/dev/ram0 initrd=/casper/initrd.gz   file=/cdrom/preseed/ubuntu.seed boot=casper quiet --
-[opt  1] boot_image: devices/parser-tests/001//casper/vmlinux
-[opt  1] initrd: devices/parser-tests/001//casper/initrd.gz
+[opt  1] boot_image: devices/parser-tests/001/ps3da1//casper/vmlinux
+[opt  1] initrd: devices/parser-tests/001/ps3da1//casper/initrd.gz
 [opt  1] boot_args: root=/dev/ram0 initrd=/casper/initrd.gz   file=/cdrom/preseed/ubuntu.seed boot=casper quiet --
 [opt  2] name: driverupdates
 [opt  2] description: /casper/vmlinux root=/dev/ram0 initrd=/casper/initrd.gz   file=/cdrom/preseed/ubuntu.seed boot=casper debian-installer/driver-update=true quiet splash --
-[opt  2] boot_image: devices/parser-tests/001//casper/vmlinux
-[opt  2] initrd: devices/parser-tests/001//casper/initrd.gz
+[opt  2] boot_image: devices/parser-tests/001/ps3da1//casper/vmlinux
+[opt  2] initrd: devices/parser-tests/001/ps3da1//casper/initrd.gz
 [opt  2] boot_args: root=/dev/ram0 initrd=/casper/initrd.gz   file=/cdrom/preseed/ubuntu.seed boot=casper debian-installer/driver-update=true quiet splash --
 [opt  3] name: check
 [opt  3] description: /casper/vmlinux root=/dev/ram0 initrd=/casper/initrd.gz   boot=casper integrity-check quiet splash --
-[opt  3] boot_image: devices/parser-tests/001//casper/vmlinux
-[opt  3] initrd: devices/parser-tests/001//casper/initrd.gz
+[opt  3] boot_image: devices/parser-tests/001/ps3da1//casper/vmlinux
+[opt  3] initrd: devices/parser-tests/001/ps3da1//casper/initrd.gz
 [opt  3] boot_args: root=/dev/ram0 initrd=/casper/initrd.gz   boot=casper integrity-check quiet splash --
diff --git a/devices/parser-tests/001/ps3da1/etc/kboot.conf b/devices/parser-tests/001/ps3da1/etc/kboot.conf
new file mode 100644 (file)
index 0000000..591c51b
--- /dev/null
@@ -0,0 +1,9 @@
+# Ubuntu feisty kboot.conf
+message=/etc/kboot.msg
+timeout=300
+default=live
+live='/casper/vmlinux initrd=/casper/initrd.gz  file=/cdrom/preseed/ubuntu.seed boot=casper quiet splash --'
+live_nosplash='/casper/vmlinux initrd=/casper/initrd.gz  file=/cdrom/preseed/ubuntu.seed boot=casper quiet --'
+driverupdates='/casper/vmlinux initrd=/casper/initrd.gz  file=/cdrom/preseed/ubuntu.seed boot=casper debian-installer/driver-update=true quiet splash --'
+check='/casper/vmlinux initrd=/casper/initrd.gz  boot=casper integrity-check quiet splash --'
+
diff --git a/devices/parser-tests/002/etc/yaboot.conf b/devices/parser-tests/002/etc/yaboot.conf
deleted file mode 100644 (file)
index f13b1b3..0000000
+++ /dev/null
@@ -1,8 +0,0 @@
-init-message = "\nWelcome to the 64-bit Yellow Dog Linux 5.0 installer!\nHit <TAB> for boot options.\n\n"
-timeout=6000
-default=linux
-
-image=/ppc/ppc64/vmlinux
-       label=linux
-       initrd=/ppc/ppc64/ramdisk.image.gz
-       read-only
index d0dde258a3ea348497915881aac609be798084e6..9d2a1468290411da9493ebe2ee87b85c2fc6d75d 100644 (file)
@@ -1,9 +1,9 @@
-[dev  0] id: sda1
+[dev  0] id: ps3da1
 [dev  0] name: (null)
 [dev  0] description: 
 [dev  0] boot_image: /usr/share/petitboot/artwork/hdd.png
 [opt  0] name: linux
 [opt  0] description: (null)
-[opt  0] boot_image: devices/parser-tests/002//ppc/ppc64/vmlinux
-[opt  0] initrd: devices/parser-tests/002//ppc/ppc64/ramdisk.image.gz
+[opt  0] boot_image: devices/parser-tests/002/ps3da1//ppc/ppc64/vmlinux
+[opt  0] initrd: devices/parser-tests/002/ps3da1//ppc/ppc64/ramdisk.image.gz
 [opt  0] boot_args: ro 
diff --git a/devices/parser-tests/002/ps3da1/etc/yaboot.conf b/devices/parser-tests/002/ps3da1/etc/yaboot.conf
new file mode 100644 (file)
index 0000000..f13b1b3
--- /dev/null
@@ -0,0 +1,8 @@
+init-message = "\nWelcome to the 64-bit Yellow Dog Linux 5.0 installer!\nHit <TAB> for boot options.\n\n"
+timeout=6000
+default=linux
+
+image=/ppc/ppc64/vmlinux
+       label=linux
+       initrd=/ppc/ppc64/ramdisk.image.gz
+       read-only
diff --git a/devices/paths.c b/devices/paths.c
new file mode 100644 (file)
index 0000000..a1df5d2
--- /dev/null
@@ -0,0 +1,69 @@
+#define _GNU_SOURCE
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "paths.h"
+
+static char *mount_base;
+
+struct device_map {
+       char *dev, *mnt;
+};
+
+#define DEVICE_MAP_SIZE 32
+static struct device_map device_map[DEVICE_MAP_SIZE];
+
+const char *mountpoint_for_device(const char *dev_path)
+{
+       int i;
+       const char *basename;
+
+       /* shorten '/dev/foo' to 'foo' */
+       basename = strrchr(dev_path, '/');
+       if (basename)
+               basename++;
+       else
+               basename = dev_path;
+
+       /* check existing entries in the map */
+       for (i = 0; (i < DEVICE_MAP_SIZE) && device_map[i].dev; i++)
+               if (!strcmp(device_map[i].dev, basename))
+                       return device_map[i].mnt;
+
+       if (i == DEVICE_MAP_SIZE)
+               return NULL;
+
+       device_map[i].dev = strdup(dev_path);
+       asprintf(&device_map[i].mnt, "%s/%s", mount_base, basename);
+       return device_map[i].mnt;
+}
+
+char *resolve_path(const char *path, const char *current_mountpoint)
+{
+       char *ret;
+       const char *devpath, *sep;
+
+       sep = strchr(path, ':');
+       if (!sep) {
+               devpath = current_mountpoint;
+               asprintf(&ret, "%s/%s", devpath, path);
+       } else {
+               /* copy just the device name into tmp */
+               char *dev = strndup(path, sep - path);
+               devpath = mountpoint_for_device(dev);
+               asprintf(&ret, "%s/%s", devpath, sep + 1);
+               free(dev);
+       }
+
+       return ret;
+}
+
+void set_mount_base(const char *path)
+{
+       if (mount_base)
+               free(mount_base);
+       mount_base = strdup(path);
+}
+
diff --git a/devices/paths.h b/devices/paths.h
new file mode 100644 (file)
index 0000000..eca6689
--- /dev/null
@@ -0,0 +1,27 @@
+#ifndef PATHS_H
+#define PATHS_H
+
+/**
+ * Get the mountpoint for a device
+ */
+const char *mountpoint_for_device(const char *dev_path);
+
+/**
+ * Resolve a path given in a config file, to a path in the local filesystem.
+ * Paths may be of the form:
+ *  device:path (eg /dev/sda:/boot/vmlinux)
+ *
+ * or just a path:
+ *  /boot/vmlinux
+ * - in this case, the current mountpoint is used.
+ *
+ * Returns a newly-allocated string containing a full path to the file in path
+ */
+char *resolve_path(const char *path, const char *current_mountpoint);
+
+/**
+ * Set the base directory for newly-created mountpoints
+ */
+void set_mount_base(const char *path);
+
+#endif /* PATHS_H */
index 4826f9da73f2cf16a2e86e9d58ce6ad1d5e719da..a55d3780906e15d5274fec996b2bf6ce8906bd5d 100644 (file)
@@ -19,6 +19,7 @@
 #include <sys/ioctl.h>
 
 #include "parser.h"
+#include "paths.h"
 #include "petitboot-paths.h"
 
 /* Define below to operate without the frontend */
@@ -183,69 +184,6 @@ int connect_to_socket()
 #endif
 }
 
-struct device_map {
-       char *dev, *mnt;
-};
-
-#define DEVICE_MAP_SIZE 32
-static struct device_map device_map[DEVICE_MAP_SIZE];
-
-const char *mountpoint_for_device(const char *dev_path)
-{
-       int i;
-       const char *basename;
-
-       /* shorten '/dev/foo' to 'foo' */
-       basename = strrchr(dev_path, '/');
-       if (basename)
-               basename++;
-       else
-               basename = dev_path;
-
-       /* check existing entries in the map */
-       for (i = 0; (i < DEVICE_MAP_SIZE) && device_map[i].dev; i++)
-               if (!strcmp(device_map[i].dev, basename))
-                       return device_map[i].mnt;
-
-       if (i == DEVICE_MAP_SIZE)
-               return NULL;
-
-       device_map[i].dev = strdup(dev_path);
-       asprintf(&device_map[i].mnt, "%s/%s", TMP_DIR, basename);
-       return device_map[i].mnt;
-}
-
-/**
- * Resolve a path given in a config file, to a path in the local filesystem.
- * Paths may be of the form:
- *  device:path (eg /dev/sda:/boot/vmlinux)
- *
- * or just a path:
- *  /boot/vmlinux
- * - in this case, the default mountpoint is used.
- *
- * Returns a newly-allocated string containing a full path to the file in path
- */
-char *resolve_path(const char *path, const char *default_mountpoint)
-{
-       char *ret;
-       const char *devpath, *sep;
-
-       sep = strchr(path, ':');
-       if (!sep) {
-               devpath = default_mountpoint;
-               asprintf(&ret, "%s/%s", devpath, path);
-       } else {
-               /* copy just the device name into tmp */
-               char *dev = strndup(path, sep - path);
-               devpath = mountpoint_for_device(dev);
-               asprintf(&ret, "%s/%s", devpath, sep + 1);
-               free(dev);
-       }
-
-       return ret;
-}
-
 int mount_device(const char *dev_path)
 {
        const char *dir;
@@ -562,6 +500,8 @@ int main(int argc, char **argv)
                return EXIT_FAILURE;
        }
 
+       set_mount_base(TMP_DIR);
+
        if (connect_to_socket())
                return EXIT_FAILURE;