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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
.Dd May 21, 2024
.Dt MOUNT 2
.Os Camellia
.Sh NAME
.Nm mount
.Nd mount a filesystem
.Sh SYNOPSIS
.In camellia/syscalls.h
.In camellia/types.h
.Ft long
.Fo _sys_mount
.Fa "hid_t hid"
.Fa "const char *mpoint"
.Fa "long len"
.Fc
.Sh DESCRIPTION
.Nm
mounts the filesystem pointed to by
.Fa hid
at
.Fa mpoint ,
which is a string of length
.Fa len .
Unless overridden by a future
.Nm mount ,
all
.Xr open 2
calls under that path in the current process
will be handled by the chosen filesystem.
Other processes are unaffected \(em
in particular, children forked off before the mount call retain their old view
of the filesystem.
.Pp
The filesystem handle,
.Fa hid ,
can come from a
.Xr fork 2
call with the
.Dv FORK_NEWFS
flag, or from
.Xr getprocfs 2 .
If the handle isn't a valid filesystem, all
.Xr open 2
calls under
.Fa mpoint
will fail.
This can be used to deny access to a path \(em
for that purpose, you can use a
.Fa hid
of -1, which will never be a valid handle.
.Sh EXAMPLES
To mount a child under a path:
.Bd -literal -offset indent
#include <camellia/flags.h>
#include <camellia/syscalls.h>
#include <camellia/types.h>
#include <stdlib.h>
hid_t h;
if (_sys_fork(FORK_NEWFS, &h) == 0) { // lacks error checking!
do_child_stuff();
exit(1);
}
_sys_mount(h, "/path/", strlen("/path"));
.Ed
.Pp
However, ideally you'd use the
.Xr MOUNT_AT 3
macro instead:
.Bd -literal -offset indent
#include <camellia/fs/misc.h>
MOUNT_AT("/path/") {
do_child_stuff();
// will automatically exit() if do_child_stuff() returns
}
.Ed
.Pp
To deny access to a path, you can run
.Bd -literal -offset indent
_sys_mount(-1, path, strlen(path));
.Ed
.Sh SEE ALSO
.Xr fork 2 ,
.Xr getprocfs 2 ,
.Xr open 2 ,
.Xr path 7
|