fsi_gram.y revision 38494
1/*
2 * Copyright (c) 1997-1998 Erez Zadok
3 * Copyright (c) 1989 Jan-Simon Pendry
4 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
5 * Copyright (c) 1989 The Regents of the University of California.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * Jan-Simon Pendry at Imperial College, London.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 *    notice, this list of conditions and the following disclaimer in the
18 *    documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 *    must display the following acknowledgement:
21 *      This product includes software developed by the University of
22 *      California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 *    may be used to endorse or promote products derived from this software
25 *    without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 *	%W% (Berkeley) %G%
40 *
41 * $Id: fsi_gram.y,v 5.2.2.1 1992/02/09 15:09:35 jsp beta $
42 *
43 */
44
45%{
46#ifdef HAVE_CONFIG_H
47# include <config.h>
48#endif /* HAVE_CONFIG_H */
49#include <am_defs.h>
50#include <fsi_data.h>
51#include <fsinfo.h>
52
53extern qelem *list_of_hosts, *list_of_automounts;
54%}
55
56%union {
57	auto_tree *a;
58	disk_fs *d;
59	ether_if *e;
60	host *h;
61	qelem *q;
62	char *s;
63	fsi_mount *m;
64	fsmount *f;
65}
66
67%token	tARCH
68%token	tAS
69%token	tAUTOMOUNT
70%token	tCLUSTER
71%token	tCONFIG
72%token	tDUMPSET
73%token	tEQ
74%token  tNFSEQ
75%token	tEXPORTFS
76%token	tFREQ
77%token	tFROM
78%token	tFS
79%token	tFSTYPE
80%token	tHWADDR
81%token	tINADDR
82%token	tHOST
83%token	tLOCALHOST
84%token	tLOG
85%token	tMOUNT
86%token	tNETMASK
87%token	tNETIF
88%token	tVOLNAME
89%token	tOPTS
90%token	tOS
91%token	tPASSNO
92%token        tDIRECT
93%token	tSEL
94%token	<s> tSTR
95
96%start list_of_hosts
97
98%type <a> automount
99%type <q> automount_tree
100%type <e> ether_attr
101%type <m> dir_tree_info
102%type <d> filesystem fs_info_list
103%type <h> host host_attr host_attr_list
104%type <q> list_of_hosts list_of_filesystems list_of_mounts dir_tree
105%type <f> localinfo_list
106%type <s> opt_auto_opts
107
108%%
109
110list_of_hosts :
111	  /* empty */
112	  { $$ = new_que(); }
113
114	| list_of_hosts host
115	  { if ($2) ins_que((qelem *) $2, list_of_hosts->q_back);
116	    $$ = $1; }
117
118	| list_of_hosts automount
119	  { if ($2) ins_que((qelem *) $2, list_of_automounts->q_back);
120	    $$ = $1; }
121	;
122
123/*
124 * A new host:
125 *
126 * host foo.domain
127 */
128host :
129	  tHOST host_attr list_of_filesystems list_of_mounts
130	  { $$ = $2; $$->h_disk_fs = $3; $$->h_mount = $4; }
131
132	| error tHOST host_attr list_of_filesystems list_of_mounts
133	  { $$ = $3; $$->h_disk_fs = $4; $$->h_mount = $5; }
134
135	;
136
137host_attr :
138	  tSTR
139	  { $$ = new_host(); set_host($$, HF_HOST, $1); }
140
141	| '{' host_attr_list '}' tSTR
142	  { $$ = $2; set_host($$, HF_HOST, $4); }
143
144	;
145
146host_attr_list :
147	  /* empty */
148	  { $$ = new_host(); }
149
150	| host_attr_list tNETIF tSTR '{' ether_attr '}'
151	  { if ($5) {
152		$5->e_if = $3;
153		$$ = $1; set_host($$, HF_ETHER, (char *) $5); }
154	  }
155
156	| host_attr_list tCONFIG tSTR
157	  { $$ = $1; set_host($$, HF_CONFIG, $3); }
158
159	| host_attr_list tARCH '=' tSTR
160	  { $$ = $1; set_host($$, HF_ARCH, $4); }
161
162	| host_attr_list tOS '=' tSTR
163	  { $$ = $1; set_host($$, HF_OS, $4); }
164
165	| host_attr_list tCLUSTER '=' tSTR
166	  { $$ = $1; set_host($$, HF_CLUSTER, $4); }
167
168	| host_attr_list error '=' tSTR
169	  { yyerror("unknown host attribute"); }
170	;
171
172ether_attr :
173	  /* empty */
174	  { $$ = new_ether_if(); }
175
176	| ether_attr tINADDR '=' tSTR
177	  { $$ = $1; set_ether_if($$, EF_INADDR, $4); }
178	| ether_attr tNETMASK '=' tSTR
179	  { $$ = $1; set_ether_if($$, EF_NETMASK, $4); }
180	| ether_attr tHWADDR '=' tSTR
181	  { $$ = $1; set_ether_if($$, EF_HWADDR, $4); }
182	;
183
184/*
185 * A new automount tree:
186 *
187 * automount /mountpoint { ... }
188 */
189automount :
190	  tAUTOMOUNT opt_auto_opts automount_tree
191	  { if ($3) {
192		$$ = new_auto_tree($2, $3);
193	    } else {
194		$$ = 0;
195	    }
196	  }
197
198	| tAUTOMOUNT error
199	  { $$ = 0; }
200	;
201
202opt_auto_opts :
203	  /* empty */
204	  { $$ = strdup(""); }
205
206	| tOPTS tSTR
207	  { $$ = $2; }
208	;
209
210list_of_filesystems :
211	  /* empty */
212	  { $$ = 0; }
213
214	| list_of_filesystems filesystem
215	  { if ($2) {
216		if ($1)
217			$$ = $1;
218		else
219			$$ = new_que();
220		ins_que(&$2->d_q, $$->q_back);
221	    } else {
222		$$ = $1;
223	    }
224	  }
225	;
226
227/*
228 * A new filesystem:
229 *
230 * fs /dev/whatever { ... }
231 */
232filesystem :
233	  tFS tSTR '{' fs_info_list '}'
234	  { $4->d_dev = $2; $$ = $4; }
235
236	| tFS error '}'
237	  { $$ = (disk_fs *) 0; }
238	;
239
240/*
241 * Per-filesystem information:
242 *
243 * fstype - the type of the filesystem (4.2, nfs, swap, export)
244 * opts - the mount options ("rw,grpid")
245 * passno - fsck pass number
246 * freq - dump frequency
247 * dumpset - tape set for filesystem dumps
248 * mount - where to mount this filesystem
249 * log - log device
250 */
251fs_info_list :
252	  /* empty */
253	  { $$ = new_disk_fs(); }
254
255	| fs_info_list tFSTYPE '=' tSTR
256	  { $$ = $1; set_disk_fs($$, DF_FSTYPE, $4); }
257
258	| fs_info_list tOPTS '=' tSTR
259	  { $$ = $1; set_disk_fs($$, DF_OPTS, $4); }
260
261	| fs_info_list tPASSNO '=' tSTR
262	  { $$ = $1; set_disk_fs($$, DF_PASSNO, $4); }
263
264	| fs_info_list tFREQ '=' tSTR
265	  { $$ = $1; set_disk_fs($$, DF_FREQ, $4); }
266
267	| fs_info_list tMOUNT dir_tree
268	  { $$ = $1; set_disk_fs($$, DF_MOUNT, (char *) $3); }
269
270	| fs_info_list tDUMPSET '=' tSTR
271	  { $$ = $1; set_disk_fs($$, DF_DUMPSET, $4); }
272
273	| fs_info_list tLOG '=' tSTR
274	  { $$ = $1; set_disk_fs($$, DF_LOG, $4); }
275
276	| fs_info_list error '=' tSTR
277	  { yyerror("unknown filesystem attribute"); }
278	;
279
280/*
281 * An automount tree:
282 *
283 * name = "volname"	name is a reference to volname
284 * name -> "string"	name is a link to "string"
285 * name nfsalias "string"  name is a link to "string", string parsed as NFS
286 *			   pathname.
287 * name { ... }		name is an automount tree
288 */
289automount_tree :
290	  /* empty */
291	  { $$ = 0; }
292
293	| automount_tree tSTR opt_auto_opts '=' tSTR
294	  { automount *a = new_automount($2);
295	    a->a_volname = $5;
296	    a->a_opts = $3;
297	    if ($1)
298		$$ = $1;
299	    else
300		$$ = new_que();
301	    ins_que(&a->a_q, $$->q_back);
302	  }
303          | automount_tree tSTR opt_auto_opts tNFSEQ tSTR
304            { automount *a = new_automount($2);
305            a->a_hardwiredfs = $5;
306            a->a_opts = $3;
307            if ($1)
308                $$ = $1;
309            else
310                $$ = new_que();
311            ins_que(&a->a_q, $$->q_back);
312          }
313
314	| automount_tree tSTR tEQ tSTR
315	  { automount *a = new_automount($2);
316	    a->a_symlink = $4;
317	    if ($1)
318		$$ = $1;
319	    else
320		$$ = new_que();
321	    ins_que(&a->a_q, $$->q_back);
322	  }
323
324	| automount_tree tSTR opt_auto_opts '{' automount_tree '}'
325	  { automount *a = new_automount($2);
326	    a->a_mount = $5;
327	    a->a_opts = $3;
328	    if ($1)
329		$$ = $1;
330	    else
331		$$ = new_que();
332	    ins_que(&a->a_q, $$->q_back);
333	  }
334	;
335
336dir_tree :
337	  /* empty */
338	  { $$ = 0; }
339
340	| dir_tree tSTR '{' dir_tree_info dir_tree '}'
341	  { $4->m_mount = $5;
342	    $4->m_name = $2;
343	    if ($2[0] != '/' && $2[1] && strchr($2+1, '/'))
344		yyerror("not allowed '/' in a directory name");
345	    if ($1)
346		$$ = $1;
347	    else
348		$$ = new_que();
349	    ins_que(&$4->m_q, $$->q_back);
350	  }
351	;
352
353dir_tree_info :
354	  /* empty */
355	  { $$ = new_mount(); }
356
357	| dir_tree_info tEXPORTFS tSTR
358	  { $$ = $1; set_mount($$, DM_EXPORTFS, $3); }
359
360	| dir_tree_info tVOLNAME tSTR
361	  { $$ = $1; set_mount($$, DM_VOLNAME, $3); }
362
363	| dir_tree_info tSEL tSTR
364	  { $$ = $1; set_mount($$, DM_SEL, $3); }
365
366	| dir_tree_info error '=' tSTR
367	  { yyerror("unknown directory attribute"); }
368	;
369
370/*
371 * Additional mounts on a host
372 *
373 * mount "volname" ...
374 */
375list_of_mounts :
376	  /* empty */
377	  { $$ = 0; }
378
379	| list_of_mounts tMOUNT tSTR localinfo_list
380	  { set_fsmount($4, FM_VOLNAME, $3);
381	    if ($1)
382		$$ = $1;
383	    else
384		$$ = new_que();
385	    ins_que(&$4->f_q, $$->q_back);
386	    }
387	;
388
389/*
390 * Mount info:
391 *
392 * from "hostname"	- obtain the object from the named host
393 * as "string"		- where to mount, if different from the volname
394 * opts "string"	- mount options
395 * fstype "type"	- type of filesystem mount, if not nfs
396 * direct             - mount entry, no need to create ad-hoc hosts file
397 */
398localinfo_list :
399	  /* empty */
400	  { $$ = new_fsmount(); }
401
402        | localinfo_list tDIRECT
403          { $$ = $1; set_fsmount($$, FM_DIRECT, ""); }
404
405	| localinfo_list tAS tSTR
406	  { $$ = $1; set_fsmount($$, FM_LOCALNAME, $3); }
407
408	| localinfo_list tFROM tSTR
409	  { $$ = $1; set_fsmount($$, FM_FROM, $3); }
410
411	| localinfo_list tFSTYPE tSTR
412	  { $$ = $1; set_fsmount($$, FM_FSTYPE, $3); }
413
414	| localinfo_list tOPTS tSTR
415	  { $$ = $1; set_fsmount($$, FM_OPTS, $3); }
416
417	| localinfo_list error '=' tSTR
418	  { yyerror("unknown mount attribute"); }
419	;
420