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