* amd/info_file.c (file_search_or_reload): Changed the key
authorDaniel Ottavio <ottavio@fsl.cs.sunysb.edu>
Sat, 27 Aug 2005 19:14:18 +0000 (19:14 +0000)
committerDaniel Ottavio <ottavio@fsl.cs.sunysb.edu>
Sat, 27 Aug 2005 19:14:18 +0000 (19:14 +0000)
variable that is passed to the sun_entry2amd.

* amd/mapc.c (mapc_add_kv): Add support for multiple entries
packed into one line.  This is a workaround for handling Sun style
mounts that contains multiple entries on one line "multi-mount
entries".  The sun2amd conversion tools will convert such entries
into type:=auto and pack each of the auto-entries into one line
separated by 'n'.  The mapc_add_kv function will now recognize
such entries and add then.

* amd/sun2amd.c (sun2amd_convert): Add print statement that
includes the line number during a parser failure.

* sun_map.c: Fix the AMD_MAP_PREF_KW definition.  Fix spelling.
(sun_mountpts2amd): removed this function
(sun_hsfs2amd): added some more comments
(sun_nfs2amd): moved support for multi-mount entries from this
function to sun_multi2amd().
(sun_multi2amd): New function to handle multi-mount entries.  This
function will convert the Sun version to an Amd type:=auto.  Each
extra auto entry will be appended to the same line separated by a
'n'.
(sun_entry2amd): Fixed a bug if-statement.  This function now
checks for multi-mount entries.

* amd/sun_map.h: Add a fstype member to the sun_mountpt struct.

* amd/sun_map_parse.y: Parser now supports fstype for multi-mount
entries.

* amd/sun_map_tok.l: No longer print the line and column number
when parsing.  This is because the parser is handed strings not
files.  Therefore, the line number will always be 1.  It is now up
to the higher level tools to echo line information during error
when they feed the parser.

ChangeLog
amd/info_file.c
amd/mapc.c
amd/sun2amd.c
amd/sun_map.c
amd/sun_map.h
amd/sun_map_parse.y
amd/sun_map_tok.l

index 0eeccce5a17772043e1565db8dffb4b9e6d2737d..bbd839a39a42ea18e897d544308fbb7ba97cfad9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,42 @@
+2005-08-27  Daniel P. Ottavio  <dottavio@ic.sunysb.edu>
+
+       * amd/info_file.c (file_search_or_reload): Changed the key
+       variable that is passed to the sun_entry2amd.
+
+       * amd/mapc.c (mapc_add_kv): Add support for multiple entries
+       packed into one line.  This is a workaround for handling Sun style
+       mounts that contains multiple entries on one line "multi-mount
+       entries".  The sun2amd conversion tools will convert such entries
+       into type:=auto and pack each of the auto-entries into one line
+       separated by '\n'.  The mapc_add_kv function will now recognize
+       such entries and add then.
+
+       * amd/sun2amd.c (sun2amd_convert): Add print statement that
+       includes the line number during a parser failure.
+
+       * sun_map.c: Fix the AMD_MAP_PREF_KW definition.  Fix spelling.
+       (sun_mountpts2amd): removed this function
+       (sun_hsfs2amd): added some more comments
+       (sun_nfs2amd): moved support for multi-mount entries from this
+       function to sun_multi2amd().
+       (sun_multi2amd): New function to handle multi-mount entries.  This
+       function will convert the Sun version to an Amd type:=auto.  Each
+       extra auto entry will be appended to the same line separated by a
+       '\n'.
+       (sun_entry2amd): Fixed a bug if-statement.  This function now
+       checks for multi-mount entries.
+
+       * amd/sun_map.h: Add a fstype member to the sun_mountpt struct.
+
+       * amd/sun_map_parse.y: Parser now supports fstype for multi-mount
+       entries.
+
+       * amd/sun_map_tok.l: No longer print the line and column number
+       when parsing.  This is because the parser is handed strings not
+       files.  Therefore, the line number will always be 1.  It is now up
+       to the higher level tools to echo line information during error
+       when they feed the parser.
+       
 2005-08-24  Erez Zadok  <ezk@cs.sunysb.edu>
 
        * configure.in: wrap all LDAP and HESIOD tests in test whether
index 654edf76a8026b60115857784bacfa24589361ba..c672509349862f938f1f478455709029f2a0388a 100644 (file)
@@ -161,7 +161,7 @@ file_search_or_reload(mnt_map *m,
         */
        char *dc;
        if (m->cfm->cfm_flags & CFM_SUN_MAP_SYNTAX)
-         dc = sun_entry2amd(key, cp);
+         dc = sun_entry2amd(kp, cp);
        else
          dc = strdup(cp);
        if (fn) {
index a159cb702d057b280af08226ebfaa38a3ef127f1..adee1897ae89ae2bdff3dbd4caef7da3d1a25cfc 100644 (file)
@@ -427,7 +427,45 @@ mapc_add_kv(mnt_map *m, char *key, char *val)
 #endif /* HAVE_REGEXEC */
 
   dlog("add_kv: %s -> %s", key, val);
-
+  
+  if (val != NULL && strchr(val, '\n') != NULL) {
+    /*
+     * If the entry value contains multiple lines we need to break
+     * them up and add them recursively.  This is a workaround to
+     * support Sun style multi-mounts.  Amd converts Sun style
+     * mulit-mounts to type:=auto.  The problem is that Sun packs all
+     * the entries on one line.  When Amd does the conversion it puts
+     * each type:=auto entry on the same line separated by '\n'.
+     */
+    char *entry, *tok;
+    
+    /*
+     * The first line should contain the first entry.  The key for
+     * this entry is the key passed into this function.
+     */
+    if ((tok = strtok(val, "\n")) != NULL) {
+      mapc_add_kv(m, key, strdup(tok));
+    }
+    
+    /*
+     * For the rest of the entries we need to tokenize them by '\n'
+     * and separate the keys from there entries.
+     */
+    while ((tok = strtok(NULL, "\n")) != NULL) {
+      key = tok;
+      /* find the entry */
+      for (entry = key; *entry && !isspace((int)*entry); entry++);
+      if (*entry) {
+       *entry++ = '\0';
+      }
+      
+      mapc_add_kv(m, strdup(key), strdup(entry));
+    }
+    
+    XFREE(val);
+    return;
+  }
+  
 #ifdef HAVE_REGEXEC
   if (MAPC_ISRE(m)) {
     char pattern[MAXPATHLEN];
@@ -1174,6 +1212,6 @@ get_full_path(const char *map, const char *path, const char *type)
       return full_path;
     str = strtok(NULL, ":");
   } while (str);
-
+  
   return map;                  /* if found nothing, return map */
 }
index 8444fb35394d0d3b9e8af0577025f786164f2064..8cc9dd83a98d8a7155b40bd792c71567545f491d 100644 (file)
@@ -110,6 +110,7 @@ sun2amd_convert(FILE *sun_in, FILE *amd_out)
 
     /* convert the sun entry to an amd entry */
     if ((tmp = sun_entry2amd(key, entry)) == NULL) {
+      plog(XLOG_ERROR, "parse error on line %d", line);
       goto err;
     }
     
index d65a6c73a9496567fbe5e79f1ac5b92704cf0fbe..80496c28567ba9beb2cae5e34a0f65a0a89f3711 100644 (file)
@@ -79,16 +79,16 @@ sun_list_add(struct sun_list *list, qelem *item)
 /*
  * AMD entry keywords
  */
-#define AMD_OPTS_KW      "addopts:="   /* add entry options */
-#define AMD_RHOST_KW     "rhost:="     /* remote host */
-#define AMD_RFS_KW       "rfs:="       /* remote file system */
-#define AMD_FS_KW        "fs:="        /* local file system */
-#define AMD_DEV_KW       "dev:="       /* device */
-#define AMD_TYPE_NFS_KW  "type:=nfs;"  /* fs type nfs */
-#define AMD_TYPE_AUTO_KW "type:=auto;" /* fs type auto */
-#define AMD_TYPE_CDFS_KW "type:=cdfs;" /* fs type cd */
-#define AMD_MAP_FS_KW    "fs:=${map};" /* set the mount map as current map */
-#define AMD_MAP_PREF_KW  "pref:=${key};" /* set the mount map as current map */
+#define AMD_OPTS_KW      "addopts:="     /* add entry options */
+#define AMD_RHOST_KW     "rhost:="       /* remote host */
+#define AMD_RFS_KW       "rfs:="         /* remote file system */
+#define AMD_FS_KW        "fs:="          /* local file system */
+#define AMD_DEV_KW       "dev:="         /* device */
+#define AMD_TYPE_NFS_KW  "type:=nfs;"    /* fs type nfs */
+#define AMD_TYPE_AUTO_KW "type:=auto;"   /* fs type auto */
+#define AMD_TYPE_CDFS_KW "type:=cdfs;"   /* fs type cd */
+#define AMD_MAP_FS_KW    "fs:=${map};"   /* set the mount map as current map */
+#define AMD_MAP_PREF_KW  "pref:=${key}/" /* set the mount map as current map */
 
 /*
  * A set of string Sun fstypes.
@@ -98,18 +98,18 @@ sun_list_add(struct sun_list *list, qelem *item)
 #define SUN_AUTOFS_TYPE  "autofs"
 #define SUN_CACHEFS_TYPE "cachefs"
 
-#define SUN_KEY_SUB      "&"         /* Sun key subsitution */
+#define SUN_KEY_SUB      "&"         /* Sun key substitution */
 
 /* a set a Sun variable substitutions for map entries */
 #define SUN_ARCH         "$ARCH"     /* host architecture */
 #define SUN_CPU          "$CPU"      /* processor type */
 #define SUN_HOST         "$HOST"     /* host name */
 #define SUN_OSNAME       "$OSNAME"   /* OS name */
-#define SUN_OSREL        "$OSREL"    /* OS realease */
+#define SUN_OSREL        "$OSREL"    /* OS release */
 #define SUN_OSVERS       "$OSVERS"   /* OS version */
 #define SUN_NATISA       "$NATISA"   /* native instruction set */
 
-/* a set of Amd varaible substitutions */
+/* a set of Amd variable substitutions */
 #define AMD_ARCH         "${arch}"   /* host architecture */
 #define AMD_HOST         "${host}"   /* host name */
 #define AMD_OSNAME       "${os}"     /* OS name */
@@ -120,7 +120,7 @@ sun_list_add(struct sun_list *list, qelem *item)
  * Return a copy of src that has all occurrences of 'str' replaced
  * with sub.
  *
- * param src - the orginal string
+ * param src - the original string
  * param str - string that is the replaced with str
  * param sub - string that replaces an occurrences of 'delim'
  *
@@ -189,7 +189,7 @@ sun_strsub(const char *src, const char *str, const char *sub)
  *
  * param str - source string
  *
- * return - A new string with the expantions, NULL if str does not
+ * return - A new string with the expansions, NULL if str does not
  * exist in src or error.
  */
 static char *
@@ -201,8 +201,8 @@ sun_expand2amd(const char *str)
 
   /*
    * Iterator through the string looking for '$' chars.  For each '$'
-   * found try to replace it with Sun variable substitions.  If we
-   * find a '$' that is not a subsitution each of the i.e $blah than
+   * found try to replace it with Sun variable substitutions.  If we
+   * find a '$' that is not a substation each of the i.e $blah than
    * each of the replace attempt will fail and we'll move on to the
    * next char.
    */
@@ -217,8 +217,8 @@ sun_expand2amd(const char *str)
     }
 
     /*
-     * If a 'replace' does not retuen NULL than a variable was
-     * successfully subsituted.
+     * If a 'replace' does not return NULL than a variable was
+     * successfully substituted.
      */
 
     /* architecture */
@@ -273,7 +273,7 @@ sun_expand2amd(const char *str)
  * equivalents.
  *
  * param dest   - destination buffer
- * param deslen - estination buffer length
+ * param deslen - destination buffer length
  * param key    - entry key, this might be needed for key substitutions
  * param str    - string to append
  */
@@ -289,7 +289,7 @@ sun_append_str(char *dest,
   out = (char*)str;
 
   /*
-   * Resolve variable substititions in two steps; 1) replace any key
+   * Resolve variable substitutions in two steps; 1) replace any key
    * map substitutions with the entry key 2) expand any variable
    * substitutions i.e $HOST.
    *
@@ -399,9 +399,8 @@ sun_locations2amd(char *dest,
        xstrlcat(dest, AMD_RFS_KW, destlen);
        /* add local path */
        sun_append_str(dest, destlen, key, local->path);
-       xstrlcat(dest, ";", destlen);
        if (NEXT(struct sun_host, host) != NULL) {
-         /* add a space to seperate each host listing */
+         xstrlcat(dest, ";", destlen);
          xstrlcat(dest, " ", destlen);
        }
       }
@@ -412,52 +411,22 @@ sun_locations2amd(char *dest,
       sun_append_str(dest, destlen, key, local->path);
     }
     if (NEXT(struct sun_location, local) != NULL) {
-      /* add a space to seperate each location */
+      /* add a space to separate each location */
       xstrlcat(dest, " ", destlen);
     }
-
   }
 }
 
 
 /*
- * Convert a list of Sun multi-mount point locations to Amd entries.
- *
- * param dest         - destination buffer
- * param deslen       - estination buffer length
- * param key          - the entry key
- * param mountpt_list - list of Sun mountpoints
+ * Convert a Sun HSFS mount point to an Amd.  The result is
+ * concatenated intp dest.
  *
- * return - 0 on success, < 0 on error
+ * param dest    - destination buffer
+ * param destlen - destination buffer length
+ * param key     - automount key
+ * param s_entry - Sun entry
  */
-static void
-sun_mountpts2amd(char *dest,
-                 size_t destlen,
-                 const char *key,
-                 const struct sun_mountpt *mountpt_list)
-{
-  const struct sun_mountpt *mountpt;
-
-  for (mountpt = mountpt_list;
-       mountpt != NULL;
-       mountpt = NEXT(struct sun_mountpt, mountpt)) {
-    /* write the key */
-    xstrlcat(dest, key, destlen);
-    /* write the mount path */
-    sun_append_str(dest, destlen, key, mountpt->path);
-    /* space */
-    xstrlcat(dest, " ", destlen);
-    /* Write all the host locations for this mount point. */
-    sun_locations2amd(dest, destlen, key, mountpt->location_list);
-
-    if (NEXT(struct sun_mountpt, mountpt) != NULL) {
-      /* If there are more mountpts add a space. */
-      xstrlcat(dest, " ", destlen);
-    }
-  }
-}
-
-
 static void
 sun_hsfs2amd(char *dest,
             size_t destlen,
@@ -488,27 +457,48 @@ sun_nfs2amd(char *dest,
            const char *key,
            const struct sun_entry *s_entry)
 {
-  /*
-   * If the Sun entry has muliple mount points we use type:=auto along
-   * with auto entries.  For a single mount point just use type:=nfs.
-   */
-  if (s_entry->mountpt_list == NULL) {
-    /* single NFS mount point */
-    if (s_entry->location_list != NULL) {
-      /* write out the list of mountpoint locations */
-      sun_locations2amd(dest, destlen, key, s_entry->location_list);
-    }
+  if (s_entry->location_list != NULL) {
+    /* write out the list of mountpoint locations */
+    sun_locations2amd(dest, destlen, key, s_entry->location_list);
   }
-  else {
-    /* multiple NFS mount points 
-     *
-     * We need to setup a auto fs Amd automount point. 
-     */
-    xstrlcat(dest, AMD_TYPE_AUTO_KW, destlen);
-    xstrlcat(dest, AMD_MAP_FS_KW, destlen);
-    xstrlcat(dest, AMD_MAP_PREF_KW, destlen);
-    /* write the mountpts */
-    sun_mountpts2amd(dest, destlen, key, s_entry->mountpt_list);
+}
+
+
+/*
+ * Convert a Sun multi-mount point entry to an Amd.  This is done
+ * using the Amd type auto.  Each auto entry is separated with a \n.
+ *
+ * param dest    - destination buffer
+ * param destlen - destination buffer length
+ * param key     - automount key
+ * param s_entry - Sun entry
+ */
+static void
+sun_multi2amd(char *dest,
+             size_t destlen,
+             const char *key,
+             const struct sun_entry *s_entry)
+{
+  const struct sun_mountpt *mountpt;
+
+  /* We need to setup a auto fs Amd automount point. */
+  xstrlcat(dest, AMD_TYPE_AUTO_KW, destlen);
+  xstrlcat(dest, AMD_MAP_FS_KW, destlen);
+  xstrlcat(dest, AMD_MAP_PREF_KW, destlen);
+
+  /* write the mountpts to dest */
+  for (mountpt = s_entry->mountpt_list;
+       mountpt != NULL;
+       mountpt = NEXT(struct sun_mountpt, mountpt)) {
+    xstrlcat(dest, "\n", destlen);
+    /* write the key */
+    xstrlcat(dest, key, destlen);
+    /* write the mount path */
+    sun_append_str(dest, destlen, key, mountpt->path);
+    /* space */
+    xstrlcat(dest, " ", destlen);
+    /* Write all the host locations for this mount point. */
+    sun_locations2amd(dest, destlen, key, mountpt->location_list);
   }
 }
 
@@ -519,7 +509,7 @@ sun_nfs2amd(char *dest,
  * param key     - automount key
  * param s_entry - Sun style automap entry
  *
- * return - Adm entry string on success, null on error.
+ * return - Amd entry on succes, NULL on error 
  */
 char *
 sun_entry2amd(const char *key, const char *s_entry_str)
@@ -527,14 +517,14 @@ sun_entry2amd(const char *key, const char *s_entry_str)
   char *retval = NULL;
   char line_buff[INFO_MAX_LINE_LEN];
   struct sun_entry *s_entry = NULL;
-
+  
   /* For now the key should no be NULL. */
   if (key == NULL) {
     plog(XLOG_ERROR,"Sun key value was null");
     goto err;
   }
   /* The Sun entry string should never be NULL. */
-  if (s_entry == NULL) {
+  if (s_entry_str == NULL) {
     plog(XLOG_ERROR,"Sun entry value was null");
     goto err;
   }
@@ -553,46 +543,54 @@ sun_entry2amd(const char *key, const char *s_entry_str)
     sun_opts2amd(line_buff, sizeof(line_buff), key, s_entry->opt_list);
   }
 
-  /* Check the fstype. */
-  if (s_entry->fstype != NULL) {
-    if (NSTREQ(s_entry->fstype, SUN_NFS_TYPE, strlen(SUN_NFS_TYPE))) {
-      /* NFS Type */
-      sun_nfs2amd(line_buff, sizeof(line_buff), key, s_entry);
-      retval = strdup(line_buff);
-    }
-    else if (NSTREQ(s_entry->fstype, SUN_HSFS_TYPE, strlen(SUN_HSFS_TYPE))) {
-      /* HSFS Type (CD fs) */
-      sun_hsfs2amd(line_buff, sizeof(line_buff), key, s_entry);
-      retval = strdup(line_buff);
-    }
-    /*
-     * XXX: The following fstypes are not yet supported.
-     */
-    else if (NSTREQ(s_entry->fstype, SUN_AUTOFS_TYPE, strlen(SUN_AUTOFS_TYPE))) {
-      /* AutoFS Type */
-      plog(XLOG_ERROR, "Sun fstype %s is currently not supported by Amd.",
-           s_entry->fstype);
-      goto err;
-      
-    }
-    else if (NSTREQ(s_entry->fstype, SUN_CACHEFS_TYPE, strlen(SUN_CACHEFS_TYPE))) {
-      /* CacheFS Type */
-      plog(XLOG_ERROR, "Sun fstype %s is currently not supported by Amd.",
-           s_entry->fstype);
-      goto err;
+  /* Check if this is a multi-mount entry. */
+  if (s_entry->mountpt_list != NULL) {
+    /* multi-mount point */
+    sun_multi2amd(line_buff, sizeof(line_buff), key, s_entry);
+    retval = strdup(line_buff);
+  }
+  else {
+    /* single mount point */
+    if (s_entry->fstype != NULL) {
+      if (NSTREQ(s_entry->fstype, SUN_NFS_TYPE, strlen(SUN_NFS_TYPE))) {
+       /* NFS Type */
+       sun_nfs2amd(line_buff, sizeof(line_buff), key, s_entry);
+       retval = strdup(line_buff);
+      }
+      else if (NSTREQ(s_entry->fstype, SUN_HSFS_TYPE, strlen(SUN_HSFS_TYPE))) {
+       /* HSFS Type (CD fs) */
+       sun_hsfs2amd(line_buff, sizeof(line_buff), key, s_entry);
+       retval = strdup(line_buff);
+      }
+      /*
+       * XXX: The following fstypes are not yet supported.
+       */
+      else if (NSTREQ(s_entry->fstype, SUN_AUTOFS_TYPE, strlen(SUN_AUTOFS_TYPE))) {
+       /* AutoFS Type */
+       plog(XLOG_ERROR, "Sun fstype %s is currently not supported by Amd.",
+            s_entry->fstype);
+       goto err;
+       
+      }
+      else if (NSTREQ(s_entry->fstype, SUN_CACHEFS_TYPE, strlen(SUN_CACHEFS_TYPE))) {
+       /* CacheFS Type */
+       plog(XLOG_ERROR, "Sun fstype %s is currently not supported by Amd.",
+            s_entry->fstype);
+       goto err;
+      }
+      else {
+       plog(XLOG_ERROR, "Sun fstype %s is currently not supported by Amd.",
+            s_entry->fstype);
+       goto err;
+      }
     }
     else {
-      plog(XLOG_ERROR, "Sun fstype %s is currently not supported by Amd.",
-          s_entry->fstype);
-      goto err;
+      plog(XLOG_INFO, "No SUN fstype specified defaulting to NFS.");
+      sun_nfs2amd(line_buff, sizeof(line_buff), key, s_entry);
+      retval = strdup(line_buff);
     }
   }
-  else {
-    plog(XLOG_INFO, "No SUN fstype specified defaulting to NFS.");
-    sun_nfs2amd(line_buff, sizeof(line_buff), key, s_entry);
-    retval = strdup(line_buff);
-  }
-
+  
  err:
   if (s_entry != NULL) {
     XFREE(s_entry);
index 8c8b527d3ee58227cca8bf4219e5d34750a6d8fd..514cd101b36ee45d677308479d95058ad4f7348b 100644 (file)
@@ -69,6 +69,7 @@ struct sun_opt {
 struct sun_mountpt {
   qelem head;                         /* link-list header */
   char *path;                         /* optional mount point path */
+  char *fstype;                       /* filesystem type */
   struct sun_opt      *opt_list;      /* list of option strings */
   struct sun_location *location_list; /* list of 'struct s2a_location' */
 };
index 86fa7cd4c1b5cb7fcc030962ed96099ad3c7e398..2914ef09d9b5d2d77d45e85053ea9797bb1c3b95 100644 (file)
@@ -98,7 +98,7 @@ file : new_lines entries
      | entries
      ;
 
-entries : entry
+entries : entry 
         | entry new_lines
         | entry new_lines entries
         ;
@@ -215,7 +215,7 @@ entry : locations {
   list = get_sun_opt_list();
   entry->opt_list = (struct sun_opt *)list->first;
   sun_opt_list = NULL;
-
+  
   /* Add this entry to the entry list. */
   sun_list_add(get_sun_entry_list(), (qelem *)entry);
 }
@@ -256,8 +256,14 @@ mountpoint : WORD WSPACE location {
   /* allocate a mountpt */
   mountpt = CALLOC(struct sun_mountpt);
 
+  /* An fstype may have been defined in the 'options'. */
+  if (tmpFsType != NULL) {
+    mountpt->fstype = tmpFsType;
+    tmpFsType = NULL;
+  }
+
   /*
-   * Assign the global loaction list to this entry and reset the
+   * Assign the global location list to this entry and reset the
    * global pointer.  Reseting the global pointer will create a new
    * list instance next time get_sun_location_list() is called.
    */
@@ -369,7 +375,6 @@ options : option
         | option ',' options
         ;
 
-
 option : WORD {
 
   char *type;
index 105a71dd122eacb828d065f54e90a7672f8f91cf..5b5586639bd8fca061a2bb795c96df333924fa96 100644 (file)
@@ -188,8 +188,6 @@ CONTINUE_REX   "\\"\n
 int
 yyerror(const char* s)
 {
-  plog(XLOG_ERROR,"sun2amd : parsing error : line %d, column %d\n",
-       sun_map_line,sun_map_tokpos);
   return 1;
 }