Commit c454f961 by Celine Mercier

changed 'column groups' to be called 'column directories' for now.

parent 71cd59f7
......@@ -20,10 +20,11 @@
#include <sys/mman.h> /* mmap() is defined in this header */
#include "obidmscolumn.h"
#include "obidmscolumngroup.h"
#include "obidmscolumndir.h"
#include "obidms.h"
#include "obitypes.h"
#include "obierrno.h"
#include "obidebug.h"
#include "obilittlebigman.h"
#include "private_at_functions.h"
......@@ -93,7 +94,7 @@ static char *build_version_file_name(const char *column_name);
* @since May 2015
* @author Eric Coissac (eric.coissac@metabarcoding.org)
*/
static obiversion_t obi_get_new_version_number(OBIDMS_column_group_p column_group, bool block);
static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_directory, bool block);
/**
......@@ -111,7 +112,7 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_group_p column_grou
* @since May 2015
* @author Eric Coissac (eric.coissac@metabarcoding.org)
*/
static int create_version_file(OBIDMS_column_group_p column_group);
static int create_version_file(OBIDMS_column_directory_p column_directory);
/************************************************************************
......@@ -120,14 +121,17 @@ static int create_version_file(OBIDMS_column_group_p column_group);
*
************************************************************************/
#define DEBUG_LEVEL 0
static char *build_column_file_name(const char *column_name, obiversion_t version_number)
{
char *filename;
// 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(OBICOL_MEMORY_ERROR);
obidebug(1, "\nasprintf() function failed");
return NULL;
}
......@@ -150,7 +154,7 @@ static char *build_version_file_name(const char *column_name)
}
static obiversion_t obi_get_new_version_number(OBIDMS_column_group_p column_group, bool block)
static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_directory, bool block)
{
off_t loc_size;
obiversion_t new_version_number;
......@@ -170,12 +174,12 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_group_p column_grou
lock_mode=F_TLOCK;
// Build the version file name
version_file_name = build_version_file_name(column_group->column_name);
version_file_name = build_version_file_name(column_directory->column_name);
if (version_file_name == NULL)
return -1;
// Get the file descriptor associated to the column group directory
column_dir_file_descriptor = dirfd(column_group->directory);
// Get the file descriptor associated to the column directory
column_dir_file_descriptor = dirfd(column_directory->directory);
if (column_dir_file_descriptor < 0)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
......@@ -188,9 +192,8 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_group_p column_grou
if (version_file_descriptor < 0)
{
free(version_file_name);
//close(column_dir_file_descriptor);
if (errno == ENOENT)
return create_version_file(column_group);
return create_version_file(column_directory);
else
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
......@@ -300,14 +303,13 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_group_p column_grou
}
close(version_file_descriptor);
//close(column_dir_file_descriptor);
free(version_file_name);
return new_version_number;
}
static int create_version_file(OBIDMS_column_group_p column_group)
static int create_version_file(OBIDMS_column_directory_p column_directory)
{
off_t loc_size;
obiversion_t version_number;
......@@ -319,12 +321,12 @@ static int create_version_file(OBIDMS_column_group_p column_group)
loc_size = sizeof(bool) + sizeof(obiversion_t);
version_number = 0;
version_file_name = build_version_file_name(column_group->column_name);
version_file_name = build_version_file_name(column_directory->column_name);
if (version_file_name == NULL)
return -1;
// Get the file descriptor associated to the column group directory
column_dir_file_descriptor = dirfd(column_group->directory);
// Get the file descriptor associated to the column directory
column_dir_file_descriptor = dirfd(column_directory->directory);
if (column_dir_file_descriptor < 0)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
......@@ -415,7 +417,6 @@ static int create_version_file(OBIDMS_column_group_p column_group)
}
close(version_file_descriptor);
//close(column_dir_file_descriptor);
free(version_file_name);
return version_number;
......@@ -428,7 +429,7 @@ static int create_version_file(OBIDMS_column_group_p column_group)
*
**********************************************************************/
obiversion_t obi_get_latest_version_number(OBIDMS_column_group_p column_group)
obiversion_t obi_get_latest_version_number(OBIDMS_column_directory_p column_directory)
{
off_t loc_size;
obiversion_t latest_version_number;
......@@ -440,12 +441,12 @@ obiversion_t obi_get_latest_version_number(OBIDMS_column_group_p column_group)
loc_size = sizeof(bool) + sizeof(obiversion_t);
latest_version_number = 0;
version_file_name = build_version_file_name(column_group->column_name);
version_file_name = build_version_file_name(column_directory->column_name);
if (version_file_name==NULL)
return -1;
// Get the file descriptor associated to the column group directory
column_dir_file_descriptor = dirfd(column_group->directory);
// Get the file descriptor associated to the column directory
column_dir_file_descriptor = dirfd(column_directory->directory);
if (column_dir_file_descriptor < 0)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
......@@ -515,7 +516,6 @@ obiversion_t obi_get_latest_version_number(OBIDMS_column_group_p column_group)
free(version_file_name);
close(version_file_descriptor);
//close(column_dir_file_descriptor);
return latest_version_number;
}
......@@ -533,7 +533,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
size_t nb_elements)
{
OBIDMS_column_p new_column;
OBIDMS_column_group_p column_group;
OBIDMS_column_directory_p column_directory;
OBIDMS_column_header_p header;
size_t file_size;
obiversion_t version_number;
......@@ -545,17 +545,17 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
new_column = NULL;
// Get the column group structure associated to the column
column_group = obi_column_group(dms, column_name);
if (column_group == NULL)
// Get the column directory structure associated to the column
column_directory = obi_column_directory(dms, column_name);
if (column_directory == NULL)
return NULL;
// Get the file descriptor associated to the column group directory
column_dir_file_descriptor = dirfd(column_group->directory);
// Get the file descriptor associated to the column directory
column_dir_file_descriptor = dirfd(column_directory->directory);
if (column_dir_file_descriptor < 0)
{
obi_set_errno(OBICOLDIR_UNKNOWN_ERROR);
obi_close_column_group(column_group);
obi_close_column_directory(column_directory);
return NULL;
}
......@@ -565,10 +565,10 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
file_size = header_size + data_size;
// Get the latest version number
version_number = obi_get_new_version_number(column_group, true);
version_number = obi_get_new_version_number(column_directory, true);
if (version_number < 0)
{
obi_close_column_group(column_group);
obi_close_column_directory(column_directory);
close(column_dir_file_descriptor);
return NULL;
}
......@@ -577,7 +577,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
column_file_name = build_column_file_name(column_name, version_number);
if (column_file_name == NULL)
{
obi_close_column_group(column_group);
obi_close_column_directory(column_directory);
close(column_dir_file_descriptor);
return NULL;
}
......@@ -587,7 +587,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
if (column_file_descriptor < 0)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
obi_close_column_group(column_group);
obi_close_column_directory(column_directory);
close(column_dir_file_descriptor);
free(column_file_name);
return NULL;
......@@ -597,7 +597,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
if (ftruncate(column_file_descriptor, file_size) < 0)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
obi_close_column_group(column_group);
obi_close_column_directory(column_directory);
close(column_dir_file_descriptor);
close(column_file_descriptor);
free(column_file_name);
......@@ -609,7 +609,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
if (new_column == NULL)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
obi_close_column_group(column_group);
obi_close_column_directory(column_directory);
close(column_dir_file_descriptor);
close(column_file_descriptor);
free(column_file_name);
......@@ -618,7 +618,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
// Fill the column structure
new_column->dms = dms;
new_column->column_group = column_group;
new_column->column_directory = column_directory;
new_column->header = mmap(NULL,
header_size,
PROT_READ | PROT_WRITE,
......@@ -630,7 +630,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
if (new_column->header == MAP_FAILED)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
obi_close_column_group(column_group);
obi_close_column_directory(column_directory);
close(column_dir_file_descriptor);
close(column_file_descriptor);
free(column_file_name);
......@@ -650,7 +650,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
{
munmap(new_column->header, header_size);
obi_set_errno(OBICOL_UNKNOWN_ERROR);
obi_close_column_group(column_group);
obi_close_column_directory(column_directory);
close(column_dir_file_descriptor);
close(column_file_descriptor);
free(column_file_name);
......@@ -672,7 +672,6 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
strncpy(header->name, column_name, OBIDMS_MAX_COLNAME);
free(column_file_name);
//close(column_dir_file_descriptor);
close(column_file_descriptor);
return new_column;
......
......@@ -22,7 +22,7 @@
#include "obitypes.h"
#include "obierrno.h"
#include "obilittlebigman.h"
#include "obidmscolumngroup.h"
#include "obidmscolumndir.h"
typedef int32_t obiversion_t; /**< Used to store the column version number
......@@ -65,7 +65,7 @@ typedef struct OBIDMS_column_header {
typedef struct OBIDMS_column {
OBIDMS_p dms; /**< A pointer to a DMS instance
*/
OBIDMS_column_group_p column_group; /**< A pointer to an OBIDMS column group instance
OBIDMS_column_directory_p column_directory; /**< A pointer to an OBIDMS column directory instance
*/
OBIDMS_column_header_p header; /**< A pointer to the header of the column
*/
......@@ -127,7 +127,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
* @return the bigger version number used for this column
* @return -1 if the column does not exist
*/
obiversion_t obi_get_latest_version_number(OBIDMS_column_group_p column_group);
obiversion_t obi_get_latest_version_number(OBIDMS_column_directory_p column_directory);
#endif /* OBIDMSCOLUMN_H_ */
/****************************************************************************
* OBIDMS column groups functions *
* OBIDMS column directories functions *
****************************************************************************/
/**
* @file obidmscolumngroup.c
* @file obidmscolumndir.c
* @author Celine Mercier
* @date 18 June 2015
* @brief Functions for OBIDMS column groups.
* @brief Functions for OBIDMS column directories.
*/
......@@ -17,7 +17,7 @@
#include <fcntl.h>
#include <unistd.h>
#include "obidmscolumngroup.h"
#include "obidmscolumndir.h"
#include "obidms.h"
#include "private_at_functions.h"
#include "obierrno.h"
......@@ -31,9 +31,9 @@
/**
* Internal function building the group directory name from an OBIDMS column name.
* Internal function building the column directory name from an OBIDMS column name.
*
* The function builds the directory name corresponding to an OBIDMS column group.
* The function builds the directory name corresponding to an OBIDMS column directory.
* It checks also that the name is not too long.
*
* @warning The returned pointer has to be freed by the caller.
......@@ -89,7 +89,7 @@ static char* build_column_directory_name(const char* column_name)
*
**********************************************************************/
int obi_column_group_exists(OBIDMS_p dms, const char* column_name)
int obi_column_directory_exists(OBIDMS_p dms, const char* column_name)
{
struct stat buffer;
char* column_directory_name;
......@@ -127,7 +127,6 @@ int obi_column_group_exists(OBIDMS_p dms, const char* column_name)
free(column_directory_name);
free(full_path);
//close(dms_file_descriptor);
if(check_dir == 0)
return 1;
......@@ -136,7 +135,7 @@ int obi_column_group_exists(OBIDMS_p dms, const char* column_name)
}
OBIDMS_column_group_p obi_create_column_group(OBIDMS_p dms, const char* column_name)
OBIDMS_column_directory_p obi_create_column_directory(OBIDMS_p dms, const char* column_name)
{
char* column_directory_name;
int dms_file_descriptor;
......@@ -171,20 +170,19 @@ OBIDMS_column_group_p obi_create_column_group(OBIDMS_p dms, const char* column_n
}
free(column_directory_name);
//close(dms_file_descriptor);
return obi_open_column_group(dms, column_name);
return obi_open_column_directory(dms, column_name);
}
OBIDMS_column_group_p obi_open_column_group(OBIDMS_p dms, const char* column_name)
OBIDMS_column_directory_p obi_open_column_directory(OBIDMS_p dms, const char* column_name)
{
OBIDMS_column_group_p column_group;
OBIDMS_column_directory_p column_directory;
char* column_directory_name;
DIR* directory;
int dms_file_descriptor;
column_group = NULL;
column_directory = NULL;
// Build and check the directory name
column_directory_name = build_column_directory_name(column_name);
......@@ -226,8 +224,8 @@ OBIDMS_column_group_p obi_open_column_group(OBIDMS_p dms, const char* column_nam
}
// Allocate the column dir structure
column_group = (OBIDMS_column_group_p) malloc(sizeof(OBIDMS_column_group_t));
if (column_group == NULL)
column_directory = (OBIDMS_column_directory_p) malloc(sizeof(OBIDMS_column_directory_t));
if (column_directory == NULL)
{
obi_set_errno(OBICOLDIR_MEMORY_ERROR);
free(column_directory_name);
......@@ -236,46 +234,45 @@ OBIDMS_column_group_p obi_open_column_group(OBIDMS_p dms, const char* column_nam
}
// Initialize the data structure
strcpy(column_group->directory_name, column_directory_name);
strcpy(column_group->column_name, column_name);
column_group->directory = directory;
strcpy(column_directory->directory_name, column_directory_name);
strcpy(column_directory->column_name, column_name);
column_directory->directory = directory;
free(column_directory_name);
//close(dms_file_descriptor);
return column_group;
return column_directory;
}
OBIDMS_column_group_p obi_column_group(OBIDMS_p dms, const char* column_name)
OBIDMS_column_directory_p obi_column_directory(OBIDMS_p dms, const char* column_name)
{
int exists;
exists = obi_column_group_exists(dms, column_name);
exists = obi_column_directory_exists(dms, column_name);
switch (exists)
{
case 0:
return obi_create_column_group(dms, column_name);
return obi_create_column_directory(dms, column_name);
case 1:
return obi_open_column_group(dms, column_name);
return obi_open_column_directory(dms, column_name);
};
return NULL;
}
int obi_close_column_group(OBIDMS_column_group_p column_group)
int obi_close_column_directory(OBIDMS_column_directory_p column_directory)
{
if (column_group != NULL)
if (column_directory != NULL)
{
// Close the column directory
if (closedir(column_group->directory) < 0)
if (closedir(column_directory->directory) < 0)
{
obi_set_errno(OBICOLDIR_MEMORY_ERROR);
free(column_group);
free(column_directory);
return -1;
}
free(column_group);
free(column_directory);
}
return 0;
......
......@@ -3,10 +3,10 @@
****************************************************************************/
/**
* @file obidmscolumngroup.h
* @file obidmscolumndir.h
* @author Celine Mercier
* @date 18 June 2015
* @brief Header file for OBIDMS column groups.
* @brief Header file for OBIDMS column directories.
*/
#ifndef OBIDMSCOLUMNGROUP_H_
......@@ -24,106 +24,106 @@
#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
/** @brief A structure describing an OBIDMS column directory instance
*
* A pointer to this structure is returned on creation
* and opening of an OBIDMS column group.
* and opening of an OBIDMS column directory.
*/
typedef struct OBIDMS_column_group {
typedef struct OBIDMS_column_directory {
OBIDMS_p dms; /**< A pointer to a DMS instance.
*/
char column_name[OBIDMS_MAX_COLNAME+1]; /**< The name of the column group
char column_name[OBIDMS_MAX_COLNAME+1]; /**< The name of the column
* contained in the directory.
*/
char directory_name[OBIDMS_COLUMN_DIR_MAX_NAME+1]; /**< The name of the directory
* containing the column group.
* containing the column.
*/
DIR* directory; /**< A directory entry usable to
* refer and scan the database directory.
*/
} OBIDMS_column_group_t, *OBIDMS_column_group_p;
} OBIDMS_column_directory_t, *OBIDMS_column_directory_p;
/*@
* @brief Checks if an OBIDMS column group exists
* @brief Checks if an OBIDMS column directory 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
* @return an integer value indicating the status of the column directory
* @retvalue 1 the directory exist
* @retvalue 0 the directory does not exist
* @retvalue -1 an error occurred
*
* @see obi_close_column_group()
* @see obi_close_column_directory()
* @since June 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
int obi_column_group_exists(OBIDMS_p dms, const char* column_name);
int obi_column_directory_exists(OBIDMS_p dms, const char* column_name);
/**
* @brief Creates a new OBIDMS column group instance.
* @brief Creates a new OBIDMS column directory instance.
*
* A new OBIDMS column group is created. This function checks
* A new OBIDMS column directory is created. This function checks
* if a directory with this name does not already exist
* before creating the new column group.
* before creating the new column directory.
*
* @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
* @return a pointer to an OBIDMS column directory structure describing the newly created
* directory
* @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()
* @see obi_close_column_directory()
* @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);
OBIDMS_column_directory_p obi_create_column_directory(OBIDMS_p dms, const char* column_name);
/**
* @brief Opens an existing OBIDMS column group instance.
* @brief Opens an existing OBIDMS column directory 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
* @return a pointer to the OBIDMS column directory structure describing the directory
* @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()
* @see obi_close_column_directory()
* @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);
OBIDMS_column_directory_p obi_open_column_directory(OBIDMS_p dms, const char* column_name);
/**
* @brief Opens or creates a new OBIDMS column group instance.
* @brief Opens or creates a new OBIDMS column directory instance.
*
* If the group already exists, this function opens it, otherwise it
* creates a new column group.
* If the directory already exists, this function opens it, otherwise it
* creates a new column directory.
*
* @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
* @return a pointer to the OBIDMS column directory structure describing the directory
* @retval NULL on error and the `obi_errno`variable is set.
*
* ###Error values
......@@ -133,26 +133,26 @@ OBIDMS_column_group_p obi_open_column_group(OBIDMS_p dms, const char* column_nam
* @since June 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
OBIDMS_column_group_p obi_column_group(OBIDMS_p dms, const char* column_name);
OBIDMS_column_directory_p obi_column_directory(OBIDMS_p dms, const char* column_name);
/**
* @brief Closes an opened OBIDMS column group instance.
* @brief Closes an opened OBIDMS column directory instance.
*
* @param column_group a pointer to an OBIDMS column group as returned by
* obi_create_column_group() or obi_open_column_group()
* @param column_directory a pointer to an OBIDMS column directory as returned by
* obi_create_column_directory() or obi_open_column_directory()
*
* @return an integer value indicating the success of the operation. Even on
* error, the `OBIDMS_column_group` structure is freed
* error, the `OBIDMS_column_directory` 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()
* @see obi_create_column_directory()
* @see obi_open_column_directory()
* @since June 2015
* @author Celine Mercier (celine.mercier@metabarcoding.org)
*/
int obi_close_column_group(OBIDMS_column_group_p column_group);
int obi_close_column_directory(OBIDMS_column_directory_p column_directory);
#endif /* OBIDMSCOLUMNDIR_H_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment