| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
package mount |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 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 |
} |