xref: /csrg-svn/usr.sbin/amd/fsinfo/fsi_gram.y (revision 61793)
147482Spendry /*
247482Spendry  * Copyright (c) 1989 Jan-Simon Pendry
347482Spendry  * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
4*61793Sbostic  * Copyright (c) 1989, 1993
5*61793Sbostic  *	The Regents of the University of California.  All rights reserved.
647482Spendry  *
747482Spendry  * This code is derived from software contributed to Berkeley by
847482Spendry  * Jan-Simon Pendry at Imperial College, London.
947482Spendry  *
1047530Spendry  * %sccs.include.redist.c%
1147482Spendry  *
12*61793Sbostic  *	@(#)fsi_gram.y	8.1 (Berkeley) 06/06/93
1349686Spendry  *
1452455Spendry  * $Id: fsi_gram.y,v 5.2.2.1 1992/02/09 15:09:35 jsp beta $
1549686Spendry  *
1647482Spendry  */
1747482Spendry 
1847482Spendry %{
1947482Spendry #include "../fsinfo/fsinfo.h"
2047482Spendry #include <stdio.h>
2147482Spendry 
2247482Spendry extern qelem *list_of_hosts, *list_of_automounts;
2347482Spendry %}
2447482Spendry 
2547482Spendry %union {
2647482Spendry 	auto_tree *a;
2747482Spendry 	disk_fs *d;
2847482Spendry 	ether_if *e;
2947482Spendry 	host *h;
3047482Spendry 	qelem *q;
3147482Spendry 	char *s;
3247482Spendry 	mount *m;
3347482Spendry 	fsmount *f;
3447482Spendry }
3547482Spendry 
3647482Spendry %token	tARCH
3747482Spendry %token	tAS
3847482Spendry %token	tAUTOMOUNT
3947482Spendry %token	tCLUSTER
4047482Spendry %token	tCONFIG
4147482Spendry %token	tDUMPSET
4247482Spendry %token	tEQ
4347482Spendry %token	tEXPORTFS
4447482Spendry %token	tFREQ
4547482Spendry %token	tFROM
4647482Spendry %token	tFS
4747482Spendry %token	tFSTYPE
4847482Spendry %token	tHWADDR
4947482Spendry %token	tINADDR
5047482Spendry %token	tHOST
5147482Spendry %token	tLOCALHOST
5247482Spendry %token	tLOG
5347482Spendry %token	tMOUNT
5447482Spendry %token	tNETMASK
5547482Spendry %token	tNETIF
5647482Spendry %token	tVOLNAME
5747482Spendry %token	tOPTS
5847482Spendry %token	tOS
5947482Spendry %token	tPASSNO
6047482Spendry %token	tSEL
6147482Spendry %token	<s> tSTR
6247482Spendry 
6347482Spendry %start list_of_hosts
6447482Spendry 
6547482Spendry %type <a> automount
6647482Spendry %type <q> automount_tree
6747482Spendry %type <e> ether_attr
6847482Spendry %type <m> dir_tree_info
6947482Spendry %type <d> filesystem fs_info_list
7047482Spendry %type <h> host host_attr host_attr_list
7147482Spendry %type <q> list_of_hosts list_of_filesystems list_of_mounts dir_tree
7247482Spendry %type <f> localinfo_list
7347482Spendry %type <s> opt_auto_opts
7447482Spendry 
7547482Spendry %%
7647482Spendry 
7747482Spendry list_of_hosts :
7847482Spendry 	  /* empty */
7947482Spendry 	  { $$ = new_que(); }
8047482Spendry 
8147482Spendry 	| list_of_hosts host
8247482Spendry 	  { if ($2) ins_que((qelem *) $2, list_of_hosts->q_back);
8347482Spendry 	    $$ = $1; }
8447482Spendry 
8547482Spendry 	| list_of_hosts automount
8647482Spendry 	  { if ($2) ins_que((qelem *) $2, list_of_automounts->q_back);
8747482Spendry 	    $$ = $1; }
8847482Spendry 	;
8947482Spendry 
9047482Spendry /*
9147482Spendry  * A new host:
9247482Spendry  *
9347482Spendry  * host foo.domain
9447482Spendry  */
9547482Spendry host :
9647482Spendry 	  tHOST host_attr list_of_filesystems list_of_mounts
9747482Spendry 	  { $$ = $2; $$->h_disk_fs = $3; $$->h_mount = $4; }
9847482Spendry 
9947482Spendry 	| error tHOST host_attr list_of_filesystems list_of_mounts
10047482Spendry 	  { $$ = $3; $$->h_disk_fs = $4; $$->h_mount = $5; }
10147482Spendry 
10247482Spendry 	;
10347482Spendry 
10447482Spendry host_attr :
10547482Spendry 	  tSTR
10647482Spendry 	  { $$ = new_host(); set_host($$, HF_HOST, $1); }
10747482Spendry 
10847482Spendry 	| '{' host_attr_list '}' tSTR
10947482Spendry 	  { $$ = $2; set_host($$, HF_HOST, $4); }
11047482Spendry 
11147482Spendry 	;
11247482Spendry 
11347482Spendry host_attr_list :
11447482Spendry 	  /* empty */
11547482Spendry 	  { $$ = new_host(); }
11647482Spendry 
11747482Spendry 	| host_attr_list tNETIF tSTR '{' ether_attr '}'
11847482Spendry 	  { if ($5) {
11947482Spendry 		$5->e_if = $3;
12047482Spendry 		$$ = $1; set_host($$, HF_ETHER, $5); }
12147482Spendry 	  }
12247482Spendry 
12347482Spendry 	| host_attr_list tCONFIG tSTR
12447482Spendry 	  { $$ = $1; set_host($$, HF_CONFIG, $3); }
12547482Spendry 
12647482Spendry 	| host_attr_list tARCH '=' tSTR
12747482Spendry 	  { $$ = $1; set_host($$, HF_ARCH, $4); }
12847482Spendry 
12947482Spendry 	| host_attr_list tOS '=' tSTR
13047482Spendry 	  { $$ = $1; set_host($$, HF_OS, $4); }
13147482Spendry 
13247482Spendry 	| host_attr_list tCLUSTER '=' tSTR
13347482Spendry 	  { $$ = $1; set_host($$, HF_CLUSTER, $4); }
13447482Spendry 
13547482Spendry 	| host_attr_list error '=' tSTR
13647482Spendry 	  { yyerror("unknown host attribute"); }
13747482Spendry 	;
13847482Spendry 
13947482Spendry ether_attr :
14047482Spendry 	  /* empty */
14147482Spendry 	  { $$ = new_ether_if(); }
14247482Spendry 
14347482Spendry 	| ether_attr tINADDR '=' tSTR
14447482Spendry 	  { $$ = $1; set_ether_if($$, EF_INADDR, $4); }
14547482Spendry 	| ether_attr tNETMASK '=' tSTR
14647482Spendry 	  { $$ = $1; set_ether_if($$, EF_NETMASK, $4); }
14747482Spendry 	| ether_attr tHWADDR '=' tSTR
14847482Spendry 	  { $$ = $1; set_ether_if($$, EF_HWADDR, $4); }
14947482Spendry 	;
15047482Spendry 
15147482Spendry /*
15247482Spendry  * A new automount tree:
15347482Spendry  *
15447482Spendry  * automount /mountpoint { ... }
15547482Spendry  */
15647482Spendry automount :
15747482Spendry 	  tAUTOMOUNT opt_auto_opts automount_tree
15847482Spendry 	  { if ($3) {
15947482Spendry 		$$ = new_auto_tree($2, $3);
16047482Spendry 	    } else {
16147482Spendry 		$$ = 0;
16247482Spendry 	    }
16347482Spendry 	  }
16447482Spendry 
16547482Spendry 	| tAUTOMOUNT error
16647482Spendry 	  { $$ = 0; }
16747482Spendry 	;
16847482Spendry 
16947482Spendry opt_auto_opts :
17047482Spendry 	  /* empty */
17147482Spendry 	  { $$ = strdup(""); }
17247482Spendry 
17347482Spendry 	| tOPTS tSTR
17447482Spendry 	  { $$ = $2; }
17547482Spendry 	;
17647482Spendry 
17747482Spendry list_of_filesystems :
17847482Spendry 	  /* empty */
17947482Spendry 	  { $$ = 0; }
18047482Spendry 
18147482Spendry 	| list_of_filesystems filesystem
18247482Spendry 	  { if ($2) {
18347482Spendry 		if ($1)
18447482Spendry 			$$ = $1;
18547482Spendry 		else
18647482Spendry 			$$ = new_que();
18747482Spendry 		ins_que(&$2->d_q, $$->q_back);
18847482Spendry 	    } else {
18947482Spendry 		$$ = $1;
19047482Spendry 	    }
19147482Spendry 	  }
19247482Spendry 	;
19347482Spendry 
19447482Spendry /*
19547482Spendry  * A new filesystem:
19647482Spendry  *
19747482Spendry  * fs /dev/whatever { ... }
19847482Spendry  */
19947482Spendry filesystem :
20047482Spendry 	  tFS tSTR '{' fs_info_list '}'
20147482Spendry 	  { $4->d_dev = $2; $$ = $4; }
20247482Spendry 
20347482Spendry 	| tFS error '}'
20447482Spendry 	  { $$ = (disk_fs *) 0; }
20547482Spendry 	;
20647482Spendry 
20747482Spendry /*
20847482Spendry  * Per-filesystem information:
20947482Spendry  *
21047482Spendry  * fstype - the type of the filesystem (4.2, nfs, swap, export)
21147482Spendry  * opts - the mount options ("rw,grpid")
21247482Spendry  * passno - fsck pass number
21347482Spendry  * freq - dump frequency
21447482Spendry  * dumpset - tape set for filesystem dumps
21547482Spendry  * mount - where to mount this filesystem
21647482Spendry  * log - log device
21747482Spendry  */
21847482Spendry fs_info_list :
21947482Spendry 	  /* empty */
22047482Spendry 	  { $$ = new_disk_fs(); }
22147482Spendry 
22247482Spendry 	| fs_info_list tFSTYPE '=' tSTR
22347482Spendry 	  { $$ = $1; set_disk_fs($$, DF_FSTYPE, $4); }
22447482Spendry 
22547482Spendry 	| fs_info_list tOPTS '=' tSTR
22647482Spendry 	  { $$ = $1; set_disk_fs($$, DF_OPTS, $4); }
22747482Spendry 
22847482Spendry 	| fs_info_list tPASSNO '=' tSTR
22947482Spendry 	  { $$ = $1; set_disk_fs($$, DF_PASSNO, $4); }
23047482Spendry 
23147482Spendry 	| fs_info_list tFREQ '=' tSTR
23247482Spendry 	  { $$ = $1; set_disk_fs($$, DF_FREQ, $4); }
23347482Spendry 
23447482Spendry 	| fs_info_list tMOUNT dir_tree
23547482Spendry 	  { $$ = $1; set_disk_fs($$, DF_MOUNT, (char *) $3); }
23647482Spendry 
23747482Spendry 	| fs_info_list tDUMPSET '=' tSTR
23847482Spendry 	  { $$ = $1; set_disk_fs($$, DF_DUMPSET, $4); }
23947482Spendry 
24047482Spendry 	| fs_info_list tLOG '=' tSTR
24147482Spendry 	  { $$ = $1; set_disk_fs($$, DF_LOG, $4); }
24247482Spendry 
24347482Spendry 	| fs_info_list error '=' tSTR
24447482Spendry 	  { yyerror("unknown filesystem attribute"); }
24547482Spendry 	;
24647482Spendry 
24747482Spendry /*
24847482Spendry  * An automount tree:
24947482Spendry  *
25047482Spendry  * name = "volname"	name is a reference to volname
25147482Spendry  * name -> "string"	name is a link to "string"
25247482Spendry  * name { ... }		name is an automount tree
25347482Spendry  */
25447482Spendry automount_tree :
25547482Spendry 	  /* empty */
25647482Spendry 	  { $$ = 0; }
25747482Spendry 
25847482Spendry 	| automount_tree tSTR '=' tSTR
25947482Spendry 	  { automount *a = new_automount($2);
26047482Spendry 	    a->a_volname = $4;
26147482Spendry 	    if ($1)
26247482Spendry 		$$ = $1;
26347482Spendry 	    else
26447482Spendry 		$$ = new_que();
26547482Spendry 	    ins_que(&a->a_q, $$->q_back);
26647482Spendry 	  }
26747482Spendry 
26847482Spendry 	| automount_tree tSTR tEQ tSTR
26947482Spendry 	  { automount *a = new_automount($2);
27047482Spendry 	    a->a_symlink = $4;
27147482Spendry 	    if ($1)
27247482Spendry 		$$ = $1;
27347482Spendry 	    else
27447482Spendry 		$$ = new_que();
27547482Spendry 	    ins_que(&a->a_q, $$->q_back);
27647482Spendry 	  }
27747482Spendry 
27847482Spendry 	| automount_tree tSTR '{' automount_tree '}'
27947482Spendry 	  { automount *a = new_automount($2);
28047482Spendry 	    a->a_mount = $4;
28147482Spendry 	    if ($1)
28247482Spendry 		$$ = $1;
28347482Spendry 	    else
28447482Spendry 		$$ = new_que();
28547482Spendry 	    ins_que(&a->a_q, $$->q_back);
28647482Spendry 	  }
28747482Spendry 	;
28847482Spendry 
28947482Spendry dir_tree :
29047482Spendry 	  /* empty */
29147482Spendry 	  { $$ = 0; }
29247482Spendry 
29347482Spendry 	| dir_tree tSTR '{' dir_tree_info dir_tree '}'
29447482Spendry 	  { $4->m_mount = $5;
29547482Spendry 	    $4->m_name = $2;
29647482Spendry 	    if ($2[0] != '/' && $2[1] && strchr($2+1, '/'))
29747482Spendry 		yyerror("not allowed '/' in a directory name");
29847482Spendry 	    if ($1)
29947482Spendry 		$$ = $1;
30047482Spendry 	    else
30147482Spendry 		$$ = new_que();
30247482Spendry 	    ins_que(&$4->m_q, $$->q_back);
30347482Spendry 	  }
30447482Spendry 	;
30547482Spendry 
30647482Spendry dir_tree_info :
30747482Spendry 	  /* empty */
30847482Spendry 	  { $$ = new_mount(); }
30947482Spendry 
31047482Spendry 	| dir_tree_info tEXPORTFS tSTR
31147482Spendry 	  { $$ = $1; set_mount($$, DM_EXPORTFS, $3); }
31247482Spendry 
31347482Spendry 	| dir_tree_info tVOLNAME tSTR
31447482Spendry 	  { $$ = $1; set_mount($$, DM_VOLNAME, $3); }
31547482Spendry 
31647482Spendry 	| dir_tree_info tSEL tSTR
31747482Spendry 	  { $$ = $1; set_mount($$, DM_SEL, $3); }
31847482Spendry 
31947482Spendry 	| dir_tree_info error '=' tSTR
32047482Spendry 	  { yyerror("unknown directory attribute"); }
32147482Spendry 	;
32247482Spendry 
32347482Spendry /*
32447482Spendry  * Additional mounts on a host
32547482Spendry  *
32647482Spendry  * mount "volname" ...
32747482Spendry  */
32847482Spendry list_of_mounts :
32947482Spendry 	  /* empty */
33047482Spendry 	  { $$ = 0; }
33147482Spendry 
33247482Spendry 	| list_of_mounts tMOUNT tSTR localinfo_list
33347482Spendry 	  { set_fsmount($4, FM_VOLNAME, $3);
33447482Spendry 	    if ($1)
33547482Spendry 		$$ = $1;
33647482Spendry 	    else
33747482Spendry 		$$ = new_que();
33847482Spendry 	    ins_que(&$4->f_q, $$->q_back);
33947482Spendry 	    }
34047482Spendry 	;
34147482Spendry 
34247482Spendry /*
34347482Spendry  * Mount info:
34447482Spendry  *
34547482Spendry  * from "hostname"	- obtain the object from the named host
34647482Spendry  * as "string"		- where to mount, if different from the volname
34747482Spendry  * opts "string"	- mount options
34847482Spendry  * fstype "type"	- type of filesystem mount, if not nfs
34947482Spendry  */
35047482Spendry localinfo_list :
35147482Spendry 	  /* empty */
35247482Spendry 	  { $$ = new_fsmount(); }
35347482Spendry 
35447482Spendry 	| localinfo_list tAS tSTR
35547482Spendry 	  { $$ = $1; set_fsmount($$, FM_LOCALNAME, $3); }
35647482Spendry 
35747482Spendry 	| localinfo_list tFROM tSTR
35847482Spendry 	  { $$ = $1; set_fsmount($$, FM_FROM, $3); }
35947482Spendry 
36047482Spendry 	| localinfo_list tFSTYPE tSTR
36147482Spendry 	  { $$ = $1; set_fsmount($$, FM_FSTYPE, $3); }
36247482Spendry 
36347482Spendry 	| localinfo_list tOPTS tSTR
36447482Spendry 	  { $$ = $1; set_fsmount($$, FM_OPTS, $3); }
36547482Spendry 
36647482Spendry 	| localinfo_list error '=' tSTR
36747482Spendry 	  { yyerror("unknown mount attribute"); }
36847482Spendry 	;
369