Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore sysfs file read errors #799

Merged
merged 1 commit into from Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions pkg/device/sysfs_linux.go
Expand Up @@ -57,22 +57,22 @@ func getHidden(name string) bool {
// errors ignored since real devices do not have <sys>/hidden
// borrow idea from 'lsblk'
// https://github.com/util-linux/util-linux/commit/c8487d854ba5cf5bfcae78d8e5af5587e7622351
v, _ := readFirstLine("/sys/class/block/"+name+"/hidden", false)
v, _ := readFirstLine("/sys/class/block/" + name + "/hidden")
return v == "1"
}

func getRemovable(name string) (bool, error) {
s, err := readFirstLine("/sys/class/block/"+name+"/removable", false)
s, err := readFirstLine("/sys/class/block/" + name + "/removable")
return s != "" && s != "0", err
}

func getReadOnly(name string) (bool, error) {
s, err := readFirstLine("/sys/class/block/"+name+"/ro", false)
s, err := readFirstLine("/sys/class/block/" + name + "/ro")
return s != "" && s != "0", err
}

func getSize(name string) (uint64, error) {
s, err := readFirstLine("/sys/class/block/"+name+"/size", true)
s, err := readFirstLine("/sys/class/block/" + name + "/size")
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -104,5 +104,5 @@ func getHolders(name string) ([]string, error) {
}

func getDMName(name string) (string, error) {
return readFirstLine("/sys/class/block/"+name+"/dm/name", false)
return readFirstLine("/sys/class/block/" + name + "/dm/name")
}
5 changes: 1 addition & 4 deletions pkg/device/utils.go
Expand Up @@ -37,11 +37,8 @@ func readdirnames(dirname string, errorIfNotExist bool) ([]string, error) {
return dir.Readdirnames(-1)
}

func readFirstLine(filename string, errorIfNotExist bool) (string, error) {
func readFirstLine(filename string) (string, error) {
getError := func(err error) error {
if errorIfNotExist {
return err
}
switch {
case errors.Is(err, os.ErrNotExist), errors.Is(err, os.ErrInvalid):
return nil
Expand Down