storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/pkg/disk/stat_linux_s390x.go (about) 1 //go:build linux && s390x 2 // +build linux,s390x 3 4 /* 5 * MinIO Cloud Storage, (C) 2020 MinIO, Inc. 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19 20 package disk 21 22 import ( 23 "fmt" 24 "strconv" 25 "syscall" 26 ) 27 28 // fsType2StringMap - list of filesystems supported on linux 29 var fsType2StringMap = map[string]string{ 30 "1021994": "TMPFS", 31 "137d": "EXT", 32 "4244": "HFS", 33 "4d44": "MSDOS", 34 "52654973": "REISERFS", 35 "5346544e": "NTFS", 36 "58465342": "XFS", 37 "61756673": "AUFS", 38 "6969": "NFS", 39 "ef51": "EXT2OLD", 40 "ef53": "EXT4", 41 "f15f": "ecryptfs", 42 "794c7630": "overlayfs", 43 "2fc12fc1": "zfs", 44 "ff534d42": "cifs", 45 "53464846": "wslfs", 46 } 47 48 // getFSType returns the filesystem type of the underlying mounted filesystem 49 func getFSType(ftype uint32) string { 50 fsTypeHex := strconv.FormatUint(uint64(ftype), 16) 51 fsTypeString, ok := fsType2StringMap[fsTypeHex] 52 if !ok { 53 return "UNKNOWN" 54 } 55 return fsTypeString 56 } 57 58 // GetInfo returns total and free bytes available in a directory, e.g. `/`. 59 func GetInfo(path string) (info Info, err error) { 60 s := syscall.Statfs_t{} 61 err = syscall.Statfs(path, &s) 62 if err != nil { 63 return Info{}, err 64 } 65 reservedBlocks := s.Bfree - s.Bavail 66 info = Info{ 67 Total: uint64(s.Frsize) * (s.Blocks - reservedBlocks), 68 Free: uint64(s.Frsize) * s.Bavail, 69 Files: s.Files, 70 Ffree: s.Ffree, 71 FSType: getFSType(s.Type), 72 } 73 // Check for overflows. 74 // https://github.com/minio/minio/issues/8035 75 // XFS can show wrong values at times error out 76 // in such scenarios. 77 if info.Free > info.Total { 78 return info, fmt.Errorf("detected free space (%d) > total disk space (%d), fs corruption at (%s). please run 'fsck'", info.Free, info.Total, path) 79 } 80 info.Used = info.Total - info.Free 81 return info, nil 82 }