home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / bsd_srcs / usr.sbin / amd / fsinfo / fsi_gram.y < prev    next >
Encoding:
Text File  |  1991-05-12  |  8.7 KB  |  395 lines

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