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
14 int mountpoint_main(int argc, char **argv)
18 int opt = getopt32(argc, argv, "qdx");
23 if (optind != argc - 1)
28 if ( (opt & OPT_x && stat(arg, &st) == 0) || (lstat(arg, &st) == 0) ) {
30 if (S_ISBLK(st.st_mode)) {
31 printf("%u:%u\n", major(st.st_rdev),
38 bb_error_msg("%s: not a block device", arg);
42 if (S_ISDIR(st.st_mode)) {
43 dev_t st_dev = st.st_dev;
44 ino_t st_ino = st.st_ino;
45 char *p = xasprintf("%s/..", arg);
47 if (stat(p, &st) == 0) {
48 int ret = (st_dev != st.st_dev) ||
49 (st_dev == st.st_dev && st_ino == st.st_ino);
51 printf("%u:%u\n", major(st_dev), minor(st_dev));
52 else if (!(opt & OPT_q))
53 printf("%s is %sa mountpoint\n", arg, ret?"":"not ");
58 bb_error_msg("%s: not a directory", arg);
63 bb_perror_msg("%s", arg);