Skip to content

Commit

Permalink
moved SectorSize const to fs.go in procfs package
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 d0f7a38 commit 6c3ef0b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 16 deletions.
19 changes: 10 additions & 9 deletions blockdevice/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import (
"os"
"strings"

filesystem "github.com/prometheus/procfs/internal/fs"
"github.com/prometheus/procfs"
"github.com/prometheus/procfs/internal/fs"
"github.com/prometheus/procfs/internal/util"
)

Expand Down Expand Up @@ -215,30 +216,30 @@ const (
// FS represents the pseudo-filesystems proc and sys, which provides an
// interface to kernel data structures.
type FS struct {
proc *filesystem.FS
sys *filesystem.FS
proc *fs.FS
sys *fs.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(filesystem.DefaultProcMountPoint, filesystem.DefaultSysMountPoint)
return NewFS(fs.DefaultProcMountPoint, fs.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 = filesystem.DefaultProcMountPoint
procMountPoint = fs.DefaultProcMountPoint
}
procfs, err := filesystem.NewFS(procMountPoint)
procfs, err := fs.NewFS(procMountPoint)
if err != nil {
return FS{}, err
}
if strings.TrimSpace(sysMountPoint) == "" {
sysMountPoint = filesystem.DefaultSysMountPoint
sysMountPoint = fs.DefaultSysMountPoint
}
sysfs, err := filesystem.NewFS(sysMountPoint)
sysfs, err := fs.NewFS(sysMountPoint)
if err != nil {
return FS{}, err
}
Expand Down Expand Up @@ -483,5 +484,5 @@ func (fs FS) SysBlockDeviceSize(device string) (uint64, error) {
if err != nil {
return 0, err
}
return filesystem.SectorSize * size, nil
return procfs.SectorSize * size, nil
}
3 changes: 2 additions & 1 deletion btrfs/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strconv"
"strings"

"github.com/prometheus/procfs"
"github.com/prometheus/procfs/internal/fs"
"github.com/prometheus/procfs/internal/util"
)
Expand Down Expand Up @@ -208,7 +209,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: fs.SectorSize * r.readValue("devices/"+n+"/size"),
Size: procfs.SectorSize * r.readValue("devices/"+n+"/size"),
}
}

Expand Down
10 changes: 8 additions & 2 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,14 @@ type FS struct {
isReal bool
}

// DefaultMountPoint is the common mount point of the proc filesystem.
const DefaultMountPoint = fs.DefaultProcMountPoint
const (
// DefaultMountPoint is the common mount point of the proc filesystem.
DefaultMountPoint = fs.DefaultProcMountPoint

// SectorSize represents the size of a sector in bytes.
// It is specific to Linux block I/O operations.
SectorSize = 512
)

// NewDefaultFS returns a new proc FS mounted under the default proc mountPoint.
// It will error if the mount point directory can't be read or is a file.
Expand Down
4 changes: 0 additions & 4 deletions internal/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ 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 6c3ef0b

Please sign in to comment.