github.com/vmware/govmomi@v0.51.0/toolbox/toolbox_linux.go (about) 1 // © Broadcom. All Rights Reserved. 2 // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. 3 // SPDX-License-Identifier: Apache-2.0 4 5 package toolbox 6 7 import ( 8 "fmt" 9 "os" 10 "path/filepath" 11 "syscall" 12 "time" 13 14 "github.com/vmware/govmomi/toolbox/vix" 15 ) 16 17 func fileExtendedInfoFormat(dir string, info os.FileInfo) string { 18 const format = "<fxi>" + 19 "<Name>%s</Name>" + 20 "<ft>%d</ft>" + 21 "<fs>%d</fs>" + 22 "<mt>%d</mt>" + 23 "<at>%d</at>" + 24 "<uid>%d</uid>" + 25 "<gid>%d</gid>" + 26 "<perm>%d</perm>" + 27 "<slt>%s</slt>" + 28 "</fxi>" 29 30 props := 0 31 targ := "" 32 33 if info.IsDir() { 34 props |= vix.FileAttributesDirectory 35 } 36 37 if info.Mode()&os.ModeSymlink == os.ModeSymlink { 38 props |= vix.FileAttributesSymlink 39 targ, _ = os.Readlink(filepath.Join(dir, info.Name())) 40 } 41 42 size := info.Size() 43 mtime := info.ModTime().Unix() 44 perm := info.Mode().Perm() 45 46 atime := mtime 47 uid := os.Getuid() 48 gid := os.Getgid() 49 50 if sys, ok := info.Sys().(*syscall.Stat_t); ok { 51 atime = time.Unix(sys.Atim.Unix()).Unix() 52 uid = int(sys.Uid) 53 gid = int(sys.Gid) 54 } 55 56 return fmt.Sprintf(format, info.Name(), props, size, mtime, atime, uid, gid, perm, targ) 57 }