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