1 /*
2  * BEGIN illumos section
3  *   This is an unstable interface; changes may be made
4  *   without notice.
5  * END illumos section
6  */
7 /***********************************************************************
8 *                                                                      *
9 *               This software is part of the ast package               *
10 *          Copyright (c) 1985-2012 AT&T Intellectual Property          *
11 *                      and is licensed under the                       *
12 *                 Eclipse Public License, Version 1.0                  *
13 *                    by AT&T Intellectual Property                     *
14 *                                                                      *
15 *                A copy of the License is available at                 *
16 *          http://www.eclipse.org/org/documents/epl-v10.html           *
17 *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
18 *                                                                      *
19 *              Information and Software Systems Research               *
20 *                            AT&T Research                             *
21 *                           Florham Park NJ                            *
22 *                                                                      *
23 *                 Glenn Fowler <gsf@research.att.com>                  *
24 *                  David Korn <dgk@research.att.com>                   *
25 *                   Phong Vo <kpv@research.att.com>                    *
26 *                                                                      *
27 ***********************************************************************/
28 #ifndef _SFIO_T_H
29 #define _SFIO_T_H	1
30 
31 /*	This header file is for library writers who need to know certain
32 **	internal info concerning the full Sfio_t structure. Including this
33 **	file means that you agree to track closely with sfio development
34 **	in case its internal architecture is changed.
35 **
36 **	Written by Kiem-Phong Vo
37 */
38 
39 /* the parts of Sfio_t private to sfio functions */
40 #define _SFIO_PRIVATE \
41 	Sfoff_t			extent;	/* current file	size		*/ \
42 	Sfoff_t			here;	/* current physical location	*/ \
43 	unsigned char		unused_1;/* unused #1			*/ \
44 	unsigned char		tiny[1];/* for unbuffered read stream	*/ \
45 	unsigned short		bits;	/* private flags		*/ \
46 	unsigned int		mode;	/* current io mode		*/ \
47 	struct _sfdisc_s*	disc;	/* discipline			*/ \
48 	struct _sfpool_s*	pool;	/* the pool containing this	*/ \
49 	struct _sfrsrv_s*	rsrv;	/* reserved buffer		*/ \
50 	struct _sfproc_s*	proc;	/* coprocess id, etc.		*/ \
51 	Void_t*			mutex;	/* mutex for thread-safety	*/ \
52 	Void_t*			stdio;	/* stdio FILE if any		*/ \
53 	Sfoff_t			lpos;	/* last seek position		*/ \
54 	size_t			iosz;	/* preferred size for I/O	*/ \
55 	size_t			blksz;	/* preferred block size		*/ \
56 	int			getr;	/* the last sfgetr separator 	*/ \
57 	_SFIO_PRIVATE_PAD
58 
59 #if _ast_sizeof_pointer == 8
60 #define _SFIO_PRIVATE_PAD	int pad;
61 #else
62 #define _SFIO_PRIVATE_PAD
63 #endif
64 
65 #include	"sfio.h"
66 
67 /* mode bit to indicate that the structure hasn't been initialized */
68 #define SF_INIT		0000004
69 #define SF_DCDOWN	00010000
70 
71 /* short-hand for common stream types */
72 #define SF_RDWR		(SF_READ|SF_WRITE)
73 #define SF_RDSTR	(SF_READ|SF_STRING)
74 #define SF_WRSTR	(SF_WRITE|SF_STRING)
75 #define SF_RDWRSTR	(SF_RDWR|SF_STRING)
76 
77 /* for static initialization of an Sfio_t structure */
78 #define SFNEW(data,size,file,type,disc,mutex)	\
79 	{ (unsigned char*)(data),			/* next		*/ \
80 	  (unsigned char*)(data),			/* endw		*/ \
81 	  (unsigned char*)(data),			/* endr		*/ \
82 	  (unsigned char*)(data),			/* endb		*/ \
83 	  (Sfio_t*)0,					/* push		*/ \
84 	  (unsigned short)((type)&SF_FLAGS),		/* flags	*/ \
85 	  (short)(file),				/* file		*/ \
86 	  (unsigned char*)(data),			/* data		*/ \
87 	  (ssize_t)(size),				/* size		*/ \
88 	  (ssize_t)(-1),				/* val		*/ \
89 	  (Sfoff_t)0,					/* extent	*/ \
90 	  (Sfoff_t)0,					/* here		*/ \
91 	  0,						/* getr		*/ \
92 	  {0},						/* tiny		*/ \
93 	  0,						/* bits		*/ \
94 	  (unsigned int)(((type)&(SF_RDWR))|SF_INIT),	/* mode		*/ \
95 	  (struct _sfdisc_s*)(disc),			/* disc		*/ \
96 	  (struct _sfpool_s*)0,				/* pool		*/ \
97 	  (struct _sfrsrv_s*)0,				/* rsrv		*/ \
98 	  (struct _sfproc_s*)0,				/* proc		*/ \
99 	  (mutex),					/* mutex	*/ \
100 	  (Void_t*)0,					/* stdio	*/ \
101 	  (Sfoff_t)0,					/* lpos		*/ \
102 	  (size_t)0					/* iosz		*/ \
103 	}
104 
105 /* function to clear an Sfio_t structure */
106 #define SFCLEAR(f,mtx) \
107 	( (f)->next = (unsigned char*)0,		/* next		*/ \
108 	  (f)->endw = (unsigned char*)0,		/* endw		*/ \
109 	  (f)->endr = (unsigned char*)0,		/* endr		*/ \
110 	  (f)->endb = (unsigned char*)0,		/* endb		*/ \
111 	  (f)->push = (Sfio_t*)0,			/* push		*/ \
112 	  (f)->flags = (unsigned short)0,		/* flags	*/ \
113 	  (f)->file = -1,				/* file		*/ \
114 	  (f)->data = (unsigned char*)0,		/* data		*/ \
115 	  (f)->size = (ssize_t)(-1),			/* size		*/ \
116 	  (f)->val = (ssize_t)(-1),			/* val		*/ \
117 	  (f)->extent = (Sfoff_t)(-1),			/* extent	*/ \
118 	  (f)->here = (Sfoff_t)0,			/* here		*/ \
119 	  (f)->getr = 0,				/* getr		*/ \
120 	  (f)->tiny[0] = 0,				/* tiny		*/ \
121 	  (f)->bits = 0,				/* bits		*/ \
122 	  (f)->mode = 0,				/* mode		*/ \
123 	  (f)->disc = (struct _sfdisc_s*)0,		/* disc		*/ \
124 	  (f)->pool = (struct _sfpool_s*)0,		/* pool		*/ \
125 	  (f)->rsrv = (struct _sfrsrv_s*)0,		/* rsrv		*/ \
126 	  (f)->proc = (struct _sfproc_s*)0,		/* proc		*/ \
127 	  (f)->mutex = (mtx),				/* mutex	*/ \
128 	  (f)->stdio = (Void_t*)0,			/* stdio	*/ \
129 	  (f)->lpos = (Sfoff_t)0,			/* lpos		*/ \
130 	  (f)->iosz = (size_t)0				/* iosz		*/ \
131 	)
132 
133 /* expose next stream inside discipline function; state saved in int f */
134 #define SFDCNEXT(sp,f)	(((f)=(sp)->bits&SF_DCDOWN),(sp)->bits|=SF_DCDOWN)
135 
136 /* restore SFDCNEXT() state from int f */
137 #define SFDCPREV(sp,f)	((f)?(0):((sp)->bits&=~SF_DCDOWN))
138 
139 #endif /* _SFIO_T_H */
140