Merge pull request #1553 from mlaventure/handle-non-devices
Handle non-devices correctly in DeviceFromPath
This commit is contained in:
commit
3f2f8b84a7
|
@ -28,6 +28,15 @@ func DeviceFromPath(path, permissions string) (*configs.Device, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
devNumber = int(stat.Rdev)
|
||||||
|
major = Major(devNumber)
|
||||||
|
)
|
||||||
|
if major == 0 {
|
||||||
|
return nil, ErrNotADevice
|
||||||
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
devType rune
|
devType rune
|
||||||
mode = stat.Mode
|
mode = stat.Mode
|
||||||
|
@ -37,21 +46,16 @@ func DeviceFromPath(path, permissions string) (*configs.Device, error) {
|
||||||
devType = 'b'
|
devType = 'b'
|
||||||
case mode&unix.S_IFCHR == unix.S_IFCHR:
|
case mode&unix.S_IFCHR == unix.S_IFCHR:
|
||||||
devType = 'c'
|
devType = 'c'
|
||||||
default:
|
|
||||||
return nil, ErrNotADevice
|
|
||||||
}
|
}
|
||||||
devNumber := int(stat.Rdev)
|
|
||||||
uid := stat.Uid
|
|
||||||
gid := stat.Gid
|
|
||||||
return &configs.Device{
|
return &configs.Device{
|
||||||
Type: devType,
|
Type: devType,
|
||||||
Path: path,
|
Path: path,
|
||||||
Major: Major(devNumber),
|
Major: major,
|
||||||
Minor: Minor(devNumber),
|
Minor: Minor(devNumber),
|
||||||
Permissions: permissions,
|
Permissions: permissions,
|
||||||
FileMode: os.FileMode(mode),
|
FileMode: os.FileMode(mode),
|
||||||
Uid: uid,
|
Uid: stat.Uid,
|
||||||
Gid: gid,
|
Gid: stat.Gid,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue