diff options
author | Jacob Smith <jake.smith@hdfgroup.org> | 2019-09-23 22:23:02 (GMT) |
---|---|---|
committer | Jacob Smith <jake.smith@hdfgroup.org> | 2019-09-23 22:23:02 (GMT) |
commit | 35a9e9c50fbbab20ed920daa3daf903d82cd79d7 (patch) | |
tree | 90299be3be2ffe9eb0e53b530eca309d789ac6c0 /tools/src | |
parent | 1070468dac5d0fd5e02b69514d7a0dfacfd28606 (diff) | |
parent | 7997eb8c84dd07dacbcc427049f838d883e263b8 (diff) | |
download | hdf5-35a9e9c50fbbab20ed920daa3daf903d82cd79d7.zip hdf5-35a9e9c50fbbab20ed920daa3daf903d82cd79d7.tar.gz hdf5-35a9e9c50fbbab20ed920daa3daf903d82cd79d7.tar.bz2 |
Merge branch 'develop' of https://bitbucket.hdfgroup.org/scm/~jake.smith/hdf5 into bugfix/repack_external_storage
Diffstat (limited to 'tools/src')
-rw-r--r-- | tools/src/h5copy/h5copy.c | 8 | ||||
-rw-r--r-- | tools/src/h5diff/h5diff_common.c | 28 | ||||
-rw-r--r-- | tools/src/h5diff/ph5diff_main.c | 26 | ||||
-rw-r--r-- | tools/src/h5dump/h5dump.c | 329 | ||||
-rw-r--r-- | tools/src/h5dump/h5dump_ddl.c | 15 | ||||
-rw-r--r-- | tools/src/h5dump/h5dump_xml.c | 11 | ||||
-rw-r--r-- | tools/src/h5import/h5import.c | 2 | ||||
-rw-r--r-- | tools/src/h5ls/h5ls.c | 1212 | ||||
-rw-r--r-- | tools/src/h5repack/h5repack.c | 6 | ||||
-rw-r--r-- | tools/src/h5repack/h5repack_copy.c | 15 | ||||
-rw-r--r-- | tools/src/h5repack/h5repack_main.c | 3 | ||||
-rw-r--r-- | tools/src/h5repack/h5repack_refs.c | 28 | ||||
-rw-r--r-- | tools/src/h5stat/h5stat.c | 409 | ||||
-rw-r--r-- | tools/src/misc/CMakeLists.txt | 7 | ||||
-rw-r--r-- | tools/src/misc/h5debug.c | 496 | ||||
-rw-r--r-- | tools/src/misc/h5mkgrp.c | 6 | ||||
-rw-r--r-- | tools/src/misc/h5repart.c | 601 |
17 files changed, 1794 insertions, 1408 deletions
diff --git a/tools/src/h5copy/h5copy.c b/tools/src/h5copy/h5copy.c index 1800810..9490cd9 100644 --- a/tools/src/h5copy/h5copy.c +++ b/tools/src/h5copy/h5copy.c @@ -381,10 +381,10 @@ main (int argc, const char *argv[]) *-------------------------------------------------------------------------*/ if (verbose) { - printf("Copying file <%s> and object <%s> to file <%s> and object <%s>\n", + HDprintf("Copying file <%s> and object <%s> to file <%s> and object <%s>\n", fname_src, oname_src, fname_dst, oname_dst); if (flag) { - printf("Using %s flag\n", str_flag); + HDprintf("Using %s flag\n", str_flag); } } @@ -419,7 +419,7 @@ main (int argc, const char *argv[]) /* Display some output if requested */ if(verbose) - printf("%s: Creating parent groups\n", h5tools_getprogname()); + HDprintf("%s: Creating parent groups\n", h5tools_getprogname()); } /* end if */ else { /* error, if parent groups doesn't already exist in destination file */ @@ -490,7 +490,7 @@ main (int argc, const char *argv[]) leave(EXIT_SUCCESS); done: - printf("Error in copy...Exiting\n"); + HDprintf("Error in copy...Exiting\n"); /* free link info path */ if (linkinfo.trg_path) diff --git a/tools/src/h5diff/h5diff_common.c b/tools/src/h5diff/h5diff_common.c index 0c1521e..362e3f2 100644 --- a/tools/src/h5diff/h5diff_common.c +++ b/tools/src/h5diff/h5diff_common.c @@ -62,9 +62,9 @@ static void check_options(diff_opt_t* opts) * These options are mutually exclusive. */ if ((opts->d + opts->p + opts->use_system_epsilon) > 1) { - printf("%s error: -d, -p and --use-system-epsilon options are mutually-exclusive;\n", PROGRAMNAME); - printf("use no more than one.\n"); - printf("Try '-h' or '--help' option for more information or see the %s entry in the 'HDF5 Reference Manual'.\n", PROGRAMNAME); + HDprintf("%s error: -d, -p and --use-system-epsilon options are mutually-exclusive;\n", PROGRAMNAME); + HDprintf("use no more than one.\n"); + HDprintf("Try '-h' or '--help' option for more information or see the %s entry in the 'HDF5 Reference Manual'.\n", PROGRAMNAME); h5diff_exit(EXIT_FAILURE); } } @@ -186,7 +186,7 @@ void parse_command_line(int argc, /* create linked list of excluding objects */ if( (exclude_node = (struct exclude_path_list*) HDmalloc(sizeof(struct exclude_path_list))) == NULL) { - printf("Error: lack of memory!\n"); + HDprintf("Error: lack of memory!\n"); h5diff_exit(EXIT_FAILURE); } @@ -212,7 +212,7 @@ void parse_command_line(int argc, opts->d=1; if (check_d_input(opt_arg) == - 1) { - printf("<-d %s> is not a valid option\n", opt_arg); + HDprintf("<-d %s> is not a valid option\n", opt_arg); usage(); h5diff_exit(EXIT_FAILURE); } @@ -226,7 +226,7 @@ void parse_command_line(int argc, case 'p': opts->p=1; if (check_p_input(opt_arg) == -1) { - printf("<-p %s> is not a valid option\n", opt_arg); + HDprintf("<-p %s> is not a valid option\n", opt_arg); usage(); h5diff_exit(EXIT_FAILURE); } @@ -240,7 +240,7 @@ void parse_command_line(int argc, case 'n': opts->n=1; if ( check_n_input(opt_arg) == -1) { - printf("<-n %s> is not a valid option\n", opt_arg); + HDprintf("<-n %s> is not a valid option\n", opt_arg); usage(); h5diff_exit(EXIT_FAILURE); } @@ -309,20 +309,20 @@ void parse_command_line(int argc, return; if (opts->cmn_objs == 0) { - printf("No common objects found. Files are not comparable.\n"); + HDprintf("No common objects found. Files are not comparable.\n"); if (!opts->m_verbose) - printf("Use -v for a list of objects.\n"); + HDprintf("Use -v for a list of objects.\n"); } if (opts->not_cmp == 1) { if (opts->m_list_not_cmp == 0) { - printf("--------------------------------\n"); - printf("Some objects are not comparable\n"); - printf("--------------------------------\n"); + HDprintf("--------------------------------\n"); + HDprintf("Some objects are not comparable\n"); + HDprintf("--------------------------------\n"); if (opts->m_verbose) - printf("Use -c for a list of objects without details of differences.\n"); + HDprintf("Use -c for a list of objects without details of differences.\n"); else - printf("Use -c for a list of objects.\n"); + HDprintf("Use -c for a list of objects.\n"); } } } diff --git a/tools/src/h5diff/ph5diff_main.c b/tools/src/h5diff/ph5diff_main.c index 83240cb..380ab3b 100644 --- a/tools/src/h5diff/ph5diff_main.c +++ b/tools/src/h5diff/ph5diff_main.c @@ -68,7 +68,7 @@ int main(int argc, const char *argv[]) if(g_nTasks == 1) { - printf("Only 1 task available...doing serial diff\n"); + HDprintf("Only 1 task available...doing serial diff\n"); g_Parallel = 0; @@ -148,12 +148,12 @@ ph5diff_worker(int nID) /* Open the files */ if ((file1_id = H5Fopen (filenames[0], H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) { - printf ("h5diff Task [%d]: <%s>: unable to open file\n", nID, filenames[0]); + HDprintf("h5diff Task [%d]: <%s>: unable to open file\n", nID, filenames[0]); MPI_Abort(MPI_COMM_WORLD, 0); } if ((file2_id = H5Fopen (filenames[1], H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) { - printf ("h5diff Task [%d]: <%s>: unable to open file\n", nID, filenames[1]); + HDprintf("h5diff Task [%d]: <%s>: unable to open file\n", nID, filenames[1]); MPI_Abort(MPI_COMM_WORLD, 0); } /* enable error reporting */ @@ -170,7 +170,7 @@ ph5diff_worker(int nID) /* Make certain we've received the filenames and opened the files already */ if(file1_id < 0 || file2_id < 0) { - printf("ph5diff_worker: ERROR: work received before/without filenames\n"); + HDprintf("ph5diff_worker: ERROR: work received before/without filenames\n"); break; } @@ -199,7 +199,7 @@ ph5diff_worker(int nID) char out_data[PRINT_DATA_MAX_SIZE]; int tmp; - memset(out_data, 0, PRINT_DATA_MAX_SIZE); + HDmemset(out_data, 0, PRINT_DATA_MAX_SIZE); i=0; rewind(overflow_file); @@ -210,7 +210,7 @@ ph5diff_worker(int nID) { MPI_Send(out_data, PRINT_DATA_MAX_SIZE, MPI_BYTE, 0, MPI_TAG_PRINT_DATA, MPI_COMM_WORLD); i=0; - memset(out_data, 0, PRINT_DATA_MAX_SIZE); + HDmemset(out_data, 0, PRINT_DATA_MAX_SIZE); } } @@ -221,8 +221,8 @@ ph5diff_worker(int nID) overflow_file = NULL; } - fflush(stdout); - memset(outBuff, 0, OUTBUFF_SIZE); + HDfflush(stdout); + HDmemset(outBuff, 0, OUTBUFF_SIZE); outBuffOffset = 0; MPI_Send(&diffs, sizeof(diffs), MPI_BYTE, 0, MPI_TAG_TOK_RETURN, MPI_COMM_WORLD); @@ -238,7 +238,7 @@ ph5diff_worker(int nID) } else { - printf("ph5diff_worker: ERROR: invalid tag (%d) received\n", Status.MPI_TAG); + HDprintf("ph5diff_worker: ERROR: invalid tag (%d) received\n", Status.MPI_TAG); break; } @@ -266,14 +266,14 @@ void print_manager_output(void) /* If there was something we buffered, let's print it now */ if( (outBuffOffset>0) && g_Parallel) { - printf("%s", outBuff); + HDprintf("%s", outBuff); if(overflow_file) { int tmp; rewind(overflow_file); - while((tmp = getc(overflow_file)) >= 0) - putchar(tmp); + while((tmp = HDgetc(overflow_file)) >= 0) + HDputchar(tmp); fclose(overflow_file); overflow_file = NULL; } @@ -321,6 +321,6 @@ void h5diff_exit(int status) /* Always exit(0), since MPI implementations do weird stuff when they * receive a non-zero exit value. - QAK */ - exit(0); + HDexit(0); } diff --git a/tools/src/h5dump/h5dump.c b/tools/src/h5dump/h5dump.c index b9e37e8..b1e736a 100644 --- a/tools/src/h5dump/h5dump.c +++ b/tools/src/h5dump/h5dump.c @@ -24,6 +24,27 @@ static int doxml = 0; static int useschema = 1; static const char *xml_dtd_uri = NULL; +#ifdef H5_HAVE_ROS3_VFD +static H5FD_ros3_fapl_t ros3_fa = { + 1, /* version */ + false, /* authenticate */ + "", /* aws region */ + "", /* access key id */ + "", /* secret access key */ +}; +#endif /* H5_HAVE_ROS3_VFD */ + +#ifdef H5_HAVE_LIBHDFS +static H5FD_hdfs_fapl_t hdfs_fa = { + 1, /* fapl version */ + "localhost", /* namenode name */ + 0, /* namenode port */ + "", /* kerberos ticket cache */ + "", /* user name */ + 2048, /* stream buffer size */ +}; +#endif /* H5_HAVE_LIBHDFS */ + /* module-scoped variables for XML option */ #define DEFAULT_XSD "http://www.hdfgroup.org/HDF5/XML/schema/HDF5-File.xsd" #define DEFAULT_DTD "http://www.hdfgroup.org/HDF5/XML/DTD/HDF5-File.dtd" @@ -188,6 +209,8 @@ static struct long_options l_opts[] = { { "any_path", require_arg, 'N' }, { "vds-view-first-missing", no_arg, 'v' }, { "vds-gap-size", require_arg, 'G' }, + { "s3-cred", require_arg, '$' }, + { "hdfs-attrs", require_arg, '#' }, { NULL, 0, '\0' } }; @@ -241,6 +264,16 @@ usage(const char *prog) PRINTVALSTREAM(rawoutstream, " -b B, --binary=B Binary file output, of form B\n"); PRINTVALSTREAM(rawoutstream, " -O F, --ddl=F Output ddl text into file F\n"); PRINTVALSTREAM(rawoutstream, " Use blank(empty) filename F to suppress ddl display\n"); + PRINTVALSTREAM(rawoutstream, " --s3-cred=<cred> Supply S3 authentication information to \"ros3\" vfd.\n"); + PRINTVALSTREAM(rawoutstream, " <cred> :: \"(<aws-region>,<access-id>,<access-key>)\"\n"); + PRINTVALSTREAM(rawoutstream, " If absent or <cred> -> \"(,,)\", no authentication.\n"); + PRINTVALSTREAM(rawoutstream, " Has no effect is filedriver is not `ros3'.\n"); + PRINTVALSTREAM(rawoutstream, " --hdfs-attrs=<attrs> Supply configuration information for HDFS file access.\n"); + PRINTVALSTREAM(rawoutstream, " For use with \"--filedriver=hdfs\"\n"); + PRINTVALSTREAM(rawoutstream, " <attrs> :: (<namenode name>,<namenode port>,\n"); + PRINTVALSTREAM(rawoutstream, " <kerberos cache path>,<username>,\n"); + PRINTVALSTREAM(rawoutstream, " <buffer size>)\n"); + PRINTVALSTREAM(rawoutstream, " Any absent attribute will use a default value.\n"); PRINTVALSTREAM(rawoutstream, "--------------- Object Options ---------------\n"); PRINTVALSTREAM(rawoutstream, " -a P, --attribute=P Print the specified attribute\n"); PRINTVALSTREAM(rawoutstream, " If an attribute name contains a slash (/), escape the\n"); @@ -1282,6 +1315,126 @@ end_collect: hand = NULL; h5tools_setstatus(EXIT_SUCCESS); goto done; + + case '$': +#ifndef H5_HAVE_ROS3_VFD + error_msg("Read-Only S3 VFD not enabled.\n"); + h5tools_setstatus(EXIT_FAILURE); + goto done; +#else + /* s3 credential */ + { + char **s3_cred = NULL; + char *s3_cred_string = NULL; + const char *ccred[3]; + unsigned nelems = 0; + if ( FAIL == + parse_tuple(opt_arg, ',', + &s3_cred_string, &nelems, &s3_cred)) + { + error_msg("unable to parse malformed s3 credentials\n"); + usage(h5tools_getprogname()); + free_handler(hand, argc); + hand= NULL; + h5tools_setstatus(EXIT_FAILURE); + goto done; + } + if (nelems != 3) { + error_msg("s3 credentials expects 3 elements\n"); + usage(h5tools_getprogname()); + free_handler(hand, argc); + hand= NULL; + h5tools_setstatus(EXIT_FAILURE); + goto done; + } + ccred[0] = (const char *)s3_cred[0]; + ccred[1] = (const char *)s3_cred[1]; + ccred[2] = (const char *)s3_cred[2]; + if (0 == h5tools_populate_ros3_fapl(&ros3_fa, ccred)) { + error_msg("Invalid S3 credentials\n"); + usage(h5tools_getprogname()); + free_handler(hand, argc); + hand= NULL; + h5tools_setstatus(EXIT_FAILURE); + goto done; + } + HDfree(s3_cred); + HDfree(s3_cred_string); + } /* s3 credential block */ + break; +#endif /* H5_HAVE_ROS3_VFD */ + + case '#': +#ifndef H5_HAVE_LIBHDFS + error_msg("HDFS VFD is not enabled.\n"); + goto error; +#else + { + /* read hdfs properties tuple and store values in `hdfs_fa` + */ + unsigned nelems = 0; + char *props_src = NULL; + char **props = NULL; + unsigned long k = 0; + if (FAIL == parse_tuple( + (const char *)opt_arg, + ',', + &props_src, + &nelems, + &props)) + { + error_msg("unable to parse hdfs properties tuple\n"); + goto error; + } + /* sanity-check tuple count + */ + if (nelems != 5) { + h5tools_setstatus(EXIT_FAILURE); + goto error; + } + /* Populate fapl configuration structure with given + * properties. + * WARNING: No error-checking is done on length of input + * strings... Silent overflow is possible, albeit + * unlikely. + */ + if (strncmp(props[0], "", 1)) { + HDstrncpy(hdfs_fa.namenode_name, + (const char *)props[0], + HDstrlen(props[0])); + } + if (strncmp(props[1], "", 1)) { + k = strtoul((const char *)props[1], NULL, 0); + if (errno == ERANGE) { + h5tools_setstatus(EXIT_FAILURE); + goto error; + } + hdfs_fa.namenode_port = (int32_t)k; + } + if (strncmp(props[2], "", 1)) { + HDstrncpy(hdfs_fa.kerberos_ticket_cache, + (const char *)props[2], + HDstrlen(props[2])); + } + if (strncmp(props[3], "", 1)) { + HDstrncpy(hdfs_fa.user_name, + (const char *)props[3], + HDstrlen(props[3])); + } + if (strncmp(props[4], "", 1)) { + k = strtoul((const char *)props[4], NULL, 0); + if (errno == ERANGE) { + h5tools_setstatus(EXIT_FAILURE); + goto error; + } + hdfs_fa.stream_buffer_size = (int32_t)k; + } + HDfree(props); + HDfree(props_src); + } +#endif /* H5_HAVE_LIBHDFS */ + break; + case '?': default: usage(h5tools_getprogname()); @@ -1354,6 +1507,7 @@ main(int argc, const char *argv[]) { hid_t fid = -1; hid_t gid = -1; + hid_t fapl_id = H5P_DEFAULT; H5E_auto2_t func; H5E_auto2_t tools_func; H5O_info_t oi; @@ -1440,10 +1594,56 @@ main(int argc, const char *argv[]) /* Initialize indexing options */ h5trav_set_index(sort_by, sort_order); + if (driver != NULL) { + void *conf_fa = NULL; + + if (!strcmp(driver, "ros3")) { +#ifndef H5_HAVE_ROS3_VFD + error_msg("Read-Only S3 VFD not enabled.\n"); + h5tools_setstatus(EXIT_FAILURE); + goto done; +#else + conf_fa = (void *)&ros3_fa; +#endif /* H5_HAVE_ROS3_VFD */ + } else if (!HDstrcmp(driver, "hdfs")) { +#ifndef H5_HAVE_LIBHDFS + error_msg("HDFS VFD is not enabled.\n"); + h5tools_setstatus(EXIT_FAILURE); + goto done; +#else + conf_fa = (void *)&hdfs_fa; +#endif /* H5_HAVE_LIBHDFS */ + } + + if (conf_fa != NULL) { + fapl_id = H5Pcreate(H5P_FILE_ACCESS); + if (fapl_id < 0) { + error_msg("unable to create fapl entry\n"); + h5tools_setstatus(EXIT_FAILURE); + goto done; + } + if (0 == h5tools_set_configured_fapl( + fapl_id, + driver, /* guaranteed "ros3" or "hdfs" */ + conf_fa)) /* appropriate to driver */ + { + error_msg("unable to set fapl\n"); + h5tools_setstatus(EXIT_FAILURE); + goto done; + } + } + } /* driver defined */ + while(opt_ind < argc) { fname = HDstrdup(argv[opt_ind++]); - fid = h5tools_fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT, driver, NULL, 0); + if (fapl_id != H5P_DEFAULT) { + fid = H5Fopen(fname, H5F_ACC_RDONLY, fapl_id); + } + else { + fid = h5tools_fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT, + driver, NULL, 0); + } if (fid < 0) { error_msg("unable to open file \"%s\"\n", fname); @@ -1624,6 +1824,11 @@ done: /* Free tables for objects */ table_list_free(); + if (fapl_id != H5P_DEFAULT && 0 < H5Pclose(fapl_id)) { + error_msg("Can't close fapl entry\n"); + h5tools_setstatus(EXIT_FAILURE); + } + if(fid >=0) if (H5Fclose(fid) < 0) h5tools_setstatus(EXIT_FAILURE); @@ -1645,127 +1850,7 @@ done: H5Eset_auto2(H5E_DEFAULT, func, edata); leave(h5tools_getstatus()); -} - -/*------------------------------------------------------------------------- - * Function: h5_fileaccess - * - * Purpose: Returns a file access template which is the default template - * but with a file driver set according to the constant or - * environment variable HDF5_DRIVER - * - * Return: Success: A file access property list - * - * Failure: -1 - * - * Programmer: Robb Matzke - * Thursday, November 19, 1998 - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -hid_t -h5_fileaccess(void) -{ - static const char *multi_letters = "msbrglo"; - const char *val = NULL; - const char *name; - char s[1024]; - hid_t fapl = -1; - - /* First use the environment variable, then the constant */ - val = HDgetenv("HDF5_DRIVER"); -#ifdef HDF5_DRIVER - if (!val) val = HDF5_DRIVER; -#endif - - if ((fapl=H5Pcreate(H5P_FILE_ACCESS))<0) return -1; - if (!val || !*val) return fapl; /*use default*/ - - HDstrncpy(s, val, sizeof s); - s[sizeof(s)-1] = '\0'; - if (NULL==(name=HDstrtok(s, " \t\n\r"))) return fapl; - - if (!HDstrcmp(name, "sec2")) { - /* Unix read() and write() system calls */ - if (H5Pset_fapl_sec2(fapl)<0) return -1; - } - else if (!HDstrcmp(name, "stdio")) { - /* Standard C fread() and fwrite() system calls */ - if (H5Pset_fapl_stdio(fapl)<0) return -1; - } - else if (!HDstrcmp(name, "core")) { - /* In-core temporary file with 1MB increment */ - if (H5Pset_fapl_core(fapl, 1024*1024, FALSE)<0) return -1; - } - else if (!HDstrcmp(name, "split")) { - /* Split meta data and raw data each using default driver */ - if (H5Pset_fapl_split(fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT) < 0) - return -1; - } - else if (!HDstrcmp(name, "multi")) { - /* Multi-file driver, general case of the split driver */ - H5FD_mem_t memb_map[H5FD_MEM_NTYPES]; - hid_t memb_fapl[H5FD_MEM_NTYPES]; - const char *memb_name[H5FD_MEM_NTYPES]; - char sv[H5FD_MEM_NTYPES][1024]; - haddr_t memb_addr[H5FD_MEM_NTYPES]; - H5FD_mem_t mt; - - HDmemset(memb_map, 0, sizeof memb_map); - HDmemset(memb_fapl, 0, sizeof memb_fapl); - HDmemset(memb_name, 0, sizeof memb_name); - HDmemset(memb_addr, 0, sizeof memb_addr); - - if(HDstrlen(multi_letters)==H5FD_MEM_NTYPES) { - for (mt=H5FD_MEM_DEFAULT; mt<H5FD_MEM_NTYPES; H5_INC_ENUM(H5FD_mem_t,mt)) { - memb_fapl[mt] = H5P_DEFAULT; - memb_map[mt] = mt; - sprintf(sv[mt], "%%s-%c.h5", multi_letters[mt]); - memb_name[mt] = sv[mt]; - memb_addr[mt] = (haddr_t)MAX(mt - 1, 0) * (HADDR_MAX / 10); - } - } - else { - error_msg("Bad multi_letters list\n"); - return FAIL; - } - - if (H5Pset_fapl_multi(fapl, memb_map, memb_fapl, memb_name, memb_addr, FALSE) < 0) - return -1; - } - else if (!HDstrcmp(name, "family")) { - hsize_t fam_size = 100*1024*1024; /*100 MB*/ - - /* Family of files, each 1MB and using the default driver */ - if ((val=HDstrtok(NULL, " \t\n\r"))) - fam_size = (hsize_t)(HDstrtod(val, NULL) * 1024*1024); - if (H5Pset_fapl_family(fapl, fam_size, H5P_DEFAULT)<0) - return -1; - } - else if (!HDstrcmp(name, "log")) { - long log_flags = H5FD_LOG_LOC_IO; - - /* Log file access */ - if ((val = HDstrtok(NULL, " \t\n\r"))) - log_flags = HDstrtol(val, NULL, 0); - - if (H5Pset_fapl_log(fapl, NULL, (unsigned)log_flags, 0) < 0) - return -1; - } - else if (!HDstrcmp(name, "direct")) { - /* Substitute Direct I/O driver with sec2 driver temporarily because - * some output has sec2 driver as the standard. */ - if (H5Pset_fapl_sec2(fapl)<0) return -1; - } - else { - /* Unknown driver */ - return -1; - } - - return fapl; -} +} /* main */ /*------------------------------------------------------------------------- diff --git a/tools/src/h5dump/h5dump_ddl.c b/tools/src/h5dump/h5dump_ddl.c index 5c47abd..d7c7b1a 100644 --- a/tools/src/h5dump/h5dump_ddl.c +++ b/tools/src/h5dump/h5dump_ddl.c @@ -393,6 +393,7 @@ dump_all_cb(hid_t group, const char *name, const H5L_info_t *linfo, void H5_ATTR } break; + case H5O_TYPE_MAP: case H5O_TYPE_UNKNOWN: case H5O_TYPE_NTYPES: default: @@ -864,7 +865,7 @@ dump_group(hid_t gid, const char *name) if(!type_table->objs[u].recorded) { dset = H5Dopen2(gid, type_table->objs[u].objname, H5P_DEFAULT); type = H5Dget_type(dset); - sprintf(type_name, "#"H5_PRINTF_HADDR_FMT, type_table->objs[u].objno); + HDsprintf(type_name, "#"H5_PRINTF_HADDR_FMT, type_table->objs[u].objno); dump_function_table->dump_named_datatype_function(type, type_name); H5Tclose(type); H5Dclose(dset); @@ -1404,6 +1405,7 @@ obj_search(const char *path, const H5O_info_t *oi, const char H5_ATTR_UNUSED *al handle_datatypes(handle_data->fid, path, NULL, 0, NULL); break; + case H5O_TYPE_MAP: case H5O_TYPE_UNKNOWN: case H5O_TYPE_NTYPES: default: @@ -1941,9 +1943,6 @@ handle_links(hid_t fid, const char *links, void H5_ATTR_UNUSED * data, int H5_AT break; case H5L_TYPE_EXTERNAL: - begin_obj(h5tools_dump_header_format->udlinkbegin, links, h5tools_dump_header_format->udlinkblockbegin); - PRINTVALSTREAM(rawoutstream, "\n"); - indentation(COL); begin_obj(h5tools_dump_header_format->extlinkbegin, links, h5tools_dump_header_format->extlinkblockbegin); PRINTVALSTREAM(rawoutstream, "\n"); if(H5Lget_val(fid, links, buf, linfo.u.val_size, H5P_DEFAULT) >= 0) { @@ -1952,8 +1951,6 @@ handle_links(hid_t fid, const char *links, void H5_ATTR_UNUSED * data, int H5_AT if(H5Lunpack_elink_val(buf, linfo.u.val_size, NULL, &elink_file, &elink_path)>=0) { indentation(COL); - PRINTSTREAM(rawoutstream, "LINKCLASS %d\n", linfo.type); - indentation(COL); PRINTSTREAM(rawoutstream, "TARGETFILE \"%s\"\n", elink_file); indentation(COL); PRINTSTREAM(rawoutstream, "TARGETPATH \"%s\"\n", elink_path); @@ -1977,9 +1974,6 @@ handle_links(hid_t fid, const char *links, void H5_ATTR_UNUSED * data, int H5_AT begin_obj(h5tools_dump_header_format->udlinkbegin, links, h5tools_dump_header_format->udlinkblockbegin); PRINTVALSTREAM(rawoutstream, "\n"); indentation(COL); - begin_obj(h5tools_dump_header_format->udlinkbegin, links, h5tools_dump_header_format->udlinkblockbegin); - PRINTVALSTREAM(rawoutstream, "\n"); - indentation(COL); PRINTSTREAM(rawoutstream, "LINKCLASS %d\n", linfo.type); end_obj(h5tools_dump_header_format->udlinkend, h5tools_dump_header_format->udlinkblockend); break; @@ -2022,7 +2016,7 @@ handle_datatypes(hid_t fid, const char *type, void H5_ATTR_UNUSED * data, int pe if(!type_table->objs[idx].recorded) { /* unamed datatype */ - sprintf(name, "/#"H5_PRINTF_HADDR_FMT, type_table->objs[idx].objno); + HDsprintf(name, "/#"H5_PRINTF_HADDR_FMT, type_table->objs[idx].objno); if(!HDstrcmp(name, real_name)) break; @@ -2143,6 +2137,7 @@ dump_extlink(hid_t group, const char *linkname, const char *objname) handle_datatypes(group, linkname, NULL, 0, objname); break; + case H5O_TYPE_MAP: case H5O_TYPE_UNKNOWN: case H5O_TYPE_NTYPES: default: diff --git a/tools/src/h5dump/h5dump_xml.c b/tools/src/h5dump/h5dump_xml.c index 2fa9fd0..c4fd948 100644 --- a/tools/src/h5dump/h5dump_xml.c +++ b/tools/src/h5dump/h5dump_xml.c @@ -346,6 +346,7 @@ xml_dump_all_cb(hid_t group, const char *name, const H5L_info_t *linfo, void H5_ } break; + case H5O_TYPE_MAP: case H5O_TYPE_UNKNOWN: case H5O_TYPE_NTYPES: default: @@ -587,7 +588,7 @@ xml_name_to_XID(const char *str , char *outstr, int outlen, int gen) if (objno == HADDR_UNDEF) { if (gen) { objno = ref_path_table_gen_fake(str); - sprintf(outstr, "xid_"H5_PRINTF_HADDR_FMT, objno); + HDsprintf(outstr, "xid_"H5_PRINTF_HADDR_FMT, objno); return 0; } else { @@ -598,7 +599,7 @@ xml_name_to_XID(const char *str , char *outstr, int outlen, int gen) else { if (gen) { objno = ref_path_table_gen_fake(str); - sprintf(outstr, "xid_"H5_PRINTF_HADDR_FMT, objno); + HDsprintf(outstr, "xid_"H5_PRINTF_HADDR_FMT, objno); return 0; } else { @@ -607,7 +608,7 @@ xml_name_to_XID(const char *str , char *outstr, int outlen, int gen) } } - sprintf(outstr, "xid_"H5_PRINTF_HADDR_FMT, objno); + HDsprintf(outstr, "xid_"H5_PRINTF_HADDR_FMT, objno); return(0); } @@ -2685,7 +2686,7 @@ xml_dump_group(hid_t gid, const char *name) if(!type_table->objs[u].recorded) { dset = H5Dopen2(gid, type_table->objs[u].objname, H5P_DEFAULT); type = H5Dget_type(dset); - sprintf(type_name, "#"H5_PRINTF_HADDR_FMT, type_table->objs[u].objno); + HDsprintf(type_name, "#"H5_PRINTF_HADDR_FMT, type_table->objs[u].objno); dump_function_table->dump_named_datatype_function(type, type_name); H5Tclose(type); H5Dclose(dset); @@ -2767,7 +2768,7 @@ xml_dump_group(hid_t gid, const char *name) if(!type_table->objs[u].recorded) { dset = H5Dopen2(gid, type_table->objs[u].objname, H5P_DEFAULT); type = H5Dget_type(dset); - sprintf(type_name, "#"H5_PRINTF_HADDR_FMT, type_table->objs[u].objno); + HDsprintf(type_name, "#"H5_PRINTF_HADDR_FMT, type_table->objs[u].objno); dump_function_table->dump_named_datatype_function(type, type_name); H5Tclose(type); H5Dclose(dset); diff --git a/tools/src/h5import/h5import.c b/tools/src/h5import/h5import.c index 16c0d8c..1eef5ab 100644 --- a/tools/src/h5import/h5import.c +++ b/tools/src/h5import/h5import.c @@ -3753,7 +3753,7 @@ void setDefaultValues(struct Input *in, int count) in->path.count = 1; HDstrcpy(temp, "dataset"); - sprintf(num, "%d", count); + HDsprintf(num, "%d", count); HDstrcat(temp, num); HDstrcpy(in->path.group[0], temp); diff --git a/tools/src/h5ls/h5ls.c b/tools/src/h5ls/h5ls.c index 4bc1526..20a68e8 100644 --- a/tools/src/h5ls/h5ls.c +++ b/tools/src/h5ls/h5ls.c @@ -158,19 +158,13 @@ static hbool_t print_int_type(h5tools_str_t *buffer, hid_t type, int ind); static hbool_t print_float_type(h5tools_str_t *buffer, hid_t type, int ind); static herr_t visit_obj(hid_t file, const char *oname, iter_t *iter); - + /*------------------------------------------------------------------------- * Function: usage * * Purpose: Prints a usage message on stderr and then returns. * * Return: void - * - * Programmer: Robb Matzke - * Thursday, July 16, 1998 - * - * Modifications: - * *------------------------------------------------------------------------- */ static void @@ -216,6 +210,15 @@ usage (void) PRINTVALSTREAM(rawoutstream, " -V, --version Print version number and exit\n"); PRINTVALSTREAM(rawoutstream, " --vfd=DRIVER Use the specified virtual file driver\n"); PRINTVALSTREAM(rawoutstream, " -x, --hexdump Show raw data in hexadecimal format\n"); + PRINTVALSTREAM(rawoutstream, " --s3-cred=C Supply S3 authentication information to \"ros3\" vfd.\n"); + PRINTVALSTREAM(rawoutstream, " Accepts tuple of \"(<aws-region>,<access-id>,<access-key>)\".\n"); + PRINTVALSTREAM(rawoutstream, " If absent or C->\"(,,)\", defaults to no-authentication.\n"); + PRINTVALSTREAM(rawoutstream, " Has no effect if vfd flag not set to \"ros3\".\n"); + PRINTVALSTREAM(rawoutstream, " --hdfs-attrs=A Supply configuration information to Hadoop VFD.\n"); + PRINTVALSTREAM(rawoutstream, " Accepts tuple of (<namenode name>,<namenode port>,\n"); + PRINTVALSTREAM(rawoutstream, " ...<kerberos cache path>,<username>,<buffer size>)\n"); + PRINTVALSTREAM(rawoutstream, " If absent or A == '(,,,,)', all default values are used.\n"); + PRINTVALSTREAM(rawoutstream, " Has no effect if vfd flag is not 'hdfs'.\n"); PRINTVALSTREAM(rawoutstream, "\n"); PRINTVALSTREAM(rawoutstream, " file/OBJECT\n"); PRINTVALSTREAM(rawoutstream, " Each object consists of an HDF5 file name optionally followed by a\n"); @@ -237,22 +240,14 @@ usage (void) PRINTVALSTREAM(rawoutstream, " Replaced by --enable-error-stack.\n"); } - /*------------------------------------------------------------------------- * Function: print_string * * Purpose: Print a string value by escaping unusual characters. If - * STREAM is null then we only count how large the output would - * be. + * STREAM is null then we only count how large the output would be. * * Return: Number of characters printed. - * - * Programmer: Robb Matzke - * Thursday, November 5, 1998 - * - * Modifications: - * *------------------------------------------------------------------------- */ static int @@ -263,27 +258,33 @@ print_string(h5tools_str_t *buffer, const char *s, hbool_t escape_spaces) for (/*void*/; s && *s; s++) { switch (*s) { case '"': - if (buffer) h5tools_str_append(buffer, "\\\""); + if (buffer) + h5tools_str_append(buffer, "\\\""); nprint += 2; break; case '\\': - if (buffer) h5tools_str_append(buffer, "\\\\"); + if (buffer) + h5tools_str_append(buffer, "\\\\"); nprint += 2; break; case '\b': - if (buffer) h5tools_str_append(buffer, "\\b"); + if (buffer) + h5tools_str_append(buffer, "\\b"); nprint += 2; break; case '\f': - if (buffer) h5tools_str_append(buffer, "\\f"); + if (buffer) + h5tools_str_append(buffer, "\\f"); nprint += 2; break; case '\n': - if (buffer) h5tools_str_append(buffer, "\\n"); + if (buffer) + h5tools_str_append(buffer, "\\n"); nprint += 2; break; case '\r': - if (buffer) h5tools_str_append(buffer, "\\r"); + if (buffer) + h5tools_str_append(buffer, "\\r"); nprint += 2; break; case '\t': @@ -292,21 +293,25 @@ print_string(h5tools_str_t *buffer, const char *s, hbool_t escape_spaces) break; case ' ': if (escape_spaces) { - if (buffer) h5tools_str_append(buffer, "\\ "); + if (buffer) + h5tools_str_append(buffer, "\\ "); nprint += 2; } else { - if (buffer) h5tools_str_append(buffer, " "); + if (buffer) + h5tools_str_append(buffer, " "); nprint++; } break; default: if (isprint((int)*s)) { - if (buffer) h5tools_str_append(buffer, "%c", *s); + if (buffer) + h5tools_str_append(buffer, "%c", *s); nprint++; } else { - if (buffer) h5tools_str_append(buffer, "\\%03o", *((const unsigned char*)s)); + if (buffer) + h5tools_str_append(buffer, "\\%03o", *((const unsigned char*)s)); nprint += 4; } break; @@ -315,21 +320,14 @@ print_string(h5tools_str_t *buffer, const char *s, hbool_t escape_spaces) return nprint; } - + /*------------------------------------------------------------------------- * Function: print_obj_name * * Purpose: Print an object name and another string. * * Return: Success: TRUE - * - * Failure: FALSE, nothing printed - * - * Programmer: Quincey Koziol - * Tuesday, November 6, 2007 - * - * Modifications: - * + * Failure: FALSE, nothing printed *------------------------------------------------------------------------- */ static int @@ -340,19 +338,19 @@ print_obj_name(h5tools_str_t *buffer, const iter_t *iter, const char *oname, const char *name = fullname; /* Pointer to buffer for printing */ int n; - if(show_file_name_g) + if (show_file_name_g) HDsnprintf(fullname, sizeof(fullname), "%s/%s", iter->fname, oname + iter->name_start); else name = oname + iter->name_start; /* Print the object name, either full name or base name */ - if(fullname_g) + if (fullname_g) n = print_string(buffer, name, TRUE); else { const char *last_sep; /* The location of the last group separator */ /* Find the last component of the path name */ - if(NULL == (last_sep = HDstrrchr(name, '/'))) + if (NULL == (last_sep = HDstrrchr(name, '/'))) last_sep = name; else { last_sep++; @@ -364,123 +362,158 @@ print_obj_name(h5tools_str_t *buffer, const iter_t *iter, const char *oname, return TRUE; } - + /*------------------------------------------------------------------------- * Function: print_native_type * * Purpose: Prints the name of a native C data type. * * Return: Success: TRUE - * - * Failure: FALSE, nothing printed. - * - * Programmer: Robb Matzke - * Thursday, November 5, 1998 - * - * Modifications: - * Robb Matzke, 1999-06-11 - * Added the C9x types, but we still prefer to display the types - * from the C language itself (like `int' vs. `int32_t'). - * + * Failure: FALSE, nothing printed. *------------------------------------------------------------------------- */ static hbool_t print_native_type(h5tools_str_t *buffer, hid_t type, int ind) { - if(!simple_output_g) { - if (H5Tequal(type, H5T_NATIVE_SCHAR)==TRUE) { + if (!simple_output_g) { + if (H5Tequal(type, H5T_NATIVE_SCHAR) == TRUE) { h5tools_str_append(buffer, "native signed char"); - } else if (H5Tequal(type, H5T_NATIVE_UCHAR)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_UCHAR) == TRUE) { h5tools_str_append(buffer, "native unsigned char"); - } else if (H5Tequal(type, H5T_NATIVE_INT)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_INT) == TRUE) { h5tools_str_append(buffer, "native int"); - } else if (H5Tequal(type, H5T_NATIVE_UINT)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_UINT) == TRUE) { h5tools_str_append(buffer, "native unsigned int"); - } else if (H5Tequal(type, H5T_NATIVE_SHORT)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_SHORT) == TRUE) { h5tools_str_append(buffer, "native short"); - } else if (H5Tequal(type, H5T_NATIVE_USHORT)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_USHORT) == TRUE) { h5tools_str_append(buffer, "native unsigned short"); - } else if (H5Tequal(type, H5T_NATIVE_LONG)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_LONG) == TRUE) { h5tools_str_append(buffer, "native long"); - } else if (H5Tequal(type, H5T_NATIVE_ULONG)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_ULONG) == TRUE) { h5tools_str_append(buffer, "native unsigned long"); - } else if (H5Tequal(type, H5T_NATIVE_LLONG)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_LLONG) == TRUE) { h5tools_str_append(buffer, "native long long"); - } else if (H5Tequal(type, H5T_NATIVE_ULLONG)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_ULLONG) == TRUE) { h5tools_str_append(buffer, "native unsigned long long"); - } else if (H5Tequal(type, H5T_NATIVE_FLOAT)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_FLOAT) == TRUE) { h5tools_str_append(buffer, "native float"); - } else if (H5Tequal(type, H5T_NATIVE_DOUBLE)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_DOUBLE) == TRUE) { h5tools_str_append(buffer, "native double"); + } #if H5_SIZEOF_LONG_DOUBLE !=0 - } else if (H5Tequal(type, H5T_NATIVE_LDOUBLE)==TRUE) { + else if (H5Tequal(type, H5T_NATIVE_LDOUBLE) == TRUE) { h5tools_str_append(buffer, "native long double"); + } #endif - } else if (H5Tequal(type, H5T_NATIVE_INT8)==TRUE) { + else if (H5Tequal(type, H5T_NATIVE_INT8) == TRUE) { h5tools_str_append(buffer, "native int8_t"); - } else if (H5Tequal(type, H5T_NATIVE_UINT8)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_UINT8) == TRUE) { h5tools_str_append(buffer, "native uint8_t"); - } else if (H5Tequal(type, H5T_NATIVE_INT16)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_INT16) == TRUE) { h5tools_str_append(buffer, "native int16_t"); - } else if (H5Tequal(type, H5T_NATIVE_UINT16)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_UINT16) == TRUE) { h5tools_str_append(buffer, "native uint16_t"); - } else if (H5Tequal(type, H5T_NATIVE_INT32)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_INT32) == TRUE) { h5tools_str_append(buffer, "native int32_t"); - } else if (H5Tequal(type, H5T_NATIVE_UINT32)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_UINT32) == TRUE) { h5tools_str_append(buffer, "native uint32_t"); - } else if (H5Tequal(type, H5T_NATIVE_INT64)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_INT64) == TRUE) { h5tools_str_append(buffer, "native int64_t"); - } else if (H5Tequal(type, H5T_NATIVE_UINT64)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_UINT64) == TRUE) { h5tools_str_append(buffer, "native uint64_t"); - } else if (H5Tequal(type, H5T_NATIVE_INT_LEAST8)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_INT_LEAST8) == TRUE) { h5tools_str_append(buffer, "native int_least8_t"); - } else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST8)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST8) == TRUE) { h5tools_str_append(buffer, "native uint_least8_t"); - } else if (H5Tequal(type, H5T_NATIVE_INT_LEAST16)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_INT_LEAST16) == TRUE) { h5tools_str_append(buffer, "native int_least16_t"); - } else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST16)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST16) == TRUE) { h5tools_str_append(buffer, "native uint_least16_t"); - } else if (H5Tequal(type, H5T_NATIVE_INT_LEAST32)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_INT_LEAST32) == TRUE) { h5tools_str_append(buffer, "native int_least32_t"); - } else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST32)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST32) == TRUE) { h5tools_str_append(buffer, "native uint_least32_t"); - } else if (H5Tequal(type, H5T_NATIVE_INT_LEAST64)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_INT_LEAST64) == TRUE) { h5tools_str_append(buffer, "native int_least64_t"); - } else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST64)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_UINT_LEAST64) == TRUE) { h5tools_str_append(buffer, "native uint_least64_t"); - } else if (H5Tequal(type, H5T_NATIVE_INT_FAST8)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_INT_FAST8) == TRUE) { h5tools_str_append(buffer, "native int_fast8_t"); - } else if (H5Tequal(type, H5T_NATIVE_UINT_FAST8)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_UINT_FAST8) == TRUE) { h5tools_str_append(buffer, "native uint_fast8_t"); - } else if (H5Tequal(type, H5T_NATIVE_INT_FAST16)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_INT_FAST16) == TRUE) { h5tools_str_append(buffer, "native int_fast16_t"); - } else if (H5Tequal(type, H5T_NATIVE_UINT_FAST16)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_UINT_FAST16) == TRUE) { h5tools_str_append(buffer, "native uint_fast16_t"); - } else if (H5Tequal(type, H5T_NATIVE_INT_FAST32)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_INT_FAST32) == TRUE) { h5tools_str_append(buffer, "native int_fast32_t"); - } else if (H5Tequal(type, H5T_NATIVE_UINT_FAST32)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_UINT_FAST32) == TRUE) { h5tools_str_append(buffer, "native uint_fast32_t"); - } else if (H5Tequal(type, H5T_NATIVE_INT_FAST64)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_INT_FAST64) == TRUE) { h5tools_str_append(buffer, "native int_fast64_t"); - } else if (H5Tequal(type, H5T_NATIVE_UINT_FAST64)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_UINT_FAST64) == TRUE) { h5tools_str_append(buffer, "native uint_fast64_t"); - } else if (H5Tequal(type, H5T_NATIVE_B8)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_B8) == TRUE) { h5tools_str_append(buffer, "native 8-bit field"); - } else if (H5Tequal(type, H5T_NATIVE_B16)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_B16) == TRUE) { h5tools_str_append(buffer, "native 16-bit field"); - } else if (H5Tequal(type, H5T_NATIVE_B32)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_B32) == TRUE) { h5tools_str_append(buffer, "native 32-bit field"); - } else if (H5Tequal(type, H5T_NATIVE_B64)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_B64) == TRUE) { h5tools_str_append(buffer, "native 64-bit field"); - } else if (H5Tequal(type, H5T_NATIVE_HSIZE)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_HSIZE) == TRUE) { h5tools_str_append(buffer, "native hsize_t"); - } else if (H5Tequal(type, H5T_NATIVE_HSSIZE)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_HSSIZE) == TRUE) { h5tools_str_append(buffer, "native hssize_t"); - } else if (H5Tequal(type, H5T_NATIVE_HERR)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_HERR) == TRUE) { h5tools_str_append(buffer, "native herr_t"); - } else if (H5Tequal(type, H5T_NATIVE_HBOOL)==TRUE) { + } + else if (H5Tequal(type, H5T_NATIVE_HBOOL) == TRUE) { h5tools_str_append(buffer, "native hbool_t"); - } else { + } + else { return print_int_type(buffer, type, ind); } } else { @@ -489,36 +522,29 @@ print_native_type(h5tools_str_t *buffer, hid_t type, int ind) return TRUE; } - + /*------------------------------------------------------------------------- * Function: print_ieee_type * * Purpose: Print the name of an IEEE floating-point data type. * * Return: Success: TRUE - * - * Failure: FALSE, nothing printed - * - * Programmer: Robb Matzke - * Thursday, November 5, 1998 - * - * Modifications: - * + * Failure: FALSE, nothing printed *------------------------------------------------------------------------- */ static hbool_t print_ieee_type(h5tools_str_t *buffer, hid_t type, int ind) { - if (H5Tequal(type, H5T_IEEE_F32BE)==TRUE) { + if (H5Tequal(type, H5T_IEEE_F32BE) == TRUE) { h5tools_str_append(buffer, "IEEE 32-bit big-endian float"); } - else if (H5Tequal(type, H5T_IEEE_F32LE)==TRUE) { + else if (H5Tequal(type, H5T_IEEE_F32LE) == TRUE) { h5tools_str_append(buffer, "IEEE 32-bit little-endian float"); } - else if (H5Tequal(type, H5T_IEEE_F64BE)==TRUE) { + else if (H5Tequal(type, H5T_IEEE_F64BE) == TRUE) { h5tools_str_append(buffer, "IEEE 64-bit big-endian float"); } - else if (H5Tequal(type, H5T_IEEE_F64LE)==TRUE) { + else if (H5Tequal(type, H5T_IEEE_F64LE) == TRUE) { h5tools_str_append(buffer, "IEEE 64-bit little-endian float"); } else { @@ -527,21 +553,15 @@ print_ieee_type(h5tools_str_t *buffer, hid_t type, int ind) return TRUE; } - + /*------------------------------------------------------------------------- * Function: print_precision * * Purpose: Prints information on the next line about precision and - * padding if the precision is less than the total data type - * size. + * padding if the precision is less than the total data type + * size. * * Return: void - * - * Programmer: Robb Matzke - * Thursday, November 5, 1998 - * - * Modifications: - * *------------------------------------------------------------------------- */ static void @@ -556,13 +576,12 @@ print_precision(h5tools_str_t *buffer, hid_t type, int ind) /* If the precision is less than the total size then show the precision * and offset on the following line. Also display the padding * information. */ - if(8 * H5Tget_size(type) != (prec = H5Tget_precision(type))) { + if (8 * H5Tget_size(type) != (prec = H5Tget_precision(type))) { h5tools_str_append(buffer, "\n%*s(%lu bit%s of precision beginning at bit %lu)", - ind, "", (unsigned long)prec, 1 == prec ? "" : "s", - (unsigned long)H5Tget_offset(type)); + ind, "", (unsigned long)prec, 1 == prec ? "" : "s", (unsigned long)H5Tget_offset(type)); H5Tget_pad(type, &plsb, &pmsb); - if(H5Tget_offset(type) > 0) { + if (H5Tget_offset(type) > 0) { switch(plsb) { case H5T_PAD_ZERO: plsb_s = "zero"; @@ -581,7 +600,7 @@ print_precision(h5tools_str_t *buffer, hid_t type, int ind) break; } } - if((unsigned)H5Tget_offset(type) + prec < 8 * H5Tget_size(type)) { + if ((unsigned)H5Tget_offset(type) + prec < 8 * H5Tget_size(type)) { switch(pmsb) { case H5T_PAD_ZERO: pmsb_s = "zero"; @@ -604,61 +623,53 @@ print_precision(h5tools_str_t *buffer, hid_t type, int ind) h5tools_str_append(buffer, "\n%*s(", ind, ""); if (plsb_s) { nbits = (unsigned)H5Tget_offset(type); - h5tools_str_append(buffer, "%lu %s bit%s at bit 0", - (unsigned long)nbits, plsb_s, 1 == nbits ? "" : "s"); + h5tools_str_append(buffer, "%lu %s bit%s at bit 0", (unsigned long)nbits, plsb_s, 1 == nbits ? "" : "s"); } - if (plsb_s && pmsb_s) h5tools_str_append(buffer, ", "); + if (plsb_s && pmsb_s) + h5tools_str_append(buffer, ", "); if (pmsb_s) { nbits = (8 * H5Tget_size(type)) - ((unsigned)H5Tget_offset(type) + prec); - h5tools_str_append(buffer, "%lu %s bit%s at bit %lu", - (unsigned long)nbits, pmsb_s, 1 == nbits ? "" : "s", - (unsigned long)(8 * H5Tget_size(type) - nbits)); + h5tools_str_append(buffer, "%lu %s bit%s at bit %lu", (unsigned long)nbits, pmsb_s, 1 == nbits ? "" : "s", (unsigned long)(8 * H5Tget_size(type) - nbits)); } h5tools_str_append(buffer, ")"); } } } - + /*------------------------------------------------------------------------- * Function: print_int_type * * Purpose: Print the name of an integer data type. Common information - * like number of bits, byte order, and sign scheme appear on - * the first line. Additional information might appear in - * parentheses on the following lines. + * like number of bits, byte order, and sign scheme appear on + * the first line. Additional information might appear in + * parentheses on the following lines. * * Return: Success: TRUE - * - * Failure: FALSE, nothing printed - * - * Programmer: Robb Matzke - * Thursday, November 5, 1998 - * - * Modifications: - * + * Failure: FALSE, nothing printed *------------------------------------------------------------------------- */ static hbool_t print_int_type(h5tools_str_t *buffer, hid_t type, int ind) { - H5T_order_t order; /* byte order value */ - const char *order_s=NULL; /* byte order string */ - H5T_sign_t sign; /* sign scheme value */ - const char *sign_s=NULL; /* sign scheme string */ + H5T_order_t order; /* byte order value */ + const char *order_s = NULL; /* byte order string */ + H5T_sign_t sign; /* sign scheme value */ + const char *sign_s = NULL; /* sign scheme string */ - if (H5T_INTEGER!=H5Tget_class(type)) return FALSE; + if (H5T_INTEGER != H5Tget_class(type)) + return FALSE; /* Byte order */ - if (H5Tget_size(type)>1) { + if (H5Tget_size(type) > 1) { order = H5Tget_order(type); - if (H5T_ORDER_LE==order) { + if (H5T_ORDER_LE == order) { order_s = " little-endian"; } - else if (H5T_ORDER_BE==order) { + else if (H5T_ORDER_BE == order) { order_s = " big-endian"; } - else if (H5T_ORDER_VAX==order) { + else if (H5T_ORDER_VAX == order) { order_s = " mixed-endian"; } else { @@ -670,11 +681,11 @@ print_int_type(h5tools_str_t *buffer, hid_t type, int ind) } /* Sign */ - if ((sign=H5Tget_sign(type))>=0) { - if (H5T_SGN_NONE==sign) { + if ((sign = H5Tget_sign(type)) >= 0) { + if (H5T_SGN_NONE == sign) { sign_s = " unsigned"; } - else if (H5T_SGN_2==sign) { + else if (H5T_SGN_2 == sign) { sign_s = ""; } else { @@ -687,27 +698,19 @@ print_int_type(h5tools_str_t *buffer, hid_t type, int ind) /* Print size, order, and sign on first line, precision and padding * information on the subsequent lines */ - h5tools_str_append(buffer, "%lu-bit%s%s integer", - (unsigned long)(8*H5Tget_size(type)), order_s, sign_s); + h5tools_str_append(buffer, "%lu-bit%s%s integer", (unsigned long)(8*H5Tget_size(type)), order_s, sign_s); print_precision(buffer, type, ind); return TRUE; } - + /*------------------------------------------------------------------------- * Function: print_float_type * * Purpose: Print info about a floating point data type. * * Return: Success: TRUE - * - * Failure: FALSE, nothing printed - * - * Programmer: Robb Matzke - * Thursday, November 5, 1998 - * - * Modifications: - * + * Failure: FALSE, nothing printed *------------------------------------------------------------------------- */ static hbool_t @@ -724,18 +727,19 @@ print_float_type(h5tools_str_t *buffer, hid_t type, int ind) H5T_pad_t pad; /* internal padding value */ const char *pad_s=NULL; /* internal padding string */ - if (H5T_FLOAT!=H5Tget_class(type)) return FALSE; + if (H5T_FLOAT != H5Tget_class(type)) + return FALSE; /* Byte order */ - if (H5Tget_size(type)>1) { + if (H5Tget_size(type) > 1) { order = H5Tget_order(type); - if (H5T_ORDER_LE==order) { + if (H5T_ORDER_LE == order) { order_s = " little-endian"; } - else if (H5T_ORDER_BE==order) { + else if (H5T_ORDER_BE == order) { order_s = " big-endian"; } - else if (H5T_ORDER_VAX==order) { + else if (H5T_ORDER_VAX == order) { order_s = " mixed-endian"; } else { @@ -748,8 +752,7 @@ print_float_type(h5tools_str_t *buffer, hid_t type, int ind) /* Print size and byte order on first line, precision and padding on * subsequent lines. */ - h5tools_str_append(buffer, "%lu-bit%s floating-point", - (unsigned long)(8*H5Tget_size(type)), order_s); + h5tools_str_append(buffer, "%lu-bit%s floating-point", (unsigned long)(8*H5Tget_size(type)), order_s); print_precision(buffer, type, ind); /* Print sizes, locations, and other information about each field */ @@ -774,15 +777,13 @@ print_float_type(h5tools_str_t *buffer, hid_t type, int ind) break; } h5tools_str_append(buffer, "\n%*s(significant for %lu bit%s at bit %lu%s)", ind, "", - (unsigned long)msize, 1==msize?"":"s", (unsigned long)mpos, - norm_s); + (unsigned long)msize, 1==msize?"":"s", (unsigned long)mpos, norm_s); h5tools_str_append(buffer, "\n%*s(exponent for %lu bit%s at bit %lu, bias is 0x%lx)", - ind, "", (unsigned long)esize, 1==esize?"":"s", - (unsigned long)epos, (unsigned long)ebias); + ind, "", (unsigned long)esize, 1==esize?"":"s", (unsigned long)epos, (unsigned long)ebias); h5tools_str_append(buffer, "\n%*s(sign bit at %lu)", ind, "", (unsigned long)spos); /* Display internal padding */ - if (1+esize+msize<H5Tget_precision(type)) { + if ((1 + esize + msize) < H5Tget_precision(type)) { pad = H5Tget_inpad(type); switch (pad) { case H5T_PAD_ZERO: @@ -807,19 +808,14 @@ print_float_type(h5tools_str_t *buffer, hid_t type, int ind) return TRUE; } - + /*------------------------------------------------------------------------- * Function: print_cmpd_type * * Purpose: Print info about a compound data type. * * Return: Success: TRUE - * - * Failure: FALSE, nothing printed - * - * Programmer: Robb Matzke - * Thursday, November 5, 1998 - * + * Failure: FALSE, nothing printed *------------------------------------------------------------------------- */ static hbool_t @@ -838,14 +834,12 @@ print_cmpd_type(h5tools_str_t *buffer, hid_t type, int ind) return FALSE; h5tools_str_append(buffer, "struct {"); - for(i = 0; i < (unsigned)nmembs; i++) { - + for (i = 0; i < (unsigned)nmembs; i++) { /* Name and offset */ name = H5Tget_member_name(type, i); h5tools_str_append(buffer, "\n%*s\"", ind+4, ""); n = print_string(buffer, name, FALSE); - h5tools_str_append(buffer, "\"%*s +%-4lu ", MAX(0, 16-n), "", - (unsigned long)H5Tget_member_offset(type, i)); + h5tools_str_append(buffer, "\"%*s +%-4lu ", MAX(0, 16-n), "", (unsigned long)H5Tget_member_offset(type, i)); H5free_memory(name); /* Member's type */ @@ -854,27 +848,19 @@ print_cmpd_type(h5tools_str_t *buffer, hid_t type, int ind) H5Tclose(subtype); } size = H5Tget_size(type); - h5tools_str_append(buffer, "\n%*s} %lu byte%s", - ind, "", (unsigned long)size, 1==size?"":"s"); + h5tools_str_append(buffer, "\n%*s} %lu byte%s", ind, "", (unsigned long)size, 1==size?"":"s"); return TRUE; } - + /*------------------------------------------------------------------------- * Function: print_enum_type * * Purpose: Print info about an enumeration data type. * * Return: Success: TRUE - * - * Failure: FALSE, nothing printed - * - * Programmer: Robb Matzke - * Wednesday, December 23, 1998 - * - * Modifications: - * + * Failure: FALSE, nothing printed *------------------------------------------------------------------------- */ static hbool_t @@ -883,9 +869,9 @@ print_enum_type(h5tools_str_t *buffer, hid_t type, int ind) int nmembs; /* number of members */ hid_t super; /* enum base integer type */ - if(H5T_ENUM != H5Tget_class(type)) + if (H5T_ENUM != H5Tget_class(type)) return FALSE; - if((nmembs = H5Tget_nmembers(type)) < 0) + if ((nmembs = H5Tget_nmembers(type)) < 0) return FALSE; super = H5Tget_super(type); @@ -893,7 +879,7 @@ print_enum_type(h5tools_str_t *buffer, hid_t type, int ind) print_type(buffer, super, ind + 4); h5tools_str_append(buffer, " {"); - if(nmembs > 0) { + if (nmembs > 0) { char **name; /* member names */ unsigned char *value; /* value array */ hid_t native = -1; /* native integer data type */ @@ -905,9 +891,9 @@ print_enum_type(h5tools_str_t *buffer, hid_t type, int ind) * 1. long long -- the largest native signed integer * 2. unsigned long long -- the largest native unsigned integer * 3. raw format */ - if(H5Tget_size(type) <= sizeof(long long)) { + if (H5Tget_size(type) <= sizeof(long long)) { dst_size = sizeof(long long); - if(H5T_SGN_NONE == H5Tget_sign(type)) + if (H5T_SGN_NONE == H5Tget_sign(type)) native = H5T_NATIVE_ULLONG; else native = H5T_NATIVE_LLONG; @@ -918,16 +904,16 @@ print_enum_type(h5tools_str_t *buffer, hid_t type, int ind) /* Get the names and raw values of all members */ name = (char **)HDcalloc((size_t)nmembs, sizeof(char *)); value = (unsigned char *)HDcalloc((size_t)nmembs, MAX(H5Tget_size(type), dst_size)); - for(i = 0; i < (unsigned)nmembs; i++) { + for (i = 0; i < (unsigned)nmembs; i++) { name[i] = H5Tget_member_name(type, i); H5Tget_member_value(type, i, value + i * H5Tget_size(type)); } /* Convert values to native data type */ - if(native > 0) - if(H5Tconvert(super, native, (size_t)nmembs, value, NULL, H5P_DEFAULT) < 0) { + if (native > 0) + if (H5Tconvert(super, native, (size_t)nmembs, value, NULL, H5P_DEFAULT) < 0) { /* Release resources */ - for(i = 0; i < (unsigned)nmembs; i++) + for (i = 0; i < (unsigned)nmembs; i++) H5free_memory(name[i]); HDfree(name); HDfree(value); @@ -939,7 +925,7 @@ print_enum_type(h5tools_str_t *buffer, hid_t type, int ind) /*not implemented yet*/ /* Print members */ - for(i = 0; i < (unsigned)nmembs; i++) { + for (i = 0; i < (unsigned)nmembs; i++) { unsigned char *copy; /* a pointer to value array */ int nchars; /* number of output characters */ @@ -947,14 +933,14 @@ print_enum_type(h5tools_str_t *buffer, hid_t type, int ind) nchars = print_string(buffer, name[i], TRUE); h5tools_str_append(buffer, "%*s = ", MAX(0, 16 - nchars), ""); - if(native < 0) { + if (native < 0) { size_t j; h5tools_str_append(buffer, "0x"); - for(j = 0; j < dst_size; j++) + for (j = 0; j < dst_size; j++) h5tools_str_append(buffer, "%02x", value[i*dst_size+j]); } - else if(H5T_SGN_NONE == H5Tget_sign(native)) { + else if (H5T_SGN_NONE == H5Tget_sign(native)) { /*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size" *strangely, unless use another pointer "copy".*/ copy = value + i * dst_size; @@ -964,8 +950,7 @@ print_enum_type(h5tools_str_t *buffer, hid_t type, int ind) /*On SGI Altix(cobalt), wrong values were printed out with "value+i*dst_size" *strangely, unless use another pointer "copy".*/ copy = value + i * dst_size; - h5tools_str_append(buffer, "%"H5_PRINTF_LL_WIDTH"d", - *((long long*)((void*)copy))); + h5tools_str_append(buffer, "%"H5_PRINTF_LL_WIDTH"d", *((long long*)((void*)copy))); } } @@ -985,21 +970,14 @@ print_enum_type(h5tools_str_t *buffer, hid_t type, int ind) return TRUE; } - + /*------------------------------------------------------------------------- * Function: print_string_type * * Purpose: Print information about a string data type. * * Return: Success: TRUE - * - * Failure: FALSE, nothing printed - * - * Programmer: Robb Matzke - * Thursday, November 5, 1998 - * - * Modifications: - * + * Failure: FALSE, nothing printed *------------------------------------------------------------------------- */ static hbool_t @@ -1010,7 +988,8 @@ print_string_type(h5tools_str_t *buffer, hid_t type, int H5_ATTR_UNUSED ind) H5T_cset_t cset; const char *cset_s=NULL; - if (H5T_STRING!=H5Tget_class(type)) return FALSE; + if (H5T_STRING != H5Tget_class(type)) + return FALSE; /* Padding */ pad = H5Tget_strpad(type); @@ -1086,59 +1065,43 @@ print_string_type(h5tools_str_t *buffer, hid_t type, int H5_ATTR_UNUSED ind) return TRUE; } - + /*------------------------------------------------------------------------- * Function: print_reference_type * * Purpose: Prints information about a reference data type. * * Return: Success: TRUE - * - * Failure: FALSE, nothing printed - * - * Programmer: Robb Matzke - * Thursday, November 5, 1998 - * - * Modifications: - * Robb Matzke, 1999-06-04 - * Knows about object and dataset region references. - * + * Failure: FALSE, nothing printed *------------------------------------------------------------------------- */ static hbool_t print_reference_type(h5tools_str_t *buffer, hid_t type, int H5_ATTR_UNUSED ind) { - if (H5T_REFERENCE!=H5Tget_class(type)) return FALSE; + if (H5T_REFERENCE != H5Tget_class(type)) + return FALSE; - if (H5Tequal(type, H5T_STD_REF_OBJ)==TRUE) { + if (H5Tequal(type, H5T_STD_REF_OBJ) == TRUE) { h5tools_str_append(buffer, "object reference"); } - else if (H5Tequal(type, H5T_STD_REF_DSETREG)==TRUE) { + else if (H5Tequal(type, H5T_STD_REF_DSETREG) == TRUE) { h5tools_str_append(buffer, "dataset region reference"); } else { - h5tools_str_append(buffer, "%lu-byte unknown reference", - (unsigned long)H5Tget_size(type)); + h5tools_str_append(buffer, "%lu-byte unknown reference", (unsigned long)H5Tget_size(type)); } return TRUE; } - + /*------------------------------------------------------------------------- * Function: print_opaque_type * * Purpose: Prints information about an opaque data type. * * Return: Success: TRUE - * - * Failure: FALSE, nothing printed - * - * Programmer: Robb Matzke - * Monday, June 7, 1999 - * - * Modifications: - * + * Failure: FALSE, nothing printed *------------------------------------------------------------------------- */ static hbool_t @@ -1147,11 +1110,12 @@ print_opaque_type(h5tools_str_t *buffer, hid_t type, int ind) char *tag; size_t size; - if (H5T_OPAQUE!=H5Tget_class(type)) return FALSE; + if (H5T_OPAQUE != H5Tget_class(type)) + return FALSE; size = H5Tget_size(type); h5tools_str_append(buffer, "%lu-byte opaque type", (unsigned long)size); - if ((tag=H5Tget_tag(type))) { + if ((tag = H5Tget_tag(type))) { h5tools_str_append(buffer, "\n%*s(tag = \"", ind, ""); print_string(buffer, tag, FALSE); h5tools_str_append(buffer, "\")"); @@ -1160,20 +1124,14 @@ print_opaque_type(h5tools_str_t *buffer, hid_t type, int ind) return TRUE; } - + /*------------------------------------------------------------------------- * Function: print_vlen_type * * Purpose: Print information about a variable-length type * * Return: Success: TRUE - * * Failure: FALSE - * - * Programmer: Robb Matzke - * Friday, December 1, 2000 - * - * Modifications: *------------------------------------------------------------------------- */ static hbool_t @@ -1181,27 +1139,22 @@ print_vlen_type(h5tools_str_t *buffer, hid_t type, int ind) { hid_t super; - if (H5T_VLEN!=H5Tget_class(type)) return FALSE; + if (H5T_VLEN != H5Tget_class(type)) + return FALSE; - h5tools_str_append(buffer, "variable length of\n%*s", ind+4, ""); + h5tools_str_append(buffer, "variable length of\n%*s", ind + 4, ""); super = H5Tget_super(type); - print_type(buffer, super, ind+4); + print_type(buffer, super, ind + 4); H5Tclose(super); return TRUE; } - + /*--------------------------------------------------------------------------- * Purpose: Print information about an array type * * Return: Success: TRUE - * * Failure: FALSE - * - * Programmer: Robb Matzke - * Thursday, January 31, 2002 - * - * Modifications: *--------------------------------------------------------------------------- */ static hbool_t @@ -1211,7 +1164,7 @@ print_array_type(h5tools_str_t *buffer, hid_t type, int ind) int ndims, i; hsize_t *dims=NULL; - if (H5T_ARRAY!=H5Tget_class(type)) + if (H5T_ARRAY != H5Tget_class(type)) return FALSE; ndims = H5Tget_array_ndims(type); if (ndims) { @@ -1219,7 +1172,7 @@ print_array_type(h5tools_str_t *buffer, hid_t type, int ind) H5Tget_array_dims2(type, dims); /* Print dimensions */ - for (i=0; i<ndims; i++) + for (i = 0; i < ndims; i++) h5tools_str_append(buffer, "%s" HSIZE_T_FORMAT , i?",":"[", dims[i]); h5tools_str_append(buffer, "]"); @@ -1237,23 +1190,14 @@ print_array_type(h5tools_str_t *buffer, hid_t type, int ind) return TRUE; } - + /*------------------------------------------------------------------------- * Function: print_bitfield_type * * Purpose: Print information about a bitfield type. * * Return: Success: TRUE - * - * Failure: FALSE, nothing printed - * - * Programmer: Pedro Vicente - * Tuesday, May 20, 2003 - * - * Modifications: - * Robb Matzke, LLNL 2003-06-05 - * Generalized Pedro's original if/then/else. Also display - * precision/offset information. + * Failure: FALSE, nothing printed *------------------------------------------------------------------------- */ static hbool_t @@ -1262,24 +1206,28 @@ print_bitfield_type(h5tools_str_t *buffer, hid_t type, int ind) H5T_order_t order; /* byte order value */ const char *order_s=NULL; /* byte order string */ - if (H5T_BITFIELD!=H5Tget_class(type)) return FALSE; + if (H5T_BITFIELD != H5Tget_class(type)) + return FALSE; if (H5Tget_size(type)>1) { order = H5Tget_order(type); - if (H5T_ORDER_LE==order) { + if (H5T_ORDER_LE == order) { order_s = " little-endian"; - } else if (H5T_ORDER_BE==order) { + } + else if (H5T_ORDER_BE == order) { order_s = " big-endian"; - } else if (H5T_ORDER_VAX==order) { + } + else if (H5T_ORDER_VAX == order) { order_s = " mixed-endian"; - } else { + } + else { order_s = "unknown-byte-order"; } - } else { + } + else { order_s = ""; } - h5tools_str_append(buffer, "%lu-bit%s bitfield", - (unsigned long)(8*H5Tget_size(type)), order_s); + h5tools_str_append(buffer, "%lu-bit%s bitfield", (unsigned long)(8*H5Tget_size(type)), order_s); print_precision(buffer, type, ind); return TRUE; } @@ -1293,16 +1241,9 @@ print_bitfield_type(h5tools_str_t *buffer, hid_t type, int ind) * there might be line-feeds inside the type definition). The * first line is assumed to have IND characters before it on * the same line (printed by the caller). - * - * Return: void - * - * Programmer: Robb Matzke - * Thursday, November 5, 1998 - * - * Modifications: - * Robb Matzke, 1999-06-11 * Prints the OID of shared data types. * + * Return: void *------------------------------------------------------------------------- */ static void @@ -1311,24 +1252,23 @@ print_type(h5tools_str_t *buffer, hid_t type, int ind) H5T_class_t data_class = H5Tget_class(type); /* Bad data type */ - if (type<0) { + if (type < 0) { h5tools_str_append(buffer,"<ERROR>"); return; } /* Shared? If so then print the type's OID */ - if(H5Tcommitted(type)) { + if (H5Tcommitted(type)) { H5O_info_t oi; - if(H5Oget_info2(type, &oi, H5O_INFO_BASIC) >= 0) - h5tools_str_append(buffer,"shared-%lu:"H5_PRINTF_HADDR_FMT" ", - oi.fileno, oi.addr); + if (H5Oget_info2(type, &oi, H5O_INFO_BASIC) >= 0) + h5tools_str_append(buffer,"shared-%lu:"H5_PRINTF_HADDR_FMT" ", oi.fileno, oi.addr); else h5tools_str_append(buffer,"shared "); } /* end if */ /* Print the type */ - if(print_native_type(buffer, type, ind) || + if (print_native_type(buffer, type, ind) || print_ieee_type(buffer, type, ind) || print_cmpd_type(buffer, type, ind) || print_enum_type(buffer, type, ind) || @@ -1341,25 +1281,16 @@ print_type(h5tools_str_t *buffer, hid_t type, int ind) return; /* Unknown type */ - h5tools_str_append(buffer,"%lu-byte class-%u unknown", - (unsigned long)H5Tget_size(type), (unsigned)data_class); + h5tools_str_append(buffer,"%lu-byte class-%u unknown", (unsigned long)H5Tget_size(type), (unsigned)data_class); } - + /*------------------------------------------------------------------------- * Function: dump_dataset_values * * Purpose: Prints all values of a dataset. * * Return: void - * - * Programmer: Robb Matzke - * Tuesday, July 21, 1998 - * - * Modifications: - * Robb Matzke, 1999-09-27 - * Understands the simple_output_g switch which causes data to - * be displayed in a more machine-readable format. *------------------------------------------------------------------------- */ static void @@ -1399,7 +1330,8 @@ dump_dataset_values(hid_t dset) } outputformat.cmpd_sep = " "; - if (label_g) outputformat.cmpd_name = "%s="; + if (label_g) + outputformat.cmpd_name = "%s="; outputformat.elmt_suf1 = " "; outputformat.str_locale = ESCAPE_HTML; @@ -1442,7 +1374,7 @@ dump_dataset_values(hid_t dset) * command line switch was given. */ outputformat.raw = TRUE; } - else if (string_g && 1==size && H5T_INTEGER==H5Tget_class(f_type)) { + else if (string_g && 1 == size && H5T_INTEGER == H5Tget_class(f_type)) { /* Print 1-byte integer data as an ASCI character string instead of * integers if the `-s' or `--string' command-line option was given. */ outputformat.ascii = TRUE; @@ -1475,21 +1407,14 @@ dump_dataset_values(hid_t dset) PRINTVALSTREAM(rawoutstream, "\n"); } - + /*------------------------------------------------------------------------- * Function: list_attr * * Purpose: Prints information about attributes. * * Return: Success: 0 - * - * Failure: -1 - * - * Programmer: Robb Matzke - * Friday, June 5, 1998 - * - * Modifications: - * + * Failure: -1 *------------------------------------------------------------------------- */ static herr_t @@ -1522,7 +1447,7 @@ list_attr(hid_t obj, const char *attr_name, const H5A_info_t H5_ATTR_UNUSED *ain print_string(&buffer, attr_name, TRUE); - if((attr = H5Aopen(obj, attr_name, H5P_DEFAULT))) { + if ((attr = H5Aopen(obj, attr_name, H5P_DEFAULT))) { space = H5Aget_space(attr); type = H5Aget_type(attr); @@ -1539,7 +1464,7 @@ list_attr(hid_t obj, const char *attr_name, const H5A_info_t H5_ATTR_UNUSED *ain case H5S_SIMPLE: /* simple dataspace */ h5tools_str_append(&buffer, " {"); - for (i=0; i<ndims; i++) { + for (i = 0; i < ndims; i++) { h5tools_str_append(&buffer, "%s" HSIZE_T_FORMAT, i?", ":"", size[i]); nelmts *= size[i]; } @@ -1571,7 +1496,7 @@ list_attr(hid_t obj, const char *attr_name, const H5A_info_t H5_ATTR_UNUSED *ain /* Data */ outputformat = *info; - if(nelmts < 5) { + if (nelmts < 5) { outputformat.idx_fmt = ""; outputformat.line_1st = " Data: "; outputformat.line_pre = " "; @@ -1590,10 +1515,9 @@ list_attr(hid_t obj, const char *attr_name, const H5A_info_t H5_ATTR_UNUSED *ain } outputformat.line_ncols = (unsigned)width_g; - if(label_g) + if (label_g) outputformat.cmpd_name = "%s="; - if(string_g && 1==H5Tget_size(type) && - H5T_INTEGER==H5Tget_class(type)) { + if (string_g && 1 == H5Tget_size(type) && H5T_INTEGER == H5Tget_class(type)) { outputformat.ascii = TRUE; outputformat.elmt_suf1 = ""; outputformat.elmt_suf2 = ""; @@ -1617,13 +1541,13 @@ list_attr(hid_t obj, const char *attr_name, const H5A_info_t H5_ATTR_UNUSED *ain info = &outputformat; - if(space_type != H5S_NULL && space_type != H5S_NO_CLASS) { - if(hexdump_g) + if (space_type != H5S_NULL && space_type != H5S_NO_CLASS) { + if (hexdump_g) p_type = H5Tcopy(type); else p_type = H5Tget_native_type(type, H5T_DIR_DEFAULT); - if(p_type >= 0) { + if (p_type >= 0) { /* VL data special information */ unsigned int vl_data = 0; /* contains VL datatypes */ @@ -1662,7 +1586,7 @@ list_attr(hid_t obj, const char *attr_name, const H5A_info_t H5_ATTR_UNUSED *ain return 0; } - + /*------------------------------------------------------------------------- * Function: dataset_list1 * @@ -1672,14 +1596,7 @@ list_attr(hid_t obj, const char *attr_name, const H5A_info_t H5_ATTR_UNUSED *ain * printed by the caller. * * Return: Success: 0 - * - * Failure: -1 - * - * Programmer: Robb Matzke - * Thursday, August 27, 1998 - * - * Modifications: - * + * Failure: -1 *------------------------------------------------------------------------- */ static herr_t @@ -1707,17 +1624,19 @@ dataset_list1(hid_t dset) space_type = H5Sget_simple_extent_type(space); ndims = H5Sget_simple_extent_dims(space, cur_size, max_size); h5tools_str_append(&buffer, " {"); - for (i=0; i<ndims; i++) { + for (i = 0; i < ndims; i++) { h5tools_str_append(&buffer, "%s"HSIZE_T_FORMAT, i?", ":"", cur_size[i]); if (max_size[i]==H5S_UNLIMITED) { h5tools_str_append(&buffer, "/%s", "Inf"); } - else if (max_size[i]!=cur_size[i] || verbose_g>0) { + else if (max_size[i] != cur_size[i] || verbose_g > 0) { h5tools_str_append(&buffer, "/"HSIZE_T_FORMAT, max_size[i]); } } - if (space_type==H5S_SCALAR) h5tools_str_append(&buffer, "SCALAR"); - else if (space_type==H5S_NULL) h5tools_str_append(&buffer, "NULL"); + if (space_type == H5S_SCALAR) + h5tools_str_append(&buffer, "SCALAR"); + else if (space_type == H5S_NULL) + h5tools_str_append(&buffer, "NULL"); h5tools_str_append(&buffer, "}"); h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0); H5Sclose (space); @@ -1727,7 +1646,7 @@ dataset_list1(hid_t dset) return 0; } - + /*------------------------------------------------------------------------- * Function: dataset_list2 * @@ -1735,14 +1654,7 @@ dataset_list1(hid_t dset) * information which is general to all objects. * * Return: Success: 0 - * - * Failure: -1 - * - * Programmer: Robb Matzke - * Thursday, August 27, 1998 - * - * Modifications: - * + * Failure: -1 *------------------------------------------------------------------------- */ static herr_t @@ -1778,7 +1690,7 @@ dataset_list2(hid_t dset, const char H5_ATTR_UNUSED *name) h5tools_str_reset(&buffer); - if(verbose_g > 0) { + if (verbose_g > 0) { dcpl = H5Dget_create_plist(dset); space = H5Dget_space(dset); type = H5Dget_type(dset); @@ -1792,7 +1704,7 @@ dataset_list2(hid_t dset, const char H5_ATTR_UNUSED *name) ndims = H5Pget_chunk(dcpl, (int)NELMTS(chsize), chsize/*out*/); h5tools_str_append(&buffer, " %-10s {", "Chunks:"); total = H5Tget_size(type); - for (i=0; i<ndims; i++) { + for (i = 0; i < ndims; i++) { h5tools_str_append(&buffer, "%s"HSIZE_T_FORMAT, i?", ":"", chsize[i]); total *= chsize[i]; } @@ -1803,29 +1715,25 @@ dataset_list2(hid_t dset, const char H5_ATTR_UNUSED *name) break; case H5D_CONTIGUOUS: /* Print information about external storage */ - if((nf = H5Pget_external_count(dcpl)) > 0) { - for(i = 0, max_len = 0; i < nf; i++) { - if(H5Pget_external(dcpl, (unsigned)i, sizeof(f_name), f_name, NULL, NULL) < 0) + if ((nf = H5Pget_external_count(dcpl)) > 0) { + for (i = 0, max_len = 0; i < nf; i++) { + if (H5Pget_external(dcpl, (unsigned)i, sizeof(f_name), f_name, NULL, NULL) < 0) continue; n = print_string(NULL, f_name, TRUE); max_len = MAX(max_len, n); } /* end for */ - h5tools_str_append(&buffer, " %-10s %d external file%s\n", - "Extern:", nf, 1==nf?"":"s"); - h5tools_str_append(&buffer, " %4s %10s %10s %10s %s\n", - "ID", "DSet-Addr", "File-Addr", "Bytes", "File"); - h5tools_str_append(&buffer, " %4s %10s %10s %10s ", - "----", "----------", "----------", "----------"); - for (i=0; i<max_len; i++) h5tools_str_append(&buffer, "-"); + h5tools_str_append(&buffer, " %-10s %d external file%s\n", "Extern:", nf, 1==nf?"":"s"); + h5tools_str_append(&buffer, " %4s %10s %10s %10s %s\n", "ID", "DSet-Addr", "File-Addr", "Bytes", "File"); + h5tools_str_append(&buffer, " %4s %10s %10s %10s ", "----", "----------", "----------", "----------"); + for (i = 0; i < max_len; i++) + h5tools_str_append(&buffer, "-"); h5tools_str_append(&buffer, "\n"); - for (i=0, total=0; i<nf; i++) { + for (i = 0, total=0; i < nf; i++) { if (H5Pget_external(dcpl, (unsigned)i, sizeof(f_name), f_name, &f_offset, &f_size)<0) { - h5tools_str_append(&buffer, - " #%03d %10"H5_PRINTF_LL_WIDTH"u %10s %10s ***ERROR*** %s\n", - i, total, "", "", - i+1<nf?"Following addresses are incorrect":""); + h5tools_str_append(&buffer, " #%03d %10"H5_PRINTF_LL_WIDTH"u %10s %10s ***ERROR*** %s\n", + i, total, "", "", i+1<nf?"Following addresses are incorrect":""); } - else if (H5S_UNLIMITED==f_size) { + else if (H5S_UNLIMITED == f_size) { h5tools_str_append(&buffer, " #%03d %10"H5_PRINTF_LL_WIDTH"u %10"H5_PRINTF_LL_WIDTH"u %10s ", i, total, (hsize_t)f_offset, "INF"); print_string(&buffer, f_name, TRUE); @@ -1838,9 +1746,8 @@ dataset_list2(hid_t dset, const char H5_ATTR_UNUSED *name) h5tools_str_append(&buffer, "\n"); total += f_size; } - h5tools_str_append(&buffer, " %4s %10s %10s %10s ", - "----", "----------", "----------", "----------"); - for (i=0; i<max_len; i++) + h5tools_str_append(&buffer, " %4s %10s %10s %10s ", "----", "----------", "----------", "----------"); + for (i = 0; i < max_len; i++) h5tools_str_append(&buffer, "-"); h5tools_str_append(&buffer, "\n"); } /* end if */ @@ -1882,16 +1789,13 @@ dataset_list2(hid_t dset, const char H5_ATTR_UNUSED *name) used = H5Dget_storage_size(dset); tclass = H5Tget_class(type); h5tools_str_append(&buffer, " %-10s ", "Storage:"); - switch (tclass) - { - + switch (tclass) { case H5T_VLEN: h5tools_str_append(&buffer, "information not available"); break; case H5T_REFERENCE: - if ( H5Tequal(type, H5T_STD_REF_DSETREG)) - { + if (H5Tequal(type, H5T_STD_REF_DSETREG)) { h5tools_str_append(&buffer, "information not available"); } break; @@ -1908,11 +1812,8 @@ dataset_list2(hid_t dset, const char H5_ATTR_UNUSED *name) case H5T_ARRAY: case H5T_NCLASSES: default: - h5tools_str_append(&buffer, HSIZE_T_FORMAT" logical byte%s, "HSIZE_T_FORMAT" allocated byte%s", - total, 1==total?"":"s", - used, 1==used?"":"s"); - if (used>0) - { + h5tools_str_append(&buffer, HSIZE_T_FORMAT" logical byte%s, "HSIZE_T_FORMAT" allocated byte%s", total, 1==total?"":"s", used, 1==used?"":"s"); + if (used>0) { utilization = ((double)total * (double)100.0f) / (double)used; h5tools_str_append(&buffer, ", %1.2f%% utilization", utilization); } @@ -1921,18 +1822,14 @@ dataset_list2(hid_t dset, const char H5_ATTR_UNUSED *name) h5tools_str_append(&buffer, "\n"); /* Print information about raw data filters */ - if((nf = H5Pget_nfilters(dcpl)) > 0) { - for(i = 0; i < nf; i++) { + if ((nf = H5Pget_nfilters(dcpl)) > 0) { + for (i = 0; i < nf; i++) { cd_nelmts = NELMTS(cd_values); - filt_id = H5Pget_filter2(dcpl, (unsigned)i, &filt_flags, &cd_nelmts, - cd_values, sizeof(f_name), f_name, NULL); + filt_id = H5Pget_filter2(dcpl, (unsigned)i, &filt_flags, &cd_nelmts, cd_values, sizeof(f_name), f_name, NULL); f_name[sizeof(f_name) - 1] = '\0'; HDsnprintf(s, sizeof(s), "Filter-%d:", i); - h5tools_str_append(&buffer, " %-10s %s-%u %s {", s, - (f_name[0] ? f_name : "method"), - (unsigned)filt_id, - ((filt_flags & H5Z_FLAG_OPTIONAL) ? "OPT" : "")); - for(cd_num = 0; cd_num < cd_nelmts; cd_num++) + h5tools_str_append(&buffer, " %-10s %s-%u %s {", s, (f_name[0] ? f_name : "method"), (unsigned)filt_id, ((filt_flags & H5Z_FLAG_OPTIONAL) ? "OPT" : "")); + for (cd_num = 0; cd_num < cd_nelmts; cd_num++) h5tools_str_append(&buffer, "%s%u", (cd_num ? ", " : ""), cd_values[cd_num]); h5tools_str_append(&buffer, "}\n"); } /* end for */ @@ -1945,7 +1842,7 @@ dataset_list2(hid_t dset, const char H5_ATTR_UNUSED *name) h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0); /* Print address information */ - if(address_g) + if (address_g) H5Ddebug(dset); /* Close stuff */ @@ -1956,13 +1853,13 @@ dataset_list2(hid_t dset, const char H5_ATTR_UNUSED *name) h5tools_str_close(&buffer); - if(data_g) + if (data_g) dump_dataset_values(dset); return 0; } /* end dataset_list2() */ - + /*------------------------------------------------------------------------- * Function: datatype_list2 * @@ -1970,20 +1867,13 @@ dataset_list2(hid_t dset, const char H5_ATTR_UNUSED *name) * information which is general to all objects. * * Return: Success: 0 - * - * Failure: -1 - * - * Programmer: Robb Matzke - * Thursday, November 5, 1998 - * - * Modifications: - * + * Failure: -1 *------------------------------------------------------------------------- */ static herr_t datatype_list2(hid_t type, const char H5_ATTR_UNUSED *name) { - if (verbose_g>0) { + if (verbose_g > 0) { hsize_t curr_pos = 0; /* total data element position */ h5tools_str_t buffer; /* string into which to render */ h5tools_context_t ctx; /* print context */ @@ -2004,19 +1894,14 @@ datatype_list2(hid_t type, const char H5_ATTR_UNUSED *name) return 0; } - + /*------------------------------------------------------------------------- * Function: list_obj * * Purpose: Prints information about an object * * Return: Success: 0 - * - * Failure: -1 - * - * Programmer: Quincey Koziol - * Tuesday, November 6, 2007 - * + * Failure: -1 *------------------------------------------------------------------------- */ static herr_t @@ -2035,26 +1920,26 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void h5tools_str_reset(&buffer); /* Print the link's name, either full name or base name */ - if(!iter->symlink_target) + if (!iter->symlink_target) print_obj_name(&buffer, iter, name, ""); /* Check object information */ - if(oinfo->type < 0 || oinfo->type >= H5O_TYPE_NTYPES) { + if (oinfo->type < 0 || oinfo->type >= H5O_TYPE_NTYPES) { h5tools_str_append(&buffer, "Unknown type(%d)", (int)oinfo->type); obj_type = H5O_TYPE_UNKNOWN; } - if(iter->symlink_target) + if (iter->symlink_target) h5tools_str_append(&buffer, "{"); - if(obj_type >= 0 && dispatch_g[obj_type].name) + if (obj_type >= 0 && dispatch_g[obj_type].name) h5tools_str_append(&buffer, "%s", dispatch_g[obj_type].name); h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0); /* Check if we've seen this object before */ - if(first_seen) { + if (first_seen) { h5tools_str_reset(&buffer); h5tools_str_append(&buffer, ", same as "); print_string(&buffer, first_seen, TRUE); - if(!iter->symlink_target) { + if (!iter->symlink_target) { h5tools_str_append(&buffer, "\n"); } h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0); @@ -2065,7 +1950,7 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void /* Open the object. Not all objects can be opened. If this is the case * then return right away. */ - if(obj_type >= 0 && (obj = H5Oopen(iter->fid, name, H5P_DEFAULT)) < 0) { + if (obj_type >= 0 && (obj = H5Oopen(iter->fid, name, H5P_DEFAULT)) < 0) { h5tools_str_reset(&buffer); h5tools_str_append(&buffer, " *ERROR*\n"); h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0); @@ -2073,9 +1958,9 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void } /* end if */ /* List the first line of information for the object. */ - if(obj_type >= 0 && dispatch_g[obj_type].list1) + if (obj_type >= 0 && dispatch_g[obj_type].list1) (dispatch_g[obj_type].list1)(obj); - if(!iter->symlink_target || (verbose_g > 0)) { + if (!iter->symlink_target || (verbose_g > 0)) { h5tools_str_reset(&buffer); h5tools_str_append(&buffer, "\n"); h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0); @@ -2083,13 +1968,13 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void /* Show detailed information about the object, beginning with information * which is common to all objects. */ - if(verbose_g > 0) { + if (verbose_g > 0) { size_t buf_size = 0; char* comment = NULL; ssize_t cmt_bufsize = -1; /* Display attributes */ - if(obj_type >= 0) + if (obj_type >= 0) H5Aiterate2(obj, H5_INDEX_NAME, H5_ITER_INC, NULL, list_attr, NULL); /* Object location & reference count */ @@ -2099,7 +1984,7 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0); /* Modification time */ - if(oinfo->mtime > 0) { + if (oinfo->mtime > 0) { char buf[256]; struct tm *tm; @@ -2107,7 +1992,7 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void tm = HDgmtime(&(oinfo->mtime)); else tm = HDlocaltime(&(oinfo->mtime)); - if(tm) { + if (tm) { HDstrftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", tm); h5tools_str_reset(&buffer); h5tools_str_append(&buffer, " %-10s %s\n", "Modified:", buf); @@ -2123,9 +2008,9 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void * If the call to H5Oget_comment returned an error, skip this block */ if (cmt_bufsize > 0) { comment = (char *)HDmalloc((size_t)cmt_bufsize + 1); /* new_size including null terminator */ - if(comment) { + if (comment) { cmt_bufsize = H5Oget_comment(obj, comment, (size_t)cmt_bufsize); - if(cmt_bufsize > 0) { + if (cmt_bufsize > 0) { comment[cmt_bufsize] = 0; h5tools_str_reset(&buffer); h5tools_str_append(&buffer, " %-10s \"", "Comment:"); @@ -2139,16 +2024,16 @@ list_obj(const char *name, const H5O_info_t *oinfo, const char *first_seen, void } /* end if */ /* Detailed list for object */ - if(obj_type >= 0 && dispatch_g[obj_type].list2) + if (obj_type >= 0 && dispatch_g[obj_type].list2) (dispatch_g[obj_type].list2)(obj, name); /* Close the object. */ - if(obj_type >= 0) + if (obj_type >= 0) H5Oclose(obj); } /* end else */ done: - if(iter->symlink_target) { + if (iter->symlink_target) { h5tools_str_reset(&buffer); h5tools_str_append(&buffer, "}\n"); h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0); @@ -2160,19 +2045,13 @@ done: } /* end list_obj() */ - /*------------------------------------------------------------------------- * Function: list_lnk * * Purpose: Prints information about a link * * Return: Success: 0 - * - * Failure: -1 - * - * Programmer: Quincey Koziol - * Thursday, November 8, 2007 - * + * Failure: -1 *------------------------------------------------------------------------- */ static herr_t @@ -2219,15 +2098,13 @@ list_lnk(const char *name, const H5L_info_t *linfo, void *_iter) h5tools_str_append(&buffer, buf); h5tools_str_append(&buffer, "}"); h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0); - if(follow_symlink_g) - { + if (follow_symlink_g) { hbool_t orig_grp_literal = grp_literal_g; h5tools_str_reset(&buffer); h5tools_str_append(&buffer, " "); /* Check if we have already seen this softlink */ - if(symlink_is_visited(iter->symlink_list, linfo->type, NULL, buf)) - { + if (symlink_is_visited(iter->symlink_list, linfo->type, NULL, buf)) { h5tools_str_append(&buffer, "{Already Visited}\n"); h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0); goto done; @@ -2235,7 +2112,7 @@ list_lnk(const char *name, const H5L_info_t *linfo, void *_iter) h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0); /* Add this link to the list of seen softlinks */ - if(symlink_visit_add(iter->symlink_list, linfo->type, NULL, buf) < 0) + if (symlink_visit_add(iter->symlink_list, linfo->type, NULL, buf) < 0) goto done; /* Adjust user data to specify that we are operating on the @@ -2244,11 +2121,10 @@ list_lnk(const char *name, const H5L_info_t *linfo, void *_iter) /* Prevent recursive listing of soft link target if * recursive_g is off */ - if(!recursive_g) + if (!recursive_g) grp_literal_g = TRUE; /* Recurse through the soft link */ - if(visit_obj(iter->fid, name, iter) < 0) - { + if (visit_obj(iter->fid, name, iter) < 0) { grp_literal_g = orig_grp_literal; goto done; } @@ -2280,7 +2156,7 @@ list_lnk(const char *name, const H5L_info_t *linfo, void *_iter) else if (no_dangling_link_g && ret == 0) iter->symlink_list->dangle_link = TRUE; - if(H5Lunpack_elink_val(buf, linfo->u.val_size, NULL, &filename, &path) < 0) + if (H5Lunpack_elink_val(buf, linfo->u.val_size, NULL, &filename, &path) < 0) goto done; h5tools_str_append(&buffer, "External Link {"); @@ -2288,21 +2164,19 @@ list_lnk(const char *name, const H5L_info_t *linfo, void *_iter) h5tools_str_append(&buffer, "/"); if(*path != '/') h5tools_str_append(&buffer, "/"); - h5tools_str_append(&buffer, path); + h5tools_str_append(&buffer, path); h5tools_str_append(&buffer, "}"); h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0); /* Recurse through the external link */ /* keep the follow_elink_g for backward compatibility with -E */ - if(follow_link) - { + if (follow_link) { hbool_t orig_grp_literal = grp_literal_g; h5tools_str_reset(&buffer); h5tools_str_append(&buffer, " "); /* Check if we have already seen this elink */ - if(symlink_is_visited(iter->symlink_list, linfo->type, filename, path)) - { + if (symlink_is_visited(iter->symlink_list, linfo->type, filename, path)) { h5tools_str_append(&buffer, "{Already Visited}\n"); h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0); goto done; @@ -2310,8 +2184,7 @@ list_lnk(const char *name, const H5L_info_t *linfo, void *_iter) h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0); /* Add this link to the list of seen elinks */ - if(symlink_visit_add(iter->symlink_list, linfo->type, filename, path) < 0) - { + if (symlink_visit_add(iter->symlink_list, linfo->type, filename, path) < 0) { goto done; } @@ -2321,11 +2194,11 @@ list_lnk(const char *name, const H5L_info_t *linfo, void *_iter) /* Prevent recursive listing of external link target if * recursive_g is off */ - if(!recursive_g) + if (!recursive_g) grp_literal_g = TRUE; /* Recurse through the external link */ - if(visit_obj(iter->fid, name, iter) < 0) { + if (visit_obj(iter->fid, name, iter) < 0) { grp_literal_g = orig_grp_literal; goto done; } @@ -2354,7 +2227,7 @@ done: return 0; } /* end list_lnk() */ - + /*------------------------------------------------------------------------- * Function: visit_obj * @@ -2363,11 +2236,6 @@ done: * Return: * Success: 0 * Failure: -1 - * - * Programmer: Neil Fortner - * Wednesday, August 21, 2008 - * Mostly copied from main() - * *------------------------------------------------------------------------- */ static herr_t @@ -2386,8 +2254,8 @@ visit_obj(hid_t file, const char *oname, iter_t *iter) h5tools_str_reset(&buffer); /* Retrieve info for object to list */ - if(H5Oget_info_by_name2(file, oname, &oi, H5O_INFO_BASIC|H5O_INFO_TIME, H5P_DEFAULT) < 0) { - if(iter->symlink_target) { + if (H5Oget_info_by_name2(file, oname, &oi, H5O_INFO_BASIC|H5O_INFO_TIME, H5P_DEFAULT) < 0) { + if (iter->symlink_target) { h5tools_str_append(&buffer, "{**NOT FOUND**}\n"); iter->symlink_target = FALSE; } @@ -2399,9 +2267,9 @@ visit_obj(hid_t file, const char *oname, iter_t *iter) } /* end if */ /* Check for group iteration */ - if(H5O_TYPE_GROUP == oi.type && !grp_literal_g) { + if (H5O_TYPE_GROUP == oi.type && !grp_literal_g) { /* Get ID for group */ - if(!iter->symlink_target && (iter->gid = H5Gopen2(file, oname, H5P_DEFAULT)) < 0) { + if (!iter->symlink_target && (iter->gid = H5Gopen2(file, oname, H5P_DEFAULT)) < 0) { h5tools_str_append(&buffer, "%s: unable to open '%s' as group\n", iter->fname, oname); h5tools_render_element(rawoutstream, info, &ctx, &buffer, &curr_pos, (size_t)info->line_ncols, (hsize_t)0, (hsize_t)0); goto done; /* Previously "continue", when this code was in main(). @@ -2417,7 +2285,7 @@ visit_obj(hid_t file, const char *oname, iter_t *iter) h5trav_visit(file, oname, (hbool_t) (display_root_g || iter->symlink_target), recursive_g, list_obj, list_lnk, iter, H5O_INFO_BASIC|H5O_INFO_TIME); /* Close group */ - if(!iter->symlink_target) + if (!iter->symlink_target) H5Gclose(iter->gid); } /* end if */ else { @@ -2434,7 +2302,7 @@ done: return retval; } - + /*------------------------------------------------------------------------- * Function: get_width * @@ -2444,14 +2312,7 @@ done: * were borrowed from the GNU less(1). * * Return: Success: Number of columns. - * - * Failure: Some default number of columms. - * - * Programmer: Robb Matzke - * Friday, November 6, 1998 - * - * Modifications: - * + * Failure: Some default number of columms. *------------------------------------------------------------------------- */ static int @@ -2462,7 +2323,7 @@ get_width(void) /* Try to get it from the COLUMNS environment variable first since it's * value is sometimes wrong. */ - if ((s=HDgetenv("COLUMNS")) && *s && isdigit((int)*s)) + if ((s = HDgetenv("COLUMNS")) && *s && isdigit((int)*s)) width = (int)HDstrtol(s, NULL, 0); #if defined(H5_HAVE_STRUCT_VIDEOCONFIG) && defined(H5_HAVE__GETVIDEOCONFIG) @@ -2510,7 +2371,8 @@ get_width(void) #endif /* Set to at least 1 */ - if (width<1) width = 1; + if (width < 1) + width = 1; return width; } @@ -2522,25 +2384,19 @@ get_width(void) * Return: * Success: TRUE (1) * Failure: FALSE (0) - * - * Programmer: - * Jonathan Kim (06/15/2010) - * *-------------------------------------------------------------------------*/ static hbool_t is_valid_args(void) { hbool_t ret = TRUE; - if(recursive_g && grp_literal_g) - { + if (recursive_g && grp_literal_g) { HDfprintf(rawerrorstream, "Error: 'recursive' option not compatible with 'group info' option!\n\n"); ret = FALSE; goto out; } - if(no_dangling_link_g && !follow_symlink_g) - { + if (no_dangling_link_g && !follow_symlink_g) { HDfprintf(rawerrorstream, "Error: --no-dangling-links must be used along with --follow-symlinks option!\n\n"); ret = FALSE; goto out; @@ -2550,19 +2406,13 @@ out: return ret; } - + /*------------------------------------------------------------------------- * Function: leave * * Purpose: Close HDF5 and MPI and call exit() * * Return: Does not return - * - * Programmer: Quincey Koziol - * Saturday, January 31, 2004 - * - * Modifications: - * *------------------------------------------------------------------------- */ static void @@ -2573,35 +2423,52 @@ leave(int ret) HDexit(ret); } - + /*------------------------------------------------------------------------- * Function: main * * Purpose: Opens a file and lists the specified group * * Return: Success: 0 - * - * Failure: 1 - * - * Programmer: Robb Matzke - * Monday, March 23, 1998 - * - * Modifications: - * + * Failure: 1 *------------------------------------------------------------------------- */ int main(int argc, const char *argv[]) { - hid_t file = -1; - char *fname = NULL, *oname = NULL, *x; + hid_t file = -1; + char *fname = NULL, *oname = NULL, *x; const char *s = NULL; - char *rest; - int argno; + char *rest; + int argno; static char root_name[] = "/"; char drivername[50]; const char *preferred_driver = NULL; - int err_exit = 0; + int err_exit = 0; + hid_t fapl_id = H5P_DEFAULT; + +#ifdef H5_HAVE_ROS3_VFD + /* default "anonymous" s3 configuration */ + H5FD_ros3_fapl_t ros3_fa = { + 1, /* fapl version */ + false, /* authenticate */ + "", /* aws region */ + "", /* access key id */ + "", /* secret access key */ + }; +#endif /* H5_HVAE_ROS3_VFD */ + +#ifdef H5_HAVE_LIBHDFS + /* "default" HDFS configuration */ + H5FD_hdfs_fapl_t hdfs_fa = { + 1, /* fapl version */ + "localhost", /* namenode name */ + 0, /* namenode port */ + "", /* kerberos ticket cache */ + "", /* user name */ + 2048, /* stream buffer size */ + }; +#endif /* H5_HAVE_LIBHDFS */ h5tools_setprogname(PROGRAMNAME); h5tools_setstatus(EXIT_SUCCESS); @@ -2618,90 +2485,258 @@ main(int argc, const char *argv[]) width_g = get_width(); /* Switches come before non-switch arguments */ - for(argno = 1; argno < argc && '-' == argv[argno][0]; argno++) { - if(!HDstrcmp(argv[argno], "--")) { + for (argno = 1; argno < argc && '-' == argv[argno][0]; argno++) { + if (!HDstrcmp(argv[argno], "--")) { /* Last switch */ argno++; break; - } else if(!HDstrcmp(argv[argno], "--help")) { + } + else if (!HDstrcmp(argv[argno], "--help")) { usage(); leave(EXIT_SUCCESS); - } else if(!HDstrcmp(argv[argno], "--address")) { + } + else if (!HDstrcmp(argv[argno], "--address")) { address_g = TRUE; - } else if(!HDstrcmp(argv[argno], "--data")) { + } + else if(!HDstrcmp(argv[argno], "--data")) { data_g = TRUE; - } else if(!HDstrcmp(argv[argno], "--enable-error-stack")) { + } + else if (!HDstrcmp(argv[argno], "--enable-error-stack")) { show_errors_g = TRUE; /* deprecated --errors */ - } else if(!HDstrcmp(argv[argno], "--errors")) { + } + else if (!HDstrcmp(argv[argno], "--errors")) { show_errors_g = TRUE; - } else if(!HDstrcmp(argv[argno], "--follow-symlinks")) { + } + else if (!HDstrcmp(argv[argno], "--follow-symlinks")) { follow_symlink_g = TRUE; - } else if(!HDstrcmp(argv[argno], "--no-dangling-links")) { + } + else if (!HDstrcmp(argv[argno], "--no-dangling-links")) { no_dangling_link_g = TRUE; - } else if(!HDstrcmp(argv[argno], "--external")) { + } + else if (!HDstrcmp(argv[argno], "--external")) { follow_elink_g = TRUE; - } else if(!HDstrcmp(argv[argno], "--full")) { + } + else if (!HDstrcmp(argv[argno], "--full")) { fullname_g = TRUE; - } else if(!HDstrcmp(argv[argno], "--group")) { + } + else if (!HDstrcmp(argv[argno], "--group")) { grp_literal_g = TRUE; - } else if(!HDstrcmp(argv[argno], "--label")) { + } + else if (!HDstrcmp(argv[argno], "--label")) { label_g = TRUE; - } else if(!HDstrcmp(argv[argno], "--recursive")) { + } + else if (!HDstrcmp(argv[argno], "--recursive")) { recursive_g = TRUE; fullname_g = TRUE; - } else if(!HDstrcmp(argv[argno], "--simple")) { + } + else if (!HDstrcmp(argv[argno], "--simple")) { simple_output_g = TRUE; - } else if(!HDstrcmp(argv[argno], "--string")) { + } + else if (!HDstrcmp(argv[argno], "--string")) { string_g = TRUE; - } else if(!HDstrncmp(argv[argno], "--vfd=", (size_t)6)) { + } + else if (!HDstrncmp(argv[argno], "--vfd=", (size_t)6)) { preferred_driver = argv[argno]+6; - } else if(!HDstrncmp(argv[argno], "--width=", (size_t)8)) { + } + else if (!HDstrncmp(argv[argno], "--width=", (size_t)8)) { width_g = (int)HDstrtol(argv[argno]+8, &rest, 0); - if(0 == width_g) + if (0 == width_g) no_line_wrap_g = TRUE; - else if(width_g < 0 || *rest) { + else if (width_g < 0 || *rest) { usage(); leave(EXIT_FAILURE); } - } else if(!HDstrcmp(argv[argno], "--width")) { - if((argno + 1) >= argc) { + } + else if (!HDstrcmp(argv[argno], "--width")) { + if ((argno + 1) >= argc) { usage(); leave(EXIT_FAILURE); - } else { + } + else { s = argv[++argno]; } width_g = (int)HDstrtol(s, &rest, 0); - if(width_g <= 0 || *rest) { + if (width_g <= 0 || *rest) { usage(); leave(EXIT_FAILURE); } - } else if(!HDstrcmp(argv[argno], "--verbose")) { + } + else if (!HDstrcmp(argv[argno], "--verbose")) { verbose_g++; - } else if(!HDstrcmp(argv[argno], "--version")) { + } + else if (!HDstrcmp(argv[argno], "--version")) { print_version(h5tools_getprogname()); leave(EXIT_SUCCESS); - } else if(!HDstrcmp(argv[argno], "--hexdump")) { + } + else if (!HDstrcmp(argv[argno], "--hexdump")) { hexdump_g = TRUE; - } else if(!HDstrncmp(argv[argno], "-w", (size_t)2)) { - if(argv[argno][2]) { + } + else if (!HDstrncmp(argv[argno], "-w", (size_t)2)) { + if (argv[argno][2]) { s = argv[argno] + 2; - } else if((argno + 1) >= argc) { + } + else if ((argno + 1) >= argc) { usage(); leave(EXIT_FAILURE); - } else { + } + else { s = argv[++argno]; } width_g = (int)HDstrtol(s, &rest, 0); - if(0 == width_g) + if(0 == width_g) { no_line_wrap_g = TRUE; + } else if(width_g < 0 || *rest) { usage(); leave(EXIT_FAILURE); } - } else if('-'!=argv[argno][1]) { + + } else if (!HDstrncmp(argv[argno], "--s3-cred=", (size_t)10)) { +#ifndef H5_HAVE_ROS3_VFD + HDfprintf(rawerrorstream, "Error: Read-Only S3 VFD is not enabled\n\n"); + usage(); + leave(EXIT_FAILURE); +#else + unsigned nelems = 0; + char *start = NULL; + char *s3cred_src = NULL; + char **s3cred = NULL; + char const *ccred[3]; + /* try to parse s3 credentials tuple + */ + start = strchr(argv[argno], '='); + if (start == NULL) { + HDfprintf(rawerrorstream, + "Error: Unable to parse null credentials tuple\n" + " For anonymous access, omit \"--s3-cred\" and use only \"--vfd=ros3\"\n\n"); + usage(); + leave(EXIT_FAILURE); + } + start++; + if (FAIL == parse_tuple((const char *)start, ',', &s3cred_src, &nelems, &s3cred)) { + HDfprintf(rawerrorstream, "Error: Unable to parse S3 credentials\n\n"); + usage(); + leave(EXIT_FAILURE); + } + /* sanity-check tuple count + */ + if (nelems != 3) { + HDfprintf(rawerrorstream, "Error: Invalid S3 credentials\n\n"); + usage(); + leave(EXIT_FAILURE); + } + ccred[0] = (const char *)s3cred[0]; + ccred[1] = (const char *)s3cred[1]; + ccred[2] = (const char *)s3cred[2]; + if (0 == h5tools_populate_ros3_fapl(&ros3_fa, ccred)) { + HDfprintf(rawerrorstream, "Error: Invalid S3 credentials\n\n"); + usage(); + leave(EXIT_FAILURE); + } + HDfree(s3cred); + HDfree(s3cred_src); +#endif /* H5_HAVE_ROS3_VFD */ + + } + else if (!HDstrncmp(argv[argno], "--hdfs-attrs=", (size_t)13)) { +#ifndef H5_HAVE_LIBHDFS + PRINTVALSTREAM(rawoutstream, "The HDFS VFD is not enabled.\n"); + leave(EXIT_FAILURE); +#else + /* Parse received configuration data and set fapl config struct */ + + hbool_t _debug = FALSE; + unsigned nelems = 0; + char const *start = NULL; + char *props_src = NULL; + char **props = NULL; + unsigned long k = 0; + + /* try to parse tuple + */ + if (_debug) { + HDfprintf(stderr, "configuring hdfs...\n"); + } + start = argv[argno]+13; /* should never segfault: worst case of */ + if (*start != '(') { /* null-termintor after '='. */ + + if (_debug) { + HDfprintf(stderr, " no tuple.\n"); + } + usage(); + leave(EXIT_FAILURE); + } + if (FAIL == parse_tuple((const char *)start, ',', &props_src, &nelems, &props)) { + HDfprintf(stderr, " unable to parse tuple.\n"); + usage(); + leave(EXIT_FAILURE); + } + + /* sanity-check tuple count + */ + if (nelems != 5) { + HDfprintf(stderr, " expected 5-ple, got `%d`\n", nelems); + usage(); + leave(EXIT_FAILURE); + } + if (_debug) { + HDfprintf(stderr, " got hdfs-attrs tuple: `(%s,%s,%s,%s,%s)`\n", + props[0], props[1], props[2], props[3], props[4]); + } + + /* Populate fapl configuration structure with given properties. + * WARNING: No error-checking is done on length of input strings... + * Silent overflow is possible, albeit unlikely. + */ + if (HDstrncmp(props[0], "", 1)) { + if (_debug) { + HDfprintf(stderr, " setting namenode name: %s\n", props[0]); + } + HDstrncpy(hdfs_fa.namenode_name, (const char *)props[0], HDstrlen(props[0])); + } + if (HDstrncmp(props[1], "", 1)) { + k = strtoul((const char *)props[1], NULL, 0); + if (errno == ERANGE) { + HDfprintf(stderr, " supposed port number wasn't.\n"); + leave(EXIT_FAILURE); + } + if (_debug) { + HDfprintf(stderr, " setting namenode port: %lu\n", k); + } + hdfs_fa.namenode_port = (int32_t)k; + } + if (HDstrncmp(props[2], "", 1)) { + if (_debug) { + HDfprintf(stderr, " setting kerb cache path: %s\n", props[2]); + } + HDstrncpy(hdfs_fa.kerberos_ticket_cache, (const char *)props[2], HDstrlen(props[2])); + } + if (HDstrncmp(props[3], "", 1)) { + if (_debug) { + HDfprintf(stderr, " setting username: %s\n", props[3]); + } + HDstrncpy(hdfs_fa.user_name, (const char *)props[3], HDstrlen(props[3])); + } + if (HDstrncmp(props[4], "", 1)) { + k = HDstrtoul((const char *)props[4], NULL, 0); + if (errno == ERANGE) { + HDfprintf(stderr, " supposed buffersize number wasn't.\n"); + leave(EXIT_FAILURE); + } + if (_debug) { + HDfprintf(stderr, " setting stream buffer size: %lu\n", k); + } + hdfs_fa.stream_buffer_size = (int32_t)k; + } + HDfree(props); + HDfree(props_src); +#endif /* H5_HAVE_LIBHDFS */ + + } + else if('-'!=argv[argno][1]) { /* Single-letter switches */ for(s = argv[argno] + 1; *s; s++) { switch(*s) { @@ -2771,7 +2806,9 @@ main(int argc, const char *argv[]) leave(EXIT_FAILURE); } /* end switch */ } /* end for */ - } else { + } + else { + HDfprintf(stderr, "Unknown argument: %s\n", argv[argno]); usage(); leave(EXIT_FAILURE); } @@ -2779,18 +2816,54 @@ main(int argc, const char *argv[]) /* If no arguments remain then print a usage message (instead of doing * absolutely nothing ;-) */ - if(argno >= argc) { + if (argno >= argc) { usage(); leave(EXIT_FAILURE); } /* end if */ /* Check for conflicting arguments */ - if (!is_valid_args()) - { + if (!is_valid_args()) { usage(); leave(EXIT_FAILURE); } + if (preferred_driver) { + void *conf_fa = NULL; + + if (!HDstrcmp(preferred_driver, "ros3")) { +#ifndef H5_HAVE_ROS3_VFD + HDfprintf(rawerrorstream, "Error: Read-Only S3 VFD not enabled.\n\n"); + usage(); + leave(EXIT_FAILURE); +#else + conf_fa = (void *)&ros3_fa; +#endif /* H5_HAVE_ROS3_VFD */ + + } + else if (!HDstrcmp(preferred_driver, "hdfs")) { +#ifndef H5_HAVE_LIBHDFS + PRINTVALSTREAM(rawoutstream, "The HDFS VFD is not enabled.\n"); + leave(EXIT_FAILURE); +#else + conf_fa = (void *)&hdfs_fa; +#endif /* H5_HAVE_LIBHDFS */ + } + + if (conf_fa != NULL) { + HDassert(fapl_id == H5P_DEFAULT); + fapl_id = H5Pcreate(H5P_FILE_ACCESS); + if (fapl_id < 0) { + HDfprintf(rawerrorstream, "Error: Unable to create fapl entry\n\n"); + leave(EXIT_FAILURE); + } + if (0 == h5tools_set_configured_fapl(fapl_id, preferred_driver, conf_fa)) { + HDfprintf(rawerrorstream, "Error: Unable to set fapl\n\n"); + usage(); + leave(EXIT_FAILURE); + } + } + } /* preferred_driver defined */ + /* Turn off HDF5's automatic error printing unless you're debugging h5ls */ if(!show_errors_g) H5Eset_auto2(H5E_DEFAULT, NULL, NULL); @@ -2819,11 +2892,16 @@ main(int argc, const char *argv[]) oname = NULL; file = -1; - while(fname && *fname) { - file = h5tools_fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT, preferred_driver, drivername, sizeof drivername); + while (fname && *fname) { + if (fapl_id != H5P_DEFAULT) { + file = H5Fopen(fname, H5F_ACC_RDONLY, fapl_id); + } + else { + file = h5tools_fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT, preferred_driver, drivername, sizeof drivername); + } - if(file >= 0) { - if(verbose_g) + if (file >= 0) { + if (verbose_g) PRINTSTREAM(rawoutstream, "Opened \"%s\" with %s driver.\n", fname, drivername); break; /*success*/ } /* end if */ @@ -2831,27 +2909,27 @@ main(int argc, const char *argv[]) /* Shorten the file name; lengthen the object name */ x = oname; oname = HDstrrchr(fname, '/'); - if(x) + if (x) *x = '/'; - if(!oname) + if (!oname) break; *oname = '\0'; } /* end while */ - if(file < 0) { + if (file < 0) { HDfprintf(rawerrorstream, "%s: unable to open file\n", argv[argno-1]); HDfree(fname); err_exit = 1; continue; } /* end if */ - if(oname) { + if (oname) { /* Always use absolute paths to avoid confusion, keep track of where * to begin path name output */ *oname = '/'; iter.base_len = HDstrlen(oname); iter.base_len -= oname[iter.base_len-1] == '/'; x = oname; - if(NULL == (oname = HDstrdup(oname))) { + if (NULL == (oname = HDstrdup(oname))) { HDfprintf(rawerrorstream, "memory allocation failed\n"); leave(EXIT_FAILURE); } @@ -2860,9 +2938,9 @@ main(int argc, const char *argv[]) * is displayed if it is a link or non-group object */ iter.name_start = 1; } - if(!oname || !*oname) { + if (!oname || !*oname) { oname = root_name; - if(recursive_g) + if (recursive_g) display_root_g = TRUE; iter.base_len = 0; iter.name_start = 0; @@ -2883,9 +2961,9 @@ main(int argc, const char *argv[]) symlink_list.objs = NULL; /* Check for root group as object name */ - if(HDstrcmp(oname, root_name)) { + if (HDstrcmp(oname, root_name)) { /* Check the type of link given */ - if(H5Lget_info(file, oname, &li, H5P_DEFAULT) < 0) { + if (H5Lget_info(file, oname, &li, H5P_DEFAULT) < 0) { hsize_t curr_pos = 0; /* total data element position */ h5tools_str_t buffer; /* string into which to render */ h5tools_context_t ctx; /* print context */ @@ -2904,8 +2982,8 @@ main(int argc, const char *argv[]) li.type = H5L_TYPE_HARD; /* Open the object and display it's information */ - if(li.type == H5L_TYPE_HARD) { - if(visit_obj(file, oname, &iter) < 0) + if (li.type == H5L_TYPE_HARD) { + if (visit_obj(file, oname, &iter) < 0) leave(EXIT_FAILURE); } /* end if(li.type == H5L_TYPE_HARD) */ else { @@ -2916,11 +2994,10 @@ main(int argc, const char *argv[]) } H5Fclose(file); HDfree(fname); - if(x) + if (x) HDfree(oname); - for(u=0; u < symlink_list.nused; u++) - { + for (u = 0; u < symlink_list.nused; u++) { if (symlink_list.objs[u].type == H5L_TYPE_EXTERNAL) HDfree(symlink_list.objs[u].file); @@ -2933,6 +3010,13 @@ main(int argc, const char *argv[]) err_exit = 1; } /* end while */ + if (fapl_id != H5P_DEFAULT) { + if (0 < H5Pclose(fapl_id)) { + HDfprintf(rawerrorstream, "Error: Unable to set close fapl entry\n\n"); + leave(EXIT_FAILURE); + } + } + if (err_exit) leave(EXIT_FAILURE); else diff --git a/tools/src/h5repack/h5repack.c b/tools/src/h5repack/h5repack.c index f12c3b4..24f4e6c 100644 --- a/tools/src/h5repack/h5repack.c +++ b/tools/src/h5repack/h5repack.c @@ -609,7 +609,7 @@ check_options(pack_opt_t *options) if (options->verbose) { HDprintf(" <%s> with chunk size ", name); for (k = 0; k < options->op_tbl->objs[i].chunk.rank; k++) - HDprintf("%d ", (int)options->op_tbl->objs[i].chunk.chunk_lengths[k]); + HDprintf("%d ", (int) options->op_tbl->objs[i].chunk.chunk_lengths[k]); HDprintf("\n"); } has_ck = 1; @@ -649,9 +649,7 @@ check_options(pack_opt_t *options) break; case H5Z_FILTER_SZIP: case H5Z_FILTER_DEFLATE: - HDprintf(" All with %s, parameter %d\n", - get_sfilter(filtn), - options->filter_g[k].cd_values[0]); + HDprintf(" All with %s, parameter %d\n", get_sfilter(filtn), options->filter_g[k].cd_values[0]); break; default: HDprintf(" User Defined %d\n", filtn); diff --git a/tools/src/h5repack/h5repack_copy.c b/tools/src/h5repack/h5repack_copy.c index 07defa5..398d632 100644 --- a/tools/src/h5repack/h5repack_copy.c +++ b/tools/src/h5repack/h5repack_copy.c @@ -921,10 +921,12 @@ do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, H5E_tools_g, H5E_tools_min_id_g, "H5Dcreate2 failed"); - if (options->verbose) + if (options->verbose) { HDprintf(" warning: could not create dataset <%s>. Applying original settings\n", travt->objs[i].name); - dset_out = H5Dcreate2(fidout, + } + dset_out = H5Dcreate2( + fidout, travt->objs[i].name, wtype_id, f_space_id, @@ -1127,10 +1129,11 @@ do_copy_objects(hid_t fidin, hid_t fidout, trav_table_t *travt, /* print a message that the filter was not applied * (in case there was a filter) */ - if (has_filter && apply_s == 0) + if (has_filter && apply_s == 0) { HDprintf(" <warning: filter not applied to %s. dataset smaller than %d bytes>\n", travt->objs[i].name, (int) options->min_comp); + } if (has_filter && apply_f == 0) HDprintf(" <warning: could not apply the filter to %s>\n", travt->objs[i].name); @@ -1358,7 +1361,7 @@ print_dataset_info(hid_t dcpl_id, char *objname, double ratio, int pr) { unsigned level = cd_values[0]; - sprintf(temp,"(%d)", level); + HDsprintf(temp,"(%d)", level); HDstrcat(strfilter, temp); } #endif @@ -1372,7 +1375,7 @@ print_dataset_info(hid_t dcpl_id, char *objname, double ratio, int pr) unsigned options_mask = cd_values[0]; /* from dcpl, not filt*/ unsigned ppb = cd_values[1]; - sprintf(temp,"(%d,", ppb); + HDsprintf(temp,"(%d,", ppb); HDstrcat(strfilter, temp); if (options_mask & H5_SZIP_EC_OPTION_MASK) HDstrcpy(temp, "EC) "); @@ -1412,7 +1415,7 @@ print_dataset_info(hid_t dcpl_id, char *objname, double ratio, int pr) HDstrcpy(str, "dset "); HDstrcat(str, strfilter); - sprintf(temp, " (%.3f:1)", ratio); + HDsprintf(temp, " (%.3f:1)", ratio); HDstrcat(str, temp); HDprintf(FORMAT_OBJ, str, objname); } diff --git a/tools/src/h5repack/h5repack_main.c b/tools/src/h5repack/h5repack_main.c index a146499..c94a0bd 100644 --- a/tools/src/h5repack/h5repack_main.c +++ b/tools/src/h5repack/h5repack_main.c @@ -138,7 +138,8 @@ static void usage(const char *prog) { PRINTVALSTREAM(rawoutstream, " 0: This is H5F_LIBVER_EARLIEST in H5F_libver_t struct\n"); PRINTVALSTREAM(rawoutstream, " 1: This is H5F_LIBVER_V18 in H5F_libver_t struct\n"); PRINTVALSTREAM(rawoutstream, " 2: This is H5F_LIBVER_V110 in H5F_libver_t struct\n"); - PRINTVALSTREAM(rawoutstream, " (H5F_LIBVER_LATEST is aliased to H5F_LIBVER_V110 for this release\n"); + PRINTVALSTREAM(rawoutstream, " 3: This is H5F_LIBVER_V112 in H5F_libver_t struct\n"); + PRINTVALSTREAM(rawoutstream, " (H5F_LIBVER_LATEST is aliased to H5F_LIBVER_V112 for this release\n"); PRINTVALSTREAM(rawoutstream, "\n"); PRINTVALSTREAM(rawoutstream, " FS_STRATEGY is a string indicating the file space strategy used:\n"); PRINTVALSTREAM(rawoutstream, " FSM_AGGR:\n"); diff --git a/tools/src/h5repack/h5repack_refs.c b/tools/src/h5repack/h5repack_refs.c index f5846ba..7e8951f 100644 --- a/tools/src/h5repack/h5repack_refs.c +++ b/tools/src/h5repack/h5repack_refs.c @@ -158,7 +158,7 @@ int do_copy_refobjs(hid_t fidin, if(nelmts) { buf = (hobj_ref_t *)HDmalloc((unsigned)(nelmts * msize)); if(buf==NULL) { - printf("cannot read into memory\n" ); + HDprintf("cannot read into memory\n" ); HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed"); } /* end if */ if(H5Dread(dset_in, mtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) @@ -166,7 +166,7 @@ int do_copy_refobjs(hid_t fidin, refbuf = (hobj_ref_t*) HDcalloc((unsigned)nelmts, msize); if(refbuf == NULL){ - printf("cannot allocate memory\n" ); + HDprintf("cannot allocate memory\n" ); HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDcalloc failed"); } /* end if */ for(u = 0; u < nelmts; u++) { @@ -183,8 +183,8 @@ int do_copy_refobjs(hid_t fidin, if(H5Rcreate(&refbuf[u], fidout, refname, H5R_OBJECT, (hid_t)-1) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Rcreate failed"); if(options->verbose) { - printf(FORMAT_OBJ,"dset",travt->objs[i].name ); - printf("object <%s> object reference created to <%s>\n", + HDprintf(FORMAT_OBJ,"dset",travt->objs[i].name ); + HDprintf("object <%s> object reference created to <%s>\n", travt->objs[i].name, refname); } @@ -234,7 +234,7 @@ int do_copy_refobjs(hid_t fidin, if(nelmts) { buf = (hdset_reg_ref_t *)HDmalloc((unsigned)(nelmts * msize)); if(buf == NULL) { - printf("cannot read into memory\n"); + HDprintf("cannot read into memory\n"); HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed"); } /* end if */ if(H5Dread(dset_in, mtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) @@ -246,7 +246,7 @@ int do_copy_refobjs(hid_t fidin, */ refbuf = (hdset_reg_ref_t *)HDcalloc(sizeof(hdset_reg_ref_t), (size_t)nelmts); /*init to zero */ if(refbuf == NULL) { - printf("cannot allocate memory\n"); + HDprintf("cannot allocate memory\n"); HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDcalloc failed"); } /* end if */ @@ -271,8 +271,8 @@ int do_copy_refobjs(hid_t fidin, if(H5Sclose(region_id) < 0) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "H5Sclose failed"); if(options->verbose) { - printf(FORMAT_OBJ,"dset",travt->objs[i].name ); - printf("object <%s> region reference created to <%s>\n", + HDprintf(FORMAT_OBJ,"dset",travt->objs[i].name ); + HDprintf("object <%s> region reference created to <%s>\n", travt->objs[i].name, refname); } @@ -590,7 +590,7 @@ static int copy_refs_attr(hid_t loc_in, if((is_ref || is_ref_array) && (H5R_OBJ_REF_BUF_SIZE==msize)) { buf = (hobj_ref_t *)HDmalloc((unsigned)(nelmts * msize)); if(buf == NULL) { - printf("cannot read into memory\n"); + HDprintf("cannot read into memory\n"); HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed"); } /* end if */ if(H5Aread(attr_id, mtype_id, buf) < 0) @@ -598,7 +598,7 @@ static int copy_refs_attr(hid_t loc_in, refbuf = (hobj_ref_t *)HDcalloc((unsigned)nelmts, msize); if(refbuf == NULL) { - printf("cannot allocate memory\n"); + HDprintf("cannot allocate memory\n"); HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDcalloc failed"); } /* end if */ @@ -611,7 +611,7 @@ static int copy_refs_attr(hid_t loc_in, buf = (hdset_reg_ref_t *)HDmalloc((unsigned)(nelmts * msize)); if(buf == NULL) { - printf( "cannot read into memory\n" ); + HDprintf( "cannot read into memory\n" ); HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed"); } /* end if */ if(H5Aread(attr_id, mtype_id, buf) < 0) @@ -623,7 +623,7 @@ static int copy_refs_attr(hid_t loc_in, */ refbuf = (hdset_reg_ref_t *)HDcalloc(sizeof(hdset_reg_ref_t), (size_t)nelmts); /*init to zero */ if(refbuf == NULL) { - printf( "cannot allocate memory\n" ); + HDprintf( "cannot allocate memory\n" ); HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDcalloc failed"); } /* end if */ @@ -638,7 +638,7 @@ static int copy_refs_attr(hid_t loc_in, refbuf = buf; /* reuse the read buffer for write */ if(buf == NULL) { - printf( "cannot read into memory\n" ); + HDprintf( "cannot read into memory\n" ); HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed"); } /* end if */ @@ -679,7 +679,7 @@ static int copy_refs_attr(hid_t loc_in, refbuf = buf; /* reuse the read buffer for write */ if(buf == NULL) { - printf( "cannot read into memory\n" ); + HDprintf( "cannot read into memory\n" ); HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "HDmalloc failed"); } /* end if */ diff --git a/tools/src/h5stat/h5stat.c b/tools/src/h5stat/h5stat.c index 450f731..9528d2c 100644 --- a/tools/src/h5stat/h5stat.c +++ b/tools/src/h5stat/h5stat.c @@ -74,14 +74,14 @@ typedef struct iter_t { ohdr_info_t group_ohdr_info; /* Object header information for groups */ hsize_t max_attrs; /* Maximum attributes from a group */ - unsigned long *num_small_attrs; /* Size of small attributes tracked */ + unsigned long *num_small_attrs; /* Size of small attributes tracked */ unsigned attr_nbins; /* Number of bins for attribute counts */ unsigned long *attr_bins; /* Pointer to array of bins for attribute counts */ unsigned max_dset_rank; /* Maximum rank of dataset */ unsigned long dset_rank_count[H5S_MAX_RANK]; /* Number of datasets of each rank */ hsize_t max_dset_dims; /* Maximum dimension size of dataset */ - unsigned long *small_dset_dims; /* Size of dimensions of small datasets tracked */ + unsigned long *small_dset_dims; /* Size of dimensions of small datasets tracked */ unsigned long dset_layouts[H5D_NLAYOUTS]; /* Type of storage for each dataset */ unsigned long dset_comptype[H5_NFILTERS_IMPL]; /* Number of currently implemented filters */ unsigned long dset_ntypes; /* Number of diff. dataset datatypes found */ @@ -118,6 +118,33 @@ typedef struct iter_t { } iter_t; +static const char *drivername = ""; + +#ifdef H5_HAVE_ROS3_VFD +/* default "anonymous" s3 configuration + */ +static H5FD_ros3_fapl_t ros3_fa = { + 1, /* fapl version */ + false, /* authenticate */ + "", /* aws region */ + "", /* access key id */ + "", /* secret access key */ +}; +#endif /* H5_HAVE_ROS3_VFD */ + +#ifdef H5_HAVE_LIBHDFS +/* default HDFS access configuration + */ +static H5FD_hdfs_fapl_t hdfs_fa = { + 1, /* fapl version */ + "localhost", /* namenode name */ + 0, /* namenode port */ + "", /* kerberos ticket cache */ + "", /* user name */ + 2048, /* stream buffer size */ +}; +#endif /* H5_HAVE_LIBHDFS */ + static int display_all = TRUE; /* Enable the printing of selected statistics */ @@ -146,7 +173,7 @@ struct handler_t { char **obj; }; -static const char *s_opts ="Aa:Ddm:EFfhGgl:sSTO:V"; +static const char *s_opts ="Aa:Ddm:EFfhGgl:sSTO:Vw:"; /* e.g. "filemetadata" has to precede "file"; "groupmetadata" has to precede "group" etc. */ static struct long_options l_opts[] = { {"help", no_arg, 'h'}, @@ -246,6 +273,8 @@ static struct long_options l_opts[] = { { "summ", no_arg, 'S' }, { "sum", no_arg, 'S' }, { "su", no_arg, 'S' }, + { "s3-cred", require_arg, 'w' }, + { "hdfs-attrs", require_arg, 'H' }, { NULL, 0, '\0' } }; @@ -257,7 +286,7 @@ leave(int ret) } - + /*------------------------------------------------------------------------- * Function: usage * @@ -295,9 +324,19 @@ static void usage(const char *prog) HDfprintf(stdout, " -s, --freespace Print free space information\n"); HDfprintf(stdout, " -S, --summary Print summary of file space information\n"); HDfprintf(stdout, " --enable-error-stack Prints messages from the HDF5 error stack as they occur\n"); + HDfprintf(stdout, " --s3-cred=<cred> Access file on S3, using provided credential\n"); + HDfprintf(stdout, " <cred> :: (region,id,key)\n"); + HDfprintf(stdout, " If <cred> == \"(,,)\", no authentication is used.\n"); + HDfprintf(stdout, " --hdfs-attrs=<attrs> Access a file on HDFS with given configuration\n"); + HDfprintf(stdout, " attributes.\n"); + HDfprintf(stdout, " <attrs> :: (<namenode name>,<namenode port>,\n"); + HDfprintf(stdout, " <kerberos cache path>,<username>,\n"); + HDfprintf(stdout, " <buffer size>)\n"); + HDfprintf(stdout, " If an attribute is empty, a default value will be\n"); + HDfprintf(stdout, " used.\n"); } - + /*------------------------------------------------------------------------- * Function: ceil_log10 * @@ -324,7 +363,7 @@ ceil_log10(unsigned long x) return ret; } /* ceil_log10() */ - + /*------------------------------------------------------------------------- * Function: attribute_stats * @@ -357,12 +396,12 @@ attribute_stats(iter_t *iter, const H5O_info_t *oi) /* Add attribute count to proper bin */ bin = ceil_log10((unsigned long)oi->num_attrs); if((bin + 1) > iter->attr_nbins) { - iter->attr_bins = (unsigned long *)HDrealloc(iter->attr_bins, (bin + 1) * sizeof(unsigned long)); + iter->attr_bins = (unsigned long *)HDrealloc(iter->attr_bins, (bin + 1) * sizeof(unsigned long)); HDassert(iter->attr_bins); /* Initialize counts for intermediate bins */ while(iter->attr_nbins < bin) - iter->attr_bins[iter->attr_nbins++] = 0; + iter->attr_bins[iter->attr_nbins++] = 0; iter->attr_nbins++; /* Initialize count for new bin */ @@ -374,7 +413,7 @@ attribute_stats(iter_t *iter, const H5O_info_t *oi) return 0; } /* end attribute_stats() */ - + /*------------------------------------------------------------------------- * Function: group_stats * @@ -456,7 +495,7 @@ done: return ret_value; } /* end group_stats() */ - + /*------------------------------------------------------------------------- * Function: dataset_stats * @@ -509,6 +548,7 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi) HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "attribute_stats() failed"); /* Get storage info */ + /* Failure 0 indistinguishable from no-data-stored 0 */ storage = H5Dget_storage_size(did); /* Gather layout statistics */ @@ -534,7 +574,8 @@ dataset_stats(iter_t *iter, const char *name, const H5O_info_t *oi) if(num_ext) { iter->nexternal += (unsigned long)num_ext; iter->dset_external_storage_size += (unsigned long)storage; - } else + } + else iter->dset_storage_size += storage; /* Gather dataspace statistics */ @@ -647,7 +688,7 @@ done: return ret_value; } /* end dataset_stats() */ - + /*------------------------------------------------------------------------- * Function: datatype_stats * @@ -679,7 +720,7 @@ done: return ret_value; } /* end datatype_stats() */ - + /*------------------------------------------------------------------------- * Function: obj_stats * @@ -722,6 +763,7 @@ obj_stats(const char *path, const H5O_info_t *oi, const char *already_visited, HGOTO_ERROR(FAIL, H5E_tools_min_id_g, "datatype_stats failed"); break; + case H5O_TYPE_MAP: case H5O_TYPE_UNKNOWN: case H5O_TYPE_NTYPES: default: @@ -735,7 +777,7 @@ done: return ret_value; } /* end obj_stats() */ - + /*------------------------------------------------------------------------- * Function: lnk_stats * @@ -833,7 +875,7 @@ freespace_stats(hid_t fid, iter_t *iter) return 0; } /* end freespace_stats() */ - + /*------------------------------------------------------------------------- * Function: hand_free * @@ -862,7 +904,7 @@ hand_free(struct handler_t *hand) } /* end if */ } /* end hand_free() */ - + /*------------------------------------------------------------------------- * Function: parse_command_line * @@ -930,7 +972,8 @@ parse_command_line(int argc, const char *argv[], struct handler_t **hand_ret) error_msg("Invalid threshold for small groups\n"); goto error; } - } else + } + else error_msg("Missing threshold for small groups\n"); break; @@ -952,7 +995,8 @@ parse_command_line(int argc, const char *argv[], struct handler_t **hand_ret) error_msg("Invalid threshold for small datasets\n"); goto error; } - } else + } + else error_msg("Missing threshold for small datasets\n"); break; @@ -974,7 +1018,8 @@ parse_command_line(int argc, const char *argv[], struct handler_t **hand_ret) error_msg("Invalid threshold for small # of attributes\n"); goto error; } - } else + } + else error_msg("Missing threshold for small # of attributes\n"); break; @@ -1014,6 +1059,105 @@ parse_command_line(int argc, const char *argv[], struct handler_t **hand_ret) } /* end if */ break; + case 'w': +#ifndef H5_HAVE_ROS3_VFD + error_msg("Read-Only S3 VFD not enabled.\n"); + goto error; +#else + { + char *cred_str = NULL; + unsigned nelems = 0; + char **cred = NULL; + char const *ccred[3]; + + if (FAIL == parse_tuple((const char *)opt_arg, ',', &cred_str, &nelems, &cred)) { + error_msg("Unable to parse s3 credential\n"); + goto error; + } + if (nelems != 3) { + error_msg("s3 credential must have three elements\n"); + goto error; + } + ccred[0] = (const char *)cred[0]; + ccred[1] = (const char *)cred[1]; + ccred[2] = (const char *)cred[2]; + if (0 == h5tools_populate_ros3_fapl(&ros3_fa, ccred)) { + error_msg("Unable to set ros3 fapl config\n"); + goto error; + } + HDfree(cred); + HDfree(cred_str); + } /* parse s3-cred block */ + drivername = "ros3"; + break; +#endif /* H5_HAVE_ROS3_VFD */ + + case 'H': +#ifndef H5_HAVE_LIBHDFS + error_msg("HDFS VFD is not enabled.\n"); + goto error; +#else + { + unsigned nelems = 0; + char *props_src = NULL; + char **props = NULL; + unsigned long k = 0; + if (FAIL == parse_tuple((const char *)opt_arg, + ',', &props_src, &nelems, &props)) { + error_msg("unable to parse hdfs properties tuple\n"); + goto error; + } + /* sanity-check tuple count + */ + if (nelems != 5) { + char str[64] = ""; + HDsprintf(str, + "expected 5 elements in hdfs properties tuple " + "but found %u\n", + nelems); + HDfree(props); + HDfree(props_src); + error_msg(str); + goto error; + } + /* Populate fapl configuration structure with given + * properties. + * TODO/WARNING: No error-checking is done on length of + * input strings... Silent overflow is possible, + * albeit unlikely. + */ + if (HDstrncmp(props[0], "", 1)) { + HDstrncpy(hdfs_fa.namenode_name,(const char *)props[0], HDstrlen(props[0])); + } + if (HDstrncmp(props[1], "", 1)) { + k = strtoul((const char *)props[1], NULL, 0); + if (errno == ERANGE) { + error_msg("supposed port number wasn't.\n"); + goto error; + } + hdfs_fa.namenode_port = (int32_t)k; + } + if (HDstrncmp(props[2], "", 1)) { + HDstrncpy(hdfs_fa.kerberos_ticket_cache, (const char *)props[2], HDstrlen(props[2])); + } + if (HDstrncmp(props[3], "", 1)) { + HDstrncpy(hdfs_fa.user_name, (const char *)props[3], HDstrlen(props[3])); + } + if (strncmp(props[4], "", 1)) { + k = HDstrtoul((const char *)props[4], NULL, 0); + if (errno == ERANGE) { + error_msg("supposed buffersize number wasn't.\n"); + goto error; + } + hdfs_fa.stream_buffer_size = (int32_t)k; + } + HDfree(props); + HDfree(props_src); + drivername = "hdfs"; + } + break; +#endif /* H5_HAVE_LIBHDFS */ + default: usage(h5tools_getprogname()); goto error; @@ -1040,7 +1184,7 @@ error: return -1; } - + /*------------------------------------------------------------------------- * Function: iter_free * @@ -1105,7 +1249,7 @@ iter_free(iter_t *iter) } /* end if */ } /* end iter_free() */ - + /*------------------------------------------------------------------------- * Function: print_file_info * @@ -1125,19 +1269,19 @@ iter_free(iter_t *iter) static herr_t print_file_info(const iter_t *iter) { - printf("File information\n"); - printf("\t# of unique groups: %lu\n", iter->uniq_groups); - printf("\t# of unique datasets: %lu\n", iter->uniq_dsets); - printf("\t# of unique named datatypes: %lu\n", iter->uniq_dtypes); - printf("\t# of unique links: %lu\n", iter->uniq_links); - printf("\t# of unique other: %lu\n", iter->uniq_others); - printf("\tMax. # of links to object: %lu\n", iter->max_links); + HDprintf("File information\n"); + HDprintf("\t# of unique groups: %lu\n", iter->uniq_groups); + HDprintf("\t# of unique datasets: %lu\n", iter->uniq_dsets); + HDprintf("\t# of unique named datatypes: %lu\n", iter->uniq_dtypes); + HDprintf("\t# of unique links: %lu\n", iter->uniq_links); + HDprintf("\t# of unique other: %lu\n", iter->uniq_others); + HDprintf("\tMax. # of links to object: %lu\n", iter->max_links); HDfprintf(stdout, "\tMax. # of objects in group: %Hu\n", iter->max_fanout); return 0; } /* print_file_info() */ - + /*------------------------------------------------------------------------- * Function: print_file_metadata * @@ -1161,15 +1305,12 @@ print_file_metadata(const iter_t *iter) HDfprintf(stdout, "\tUser block: %Hu\n", iter->ublk_size); HDfprintf(stdout, "\tObject headers: (total/unused)\n"); - HDfprintf(stdout, "\t\tGroups: %Hu/%Hu\n", - iter->group_ohdr_info.total_size, - iter->group_ohdr_info.free_size); + HDfprintf(stdout, "\t\tGroups: %Hu/%Hu\n", iter->group_ohdr_info.total_size, + iter->group_ohdr_info.free_size); HDfprintf(stdout, "\t\tDatasets(exclude compact data): %Hu/%Hu\n", - iter->dset_ohdr_info.total_size, - iter->dset_ohdr_info.free_size); - HDfprintf(stdout, "\t\tDatatypes: %Hu/%Hu\n", - iter->dtype_ohdr_info.total_size, - iter->dtype_ohdr_info.free_size); + iter->dset_ohdr_info.total_size, iter->dset_ohdr_info.free_size); + HDfprintf(stdout, "\t\tDatatypes: %Hu/%Hu\n", iter->dtype_ohdr_info.total_size, + iter->dtype_ohdr_info.free_size); HDfprintf(stdout, "\tGroups:\n"); HDfprintf(stdout, "\t\tB-tree/List: %Hu\n", iter->groups_btree_storage_size); @@ -1197,7 +1338,7 @@ print_file_metadata(const iter_t *iter) return 0; } /* print_file_metadata() */ - + /*------------------------------------------------------------------------- * Function: print_group_info * @@ -1224,37 +1365,37 @@ print_group_info(const iter_t *iter) unsigned long total; /* Total count for various statistics */ unsigned u; /* Local index variable */ - printf("Small groups (with 0 to %u links):\n", sgroups_threshold-1); + HDprintf("Small groups (with 0 to %u links):\n", sgroups_threshold-1); total = 0; for(u = 0; u < (unsigned)sgroups_threshold; u++) { if(iter->num_small_groups[u] > 0) { - printf("\t# of groups with %u link(s): %lu\n", u, iter->num_small_groups[u]); + HDprintf("\t# of groups with %u link(s): %lu\n", u, iter->num_small_groups[u]); total += iter->num_small_groups[u]; } /* end if */ } /* end for */ - printf("\tTotal # of small groups: %lu\n", total); + HDprintf("\tTotal # of small groups: %lu\n", total); - printf("Group bins:\n"); + HDprintf("Group bins:\n"); total = 0; if((iter->group_nbins > 0) && (iter->group_bins[0] > 0)) { - printf("\t# of groups with 0 link: %lu\n", iter->group_bins[0]); + HDprintf("\t# of groups with 0 link: %lu\n", iter->group_bins[0]); total = iter->group_bins[0]; } /* end if */ power = 1; for(u = 1; u < iter->group_nbins; u++) { if(iter->group_bins[u] > 0) { - printf("\t# of groups with %lu - %lu links: %lu\n", power, (power * 10) - 1, + HDprintf("\t# of groups with %lu - %lu links: %lu\n", power, (power * 10) - 1, iter->group_bins[u]); total += iter->group_bins[u]; } /* end if */ power *= 10; } /* end for */ - printf("\tTotal # of groups: %lu\n", total); + HDprintf("\tTotal # of groups: %lu\n", total); return 0; } /* print_group_info() */ - + /*------------------------------------------------------------------------- * Function: print_group_metadata * @@ -1270,7 +1411,7 @@ print_group_info(const iter_t *iter) static herr_t print_group_metadata(const iter_t *iter) { - printf("File space information for groups' metadata (in bytes):\n"); + HDprintf("File space information for groups' metadata (in bytes):\n"); HDfprintf(stdout, "\tObject headers (total/unused): %Hu/%Hu\n", iter->group_ohdr_info.total_size, iter->group_ohdr_info.free_size); @@ -1281,7 +1422,7 @@ print_group_metadata(const iter_t *iter) return 0; } /* print_group_metadata() */ - + /*------------------------------------------------------------------------- * Function: print_dataset_info * @@ -1303,72 +1444,72 @@ print_dataset_info(const iter_t *iter) unsigned u; /* Local index variable */ if(iter->uniq_dsets > 0) { - printf("Dataset dimension information:\n"); - printf("\tMax. rank of datasets: %u\n", iter->max_dset_rank); - printf("\tDataset ranks:\n"); + HDprintf("Dataset dimension information:\n"); + HDprintf("\tMax. rank of datasets: %u\n", iter->max_dset_rank); + HDprintf("\tDataset ranks:\n"); for(u = 0; u < H5S_MAX_RANK; u++) if(iter->dset_rank_count[u] > 0) - printf("\t\t# of dataset with rank %u: %lu\n", u, iter->dset_rank_count[u]); + HDprintf("\t\t# of dataset with rank %u: %lu\n", u, iter->dset_rank_count[u]); - printf("1-D Dataset information:\n"); + HDprintf("1-D Dataset information:\n"); HDfprintf(stdout, "\tMax. dimension size of 1-D datasets: %Hu\n", iter->max_dset_dims); - printf("\tSmall 1-D datasets (with dimension sizes 0 to %u):\n", sdsets_threshold - 1); + HDprintf("\tSmall 1-D datasets (with dimension sizes 0 to %u):\n", sdsets_threshold - 1); total = 0; for(u = 0; u < (unsigned)sdsets_threshold; u++) { if(iter->small_dset_dims[u] > 0) { - printf("\t\t# of datasets with dimension sizes %u: %lu\n", u, + HDprintf("\t\t# of datasets with dimension sizes %u: %lu\n", u, iter->small_dset_dims[u]); total += iter->small_dset_dims[u]; } /* end if */ } /* end for */ - printf("\t\tTotal # of small datasets: %lu\n", total); + HDprintf("\t\tTotal # of small datasets: %lu\n", total); /* Protect against no datasets in file */ if(iter->dset_dim_nbins > 0) { - printf("\t1-D Dataset dimension bins:\n"); + HDprintf("\t1-D Dataset dimension bins:\n"); total = 0; if(iter->dset_dim_bins[0] > 0) { - printf("\t\t# of datasets with dimension size 0: %lu\n", iter->dset_dim_bins[0]); + HDprintf("\t\t# of datasets with dimension size 0: %lu\n", iter->dset_dim_bins[0]); total = iter->dset_dim_bins[0]; } /* end if */ power = 1; for(u = 1; u < iter->dset_dim_nbins; u++) { if(iter->dset_dim_bins[u] > 0) { - printf("\t\t# of datasets with dimension size %lu - %lu: %lu\n", power, (power * 10) - 1, + HDprintf("\t\t# of datasets with dimension size %lu - %lu: %lu\n", power, (power * 10) - 1, iter->dset_dim_bins[u]); total += iter->dset_dim_bins[u]; } /* end if */ power *= 10; } /* end for */ - printf("\t\tTotal # of datasets: %lu\n", total); + HDprintf("\t\tTotal # of datasets: %lu\n", total); } /* end if */ - printf("Dataset storage information:\n"); + HDprintf("Dataset storage information:\n"); HDfprintf(stdout, "\tTotal raw data size: %Hu\n", iter->dset_storage_size); HDfprintf(stdout, "\tTotal external raw data size: %Hu\n", iter->dset_external_storage_size); - printf("Dataset layout information:\n"); + HDprintf("Dataset layout information:\n"); for(u = 0; u < H5D_NLAYOUTS; u++) - printf("\tDataset layout counts[%s]: %lu\n", (u == H5D_COMPACT ? "COMPACT" : + HDprintf("\tDataset layout counts[%s]: %lu\n", (u == H5D_COMPACT ? "COMPACT" : (u == H5D_CONTIGUOUS ? "CONTIG" : (u == H5D_CHUNKED ? "CHUNKED" : "VIRTUAL"))), iter->dset_layouts[u]); - printf("\tNumber of external files : %lu\n", iter->nexternal); - - printf("Dataset filters information:\n"); - printf("\tNumber of datasets with:\n"); - printf("\t\tNO filter: %lu\n", iter->dset_comptype[H5Z_FILTER_ERROR+1]); - printf("\t\tGZIP filter: %lu\n", iter->dset_comptype[H5Z_FILTER_DEFLATE]); - printf("\t\tSHUFFLE filter: %lu\n", iter->dset_comptype[H5Z_FILTER_SHUFFLE]); - printf("\t\tFLETCHER32 filter: %lu\n", iter->dset_comptype[H5Z_FILTER_FLETCHER32]); - printf("\t\tSZIP filter: %lu\n", iter->dset_comptype[H5Z_FILTER_SZIP]); - printf("\t\tNBIT filter: %lu\n", iter->dset_comptype[H5Z_FILTER_NBIT]); - printf("\t\tSCALEOFFSET filter: %lu\n", iter->dset_comptype[H5Z_FILTER_SCALEOFFSET]); - printf("\t\tUSER-DEFINED filter: %lu\n", iter->dset_comptype[H5_NFILTERS_IMPL-1]); + HDprintf("\tNumber of external files : %lu\n", iter->nexternal); + + HDprintf("Dataset filters information:\n"); + HDprintf("\tNumber of datasets with:\n"); + HDprintf("\t\tNO filter: %lu\n", iter->dset_comptype[H5Z_FILTER_ERROR+1]); + HDprintf("\t\tGZIP filter: %lu\n", iter->dset_comptype[H5Z_FILTER_DEFLATE]); + HDprintf("\t\tSHUFFLE filter: %lu\n", iter->dset_comptype[H5Z_FILTER_SHUFFLE]); + HDprintf("\t\tFLETCHER32 filter: %lu\n", iter->dset_comptype[H5Z_FILTER_FLETCHER32]); + HDprintf("\t\tSZIP filter: %lu\n", iter->dset_comptype[H5Z_FILTER_SZIP]); + HDprintf("\t\tNBIT filter: %lu\n", iter->dset_comptype[H5Z_FILTER_NBIT]); + HDprintf("\t\tSCALEOFFSET filter: %lu\n", iter->dset_comptype[H5Z_FILTER_SCALEOFFSET]); + HDprintf("\t\tUSER-DEFINED filter: %lu\n", iter->dset_comptype[H5_NFILTERS_IMPL-1]); } /* end if */ return 0; } /* print_dataset_info() */ - + /*------------------------------------------------------------------------- * Function: print_dataset_metadata * @@ -1385,7 +1526,7 @@ print_dataset_info(const iter_t *iter) static herr_t print_dset_metadata(const iter_t *iter) { - printf("File space information for datasets' metadata (in bytes):\n"); + HDprintf("File space information for datasets' metadata (in bytes):\n"); HDfprintf(stdout, "\tObject headers (total/unused): %Hu/%Hu\n", iter->dset_ohdr_info.total_size, iter->dset_ohdr_info.free_size); @@ -1397,7 +1538,7 @@ print_dset_metadata(const iter_t *iter) return 0; } /* print_dset_metadata() */ - + /*------------------------------------------------------------------------- * Function: print_dset_dtype_meta * @@ -1419,26 +1560,26 @@ print_dset_dtype_meta(const iter_t *iter) unsigned u; /* Local index variable */ if(iter->dset_ntypes) { - printf("Dataset datatype information:\n"); - printf("\t# of unique datatypes used by datasets: %lu\n", iter->dset_ntypes); + HDprintf("Dataset datatype information:\n"); + HDprintf("\t# of unique datatypes used by datasets: %lu\n", iter->dset_ntypes); total = 0; for(u = 0; u < iter->dset_ntypes; u++) { H5Tencode(iter->dset_type_info[u].tid, NULL, &dtype_size); - printf("\tDataset datatype #%u:\n", u); - printf("\t\tCount (total/named) = (%lu/%lu)\n", + HDprintf("\tDataset datatype #%u:\n", u); + HDprintf("\t\tCount (total/named) = (%lu/%lu)\n", iter->dset_type_info[u].count, iter->dset_type_info[u].named); - printf("\t\tSize (desc./elmt) = (%lu/%lu)\n", (unsigned long)dtype_size, + HDprintf("\t\tSize (desc./elmt) = (%lu/%lu)\n", (unsigned long)dtype_size, (unsigned long)H5Tget_size(iter->dset_type_info[u].tid)); H5Tclose(iter->dset_type_info[u].tid); total += iter->dset_type_info[u].count; } /* end for */ - printf("\tTotal dataset datatype count: %lu\n", total); + HDprintf("\tTotal dataset datatype count: %lu\n", total); } /* end if */ return 0; } /* print_dset_dtype_meta() */ - + /*------------------------------------------------------------------------- * Function: print_attr_info * @@ -1460,34 +1601,34 @@ print_attr_info(const iter_t *iter) unsigned long total; /* Total count for various statistics */ unsigned u; /* Local index variable */ - printf("Small # of attributes (objects with 1 to %u attributes):\n", sattrs_threshold); + HDprintf("Small # of attributes (objects with 1 to %u attributes):\n", sattrs_threshold); total = 0; for(u = 1; u <= (unsigned)sattrs_threshold; u++) { if(iter->num_small_attrs[u] > 0) { - printf("\t# of objects with %u attributes: %lu\n", u, iter->num_small_attrs[u]); + HDprintf("\t# of objects with %u attributes: %lu\n", u, iter->num_small_attrs[u]); total += iter->num_small_attrs[u]; } /* end if */ } /* end for */ - printf("\tTotal # of objects with small # of attributes: %lu\n", total); + HDprintf("\tTotal # of objects with small # of attributes: %lu\n", total); - printf("Attribute bins:\n"); + HDprintf("Attribute bins:\n"); total = 0; power = 1; for(u = 1; u < iter->attr_nbins; u++) { if(iter->attr_bins[u] > 0) { - printf("\t# of objects with %lu - %lu attributes: %lu\n", power, (power * 10) - 1, + HDprintf("\t# of objects with %lu - %lu attributes: %lu\n", power, (power * 10) - 1, iter->attr_bins[u]); total += iter->attr_bins[u]; } /* end if */ power *= 10; } /* end for */ - printf("\tTotal # of objects with attributes: %lu\n", total); - printf("\tMax. # of attributes to objects: %lu\n", (unsigned long)iter->max_attrs); + HDprintf("\tTotal # of objects with attributes: %lu\n", total); + HDprintf("\tMax. # of attributes to objects: %lu\n", (unsigned long)iter->max_attrs); return 0; } /* print_attr_info() */ - + /*------------------------------------------------------------------------- * Function: print_freespace_info * @@ -1510,34 +1651,34 @@ print_freespace_info(const iter_t *iter) HDfprintf(stdout, "Free-space persist: %s\n", iter->fs_persist ? "TRUE" : "FALSE"); HDfprintf(stdout, "Free-space section threshold: %Hu bytes\n", iter->fs_threshold); - printf("Small size free-space sections (< %u bytes):\n", (unsigned)SIZE_SMALL_SECTS); + HDprintf("Small size free-space sections (< %u bytes):\n", (unsigned)SIZE_SMALL_SECTS); total = 0; for(u = 0; u < SIZE_SMALL_SECTS; u++) { if(iter->num_small_sects[u] > 0) { - printf("\t# of sections of size %u: %lu\n", u, iter->num_small_sects[u]); + HDprintf("\t# of sections of size %u: %lu\n", u, iter->num_small_sects[u]); total += iter->num_small_sects[u]; } /* end if */ } /* end for */ - printf("\tTotal # of small size sections: %lu\n", total); + HDprintf("\tTotal # of small size sections: %lu\n", total); - printf("Free-space section bins:\n"); + HDprintf("Free-space section bins:\n"); total = 0; power = 1; for(u = 1; u < iter->sect_nbins; u++) { if(iter->sect_bins[u] > 0) { - printf("\t# of sections of size %lu - %lu: %lu\n", power, (power * 10) - 1, + HDprintf("\t# of sections of size %lu - %lu: %lu\n", power, (power * 10) - 1, iter->sect_bins[u]); total += iter->sect_bins[u]; } /* end if */ power *= 10; } /* end for */ - printf("\tTotal # of sections: %lu\n", total); + HDprintf("\tTotal # of sections: %lu\n", total); return 0; } /* print_freespace_info() */ - + /*------------------------------------------------------------------------- * Function: print_storage_summary * @@ -1560,7 +1701,7 @@ print_storage_summary(const iter_t *iter) HDfprintf(stdout, "File space management strategy: %s\n", FS_STRATEGY_NAME[iter->fs_strategy]); HDfprintf(stdout, "File space page size: %Hu bytes\n", iter->fsp_size); - printf("Summary of file space information:\n"); + HDprintf("Summary of file space information:\n"); total_meta = iter->super_size + iter->super_ext_size + iter->ublk_size + iter->group_ohdr_info.total_size + @@ -1601,7 +1742,7 @@ print_storage_summary(const iter_t *iter) return 0; } /* print_storage_summary() */ - + /*------------------------------------------------------------------------- * Function: print_file_statistics * @@ -1648,7 +1789,7 @@ print_file_statistics(const iter_t *iter) if(display_summary) print_storage_summary(iter); } /* print_file_statistics() */ - + /*------------------------------------------------------------------------- * Function: print_object_statistics * @@ -1668,10 +1809,10 @@ print_file_statistics(const iter_t *iter) static void print_object_statistics(const char *name) { - printf("Object name %s\n", name); + HDprintf("Object name %s\n", name); } /* print_object_statistics() */ - + /*------------------------------------------------------------------------- * Function: print_statistics * @@ -1697,7 +1838,7 @@ print_statistics(const char *name, const iter_t *iter) print_file_statistics(iter); } /* print_statistics() */ - + /*------------------------------------------------------------------------- * Function: main * @@ -1718,6 +1859,7 @@ main(int argc, const char *argv[]) void *edata; void *tools_edata; struct handler_t *hand = NULL; + hid_t fapl_id = H5P_DEFAULT; h5tools_setprogname(PROGRAMNAME); h5tools_setstatus(EXIT_SUCCESS); @@ -1738,6 +1880,42 @@ main(int argc, const char *argv[]) if(parse_command_line(argc, argv, &hand) < 0) goto done; + /* if drivername is not null, probably need to set the fapl */ + if (HDstrcmp(drivername, "")) { + void *conf_fa = NULL; + + if (!HDstrcmp(drivername, "ros3")) { +#ifndef H5_HAVE_ROS3_VFD + error_msg("Read-Only S3 VFD not enabled.\n\n"); + goto done; +#else + conf_fa = (void *)&ros3_fa; +#endif /* H5_HAVE_ROS3_VFD */ + + } + else if (!HDstrcmp(drivername, "hdfs")) { +#ifndef H5_HAVE_LIBHDFS + error_msg("HDFS VFD not enabled.\n\n"); + goto done; +#else + conf_fa = (void *)&hdfs_fa; +#endif /* H5_HAVE_LIBHDFS */ + } + + if (conf_fa != NULL) { + HDassert(fapl_id == H5P_DEFAULT); + fapl_id = H5Pcreate(H5P_FILE_ACCESS); + if (fapl_id < 0) { + error_msg("Unable to create fapl entry\n"); + goto done; + } + if (1 > h5tools_set_configured_fapl(fapl_id, drivername, conf_fa)) { + error_msg("Unable to set fapl\n"); + goto done; + } + } + } /* drivername set */ + fname = argv[opt_ind]; if(enable_error_stack > 0) { @@ -1750,9 +1928,9 @@ main(int argc, const char *argv[]) hid_t fcpl; H5F_info2_t finfo; - printf("Filename: %s\n", fname); + HDprintf("Filename: %s\n", fname); - fid = H5Fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT); + fid = H5Fopen(fname, H5F_ACC_RDONLY, fapl_id); if(fid < 0) { error_msg("unable to open file \"%s\"\n", fname); h5tools_setstatus(EXIT_FAILURE); @@ -1785,7 +1963,7 @@ main(int argc, const char *argv[]) if(iter.num_small_groups == NULL || iter.num_small_attrs == NULL || iter.small_dset_dims == NULL) { error_msg("Unable to allocate memory for tracking small groups/datasets/attributes\n"); - h5tools_setstatus(EXIT_FAILURE); + h5tools_setstatus(EXIT_FAILURE); goto done; } @@ -1814,7 +1992,8 @@ main(int argc, const char *argv[]) if(h5trav_visit(fid, hand->obj[u], TRUE, TRUE, obj_stats, lnk_stats, &iter, H5O_INFO_ALL) < 0) { error_msg("unable to traverse object \"%s\"\n", hand->obj[u]); h5tools_setstatus(EXIT_FAILURE); - } else + } + else print_statistics(hand->obj[u], &iter); } /* end for */ } /* end if */ @@ -1822,7 +2001,8 @@ main(int argc, const char *argv[]) if(h5trav_visit(fid, "/", TRUE, TRUE, obj_stats, lnk_stats, &iter, H5O_INFO_ALL) < 0) { error_msg("unable to traverse objects/links in file \"%s\"\n", fname); h5tools_setstatus(EXIT_FAILURE); - } else + } + else print_statistics("/", &iter); } /* end else */ } /* end if */ @@ -1833,6 +2013,13 @@ done: /* Free iter structure */ iter_free(&iter); + if (fapl_id != H5P_DEFAULT) { + if (0 < H5Pclose(fapl_id)) { + error_msg("unable to close fapl entry\n"); + h5tools_setstatus(EXIT_FAILURE); + } + } + if(fid >= 0 && H5Fclose(fid) < 0) { error_msg("unable to close file \"%s\"\n", fname); h5tools_setstatus(EXIT_FAILURE); diff --git a/tools/src/misc/CMakeLists.txt b/tools/src/misc/CMakeLists.txt index 7c3d7f0..6b41d7f 100644 --- a/tools/src/misc/CMakeLists.txt +++ b/tools/src/misc/CMakeLists.txt @@ -78,13 +78,6 @@ if (BUILD_SHARED_LIBS) ) endif () -#----------------------------------------------------------------------------- -# Generate the h5cc file containing settings needed to compile programs -#----------------------------------------------------------------------------- -#if (NOT WIN32) -# configure_file (${HDF5_TOOLS_SRC_MISC_SOURCE_DIR}/h5cc.in ${HDF5_BINARY_DIR}/h5cc @ONLY) -#endif () - ############################################################################## ############################################################################## ### I N S T A L L A T I O N ### diff --git a/tools/src/misc/h5debug.c b/tools/src/misc/h5debug.c index 088e6e9..96d6b9f 100644 --- a/tools/src/misc/h5debug.c +++ b/tools/src/misc/h5debug.c @@ -21,19 +21,19 @@ * *------------------------------------------------------------------------- */ -#define H5A_FRIEND /*suppress error about including H5Apkg */ -#define H5B2_FRIEND /*suppress error about including H5B2pkg */ -#define H5B2_TESTING /*suppress warning about H5B2 testing funcs*/ -#define H5D_FRIEND /*suppress error about including H5Dpkg */ -#define H5EA_FRIEND /*suppress error about including H5EApkg */ -#define H5EA_TESTING /*suppress warning about H5EA testing funcs*/ -#define H5FA_FRIEND /*suppress error about including H5FApkg */ -#define H5FA_TESTING /*suppress warning about H5FA testing funcs*/ -#define H5F_FRIEND /*suppress error about including H5Fpkg */ -#define H5G_FRIEND /*suppress error about including H5Gpkg */ -#define H5HF_FRIEND /*suppress error about including H5HFpkg */ -#define H5O_FRIEND /*suppress error about including H5Opkg */ -#define H5SM_FRIEND /*suppress error about including H5SMpkg */ +#define H5A_FRIEND /*suppress error about including H5Apkg */ +#define H5B2_FRIEND /*suppress error about including H5B2pkg */ +#define H5B2_TESTING /*suppress warning about H5B2 testing funcs*/ +#define H5D_FRIEND /*suppress error about including H5Dpkg */ +#define H5EA_FRIEND /*suppress error about including H5EApkg */ +#define H5EA_TESTING /*suppress warning about H5EA testing funcs*/ +#define H5FA_FRIEND /*suppress error about including H5FApkg */ +#define H5FA_TESTING /*suppress warning about H5FA testing funcs*/ +#define H5F_FRIEND /*suppress error about including H5Fpkg */ +#define H5G_FRIEND /*suppress error about including H5Gpkg */ +#define H5HF_FRIEND /*suppress error about including H5HFpkg */ +#define H5O_FRIEND /*suppress error about including H5Opkg */ +#define H5SM_FRIEND /*suppress error about including H5SMpkg */ #include "H5private.h" /* Generic Functions */ #include "H5Apkg.h" /* Attributes */ @@ -57,7 +57,7 @@ #define VCOL 50 - + /*------------------------------------------------------------------------- * Function: get_H5B2_class * @@ -80,68 +80,68 @@ get_H5B2_class(const uint8_t *sig) const H5B2_class_t *cls; switch(subtype) { - case H5B2_TEST_ID: - cls = H5B2_TEST; - break; + case H5B2_TEST_ID: + cls = H5B2_TEST; + break; - case H5B2_FHEAP_HUGE_INDIR_ID: - cls = H5HF_HUGE_BT2_INDIR; - break; + case H5B2_FHEAP_HUGE_INDIR_ID: + cls = H5HF_HUGE_BT2_INDIR; + break; - case H5B2_FHEAP_HUGE_FILT_INDIR_ID: - cls = H5HF_HUGE_BT2_FILT_INDIR; - break; + case H5B2_FHEAP_HUGE_FILT_INDIR_ID: + cls = H5HF_HUGE_BT2_FILT_INDIR; + break; - case H5B2_FHEAP_HUGE_DIR_ID: - cls = H5HF_HUGE_BT2_DIR; - break; + case H5B2_FHEAP_HUGE_DIR_ID: + cls = H5HF_HUGE_BT2_DIR; + break; - case H5B2_FHEAP_HUGE_FILT_DIR_ID: - cls = H5HF_HUGE_BT2_FILT_DIR; - break; + case H5B2_FHEAP_HUGE_FILT_DIR_ID: + cls = H5HF_HUGE_BT2_FILT_DIR; + break; - case H5B2_GRP_DENSE_NAME_ID: - cls = H5G_BT2_NAME; - break; + case H5B2_GRP_DENSE_NAME_ID: + cls = H5G_BT2_NAME; + break; - case H5B2_GRP_DENSE_CORDER_ID: - cls = H5G_BT2_CORDER; - break; + case H5B2_GRP_DENSE_CORDER_ID: + cls = H5G_BT2_CORDER; + break; - case H5B2_SOHM_INDEX_ID: - cls = H5SM_INDEX; - break; + case H5B2_SOHM_INDEX_ID: + cls = H5SM_INDEX; + break; - case H5B2_ATTR_DENSE_NAME_ID: - cls = H5A_BT2_NAME; - break; + case H5B2_ATTR_DENSE_NAME_ID: + cls = H5A_BT2_NAME; + break; - case H5B2_ATTR_DENSE_CORDER_ID: - cls = H5A_BT2_CORDER; - break; + case H5B2_ATTR_DENSE_CORDER_ID: + cls = H5A_BT2_CORDER; + break; - case H5B2_CDSET_ID: - cls = H5D_BT2; - break; + case H5B2_CDSET_ID: + cls = H5D_BT2; + break; - case H5B2_CDSET_FILT_ID: - cls = H5D_BT2_FILT; - break; + case H5B2_CDSET_FILT_ID: + cls = H5D_BT2_FILT; + break; - case H5B2_TEST2_ID: - cls = H5B2_TEST2; - break; + case H5B2_TEST2_ID: + cls = H5B2_TEST2; + break; - case H5B2_NUM_BTREE_ID: - default: - HDfprintf(stderr, "Unknown v2 B-tree subtype %u\n", (unsigned)(subtype)); - HDexit(4); + case H5B2_NUM_BTREE_ID: + default: + HDfprintf(stderr, "Unknown v2 B-tree subtype %u\n", (unsigned)(subtype)); + HDexit(4); } /* end switch */ return(cls); } /* end get_H5B2_class() */ - + /*------------------------------------------------------------------------- * Function: get_H5EA_class * @@ -164,28 +164,28 @@ get_H5EA_class(const uint8_t *sig) const H5EA_class_t *cls; switch(clsid) { - case H5EA_CLS_TEST_ID: - cls = H5EA_CLS_TEST; - break; + case H5EA_CLS_TEST_ID: + cls = H5EA_CLS_TEST; + break; - case H5EA_CLS_CHUNK_ID: - cls = H5EA_CLS_CHUNK; - break; + case H5EA_CLS_CHUNK_ID: + cls = H5EA_CLS_CHUNK; + break; - case H5EA_CLS_FILT_CHUNK_ID: - cls = H5EA_CLS_FILT_CHUNK; - break; + case H5EA_CLS_FILT_CHUNK_ID: + cls = H5EA_CLS_FILT_CHUNK; + break; - case H5EA_NUM_CLS_ID: - default: - HDfprintf(stderr, "Unknown extensible array class %u\n", (unsigned)(clsid)); - HDexit(4); + case H5EA_NUM_CLS_ID: + default: + HDfprintf(stderr, "Unknown extensible array class %u\n", (unsigned)(clsid)); + HDexit(4); } /* end switch */ return(cls); } /* end get_H5EA_class() */ - + /*------------------------------------------------------------------------- * Function: get_H5FA_class * @@ -208,28 +208,28 @@ get_H5FA_class(const uint8_t *sig) const H5FA_class_t *cls; switch(clsid) { - case H5FA_CLS_TEST_ID: - cls = H5FA_CLS_TEST; - break; + case H5FA_CLS_TEST_ID: + cls = H5FA_CLS_TEST; + break; - case H5FA_CLS_CHUNK_ID: - cls = H5FA_CLS_CHUNK; - break; + case H5FA_CLS_CHUNK_ID: + cls = H5FA_CLS_CHUNK; + break; - case H5FA_CLS_FILT_CHUNK_ID: - cls = H5FA_CLS_FILT_CHUNK; - break; + case H5FA_CLS_FILT_CHUNK_ID: + cls = H5FA_CLS_FILT_CHUNK; + break; - case H5FA_NUM_CLS_ID: - default: - HDfprintf(stderr, "Unknown fixed array class %u\n", (unsigned)(clsid)); - HDexit(4); + case H5FA_NUM_CLS_ID: + default: + HDfprintf(stderr, "Unknown fixed array class %u\n", (unsigned)(clsid)); + HDexit(4); } /* end switch */ return(cls); } /* end get_H5FA_class() */ - + /*------------------------------------------------------------------------- * Function: main * @@ -254,13 +254,13 @@ main(int argc, char *argv[]) uint8_t sig[H5F_SIGNATURE_LEN]; size_t u; H5E_auto2_t func; - void *edata; + void *edata; hbool_t api_ctx_pushed = FALSE; /* Whether API context pushed */ herr_t status = SUCCEED; if(argc == 1) { - HDfprintf(stderr, "Usage: %s filename [signature-addr [extra]]\n", argv[0]); - HDexit(1); + HDfprintf(stderr, "Usage: %s filename [signature-addr [extra]]\n", argv[0]); + HDexit(1); } /* end if */ /* Initialize the library */ @@ -274,15 +274,15 @@ main(int argc, char *argv[]) H5Eset_auto2(H5E_DEFAULT, NULL, NULL); /* - * Open the file and get the file descriptor. - */ + * Open the file and get the file descriptor. + */ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) { HDfprintf(stderr, "cannot create file access property list\n"); HDexit(1); } /* end if */ if(HDstrchr(argv[1], '%')) if(H5Pset_fapl_family (fapl, (hsize_t)0, H5P_DEFAULT) < 0) { - fprintf(stderr, "cannot set file access property list\n"); + HDfprintf(stderr, "cannot set file access property list\n"); HDexit(1); } if((fid = H5Fopen(argv[1], H5F_ACC_RDONLY, fapl)) < 0) { @@ -309,8 +309,8 @@ main(int argc, char *argv[]) } /* - * Parse command arguments. - */ + * Parse command arguments. + */ if(argc > 2) addr = (haddr_t)HDstrtoll(argv[2], NULL, 0); if(argc > 3) @@ -323,8 +323,8 @@ main(int argc, char *argv[]) extra4 = (haddr_t)HDstrtoll(argv[6], NULL, 0); /* - * Read the signature at the specified file position. - */ + * Read the signature at the specified file position. + */ HDfprintf(stdout, "Reading signature at address %a (rel)\n", addr); if(H5F_block_read(f, H5FD_MEM_SUPER, addr, sizeof(sig), sig) < 0) { HDfprintf(stderr, "cannot read signature\n"); @@ -332,26 +332,28 @@ main(int argc, char *argv[]) } if(!HDmemcmp(sig, H5F_SIGNATURE, (size_t)H5F_SIGNATURE_LEN)) { /* - * Debug the file's super block. - */ + * Debug the file's super block. + */ status = H5F_debug(f, stdout, 0, VCOL); } else if(!HDmemcmp(sig, H5HL_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* - * Debug a local heap. - */ + * Debug a local heap. + */ status = H5HL_debug(f, addr, stdout, 0, VCOL); - } else if(!HDmemcmp (sig, H5HG_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { - /* - * Debug a global heap collection. - */ - status = H5HG_debug(f, addr, stdout, 0, VCOL); + } + else if(!HDmemcmp (sig, H5HG_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { + /* + * Debug a global heap collection. + */ + status = H5HG_debug(f, addr, stdout, 0, VCOL); - } else if(!HDmemcmp(sig, H5G_NODE_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { + } + else if(!HDmemcmp(sig, H5G_NODE_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* - * Debug a symbol table node. - */ + * Debug a symbol table node. + */ /* Check for extra parameters */ if(extra == 0) { @@ -362,107 +364,109 @@ main(int argc, char *argv[]) status = H5G_node_debug(f, addr, stdout, 0, VCOL, extra); - } else if(!HDmemcmp(sig, H5B_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { + } + else if(!HDmemcmp(sig, H5B_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* - * Debug a B-tree. B-trees are debugged through the B-tree - * subclass. The subclass identifier is the byte immediately - * after the B-tree signature. - */ + * Debug a B-tree. B-trees are debugged through the B-tree + * subclass. The subclass identifier is the byte immediately + * after the B-tree signature. + */ H5B_subid_t subtype = (H5B_subid_t)sig[H5_SIZEOF_MAGIC]; unsigned ndims; uint32_t dim[H5O_LAYOUT_NDIMS]; switch(subtype) { - case H5B_SNODE_ID: - /* Check for extra parameters */ - if(extra == 0) { - HDfprintf(stderr, "\nWarning: Providing the group's local heap address will give more information\n"); - HDfprintf(stderr, "B-tree symbol table node usage:\n"); - HDfprintf(stderr, "\th5debug <filename> <B-tree node address> <address of local heap>\n\n"); - HDexit(4); - } /* end if */ + case H5B_SNODE_ID: + /* Check for extra parameters */ + if(extra == 0) { + HDfprintf(stderr, "\nWarning: Providing the group's local heap address will give more information\n"); + HDfprintf(stderr, "B-tree symbol table node usage:\n"); + HDfprintf(stderr, "\th5debug <filename> <B-tree node address> <address of local heap>\n\n"); + HDexit(4); + } /* end if */ - status = H5G_node_debug(f, addr, stdout, 0, VCOL, extra); - break; + status = H5G_node_debug(f, addr, stdout, 0, VCOL, extra); + break; - case H5B_CHUNK_ID: - /* Check for extra parameters */ - if(extra == 0) { - HDfprintf(stderr, "ERROR: Need number of dimensions of chunk in order to dump chunk B-tree node\n"); + case H5B_CHUNK_ID: + /* Check for extra parameters */ + if(extra == 0) { + HDfprintf(stderr, "ERROR: Need number of dimensions of chunk in order to dump chunk B-tree node\n"); + HDfprintf(stderr, "B-tree chunked storage node usage:\n"); + HDfprintf(stderr, "\th5debug <filename> <B-tree node address> <# of dimensions> <slowest chunk dim>...<fastest chunk dim>\n"); + HDexit(4); + } /* end if */ + + /* Build array of chunk dimensions */ + ndims = (unsigned)extra; + dim[0] = (uint32_t)extra2; + if(ndims > 1) + dim[1] = (uint32_t)extra3; + if(ndims > 2) + dim[2] = (uint32_t)extra4; + + /* Check for dimension error */ + if(ndims > 3) { + HDfprintf(stderr, "ERROR: Only 3 dimensions support currently (fix h5debug)\n"); + HDfprintf(stderr, "B-tree chunked storage node usage:\n"); + HDfprintf(stderr, "\th5debug <filename> <B-tree node address> <# of dimensions> <slowest chunk dim>...<fastest chunk dim>\n"); + HDexit(4); + } /* end for */ + for(u = 0; u < ndims; u++) + if(0 == dim[u]) { + HDfprintf(stderr, "ERROR: Chunk dimensions should be >0\n"); HDfprintf(stderr, "B-tree chunked storage node usage:\n"); HDfprintf(stderr, "\th5debug <filename> <B-tree node address> <# of dimensions> <slowest chunk dim>...<fastest chunk dim>\n"); HDexit(4); } /* end if */ - /* Build array of chunk dimensions */ - ndims = (unsigned)extra; - dim[0] = (uint32_t)extra2; - if(ndims > 1) - dim[1] = (uint32_t)extra3; - if(ndims > 2) - dim[2] = (uint32_t)extra4; - - /* Check for dimension error */ - if(ndims > 3) { - HDfprintf(stderr, "ERROR: Only 3 dimensions support currently (fix h5debug)\n"); - HDfprintf(stderr, "B-tree chunked storage node usage:\n"); - HDfprintf(stderr, "\th5debug <filename> <B-tree node address> <# of dimensions> <slowest chunk dim>...<fastest chunk dim>\n"); - HDexit(4); - } /* end for */ - for(u = 0; u < ndims; u++) - if(0 == dim[u]) { - HDfprintf(stderr, "ERROR: Chunk dimensions should be >0\n"); - HDfprintf(stderr, "B-tree chunked storage node usage:\n"); - HDfprintf(stderr, "\th5debug <filename> <B-tree node address> <# of dimensions> <slowest chunk dim>...<fastest chunk dim>\n"); - HDexit(4); - } /* end if */ - - /* Set the last dimension (the element size) to zero */ - dim[ndims] = 0; - - status = H5D_btree_debug(f, addr, stdout, 0, VCOL, ndims, dim); - break; - - case H5B_NUM_BTREE_ID: - default: - HDfprintf(stderr, "Unknown v1 B-tree subtype %u\n", (unsigned)(subtype)); - HDexit(4); + /* Set the last dimension (the element size) to zero */ + dim[ndims] = 0; + + status = H5D_btree_debug(f, addr, stdout, 0, VCOL, ndims, dim); + break; + + case H5B_NUM_BTREE_ID: + default: + HDfprintf(stderr, "Unknown v1 B-tree subtype %u\n", (unsigned)(subtype)); + HDexit(4); } - } else if(!HDmemcmp(sig, H5B2_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { + } + else if(!HDmemcmp(sig, H5B2_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* - * Debug a v2 B-tree header. - */ + * Debug a v2 B-tree header. + */ const H5B2_class_t *cls = get_H5B2_class(sig); HDassert(cls); - if((cls == H5D_BT2 || cls == H5D_BT2_FILT) && extra == 0) { + if((cls == H5D_BT2 || cls == H5D_BT2_FILT) && extra == 0) { HDfprintf(stderr, "ERROR: Need v2 B-tree header address and object header address containing the layout message in order to dump header\n"); HDfprintf(stderr, "v2 B-tree hdr usage:\n"); HDfprintf(stderr, "\th5debug <filename> <v2 B-tree header address> <object header address>\n"); HDexit(4); - } /* end if */ + } /* end if */ status = H5B2__hdr_debug(f, addr, stdout, 0, VCOL, cls, (haddr_t)extra); - } else if(!HDmemcmp(sig, H5B2_INT_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { + } + else if(!HDmemcmp(sig, H5B2_INT_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* - * Debug a v2 B-tree internal node. - */ + * Debug a v2 B-tree internal node. + */ const H5B2_class_t *cls = get_H5B2_class(sig); HDassert(cls); /* Check for enough valid parameters */ - if((cls == H5D_BT2 || cls == H5D_BT2_FILT) && - (extra == 0 || extra2 == 0 || extra3 == 0 || extra4 == 0)) { - - fprintf(stderr, "ERROR: Need v2 B-tree header address, the node's number of records, depth, and object header address containing the layout message in order to dump internal node\n"); - fprintf(stderr, "NOTE: Leaf nodes are depth 0, the internal nodes above them are depth 1, etc.\n"); - fprintf(stderr, "v2 B-tree internal node usage:\n"); - fprintf(stderr, "\th5debug <filename> <internal node address> <v2 B-tree header address> <number of records> <depth> <object header address>\n"); + if((cls == H5D_BT2 || cls == H5D_BT2_FILT) && (extra == 0 || extra2 == 0 || extra3 == 0 || extra4 == 0)) { + HDfprintf(stderr, "ERROR: Need v2 B-tree header address, the node's number of records, depth, and object header address containing the layout message in order to dump internal node\n"); + HDfprintf(stderr, "NOTE: Leaf nodes are depth 0, the internal nodes above them are depth 1, etc.\n"); + HDfprintf(stderr, "v2 B-tree internal node usage:\n"); + HDfprintf(stderr, "\th5debug <filename> <internal node address> <v2 B-tree header address> <number of records> <depth> <object header address>\n"); HDexit(4); - } else if(extra == 0 || extra2 == 0 || extra3 == 0) { + } + else if(extra == 0 || extra2 == 0 || extra3 == 0) { HDfprintf(stderr, "ERROR: Need v2 B-tree header address and the node's number of records and depth in order to dump internal node\n"); HDfprintf(stderr, "NOTE: Leaf nodes are depth 0, the internal nodes above them are depth 1, etc.\n"); HDfprintf(stderr, "v2 B-tree internal node usage:\n"); @@ -472,23 +476,24 @@ main(int argc, char *argv[]) status = H5B2__int_debug(f, addr, stdout, 0, VCOL, cls, extra, (unsigned)extra2, (unsigned)extra3, (haddr_t)extra4); - } else if(!HDmemcmp(sig, H5B2_LEAF_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { + } + else if(!HDmemcmp(sig, H5B2_LEAF_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* - * Debug a v2 B-tree leaf node. - */ + * Debug a v2 B-tree leaf node. + */ const H5B2_class_t *cls = get_H5B2_class(sig); HDassert(cls); /* Check for enough valid parameters */ - if((cls == H5D_BT2 || cls == H5D_BT2_FILT) && - (extra == 0 || extra2 == 0 || extra3 == 0 )) { + if((cls == H5D_BT2 || cls == H5D_BT2_FILT) && (extra == 0 || extra2 == 0 || extra3 == 0 )) { - fprintf(stderr, "ERROR: Need v2 B-tree header address, number of records, and object header address containing the layout message in order to dump leaf node\n"); - fprintf(stderr, "v2 B-tree leaf node usage:\n"); - fprintf(stderr, "\th5debug <filename> <leaf node address> <v2 B-tree header address> <number of records> <object header address>\n"); + HDfprintf(stderr, "ERROR: Need v2 B-tree header address, number of records, and object header address containing the layout message in order to dump leaf node\n"); + HDfprintf(stderr, "v2 B-tree leaf node usage:\n"); + HDfprintf(stderr, "\th5debug <filename> <leaf node address> <v2 B-tree header address> <number of records> <object header address>\n"); HDexit(4); - } else if(extra == 0 || extra2 == 0) { + } + else if(extra == 0 || extra2 == 0) { HDfprintf(stderr, "ERROR: Need v2 B-tree header address and number of records in order to dump leaf node\n"); HDfprintf(stderr, "v2 B-tree leaf node usage:\n"); HDfprintf(stderr, "\th5debug <filename> <leaf node address> <v2 B-tree header address> <number of records>\n"); @@ -497,16 +502,18 @@ main(int argc, char *argv[]) status = H5B2__leaf_debug(f, addr, stdout, 0, VCOL, cls, extra, (unsigned)extra2, (haddr_t)extra3); - } else if(!HDmemcmp(sig, H5HF_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { + } + else if(!HDmemcmp(sig, H5HF_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* - * Debug a fractal heap header. - */ + * Debug a fractal heap header. + */ status = H5HF_hdr_debug(f, addr, stdout, 0, VCOL); - } else if(!HDmemcmp(sig, H5HF_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { + } + else if(!HDmemcmp(sig, H5HF_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* - * Debug a fractal heap direct block. - */ + * Debug a fractal heap direct block. + */ /* Check for enough valid parameters */ if(extra == 0 || extra2 == 0) { @@ -518,10 +525,11 @@ main(int argc, char *argv[]) status = H5HF_dblock_debug(f, addr, stdout, 0, VCOL, extra, (size_t)extra2); - } else if(!HDmemcmp(sig, H5HF_IBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { + } + else if(!HDmemcmp(sig, H5HF_IBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* - * Debug a fractal heap indirect block. - */ + * Debug a fractal heap indirect block. + */ /* Check for enough valid parameters */ if(extra == 0 || extra2 == 0) { @@ -533,17 +541,19 @@ main(int argc, char *argv[]) status = H5HF_iblock_debug(f, addr, stdout, 0, VCOL, extra, (unsigned)extra2); - } else if(!HDmemcmp(sig, H5FS_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { + } + else if(!HDmemcmp(sig, H5FS_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* - * Debug a free space header. - */ + * Debug a free space header. + */ status = H5FS_debug(f, addr, stdout, 0, VCOL); - } else if(!HDmemcmp(sig, H5FS_SINFO_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { + } + else if(!HDmemcmp(sig, H5FS_SINFO_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* - * Debug free space serialized sections. - */ + * Debug free space serialized sections. + */ /* Check for enough valid parameters */ if(extra == 0 || extra2 == 0) { @@ -555,17 +565,19 @@ main(int argc, char *argv[]) status = H5FS_sects_debug(f, addr, stdout, 0, VCOL, extra, extra2); - } else if(!HDmemcmp(sig, H5SM_TABLE_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { + } + else if(!HDmemcmp(sig, H5SM_TABLE_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* - * Debug shared message master table. - */ + * Debug shared message master table. + */ status = H5SM_table_debug(f, addr, stdout, 0, VCOL, (unsigned) UFAIL, (unsigned) UFAIL); - } else if(!HDmemcmp(sig, H5SM_LIST_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { + } + else if(!HDmemcmp(sig, H5SM_LIST_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* - * Debug shared message list index. - */ + * Debug shared message list index. + */ /* Check for enough valid parameters */ if(extra == 0) { @@ -577,10 +589,11 @@ main(int argc, char *argv[]) status = H5SM_list_debug(f, addr, stdout, 0, VCOL, (haddr_t)extra); - } else if(!HDmemcmp(sig, H5EA_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { + } + else if(!HDmemcmp(sig, H5EA_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* - * Debug an extensible aray header. - */ + * Debug an extensible aray header. + */ const H5EA_class_t *cls = get_H5EA_class(sig); HDassert(cls); @@ -594,10 +607,11 @@ main(int argc, char *argv[]) status = H5EA__hdr_debug(f, addr, stdout, 0, VCOL, cls, extra); - } else if(!HDmemcmp(sig, H5EA_IBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { + } + else if(!HDmemcmp(sig, H5EA_IBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* - * Debug an extensible aray index block. - */ + * Debug an extensible aray index block. + */ const H5EA_class_t *cls = get_H5EA_class(sig); HDassert(cls); @@ -611,10 +625,11 @@ main(int argc, char *argv[]) status = H5EA__iblock_debug(f, addr, stdout, 0, VCOL, cls, extra, extra2); - } else if(!HDmemcmp(sig, H5EA_SBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { + } + else if(!HDmemcmp(sig, H5EA_SBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* - * Debug an extensible aray super block. - */ + * Debug an extensible aray super block. + */ const H5EA_class_t *cls = get_H5EA_class(sig); HDassert(cls); @@ -628,10 +643,11 @@ main(int argc, char *argv[]) status = H5EA__sblock_debug(f, addr, stdout, 0, VCOL, cls, extra, (unsigned)extra2, extra3); - } else if(!HDmemcmp(sig, H5EA_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { + } + else if(!HDmemcmp(sig, H5EA_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* - * Debug an extensible aray data block. - */ + * Debug an extensible aray data block. + */ const H5EA_class_t *cls = get_H5EA_class(sig); HDassert(cls); @@ -645,10 +661,11 @@ main(int argc, char *argv[]) status = H5EA__dblock_debug(f, addr, stdout, 0, VCOL, cls, extra, (size_t)extra2, extra3); - } else if(!HDmemcmp(sig, H5FA_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { + } + else if(!HDmemcmp(sig, H5FA_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* - * Debug a fixed array header. - */ + * Debug a fixed array header. + */ const H5FA_class_t *cls = get_H5FA_class(sig); HDassert(cls); @@ -662,10 +679,11 @@ main(int argc, char *argv[]) status = H5FA__hdr_debug(f, addr, stdout, 0, VCOL, cls, extra); - } else if(!HDmemcmp(sig, H5FA_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { + } + else if(!HDmemcmp(sig, H5FA_DBLOCK_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* - * Debug a fixed array data block. - */ + * Debug a fixed array data block. + */ const H5FA_class_t *cls = get_H5FA_class(sig); HDassert(cls); @@ -679,33 +697,37 @@ main(int argc, char *argv[]) status = H5FA__dblock_debug(f, addr, stdout, 0, VCOL, cls, extra, extra2); - } else if(!HDmemcmp(sig, H5O_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { + } + else if(!HDmemcmp(sig, H5O_HDR_MAGIC, (size_t)H5_SIZEOF_MAGIC)) { /* - * Debug v2 object header (which have signatures). - */ + * Debug v2 object header (which have signatures). + */ status = H5O_debug(f, addr, stdout, 0, VCOL); - } else if(sig[0] == H5O_VERSION_1) { + } + else if(sig[0] == H5O_VERSION_1) { /* - * This could be a v1 object header. Since they don't have a signature - * it's a somewhat "ify" detection. - */ + * This could be a v1 object header. Since they don't have a signature + * it's a somewhat "ify" detection. + */ status = H5O_debug(f, addr, stdout, 0, VCOL); - } else { + } + else { /* - * Got some other unrecognized signature. - */ - printf("%-*s ", VCOL, "Signature:"); + * Got some other unrecognized signature. + */ + HDprintf("%-*s ", VCOL, "Signature:"); for (u = 0; u < sizeof(sig); u++) { if (sig[u] > ' ' && sig[u] <= '~' && '\\' != sig[u]) HDputchar(sig[u]); else if ('\\' == sig[u]) { HDputchar('\\'); HDputchar('\\'); - } else - printf("\\%03o", sig[u]); + } + else + HDprintf("\\%03o", sig[u]); } HDputchar('\n'); diff --git a/tools/src/misc/h5mkgrp.c b/tools/src/misc/h5mkgrp.c index b7ff73c..feb60d4 100644 --- a/tools/src/misc/h5mkgrp.c +++ b/tools/src/misc/h5mkgrp.c @@ -251,7 +251,7 @@ main(int argc, const char *argv[]) /* Display some output if requested */ if(params.verbose) - printf("%s: Creating groups with latest version of the format\n", h5tools_getprogname()); + HDprintf("%s: Creating groups with latest version of the format\n", h5tools_getprogname()); } /* end if */ /* Attempt to open an existing HDF5 file first */ @@ -284,7 +284,7 @@ main(int argc, const char *argv[]) /* Display some output if requested */ if(params.verbose) - printf("%s: Creating parent groups\n", h5tools_getprogname()); + HDprintf("%s: Creating parent groups\n", h5tools_getprogname()); } /* end if */ /* Loop over creating requested groups */ @@ -305,7 +305,7 @@ main(int argc, const char *argv[]) /* Display some output if requested */ if(params.verbose) - printf("%s: created group '%s'\n", h5tools_getprogname(), params.groups[curr_group]); + HDprintf("%s: created group '%s'\n", h5tools_getprogname(), params.groups[curr_group]); } /* end for */ /* Close link creation property list */ diff --git a/tools/src/misc/h5repart.c b/tools/src/misc/h5repart.c index 2f4d93e..d516fa0 100644 --- a/tools/src/misc/h5repart.c +++ b/tools/src/misc/h5repart.c @@ -15,19 +15,19 @@ * Programmer: Robb Matzke <matzke@llnl.gov> * Wednesday, May 13, 1998 * - * Purpose: Repartitions a file family. This program can be used to - * split a single file into a family of files, join a family of - * files into a single file, or copy one family to another while - * changing the size of the family members. It can also be used - * to copy a single file to a single file with holes. + * Purpose: Repartitions a file family. This program can be used to + * split a single file into a family of files, join a family of + * files into a single file, or copy one family to another while + * changing the size of the family members. It can also be used + * to copy a single file to a single file with holes. */ /* See H5private.h for how to include system headers */ #include "hdf5.h" #include "H5private.h" -#define NAMELEN 4096 -#define GB *1024*1024*1024 +#define NAMELEN 4096 +#define GB *1024*1024*1024 /* Make these 2 private properties(defined in H5Fprivate.h) available to h5repart. * The first one updates the member file size in the superblock. The second one @@ -36,15 +36,15 @@ #define H5F_ACS_FAMILY_NEWSIZE_NAME "family_newsize" #define H5F_ACS_FAMILY_TO_SINGLE_NAME "family_to_single" - + /*------------------------------------------------------------------------- - * Function: usage + * Function: usage * - * Purpose: Prints a usage message. + * Purpose: Prints a usage message. * - * Return: void + * Return: void * - * Programmer: Robb Matzke + * Programmer: Robb Matzke * Wednesday, May 13, 1998 * * Modifications: @@ -54,98 +54,99 @@ static void usage (const char *progname) { - fprintf(stderr, "usage: %s [-v] [-V] [-[b|m] N[g|m|k]] [-family_to_sec2|-family_to_single] SRC DST\n", - progname); - fprintf(stderr, " -v Produce verbose output\n"); - fprintf(stderr, " -V Print a version number and exit\n"); - fprintf(stderr, " -b N The I/O block size, defaults to 1kB\n"); - fprintf(stderr, " -m N The destination member size or 1GB\n"); - fprintf(stderr, " -family_to_sec2 Deprecated version of -family_to_single (below)\n"); - fprintf(stderr, " -family_to_single Change file driver from family to the default single-file VFD (windows or sec2)\n"); - fprintf(stderr, " SRC The name of the source file\n"); - fprintf(stderr, " DST The name of the destination files\n"); - fprintf(stderr, "Sizes may be suffixed with `g' for GB, `m' for MB or " - "`k' for kB.\n"); - fprintf(stderr, "File family names include an integer printf " - "format such as `%%d'\n"); - exit (EXIT_FAILURE); + HDfprintf(stderr, "usage: %s [-v] [-V] [-[b|m] N[g|m|k]] [-family_to_sec2|-family_to_single] SRC DST\n", + progname); + HDfprintf(stderr, " -v Produce verbose output\n"); + HDfprintf(stderr, " -V Print a version number and exit\n"); + HDfprintf(stderr, " -b N The I/O block size, defaults to 1kB\n"); + HDfprintf(stderr, " -m N The destination member size or 1GB\n"); + HDfprintf(stderr, " -family_to_sec2 Deprecated version of -family_to_single (below)\n"); + HDfprintf(stderr, " -family_to_single Change file driver from family to the default single-file VFD (windows or sec2)\n"); + HDfprintf(stderr, " SRC The name of the source file\n"); + HDfprintf(stderr, " DST The name of the destination files\n"); + HDfprintf(stderr, "Sizes may be suffixed with `g' for GB, `m' for MB or " + "`k' for kB.\n"); + HDfprintf(stderr, "File family names include an integer printf " + "format such as `%%d'\n"); + HDexit (EXIT_FAILURE); } - + /*------------------------------------------------------------------------- - * Function: get_size + * Function: get_size * - * Purpose: Reads a size option of the form `-XNS' where `X' is any - * letter, `N' is a multi-character positive decimal number, and - * `S' is an optional suffix letter in the set [GgMmk]. The - * option may also be split among two arguments as: `-X NS'. - * The input value of ARGNO is the argument number for the - * switch in the ARGV vector and ARGC is the number of entries - * in that vector. + * Purpose: Reads a size option of the form `-XNS' where `X' is any + * letter, `N' is a multi-character positive decimal number, and + * `S' is an optional suffix letter in the set [GgMmk]. The + * option may also be split among two arguments as: `-X NS'. + * The input value of ARGNO is the argument number for the + * switch in the ARGV vector and ARGC is the number of entries + * in that vector. * - * Return: Success: The value N multiplied according to the - * suffix S. On return ARGNO will be the number - * of the next argument to process. + * Return: Success: The value N multiplied according to the + * suffix S. On return ARGNO will be the number + * of the next argument to process. * - * Failure: Calls usage() which exits with a non-zero - * status. + * Failure: Calls usage() which exits with a non-zero + * status. * - * Programmer: Robb Matzke + * Programmer: Robb Matzke * Wednesday, May 13, 1998 - * - * Modifications: - * *------------------------------------------------------------------------- */ static off_t get_size (const char *progname, int *argno, int argc, char *argv[]) { - off_t retval=-1; - char *suffix; + off_t retval=-1; + char *suffix; if (isdigit ((int)(argv[*argno][2]))) { - retval = strtol (argv[*argno]+2, &suffix, 10); - (*argno)++; - } else if (argv[*argno][2] || *argno+1>=argc) { - usage (progname); - } else { - retval = strtol (argv[*argno+1], &suffix, 0); - if (suffix==argv[*argno+1]) usage (progname); - *argno += 2; + retval = HDstrtol(argv[*argno]+2, &suffix, 10); + (*argno)++; + } + else if (argv[*argno][2] || *argno+1>=argc) { + usage (progname); + } + else { + retval = HDstrtol(argv[*argno+1], &suffix, 0); + if (suffix == argv[*argno+1]) + usage (progname); + *argno += 2; } if (suffix && suffix[0] && !suffix[1]) { - switch (*suffix) { - case 'G': - case 'g': - retval *= 1024 * 1024 * 1024; - break; - case 'M': - case 'm': - retval *= 1024 * 1024; - break; - case 'k': - retval *= 1024; - break; - default: - usage (progname); - } - } else if (suffix && suffix[0]) { - usage (progname); + switch (*suffix) { + case 'G': + case 'g': + retval *= 1024 * 1024 * 1024; + break; + case 'M': + case 'm': + retval *= 1024 * 1024; + break; + case 'k': + retval *= 1024; + break; + default: + usage(progname); + } + } + else if (suffix && suffix[0]) { + usage (progname); } return retval; } - + /*------------------------------------------------------------------------- - * Function: main + * Function: main * - * Purpose: Split an hdf5 file + * Purpose: Split an hdf5 file * - * Return: Success: + * Return: Success: * - * Failure: + * Failure: * - * Programmer: Robb Matzke + * Programmer: Robb Matzke * Wednesday, May 13, 1998 * * Modifications: @@ -155,36 +156,36 @@ get_size (const char *progname, int *argno, int argc, char *argv[]) int main (int argc, char *argv[]) { - const char *prog_name; /*program name */ - size_t blk_size=1024; /*size of each I/O block */ - char *buf=NULL; /*I/O block buffer */ - size_t n, i; /*counters */ - ssize_t nio; /*I/O return value */ - int argno=1; /*program argument number */ - int src, dst=-1; /*source & destination files */ - int need_seek=FALSE; /*destination needs to seek? */ - int need_write; /*data needs to be written? */ - h5_stat_t sb; /*temporary file stat buffer */ - - int verbose=FALSE; /*display file names? */ - - const char *src_gen_name; /*general source name */ - char *src_name=NULL; /*source member name */ - - int src_is_family; /*is source name a family name? */ - int src_membno=0; /*source member number */ - - const char *dst_gen_name; /*general destination name */ - char *dst_name=NULL; /*destination member name */ - int dst_is_family; /*is dst name a family name? */ - int dst_membno=0; /*destination member number */ - - off_t left_overs=0; /*amount of zeros left over */ - off_t src_offset=0; /*offset in source member */ - off_t dst_offset=0; /*offset in destination member */ - off_t src_size; /*source logical member size */ - off_t src_act_size; /*source actual member size */ - off_t dst_size=1 GB; /*destination logical memb size */ + const char *prog_name; /*program name */ + size_t blk_size=1024; /*size of each I/O block */ + char *buf=NULL; /*I/O block buffer */ + size_t n, i; /*counters */ + ssize_t nio; /*I/O return value */ + int argno=1; /*program argument number */ + int src, dst=-1; /*source & destination files */ + int need_seek=FALSE; /*destination needs to seek? */ + int need_write; /*data needs to be written? */ + h5_stat_t sb; /*temporary file stat buffer */ + + int verbose=FALSE; /*display file names? */ + + const char *src_gen_name; /*general source name */ + char *src_name=NULL; /*source member name */ + + int src_is_family; /*is source name a family name? */ + int src_membno=0; /*source member number */ + + const char *dst_gen_name; /*general destination name */ + char *dst_name=NULL; /*destination member name */ + int dst_is_family; /*is dst name a family name? */ + int dst_membno=0; /*destination member number */ + + off_t left_overs=0; /*amount of zeros left over */ + off_t src_offset=0; /*offset in source member */ + off_t dst_offset=0; /*offset in destination member */ + off_t src_size; /*source logical member size */ + off_t src_act_size; /*source actual member size */ + off_t dst_size=1 GB; /*destination logical memb size */ hid_t fapl; /*file access property list */ hid_t file; hsize_t hdsize; /*destination logical memb size */ @@ -193,48 +194,50 @@ main (int argc, char *argv[]) /* * Get the program name from argv[0]. Use only the last component. */ - if ((prog_name=strrchr (argv[0], '/'))) prog_name++; - else prog_name = argv[0]; + if ((prog_name = HDstrrchr (argv[0], '/'))) + prog_name++; + else + prog_name = argv[0]; /* * Parse switches. */ - while (argno<argc && '-'==argv[argno][0]) { - if (!strcmp (argv[argno], "-v")) { + while (argno < argc && '-' == argv[argno][0]) { + if (!HDstrcmp(argv[argno], "-v")) { verbose = TRUE; argno++; - } else if (!strcmp(argv[argno], "-V")) { - printf("This is %s version %u.%u release %u\n", - prog_name, H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE); - exit(EXIT_SUCCESS); - } else if (!strcmp (argv[argno], "-family_to_sec2")) { + } else if (!HDstrcmp(argv[argno], "-V")) { + HDprintf("This is %s version %u.%u release %u\n", prog_name, H5_VERS_MAJOR, H5_VERS_MINOR, H5_VERS_RELEASE); + HDexit(EXIT_SUCCESS); + } else if (!HDstrcmp(argv[argno], "-family_to_sec2")) { family_to_single = TRUE; argno++; - } else if (!strcmp (argv[argno], "-family_to_single")) { + } else if (!HDstrcmp(argv[argno], "-family_to_single")) { family_to_single = TRUE; argno++; - } else if ('b'==argv[argno][1]) { - blk_size = (size_t)get_size (prog_name, &argno, argc, argv); - } else if ('m'==argv[argno][1]) { - dst_size = get_size (prog_name, &argno, argc, argv); + } else if ('b' == argv[argno][1]) { + blk_size = (size_t) get_size(prog_name, &argno, argc, argv); + } else if ('m' == argv[argno][1]) { + dst_size = get_size(prog_name, &argno, argc, argv); } else { - usage (prog_name); + usage(prog_name); } /* end if */ } /* end while */ /* allocate names */ if(NULL == (src_name = (char *)HDcalloc((size_t)NAMELEN, sizeof(char)))) - exit(EXIT_FAILURE); + HDexit(EXIT_FAILURE); if(NULL == (dst_name = (char *)HDcalloc((size_t)NAMELEN, sizeof(char)))) - exit(EXIT_FAILURE); + HDexit(EXIT_FAILURE); /* * Get the name for the source file and open the first member. The size * of the first member determines the logical size of all the members. */ - if (argno>=argc) usage (prog_name); + if (argno >= argc) + usage(prog_name); src_gen_name = argv[argno++]; - sprintf (src_name, src_gen_name, src_membno); + HDsprintf(src_name, src_gen_name, src_membno); src_is_family = strcmp (src_name, src_gen_name); if ((src = HDopen(src_name, O_RDONLY)) < 0) { @@ -242,157 +245,170 @@ main (int argc, char *argv[]) HDexit(EXIT_FAILURE); } - if (HDfstat(src, &sb)<0) { - perror ("fstat"); - exit (EXIT_FAILURE); + if (HDfstat(src, &sb) < 0) { + HDperror("fstat"); + HDexit(EXIT_FAILURE); } src_size = src_act_size = sb.st_size; - if (verbose) fprintf (stderr, "< %s\n", src_name); + if (verbose) + HDfprintf(stderr, "< %s\n", src_name); /* * Get the name for the destination file and open the first member. */ - if (argno>=argc) usage (prog_name); + if (argno>=argc) + usage (prog_name); dst_gen_name = argv[argno++]; - sprintf (dst_name, dst_gen_name, dst_membno); - dst_is_family = strcmp (dst_name, dst_gen_name); + HDsprintf(dst_name, dst_gen_name, dst_membno); + dst_is_family = HDstrcmp(dst_name, dst_gen_name); if ((dst = HDopen(dst_name, O_RDWR|O_CREAT|O_TRUNC, H5_POSIX_CREATE_MODE_RW)) < 0) { HDperror(dst_name); HDexit(EXIT_FAILURE); } - if (verbose) fprintf (stderr, "> %s\n", dst_name); + if (verbose) + HDfprintf(stderr, "> %s\n", dst_name); /* No more arguments */ - if (argno<argc) usage (prog_name); + if (argno < argc) + usage (prog_name); /* Now the real work, split the file */ buf = (char *)HDmalloc(blk_size); while (src_offset<src_size) { - /* Read a block. The amount to read is the minimum of: - * 1. The I/O block size - * 2. What's left to write in the destination member - * 3. Left over zeros or what's left in the source member. - */ - n = blk_size; - if (dst_is_family) n = (size_t)MIN((off_t)n, dst_size-dst_offset); - if (left_overs) { - n = (size_t)MIN ((off_t)n, left_overs); - left_overs = left_overs - (off_t)n; - need_write = FALSE; - } else if (src_offset<src_act_size) { - n = (size_t)MIN ((off_t)n, src_act_size-src_offset); - if ((nio=HDread (src, buf, n))<0) { - perror ("read"); - exit (EXIT_FAILURE); - } else if ((size_t)nio!=n) { - fprintf (stderr, "%s: short read\n", src_name); - exit (EXIT_FAILURE); - } - for (i=0; i<n; i++) { - if (buf[i]) break; - } - need_write = (i<n); - } else { - n = 0; - left_overs = src_size - src_act_size; - need_write = FALSE; - } - - /* - * If the block contains non-zero data then write it to the - * destination, otherwise just remember that we'll have to do a seek - * later in the destination when we finally get non-zero data. - */ - if (need_write) { - if (need_seek && HDlseek (dst, dst_offset, SEEK_SET)<0) { - perror ("HDlseek"); - exit (EXIT_FAILURE); - } - if ((nio=HDwrite (dst, buf, n))<0) { - perror ("write"); - exit (EXIT_FAILURE); - } else if ((size_t)nio!=n) { - fprintf (stderr, "%s: short write\n", dst_name); - exit (EXIT_FAILURE); - } - need_seek = FALSE; - } else { - need_seek = TRUE; - } - - /* - * Update the source offset and open the next source family member if - * necessary. The source stream ends at the first member which - * cannot be opened because it doesn't exist. At the end of the - * source stream, update the destination offset and break out of the - * loop. The destination offset must be updated so we can fix - * trailing holes. - */ - src_offset = src_offset + (off_t)n; - if (src_offset==src_act_size) { - HDclose (src); - if (!src_is_family) { - dst_offset = dst_offset + (off_t)n; - break; - } - sprintf (src_name, src_gen_name, ++src_membno); - if ((src = HDopen(src_name, O_RDONLY)) < 0 && ENOENT == errno) { - dst_offset = dst_offset + (off_t)n; - break; - } else if (src<0) { - perror (src_name); - exit (EXIT_FAILURE); - } - if (HDfstat (src, &sb)<0) { - perror ("fstat"); - exit (EXIT_FAILURE); - } - src_act_size = sb.st_size; - if (src_act_size>src_size) { - fprintf (stderr, "%s: member truncated to %lu bytes\n", - src_name, (unsigned long)src_size); - } - src_offset = 0; - if (verbose) fprintf (stderr, "< %s\n", src_name); - } - - /* - * Update the destination offset, opening a new member if one will be - * needed. The first member is extended to the logical member size - * but other members might be smaller if they end with a hole. - */ - dst_offset = dst_offset + (off_t)n; - if (dst_is_family && dst_offset==dst_size) { - if (0==dst_membno) { - if (HDlseek (dst, dst_size-1, SEEK_SET)<0) { - perror ("HDHDlseek"); - exit (EXIT_FAILURE); - } - if (HDread (dst, buf, 1)<0) { - perror ("read"); - exit (EXIT_FAILURE); - } - if (HDlseek (dst, dst_size-1, SEEK_SET)<0) { - perror ("HDlseek"); - exit (EXIT_FAILURE); - } - if (HDwrite (dst, buf, 1)<0) { - perror ("write"); - exit (EXIT_FAILURE); - } - } - HDclose (dst); - sprintf (dst_name, dst_gen_name, ++dst_membno); - if ((dst = HDopen(dst_name, O_RDWR|O_CREAT|O_TRUNC, H5_POSIX_CREATE_MODE_RW)) < 0) { - HDperror(dst_name); - HDexit(EXIT_FAILURE); - } - dst_offset = 0; - need_seek = FALSE; - if (verbose) fprintf (stderr, "> %s\n", dst_name); - } + /* Read a block. The amount to read is the minimum of: + * 1. The I/O block size + * 2. What's left to write in the destination member + * 3. Left over zeros or what's left in the source member. + */ + n = blk_size; + if (dst_is_family) + n = (size_t)MIN((off_t)n, dst_size-dst_offset); + if (left_overs) { + n = (size_t)MIN((off_t)n, left_overs); + left_overs = left_overs - (off_t) n; + need_write = FALSE; + } + else if (src_offset < src_act_size) { + n = (size_t)MIN((off_t)n, src_act_size-src_offset); + if ((nio = HDread(src, buf, n)) < 0) { + HDperror("read"); + HDexit(EXIT_FAILURE); + } + else if ((size_t) nio != n) { + HDfprintf(stderr, "%s: short read\n", src_name); + HDexit(EXIT_FAILURE); + } + for (i = 0; i < n; i++) { + if (buf[i]) + break; + } + need_write = (i < n); + } + else { + n = 0; + left_overs = src_size - src_act_size; + need_write = FALSE; + } + + /* + * If the block contains non-zero data then write it to the + * destination, otherwise just remember that we'll have to do a seek + * later in the destination when we finally get non-zero data. + */ + if (need_write) { + if (need_seek && HDlseek (dst, dst_offset, SEEK_SET) < 0) { + HDperror("HDlseek"); + HDexit(EXIT_FAILURE); + } + if ((nio = HDwrite(dst, buf, n)) < 0) { + HDperror("write"); + HDexit(EXIT_FAILURE); + } + else if ((size_t) nio != n) { + HDfprintf(stderr, "%s: short write\n", dst_name); + HDexit(EXIT_FAILURE); + } + need_seek = FALSE; + } + else { + need_seek = TRUE; + } + + /* + * Update the source offset and open the next source family member if + * necessary. The source stream ends at the first member which + * cannot be opened because it doesn't exist. At the end of the + * source stream, update the destination offset and break out of the + * loop. The destination offset must be updated so we can fix + * trailing holes. + */ + src_offset = src_offset + (off_t) n; + if (src_offset == src_act_size) { + HDclose(src); + if (!src_is_family) { + dst_offset = dst_offset + (off_t) n; + break; + } + HDsprintf(src_name, src_gen_name, ++src_membno); + if ((src = HDopen(src_name, O_RDONLY)) < 0 && ENOENT == errno) { + dst_offset = dst_offset + (off_t) n; + break; + } + else if (src < 0) { + HDperror(src_name); + HDexit(EXIT_FAILURE); + } + if (HDfstat (src, &sb) < 0) { + HDperror("fstat"); + HDexit(EXIT_FAILURE); + } + src_act_size = sb.st_size; + if (src_act_size > src_size) { + HDfprintf(stderr, "%s: member truncated to %lu bytes\n", src_name, (unsigned long) src_size); + } + src_offset = 0; + if (verbose) + HDfprintf(stderr, "< %s\n", src_name); + } + + /* + * Update the destination offset, opening a new member if one will be + * needed. The first member is extended to the logical member size + * but other members might be smaller if they end with a hole. + */ + dst_offset = dst_offset + (off_t) n; + if (dst_is_family && dst_offset == dst_size) { + if (0 == dst_membno) { + if (HDlseek (dst, dst_size-1, SEEK_SET) < 0) { + HDperror("HDHDlseek"); + HDexit(EXIT_FAILURE); + } + if (HDread (dst, buf, 1) < 0) { + HDperror("read"); + HDexit(EXIT_FAILURE); + } + if (HDlseek (dst, dst_size-1, SEEK_SET) < 0) { + HDperror("HDlseek"); + HDexit(EXIT_FAILURE); + } + if (HDwrite (dst, buf, 1) < 0) { + HDperror("write"); + HDexit(EXIT_FAILURE); + } + } + HDclose(dst); + HDsprintf(dst_name, dst_gen_name, ++dst_membno); + if ((dst = HDopen(dst_name, O_RDWR | O_CREAT | O_TRUNC, H5_POSIX_CREATE_MODE_RW)) < 0) { + HDperror(dst_name); + HDexit(EXIT_FAILURE); + } + dst_offset = 0; + need_seek = FALSE; + if (verbose) + HDfprintf(stderr, "> %s\n", dst_name); + } } /* @@ -401,30 +417,30 @@ main (int argc, char *argv[]) * family has been truncated. */ if (need_seek) { - if (HDlseek (dst, dst_offset-1, SEEK_SET)<0) { - perror ("HDlseek"); - exit (EXIT_FAILURE); - } - if (HDread (dst, buf, 1)<0) { - perror ("read"); - exit (EXIT_FAILURE); - } - if (HDlseek (dst, dst_offset-1, SEEK_SET)<0) { - perror ("HDlseek"); - exit (EXIT_FAILURE); - } - if (HDwrite (dst, buf, 1)<0) { - perror ("write"); - exit (EXIT_FAILURE); - } + if (HDlseek (dst, dst_offset-1, SEEK_SET)<0) { + HDperror ("HDlseek"); + HDexit (EXIT_FAILURE); + } + if (HDread (dst, buf, 1)<0) { + HDperror ("read"); + HDexit (EXIT_FAILURE); + } + if (HDlseek (dst, dst_offset-1, SEEK_SET)<0) { + HDperror ("HDlseek"); + HDexit (EXIT_FAILURE); + } + if (HDwrite (dst, buf, 1)<0) { + HDperror ("write"); + HDexit (EXIT_FAILURE); + } } HDclose (dst); /* Modify family driver information saved in superblock through private property. * These private properties are for this tool only. */ - if ((fapl=H5Pcreate(H5P_FILE_ACCESS))<0) { - perror ("H5Pcreate"); - exit (EXIT_FAILURE); + if ((fapl=H5Pcreate(H5P_FILE_ACCESS)) < 0) { + HDperror ("H5Pcreate"); + HDexit (EXIT_FAILURE); } if(family_to_single) { @@ -433,23 +449,24 @@ main (int argc, char *argv[]) * the library to ignore the family driver information saved in the superblock. */ if(H5Pset(fapl, H5F_ACS_FAMILY_TO_SINGLE_NAME, &family_to_single) < 0) { - perror ("H5Pset"); - exit (EXIT_FAILURE); + HDperror ("H5Pset"); + HDexit (EXIT_FAILURE); } - } else { + } + else { /* Modify family size saved in superblock through private property. It signals * library to save the new member size(specified in command line) in superblock. * This private property is for this tool only. */ if(H5Pset_fapl_family(fapl, H5F_FAMILY_DEFAULT, H5P_DEFAULT) < 0) { - perror ("H5Pset_fapl_family"); - exit (EXIT_FAILURE); + HDperror ("H5Pset_fapl_family"); + HDexit (EXIT_FAILURE); } /* Set the property of the new member size as hsize_t */ hdsize = (hsize_t)dst_size; if(H5Pset(fapl, H5F_ACS_FAMILY_NEWSIZE_NAME, &hdsize) < 0) { - perror ("H5Pset"); - exit (EXIT_FAILURE); + HDperror ("H5Pset"); + HDexit (EXIT_FAILURE); } } @@ -465,16 +482,16 @@ main (int argc, char *argv[]) file = H5Fopen(dst_gen_name, H5F_ACC_RDWR, fapl); } H5E_END_TRY; - if(file>=0) { - if(H5Fclose(file)<0) { - perror ("H5Fclose"); - exit (EXIT_FAILURE); + if(file >= 0) { + if(H5Fclose(file) < 0) { + HDperror("H5Fclose"); + HDexit(EXIT_FAILURE); } /* end if */ } /* end if */ - if(H5Pclose(fapl)<0) { - perror ("H5Pclose"); - exit (EXIT_FAILURE); + if(H5Pclose(fapl) < 0) { + HDperror("H5Pclose"); + HDexit(EXIT_FAILURE); } /* end if */ /* Free resources and return */ |