Documentation
¶
Overview ¶
Package filemode contains helpers when you need to work with file modes.
Index ¶
Constants ¶
const ( UserR = read << shiftUser UserW = write << shiftUser UserX = execute << shiftUser UserRW = UserR | UserW UserRWX = UserRW | UserX GroupR = read << shiftGroup GroupW = write << shiftGroup GroupX = execute << shiftGroup GroupRW = GroupR | GroupW GroupRWX = GroupRW | GroupX OtherR = read << shiftOther OtherW = write << shiftOther OtherX = execute << shiftOther OtherRW = OtherR | OtherW OtherRWX = OtherRW | OtherX AllR = UserR | GroupR | OtherR AllW = UserW | GroupW | OtherW AllX = UserX | GroupX | OtherX AllRW = AllR | AllW AllRWX = AllRW | AllX )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Octal ¶
Octal represents Unix file permissions in octal (base-8) notation.
Octal notation is the numeric representation of POSIX file permissions, where each digit (0-7) represents a combination of read (4), write (2), and execute (1) permissions for user, group, and other respectively.
Format:
- 3-digit format: Standard permissions (e.g., 755, 644, 777)
- 4-digit format: Special bits + standard permissions (e.g., 4755, 2644, 1777)
Standard 3-digit format:
- 2 to left digit: User/owner permissions
- 1 to left digit: Group permissions
- 0 to left digit: Other/world permissions
Each digit is calculated by summing the permission values:
- Read (r): 4
- Write (w): 2
- Execute (x): 1
Permission value table:
0 (000): --- (no permissions) 1 (001): --x (execute only) 2 (010): -w- (write only) 3 (011): -wx (write + execute) 4 (100): r-- (read only) 5 (101): r-x (read + execute) 6 (110): rw- (read + write) 7 (111): rwx (read + write + execute)
Examples:
755 = -rwxr-xr-x (user: rwx, group: r-x, other: r-x) 644 = -rw-r--r-- (user: rw-, group: r--, other: r--) 777 = -rwxrwxrwx (user: rwx, group: rwx, other: rwx) 600 = -rw------- (user: rw-, group: ---, other: ---)
Special permission bits (4-digit format):
- First digit represents special bits: 4000: setuid bit (s in user execute position) 2000: setgid bit (s in group execute position) 1000: sticky bit (t in other execute position)
Examples with special bits:
4755 = rwsr-xr-x (setuid + rwxr-xr-x) 2755 = rwxr-sr-x (setgid + rwxr-xr-x) 1777 = rwxrwxrwt (sticky + rwxrwxrwx)
Conversion from os.FileMode:
mode.Perm() returns the permission bits as os.FileMode Use Octal(mode.Perm()) to convert to octal representation
Standards:
- Defined by POSIX.1 standard
- Supported by chmod, stat, and umask commands
- Compatible with all Unix-like systems (Linux, macOS, BSD)
func (Octal) Group ¶
func (o Octal) Group() Permission
func (Octal) Other ¶
func (o Octal) Other() Permission
func (Octal) SymbolicNotation ¶
SymbolicNotation returns a POSIX compliant symbolic notation for a given file mode.
func (Octal) User ¶
func (o Octal) User() Permission
type Permission ¶
func (Permission) Contains ¶
func (p Permission) Contains(o Permission) bool
func (Permission) IsZero ¶
func (p Permission) IsZero() bool
func (Permission) Octal ¶
func (p Permission) Octal() Octal