diff options
Diffstat (limited to 'tools/src/misc/h5clear.c')
-rw-r--r-- | tools/src/misc/h5clear.c | 196 |
1 files changed, 97 insertions, 99 deletions
diff --git a/tools/src/misc/h5clear.c b/tools/src/misc/h5clear.c index 3bd570a..8294ae3 100644 --- a/tools/src/misc/h5clear.c +++ b/tools/src/misc/h5clear.c @@ -24,64 +24,60 @@ #include "h5tools_utils.h" /* Name of tool */ -#define PROGRAMNAME "h5clear" +#define PROGRAMNAME "h5clear" /* Make these private properties (defined in H5Fprivate.h) available to h5clear. */ -#define H5F_ACS_CLEAR_STATUS_FLAGS_NAME "clear_status_flags" -#define H5F_ACS_NULL_FSM_ADDR_NAME "null_fsm_addr" -#define H5F_ACS_SKIP_EOF_CHECK_NAME "skip_eof_check" +#define H5F_ACS_CLEAR_STATUS_FLAGS_NAME "clear_status_flags" +#define H5F_ACS_NULL_FSM_ADDR_NAME "null_fsm_addr" +#define H5F_ACS_SKIP_EOF_CHECK_NAME "skip_eof_check" /* Default increment is 1 megabytes for the --increment option */ -#define DEFAULT_INCREMENT 1024*1024 +#define DEFAULT_INCREMENT 1024 * 1024 -static char *fname_g = NULL; +static char * fname_g = NULL; static hbool_t clear_status_flags = FALSE; static hbool_t remove_cache_image = FALSE; -static hbool_t print_filesize = FALSE; -static hbool_t increment_eoa_eof = FALSE; -static hsize_t increment = DEFAULT_INCREMENT; +static hbool_t print_filesize = FALSE; +static hbool_t increment_eoa_eof = FALSE; +static hsize_t increment = DEFAULT_INCREMENT; /* * Command-line options: only publicize long options */ -static const char *s_opts = "hVsmzi*"; -static struct long_options l_opts[] = { - { "help", no_arg, 'h' }, - { "hel", no_arg, 'h'}, - { "he", no_arg, 'h'}, - { "version", no_arg, 'V' }, - { "version", no_arg, 'V' }, - { "versio", no_arg, 'V' }, - { "versi", no_arg, 'V' }, - { "vers", no_arg, 'V' }, - { "status", no_arg, 's' }, - { "statu", no_arg, 's' }, - { "stat", no_arg, 's' }, - { "sta", no_arg, 's' }, - { "st", no_arg, 's' }, - { "image", no_arg, 'm' }, - { "imag", no_arg, 'm' }, - { "ima", no_arg, 'm' }, - { "im", no_arg, 'm' }, - { "filesize", no_arg, 'z' }, - { "filesiz", no_arg, 'z' }, - { "filesi", no_arg, 'z' }, - { "files", no_arg, 'z' }, - { "file", no_arg, 'z' }, - { "fil", no_arg, 'z' }, - { "fi", no_arg, 'z' }, - { "increment", optional_arg, 'i' }, - { "incremen", optional_arg, 'i' }, - { "increme", optional_arg, 'i' }, - { "increm", optional_arg, 'i' }, - { "incre", optional_arg, 'i' }, - { "incr", optional_arg, 'i' }, - { "inc", optional_arg, 'i' }, - { "in", optional_arg, 'i' }, - { NULL, 0, '\0' } -}; - - +static const char * s_opts = "hVsmzi*"; +static struct long_options l_opts[] = {{"help", no_arg, 'h'}, + {"hel", no_arg, 'h'}, + {"he", no_arg, 'h'}, + {"version", no_arg, 'V'}, + {"version", no_arg, 'V'}, + {"versio", no_arg, 'V'}, + {"versi", no_arg, 'V'}, + {"vers", no_arg, 'V'}, + {"status", no_arg, 's'}, + {"statu", no_arg, 's'}, + {"stat", no_arg, 's'}, + {"sta", no_arg, 's'}, + {"st", no_arg, 's'}, + {"image", no_arg, 'm'}, + {"imag", no_arg, 'm'}, + {"ima", no_arg, 'm'}, + {"im", no_arg, 'm'}, + {"filesize", no_arg, 'z'}, + {"filesiz", no_arg, 'z'}, + {"filesi", no_arg, 'z'}, + {"files", no_arg, 'z'}, + {"file", no_arg, 'z'}, + {"fil", no_arg, 'z'}, + {"fi", no_arg, 'z'}, + {"increment", optional_arg, 'i'}, + {"incremen", optional_arg, 'i'}, + {"increme", optional_arg, 'i'}, + {"increm", optional_arg, 'i'}, + {"incre", optional_arg, 'i'}, + {"incr", optional_arg, 'i'}, + {"inc", optional_arg, 'i'}, + {"in", optional_arg, 'i'}, + {NULL, 0, '\0'}}; /*------------------------------------------------------------------------- * Function: usage @@ -92,7 +88,8 @@ static struct long_options l_opts[] = { * *------------------------------------------------------------------------- */ -static void usage(const char *prog) +static void +usage(const char *prog) { HDfprintf(stdout, "usage: %s [OPTIONS] file_name\n", prog); HDfprintf(stdout, " OPTIONS\n"); @@ -101,12 +98,17 @@ static void usage(const char *prog) HDfprintf(stdout, " -s, --status Clear the status_flags field in the file's superblock\n"); HDfprintf(stdout, " -m, --image Remove the metadata cache image from the file\n"); HDfprintf(stdout, " --filesize Print the file's EOA and EOF\n"); - HDfprintf(stdout, " --increment=C Set the file's EOA to the maximum of (EOA, EOF) + C for\n"); + HDfprintf(stdout, + " --increment=C Set the file's EOA to the maximum of (EOA, EOF) + C for\n"); HDfprintf(stdout, " the file <file_name>.\n"); - HDfprintf(stdout, " C is >= 0; C is optional and will default to 1M when not set.\n"); - HDfprintf(stdout, " This option helps to repair a crashed file where the stored EOA\n"); + HDfprintf(stdout, + " C is >= 0; C is optional and will default to 1M when not set.\n"); + HDfprintf( + stdout, + " This option helps to repair a crashed file where the stored EOA\n"); HDfprintf(stdout, " in the superblock is different from the actual EOF.\n"); - HDfprintf(stdout, " The file’s EOA and EOF will be the same after applying\n"); + HDfprintf(stdout, + " The file’s EOA and EOF will be the same after applying\n"); HDfprintf(stdout, " this option to the file.\n"); HDfprintf(stdout, "\n"); HDfprintf(stdout, "Examples of use:\n"); @@ -124,7 +126,6 @@ static void usage(const char *prog) HDfprintf(stdout, " Set the EOA to the maximum of (EOA, EOF) + 512 for the file <file_name>.\n"); } /* usage() */ - /*------------------------------------------------------------------------- * Function: parse_command_line * @@ -141,7 +142,7 @@ parse_command_line(int argc, const char **argv) { int opt; - /* no arguments */ + /* no arguments */ if (argc == 1) { usage(h5tools_getprogname()); h5tools_setstatus(EXIT_FAILURE); @@ -149,8 +150,8 @@ parse_command_line(int argc, const char **argv) } /* parse command line options */ - while((opt = get_option(argc, argv, s_opts, l_opts)) != EOF) { - switch((char)opt) { + while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF) { + switch ((char)opt) { case 'h': usage(h5tools_getprogname()); h5tools_setstatus(EXIT_SUCCESS); @@ -175,7 +176,7 @@ parse_command_line(int argc, const char **argv) case 'i': increment_eoa_eof = TRUE; - if(opt_arg != NULL) { + if (opt_arg != NULL) { if (HDatoi(opt_arg) < 0) { usage(h5tools_getprogname()); goto done; @@ -189,10 +190,10 @@ parse_command_line(int argc, const char **argv) h5tools_setstatus(EXIT_FAILURE); goto error; } /* end switch */ - } /* end while */ + } /* end while */ /* check for file name to be processed */ - if(argc <= opt_ind) { + if (argc <= opt_ind) { error_msg("missing file name\n"); usage(h5tools_getprogname()); h5tools_setstatus(EXIT_FAILURE); @@ -202,7 +203,7 @@ parse_command_line(int argc, const char **argv) fname_g = HDstrdup(argv[opt_ind]); done: - return(0); + return (0); error: return -1; @@ -224,8 +225,6 @@ leave(int ret) HDexit(ret); } /* leave() */ - - /*------------------------------------------------------------------------- * Function: main * @@ -254,14 +253,14 @@ leave(int ret) *------------------------------------------------------------------------- */ int -main (int argc, const char *argv[]) +main(int argc, const char *argv[]) { - char *fname = NULL; /* File name */ - hid_t fapl = H5I_INVALID_HID; /* File access property list */ - hid_t fid = H5I_INVALID_HID; /* File ID */ - haddr_t image_addr; - hsize_t image_len; - unsigned flags = H5F_ACC_RDWR; /* file access flags */ + char * fname = NULL; /* File name */ + hid_t fapl = H5I_INVALID_HID; /* File access property list */ + hid_t fid = H5I_INVALID_HID; /* File ID */ + haddr_t image_addr; + hsize_t image_len; + unsigned flags = H5F_ACC_RDWR; /* file access flags */ h5tools_setprogname(PROGRAMNAME); h5tools_setstatus(EXIT_SUCCESS); @@ -270,26 +269,24 @@ main (int argc, const char *argv[]) h5tools_init(); /* Parse command line options */ - if(parse_command_line(argc, argv) < 0) + if (parse_command_line(argc, argv) < 0) goto done; - if(fname_g == NULL) + if (fname_g == NULL) goto done; /* enable error reporting if command line option */ h5tools_error_report(); /* Print usage/exit if not using at least one of the options */ - if(!clear_status_flags && !remove_cache_image && - !increment_eoa_eof && !print_filesize) { + if (!clear_status_flags && !remove_cache_image && !increment_eoa_eof && !print_filesize) { usage(h5tools_getprogname()); h5tools_setstatus(EXIT_FAILURE); goto done; } /* Cannot combine the --filesize option with other options */ - if(print_filesize && - (clear_status_flags || remove_cache_image || increment_eoa_eof)) { + if (print_filesize && (clear_status_flags || remove_cache_image || increment_eoa_eof)) { error_msg("Cannot combine --filesize with other options\n"); h5tools_setstatus(EXIT_FAILURE); goto done; @@ -299,17 +296,17 @@ main (int argc, const char *argv[]) fname = HDstrdup(fname_g); /* Get a copy of the file access property list */ - if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) { + if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) { error_msg("H5Pcreate\n"); h5tools_setstatus(EXIT_FAILURE); goto done; - } + } /* -s option */ - if(clear_status_flags) { + if (clear_status_flags) { /* Set to clear the status_flags in the file's superblock */ /* Activate this private property */ - if(H5Pset(fapl, H5F_ACS_CLEAR_STATUS_FLAGS_NAME, &clear_status_flags) < 0) { + if (H5Pset(fapl, H5F_ACS_CLEAR_STATUS_FLAGS_NAME, &clear_status_flags) < 0) { error_msg("H5Pset\n"); h5tools_setstatus(EXIT_FAILURE); goto done; @@ -317,15 +314,15 @@ main (int argc, const char *argv[]) } /* --increment option */ - if(increment_eoa_eof) { + if (increment_eoa_eof) { /* Activate this private property */ - if(H5Pset(fapl, H5F_ACS_SKIP_EOF_CHECK_NAME, &increment_eoa_eof) < 0) { + if (H5Pset(fapl, H5F_ACS_SKIP_EOF_CHECK_NAME, &increment_eoa_eof) < 0) { error_msg("H5Pset\n"); h5tools_setstatus(EXIT_FAILURE); goto done; } /* Activate this private property */ - if(H5Pset(fapl, H5F_ACS_NULL_FSM_ADDR_NAME, &increment_eoa_eof) < 0) { + if (H5Pset(fapl, H5F_ACS_NULL_FSM_ADDR_NAME, &increment_eoa_eof) < 0) { error_msg("H5Pset\n"); h5tools_setstatus(EXIT_FAILURE); goto done; @@ -333,9 +330,9 @@ main (int argc, const char *argv[]) } /* --filesize option; open the file read-only */ - if(print_filesize) { + if (print_filesize) { /* Activate this private property */ - if(H5Pset(fapl, H5F_ACS_SKIP_EOF_CHECK_NAME, &print_filesize) < 0) { + if (H5Pset(fapl, H5F_ACS_SKIP_EOF_CHECK_NAME, &print_filesize) < 0) { error_msg("H5Pset\n"); h5tools_setstatus(EXIT_FAILURE); goto done; @@ -344,19 +341,19 @@ main (int argc, const char *argv[]) } /* Open the file */ - if((fid = h5tools_fopen(fname, flags, fapl, FALSE, NULL, (size_t)0)) < 0) { + if ((fid = h5tools_fopen(fname, flags, fapl, FALSE, NULL, (size_t)0)) < 0) { error_msg("h5tools_fopen\n"); h5tools_setstatus(EXIT_FAILURE); goto done; } /* --filesize option */ - if(print_filesize) { - h5_stat_t st; /* Stat info call */ - haddr_t eoa; /* The EOA value */ + if (print_filesize) { + h5_stat_t st; /* Stat info call */ + haddr_t eoa; /* The EOA value */ /* Get the file's EOA and EOF */ - if(H5Fget_eoa(fid, &eoa) < 0 || HDstat(fname, &st) < 0) { + if (H5Fget_eoa(fid, &eoa) < 0 || HDstat(fname, &st) < 0) { error_msg("H5Fget_eoa or HDstat\n"); h5tools_setstatus(EXIT_FAILURE); goto done; @@ -365,9 +362,9 @@ main (int argc, const char *argv[]) } /* --increment option */ - if(increment_eoa_eof) { + if (increment_eoa_eof) { /* Set the file's EOA to the maximum of (EOA, EOF) + increment */ - if(H5Fincrement_filesize(fid, increment) < 0) { + if (H5Fincrement_filesize(fid, increment) < 0) { error_msg("H5Fset_eoa\n"); h5tools_setstatus(EXIT_FAILURE); goto done; @@ -375,29 +372,30 @@ main (int argc, const char *argv[]) } /* -m option */ - if(remove_cache_image) { - if(H5Fget_mdc_image_info(fid, &image_addr, &image_len) < 0) { + if (remove_cache_image) { + if (H5Fget_mdc_image_info(fid, &image_addr, &image_len) < 0) { error_msg("H5Fget_mdc_image_info\n"); h5tools_setstatus(EXIT_FAILURE); goto done; } - if(image_addr == HADDR_UNDEF && image_len == 0) + if (image_addr == HADDR_UNDEF && image_len == 0) warn_msg("No cache image in the file\n"); } h5tools_setstatus(EXIT_SUCCESS); done: - if(fname) + if (fname) HDfree(fname); - if(fname_g) + if (fname_g) HDfree(fname_g); - H5E_BEGIN_TRY { + H5E_BEGIN_TRY + { H5Pclose(fapl); H5Fclose(fid); - } H5E_END_TRY + } + H5E_END_TRY leave(h5tools_getstatus()); } /* main() */ - |