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