xref: /illumos-gate/usr/src/cmd/mdb/common/mdb/mdb_io_impl.h (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 1999-2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef	_MDB_IO_IMPL_H
28 #define	_MDB_IO_IMPL_H
29 
30 #include <mdb/mdb_io.h>
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #ifdef _MDB
37 
38 typedef struct mdb_io_ops {
39 	ssize_t (*io_read)(mdb_io_t *, void *, size_t);
40 	ssize_t (*io_write)(mdb_io_t *, const void *, size_t);
41 	off64_t (*io_seek)(mdb_io_t *, off64_t, int);
42 	int (*io_ctl)(mdb_io_t *, int, void *);
43 	void (*io_close)(mdb_io_t *);
44 	const char *(*io_name)(mdb_io_t *);
45 	void (*io_link)(mdb_io_t *, mdb_iob_t *);
46 	void (*io_unlink)(mdb_io_t *, mdb_iob_t *);
47 	int (*io_setattr)(mdb_io_t *, int, uint_t);
48 	void (*io_suspend)(mdb_io_t *);
49 	void (*io_resume)(mdb_io_t *);
50 } mdb_io_ops_t;
51 
52 #define	IOP_READ(io, buf, len) ((io)->io_ops->io_read((io), (buf), (len)))
53 #define	IOP_WRITE(io, buf, len) ((io)->io_ops->io_write((io), (buf), (len)))
54 #define	IOP_SEEK(io, off, whence) ((io)->io_ops->io_seek((io), (off), (whence)))
55 #define	IOP_CTL(io, req, arg) ((io)->io_ops->io_ctl((io), (req), (arg)))
56 #define	IOP_CLOSE(io) ((io)->io_ops->io_close((io)))
57 #define	IOP_NAME(io) ((io)->io_ops->io_name((io)))
58 #define	IOP_LINK(io, iob) ((io)->io_ops->io_link((io), (iob)))
59 #define	IOP_UNLINK(io, iob) ((io)->io_ops->io_unlink((io), (iob)))
60 #define	IOP_SETATTR(io, r, a) ((io)->io_ops->io_setattr((io), (r), (a)))
61 #define	IOP_SUSPEND(io) ((io)->io_ops->io_suspend((io)))
62 #define	IOP_RESUME(io) ((io)->io_ops->io_resume((io)))
63 
64 #define	IOPF_READ(io)	\
65 	((ssize_t (*)(mdb_io_t *, void *, size_t))(io)->io_ops->io_read)
66 
67 #define	IOPF_WRITE(io)	\
68 	((ssize_t (*)(mdb_io_t *, void *, size_t))(io)->io_ops->io_write)
69 
70 #define	ATT_STANDOUT	0x01		/* Standout mode */
71 #define	ATT_UNDERLINE	0x02		/* Underline mode */
72 #define	ATT_REVERSE	0x04		/* Reverse video mode */
73 #define	ATT_BOLD	0x08		/* Bold text mode */
74 #define	ATT_DIM		0x10		/* Dim text mode */
75 #define	ATT_ALTCHARSET	0x20		/* Alternate character set mode */
76 
77 #define	ATT_ALL		0x3f		/* Mask of all valid attributes */
78 
79 #define	ATT_OFF		0		/* Turn attributes off */
80 #define	ATT_ON		1		/* Turn attributes on */
81 
82 struct mdb_io {
83 	const mdb_io_ops_t *io_ops;	/* I/O type-specific operations */
84 	void *io_data;			/* I/O type-specific data pointer */
85 	mdb_io_t *io_next;		/* Link to next i/o object on stack */
86 	size_t io_refcnt;		/* Reference count */
87 };
88 
89 struct mdb_iob {
90 	char *iob_buf;			/* Input/output buffer */
91 	size_t iob_bufsiz;		/* Size of iob_buf in bytes */
92 	char *iob_bufp;			/* Current buffer location */
93 	size_t iob_nbytes;		/* Number of bytes in io_buf */
94 	size_t iob_nlines;		/* Lines output on current page */
95 	size_t iob_lineno;		/* Storage for saved yylineno */
96 	size_t iob_rows;		/* Terminal height */
97 	size_t iob_cols;		/* Terminal width */
98 	size_t iob_tabstop;		/* Tab stop width */
99 	size_t iob_margin;		/* Margin width */
100 	uint_t iob_flags;		/* Flags (see <mdb/mdb_io.h>) */
101 	mdb_io_t *iob_iop;		/* I/o implementation pointer */
102 	mdb_io_t *iob_pgp;		/* Pager i/o implementation pointer */
103 	mdb_iob_t *iob_next;		/* Stack next pointer */
104 };
105 
106 /*
107  * Stub functions for i/o backend implementors: these stubs either act as
108  * pass-through no-ops or return ENOTSUP as appropriate.
109  */
110 extern ssize_t no_io_read(mdb_io_t *, void *, size_t);
111 extern ssize_t no_io_write(mdb_io_t *, const void *, size_t);
112 extern off64_t no_io_seek(mdb_io_t *, off64_t, int);
113 extern int no_io_ctl(mdb_io_t *, int, void *);
114 extern void no_io_close(mdb_io_t *);
115 extern const char *no_io_name(mdb_io_t *);
116 extern void no_io_link(mdb_io_t *, mdb_iob_t *);
117 extern void no_io_unlink(mdb_io_t *, mdb_iob_t *);
118 extern int no_io_setattr(mdb_io_t *, int, uint_t);
119 extern void no_io_suspend(mdb_io_t *);
120 extern void no_io_resume(mdb_io_t *);
121 
122 #endif	/* _MDB */
123 
124 #ifdef	__cplusplus
125 }
126 #endif
127 
128 #endif	/* _MDB_IO_IMPL_H */
129