Skip to content

Commit f6f1e99

Browse files
committed
created central sectorsize const
Signed-off-by: fs185143 <[email protected]>
1 parent c4dab9f commit f6f1e99

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

blockdevice/stats.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ import (
2121
"os"
2222
"strings"
2323

24-
"github.com/prometheus/procfs/btrfs"
25-
"github.com/prometheus/procfs/internal/fs"
24+
filesystem "github.com/prometheus/procfs/internal/fs"
2625
"github.com/prometheus/procfs/internal/util"
2726
)
2827

@@ -216,30 +215,30 @@ const (
216215
// FS represents the pseudo-filesystems proc and sys, which provides an
217216
// interface to kernel data structures.
218217
type FS struct {
219-
proc *fs.FS
220-
sys *fs.FS
218+
proc *filesystem.FS
219+
sys *filesystem.FS
221220
}
222221

223222
// NewDefaultFS returns a new blockdevice fs using the default mountPoints for proc and sys.
224223
// It will error if either of these mount points can't be read.
225224
func NewDefaultFS() (FS, error) {
226-
return NewFS(fs.DefaultProcMountPoint, fs.DefaultSysMountPoint)
225+
return NewFS(filesystem.DefaultProcMountPoint, filesystem.DefaultSysMountPoint)
227226
}
228227

229228
// NewFS returns a new blockdevice fs using the given mountPoints for proc and sys.
230229
// It will error if either of these mount points can't be read.
231230
func NewFS(procMountPoint string, sysMountPoint string) (FS, error) {
232231
if strings.TrimSpace(procMountPoint) == "" {
233-
procMountPoint = fs.DefaultProcMountPoint
232+
procMountPoint = filesystem.DefaultProcMountPoint
234233
}
235-
procfs, err := fs.NewFS(procMountPoint)
234+
procfs, err := filesystem.NewFS(procMountPoint)
236235
if err != nil {
237236
return FS{}, err
238237
}
239238
if strings.TrimSpace(sysMountPoint) == "" {
240-
sysMountPoint = fs.DefaultSysMountPoint
239+
sysMountPoint = filesystem.DefaultSysMountPoint
241240
}
242-
sysfs, err := fs.NewFS(sysMountPoint)
241+
sysfs, err := filesystem.NewFS(sysMountPoint)
243242
if err != nil {
244243
return FS{}, err
245244
}
@@ -484,5 +483,5 @@ func (fs FS) SysBlockDeviceSize(device string) (uint64, error) {
484483
if err != nil {
485484
return 0, err
486485
}
487-
return btrfs.SectorSize * size, nil
486+
return filesystem.SectorSize * size, nil
488487
}

btrfs/get.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ import (
2626
"github.com/prometheus/procfs/internal/util"
2727
)
2828

29-
// SectorSize contains the Linux sector size.
30-
// > Linux always considers sectors to be 512 bytes long independently
31-
// > of the devices real block size.
32-
const SectorSize = 512
33-
3429
// FS represents the pseudo-filesystem sys, which provides an interface to
3530
// kernel data structures.
3631
type FS struct {
@@ -213,7 +208,7 @@ func (r *reader) readDeviceInfo(d string) map[string]*Device {
213208
info := make(map[string]*Device, len(devs))
214209
for _, n := range devs {
215210
info[n] = &Device{
216-
Size: SectorSize * r.readValue("devices/"+n+"/size"),
211+
Size: fs.SectorSize * r.readValue("devices/"+n+"/size"),
217212
}
218213
}
219214

internal/fs/fs.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ const (
3131

3232
// DefaultSelinuxMountPoint is the common mount point of the selinuxfs.
3333
DefaultSelinuxMountPoint = "/sys/fs/selinux"
34+
35+
// SectorSize represents the size of a sector in bytes.
36+
// It is specific to Linux block I/O operations.
37+
SectorSize = 512
3438
)
3539

3640
// FS represents a pseudo-filesystem, normally /proc or /sys, which provides an

0 commit comments

Comments
 (0)