Closes #10 : column groups stored in directories
This commit is contained in:
@ -6,5 +6,5 @@
|
|||||||
../../../src/obilittlebigman.c
|
../../../src/obilittlebigman.c
|
||||||
../../../src/obitypes.h
|
../../../src/obitypes.h
|
||||||
../../../src/obitypes.c
|
../../../src/obitypes.c
|
||||||
../../../src/private_openat.h
|
../../../src/private_at_functions.h
|
||||||
../../../src/private_openat.c
|
../../../src/private_at_functions.c
|
||||||
|
@ -16,11 +16,11 @@ cdef extern from "obidms.h" nogil:
|
|||||||
|
|
||||||
ctypedef OBIDMS_t* OBIDMS_p
|
ctypedef OBIDMS_t* OBIDMS_p
|
||||||
|
|
||||||
OBIDMS_p obi_create_dms(const_char_p name)
|
OBIDMS_p obi_create_dms(const_char_p dms_name)
|
||||||
|
|
||||||
OBIDMS_p obi_open_dms(const_char_p name)
|
OBIDMS_p obi_open_dms(const_char_p dms_name)
|
||||||
|
|
||||||
OBIDMS_p obi_dms(const_char_p name)
|
OBIDMS_p obi_dms(const_char_p dms_name)
|
||||||
|
|
||||||
int obi_close_dms(OBIDMS_p dms)
|
int obi_close_dms(OBIDMS_p dms)
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
../../../../src/obidmscolumn.h
|
../../../../src/obidmscolumn.h
|
||||||
../../../../src/obidmscolumn.c
|
../../../../src/obidmscolumn.c
|
||||||
|
../../../../src/obidmscolumngroup.h
|
||||||
|
../../../../src/obidmscolumngroup.c
|
||||||
../../../../src/obidms.h
|
../../../../src/obidms.h
|
||||||
../../../../src/obidms.c
|
../../../../src/obidms.c
|
||||||
../../../../src/obierrno.h
|
../../../../src/obierrno.h
|
||||||
@ -8,5 +10,5 @@
|
|||||||
../../../../src/obilittlebigman.c
|
../../../../src/obilittlebigman.c
|
||||||
../../../../src/obitypes.h
|
../../../../src/obitypes.h
|
||||||
../../../../src/obitypes.c
|
../../../../src/obitypes.c
|
||||||
../../../../src/private_openat.h
|
../../../../src/private_at_functions.h
|
||||||
../../../../src/private_openat.c
|
../../../../src/private_at_functions.c
|
||||||
|
76
src/obidms.c
76
src/obidms.c
@ -7,15 +7,20 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
#include "obidms.h"
|
#include "obidms.h"
|
||||||
|
#include "obierrno.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
|
||||||
*
|
*
|
||||||
************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -33,7 +38,7 @@
|
|||||||
* @retvalue NULL if an error occurs
|
* @retvalue NULL if an error occurs
|
||||||
*
|
*
|
||||||
* ###Error values
|
* ###Error values
|
||||||
* - OBIDMS_MEMORY_ERROR : something wrong occured during memory allocation.
|
* - OBIDMS_MEMORY_ERROR : something wrong occurred 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
|
||||||
@ -42,11 +47,11 @@
|
|||||||
static char *build_directory_name(const char *dms_name);
|
static char *build_directory_name(const char *dms_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_directory_name(const char *dms_name)
|
static char *build_directory_name(const char *dms_name)
|
||||||
{
|
{
|
||||||
@ -71,31 +76,31 @@ static char *build_directory_name(const char *dms_name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*********************************************************************
|
/**********************************************************************
|
||||||
*
|
*
|
||||||
* 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
|
||||||
*
|
*
|
||||||
*********************************************************************/
|
**********************************************************************/
|
||||||
|
|
||||||
int obi_dms_exists(const char* dms_name)
|
int obi_dms_exists(const char* dms_name)
|
||||||
{
|
{
|
||||||
struct stat buffer;
|
struct stat buffer;
|
||||||
char *directory_name;
|
char *directory_name;
|
||||||
int exists;
|
int check_dir;
|
||||||
|
|
||||||
// Build and check the directory name
|
// Build and check the directory name
|
||||||
directory_name = build_directory_name(dms_name);
|
directory_name = build_directory_name(dms_name);
|
||||||
if (directory_name == NULL)
|
if (directory_name == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
exists = stat(directory_name, &buffer);
|
check_dir = stat(directory_name, &buffer);
|
||||||
|
|
||||||
free(directory_name);
|
free(directory_name);
|
||||||
|
|
||||||
if(exists == 0)
|
if (check_dir == 0)
|
||||||
return 1;
|
return 1;
|
||||||
else // -1
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -108,7 +113,6 @@ OBIDMS_p obi_create_dms(const char* dms_name)
|
|||||||
if (directory_name == NULL)
|
if (directory_name == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
||||||
// Try to create the directory
|
// Try to create the directory
|
||||||
if (mkdir(directory_name, 0x777) < 0)
|
if (mkdir(directory_name, 0x777) < 0)
|
||||||
{
|
{
|
||||||
@ -140,24 +144,26 @@ OBIDMS_p obi_open_dms(const char* dms_name)
|
|||||||
if (directory_name == NULL)
|
if (directory_name == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
// try to open the directory
|
// Try to open the directory
|
||||||
directory = opendir(directory_name);
|
directory = opendir(directory_name);
|
||||||
if (directory == NULL) {
|
if (directory == NULL)
|
||||||
switch (errno) {
|
{
|
||||||
case ENOENT:
|
switch (errno)
|
||||||
obi_set_errno(OBIDMS_NOT_EXIST_ERROR);
|
{
|
||||||
break;
|
case ENOENT:
|
||||||
|
obi_set_errno(OBIDMS_NOT_EXIST_ERROR);
|
||||||
|
break;
|
||||||
|
|
||||||
case EACCES:
|
case EACCES:
|
||||||
obi_set_errno(OBIDMS_ACCESS_ERROR);
|
obi_set_errno(OBIDMS_ACCESS_ERROR);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ENOMEM:
|
case ENOMEM:
|
||||||
obi_set_errno(OBIDMS_MEMORY_ERROR);
|
obi_set_errno(OBIDMS_MEMORY_ERROR);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
||||||
}
|
}
|
||||||
free(directory_name);
|
free(directory_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -165,7 +171,6 @@ OBIDMS_p obi_open_dms(const char* dms_name)
|
|||||||
|
|
||||||
// Allocate the data structure
|
// Allocate the data structure
|
||||||
dms = (OBIDMS_p) malloc(sizeof(OBIDMS_t));
|
dms = (OBIDMS_p) malloc(sizeof(OBIDMS_t));
|
||||||
|
|
||||||
if (dms == NULL)
|
if (dms == NULL)
|
||||||
{
|
{
|
||||||
obi_set_errno(OBIDMS_MEMORY_ERROR);
|
obi_set_errno(OBIDMS_MEMORY_ERROR);
|
||||||
@ -178,15 +183,19 @@ OBIDMS_p obi_open_dms(const char* dms_name)
|
|||||||
dms->directory = directory;
|
dms->directory = directory;
|
||||||
|
|
||||||
free(directory_name);
|
free(directory_name);
|
||||||
|
|
||||||
return dms;
|
return dms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
OBIDMS_p obi_dms(const char* dms_name)
|
OBIDMS_p obi_dms(const char* dms_name)
|
||||||
{
|
{
|
||||||
int exists = obi_dms_exists(dms_name);
|
int exists;
|
||||||
|
|
||||||
switch (exists) {
|
exists = obi_dms_exists(dms_name);
|
||||||
|
|
||||||
|
switch (exists)
|
||||||
|
{
|
||||||
case 0:
|
case 0:
|
||||||
return obi_create_dms(dms_name);
|
return obi_create_dms(dms_name);
|
||||||
case 1:
|
case 1:
|
||||||
@ -194,7 +203,6 @@ OBIDMS_p obi_dms(const char* dms_name)
|
|||||||
};
|
};
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
11
src/obidms.h
11
src/obidms.h
@ -41,12 +41,12 @@ typedef struct OBIDMS {
|
|||||||
*
|
*
|
||||||
* @param dms_name a pointer to a C string containing the name of the database.
|
* @param dms_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`.
|
* `<dms_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 occured
|
* @retvalue -1 an error occurred
|
||||||
*
|
*
|
||||||
* @see obi_close_dms()
|
* @see obi_close_dms()
|
||||||
* @since May 2015
|
* @since May 2015
|
||||||
@ -72,7 +72,7 @@ int obi_dms_exists(const char* dms_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 occured during memory allocation.
|
* - OBIDMS_MEMORY_ERROR : something wrong occurred during memory allocation.
|
||||||
*
|
*
|
||||||
* @see obi_close_dms()
|
* @see obi_close_dms()
|
||||||
* @since May 2015
|
* @since May 2015
|
||||||
@ -92,9 +92,8 @@ OBIDMS_p obi_create_dms(const char *dms_name);
|
|||||||
* @retval NULL on error and the `obi_errno`variable is set.
|
* @retval NULL on error and the `obi_errno`variable is set.
|
||||||
*
|
*
|
||||||
* ###Error values
|
* ###Error values
|
||||||
* - 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 occured during memory allocation.
|
* - OBIDMS_MEMORY_ERROR : something wrong occurred during memory allocation.
|
||||||
*
|
*
|
||||||
* @see obi_close_dms()
|
* @see obi_close_dms()
|
||||||
* @since May 2015
|
* @since May 2015
|
||||||
@ -118,7 +117,7 @@ OBIDMS_p obi_open_dms(const char *dms_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 occured during memory allocation.
|
* - OBIDMS_MEMORY_ERROR : something wrong occurred during memory allocation.
|
||||||
*
|
*
|
||||||
* @see obi_close_dms()
|
* @see obi_close_dms()
|
||||||
* @since May 2015
|
* @since May 2015
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* OBIDMS_column functions *
|
* OBIDMS_column functions *
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -13,22 +13,25 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <dirent.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <sys/mman.h> /* mmap() is defined in this header */
|
#include <sys/mman.h> /* mmap() is defined in this header */
|
||||||
|
|
||||||
#include "obidmscolumn.h"
|
#include "obidmscolumn.h"
|
||||||
|
#include "obidmscolumngroup.h"
|
||||||
#include "obidms.h"
|
#include "obidms.h"
|
||||||
#include "obitypes.h"
|
#include "obitypes.h"
|
||||||
#include "obierrno.h"
|
#include "obierrno.h"
|
||||||
#include "obilittlebigman.h"
|
#include "obilittlebigman.h"
|
||||||
#include "private_openat.h"
|
#include "private_at_functions.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
|
||||||
*
|
*
|
||||||
*************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -44,7 +47,7 @@
|
|||||||
* @retvalue NULL if an error occurs
|
* @retvalue NULL if an error occurs
|
||||||
*
|
*
|
||||||
* ###Error values
|
* ###Error values
|
||||||
* - OBIDMS_MEMORY_ERROR : something wrong occured during memory allocation.
|
* - OBIDMS_MEMORY_ERROR : something wrong occurred during memory allocation.
|
||||||
*
|
*
|
||||||
* @since May 2015
|
* @since May 2015
|
||||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||||
@ -90,7 +93,7 @@ static char *build_version_file_name(const char *column_name);
|
|||||||
* @since May 2015
|
* @since May 2015
|
||||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
static obiversion_t obi_get_new_version_number(OBIDMS_p dms, char *column_name, bool block);
|
static obiversion_t obi_get_new_version_number(OBIDMS_column_group_p column_group, bool block);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -108,7 +111,7 @@ static obiversion_t obi_get_new_version_number(OBIDMS_p dms, char *column_name,
|
|||||||
* @since May 2015
|
* @since May 2015
|
||||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
static int create_version_file(OBIDMS_p dms, char *column_name);
|
static int create_version_file(OBIDMS_column_group_p column_group);
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************
|
/************************************************************************
|
||||||
@ -124,7 +127,7 @@ static char *build_column_file_name(const char *column_name, obiversion_t versio
|
|||||||
// Build the database directory name
|
// Build the database directory name
|
||||||
if (asprintf(&filename,"%s@%d.odc", column_name, version_number) < 0)
|
if (asprintf(&filename,"%s@%d.odc", column_name, version_number) < 0)
|
||||||
{
|
{
|
||||||
obi_set_errno(OBIDMS_MEMORY_ERROR);
|
obi_set_errno(OBICOL_MEMORY_ERROR);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +142,7 @@ static char *build_version_file_name(const char *column_name)
|
|||||||
// Build the database directory name
|
// Build the database directory name
|
||||||
if (asprintf(&filename,"%s.odv", column_name) < 0)
|
if (asprintf(&filename,"%s.odv", column_name) < 0)
|
||||||
{
|
{
|
||||||
obi_set_errno(OBIDMS_MEMORY_ERROR);
|
obi_set_errno(OBICOL_MEMORY_ERROR);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,12 +150,12 @@ static char *build_version_file_name(const char *column_name)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static obiversion_t obi_get_new_version_number(OBIDMS_p dms, char *column_name, bool block)
|
static obiversion_t obi_get_new_version_number(OBIDMS_column_group_p column_group, bool block)
|
||||||
{
|
{
|
||||||
off_t loc_size;
|
off_t loc_size;
|
||||||
obiversion_t new_version_number;
|
obiversion_t new_version_number;
|
||||||
char* version_file_name;
|
char* version_file_name;
|
||||||
int directory_file_descriptor;
|
int column_dir_file_descriptor;
|
||||||
int version_file_descriptor;
|
int version_file_descriptor;
|
||||||
bool little_endian;
|
bool little_endian;
|
||||||
int lock_mode;
|
int lock_mode;
|
||||||
@ -166,34 +169,31 @@ static obiversion_t obi_get_new_version_number(OBIDMS_p dms, char *column_name,
|
|||||||
else
|
else
|
||||||
lock_mode=F_TLOCK;
|
lock_mode=F_TLOCK;
|
||||||
|
|
||||||
// build the version file name
|
// Build the version file name
|
||||||
version_file_name = build_version_file_name(column_name);
|
version_file_name = build_version_file_name(column_group->column_name);
|
||||||
if (version_file_name == NULL)
|
if (version_file_name == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// Get the file descriptor associated to the database directory
|
// Get the file descriptor associated to the column group directory
|
||||||
directory_file_descriptor = dirfd(dms->directory);
|
column_dir_file_descriptor = dirfd(column_group->directory);
|
||||||
if (directory_file_descriptor < 0)
|
if (column_dir_file_descriptor < 0)
|
||||||
{
|
{
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//open the version file
|
// Open the version file
|
||||||
version_file_descriptor = private_openat(directory_file_descriptor, version_file_name, O_RDWR);
|
version_file_descriptor = private_openat(column_dir_file_descriptor, version_file_name, O_RDWR);
|
||||||
|
|
||||||
if (version_file_descriptor < 0)
|
if (version_file_descriptor < 0)
|
||||||
{
|
{
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
|
//close(column_dir_file_descriptor);
|
||||||
if (errno == ENOENT)
|
if (errno == ENOENT)
|
||||||
{
|
return create_version_file(column_group);
|
||||||
return create_version_file(dms, column_name);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -201,199 +201,223 @@ static obiversion_t obi_get_new_version_number(OBIDMS_p dms, char *column_name,
|
|||||||
// Test if the version file size is ok
|
// Test if the version file size is ok
|
||||||
if (lseek(version_file_descriptor, 0, SEEK_END) < loc_size)
|
if (lseek(version_file_descriptor, 0, SEEK_END) < loc_size)
|
||||||
{
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
close(version_file_descriptor);
|
close(version_file_descriptor);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
close(column_dir_file_descriptor);
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare the file for locking
|
// Prepare the file for locking
|
||||||
if (lseek(version_file_descriptor, 0, SEEK_SET) != 0)
|
if (lseek(version_file_descriptor, 0, SEEK_SET) != 0)
|
||||||
{
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
close(version_file_descriptor);
|
close(version_file_descriptor);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
close(column_dir_file_descriptor);
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock the file
|
// Lock the file
|
||||||
if (lockf(version_file_descriptor, lock_mode, loc_size) < -1)
|
if (lockf(version_file_descriptor, lock_mode, loc_size) < 0)
|
||||||
{
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
close(version_file_descriptor);
|
close(version_file_descriptor);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
close(column_dir_file_descriptor);
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// read the endianess of the file
|
// Read the endianness of the file
|
||||||
if (read(version_file_descriptor, &little_endian, sizeof(bool)) < sizeof(bool))
|
if (read(version_file_descriptor, &little_endian, sizeof(bool)) < sizeof(bool))
|
||||||
{
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
close(version_file_descriptor);
|
close(version_file_descriptor);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
close(column_dir_file_descriptor);
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if endianess is correct
|
// Check if endianness is correct
|
||||||
if (little_endian != obi_is_little_endian())
|
if (little_endian != obi_is_little_endian())
|
||||||
{
|
{
|
||||||
|
obi_set_errno(OBICOL_BAD_ENDIAN_ERROR);
|
||||||
close(version_file_descriptor);
|
close(version_file_descriptor);
|
||||||
obi_set_errno(OBIDMS_BAD_ENDIAN_ERROR);
|
close(column_dir_file_descriptor);
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// read the current version number
|
// Read the current version number
|
||||||
if (read(version_file_descriptor, &new_version_number, sizeof(obiversion_t)) < sizeof(obiversion_t))
|
if (read(version_file_descriptor, &new_version_number, sizeof(obiversion_t)) < sizeof(obiversion_t))
|
||||||
{
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
close(version_file_descriptor);
|
close(version_file_descriptor);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
close(column_dir_file_descriptor);
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_version_number++;
|
new_version_number++;
|
||||||
|
|
||||||
// write the new version number
|
// Write the new version number
|
||||||
if (lseek(version_file_descriptor, sizeof(bool), SEEK_SET) != sizeof(bool))
|
if (lseek(version_file_descriptor, sizeof(bool), SEEK_SET) != sizeof(bool))
|
||||||
{
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
close(version_file_descriptor);
|
close(version_file_descriptor);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
close(column_dir_file_descriptor);
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write(version_file_descriptor, &new_version_number, sizeof(obiversion_t)) < sizeof(obiversion_t))
|
if (write(version_file_descriptor, &new_version_number, sizeof(obiversion_t)) < sizeof(obiversion_t))
|
||||||
{
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
close(version_file_descriptor);
|
close(version_file_descriptor);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
close(column_dir_file_descriptor);
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare for the unlocking
|
// Prepare for unlocking
|
||||||
if (lseek(version_file_descriptor, 0, SEEK_SET) != 0)
|
if (lseek(version_file_descriptor, 0, SEEK_SET) != 0)
|
||||||
{
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
close(version_file_descriptor);
|
close(version_file_descriptor);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
close(column_dir_file_descriptor);
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// unlock the file
|
// Unlock the file
|
||||||
if (lockf(version_file_descriptor, F_ULOCK, loc_size) < -1)
|
if (lockf(version_file_descriptor, F_ULOCK, loc_size) < 0)
|
||||||
{
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
close(version_file_descriptor);
|
close(version_file_descriptor);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
close(column_dir_file_descriptor);
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(version_file_descriptor);
|
//close(version_file_descriptor);
|
||||||
|
//close(column_dir_file_descriptor);
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
|
|
||||||
return new_version_number;
|
return new_version_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int create_version_file(OBIDMS_p dms, char *column_name)
|
static int create_version_file(OBIDMS_column_group_p column_group)
|
||||||
{
|
{
|
||||||
off_t loc_size;
|
off_t loc_size;
|
||||||
obiversion_t version_number;
|
obiversion_t version_number;
|
||||||
char* version_file_name;
|
char* version_file_name;
|
||||||
int directory_file_descriptor;
|
int column_dir_file_descriptor;
|
||||||
int version_file_descriptor;
|
int version_file_descriptor;
|
||||||
bool little_endian;
|
bool little_endian;
|
||||||
|
|
||||||
loc_size = sizeof(bool) + sizeof(obiversion_t);
|
loc_size = sizeof(bool) + sizeof(obiversion_t);
|
||||||
version_number = 0;
|
version_number = 0;
|
||||||
|
|
||||||
version_file_name = build_version_file_name(column_name);
|
version_file_name = build_version_file_name(column_group->column_name);
|
||||||
|
|
||||||
if (version_file_name == NULL)
|
if (version_file_name == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
directory_file_descriptor = dirfd(dms->directory);
|
// Get the file descriptor associated to the column group directory
|
||||||
if (directory_file_descriptor < 0)
|
column_dir_file_descriptor = dirfd(column_group->directory);
|
||||||
|
if (column_dir_file_descriptor < 0)
|
||||||
{
|
{
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
version_file_descriptor = private_openat(directory_file_descriptor,
|
// Get the file descriptor associated to the version file
|
||||||
version_file_name,
|
version_file_descriptor = private_openat(column_dir_file_descriptor, version_file_name, O_RDWR | O_CREAT);
|
||||||
O_RDWR | O_CREAT);
|
|
||||||
|
|
||||||
if (version_file_descriptor < 0)
|
if (version_file_descriptor < 0)
|
||||||
{
|
{
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
|
close(column_dir_file_descriptor);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lock the file
|
// Lock the file
|
||||||
if (lockf(version_file_descriptor, F_LOCK, loc_size) < -1)
|
if (lockf(version_file_descriptor, F_LOCK, loc_size) < 0)
|
||||||
{
|
{
|
||||||
close(version_file_descriptor);
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
|
close(version_file_descriptor);
|
||||||
|
close(column_dir_file_descriptor);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Truncate the version file to the right size
|
||||||
if (ftruncate(version_file_descriptor, loc_size) < 0)
|
if (ftruncate(version_file_descriptor, loc_size) < 0)
|
||||||
{
|
{
|
||||||
close(version_file_descriptor);
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
|
close(version_file_descriptor);
|
||||||
|
close(column_dir_file_descriptor);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Position offset to 0 to prepare for writing
|
||||||
if (lseek(version_file_descriptor, 0, SEEK_SET) != 0)
|
if (lseek(version_file_descriptor, 0, SEEK_SET) != 0)
|
||||||
{
|
{
|
||||||
close(version_file_descriptor);
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
|
close(version_file_descriptor);
|
||||||
|
close(column_dir_file_descriptor);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
little_endian = obi_is_little_endian();
|
little_endian = obi_is_little_endian();
|
||||||
|
|
||||||
|
// Write endianness
|
||||||
if (write(version_file_descriptor, &little_endian, sizeof(bool)) < sizeof(bool))
|
if (write(version_file_descriptor, &little_endian, sizeof(bool)) < sizeof(bool))
|
||||||
{
|
{
|
||||||
close(version_file_descriptor);
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
|
close(version_file_descriptor);
|
||||||
|
close(column_dir_file_descriptor);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write version number
|
||||||
if (write(version_file_descriptor, &version_number, sizeof(obiversion_t)) < sizeof(obiversion_t))
|
if (write(version_file_descriptor, &version_number, sizeof(obiversion_t)) < sizeof(obiversion_t))
|
||||||
{
|
{
|
||||||
close(version_file_descriptor);
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
|
close(version_file_descriptor);
|
||||||
|
close(column_dir_file_descriptor);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare for the unlocking
|
// Prepare for unlocking
|
||||||
if (lseek(version_file_descriptor, 0, SEEK_SET) != 0)
|
if (lseek(version_file_descriptor, 0, SEEK_SET) != 0)
|
||||||
{
|
{
|
||||||
close(version_file_descriptor);
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
|
close(version_file_descriptor);
|
||||||
|
close(column_dir_file_descriptor);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// unlock the file
|
// Unlock the file
|
||||||
if (lockf(version_file_descriptor, F_ULOCK, loc_size) < -1)
|
if (lockf(version_file_descriptor, F_ULOCK, loc_size) < 0)
|
||||||
{
|
{
|
||||||
close(version_file_descriptor);
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
|
close(version_file_descriptor);
|
||||||
|
close(column_dir_file_descriptor);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
close(version_file_descriptor);
|
//close(version_file_descriptor);
|
||||||
|
//close(column_dir_file_descriptor);
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
|
|
||||||
return version_number;
|
return version_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -404,80 +428,95 @@ static int create_version_file(OBIDMS_p dms, char *column_name)
|
|||||||
*
|
*
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
|
|
||||||
obiversion_t obi_get_latest_version_number(OBIDMS_p dms, char *column_name)
|
obiversion_t obi_get_latest_version_number(OBIDMS_column_group_p column_group)
|
||||||
{
|
{
|
||||||
off_t loc_size;
|
off_t loc_size;
|
||||||
obiversion_t latest_version_number;
|
obiversion_t latest_version_number;
|
||||||
char * version_file_name;
|
char * version_file_name;
|
||||||
int directory_file_descriptor;
|
int column_dir_file_descriptor;
|
||||||
int version_file_descriptor;
|
int version_file_descriptor;
|
||||||
bool little_endian;
|
bool little_endian;
|
||||||
|
|
||||||
loc_size = sizeof(bool) + sizeof(obiversion_t);
|
loc_size = sizeof(bool) + sizeof(obiversion_t);
|
||||||
latest_version_number = 0;
|
latest_version_number = 0;
|
||||||
|
|
||||||
version_file_name = build_version_file_name(column_name);
|
version_file_name = build_version_file_name(column_group->column_name);
|
||||||
if (version_file_name==NULL)
|
if (version_file_name==NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
directory_file_descriptor = dirfd(dms->directory);
|
// Get the file descriptor associated to the column group directory
|
||||||
if (directory_file_descriptor < 0) {
|
column_dir_file_descriptor = dirfd(column_group->directory);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
if (column_dir_file_descriptor < 0)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
version_file_descriptor = private_openat(directory_file_descriptor, version_file_name, O_RDONLY);
|
// Get the file descriptor associated to the version file
|
||||||
|
version_file_descriptor = private_openat(column_dir_file_descriptor, version_file_name, O_RDONLY);
|
||||||
if (version_file_descriptor < 0) {
|
if (version_file_descriptor < 0)
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
|
close(column_dir_file_descriptor);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check that the version file size is ok
|
||||||
if (lseek(version_file_descriptor, 0, SEEK_END) < loc_size)
|
if (lseek(version_file_descriptor, 0, SEEK_END) < loc_size)
|
||||||
{
|
{
|
||||||
close(version_file_descriptor);
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
|
close(version_file_descriptor);
|
||||||
|
close(column_dir_file_descriptor);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set the offset to 0 in the version file
|
||||||
if (lseek(version_file_descriptor, 0, SEEK_SET) != 0)
|
if (lseek(version_file_descriptor, 0, SEEK_SET) != 0)
|
||||||
{
|
{
|
||||||
close(version_file_descriptor);
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
|
close(version_file_descriptor);
|
||||||
|
close(column_dir_file_descriptor);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read the endianness
|
||||||
if (read(version_file_descriptor, &little_endian, sizeof(bool)) < sizeof(bool))
|
if (read(version_file_descriptor, &little_endian, sizeof(bool)) < sizeof(bool))
|
||||||
{
|
{
|
||||||
close(version_file_descriptor);
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
|
close(version_file_descriptor);
|
||||||
|
close(column_dir_file_descriptor);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Verify the endianness
|
||||||
if (little_endian != obi_is_little_endian())
|
if (little_endian != obi_is_little_endian())
|
||||||
{
|
{
|
||||||
close(version_file_descriptor);
|
obi_set_errno(OBICOL_BAD_ENDIAN_ERROR);
|
||||||
obi_set_errno(OBIDMS_BAD_ENDIAN_ERROR);
|
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
|
close(version_file_descriptor);
|
||||||
|
close(column_dir_file_descriptor);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read the latest version number
|
||||||
if (read(version_file_descriptor, &latest_version_number, sizeof(obiversion_t)) < sizeof(obiversion_t))
|
if (read(version_file_descriptor, &latest_version_number, sizeof(obiversion_t)) < sizeof(obiversion_t))
|
||||||
{
|
{
|
||||||
close(version_file_descriptor);
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
|
close(version_file_descriptor);
|
||||||
|
close(column_dir_file_descriptor);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
close(version_file_descriptor);
|
|
||||||
free(version_file_name);
|
free(version_file_name);
|
||||||
|
//close(version_file_descriptor);
|
||||||
|
//close(column_dir_file_descriptor);
|
||||||
|
|
||||||
return latest_version_number;
|
return latest_version_number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -489,104 +528,139 @@ size_t obi_get_platform_header_size()
|
|||||||
|
|
||||||
|
|
||||||
OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||||
char *column_name,
|
const char *column_name,
|
||||||
OBIType_t type,
|
OBIType_t type,
|
||||||
size_t nb_elements)
|
size_t nb_elements)
|
||||||
{
|
{
|
||||||
OBIDMS_column_p new_column;
|
OBIDMS_column_p new_column;
|
||||||
|
OBIDMS_column_group_p column_group;
|
||||||
OBIDMS_column_header_p header;
|
OBIDMS_column_header_p header;
|
||||||
size_t file_size;
|
size_t file_size;
|
||||||
obiversion_t version_number;
|
obiversion_t version_number;
|
||||||
char* column_file_name;
|
char* column_file_name;
|
||||||
int column_file_descriptor;
|
int column_file_descriptor;
|
||||||
int directory_file_descriptor;
|
int column_dir_file_descriptor;
|
||||||
size_t header_size;
|
size_t header_size;
|
||||||
size_t data_size;
|
size_t data_size;
|
||||||
|
|
||||||
new_column = NULL;
|
new_column = NULL;
|
||||||
|
|
||||||
directory_file_descriptor = dirfd(dms->directory);
|
// Get the column group structure associated to the column
|
||||||
if (directory_file_descriptor < 0) {
|
column_group = obi_column_group(dms, column_name);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
if (column_group == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
// Get the file descriptor associated to the column group directory
|
||||||
|
column_dir_file_descriptor = dirfd(column_group->directory);
|
||||||
|
if (column_dir_file_descriptor < 0)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOLDIR_UNKNOWN_ERROR);
|
||||||
|
obi_close_column_group(column_group);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate the size needed
|
||||||
header_size = obi_get_platform_header_size();
|
header_size = obi_get_platform_header_size();
|
||||||
data_size = obi_array_sizeof(type, nb_elements);
|
data_size = obi_array_sizeof(type, nb_elements);
|
||||||
|
|
||||||
file_size = header_size + data_size;
|
file_size = header_size + data_size;
|
||||||
|
|
||||||
version_number = obi_get_new_version_number(dms, column_name, true);
|
// Get the latest version number
|
||||||
|
version_number = obi_get_new_version_number(column_group, true);
|
||||||
if (version_number < 0)
|
if (version_number < 0)
|
||||||
{
|
{
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
obi_close_column_group(column_group);
|
||||||
|
close(column_dir_file_descriptor);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the column file name
|
||||||
column_file_name = build_column_file_name(column_name, version_number);
|
column_file_name = build_column_file_name(column_name, version_number);
|
||||||
|
if (column_file_name == NULL)
|
||||||
|
{
|
||||||
|
obi_close_column_group(column_group);
|
||||||
|
close(column_dir_file_descriptor);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
column_file_descriptor = private_openat(directory_file_descriptor,
|
// Open the column file
|
||||||
column_file_name,
|
column_file_descriptor = private_openat(column_dir_file_descriptor, column_file_name, O_RDWR | O_CREAT);
|
||||||
O_RDWR | O_CREAT);
|
if (column_file_descriptor < 0)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obi_close_column_group(column_group);
|
||||||
|
close(column_dir_file_descriptor);
|
||||||
|
free(column_file_name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Truncate the column file to the right size
|
||||||
if (ftruncate(column_file_descriptor, file_size) < 0)
|
if (ftruncate(column_file_descriptor, file_size) < 0)
|
||||||
{
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obi_close_column_group(column_group);
|
||||||
|
close(column_dir_file_descriptor);
|
||||||
close(column_file_descriptor);
|
close(column_file_descriptor);
|
||||||
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
|
||||||
free(column_file_name);
|
free(column_file_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Allocate the memory for the column structure
|
||||||
new_column = (OBIDMS_column_p) malloc(sizeof(OBIDMS_column_t));
|
new_column = (OBIDMS_column_p) malloc(sizeof(OBIDMS_column_t));
|
||||||
|
if (new_column == NULL)
|
||||||
if (new_column)
|
|
||||||
{
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obi_close_column_group(column_group);
|
||||||
|
close(column_dir_file_descriptor);
|
||||||
close(column_file_descriptor);
|
close(column_file_descriptor);
|
||||||
obi_set_errno(OBIDMS_MEMORY_ERROR);
|
|
||||||
free(column_file_name);
|
free(column_file_name);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_column->dms = dms;
|
// Fill the column structure
|
||||||
new_column->header = mmap(NULL,
|
new_column->dms = dms;
|
||||||
header_size,
|
new_column->column_group = column_group;
|
||||||
PROT_READ | PROT_WRITE,
|
new_column->header = mmap(NULL,
|
||||||
MAP_SHARED,
|
header_size,
|
||||||
column_file_descriptor,
|
PROT_READ | PROT_WRITE,
|
||||||
0
|
MAP_SHARED,
|
||||||
);
|
column_file_descriptor,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
if (new_column->header == MAP_FAILED)
|
if (new_column->header == MAP_FAILED)
|
||||||
{
|
{
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obi_close_column_group(column_group);
|
||||||
|
close(column_dir_file_descriptor);
|
||||||
close(column_file_descriptor);
|
close(column_file_descriptor);
|
||||||
obi_set_errno(OBIDMS_MEMORY_ERROR);
|
|
||||||
free(column_file_name);
|
free(column_file_name);
|
||||||
free(new_column);
|
free(new_column);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_column->data = mmap(NULL,
|
new_column->data = mmap(NULL,
|
||||||
data_size,
|
data_size,
|
||||||
PROT_READ | PROT_WRITE,
|
PROT_READ | PROT_WRITE,
|
||||||
MAP_SHARED,
|
MAP_SHARED,
|
||||||
column_file_descriptor,
|
column_file_descriptor,
|
||||||
header_size
|
header_size
|
||||||
);
|
);
|
||||||
|
|
||||||
if (new_column->data == MAP_FAILED)
|
if (new_column->data == MAP_FAILED)
|
||||||
{
|
{
|
||||||
munmap(new_column->header, header_size);
|
munmap(new_column->header, header_size);
|
||||||
|
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||||
|
obi_close_column_group(column_group);
|
||||||
|
close(column_dir_file_descriptor);
|
||||||
close(column_file_descriptor);
|
close(column_file_descriptor);
|
||||||
obi_set_errno(OBIDMS_MEMORY_ERROR);
|
|
||||||
free(column_file_name);
|
free(column_file_name);
|
||||||
free(new_column);
|
free(new_column);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_column->writable= true;
|
new_column->writable = true;
|
||||||
|
|
||||||
header = new_column->header;
|
header = new_column->header;
|
||||||
header->little_endian = obi_is_little_endian();
|
header->little_endian = obi_is_little_endian();
|
||||||
header->header_size = header_size;
|
header->header_size = header_size;
|
||||||
header->line_count = nb_elements;
|
header->line_count = nb_elements;
|
||||||
@ -598,14 +672,9 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
|||||||
strncpy(header->name, column_name, OBIDMS_MAX_COLNAME);
|
strncpy(header->name, column_name, OBIDMS_MAX_COLNAME);
|
||||||
|
|
||||||
free(column_file_name);
|
free(column_file_name);
|
||||||
|
//obi_close_column_group(column_group);
|
||||||
|
//close(column_dir_file_descriptor);
|
||||||
|
//close(column_file_descriptor);
|
||||||
|
|
||||||
return new_column;
|
return new_column;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// if( access( fname, F_OK ) != -1 ) {
|
|
||||||
// // file exists
|
|
||||||
// } else {
|
|
||||||
// // file doesn't exist
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,11 +22,9 @@
|
|||||||
#include "obitypes.h"
|
#include "obitypes.h"
|
||||||
#include "obierrno.h"
|
#include "obierrno.h"
|
||||||
#include "obilittlebigman.h"
|
#include "obilittlebigman.h"
|
||||||
|
#include "obidmscolumngroup.h"
|
||||||
|
|
||||||
|
|
||||||
#define OBIDMS_MAX_COLNAME (128) /**< The maximum length of an OBIDMS column name
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef int32_t obiversion_t; /**< Used to store the column version number
|
typedef int32_t obiversion_t; /**< Used to store the column version number
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -35,7 +33,7 @@ typedef int32_t obiversion_t; /**< Used to store the column version number
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct OBIDMS_column_header {
|
typedef struct OBIDMS_column_header {
|
||||||
bool little_endian; /**< endianess of the column:
|
bool little_endian; /**< endianness of the column:
|
||||||
- `true` on little endian platforms
|
- `true` on little endian platforms
|
||||||
- `false` on big endian platforms
|
- `false` on big endian platforms
|
||||||
|
|
||||||
@ -57,6 +55,7 @@ typedef struct OBIDMS_column_header {
|
|||||||
*/
|
*/
|
||||||
} OBIDMS_column_header_t, *OBIDMS_column_header_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
|
||||||
*
|
*
|
||||||
@ -64,25 +63,27 @@ typedef struct OBIDMS_column_header {
|
|||||||
* creating, opening or cloning an OBIDMS_column.
|
* creating, opening or cloning an OBIDMS_column.
|
||||||
*/
|
*/
|
||||||
typedef struct OBIDMS_column {
|
typedef struct OBIDMS_column {
|
||||||
OBIDMS_p dms ; /**< A pointer to a DMS instance
|
OBIDMS_p dms; /**< A pointer to a DMS instance
|
||||||
*/
|
*/
|
||||||
OBIDMS_column_header_p header; /**< A pointer to the header of the column
|
OBIDMS_column_group_p column_group; /**< A pointer to an OBIDMS column group instance
|
||||||
*/
|
*/
|
||||||
void* data; /**< A `void` pointer to the beginning of the
|
OBIDMS_column_header_p header; /**< A pointer to the header of the column
|
||||||
* data.
|
*/
|
||||||
*
|
void* data; /**< A `void` pointer to the beginning of the
|
||||||
* @warning never use this member directly
|
* data.
|
||||||
* outside of the code of the
|
*
|
||||||
* low level functions
|
* @warning never use this member directly
|
||||||
* of the OBITools DMS
|
* outside of the code of the
|
||||||
*/
|
* low level functions
|
||||||
bool writable;/**< Indicates if the column is writable or not.
|
* of the OBITools DMS
|
||||||
* - `true` the column is writable
|
*/
|
||||||
* - `false` the column is read-only
|
bool writable; /**< Indicates if the column is writable or not.
|
||||||
*
|
* - `true` the column is writable
|
||||||
* A column is writable only by its creator
|
* - `false` the column is read-only
|
||||||
* until it closes it.
|
*
|
||||||
*/
|
* A column is writable only by its creator
|
||||||
|
* until it closes it.
|
||||||
|
*/
|
||||||
} OBIDMS_column_t, *OBIDMS_column_p;
|
} OBIDMS_column_t, *OBIDMS_column_p;
|
||||||
|
|
||||||
|
|
||||||
@ -103,7 +104,7 @@ size_t obi_get_platform_header_size();
|
|||||||
/**
|
/**
|
||||||
* @brief Creates a column.
|
* @brief Creates a column.
|
||||||
*
|
*
|
||||||
* @param dms a pointer as returned by obi_create_dms() or obi_open_dms()
|
* @param dms a pointer on an OBIDMS column
|
||||||
* @param column_name the name of the new column
|
* @param column_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 nb_elements the number of elements to be stored
|
* @param nb_elements the number of elements to be stored
|
||||||
@ -112,9 +113,9 @@ size_t obi_get_platform_header_size();
|
|||||||
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
* @author Eric Coissac (eric.coissac@metabarcoding.org)
|
||||||
*/
|
*/
|
||||||
OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||||
char* column_name,
|
const char* column_name,
|
||||||
OBIType_t type,
|
OBIType_t type,
|
||||||
size_t nb_elements);
|
size_t nb_elements);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -126,7 +127,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
|||||||
* @return the bigger version number used for this column
|
* @return the bigger version number used for this column
|
||||||
* @return -1 if the column does not exist
|
* @return -1 if the column does not exist
|
||||||
*/
|
*/
|
||||||
obiversion_t obi_get_latest_version_number(OBIDMS_p dms, char *column_name);
|
obiversion_t obi_get_latest_version_number(OBIDMS_column_group_p column_group);
|
||||||
|
|
||||||
|
|
||||||
#endif /* OBIDMSCOLUMN_H_ */
|
#endif /* OBIDMSCOLUMN_H_ */
|
||||||
|
283
src/obidmscolumngroup.c
Normal file
283
src/obidmscolumngroup.c
Normal file
@ -0,0 +1,283 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* OBIDMS column groups functions *
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file obidmscolumngroup.c
|
||||||
|
* @author Celine Mercier
|
||||||
|
* @date 18 June 2015
|
||||||
|
* @brief Functions for OBIDMS column groups.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include "obidmscolumngroup.h"
|
||||||
|
#include "obidms.h"
|
||||||
|
#include "private_at_functions.h"
|
||||||
|
#include "obierrno.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
|
||||||
|
*
|
||||||
|
**************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internal function building the group directory name from an OBIDMS column name.
|
||||||
|
*
|
||||||
|
* The function builds the directory name corresponding to an OBIDMS column group.
|
||||||
|
* It checks also that the name is not too long.
|
||||||
|
*
|
||||||
|
* @warning The returned pointer has to be freed by the caller.
|
||||||
|
*
|
||||||
|
* @param column_name the name of the OBIDMS column
|
||||||
|
*
|
||||||
|
* @return a pointer to the OBIDMS column directory name
|
||||||
|
* @retvalue <column_directory_name> if everything is ok
|
||||||
|
* @retvalue NULL if an error occurs
|
||||||
|
*
|
||||||
|
* ###Error values
|
||||||
|
* - OBIDMS_MEMORY_ERROR : something wrong occurred during memory allocation.
|
||||||
|
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
|
||||||
|
*
|
||||||
|
* @since June 2015
|
||||||
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
|
*/
|
||||||
|
static char* build_column_directory_name(const char* column_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
|
||||||
|
*
|
||||||
|
************************************************************************/
|
||||||
|
|
||||||
|
static char* build_column_directory_name(const char* column_name)
|
||||||
|
{
|
||||||
|
char* column_directory_name;
|
||||||
|
|
||||||
|
// Build the database directory name
|
||||||
|
if (asprintf(&column_directory_name, "%s.obicol", column_name) < 0)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOLDIR_MEMORY_ERROR);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test if the database name is not too long
|
||||||
|
if (strlen(column_directory_name) >= OBIDMS_COLUMN_DIR_MAX_NAME)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOLDIR_LONG_NAME_ERROR);
|
||||||
|
free(column_directory_name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return column_directory_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**********************************************************************
|
||||||
|
*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
**********************************************************************/
|
||||||
|
|
||||||
|
int obi_column_group_exists(OBIDMS_p dms, const char* column_name)
|
||||||
|
{
|
||||||
|
struct stat buffer;
|
||||||
|
char* column_directory_name;
|
||||||
|
char* full_path;
|
||||||
|
int check_dir;
|
||||||
|
int dms_file_descriptor;
|
||||||
|
|
||||||
|
// Build and check the directory name
|
||||||
|
column_directory_name = build_column_directory_name(column_name);
|
||||||
|
if (column_directory_name == NULL)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOLDIR_UNKNOWN_ERROR);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the file descriptor for the dms
|
||||||
|
dms_file_descriptor = dirfd(dms->directory);
|
||||||
|
if (dms_file_descriptor < 0)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
||||||
|
free(column_directory_name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the full path for the column directory
|
||||||
|
full_path = get_full_path(dms_file_descriptor, column_directory_name);
|
||||||
|
if (full_path == NULL)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOLDIR_UNKNOWN_ERROR);
|
||||||
|
free(column_directory_name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
check_dir = stat(full_path, &buffer);
|
||||||
|
|
||||||
|
free(column_directory_name);
|
||||||
|
free(full_path);
|
||||||
|
//close(dms_file_descriptor);
|
||||||
|
|
||||||
|
if(check_dir == 0)
|
||||||
|
return 1;
|
||||||
|
else
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
OBIDMS_column_group_p obi_create_column_group(OBIDMS_p dms, const char* column_name)
|
||||||
|
{
|
||||||
|
char* column_directory_name;
|
||||||
|
int dms_file_descriptor;
|
||||||
|
|
||||||
|
// Build and check the directory name
|
||||||
|
column_directory_name = build_column_directory_name(column_name);
|
||||||
|
if (column_directory_name == NULL)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOLDIR_UNKNOWN_ERROR);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the file descriptor for the dms
|
||||||
|
dms_file_descriptor = dirfd(dms->directory);
|
||||||
|
if (dms_file_descriptor < 0)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
||||||
|
free(column_directory_name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to create the directory
|
||||||
|
if (private_mkdirat(dms_file_descriptor, column_directory_name, 0x777) < 0)
|
||||||
|
{
|
||||||
|
if (errno == EEXIST)
|
||||||
|
obi_set_errno(OBICOLDIR_EXIST_ERROR);
|
||||||
|
else
|
||||||
|
obi_set_errno(OBICOLDIR_UNKNOWN_ERROR);
|
||||||
|
free(column_directory_name);
|
||||||
|
close(dms_file_descriptor);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(column_directory_name);
|
||||||
|
//close(dms_file_descriptor);
|
||||||
|
|
||||||
|
return obi_open_column_group(dms, column_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
OBIDMS_column_group_p obi_open_column_group(OBIDMS_p dms, const char* column_name)
|
||||||
|
{
|
||||||
|
OBIDMS_column_group_p column_group;
|
||||||
|
char* column_directory_name;
|
||||||
|
DIR* directory;
|
||||||
|
int dms_file_descriptor;
|
||||||
|
|
||||||
|
column_group = NULL;
|
||||||
|
|
||||||
|
// Build and check the directory name
|
||||||
|
column_directory_name = build_column_directory_name(column_name);
|
||||||
|
if (column_directory_name == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
// Get the file descriptor for the dms
|
||||||
|
dms_file_descriptor = dirfd(dms->directory);
|
||||||
|
if (dms_file_descriptor < 0)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBIDMS_UNKNOWN_ERROR);
|
||||||
|
free(column_directory_name);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to open the column directory
|
||||||
|
directory = private_opendirat(dms_file_descriptor, column_directory_name);
|
||||||
|
if (directory == NULL) {
|
||||||
|
switch (errno)
|
||||||
|
{
|
||||||
|
case ENOENT:
|
||||||
|
obi_set_errno(OBICOLDIR_NOT_EXIST_ERROR);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case EACCES:
|
||||||
|
obi_set_errno(OBICOLDIR_ACCESS_ERROR);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ENOMEM:
|
||||||
|
obi_set_errno(OBICOLDIR_MEMORY_ERROR);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
obi_set_errno(OBICOLDIR_UNKNOWN_ERROR);
|
||||||
|
}
|
||||||
|
free(column_directory_name);
|
||||||
|
close(dms_file_descriptor);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allocate the column dir structure
|
||||||
|
column_group = (OBIDMS_column_group_p) malloc(sizeof(OBIDMS_column_group_t));
|
||||||
|
if (column_group == NULL)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOLDIR_MEMORY_ERROR);
|
||||||
|
free(column_directory_name);
|
||||||
|
close(dms_file_descriptor);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize the data structure
|
||||||
|
strcpy(column_group->directory_name, column_directory_name);
|
||||||
|
strcpy(column_group->column_name, column_name);
|
||||||
|
column_group->directory = directory;
|
||||||
|
|
||||||
|
free(column_directory_name);
|
||||||
|
//close(dms_file_descriptor);
|
||||||
|
|
||||||
|
return column_group;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
OBIDMS_column_group_p obi_column_group(OBIDMS_p dms, const char* column_name)
|
||||||
|
{
|
||||||
|
int exists;
|
||||||
|
exists = obi_column_group_exists(dms, column_name);
|
||||||
|
|
||||||
|
switch (exists)
|
||||||
|
{
|
||||||
|
case 0:
|
||||||
|
return obi_create_column_group(dms, column_name);
|
||||||
|
case 1:
|
||||||
|
return obi_open_column_group(dms, column_name);
|
||||||
|
};
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int obi_close_column_group(OBIDMS_column_group_p column_group)
|
||||||
|
{
|
||||||
|
if (column_group != NULL)
|
||||||
|
{
|
||||||
|
// Close the column directory
|
||||||
|
if (closedir(column_group->directory) < 0)
|
||||||
|
{
|
||||||
|
obi_set_errno(OBICOLDIR_MEMORY_ERROR);
|
||||||
|
free(column_group);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
free(column_group);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
158
src/obidmscolumngroup.h
Normal file
158
src/obidmscolumngroup.h
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* OBIDMS column directories header file *
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @file obidmscolumngroup.h
|
||||||
|
* @author Celine Mercier
|
||||||
|
* @date 18 June 2015
|
||||||
|
* @brief Header file for OBIDMS column groups.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef OBIDMSCOLUMNGROUP_H_
|
||||||
|
#define OBIDMSCOLUMNGROUP_H_
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <dirent.h>
|
||||||
|
|
||||||
|
#include "obidms.h"
|
||||||
|
|
||||||
|
#define OBIDMS_MAX_COLNAME (128) /**< The maximum length of an OBIDMS column name
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define OBIDMS_COLUMN_DIR_MAX_NAME (2048) /**< The maximum length of an OBIDMS column directory name
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @brief A structure describing an OBIDMS column group instance
|
||||||
|
*
|
||||||
|
* A pointer to this structure is returned on creation
|
||||||
|
* and opening of an OBIDMS column group.
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct OBIDMS_column_group {
|
||||||
|
OBIDMS_p dms; /**< A pointer to a DMS instance.
|
||||||
|
*/
|
||||||
|
char column_name[OBIDMS_MAX_COLNAME+1]; /**< The name of the column group
|
||||||
|
* contained in the directory.
|
||||||
|
*/
|
||||||
|
char directory_name[OBIDMS_COLUMN_DIR_MAX_NAME+1]; /**< The name of the directory
|
||||||
|
* containing the column group.
|
||||||
|
*/
|
||||||
|
DIR* directory; /**< A directory entry usable to
|
||||||
|
* refer and scan the database directory.
|
||||||
|
*/
|
||||||
|
} OBIDMS_column_group_t, *OBIDMS_column_group_p;
|
||||||
|
|
||||||
|
|
||||||
|
/*@
|
||||||
|
* @brief Checks if an OBIDMS column group exists
|
||||||
|
*
|
||||||
|
* @param dms a pointer to an OBIDMS as returned by obi_create_dms() or obi_open_dms()
|
||||||
|
* @param column_name a pointer to a C string containing the name of the column.
|
||||||
|
* The actual directory name used to store the column is
|
||||||
|
* `<column_name>.obicol`.
|
||||||
|
*
|
||||||
|
* @return an integer value indicating the status of the column group
|
||||||
|
* @retvalue 1 the group exist
|
||||||
|
* @retvalue 0 the group does not exist
|
||||||
|
* @retvalue -1 an error occurred
|
||||||
|
*
|
||||||
|
* @see obi_close_column_group()
|
||||||
|
* @since June 2015
|
||||||
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
|
*/
|
||||||
|
int obi_column_group_exists(OBIDMS_p dms, const char* column_name);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Creates a new OBIDMS column group instance.
|
||||||
|
*
|
||||||
|
* A new OBIDMS column group is created. This function checks
|
||||||
|
* if a directory with this name does not already exist
|
||||||
|
* before creating the new column group.
|
||||||
|
*
|
||||||
|
* @param dms a pointer to an OBIDMS as returned by obi_create_dms() or obi_open_dms()
|
||||||
|
* @param column_name a pointer to a C string containing the name of the column.
|
||||||
|
* The actual directory name used to store the column will be
|
||||||
|
* `<column_name>.obicol`.
|
||||||
|
*
|
||||||
|
* @return a pointer to an OBIDMS column group structure describing the newly created
|
||||||
|
* group
|
||||||
|
* @retval NULL on error and the `obi_errno` variable is set.
|
||||||
|
*
|
||||||
|
* ###Error values
|
||||||
|
* - OBIDMS_COL_DIR_EXIST_ERROR : xxxxx a database with the same name already exists.
|
||||||
|
*
|
||||||
|
* @see obi_close_column_group()
|
||||||
|
* @since June 2015
|
||||||
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
|
*/
|
||||||
|
OBIDMS_column_group_p obi_create_column_group(OBIDMS_p dms, const char* column_name);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Opens an existing OBIDMS column group instance.
|
||||||
|
*
|
||||||
|
* @param dms a pointer to an OBIDMS as returned by obi_create_dms() or obi_open_dms()
|
||||||
|
* @param column_name a pointer to a C string containing the name of the column.
|
||||||
|
* The actual directory name used to store the column is
|
||||||
|
* `<column_name>.obicol`.
|
||||||
|
*
|
||||||
|
* @return a pointer to the OBIDMS column group structure describing the group
|
||||||
|
* @retval NULL on error and the `obi_errno`variable is set.
|
||||||
|
*
|
||||||
|
* ###Error values
|
||||||
|
* - OBIDMS_COL_DIR_ERROR : xxxxx a database with the same name already exists.
|
||||||
|
*
|
||||||
|
* @see obi_close_column_group()
|
||||||
|
* @since June 2015
|
||||||
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
|
*/
|
||||||
|
OBIDMS_column_group_p obi_open_column_group(OBIDMS_p dms, const char* column_name);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Opens or creates a new OBIDMS column group instance.
|
||||||
|
*
|
||||||
|
* If the group already exists, this function opens it, otherwise it
|
||||||
|
* creates a new column group.
|
||||||
|
*
|
||||||
|
* @param dms a pointer to an OBIDMS as returned by obi_create_dms() or obi_open_dms()
|
||||||
|
* @param column_name a pointer to a C string containing the name of the column.
|
||||||
|
* The actual directory name used to store the column is
|
||||||
|
* `<column_name>.obicol`.
|
||||||
|
*
|
||||||
|
* @return a pointer to the OBIDMS column group structure describing the group
|
||||||
|
* @retval NULL on error and the `obi_errno`variable is set.
|
||||||
|
*
|
||||||
|
* ###Error values
|
||||||
|
* - OBIDMS_LONG_NAME_ERROR : the database name exceeds the limit.
|
||||||
|
* - OBIDMS_MEMORY_ERROR : something wrong occurred during memory allocation.
|
||||||
|
*
|
||||||
|
* @since June 2015
|
||||||
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
|
*/
|
||||||
|
OBIDMS_column_group_p obi_column_group(OBIDMS_p dms, const char* column_name);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Closes an opened OBIDMS column group instance.
|
||||||
|
*
|
||||||
|
* @param column_group a pointer to an OBIDMS column group as returned by
|
||||||
|
* obi_create_column_group() or obi_open_column_group()
|
||||||
|
*
|
||||||
|
* @return an integer value indicating the success of the operation. Even on
|
||||||
|
* error, the `OBIDMS_column_group` structure is freed
|
||||||
|
* @retvalue 0 on success
|
||||||
|
* @retvalue -1 on failure and the `obi_errno` variable is set.
|
||||||
|
*
|
||||||
|
* @see obi_create_column_group()
|
||||||
|
* @see obi_open_column_group()
|
||||||
|
* @since June 2015
|
||||||
|
* @author Celine Mercier (celine.mercier@metabarcoding.org)
|
||||||
|
*/
|
||||||
|
int obi_close_column_group(OBIDMS_column_group_p column_group);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* OBIDMSCOLUMNDIR_H_ */
|
@ -8,7 +8,8 @@
|
|||||||
#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;
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@ -34,15 +35,16 @@ size_t obi_sizeof(OBIType_t type) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
size_t obi_array_sizeof(OBIType_t type, size_t nbelements) {
|
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) * nbelements;
|
size = obi_sizeof(type) * nbelements;
|
||||||
|
|
||||||
psize= getpagesize();
|
psize = getpagesize();
|
||||||
rsize= size % psize;
|
rsize = size % psize;
|
||||||
|
|
||||||
// Round at a size multiple of pagesize
|
// Round at a size multiple of pagesize
|
||||||
if (rsize)
|
if (rsize)
|
||||||
|
Reference in New Issue
Block a user