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