Commit f97e3c8f authored by gsell's avatar gsell
Browse files

core API:

- debugging macros simplified
- cleanup
- h5_delete_attachment(): check of file mode added
parent fba78db1
Pipeline #9 skipped
......@@ -48,10 +48,11 @@ lib_LTLIBRARIES = libH5hut.la
libH5hut_la_SOURCES = \
h5_attachments.c \
h5_attribs.c \
h5_log.c \
h5_err.c \
h5_model.c \
h5_log.c \
h5_file.c \
h5_model.c \
h5_syscall.c \
h5u_io.c \
h5b_io.c \
h5u_model.c \
......
......@@ -32,13 +32,13 @@ h5_add_attachment (
H5_CORE_API_ENTER (h5_err_t, "f=%p, fname='%s'", f, fname);
// allowed file modes: O_RDWR, O_WRONLY; O_APPEND
if (f->props->flags & H5_O_RDONLY) {
H5_PRIV_FUNC_LEAVE (
H5_LEAVE (
h5priv_handle_file_mode_error (f->props->flags));
}
struct stat st;
if (stat (fname, &st) < 0) {
H5_CORE_API_LEAVE (
H5_LEAVE (
h5_error (
H5_ERR_HDF5,
"Cannot stat file '%s'",
......@@ -52,7 +52,7 @@ h5_add_attachment (
write_length = fsize;
int fd;
if ((fd = open (fname, O_RDONLY)) < 0) {
H5_CORE_API_LEAVE (
H5_LEAVE (
h5_error (
H5_ERR_HDF5,
"Cannot open file '%s' for reading",
......@@ -63,7 +63,7 @@ h5_add_attachment (
if (errno == EINTR) {
goto again;
} else {
H5_CORE_API_LEAVE (
H5_LEAVE (
h5_error (
H5_ERR_HDF5,
"Cannot read file '%s'",
......@@ -71,7 +71,7 @@ h5_add_attachment (
}
}
if (close (fd) < 0) {
H5_CORE_API_LEAVE (
H5_LEAVE (
h5_error (
H5_ERR_HDF5,
"Cannot close file '%s'",
......@@ -88,7 +88,7 @@ h5_add_attachment (
h5_err_t exists;
TRY (exists = hdf5_link_exists (loc_id, fname));
if (exists && (f->props->flags & H5_O_APPENDONLY)) {
H5_PRIV_FUNC_LEAVE (
H5_LEAVE (
h5priv_handle_file_mode_error (f->props->flags));
}
hid_t diskspace_id;
......@@ -125,7 +125,7 @@ h5_add_attachment (
TRY (h5_free (buf));
H5_CORE_API_RETURN (H5_SUCCESS);
H5_RETURN (H5_SUCCESS);
}
h5_err_t
......@@ -135,7 +135,7 @@ h5_has_attachments (
h5_file_p f = (h5_file_p)f_;
H5_CORE_API_ENTER (h5_ssize_t, "f=%p", f);
TRY (ret_value = hdf5_link_exists (f->file, H5_ATTACHMENT));
H5_CORE_API_RETURN (ret_value);
H5_RETURN (ret_value);
}
h5_ssize_t
......@@ -153,7 +153,7 @@ h5_get_num_attachments (
TRY (group_id = hdf5_open_group (f->file, H5_ATTACHMENT));
TRY (ret_value = hdf5_get_num_datasets (group_id));
TRY (hdf5_close_group (group_id));
H5_CORE_API_RETURN (ret_value);
H5_RETURN (ret_value);
}
h5_err_t
......@@ -184,7 +184,7 @@ h5_get_attachment_info_by_idx (
*fsize = ssize;
}
TRY (hdf5_close_group (loc_id));
H5_CORE_API_RETURN (H5_SUCCESS);
H5_RETURN (H5_SUCCESS);
}
h5_err_t
......@@ -197,7 +197,7 @@ h5_has_attachment (
hid_t loc_id;
TRY (loc_id = hdf5_open_group (f->file, H5_ATTACHMENT));
TRY (ret_value = hdf5_link_exists (f->file, fname));
H5_CORE_API_RETURN (ret_value);
H5_RETURN (ret_value);
}
h5_err_t
......@@ -218,7 +218,7 @@ h5_get_attachment_info_by_name (
*fsize = ssize;
}
TRY (hdf5_close_group (loc_id));
H5_CORE_API_RETURN (H5_SUCCESS);
H5_RETURN (H5_SUCCESS);
}
h5_err_t
......@@ -231,7 +231,7 @@ h5_get_attachment (
// allowed modes: O_RDWR, O_RDONLY; O_APPEND
// forbidden modes: O_WRONLY
if (f->props->flags & H5_O_WRONLY) {
H5_PRIV_FUNC_LEAVE (
H5_LEAVE (
h5priv_handle_file_mode_error (f->props->flags));
}
......@@ -248,11 +248,11 @@ h5_get_attachment (
hsize_t read_length;
char* buf = NULL;
if (f->myproc == 0) {
buf = malloc (fsize);
buf = h5_calloc (1, fsize);
read_length = fsize;
} else {
buf = malloc (1);
buf = h5_calloc (1, 1);
read_length = 0;
}
......@@ -284,21 +284,21 @@ h5_get_attachment (
if (f->myproc == 0) {
int fd;
if ((fd = open (fname, O_WRONLY|O_CREAT|O_TRUNC, 0600)) < 0) {
H5_CORE_API_LEAVE (
H5_LEAVE (
h5_error (
H5_ERR_H5,
"Error opening file '%s': %s",
fname, strerror(errno)));
}
if (write (fd, buf, fsize) != fsize) {
H5_CORE_API_LEAVE (
H5_LEAVE (
h5_error (
H5_ERR_H5,
"Error writing to file '%s': %s",
fname, strerror(errno)));
}
if (close (fd) < 0) {
H5_CORE_API_LEAVE (
H5_LEAVE (
h5_error (
H5_ERR_H5,
"Error closing file '%s': %s",
......@@ -307,7 +307,7 @@ h5_get_attachment (
}
TRY (h5_free (buf));
H5_CORE_API_RETURN (H5_SUCCESS);
H5_RETURN (H5_SUCCESS);
}
h5_err_t
......@@ -317,10 +317,15 @@ h5_delete_attachment (
) {
h5_file_p f = (h5_file_p)f_;
H5_CORE_API_ENTER (h5_err_t, "f=%p, fname='%s'", f, fname);
// allowed file modes: O_RDWR, O_WRONLY; O_APPEND
if (f->props->flags & H5_O_RDONLY) {
H5_LEAVE (
h5priv_handle_file_mode_error (f->props->flags));
}
hid_t loc_id;
TRY (loc_id = hdf5_open_group (f->file, H5_ATTACHMENT));
TRY (hdf5_delete_link (loc_id, fname, H5P_DEFAULT));
TRY (hdf5_close_group (loc_id));
H5_CORE_API_RETURN (H5_SUCCESS);
H5_RETURN (H5_SUCCESS);
}
......@@ -28,7 +28,7 @@ h5_has_file_attrib (
attrib_name);
CHECK_FILEHANDLE (f);
TRY (ret_value = hdf5_attribute_exists(f->root_gid, attrib_name));
H5_CORE_API_RETURN (ret_value);
H5_RETURN (ret_value);
}
h5_err_t
......@@ -44,7 +44,7 @@ h5_has_step_attrib (
attrib_name);
CHECK_FILEHANDLE (f);
TRY (ret_value = hdf5_attribute_exists (f->step_gid, attrib_name));
H5_CORE_API_RETURN (ret_value);
H5_RETURN (ret_value);
}
h5_ssize_t
......@@ -55,7 +55,7 @@ h5_get_num_file_attribs (
H5_CORE_API_ENTER (h5_ssize_t, "f=%p", f);
CHECK_FILEHANDLE (f);
TRY (ret_value = hdf5_get_num_attribute (f->root_gid));
H5_CORE_API_RETURN (ret_value);
H5_RETURN (ret_value);
}
h5_ssize_t
......@@ -67,7 +67,7 @@ h5_get_num_step_attribs (
CHECK_FILEHANDLE (f);
CHECK_TIMEGROUP (f);
TRY (ret_value = hdf5_get_num_attribute (f->step_gid));
H5_CORE_API_RETURN (ret_value);
H5_RETURN (ret_value);
}
h5_err_t
......@@ -95,7 +95,7 @@ h5_get_file_attrib_info_by_idx (
attrib_idx,
attrib_name, len_attrib_name,
attrib_type, attrib_nelem));
H5_CORE_API_RETURN (ret_value);
H5_RETURN (ret_value);
}
h5_err_t
......@@ -118,7 +118,7 @@ h5_get_file_attrib_info_by_name (
f->root_gid,
attrib_name,
attrib_type, attrib_nelem));
H5_CORE_API_RETURN (ret_value);
H5_RETURN (ret_value);
}
......@@ -148,7 +148,7 @@ h5_get_step_attrib_info_by_idx (
attrib_idx,
attrib_name, len_attrib_name,
attrib_type, attrib_nelem));
H5_CORE_API_RETURN (ret_value);
H5_RETURN (ret_value);
}
h5_err_t
......@@ -172,7 +172,7 @@ h5_get_step_attrib_info_by_name (
f->step_gid,
attrib_name,
attrib_type, attrib_nelem));
H5_CORE_API_RETURN (ret_value);
H5_RETURN (ret_value);
}
h5_err_t
......@@ -196,7 +196,7 @@ h5_read_file_attrib (
attrib_name,
attrib_type,
attrib_value));
H5_CORE_API_RETURN (ret_value);
H5_RETURN (ret_value);
}
h5_err_t
......@@ -222,7 +222,7 @@ h5_read_step_attrib (
attrib_name,
attrib_type,
attrib_value));
H5_CORE_API_RETURN (ret_value);
H5_RETURN (ret_value);
}
......@@ -252,7 +252,7 @@ h5_write_file_attrib (
attrib_value,
attrib_nelem,
!is_appendonly (f)));
H5_CORE_API_RETURN (ret_value);
H5_RETURN (ret_value);
}
h5_err_t
......@@ -282,7 +282,7 @@ h5_write_step_attrib (
attrib_value,
attrib_nelem,
!is_appendonly (f)));
H5_CORE_API_RETURN (ret_value);
H5_RETURN (ret_value);
}
......@@ -10,6 +10,7 @@
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include "h5core/h5_log.h"
......@@ -55,7 +56,7 @@ h5_get_hdf5_file(
) {
h5_file_p f = (h5_file_p)f_;
H5_CORE_API_ENTER (hid_t, "f=%p", f);
H5_CORE_API_RETURN (f->file);
H5_RETURN (f->file);
}
/*!
......@@ -140,7 +141,7 @@ mpi_init (
}
#endif
#endif /* PARALLEL_IO */
H5_INLINE_FUNC_RETURN (H5_SUCCESS);
H5_RETURN (H5_SUCCESS);
}
static inline h5_err_t
......@@ -162,7 +163,7 @@ set_alignment (
(long long int)f->props->align);
TRY (H5Pset_meta_block_size (f->props->access_prop, f->props->align));
}
H5_INLINE_FUNC_RETURN (H5_SUCCESS);
H5_RETURN (H5_SUCCESS);
}
static inline h5_err_t
......@@ -180,7 +181,7 @@ set_default_file_props (
H5_STEPNAME_LEN - 1);
props->width_step_idx = H5_STEPWIDTH;
props->comm = MPI_COMM_WORLD;
H5_INLINE_FUNC_RETURN (H5_SUCCESS);
H5_RETURN (H5_SUCCESS);
}
h5_err_t
......@@ -192,7 +193,7 @@ h5_set_prop_file_mpio_collective (
H5_CORE_API_ENTER (h5_err_t, "props=%p, comm=%p", props, comm);
if (props->class != H5_PROP_FILE) {
H5_INLINE_FUNC_LEAVE (
H5_LEAVE (
h5_error (
H5_ERR_INVAL,
"Invalid property class: %lld",
......@@ -206,7 +207,7 @@ h5_set_prop_file_mpio_collective (
props->throttle = 0;
}
H5_CORE_API_RETURN (H5_SUCCESS);
H5_RETURN (H5_SUCCESS);
}
h5_err_t
......@@ -218,7 +219,7 @@ h5_set_prop_file_mpio_independent (
H5_CORE_API_ENTER (h5_err_t, "props=%p, comm=%p", props, comm);
if (props->class != H5_PROP_FILE) {
H5_INLINE_FUNC_LEAVE (
H5_LEAVE (
h5_error (
H5_ERR_INVAL,
"Invalid property class: %lld",
......@@ -227,7 +228,7 @@ h5_set_prop_file_mpio_independent (
props->flags &= ~(H5_VFD_MPIO_COLLECTIVE | H5_VFD_MPIO_POSIX | H5_VFD_CORE);
props->flags |= H5_VFD_MPIO_INDEPENDENT;
props->comm = *comm;
H5_CORE_API_RETURN (H5_SUCCESS);
H5_RETURN (H5_SUCCESS);
}
#if H5_VERSION_LE(1,8,12)
......@@ -240,7 +241,7 @@ h5_set_prop_file_mpio_posix (
H5_CORE_API_ENTER (h5_err_t, "props=%p, comm=%p", props, comm);
if (props->class != H5_PROP_FILE) {
H5_INLINE_FUNC_LEAVE (
H5_LEAVE (
h5_error (
H5_ERR_INVAL,
"Invalid property class: %lld",
......@@ -249,7 +250,7 @@ h5_set_prop_file_mpio_posix (
props->flags &= ~(H5_VFD_MPIO_COLLECTIVE | H5_VFD_MPIO_POSIX | H5_VFD_CORE);
props->flags |= H5_VFD_MPIO_INDEPENDENT;
props->comm = *comm;
H5_CORE_API_RETURN (H5_SUCCESS);
H5_RETURN (H5_SUCCESS);
}
#endif
......@@ -262,7 +263,7 @@ h5_set_prop_file_core_vfd (
H5_CORE_API_ENTER (h5_err_t, "props=%p, increment=%lld", props, (long long int)increment);
if (props->class != H5_PROP_FILE) {
H5_INLINE_FUNC_LEAVE (
H5_LEAVE (
h5_error (
H5_ERR_INVAL,
"Invalid property class: %lld",
......@@ -276,7 +277,7 @@ h5_set_prop_file_core_vfd (
h5_warn ("Throttling is not permitted with core VFD. Reset throttling.");
props->throttle = 0;
}
H5_CORE_API_RETURN (H5_SUCCESS);
H5_RETURN (H5_SUCCESS);
}
......@@ -291,14 +292,14 @@ h5_set_prop_file_align (
"props=%p, align=%lld",
props, (long long int)align);
if (props->class != H5_PROP_FILE) {
H5_INLINE_FUNC_LEAVE (
H5_LEAVE (
h5_error (
H5_ERR_INVAL,
"Invalid property class: %lld",
(long long int)props->class));
}
props->align = align;
H5_CORE_API_RETURN (H5_SUCCESS);
H5_RETURN (H5_SUCCESS);
}
h5_err_t
......@@ -312,7 +313,7 @@ h5_set_prop_file_throttle (
"props=%p, throttle=%lld",
props, (long long int)throttle);
if (props->class != H5_PROP_FILE) {
H5_CORE_API_LEAVE (
H5_LEAVE (
h5_error (
H5_ERR_INVAL,
"Invalid property class: %lld",
......@@ -337,7 +338,7 @@ h5_set_prop_file_throttle (
}
props->throttle = throttle;
H5_CORE_API_RETURN (H5_SUCCESS);
H5_RETURN (H5_SUCCESS);
}
......@@ -356,13 +357,13 @@ h5_create_prop (
set_default_file_props ((h5_prop_file_t*)prop);
break;
default:
H5_CORE_API_LEAVE (
H5_LEAVE (
h5_error (
H5_ERR_INVAL,
"Invalid property class: %lld",
(long long int)class));
}
H5_CORE_API_RETURN ((h5_prop_t)prop);
H5_RETURN ((h5_prop_t)prop);
}
h5_err_t
......@@ -378,13 +379,13 @@ h5_close_prop (
break;
}
default:
H5_CORE_API_LEAVE (
H5_LEAVE (
h5_error (
H5_ERR_INVAL,
"Invalid property class: %lld",
(long long int)prop->class));
}
H5_CORE_API_RETURN (h5_free (prop));
H5_RETURN (h5_free (prop));
}
static inline h5_err_t
......@@ -440,7 +441,7 @@ open_file (
}
}
else {
H5_PRIV_FUNC_LEAVE (
H5_LEAVE (
h5_error (
H5_ERR_INVAL,
"Invalid file access mode '%lld'.",
......@@ -448,7 +449,7 @@ open_file (
}
if (f->file < 0)
H5_PRIV_FUNC_LEAVE (
H5_LEAVE (
h5_error (
H5_ERR_HDF5,
"Cannot open file '%s' with mode '%s'",
......@@ -458,7 +459,7 @@ open_file (
TRY (h5upriv_open_file (f));
TRY (h5bpriv_open_file (f));
H5_INLINE_FUNC_RETURN (H5_SUCCESS);
H5_RETURN (H5_SUCCESS);
}
h5_file_t
......@@ -481,7 +482,7 @@ h5_open_file2 (
if (props != H5_PROP_DEFAULT) {
if (props->class != H5_PROP_FILE) {
H5_CORE_API_LEAVE (
H5_LEAVE (
h5_error (
H5_ERR_INVAL,
"Invalid property class: %lld.",
......@@ -501,7 +502,7 @@ h5_open_file2 (
TRY (open_file (f, filename, mode));
H5_CORE_API_RETURN ((h5_file_t)f);
H5_RETURN ((h5_file_t)f);
}
/*!
......@@ -539,7 +540,7 @@ h5_open_file1 (
TRY (f = h5_open_file2 (filename, mode, (h5_prop_t)props));
TRY (h5_close_prop ((h5_prop_t)props));
h5_file_p _f = (h5_file_p)f;
H5_CORE_API_RETURN (_f);
H5_RETURN (_f);
}
......@@ -574,7 +575,7 @@ h5_close_file (
TRY (hdf5_close_file (f->file));
TRY (h5_free (f->step_name));
TRY (h5_free (f));
H5_CORE_API_RETURN (H5_SUCCESS);
H5_RETURN (H5_SUCCESS);
}
h5_err_t
......@@ -583,7 +584,7 @@ h5_close_hdf5 (
) {
H5_CORE_API_ENTER (h5_err_t, "%s", "");
TRY (ret_value = hdf5_close ());
H5_CORE_API_RETURN (ret_value);
H5_RETURN (ret_value);
}
h5_err_t
......@@ -593,7 +594,7 @@ h5_flush_step (
h5_file_p f = (h5_file_p)f_;
H5_CORE_API_ENTER (h5_err_t, "f=%p", f);
TRY (ret_value = hdf5_flush (f->step_gid, H5F_SCOPE_LOCAL));
H5_CORE_API_RETURN (ret_value);
H5_RETURN (ret_value);
}
h5_err_t
......@@ -603,7 +604,7 @@ h5_flush_file (
h5_file_p f = (h5_file_p)f_;
H5_CORE_API_ENTER (h5_err_t, "f=%p", f);
TRY (ret_value = hdf5_flush (f->file, H5F_SCOPE_GLOBAL));
H5_CORE_API_RETURN (ret_value);
H5_RETURN (ret_value);
}
......@@ -635,7 +636,7 @@ h5_set_stepname_fmt (
H5_STEPNAME_LEN - 1);
f->props->width_step_idx = width;
H5_CORE_API_RETURN (H5_SUCCESS);
H5_RETURN (H5_SUCCESS);
}
/*!
......@@ -673,7 +674,7 @@ h5_get_step (
) {
h5_file_p f = (h5_file_p)f_;
H5_CORE_API_ENTER (h5_id_t, "f=%p", f);
H5_CORE_API_RETURN (f->step_idx);
H5_RETURN (f->step_idx);
}
/*!
......@@ -689,7 +690,7 @@ h5_get_num_procs (
) {
h5_file_p f = (h5_file_p)f_;
H5_CORE_API_ENTER (int, "f=%p", f);
H5_CORE_API_RETURN (f->nprocs);
H5_RETURN (f->nprocs);
}
/*!
......@@ -708,7 +709,7 @@ h5_get_num_steps(
TRY (ret_value = hdf5_get_num_groups_matching_prefix (
f->root_gid,
f->props->prefix_step_name));
H5_CORE_API_RETURN (ret_value);
H5_RETURN (ret_value);
}
/*!
......@@ -731,7 +732,7 @@ h5_start_traverse_steps (
loop over all steps and get smallest step number
*/
H5_CORE_API_RETURN (h5_error_not_implemented ());
H5_RETURN (h5_error_not_implemented ());
}
/*!
......
......@@ -20,12 +20,12 @@ h5priv_close_step (
) {
H5_PRIV_API_ENTER (h5_err_t, "f=%p", f);
if (f->step_gid <= 0)
H5_PRIV_API_LEAVE (H5_SUCCESS);
H5_LEAVE (H5_SUCCESS);
TRY (hdf5_close_group (f->step_gid));
f->step_gid = -1;
H5_PRIV_API_RETURN (H5_SUCCESS);
H5_RETURN (H5_SUCCESS);
}
h5_err_t
......@@ -53,7 +53,7 @@ h5_set_step (
TRY (f->step_gid = h5priv_open_group (is_writable(f),
f->file,
f->step_name));
H5_CORE_API_RETURN (H5_SUCCESS);
H5_RETURN (H5_SUCCESS);
}
/*
......@@ -75,7 +75,7 @@ h5_has_step (
f->props->prefix_step_name, f->props->width_step_idx,
(long long)step_idx);
TRY (ret_value = hdf5_link_exists (f->file, name));
H5_CORE_API_RETURN (ret_value);
H5_RETURN (ret_value);
}
h5_err_t
......@@ -93,12 +93,12 @@ h5priv_normalize_dataset_name (
}
if ( strcmp( name2, H5BLOCK_GROUPNAME_BLOCK ) == 0 ) {
H5_CORE_API_LEAVE (
H5_LEAVE (
h5_error (
H5_ERR_INVAL,
"Can't create dataset or field with name '%s'"
" because it is reserved by H5Block.",
H5BLOCK_GROUPNAME_BLOCK));
}
H5_CORE_API_RETURN (H5_SUCCESS);
H5_RETURN (H5_SUCCESS);
}
/*
Copyright (c) 2006-2016, The Regents of the University of California,
through Lawrence Berkeley National Laboratory (subject to receipt of any
required approvals from the U.S. Dept. of Energy) and the Paul Scherrer
Institut (Switzerland). All rights reserved.
License: see file COPYING in top level of source distribution.
*/