Skip to content

Commit

Permalink
created central sectorsize const
Browse files Browse the repository at this point in the history
Signed-off-by: fs185143 <[email protected]>
  • Loading branch information
fs185143 committed Nov 26, 2024
1 parent c4dab9f commit f6f1e99
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
19 changes: 9 additions & 10 deletions blockdevice/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
7 changes: 1 addition & 6 deletions btrfs/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"),
}
}

Expand Down
4 changes: 4 additions & 0 deletions internal/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f6f1e99

Please sign in to comment.