/****************************************************************************
**  SIONLIB     http://www.fz-juelich.de/jsc/sionlib                       **
*****************************************************************************
**  Copyright (c) 2008-2018                                                **
**  Forschungszentrum Juelich, Juelich Supercomputing Centre               **
**                                                                         **
**  See the file COPYRIGHT in the package base directory for details       **
****************************************************************************/

/*!
 * \cond sion_internal
 * \file
 *
 * Functions related to the duplication of sion file descriptor.
 */

#ifndef SION_SION_DUP_H
#define SION_SION_DUP_H

#include <stdint.h>

#include "sion_filedesc.h"

#ifdef __cplusplus
extern "C" {
#endif

/*!
 * @brief Create a duplicated sion file descriptor.
 *
 * @param[in]   sid    original sid to be duplicated
 * @param[in]   mode   mode for duplication (SION_DUP_RANK or SION_DUP_RANK_KEY)
 * @param[in]   rank   rank for new file descriptor
 * @param[in]   key    key for new file descriptor
 *
 * @return     SION_SUCCESS if okay
 */
int _lsion_dup(int sid, int mode, int rank, uint64_t key);

/*!
 * @brief Destroy a duplicated sion file descriptor.
 *
 * @return     SION_SUCCESS if okay
 */
int _lsion_dedup(int sid);

/* internal auxiliary  */
/*!
 * @brief Duplicate sion_filedesc if the file is opened in paropen_mapped_master.
 *
 * @return     SION_SUCCESS if okay
 */
int _lsion_dup_paropen(_sion_filedesc *sion_filedesc, _sion_filedesc *new_filedesc);

/*!
 * @brief Duplicate sion_filedesc if the file is opened in paropen_mapped_master.
 *
 * @return     SION_SUCCESS if okay
 */
int _lsion_dup_paropenmappedmaster(_sion_filedesc *sion_filedesc, _sion_filedesc *new_filedesc);

/*!
 * @brief Duplicate the blocksizes array of sion_filedesc.
 *
 * @return     SION_SUCCESS if okay
 */
int _lsion_dup_blocksizes(_sion_filedesc *sion_filedesc, _sion_filedesc *new_filedesc);

/*!
 * @brief Duplicate the all* array of sion_filedesc.
 *
 * @return     SION_SUCCESS if okay
 */
int _lsion_dup_all_ds(_sion_filedesc *sion_filedesc, _sion_filedesc *new_filedesc);

/*!
 * @brief Duplicate the keyvalue data structure of sion_filedesc.
 *
 * @return     SION_SUCCESS if okay
 */
int _lsion_dup_keyvalptr(_sion_filedesc *sion_filedesc, _sion_filedesc *new_filedesc);

/*!
 * @brief Duplicate the keyvalue data structures of sion_filedesc.
 *
 * @return     SION_SUCCESS if okay
 */
int _lsion_dup_all_keyvalptr(_sion_filedesc *sion_filedesc, _sion_filedesc *new_filedesc);

#ifdef __cplusplus
}
#endif

#endif

/// \endcond
