Skip to content

Commit

Permalink
ignore devices with device metadata missing
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana committed Jun 11, 2023
1 parent c0ae169 commit 76ac5aa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
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

0 comments on commit 76ac5aa

Please sign in to comment.