forked from ygrek/extunix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmount.c
65 lines (48 loc) · 1.75 KB
/
mount.c
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
62
63
64
#define EXTUNIX_WANT_MOUNT
#include "config.h"
#if defined(EXTUNIX_HAVE_MOUNT)
static const int mountflags_table[] = {
MS_RDONLY, MS_NOSUID, MS_NODEV, MS_NOEXEC, MS_SYNCHRONOUS, MS_REMOUNT,
MS_MANDLOCK, MS_DIRSYNC, MS_NOATIME, MS_NODIRATIME, MS_BIND, MS_MOVE,
MS_REC, MS_SILENT, MS_POSIXACL, MS_UNBINDABLE, MS_PRIVATE, MS_SLAVE,
MS_SHARED, MS_RELATIME, MS_KERNMOUNT, MS_I_VERSION, MS_STRICTATIME,
MS_NOUSER
};
CAMLprim value caml_extunix_mount(value v_source, value v_target,
value v_fstype, value v_mountflags,
value v_data)
{
CAMLparam5(v_source, v_target, v_fstype, v_mountflags, v_data);
int ret;
char* p_source = strdup(String_val(v_source));
char* p_target = strdup(String_val(v_target));
char* p_fstype = strdup(String_val(v_fstype));
char* p_data = strdup(String_val(v_data));
int p_mountflags = caml_convert_flag_list(v_mountflags, mountflags_table);
caml_enter_blocking_section();
ret = mount(p_source, p_target, p_fstype, p_mountflags, p_data);
caml_leave_blocking_section();
free(p_source);
free(p_target);
free(p_fstype);
free(p_data);
if (ret != 0) uerror("mount", v_target);
CAMLreturn(Val_unit);
}
static const int umountflags_table[] = {
MNT_FORCE, MNT_DETACH, MNT_EXPIRE, UMOUNT_NOFOLLOW,
};
CAMLprim value caml_extunix_umount2(value v_target,value v_umountflags)
{
CAMLparam2(v_target, v_umountflags);
int ret;
char* p_target = strdup(String_val(v_target));
int p_umountflags = caml_convert_flag_list(v_umountflags, umountflags_table);
caml_enter_blocking_section();
ret = umount2(p_target, p_umountflags);
caml_leave_blocking_section();
free(p_target);
if (ret != 0) uerror("umount", v_target);
CAMLreturn(Val_unit);
}
#endif