Home | History | Annotate | Line # | Download | only in amd
      1  1.4  christos /*	$NetBSD: sun_map_parse.y,v 1.4 2015/01/17 17:46:31 christos Exp $	*/
      2  1.1  christos 
      3  1.1  christos %{
      4  1.1  christos /*
      5  1.4  christos  * Copyright (c) 1997-2014 Erez Zadok
      6  1.1  christos  * Copyright (c) 2005 Daniel P. Ottavio
      7  1.1  christos  * Copyright (c) 1990 Jan-Simon Pendry
      8  1.1  christos  * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
      9  1.1  christos  * Copyright (c) 1990 The Regents of the University of California.
     10  1.1  christos  * All rights reserved.
     11  1.1  christos  *
     12  1.1  christos  * This code is derived from software contributed to Berkeley by
     13  1.1  christos  * Jan-Simon Pendry at Imperial College, London.
     14  1.1  christos  *
     15  1.1  christos  * Redistribution and use in source and binary forms, with or without
     16  1.1  christos  * modification, are permitted provided that the following conditions
     17  1.1  christos  * are met:
     18  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     19  1.1  christos  *    notice, this list of conditions and the following disclaimer.
     20  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     21  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     22  1.1  christos  *    documentation and/or other materials provided with the distribution.
     23  1.4  christos  * 3. Neither the name of the University nor the names of its contributors
     24  1.1  christos  *    may be used to endorse or promote products derived from this software
     25  1.1  christos  *    without specific prior written permission.
     26  1.1  christos  *
     27  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     28  1.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     29  1.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     30  1.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     31  1.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     32  1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     33  1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     34  1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     35  1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     36  1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     37  1.1  christos  * SUCH DAMAGE.
     38  1.1  christos  *
     39  1.1  christos  *
     40  1.1  christos  * File: am-utils/amd/sun_map_parse.y
     41  1.1  christos  *
     42  1.1  christos  */
     43  1.1  christos 
     44  1.1  christos #ifdef HAVE_CONFIG_H
     45  1.1  christos # include <config.h>
     46  1.1  christos #endif /* HAVE_CONFIG_H */
     47  1.1  christos #include <am_defs.h>
     48  1.1  christos #include <amd.h>
     49  1.1  christos #include <sun_map.h>
     50  1.1  christos 
     51  1.1  christos 
     52  1.1  christos #define SUN_FSTYPE_STR  "fstype="
     53  1.1  christos 
     54  1.1  christos 
     55  1.1  christos extern int sun_map_lex(void);
     56  1.1  christos extern int sun_map_error(const char *);
     57  1.1  christos extern void sun_map_tok_setbuff(const char *);
     58  1.1  christos extern int sun_map_parse(void);
     59  1.1  christos 
     60  1.1  christos struct sun_entry *sun_map_parse_read(const char *);
     61  1.1  christos 
     62  1.1  christos static struct sun_list *sun_entry_list = NULL;
     63  1.1  christos static struct sun_list *sun_opt_list = NULL;
     64  1.1  christos static struct sun_list *sun_host_list = NULL;
     65  1.1  christos static struct sun_list *sun_location_list = NULL;
     66  1.1  christos static struct sun_list *mountpt_list = NULL;
     67  1.1  christos static char *tmpFsType = NULL;
     68  1.1  christos 
     69  1.1  christos 
     70  1.1  christos /*
     71  1.1  christos  * Each get* function returns a pointer to the corresponding global
     72  1.1  christos  * list structure.  If the structure is NULL than a new instance is
     73  1.1  christos  * returned.
     74  1.1  christos  */
     75  1.2  christos static struct sun_list *get_sun_opt_list(void);
     76  1.2  christos static struct sun_list *get_sun_host_list(void);
     77  1.2  christos static struct sun_list *get_sun_location_list(void);
     78  1.2  christos static struct sun_list *get_mountpt_list(void);
     79  1.2  christos static struct sun_list *get_sun_entry_list(void);
     80  1.1  christos 
     81  1.1  christos %}
     82  1.1  christos 
     83  1.1  christos %union {
     84  1.1  christos   char strval[2048];
     85  1.1  christos }
     86  1.1  christos 
     87  1.1  christos %token NEWLINE COMMENT WSPACE
     88  1.1  christos %token <strval> WORD
     89  1.1  christos 
     90  1.1  christos %%
     91  1.1  christos 
     92  1.1  christos amap : file
     93  1.1  christos      ;
     94  1.1  christos 
     95  1.1  christos file : new_lines entries
     96  1.1  christos      | entries
     97  1.1  christos      ;
     98  1.1  christos 
     99  1.1  christos entries : entry
    100  1.1  christos         | entry new_lines
    101  1.1  christos         | entry new_lines entries
    102  1.1  christos         ;
    103  1.1  christos 
    104  1.1  christos new_lines : NEWLINE
    105  1.1  christos           | NEWLINE new_lines
    106  1.1  christos           ;
    107  1.1  christos 
    108  1.1  christos entry : locations {
    109  1.1  christos 
    110  1.1  christos   struct sun_list *list;
    111  1.1  christos   struct sun_entry *entry;
    112  1.1  christos 
    113  1.1  christos   /* allocate an entry */
    114  1.1  christos   entry = CALLOC(struct sun_entry);
    115  1.1  christos 
    116  1.1  christos   /*
    117  1.1  christos    * Assign the global location list to this entry and reset the
    118  1.1  christos    * global pointer.  Reseting the global pointer will create a new
    119  1.1  christos    * list instance next time get_sun_location_list() is called.
    120  1.1  christos    */
    121  1.1  christos   list = get_sun_location_list();
    122  1.1  christos   entry->location_list = (struct sun_location *)list->first;
    123  1.1  christos   sun_location_list = NULL;
    124  1.1  christos 
    125  1.1  christos    /* Add this entry to the entry list. */
    126  1.1  christos   sun_list_add(get_sun_entry_list(), (qelem *)entry);
    127  1.1  christos }
    128  1.1  christos 
    129  1.1  christos | '-' options WSPACE locations {
    130  1.1  christos 
    131  1.1  christos   struct sun_list *list;
    132  1.1  christos   struct sun_entry *entry;
    133  1.1  christos 
    134  1.1  christos   entry = CALLOC(struct sun_entry);
    135  1.1  christos 
    136  1.1  christos   /* An fstype may have been defined in the 'options'. */
    137  1.1  christos   if (tmpFsType != NULL) {
    138  1.1  christos     entry->fstype = tmpFsType;
    139  1.1  christos     tmpFsType = NULL;
    140  1.1  christos   }
    141  1.1  christos 
    142  1.1  christos   /*
    143  1.1  christos    * Assign the global location list to this entry and reset the
    144  1.1  christos    * global pointer.  Reseting the global pointer will create a new
    145  1.1  christos    * list instance next time get_sun_location_list() is called.
    146  1.1  christos    */
    147  1.1  christos   list = get_sun_location_list();
    148  1.1  christos   entry->location_list = (struct sun_location *)list->first;
    149  1.1  christos   sun_location_list = NULL;
    150  1.1  christos 
    151  1.1  christos   /*
    152  1.1  christos    * Assign the global opt list to this entry and reset the global
    153  1.1  christos    * pointer.  Reseting the global pointer will create a new list
    154  1.1  christos    * instance next time get_sun_opt_list() is called.
    155  1.1  christos    */
    156  1.1  christos   list = get_sun_opt_list();
    157  1.1  christos   entry->opt_list = (struct sun_opt *)list->first;
    158  1.1  christos   sun_opt_list = NULL;
    159  1.1  christos 
    160  1.1  christos   /* Add this entry to the entry list. */
    161  1.1  christos   sun_list_add(get_sun_entry_list(), (qelem *)entry);
    162  1.1  christos }
    163  1.1  christos 
    164  1.1  christos | mountpoints {
    165  1.1  christos 
    166  1.1  christos   struct sun_list *list;
    167  1.1  christos   struct sun_entry *entry;
    168  1.1  christos 
    169  1.1  christos   /* allocate an entry */
    170  1.1  christos   entry = CALLOC(struct sun_entry);
    171  1.1  christos 
    172  1.1  christos   /*
    173  1.1  christos    * Assign the global mountpt list to this entry and reset the global
    174  1.1  christos    * pointer.  Reseting the global pointer will create a new list
    175  1.1  christos    * instance next time get_mountpt_list() is called.
    176  1.1  christos    */
    177  1.1  christos   list = get_mountpt_list();
    178  1.1  christos   entry->mountpt_list = (struct sun_mountpt *)list->first;
    179  1.1  christos   mountpt_list = NULL;
    180  1.1  christos 
    181  1.1  christos   /* Add this entry to the entry list. */
    182  1.1  christos   sun_list_add(get_sun_entry_list(), (qelem *)entry);
    183  1.1  christos }
    184  1.1  christos 
    185  1.1  christos | '-' options WSPACE mountpoints {
    186  1.1  christos 
    187  1.1  christos   struct sun_list *list;
    188  1.1  christos   struct sun_entry *entry;
    189  1.1  christos 
    190  1.1  christos   /* allocate an entry */
    191  1.1  christos   entry = CALLOC(struct sun_entry);
    192  1.1  christos 
    193  1.1  christos   /* An fstype may have been defined in the 'options'. */
    194  1.1  christos   if (tmpFsType != NULL) {
    195  1.1  christos     entry->fstype = tmpFsType;
    196  1.1  christos     tmpFsType = NULL;
    197  1.1  christos   }
    198  1.1  christos 
    199  1.1  christos   /*
    200  1.1  christos    * Assign the global mountpt list to this entry and reset the global
    201  1.1  christos    * pointer.  Reseting the global pointer will create a new list
    202  1.1  christos    * instance next time get_mountpt_list() is called.
    203  1.1  christos    */
    204  1.1  christos   list = get_mountpt_list();
    205  1.1  christos   entry->mountpt_list = (struct sun_mountpt *)list->first;
    206  1.1  christos   mountpt_list = NULL;
    207  1.1  christos 
    208  1.1  christos   /*
    209  1.1  christos    * Assign the global opt list to this entry and reset the global
    210  1.1  christos    * pointer.  Reseting the global pointer will create a new list
    211  1.1  christos    * instance next time get_sun_opt_list() is called.
    212  1.1  christos    */
    213  1.1  christos   list = get_sun_opt_list();
    214  1.1  christos   entry->opt_list = (struct sun_opt *)list->first;
    215  1.1  christos   sun_opt_list = NULL;
    216  1.1  christos 
    217  1.1  christos   /* Add this entry to the entry list. */
    218  1.1  christos   sun_list_add(get_sun_entry_list(), (qelem *)entry);
    219  1.1  christos }
    220  1.1  christos ;
    221  1.1  christos 
    222  1.1  christos mountpoints : mountpoint
    223  1.1  christos             | mountpoint WSPACE mountpoints
    224  1.1  christos             ;
    225  1.1  christos 
    226  1.1  christos mountpoint : WORD WSPACE location {
    227  1.1  christos 
    228  1.1  christos   struct sun_list *list;
    229  1.1  christos   struct sun_mountpt *mountpt;
    230  1.1  christos 
    231  1.1  christos   /* allocate a mountpt */
    232  1.1  christos   mountpt = CALLOC(struct sun_mountpt);
    233  1.1  christos 
    234  1.1  christos   /*
    235  1.1  christos    * Assign the global loaction list to this entry and reset the
    236  1.1  christos    * global pointer.  Reseting the global pointer will create a new
    237  1.1  christos    * list instance next time get_sun_location_list() is called.
    238  1.1  christos    */
    239  1.1  christos   list = get_sun_location_list();
    240  1.1  christos   mountpt->location_list = (struct sun_location *)list->first;
    241  1.1  christos   sun_location_list = NULL;
    242  1.1  christos 
    243  1.4  christos   mountpt->path = xstrdup($1);
    244  1.1  christos 
    245  1.1  christos   /* Add this mountpt to the mountpt list. */
    246  1.1  christos   sun_list_add(get_mountpt_list(), (qelem *)mountpt);
    247  1.1  christos }
    248  1.1  christos 
    249  1.1  christos | WORD WSPACE '-' options WSPACE location {
    250  1.1  christos 
    251  1.1  christos   struct sun_list *list;
    252  1.1  christos   struct sun_mountpt *mountpt;
    253  1.1  christos 
    254  1.1  christos   /* allocate a mountpt */
    255  1.1  christos   mountpt = CALLOC(struct sun_mountpt);
    256  1.1  christos 
    257  1.1  christos   /* An fstype may have been defined in the 'options'. */
    258  1.1  christos   if (tmpFsType != NULL) {
    259  1.1  christos     mountpt->fstype = tmpFsType;
    260  1.1  christos     tmpFsType = NULL;
    261  1.1  christos   }
    262  1.1  christos 
    263  1.1  christos   /*
    264  1.1  christos    * Assign the global location list to this entry and reset the
    265  1.1  christos    * global pointer.  Reseting the global pointer will create a new
    266  1.1  christos    * list instance next time get_sun_location_list() is called.
    267  1.1  christos    */
    268  1.1  christos   list = get_sun_location_list();
    269  1.1  christos   mountpt->location_list = (struct sun_location *)list->first;
    270  1.1  christos   sun_location_list = NULL;
    271  1.1  christos 
    272  1.1  christos   /*
    273  1.1  christos    * Assign the global opt list to this entry and reset the global
    274  1.1  christos    * pointer.  Reseting the global pointer will create a new list
    275  1.1  christos    * instance next time get_sun_opt_list() is called.
    276  1.1  christos    */
    277  1.1  christos   list = get_sun_opt_list();
    278  1.1  christos   mountpt->opt_list = (struct sun_opt *)list->first;
    279  1.1  christos   sun_opt_list = NULL;
    280  1.1  christos 
    281  1.4  christos   mountpt->path = xstrdup($1);
    282  1.1  christos 
    283  1.1  christos   /* Add this mountpt to the mountpt list. */
    284  1.1  christos   sun_list_add(get_mountpt_list(), (qelem *)mountpt);
    285  1.1  christos }
    286  1.1  christos ;
    287  1.1  christos 
    288  1.1  christos locations : location
    289  1.1  christos           | location WSPACE locations
    290  1.1  christos           ;
    291  1.1  christos 
    292  1.1  christos location : hosts ':' WORD {
    293  1.1  christos 
    294  1.1  christos   struct sun_list *list;
    295  1.1  christos   struct sun_location *location;
    296  1.1  christos 
    297  1.1  christos   /* allocate a new location */
    298  1.1  christos   location = CALLOC(struct sun_location);
    299  1.1  christos 
    300  1.1  christos   /*
    301  1.1  christos    * Assign the global opt list to this entry and reset the global
    302  1.1  christos    * pointer.  Reseting the global pointer will create a new list
    303  1.1  christos    * instance next time get_sun_opt_list() is called.
    304  1.1  christos    */
    305  1.1  christos   list = get_sun_host_list();
    306  1.1  christos   location->host_list = (struct sun_host *)list->first;
    307  1.1  christos   sun_host_list = NULL;
    308  1.1  christos 
    309  1.4  christos   location->path = xstrdup($3);
    310  1.1  christos 
    311  1.1  christos   /* Add this location to the location list. */
    312  1.1  christos   sun_list_add(get_sun_location_list(), (qelem *)location);
    313  1.1  christos }
    314  1.1  christos 
    315  1.1  christos | ':' WORD {
    316  1.1  christos 
    317  1.1  christos   struct sun_location *location;
    318  1.1  christos 
    319  1.1  christos   /* allocate a new location */
    320  1.1  christos   location = CALLOC(struct sun_location);
    321  1.1  christos 
    322  1.4  christos   location->path = xstrdup($2);
    323  1.1  christos 
    324  1.1  christos   /* Add this location to the location list. */
    325  1.1  christos   sun_list_add(get_sun_location_list(), (qelem *)location);
    326  1.1  christos }
    327  1.1  christos ;
    328  1.1  christos 
    329  1.1  christos hosts : host
    330  1.1  christos       | host ',' hosts
    331  1.1  christos       ;
    332  1.1  christos 
    333  1.1  christos host : WORD {
    334  1.1  christos 
    335  1.1  christos   /* allocate a new host */
    336  1.1  christos   struct sun_host *host = CALLOC(struct sun_host);
    337  1.1  christos 
    338  1.4  christos   host->name = xstrdup($1);
    339  1.1  christos 
    340  1.1  christos   /* Add this host to the host list. */
    341  1.1  christos   sun_list_add(get_sun_host_list(),(qelem *)host);
    342  1.1  christos }
    343  1.1  christos 
    344  1.1  christos | WORD weight {
    345  1.1  christos 
    346  1.1  christos   /*
    347  1.1  christos    * It is assumed that the host for this rule was allocated by the
    348  1.1  christos    * 'weight' rule and assigned to be the last host item on the host
    349  1.1  christos    * list.
    350  1.1  christos    */
    351  1.1  christos   struct sun_host *host = (struct sun_host *)sun_host_list->last;
    352  1.1  christos 
    353  1.4  christos   host->name = xstrdup($1);
    354  1.1  christos }
    355  1.1  christos ;
    356  1.1  christos 
    357  1.1  christos weight : '(' WORD ')' {
    358  1.1  christos 
    359  1.1  christos   int val;
    360  1.1  christos   /* allocate a new host */
    361  1.1  christos   struct sun_host *host = CALLOC(struct sun_host);
    362  1.1  christos 
    363  1.1  christos   val = atoi($2);
    364  1.1  christos 
    365  1.1  christos   host->weight = val;
    366  1.1  christos 
    367  1.1  christos   /* Add this host to the host list. */
    368  1.1  christos   sun_list_add(get_sun_host_list(), (qelem *)host);
    369  1.1  christos }
    370  1.1  christos ;
    371  1.1  christos 
    372  1.1  christos options : option
    373  1.1  christos         | option ',' options
    374  1.1  christos         ;
    375  1.1  christos 
    376  1.1  christos option : WORD {
    377  1.1  christos 
    378  1.1  christos   char *type;
    379  1.1  christos 
    380  1.1  christos   /* check if this is an fstype option */
    381  1.1  christos   if ((type = strstr($1,SUN_FSTYPE_STR)) != NULL) {
    382  1.1  christos     /* parse out the fs type from the Sun fstype keyword  */
    383  1.1  christos     if ((type = type + strlen(SUN_FSTYPE_STR)) != NULL) {
    384  1.1  christos       /*
    385  1.1  christos        * This global fstype str will be assigned to the current being
    386  1.1  christos        * parsed later in the parsing.
    387  1.1  christos        */
    388  1.4  christos       tmpFsType = xstrdup(type);
    389  1.1  christos     }
    390  1.1  christos   }
    391  1.1  christos   else {
    392  1.1  christos     /*
    393  1.1  christos      * If it is not an fstype option allocate an opt struct and assign
    394  1.1  christos      * the value.
    395  1.1  christos      */
    396  1.1  christos     struct sun_opt *opt = CALLOC(struct sun_opt);
    397  1.4  christos     opt->str = xstrdup($1);
    398  1.1  christos     /* Add this opt to the opt list. */
    399  1.1  christos     sun_list_add(get_sun_opt_list(), (qelem *)opt);
    400  1.1  christos   }
    401  1.1  christos }
    402  1.1  christos 
    403  1.1  christos ;
    404  1.1  christos 
    405  1.1  christos %%
    406  1.1  christos 
    407  1.1  christos /*
    408  1.1  christos  * Parse 'map_data' which is assumed to be a Sun-syle map.  If
    409  1.1  christos  * successful a sun_entry is returned.
    410  1.1  christos  *
    411  1.1  christos  * The parser is designed to parse map entries with out the keys.  For
    412  1.1  christos  * example the entry:
    413  1.1  christos  *
    414  1.1  christos  * usr -ro pluto:/usr/local
    415  1.1  christos  *
    416  1.1  christos  * should be passed to the parser as:
    417  1.1  christos  *
    418  1.1  christos  * -ro pluto:/usr/local
    419  1.1  christos  *
    420  1.1  christos  * The reason for this is that the Amd info services already strip off
    421  1.1  christos  * the key when they read map info.
    422  1.1  christos  */
    423  1.1  christos struct sun_entry *
    424  1.1  christos sun_map_parse_read(const char *map_data)
    425  1.1  christos {
    426  1.1  christos   struct sun_entry *retval = NULL;
    427  1.1  christos 
    428  1.1  christos   /* pass map_data to lex */
    429  1.1  christos   sun_map_tok_setbuff(map_data);
    430  1.1  christos 
    431  1.1  christos   /* call yacc */
    432  1.1  christos   sun_map_parse();
    433  1.1  christos 
    434  1.1  christos   if (sun_entry_list != NULL) {
    435  1.1  christos     /* return the first Sun entry in the list */
    436  1.1  christos     retval = (struct sun_entry*)sun_entry_list->first;
    437  1.1  christos     sun_entry_list = NULL;
    438  1.1  christos   }
    439  1.1  christos   else {
    440  1.1  christos     plog(XLOG_ERROR, "Sun map parser did not produce data structs.");
    441  1.1  christos   }
    442  1.1  christos 
    443  1.1  christos   return retval;
    444  1.1  christos }
    445  1.1  christos 
    446  1.1  christos 
    447  1.1  christos static struct sun_list *
    448  1.1  christos get_sun_entry_list(void)
    449  1.1  christos {
    450  1.1  christos   if (sun_entry_list == NULL) {
    451  1.1  christos     sun_entry_list = CALLOC(struct sun_list);
    452  1.1  christos   }
    453  1.1  christos   return sun_entry_list;
    454  1.1  christos }
    455  1.1  christos 
    456  1.1  christos 
    457  1.1  christos static struct sun_list *
    458  1.1  christos get_mountpt_list(void)
    459  1.1  christos {
    460  1.1  christos   if (mountpt_list == NULL) {
    461  1.1  christos     mountpt_list = CALLOC(struct sun_list);
    462  1.1  christos   }
    463  1.1  christos   return mountpt_list;
    464  1.1  christos }
    465  1.1  christos 
    466  1.1  christos 
    467  1.1  christos static struct sun_list *
    468  1.1  christos get_sun_location_list(void)
    469  1.1  christos {
    470  1.1  christos   if (sun_location_list == NULL) {
    471  1.1  christos     sun_location_list = CALLOC(struct sun_list);
    472  1.1  christos   }
    473  1.1  christos   return sun_location_list;
    474  1.1  christos }
    475  1.1  christos 
    476  1.1  christos 
    477  1.1  christos static struct sun_list *
    478  1.1  christos get_sun_host_list(void)
    479  1.1  christos {
    480  1.1  christos   if (sun_host_list == NULL) {
    481  1.1  christos     sun_host_list = CALLOC(struct sun_list);
    482  1.1  christos   }
    483  1.1  christos   return sun_host_list;
    484  1.1  christos }
    485  1.1  christos 
    486  1.1  christos 
    487  1.1  christos static struct sun_list *
    488  1.1  christos get_sun_opt_list(void)
    489  1.1  christos {
    490  1.1  christos   if (sun_opt_list == NULL) {
    491  1.1  christos     sun_opt_list = CALLOC(struct sun_list);
    492  1.1  christos   }
    493  1.1  christos   return sun_opt_list;
    494  1.1  christos }
    495