From aac2bb6182878e3591de390173e769bb761c83e2 Mon Sep 17 00:00:00 2001 From: Mohamad Chaarawi Date: Tue, 20 Jan 2015 12:17:05 -0500 Subject: [svn-r25984] change the message flag H5O_MSG_FLAG_FAIL_IF_UNKNOWN to H5O_MSG_FLAG_FAIL_IF_UNKNOWN_AND_OPEN_FOR_WRITE. Will add a new H5O_MSG_FLAG_FAIL_IF_UNKNOWN_ALWAYS with the new avoid_truncate patch coming later. tested h5committest --- src/H5Obogus.c | 12 ++++++------ src/H5Ocache.c | 5 +++-- src/H5Odbg.c | 2 +- src/H5Oprivate.h | 4 ++-- test/gen_bogus.c | 2 +- test/ohdr.c | 33 +++++++++++++++++++++++++-------- test/tbogus.h5 | Bin 1944 -> 1944 bytes 7 files changed, 38 insertions(+), 20 deletions(-) diff --git a/src/H5Obogus.c b/src/H5Obogus.c index cee3199..d930683 100644 --- a/src/H5Obogus.c +++ b/src/H5Obogus.c @@ -87,20 +87,20 @@ const H5O_msg_class_t H5O_MSG_BOGUS[1] = {{ *------------------------------------------------------------------------- */ static void * -H5O_bogus_decode(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, H5O_t UNUSED *open_oh, +H5O_bogus_decode(H5F_t *f, hid_t UNUSED dxpl_id, H5O_t UNUSED *open_oh, unsigned UNUSED mesg_flags, unsigned UNUSED *ioflags, const uint8_t *p) { H5O_bogus_t *mesg = NULL; void *ret_value; /* Return value */ - FUNC_ENTER_NOAPI_NOINIT(H5O_bogus_decode) + FUNC_ENTER_NOAPI_NOINIT /* check args */ HDassert(f); HDassert(p); /* Allocate the bogus message */ - if(NULL == (mesg = H5MM_calloc(sizeof(H5O_bogus_t)))) + if(NULL == (mesg = (H5O_bogus_t *)H5MM_calloc(sizeof(H5O_bogus_t)))) HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed") /* decode */ @@ -137,7 +137,7 @@ done: static herr_t H5O_bogus_encode(H5F_t UNUSED *f, hbool_t UNUSED disable_shared, uint8_t *p, const void UNUSED *mesg) { - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_bogus_encode) + FUNC_ENTER_NOAPI_NOINIT_NOERR /* check args */ HDassert(f); @@ -172,7 +172,7 @@ H5O_bogus_encode(H5F_t UNUSED *f, hbool_t UNUSED disable_shared, uint8_t *p, con static size_t H5O_bogus_size(const H5F_t UNUSED *f, hbool_t UNUSED disable_shared, const void UNUSED *mesg) { - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_bogus_size) + FUNC_ENTER_NOAPI_NOINIT_NOERR FUNC_LEAVE_NOAPI(4) } /* end H5O_bogus_size() */ @@ -199,7 +199,7 @@ H5O_bogus_debug(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, const void *_mesg, FILE * { const H5O_bogus_t *mesg = (const H5O_bogus_t *)_mesg; - FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5O_bogus_debug) + FUNC_ENTER_NOAPI_NOINIT_NOERR /* check args */ HDassert(f); diff --git a/src/H5Ocache.c b/src/H5Ocache.c index 847bf71..b3dea03 100644 --- a/src/H5Ocache.c +++ b/src/H5Ocache.c @@ -1132,7 +1132,7 @@ H5O_chunk_deserialize(H5O_t *oh, haddr_t addr, size_t len, const uint8_t *image, HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "unknown flag for message") if((flags & H5O_MSG_FLAG_SHARED) && (flags & H5O_MSG_FLAG_DONTSHARE)) HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "bad flag combination for message") - if((flags & H5O_MSG_FLAG_WAS_UNKNOWN) && (flags & H5O_MSG_FLAG_FAIL_IF_UNKNOWN)) + if((flags & H5O_MSG_FLAG_WAS_UNKNOWN) && (flags & H5O_MSG_FLAG_FAIL_IF_UNKNOWN_AND_OPEN_FOR_WRITE)) HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "bad flag combination for message") if((flags & H5O_MSG_FLAG_WAS_UNKNOWN) && !(flags & H5O_MSG_FLAG_MARK_IF_UNKNOWN)) HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, FAIL, "bad flag combination for message") @@ -1208,7 +1208,8 @@ H5O_chunk_deserialize(H5O_t *oh, haddr_t addr, size_t len, const uint8_t *image, oh->mesg[mesgno].type = H5O_msg_class_g[H5O_UNKNOWN_ID]; /* Check for "fail if unknown" message flag */ - if(flags & H5O_MSG_FLAG_FAIL_IF_UNKNOWN) + if((udata->file_intent & H5F_ACC_RDWR) && + (flags & H5O_MSG_FLAG_FAIL_IF_UNKNOWN_AND_OPEN_FOR_WRITE)) HGOTO_ERROR(H5E_OHDR, H5E_BADMESG, FAIL, "unknown message with 'fail if unknown' flag found") /* Check for "mark if unknown" message flag, etc. */ else if((flags & H5O_MSG_FLAG_MARK_IF_UNKNOWN) && diff --git a/src/H5Odbg.c b/src/H5Odbg.c index b91a51a..0531a90 100644 --- a/src/H5Odbg.c +++ b/src/H5Odbg.c @@ -466,7 +466,7 @@ H5O_debug_real(H5F_t *f, hid_t dxpl_id, H5O_t *oh, haddr_t addr, FILE *stream, i HDfprintf(stream, "%sDS", (flag_printed ? ", " : "<")); flag_printed = TRUE; } /* end if */ - if(oh->mesg[i].flags & H5O_MSG_FLAG_FAIL_IF_UNKNOWN) { + if(oh->mesg[i].flags & H5O_MSG_FLAG_FAIL_IF_UNKNOWN_AND_OPEN_FOR_WRITE) { HDfprintf(stream, "%sFIU", (flag_printed ? ", " : "<")); flag_printed = TRUE; } /* end if */ diff --git a/src/H5Oprivate.h b/src/H5Oprivate.h index d5cd621..e3a2d33 100644 --- a/src/H5Oprivate.h +++ b/src/H5Oprivate.h @@ -70,11 +70,11 @@ typedef struct H5O_t H5O_t; #define H5O_MSG_FLAG_CONSTANT 0x01u #define H5O_MSG_FLAG_SHARED 0x02u #define H5O_MSG_FLAG_DONTSHARE 0x04u -#define H5O_MSG_FLAG_FAIL_IF_UNKNOWN 0x08u +#define H5O_MSG_FLAG_FAIL_IF_UNKNOWN_AND_OPEN_FOR_WRITE 0x08u #define H5O_MSG_FLAG_MARK_IF_UNKNOWN 0x10u #define H5O_MSG_FLAG_WAS_UNKNOWN 0x20u #define H5O_MSG_FLAG_SHAREABLE 0x40u -#define H5O_MSG_FLAG_BITS (H5O_MSG_FLAG_CONSTANT|H5O_MSG_FLAG_SHARED|H5O_MSG_FLAG_DONTSHARE|H5O_MSG_FLAG_FAIL_IF_UNKNOWN|H5O_MSG_FLAG_MARK_IF_UNKNOWN|H5O_MSG_FLAG_WAS_UNKNOWN|H5O_MSG_FLAG_SHAREABLE) +#define H5O_MSG_FLAG_BITS (H5O_MSG_FLAG_CONSTANT|H5O_MSG_FLAG_SHARED|H5O_MSG_FLAG_DONTSHARE|H5O_MSG_FLAG_FAIL_IF_UNKNOWN_AND_OPEN_FOR_WRITE|H5O_MSG_FLAG_MARK_IF_UNKNOWN|H5O_MSG_FLAG_WAS_UNKNOWN|H5O_MSG_FLAG_SHAREABLE) /* Flags for updating messages */ #define H5O_UPDATE_TIME 0x01u diff --git a/test/gen_bogus.c b/test/gen_bogus.c index 7d8d073..df1e81f 100644 --- a/test/gen_bogus.c +++ b/test/gen_bogus.c @@ -62,7 +62,7 @@ int main(void) if(H5Dclose(did) < 0) goto error; /* Set "fail if unknown" message flag for bogus message */ - bogus_flags = H5O_MSG_FLAG_FAIL_IF_UNKNOWN; + bogus_flags = H5O_MSG_FLAG_FAIL_IF_UNKNOWN_AND_OPEN_FOR_WRITE; if(H5Pset(dcpl, H5O_BOGUS_MSG_FLAGS_NAME, &bogus_flags) < 0) goto error; /* Create second dataset, with "fail if unknown" message flag */ diff --git a/test/ohdr.c b/test/ohdr.c index 502a8b1..0ed3d97 100644 --- a/test/ohdr.c +++ b/test/ohdr.c @@ -687,16 +687,13 @@ main(void) PASSED(); - TESTING("object with unknown header message & 'fail if unknown' flag set"); + TESTING("object with unknown header message & 'fail if unknown and open for write' flag set"); - /* Attempt to open the dataset with the unknown header message, and "fail if unknown" flag */ - H5E_BEGIN_TRY { - dset = H5Dopen2(file2, "/Dataset2", H5P_DEFAULT); - } H5E_END_TRY; - if(dset >= 0) { - H5Dclose(dset); + /* Open the dataset with the unknown header message, and "fail if unknown and open for write" flag */ + if((dset = H5Dopen2(file2, "/Dataset2", H5P_DEFAULT)) < 0) + TEST_ERROR + if(H5Dclose(dset) < 0) TEST_ERROR - } /* end if */ PASSED(); @@ -778,6 +775,26 @@ main(void) if(H5Dclose(dset) < 0) TEST_ERROR + /* Close the file with the bogus objects */ + if(H5Fclose(file2) < 0) + TEST_ERROR + + PASSED(); + + /* Open the file with objects that have unknown header messages (generated with gen_bogus.c) with RW intent this time */ + if((file2 = H5Fopen(testfile, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) + TEST_ERROR + + TESTING("object with unknown header message & 'fail if unknown and open for write' flag set"); + + /* Attempt to open the dataset with the unknown header message, and "fail if unknown and open for write" flag */ + H5E_BEGIN_TRY { + dset = H5Dopen2(file2, "/Dataset2", H5P_DEFAULT); + } H5E_END_TRY; + if(dset >= 0) { + H5Dclose(dset); + TEST_ERROR + } /* end if */ /* Close the file with the bogus objects */ if(H5Fclose(file2) < 0) diff --git a/test/tbogus.h5 b/test/tbogus.h5 index 2b8b1dd..906921c 100644 Binary files a/test/tbogus.h5 and b/test/tbogus.h5 differ -- cgit v0.12