1 /* vi: set sw=4 ts=4: */
3 * mountpoint implementation for busybox
5 * Copyright (C) 2005 Bernhard Fischer
7 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
9 * Based on sysvinit's mountpoint
13 #include <errno.h> /* errno */
14 #include <string.h> /* strerror */
15 #include <getopt.h> /* optind */
18 int mountpoint_main(int argc, char **argv)
20 int opt = bb_getopt_ulflags(argc, argv, "qdx");
25 if (optind != argc - 1)
28 char *arg = argv[optind];
31 if ( (opt & OPT_x && stat(arg, &st) == 0) || (lstat(arg, &st) == 0) ) {
33 if (S_ISBLK(st.st_mode))
35 bb_printf("%u:%u\n", major(st.st_rdev),
42 bb_error_msg("%s: not a block device", arg);
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 = bb_xasprintf("%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);
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 ");
62 bb_error_msg("%s: not a directory", arg);
67 bb_perror_msg("%s", arg);