2024-03-28 13:09:42 +00:00
|
|
|
package nfs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/willscott/go-nfs-client/nfs/xdr"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
mountServiceID = 100005
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
_ = RegisterMessageHandler(mountServiceID, uint32(MountProcNull), onMountNull)
|
|
|
|
_ = RegisterMessageHandler(mountServiceID, uint32(MountProcMount), onMount)
|
|
|
|
_ = RegisterMessageHandler(mountServiceID, uint32(MountProcUmnt), onUMount)
|
|
|
|
}
|
|
|
|
|
|
|
|
func onMountNull(ctx context.Context, w *response, userHandle Handler) error {
|
|
|
|
return w.writeHeader(ResponseCodeSuccess)
|
|
|
|
}
|
|
|
|
|
|
|
|
func onMount(ctx context.Context, w *response, userHandle Handler) error {
|
|
|
|
// TODO: auth check.
|
|
|
|
dirpath, err := xdr.ReadOpaque(w.req.Body)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
mountReq := MountRequest{Header: w.req.Header, Dirpath: dirpath}
|
|
|
|
status, handle, flavors := userHandle.Mount(ctx, w.conn, mountReq)
|
|
|
|
|
|
|
|
if err := w.writeHeader(ResponseCodeSuccess); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
writer := bytes.NewBuffer([]byte{})
|
|
|
|
if err := xdr.Write(writer, uint32(status)); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-06-16 21:34:46 +00:00
|
|
|
rootHndl := userHandle.ToHandle(ctx, handle, []string{})
|
2024-03-28 13:09:42 +00:00
|
|
|
|
|
|
|
if status == MountStatusOk {
|
|
|
|
_ = xdr.Write(writer, rootHndl)
|
|
|
|
_ = xdr.Write(writer, flavors)
|
|
|
|
}
|
|
|
|
return w.Write(writer.Bytes())
|
|
|
|
}
|
|
|
|
|
|
|
|
func onUMount(ctx context.Context, w *response, userHandle Handler) error {
|
|
|
|
_, err := xdr.ReadOpaque(w.req.Body)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return w.writeHeader(ResponseCodeSuccess)
|
|
|
|
}
|