freax

package
v0.0.0-...-ce320d0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package freax provides operating system functions for Linux.

Index

Constants

View Source
const (
	// Exactly one of O_RDONLY, O_WRONLY, or O_RDWR must be specified.
	O_RDONLY = unix.O_RDONLY // open the file read-only.
	O_WRONLY = unix.O_WRONLY // open the file write-only.
	O_RDWR   = unix.O_RDWR   // open the file read-write.
	// The remaining values may be or'ed in to control behavior.
	O_APPEND = unix.O_APPEND // append data to the file when writing.
	O_CREATE = unix.O_CREAT  // create a new file if none exists.
	O_EXCL   = unix.O_EXCL   // used with O_CREATE, file must not exist.
	O_SYNC   = unix.O_SYNC   // open for synchronous I/O.
	O_TRUNC  = unix.O_TRUNC  // truncate regular writable file when opened.
)

Flags to OpenFile wrapping those of the underlying system. Not all flags may be implemented on a given system.

View Source
const (
	SEEK_SET = unix.SEEK_SET // seek relative to the origin of the file
	SEEK_CUR = unix.SEEK_CUR // seek relative to the current offset
	SEEK_END = unix.SEEK_END // seek relative to the end
)

Seek whence values.

View Source
const (
	PasswdFile = "/etc/passwd"
)

Variables

View Source
var (
	EPERM           = &Errno{"EPERM", 1, "Operation not permitted"}
	ENOENT          = &Errno{"ENOENT", 2, "No such file or directory"}
	ESRCH           = &Errno{"ESRCH", 3, "No such process"}
	EINTR           = &Errno{"EINTR", 4, "Interrupted system call"}
	EIO             = &Errno{"EIO", 5, "I/O error"}
	ENXIO           = &Errno{"ENXIO", 6, "No such device or address"}
	E2BIG           = &Errno{"E2BIG", 7, "Argument list too long"}
	ENOEXEC         = &Errno{"ENOEXEC", 8, "Exec format error"}
	EBADF           = &Errno{"EBADF", 9, "Bad file number"}
	ECHILD          = &Errno{"ECHILD", 10, "No child processes"}
	EAGAIN          = &Errno{"EAGAIN", 11, "Try again"}
	ENOMEM          = &Errno{"ENOMEM", 12, "Out of memory"}
	EACCES          = &Errno{"EACCES", 13, "Permission denied"}
	EFAULT          = &Errno{"EFAULT", 14, "Bad address"}
	ENOTBLK         = &Errno{"ENOTBLK", 15, "Block device required"}
	EBUSY           = &Errno{"EBUSY", 16, "Device or resource busy"}
	EEXIST          = &Errno{"EEXIST", 17, "File exists"}
	EXDEV           = &Errno{"EXDEV", 18, "Cross-device link"}
	ENODEV          = &Errno{"ENODEV", 19, "No such device"}
	ENOTDIR         = &Errno{"ENOTDIR", 20, "Not a directory"}
	EISDIR          = &Errno{"EISDIR", 21, "Is a directory"}
	EINVAL          = &Errno{"EINVAL", 22, "Invalid argument"}
	ENFILE          = &Errno{"ENFILE", 23, "File table overflow"}
	EMFILE          = &Errno{"EMFILE", 24, "Too many open files"}
	ENOTTY          = &Errno{"ENOTTY", 25, "Not a typewriter"}
	ETXTBSY         = &Errno{"ETXTBSY", 26, "Text file busy"}
	EFBIG           = &Errno{"EFBIG", 27, "File too large"}
	ENOSPC          = &Errno{"ENOSPC", 28, "No space left on device"}
	ESPIPE          = &Errno{"ESPIPE", 29, "Illegal seek"}
	EROFS           = &Errno{"EROFS", 30, "Read-only file system"}
	EMLINK          = &Errno{"EMLINK", 31, "Too many links"}
	EPIPE           = &Errno{"EPIPE", 32, "Broken pipe"}
	EDOM            = &Errno{"EDOM", 33, "Math argument out of domain of func"}
	ERANGE          = &Errno{"ERANGE", 34, "Math result not representable"}
	EDEADLK         = &Errno{"EDEADLK", 35, "Resource deadlock would occur"}
	ENAMETOOLONG    = &Errno{"ENAMETOOLONG", 36, "File name too long"}
	ENOLCK          = &Errno{"ENOLCK", 37, "No record locks available"}
	ENOSYS          = &Errno{"ENOSYS", 38, "Invalid system call number"}
	ENOTEMPTY       = &Errno{"ENOTEMPTY", 39, "Directory not empty"}
	ELOOP           = &Errno{"ELOOP", 40, "Too many symbolic links encountered"}
	ENOMSG          = &Errno{"ENOMSG", 42, "No message of desired type"}
	EIDRM           = &Errno{"EIDRM", 43, "Identifier removed"}
	ECHRNG          = &Errno{"ECHRNG", 44, "Channel number out of range"}
	EL2NSYNC        = &Errno{"EL2NSYNC", 45, "Level 2 not synchronized"}
	EL3HLT          = &Errno{"EL3HLT", 46, "Level 3 halted"}
	EL3RST          = &Errno{"EL3RST", 47, "Level 3 reset"}
	ELNRNG          = &Errno{"ELNRNG", 48, "Link number out of range"}
	EUNATCH         = &Errno{"EUNATCH", 49, "Protocol driver not attached"}
	ENOCSI          = &Errno{"ENOCSI", 50, "No CSI structure available"}
	EL2HLT          = &Errno{"EL2HLT", 51, "Level 2 halted"}
	EBADE           = &Errno{"EBADE", 52, "Invalid exchange"}
	EBADR           = &Errno{"EBADR", 53, "Invalid request descriptor"}
	EXFULL          = &Errno{"EXFULL", 54, "Exchange full"}
	ENOANO          = &Errno{"ENOANO", 55, "No anode"}
	EBADRQC         = &Errno{"EBADRQC", 56, "Invalid request code"}
	EBADSLT         = &Errno{"EBADSLT", 57, "Invalid slot"}
	EBFONT          = &Errno{"EBFONT", 59, "Bad font file format"}
	ENOSTR          = &Errno{"ENOSTR", 60, "Device not a stream"}
	ENODATA         = &Errno{"ENODATA", 61, "No data available"}
	ETIME           = &Errno{"ETIME", 62, "Timer expired"}
	ENOSR           = &Errno{"ENOSR", 63, "Out of streams resources"}
	ENONET          = &Errno{"ENONET", 64, "Machine is not on the network"}
	ENOPKG          = &Errno{"ENOPKG", 65, "Package not installed"}
	EREMOTE         = &Errno{"EREMOTE", 66, "Object is remote"}
	ENOLINK         = &Errno{"ENOLINK", 67, "Link has been severed"}
	EADV            = &Errno{"EADV", 68, "Advertise error"}
	ESRMNT          = &Errno{"ESRMNT", 69, "Srmount error"}
	ECOMM           = &Errno{"ECOMM", 70, "Communication error on send"}
	EPROTO          = &Errno{"EPROTO", 71, "Protocol error"}
	EMULTIHOP       = &Errno{"EMULTIHOP", 72, "Multihop attempted"}
	EDOTDOT         = &Errno{"EDOTDOT", 73, "RFS specific error"}
	EBADMSG         = &Errno{"EBADMSG", 74, "Not a data message"}
	EOVERFLOW       = &Errno{"EOVERFLOW", 75, "Value too large for defined data type"}
	ENOTUNIQ        = &Errno{"ENOTUNIQ", 76, "Name not unique on network"}
	EBADFD          = &Errno{"EBADFD", 77, "File descriptor in bad state"}
	EREMCHG         = &Errno{"EREMCHG", 78, "Remote address changed"}
	ELIBACC         = &Errno{"ELIBACC", 79, "Can not access a needed shared library"}
	ELIBBAD         = &Errno{"ELIBBAD", 80, "Accessing a corrupted shared library"}
	ELIBSCN         = &Errno{"ELIBSCN", 81, ".lib section in a.out corrupted"}
	ELIBMAX         = &Errno{"ELIBMAX", 82, "Attempting to link in too many shared libraries"}
	ELIBEXEC        = &Errno{"ELIBEXEC", 83, "Cannot exec a shared library directly"}
	EILSEQ          = &Errno{"EILSEQ", 84, "Illegal byte sequence"}
	ERESTART        = &Errno{"ERESTART", 85, "Interrupted system call should be restarted"}
	ESTRPIPE        = &Errno{"ESTRPIPE", 86, "Streams pipe error"}
	EUSERS          = &Errno{"EUSERS", 87, "Too many users"}
	ENOTSOCK        = &Errno{"ENOTSOCK", 88, "Socket operation on non-socket"}
	EDESTADDRREQ    = &Errno{"EDESTADDRREQ", 89, "Destination address required"}
	EMSGSIZE        = &Errno{"EMSGSIZE", 90, "Message too long"}
	EPROTOTYPE      = &Errno{"EPROTOTYPE", 91, "Protocol wrong type for socket"}
	ENOPROTOOPT     = &Errno{"ENOPROTOOPT", 92, "Protocol not available"}
	EPROTONOSUPPORT = &Errno{"EPROTONOSUPPORT", 93, "Protocol not supported"}
	ESOCKTNOSUPPORT = &Errno{"ESOCKTNOSUPPORT", 94, "Socket type not supported"}
	EOPNOTSUPP      = &Errno{"EOPNOTSUPP", 95, "Operation not supported on transport endpoint"}
	EPFNOSUPPORT    = &Errno{"EPFNOSUPPORT", 96, "Protocol family not supported"}
	EAFNOSUPPORT    = &Errno{"EAFNOSUPPORT", 97, "Address family not supported by protocol"}
	EADDRINUSE      = &Errno{"EADDRINUSE", 98, "Address already in use"}
	EADDRNOTAVAIL   = &Errno{"EADDRNOTAVAIL", 99, "Cannot assign requested address"}
	ENETDOWN        = &Errno{"ENETDOWN", 100, "Network is down"}
	ENETUNREACH     = &Errno{"ENETUNREACH", 101, "Network is unreachable"}
	ENETRESET       = &Errno{"ENETRESET", 102, "Network dropped connection because of reset"}
	ECONNABORTED    = &Errno{"ECONNABORTED", 103, "Software caused connection abort"}
	ECONNRESET      = &Errno{"ECONNRESET", 104, "Connection reset by peer"}
	ENOBUFS         = &Errno{"ENOBUFS", 105, "No buffer space available"}
	EISCONN         = &Errno{"EISCONN", 106, "Transport endpoint is already connected"}
	ENOTCONN        = &Errno{"ENOTCONN", 107, "Transport endpoint is not connected"}
	ESHUTDOWN       = &Errno{"ESHUTDOWN", 108, "Cannot send after transport endpoint shutdown"}
	ETOOMANYREFS    = &Errno{"ETOOMANYREFS", 109, "Too many references: cannot splice"}
	ETIMEDOUT       = &Errno{"ETIMEDOUT", 110, "Connection timed out"}
	ECONNREFUSED    = &Errno{"ECONNREFUSED", 111, "Connection refused"}
	EHOSTDOWN       = &Errno{"EHOSTDOWN", 112, "Host is down"}
	EHOSTUNREACH    = &Errno{"EHOSTUNREACH", 113, "No route to host"}
	EALREADY        = &Errno{"EALREADY", 114, "Operation already in progress"}
	EINPROGRESS     = &Errno{"EINPROGRESS", 115, "Operation now in progress"}
	ESTALE          = &Errno{"ESTALE", 116, "Stale file handle"}
	EUCLEAN         = &Errno{"EUCLEAN", 117, "Structure needs cleaning"}
	ENOTNAM         = &Errno{"ENOTNAM", 118, "Not a XENIX named type file"}
	ENAVAIL         = &Errno{"ENAVAIL", 119, "No XENIX semaphores available"}
	EISNAM          = &Errno{"EISNAM", 120, "Is a named type file"}
	EREMOTEIO       = &Errno{"EREMOTEIO", 121, "Remote I/O error"}
	EDQUOT          = &Errno{"EDQUOT", 122, "Quota exceeded"}
	ENOMEDIUM       = &Errno{"ENOMEDIUM", 123, "No medium found"}
	EMEDIUMTYPE     = &Errno{"EMEDIUMTYPE", 124, "Wrong medium type"}
	ECANCELED       = &Errno{"ECANCELED", 125, "Operation Canceled"}
	ENOKEY          = &Errno{"ENOKEY", 126, "Required key not available"}
	EKEYEXPIRED     = &Errno{"EKEYEXPIRED", 127, "Key has expired"}
	EKEYREVOKED     = &Errno{"EKEYREVOKED", 128, "Key has been revoked"}
	EKEYREJECTED    = &Errno{"EKEYREJECTED", 129, "Key was rejected by service"}
	EOWNERDEAD      = &Errno{"EOWNERDEAD", 130, "Owner died"}
	ENOTRECOVERABLE = &Errno{"ENOTRECOVERABLE", 131, "State not recoverable"}
	ERFKILL         = &Errno{"ERFKILL", 132, "Operation not possible due to RF-kill"}
	EHWPOISON       = &Errno{"EHWPOISON", 133, "Memory page has hardware error"}

	EDEADLOCK   = &Errno{"EDEADLOCK", 35, "Resource deadlock would occur"} //	EDEADLK
	EWOULDBLOCK = &Errno{"EWOULDBLOCK", 11, "Operation would block"}       // EAGAIN
)
View Source
var (
	F_RDLCK int16 = unix.F_RDLCK // Place a read lock on a file with FcntlFlock
	F_WRLCK int16 = unix.F_WRLCK // Place a write lock on a file with FcntlFlock
	F_UNLCK int16 = unix.F_UNLCK // Release the lock on a file with FcntlFlock
)
View Source
var (
	F_SETLK  = unix.F_SETLK  // Acquire or release a lock
	F_SETLKW = unix.F_SETLKW // As for F_SETLK, but if a conflicting lock is held on the file, then wait for that lock to be released
	F_GETLK  = unix.F_GETLK  // Return details about the current lock
)
View Source
var (
	ErrEmpty      = errors.New("empty")
	ErrInvalidPid = errors.New("invalid pid")
)
View Source
var (
	ErrAssert = errors.New("syscall.Stat_t assertion failed")
)
View Source
var (
	ErrUserNotFound = errors.New("user not found")
)
View Source
var Errnos = []Errno{}/* 133 elements not displayed */

Errno table

View Source
var (
	ShredIterations = 3 // Default iteration number for Shred()
)

Functions

func ErrnoFromSyscallErrno

func ErrnoFromSyscallErrno(err error) error

ErrnoFromSyscallErrno converts a syscall.Errno to *Errno.

If err is not a valid syscall.Errno, returns the err as is. If err is syscall.Errno, but not with a valid number, returns the number as an error string.

func FDRead

func FDRead(fd uintptr, p []byte) (n int, err error)

func FDReadAll

func FDReadAll(fd uintptr) ([]byte, error)

func FcntlCheckfl

func FcntlCheckfl(fd uintptr, flag int) (bool, error)

FcntlCheckfl returns whether the flag is set for fd.

func FcntlGetfl

func FcntlGetfl(fd uintptr) (int, error)

FcntlGetfl returns the file access mode and the file status flags.

func FileContains

func FileContains(path, substr string) (bool, error)

FileContains reports whether substr is in path file. A line in the file does not contains the newline character ("\n"). This function uses bufio.Scanner to able to handle large files.

func FileContainsLine

func FileContainsLine(path, line string) (bool, error)

FileContainsLine reports whether line is in path file. A line in the file does not contains the newline character ("\n"). This function uses bufio.Scanner to able to handle large files.

func FileCountLines

func FileCountLines(path string) (int, error)

FileCountLines returns the number lines in file.

func FileModeIsBlk

func FileModeIsBlk(m FileMode) bool

FileModeIsBlk returns whether the file is a block special file (a device like a disk).

func FileModeIsChr

func FileModeIsChr(m FileMode) bool

FileModeIsChr returns whether the file is a character special file (a device like a terminal).

func FileModeIsFifo

func FileModeIsFifo(m FileMode) bool

FileModeIsFifo returns whether the file is a FIFO special file, or a pipe.

func FileModeIsLnk

func FileModeIsLnk(m FileMode) bool

FileModeIsLnk returns whether the file is a symbolic link.

func FileModeIsReg

func FileModeIsReg(m FileMode) bool

FileModeIsReg returns whether the file is a regular file.

func FileModeIsSet

func FileModeIsSet(mode, m FileMode) bool

FileModeIsSet check whether m bit is set in mode.

func FileModeIsSetPath

func FileModeIsSetPath(path string, m FileMode) (bool, error)

FileModeIsSetPath returns whether mode m of file is set in path. This function does not follow symbolic link.

func FileModeIsSock

func FileModeIsSock(m FileMode) bool

FileModeIsSock returns whether the file is a socket.

func FileModeSetPath

func FileModeSetPath(path string, m FileMode) error

FileModeSetPath sets the mode bit m for file in path.

func FileModeUnsetPath

func FileModeUnsetPath(path string, m FileMode) error

FileModeUnsetPath unsets the mode bit m for file in path.

func FlockGetRead

func FlockGetRead(fd uintptr) (bool, error)

FlockGetRead returns whether read lock (F_RDLCK) could be placed on fd. Every byte will be checked for lock.

func FlockGetWrite

func FlockGetWrite(fd uintptr) (bool, error)

FlockGetRead returns whether write lock (F_WRLCK) could be placed on fd. Every byte will be checked for lock.

func FlockSetRead

func FlockSetRead(fd uintptr) error

FlockSetRead acquire the advisory record lock for read on fd. This function returns error if a conflicting lock is held by another process. In order to place a read lock, fd must be open for reading.

func FlockSetReadWait

func FlockSetReadWait(fd uintptr) error

FlockSetReadWait acquire the advisory record lock for read on fd. If a conflicting lock is held on the file, then wait for that lock to be released. In order to place a read lock, fd must be open for reading.

func FlockSetWrite

func FlockSetWrite(fd uintptr) error

FlockSetWrite acquire the advisory record lock for write on fd. This function returns error if a conflicting lock is held by another process. In order to place a write lock, fd must be open for writing.

func FlockSetWriteWait

func FlockSetWriteWait(fd uintptr) error

FlockSetWriteWait acquire the advisory record lock for write on fd. If a conflicting lock is held on the file, then wait for that lock to be released. In order to place a write lock, fd must be open for writing.

func FlockUnlock

func FlockUnlock(fd uintptr) error

FlockUnlock release the advisory record lock on fd. This function returns error if a conflicting lock is held by another process.

func FlockUnlockWait

func FlockUnlockWait(fd uintptr) error

FlockUnlockWait release the advisory record lock on fd. If a conflicting lock is held on the file, then wait for that lock to be released.

func GetFileGroup deprecated

func GetFileGroup(file string) (*user.Group, error)

GetFileGroup returns the user.Group struct of file. Returns ErrAssert if syscall assertion failed or UnknownGroupIdError if failed to get owner from the GID.

Deprecated: Use Stat(), Fstat() or Lstat() instead.

func GetFileOwner deprecated

func GetFileOwner(file string) (*user.User, error)

GetFileOwner returns the owner user.User struct of file. Returns ErrAssert if syscall assertion failed or UnknownUserIdError if failed to get owner from the UID.

Deprecated: Use Stat(), Fstat() or Lstat() instead.

func IsBlkPath

func IsBlkPath(path string) (bool, error)

IsBlkPath returns whether the file in path is a block special file (a device like a disk).

func IsChrPath

func IsChrPath(path string) (bool, error)

IsChrPath returns whether the file in path is a character special file (a device like a terminal).

func IsDir

func IsDir(m FileMode) bool

FileModeIsDir returns whether the file is a directory.

func IsDirPath

func IsDirPath(path string) (bool, error)

IsDirPath returns whether the file in path is a directory.

func IsFifoPath

func IsFifoPath(path string) (bool, error)

IsFifoPath returns whether the file in path is a FIFO special file, or a pipe.

func IsLnkPath

func IsLnkPath(path string) (bool, error)

IsLnkPath returns whether the file in path is a symbolic link.

func IsPathExists

func IsPathExists(path string) (bool, error)

IsPathExists returns whether path is exists. If path is a symbolic link, it is dereferenced.

func IsRegPath

func IsRegPath(path string) (bool, error)

IsRegPath returns whether the file in path is a regular file.

func IsSockPath

func IsSockPath(path string) (bool, error)

IsSockPath returns whether the file in path is a socket.

func ListDir

func ListDir(name string, recursive bool, hidden bool) ([]string, error)

func ListFiles

func ListFiles(path string) ([]string, error)

func NewErrno

func NewErrno(n int) error

NewErrno returns a new *Errno from code n. If n is not a valid errno, returns n as a string.

This function allocates a new struct.

func PIDCheck

func PIDCheck(path string) (bool, error)

CheckPath returns true if the stored PID in path is running. Remove the newline character ('\n') from the content if exist.

Returns ErrEmpty if lock file is empty. Returns ErrInvalidPid if the content is an invalid (eg.: not a number).

func PIDCreate

func PIDCreate(path string, perm uint32) error

PIDCreate creates the pid file in path with mode perm (before umask). The file in path should not exist.

func PIDRead

func PIDRead(path string) (int, error)

PIDRead returns the stored pid in path. Remove the newline character ('\n') from the content if exist.

Returns -1 if error occurred. Returns ErrEmpty if file is empty. Returns ErrInvalidPid if the content is an invalid (eg.: not a number).

func PIDRemove

func PIDRemove(path string) error

PIDRemove deletes the pid file in path. Simply calls os.Remove(path).

func ReadAll

func ReadAll(name string) ([]byte, error)

func Shred

func Shred(path string, n int, random bool) (int64, error)

Shred overwrites file in path for n times. Writes random data if random is true, else zeroes.

func ShredLock

func ShredLock(path string, n int, random bool) (int64, error)

ShredLock apply a nonblocking write lock with FlockWrite and overwrites file in path for n times. Writes random data if random is true, else zeroes.

This function returns error if other lock is applied on path.

func ShredLockWait

func ShredLockWait(path string, n int, random bool) (int64, error)

ShredLock apply a blocking write lock with FlockWriteWait and overwrites file in path for n times. Writes random data if random is true, else zeroes.

This function blocks until other lock is applied on path.

func Truncate

func Truncate(file *os.File) error

Truncate overwrites the file with shred for ShredIterations times and truncates to 0.

func TruncatePath

func TruncatePath(path string) error

TruncatePath overwrites the file at path with shred for ShredIterations times and truncates to 0.

func Write

func Write(name string, data []byte, perm uint32) error

Write writes data to the file in path. This function truncates the file before writing. If path does not exist, create a new file with permission perm (before umask).

func WriteSync

func WriteSync(name string, data []byte, perm uint32) error

WriteSync writes and syncronise data to the file in path. This function truncates the file before writing. If path does not exist, create a new file with permission perm (before umask).

Types

type Errno

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

TODO

func (*Errno) Error

func (e *Errno) Error() string

func (*Errno) Is

func (e *Errno) Is(err error) bool

type File

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

func OpenFile

func OpenFile(pathname string, flags int, mode uint32) (*File, error)

func (*File) Close

func (f *File) Close() error

func (*File) Fd

func (f *File) Fd() uintptr

func (*File) Lock

func (f *File) Lock() error

Lock locks the fd with FcntlFlock(). Blocks until the lock is not released.

func (*File) Read

func (f *File) Read(p []byte) (n int, err error)

func (*File) ReadByte

func (f *File) ReadByte() (byte, error)

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

func (*File) Stat

func (f *File) Stat() (*FileInfo, error)

func (*File) Sync

func (f *File) Sync() error

func (*File) Unlock

func (f *File) Unlock() error

Unlock unlocks the lockon fd. Blocks until the lock is not released.

func (*File) Write

func (f *File) Write(p []byte) (n int, err error)

func (*File) WriteByte

func (f *File) WriteByte(c byte) error

func (*File) WriteString

func (f *File) WriteString(s string) (n int, err error)

type FileInfo

type FileInfo struct {
	Dev     uint64     // ID of device containing file
	Ino     uint64     // Inode number
	Mode    FileMode   // File type and mode
	Nlink   uint64     // Number of hard links
	User    user.User  // Owner user. If invalid uid found (that can happen), only the Uid field is set.
	Group   user.Group // Owner group. If invalid gid found (that can happen), only the Gid field is set.
	Rdev    uint64     // Device ID (if special file)
	Size    int64      // Total size, in bytes
	Blksize int64      // Block size for filesystem I/O
	Blocks  int64      // Number of 512 B blocks allocated
	Atim    time.Time  // Time of last access
	Mtim    time.Time  // Time of last modification
	Ctim    time.Time  // Time of last status change
}

FileInfo describes information about a file. See struct stat at stat(3) manual for more info.

func Fstat

func Fstat(fd int) (*FileInfo, error)

Fstat returns information about a file specified by file.

func Lstat

func Lstat(path string) (*FileInfo, error)

Lstat returns information about a file specified by path. If path is a symbolic link, then it returns information about the link itself, not the file that the link refers to.

No permissions are required on the file itself, execute (search) permission is required on all of the directories in pathname that lead to the file. See stat(2) manual for more info.

func Stat

func Stat(path string) (*FileInfo, error)

Stat returns information about a file specified by path.

No permissions are required on the file itself, execute (search) permission is required on all of the directories in pathname that lead to the file. See stat(2) manual for more info.

type FileMode

type FileMode uint32
const (
	S_IFMT   FileMode = 00170000 // This is a bit mask used to extract the file type code from a mode value.
	S_IFSOCK FileMode = 0140000  // This is the file type constant of a socket.
	S_IFLNK  FileMode = 0120000  // This is the file type constant of a symbolic link.
	S_IFREG  FileMode = 0100000  // This is the file type constant of a regular file.
	S_IFBLK  FileMode = 0060000  // This is the file type constant of a block-oriented device file.
	S_IFDIR  FileMode = 0040000  // This is the file type constant of a directory file.
	S_IFCHR  FileMode = 0020000  // This is the file type constant of a character-oriented device file.
	S_IFIFO  FileMode = 0010000  // This is the file type constant of a FIFO or pipe.
	S_ISUID  FileMode = 0004000  // This is the set-user-ID on execute bit.
	S_ISGID  FileMode = 0002000  // This is the set-group-ID on execute bit.
	S_ISVTX  FileMode = 0001000  // This is the sticky bit.
	S_IRWXU  FileMode = 0000700  // This is equivalent to (S_IRUSR | S_IWUSR | S_IXUSR).
	S_IRUSR  FileMode = 00000400 // Read permission bit for the owner of the file.
	S_IWUSR  FileMode = 00000200 // Write permission bit for the owner of the file.
	S_IXUSR  FileMode = 00000100 // Execute (for ordinary files) or search (for directories) permission bit for the owner of the file.
	S_IRWXG  FileMode = 00000070 // This is equivalent to (S_IRGRP | S_IWGRP | S_IXGRP).
	S_IRGRP  FileMode = 00000040 // Read permission bit for the group owner of the file.
	S_IWGRP  FileMode = 00000020 // Write permission bit for the group owner of the file.
	S_IXGRP  FileMode = 00000010 // Execute or search permission bit for the group owner of the file.
	S_IRWXO  FileMode = 00000007 // This is equivalent to (S_IROTH | S_IWOTH | S_IXOTH).
	S_IROTH  FileMode = 00000004 // Read permission bit for other users.
	S_IWOTH  FileMode = 00000002 // Write permission bit for other users.
	S_IXOTH  FileMode = 00000001 // Execute or search permission bit for other users.

)

func FileModeClear

func FileModeClear(mode, m FileMode) FileMode

FileModeClear clears m bit in mode.

func FileModeGetPath

func FileModeGetPath(path string) (FileMode, error)

FileModeGetPath returns the mode of the file in path. This function (and every *Path functions) does not follows symbolic link.

func FileModeSet

func FileModeSet(mode, m FileMode) FileMode

FileModeSet sets m bit in mode.

func FileModeToggle

func FileModeToggle(mode, m FileMode) FileMode

FileModeClear clears m bit in mode.

type FileType

type FileType uint32

func (FileType) String

func (t FileType) String() string

type User

type User struct {
	Username string // Login name
	Password string // Optional encrypted password
	UID      int    // Numerical user ID
	GID      int    // Numerical group ID
	Gecos    string // User name or comment field
	Home     string // User  home directory
	Shell    string // Optional user command interpreter
}

Passwd stores the user account information.

See passwd(5) for more info.

func LookupUser

func LookupUser(username string) (*User, error)

LookupUser search for user with username username. If the user cannot be found, returns ErrUserNotFound.

This function parses the "/etc/passwd" file.

func LookupUserID

func LookupUserID(uid int) (*User, error)

LookupUserID search for user with ID uid. If the user cannot be found, returns ErrUserNotFound.

This function parses the "/etc/passwd" file.

Jump to

Keyboard shortcuts

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