2019-04-05 00:03:05 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Copyright by The HDF Group. *
|
|
|
|
* Copyright by the Board of Trustees of the University of Illinois. *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
|
|
|
* the COPYING file, which can be found at the root of the source code *
|
2021-02-17 22:52:04 +08:00
|
|
|
* distribution tree, or in https://www.hdfgroup.org/licenses. *
|
2019-04-05 00:03:05 +08:00
|
|
|
* If you do not have access to either file, you may request a copy from *
|
|
|
|
* help@hdfgroup.org. *
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
/*
|
2020-08-07 08:58:07 +08:00
|
|
|
* Programmer: Raymond Lu
|
2019-04-10 05:20:19 +08:00
|
|
|
* April, 2019
|
2019-04-05 00:03:05 +08:00
|
|
|
*
|
2019-04-10 05:20:19 +08:00
|
|
|
* Purpose: Private function for external.c and external_env.c
|
2019-04-05 00:03:05 +08:00
|
|
|
*/
|
|
|
|
|
2019-04-10 05:20:19 +08:00
|
|
|
#include "external_common.h"
|
2019-04-05 00:03:05 +08:00
|
|
|
|
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
* Function: reset_raw_data_files
|
|
|
|
*
|
|
|
|
* Purpose: Resets the data in the raw data files for tests that
|
|
|
|
* perform dataset I/O on a set of files.
|
|
|
|
*
|
|
|
|
* Return: SUCCEED/FAIL
|
|
|
|
*
|
|
|
|
* Programmer: Dana Robinson
|
|
|
|
* February 2016
|
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2019-04-10 05:20:19 +08:00
|
|
|
herr_t
|
2019-08-01 23:18:45 +08:00
|
|
|
reset_raw_data_files(hbool_t is_env)
|
2019-04-05 00:03:05 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
int fd = 0; /* external file descriptor */
|
|
|
|
size_t i, j; /* iterators */
|
|
|
|
hssize_t n; /* bytes of I/O */
|
|
|
|
char filename[1024]; /* file name */
|
|
|
|
int data[PART_SIZE]; /* raw data buffer */
|
|
|
|
uint8_t *garbage = NULL; /* buffer of garbage data */
|
|
|
|
size_t garbage_count; /* size of garbage buffer */
|
|
|
|
size_t garbage_bytes; /* # of garbage bytes written to file */
|
2019-04-05 00:03:05 +08:00
|
|
|
|
|
|
|
/* Set up garbage buffer */
|
|
|
|
garbage_count = N_EXT_FILES * GARBAGE_PER_FILE;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (NULL == (garbage = (uint8_t *)HDcalloc(garbage_count, sizeof(uint8_t))))
|
2019-04-05 00:03:05 +08:00
|
|
|
goto error;
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < garbage_count; i++)
|
2019-04-05 00:03:05 +08:00
|
|
|
garbage[i] = 0xFF;
|
|
|
|
|
|
|
|
/* The *r files are pre-filled with data and are used to
|
|
|
|
* verify that read operations work correctly.
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < N_EXT_FILES; i++) {
|
2019-04-05 00:03:05 +08:00
|
|
|
|
|
|
|
/* Open file */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (is_env)
|
2022-01-29 06:43:48 +08:00
|
|
|
HDsnprintf(filename, sizeof(filename), "extern_env_%lur.raw", (unsigned long)i + 1);
|
2019-04-22 23:23:38 +08:00
|
|
|
else
|
2022-01-29 06:43:48 +08:00
|
|
|
HDsnprintf(filename, sizeof(filename), "extern_%lur.raw", (unsigned long)i + 1);
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((fd = HDopen(filename, O_RDWR | O_CREAT | O_TRUNC, H5_POSIX_CREATE_MODE_RW)) < 0)
|
2019-04-05 00:03:05 +08:00
|
|
|
goto error;
|
2020-04-21 07:12:00 +08:00
|
|
|
|
2019-04-05 00:03:05 +08:00
|
|
|
/* Write garbage data to the file. This allows us to test the
|
|
|
|
* the ability to set an offset in the raw data file.
|
|
|
|
*/
|
|
|
|
garbage_bytes = i * 10;
|
2020-09-30 22:27:10 +08:00
|
|
|
n = HDwrite(fd, garbage, garbage_bytes);
|
|
|
|
if (n < 0 || (size_t)n != garbage_bytes)
|
2019-04-05 00:03:05 +08:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* Fill array with data */
|
2020-09-30 22:27:10 +08:00
|
|
|
for (j = 0; j < PART_SIZE; j++) {
|
2019-04-05 00:03:05 +08:00
|
|
|
data[j] = (int)(i * 25 + j);
|
|
|
|
} /* end for */
|
|
|
|
|
|
|
|
/* Write raw data to the file. */
|
|
|
|
n = HDwrite(fd, data, sizeof(data));
|
2020-09-30 22:27:10 +08:00
|
|
|
if (n != sizeof(data))
|
2019-04-05 00:03:05 +08:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* Close this file */
|
|
|
|
HDclose(fd);
|
|
|
|
|
|
|
|
} /* end for */
|
|
|
|
|
|
|
|
/* The *w files are only pre-filled with the garbage data and are
|
|
|
|
* used to verify that write operations work correctly. The individual
|
|
|
|
* tests fill in the actual data.
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
for (i = 0; i < N_EXT_FILES; i++) {
|
2019-04-05 00:03:05 +08:00
|
|
|
|
|
|
|
/* Open file */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (is_env)
|
2022-01-29 06:43:48 +08:00
|
|
|
HDsnprintf(filename, sizeof(filename), "extern_env_%luw.raw", (unsigned long)i + 1);
|
2019-04-22 23:23:38 +08:00
|
|
|
else
|
2022-01-29 06:43:48 +08:00
|
|
|
HDsnprintf(filename, sizeof(filename), "extern_%luw.raw", (unsigned long)i + 1);
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((fd = HDopen(filename, O_RDWR | O_CREAT | O_TRUNC, H5_POSIX_CREATE_MODE_RW)) < 0)
|
2019-04-05 00:03:05 +08:00
|
|
|
goto error;
|
2020-04-21 07:12:00 +08:00
|
|
|
|
2019-04-05 00:03:05 +08:00
|
|
|
/* Write garbage data to the file. This allows us to test the
|
|
|
|
* the ability to set an offset in the raw data file.
|
|
|
|
*/
|
|
|
|
garbage_bytes = i * 10;
|
2020-09-30 22:27:10 +08:00
|
|
|
n = HDwrite(fd, garbage, garbage_bytes);
|
|
|
|
if (n < 0 || (size_t)n != garbage_bytes)
|
2019-04-05 00:03:05 +08:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* Close this file */
|
|
|
|
HDclose(fd);
|
|
|
|
|
|
|
|
} /* end for */
|
|
|
|
HDfree(garbage);
|
|
|
|
return SUCCEED;
|
|
|
|
|
|
|
|
error:
|
2020-09-30 22:27:10 +08:00
|
|
|
if (fd)
|
2019-04-05 00:03:05 +08:00
|
|
|
HDclose(fd);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (garbage)
|
2019-04-05 00:03:05 +08:00
|
|
|
HDfree(garbage);
|
|
|
|
return FAIL;
|
2019-04-10 05:20:19 +08:00
|
|
|
}
|