github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/ios/fsutils_linux.go (about)

     1  // Package ios is a collection of interfaces to the local storage subsystem;
     2  // the package includes OS-dependent implementations for those interfaces.
     3  /*
     4   * Copyright (c) 2018-2021, NVIDIA CORPORATION. All rights reserved.
     5   */
     6  package ios
     7  
     8  import (
     9  	"os"
    10  	"os/exec"
    11  	"syscall"
    12  	"time"
    13  
    14  	"golang.org/x/sys/unix"
    15  )
    16  
    17  func DirSizeOnDisk(dirPath string, withNonDirPrefix bool) (uint64, error) {
    18  	// GNU implementation of du uses -b to get apparent size with a block size of 1 and -c to show a total
    19  	cmd := exec.Command("du", "-bc", dirPath)
    20  	return executeDU(cmd, dirPath, withNonDirPrefix, 1)
    21  }
    22  
    23  func GetFSStats(path string) (blocks, bavail uint64, bsize int64, err error) {
    24  	var fsStats unix.Statfs_t
    25  	fsStats, err = getFSStats(path)
    26  	if err != nil {
    27  		return
    28  	}
    29  	return fsStats.Blocks, fsStats.Bavail, fsStats.Bsize, nil
    30  }
    31  
    32  func GetATime(osfi os.FileInfo) time.Time {
    33  	stat := osfi.Sys().(*syscall.Stat_t)
    34  	atime := time.Unix(stat.Atim.Sec, stat.Atim.Nsec)
    35  	// NOTE: see https://en.wikipedia.org/wiki/Stat_(system_call)#Criticism_of_atime
    36  	return atime
    37  }