-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample1-tmpfs.c
More file actions
61 lines (47 loc) · 1.58 KB
/
Copy pathexample1-tmpfs.c
File metadata and controls
61 lines (47 loc) · 1.58 KB
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "common.h"
// Mount now happens in 5 steps:
// 1 - Create a filesystem context
// 2 - Configure
// 3 - Validate configuration
// 4 - Mount (detached)
// 5 - Attach to the filesystem
int main(void) {
char mountpoint[255] = "tmpfs/";
addcurpath(mountpoint);
printpid();
wait("* Step 1: Will create a filesystem context");
int fscontext_fd = fsopen("tmpfs", 0);
if (fscontext_fd < 0) {
perror("fsopen failed");
return 1;
}
printf("The file descriptor for the handle is fd %d\n", fscontext_fd);
wait("* Step 2: Configuring the size to 50M...");
if (fsconfig(fscontext_fd, FSCONFIG_SET_STRING, "size", "50M", 0) < 0) {
perror("fsconfig size");
return 1;
}
printf("Finished configuration\n");
wait("* Step 3: Validate the configuration.");
if (fsconfig(fscontext_fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0) < 0) {
perror("fsconfig create");
return 1;
}
printf("Configuration is valid\n");
wait("* Step 4: Mount");
int mount_fd = fsmount(fscontext_fd, 0, 0);
if (mount_fd < 0) {
perror("fsmount");
return 1;
}
printf("Mount successful. Mount fd is %d. Have a look at /proc/%d/fdinfo/%d\n", mount_fd, getpid(), mount_fd);
wait("* Step 5: Move mount and make it visible");
if (move_mount(mount_fd, "", AT_FDCWD, mountpoint, MOVE_MOUNT_F_EMPTY_PATH) < 0) {
perror("move_mount");
return 1;
}
printf("tmpfs is now visible at %s. Don't forget to umount!\n", mountpoint);
close(fscontext_fd);
close(mount_fd);
return 0;
}