fork/gdu

git clone https://git.julia.blue/fork/gdu

Daniel Mildefeat: top-dir analyzer for non-interactive mode (#557)fbab3ef

ignore
1.2 KiB54 linesraw
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) {
14	if stat, ok := info.Sys().(*syscall.Stat_t); ok {
15		if stat.Nlink > 1 {
16			ino = stat.Ino
17		}
18		return stat.Blocks * devBSize, ino
19	}
20	return 0, 0
21}
22
23func setPlatformSpecificAttrs(file *File, f os.FileInfo) {
24	if stat, ok := f.Sys().(*syscall.Stat_t); ok {
25		file.Usage = stat.Blocks * devBSize
26		file.Mtime = time.Unix(int64(stat.Mtimespec.Sec), int64(stat.Mtimespec.Nsec))
27
28		if stat.Nlink > 1 {
29			file.Mli = stat.Ino
30		}
31	}
32}
33
34func setDirPlatformSpecificAttrs(dir *Dir, path string) {
35	var stat syscall.Stat_t
36	if err := syscall.Stat(path, &stat); err != nil {
37		return
38	}
39
40	dir.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) {
45	if stat, ok := info.Sys().(*syscall.Stat_t); ok {
46		usage = stat.Blocks * 512 // 512-byte blocks
47		if stat.Nlink > 1 {
48			mli = stat.Ino
49		}
50	} else {
51		usage = info.Size()
52	}
53	return
54}