Skip to content

Commit

Permalink
pkg: system: use Major, Minor and Mkdev from x/sys/unix
Browse files Browse the repository at this point in the history
Use these functions from golang.org/x/sys instead of re-implementing
them.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
  • Loading branch information
tklauser committed Oct 17, 2017
1 parent ba80c2e commit 7220123
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions pkg/system/mknod_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,17 @@ func Tarmode(typeflag byte) uint32 {
// similar to makedev(3).
func Makedev(major, minor uint64) Dev_t {
// These values come from new_envode_dev inside <linux/kdev_t.h>.
return Dev_t((minor & 0xff) | (major << 8) | ((minor &^ 0xff) << 12))
return Dev_t(unix.Mkdev(uint32(major), uint32(minor)))
}

// Majordev returns the major device number given a dev_t, similar to major(3).
func Majordev(device Dev_t) uint64 {
// These values come from new_decode_dev() inside <linux/kdev_t.h>.
return uint64((device & 0xfff00) >> 8)
return uint64(unix.Major(uint64(device)))
}

// Minordev returns the minor device number given a dev_t, similar to minor(3).
func Minordev(device Dev_t) uint64 {
// These values come from new_decode_dev() inside <linux/kdev_t.h>.
return uint64((device & 0xff) | ((device >> 12) & 0xfff00))
return uint64(unix.Minor(uint64(device)))
}

// Mknod is a wrapper around mknod(2).
Expand Down

0 comments on commit 7220123

Please sign in to comment.