home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 9.ddi / usr / include / sys / sysmacros.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-08  |  6.2 KB  |  199 lines

  1. /*    Copyright (c) 1990 UNIX System Laboratories, Inc.    */
  2. /*    Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T    */
  3. /*      All Rights Reserved      */
  4.  
  5. /*    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF         */
  6. /*    UNIX System Laboratories, Inc.                         */
  7. /*    The copyright notice above does not evidence any       */
  8. /*    actual or intended publication of such source code.    */
  9.  
  10. #ifndef _SYS_SYSMACROS_H
  11. #define _SYS_SYSMACROS_H
  12.  
  13. #ident    "@(#)/usr/include/sys/sysmacros.h.sl 1.1 4.0 12/08/90 39923 AT&T-USL"
  14.  
  15. #include <sys/param.h>
  16.  
  17. /* Core clicks to page tables and vice versa */
  18. /* This is still called ctos, etc to avoid large scale
  19.  * changes in the code. "Segment" here means the
  20.  * memory spanned by a page table.
  21.  */
  22.  
  23. #define ctos(x)        (((x) + (NCPPT-1)) >> CPPTSHIFT)
  24. #define    ctost(x)    ((x) >> CPPTSHIFT)
  25. #define    stoc(x)        ((x) * NCPPT)
  26.  
  27. /* Core clicks to segments and vice versa */
  28. #define    ctod(x) ((x)*NDPC)
  29.  
  30. /*
  31.  * Disk blocks (sectors) and bytes.
  32.  */
  33. #define    dtob(DD)    ((DD) << SCTRSHFT)
  34. #define    btod(BB)    (((BB) + NBPSCTR - 1) >> SCTRSHFT)
  35. #define    btodt(BB)    ((BB) >> SCTRSHFT)
  36.  
  37. /*
  38.  * Disk blocks (sectors) and pages.
  39.  */
  40. #define NDPP        8    /* Number of disk blocks per page */
  41. #define DPPSHFT        3    /* Shift for disk blocks per page. */
  42. #define    ptod(PP)    ((PP) << DPPSHFT)
  43. #define    dtop(DD)    (((DD) + NDPP - 1) >> DPPSHFT)
  44. #define dtopt(DD)    ((DD) >> DPPSHFT)
  45.  
  46. /* clicks to bytes */
  47. #ifdef BPCSHIFT
  48. #define    ctob(x)    ((x)<<BPCSHIFT)
  49. #else
  50. #define    ctob(x)    ((x)*NBPC)
  51. #endif
  52.  
  53. /* bytes to clicks */
  54. #ifdef BPCSHIFT
  55. #define    btoc(x)    (((unsigned)(x)+(NBPC-1))>>BPCSHIFT)
  56. #define    btoct(x)    ((unsigned)(x)>>BPCSHIFT)
  57. #else
  58. #define    btoc(x)    (((unsigned)(x)+(NBPC-1))/NBPC)
  59. #define    btoct(x)    ((unsigned)(x)/NBPC)
  60. #endif
  61.  
  62. /* common macros */
  63.  
  64. #define MIN(a, b)    ((a) < (b) ? (a) : (b))
  65. #define MAX(a, b)    ((a) < (b) ? (b) : (a))
  66.  
  67. /* WARNING: The device number macros defined here should not be used by device 
  68. ** drivers or user software. Device drivers should use the device functions
  69. ** defined in the DDI/DKI interface (see also ddi.h). Application software should 
  70. ** make use of the library routines available in makedev(3). A set of new device 
  71. ** macros are provided to operate on the expanded device number format supported
  72. ** in SVR4. Macro versions of the DDI device functions are provided for use by
  73. ** kernel proper routines only. Macro routines bmajor(), major(), minor(),
  74. ** emajor(), eminor(), and makedev() will be removed or their definitions 
  75. ** changed at the next major release following SVR4.
  76. */
  77.  
  78. #define O_BITSMAJOR    7    /* # of SVR3 major device bits */
  79. #define O_BITSMINOR    8    /* # of SVR3 minor device bits */
  80. #define O_MAXMAJ    0x7f    /* SVR3 max major value */
  81. #define O_MAXMIN    0xff    /* SVR3 max major value */
  82.  
  83.  
  84. #define L_BITSMAJOR    14    /* # of SVR4 major device bits */
  85. #define L_BITSMINOR    18    /* # of SVR4 minor device bits */
  86. #define L_MAXMAJ    0xff    /* Although 14 bits are reserved, 
  87.                 ** the 3b2 major number is restricted
  88.                 ** to 8 bits. 
  89.                 */
  90.  
  91. #define L_MAXMIN    0x3ffff    /* MAX minor for 3b2 software drivers.
  92.                 ** For 3b2 hardware devices the minor is
  93.                 ** restricted to 256 (0-255)
  94.                 */
  95.  
  96. #if _KERNEL && u3b2
  97.  
  98. /* major part of a device internal to the kernel */
  99. #define NMAJORENTRY    256    /* Number of entries in major/minor array */
  100.  
  101. extern char MAJOR[NMAJORENTRY];
  102. #define    major(x)    (int)(MAJOR[(unsigned)((x)>>O_BITSMINOR) & O_MAXMAJ])
  103. #define    bmajor(x)    (int)(MAJOR[(unsigned)((x)>>O_BITSMINOR) & O_MAXMAJ])
  104.  
  105. /* get internal major part of expanded device number */
  106.  
  107. #define getmajor(x) (int)(MAJOR[(unsigned)((x)>>L_BITSMINOR) & L_MAXMAJ])
  108.  
  109. /* minor part of a device internal to the kernel */
  110. extern char MINOR[256];
  111. #define    minor(x)    (int)(MINOR[(unsigned)((x)>>O_BITSMINOR)&O_MAXMAJ]+((x)&O_MAXMIN))
  112.  
  113. /* get internal minor part of expanded device number */
  114.  
  115. #define getminor(x) (int)(MINOR[(unsigned)((x)>>L_BITSMINOR)&L_MAXMAJ]+((x)&L_MAXMIN))
  116.  
  117. #else
  118.  
  119. /* major part of a device external from the kernel (same as emajor below) */
  120. #define    major(x)    (int)(((unsigned)x>>O_BITSMINOR)&O_MAXMAJ)
  121. #define    bmajor(x)    (int)(((unsigned)x>>O_BITSMINOR)&O_MAXMAJ)
  122.  
  123.  
  124. /* minor part of a device external from the kernel  (same as eminor below)*/
  125. #define    minor(x)    (int)(x&O_MAXMIN)
  126.  
  127. #endif    /* _KERNEL && u3b2 */
  128.  
  129. /* create old device number */
  130.  
  131. #define    makedev(x,y)    (unsigned short)(((x)<<O_BITSMINOR) | (y&O_MAXMIN))
  132.  
  133. /* make an new device number */
  134.             
  135. #define makedevice(x,y)    (unsigned long)(((x)<<L_BITSMINOR) | ((y)&L_MAXMIN))
  136.  
  137.  
  138. /*
  139.  *   emajor() allows kernel/driver code to print external major numbers
  140.  *   eminor() allows kernel/driver code to print external minor numbers
  141.  */
  142. #define emajor(x)   (int)((((unsigned long)(x)>>O_BITSMINOR) > O_MAXMAJ) ? \
  143.             NODEV : (((unsigned long)(x)>>O_BITSMINOR)&O_MAXMAJ))
  144. #define eminor(x)    (int)((x)&O_MAXMIN)
  145.  
  146. /* get external major and minor device 
  147. ** components from expanded device number
  148. */
  149. #define getemajor(x)    (int)((((unsigned long)(x)>>L_BITSMINOR) > L_MAXMAJ) ? \
  150.             NODEV : (((unsigned long)(x)>>L_BITSMINOR)&L_MAXMAJ))
  151. #define geteminor(x)    (int)((x)&L_MAXMIN)
  152.  
  153.  
  154. /* convert to old dev format */
  155.  
  156. #define cmpdev(x)     (unsigned long)((((x)>>L_BITSMINOR) > O_MAXMAJ || \
  157.                 ((x)&L_MAXMIN) > O_MAXMIN) ? NODEV : \
  158.                 ((((x)>>L_BITSMINOR)<<O_BITSMINOR)|((x)&O_MAXMIN)))
  159.  
  160. /* convert to new dev format */
  161.  
  162. #define expdev(x)     (unsigned long)(((((x)>>O_BITSMINOR)&O_MAXMAJ)<<L_BITSMINOR) \
  163.                 | ((x)&O_MAXMIN))
  164.  
  165. /*
  166.  *  Evaluate to true if the process is an RFS server.
  167.  */
  168. #define    RF_SERVER()    (u.u_procp->p_sysid != 0)
  169.  
  170. /* machine dependent operations - defined for RFS and STREAMS */
  171.  
  172. #ifdef    pdp11
  173. #define    SALIGN(p)        (char *)(((int)p+1) & ~1)
  174. #define    IALIGN(p)        (char *)(((int)p+1) & ~1)
  175. #define LALIGN(p)        (char *)(((int)p+1) & ~3)
  176. #endif
  177. #if    vax | i386
  178. #define    SALIGN(p)        (char *)(((int)p+1) & ~1)
  179. #define    IALIGN(p)        (char *)(((int)p+3) & ~3)
  180. #define    LALIGN(p)        (char *)(((int)p+3) & ~3)
  181. #endif
  182. #ifdef    u3b2
  183. #define    SALIGN(p)        (char *)(((int)p+1) & ~1)
  184. #define    IALIGN(p)        (char *)(((int)p+3) & ~3)
  185. #define    LALIGN(p)        (char *)(((int)p+3) & ~3)
  186. #endif
  187.  
  188. #define SNEXT(p)        (char *)((int)p + sizeof (short))
  189. #define INEXT(p)        (char *)((int)p + sizeof (int))
  190. #define LNEXT(p)        (char *)((int)p + sizeof (long))
  191.  
  192. /*
  193.  * Macros for counting and rounding.
  194.  */
  195. #define howmany(x, y)    (((x)+((y)-1))/(y))
  196. #define roundup(x, y)    ((((x)+((y)-1))/(y))*(y))
  197.  
  198. #endif    /* _SYS_SYSMACROS_H */
  199.