Debian Codegraph @

abi/linux/dev.go

raw symbols SCIP
1 // Copyright 2018 The gVisor Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package linux
16
17 // MakeDeviceID encodes a major and minor device number into a single device ID.
18 //
19 // Format (see linux/kdev_t.h:new_encode_dev):
20 //
21 // Bits 7:0 - minor bits 7:0
22 // Bits 19:8 - major bits 11:0
23 // Bits 31:20 - minor bits 19:8
24 func MakeDeviceID(major uint16, minor uint32) uint32 {
25 return (minor & 0xff) | ((uint32(major) & 0xfff) << 8) | ((minor >> 8) << 20)
26 }
27
28 // DecodeDeviceID decodes a device ID into major and minor device numbers.
29 func DecodeDeviceID(rdev uint32) (uint16, uint32) {
30 major := uint16((rdev >> 8) & 0xfff)
31 minor := (rdev & 0xff) | ((rdev >> 20) << 8)
32 return major, minor
33 }
34
35 // Character device IDs.
36 //
37 // See Documentations/devices.txt and uapi/linux/major.h.
38 const (
39 // UNNAMED_MAJOR is the major device number for "unnamed" devices, whose
40 // minor numbers are dynamically allocated by the kernel.
41 UNNAMED_MAJOR = 0
42
43 // MEM_MAJOR is the major device number for "memory" character devices.
44 MEM_MAJOR = 1
45
46 // TTYAUX_MAJOR is the major device number for alternate TTY devices.
47 TTYAUX_MAJOR = 5
48
49 // MISC_MAJOR is the major device number for non-serial mice, misc feature
50 // devices.
51 MISC_MAJOR = 10
52
53 // UNIX98_PTY_MASTER_MAJOR is the initial major device number for
54 // Unix98 PTY masters.
55 UNIX98_PTY_MASTER_MAJOR = 128
56
57 // UNIX98_PTY_REPLICA_MAJOR is the initial major device number for
58 // Unix98 PTY replicas.
59 UNIX98_PTY_REPLICA_MAJOR = 136
60 )
61
62 // Minor device numbers for TTYAUX_MAJOR.
63 const (
64 // PTMX_MINOR is the minor device number for /dev/ptmx.
65 PTMX_MINOR = 2
66 )