Module: fs.perm

Source: ./fs/perm.reef


Overview

fs/perm - File permission operations

Provides chmod, chown, permission testing, and POSIX permission constants.

is_executable uses libc access(X_OK) (an authz hint — e.g. root may succeed even when no execute bits are set). has_execute_bit inspects the file mode for any of S_IXUSR|S_IXGRP|S_IXOTH ("marked executable").

Permission modification and the set_executable/set_readonly convenience helpers return Result[bool, error.Error]: Ok(true) on success (the void-success convention — never Ok(false)), Err(NotFound) when the path does not exist, Err(PermissionDenied) for any other chmod/chown/lchown failure (the dominant real-world cause once existence is ruled out). set_executable/set_readonly compose fs.stat.file_mode's Result to read the current mode, propagating its Err unchanged on failure.


Functions

fn chmod(path: string, mode: int): result.Result[bool, error.Error]

Changes path's permission bits to mode. Ok(true) on success (the void-success convention). Err(NotFound) if path doesn't exist, Err(PermissionDenied) for any other failure.

fn chown(path: string, uid: int, gid: int): result.Result[bool, error.Error]

Changes path's owning uid/gid (following symlinks). Ok(true) on success. Err(NotFound) if path doesn't exist, Err(PermissionDenied) for any other failure (commonly EPERM — chown requires privilege).

fn lchown(path: string, uid: int, gid: int): result.Result[bool, error.Error]

Changes path's owning uid/gid without following symlinks. Same Ok/Err contract as chown.

fn set_executable(path: string): result.Result[bool, error.Error]

Add execute permission for user, group, and other Sets mode to current | 0111 (user+group+other execute)

Composes fs.stat.file_mode's Result to read the current mode: its Err (NotFound/IoError) is propagated unchanged; on Ok, chmod's own Result (NotFound/PermissionDenied) is returned. Ok(true) on success.

fn set_readonly(path: string): result.Result[bool, error.Error]

Remove write permission for user, group, and other Sets mode to current & ~0222

Same composition contract as set_executable: propagates fs.stat.file_mode's Err unchanged, otherwise returns chmod's Result.

fn is_readable(path: string): bool

fn is_writable(path: string): bool

fn is_executable(path: string): bool

True when access(path, X_OK) succeeds. Authz hint only: root (and some other privileged callers) may get true even when no execute bits are set. Prefer has_execute_bit when the policy is "file is marked executable".

fn has_execute_bit(path: string): bool

True iff path's mode has any of S_IXUSR|S_IXGRP|S_IXOTH. Returns false when the path cannot be statted. Does not call access(X_OK).

fn S_IRUSR(): int

fn S_IWUSR(): int

fn S_IXUSR(): int

fn S_IRGRP(): int

fn S_IWGRP(): int

fn S_IXGRP(): int

fn S_IROTH(): int

fn S_IWOTH(): int

fn S_IXOTH(): int

fn S_ISUID(): int

fn S_ISGID(): int

fn S_ISVTX(): int


Generated by reefc doc