From ed2e03d3780b8d96b189c1311c92b9db2fbcb35a Mon Sep 17 00:00:00 2001 From: Neel Natu Date: Tue, 17 Jul 2018 10:50:02 -0700 Subject: Add API to decode 'stat.st_rdev' into major and minor numbers. PiperOrigin-RevId: 204936533 Change-Id: Ib060920077fc914f97c4a0548a176d1368510c7b --- pkg/abi/linux/dev.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'pkg/abi') 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. -- cgit v1.2.3