Print this page
6136 sysmacros.h unnecessarily polutes the namespace


  66 #ifdef _KERNEL
  67 
  68 /*
  69  * Convert a single byte to/from binary-coded decimal (BCD).
  70  */
  71 extern unsigned char byte_to_bcd[256];
  72 extern unsigned char bcd_to_byte[256];
  73 
  74 #define BYTE_TO_BCD(x)  byte_to_bcd[(x) & 0xff]
  75 #define BCD_TO_BYTE(x)  bcd_to_byte[(x) & 0xff]
  76 
  77 #endif  /* _KERNEL */
  78 
  79 /*
  80  * WARNING: The device number macros defined here should not be used by device
  81  * drivers or user software. Device drivers should use the device functions
  82  * defined in the DDI/DKI interface (see also ddi.h). Application software
  83  * should make use of the library routines available in makedev(3). A set of
  84  * new device macros are provided to operate on the expanded device number
  85  * format supported in SVR4. Macro versions of the DDI device functions are
  86  * provided for use by kernel proper routines only. Macro routines bmajor(),
  87  * major(), minor(), emajor(), eminor(), and makedev() will be removed or
  88  * their definitions changed at the next major release following SVR4.
  89  */
  90 
  91 #define O_BITSMAJOR     7       /* # of SVR3 major device bits */
  92 #define O_BITSMINOR     8       /* # of SVR3 minor device bits */
  93 #define O_MAXMAJ        0x7f    /* SVR3 max major value */
  94 #define O_MAXMIN        0xff    /* SVR3 max minor value */
  95 
  96 
  97 #define L_BITSMAJOR32   14      /* # of SVR4 major device bits */
  98 #define L_BITSMINOR32   18      /* # of SVR4 minor device bits */
  99 #define L_MAXMAJ32      0x3fff  /* SVR4 max major value */
 100 #define L_MAXMIN32      0x3ffff /* MAX minor for 3b2 software drivers. */
 101                                 /* For 3b2 hardware devices the minor is */
 102                                 /* restricted to 256 (0-255) */
 103 
 104 #ifdef _LP64
 105 #define L_BITSMAJOR     32      /* # of major device bits in 64-bit Solaris */
 106 #define L_BITSMINOR     32      /* # of minor device bits in 64-bit Solaris */
 107 #define L_MAXMAJ        0xfffffffful    /* max major value */
 108 #define L_MAXMIN        0xfffffffful    /* max minor value */
 109 #else
 110 #define L_BITSMAJOR     L_BITSMAJOR32
 111 #define L_BITSMINOR     L_BITSMINOR32
 112 #define L_MAXMAJ        L_MAXMAJ32
 113 #define L_MAXMIN        L_MAXMIN32
 114 #endif
 115 
 116 #ifdef _KERNEL
 117 
 118 /* major part of a device internal to the kernel */
 119 
 120 #define major(x)        (major_t)((((unsigned)(x)) >> O_BITSMINOR) & O_MAXMAJ)
 121 #define bmajor(x)       (major_t)((((unsigned)(x)) >> O_BITSMINOR) & O_MAXMAJ)
 122 
 123 /* get internal major part of expanded device number */
 124 
 125 #define getmajor(x)     (major_t)((((dev_t)(x)) >> L_BITSMINOR) & L_MAXMAJ)
 126 
 127 /* minor part of a device internal to the kernel */
 128 
 129 #define minor(x)        (minor_t)((x) & O_MAXMIN)
 130 
 131 /* get internal minor part of expanded device number */
 132 
 133 #define getminor(x)     (minor_t)((x) & L_MAXMIN)
 134 
 135 #else   /* _KERNEL */
 136 
 137 /* major part of a device external from the kernel (same as emajor below) */
 138 
 139 #define major(x)        (major_t)((((unsigned)(x)) >> O_BITSMINOR) & O_MAXMAJ)
 140 
 141 /* minor part of a device external from the kernel  (same as eminor below) */
 142 
 143 #define minor(x)        (minor_t)((x) & O_MAXMIN)
 144 
 145 #endif  /* _KERNEL */
 146 
 147 /* create old device number */
 148 
 149 #define makedev(x, y) (unsigned short)(((x) << O_BITSMINOR) | ((y) & O_MAXMIN))
 150 
 151 /* make an new device number */
 152 
 153 #define makedevice(x, y) (dev_t)(((dev_t)(x) << L_BITSMINOR) | ((y) & L_MAXMIN))
 154 
 155 
 156 /*
 157  * emajor() allows kernel/driver code to print external major numbers
 158  * eminor() allows kernel/driver code to print external minor numbers
 159  */
 160 
 161 #define emajor(x) \
 162         (major_t)(((unsigned int)(x) >> O_BITSMINOR) > O_MAXMAJ) ? \
 163             NODEV : (((unsigned int)(x) >> O_BITSMINOR) & O_MAXMAJ)
 164 
 165 #define eminor(x) \
 166         (minor_t)((x) & O_MAXMIN)
 167 
 168 /*
 169  * get external major and minor device
 170  * components from expanded device number
 171  */
 172 #define getemajor(x)    (major_t)((((dev_t)(x) >> L_BITSMINOR) > L_MAXMAJ) ? \
 173                             NODEV : (((dev_t)(x) >> L_BITSMINOR) & L_MAXMAJ))
 174 #define geteminor(x)    (minor_t)((x) & L_MAXMIN)
 175 
 176 /*
 177  * These are versions of the kernel routines for compressing and
 178  * expanding long device numbers that don't return errors.
 179  */
 180 #if (L_BITSMAJOR32 == L_BITSMAJOR) && (L_BITSMINOR32 == L_BITSMINOR)
 181 
 182 #define DEVCMPL(x)      (x)
 183 #define DEVEXPL(x)      (x)
 184 
 185 #else
 186 




  66 #ifdef _KERNEL
  67 
  68 /*
  69  * Convert a single byte to/from binary-coded decimal (BCD).
  70  */
  71 extern unsigned char byte_to_bcd[256];
  72 extern unsigned char bcd_to_byte[256];
  73 
  74 #define BYTE_TO_BCD(x)  byte_to_bcd[(x) & 0xff]
  75 #define BCD_TO_BYTE(x)  bcd_to_byte[(x) & 0xff]
  76 
  77 #endif  /* _KERNEL */
  78 
  79 /*
  80  * WARNING: The device number macros defined here should not be used by device
  81  * drivers or user software. Device drivers should use the device functions
  82  * defined in the DDI/DKI interface (see also ddi.h). Application software
  83  * should make use of the library routines available in makedev(3). A set of
  84  * new device macros are provided to operate on the expanded device number
  85  * format supported in SVR4. Macro versions of the DDI device functions are
  86  * provided for use by kernel proper routines only.


  87  */
  88 
  89 #define O_BITSMAJOR     7       /* # of SVR3 major device bits */
  90 #define O_BITSMINOR     8       /* # of SVR3 minor device bits */
  91 #define O_MAXMAJ        0x7f    /* SVR3 max major value */
  92 #define O_MAXMIN        0xff    /* SVR3 max minor value */
  93 
  94 
  95 #define L_BITSMAJOR32   14      /* # of SVR4 major device bits */
  96 #define L_BITSMINOR32   18      /* # of SVR4 minor device bits */
  97 #define L_MAXMAJ32      0x3fff  /* SVR4 max major value */
  98 #define L_MAXMIN32      0x3ffff /* MAX minor for 3b2 software drivers. */
  99                                 /* For 3b2 hardware devices the minor is */
 100                                 /* restricted to 256 (0-255) */
 101 
 102 #ifdef _LP64
 103 #define L_BITSMAJOR     32      /* # of major device bits in 64-bit Solaris */
 104 #define L_BITSMINOR     32      /* # of minor device bits in 64-bit Solaris */
 105 #define L_MAXMAJ        0xfffffffful    /* max major value */
 106 #define L_MAXMIN        0xfffffffful    /* max minor value */
 107 #else
 108 #define L_BITSMAJOR     L_BITSMAJOR32
 109 #define L_BITSMINOR     L_BITSMINOR32
 110 #define L_MAXMAJ        L_MAXMAJ32
 111 #define L_MAXMIN        L_MAXMIN32
 112 #endif
 113 
 114 #ifdef _KERNEL
 115 





 116 /* get internal major part of expanded device number */
 117 
 118 #define getmajor(x)     (major_t)((((dev_t)(x)) >> L_BITSMINOR) & L_MAXMAJ)
 119 




 120 /* get internal minor part of expanded device number */
 121 
 122 #define getminor(x)     (minor_t)((x) & L_MAXMIN)
 123 










 124 #endif  /* _KERNEL */
 125 




 126 /* make an new device number */
 127 
 128 #define makedevice(x, y) (dev_t)(((dev_t)(x) << L_BITSMINOR) | ((y) & L_MAXMIN))













 129 
 130 /*
 131  * get external major and minor device
 132  * components from expanded device number
 133  */
 134 #define getemajor(x)    (major_t)((((dev_t)(x) >> L_BITSMINOR) > L_MAXMAJ) ? \
 135                             NODEV : (((dev_t)(x) >> L_BITSMINOR) & L_MAXMAJ))
 136 #define geteminor(x)    (minor_t)((x) & L_MAXMIN)
 137 
 138 /*
 139  * These are versions of the kernel routines for compressing and
 140  * expanding long device numbers that don't return errors.
 141  */
 142 #if (L_BITSMAJOR32 == L_BITSMAJOR) && (L_BITSMINOR32 == L_BITSMINOR)
 143 
 144 #define DEVCMPL(x)      (x)
 145 #define DEVEXPL(x)      (x)
 146 
 147 #else
 148