The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/vinum/vinumparser.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 1997, 1998
    3  *      Nan Yang Computer Services Limited.  All rights reserved.
    4  *
    5  *  This software is distributed under the so-called ``Berkeley
    6  *  License'':
    7  *
    8  * Redistribution and use in source and binary forms, with or without
    9  * modification, are permitted provided that the following conditions
   10  * are met:
   11  * 1. Redistributions of source code must retain the above copyright
   12  *    notice, this list of conditions and the following disclaimer.
   13  * 2. Redistributions in binary form must reproduce the above copyright
   14  *    notice, this list of conditions and the following disclaimer in the
   15  *    documentation and/or other materials provided with the distribution.
   16  * 3. All advertising materials mentioning features or use of this software
   17  *    must display the following acknowledgement:
   18  *      This product includes software developed by Nan Yang Computer
   19  *      Services Limited.
   20  * 4. Neither the name of the Company nor the names of its contributors
   21  *    may be used to endorse or promote products derived from this software
   22  *    without specific prior written permission.
   23  *
   24  * This software is provided ``as is'', and any express or implied
   25  * warranties, including, but not limited to, the implied warranties of
   26  * merchantability and fitness for a particular purpose are disclaimed.
   27  * In no event shall the company or contributors be liable for any
   28  * direct, indirect, incidental, special, exemplary, or consequential
   29  * damages (including, but not limited to, procurement of substitute
   30  * goods or services; loss of use, data, or profits; or business
   31  * interruption) however caused and on any theory of liability, whether
   32  * in contract, strict liability, or tort (including negligence or
   33  * otherwise) arising in any way out of the use of this software, even if
   34  * advised of the possibility of such damage.
   35  *
   36  * $Id: vinumparser.c,v 1.20 2000/04/22 05:32:50 grog Exp grog $
   37  * $FreeBSD$
   38  */
   39 
   40 /*
   41  * This file contains the parser for the configuration routines.  It's used
   42  * both in the kernel and in the user interface program, thus the separate file.
   43  */
   44 
   45 /*
   46  * Go through a text and split up into text tokens.  These are either non-blank
   47  * sequences, or any sequence (except \0) enclosed in ' or ".  Embedded ' or
   48  * " characters may be escaped by \, which otherwise has no special meaning.
   49  *
   50  * Delimit by following with a \0, and return pointers to the starts at token [].
   51  * Return the number of tokens found as the return value.
   52  *
   53  * This method has the restriction that a closing " or ' must be followed by
   54  * grey space.
   55  *
   56  * Error conditions are end of line before end of quote, or no space after
   57  * a closing quote.  In this case, tokenize() returns -1.
   58  */
   59 
   60 #include <sys/param.h>
   61 #ifdef KERNEL
   62 #include <sys/systm.h>
   63 #else
   64 #include <ctype.h>
   65 #include <errno.h>
   66 #include <fcntl.h>
   67 #endif
   68 #include <machine/setjmp.h>
   69 /* All this mess for a single struct definition */
   70 #include <sys/uio.h>
   71 #include <sys/namei.h>
   72 #include <sys/disklabel.h>
   73 #include <sys/mount.h>
   74 #include <sys/conf.h>
   75 
   76 #include <dev/vinum/vinumvar.h>
   77 #include <dev/vinum/vinumkw.h>
   78 #include <dev/vinum/vinumio.h>
   79 #include <dev/vinum/vinumext.h>
   80 
   81 #ifdef KERNEL
   82 #define iswhite(c) ((c == ' ') || (c == '\t'))              /* check for white space */
   83 #else /* get it from the headers */
   84 #include <ctype.h>
   85 #define iswhite isspace                                     /* use the ctype macro */
   86 #endif
   87 
   88 /* enum keyword is defined in vinumvar.h */
   89 
   90 #define keypair(x) { #x, kw_##x }                           /* create pair "foo", kw_foo */
   91 #define flagkeypair(x) { "-"#x, kw_##x }                    /* create pair "-foo", kw_foo */
   92 #define KEYWORDSET(x) {sizeof (x) / sizeof (struct _keywords), x}
   93 
   94 /* Normal keywords.  These are all the words that vinum knows. */
   95 struct _keywords keywords[] =
   96 {keypair(drive),
   97     keypair(partition),
   98     keypair(sd),
   99     keypair(subdisk),
  100     keypair(plex),
  101     keypair(volume),
  102     keypair(vol),
  103     keypair(setupstate),
  104     keypair(readpol),
  105     keypair(org),
  106     keypair(name),
  107     keypair(writethrough),
  108     keypair(writeback),
  109     keypair(raw),
  110     keypair(device),
  111     keypair(concat),
  112     keypair(raid4),
  113     keypair(raid5),
  114     keypair(striped),
  115     keypair(plexoffset),
  116     keypair(driveoffset),
  117     keypair(length),
  118     keypair(len),
  119     keypair(size),
  120     keypair(state),
  121     keypair(round),
  122     keypair(prefer),
  123     keypair(rename),
  124     keypair(detached),
  125 #ifndef KERNEL                                              /* for vinum(8) only */
  126 #ifdef VINUMDEBUG
  127     keypair(debug),
  128 #endif
  129     keypair(stripe),
  130     keypair(mirror),
  131 #endif
  132     keypair(attach),
  133     keypair(detach),
  134     keypair(printconfig),
  135     keypair(saveconfig),
  136     keypair(replace),
  137     keypair(create),
  138     keypair(read),
  139     keypair(modify),
  140     keypair(list),
  141     keypair(l),
  142     keypair(ld),
  143     keypair(ls),
  144     keypair(lp),
  145     keypair(lv),
  146     keypair(info),
  147     keypair(set),
  148     keypair(rm),
  149     keypair(mv),
  150     keypair(move),
  151     keypair(init),
  152     keypair(label),
  153     keypair(resetconfig),
  154     keypair(start),
  155     keypair(stop),
  156     keypair(makedev),
  157     keypair(help),
  158     keypair(quit),
  159     keypair(setdaemon),
  160     keypair(getdaemon),
  161     keypair(max),
  162     keypair(replace),
  163     keypair(readpol),
  164     keypair(resetstats),
  165     keypair(setstate),
  166     keypair(checkparity),
  167     keypair(rebuildparity),
  168     keypair(dumpconfig)
  169 };
  170 struct keywordset keyword_set = KEYWORDSET(keywords);
  171 
  172 #ifndef KERNEL
  173 struct _keywords flag_keywords[] =
  174 {flagkeypair(f),
  175     flagkeypair(d),
  176     flagkeypair(v),
  177     flagkeypair(s),
  178     flagkeypair(r),
  179     flagkeypair(w)
  180 };
  181 struct keywordset flag_set = KEYWORDSET(flag_keywords);
  182 
  183 #endif
  184 
  185 /*
  186  * Take a blank separated list of tokens and turn it into a list of
  187  * individual nul-delimited strings.  Build a list of pointers at
  188  * token, which must have enough space for the tokens.  Return the
  189  * number of tokens, or -1 on error (typically a missing string
  190  * delimiter).
  191  */
  192 int
  193 tokenize(char *cptr, char *token[])
  194 {
  195     char delim;                                             /* delimiter for searching for the partner */
  196     int tokennr;                                            /* index of this token */
  197     tokennr = 0;                                            /* none found yet */
  198 
  199     for (;;) {
  200         while (iswhite(*cptr))
  201             cptr++;                                         /* skip initial white space */
  202         if ((*cptr == '\0') || (*cptr == '\n') || (*cptr == '#')) /* end of line */
  203             return tokennr;                                 /* return number of tokens found */
  204         delim = *cptr;
  205         token[tokennr] = cptr;                              /* point to it */
  206         tokennr++;                                          /* one more */
  207         /* XXX this is broken.  It leaves superfluous \\ characters in the text */
  208         if ((delim == '\'') || (delim == '"')) {            /* delimitered */
  209             for (;;) {
  210                 cptr++;
  211                 if ((*cptr == delim) && (cptr[-1] != '\\')) { /* found the partner */
  212                     cptr++;                                 /* move on past */
  213                     if (!iswhite(*cptr))                    /* error, no space after closing quote */
  214                         return -1;
  215                     *cptr++ = '\0';                         /* delimit */
  216                 } else if ((*cptr == '\0') || (*cptr == '\n')) /* end of line */
  217                     return -1;
  218             }
  219         } else {                                            /* not quoted */
  220             while ((*cptr != '\0') && (!iswhite(*cptr)) && (*cptr != '\n'))
  221                 cptr++;
  222             if (*cptr != '\0')                              /* not end of the line, */
  223                 *cptr++ = '\0';                             /* delimit and move to the next */
  224         }
  225     }
  226 }
  227 
  228 /* Find a keyword and return an index */
  229 enum keyword
  230 get_keyword(char *name, struct keywordset *keywordset)
  231 {
  232     int i;
  233     struct _keywords *keywords = keywordset->k;             /* point to the keywords */
  234     if (name != NULL) {                                     /* parameter exists */
  235         for (i = 0; i < keywordset->size; i++)
  236             if (!strcmp(name, keywords[i].name))
  237                 return (enum keyword) keywords[i].keyword;
  238     }
  239     return kw_invalid_keyword;
  240 }

Cache object: 65691495d87646ddf87732f7d3ecf8f9


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.