xref: /titanic_41/usr/src/lib/libadm/inc/devtab.h (revision 6185db853e024a486ff8837e6784dd290d866112)
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 1997 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
27 /*	  All Rights Reserved  	*/
28 
29 
30 #ifndef	_DEVTAB_H
31 #define	_DEVTAB_H
32 
33 #pragma ident	"%Z%%M%	%I%	%E% SMI"
34 
35 #include <stdio.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 /*
42  * devtab.h
43  *
44  *	This header file is local to the liboam component
45  *	and should not contain any data that may need to
46  *	be reference anywhere.  The definitions here are used
47  *	to reference the device tables and the device-group
48  *	tables.
49  */
50 
51 /*
52  *  Constant definitions
53  *	NULL		Manifest constant NULL (null-address)
54  *	TRUE		Boolean TRUE value
55  *	FALSE		Boolean FALSE value
56  *	DTAB_BUFSIZ	Initial buffersize for reading device table records
57  *	DTAB_BUFINC	Amount to increase device table record buffer
58  *	DGRP_BUFSIZ	Initial buffersize for reading devgrp table records
59  *	DGRP_BUFINC	Amount to increase device-group table record buffer
60  *	XTND_MAXCNT	Maximum extend count (may have insane tables)
61  *	DTAB_ESCS	Characters that are escaped in fields in the devtab
62  */
63 
64 #ifndef	NULL
65 #define	NULL	(0)
66 #endif
67 
68 #ifndef	TRUE
69 #define	TRUE	(1)
70 #endif
71 
72 #ifndef	FALSE
73 #define	FALSE	(0)
74 #endif
75 
76 #define	DTAB_BUFSIZ	512
77 #define	DTAB_BUFINC	512
78 #define	DGRP_BUFSIZ	512
79 #define	DGRP_BUFINC	512
80 #define	XTND_MAXCNT	16
81 
82 #define	DTAB_ESCS	":\\\"\n"
83 
84 /*
85  *	oam_devtab	File descriptor of the open device table
86  */
87 
88 extern	FILE	*oam_devtab;
89 extern	FILE	*oam_dgroup;
90 
91 /*
92  *  Structure definitions for device table records:
93  *	devtabent	Describes an entry in the device table
94  *	dgrpent		Describes an entry in the device-group table
95  *	attrval		Describes an attribute/value pair
96  */
97 
98 /*
99  *  struct devtabent
100  *
101  *	Describes an entry in the device table.
102  *
103  *	entryno		This record's entry number in the device table
104  *	comment		Comment flag, TRUE if record is a comment
105  *	alias		The device's alias
106  *	cdevice		A pathname to the inode describing the device as
107  *			a character-special device
108  *	bdevice		A pathname to the inode describing the device as
109  *			a block-special device
110  *	pathname	A pathname to the device (not char or blk special)
111  *	attrstr		The character-string containing the attributes
112  *	attrlist	The address of the first attribute description
113  */
114 
115 struct devtabent {
116 	int		entryno;	/* Entry number of this record */
117 	int		comment;	/* Comment flag */
118 	char		*alias;		/* Alias of the device */
119 	char		*cdevice;	/* Character device pathname */
120 	char		*bdevice;	/* Block device pathname */
121 	char		*pathname;	/* Vanilla pathname */
122 	char		*attrstr;	/* String containing attributes */
123 	struct attrval *attrlist;	/* Addr of 1st attribute description */
124 };
125 
126 /*
127  *  struct attrval
128  *
129  *	Describes an attribute-value pair
130  *
131  *	char *attr		Pointer to the name of the attribute
132  *	char *val		Pointer to the name of the value of the attr
133  *	struct attrval *next	Pointer to the next item in the list
134  */
135 
136 struct attrval {
137 	char		*attr;		/* Attribute name */
138 	char		*val;		/* Value of the attribute */
139 	struct attrval *next;		/* Next attrval in list */
140 };
141 
142 /*
143  *  Structure definitions for device-group records:
144  *	struct dgrptabent	Describes a record in the device-group table
145  *	struct member		Describes a member of a device group
146  */
147 
148 /*
149  *  struct dgrptabent
150  *	entryno			The entry number of this record
151  *	comment			Comment flag, TRUE if record is a comment
152  *	name			The name of the device group
153  *	memberspace		The buffer containing the members of the
154  *				device group
155  *	membership		Pointer to the head of the list of
156  *				members in the group.
157  */
158 
159 struct dgrptabent {
160 	int		entryno;	/* Entry number of this record */
161 	int		comment;	/* TRUE if a comment record */
162 	char		*name;		/* Device group name */
163 	char		*dataspace;	/* Buffer containing membership */
164 	struct member  *membership;	/* Ptr to top of membership list */
165 };
166 
167 
168 /*
169  *  struct member
170  *	name			Member name (a device alias or pathname)
171  *	next			Ptr to next item in the list
172  */
173 
174 struct member {
175 	char		*name;		/* Member name */
176 	struct member  *next;		/* Next member in the list */
177 };
178 
179 /*
180  *  Global function and data definitions:
181  *	_setdevtab()		Rewinds the open device table
182  *	_enddevtab()		Closes the open device table
183  *	_getdevtabent()		Gets the next device table entry
184  *	_freedevtabent()	Frees space allocated to a device-table entry
185  *	_getdevrec()		Gets a specific device table entry
186  *	_opendevtab()		Open the device table
187  *	_devtabpath()		Get the pathname of the device table file
188  *
189  *	_setdgrptab()		Rewind the open device-group table
190  *	_enddgrptab()		Close the open device table
191  *	_getdgrptabent()	Get the next device-group table entry
192  *	_freedgrptabent()	Frees space alloced to a dev-grp table entry
193  *	_getdgrprec()		Gets a specific device-group table entry
194  *	_opendgrptab()		Open the device group table
195  *	_dgrptabpath()		Get the pathname of the device group table file
196  *
197  *	_openlkfile()		Open device lock file
198  *	rsvtabpath()		Get device lock file pathname
199  * 	_closelkfile()		Close device lock file
200  *
201  *	_validalias()		Determine if a character-string is a valid alias
202  *	unreserv()		Remove a device reservation
203  */
204 
205 	void			_setdevtab(void);
206 	void			_enddevtab(void);
207 	struct devtabent	*_getdevtabent(void);
208 	void			_freedevtabent(struct devtabent *);
209 	struct devtabent	*_getdevrec(char *);
210 	int			_opendevtab(char *);
211 	char			*_devtabpath(void);
212 
213 	void			_setdgrptab(void);
214 	void			_enddgrptab(void);
215 	struct dgrptabent	*_getdgrptabent(void);
216 	void			_freedgrptabent(struct dgrptabent *);
217 	struct dgrptabent	*_getdgrprec(char *);
218 	int			_opendgrptab(char *);
219 	char			*_dgrptabpath(void);
220 
221 	int			_openlkfile(void);
222 	char			*_rsvtabpath(void);
223 	int			_closelkfile(void);
224 
225 	int			_validalias(char *);
226 	int			unreserv(int, char *);
227 
228 extern int _adddevtabrec(char *, char **);
229 extern int _moddevtabrec(char *, char **);
230 extern int _putdevtabrec(FILE *stream, struct devtabent *rec);
231 extern int _rmdevtabattrs(char   *, char **, char ***);
232 extern int _rmdevtabrec(char *);
233 
234 extern int _adddgrptabrec(char *dgrp, char  **members);
235 extern int _putdgrptabrec(FILE *stream, struct dgrptabent *rec);
236 extern int _rmdgrpmems(char *dgrp, char **mems, char ***notfounds);
237 extern int _rmdgrptabrec(char *dgrp);
238 
239 #ifdef	__cplusplus
240 }
241 #endif
242 
243 #endif	/* _DEVTAB_H */
244