Debian Codegraph @

mount/mounter_openbsd.go

raw symbols SCIP
1 //go:build openbsd && cgo
2
3 /*
4 Due to how OpenBSD mount(2) works, filesystem types need to be
5 supported explicitly since it uses separate structs to pass
6 filesystem-specific arguments.
7
8 For now only UFS/FFS is supported as it's the default fs
9 on OpenBSD systems.
10
11 See: https://man.openbsd.org/mount.2
12 */
13
14 package mount
15
16 /*
17 #include <sys/types.h>
18 #include <sys/mount.h>
19 */
20 import "C"
21
22 import (
23 "fmt"
24 "syscall"
25 "unsafe"
26 )
27
28 func createExportInfo(readOnly bool) C.struct_export_args {
29 exportFlags := C.int(0)
30 if readOnly {
31 exportFlags = C.MNT_EXRDONLY
32 }
33 out := C.struct_export_args{
34 ex_root: 0,
35 ex_flags: exportFlags,
36 }
37 return out
38 }
39
40 func createUfsArgs(device string, readOnly bool) unsafe.Pointer {
41 out := &C.struct_ufs_args{
42 fspec: C.CString(device),
43 export_info: createExportInfo(readOnly),
44 }
45 return unsafe.Pointer(out)
46 }
47
48 func mount(device, target, mType string, flag uintptr, data string) error {
49 readOnly := flag&RDONLY != 0
50
51 var fsArgs unsafe.Pointer
52
53 switch mType {
54 case "ffs":
55 fsArgs = createUfsArgs(device, readOnly)
56 default:
57 return &mountError{
58 op: "mount",
59 source: device,
60 target: target,
61 flags: flag,
62 err: fmt.Errorf("unsupported file system type: %s", mType),
63 }
64 }
65
66 if errno := C.mount(C.CString(mType), C.CString(target), C.int(flag), fsArgs); errno != 0 {
67 return &mountError{
68 op: "mount",
69 source: device,
70 target: target,
71 flags: flag,
72 err: syscall.Errno(errno),
73 }
74 }
75
76 return nil
77 }