github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/internal/disk/stat_netbsd.go (about) 1 //go:build netbsd 2 // +build netbsd 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 27 "golang.org/x/sys/unix" 28 ) 29 30 // GetInfo returns total and free bytes available in a directory, e.g. `/`. 31 func GetInfo(path string, _ bool) (info Info, err error) { 32 s := unix.Statvfs_t{} 33 if err = unix.Statvfs(path, &s); err != nil { 34 return Info{}, err 35 } 36 reservedBlocks := uint64(s.Bfree) - uint64(s.Bavail) 37 info = Info{ 38 Total: uint64(s.Frsize) * (uint64(s.Blocks) - reservedBlocks), 39 Free: uint64(s.Frsize) * uint64(s.Bavail), 40 Files: uint64(s.Files), 41 Ffree: uint64(s.Ffree), 42 FSType: string(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 }