summaryrefslogtreecommitdiffstats
path: root/sys-utils/mountpoint.c
diff options
context:
space:
mode:
authorDave Reisner2011-10-09 05:31:50 +0200
committerKarel Zak2011-10-11 09:56:07 +0200
commit7982e85a61889a739c6b3116293e89ba767955dd (patch)
tree3c2b8eb5efbde620f7699d1d74b4c809a62eb849 /sys-utils/mountpoint.c
parentlsblk: inform about depencency to /sys/dev/block (diff)
downloadkernel-qcow2-util-linux-7982e85a61889a739c6b3116293e89ba767955dd.tar.gz
kernel-qcow2-util-linux-7982e85a61889a739c6b3116293e89ba767955dd.tar.xz
kernel-qcow2-util-linux-7982e85a61889a739c6b3116293e89ba767955dd.zip
mountpoint: return dev_t from dir_to_device
The string returned from this function was never of much use other than to stat the path when the user requested a major:minor pair beyond the true/false exit. Save some processing and directly returning the dev_t on success, and an impossible value on failure. [kzak@redhat.com: - use 0 as dir_to_device() return value on failure] Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/mountpoint.c')
-rw-r--r--sys-utils/mountpoint.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/sys-utils/mountpoint.c b/sys-utils/mountpoint.c
index f66836885..273fea712 100644
--- a/sys-utils/mountpoint.c
+++ b/sys-utils/mountpoint.c
@@ -40,18 +40,18 @@
static int quiet;
-static char *dir_to_device(const char *spec)
+static dev_t dir_to_device(const char *spec)
{
struct libmnt_table *tb = mnt_new_table_from_file("/proc/self/mountinfo");
struct libmnt_fs *fs;
- char *res = NULL;
+ dev_t res = 0;
if (!tb)
- return NULL;
+ return 0;
fs = mnt_table_find_target(tb, spec, MNT_ITER_BACKWARD);
if (fs && mnt_fs_get_target(fs))
- res = xstrdup(mnt_fs_get_source(fs));
+ res = mnt_fs_get_devno(fs);
mnt_free_table(tb);
return res;
@@ -146,7 +146,7 @@ int main(int argc, char **argv)
if (dev_devno)
rc = print_devno(spec, &st);
else {
- char *src;
+ dev_t src;
if (!S_ISDIR(st.st_mode)) {
if (!quiet)
@@ -160,10 +160,9 @@ int main(int argc, char **argv)
return EXIT_FAILURE;
}
if (fs_devno)
- rc = print_devno(src, NULL);
+ printf("%u:%u\n", major(src), minor(src));
else if (!quiet)
printf(_("%s is a mountpoint\n"), spec);
- free(src);
}
return rc ? EXIT_FAILURE : EXIT_SUCCESS;