-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample3-bind-mount.c
More file actions
30 lines (24 loc) · 863 Bytes
/
Copy pathexample3-bind-mount.c
File metadata and controls
30 lines (24 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "common.h"
int main(void) {
printpid();
char source_dir[255] = "bind-source/";
addcurpath(source_dir);
char target_dir[255] = "bind-target/";
addcurpath(target_dir);
wait("* Step 1: Will do a mount_tree() on the existing directory %s", source_dir);
int source_fd = open_tree(0, source_dir, OPEN_TREE_CLONE);
if (source_fd < 0) {
perror("open_tree failed");
return 1;
}
printf("open_tree successful. Source dir fd = %d\n", source_fd);
wait("* Step 2: make the bind-mount visible with move_mount");
if (move_mount(source_fd, "", AT_FDCWD, target_dir, MOVE_MOUNT_F_EMPTY_PATH)) {
perror("move_mount");
return 1;
}
printf("bind mount is now visible at %s. Don't forget to umount!\n", target_dir);
wait("Press ENTER to finish the program");
close(source_fd);
return 0;
}