aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/sys/unix/dev_linux.go
diff options
context:
space:
mode:
authorLibravatar Rutger Broekhoff2023-12-29 21:31:53 +0100
committerLibravatar Rutger Broekhoff2023-12-29 21:31:53 +0100
commit404aeae4545d2426c089a5f8d5e82dae56f5212b (patch)
tree2d84e00af272b39fc04f3795ae06bc48970e57b5 /vendor/golang.org/x/sys/unix/dev_linux.go
parent209d8b0187ed025dec9ac149ebcced3462877bff (diff)
downloadgitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.tar.gz
gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.zip
Make Nix builds work
Diffstat (limited to 'vendor/golang.org/x/sys/unix/dev_linux.go')
-rw-r--r--vendor/golang.org/x/sys/unix/dev_linux.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/vendor/golang.org/x/sys/unix/dev_linux.go b/vendor/golang.org/x/sys/unix/dev_linux.go
new file mode 100644
index 0000000..d165d6f
--- /dev/null
+++ b/vendor/golang.org/x/sys/unix/dev_linux.go
@@ -0,0 +1,42 @@
1// Copyright 2017 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// Functions to access/create device major and minor numbers matching the
6// encoding used by the Linux kernel and glibc.
7//
8// The information below is extracted and adapted from bits/sysmacros.h in the
9// glibc sources:
10//
11// dev_t in glibc is 64-bit, with 32-bit major and minor numbers. glibc's
12// default encoding is MMMM Mmmm mmmM MMmm, where M is a hex digit of the major
13// number and m is a hex digit of the minor number. This is backward compatible
14// with legacy systems where dev_t is 16 bits wide, encoded as MMmm. It is also
15// backward compatible with the Linux kernel, which for some architectures uses
16// 32-bit dev_t, encoded as mmmM MMmm.
17
18package unix
19
20// Major returns the major component of a Linux device number.
21func Major(dev uint64) uint32 {
22 major := uint32((dev & 0x00000000000fff00) >> 8)
23 major |= uint32((dev & 0xfffff00000000000) >> 32)
24 return major
25}
26
27// Minor returns the minor component of a Linux device number.
28func Minor(dev uint64) uint32 {
29 minor := uint32((dev & 0x00000000000000ff) >> 0)
30 minor |= uint32((dev & 0x00000ffffff00000) >> 12)
31 return minor
32}
33
34// Mkdev returns a Linux device number generated from the given major and minor
35// components.
36func Mkdev(major, minor uint32) uint64 {
37 dev := (uint64(major) & 0x00000fff) << 8
38 dev |= (uint64(major) & 0xfffff000) << 32
39 dev |= (uint64(minor) & 0x000000ff) << 0
40 dev |= (uint64(minor) & 0xffffff00) << 12
41 return dev
42}