diff options
| author | Natanael Copa <natanael.copa@gmail.com> | 2009-09-20 04:28:22 +0200 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-09-20 04:28:22 +0200 |
| commit | 9aff29997ed22932f78aa8d8c7c2412e9d3f49e5 (patch) | |
| tree | 8df24e36d81c3f4f6d1cf6b9892341f96b5ecb92 /util-linux | |
| parent | 2bf6634ef46b5360e6381e61b27415e52a1cd7c7 (diff) | |
| download | busybox-w32-9aff29997ed22932f78aa8d8c7c2412e9d3f49e5.tar.gz busybox-w32-9aff29997ed22932f78aa8d8c7c2412e9d3f49e5.tar.bz2 busybox-w32-9aff29997ed22932f78aa8d8c7c2412e9d3f49e5.zip | |
swaponoff: add uuid/label support. By Natanael Copa
function old new delta
swap_enable_disable 130 150 +20
resolve_mount_spec 76 96 +20
mount_main 1152 1154 +2
findfs_main 125 80 -45
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 42/-45) Total: -3 bytes
Signed-off-by: Natanael Copa <natanael.copa@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux')
| -rw-r--r-- | util-linux/Config.in | 1 | ||||
| -rw-r--r-- | util-linux/findfs.c | 31 | ||||
| -rw-r--r-- | util-linux/mount.c | 21 | ||||
| -rw-r--r-- | util-linux/swaponoff.c | 7 | ||||
| -rw-r--r-- | util-linux/volume_id/get_devname.c | 17 |
5 files changed, 44 insertions, 33 deletions
diff --git a/util-linux/Config.in b/util-linux/Config.in index 5f5adc0fe..7cf17575c 100644 --- a/util-linux/Config.in +++ b/util-linux/Config.in | |||
| @@ -689,6 +689,7 @@ config FEATURE_MOUNT_LABEL | |||
| 689 | help | 689 | help |
| 690 | This allows for specifying a device by label or uuid, rather than by | 690 | This allows for specifying a device by label or uuid, rather than by |
| 691 | name. This feature utilizes the same functionality as blkid/findfs. | 691 | name. This feature utilizes the same functionality as blkid/findfs. |
| 692 | This also enables label or uuid support for swapon. | ||
| 692 | 693 | ||
| 693 | config FEATURE_MOUNT_NFS | 694 | config FEATURE_MOUNT_NFS |
| 694 | bool "Support mounting NFS file systems" | 695 | bool "Support mounting NFS file systems" |
diff --git a/util-linux/findfs.c b/util-linux/findfs.c index 5b64399ad..1e9c68752 100644 --- a/util-linux/findfs.c +++ b/util-linux/findfs.c | |||
| @@ -12,26 +12,27 @@ | |||
| 12 | #include "volume_id.h" | 12 | #include "volume_id.h" |
| 13 | 13 | ||
| 14 | int findfs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 14 | int findfs_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 15 | int findfs_main(int argc, char **argv) | 15 | int findfs_main(int argc UNUSED_PARAM, char **argv) |
| 16 | { | 16 | { |
| 17 | char *tmp = NULL; | 17 | char *dev = *++argv; |
| 18 | 18 | ||
| 19 | if (argc != 2) | 19 | if (!dev) |
| 20 | bb_show_usage(); | 20 | bb_show_usage(); |
| 21 | 21 | ||
| 22 | if (!strncmp(argv[1], "LABEL=", 6)) | 22 | if (strncmp(dev, "/dev/", 5) == 0) { |
| 23 | tmp = get_devname_from_label(argv[1] + 6); | 23 | /* Just pass any /dev/xxx name right through. |
| 24 | else if (!strncmp(argv[1], "UUID=", 5)) | 24 | * This might aid in some scripts being able |
| 25 | tmp = get_devname_from_uuid(argv[1] + 5); | 25 | * to call this unconditionally */ |
| 26 | else if (!strncmp(argv[1], "/dev/", 5)) { | 26 | dev = NULL; |
| 27 | /* Just pass a device name right through. This might aid in some scripts | 27 | } else { |
| 28 | being able to call this unconditionally */ | 28 | /* Otherwise, handle LABEL=xxx and UUID=xxx, |
| 29 | tmp = argv[1]; | 29 | * fail on anything else */ |
| 30 | } else | 30 | if (!resolve_mount_spec(argv)) |
| 31 | bb_show_usage(); | 31 | bb_show_usage(); |
| 32 | } | ||
| 32 | 33 | ||
| 33 | if (tmp) { | 34 | if (*argv != dev) { |
| 34 | puts(tmp); | 35 | puts(*argv); |
| 35 | return 0; | 36 | return 0; |
| 36 | } | 37 | } |
| 37 | return 1; | 38 | return 1; |
diff --git a/util-linux/mount.c b/util-linux/mount.c index 478dc2409..9f465f131 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c | |||
| @@ -50,7 +50,9 @@ | |||
| 50 | #include "libbb.h" | 50 | #include "libbb.h" |
| 51 | 51 | ||
| 52 | #if ENABLE_FEATURE_MOUNT_LABEL | 52 | #if ENABLE_FEATURE_MOUNT_LABEL |
| 53 | #include "volume_id.h" | 53 | # include "volume_id.h" |
| 54 | #else | ||
| 55 | # define resolve_mount_spec(fsname) ((void)0) | ||
| 54 | #endif | 56 | #endif |
| 55 | 57 | ||
| 56 | // Needed for nfs support only | 58 | // Needed for nfs support only |
| @@ -290,23 +292,6 @@ static int verbose_mount(const char *source, const char *target, | |||
| 290 | #define verbose_mount(...) mount(__VA_ARGS__) | 292 | #define verbose_mount(...) mount(__VA_ARGS__) |
| 291 | #endif | 293 | #endif |
| 292 | 294 | ||
| 293 | #if ENABLE_FEATURE_MOUNT_LABEL | ||
| 294 | static void resolve_mount_spec(char **fsname) | ||
| 295 | { | ||
| 296 | char *tmp = NULL; | ||
| 297 | |||
| 298 | if (!strncmp(*fsname, "UUID=", 5)) | ||
| 299 | tmp = get_devname_from_uuid(*fsname + 5); | ||
| 300 | else if (!strncmp(*fsname, "LABEL=", 6)) | ||
| 301 | tmp = get_devname_from_label(*fsname + 6); | ||
| 302 | |||
| 303 | if (tmp) | ||
| 304 | *fsname = tmp; | ||
| 305 | } | ||
| 306 | #else | ||
| 307 | #define resolve_mount_spec(fsname) ((void)0) | ||
| 308 | #endif | ||
| 309 | |||
| 310 | // Append mount options to string | 295 | // Append mount options to string |
| 311 | static void append_mount_options(char **oldopts, const char *newopts) | 296 | static void append_mount_options(char **oldopts, const char *newopts) |
| 312 | { | 297 | { |
diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c index 863f7734a..33ad00ac1 100644 --- a/util-linux/swaponoff.c +++ b/util-linux/swaponoff.c | |||
| @@ -11,6 +11,12 @@ | |||
| 11 | #include <mntent.h> | 11 | #include <mntent.h> |
| 12 | #include <sys/swap.h> | 12 | #include <sys/swap.h> |
| 13 | 13 | ||
| 14 | #if ENABLE_FEATURE_MOUNT_LABEL | ||
| 15 | # include "volume_id.h" | ||
| 16 | #else | ||
| 17 | # define resolve_mount_spec(fsname) ((void)0) | ||
| 18 | #endif | ||
| 19 | |||
| 14 | #if ENABLE_FEATURE_SWAPON_PRI | 20 | #if ENABLE_FEATURE_SWAPON_PRI |
| 15 | struct globals { | 21 | struct globals { |
| 16 | int flags; | 22 | int flags; |
| @@ -26,6 +32,7 @@ static int swap_enable_disable(char *device) | |||
| 26 | int status; | 32 | int status; |
| 27 | struct stat st; | 33 | struct stat st; |
| 28 | 34 | ||
| 35 | resolve_mount_spec(&device); | ||
| 29 | xstat(device, &st); | 36 | xstat(device, &st); |
| 30 | 37 | ||
| 31 | #if ENABLE_DESKTOP | 38 | #if ENABLE_DESKTOP |
diff --git a/util-linux/volume_id/get_devname.c b/util-linux/volume_id/get_devname.c index 0686a0741..9b5283f87 100644 --- a/util-linux/volume_id/get_devname.c +++ b/util-linux/volume_id/get_devname.c | |||
| @@ -260,3 +260,20 @@ char *get_devname_from_uuid(const char *spec) | |||
| 260 | } | 260 | } |
| 261 | return NULL; | 261 | return NULL; |
| 262 | } | 262 | } |
| 263 | |||
| 264 | int resolve_mount_spec(char **fsname) | ||
| 265 | { | ||
| 266 | char *tmp = *fsname; | ||
| 267 | |||
| 268 | if (strncmp(*fsname, "UUID=", 5) == 0) | ||
| 269 | tmp = get_devname_from_uuid(*fsname + 5); | ||
| 270 | else if (strncmp(*fsname, "LABEL=", 6) == 0) | ||
| 271 | tmp = get_devname_from_label(*fsname + 6); | ||
| 272 | |||
| 273 | if (tmp == *fsname) | ||
| 274 | return 0; /* no UUID= or LABEL= prefix found */ | ||
| 275 | |||
| 276 | if (tmp) | ||
| 277 | *fsname = tmp; | ||
| 278 | return 1; | ||
| 279 | } | ||
