2023-11-29 20:22:58 +00:00
|
|
|
# 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)
|
2023-12-25 23:11:54 +00:00
|
|
|
during(turn, root, ?:BootArgs) do (ds: Cap):
|
2023-11-29 20:22:58 +00:00
|
|
|
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:
|
2023-12-25 23:11:54 +00:00
|
|
|
mountpoint.status = Status(orKind: StatusKind.success)
|
2023-11-29 20:22:58 +00:00
|
|
|
else:
|
|
|
|
mountpoint.status = Status(orKind: StatusKind.Failure)
|
|
|
|
mountpoint.status.failure.msg = osErrorMsg(osLastError())
|
|
|
|
discard publish(turn, ds, mountpoint)
|
|
|
|
do:
|
|
|
|
discard umount(target)
|