New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/sys/unix: no major, minor, and mkdev functions #8106
Comments
Hopefully the bit-fiddling is all right here: https://github.com/dotcloud/docker/pull/4191/files#diff-6ce9e79ddb91a3f06352abe1f2c72ecbR468 func Major(devNumber int) int64{ return int64((devNumber >> 8) & 0xfff) } func Minor(devNumber int) int64{ return int64((devNumber & 0xff) | ((devNumber >> 12) & 0xfff00)) } func Mkdev(majorNumber int64,minorNumber int64) int{ return int((majorNumber << 8) | (minorNumber & 0xff) | ((minorNumber & 0xfff00) << 12)) } Not so sure about the last one, as I wrote it myself and I don't really understand the format of the numbers and I am not an expert at bit fiddling. |
The functions in comment 2 might work for Linux, but FreeBSD is different, as are most likely other flavours of Unix. Whilst Linux (2.6+) specifies 12 bits for the major number and 20 bits for the minor number, FreeBSD states:
(https://www.freebsd.org/cgi/man.cgi?query=major()&sektion=#end) Also, if we're being pedantic, shouldn't the functions take (and return) uint64 instead, so as to comply with https://golang.org/pkg/syscall/#Stat_t ? |
CL https://golang.org/cl/50550 mentions this issue. |
I sent CL https://golang.org/cl/50550 adding the requested functions on Linux. For FreeBSD, the macros in https://github.com/freebsd/freebsd/blob/master/sys/sys/types.h#L372-L374 could possibly be re-implemented in x/sys/unix. As I don't have a FreeBSD system at hand for testing, I didn't add them though. |
After a bit of searching, I found the macros that Darwin uses. It looks to be more or less the same as BSD, which is not that big of a surprise. #define major(x) ((int32_t)(((u_int32_t)(x) >> 24) & 0xff))
#define minor(x) ((int32_t)((x) & 0xffffff))
#define makedev(x,y) ((dev_t)(((x) << 24) | (y))) (https://github.com/apple/darwin-xnu/blob/master/bsd/sys/types.h) |
Change https://golang.org/cl/60610 mentions this issue: |
Add Major, Minor and Mkdev functions for converting devices numbers to their major/minor components and vice versa. The functions follow the behavior of the macros defined in Darwin's sys/types.h header. However, the parameter and return types are changed to match the respective Linux implementation of these functions. Test the conversion macros with some well-known static device numbers for devices which should be present on any Darwin system. Updates golang/go#8106 Change-Id: I1862be64684cc1b5a53e15a883819571e368cb2b Reviewed-on: https://go-review.googlesource.com/60610 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Change https://golang.org/cl/60970 mentions this issue: |
Add Major, Minor and Mkdev functions for converting devices numbers to their major/minor components and vice versa. The functions follow the behavior of the macros defined in NetBSD's sys/types.h header. However, the parameter and return types are changed to match the existing implementations of these functions. Test the conversion macros with some well-known device numbers. Updates golang/go#8106 Change-Id: I536d6d2622f6fe9be3c1ed3beb266745fe4bfb6e Reviewed-on: https://go-review.googlesource.com/60970 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Change https://golang.org/cl/61631 mentions this issue: |
Change https://golang.org/cl/61630 mentions this issue: |
Add Major, Minor and Mkdev functions for converting devices numbers to their major/minor components and vice versa. The functions follow the behavior of the macros defined in DragonFlyBSD's sys/types.h header. However, the parameter and return types are changed to match the existing implementations of these functions. Test the conversion macros with some well-known device numbers. Updates golang/go#8106 Change-Id: I84c128dff3108821caaa75dcec620cf5bdb1f32d Reviewed-on: https://go-review.googlesource.com/61630 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Add Major, Minor and Mkdev functions for converting devices numbers to their major/minor components and vice versa. The functions follow the behavior of the macros defined in FreeBSD's sys/types.h header. However, the parameter and return types are changed to match the existing implementations of these functions. Because FreeBSD dynamically allocates major/minor device numbers through devfs at runtime, testing the conversion macros against well-known device numbers is not possible. Updates golang/go#8106 Change-Id: I9874e63f388cfc5c0d5cc47d4d0f6ccc489b28f2 Reviewed-on: https://go-review.googlesource.com/61631 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Add Major, Minor and Mkdev functions for converting devices numbers to their major/minor components and vice versa. The functions follow the behavior of glibc's corresponding macros. Also add an explanatory comment about the device number format, so the magic numbers make more sense. Test the conversion macros with some well-known device numbers for devices which should be present on any Linux system. Fixes golang/go#8106 Change-Id: Id336317985d6ac85ee83bc54e5f23703257c9121 Reviewed-on: https://go-review.googlesource.com/50550 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Add Major, Minor and Mkdev functions for converting devices numbers to their major/minor components and vice versa. The functions follow the behavior of the macros defined in Darwin's sys/types.h header. However, the parameter and return types are changed to match the respective Linux implementation of these functions. Test the conversion macros with some well-known static device numbers for devices which should be present on any Darwin system. Updates golang/go#8106 Change-Id: I1862be64684cc1b5a53e15a883819571e368cb2b Reviewed-on: https://go-review.googlesource.com/60610 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Add Major, Minor and Mkdev functions for converting devices numbers to their major/minor components and vice versa. The functions follow the behavior of the macros defined in NetBSD's sys/types.h header. However, the parameter and return types are changed to match the existing implementations of these functions. Test the conversion macros with some well-known device numbers. Updates golang/go#8106 Change-Id: I536d6d2622f6fe9be3c1ed3beb266745fe4bfb6e Reviewed-on: https://go-review.googlesource.com/60970 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Add Major, Minor and Mkdev functions for converting devices numbers to their major/minor components and vice versa. The functions follow the behavior of the macros defined in DragonFlyBSD's sys/types.h header. However, the parameter and return types are changed to match the existing implementations of these functions. Test the conversion macros with some well-known device numbers. Updates golang/go#8106 Change-Id: I84c128dff3108821caaa75dcec620cf5bdb1f32d Reviewed-on: https://go-review.googlesource.com/61630 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Add Major, Minor and Mkdev functions for converting devices numbers to their major/minor components and vice versa. The functions follow the behavior of the macros defined in FreeBSD's sys/types.h header. However, the parameter and return types are changed to match the existing implementations of these functions. Because FreeBSD dynamically allocates major/minor device numbers through devfs at runtime, testing the conversion macros against well-known device numbers is not possible. Updates golang/go#8106 Change-Id: I9874e63f388cfc5c0d5cc47d4d0f6ccc489b28f2 Reviewed-on: https://go-review.googlesource.com/61631 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Change https://golang.org/cl/63070 mentions this issue: |
Add Major, Minor and Mkdev functions for converting devices numbers to their major/minor components and vice versa. The functions follow the behavior of the macros defined in OpenBSD's sys/types.h header. However, the parameter and return types are changed to match the existing implementations of these functions. Test the conversion macros with some well-known device numbers. Updates golang/go#8106 Change-Id: Ia50b7ccab18ff7c7e9dd77ddc7e4aa6cf5c79963 Reviewed-on: https://go-review.googlesource.com/63070 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
by tim.thelion:
The text was updated successfully, but these errors were encountered: