diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2008-01-03 14:46:06 +1100 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2008-01-03 14:46:06 +1100 |
commit | dbacb44c0ebb587b5cfcbbf84c770502c217473a (patch) | |
tree | 43c0c9cf3df61c79f0f545ed496302a296122e27 | |
parent | 02aeee42aebbb3a7098b6e0fc570522f9d44de96 (diff) | |
download | talos-petitboot-dbacb44c0ebb587b5cfcbbf84c770502c217473a.tar.gz talos-petitboot-dbacb44c0ebb587b5cfcbbf84c770502c217473a.zip |
Move path maniuplation functions to devices/paths.c
This allows us to include the real functions in the parser testsuite,
instead of using fakes.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | devices/parser-test.c | 38 | ||||
-rwxr-xr-x | devices/parser-test.sh | 8 | ||||
-rw-r--r-- | devices/parser-tests/001/expected-output | 18 | ||||
-rw-r--r-- | devices/parser-tests/001/ps3da1/etc/kboot.conf (renamed from devices/parser-tests/001/etc/kboot.conf) | 0 | ||||
-rw-r--r-- | devices/parser-tests/002/expected-output | 6 | ||||
-rw-r--r-- | devices/parser-tests/002/ps3da1/etc/yaboot.conf (renamed from devices/parser-tests/002/etc/yaboot.conf) | 0 | ||||
-rw-r--r-- | devices/paths.c | 69 | ||||
-rw-r--r-- | devices/paths.h | 27 | ||||
-rw-r--r-- | devices/udev-helper.c | 66 |
10 files changed, 128 insertions, 108 deletions
@@ -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 $@ $^ diff --git a/devices/parser-test.c b/devices/parser-test.c index 12348b8..8c94d3f 100644 --- a/devices/parser-test.c +++ b/devices/parser-test.c @@ -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; } diff --git a/devices/parser-test.sh b/devices/parser-test.sh index 351dc75..cdd814b 100755 --- a/devices/parser-test.sh +++ b/devices/parser-test.sh @@ -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/expected-output b/devices/parser-tests/001/expected-output index 6e68671..9d2d0ec 100644 --- a/devices/parser-tests/001/expected-output +++ b/devices/parser-tests/001/expected-output @@ -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/etc/kboot.conf b/devices/parser-tests/001/ps3da1/etc/kboot.conf index 591c51b..591c51b 100644 --- a/devices/parser-tests/001/etc/kboot.conf +++ b/devices/parser-tests/001/ps3da1/etc/kboot.conf diff --git a/devices/parser-tests/002/expected-output b/devices/parser-tests/002/expected-output index d0dde25..9d2a146 100644 --- a/devices/parser-tests/002/expected-output +++ b/devices/parser-tests/002/expected-output @@ -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/etc/yaboot.conf b/devices/parser-tests/002/ps3da1/etc/yaboot.conf index f13b1b3..f13b1b3 100644 --- a/devices/parser-tests/002/etc/yaboot.conf +++ b/devices/parser-tests/002/ps3da1/etc/yaboot.conf diff --git a/devices/paths.c b/devices/paths.c new file mode 100644 index 0000000..a1df5d2 --- /dev/null +++ b/devices/paths.c @@ -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 index 0000000..eca6689 --- /dev/null +++ b/devices/paths.h @@ -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 */ diff --git a/devices/udev-helper.c b/devices/udev-helper.c index 4826f9d..a55d378 100644 --- a/devices/udev-helper.c +++ b/devices/udev-helper.c @@ -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; |