DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
SVR5

makedevice(D3)


makedevice -- make device number from major and minor numbers

Synopsis (Not in current DDI version)

   #include <sys/types.h>
   #include <sys/ddi.h>
   

dev_t makedevice(major_t majnum, minor_t minnum);

Description

The makedevice function creates a device number from major and minor device numbers.

Arguments


majnum
Major number.

minnum
Minor number.

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.

Usage

makedevice should be used to create device numbers so that the driver will port easily to releases that treat device numbers differently.

Context and synchronization

All contexts.

Hardware applicability

All

Version applicability

ddi: 1, 2, 3, 4, 5, 5mp, 6, 6mp, 7, 7mp, 7.1, 7.1mp

Differences between versions

makedevice( ) is not supported in DDI 8; drivers can access similar information through the resmgr key and channel number. See ``Device number'' in HDK Technical Reference.

References

getemajor(D3), geteminor(D3), getmajor(D3), getminor(D3)

Examples

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;

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	pl_t 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 } ...


19 June 2005
© 2005 The SCO Group, Inc. All rights reserved.
OpenServer 6 and UnixWare (SVR5) HDK - June 2005