mirror of
https://github.com/minio/minio.git
synced 2025-01-11 15:03:22 -05:00
Provide the correct free block size volume/disk information (#4943)
On *NIX platforms the statfs(2) system call returns a struct containing both the free blocks in the filesystem (Statfs_t.Bfree) and the free blocks available to the unprivileged or non-superuser (Statfs_t.Bavail). The `Bfree` and `Bavail` fields (with `Bfree >= Bavail`) will be set to different values on e.g. filesystems such as ext4 that reserve a certain percentage of the filesystem blocks which may only be allocated by admnistrative privileged processes. The calculations for the `Total` disk space need to subtract the difference between the `Bfree` and `Bavail` fields for it to correctly show the total available storage space available for unprivileged users. This implicitly fixes a bug where the `Used = Total - Free` calculation yielded different (and also incorrect) results for identical contents stored when only the sizes of the disks or backing volumes differed. (as can be witnessed in the `Used:` value displayed in the Minio browser) See: - https://wiki.archlinux.org/index.php/ext4#Reserved_blocks - http://man7.org/linux/man-pages/man2/statfs.2.html - https://man.openbsd.org/statfs - http://lingrok.org/xref/coreutils/src/df.c#893
This commit is contained in:
parent
d3eb5815d9
commit
0bf981278e
@ -29,11 +29,13 @@ func GetInfo(path string) (info Info, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return Info{}, err
|
return Info{}, err
|
||||||
}
|
}
|
||||||
info = Info{}
|
fsReservedBlocks := uint64(s.Bfree) - uint64(s.Bavail)
|
||||||
info.Total = uint64(s.Bsize) * uint64(s.Blocks)
|
info = Info{
|
||||||
info.Free = uint64(s.Bsize) * uint64(s.Bavail)
|
Total: uint64(s.Bsize) * (uint64(s.Blocks) - fsReservedBlocks),
|
||||||
info.Files = uint64(s.Files)
|
Free: uint64(s.Bsize) * uint64(s.Bavail),
|
||||||
info.Ffree = uint64(s.Ffree)
|
Files: uint64(s.Files),
|
||||||
info.FSType = getFSType(s.Fstypename)
|
Ffree: uint64(s.Ffree),
|
||||||
|
FSType: getFSType(s.Fstypename),
|
||||||
|
}
|
||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
@ -29,11 +29,13 @@ func GetInfo(path string) (info Info, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return Info{}, err
|
return Info{}, err
|
||||||
}
|
}
|
||||||
info = Info{}
|
fsReservedBlocks := uint64(s.Bfree) - uint64(s.Bavail)
|
||||||
info.Total = uint64(s.Bsize) * uint64(s.Blocks)
|
info = Info{
|
||||||
info.Free = uint64(s.Bsize) * uint64(s.Bavail)
|
Total: uint64(s.Bsize) * (uint64(s.Blocks) - fsReservedBlocks),
|
||||||
info.Files = uint64(s.Files)
|
Free: uint64(s.Bsize) * uint64(s.Bavail),
|
||||||
info.Ffree = uint64(s.Ffree)
|
Files: uint64(s.Files),
|
||||||
info.FSType = getFSType(int64(s.Type))
|
Ffree: uint64(s.Ffree),
|
||||||
|
FSType: getFSType(int64(s.Type)),
|
||||||
|
}
|
||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
@ -29,11 +29,13 @@ func GetInfo(path string) (info Info, err error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return Info{}, err
|
return Info{}, err
|
||||||
}
|
}
|
||||||
info = Info{}
|
fsReservedBlocks := uint64(s.F_bfree) - uint64(s.F_bavail)
|
||||||
info.Total = uint64(s.F_bsize) * uint64(s.F_blocks)
|
info = Info{
|
||||||
info.Free = uint64(s.F_bsize) * uint64(s.F_bavail)
|
Total: uint64(s.F_bsize) * (uint64(s.F_blocks) - fsReservedBlocks),
|
||||||
info.Files = uint64(s.F_files)
|
Free: uint64(s.F_bsize) * uint64(s.F_bavail),
|
||||||
info.Ffree = uint64(s.F_ffree)
|
Files: uint64(s.F_files),
|
||||||
info.FSType = getFSType(s.F_fstypename)
|
Ffree: uint64(s.F_ffree),
|
||||||
|
FSType: getFSType(s.F_fstypename),
|
||||||
|
}
|
||||||
return info, nil
|
return info, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user