From 5547228a17c07e5fbd1c543218e4a1e25cbd2a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20F=20Bj=C3=B6rklund?= Date: Fri, 14 Mar 2025 17:58:45 +0100 Subject: [PATCH] Add support for mount export for fuse-nfs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It wants to list the exported file systems, for mount. But currently the nullauth ignores the dirpath anyway. Signed-off-by: Anders F Björklund --- handler.go | 3 +++ helpers/nullauthhandler.go | 5 +++++ mount.go | 16 ++++++++++++++++ mountinterface.go | 13 +++++++++++++ 4 files changed, 37 insertions(+) diff --git a/handler.go b/handler.go index 13a0eaf..8fafd03 100644 --- a/handler.go +++ b/handler.go @@ -20,6 +20,9 @@ type Handler interface { // Optional methods - generic helpers or trivial implementations can be sufficient depending on use case. + // List of all exported file systems. + Export(context.Context) []Export + // Fill in information about a file system's free space. FSStat(context.Context, billy.Filesystem, *FSStat) error diff --git a/helpers/nullauthhandler.go b/helpers/nullauthhandler.go index f7571b1..0094512 100644 --- a/helpers/nullauthhandler.go +++ b/helpers/nullauthhandler.go @@ -34,6 +34,11 @@ func (h *NullAuthHandler) Change(fs billy.Filesystem) billy.Change { return nil } +// List of all exported file systems. +func (h *NullAuthHandler) Export(context.Context) []nfs.Export { + return []nfs.Export{{Dir: []byte("/mount")}} +} + // FSStat provides information about a filesystem. func (h *NullAuthHandler) FSStat(ctx context.Context, f billy.Filesystem, s *nfs.FSStat) error { return nil diff --git a/mount.go b/mount.go index e95d098..55e7445 100644 --- a/mount.go +++ b/mount.go @@ -15,6 +15,7 @@ func init() { _ = RegisterMessageHandler(mountServiceID, uint32(MountProcNull), onMountNull) _ = RegisterMessageHandler(mountServiceID, uint32(MountProcMount), onMount) _ = RegisterMessageHandler(mountServiceID, uint32(MountProcUmnt), onUMount) + _ = RegisterMessageHandler(mountServiceID, uint32(MountProcExport), onMountExport) } func onMountNull(ctx context.Context, w *response, userHandle Handler) error { @@ -56,3 +57,18 @@ func onUMount(ctx context.Context, w *response, userHandle Handler) error { return w.writeHeader(ResponseCodeSuccess) } + +func onMountExport(ctx context.Context, w *response, userHandle Handler) error { + exports := userHandle.Export(ctx) + + if err := w.writeHeader(ResponseCodeSuccess); err != nil { + return err + } + + writer := bytes.NewBuffer([]byte{}) + + if err := xdr.Write(writer, exports); err != nil { + return err + } + return w.Write(writer.Bytes()) +} diff --git a/mountinterface.go b/mountinterface.go index 1dc39ee..01559c0 100644 --- a/mountinterface.go +++ b/mountinterface.go @@ -88,3 +88,16 @@ type MountResponse struct { FileHandle AuthFlavors []int } + +// Group contains a group node, with information about the allowed access group. +type Group struct { + Name []byte + Next []Group +} + +// Export contains an export node, with information about an exported filesystem. +type Export struct { + Dir []byte + Groups []Group + Next []Export +}