* amd/sun2amd.c (sun2amd_convert): If the input line is too long
authorDaniel Ottavio <ottavio@fsl.cs.sunysb.edu>
Wed, 17 Aug 2005 04:12:06 +0000 (04:12 +0000)
committerDaniel Ottavio <ottavio@fsl.cs.sunysb.edu>
Wed, 17 Aug 2005 04:12:06 +0000 (04:12 +0000)
don't return an error just null terminate and continue.  Fix bug:
the map key was not written.

* amd/sun_map.c: Add a new Amd device, and cdfs constant.
(sun_locations2amd): Write the NFS type keyword
for each host of the mount entry.  Add a space between each mount
location.
(sun_hsfs2amd): New function to support hsfs to
cdfs.
(sun_nfs2amd): Don't write the nfs type here.  Fix
comments.
(sun_entry2amd): Change function parameter var for
clarity.  Add support for hsfs.

* amd/sun_map_parse.y (sun_map_parse_read): Reset the entry list
after it has been returned.

ChangeLog
amd/sun2amd.c
amd/sun_map.c
amd/sun_map_parse.y

index 16df332c1b13976ddc2448c54d26bc43735da582..16659c7c226c6b46d6a52295738962a8bfa3741f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2005-08-16  Daniel P. Ottavio  <dottavio@ic.sunysb.edu>
+
+       * amd/sun2amd.c (sun2amd_convert): If the input line is too long
+       don't return an error just null terminate and continue.  Fix bug:
+       the map key was not written.
+
+       * amd/sun_map.c: Add a new Amd device, and cdfs constant.
+       (sun_locations2amd): Write the NFS type keyword
+       for each host of the mount entry.  Add a space between each mount
+       location.
+       (sun_hsfs2amd): New function to support hsfs to
+       cdfs.
+       (sun_nfs2amd): Don't write the nfs type here.  Fix
+       comments.
+       (sun_entry2amd): Change function parameter var for
+       clarity.  Add support for hsfs.
+
+       * amd/sun_map_parse.y (sun_map_parse_read): Reset the entry list
+       after it has been returned.
+
 2005-08-16  Erez Zadok  <ezk@cs.sunysb.edu>
 
        * amd/get_args.c (get_args): initialize debug_flags if they've
index 6cf3b1cf990670f96d26380d7ecc262f1242143f..8444fb35394d0d3b9e8af0577025f786164f2064 100644 (file)
@@ -74,15 +74,8 @@ sun2amd_convert(FILE *sun_in, FILE *amd_out)
   /* Read the input line by line and do the conversion. */
   while ((pos = file_read_line(line_buff, sizeof(line_buff), sun_in))) {
     line++;
-
-    /* Make sure we have the whole line. */
-    if (line_buff[pos - 1] != '\n') {
-      plog(XLOG_ERROR, "map line %d is too long", line);
-      goto err;
-    }
-
     line_buff[pos - 1] = '\0';
-
+    
     /* remove comments */
     if ((tmp = strchr(line_buff, '#')) != NULL) {
       *tmp = '\0';
@@ -119,12 +112,12 @@ sun2amd_convert(FILE *sun_in, FILE *amd_out)
     if ((tmp = sun_entry2amd(key, entry)) == NULL) {
       goto err;
     }
-
-    if (fputs(tmp, amd_out) == EOF) {
-      plog(XLOG_ERROR, "can't write amd entry on line %d: fputs: %s", line, strerror(errno));
+    
+    if (fprintf(amd_out, "%s %s\n", key, tmp) < 0) {
+      plog(XLOG_ERROR, "can't write to output stream: %s", strerror(errno)); 
       goto err;
     }
-
+    
     /* just to be safe */
     memset(line_buff, 0, sizeof(line_buff));
   }
index cdc8211accc3649571eaa231c9206d64b57edf36..ce2ff0fdfca0a994cf2d06205606745d2e736ce9 100644 (file)
@@ -91,8 +91,10 @@ sun_list_add(struct sun_list *list, qelem *item)
 #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 */
 
@@ -387,6 +389,8 @@ sun_locations2amd(char *dest,
       for (host = local->host_list;
           host != NULL;
           host = NEXT(struct sun_host, host)) {
+       /* set fstype NFS */
+       xstrlcat(dest, AMD_TYPE_NFS_KW, destlen);
        /* add rhost key word */
        xstrlcat(dest, AMD_RHOST_KW, destlen);
        /* add host name */
@@ -408,6 +412,11 @@ sun_locations2amd(char *dest,
       xstrlcat(dest, AMD_FS_KW, destlen);
       sun_append_str(dest, destlen, key, local->path);
     }
+    if (NEXT(struct sun_location, local) != NULL) {
+      /* add a space to seperate each location */
+      xstrlcat(dest, " ", destlen);
+    }
+
   }
 }
 
@@ -450,6 +459,21 @@ sun_mountpts2amd(char *dest,
 }
 
 
+static void
+sun_hsfs2amd(char *dest,
+            size_t destlen,
+            const char *key,
+            const struct sun_entry *s_entry)
+{
+  /* set fstype CDFS */
+  xstrlcat(dest, AMD_TYPE_CDFS_KW, destlen);
+  /* set the cdrom device */
+  xstrlcat(dest, AMD_DEV_KW, destlen);
+  /* XXX: For now just assume that there is only one device. */
+  xstrlcat(dest, s_entry->location_list->path, destlen);
+}
+
+
 /*
  * Convert a Sun NFS automount entry to an Amd.  The result is concatenated
  * into dest.
@@ -471,16 +495,16 @@ sun_nfs2amd(char *dest,
    */
   if (s_entry->mountpt_list == NULL) {
     /* single NFS mount point */
-    xstrlcat(dest, AMD_TYPE_NFS_KW, destlen);
     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. */
+    /* 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);
@@ -499,64 +523,63 @@ sun_nfs2amd(char *dest,
  * return - Adm entry string on success, null on error.
  */
 char *
-sun_entry2amd(const char *key, const char *s_entry)
+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_obj;
+  struct sun_entry *s_entry;
 
   /* Parse the sun entry line. */
-  s_entry_obj = sun_map_parse_read(s_entry);
-  if (s_entry_obj == NULL) {
+  s_entry = sun_map_parse_read(s_entry_str);
+  if (s_entry == NULL) {
     plog(XLOG_ERROR,"could not parse Sun style map");
     goto err;
   }
 
   memset(line_buff, 0, sizeof(line_buff));
-
-  if (s_entry_obj->opt_list != NULL) {
+  
+  if (s_entry->opt_list != NULL) {
     /* write the mount options to the buffer  */
-    sun_opts2amd(line_buff, sizeof(line_buff), key, s_entry_obj->opt_list);
+    sun_opts2amd(line_buff, sizeof(line_buff), key, s_entry->opt_list);
   }
 
   /* Check the fstype. */
-  if (s_entry_obj->fstype != NULL) {
-    if (NSTREQ(s_entry_obj->fstype, SUN_NFS_TYPE, strlen(SUN_NFS_TYPE))) {
+  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_obj);
+      sun_nfs2amd(line_buff, sizeof(line_buff), key, s_entry);
       retval = strdup(line_buff);
     }
-    /*
-     * XXX: The following fstypes not not yet supported.
-     */
-    else if (NSTREQ(s_entry_obj->fstype, SUN_HSFS_TYPE, strlen(SUN_HSFS_TYPE))) {
+    else if (NSTREQ(s_entry->fstype, SUN_HSFS_TYPE, strlen(SUN_HSFS_TYPE))) {
       /* HSFS Type (CD fs) */
-      plog(XLOG_ERROR, "Sun fstype %s is currently not supported by Amd.",
-           s_entry_obj->fstype);
-      goto err;
+      sun_hsfs2amd(line_buff, sizeof(line_buff), key, s_entry);
+      retval = strdup(line_buff);
     }
-    else if (NSTREQ(s_entry_obj->fstype, SUN_AUTOFS_TYPE, strlen(SUN_AUTOFS_TYPE))) {
+    /*
+     * 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_obj->fstype);
+           s_entry->fstype);
       goto err;
-
+      
     }
-    else if (NSTREQ(s_entry_obj->fstype, SUN_CACHEFS_TYPE, strlen(SUN_CACHEFS_TYPE))) {
+    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_obj->fstype);
+           s_entry->fstype);
       goto err;
     }
     else {
       plog(XLOG_ERROR, "Sun fstype %s is currently not supported by Amd.",
-          s_entry_obj->fstype);
+          s_entry->fstype);
       goto err;
     }
   }
   else {
     plog(XLOG_INFO, "No SUN fstype specified defaulting to NFS.");
-    sun_nfs2amd(line_buff, sizeof(line_buff), key, s_entry_obj);
+    sun_nfs2amd(line_buff, sizeof(line_buff), key, s_entry);
     retval = strdup(line_buff);
   }
 
index 25904c02568fb74333da4fcb4cc64b8e1150f049..dfad387d27d58b35d521ec5b982c6507f3590330 100644 (file)
@@ -441,11 +441,12 @@ sun_map_parse_read(const char *map_data)
   if (sun_entry_list != NULL) {
     /* return the first Sun entry in the list */
     retval = (struct sun_entry*)sun_entry_list->first;
+    sun_entry_list = NULL;
   }
   else {
     plog(XLOG_ERROR, "Sun map parser did not produce data structs.");
   }
-
+  
   return retval;
 }