From f6f1e99a82659edbea693b707c8ce19d85a185ad Mon Sep 17 00:00:00 2001 From: fs185143 Date: Mon, 23 Sep 2024 10:34:02 +0000 Subject: [PATCH] created central sectorsize const Signed-off-by: fs185143 --- blockdevice/stats.go | 19 +++++++++---------- btrfs/get.go | 7 +------ internal/fs/fs.go | 4 ++++ 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/blockdevice/stats.go b/blockdevice/stats.go index e5331ef2..bc6b6a17 100644 --- a/blockdevice/stats.go +++ b/blockdevice/stats.go @@ -21,8 +21,7 @@ import ( "os" "strings" - "github.com/prometheus/procfs/btrfs" - "github.com/prometheus/procfs/internal/fs" + filesystem "github.com/prometheus/procfs/internal/fs" "github.com/prometheus/procfs/internal/util" ) @@ -216,30 +215,30 @@ const ( // FS represents the pseudo-filesystems proc and sys, which provides an // interface to kernel data structures. type FS struct { - proc *fs.FS - sys *fs.FS + proc *filesystem.FS + sys *filesystem.FS } // NewDefaultFS returns a new blockdevice fs using the default mountPoints for proc and sys. // It will error if either of these mount points can't be read. func NewDefaultFS() (FS, error) { - return NewFS(fs.DefaultProcMountPoint, fs.DefaultSysMountPoint) + return NewFS(filesystem.DefaultProcMountPoint, filesystem.DefaultSysMountPoint) } // NewFS returns a new blockdevice fs using the given mountPoints for proc and sys. // It will error if either of these mount points can't be read. func NewFS(procMountPoint string, sysMountPoint string) (FS, error) { if strings.TrimSpace(procMountPoint) == "" { - procMountPoint = fs.DefaultProcMountPoint + procMountPoint = filesystem.DefaultProcMountPoint } - procfs, err := fs.NewFS(procMountPoint) + procfs, err := filesystem.NewFS(procMountPoint) if err != nil { return FS{}, err } if strings.TrimSpace(sysMountPoint) == "" { - sysMountPoint = fs.DefaultSysMountPoint + sysMountPoint = filesystem.DefaultSysMountPoint } - sysfs, err := fs.NewFS(sysMountPoint) + sysfs, err := filesystem.NewFS(sysMountPoint) if err != nil { return FS{}, err } @@ -484,5 +483,5 @@ func (fs FS) SysBlockDeviceSize(device string) (uint64, error) { if err != nil { return 0, err } - return btrfs.SectorSize * size, nil + return filesystem.SectorSize * size, nil } diff --git a/btrfs/get.go b/btrfs/get.go index db0046b6..ac9c205c 100644 --- a/btrfs/get.go +++ b/btrfs/get.go @@ -26,11 +26,6 @@ import ( "github.com/prometheus/procfs/internal/util" ) -// SectorSize contains the Linux sector size. -// > Linux always considers sectors to be 512 bytes long independently -// > of the devices real block size. -const SectorSize = 512 - // FS represents the pseudo-filesystem sys, which provides an interface to // kernel data structures. type FS struct { @@ -213,7 +208,7 @@ func (r *reader) readDeviceInfo(d string) map[string]*Device { info := make(map[string]*Device, len(devs)) for _, n := range devs { info[n] = &Device{ - Size: SectorSize * r.readValue("devices/"+n+"/size"), + Size: fs.SectorSize * r.readValue("devices/"+n+"/size"), } } diff --git a/internal/fs/fs.go b/internal/fs/fs.go index 3a43e839..a98c700f 100644 --- a/internal/fs/fs.go +++ b/internal/fs/fs.go @@ -31,6 +31,10 @@ const ( // DefaultSelinuxMountPoint is the common mount point of the selinuxfs. DefaultSelinuxMountPoint = "/sys/fs/selinux" + + // SectorSize represents the size of a sector in bytes. + // It is specific to Linux block I/O operations. + SectorSize = 512 ) // FS represents a pseudo-filesystem, normally /proc or /sys, which provides an