Skip to content

Instantly share code, notes, and snippets.

@lucab
Created May 20, 2016 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucab/861c6d34e706c6a0dd8746a7ccee3361 to your computer and use it in GitHub Desktop.
Save lucab/861c6d34e706c6a0dd8746a7ccee3361 to your computer and use it in GitHub Desktop.
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mount.h>
int main(){
char *from = "/tmp/bm-source";
char *to = "/tmp/bm-target";
char *testfile = "/tmp/bm-source/testfile";
int rs1 = remove(from);
int rs2 = remove(to);
int rs3 = mkdir(from, 0777);
int rs5 = close(open(to, O_RDWR|O_CREAT, 0777));
int rs6 = close(open(testfile, O_RDWR|O_CREAT, 0777));
int rs7 = mount(from, to, NULL, MS_BIND, NULL);
printf("---\nmount: %s\n---\n", strerror(errno));
return rs7;
}
@lucab
Copy link
Author

lucab commented May 20, 2016

$ sudo rm -rf /tmp/bm-* ; cc bindmountf.c ; sudo ./a.out ; uname -r ; ls -la /tmp/bm-*

---
mount: Not a directory

---
4.5.0-2-amd64
-rwxr-xr-x 1 root root    0 May 20 16:55 /tmp/bm-target

/tmp/bm-source:
total 8
drwxr-xr-x  2 root root 4096 May 20 16:55 .
drwxrwxrwt 21 root root 4096 May 20 16:55 ..
-rwxr-xr-x  1 root root    0 May 20 16:55 testfile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment