github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/internal/disk/stat_linux_s390x.go (about)

     1  //go:build linux && s390x
     2  // +build linux,s390x
     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  	"strconv"
    27  	"syscall"
    28  )
    29  
    30  // fsType2StringMap - list of filesystems supported on linux
    31  var fsType2StringMap = map[string]string{
    32  	"1021994":  "TMPFS",
    33  	"137d":     "EXT",
    34  	"4244":     "HFS",
    35  	"4d44":     "MSDOS",
    36  	"52654973": "REISERFS",
    37  	"5346544e": "NTFS",
    38  	"58465342": "XFS",
    39  	"61756673": "AUFS",
    40  	"6969":     "NFS",
    41  	"ef51":     "EXT2OLD",
    42  	"ef53":     "EXT4",
    43  	"f15f":     "ecryptfs",
    44  	"794c7630": "overlayfs",
    45  	"2fc12fc1": "zfs",
    46  	"ff534d42": "cifs",
    47  	"53464846": "wslfs",
    48  }
    49  
    50  // getFSType returns the filesystem type of the underlying mounted filesystem
    51  func getFSType(ftype uint32) string {
    52  	fsTypeHex := strconv.FormatUint(uint64(ftype), 16)
    53  	fsTypeString, ok := fsType2StringMap[fsTypeHex]
    54  	if !ok {
    55  		return "UNKNOWN"
    56  	}
    57  	return fsTypeString
    58  }
    59  
    60  // GetInfo returns total and free bytes available in a directory, e.g. `/`.
    61  func GetInfo(path string, _ bool) (info Info, err error) {
    62  	s := syscall.Statfs_t{}
    63  	err = syscall.Statfs(path, &s)
    64  	if err != nil {
    65  		return Info{}, err
    66  	}
    67  	reservedBlocks := s.Bfree - s.Bavail
    68  	info = Info{
    69  		Total:  uint64(s.Frsize) * (s.Blocks - reservedBlocks),
    70  		Free:   uint64(s.Frsize) * s.Bavail,
    71  		Files:  s.Files,
    72  		Ffree:  s.Ffree,
    73  		FSType: getFSType(s.Type),
    74  	}
    75  	// Check for overflows.
    76  	// https://github.com/minio/minio/issues/8035
    77  	// XFS can show wrong values at times error out
    78  	// in such scenarios.
    79  	if info.Free > info.Total {
    80  		return info, fmt.Errorf("detected free space (%d) > total drive space (%d), fs corruption at (%s). please run 'fsck'", info.Free, info.Total, path)
    81  	}
    82  	info.Used = info.Total - info.Free
    83  	return info, nil
    84  }
    85  
    86  // GetDriveStats returns IO stats of the drive by its major:minor
    87  func GetDriveStats(major, minor uint32) (iostats IOStats, err error) {
    88  	return IOStats{}, errors.New("operation unsupported")
    89  }