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