1// Copyright 2016 the Go-FUSE Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5package fuse 6 7import ( 8 "os" 9 "syscall" 10 "time" 11) 12 13func (a *Attr) IsFifo() bool { return (uint32(a.Mode) & syscall.S_IFMT) == syscall.S_IFIFO } 14 15// IsChar reports whether the FileInfo describes a character special file. 16func (a *Attr) IsChar() bool { return (uint32(a.Mode) & syscall.S_IFMT) == syscall.S_IFCHR } 17 18// IsDir reports whether the FileInfo describes a directory. 19func (a *Attr) IsDir() bool { return (uint32(a.Mode) & syscall.S_IFMT) == syscall.S_IFDIR } 20 21// IsBlock reports whether the FileInfo describes a block special file. 22func (a *Attr) IsBlock() bool { return (uint32(a.Mode) & syscall.S_IFMT) == syscall.S_IFBLK } 23 24// IsRegular reports whether the FileInfo describes a regular file. 25func (a *Attr) IsRegular() bool { return (uint32(a.Mode) & syscall.S_IFMT) == syscall.S_IFREG } 26 27// IsSymlink reports whether the FileInfo describes a symbolic link. 28func (a *Attr) IsSymlink() bool { return (uint32(a.Mode) & syscall.S_IFMT) == syscall.S_IFLNK } 29 30// IsSocket reports whether the FileInfo describes a socket. 31func (a *Attr) IsSocket() bool { return (uint32(a.Mode) & syscall.S_IFMT) == syscall.S_IFSOCK } 32 33func (a *Attr) SetTimes(access *time.Time, mod *time.Time, chstatus *time.Time) { 34 if access != nil { 35 a.Atime = uint64(access.Unix()) 36 a.Atimensec = uint32(access.Nanosecond()) 37 } 38 if mod != nil { 39 a.Mtime = uint64(mod.Unix()) 40 a.Mtimensec = uint32(mod.Nanosecond()) 41 } 42 if chstatus != nil { 43 a.Ctime = uint64(chstatus.Unix()) 44 a.Ctimensec = uint32(chstatus.Nanosecond()) 45 } 46} 47 48func (a *Attr) ChangeTime() time.Time { 49 return time.Unix(int64(a.Ctime), int64(a.Ctimensec)) 50} 51 52func (a *Attr) AccessTime() time.Time { 53 return time.Unix(int64(a.Atime), int64(a.Atimensec)) 54} 55 56func (a *Attr) ModTime() time.Time { 57 return time.Unix(int64(a.Mtime), int64(a.Mtimensec)) 58} 59 60func ToStatT(f os.FileInfo) *syscall.Stat_t { 61 s, _ := f.Sys().(*syscall.Stat_t) 62 if s != nil { 63 return s 64 } 65 return nil 66} 67 68func ToAttr(f os.FileInfo) *Attr { 69 if f == nil { 70 return nil 71 } 72 s := ToStatT(f) 73 if s != nil { 74 a := &Attr{} 75 a.FromStat(s) 76 return a 77 } 78 return nil 79} 80