Tahr.Mount.Types (tahr v0.1.0)

Copy Markdown View Source

XDR types for the MOUNT v3 protocol — RFC 1813 appendix I.

Constants:

MNTPATHLEN = 1024  # max path bytes
MNTNAMLEN  = 255   # max name bytes
FHSIZE3    = 64    # max v3 file-handle bytes

Linked-list types (mountlist, exportnode, groupnode) use XDR optional-data (§4.19) chains: each node carries its data plus an optional pointer to the next node, and the chain ends with a false flag. We model them as plain Elixir lists at the Elixir layer and serialise/deserialise the chain shape on encode/decode.

Summary

Types

Mount path string, ≤ 1024 bytes.

Opaque file-handle, ≤ 64 bytes.

Mount status — :ok is success, the rest are RFC 1813 errno-style codes.

Hostname / group name string, ≤ 255 bytes.

Functions

Decode an XDR optional-data linked list into a flat Elixir list. Each item is decoded by decoder/1 which consumes one item from the binary and returns {:ok, item, rest}.

Decode a bounded dirpath.

Decode one exportnode.

Decode a fhandle3.

Decode one mountlist entry.

Decode a bounded name.

Decode a 32-bit mountstat3 code back to its atom. Unknown codes surface as {:unknown, n} so handlers can report it without crashing.

Encode a list of items as an XDR optional-data linked list. Each item is encoded by encoder, then a TRUE flag points at the next item; the final item is followed by a FALSE flag (no next).

Encode a bounded dirpath (path name).

Encode one exportnode — directory + group list (chained).

Encode a fhandle3 — variable-length opaque ≤ 64 bytes.

Encode one mountlist entry — hostname + directory.

Encode a failure mountres3 (status only, no body).

Encode a successful mountres3 (MNT_OK with file-handle and the list of accepted auth flavours).

Encode a bounded name.

Encode a mountstat3 atom as its 32-bit wire integer.

RFC 1813 max v3 file-handle size.

RFC 1813 max name length.

RFC 1813 max path length.

Types

dirpath()

@type dirpath() :: binary()

Mount path string, ≤ 1024 bytes.

fhandle3()

@type fhandle3() :: binary()

Opaque file-handle, ≤ 64 bytes.

mountstat3()

@type mountstat3() ::
  :ok
  | :perm
  | :noent
  | :io
  | :acces
  | :notdir
  | :inval
  | :nametoolong
  | :notsupp
  | :serverfault

Mount status — :ok is success, the rest are RFC 1813 errno-style codes.

name()

@type name() :: binary()

Hostname / group name string, ≤ 255 bytes.

Functions

decode_chain(binary, decoder)

@spec decode_chain(binary(), (binary() -> {:ok, term(), binary()} | {:error, term()})) ::
  {:ok, [term()], binary()} | {:error, term()}

Decode an XDR optional-data linked list into a flat Elixir list. Each item is decoded by decoder/1 which consumes one item from the binary and returns {:ok, item, rest}.

decode_dirpath(binary)

@spec decode_dirpath(binary()) :: {:ok, dirpath(), binary()} | {:error, term()}

Decode a bounded dirpath.

decode_exportnode(binary)

@spec decode_exportnode(binary()) ::
  {:ok, Tahr.Mount.Types.ExportNode.t(), binary()} | {:error, term()}

Decode one exportnode.

decode_fhandle3(binary)

@spec decode_fhandle3(binary()) :: {:ok, fhandle3(), binary()} | {:error, term()}

Decode a fhandle3.

decode_mountlist_entry(binary)

@spec decode_mountlist_entry(binary()) ::
  {:ok, Tahr.Mount.Types.MountList.t(), binary()} | {:error, term()}

Decode one mountlist entry.

decode_name(binary)

@spec decode_name(binary()) :: {:ok, name(), binary()} | {:error, term()}

Decode a bounded name.

decode_stat(binary)

@spec decode_stat(binary()) ::
  {:ok, mountstat3() | {:unknown, non_neg_integer()}, binary()}
  | {:error, term()}

Decode a 32-bit mountstat3 code back to its atom. Unknown codes surface as {:unknown, n} so handlers can report it without crashing.

encode_chain(items, encoder)

@spec encode_chain([term()], (term() -> binary())) :: binary()

Encode a list of items as an XDR optional-data linked list. Each item is encoded by encoder, then a TRUE flag points at the next item; the final item is followed by a FALSE flag (no next).

encode_dirpath(path)

@spec encode_dirpath(dirpath()) :: binary()

Encode a bounded dirpath (path name).

encode_exportnode(export_node)

@spec encode_exportnode(Tahr.Mount.Types.ExportNode.t()) :: binary()

Encode one exportnode — directory + group list (chained).

encode_fhandle3(fh)

@spec encode_fhandle3(fhandle3()) :: binary()

Encode a fhandle3 — variable-length opaque ≤ 64 bytes.

encode_mountlist_entry(mount_list)

@spec encode_mountlist_entry(Tahr.Mount.Types.MountList.t()) :: binary()

Encode one mountlist entry — hostname + directory.

encode_mountres3_err(status)

@spec encode_mountres3_err(mountstat3()) :: binary()

Encode a failure mountres3 (status only, no body).

encode_mountres3_ok(fhandle, auth_flavors)

@spec encode_mountres3_ok(fhandle3(), [non_neg_integer()]) :: binary()

Encode a successful mountres3 (MNT_OK with file-handle and the list of accepted auth flavours).

encode_name(name)

@spec encode_name(name()) :: binary()

Encode a bounded name.

encode_stat(stat)

@spec encode_stat(mountstat3()) :: binary()

Encode a mountstat3 atom as its 32-bit wire integer.

fhsize3()

@spec fhsize3() :: 64

RFC 1813 max v3 file-handle size.

mntnamlen()

@spec mntnamlen() :: 255

RFC 1813 max name length.

mntpathlen()

@spec mntpathlen() :: 1024

RFC 1813 max path length.