osfsutil

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2026 License: MIT Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package osfsutil 提供 core/osfs 使用的平台无关纯辅助、错误归一化、路径与目录项校验工具。 本包属于 core/osfs 四层最小特权隔离架构中的零特权辅助层(LayerCoreOSFSInternal), 严禁持有裸 OS 句柄、文件锁、Windows ACL 系统调用或 net 原语(受控原语分别严格收口于 core/osfs、winpipe 与 unixipc)。

Index

Constants

View Source
const (
	DefaultFilePerm fs.FileMode = 0o600
	DefaultDirPerm  fs.FileMode = 0o700
)

DefaultFilePerm 与 DefaultDirPerm 为跨平台默认文件与目录权限掩码。

View Source
const (
	SocketProbeUnknownCode uint8 = iota
	SocketProbeMissingCode
	SocketProbeNotSocketCode
	SocketProbeLiveCode
	SocketProbeStaleCode

	SocketProbeMinValidCode = SocketProbeMissingCode
	SocketProbeMaxValidCode = SocketProbeStaleCode
)

SocketProbeStatus 底层连续编码与有效边界常量,由 SocketProbeStatus(socketvalue.go)单源派生。

View Source
const (
	SocketPeerPolicyUnsetCode    uint8 = iota // 零值默认,强制归一为最严 SocketPeerOwnerOnly
	SocketPeerOwnerOnlyCode                   // 强制内核级同 UID(Unix)/ 同 SID(Windows)对端校验
	SocketPeerFilesystemPermCode              // 显式放权:委托内核 VFS 文件权限(仅 Unix 非属主掩码 StreamLocal)

	SocketPeerPolicyMaxKnownCode = SocketPeerFilesystemPermCode
)

SocketPeerPolicy 底层连续编码与有效边界常量,由 SocketPeerPolicy(socketvalue.go)单源派生。

View Source
const (
	WinAttrDirectory, WinAttrDevice, WinAttrReparsePoint                         uint32 = 0x10, 0x40, 0x400
	WinACEFlagInheritOnly, WinACETypeAllow, WinACETypeDeny                       uint8  = 0x08, 0x00, 0x01
	WinAccessWriteData, WinAccessAppendData, WinAccessWriteEA                    uint32 = 0x02, 0x04, 0x10
	WinAccessCreatePipeInstance                                                  uint32 = 0x04
	WinAccessDeleteChild                                                         uint32 = 0x40
	WinAccessWriteAttrs, WinAccessDelete, WinAccessWriteDAC, WinAccessWriteOwner uint32 = 0x100, 0x10000, 0x40000, 0x80000
	WinAccessGenericAll, WinAccessGenericWrite                                   uint32 = 0x10000000, 0x40000000
)

Win32 DACL 与文件属性位常量(跨平台纯数学副本)。

View Source
const (
	ACLModeInvalid uint8 = iota
	ACLModeOwnerOnly
	ACLModeWriteRestricted
	ACLModePipeServerSafe

	ACLModeMinValid = ACLModeOwnerOnly
	ACLModeMaxValid = ACLModePipeServerSafe
)

WindowsACLMode 底层连续编码与有效边界常量,由 WindowsACLMode(winacl.go)单源派生。

View Source
const MaxSymlinkHops = 40

MaxSymlinkHops 定义逐分量解析物理路径时允许展开的符号链接/重解析点最大跳数(对齐 POSIX SYMLOOP_MAX / Linux MAXSYMLINKS)。

View Source
const Win32LongPathThreshold = 248

Win32LongPathThreshold 是触发 Win32 扩展长路径前缀(\\?\ 与 \\?\UNC\)的 UTF-16 码元阈值(INV-A4)。

Variables

This section is empty.

Functions

func AcquireLockedHandle added in v1.4.0

func AcquireLockedHandle[F any](
	dest string,
	maxRetries int,
	openFn func() (F, error),
	tryLockFn func(F) error,
	verifySameFn func(F) (bool, error),
	closeFn func(F),
	unlockCloseFn func(F),
	errMismatch error,
) (F, bool, error)

AcquireLockedHandle 在有界重试次数内执行「打开句柄 -> 非阻塞加锁 -> SameFile 核验」,防锁目标替换竞态(INV-A2)。

func AtomicReplaceWithSidecarLock

func AtomicReplaceWithSidecarLock(ctx context.Context, root ports.RootHandle, dest pathalg.LocalRootedDest, perm fs.FileMode, fn WriteFileFunc) error

AtomicReplaceWithSidecarLock 持有同目录旁路独占锁 <dest>.lock(绝不锁目标文件)并原子替换 dest(ADR-007)。

func BuildAppendFrame

func BuildAppendFrame(line []byte) ([]byte, error)

BuildAppendFrame 校验追加行不含内嵌 '\r'/'\n' 并复制追加结尾 '\n'。

func CheckAFUnixReparseAttrs

func CheckAFUnixReparseAttrs(path string, attrs, reparseTag, expectedTag uint32, errNotSocket error) error

CheckAFUnixReparseAttrs 校验 Windows 对象句柄为非目录的 AF_UNIX 重解析点。

func CheckChtimesLstatInfo

func CheckChtimesLstatInfo(rel string, lst fs.FileInfo) error

CheckChtimesLstatInfo 校验 Chtimes 目标非符号链接且为常规文件或目录。

func CheckLockArgs

func CheckLockArgs(activeDestErr error, mode ports.LockMode, fnNil bool) error

CheckLockArgs 校验文件加锁操作的目标路径活性、回调与锁模式。

func CheckLstatInfo

func CheckLstatInfo(rel string, lst fs.FileInfo, wantDir bool) error

CheckLstatInfo 校验已获取的 Lstat 元信息非符号链接且与期望对象类型一致。

func CheckLstatKind added in v1.4.0

func CheckLstatKind(root RootOps, rel string, wantDir, allowMissing bool) (fs.FileInfo, error)

CheckLstatKind 在沙箱根内执行 Lstat 并按期望类型(目录或常规文件)强校验,拒绝符号链接。

func CheckOperatorReadArgs

func CheckOperatorReadArgs(ctx context.Context, valid bool, path pathalg.LocalSourcePath, policy pathalg.SymlinkPolicy, fnNil bool) error

CheckOperatorReadArgs 校验 WithOperatorRead 的上下文、回调、有效性与路径/软链策略。

func CheckPrepareSocketStatus

func CheckPrepareSocketStatus(nativePath string, status uint8, replaceStale bool, errNotSocket, errSlotOccupied error) error

CheckPrepareSocketStatus 判定已存在路径在绑定套接字槽位前的冲突处置状态。

func CheckReadSizeLimit

func CheckReadSizeLimit(dest string, size, maxBytes int64) error

CheckReadSizeLimit 校验文件大小不超过 ReadLimits 上限。

func CheckRootCB

func CheckRootCB(root ports.RootHandle, fnNil bool) error

CheckRootCB 校验包级原语传入的 RootHandle 与回调函数均非 nil。

func CheckSocketDialTarget

func CheckSocketDialTarget(nativePath string, status uint8, inspectErr, errNotSocket error) error

CheckSocketDialTarget 核验拨号前对本地 AF_UNIX 目标路径的探测分类,缺失或非套接字一律失败关闭。

func CheckSocketSlotEntry

func CheckSocketSlotEntry(ctx context.Context, pathValid, fnNil bool, errInvalid error) error

CheckSocketSlotEntry 统一校验 WithSocketSlot 入口的回调非空、上下文与控制路径有效性。

func CheckSocketWithinRoot

func CheckSocketWithinRoot(within bool, err error, target string) error

CheckSocketWithinRoot 核验物理路径包含判定结果,越界时 fail-closed 返回同时匹配 ErrPermissionDenied 与 ErrSymlinkRejected 的错误。

func CheckStaleProbeOutcome

func CheckStaleProbeOutcome(nativePath string, probed uint8, pErr, errSlotOccupied error) error

CheckStaleProbeOutcome 核验陈旧套接字探活结论;上下文取消原样返回,非 Stale 失败关闭返回 ErrSlotOccupied。

func CheckUnixPrivateOwnerAndMode

func CheckUnixPrivateOwnerAndMode(uid uint32, euid int, mode fs.FileMode, errInsecure error) error

CheckUnixPrivateOwnerAndMode 校验已打开 Unix 私密文件的属主 UID 与非属主权限位(mode & 0o077 == 0)。

func CheckWin32DirAttrs

func CheckWin32DirAttrs(path string, attrs uint32, errInsecure error) error

CheckWin32DirAttrs 校验 Windows 目录句柄属性非重解析点且为目录。

func CheckWin32HandleAttrs

func CheckWin32HandleAttrs(path string, attrs uint32, expectDir, rejectReparse bool) error

CheckWin32HandleAttrs 校验 Windows 句柄文件属性是否满足重解析点、非设备及目录/文件类型约束。

func ChtimesInRoot added in v1.4.0

func ChtimesInRoot(root RootOps, prepErr error, dest pathalg.LocalRootedDest, atime, mtime time.Time) error

ChtimesInRoot 校验时间戳范围与目标非软链属性后修改沙箱目标的访问与修改时间。

func CollectDirEntries

func CollectDirEntries(raw []fs.DirEntry) ([]ports.LocalDirEntry, error)

CollectDirEntries 将目录项切片校验并按名称升序排序,自动跳过并发消失条目。

func CollectMissingDirChain

func CollectMissingDirChain(
	target string,
	checkExisting func(cur string) (exists bool, err error),
	splitParent func(cur string) (parent, item string),
	onRootMissing func(cur string) error,
) (string, []string, error)

CollectMissingDirChain 沿父目录逐级向上探测直至遇到已存在目录,返回基准祖先目录与待创建子路径/分量序列。

func CopyChunkAt

func CopyChunkAt(w io.WriteSeeker, offset int64, r io.Reader, length int64) (int64, error)

CopyChunkAt 在 offset 处向目标可寻址文件写入精确 length 字节,遇流提前结束返回 io.ErrUnexpectedEOF。

func CreateSymlinkInRoot added in v1.4.0

func CreateSymlinkInRoot(root RootOps, prepErr error, link pathalg.LocalRootedDest, target string) error

CreateSymlinkInRoot 校验相对符号链接目标合规性并在沙箱根内创建符号链接。

func EffectiveSocketFilePerm

func EffectiveSocketFilePerm(filePerm fs.FileMode) fs.FileMode

EffectiveSocketFilePerm 返回归一后的有效本地套接字权限位(零值回退 0o600,含非法特殊权限位返回 0)。

func ErrField

func ErrField(s error, f string) error

ErrField 构造绑定哨兵 s 与字段名 f 的非法字段值错误。

func ErrFieldNil

func ErrFieldNil(s error, f string) error

ErrFieldNil 构造绑定哨兵 s 与字段名 f 的空字段错误。

func ErrNullDeviceTypeMismatch

func ErrNullDeviceTypeMismatch(sentinel error, expected string, actual uint64) error

ErrNullDeviceTypeMismatch 构造平台空设备非字符设备类型校验失败的结构化错误。

func ErrSocketPathTooLong

func ErrSocketPathTooLong(errTooLong error, size, limit int) error

ErrSocketPathTooLong 构造本地套接字路径超出 sun_path 上限的结构化错误。

func ErrStageDirAccessDenied

func ErrStageDirAccessDenied(errInsecure error, stageDir string) error

ErrStageDirAccessDenied 构造私有暂存目录属主/权限核验失败错误。

func ErrWrongKind

func ErrWrongKind(p string, wantDir bool) error

ErrWrongKind 构造非目录或非常规文件错误。

func EvaluateSingleWindowsACE

func EvaluateSingleWindowsACE(mode uint8, expectDir bool, aceType, aceFlags uint8, mask uint32, sidValid, sidTrusted bool) security.Verdict

EvaluateSingleWindowsACE 以失败关闭交半格语义评估单条 Windows DACL ACE 安全性。

func EvaluateWindowsObjectACL added in v1.4.0

func EvaluateWindowsObjectACL(in WindowsACLInput) security.Verdict

EvaluateWindowsObjectACL 以失败关闭交半格语义评估 Windows 对象属性与 DACL 安全性(INV-A4 / INV-E1)。

func FileInfoToLocalFileInfo

func FileInfoToLocalFileInfo(name string, fi fs.FileInfo) (ports.LocalFileInfo, error)

FileInfoToLocalFileInfo 将 fs.FileInfo 转换为不可变 ports.LocalFileInfo。

func HasForbiddenControlPathRune

func HasForbiddenControlPathRune(s string) bool

HasForbiddenControlPathRune 检测路径中是否含非法 UTF-8、控制字符、行/段分隔符或 Bidi/Cf 格式字符。

func HasInvalidSocketTail

func HasInvalidSocketTail(p string) bool

HasInvalidSocketTail 报告套接字路径末尾是否为空、'.'、'..' 或尾随斜杠。

func IsASCIIAlphaByte

func IsASCIIAlphaByte(b byte) bool

IsASCIIAlphaByte 判断字节是否为 ASCII 字母。

func IsActiveHandle

func IsActiveHandle(active *atomic.Bool, nonNil bool) bool

IsActiveHandle 判断受借用句柄的原子活性哨兵是否处于有效态。

func IsAlreadyNormalizedError

func IsAlreadyNormalizedError(err error) bool

IsAlreadyNormalizedError 报告 err 是否已携带规范 ports 或 context 哨兵错误。

func IsExtendedOrDeviceWindowsPath

func IsExtendedOrDeviceWindowsPath(path string) bool

IsExtendedOrDeviceWindowsPath 报告路径是否已携带 \\?\、\\.\ 或 \??\ Win32 设备/扩展前缀。

func IsLowerHex40

func IsLowerHex40(s string) bool

IsLowerHex40 报告 s 是否为 40 位小写十六进制字符串(OpenSSH %C 摘要格式)。

func IsPhysicalPathContained

func IsPhysicalPathContained(physTarget, physRoot string, caseInsensitive bool) bool

IsPhysicalPathContained 判定已规范物理路径 physTarget 是否等于或位于物理根目录 physRoot 内(严格段边界匹配); 正确处理 "/"、"c:/" 及 UNC 根,并在 caseInsensitive == true(windows || darwin)时折叠大小写。

func IsRawPathWithinRoot

func IsRawPathWithinRoot(targetPath, rootPath string, absFn func(string) (string, error), ops PhysicalPathOps, caseInsensitive bool) (bool, error)

IsRawPathWithinRoot 对目标路径与根路径分别执行抗悬空软链物理展开,再按段边界判定包含关系。

func IsSafeWin32ObjectAttrs

func IsSafeWin32ObjectAttrs(attrs uint32, expectDir, allowReparse bool) bool

IsSafeWin32ObjectAttrs 校验 Windows 对象属性非设备、符合期望目录/文件类型及重解析点策略。

func IsUnmappableWin32LinkTarget

func IsUnmappableWin32LinkTarget(raw string) bool

IsUnmappableWin32LinkTarget 报告剥离 \\?\ / \??\ 前缀并小写化后的 Windows 重解析目标 是否为空或无法词法映射的 NT 对象命名空间目标(Volume{GUID}、GLOBALROOT\、\Device\、Device\、\\.\ 等)。

func IsValidRFC3339Time

func IsValidRFC3339Time(t time.Time) bool

IsValidRFC3339Time 校验时间戳非零且 UTC 年份落在 [1, 9999] 内。

func IsValidWindowsACLHeader

func IsValidWindowsACLHeader(mode uint8, attrs uint32, expectDir, allowReparse, ownerTrusted, hasDACL bool) bool

IsValidWindowsACLHeader 校验 Windows 对象 ACL 评估前置头条件(模式、属主、DACL 存在性与对象属性)。

func IsValidWindowsLeaf

func IsValidWindowsLeaf(leaf string) bool

IsValidWindowsLeaf 校验单层 Windows 叶文件名不含路径分隔符、冒号或父目录穿越段。

func IsWin32Sep

func IsWin32Sep(b byte) bool

IsWin32Sep 判断字节是否为 Win32 路径分隔符 '\' 或 '/'。

func JoinAbsPhysicalRaw

func JoinAbsPhysicalRaw(raw string, cwdFn func() (string, error), isWindows bool) (string, error)

JoinAbsPhysicalRaw 在不执行词法 Clean 的前提下将原始路径归一为绝对路径(保留符号链接后的 "." / ".." 交由逐段展开处理): 绝对路径(含 Windows 扩展/设备前缀 \\?\ / \??\ / \\.\、盘符根路径与 UNC 路径)原样返回; Windows 单分隔符根相对路径(如 \a\..\b)拼接至 cwd 卷前缀;其余相对路径直接以原生分隔符拼接至 cwd。

func JoinManagedMuxPath

func JoinManagedMuxPath(nativeDir, percentC string) string

JoinManagedMuxPath 在目录 nativeDir 下按平台分隔符拼接自管控制套接字路径 cm-<percentC>.sock。

func MakeTempDestInSameDir

func MakeTempDestInSameDir(dest pathalg.LocalRootedDest) (pathalg.LocalRootedDest, error)

MakeTempDestInSameDir 在 dest 同级目录下构造带随机后缀的临时文件路径。

func MapErrTable

func MapErrTable(path string, err error, tbl []ErrMapPair) error

MapErrTable 按错误映射表将 err 映射为带路径上下文的 ports 哨兵错误,未命中返回 nil。

func MapOSError

func MapOSError(err error) error

MapOSError 将标准库 OS/FS 错误归一化包装为 ports 规范哨兵错误并保留底层错误链。

func MapProbeEOF

func MapProbeEOF(n int, err error) error

MapProbeEOF 将上限边界外 1 字节探测结果映射为 ErrLimitExceeded、底层错误或 io.EOF。

func MapSocketLinkErr

func MapSocketLinkErr(target string, err error, isExist bool, errSlotOccupied error) error

MapSocketLinkErr 映射原子 linkat 发布套接字时的冲突或 OS 错误。

func MkdirAllInRoot added in v1.4.0

func MkdirAllInRoot(
	root RootOps,
	activeDestErr error,
	dir pathalg.LocalRootedDest,
	perm fs.FileMode,
	mkdirSeg func(parentSegs []string, leaf string, mode fs.FileMode) error,
) error

MkdirAllInRoot 在沙箱根内逐段调用平台 mkdirSeg 创建目录树,已存在段必须通过非软链目录复核。

func NeedsDualParentSync

func NeedsDualParentSync(oldDest, newDest pathalg.LocalRootedDest) bool

NeedsDualParentSync 判断重命名源与目标是否位于不同父目录从而需要双向同步父目录。

func NormalizeWin32LongPathWithResolver

func NormalizeWin32LongPathWithResolver(path string, fullPath func(string) (string, error), getwd func() (string, error)) string

NormalizeWin32LongPathWithResolver 在有效路径长度 >= 248 UTF-16 码元时补齐 \\?\ 或 \\?\UNC\ 前缀(INV-A4)。

func NormalizeWindowsNamedPipePath

func NormalizeWindowsNamedPipePath(raw string) (string, error)

NormalizeWindowsNamedPipePath 校验并归一化 Windows 本地命名管道路径(\\.\pipe\<name>)。

func OrZero

func OrZero[T any](ok bool, v T) T

OrZero 当 ok 为 true 时返回 v,否则返回 T 的零值。

func ParseUnixControlSocketPath

func ParseUnixControlSocketPath(raw string, maxBytes int, errInvalid, errTooLong error) (dir, name, native string, err error)

ParseUnixControlSocketPath 按 Unix 规则解析并校验套接字路径:允许文件名含 ':',拒绝 '..' 与超长 sun_path。

func ParseWindowsControlSocketPath

func ParseWindowsControlSocketPath(raw string, maxBytes int, errInvalid, errTooLong error) (dir, name, native string, err error)

ParseWindowsControlSocketPath 按 Windows/NTFS 规则解析并校验套接字路径:除盘符前缀外严禁 ':' 与非法分量。

func PickIf

func PickIf[T any](ok bool, yes, no T) T

PickIf 按布尔条件返回 yes 或 no。

func PrepareDest added in v1.4.0

func PrepareDest(root RootOps, activeDestErr error, dest pathalg.LocalRootedDest) error

PrepareDest 校验目标路径在活跃沙箱句柄中的全部祖先目录均存在且非符号链接。

func PrepareSocketSlot

func PrepareSocketSlot[ID any](
	nativePath string,
	replaceStale bool,
	inspect func() (ID, uint8, error),
	probe func() (uint8, error),
	unlink func(ID) error,
	errNotSocket, errSlotOccupied error,
) error

PrepareSocketSlot 在目录锁内校验目标路径已有条目并按 replaceStale 策略探活清理陈旧套接字(零 OS 原语依赖)。

func ProbeSocketState

func ProbeSocketState[ID any](
	ctx context.Context,
	defaultTimeout time.Duration,
	inspect func() (ID, uint8, error),
	dial func(context.Context) error,
	isConnRefused func(error) bool,
	sameID func(ID, ID) bool,
) (uint8, error)

ProbeSocketState 编排本地 AF_UNIX 套接字 fail-closed 存活/陈旧探活状态机(前后身份复核防 TOCTOU)。

func PruneStaleSocketState

func PruneStaleSocketState[ID any](
	ctx context.Context,
	dir string,
	inspect func() (ID, uint8, error),
	withDirLock func(context.Context, string, bool, func() error) error,
	probe func() (uint8, error),
	unlink func(ID) error,
) (uint8, error)

PruneStaleSocketState 在目录锁内复核并安全清理陈旧本地 AF_UNIX 套接字,父目录缺失时零副作用返回 Missing。

func RandomHexToken

func RandomHexToken(n int) (string, error)

RandomHexToken 生成 n 字节随机数据的 2n 位小写十六进制令牌。

func ReadAllBoundedZeroing

func ReadAllBoundedZeroing(r io.Reader, sizeHint, maxBytes int64, dest string) ([]byte, error)

ReadAllBoundedZeroing 在 maxBytes 字节上限内读取私密流 r 的全部内容; 在切片扩容、超限或发生任意读取错误时均对所有中间缓冲执行 clear() 零化,防止机密字节残余堆内存。

func ReadAndBorrowPrivateFile added in v1.4.0

func ReadAndBorrowPrivateFile(r io.ReadCloser, size, maxBytes int64, dest string, fn func(box *secret.SecretBox) error) error

ReadAndBorrowPrivateFile 从已校验权限的私密文件流 r 有界读取字节、经 secret.WithBytes 借出 *secret.SecretBox, 并在退出(含 panic)前无条件关闭流且清零所有中间明文缓冲(ADR-018)。

func ReadAtBounded

func ReadAtBounded(r ports.BoundedReadHandle, p []byte, off, maxBytes int64, limited bool, active *atomic.Bool) (int, error)

ReadAtBounded 在作用域活性与字节上限约束下执行并发安全随机偏移读。

func ReadBounded

func ReadBounded(r ports.BoundedReadHandle, p []byte, remaining *int64, limited bool, active *atomic.Bool) (int, error)

ReadBounded 在作用域活性与字节上限约束下执行顺序有界读取,越限探测返回 ports.ErrLimitExceeded。

func ReadVerifiedPrivateFile added in v1.4.0

func ReadVerifiedPrivateFile(fsPort ports.ScopedRootFS, rootDir pathalg.LocalDir, dest pathalg.LocalRootedDest, limits ports.ReadLimits, fn func(box *secret.SecretBox) error) error

ReadVerifiedPrivateFile 是面向 ports.ScopedRootFS 的跨平台原子私密文件读取核心实现(ADR-018): 打开 rootDir 沙箱并在同步闭包内将通过句柄级权限校验的常规文件 dest 借出为 *secret.SecretBox, 完整兼容生产 *osfs.ScopedFS 与仿真 *sim.SimScopedRootFS。

func ReadVerifiedPrivateFileInRoot added in v1.4.0

func ReadVerifiedPrivateFileInRoot(

	root ports.RootHandle,
	dest pathalg.LocalRootedDest,
	limits ports.ReadLimits,
	fn func(box *secret.SecretBox) error,
) error

ReadVerifiedPrivateFileInRoot 在已借出的 ports.RootHandle 沙箱内通过 ports.PrivateFileReader 窄接口 原子校验并读取私密文件至 *secret.SecretBox;底层 RootHandle 未实现该接口时 fail-closed 返回 ports.ErrUnsupported。

func RelSegmentsUnderRoot

func RelSegmentsUnderRoot(rootDir, targetDir string, isWindows bool, escapeErr error) ([]string, error)

RelSegmentsUnderRoot 计算 targetDir 相对于非根绝对沙箱目录 rootDir 的逐段相对路径分量(无 OS/filepath 依赖):

  • 当 targetDir 等于 rootDir 时返回 (nil, nil);
  • 当任一方非绝对、为文件系统根、含 "."/".." 分量或 targetDir 逃逸出 rootDir 时,返回包装 escapeErr 的错误;
  • Windows 模式按大小写不敏感比对盘符与各段,自动剥离 \\?\ 长路径前缀。

func ReleaseSocketSlot

func ReleaseSocketSlot(
	withDirLock func(context.Context, string, bool, func() error) error,
	dir string,
	unlinkFn func() error,
	closeFn func() error,
	isRetryable func(error) bool,
) error

ReleaseSocketSlot 按 INV-A3 固定顺序编排「加目录锁 -> unlink -> close -> 可重试 unlink -> 忽略已消失目录锁」。

func RemoveLockedFileSafely

func RemoveLockedFileSafely(root ports.RootHandle, lockDest pathalg.LocalRootedDest) (bool, error)

RemoveLockedFileSafely 按三平台安全删锁协议清理已退役的单进程实例锁文件: 持独占锁截断清空刷盘 -> 解锁关句柄 -> Remove(忽略 ErrNotFound),消除 Windows 共享冲突。

func RenameInRoot added in v1.4.0

func RenameInRoot(
	root RootOps,
	oldPrepErr, newPrepErr error,
	oldDest, newDest pathalg.LocalRootedDest,
	syncParent func(pathalg.LocalRootedDest) error,
) error

RenameInRoot 在沙箱根内执行非软链校验、原子重命名以及单/双父目录同步。

func ResolvePhysicalPathWith

func ResolvePhysicalPathWith(absPath string, ops PhysicalPathOps) (string, error)

ResolvePhysicalPathWith 自根向叶逐分量推进并展开所有已存在及悬空符号链接/重解析点(上限 MaxSymlinkHops=40 跳), 维护 missingDepth 精确追踪悬空尾部与软链内 "..",剥离 \\?\ / \??\ / \\?\UNC\ 前缀, 拒绝 NUL 字节与 Windows 盘符相对路径,彻底阻断悬空祖先软链绕过沙箱互斥防线。

func ResolveRawPhysicalPath

func ResolveRawPhysicalPath(raw string, absFn func(string) (string, error), ops PhysicalPathOps) (string, error)

ResolveRawPhysicalPath 组合原始路径前置校验、abs 回调与 ResolvePhysicalPathWith 逐分量物理展开。

func ResolveSocketSlotConfig

func ResolveSocketSlotConfig(
	filePerm fs.FileMode,
	peerPolicy uint8,
	confineOpt algebraic.Option[pathalg.LocalDir],
	toNative func(pathalg.LocalPathKind, string) (string, error),
	errInvalid, errInsecure error,
) (fs.FileMode, uint8, string, error)

ResolveSocketSlotConfig 统一校验并归一套接字权限位、对端策略与可选内核沙箱根目录(零 OS 原语依赖)。

func ResolveSocketSlotOptions

func ResolveSocketSlotOptions(perm fs.FileMode, policy uint8, errInsecure error) (fs.FileMode, uint8, error)

ResolveSocketSlotOptions 校验并归一化本地 AF_UNIX 套接字权限位与对端接入策略:

  • 零值 perm 归一为 DefaultFilePerm(0o600);含高位特殊权限位一律拒绝;
  • 零值 policy 归一为 SocketPeerOwnerOnlyCode;未知枚举值一律拒绝;
  • 当有效策略为 SocketPeerOwnerOnlyCode 且 filePerm&0o077 != 0 时,fail-closed 返回以 ports.ErrInvalidArgument 包装 errInsecure 的结构化错误,消除权限开放却按同 UID 拦截的矛盾。

func RetryLockBackoff

func RetryLockBackoff(ctx context.Context, tryFn func() (bool, error)) error

RetryLockBackoff 在 ctx 取消控制下以有界指数退避同步重试非阻塞加锁回调(零后台协程)。

func RunWithLockedFile added in v1.4.0

func RunWithLockedFile(f SyncTruncateStatFile, baseName string, unlockAndClose func() error, fn func(f ports.LockedFile) error) (retErr error)

RunWithLockedFile 绑定活性哨兵后在同步闭包内借出 ports.LockedFile,退出时无条件失效、解锁并关闭。

func RunWithReadRegular added in v1.4.0

func RunWithReadRegular(f StatReadCloser, dest string, maxBytes int64, fn func(r ports.BoundedReadHandle, size int64) error) error

RunWithReadRegular 校验已打开文件体量上限并在同步闭包内借出有界随机只读句柄,退出前失效并关闭。

func SanitizeFilePerm

func SanitizeFilePerm(p, fb fs.FileMode) fs.FileMode

SanitizeFilePerm 剥离特殊权限位,若权限位为零则回退至 fb。

func ShouldRejectOperatorSymlink(policy pathalg.SymlinkPolicy) (bool, error)

ShouldRejectOperatorSymlink 按 SymlinkPolicy 判定只读操作是否必须拒绝跟随符号链接/重解析点。

func SiblingDest

func SiblingDest(dest pathalg.LocalRootedDest, name string) (pathalg.LocalRootedDest, error)

SiblingDest 在 dest 同级父目录下拼接新文件名分量 name。

func SidecarLockDest

func SidecarLockDest(dest pathalg.LocalRootedDest) (pathalg.LocalRootedDest, error)

SidecarLockDest 为目标文件构造同目录旁路锁路径 <name>.lock(ADR-007)。

func SocketPeerPolicyString

func SocketPeerPolicyString(policy uint8) string

SocketPeerPolicyString 将本地套接字对端策略底层码转换为规范小写名称。

func SocketProbeStatusString

func SocketProbeStatusString(status uint8) string

SocketProbeStatusString 将套接字探活状态枚举底层码转换为规范小写名称。

func StatDestInRoot added in v1.4.0

func StatDestInRoot(root RootOps, activeDestErr error, dest pathalg.LocalRootedDest, lstat bool) (ports.LocalFileInfo, error)

StatDestInRoot 对沙箱目标路径执行 Stat 或 Lstat 并转换为平台无关的 ports.LocalFileInfo。

func StripWin32ExtendedPrefix

func StripWin32ExtendedPrefix(p string) string

StripWin32ExtendedPrefix 剥离 Win32 扩展长路径及 NT 对象前缀(\\?\、\??\、\\?\UNC\、\??\UNC\)。

func StripWin32LongPathPrefix

func StripWin32LongPathPrefix(p string) string

StripWin32LongPathPrefix 剥离 Win32 \\?\ 与 \\?\UNC\ 扩展前缀。

func UTF16CodeUnitLen

func UTF16CodeUnitLen(s string) (n int)

UTF16CodeUnitLen 计算字符串在 UTF-16 编码下的精确码元数量(辅助平面码点计 2 码元)。

func ValidateChtimesArgs

func ValidateChtimesArgs(atime, mtime time.Time) error

ValidateChtimesArgs 校验 Chtimes 时间参数合法性(拒绝零值与越界年份)。

func ValidateConfineRootDir

func ValidateConfineRootDir(dir pathalg.LocalDir, errInvalid error) error

ValidateConfineRootDir 校验可选 Unix 套接字沙箱根目录:必须为有效、绝对且非文件系统根级目录(拒绝 "/"、"C:/"、"." 与相对路径)。

func ValidateCreateSymlinkTarget

func ValidateCreateSymlinkTarget(link pathalg.LocalRootedDest, target string) error

ValidateCreateSymlinkTarget 校验相对符号链接目标不逃逸沙箱深度。

func ValidateRawPhysicalPath

func ValidateRawPhysicalPath(raw string, isWindows bool) error

ValidateRawPhysicalPath 在调用 filepath.Abs 之前执行平台无关前置校验: 拒绝空路径、NUL 字节与 Windows 盘符相对路径(如 "C:foo"),避免 OS GetFullPathName 静默拼入驱动器工作目录。

func ValidateSocketCtxPath

func ValidateSocketCtxPath(ctx context.Context, pathValid bool, errInvalid error) error

ValidateSocketCtxPath 校验套接字操作的上下文与路径有效性。

func ValidateSocketPeerUID

func ValidateSocketPeerUID(valid, hasUID bool, actual, expected uint32, errUnauthorized error) error

ValidateSocketPeerUID 核验 Unix 本地套接字对端 UID 存在且等于当前进程有效 UID。

func ValidateTruncateSize

func ValidateTruncateSize(size int64) error

ValidateTruncateSize 校验 Truncate 目标长度非负。

func ValidateWriteChunkArgs

func ValidateWriteChunkArgs(r io.Reader, offset, length int64, perm fs.FileMode) error

ValidateWriteChunkArgs 校验 WriteChunk 的输入流、偏移量、长度防溢出与标准权限位。

func WithSidecarLock

func WithSidecarLock(ctx context.Context, root ports.RootHandle, target pathalg.LocalRootedDest, mode ports.LockMode, perm fs.FileMode, fn LockedFileFunc) error

WithSidecarLock 锁定 target 同目录旁路锁文件 <target>.lock 并同步执行回调(ADR-007)。

func WrapOp

func WrapOp(s, c error, op string) error

WrapOp 以哨兵 s 包装系统调用名 op 对应的底层错误 c。

func WrapOpenTarget

func WrapOpenTarget(s, c error, tgt string) error

WrapOpenTarget 以哨兵 s 包装目标路径 tgt 打开失败的错误。

func WrapS

func WrapS(s, c error) error

WrapS 以哨兵 s 包装底层错误 c。

func WrapSyscallErr

func WrapSyscallErr(err error, call string) error

WrapSyscallErr 以 osfs.syscall_failed 包装系统调用错误,并按 MapOSError 归一常见 OS 哨兵。

func WrapWinACLError

func WrapWinACLError(sentinel, cause, errInsecure error, path string) error

WrapWinACLError 按调用方指定哨兵与默认权限哨兵包装 Windows DACL 解析或评估失败错误。

func WriteAndSyncClose

func WriteAndSyncClose(w SyncCloseWriter, frame []byte) error

WriteAndSyncClose 向流写入完整帧、执行 Sync 与 Close 并归一化返回错误。

func WriteBorrowed

func WriteBorrowed(w io.Writer, p []byte, active *atomic.Bool) (int, error)

WriteBorrowed 在作用域活性哨兵保护下执行受借用写入。

func WriteChunkSyncClose

func WriteChunkSyncClose(f SyncCloseWriteSeeker, offset int64, r io.Reader, length int64) (int64, error)

WriteChunkSyncClose 执行定长分片写入、Sync 刷盘与关闭,并优先返回写入故障或合并的刷盘/关闭错误。

func WriteScopedFile added in v1.4.0

func WriteScopedFile(
	root RootOps,
	f SyncCloseWriter,
	writeDest, renameTarget pathalg.LocalRootedDest,
	syncParent func(pathalg.LocalRootedDest) error,
	fn func(w io.Writer) error,
) error

WriteScopedFile 在同步作用域内借出写入流,落盘并刷盘后按需原子重命名并同步父目录,未提交时自动回滚清理。

func Zero

func Zero[T any]() (z T)

Zero 返回类型 T 的零值。

Types

type BorrowedReader

type BorrowedReader struct {
	// contains filtered or unexported fields
}

BorrowedReader 在同步作用域关闭后拒绝一切读取,并对顺序读与随机读施加溢出安全字节上限。

func NewBorrowedReader

func NewBorrowedReader(r ports.BoundedReadHandle, maxBytes int64, limited bool, active *atomic.Bool) *BorrowedReader

NewBorrowedReader 构造绑定活性哨兵与可选字节上限的借用只读句柄包装器。

func (*BorrowedReader) Read

func (b *BorrowedReader) Read(p []byte) (int, error)

Read 执行有界顺序读;接收者为空或作用域失效时严格返回 ports.ErrHandleExpired。

func (*BorrowedReader) ReadAt

func (b *BorrowedReader) ReadAt(p []byte, off int64) (int, error)

ReadAt 在不修改顺序读游标的前提下执行并发安全随机偏移读,并强制执行句柄失效哨兵与 ReadLimits 上限。

type BorrowedWriter

type BorrowedWriter struct {
	// contains filtered or unexported fields
}

BorrowedWriter 在同步作用域关闭后拒绝一切写入。

func NewBorrowedWriter

func NewBorrowedWriter(w io.Writer, active *atomic.Bool) *BorrowedWriter

NewBorrowedWriter 构造绑定活性哨兵的借用写入句柄包装器。

func (*BorrowedWriter) Write

func (b *BorrowedWriter) Write(p []byte) (int, error)

Write 执行受控写入;接收者为空或作用域失效时严格返回 ports.ErrHandleExpired。

type ControlSocketPath added in v1.4.0

type ControlSocketPath struct {
	// contains filtered or unexported fields
}

ControlSocketPath 表示经平台安全规则与 sun_path 上限校验的本地 AF_UNIX 套接字路径。 Unix 允许 OpenSSH ControlPath 含 ':'(如 cm-alice@host:22),Windows 除盘符前缀外严禁 ':'。 父包 osfs 经类型别名 osfs.ControlSocketPath 原样对外导出。

func AssembleControlSocketPath added in v1.4.0

func AssembleControlSocketPath(dir, name, native string) ControlSocketPath

AssembleControlSocketPath 以已通过平台规则校验的 (dir, name, native) 三元组组装有效 ControlSocketPath; 仅供本包 Validate*ControlSocketPath 与父包 osfs 白盒测试使用,生产路径一律经校验入口构造。

func BuildManagedMuxSocketPath added in v1.4.0

func BuildManagedMuxSocketPath(
	dir pathalg.LocalDir,
	percentC string,
	toNativeBase func(pathalg.LocalPathKind, string) (string, error),
	validate func(string) (ControlSocketPath, error),
	errInvalid error,
) (ControlSocketPath, error)

BuildManagedMuxSocketPath 基于经校验的沙箱目录与 OpenSSH %C 40 位小写十六进制摘要构造自管套接字路径。

func ControlSocketPathFromSource added in v1.4.0

func ControlSocketPathFromSource(
	src pathalg.LocalSourcePath,
	toNativeBase func(pathalg.LocalPathKind, string) (string, error),
	validate func(string) (ControlSocketPath, error),
	errInvalid error,
) (ControlSocketPath, error)

ControlSocketPathFromSource 将经 pathalg 校验的本地源路径转换为当前平台安全控制套接字路径; 平台原生路径转换与最终平台规则校验分别由 toNativeBase 与 validate 注入。

func ValidateUnixControlSocketPath added in v1.4.0

func ValidateUnixControlSocketPath(raw string, maxBytes int, errInvalid, errTooLong error) (ControlSocketPath, error)

ValidateUnixControlSocketPath 按 Unix 规则校验套接字路径:允许文件名含 ':',拒绝 '..'、尾随分隔符/'.' 与超长 sun_path。

func ValidateWindowsControlSocketPath added in v1.4.0

func ValidateWindowsControlSocketPath(raw string, maxBytes int, errInvalid, errTooLong error) (ControlSocketPath, error)

ValidateWindowsControlSocketPath 按 Windows/NTFS 规则严格校验套接字路径:除盘符前缀外严禁 ':'、前导分隔符与尾随分隔符/'.'。

func (ControlSocketPath) Dir added in v1.4.0

func (p ControlSocketPath) Dir() string

func (ControlSocketPath) Equal added in v1.4.0

func (ControlSocketPath) IsValid added in v1.4.0

func (p ControlSocketPath) IsValid() bool

ControlSocketPath 只读访问器:无效路径(含零值)一律返回空串,Equal 仅在双方均有效时按原生路径判等。

func (ControlSocketPath) IsZero added in v1.4.0

func (p ControlSocketPath) IsZero() bool

func (ControlSocketPath) Name added in v1.4.0

func (p ControlSocketPath) Name() string

func (ControlSocketPath) NativePath added in v1.4.0

func (p ControlSocketPath) NativePath() string

func (ControlSocketPath) String added in v1.4.0

func (p ControlSocketPath) String() string

type ErrMapPair

type ErrMapPair struct {
	Src error
	Out error
}

ErrMapPair 将底层系统错误映射至目标 ports 哨兵错误。

type LockedFile

type LockedFile struct {
	// contains filtered or unexported fields
}

LockedFile 为同步作用域内借出的持锁文件句柄实现 ports.LockedFile,并在作用域结束后拒绝一切读写。

func NewLockedFile

func NewLockedFile(f SyncTruncateStatFile, name string, active *atomic.Bool) *LockedFile

NewLockedFile 构造绑定活性哨兵的持锁文件句柄适配器。

func (*LockedFile) Read

func (l *LockedFile) Read(p []byte) (int, error)

func (*LockedFile) Seek

func (l *LockedFile) Seek(off int64, w int) (int64, error)

func (*LockedFile) Stat

func (l *LockedFile) Stat() (ports.LocalFileInfo, error)

func (*LockedFile) Sync

func (l *LockedFile) Sync() error

func (*LockedFile) Truncate

func (l *LockedFile) Truncate(size int64) error

func (*LockedFile) Write

func (l *LockedFile) Write(p []byte) (int, error)

type LockedFileFunc

type LockedFileFunc func(f ports.LockedFile) error

LockedFileFunc / WriteFileFunc 定义旁路锁与原子替换辅助函数的借用回调契约。

type ParsedWindowsACE added in v1.4.0

type ParsedWindowsACE struct {
	ACEType, ACEFlags    uint8
	Mask                 uint32
	SIDValid, SIDTrusted bool
}

ParsedWindowsACE 表示从 Windows DACL 解码出的单条 ACE 纯数学视图。

type PeerCred added in v1.4.0

type PeerCred struct {
	// contains filtered or unexported fields
}

PeerCred 表示经内核查询到的本地 AF_UNIX 连接对端身份凭据快照;零值恒无效。

func NewPeerCred added in v1.4.0

func NewPeerCred(uid, gid, pid uint32, hasUID, hasGID, hasPID bool) PeerCred

NewPeerCred 以内核套接字选项查询成功后的原始字段构造有效(valid=true)对端凭据快照,供父包 osfs 平台实现调用。

func (PeerCred) Equal added in v1.4.0

func (c PeerCred) Equal(o PeerCred) bool

func (PeerCred) GID added in v1.4.0

func (c PeerCred) GID() (uint32, bool)

func (PeerCred) HasGID added in v1.4.0

func (c PeerCred) HasGID() bool

func (PeerCred) HasPID added in v1.4.0

func (c PeerCred) HasPID() bool

func (PeerCred) HasUID added in v1.4.0

func (c PeerCred) HasUID() bool

func (PeerCred) IsValid added in v1.4.0

func (c PeerCred) IsValid() bool

func (PeerCred) IsZero added in v1.4.0

func (c PeerCred) IsZero() bool

func (PeerCred) PID added in v1.4.0

func (c PeerCred) PID() (uint32, bool)

func (PeerCred) UID added in v1.4.0

func (c PeerCred) UID() (uint32, bool)

type PhysicalNodeProbe

type PhysicalNodeProbe struct {
	Exists     bool
	IsLink     bool
	LinkTarget string // 仅 IsLink == true 时有效
	Canonical  string // 仅 Exists && !IsLink 时可选返回平台规范路径(如 macOS firmlink / Windows GetFinalPathNameByHandle)
}

PhysicalNodeProbe 描述单次无跟随路径节点探测的纯数据结论(供跨平台物理路径展开算法消费)。

type PhysicalPathOps

type PhysicalPathOps struct {
	IsWindows bool
	Probe     func(candidate string) (PhysicalNodeProbe, error)
}

PhysicalPathOps 封装物理路径解析算法所需的平台特性开关与无跟随探测回调(0 os、0 filepath 依赖)。

type RootOps added in v1.4.0

type RootOps interface {
	Lstat(name string) (fs.FileInfo, error)
	Stat(name string) (fs.FileInfo, error)
	Rename(oldname, newname string) error
	Remove(name string) error
	Symlink(oldname, newname string) error
	Chtimes(name string, atime, mtime time.Time) error
}

RootOps 抽象 *os.Root 的无 os 类型元数据与变更子集,使沙箱根内通用编排逻辑保持在零特权辅助层。

type SocketPeerPolicy added in v1.4.0

type SocketPeerPolicy uint8

SocketPeerPolicy 声明本地 AF_UNIX 套接字监听器的跨用户对端接入策略。 零值 SocketPeerPolicyUnset 强制归一为最严 SocketPeerOwnerOnly(同 UID/同 SID,INV-A3)。

const (
	// SocketPeerPolicyUnset 为零值默认策略,强制归一为最严 SocketPeerOwnerOnly(INV-A3)。
	SocketPeerPolicyUnset SocketPeerPolicy = SocketPeerPolicy(SocketPeerPolicyUnsetCode)
	// SocketPeerOwnerOnly 强制每次 Accept 执行内核级同 UID(Unix)或同 SID(Windows)对端校验,
	// 且要求套接字文件权限禁止任何非属主位(filePerm & 0o077 == 0)。
	SocketPeerOwnerOnly SocketPeerPolicy = SocketPeerPolicy(SocketPeerOwnerOnlyCode)
	// SocketPeerFilesystemPerm 显式授权在 Unix StreamLocal 本地转发放宽掩码时委托内核 VFS 文件权限裁决;
	// ControlMaster 管理面与 SocketSlot.AcceptVerified 严禁受其影响,Windows 平台恒拒绝本策略。
	SocketPeerFilesystemPerm SocketPeerPolicy = SocketPeerPolicy(SocketPeerFilesystemPermCode)
)

func SocketPeerPolicyFromCode added in v1.4.0

func SocketPeerPolicyFromCode(code uint8) SocketPeerPolicy

SocketPeerPolicyFromCode 将 ResolveSocketSlotConfig 归一后的有效策略底层码提升为强类型策略。

func (SocketPeerPolicy) Effective added in v1.4.0

func (p SocketPeerPolicy) Effective() SocketPeerPolicy

Effective 返回归一后的有效对端策略:零值与未知非法值一律 fail-closed 收敛为 SocketPeerOwnerOnly。

func (SocketPeerPolicy) IsValid added in v1.4.0

func (p SocketPeerPolicy) IsValid() bool

IsValid 报告 p 是否为已登记的合法策略值(含零值 SocketPeerPolicyUnset)。

func (SocketPeerPolicy) String added in v1.4.0

func (p SocketPeerPolicy) String() string

String 返回 SocketPeerPolicy 的规范小写名称。

type SocketProbeStatus added in v1.4.0

type SocketProbeStatus uint8

SocketProbeStatus 描述 ProbeStaleUnixSocket 的探活分类结果;零值 SocketProbeUnknown 严格失败关闭。

const (
	SocketProbeUnknown   SocketProbeStatus = SocketProbeStatus(SocketProbeUnknownCode)   // 探测未完成或异常(零值失败关闭)
	SocketProbeMissing   SocketProbeStatus = SocketProbeStatus(SocketProbeMissingCode)   // 目标路径不存在
	SocketProbeNotSocket SocketProbeStatus = SocketProbeStatus(SocketProbeNotSocketCode) // 存在但非本地 AF_UNIX 套接字
	SocketProbeLive      SocketProbeStatus = SocketProbeStatus(SocketProbeLiveCode)      // 存在且活跃监听进程响应连接
	SocketProbeStale     SocketProbeStatus = SocketProbeStatus(SocketProbeStaleCode)     // 确认为套接字且连接被明确拒绝(可安全清理)
)

func SocketProbeStatusFromCode added in v1.4.0

func SocketProbeStatusFromCode(code uint8) SocketProbeStatus

SocketProbeStatusFromCode 将本包探活流程(ProbeSocketState / PruneStaleSocketState)返回的底层码提升为强类型状态。

func (SocketProbeStatus) IsValid added in v1.4.0

func (s SocketProbeStatus) IsValid() bool

IsValid 报告 s 是否为已判明的有效探测状态(零值 SocketProbeUnknown 返回 false)。

func (SocketProbeStatus) String added in v1.4.0

func (s SocketProbeStatus) String() string

String 返回 SocketProbeStatus 的可读名称。

type SocketSlotOptions added in v1.4.0

type SocketSlotOptions struct {
	ReplaceStale bool                               // 在目录锁内确证为 SocketProbeStale 后允许清理接管
	FilePerm     fs.FileMode                        // 可选 Unix 套接字权限位(零值默认 0o600;仅允许低 9 位 <= 0o777,拒绝特殊模式位;非属主位须显式配 SocketPeerFilesystemPerm)
	PeerPolicy   SocketPeerPolicy                   // 本地对端身份校验策略(零值 SocketPeerPolicyUnset 归一为 SocketPeerOwnerOnly)
	ConfineRoot  algebraic.Option[pathalg.LocalDir] // 可选:内核级防软链逃逸沙箱根目录(ADR-019 v2.2 S3-Q4b,非空须为非根绝对目录)
}

SocketSlotOptions 控制 WithSocketSlot 绑定本地 AF_UNIX 套接字时的冲突处置、权限位、对端接入策略与可选内核沙箱根。 零值最严:ReplaceStale=false、FilePerm 归一为 0o600、PeerPolicy 归一为 SocketPeerOwnerOnly(INV-A3)。

func DefaultSocketSlotOptions added in v1.4.0

func DefaultSocketSlotOptions() SocketSlotOptions

DefaultSocketSlotOptions 返回最严默认本地套接字槽位选项(0o600 + SocketPeerOwnerOnly + ReplaceStale=false)。

func (SocketSlotOptions) EffectiveFilePerm added in v1.4.0

func (o SocketSlotOptions) EffectiveFilePerm() fs.FileMode

EffectiveFilePerm 返回归一后的有效套接字权限位(零值返回 0o600,含非法特殊权限位返回 0)。

func (SocketSlotOptions) EffectivePeerPolicy added in v1.4.0

func (o SocketSlotOptions) EffectivePeerPolicy() SocketPeerPolicy

EffectivePeerPolicy 返回归一后的有效对端接入策略(零值与未知值一律 fail-closed 收敛为 SocketPeerOwnerOnly)。

type StatReadCloser added in v1.4.0

type StatReadCloser interface {
	io.Reader
	io.ReaderAt
	io.Closer
	Stat() (fs.FileInfo, error)
}

StatReadCloser 抽象支持 Stat 与随机只读的已打开文件句柄(*os.File 原生满足)。

type SyncCloseWriteSeeker

type SyncCloseWriteSeeker interface {
	io.WriteSeeker
	Sync() error
	Close() error
}

SyncCloseWriteSeeker 抽象支持定位写入、刷盘与关闭的分片写入文件流。

type SyncCloseWriter

type SyncCloseWriter interface {
	io.Writer
	Sync() error
	Close() error
}

SyncCloseWriter 抽象支持写入、刷盘与关闭的文件流。

type SyncTruncateStatFile

type SyncTruncateStatFile interface {
	io.ReadWriteSeeker
	Sync() error
	Truncate(size int64) error
	Stat() (fs.FileInfo, error)
}

SyncTruncateStatFile 抽象底层持锁文件所需的最小接口,使 LockedFile 适配器与具体 *os.File 解耦。

type WindowsACLInput added in v1.4.0

type WindowsACLInput struct {
	Mode                                           WindowsACLMode
	Attrs                                          uint32
	ExpectDir, AllowReparse, OwnerTrusted, HasDACL bool
	ACEs                                           []ParsedWindowsACE
}

WindowsACLInput 封装待评估 Windows 对象的属性与解析后 DACL 信息。

type WindowsACLMode added in v1.4.0

type WindowsACLMode uint8

WindowsACLMode 区分 Windows DACL 安全评估策略;零值 WindowsACLInvalid 严格失败关闭。 父包 osfs 经类型别名 osfs.WindowsACLMode 原样对外导出。

const (
	WindowsACLInvalid         WindowsACLMode = WindowsACLMode(ACLModeInvalid)         // 无效评估模式(零值失败关闭)
	WindowsACLOwnerOnly       WindowsACLMode = WindowsACLMode(ACLModeOwnerOnly)       // 仅受信任所有者/系统主体可访问
	WindowsACLWriteRestricted WindowsACLMode = WindowsACLMode(ACLModeWriteRestricted) // 严禁非受信任主体具备写/删/改权位
	WindowsACLPipeServerSafe  WindowsACLMode = WindowsACLMode(ACLModePipeServerSafe)  // 命名管道服务端:阻断非受信任主体抢注实例/改权限,放行合法双工 FILE_WRITE_DATA
)

type WriteFileFunc

type WriteFileFunc func(w io.Writer) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL