github.com/NVIDIA/aistore@v1.3.23-0.20240517131212-7df6609be51d/ios/fsutils_darwin.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  	// BSD implementation of du uses -A option for apparent size and -c to show a total
    19  	cmd := exec.Command("du", "-Ac", dirPath)
    20  	// Output block size with -A option will be 512
    21  	return executeDU(cmd, dirPath, withNonDirPrefix, 512)
    22  }
    23  
    24  func GetFSStats(path string) (blocks, bavail uint64, bsize int64, err error) {
    25  	var fsStats unix.Statfs_t
    26  	fsStats, err = getFSStats(path)
    27  	if err != nil {
    28  		return
    29  	}
    30  	return fsStats.Blocks, fsStats.Bavail, int64(fsStats.Bsize), nil
    31  }
    32  
    33  func GetATime(osfi os.FileInfo) time.Time {
    34  	stat := osfi.Sys().(*syscall.Stat_t)
    35  	atime := time.Unix(stat.Atimespec.Sec, stat.Atimespec.Nsec)
    36  	// NOTE: see https://en.wikipedia.org/wiki/Stat_(system_call)#Criticism_of_atime
    37  	return atime
    38  }