45 lines
1.5 KiB
Nim
45 lines
1.5 KiB
Nim
|
# SPDX-FileCopyrightText: ☭ Emery Hemingway
|
||
|
# SPDX-License-Identifier: Unlicense
|
||
|
|
||
|
## An actor for Linux file-system mounting.
|
||
|
|
||
|
when not defined(linux):
|
||
|
{.error: "this component only tested for Linux".}
|
||
|
|
||
|
import std/oserrors
|
||
|
import preserves
|
||
|
import syndicate, syndicate/relays
|
||
|
import ./schema/mountpoints
|
||
|
|
||
|
type BootArgs {.preservesDictionary.} = object
|
||
|
dataspace: Cap
|
||
|
|
||
|
proc mount(source, target, fsType: cstring; flags: culong; data: pointer): cint {.importc, header: "<sys/mount.h>".}
|
||
|
## `mount(2)`
|
||
|
|
||
|
proc umount(target: cstring): cint {.importc, header: "<sys/mount.h>".}
|
||
|
## `umount(2)`
|
||
|
|
||
|
runActor("mount_actor") do (turn: var Turn; root: Cap):
|
||
|
let
|
||
|
targetPat = ?Observe(pattern: !Mountpoint) ?? { 1: grabLit() }
|
||
|
sourcePat = ?Observe(pattern: !Mountpoint) ?? { 0: grabLit(), 2: grabLit() }
|
||
|
connectStdio(turn, root)
|
||
|
during(turn, root, ?BootArgs) do (ds: Cap):
|
||
|
during(turn, ds, targetPat) do (target: string):
|
||
|
during(turn, ds, sourcePat) do (source: string, fsType: string):
|
||
|
var mountpoint = Mountpoint(
|
||
|
source: source,
|
||
|
target: target,
|
||
|
`type`: fsType,
|
||
|
)
|
||
|
var rc = mount(source, target, fsType, 0, nil)
|
||
|
if rc == 0:
|
||
|
mountpoint.status = Status(orKind: StatusKind.true)
|
||
|
else:
|
||
|
mountpoint.status = Status(orKind: StatusKind.Failure)
|
||
|
mountpoint.status.failure.msg = osErrorMsg(osLastError())
|
||
|
discard publish(turn, ds, mountpoint)
|
||
|
do:
|
||
|
discard umount(target)
|