Skip to content

Commit bc78f07

Browse files
committed
commands: mount - add 9P2000.L host support
1 parent 8f5e41f commit bc78f07

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

internal/commands/mount.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ func makeHostCommands() []command.Command {
272272
var (
273273
commandMakers = []makeCommand{
274274
makeFUSECommand,
275+
makePlan9HostCommand,
275276
}
276277
commands = make([]command.Command, 0, len(commandMakers))
277278
)

internal/commands/mountpoint.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ func makeMountPointHosts(path ninePath, autoUnlink bool) mountPointHosts {
9090
var (
9191
hostMakers = []makeHostsFunc{
9292
makeFUSEHost,
93+
makePlan9Host,
9394
}
9495
hosts = make(mountPointHosts, len(hostMakers))
9596
)

internal/commands/mountpoint_9p.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,82 @@ import (
88
"github.com/djdv/go-filesystem-utils/internal/command"
99
"github.com/djdv/go-filesystem-utils/internal/filesystem"
1010
p9fs "github.com/djdv/go-filesystem-utils/internal/filesystem/9p"
11+
"github.com/djdv/go-filesystem-utils/internal/generic"
1112
"github.com/multiformats/go-multiaddr"
1213
)
1314

1415
type (
1516
plan9GuestSettings p9fs.Guest
1617
plan9GuestOption func(*plan9GuestSettings) error
1718
plan9GuestOptions []plan9GuestOption
19+
20+
plan9HostSettings p9fs.Host
21+
plan9HostOption func(*plan9HostSettings) error
22+
plan9HostOptions []plan9HostOption
1823
)
1924

2025
const p9GuestSrvFlagName = "server"
2126

27+
func makePlan9HostCommand() command.Command {
28+
return makeMountSubcommand(
29+
p9fs.HostID,
30+
makeGuestCommands[plan9HostOptions, plan9HostSettings](p9fs.HostID),
31+
)
32+
}
33+
34+
func makePlan9Host(path ninePath, autoUnlink bool) (filesystem.Host, p9fs.MakeGuestFunc) {
35+
guests := makeMountPointGuests[p9fs.Host](path)
36+
return p9fs.HostID, newMakeGuestFunc(guests, path, autoUnlink)
37+
}
38+
39+
func unmarshalPlan9() (filesystem.Host, decodeFunc) {
40+
return p9fs.HostID, func(b []byte) (string, error) {
41+
var host p9fs.Host
42+
err := json.Unmarshal(b, &host)
43+
return host.Maddr.String(), err
44+
}
45+
}
46+
47+
func (*plan9HostOptions) usage(guest filesystem.ID) string {
48+
return string(p9fs.HostID) + " hosts " +
49+
string(guest) + " as a 9P file server"
50+
}
51+
52+
func (o9 *plan9HostOptions) BindFlags(flagSet *flag.FlagSet) {
53+
// TODO: - dedupe with guest
54+
var (
55+
flagPrefix = prefixIDFlag(p9fs.HostID)
56+
srvUsage = "9P2000.L file system server `maddr`"
57+
srvName = flagPrefix + p9GuestSrvFlagName
58+
)
59+
flagSetFunc(flagSet, srvName, srvUsage, o9,
60+
func(value multiaddr.Multiaddr, settings *plan9HostSettings) error {
61+
settings.Maddr = value
62+
return nil
63+
})
64+
}
65+
66+
func (o9 plan9HostOptions) make() (plan9HostSettings, error) {
67+
return makeWithOptions(o9...)
68+
}
69+
70+
func (set plan9HostSettings) marshal(arg string) ([]byte, error) {
71+
if arg == "" {
72+
err := command.UsageError{
73+
Err: generic.ConstError(
74+
"expected server multiaddr",
75+
),
76+
}
77+
return nil, err
78+
}
79+
maddr, err := multiaddr.NewMultiaddr(arg)
80+
if err != nil {
81+
return nil, err
82+
}
83+
set.Maddr = maddr
84+
return json.Marshal(set)
85+
}
86+
2287
func makePlan9GuestCommand[
2388
HC mountCmdHost[HT, HM],
2489
HM marshaller,

0 commit comments

Comments
 (0)