| 1 |
#include <stdio.h> |
| 2 |
#include <stdlib.h> |
| 3 |
#include <unistd.h> |
| 4 |
#include <sys/mount.h> |
| 5 |
|
| 6 |
int main(int argc, char *argv[]) |
| 7 |
{ |
| 8 |
int res; |
| 9 |
FILE *fp; |
| 10 |
|
| 11 |
if(argc != 3) { |
| 12 |
fprintf(stderr, "usage: %s from to\n", argv[0]); |
| 13 |
exit(1); |
| 14 |
} |
| 15 |
|
| 16 |
fp = fopen("/proc/fs/redir2/mount_pid", "w"); |
| 17 |
if(fp == NULL) { |
| 18 |
perror("opening /proc/fs/redir2/mount_pid"); |
| 19 |
exit(1); |
| 20 |
} |
| 21 |
fprintf(fp, "%u", getpid()); |
| 22 |
fclose(fp); |
| 23 |
|
| 24 |
if (argv[1][0] == '-') { |
| 25 |
res = umount2(argv[2], 0); |
| 26 |
if (res == -1) { |
| 27 |
perror("umount failed"); |
| 28 |
exit(1); |
| 29 |
} |
| 30 |
} else { |
| 31 |
res = mount(argv[1], argv[2], "none", MS_BIND, NULL); |
| 32 |
if(res == -1) { |
| 33 |
perror("mount failed"); |
| 34 |
exit(1); |
| 35 |
} |
| 36 |
} |
| 37 |
return 0; |
| 38 |
} |