aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2005-08-20 05:07:08 +0000
committerRob Landley <rob@landley.net>2005-08-20 05:07:08 +0000
commitd00b3a5e944e7499bd061c0b8f9d9f0847528fce (patch)
tree2bec1c6e32716bf8bc204ed411e6287ee728e3f9
parentfc3f048f8f6de2132c83bbd1124dabd0990a952b (diff)
downloadbusybox-w32-d00b3a5e944e7499bd061c0b8f9d9f0847528fce.tar.gz
busybox-w32-d00b3a5e944e7499bd061c0b8f9d9f0847528fce.tar.bz2
busybox-w32-d00b3a5e944e7499bd061c0b8f9d9f0847528fce.zip
Bernhard Fischer provided a mountpoint(1) applet. This is apparently something
sysvinit provides, and which is used by the debian init scripts.
-rw-r--r--include/applets.h3
-rw-r--r--include/usage.h14
-rw-r--r--miscutils/Config.in6
-rw-r--r--miscutils/Makefile.in1
-rw-r--r--miscutils/mountpoint.c70
5 files changed, 94 insertions, 0 deletions
diff --git a/include/applets.h b/include/applets.h
index e2fe25167..a4e78af57 100644
--- a/include/applets.h
+++ b/include/applets.h
@@ -435,6 +435,9 @@
435#ifdef CONFIG_MOUNT 435#ifdef CONFIG_MOUNT
436 APPLET(mount, mount_main, _BB_DIR_BIN, _BB_SUID_NEVER) 436 APPLET(mount, mount_main, _BB_DIR_BIN, _BB_SUID_NEVER)
437#endif 437#endif
438#ifdef CONFIG_MOUNTPOINT
439 APPLET(mountpoint, mountpoint_main, _BB_DIR_BIN, _BB_SUID_NEVER)
440#endif
438#ifdef CONFIG_MSH 441#ifdef CONFIG_MSH
439 APPLET_NOUSAGE("msh", msh_main, _BB_DIR_BIN, _BB_SUID_NEVER) 442 APPLET_NOUSAGE("msh", msh_main, _BB_DIR_BIN, _BB_SUID_NEVER)
440#endif 443#endif
diff --git a/include/usage.h b/include/usage.h
index dc8058a20..662227818 100644
--- a/include/usage.h
+++ b/include/usage.h
@@ -1922,6 +1922,20 @@
1922 "$ mount /dev/fd0 /mnt -t msdos -o ro\n" \ 1922 "$ mount /dev/fd0 /mnt -t msdos -o ro\n" \
1923 "$ mount /tmp/diskimage /opt -t ext2 -o loop\n" 1923 "$ mount /tmp/diskimage /opt -t ext2 -o loop\n"
1924 1924
1925#define mountpoint_trivial_usage \
1926 "[-q] <[-d] DIR | -x DEVICE>"
1927#define mountpoint_full_usage \
1928 "mountpoint checks if the directory is a mountpoint\n\n" \
1929 "Options:\n" \
1930 "\t-q:\t\tBe more quiet\n" \
1931 "\t-d:\t\tPrint major/minor device number of the filesystem\n" \
1932 "\t-x:\t\tPrint major/minor device number of the blockdevice"
1933#define mountpoint_example_usage \
1934 "$ mountpoint /proc\n" \
1935 "/proc is not a mountpoint\n" \
1936 "$ mountpoint /sys\n" \
1937 "/sys is a mountpoint\n"
1938
1925#define mt_trivial_usage \ 1939#define mt_trivial_usage \
1926 "[-f device] opcode value" 1940 "[-f device] opcode value"
1927#define mt_full_usage \ 1941#define mt_full_usage \
diff --git a/miscutils/Config.in b/miscutils/Config.in
index 6c68cd08e..1f14d212f 100644
--- a/miscutils/Config.in
+++ b/miscutils/Config.in
@@ -194,6 +194,12 @@ config CONFIG_FEATURE_MAKEDEVS_TABLE
194 194
195endchoice 195endchoice
196 196
197config CONFIG_MOUNTPOINT
198 bool "mountpoint"
199 default n
200 help
201 mountpoint checks if the directory is a mountpoint.
202
197config CONFIG_MT 203config CONFIG_MT
198 bool "mt" 204 bool "mt"
199 default n 205 default n
diff --git a/miscutils/Makefile.in b/miscutils/Makefile.in
index 8c53104ed..ee1cc7519 100644
--- a/miscutils/Makefile.in
+++ b/miscutils/Makefile.in
@@ -34,6 +34,7 @@ MISCUTILS-$(CONFIG_EJECT) += eject.o
34MISCUTILS-$(CONFIG_HDPARM) += hdparm.o 34MISCUTILS-$(CONFIG_HDPARM) += hdparm.o
35MISCUTILS-$(CONFIG_LAST) += last.o 35MISCUTILS-$(CONFIG_LAST) += last.o
36MISCUTILS-$(CONFIG_MAKEDEVS) += makedevs.o 36MISCUTILS-$(CONFIG_MAKEDEVS) += makedevs.o
37MISCUTILS-$(CONFIG_MOUNTPOINT) += mountpoint.o
37MISCUTILS-$(CONFIG_MT) += mt.o 38MISCUTILS-$(CONFIG_MT) += mt.o
38MISCUTILS-$(CONFIG_RX) += rx.o 39MISCUTILS-$(CONFIG_RX) += rx.o
39MISCUTILS-$(CONFIG_SETSID) += setsid.o 40MISCUTILS-$(CONFIG_SETSID) += setsid.o
diff --git a/miscutils/mountpoint.c b/miscutils/mountpoint.c
new file mode 100644
index 000000000..46b2d4e26
--- /dev/null
+++ b/miscutils/mountpoint.c
@@ -0,0 +1,70 @@
1/* vi: set sw=4 ts=4: */
2/*
3 * mountpoint implementation for busybox
4 *
5 * Copyright (C) 2005 Bernhard Fischer
6 *
7 * Licensed under the GPL v2, see the file LICENSE in this tarball.
8 *
9 * Based on sysvinit's mountpoint
10 */
11
12#include <sys/stat.h>
13#include <errno.h> /* errno */
14#include <string.h> /* strerror */
15#include <getopt.h> /* optind */
16#include "busybox.h"
17
18int mountpoint_main(int argc, char **argv)
19{
20 int opt = bb_getopt_ulflags(argc, argv, "qdx");
21#define OPT_q (1)
22#define OPT_d (2)
23#define OPT_x (4)
24
25 if (optind != argc - 1)
26 bb_show_usage();
27 {
28 char *arg = argv[optind];
29 struct stat st;
30
31 if ( (opt & OPT_x && stat(arg, &st) == 0) || (lstat(arg, &st) == 0) ) {
32 if (opt & OPT_x) {
33 if (S_ISBLK(st.st_mode))
34 {
35 bb_printf("%u:%u\n", major(st.st_rdev),
36 minor(st.st_rdev));
37 return EXIT_SUCCESS;
38 } else {
39 if (opt & OPT_q)
40 putchar('\n');
41 else
42 bb_error_msg("%s: not a block device", arg);
43 }
44 return EXIT_FAILURE;
45 } else
46 if (S_ISDIR(st.st_mode)) {
47 dev_t st_dev = st.st_dev;
48 ino_t st_ino = st.st_ino;
49 char *p;
50 bb_xasprintf(&p, "%s/..", arg);
51 if (stat(p, &st) == 0) {
52 short ret = (st_dev != st.st_dev) ||
53 (st_dev == st.st_dev && st_ino == st.st_ino);
54 if (opt & OPT_d)
55 bb_printf("%u:%u\n", major(st_dev), minor(st_dev));
56 else if (!(opt & OPT_q))
57 bb_printf("%s is %sa mountpoint\n", arg, ret?"":"not ");
58 return !ret;
59 }
60 } else {
61 if (!(opt & OPT_q))
62 bb_error_msg("%s: not a directory", arg);
63 return EXIT_FAILURE;
64 }
65 }
66 if (!(opt & OPT_q))
67 bb_perror_msg(arg);
68 return EXIT_FAILURE;
69 }
70}