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