1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#define FOR_mountpoint
20#include "toys.h"
21
22static void die(char *gripe)
23{
24 if (!(toys.optflags & FLAG_q)) printf("%s: not a %s\n", *toys.optargs, gripe);
25
26 toys.exitval++;
27 xexit();
28}
29
30void mountpoint_main(void)
31{
32 struct stat st1, st2;
33 char *arg = *toys.optargs;
34 int quiet = toys.optflags & FLAG_q;
35
36 if (lstat(arg, &st1)) perror_exit_raw(arg);
37
38 if (toys.optflags & FLAG_x) {
39 if (S_ISBLK(st1.st_mode)) {
40 if (!quiet)
41 printf("%u:%u\n", dev_major(st1.st_rdev), dev_minor(st1.st_rdev));
42
43 return;
44 }
45 die("block device");
46 }
47
48
49 if (!S_ISDIR(st1.st_mode)) die("directory");
50
51 arg = xmprintf("%s/..", arg);
52 xstat(arg, &st2);
53 if (CFG_TOYBOX_FREE) free(arg);
54
55
56
57
58
59 toys.exitval = !(st1.st_dev != st2.st_dev || st1.st_ino == st2.st_ino);
60 if (toys.optflags & FLAG_d)
61 printf("%u:%u\n", dev_major(st1.st_dev), dev_minor(st1.st_dev));
62 else if (!quiet)
63 printf("%s is %sa mountpoint\n", *toys.optargs, toys.exitval ? "not " : "");
64}
65