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 (!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
37 if (lstat(arg, &st1)) perror_exit_raw(arg);
38
39 if (FLAG(x)) {
40 if (!S_ISBLK(st1.st_mode)) die("block device");
41 if (!FLAG(q))
42 printf("%u:%u\n", dev_major(st1.st_rdev), dev_minor(st1.st_rdev));
43
44 return;
45 }
46
47
48 if (!S_ISDIR(st1.st_mode)) die("directory");
49
50 arg = xmprintf("%s/..", arg);
51 xstat(arg, &st2);
52 free(arg);
53
54
55
56
57
58 toys.exitval = !same_file(&st1, &st2);
59 if (FLAG(d)) printf("%u:%u\n", dev_major(st1.st_dev), dev_minor(st1.st_dev));
60 else if (!FLAG(q))
61 printf("%s is %sa mountpoint\n", *toys.optargs, toys.exitval ? "not " : "");
62}
63