makedevice(D3)makedevice(D3)NAMEmakedevice - make device number from major and minor numbers
SYNOPSIS
#include <sys/types.h>
#include <sys/ddi.h>
dev_t makedevice(major_t majnum, minor_t minnum);
Arguments
majnum Major number.
minnum Minor number.
DESCRIPTION
The makedevice function creates a device number from major and minor
device numbers.
Return Values
The device number, containing both the major number and the minor number,
is returned. No validation of the major or minor numbers is performed.
USAGEmakedevice should be used to create device numbers so that the driver
will port easily to releases that treat device numbers differently.
Level
Initialization, Base or Interrupt.
Synchronization Constraints
Does not sleep.
Driver-defined basic locks, read/write locks, and sleep locks may be held
across calls to this function.
Singlethreaded Example
In the following example, makedevice is used to create the device number
selected during a clone open. If the CLONEOPEN flag is set (line 9), we
search through the list of minor devices looking for one that is
available (lines 10-11). If we find an unused minor, we break off the
search, create a new device number, and store it in the memory location
pointed to by devp (line 15). If no unused minor was found, we return
the error ENXIO.
1 xxxopen(q, devp, oflag, sflag, crp)
2 queue_t *q;
3 dev_t *devp;
4 int oflag;
5 int sflag;
6 cred_t *crp;
7 {
8 minor_t minnum;
Page 1
makedevice(D3)makedevice(D3)
9 if (sflag == CLONEOPEN) {
10 for (minnum = 0; minnum < XXXMAXMIN; minnum++)
11 if (!INUSE(minnum))
12 break;
13 if (minnum >= XXXMAXMIN)
14 return(ENXIO);
15 SETINUSE(minnum);
16 *devp = makedevice(getemajor(*devp), minnum);
17 }
...
Multithreaded Example
In the following example, makedevice is used to create the device number
selected during a clone open. If the CLONEOPEN flag is set (line 11), we
lock the list of minor devices (line 12) and search through the list,
looking for a minor device that is available (lines 13-14). If we find
an unused minor, we break off the search, mark the minor as being in use
(line 20), unlock the list, create a new device number, and store it in
the memory location pointed to by devp (line 22). If no unused minor was
found, we unlock the list and return the error ENXIO.
1 xxxopen(q, devp, oflag, sflag, crp)
2 queue_t *q;
3 dev_t *devp;
4 int oflag;
5 int sflag;
6 cred_t *crp;
7 {
8 minor_t minnum;
9 int pl;
10 extern lock_t *xxxminlock;
11 if (sflag == CLONEOPEN) {
12 pl = LOCK(xxxminlock, plstr);
13 for (minnum = 0; minnum < XXXMAXMIN; minnum++)
14 if (!INUSE(minnum))
15 break;
16 if (minnum >= XXXMAXMIN) {
17 UNLOCK(xxxminlock, pl);
18 return(ENXIO);
19 } else {
20 SETINUSE(minnum);
21 UNLOCK(xxxminlock, pl);
22 *devp = makedevice(getemajor(*devp), minnum);
23 }
24 }
...
REFERENCESgetemajor(D3), geteminor(D3), getmajor(D3), getminor(D3)
Page 2