diff options
author | Neel Natu <neelnatu@google.com> | 2018-07-17 10:50:02 -0700 |
---|---|---|
committer | Shentubot <shentubot@google.com> | 2018-07-17 10:50:53 -0700 |
commit | ed2e03d3780b8d96b189c1311c92b9db2fbcb35a (patch) | |
tree | 0f02cb8622baec1b6af179b7ce34b75416a8c07f /pkg | |
parent | beb89bb75749620969b0e1dea65240bf5d4324b2 (diff) |
Add API to decode 'stat.st_rdev' into major and minor numbers.
PiperOrigin-RevId: 204936533
Change-Id: Ib060920077fc914f97c4a0548a176d1368510c7b
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/abi/linux/dev.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/pkg/abi/linux/dev.go b/pkg/abi/linux/dev.go index d3b63063f..ea5b16b7b 100644 --- a/pkg/abi/linux/dev.go +++ b/pkg/abi/linux/dev.go @@ -25,6 +25,13 @@ func MakeDeviceID(major uint16, minor uint32) uint32 { return (minor & 0xff) | ((uint32(major) & 0xfff) << 8) | ((minor >> 8) << 20) } +// DecodeDeviceID decodes a device ID into major and minor device numbers. +func DecodeDeviceID(rdev uint32) (uint16, uint32) { + major := uint16((rdev >> 8) & 0xfff) + minor := (rdev & 0xff) | ((rdev >> 20) << 8) + return major, minor +} + // Character device IDs. // // See Documentations/devices.txt and uapi/linux/major.h. |