xref: /titanic_44/usr/src/cmd/mdb/common/mdb/mdb_io_impl.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #include <mdb/mdb_io.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 #ifdef _MDB
39 
40 typedef struct mdb_io_ops {
41 	ssize_t (*io_read)(mdb_io_t *, void *, size_t);
42 	ssize_t (*io_write)(mdb_io_t *, const void *, size_t);
43 	off64_t (*io_seek)(mdb_io_t *, off64_t, int);
44 	int (*io_ctl)(mdb_io_t *, int, void *);
45 	void (*io_close)(mdb_io_t *);
46 	const char *(*io_name)(mdb_io_t *);
47 	void (*io_link)(mdb_io_t *, mdb_iob_t *);
48 	void (*io_unlink)(mdb_io_t *, mdb_iob_t *);
49 	int (*io_setattr)(mdb_io_t *, int, uint_t);
50 	void (*io_suspend)(mdb_io_t *);
51 	void (*io_resume)(mdb_io_t *);
52 } mdb_io_ops_t;
53 
54 #define	IOP_READ(io, buf, len) ((io)->io_ops->io_read((io), (buf), (len)))
55 #define	IOP_WRITE(io, buf, len) ((io)->io_ops->io_write((io), (buf), (len)))
56 #define	IOP_SEEK(io, off, whence) ((io)->io_ops->io_seek((io), (off), (whence)))
57 #define	IOP_CTL(io, req, arg) ((io)->io_ops->io_ctl((io), (req), (arg)))
58 #define	IOP_CLOSE(io) ((io)->io_ops->io_close((io)))
59 #define	IOP_NAME(io) ((io)->io_ops->io_name((io)))
60 #define	IOP_LINK(io, iob) ((io)->io_ops->io_link((io), (iob)))
61 #define	IOP_UNLINK(io, iob) ((io)->io_ops->io_unlink((io), (iob)))
62 #define	IOP_SETATTR(io, r, a) ((io)->io_ops->io_setattr((io), (r), (a)))
63 #define	IOP_SUSPEND(io) ((io)->io_ops->io_suspend((io)))
64 #define	IOP_RESUME(io) ((io)->io_ops->io_resume((io)))
65 
66 #define	IOPF_READ(io)	\
67 	((ssize_t (*)(mdb_io_t *, void *, size_t))(io)->io_ops->io_read)
68 
69 #define	IOPF_WRITE(io)	\
70 	((ssize_t (*)(mdb_io_t *, void *, size_t))(io)->io_ops->io_write)
71 
72 #define	ATT_STANDOUT	0x01		/* Standout mode */
73 #define	ATT_UNDERLINE	0x02		/* Underline mode */
74 #define	ATT_REVERSE	0x04		/* Reverse video mode */
75 #define	ATT_BOLD	0x08		/* Bold text mode */
76 #define	ATT_DIM		0x10		/* Dim text mode */
77 #define	ATT_ALTCHARSET	0x20		/* Alternate character set mode */
78 
79 #define	ATT_ALL		0x3f		/* Mask of all valid attributes */
80 
81 #define	ATT_OFF		0		/* Turn attributes off */
82 #define	ATT_ON		1		/* Turn attributes on */
83 
84 struct mdb_io {
85 	const mdb_io_ops_t *io_ops;	/* I/O type-specific operations */
86 	void *io_data;			/* I/O type-specific data pointer */
87 	mdb_io_t *io_next;		/* Link to next i/o object on stack */
88 	size_t io_refcnt;		/* Reference count */
89 };
90 
91 struct mdb_iob {
92 	char *iob_buf;			/* Input/output buffer */
93 	size_t iob_bufsiz;		/* Size of iob_buf in bytes */
94 	char *iob_bufp;			/* Current buffer location */
95 	size_t iob_nbytes;		/* Number of bytes in io_buf */
96 	size_t iob_nlines;		/* Lines output on current page */
97 	size_t iob_lineno;		/* Storage for saved yylineno */
98 	size_t iob_rows;		/* Terminal height */
99 	size_t iob_cols;		/* Terminal width */
100 	size_t iob_tabstop;		/* Tab stop width */
101 	size_t iob_margin;		/* Margin width */
102 	uint_t iob_flags;		/* Flags (see <mdb/mdb_io.h>) */
103 	mdb_io_t *iob_iop;		/* I/o implementation pointer */
104 	mdb_io_t *iob_pgp;		/* Pager i/o implementation pointer */
105 	mdb_iob_t *iob_next;		/* Stack next pointer */
106 };
107 
108 /*
109  * Stub functions for i/o backend implementors: these stubs either act as
110  * pass-through no-ops or return ENOTSUP as appropriate.
111  */
112 extern ssize_t no_io_read(mdb_io_t *, void *, size_t);
113 extern ssize_t no_io_write(mdb_io_t *, const void *, size_t);
114 extern off64_t no_io_seek(mdb_io_t *, off64_t, int);
115 extern int no_io_ctl(mdb_io_t *, int, void *);
116 extern void no_io_close(mdb_io_t *);
117 extern const char *no_io_name(mdb_io_t *);
118 extern void no_io_link(mdb_io_t *, mdb_iob_t *);
119 extern void no_io_unlink(mdb_io_t *, mdb_iob_t *);
120 extern int no_io_setattr(mdb_io_t *, int, uint_t);
121 extern void no_io_suspend(mdb_io_t *);
122 extern void no_io_resume(mdb_io_t *);
123 
124 #endif	/* _MDB */
125 
126 #ifdef	__cplusplus
127 }
128 #endif
129 
130 #endif	/* _MDB_IO_IMPL_H */
131