aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-11-29 12:54:16 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-11-29 12:54:16 +0000
commit7a1ddf20f343b3dc08e7a413e901d78681641518 (patch)
tree33cc52e79bb300887f47dc9405d6451d106194d8
parentd723fb155d3db4152a4781dff550cd0f0ce290b5 (diff)
downloadbusybox-w32-7a1ddf20f343b3dc08e7a413e901d78681641518.tar.gz
busybox-w32-7a1ddf20f343b3dc08e7a413e901d78681641518.tar.bz2
busybox-w32-7a1ddf20f343b3dc08e7a413e901d78681641518.zip
mountpoint: add -n option (by Vladimir)
text data bss dec hex filename 799859 560 7748 808167 c54e7 busybox_old 799845 560 7748 808153 c54d9 busybox_unstripped
-rw-r--r--include/usage.h5
-rw-r--r--miscutils/mountpoint.c80
2 files changed, 46 insertions, 39 deletions
diff --git a/include/usage.h b/include/usage.h
index 502fea7a0..000b864d6 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -2788,12 +2788,13 @@
2788 "Returns 0 for success, number of failed mounts for -a, or errno for one mount." 2788 "Returns 0 for success, number of failed mounts for -a, or errno for one mount."
2789 2789
2790#define mountpoint_trivial_usage \ 2790#define mountpoint_trivial_usage \
2791 "[-q] <[-d] DIR | -x DEVICE>" 2791 "[-q] <[-dn] DIR | -x DEVICE>"
2792#define mountpoint_full_usage "\n\n" \ 2792#define mountpoint_full_usage "\n\n" \
2793 "mountpoint checks if the directory is a mountpoint\n" \ 2793 "Check if the directory is a mountpoint\n" \
2794 "\nOptions:" \ 2794 "\nOptions:" \
2795 "\n -q Quiet" \ 2795 "\n -q Quiet" \
2796 "\n -d Print major/minor device number of the filesystem" \ 2796 "\n -d Print major/minor device number of the filesystem" \
2797 "\n -n Print device name of the filesystem" \
2797 "\n -x Print major/minor device number of the blockdevice" \ 2798 "\n -x Print major/minor device number of the blockdevice" \
2798 2799
2799#define mountpoint_example_usage \ 2800#define mountpoint_example_usage \
diff --git a/miscutils/mountpoint.c b/miscutils/mountpoint.c
index 81ce429ea..b541ce28c 100644
--- a/miscutils/mountpoint.c
+++ b/miscutils/mountpoint.c
@@ -12,55 +12,61 @@
12#include "libbb.h" 12#include "libbb.h"
13 13
14int mountpoint_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 14int mountpoint_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
15int mountpoint_main(int argc, char **argv) 15int mountpoint_main(int argc UNUSED_PARAM, char **argv)
16{ 16{
17 struct stat st; 17 struct stat st;
18 const char *msg;
18 char *arg; 19 char *arg;
19 int opt = getopt32(argv, "qdx"); 20 int rc, opt;
21
22 opt_complementary = "=1"; /* must have one argument */
23 opt = getopt32(argv, "qdxn");
20#define OPT_q (1) 24#define OPT_q (1)
21#define OPT_d (2) 25#define OPT_d (2)
22#define OPT_x (4) 26#define OPT_x (4)
27#define OPT_n (8)
28 arg = argv[optind];
29 msg = "%s";
23 30
24 if (optind != argc - 1) 31 rc = (opt & OPT_x) ? stat(arg, &st) : lstat(arg, &st);
25 bb_show_usage(); 32 if (rc != 0)
33 goto err;
26 34
27 arg = argv[optind]; 35 if (opt & OPT_x) {
36 if (S_ISBLK(st.st_mode)) {
37 printf("%u:%u\n", major(st.st_rdev),
38 minor(st.st_rdev));
39 return EXIT_SUCCESS;
40 }
41 errno = 0; /* make perror_msg work as error_msg */
42 msg = "%s: not a block device";
43 goto err;
44 }
45
46 errno = ENOTDIR;
47 if (S_ISDIR(st.st_mode)) {
48 dev_t st_dev = st.st_dev;
49 ino_t st_ino = st.st_ino;
50 char *p = xasprintf("%s/..", arg);
28 51
29 if ( (opt & OPT_x && stat(arg, &st) == 0) || (lstat(arg, &st) == 0) ) { 52 if (stat(p, &st) == 0) {
30 if (opt & OPT_x) { 53 //int is_mnt = (st_dev != st.st_dev) || (st_dev == st.st_dev && st_ino == st.st_ino);
31 if (S_ISBLK(st.st_mode)) { 54 int is_not_mnt = (st_dev == st.st_dev) && (st_ino != st.st_ino);
32 printf("%u:%u\n", major(st.st_rdev),
33 minor(st.st_rdev));
34 return EXIT_SUCCESS;
35 } else {
36 if (opt & OPT_q)
37 bb_putchar('\n');
38 else
39 bb_error_msg("%s: not a block device", arg);
40 }
41 return EXIT_FAILURE;
42 } else
43 if (S_ISDIR(st.st_mode)) {
44 dev_t st_dev = st.st_dev;
45 ino_t st_ino = st.st_ino;
46 char *p = xasprintf("%s/..", arg);
47 55
48 if (stat(p, &st) == 0) { 56 if (opt & OPT_d)
49 int ret = (st_dev != st.st_dev) || 57 printf("%u:%u\n", major(st_dev), minor(st_dev));
50 (st_dev == st.st_dev && st_ino == st.st_ino); 58 if (opt & OPT_n)
51 if (opt & OPT_d) 59 printf("%s %s\n", find_block_device(arg), arg);
52 printf("%u:%u\n", major(st_dev), minor(st_dev)); 60 if (!(opt & (OPT_q | OPT_d | OPT_n)))
53 else if (!(opt & OPT_q)) 61 printf("%s is %sa mountpoint\n", arg, is_not_mnt ? "not " : "");
54 printf("%s is %sa mountpoint\n", arg, ret?"":"not "); 62 return is_not_mnt;
55 return !ret;
56 }
57 } else {
58 if (!(opt & OPT_q))
59 bb_error_msg("%s: not a directory", arg);
60 return EXIT_FAILURE;
61 } 63 }
64 arg = p;
65 /* else: stat had set errno, just fall through */
62 } 66 }
67
68 err:
63 if (!(opt & OPT_q)) 69 if (!(opt & OPT_q))
64 bb_simple_perror_msg(arg); 70 bb_perror_msg(msg, arg);
65 return EXIT_FAILURE; 71 return EXIT_FAILURE;
66} 72}