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