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