From patchwork Fri Nov 7 00:21:34 2008 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [9/9] petitboot: Merge shared headers into petitboot.h Date: Thu, 06 Nov 2008 14:21:34 -0000 From: Geoff Levand X-Patchwork-Id: 7633 Message-Id: <49138A0E.4020700@am.sony.com> To: jk@ozlabs.org Cc: cbe-oss-dev@ozlabs.org From: Yuji Mano Merge the library shared headers into a single header petitboot.h. Also fixes these warnings: warning: redundant redeclaration of 'mountpoint_for_device' warning: redundant redeclaration of 'resolve_path' Signed-off-by: Yuji Mano Signed-off-by: Geoff Levand --- This change is a step to convert petitboot into a collection of applications linking to a core petitboot library. devices.c | 3 - lib/Makefile.am | 6 -- lib/kboot-parser.c | 2 lib/message.h | 30 ---------- lib/native-parser.c | 7 +- lib/parser.c | 3 - lib/parser.h | 46 --------------- lib/paths.c | 2 lib/paths.h | 53 ------------------ lib/petitboot-paths.h | 24 -------- lib/petitboot.h | 141 ++++++++++++++++++++++++++++++++++++++++++++++++ lib/yaboot-parser.c | 9 +-- petitboot-gui.c | 2 petitboot-udev-helper.c | 4 - test/parser-test.c | 3 - 15 files changed, 156 insertions(+), 179 deletions(-) --- a/devices.c +++ b/devices.c @@ -9,9 +9,8 @@ #include #include +#include #include "petitboot-gui.h" -#include "petitboot-paths.h" -#include "message.h" #define PBOOT_DEFAULT_ICON "tux.png" --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -25,11 +25,7 @@ AM_CFLAGS = \ -Wredundant-decls \ -Winline -pkginclude_HEADERS = \ - message.h \ - parser.h \ - paths.h \ - petitboot-paths.h +include_HEADERS = petitboot.h petitboot_headers = \ params.h \ --- a/lib/kboot-parser.c +++ b/lib/kboot-parser.c @@ -10,7 +10,7 @@ #include #include -#include "parser.h" +#include "petitboot.h" #include "params.h" #define buf_size 1024 --- a/lib/message.h +++ /dev/null @@ -1,30 +0,0 @@ - -#ifndef _MESSAGE_H -#define _MESSAGE_H - -enum device_action { - DEV_ACTION_ADD_DEVICE = 0, - DEV_ACTION_ADD_OPTION = 1, - DEV_ACTION_REMOVE_DEVICE = 2, - DEV_ACTION_REMOVE_OPTION = 3 -}; - -struct device { - char *id; - char *name; - char *description; - char *icon_file; -}; - -struct boot_option { - char *id; - char *name; - char *description; - char *icon_file; - char *boot_image_file; - char *initrd_file; - char *boot_args; -}; - - -#endif /* _MESSAGE_H */ --- a/lib/native-parser.c +++ b/lib/native-parser.c @@ -1,12 +1,11 @@ -#include "parser.h" -#include "params.h" -#include "paths.h" - #include #include #include +#include "petitboot.h" +#include "params.h" + const char *conf_filename = "/boot/petitboot.conf"; static struct boot_option *cur_opt; --- a/lib/parser.c +++ b/lib/parser.c @@ -1,9 +1,8 @@ -#include #include #include -#include "parser.h" +#include "petitboot.h" extern struct parser native_parser; extern struct parser yaboot_parser; --- a/lib/parser.h +++ /dev/null @@ -1,46 +0,0 @@ - -#ifndef _PARSERS_H -#define _PARSERS_H - -#include -#include "message.h" - -struct parser { - char *name; - int priority; - int (*parse)(const char *device); - struct parser *next; -}; - -enum generic_icon_type { - ICON_TYPE_DISK, - ICON_TYPE_USB, - ICON_TYPE_OPTICAL, - ICON_TYPE_NETWORK, - ICON_TYPE_UNKNOWN -}; - -#define streq(a,b) (!strcasecmp((a),(b))) - -/* general functions provided by parsers.c */ -void iterate_parsers(const char *devpath, const char *mountpoint); - -void free_device(struct device *dev); -void free_boot_option(struct boot_option *opt); - -const char *generic_icon_file(enum generic_icon_type type); - -/* functions provided by udev-helper or the test wrapper */ -void pb_log(const char *fmt, ...); - -int mount_device(const char *dev_path); - -char *resolve_path(const char *path, const char *current_dev); -const char *mountpoint_for_device(const char *dev_path); - -enum generic_icon_type guess_device_type(void); - -int add_device(const struct device *dev); -int add_boot_option(const struct boot_option *opt); - -#endif /* _PARSERS_H */ --- a/lib/paths.c +++ b/lib/paths.c @@ -4,7 +4,7 @@ #include #include -#include "paths.h" +#include "petitboot.h" static char *mount_base; --- a/lib/paths.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef PATHS_H -#define PATHS_H - -/** - * Given a string (eg /dev/sda1, sda1 or UUID=B8E53381CA9EA0E3), parse the - * device path (eg /dev/sda1). Any device descriptions read from config files - * should be parsed into the path first. - * - * The cur_dev is provided for some remapping situations. If NULL is provided, - * no remapping will be done. - * - * Returns a newly-allocated string. - */ -char *parse_device_path(const char *dev_str, const char *current_device); - -/** - * Get the mountpoint for a device. - */ -const char *mountpoint_for_device(const char *dev); - -/** - * 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_device); - - -/** - * Set the base directory for newly-created mountpoints - */ -void set_mount_base(const char *path); - -/** - * Utility function for joining two paths. Adds a / between a and b if - * required. - * - * Returns a newly-allocated string. - */ -char *join_paths(const char *a, const char *b); - -/** - * encode a disk label (or uuid) for use in a symlink. - */ -char *encode_label(const char *label); - -#endif /* PATHS_H */ --- a/lib/petitboot-paths.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _PATHS_H -#define _PATHS_H - -#ifndef PREFIX -#define PREFIX "/usr" -#endif - -#ifndef PKG_SHARE_DIR -#define PKG_SHARE_DIR PREFIX "/share/petitboot" -#endif - -#ifndef TMP_DIR -#define TMP_DIR "/var/tmp/mnt/" -#endif - -#define PBOOT_DEVICE_SOCKET "/var/tmp/petitboot-dev" -#define MOUNT_BIN "/bin/mount" -#define UMOUNT_BIN "/bin/umount" -#define BOOT_GAMEOS_BIN "/usr/bin/ps3-boot-game-os" - -/* at present, all default artwork strings are const. */ -#define artwork_pathname(s) (PKG_SHARE_DIR "/artwork/" s) - -#endif /* _PATHS_H */ --- /dev/null +++ b/lib/petitboot.h @@ -0,0 +1,141 @@ + +#ifndef _PETITBOOT_LIB_H +#define _PETITBOOT_LIB_H + +/* default system paths */ + +#ifndef PREFIX +#define PREFIX "/usr" +#endif + +#ifndef PKG_SHARE_DIR +#define PKG_SHARE_DIR PREFIX "/share/petitboot" +#endif + +#ifndef TMP_DIR +#define TMP_DIR "/var/tmp/mnt/" +#endif + +#define PBOOT_DEVICE_SOCKET "/var/tmp/petitboot-dev" +#define MOUNT_BIN "/bin/mount" +#define UMOUNT_BIN "/bin/umount" +#define BOOT_GAMEOS_BIN "/usr/bin/ps3-boot-game-os" + +/* at present, all default artwork strings are const. */ +#define artwork_pathname(s) (PKG_SHARE_DIR "/artwork/" s) + +/* message interface */ + +enum device_action { + DEV_ACTION_ADD_DEVICE = 0, + DEV_ACTION_ADD_OPTION = 1, + DEV_ACTION_REMOVE_DEVICE = 2, + DEV_ACTION_REMOVE_OPTION = 3 +}; + +struct device { + char *id; + char *name; + char *description; + char *icon_file; +}; + +struct boot_option { + char *id; + char *name; + char *description; + char *icon_file; + char *boot_image_file; + char *initrd_file; + char *boot_args; +}; + +/* parser interface */ + +struct parser { + char *name; + int priority; + int (*parse)(const char *device); + struct parser *next; +}; + +enum generic_icon_type { + ICON_TYPE_DISK, + ICON_TYPE_USB, + ICON_TYPE_OPTICAL, + ICON_TYPE_NETWORK, + ICON_TYPE_UNKNOWN +}; + +#define streq(a,b) (!strcasecmp((a),(b))) + +/* general functions provided by parsers.c */ +void iterate_parsers(const char *devpath, const char *mountpoint); + +void free_device(struct device *dev); +void free_boot_option(struct boot_option *opt); + +const char *generic_icon_file(enum generic_icon_type type); + +/* functions provided by udev-helper or the test wrapper */ +void pb_log(const char *fmt, ...); + +int mount_device(const char *dev_path); + +enum generic_icon_type guess_device_type(void); + +int add_device(const struct device *dev); +int add_boot_option(const struct boot_option *opt); + +/* path routines */ + +/** + * Given a string (eg /dev/sda1, sda1 or UUID=B8E53381CA9EA0E3), parse the + * device path (eg /dev/sda1). Any device descriptions read from config files + * should be parsed into the path first. + * + * The cur_dev is provided for some remapping situations. If NULL is provided, + * no remapping will be done. + * + * Returns a newly-allocated string. + */ +char *parse_device_path(const char *dev_str, const char *current_device); + +/** + * Get the mountpoint for a device. + */ +const char *mountpoint_for_device(const char *dev); + +/** + * 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_device); + + +/** + * Set the base directory for newly-created mountpoints + */ +void set_mount_base(const char *path); + +/** + * Utility function for joining two paths. Adds a / between a and b if + * required. + * + * Returns a newly-allocated string. + */ +char *join_paths(const char *a, const char *b); + +/** + * encode a disk label (or uuid) for use in a symlink. + */ +char *encode_label(const char *label); + +#endif /* _PETITBOOT_LIB_H */ --- a/lib/yaboot-parser.c +++ b/lib/yaboot-parser.c @@ -1,9 +1,4 @@ -#include "parser.h" -#include "params.h" -#include "paths.h" -#include "yaboot-cfg.h" - #include #include #include @@ -14,6 +9,10 @@ #include #include +#include "petitboot.h" +#include "params.h" +#include "yaboot-cfg.h" + static struct device *dev; static char *devpath; static char *defimage; --- a/petitboot-gui.c +++ b/petitboot-gui.c @@ -21,8 +21,8 @@ #include #include +#include #include "petitboot-gui.h" -#include "petitboot-paths.h" #ifdef _USE_X11 #include --- a/petitboot-udev-helper.c +++ b/petitboot-udev-helper.c @@ -19,9 +19,7 @@ #include #include -#include "parser.h" -#include "paths.h" -#include "petitboot-paths.h" +#include /* Define below to operate without the frontend */ #undef USE_FAKE_SOCKET --- a/test/parser-test.c +++ b/test/parser-test.c @@ -6,8 +6,7 @@ #include #include -#include "parser.h" -#include "paths.h" +#include void pb_log(const char *fmt, ...) {