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