//-------------------------------------------------------------------------- // Function: FileAccPropList::setSplit ///\brief Emulates the old split file driver, which stored meta data /// in one file and raw data in another file. ///\param meta_plist - IN: File access plist for the metadata file ///\param raw_plist - IN: File access plist for the raw data file ///\param meta_ext - IN: Metadata filename extension as \c char* ///\param raw_ext - IN: Raw data filename extension as \c char* ///\exception H5::PropListIException ///\par Description /// Temporary - For information, please refer to: /// <A HREF="../RM_H5P.html#Property-SetFaplSplit">../RM_H5P.html#Property-SetFaplSplit</A> // Programmer: Binh-Minh Ribler - April, 2004 //-------------------------------------------------------------------------- void FileAccPropList::setSplit( FileAccPropList& meta_plist, FileAccPropList& raw_plist, const char* meta_ext, const char* raw_ext ) const { hid_t meta_pid = meta_plist.getId(); hid_t raw_pid = raw_plist.getId(); herr_t ret_value = H5Pset_fapl_split( id, meta_ext, meta_pid, raw_ext, raw_pid ); if( ret_value < 0 ) { throw PropListIException("FileAccPropList::setSplit", "H5Pset_fapl_split failed"); } }
/* * Create the appropriate File access property list */ hid_t create_faccess_plist(MPI_Comm comm, MPI_Info info, int l_facc_type, hbool_t use_gpfs) { hid_t ret_pl = -1; herr_t ret; /* generic return value */ int mpi_rank; /* mpi variables */ /* need the rank for error checking macros */ MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank); ret_pl = H5Pcreate (H5P_FILE_ACCESS); VRFY((ret_pl >= 0), "H5P_FILE_ACCESS"); if (l_facc_type == FACC_DEFAULT) return (ret_pl); if (l_facc_type == FACC_MPIO) { /* set Parallel access with communicator */ ret = H5Pset_fapl_mpio(ret_pl, comm, info); VRFY((ret >= 0), ""); return(ret_pl); } if (l_facc_type == (FACC_MPIO | FACC_SPLIT)) { hid_t mpio_pl; mpio_pl = H5Pcreate (H5P_FILE_ACCESS); VRFY((mpio_pl >= 0), ""); /* set Parallel access with communicator */ ret = H5Pset_fapl_mpio(mpio_pl, comm, info); VRFY((ret >= 0), ""); /* setup file access template */ ret_pl = H5Pcreate (H5P_FILE_ACCESS); VRFY((ret_pl >= 0), ""); /* set Parallel access with communicator */ ret = H5Pset_fapl_split(ret_pl, ".meta", mpio_pl, ".raw", mpio_pl); VRFY((ret >= 0), "H5Pset_fapl_split succeeded"); H5Pclose(mpio_pl); return(ret_pl); } if (l_facc_type == FACC_MPIPOSIX) { /* set Parallel access with communicator */ ret = H5Pset_fapl_mpiposix(ret_pl, comm, use_gpfs); VRFY((ret >= 0), "H5Pset_fapl_mpiposix succeeded"); return(ret_pl); } /* unknown file access types */ return (ret_pl); }
/*------------------------------------------------------------------------- * 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) { 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-memory driver settings (backing store on, 1 MB increment) */ if (H5Pset_fapl_core(fapl, (size_t)1, TRUE)<0) return -1; } else if (!HDstrcmp(name, "core_paged")) { /* In-memory driver with write tracking and paging on */ if (H5Pset_fapl_core(fapl, (size_t)1, TRUE)<0) return -1; if (H5Pset_core_write_tracking(fapl, TRUE, (size_t)4096)<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); HDassert(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; 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); } /* end for */ 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")) { unsigned log_flags = H5FD_LOG_LOC_IO | H5FD_LOG_ALLOC; /* Log file access */ if ((val = HDstrtok(NULL, " \t\n\r"))) log_flags = (unsigned)HDstrtol(val, NULL, 0); if (H5Pset_fapl_log(fapl, NULL, log_flags, (size_t)0) < 0) return -1; } else if (!HDstrcmp(name, "direct")) { #ifdef H5_HAVE_DIRECT /* Linux direct read() and write() system calls. Set memory boundary, file block size, * and copy buffer size to the default values. */ if (H5Pset_fapl_direct(fapl, 1024, 4096, 8*4096)<0) return -1; #endif } else if(!HDstrcmp(name, "latest")) { /* use the latest format */ if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) return -1; } else { /* Unknown driver */ return -1; } return fapl; }
hid_t set_vfd(parameters *param) { hid_t my_fapl = -1; vfdtype vfd; vfd = param->vfd; if ((my_fapl=H5Pcreate(H5P_FILE_ACCESS))<0) return -1; if (vfd == sec2) { /* Unix read() and write() system calls */ if (H5Pset_fapl_sec2(my_fapl)<0) return -1; } else if (vfd == stdio) { /* Standard C fread() and fwrite() system calls */ if (H5Pset_fapl_stdio(my_fapl)<0) return -1; } else if (vfd == core) { /* In-core temporary file with 1MB increment */ if (H5Pset_fapl_core(my_fapl, (size_t)1024*1024, TRUE)<0) return -1; } else if (vfd == split) { /* Split meta data and raw data each using default driver */ if (H5Pset_fapl_split(my_fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT)<0) return -1; } else if (vfd == 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); HDassert(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; 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); } if (H5Pset_fapl_multi(my_fapl, memb_map, memb_fapl, memb_name, memb_addr, FALSE)<0) { return -1; } } else if (vfd == family) { hsize_t fam_size = 1*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(my_fapl, fam_size, H5P_DEFAULT)<0) return -1; } else if (vfd == direct) { #ifdef H5_HAVE_DIRECT /* Linux direct read() and write() system calls. Set memory boundary, file block size, * and copy buffer size to the default values. */ if (H5Pset_fapl_direct(my_fapl, 1024, 4096, 8*4096)<0) return -1; #endif } else { /* Unknown driver */ return -1; } return my_fapl; }
/*------------------------------------------------------------------------- * Function: main * * Purpose: To create HDF5 files with non-zero status_flags in the superblock * via flushing and exiting without closing the library. * * Due to file locking, status_flag in the superblock will be * nonzero after H5Fcreate. The library will clear status_flags * on file closing. This program, after "H5Fcreate" the files, * exits without going through library closing. Thus, status_flags * for these files are not cleared and users cannot open them. * * These files are used by "h5clear" to see if the tool clears * status_flags properly so users can open the files afterwards. * * Return: Success: 0 * Failure: 1 * * Programmer: Vailin Choi; July 2013 * *------------------------------------------------------------------------- */ int main(void) { hid_t fid; /* File ID */ hid_t fapl, new_fapl; /* File access property lists */ char fname[512]; /* File name */ hbool_t new_format; /* To use latest library format or not */ int fd; /* File descriptor */ uint8_t super_vers; /* Superblock version */ ssize_t bytes_written; /* The # of bytes written to the file */ /* Create a copy of the file access property list */ if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0) goto error; /* Copy the file access property list */ if((new_fapl = H5Pcopy(fapl)) < 0) goto error; /* Set to latest library format */ if(H5Pset_libver_bounds(new_fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) goto error; /* Create file with/without latest library format */ for(new_format = FALSE; new_format <= TRUE; new_format++) { hid_t fapl2, my_fapl; /* File access property lists */ /* Set to use the appropriate file access property list */ if(new_format) fapl2 = new_fapl; else fapl2 = fapl; /* * Create a sec2 file */ if((my_fapl = H5Pcopy(fapl2)) < 0) goto error; /* Create the file */ sprintf(fname, "%s%s", new_format? "latest_":"", FILENAME[0]); if((fid = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, my_fapl)) < 0) goto error; /* Flush the file */ if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0) goto error; /* Close the property list */ if(H5Pclose(my_fapl) < 0) goto error; /* * Create a core file */ /* Create a copy of file access property list */ if((my_fapl = H5Pcopy(fapl2)) < 0) goto error; /* Setup the fapl for the family file driver */ if(H5Pset_fapl_core(my_fapl, (size_t)CORE_INCREMENT, TRUE) < 0) goto error; /* Create the file */ sprintf(fname, "%s%s", new_format? "latest_":"", FILENAME[1]); if((fid = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, my_fapl)) < 0) goto error; /* Flush the file */ if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0) goto error; /* Close the property list */ if(H5Pclose(my_fapl) < 0) goto error; /* * Create a family file */ /* Create a copy of file access property list */ if((my_fapl = H5Pcopy(fapl2)) < 0) goto error; /* Setup the fapl for the family file driver */ if(H5Pset_fapl_family(my_fapl, (hsize_t)FAMILY_SIZE, H5P_DEFAULT) < 0) goto error; /* Create the file */ sprintf(fname, "%s%s", new_format? "latest_":"", FILENAME[2]); if((fid = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, my_fapl)) < 0) goto error; /* Flush the file */ if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0) goto error; /* Close the property list */ if(H5Pclose(my_fapl) < 0) goto error; /* * Create a split file */ /* Create a copy of file access property list */ my_fapl = H5Pcopy(fapl2); /* Setup the fapl for the split file driver */ H5Pset_fapl_split(my_fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT); /* Create the file */ sprintf(fname, "%s%s", new_format? "latest_":"", FILENAME[3]); if((fid = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, my_fapl)) < 0) goto error; /* Flush the file */ if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0) goto error; /* Close the property list */ if(H5Pclose(my_fapl) < 0) goto error; /* * Create a sec2 file but change its superblock version # */ /* Create a copy of file access property list */ if((my_fapl = H5Pcopy(fapl2)) < 0) goto error; /* Create the file */ sprintf(fname, "%s%s", new_format? "latest_":"", FILENAME[4]); if((fid = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, my_fapl)) < 0) goto error; /* Flush the file */ if(H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0) goto error; /* Close the property list */ if(H5Pclose(my_fapl) < 0) goto error; /* Open the test file via system call "open" */ if((fd = HDopen(fname, O_RDWR, 0666)) < 0) { HDfprintf(stdout, "cannot open the file\n"); goto error; } /* Position the file to superblock version via system call "lseek" */ if(HDlseek(fd, (off_t)SUPER_VERS_OFF, SEEK_SET) < 0) { HDfprintf(stdout, "cannot lseek the file superblock version\n"); goto error; } /* Change to an incorrect superblock version */ super_vers = SUPER_VERS_LATEST + 1; /* Write to the file via system call "write" */ if((bytes_written = HDwrite(fd, &super_vers, (size_t)SUPER_VERS_SIZE)) < 0) { HDfprintf(stdout, "cannot write to the file with incorrect superblock version\n"); goto error; } /* Close the file via system call "close" */ if(HDclose(fd) < 0) { HDfprintf(stdout, "cannot close the file\n"); goto error; } } /* end for */ /* Close the property lists */ if(H5Pclose(fapl) < 0) goto error; if(H5Pclose(new_fapl) < 0) goto error; fflush(stdout); fflush(stderr); /* Not going through library closing by calling _exit(0) with success */ HD_exit(0); error: /* Exit with failure */ HD_exit(1); }