From ec8736e986d3beafa679d82b6002972d68be1d85 Mon Sep 17 00:00:00 2001 From: Daniel Ottavio Date: Wed, 17 Aug 2005 04:12:06 +0000 Subject: [PATCH] * 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. --- ChangeLog | 20 ++++++++++++ amd/sun2amd.c | 17 +++------- amd/sun_map.c | 79 +++++++++++++++++++++++++++++---------------- amd/sun_map_parse.y | 3 +- 4 files changed, 78 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index 16df332..16659c7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2005-08-16 Daniel P. Ottavio + + * 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 * amd/get_args.c (get_args): initialize debug_flags if they've diff --git a/amd/sun2amd.c b/amd/sun2amd.c index 6cf3b1c..8444fb3 100644 --- a/amd/sun2amd.c +++ b/amd/sun2amd.c @@ -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)); } diff --git a/amd/sun_map.c b/amd/sun_map.c index cdc8211..ce2ff0f 100644 --- a/amd/sun_map.c +++ b/amd/sun_map.c @@ -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); } diff --git a/amd/sun_map_parse.y b/amd/sun_map_parse.y index 25904c0..dfad387 100644 --- a/amd/sun_map_parse.y +++ b/amd/sun_map_parse.y @@ -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; } -- 2.43.0