home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / UNIX3862.ZIP / U386-06.ZIP / U386-6.TD0 / usr / include / sys / sysmacros.h < prev    next >
Encoding:
C/C++ Source or Header  |  1988-06-26  |  5.2 KB  |  211 lines

  1. /*    Copyright (c) 1984, 1986, 1987, 1988 AT&T    */
  2. /*      All Rights Reserved      */
  3.  
  4. /*    THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T    */
  5. /*    The copyright notice above does not evidence any       */
  6. /*    actual or intended publication of such source code.    */
  7.  
  8. /*    Copyright (c) 1987, 1988 Microsoft Corporation    */
  9. /*      All Rights Reserved    */
  10.  
  11. /*    This Module contains Proprietary Information of Microsoft  */
  12. /*    Corporation and should be treated as Confidential.       */
  13.  
  14. #ident    "@(#)head.sys:sysmacros.h    1.3.1.3"
  15.  
  16. /*
  17.  * Some macros for units conversion
  18.  */
  19.  
  20. /* Core clicks to page tables and vice versa */
  21. /* This is still called ctos, etc to avoid large scale
  22.  * changes in the code. "Segment" here means the
  23.  * memory spanned by a page table.
  24.  */
  25.  
  26. #define    ctos(x)    (((x) + (NCPPT-1)) >> CPPTSHIFT)
  27. #define    ctost(x)    ((x) >> CPPTSHIFT)
  28. #define    stoc(x)    ((x) * NCPPT)
  29.  
  30. /* Core clicks to disk blocks */
  31. #define    ctod(x) ((x)*NDPC)
  32.  
  33. /* inumber to disk address */
  34. #ifdef INOSHIFT
  35. #define    itod(x)    (daddr_t)(((unsigned)(x)+(2*INOPB-1))>>INOSHIFT)
  36. #else
  37. #define    itod(x)    (daddr_t)(((unsigned)(x)+(2*INOPB-1))/INOPB)
  38. #endif
  39.  
  40. /* inumber to disk offset */
  41. #ifdef INOSHIFT
  42. #define    itoo(x)    (int)(((unsigned)(x)+(2*INOPB-1))&(INOPB-1))
  43. #else
  44. #define    itoo(x)    (int)(((unsigned)(x)+(2*INOPB-1))%INOPB)
  45. #endif
  46.  
  47. /* clicks to bytes */
  48. #ifdef BPCSHIFT
  49. #define    ctob(x)    ((x)<<BPCSHIFT)
  50. #else
  51. #define    ctob(x)    ((x)*NBPC)
  52. #endif
  53.  
  54. /* bytes to clicks */
  55. #ifdef BPCSHIFT
  56. #define    btoc(x)    (((unsigned)(x)+(NBPC-1))>>BPCSHIFT)
  57. #define    btoct(x)    ((unsigned)(x)>>BPCSHIFT)
  58. #else
  59. #define    btoc(x)    (((unsigned)(x)+(NBPC-1))/NBPC)
  60. #define    btoct(x)    ((unsigned)(x)/NBPC)
  61. #endif
  62.  
  63. #if INKERNEL && u3b2
  64.  
  65. /* major part of a device internal to the kernel */
  66.  
  67. extern char MAJOR[128];
  68. #define    major(x)    (int)(MAJOR[(unsigned)((x)>>8)&0x7F])
  69. #define    bmajor(x)    (int)(MAJOR[(unsigned)((x)>>8)&0x7F])
  70.  
  71. /* minor part of a device internal to the kernel */
  72. extern char MINOR[128];
  73. #define    minor(x)    (int)(MINOR[(unsigned)((x)>>8)&0x7F]+((x)&0xFF))
  74.  
  75. #else
  76.  
  77. /* major part of a device external from the kernel */
  78. #define    major(x)    (int)((unsigned)((x)>>8)&0x7F)
  79. #define    bmajor(x)    (int)((unsigned)((x)>>8)&0x7F)
  80.  
  81. /* minor part of a device external from the kernel */
  82. #define    minor(x)    (int)(x&0xFF)
  83. #endif    /* INKERNEL && u3b2 */
  84.  
  85. /* make a device number */
  86. #define    makedev(x,y)    (dev_t)(((x)<<8) | (y))
  87.  
  88. /*
  89.  *   emajor() allows kernel/driver code to print external major numbers
  90.  *   eminor() allows kernel/driver code to print external minor numbers
  91.  */
  92. #define emajor(x)    (int)(((unsigned)(x)>>8)&0x7F)
  93. #define eminor(x)    (int)((x)&0xFF)
  94.  
  95. /*    Calculate user process priority.
  96. */
  97.  
  98. #define calcppri(p)    ((p->p_cpu) >> 1) +  p->p_nice + (PUSER - NZERO)
  99.  
  100. /*
  101.  *  Evaluate to true if the process is a server - Distributed UNIX
  102.  */
  103. #define    server()    (u.u_procp->p_sysid != 0)
  104.  
  105. /*
  106.  * Defined for RFS client caching
  107.  */
  108.  
  109. extern int rcacheinit;            /* RFS client caching flag */
  110. extern unsigned long rfs_vcode;        /* version code for RFS caching */
  111.  
  112. #define CLOSEI(ip, flag, count, offset) \
  113. { \
  114.     if (rcacheinit && (ip)->i_ftype == IFREG && (count) == 1 \
  115.         && !server() && (flag) & FWRITE) { \
  116.         (ip)->i_wcnt--; \
  117.         if ((ip)->i_flag & IWROTE && (ip)->i_wcnt == 0) { \
  118.             (ip)->i_flag &= ~IWROTE; \
  119.             if ((ip)->i_rcvd) \
  120.                 enable_cache((ip)->i_rcvd); \
  121.         } \
  122.     } \
  123.     FS_CLOSEI(ip, flag, count, offset); \
  124. }
  125.  
  126. #define OPENI(ip, mode) \
  127. { \
  128.     if (rcacheinit && (ip)->i_ftype == IFREG && !server() && (mode) & FWRITE) \
  129.         (ip)->i_wcnt++; \
  130.     FS_OPENI(ip, mode); \
  131. }
  132.  
  133. #define WRITEI(ip) \
  134. { \
  135.     if (rcacheinit && (ip)->i_ftype == IFREG) { \
  136.         if (!server()) \
  137.             (ip)->i_flag |= IWROTE; \
  138.         (ip)->i_vcode = ++rfs_vcode; \
  139.         if ((ip)->i_rcvd) \
  140.             disable_cache(ip); \
  141.     } \
  142.     FS_WRITEI(ip); \
  143. }
  144.  
  145. #define ITRUNC(ip) \
  146. { \
  147.     if (rcacheinit && (ip)->i_ftype == IFREG) { \
  148.         if (!server()) \
  149.             (ip)->i_flag |= IWROTE; \
  150.         (ip)->i_vcode = ++rfs_vcode; \
  151.         if ((ip)->i_rcvd) \
  152.             disable_cache(ip); \
  153.     } \
  154.     FS_ITRUNC(ip); \
  155. }
  156.  
  157. #define IPUT(ip) \
  158. { \
  159.     if (rcacheinit && (ip)->i_nlink <= 0 && (ip)->i_count == 1) { \
  160.         (ip)->i_vcode = ++rfs_vcode; \
  161.     } \
  162.     FS_IPUT(ip); \
  163. }
  164.  
  165. #define FREESP(ip, arg, flag, offset) \
  166. { \
  167.     if (rcacheinit && (ip)->i_ftype == IFREG) { \
  168.         if (!server()) \
  169.             (ip)->i_flag |= IWROTE; \
  170.         (ip)->i_vcode = ++rfs_vcode; \
  171.         if ((ip)->i_rcvd) \
  172.             disable_cache(ip); \
  173.     } \
  174.     FS_FCNTL(ip, F_FREESP, arg, flag, offset); \
  175. }
  176. #define CHSIZE(ip, arg, flag, offset) \
  177. { \
  178.     if (rcacheinit && (ip)->i_ftype == IFREG) { \
  179.         if (!server()) \
  180.             (ip)->i_flag |= IWROTE; \
  181.         (ip)->i_vcode = ++rfs_vcode; \
  182.         if ((ip)->i_rcvd) \
  183.             disable_cache(ip); \
  184.     } \
  185.     FS_FCNTL(ip, F_CHSIZE, arg, flag, offset); \
  186. }
  187.  
  188.  
  189. /* machine dependent operations - defined for RFS and STREAMS */
  190.  
  191. #ifdef    pdp11
  192. #define    SALIGN(p)        (char *)(((int)p+1) & ~1)
  193. #define    IALIGN(p)        (char *)(((int)p+1) & ~1)
  194. #define LALIGN(p)        (char *)(((int)p+1) & ~3)
  195. #endif
  196. #if vax | i386
  197. #define    SALIGN(p)        (char *)(((int)p+1) & ~1)
  198. #define    IALIGN(p)        (char *)(((int)p+3) & ~3)
  199. #define    LALIGN(p)        (char *)(((int)p+3) & ~3)
  200. #endif
  201. #ifdef    u3b2
  202. #define    SALIGN(p)        (char *)(((int)p+1) & ~1)
  203. #define    IALIGN(p)        (char *)(((int)p+3) & ~3)
  204. #define    LALIGN(p)        (char *)(((int)p+3) & ~3)
  205. #endif
  206.  
  207. #define SNEXT(p)        (char *)((int)p + sizeof (short))
  208. #define INEXT(p)        (char *)((int)p + sizeof (int))
  209. #define LNEXT(p)        (char *)((int)p + sizeof (long))
  210.  
  211.