138494Sobrien/* 2174294Sobrien * Copyright (c) 1997-2006 Erez Zadok 338494Sobrien * Copyright (c) 1989 Jan-Simon Pendry 438494Sobrien * Copyright (c) 1989 Imperial College of Science, Technology & Medicine 538494Sobrien * Copyright (c) 1989 The Regents of the University of California. 638494Sobrien * All rights reserved. 738494Sobrien * 838494Sobrien * This code is derived from software contributed to Berkeley by 938494Sobrien * Jan-Simon Pendry at Imperial College, London. 1038494Sobrien * 1138494Sobrien * Redistribution and use in source and binary forms, with or without 1238494Sobrien * modification, are permitted provided that the following conditions 1338494Sobrien * are met: 1438494Sobrien * 1. Redistributions of source code must retain the above copyright 1538494Sobrien * notice, this list of conditions and the following disclaimer. 1638494Sobrien * 2. Redistributions in binary form must reproduce the above copyright 1738494Sobrien * notice, this list of conditions and the following disclaimer in the 1838494Sobrien * documentation and/or other materials provided with the distribution. 1938494Sobrien * 3. All advertising materials mentioning features or use of this software 2042629Sobrien * must display the following acknowledgment: 2138494Sobrien * This product includes software developed by the University of 2238494Sobrien * California, Berkeley and its contributors. 2338494Sobrien * 4. Neither the name of the University nor the names of its contributors 2438494Sobrien * may be used to endorse or promote products derived from this software 2538494Sobrien * without specific prior written permission. 2638494Sobrien * 2738494Sobrien * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2838494Sobrien * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2938494Sobrien * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 3038494Sobrien * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 3138494Sobrien * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3238494Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3338494Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3438494Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3538494Sobrien * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3638494Sobrien * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3738494Sobrien * SUCH DAMAGE. 3838494Sobrien * 3938494Sobrien * 40174294Sobrien * File: am-utils/fsinfo/fsi_gram.y 4138494Sobrien * 4238494Sobrien */ 4338494Sobrien 4438494Sobrien%{ 4538494Sobrien#ifdef HAVE_CONFIG_H 4638494Sobrien# include <config.h> 4738494Sobrien#endif /* HAVE_CONFIG_H */ 4838494Sobrien#include <am_defs.h> 4938494Sobrien#include <fsi_data.h> 5038494Sobrien#include <fsinfo.h> 5138494Sobrien 5238494Sobrienextern qelem *list_of_hosts, *list_of_automounts; 5338494Sobrien%} 5438494Sobrien 5538494Sobrien%union { 5638494Sobrien auto_tree *a; 5738494Sobrien disk_fs *d; 5838494Sobrien ether_if *e; 5938494Sobrien host *h; 6038494Sobrien qelem *q; 6138494Sobrien char *s; 6238494Sobrien fsi_mount *m; 6338494Sobrien fsmount *f; 6438494Sobrien} 6538494Sobrien 6638494Sobrien%token tARCH 6738494Sobrien%token tAS 6838494Sobrien%token tAUTOMOUNT 6938494Sobrien%token tCLUSTER 7038494Sobrien%token tCONFIG 7138494Sobrien%token tDUMPSET 7238494Sobrien%token tEQ 7338494Sobrien%token tNFSEQ 7438494Sobrien%token tEXPORTFS 7538494Sobrien%token tFREQ 7638494Sobrien%token tFROM 7738494Sobrien%token tFS 7838494Sobrien%token tFSTYPE 7938494Sobrien%token tHWADDR 8038494Sobrien%token tINADDR 8138494Sobrien%token tHOST 8238494Sobrien%token tLOCALHOST 8338494Sobrien%token tLOG 8438494Sobrien%token tMOUNT 8538494Sobrien%token tNETMASK 8638494Sobrien%token tNETIF 8738494Sobrien%token tVOLNAME 8838494Sobrien%token tOPTS 8938494Sobrien%token tOS 9038494Sobrien%token tPASSNO 9138494Sobrien%token tDIRECT 9238494Sobrien%token tSEL 9338494Sobrien%token <s> tSTR 9438494Sobrien 9538494Sobrien%start list_of_hosts 9638494Sobrien 9738494Sobrien%type <a> automount 9838494Sobrien%type <q> automount_tree 9938494Sobrien%type <e> ether_attr 10038494Sobrien%type <m> dir_tree_info 10138494Sobrien%type <d> filesystem fs_info_list 10238494Sobrien%type <h> host host_attr host_attr_list 10338494Sobrien%type <q> list_of_hosts list_of_filesystems list_of_mounts dir_tree 10438494Sobrien%type <f> localinfo_list 10538494Sobrien%type <s> opt_auto_opts 10638494Sobrien 10738494Sobrien%% 10838494Sobrien 10938494Sobrienlist_of_hosts : 11038494Sobrien /* empty */ 11138494Sobrien { $$ = new_que(); } 11238494Sobrien 11338494Sobrien | list_of_hosts host 11438494Sobrien { if ($2) ins_que((qelem *) $2, list_of_hosts->q_back); 11538494Sobrien $$ = $1; } 11638494Sobrien 11738494Sobrien | list_of_hosts automount 11838494Sobrien { if ($2) ins_que((qelem *) $2, list_of_automounts->q_back); 11938494Sobrien $$ = $1; } 12038494Sobrien ; 12138494Sobrien 12238494Sobrien/* 12338494Sobrien * A new host: 12438494Sobrien * 12538494Sobrien * host foo.domain 12638494Sobrien */ 12738494Sobrienhost : 12838494Sobrien tHOST host_attr list_of_filesystems list_of_mounts 12938494Sobrien { $$ = $2; $$->h_disk_fs = $3; $$->h_mount = $4; } 13038494Sobrien 13138494Sobrien | error tHOST host_attr list_of_filesystems list_of_mounts 13238494Sobrien { $$ = $3; $$->h_disk_fs = $4; $$->h_mount = $5; } 13338494Sobrien 13438494Sobrien ; 13538494Sobrien 13638494Sobrienhost_attr : 13738494Sobrien tSTR 13838494Sobrien { $$ = new_host(); set_host($$, HF_HOST, $1); } 13938494Sobrien 14038494Sobrien | '{' host_attr_list '}' tSTR 14138494Sobrien { $$ = $2; set_host($$, HF_HOST, $4); } 14238494Sobrien 14338494Sobrien ; 14438494Sobrien 14538494Sobrienhost_attr_list : 14638494Sobrien /* empty */ 14738494Sobrien { $$ = new_host(); } 14838494Sobrien 14938494Sobrien | host_attr_list tNETIF tSTR '{' ether_attr '}' 15038494Sobrien { if ($5) { 15138494Sobrien $5->e_if = $3; 15238494Sobrien $$ = $1; set_host($$, HF_ETHER, (char *) $5); } 15338494Sobrien } 15438494Sobrien 15538494Sobrien | host_attr_list tCONFIG tSTR 15638494Sobrien { $$ = $1; set_host($$, HF_CONFIG, $3); } 15738494Sobrien 15838494Sobrien | host_attr_list tARCH '=' tSTR 15938494Sobrien { $$ = $1; set_host($$, HF_ARCH, $4); } 16038494Sobrien 16138494Sobrien | host_attr_list tOS '=' tSTR 16238494Sobrien { $$ = $1; set_host($$, HF_OS, $4); } 16338494Sobrien 16438494Sobrien | host_attr_list tCLUSTER '=' tSTR 16538494Sobrien { $$ = $1; set_host($$, HF_CLUSTER, $4); } 16638494Sobrien 16738494Sobrien | host_attr_list error '=' tSTR 16838494Sobrien { yyerror("unknown host attribute"); } 16938494Sobrien ; 17038494Sobrien 17138494Sobrienether_attr : 17238494Sobrien /* empty */ 17338494Sobrien { $$ = new_ether_if(); } 17438494Sobrien 17538494Sobrien | ether_attr tINADDR '=' tSTR 17638494Sobrien { $$ = $1; set_ether_if($$, EF_INADDR, $4); } 17738494Sobrien | ether_attr tNETMASK '=' tSTR 17838494Sobrien { $$ = $1; set_ether_if($$, EF_NETMASK, $4); } 17938494Sobrien | ether_attr tHWADDR '=' tSTR 18038494Sobrien { $$ = $1; set_ether_if($$, EF_HWADDR, $4); } 18138494Sobrien ; 18238494Sobrien 18338494Sobrien/* 18438494Sobrien * A new automount tree: 18538494Sobrien * 18638494Sobrien * automount /mountpoint { ... } 18738494Sobrien */ 18838494Sobrienautomount : 18938494Sobrien tAUTOMOUNT opt_auto_opts automount_tree 19038494Sobrien { if ($3) { 19138494Sobrien $$ = new_auto_tree($2, $3); 19238494Sobrien } else { 19338494Sobrien $$ = 0; 19438494Sobrien } 19538494Sobrien } 19638494Sobrien 19738494Sobrien | tAUTOMOUNT error 19838494Sobrien { $$ = 0; } 19938494Sobrien ; 20038494Sobrien 20138494Sobrienopt_auto_opts : 20238494Sobrien /* empty */ 20338494Sobrien { $$ = strdup(""); } 20438494Sobrien 20538494Sobrien | tOPTS tSTR 20638494Sobrien { $$ = $2; } 20738494Sobrien ; 20838494Sobrien 20938494Sobrienlist_of_filesystems : 21038494Sobrien /* empty */ 21138494Sobrien { $$ = 0; } 21238494Sobrien 21338494Sobrien | list_of_filesystems filesystem 21438494Sobrien { if ($2) { 21538494Sobrien if ($1) 21638494Sobrien $$ = $1; 21738494Sobrien else 21838494Sobrien $$ = new_que(); 21938494Sobrien ins_que(&$2->d_q, $$->q_back); 22038494Sobrien } else { 22138494Sobrien $$ = $1; 22238494Sobrien } 22338494Sobrien } 22438494Sobrien ; 22538494Sobrien 22638494Sobrien/* 22738494Sobrien * A new filesystem: 22838494Sobrien * 22938494Sobrien * fs /dev/whatever { ... } 23038494Sobrien */ 23138494Sobrienfilesystem : 23238494Sobrien tFS tSTR '{' fs_info_list '}' 23338494Sobrien { $4->d_dev = $2; $$ = $4; } 23438494Sobrien 23538494Sobrien | tFS error '}' 23638494Sobrien { $$ = (disk_fs *) 0; } 23738494Sobrien ; 23838494Sobrien 23938494Sobrien/* 24038494Sobrien * Per-filesystem information: 24138494Sobrien * 24238494Sobrien * fstype - the type of the filesystem (4.2, nfs, swap, export) 24338494Sobrien * opts - the mount options ("rw,grpid") 24438494Sobrien * passno - fsck pass number 24538494Sobrien * freq - dump frequency 24638494Sobrien * dumpset - tape set for filesystem dumps 24738494Sobrien * mount - where to mount this filesystem 24838494Sobrien * log - log device 24938494Sobrien */ 25038494Sobrienfs_info_list : 25138494Sobrien /* empty */ 25238494Sobrien { $$ = new_disk_fs(); } 25338494Sobrien 25438494Sobrien | fs_info_list tFSTYPE '=' tSTR 25538494Sobrien { $$ = $1; set_disk_fs($$, DF_FSTYPE, $4); } 25638494Sobrien 25738494Sobrien | fs_info_list tOPTS '=' tSTR 25838494Sobrien { $$ = $1; set_disk_fs($$, DF_OPTS, $4); } 25938494Sobrien 26038494Sobrien | fs_info_list tPASSNO '=' tSTR 26138494Sobrien { $$ = $1; set_disk_fs($$, DF_PASSNO, $4); } 26238494Sobrien 26338494Sobrien | fs_info_list tFREQ '=' tSTR 26438494Sobrien { $$ = $1; set_disk_fs($$, DF_FREQ, $4); } 26538494Sobrien 26638494Sobrien | fs_info_list tMOUNT dir_tree 26738494Sobrien { $$ = $1; set_disk_fs($$, DF_MOUNT, (char *) $3); } 26838494Sobrien 26938494Sobrien | fs_info_list tDUMPSET '=' tSTR 27038494Sobrien { $$ = $1; set_disk_fs($$, DF_DUMPSET, $4); } 27138494Sobrien 27238494Sobrien | fs_info_list tLOG '=' tSTR 27338494Sobrien { $$ = $1; set_disk_fs($$, DF_LOG, $4); } 27438494Sobrien 27538494Sobrien | fs_info_list error '=' tSTR 27638494Sobrien { yyerror("unknown filesystem attribute"); } 27738494Sobrien ; 27838494Sobrien 27938494Sobrien/* 28038494Sobrien * An automount tree: 28138494Sobrien * 28238494Sobrien * name = "volname" name is a reference to volname 28338494Sobrien * name -> "string" name is a link to "string" 28438494Sobrien * name nfsalias "string" name is a link to "string", string parsed as NFS 28538494Sobrien * pathname. 28638494Sobrien * name { ... } name is an automount tree 28738494Sobrien */ 28838494Sobrienautomount_tree : 28938494Sobrien /* empty */ 29038494Sobrien { $$ = 0; } 29138494Sobrien 29238494Sobrien | automount_tree tSTR opt_auto_opts '=' tSTR 29338494Sobrien { automount *a = new_automount($2); 29438494Sobrien a->a_volname = $5; 29538494Sobrien a->a_opts = $3; 29638494Sobrien if ($1) 29738494Sobrien $$ = $1; 29838494Sobrien else 29938494Sobrien $$ = new_que(); 30038494Sobrien ins_que(&a->a_q, $$->q_back); 30138494Sobrien } 30238494Sobrien | automount_tree tSTR opt_auto_opts tNFSEQ tSTR 30338494Sobrien { automount *a = new_automount($2); 30438494Sobrien a->a_hardwiredfs = $5; 30538494Sobrien a->a_opts = $3; 30638494Sobrien if ($1) 30738494Sobrien $$ = $1; 30838494Sobrien else 30938494Sobrien $$ = new_que(); 31038494Sobrien ins_que(&a->a_q, $$->q_back); 31138494Sobrien } 31238494Sobrien 31338494Sobrien | automount_tree tSTR tEQ tSTR 31438494Sobrien { automount *a = new_automount($2); 31538494Sobrien a->a_symlink = $4; 31638494Sobrien if ($1) 31738494Sobrien $$ = $1; 31838494Sobrien else 31938494Sobrien $$ = new_que(); 32038494Sobrien ins_que(&a->a_q, $$->q_back); 32138494Sobrien } 32238494Sobrien 32338494Sobrien | automount_tree tSTR opt_auto_opts '{' automount_tree '}' 32438494Sobrien { automount *a = new_automount($2); 32538494Sobrien a->a_mount = $5; 32638494Sobrien a->a_opts = $3; 32738494Sobrien if ($1) 32838494Sobrien $$ = $1; 32938494Sobrien else 33038494Sobrien $$ = new_que(); 33138494Sobrien ins_que(&a->a_q, $$->q_back); 33238494Sobrien } 33338494Sobrien ; 33438494Sobrien 33538494Sobriendir_tree : 33638494Sobrien /* empty */ 33738494Sobrien { $$ = 0; } 33838494Sobrien 33938494Sobrien | dir_tree tSTR '{' dir_tree_info dir_tree '}' 34038494Sobrien { $4->m_mount = $5; 34138494Sobrien $4->m_name = $2; 34238494Sobrien if ($2[0] != '/' && $2[1] && strchr($2+1, '/')) 34338494Sobrien yyerror("not allowed '/' in a directory name"); 34438494Sobrien if ($1) 34538494Sobrien $$ = $1; 34638494Sobrien else 34738494Sobrien $$ = new_que(); 34838494Sobrien ins_que(&$4->m_q, $$->q_back); 34938494Sobrien } 35038494Sobrien ; 35138494Sobrien 35238494Sobriendir_tree_info : 35338494Sobrien /* empty */ 35438494Sobrien { $$ = new_mount(); } 35538494Sobrien 35638494Sobrien | dir_tree_info tEXPORTFS tSTR 35738494Sobrien { $$ = $1; set_mount($$, DM_EXPORTFS, $3); } 35838494Sobrien 35938494Sobrien | dir_tree_info tVOLNAME tSTR 36038494Sobrien { $$ = $1; set_mount($$, DM_VOLNAME, $3); } 36138494Sobrien 36238494Sobrien | dir_tree_info tSEL tSTR 36338494Sobrien { $$ = $1; set_mount($$, DM_SEL, $3); } 36438494Sobrien 36538494Sobrien | dir_tree_info error '=' tSTR 36638494Sobrien { yyerror("unknown directory attribute"); } 36738494Sobrien ; 36838494Sobrien 36938494Sobrien/* 37038494Sobrien * Additional mounts on a host 37138494Sobrien * 37238494Sobrien * mount "volname" ... 37338494Sobrien */ 37438494Sobrienlist_of_mounts : 37538494Sobrien /* empty */ 37638494Sobrien { $$ = 0; } 37738494Sobrien 37838494Sobrien | list_of_mounts tMOUNT tSTR localinfo_list 37938494Sobrien { set_fsmount($4, FM_VOLNAME, $3); 38038494Sobrien if ($1) 38138494Sobrien $$ = $1; 38238494Sobrien else 38338494Sobrien $$ = new_que(); 38438494Sobrien ins_que(&$4->f_q, $$->q_back); 38538494Sobrien } 38638494Sobrien ; 38738494Sobrien 38838494Sobrien/* 38938494Sobrien * Mount info: 39038494Sobrien * 39138494Sobrien * from "hostname" - obtain the object from the named host 39238494Sobrien * as "string" - where to mount, if different from the volname 39338494Sobrien * opts "string" - mount options 39438494Sobrien * fstype "type" - type of filesystem mount, if not nfs 39538494Sobrien * direct - mount entry, no need to create ad-hoc hosts file 39638494Sobrien */ 39738494Sobrienlocalinfo_list : 39838494Sobrien /* empty */ 39938494Sobrien { $$ = new_fsmount(); } 40038494Sobrien 40138494Sobrien | localinfo_list tDIRECT 40238494Sobrien { $$ = $1; set_fsmount($$, FM_DIRECT, ""); } 40338494Sobrien 40438494Sobrien | localinfo_list tAS tSTR 40538494Sobrien { $$ = $1; set_fsmount($$, FM_LOCALNAME, $3); } 40638494Sobrien 40738494Sobrien | localinfo_list tFROM tSTR 40838494Sobrien { $$ = $1; set_fsmount($$, FM_FROM, $3); } 40938494Sobrien 41038494Sobrien | localinfo_list tFSTYPE tSTR 41138494Sobrien { $$ = $1; set_fsmount($$, FM_FSTYPE, $3); } 41238494Sobrien 41338494Sobrien | localinfo_list tOPTS tSTR 41438494Sobrien { $$ = $1; set_fsmount($$, FM_OPTS, $3); } 41538494Sobrien 41638494Sobrien | localinfo_list error '=' tSTR 41738494Sobrien { yyerror("unknown mount attribute"); } 41838494Sobrien ; 419