xref: /freebsd-src/share/man/man3/makedev.3 (revision 1a720cbec513210fa2e85c3882741ef2f6dc5f35)
166c6ebfeSEd Schouten.\" Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org>
266c6ebfeSEd Schouten.\" All rights reserved.
366c6ebfeSEd Schouten.\"
466c6ebfeSEd Schouten.\" Redistribution and use in source and binary forms, with or without
566c6ebfeSEd Schouten.\" modification, are permitted provided that the following conditions
666c6ebfeSEd Schouten.\" are met:
766c6ebfeSEd Schouten.\" 1. Redistributions of source code must retain the above copyright
866c6ebfeSEd Schouten.\"    notice, this list of conditions and the following disclaimer.
966c6ebfeSEd Schouten.\" 2. Redistributions in binary form must reproduce the above copyright
1066c6ebfeSEd Schouten.\"    notice, this list of conditions and the following disclaimer in the
1166c6ebfeSEd Schouten.\"    documentation and/or other materials provided with the distribution.
1266c6ebfeSEd Schouten.\"
1366c6ebfeSEd Schouten.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1466c6ebfeSEd Schouten.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1566c6ebfeSEd Schouten.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1666c6ebfeSEd Schouten.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1766c6ebfeSEd Schouten.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1866c6ebfeSEd Schouten.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1966c6ebfeSEd Schouten.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2066c6ebfeSEd Schouten.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2166c6ebfeSEd Schouten.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2266c6ebfeSEd Schouten.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2366c6ebfeSEd Schouten.\" SUCH DAMAGE.
2466c6ebfeSEd Schouten.\"
251e94ddb4SKonstantin Belousov.Dd August 3, 2017
2666c6ebfeSEd Schouten.Dt MAKEDEV 3
2766c6ebfeSEd Schouten.Os
2866c6ebfeSEd Schouten.Sh NAME
2966c6ebfeSEd Schouten.Nm makedev ,
3066c6ebfeSEd Schouten.Nm major ,
3166c6ebfeSEd Schouten.Nm minor
3266c6ebfeSEd Schouten.Nd device number conversion
3366c6ebfeSEd Schouten.Sh SYNOPSIS
3466c6ebfeSEd Schouten.In sys/types.h
3566c6ebfeSEd Schouten.Ft dev_t
3666c6ebfeSEd Schouten.Fn makedev "int major" "int minor"
3766c6ebfeSEd Schouten.Ft int
3866c6ebfeSEd Schouten.Fn major "dev_t dev"
3966c6ebfeSEd Schouten.Ft int
4066c6ebfeSEd Schouten.Fn minor "dev_t dev"
4166c6ebfeSEd Schouten.Sh DESCRIPTION
4266c6ebfeSEd SchoutenThe
4366c6ebfeSEd Schouten.Fn makedev
441e94ddb4SKonstantin Belousovmacro returns a device number created from the provided
4566c6ebfeSEd Schouten.Fa major
4666c6ebfeSEd Schoutenand
4766c6ebfeSEd Schouten.Fa minor
4866c6ebfeSEd Schoutennumber.
4966c6ebfeSEd SchoutenThe
5066c6ebfeSEd Schouten.Fn major
5166c6ebfeSEd Schoutenand
5266c6ebfeSEd Schouten.Fn minor
531e94ddb4SKonstantin Belousovmacros return the original numbers from the device number
5466c6ebfeSEd Schouten.Fa dev .
551e94ddb4SKonstantin BelousovIn other words, for a value
561e94ddb4SKonstantin Belousov.Va dev
571e94ddb4SKonstantin Belousovof the type
581e94ddb4SKonstantin Belousov.Vt dev_t ,
591e94ddb4SKonstantin Belousovand values
601e94ddb4SKonstantin Belousov.Va ma , mi
611e94ddb4SKonstantin Belousovof the type
621e94ddb4SKonstantin Belousov.Vt int ,
631e94ddb4SKonstantin Belousovthe assertions
641e94ddb4SKonstantin Belousov.Dl dev == makedev(major(dev), minor(dev))
651e94ddb4SKonstantin Belousov.Dl ma == major(makedev(ma, mi))
661e94ddb4SKonstantin Belousov.Dl mi == minor(makedev(ma, mi))
671e94ddb4SKonstantin Belousovare valid.
6866c6ebfeSEd Schouten.Pp
6966c6ebfeSEd SchoutenIn previous implementations of
7066c6ebfeSEd Schouten.Fx
7166c6ebfeSEd Schoutenall block and character devices were uniquely identified by a pair of
721e94ddb4SKonstantin Belousovstable major and minor numbers.
7366c6ebfeSEd SchoutenThe major number referred to a certain device class (e.g. disks, TTYs)
7466c6ebfeSEd Schoutenwhile the minor number identified an instance within the device class.
7566c6ebfeSEd SchoutenLater versions of
7666c6ebfeSEd Schouten.Fx
7766c6ebfeSEd Schoutenautomatically generate a unique device number for each character device
7866c6ebfeSEd Schoutenvisible in
7966c6ebfeSEd Schouten.Pa /dev/ .
801e94ddb4SKonstantin BelousovThese numbers are not divided in device classes and are not guaranteed
811e94ddb4SKonstantin Belousovto be stable upon reboot or driver reload.
8266c6ebfeSEd Schouten.Pp
8366c6ebfeSEd SchoutenOn
8466c6ebfeSEd Schouten.Fx
8566c6ebfeSEd Schoutenthese macros are only used by utilities that need to exchange numbers
8666c6ebfeSEd Schoutenwith other operating systems that may use different encodings for
8766c6ebfeSEd Schouten.Vt dev_t ,
8866c6ebfeSEd Schoutenbut also applications that present these numbers to the user in a more
8966c6ebfeSEd Schoutenconventional way.
9066c6ebfeSEd Schouten.Sh RETURN VALUES
9166c6ebfeSEd SchoutenThe
9266c6ebfeSEd Schouten.Fn major
931e94ddb4SKonstantin Belousovand
9466c6ebfeSEd Schouten.Fn minor
951e94ddb4SKonstantin Belousovmacros return numbers whose value can span the complete range of an
9666c6ebfeSEd Schouten.Vt int .
9766c6ebfeSEd Schouten.Sh SEE ALSO
98e52a1af2SBaptiste Daroussin.Xr mknod 2 ,
992c3fbde1SEd Schouten.Xr devname 3 ,
100*1a720cbeSAlexander Ziaee.Xr devfs 4
101