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