fork/gdu
git clone https://git.julia.blue/fork/gdu
fbab3ef
ignore
1//go:build darwin || netbsd || freebsd 2 3package analyze 4 5import ( 6"os" 7"syscall" 8"time" 9) 10 11const devBSize = 512 12 13func getPlatformSpecificUsageAndMli (info os.FileInfo ) (usage int64 ,ino uint64 ) { 14if stat ,ok := info .Sys ().(* syscall.Stat_t );ok { 15if stat .Nlink > 1 { 16ino = stat .Ino 17 } 18return stat .Blocks * devBSize ,ino 19 } 20return 0 ,0 21} 22 23func setPlatformSpecificAttrs (file * File ,f os.FileInfo ) { 24if stat ,ok := f .Sys ().(* syscall.Stat_t );ok { 25file .Usage = stat .Blocks * devBSize 26file .Mtime = time .Unix (int64 (stat .Mtimespec .Sec ),int64 (stat .Mtimespec .Nsec )) 27 28if stat .Nlink > 1 { 29file .Mli = stat .Ino 30 } 31 } 32} 33 34func setDirPlatformSpecificAttrs (dir * Dir ,path string ) { 35var stat syscall.Stat_t 36if err := syscall .Stat (path ,& stat );err != nil { 37return 38 } 39 40dir .Mtime = time .Unix (int64 (stat .Mtimespec .Sec ),int64 (stat .Mtimespec .Nsec )) 41} 42 43// getSyscallStats extracts usage and inode info from os.FileInfo using syscall 44func getSyscallStats (info os.FileInfo ) (usage int64 ,mli uint64 ) { 45if stat ,ok := info .Sys ().(* syscall.Stat_t );ok { 46usage = stat .Blocks * 512 // 512-byte blocks 47if stat .Nlink > 1 { 48mli = stat .Ino 49 } 50 }else { 51usage = info .Size () 52 } 53return 54}