home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 9.ddi / usr / include / sys / strsubr.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-08  |  12.8 KB  |  471 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_STRSUBR_H
  11. #define _SYS_STRSUBR_H
  12.  
  13. #ident    "@(#)/usr/include/sys/strsubr.h.sl 1.1 4.0 12/08/90 25230 AT&T-USL"
  14.  
  15. /*
  16.  * WARNING:
  17.  * Everything in this file is private, belonging to the
  18.  * STREAMS subsystem.  The only guarantee made about the
  19.  * contents of this file is that if you include it, your
  20.  * code will not port to the next release.
  21.  */
  22. #include <sys/vnode.h>
  23. #include <sys/evecb.h>
  24.  
  25. /*
  26.  * Header for a stream: interface to rest of system.
  27.  */
  28. typedef struct stdata {
  29.     struct queue *sd_wrq;        /* write queue */
  30.     struct msgb *sd_iocblk;        /* return block for ioctl */
  31.     struct vnode *sd_vnode;        /* pointer to associated vnode */
  32.     struct streamtab *sd_strtab;    /* pointer to streamtab for stream */
  33.     long sd_flag;            /* state/flags */
  34.     long sd_iocid;            /* ioctl id */
  35.     ushort sd_iocwait;        /* count of procs waiting to do ioctl */
  36.     struct pid *sd_sidp;        /* controlling session info */
  37.     struct pid *sd_pgidp;        /* controlling process group info */
  38.     ushort sd_wroff;        /* write offset */
  39.     int sd_rerror;            /* read error to set u.u_error */
  40.     int sd_werror;            /* write error to set u.u_error */
  41.     int sd_pushcnt;            /* number of pushes done on stream */
  42.     int sd_sigflags;        /* logical OR of all siglist events */
  43.     struct strevent *sd_siglist;    /* pid linked list to rcv SIGPOLL sig */
  44.     int sd_eventflags;        /* logical OR of all eventlist events */
  45.     struct strevent *sd_eventlist;    /* linked list to rcv general events */
  46.     struct pollhead sd_pollist;    /* list of all pollers to wake up */
  47.     struct msgb *sd_mark;        /* "marked" message on read queue */
  48.     int sd_closetime;        /* time to wait to drain q in close */
  49.     clock_t sd_rtime;        /* time to release held message */
  50. } stdata_t;
  51.  
  52. /*
  53.  * stdata flag field defines
  54.  */
  55. #define    IOCWAIT        0x00000001    /* Someone wants to do ioctl */
  56. #define RSLEEP        0x00000002    /* Someone wants to read/recv msg */
  57. #define    WSLEEP        0x00000004    /* Someone wants to write */
  58. #define STRPRI        0x00000008    /* An M_PCPROTO is at stream head */
  59. #define    STRHUP        0x00000010    /* Device has vanished */
  60. #define    STWOPEN        0x00000020    /* waiting for 1st open */
  61. #define STPLEX        0x00000040    /* stream is being multiplexed */
  62. #define STRISTTY    0x00000080    /* stream is a terminal */
  63. #define RMSGDIS        0x00000100    /* read msg discard */
  64. #define RMSGNODIS    0x00000200    /* read msg no discard */
  65. #define STRDERR        0x00000400    /* fatal read error from M_ERROR */
  66. #define STRTIME        0x00000800    /* used with timeout strtime */
  67. #define STR2TIME    0x00001000    /* used with timeout str2time */
  68. #define STR3TIME    0x00002000    /* used with timeout str3time */
  69. #define STRCLOSE    0x00004000    /* wait for a close to complete */
  70. #define SNDMREAD    0x00008000    /* used for read notification */
  71. #define OLDNDELAY    0x00010000    /* use old TTY semantics for NDELAY
  72.                     /* reads and writes */
  73. #define RDBUFWAIT    0x00020000    /* used with bufcall in strqbuf() */
  74. #define STRSNDZERO    0x00040000    /* send 0-length msg. down pipe/FIFO */
  75. #define STRTOSTOP    0x00080000    /* block background writes */
  76. #define    RDPROTDAT    0x00100000    /* read M_[PC]PROTO contents as data */
  77. #define RDPROTDIS    0x00200000    /* discard M_[PC]PROTO blocks and */
  78.                     /* retain data blocks */
  79. #define STRMOUNT    0x00400000    /* stream is mounted */
  80. #define STRSIGPIPE        0x00800000    /* controlling process not group */
  81. #define STRDELIM    0x01000000    /* generate delimited messages */
  82. #define STWRERR        0x02000000    /* fatal write error from M_ERROR */
  83. #define STRHOLD        0x04000000    /* enable strwrite message coalescing */
  84.  
  85.  
  86. /*
  87.  * Structure of list of processes to be sent SIGSEL signal
  88.  * on request, or for processes sleeping on select().  The valid 
  89.  * SIGSEL events are defined in stropts.h, and the valid select()
  90.  * events are defined in select.h.
  91.  */
  92. struct strevent {
  93.     union {
  94.         struct {
  95.             struct proc    *procp;
  96.             long        events;
  97.         } e;    /* stream event */
  98.         struct {
  99.             void (*func)();
  100.             long arg;
  101.             int size;
  102.         } b;    /* bufcall event */
  103.         struct {
  104.             vnode_t        *vp;
  105.             ecb_t         ecb;
  106.             pid_t         pid;
  107.             hostid_t     hostid;
  108.             uid_t         uid;
  109.             long         mask;
  110.             unchar         band;
  111.         } g;    /* general events mechanism */
  112.     } x;
  113.     struct strevent *se_next;
  114. };
  115.  
  116. #define se_procp    x.e.procp
  117. #define se_events    x.e.events
  118. #define se_func        x.b.func
  119. #define se_arg        x.b.arg
  120. #define se_size        x.b.size
  121. #define se_vp        x.g.vp
  122. #define se_kecb        x.g.ecb        /* name collision with struct str_sev */
  123. #define se_pid        x.g.pid
  124. #define se_hostid    x.g.hostid
  125. #define se_uid        x.g.uid
  126. #define se_kmask    x.g.mask    /* name collision with struct str_sev */
  127. #define se_kband    x.g.band    /* name collision with struct str_sev */
  128.  
  129. #define SE_SLEEP    0    /* ok to sleep in allocation */
  130. #define SE_NOSLP    1    /* don't sleep in allocation */
  131.  
  132. /*
  133.  * bufcall list
  134.  */
  135. struct bclist {
  136.     struct strevent    *bc_head;
  137.     struct strevent    *bc_tail;
  138. };
  139.  
  140. /*
  141.  * Structure used to track mux links and unlinks.
  142.  */
  143. struct mux_node {
  144.     long         mn_imaj;    /* internal major device number */
  145.     ushort         mn_indegree;    /* number of incoming edges */
  146.     struct mux_node *mn_originp;    /* where we came from during search */
  147.     struct mux_edge *mn_startp;    /* where search left off in mn_outp */
  148.     struct mux_edge *mn_outp;    /* list of outgoing edges */
  149.     uint         mn_flags;    /* see below */
  150. };
  151.  
  152. /*
  153.  * Flags for mux_nodes.
  154.  */
  155. #define VISITED    1
  156.  
  157. /*
  158.  * Edge structure - a list of these is hung off the
  159.  * mux_node to represent the outgoing edges.
  160.  */
  161. struct mux_edge {
  162.     struct mux_node    *me_nodep;    /* edge leads to this node */
  163.     struct mux_edge    *me_nextp;    /* next edge */
  164.     int         me_muxid;    /* id of link */
  165. };
  166.  
  167. /*
  168.  * Structure to keep track of resources that have been allocated
  169.  * for streams - an array of these are kept, one entry per
  170.  * resource.  This is used by crash to dump the data structures.
  171.  */
  172.  
  173. struct strinfo {
  174.     void    *sd_head;    /* head of in-use list */
  175.     int    sd_cnt;        /* total # allocated */
  176. };
  177.  
  178. #define DYN_STREAM    0    /* for stream heads */
  179. #define DYN_QUEUE    1    /* for queues */
  180. #define DYN_MSGBLOCK    2    /* for message blocks */
  181. #define DYN_MDBBLOCK    3    /* for mesg/data/buffer triplets */
  182. #define DYN_LINKBLK    4    /* for mux links */
  183. #define DYN_STREVENT    5    /* for stream event cells */
  184. #define DYN_QBAND    6    /* for qband structures */
  185.  
  186. #define NDYNAMIC    7    /* number of different data types that are */
  187.                 /* dynamically allocated */
  188.  
  189. /*
  190.  * The following structures are mainly used to keep track of
  191.  * the resources that have been allocated so crash can find
  192.  * them (they are stored in a doubly-linked list with the head
  193.  * of it stored in the Strinfo array.  Other data may be stored
  194.  * away here too since this is private to streams.  Pointers
  195.  * to these objects are returned by the allocating procedures,
  196.  * which are later passed to the freeing routine.  The data
  197.  * structure itself must appear first because the pointer is
  198.  * overloaded to refer to both the structure itself or its
  199.  * envelope, depending on context.
  200.  */
  201.  
  202. /*
  203.  * Stream head info
  204.  */
  205. struct shinfo {
  206.     stdata_t    sh_stdata;    /* must be first */
  207.     struct shinfo    *sh_next;    /* next in list */
  208.     struct shinfo    *sh_prev;    /* previous in list */
  209. };
  210.  
  211. /*
  212.  * data block info
  213.  */
  214. #ifdef DEBUG
  215. struct dbinfo {
  216.     dblk_t    d_dblock;    /* the data block itself */
  217.     struct dbinfo *d_next;    /* next data block */
  218.     struct dbinfo *d_prev;    /* previous */
  219. };
  220.  
  221. /*
  222.  * message block info
  223.  */
  224. struct mbinfo {
  225.     mblk_t    m_mblock;    /* the message block itself */
  226.     struct mbinfo *m_next;    /* next message block */
  227.     struct mbinfo *m_prev;    /* previous message block */
  228.     void    (*m_func)();    /* address of allocation function */    
  229. };
  230. #else
  231. /*
  232.  * data block info
  233.  */
  234. struct dbinfo {
  235.     dblk_t    d_dblock;
  236. };
  237. /*
  238.  * message block info
  239.  */
  240. struct mbinfo {
  241.     mblk_t    m_mblock;
  242.     void    (*m_func)();
  243. };
  244. #endif
  245.  
  246.  
  247.  
  248. /* convenient power of 2 */
  249. #define    FASTBUF    (128 - sizeof(struct mbinfo) - sizeof(struct dbinfo))
  250.  
  251. /*
  252.  * triplet
  253.  */
  254. struct    mdbblock {
  255.     struct    mbinfo    msgblk;
  256.     struct    dbinfo    datblk;
  257.     char    databuf[FASTBUF];
  258. };
  259.  
  260.  
  261. #ifdef DEBUG
  262. #define _INSERT_MSG_INUSE(x)    insert_msg_inuse(x)
  263. #define _INSERT_MDB_INUSE(y)    insert_mdb_inuse(y)
  264. #define _DELETE_MSG_INUSE(x)    delete_msg_inuse(x)
  265. #define _DELETE_MDB_INUSE(y)    delete_mdb_inuse(y)
  266. #else
  267. #define _INSERT_MSG_INUSE(x)
  268. #define _INSERT_MDB_INUSE(y)
  269. #define _DELETE_MSG_INUSE(x)
  270. #define _DELETE_MDB_INUSE(y)
  271. #endif
  272.  
  273.  
  274. /*
  275.  * Stream event info
  276.  */
  277. struct seinfo {
  278.     struct strevent    s_strevent;    /* must be first */
  279.     struct seinfo    *s_next;    /* next in list */
  280.     struct seinfo    *s_prev;    /* previous in list */
  281. };
  282.  
  283. /*
  284.  * Queue info
  285.  */
  286. #ifdef _STYPES
  287.  
  288. struct queinfo {
  289.     struct queue    qu_rqueue;    /* read queue - must be first */
  290.     struct queue    qu_wqueue;    /* write queue - must be second */
  291.     struct equeue    qu_requeue;    /* extended queue info (read) */
  292.     struct equeue    qu_wequeue;    /* extended queue info (write) */
  293.     struct queinfo    *qu_next;    /* next in list */
  294.     struct queinfo    *qu_prev;    /* previous in list */
  295. };
  296.  
  297. #else /* expanded struct */
  298.  
  299. struct queinfo {
  300.     struct queue    qu_rqueue;    /* read queue - must be first */
  301.     struct queue    qu_wqueue;    /* write queue - must be second */
  302.     struct queinfo    *qu_next;    /* next in list */
  303.     struct queinfo    *qu_prev;    /* previous in list */
  304. };
  305.  
  306. #endif /* _STYPES */
  307.  
  308.  
  309. /*
  310.  * Multiplexed streams info
  311.  */
  312. struct linkinfo {
  313.     struct linkblk    li_lblk;    /* must be first */
  314.     struct file    *li_fpdown;    /* file pointer for lower stream */
  315.     struct linkinfo    *li_next;    /* next in list */
  316.     struct linkinfo *li_prev;    /* previous in list */
  317. };
  318.  
  319. /*
  320.  * Qband info
  321.  */
  322. struct qbinfo {
  323.     struct qband    qbi_qband;    /* must be first */
  324.     struct qbinfo    *qbi_next;    /* next in list */
  325.     struct qbinfo    *qbi_prev;    /* previous in list */
  326. };
  327.  
  328. /*
  329.  * Miscellaneous parameters and flags.
  330.  */
  331.  
  332. /*
  333.  * Default timeout in seconds for ioctls and close
  334.  */
  335. #define STRTIMOUT 15
  336.  
  337. /*
  338.  * Flag values for stream io waiting procedure (strwaitq)
  339.  */
  340. #define WRITEWAIT    0x1    /* waiting for write event */
  341. #define READWAIT    0x2    /* waiting for read event */
  342. #define NOINTR        0x4    /* error is not to be set for signal */
  343. #define GETWAIT        0x8    /* waiting for getmsg event */
  344.  
  345. /*
  346.  * Copy modes for tty and I_STR ioctls
  347.  */
  348. #define    U_TO_K     01            /* User to Kernel */
  349. #define    K_TO_K  02            /* Kernel to Kernel */
  350.  
  351. /*
  352.  * canonical structure definitions
  353.  */
  354.  
  355. #define STRLINK        "lli"
  356. #define STRIOCTL    "iiil"
  357. #define STRPEEK        "iiliill"
  358. #define STRFDINSERT    "iiliillii"
  359. #define O_STRRECVFD    "lssc8"
  360. #define STRRECVFD    "lllc8"
  361. #define STRNAME        "c0"
  362. #define STRINT        "i"
  363. #define STRTERMIO    "ssssc12"
  364. #define STRTERMCB    "c6"
  365. #define STRSGTTYB    "c4i"
  366. #define STRTERMIOS    "llllc20"
  367. #define STRLIST        "il"
  368. #define STRSEV        "issllc1"
  369. #define STRGEV        "ili"
  370. #define STREVENT    "lssllliil"
  371. #define STRLONG        "l"
  372. #define STRBANDINFO    "ci"
  373.  
  374. #ifndef _STYPES
  375. #define STRPIDT        "l"
  376. #else
  377. #define STRPIDT        "s"
  378. #endif
  379.  
  380. /*
  381.  * Tables we reference during open(2) processing.
  382.  */
  383. #define CDEVSW    0
  384. #define FMODSW    1
  385.  
  386. /*
  387.  * Mux defines.
  388.  */
  389. #define LINKNORMAL    0x01        /* normal mux link */
  390. #define LINKPERSIST    0x02        /* persistent mux link */
  391. #define LINKTYPEMASK    0x03        /* bitmask of all link types */
  392. #define LINKCLOSE    0x04        /* unlink from strclose */
  393. #define LINKIOCTL    0x08        /* unlink from strioctl */
  394. #define LINKNOEDGE    0x10        /* no edge to remove from graph */
  395.  
  396. /*
  397.  * Definitions of Streams macros and function interfaces.
  398.  */
  399.  
  400. /*
  401.  *  Queue scheduling macros
  402.  */
  403. #define setqsched()     qrunflag = 1    /* set up queue scheduler */
  404. #define qready()    qrunflag    /* test if queues are ready to run */
  405.  
  406. /*
  407.  * Macros dealing with mux_nodes.
  408.  */
  409. #define MUX_VISIT(X)    ((X)->mn_flags |= VISITED)
  410. #define MUX_CLEAR(X)    ((X)->mn_flags &= (~VISITED)); \
  411.             ((X)->mn_originp = NULL)
  412. #define MUX_DIDVISIT(X)    ((X)->mn_flags & VISITED)
  413.  
  414. /*
  415.  * Declarations of private routines.
  416.  */
  417. extern void strsendsig();
  418. extern void strevpost();
  419. extern void strdrpost();
  420. extern int qattach();
  421. extern void qdetach();
  422. extern void strtime();
  423. extern void str2time();
  424. extern void str3time();
  425. extern int putiocd();
  426. extern int getiocd();
  427. extern struct linkinfo *alloclink();
  428. extern void lbfree();
  429. extern int linkcycle();
  430. extern struct linkinfo *findlinks();
  431. extern queue_t *getendq();
  432. extern int munlink();
  433. extern int munlinkall();
  434. extern int mux_addedge();
  435. extern void mux_rmvedge();
  436. extern void setq();
  437. extern int strmakemsg();
  438. extern int strwaitbuf();
  439. extern void strunbcall();
  440. extern int strwaitq();
  441. extern void strqbuf();
  442. extern int strctty();
  443. extern int straccess();
  444. extern int xmsgsize();
  445. extern struct stdata *shalloc();
  446. extern void shfree();
  447. extern struct mdbblock *xmdballoc();
  448. extern mblk_t *xmsgalloc();
  449. extern queue_t *allocq();
  450. extern void freeq();
  451. extern qband_t *allocband();
  452. extern void freeband();
  453. extern struct strevent *sealloc();
  454. extern void sefree();
  455. extern void queuerun();
  456. extern void runqueues();
  457. extern int findmod();
  458. extern caddr_t allocstrpage();
  459. extern void adjfmtp();
  460. extern int str2num();
  461. extern void strclearpg();
  462. extern void strclearsid();
  463. extern void strclearctty();
  464. extern void setqback();
  465. extern int strcopyin();
  466. extern int strcopyout();
  467. extern void strsignal();
  468. extern void strscan();
  469.  
  470. #endif    /* _SYS_STRSUBR_H */
  471.