Skip to content

Commit

Permalink
lxd/device: Add named return results to unixDeviceAttributes function
Browse files Browse the repository at this point in the history
Signed-off-by: Kadin Sayani <[email protected]>
  • Loading branch information
kadinsayani committed Nov 12, 2024
1 parent 7466e77 commit dcd73cb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lxd/device/device_utils_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,16 @@ import (
// unixDefaultMode default mode to create unix devices with if not specified in device config.
const unixDefaultMode = 0660

// unixDeviceAttributes returns the decice type, major and minor numbers for a device.
func unixDeviceAttributes(path string) (string, uint32, uint32, error) {
// unixDeviceAttributes returns the device type, major and minor numbers for a device.
func unixDeviceAttributes(path string) (dType string, major uint32, minor uint32, err error) {
// Get a stat struct from the provided path
stat := unix.Stat_t{}
err := unix.Stat(path, &stat)
err = unix.Stat(path, &stat)
if err != nil {
return "", 0, 0, err
}

// Check what kind of file it is
dType := ""
if stat.Mode&unix.S_IFMT == unix.S_IFBLK {
dType = "b"
} else if stat.Mode&unix.S_IFMT == unix.S_IFCHR {
Expand All @@ -40,8 +39,9 @@ func unixDeviceAttributes(path string) (string, uint32, uint32, error) {
}

// Return the device information
major := unix.Major(uint64(stat.Rdev))
minor := unix.Minor(uint64(stat.Rdev))
major = unix.Major(uint64(stat.Rdev))
minor = unix.Minor(uint64(stat.Rdev))

return dType, major, minor, nil
}

Expand Down

0 comments on commit dcd73cb

Please sign in to comment.