parent
72f5d04030
commit
3c8b485d32
43
README.md
43
README.md
|
@ -34,6 +34,49 @@ Do not send messages immediately to the dataspace passed `json_socket_translator
|
||||||
|
|
||||||
A utility for minting [Sturdyrefs](https://synit.org/book/operation/builtin/gatekeeper.html#sturdyrefs).
|
A utility for minting [Sturdyrefs](https://synit.org/book/operation/builtin/gatekeeper.html#sturdyrefs).
|
||||||
|
|
||||||
|
## mount_actor
|
||||||
|
|
||||||
|
Actor for mounting filesystems on Linux.
|
||||||
|
|
||||||
|
Sample Syndicate server script:
|
||||||
|
```
|
||||||
|
# Assert a file-system we want to mount.
|
||||||
|
<mount "/dev/sda3" "/boot" "vfat">
|
||||||
|
|
||||||
|
# Transform mount assertions into mount status observations.
|
||||||
|
? <mount ?source ?target ?fs> [
|
||||||
|
? <mount $source $target $fs _> [ ]
|
||||||
|
]
|
||||||
|
|
||||||
|
# Assert mounting succeded.
|
||||||
|
? <mount _ ?target _ #t> [
|
||||||
|
<service-state <mountpoint $target> ready>
|
||||||
|
]
|
||||||
|
# Assert mount failed.
|
||||||
|
? <mount _ ?target _ <failure _>> [
|
||||||
|
<service-state <mountpoint $target> failed>
|
||||||
|
]
|
||||||
|
|
||||||
|
# Assert the details into the machine dataspace.
|
||||||
|
? <machine-dataspace ?machine> [
|
||||||
|
$config ? <mount ?source ?target ?fs ?status> [
|
||||||
|
$machine <mount $source $target $fs $status>
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
# Require the mount_actor daemon.
|
||||||
|
<require-service <daemon mount_actor>>
|
||||||
|
<daemon mount_actor {
|
||||||
|
argv: ["/home/emery/src/bin/mount_actor"]
|
||||||
|
protocol: application/syndicate
|
||||||
|
}>
|
||||||
|
|
||||||
|
# Pass the daemon the config dataspace.
|
||||||
|
? <service-object <daemon mount_actor> ?cap> [
|
||||||
|
$cap { dataspace: $config }
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
## msg
|
## msg
|
||||||
|
|
||||||
A utility that sends messages to `$SYNDICATE_ROUTE`.
|
A utility that sends messages to `$SYNDICATE_ROUTE`.
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
version 1.
|
||||||
|
|
||||||
|
Mountpoint = <mount @source string @target string @type string @status Status> .
|
||||||
|
Status = Failure / #t.
|
||||||
|
Failure = <failure @msg string> .
|
|
@ -0,0 +1,44 @@
|
||||||
|
# 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)
|
|
@ -0,0 +1,30 @@
|
||||||
|
|
||||||
|
import
|
||||||
|
preserves
|
||||||
|
|
||||||
|
type
|
||||||
|
Failure* {.preservesRecord: "failure".} = object
|
||||||
|
`msg`*: string
|
||||||
|
|
||||||
|
Mountpoint* {.preservesRecord: "mount".} = object
|
||||||
|
`source`*: string
|
||||||
|
`target`*: string
|
||||||
|
`type`*: string
|
||||||
|
`status`*: Status
|
||||||
|
|
||||||
|
StatusKind* {.pure.} = enum
|
||||||
|
`Failure`, `true`
|
||||||
|
`Status`* {.preservesOr.} = object
|
||||||
|
case orKind*: StatusKind
|
||||||
|
of StatusKind.`Failure`:
|
||||||
|
`failure`*: Failure
|
||||||
|
|
||||||
|
of StatusKind.`true`:
|
||||||
|
`true`* {.preservesLiteral: "#t".}: bool
|
||||||
|
|
||||||
|
|
||||||
|
proc `$`*(x: Failure | Mountpoint | Status): string =
|
||||||
|
`$`(toPreserve(x))
|
||||||
|
|
||||||
|
proc encode*(x: Failure | Mountpoint | Status): seq[byte] =
|
||||||
|
encode(toPreserve(x))
|
|
@ -1,11 +1,11 @@
|
||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "20231108"
|
version = "20231129"
|
||||||
author = "Emery Hemingway"
|
author = "Emery Hemingway"
|
||||||
description = "Utilites for Syndicated Actors and Synit"
|
description = "Utilites for Syndicated Actors and Synit"
|
||||||
license = "unlicense"
|
license = "unlicense"
|
||||||
srcDir = "src"
|
srcDir = "src"
|
||||||
bin = @["cache_actor", "json_socket_translator", "json_translator", "mintsturdyref", "msg", "net_mapper", "preserve_process_environment", "syndex_card", "syndump"]
|
bin = @["cache_actor", "json_socket_translator", "json_translator", "mintsturdyref", "mount_actor", "msg", "net_mapper", "preserve_process_environment", "syndex_card", "syndump"]
|
||||||
|
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
|
Loading…
Reference in New Issue