github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/internal/disk/stat_bsd.go (about) 1 //go:build darwin || dragonfly 2 // +build darwin dragonfly 3 4 // Copyright (c) 2015-2021 MinIO, Inc. 5 // 6 // This file is part of MinIO Object Storage stack 7 // 8 // This program is free software: you can redistribute it and/or modify 9 // it under the terms of the GNU Affero General Public License as published by 10 // the Free Software Foundation, either version 3 of the License, or 11 // (at your option) any later version. 12 // 13 // This program is distributed in the hope that it will be useful 14 // but WITHOUT ANY WARRANTY; without even the implied warranty of 15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 // GNU Affero General Public License for more details. 17 // 18 // You should have received a copy of the GNU Affero General Public License 19 // along with this program. If not, see <http://www.gnu.org/licenses/>. 20 21 package disk 22 23 import ( 24 "errors" 25 "fmt" 26 "syscall" 27 ) 28 29 // GetInfo returns total and free bytes available in a directory, e.g. `/`. 30 func GetInfo(path string, _ bool) (info Info, err error) { 31 s := syscall.Statfs_t{} 32 err = syscall.Statfs(path, &s) 33 if err != nil { 34 return Info{}, err 35 } 36 reservedBlocks := s.Bfree - s.Bavail 37 info = Info{ 38 Total: uint64(s.Bsize) * (s.Blocks - reservedBlocks), 39 Free: uint64(s.Bsize) * s.Bavail, 40 Files: s.Files, 41 Ffree: s.Ffree, 42 FSType: getFSType(s.Fstypename[:]), 43 } 44 if info.Free > info.Total { 45 return info, fmt.Errorf("detected free space (%d) > total drive space (%d), fs corruption at (%s). please run 'fsck'", info.Free, info.Total, path) 46 } 47 info.Used = info.Total - info.Free 48 return info, nil 49 } 50 51 // GetDriveStats returns IO stats of the drive by its major:minor 52 func GetDriveStats(major, minor uint32) (iostats IOStats, err error) { 53 return IOStats{}, errors.New("operation unsupported") 54 }