71 lines
2.2 KiB
Go
71 lines
2.2 KiB
Go
// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
|
|||
|
|
// SPDX-License-Identifier: MIT
|
||
|
|
|
||
|
|
// The extended attribute operations of RFC 8276: four narrow operations
|
||
|
|
// over named opaque values.
|
||
|
|
|
||
|
|
package nfs4
|
||
|
|
|
||
|
|
import (
|
||
|
|
"sourcedock.dev/petrbalvin/nfs/internal/xdr"
|
||
|
|
)
|
||
|
|
|
||
|
|
// SETXATTR modes of the setxattr4mode4 enum.
|
||
|
|
const (
|
||
|
|
SetXattrUnchecked = 0
|
||
|
|
SetXattrCreate = 1
|
||
|
|
SetXattrReplace = 2
|
||
|
|
)
|
||
|
|
|
||
|
|
// AppendGetXattrArgs appends the GETXATTR argop: the name alone, the
|
||
|
|
// whole argument RFC 8276 defines.
|
||
|
|
func AppendGetXattrArgs(b []byte, name string) []byte {
|
||
|
|
b = xdr.AppendUint32(b, OpGetxattr)
|
||
|
|
return xdr.AppendString(b, name)
|
||
|
|
}
|
||
|
|
|
||
|
|
// AppendGetXattrRes appends a successful GETXATTR result: the value as
|
||
|
|
// one opaque.
|
||
|
|
func AppendGetXattrRes(b []byte, value []byte) []byte {
|
||
|
|
return xdr.AppendVarOpaque(b, value)
|
||
|
|
}
|
||
|
|
|
||
|
|
// DecodeGetXattrRes decodes a successful GETXATTR result.
|
||
|
|
func DecodeGetXattrRes(body []byte) ([]byte, error) {
|
||
|
|
return xdr.NewDecoder(body).VarOpaque()
|
||
|
|
}
|
||
|
|
|
||
|
|
// AppendSetXattrArgs appends the SETXATTR argop: the create mode, the
|
||
|
|
// name and the value.
|
||
|
|
func AppendSetXattrArgs(b []byte, mode uint32, name string, value []byte) []byte {
|
||
|
|
b = xdr.AppendUint32(b, OpSetxattr)
|
||
|
|
b = xdr.AppendUint32(b, mode)
|
||
|
|
b = xdr.AppendString(b, name)
|
||
|
|
return xdr.AppendVarOpaque(b, value)
|
||
|
|
}
|
||
|
|
|
||
|
|
// AppendListXattrArgs appends the LISTXATTR argop: the cookie the last
|
||
|
|
// reply returned and the response size budget.
|
||
|
|
func AppendListXattrArgs(b []byte, cookie uint64, maxcount uint32) []byte {
|
||
|
|
b = xdr.AppendUint32(b, OpListxattr)
|
||
|
|
b = xdr.AppendUint64(b, cookie)
|
||
|
|
return xdr.AppendUint32(b, maxcount)
|
||
|
|
}
|
||
|
|
|
||
|
|
// AppendListXattrRes appends a successful LISTXATTR result: the cookie
|
||
|
|
// of the last name, the names and the end of list flag.
|
||
|
|
func AppendListXattrRes(b []byte, cookie uint64, names []string, eof bool) []byte {
|
||
|
|
b = xdr.AppendUint64(b, cookie)
|
||
|
|
b = xdr.AppendUint32(b, uint32(len(names)))
|
||
|
|
for _, n := range names {
|
||
|
|
b = xdr.AppendString(b, n)
|
||
|
|
}
|
||
|
|
return xdr.AppendBool(b, eof)
|
||
|
|
}
|
||
|
|
|
||
|
|
// AppendRemoveXattrArgs appends the REMOVEXATTR argop: the name.
|
||
|
|
func AppendRemoveXattrArgs(b []byte, name string) []byte {
|
||
|
|
b = xdr.AppendUint32(b, OpRemovexattr)
|
||
|
|
return xdr.AppendString(b, name)
|
||
|
|
}
|