github.com/kaisenlinux/docker.io@v0.0.0-20230510090727-ea55db55fac7/engine/pkg/system/stat_unix.go (about) 1 //go:build !windows 2 // +build !windows 3 4 package system // import "github.com/docker/docker/pkg/system" 5 6 import ( 7 "os" 8 "syscall" 9 ) 10 11 // StatT type contains status of a file. It contains metadata 12 // like permission, owner, group, size, etc about a file. 13 type StatT struct { 14 mode uint32 15 uid uint32 16 gid uint32 17 rdev uint64 18 size int64 19 mtim syscall.Timespec 20 } 21 22 // Mode returns file's permission mode. 23 func (s StatT) Mode() uint32 { 24 return s.mode 25 } 26 27 // UID returns file's user id of owner. 28 func (s StatT) UID() uint32 { 29 return s.uid 30 } 31 32 // GID returns file's group id of owner. 33 func (s StatT) GID() uint32 { 34 return s.gid 35 } 36 37 // Rdev returns file's device ID (if it's special file). 38 func (s StatT) Rdev() uint64 { 39 return s.rdev 40 } 41 42 // Size returns file's size. 43 func (s StatT) Size() int64 { 44 return s.size 45 } 46 47 // Mtim returns file's last modification time. 48 func (s StatT) Mtim() syscall.Timespec { 49 return s.mtim 50 } 51 52 // IsDir reports whether s describes a directory. 53 func (s StatT) IsDir() bool { 54 return s.mode&syscall.S_IFDIR != 0 55 } 56 57 // Stat takes a path to a file and returns 58 // a system.StatT type pertaining to that file. 59 // 60 // Throws an error if the file does not exist 61 func Stat(path string) (*StatT, error) { 62 s := &syscall.Stat_t{} 63 if err := syscall.Stat(path, s); err != nil { 64 return nil, &os.PathError{Op: "Stat", Path: path, Err: err} 65 } 66 return fromStatT(s) 67 }