fixed typos and other minor things
This commit is contained in:
13
src/obidms.c
13
src/obidms.c
@ -8,17 +8,17 @@
|
|||||||
#include <obidms.h>
|
#include <obidms.h>
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
/************************************************************************
|
||||||
*
|
*
|
||||||
* D E C L A R A T I O N O F T H E P R I V A T E F U N C T I O N S
|
* D E C L A R A T I O N O F T H E P R I V A T E F U N C T I O N S
|
||||||
*
|
*
|
||||||
***********************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal function building the directory name from a OBIDMS name.
|
* Internal function building the directory name from an OBIDMS name.
|
||||||
*
|
*
|
||||||
* The function build the directory name corresponding to a OBIDMS.
|
* The function builds the directory name corresponding to an OBIDMS.
|
||||||
* It checks also that the name is not too long.
|
* It checks also that the name is not too long.
|
||||||
*
|
*
|
||||||
* @warning The returned pointer has to be freed by the caller.
|
* @warning The returned pointer has to be freed by the caller.
|
||||||
@ -30,7 +30,7 @@
|
|||||||
* @retvalue NULL if an error occurs
|
* @retvalue NULL if an error occurs
|
||||||
*
|
*
|
||||||
* ###Error values
|
* ###Error values
|
||||||
* - OBIDMS_MEMORY_ERROR : something wrong occurs during memory allocation.
|
* - OBIDMS_MEMORY_ERROR : something wrong occured during memory allocation.
|
||||||
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
|
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
|
||||||
*
|
*
|
||||||
* @since May 2015
|
* @since May 2015
|
||||||
@ -58,6 +58,7 @@ static char *build_directory_name(const char *name) {
|
|||||||
return dirdbname;
|
return dirdbname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
*
|
*
|
||||||
* D E F I N I T I O N O F T H E P R I V A T E F U N C T I O N S
|
* D E F I N I T I O N O F T H E P R I V A T E F U N C T I O N S
|
||||||
@ -111,6 +112,7 @@ OBIDMS_p obi_create_dms(const char *name) {
|
|||||||
return obi_open_dms(name);
|
return obi_open_dms(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
OBIDMS_p obi_open_dms(const char *name) {
|
OBIDMS_p obi_open_dms(const char *name) {
|
||||||
OBIDMS_p dms=NULL;
|
OBIDMS_p dms=NULL;
|
||||||
char *dirdbname;
|
char *dirdbname;
|
||||||
@ -162,6 +164,7 @@ OBIDMS_p obi_open_dms(const char *name) {
|
|||||||
return dms;
|
return dms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
OBIDMS_p obi_dms(const char *name) {
|
OBIDMS_p obi_dms(const char *name) {
|
||||||
int exist = obi_dms_exists(name);
|
int exist = obi_dms_exists(name);
|
||||||
|
|
||||||
|
76
src/obidms.h
76
src/obidms.h
@ -35,43 +35,18 @@ typedef struct OBIDMS {
|
|||||||
*/
|
*/
|
||||||
} OBIDMS_t, *OBIDMS_p;
|
} OBIDMS_t, *OBIDMS_p;
|
||||||
|
|
||||||
/**
|
|
||||||
* @defgroup OBIDMSErrors OBIDMS related error codes
|
|
||||||
*
|
|
||||||
* Error codes set in errno following an error related
|
|
||||||
* to the manipulation of an OBIDMS.
|
|
||||||
*
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
#define OBIDMS_EXIST_ERROR (1) /**< Try to create an OBIDMS with a name
|
|
||||||
* that corresponds to an existing OBIDMS
|
|
||||||
*/
|
|
||||||
#define OBIDMS_NOT_EXIST_ERROR (2) /**< Try to open a non-existing OBIDMS
|
|
||||||
*/
|
|
||||||
#define OBIDMS_LONG_NAME_ERROR (3) /**< The specified OBIDMS name is too long
|
|
||||||
*/
|
|
||||||
#define OBIDMS_MEMORY_ERROR (4) /**< A memory error occurred during allocation
|
|
||||||
*/
|
|
||||||
#define OBIDMS_UNKNOWN_ERROR (5) /**< Not determined error
|
|
||||||
*/
|
|
||||||
#define OBIDMS_ACCESS_ERROR (6) /**< Permission error for accessing to the database
|
|
||||||
*/
|
|
||||||
#define OBIDMS_BAD_ENDIAN_ERROR (7) /**< The opened data structure does not corresponds
|
|
||||||
* to the endianess of the platform.
|
|
||||||
*/
|
|
||||||
/**@}*/
|
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
* @brief Check if a OBIDMS exist
|
* @brief Checks if an OBIDMS exists
|
||||||
*
|
*
|
||||||
* @param name a pointer to a C string containing the name of the database
|
* @param name a pointer to a C string containing the name of the database.
|
||||||
* the actual directory name used to store the DMS will be
|
* The actual directory name used to store the DMS will be
|
||||||
* `<name>.obidms`
|
* `<name>.obidms`.
|
||||||
*
|
*
|
||||||
* @return an integer value indicating the status of the database
|
* @return an integer value indicating the status of the database
|
||||||
* @retvalue 1 the database exist
|
* @retvalue 1 the database exist
|
||||||
* @retvalue 0 the database does not exist
|
* @retvalue 0 the database does not exist
|
||||||
* @retvalue -1 an error occurs
|
* @retvalue -1 an error occured
|
||||||
*
|
*
|
||||||
* @see obi_close_dms()
|
* @see obi_close_dms()
|
||||||
* @since May 2015
|
* @since May 2015
|
||||||
@ -79,15 +54,16 @@ typedef struct OBIDMS {
|
|||||||
*/
|
*/
|
||||||
int obi_dms_exists(const char* name);
|
int obi_dms_exists(const char* name);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create a new OBITools Data Management instance (OBIDMS).
|
* @brief Creates a new OBITools Data Management instance (OBIDMS).
|
||||||
*
|
*
|
||||||
* A `DMS` is implemented as a directory. This function takes care
|
* A `DMS` is implemented as a directory. This function checks
|
||||||
* to check if a directory with this name does not already exist
|
* if a directory with this name does not already exist
|
||||||
* before creating the new database
|
* before creating the new database.
|
||||||
*
|
*
|
||||||
* @param name a pointer to a C string containing the name of the database
|
* @param name a pointer to a C string containing the name of the database.
|
||||||
* the actual directory name used to store the DMS will be
|
* The actual directory name used to store the DMS will be
|
||||||
* `<name>.obidms`
|
* `<name>.obidms`
|
||||||
*
|
*
|
||||||
* @return a pointer to an OBIDMS structure describing the newly created DMS
|
* @return a pointer to an OBIDMS structure describing the newly created DMS
|
||||||
@ -96,7 +72,7 @@ int obi_dms_exists(const char* name);
|
|||||||
* ###Error values
|
* ###Error values
|
||||||
* - OBIDMS_EXIST_ERROR : a database with the same name already exists.
|
* - OBIDMS_EXIST_ERROR : a database with the same name already exists.
|
||||||
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
|
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
|
||||||
* - OBIDMS_MEMORY_ERROR : something wrong occurs during memory allocation.
|
* - OBIDMS_MEMORY_ERROR : something wrong occured during memory allocation.
|
||||||
*
|
*
|
||||||
* @see obi_close_dms()
|
* @see obi_close_dms()
|
||||||
* @since May 2015
|
* @since May 2015
|
||||||
@ -104,11 +80,12 @@ int obi_dms_exists(const char* name);
|
|||||||
*/
|
*/
|
||||||
OBIDMS_p obi_create_dms(const char *name);
|
OBIDMS_p obi_create_dms(const char *name);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Open an existing OBITools Data Management instance (OBIDMS).
|
* @brief Opens an existing OBITools Data Management instance (OBIDMS).
|
||||||
*
|
*
|
||||||
* @param name a pointer to a C string containing the name of the database
|
* @param name a pointer to a C string containing the name of the database.
|
||||||
* the actual directory name used to store the DMS will be
|
* The actual directory name used to store the DMS will be
|
||||||
* `<name>.obidms`
|
* `<name>.obidms`
|
||||||
*
|
*
|
||||||
* @return a pointer to an OBIDMS structure describing the newly created DMS
|
* @return a pointer to an OBIDMS structure describing the newly created DMS
|
||||||
@ -117,7 +94,7 @@ OBIDMS_p obi_create_dms(const char *name);
|
|||||||
* ###Error values
|
* ###Error values
|
||||||
* - OBIDMS_EXIST_ERROR : a database with the same name already exists.
|
* - OBIDMS_EXIST_ERROR : a database with the same name already exists.
|
||||||
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
|
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
|
||||||
* - OBIDMS_MEMORY_ERROR : something wrong occurs during memory allocation.
|
* - OBIDMS_MEMORY_ERROR : something wrong occured during memory allocation.
|
||||||
*
|
*
|
||||||
* @see obi_close_dms()
|
* @see obi_close_dms()
|
||||||
* @since May 2015
|
* @since May 2015
|
||||||
@ -125,14 +102,15 @@ OBIDMS_p obi_create_dms(const char *name);
|
|||||||
*/
|
*/
|
||||||
OBIDMS_p obi_open_dms(const char *name);
|
OBIDMS_p obi_open_dms(const char *name);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create a new OBIDMS instance.
|
* @brief Creates a new OBIDMS instance.
|
||||||
*
|
*
|
||||||
* If the database already exist this function open it, otherwise it
|
* If the database already exists, this function opens it, otherwise it
|
||||||
* creates a new databse.
|
* creates a new database.
|
||||||
*
|
*
|
||||||
* @param name a pointer to a C string containing the name of the database
|
* @param name a pointer to a C string containing the name of the database.
|
||||||
* the actual directory name used to store the DMS is
|
* The actual directory name used to store the DMS is
|
||||||
* `<name>.obidms`
|
* `<name>.obidms`
|
||||||
*
|
*
|
||||||
* @return a pointer to an OBIDMS structure describing the newly created DMS
|
* @return a pointer to an OBIDMS structure describing the newly created DMS
|
||||||
@ -140,7 +118,7 @@ OBIDMS_p obi_open_dms(const char *name);
|
|||||||
*
|
*
|
||||||
* ###Error values
|
* ###Error values
|
||||||
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
|
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
|
||||||
* - OBIDMS_MEMORY_ERROR : something wrong occurs during memory allocation.
|
* - OBIDMS_MEMORY_ERROR : something wrong occured during memory allocation.
|
||||||
*
|
*
|
||||||
* @see obi_close_dms()
|
* @see obi_close_dms()
|
||||||
* @since May 2015
|
* @since May 2015
|
||||||
@ -148,8 +126,9 @@ OBIDMS_p obi_open_dms(const char *name);
|
|||||||
*/
|
*/
|
||||||
OBIDMS_p obi_dms(const char *name);
|
OBIDMS_p obi_dms(const char *name);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Close an opened OBITools Data Management instance (OBIDMS).
|
* @brief Closes an opened OBITools Data Management instance (OBIDMS).
|
||||||
*
|
*
|
||||||
* @param dms a pointer as returned by obi_create_dms() or obi_open_dms()
|
* @param dms a pointer as returned by obi_create_dms() or obi_open_dms()
|
||||||
*
|
*
|
||||||
@ -165,4 +144,5 @@ OBIDMS_p obi_dms(const char *name);
|
|||||||
*/
|
*/
|
||||||
int obi_close_dms(OBIDMS_p dms);
|
int obi_close_dms(OBIDMS_p dms);
|
||||||
|
|
||||||
|
|
||||||
#endif /* OBIDMS_H_ */
|
#endif /* OBIDMS_H_ */
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* OBIDMSColumn functions *
|
* OBIDMS_column functions *
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file obidmscolumn.h
|
* @file OBIDMS_column.h
|
||||||
* @author Celine Mercier
|
* @author Celine Mercier
|
||||||
* @date 22 May 2015
|
* @date 22 May 2015
|
||||||
* @brief Functions for the shared elements of all the OBIColumn structures.
|
* @brief Functions for the shared elements of all the OBIColumn structures.
|
||||||
@ -16,17 +16,17 @@
|
|||||||
#include <sys/mman.h> /* mmap() is defined in this header */
|
#include <sys/mman.h> /* mmap() is defined in this header */
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
/*************************************************************************
|
||||||
*
|
*
|
||||||
* D E C L A R A T I O N O F T H E P R I V A T E F U N C T I O N S
|
* D E C L A R A T I O N O F T H E P R I V A T E F U N C T I O N S
|
||||||
*
|
*
|
||||||
***********************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Internal function building the file name for a column.
|
* @brief Internal function building the file name for a column.
|
||||||
*
|
*
|
||||||
* The function build the file name corresponding to a column of an OBIDMS.
|
* The function builds the file name corresponding to a column of an OBIDMS.
|
||||||
*
|
*
|
||||||
* @warning The returned pointer has to be freed by the caller.
|
* @warning The returned pointer has to be freed by the caller.
|
||||||
*
|
*
|
||||||
@ -36,13 +36,14 @@
|
|||||||
* @retvalue NULL if an error occurs
|
* @retvalue NULL if an error occurs
|
||||||
*
|
*
|
||||||
* ###Error values
|
* ###Error values
|
||||||
* - OBIDMS_MEMORY_ERROR : something wrong occurs during memory allocation.
|
* - OBIDMS_MEMORY_ERROR : something wrong occured during memory allocation.
|
||||||
*
|
*
|
||||||
* @since May 2015
|
* @since May 2015
|
||||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
static char *build_column_name(const char *name, obiversion_t version);
|
static char *build_column_name(const char *name, obiversion_t version);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Internal function building the file name for a version column file.
|
* @brief Internal function building the file name for a version column file.
|
||||||
*
|
*
|
||||||
@ -64,6 +65,7 @@ static char *build_column_name(const char *name,obiversion_t version);
|
|||||||
*/
|
*/
|
||||||
static char *build_version_name(const char *name);
|
static char *build_version_name(const char *name);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Internal function returning a new column version number
|
* @brief Internal function returning a new column version number
|
||||||
* in the `dms` database
|
* in the `dms` database
|
||||||
@ -82,6 +84,7 @@ static char *build_version_name(const char *name);
|
|||||||
*/
|
*/
|
||||||
static obiversion_t obi_new_version(OBIDMS_p dms,char *name, bool block);
|
static obiversion_t obi_new_version(OBIDMS_p dms,char *name, bool block);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Internal function creating a new column version file
|
* @brief Internal function creating a new column version file
|
||||||
* in the `dms` database
|
* in the `dms` database
|
||||||
@ -99,11 +102,12 @@ static obiversion_t obi_new_version(OBIDMS_p dms,char *name, bool block);
|
|||||||
*/
|
*/
|
||||||
static int create_version(OBIDMS_p dms,char *name);
|
static int create_version(OBIDMS_p dms,char *name);
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
|
/************************************************************************
|
||||||
*
|
*
|
||||||
* D E F I N I T I O N O F T H E P R I V A T E F U N C T I O N S
|
* D E F I N I T I O N O F T H E P R I V A T E F U N C T I O N S
|
||||||
*
|
*
|
||||||
***********************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
static char *build_column_name(const char *name,obiversion_t version) {
|
static char *build_column_name(const char *name,obiversion_t version) {
|
||||||
|
|
||||||
@ -134,6 +138,7 @@ static char *build_version_name(const char *name) {
|
|||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static obiversion_t obi_new_version(OBIDMS_p dms,char *name, bool block) {
|
static obiversion_t obi_new_version(OBIDMS_p dms,char *name, bool block) {
|
||||||
|
|
||||||
off_t locsize=sizeof(bool) + sizeof(obiversion_t);
|
off_t locsize=sizeof(bool) + sizeof(obiversion_t);
|
||||||
@ -164,7 +169,10 @@ static obiversion_t obi_new_version(OBIDMS_p dms,char *name, bool block) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//open the version file
|
//open the version file
|
||||||
versionfd = openat(directoryfd,versionfile,O_RDWR);
|
//versionfd = openat(directoryfd, versionfile, O_RDWR);
|
||||||
|
versionfd = open(versionfile, O_RDWR);
|
||||||
|
|
||||||
|
|
||||||
if (versionfd < 0) {
|
if (versionfd < 0) {
|
||||||
free(versionfile);
|
free(versionfile);
|
||||||
|
|
||||||
@ -216,7 +224,7 @@ static obiversion_t obi_new_version(OBIDMS_p dms,char *name, bool block) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if endianess is correct
|
// check if endianess is correct
|
||||||
if (little != obi_is_little_end())
|
if (little != obi_is_little_endian())
|
||||||
{
|
{
|
||||||
close(versionfd);
|
close(versionfd);
|
||||||
obi_set_errno(OBIDMS_BAD_ENDIAN_ERROR);
|
obi_set_errno(OBIDMS_BAD_ENDIAN_ERROR);
|
||||||
@ -275,6 +283,7 @@ static obiversion_t obi_new_version(OBIDMS_p dms,char *name, bool block) {
|
|||||||
return newversion;
|
return newversion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int create_version(OBIDMS_p dms,char *name) {
|
static int create_version(OBIDMS_p dms,char *name) {
|
||||||
off_t locsize=sizeof(bool) + sizeof(obiversion_t);
|
off_t locsize=sizeof(bool) + sizeof(obiversion_t);
|
||||||
obiversion_t version=0;
|
obiversion_t version=0;
|
||||||
@ -295,11 +304,16 @@ static int create_version(OBIDMS_p dms,char *name) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
versionfd = openat(directoryfd,
|
//versionfd = openat(directoryfd,
|
||||||
versionfile,
|
// versionfile,
|
||||||
|
// O_RDWR|O_CREAT|O_EXCL,
|
||||||
|
// 666);
|
||||||
|
|
||||||
|
versionfd = open(versionfile,
|
||||||
O_RDWR|O_CREAT|O_EXCL,
|
O_RDWR|O_CREAT|O_EXCL,
|
||||||
666);
|
666);
|
||||||
|
|
||||||
|
|
||||||
if (versionfd < 0) {
|
if (versionfd < 0) {
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
||||||
free(versionfile);
|
free(versionfile);
|
||||||
@ -331,7 +345,7 @@ static int create_version(OBIDMS_p dms,char *name) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
little = obi_is_little_end();
|
little = obi_is_little_endian();
|
||||||
|
|
||||||
if (write(versionfd, &little, sizeof(bool)) < sizeof(bool))
|
if (write(versionfd, &little, sizeof(bool)) < sizeof(bool))
|
||||||
{
|
{
|
||||||
@ -372,6 +386,7 @@ static int create_version(OBIDMS_p dms,char *name) {
|
|||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
*
|
*
|
||||||
* D E F I N I T I O N O F T H E P U B L I C F U N C T I O N S
|
* D E F I N I T I O N O F T H E P U B L I C F U N C T I O N S
|
||||||
@ -397,7 +412,9 @@ obiversion_t obi_latest_version(OBIDMS_p dms,char *name) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
versionfd = openat(directoryfd,versionfile,O_RDWR);
|
//versionfd = openat(directoryfd,versionfile,O_RDWR);
|
||||||
|
versionfd = open(versionfile,O_RDWR);
|
||||||
|
|
||||||
if (versionfd < 0) {
|
if (versionfd < 0) {
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
||||||
free(versionfile);
|
free(versionfile);
|
||||||
@ -428,7 +445,7 @@ obiversion_t obi_latest_version(OBIDMS_p dms,char *name) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (little != obi_is_little_end())
|
if (little != obi_is_little_endian())
|
||||||
{
|
{
|
||||||
close(versionfd);
|
close(versionfd);
|
||||||
obi_set_errno(OBIDMS_BAD_ENDIAN_ERROR);
|
obi_set_errno(OBIDMS_BAD_ENDIAN_ERROR);
|
||||||
@ -450,20 +467,20 @@ obiversion_t obi_latest_version(OBIDMS_p dms,char *name) {
|
|||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t obi_get_platform_header_size()
|
size_t obi_get_platform_header_size()
|
||||||
{
|
{
|
||||||
return getpagesize() * 1;
|
return getpagesize() * 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||||
OBIDMSColumn_p obi_create_column(OBIDMS_p dms,
|
|
||||||
char *name,
|
char *name,
|
||||||
OBIType_t type,
|
OBIType_t type,
|
||||||
size_t nbelement)
|
size_t nbelements)
|
||||||
{
|
{
|
||||||
OBIDMSColumn_p newcolumn=NULL;
|
OBIDMS_column_p newcolumn=NULL;
|
||||||
OBIDMSColumnHeader_p header;
|
OBIDMS_column_header_p header;
|
||||||
size_t filesize;
|
size_t filesize;
|
||||||
obiversion_t version;
|
obiversion_t version;
|
||||||
char * columnfile;
|
char * columnfile;
|
||||||
@ -480,7 +497,7 @@ OBIDMSColumn_p obi_create_column(OBIDMS_p dms,
|
|||||||
}
|
}
|
||||||
|
|
||||||
hsize = obi_get_platform_header_size();
|
hsize = obi_get_platform_header_size();
|
||||||
dsize = obi_array_sizeof(type,nbelement);
|
dsize = obi_array_sizeof(type,nbelements);
|
||||||
|
|
||||||
filesize = hsize + dsize;
|
filesize = hsize + dsize;
|
||||||
|
|
||||||
@ -494,8 +511,12 @@ OBIDMSColumn_p obi_create_column(OBIDMS_p dms,
|
|||||||
|
|
||||||
columnfile = build_column_name(name,version);
|
columnfile = build_column_name(name,version);
|
||||||
|
|
||||||
columnfd = openat(directoryfd,
|
//columnfd = openat(directoryfd,
|
||||||
columnfile,
|
// columnfile,
|
||||||
|
// O_RDWR|O_CREAT|O_EXCL,
|
||||||
|
// 666);
|
||||||
|
|
||||||
|
columnfd = open(columnfile,
|
||||||
O_RDWR|O_CREAT|O_EXCL,
|
O_RDWR|O_CREAT|O_EXCL,
|
||||||
666);
|
666);
|
||||||
|
|
||||||
@ -507,7 +528,7 @@ OBIDMSColumn_p obi_create_column(OBIDMS_p dms,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
newcolumn = (OBIDMSColumn_p) malloc(sizeof(OBIDMSColumn_t));
|
newcolumn = (OBIDMS_column_p) malloc(sizeof(OBIDMS_column_t));
|
||||||
|
|
||||||
if (newcolumn)
|
if (newcolumn)
|
||||||
{
|
{
|
||||||
@ -556,9 +577,9 @@ OBIDMSColumn_p obi_create_column(OBIDMS_p dms,
|
|||||||
newcolumn->writable= true;
|
newcolumn->writable= true;
|
||||||
|
|
||||||
header = newcolumn->header;
|
header = newcolumn->header;
|
||||||
header->little_endian = obi_is_little_end();
|
header->little_endian = obi_is_little_endian();
|
||||||
header->header_size = hsize;
|
header->header_size = hsize;
|
||||||
header->line_count = nbelement;
|
header->line_count = nbelements;
|
||||||
header->line_used = 0;
|
header->line_used = 0;
|
||||||
header->data_type = type;
|
header->data_type = type;
|
||||||
header->creation_date = time(NULL);
|
header->creation_date = time(NULL);
|
||||||
@ -571,7 +592,6 @@ OBIDMSColumn_p obi_create_column(OBIDMS_p dms,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// if( access( fname, F_OK ) != -1 ) {
|
// if( access( fname, F_OK ) != -1 ) {
|
||||||
// // file exists
|
// // file exists
|
||||||
// } else {
|
// } else {
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* OBIDMSColumn header file *
|
* OBIDMS_column header file *
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file obidmscolumn.h
|
* @file obidmscolumn.h
|
||||||
* @author Celine Mercier
|
* @author Celine Mercier
|
||||||
* @date 12 May 2015
|
* @date 12 May 2015
|
||||||
* @brief Header file for the shared elements of all the OBIColumn structures.
|
* @brief Header file for the shared elements of all the OBIDMS column structures.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef OBIDMSCOLUMN_H_
|
#ifndef OBIDMSCOLUMN_H_
|
||||||
@ -34,10 +34,10 @@ typedef int32_t obiversion_t; /**< Used to store the column version number
|
|||||||
* @brief OBIColumnHeader structure.
|
* @brief OBIColumnHeader structure.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct OBIDMSColumnHeader {
|
typedef struct OBIDMS_column_header {
|
||||||
bool little_endian; /**< endianess of the column:
|
bool little_endian; /**< endianess of the column:
|
||||||
- `true` on little endian platform
|
- `true` on little endian platforms
|
||||||
- `false` on big endian platform
|
- `false` on big endian platforms
|
||||||
|
|
||||||
@see obi_is_little_end()
|
@see obi_is_little_end()
|
||||||
*/
|
*/
|
||||||
@ -52,26 +52,26 @@ typedef struct OBIDMSColumnHeader {
|
|||||||
*/
|
*/
|
||||||
char comments[1]; /**< comments stored as a classical
|
char comments[1]; /**< comments stored as a classical
|
||||||
zero end C string. T
|
zero end C string. T
|
||||||
The size of the comment is just limited
|
The size of the comment is only limited
|
||||||
by the header size
|
by the header size
|
||||||
*/
|
*/
|
||||||
} OBIDMSColumnHeader_t, *OBIDMSColumnHeader_p;
|
} OBIDMS_column_header_t, *OBIDMS_column_header_p;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Structure describing a Column of the OBITools DMS
|
* @brief Structure describing a Column of the OBITools DMS
|
||||||
*
|
*
|
||||||
* A data structure of this type is returned by the functions
|
* A data structure of this type is returned by the functions
|
||||||
* creating, opening or cloning an OBIDMSColumn.
|
* creating, opening or cloning an OBIDMS_column.
|
||||||
*/
|
*/
|
||||||
typedef struct OBIDMSColumn {
|
typedef struct OBIDMS_column {
|
||||||
OBIDMS_p dms ; /**< A pointer to a DMS instance
|
OBIDMS_p dms ; /**< A pointer to a DMS instance
|
||||||
*/
|
*/
|
||||||
OBIDMSColumnHeader_p header; /**< A pointer to the header of the column
|
OBIDMS_column_header_p header; /**< A pointer to the header of the column
|
||||||
*/
|
*/
|
||||||
void* data; /**< A `void` pointer to the beginning of the
|
void* data; /**< A `void` pointer to the beginning of the
|
||||||
* data.
|
* data.
|
||||||
*
|
*
|
||||||
* @attention never use this member directly
|
* @warning never use this member directly
|
||||||
* outside of the code of the
|
* outside of the code of the
|
||||||
* low level functions
|
* low level functions
|
||||||
* of the OBITools DMS
|
* of the OBITools DMS
|
||||||
@ -81,12 +81,13 @@ typedef struct OBIDMSColumn {
|
|||||||
* - `false` the column is read-only
|
* - `false` the column is read-only
|
||||||
*
|
*
|
||||||
* A column is writable only by its creator
|
* A column is writable only by its creator
|
||||||
* until he closes it.
|
* until it closes it.
|
||||||
*/
|
*/
|
||||||
} OBIDMSColumn_t, *OBIDMSColumn_p;
|
} OBIDMS_column_t, *OBIDMS_column_p;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the header size in bytes of a column on this platform.
|
* @brief Returns the header size in bytes of a column on this platform.
|
||||||
*
|
*
|
||||||
* Header size is defined as a multiple of the memory page size.
|
* Header size is defined as a multiple of the memory page size.
|
||||||
* Up to now the header size is defined as one time the page size
|
* Up to now the header size is defined as one time the page size
|
||||||
@ -99,27 +100,25 @@ typedef struct OBIDMSColumn {
|
|||||||
size_t obi_get_platform_header_size();
|
size_t obi_get_platform_header_size();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create a column.
|
* @brief Creates a column.
|
||||||
*
|
*
|
||||||
* @param dms a pointer as returned by obi_create_dms() or obi_open_dms()
|
* @param dms a pointer as returned by obi_create_dms() or obi_open_dms()
|
||||||
* @param name the name of the new column
|
* @param name the name of the new column
|
||||||
* @param type the OBIType code used to create the column
|
* @param type the OBIType code used to create the column
|
||||||
* @param nbelement the number of element to be stored
|
* @param nbelements the number of elements to be stored
|
||||||
*
|
*
|
||||||
* @since May 2015
|
* @since May 2015
|
||||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
|
OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||||
OBIDMSColumn_p obi_create_column(OBIDMS_p dms,
|
|
||||||
char* name,
|
char* name,
|
||||||
OBIType_t type,
|
OBIType_t type,
|
||||||
size_t nbelement);
|
size_t nbelements);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return the latest column version in the `dms` database
|
* @brief Returns the latest column version in the `dms` database
|
||||||
*
|
*
|
||||||
* @param dms a pointer as returned by obi_create_dms() or obi_open_dms()
|
* @param dms a pointer as returned by obi_create_dms() or obi_open_dms()
|
||||||
* @param name the name of the column
|
* @param name the name of the column
|
||||||
@ -130,5 +129,4 @@ OBIDMSColumn_p obi_create_column(OBIDMS_p dms,
|
|||||||
obiversion_t obi_latest_version(OBIDMS_p dms,char *name);
|
obiversion_t obi_latest_version(OBIDMS_p dms,char *name);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* OBIDMSCOLUMN_H_ */
|
#endif /* OBIDMSCOLUMN_H_ */
|
||||||
|
@ -11,26 +11,54 @@
|
|||||||
/**
|
/**
|
||||||
* @brief The declaration of the external variable `obi_errno`.
|
* @brief The declaration of the external variable `obi_errno`.
|
||||||
*
|
*
|
||||||
* `obi_errno` is an equivalent of `errno` for the system level error
|
* `obi_errno` is an equivalent of `errno` for the system level error,
|
||||||
* but for for error generated by the C layer of the OBITools framework.
|
* but for errors generated by the C layer of the OBITools framework.
|
||||||
*
|
*
|
||||||
* @todo We have to look for defining this variable as thread specific.
|
* @todo We have to look into defining this variable as thread specific.
|
||||||
*/
|
*/
|
||||||
extern int obi_errno;
|
extern int obi_errno;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief set the global `obi_errno` variable with
|
* @brief Sets the global `obi_errno` variable with
|
||||||
* the specified `err` code
|
* the specified `err` code
|
||||||
*
|
*
|
||||||
* This function is defined as a macro to reduce the risk
|
* This function is defined as a macro to reduce the risk
|
||||||
* to increase the problem generating the error by calling
|
* of increasing the problem generating the error by calling
|
||||||
* a new function.
|
* a new function.
|
||||||
*
|
*
|
||||||
* @param err the error code as an integer value
|
* @param err The error code as an integer value.
|
||||||
*
|
*
|
||||||
* @since May 2015
|
* @since May 2015
|
||||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
#define obi_set_errno(err) (obi_errno = (err))
|
#define obi_set_errno(err) (obi_errno = (err))
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup OBIDMSErrors OBIDMS related error codes
|
||||||
|
*
|
||||||
|
* Error codes set in errno following an error related
|
||||||
|
* to the manipulation of an OBIDMS.
|
||||||
|
*
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
#define OBIDMS_EXIST_ERROR (1) /**< Trying to create an OBIDMS with a name
|
||||||
|
* that corresponds to an existing OBIDMS
|
||||||
|
*/
|
||||||
|
#define OBIDMS_NOT_EXIST_ERROR (2) /**< Trying to open a non-existing OBIDMS
|
||||||
|
*/
|
||||||
|
#define OBIDMS_LONG_NAME_ERROR (3) /**< The specified OBIDMS name is too long
|
||||||
|
*/
|
||||||
|
#define OBIDMS_MEMORY_ERROR (4) /**< A memory error occurred during allocation
|
||||||
|
*/
|
||||||
|
#define OBIDMS_UNKNOWN_ERROR (5) /**< Undetermined error
|
||||||
|
*/
|
||||||
|
#define OBIDMS_ACCESS_ERROR (6) /**< Permission error trying to access the database
|
||||||
|
*/
|
||||||
|
#define OBIDMS_BAD_ENDIAN_ERROR (7) /**< The opened data structure does not corresponds
|
||||||
|
* to the endianess of the platform.
|
||||||
|
*/
|
||||||
|
/**@}*/
|
||||||
|
|
||||||
#endif /* OBIERRNO_H_ */
|
#endif /* OBIERRNO_H_ */
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
|
|
||||||
#include "obilittlebigman.h"
|
#include "obilittlebigman.h"
|
||||||
|
|
||||||
bool obi_is_little_end()
|
|
||||||
{
|
bool obi_is_little_endian() {
|
||||||
union { int entier;
|
union { int entier;
|
||||||
char caractere[4] ;
|
char caractere[4] ;
|
||||||
} test;
|
} test;
|
||||||
|
@ -11,17 +11,17 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test is the architecture of the processor is little endian.
|
* Test if the architecture of the processor is little endian.
|
||||||
*
|
*
|
||||||
* ##Two classes of CPU architecture can be define:
|
* ##Two classes of CPU architecture can be defined:
|
||||||
* - little endian
|
* - little endian
|
||||||
* - big endian
|
* - big endian
|
||||||
*
|
*
|
||||||
* They describe the way the processor store multi-byte values
|
* They describe the way the processor stores multi-byte values
|
||||||
* in memory. Considering an 32 bits integer value encoded in
|
* in memory. If we consider a 32 bits integer value encoded in
|
||||||
* hexadecimal `0x11223344`. This value needs four bytes to be
|
* hexadecimal `0x11223344`, this value needs four bytes to be
|
||||||
* stored. These for bytes will have consecutive addresses in memory.
|
* stored. These four bytes will have consecutive addresses in memory.
|
||||||
* Let says that these addresses will be : 01, 02, 03, and 04
|
* Let's say that these addresses will be : 01, 02, 03, and 04
|
||||||
*
|
*
|
||||||
* ###A big endian architecture will store our integer with the following schema:
|
* ###A big endian architecture will store our integer with the following schema:
|
||||||
*
|
*
|
||||||
@ -29,7 +29,7 @@
|
|||||||
* ---------|------|------|------|------
|
* ---------|------|------|------|------
|
||||||
* value | Ox11 | Ox22 | 0x33 | 0x44
|
* value | Ox11 | Ox22 | 0x33 | 0x44
|
||||||
*
|
*
|
||||||
* In this architecture the last address (the end of the representation) is
|
* In this architecture, the last address (the end of the representation) is
|
||||||
* used to store the byte of higher weight (BIG ENDian)
|
* used to store the byte of higher weight (BIG ENDian)
|
||||||
*
|
*
|
||||||
* ###A little endian architecture will store our integer with the following schema:
|
* ###A little endian architecture will store our integer with the following schema:
|
||||||
@ -38,7 +38,7 @@
|
|||||||
* ---------|------|------|------|------
|
* ---------|------|------|------|------
|
||||||
* value | Ox44 | Ox33 | 0x22 | 0x11
|
* value | Ox44 | Ox33 | 0x22 | 0x11
|
||||||
*
|
*
|
||||||
* In this architecture the last address is
|
* In this architecture, the last address is
|
||||||
* used to store the byte of lighter weight (LITTLE ENDian)
|
* used to store the byte of lighter weight (LITTLE ENDian)
|
||||||
*
|
*
|
||||||
* @return a `bool` value:
|
* @return a `bool` value:
|
||||||
@ -48,7 +48,7 @@
|
|||||||
* @since May 2015
|
* @since May 2015
|
||||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
bool obi_is_little_end();
|
bool obi_is_little_endian();
|
||||||
|
|
||||||
|
|
||||||
#endif /* OBILITTLEBIGMAN_H_ */
|
#endif /* OBILITTLEBIGMAN_H_ */
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
#include <obitypes.h>
|
#include <obitypes.h>
|
||||||
|
|
||||||
|
|
||||||
size_t obi_sizeof(OBIType_t type) {
|
size_t obi_sizeof(OBIType_t type) {
|
||||||
size_t size=0;
|
size_t size=0;
|
||||||
|
|
||||||
@ -33,12 +34,12 @@ size_t obi_sizeof(OBIType_t type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t obi_array_sizeof(OBIType_t type,size_t nbelement) {
|
size_t obi_array_sizeof(OBIType_t type, size_t nbelements) {
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t rsize;
|
size_t rsize;
|
||||||
size_t psize;
|
size_t psize;
|
||||||
|
|
||||||
size = obi_sizeof(type) * nbelement;
|
size = obi_sizeof(type) * nbelements;
|
||||||
|
|
||||||
psize= getpagesize();
|
psize= getpagesize();
|
||||||
rsize= size % psize;
|
rsize= size % psize;
|
||||||
@ -47,7 +48,6 @@ size_t obi_array_sizeof(OBIType_t type,size_t nbelement) {
|
|||||||
if (rsize)
|
if (rsize)
|
||||||
size = (size / psize) * psize + psize;
|
size = (size / psize) * psize + psize;
|
||||||
|
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
#define OBIInt_NA (INT32_MIN)
|
#define OBIInt_NA (INT32_MIN)
|
||||||
#define OBIFloat_NA (NAN)
|
#define OBIFloat_NA (NAN)
|
||||||
#define OBIIdx_NA (SIZE_MAX)
|
#define OBIIdx_NA (SIZE_MAX)
|
||||||
@ -28,7 +29,7 @@ typedef enum {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief enum OBITypes for the data type of the OBIColumns.
|
* @brief enum OBITypes for the data type of the OBIDMS columns.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef enum OBIType {
|
typedef enum OBIType {
|
||||||
@ -60,18 +61,18 @@ size_t obi_sizeof(OBIType_t type);
|
|||||||
/**
|
/**
|
||||||
* @brief returns the size requested to store an array of OBIType
|
* @brief returns the size requested to store an array of OBIType
|
||||||
*
|
*
|
||||||
* The returned size is enouth large to store an array of size nbelement
|
* The returned size is large enough to store an array of size nbelement
|
||||||
* but rounded at a multiple of the memory page size.
|
* but rounded at a multiple of the memory page size.
|
||||||
*
|
*
|
||||||
* @param type the OBIType code used as query
|
* @param type the OBIType code used as query
|
||||||
* @param nbelement the number of element to be stored
|
* @param nbelement the number of elements to be stored
|
||||||
*
|
*
|
||||||
* @return the size in bytes of the type
|
* @return the size in bytes of the array
|
||||||
* @retval 0 on error (unknown type)
|
* @retval 0 on error (unknown type)
|
||||||
*
|
*
|
||||||
* @since May 2015
|
* @since May 2015
|
||||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
size_t obi_array_sizeof(OBIType_t type,size_t nbelement);
|
size_t obi_array_sizeof(OBIType_t type, size_t nbelements);
|
||||||
|
|
||||||
#endif /* OBITYPES_H_ */
|
#endif /* OBITYPES_H_ */
|
||||||
|
Reference in New Issue
Block a user