File descriptors for dms, column and array directories are now stored in

structures.
This commit is contained in:
Celine Mercier
2015-11-09 15:06:02 +01:00
parent 05e3956a0c
commit b37bd8f21c
7 changed files with 134 additions and 307 deletions

View File

@ -190,7 +190,6 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
off_t loc_size;
obiversion_t new_version_number;
char* version_file_name;
int column_dir_file_descriptor;
int version_file_descriptor;
bool little_endian;
int lock_mode;
@ -209,18 +208,8 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
if (version_file_name == NULL)
return -1;
// 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);
obidebug(1, "\nError getting the file descriptor for a column file directory");
free(version_file_name);
return -1;
}
// Open the version file
version_file_descriptor = openat(column_dir_file_descriptor, version_file_name, O_RDWR);
version_file_descriptor = openat(column_directory->dir_fd, version_file_name, O_RDWR);
if (version_file_descriptor < 0)
{
if (errno == ENOENT)
@ -338,7 +327,6 @@ static obiversion_t create_version_file(OBIDMS_column_directory_p column_directo
off_t loc_size;
obiversion_t version_number;
char* version_file_name;
int column_dir_file_descriptor;
int version_file_descriptor;
bool little_endian;
@ -349,18 +337,8 @@ static obiversion_t create_version_file(OBIDMS_column_directory_p column_directo
if (version_file_name == NULL)
return -1;
// 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);
obidebug(1, "\nError getting the file descriptor for a column directory");
free(version_file_name);
return -1;
}
// Get the file descriptor associated to the version file
version_file_descriptor = openat(column_dir_file_descriptor, version_file_name, O_RDWR | O_CREAT, 0777);
version_file_descriptor = openat(column_directory->dir_fd, version_file_name, O_RDWR | O_CREAT, 0777);
if (version_file_descriptor < 0)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
@ -465,7 +443,6 @@ obiversion_t obi_get_latest_version_number(OBIDMS_column_directory_p column_dire
off_t loc_size;
obiversion_t latest_version_number;
char * version_file_name;
int column_dir_file_descriptor;
int version_file_descriptor;
bool little_endian;
@ -476,18 +453,8 @@ obiversion_t obi_get_latest_version_number(OBIDMS_column_directory_p column_dire
if (version_file_name==NULL)
return -1;
// 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);
obidebug(1, "\nError getting the file descriptor for a column directory");
free(version_file_name);
return -1;
}
// Get the file descriptor associated to the version file
version_file_descriptor = openat(column_dir_file_descriptor, version_file_name, O_RDONLY);
version_file_descriptor = openat(column_directory->dir_fd, version_file_name, O_RDONLY);
if (version_file_descriptor < 0)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
@ -596,7 +563,6 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
obiversion_t version_number;
char* column_file_name;
int column_file_descriptor;
int column_dir_file_descriptor;
size_t header_size;
size_t data_size;
index_t minimum_line_count;
@ -674,15 +640,6 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
return NULL;
}
// 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);
obidebug(1, "\nError getting the file descriptor for a column directory");
return NULL;
}
// Calculate the size needed
header_size = obi_get_platform_header_size();
data_size = obi_array_sizeof(data_type, nb_lines, nb_elements_per_line);
@ -703,7 +660,7 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
}
// Open the column file
column_file_descriptor = openat(column_dir_file_descriptor, column_file_name, O_RDWR | O_CREAT, 0777);
column_file_descriptor = openat(column_directory->dir_fd, column_file_name, O_RDWR | O_CREAT, 0777);
if (column_file_descriptor < 0)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
@ -823,7 +780,6 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
OBIDMS_array_p array;
char* column_file_name;
int column_file_descriptor;
int column_dir_file_descriptor;
size_t header_size;
size_t data_size;
@ -837,15 +793,6 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
return NULL;
}
// 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);
obidebug(1, "\nError getting the file descriptor for a column directory");
return NULL;
}
// Calculate the header size
header_size = obi_get_platform_header_size();
@ -868,7 +815,7 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
}
// Open the column file, ALWAYS READ-ONLY
column_file_descriptor = openat(column_dir_file_descriptor, column_file_name, O_RDONLY);
column_file_descriptor = openat(column_directory->dir_fd, column_file_name, O_RDONLY);
if (column_file_descriptor < 0)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
@ -909,8 +856,6 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
return NULL;
}
// TODO Check endianness?
// Compute data size from the informations in the header
data_size = obi_array_sizeof((column->header)->data_type, (column->header)->line_count, (column->header)->nb_elements_per_line);
@ -1045,7 +990,7 @@ int obi_close_column(OBIDMS_column_p column)
return -1;
}
obi_close_column_directory(column->column_directory);
obi_close_column_directory(column->column_directory); // TODO or not
free(column);
@ -1055,13 +1000,12 @@ int obi_close_column(OBIDMS_column_p column)
int obi_truncate_column_to_lines_used(OBIDMS_column_p column) // TODO is it necessary to unmap/remap?
{
size_t file_size;
size_t data_size;
size_t file_size;
size_t data_size;
index_t new_line_count;
double multiple;
int column_dir_file_descriptor;
int column_file_descriptor;
char* column_file_name;
double multiple;
int column_file_descriptor;
char* column_file_name;
// Compute the new line count = the number of lines used rounded to the nearest greater multiple of page size greater than 0
multiple = ceil((double) (ONE_IF_ZERO((column->header)->lines_used) * (column->header)->nb_elements_per_line * obi_sizeof((column->header)->data_type)) / (double) getpagesize());
@ -1071,15 +1015,6 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column) // TODO is it nece
if ((column->header)->line_count == new_line_count)
return 0;
// Get the file descriptor associated to the column directory
column_dir_file_descriptor = dirfd((column->column_directory)->directory);
if (column_dir_file_descriptor < 0)
{
obi_set_errno(OBICOLDIR_UNKNOWN_ERROR);
obidebug(1, "\nError getting the file descriptor for a column directory");
return -1;
}
// Get the column file name
column_file_name = build_column_file_name((column->header)->name, (column->header)->version);
if (column_file_name == NULL)
@ -1088,7 +1023,7 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column) // TODO is it nece
}
// Open the column file
column_file_descriptor = openat(column_dir_file_descriptor, column_file_name, O_RDWR);
column_file_descriptor = openat((column->column_directory)->dir_fd, column_file_name, O_RDWR);
if (column_file_descriptor < 0)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
@ -1121,13 +1056,13 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column) // TODO is it nece
}
// Remap the data
column->data = mmap(NULL,
data_size,
PROT_READ | PROT_WRITE,
MAP_SHARED,
column_file_descriptor,
(column->header)->header_size
);
column->data = mmap(NULL,
data_size,
PROT_READ | PROT_WRITE,
MAP_SHARED,
column_file_descriptor,
(column->header)->header_size
);
if (column->data == MAP_FAILED)
{
@ -1148,25 +1083,15 @@ int obi_truncate_column_to_lines_used(OBIDMS_column_p column) // TODO is it nece
int obi_enlarge_column(OBIDMS_column_p column)
{
size_t file_size;
size_t old_data_size;
size_t new_data_size;
size_t header_size;
size_t file_size;
size_t old_data_size;
size_t new_data_size;
size_t header_size;
index_t old_line_count;
index_t new_line_count;
int column_dir_file_descriptor;
int column_file_descriptor;
char* column_file_name;
void* new_data;
// Get the file descriptor associated to the column directory
column_dir_file_descriptor = dirfd((column->column_directory)->directory);
if (column_dir_file_descriptor < 0)
{
obi_set_errno(OBICOLDIR_UNKNOWN_ERROR);
obidebug(1, "\nError getting the file descriptor for a column directory");
return -1;
}
int column_file_descriptor;
char* column_file_name;
void* new_data;
// Get the column file name
column_file_name = build_column_file_name((column->header)->name, (column->header)->version);
@ -1176,7 +1101,7 @@ int obi_enlarge_column(OBIDMS_column_p column)
}
// Open the column file
column_file_descriptor = openat(column_dir_file_descriptor, column_file_name, O_RDWR);
column_file_descriptor = openat((column->column_directory)->dir_fd, column_file_name, O_RDWR);
if (column_file_descriptor < 0)
{
obi_set_errno(OBICOL_UNKNOWN_ERROR);
@ -1336,7 +1261,6 @@ OBIDMS_column_header_p obi_column_get_header_from_name(OBIDMS_p dms, const char*
OBIDMS_column_directory_p column_directory;
char* column_file_name;
int column_file_descriptor;
int column_dir_file_descriptor;
size_t header_size;
obiversion_t version_number;
@ -1348,16 +1272,6 @@ OBIDMS_column_header_p obi_column_get_header_from_name(OBIDMS_p dms, const char*
return NULL;
}
// 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);
obidebug(1, "\nError getting the file descriptor of a column directory");
obi_close_column_directory(column_directory);
return NULL;
}
// Calculate the header size
header_size = obi_get_platform_header_size(); // TODO read in header itself
@ -1377,7 +1291,7 @@ OBIDMS_column_header_p obi_column_get_header_from_name(OBIDMS_p dms, const char*
}
// Open the column file (READ-ONLY)
column_file_descriptor = openat(column_dir_file_descriptor, column_file_name, O_RDONLY);
column_file_descriptor = openat(column_directory->dir_fd, column_file_name, O_RDONLY);
if (column_file_descriptor < 0)
{
obidebug(1, "\nError opening a column file");
@ -1405,8 +1319,6 @@ OBIDMS_column_header_p obi_column_get_header_from_name(OBIDMS_p dms, const char*
return NULL;
}
// TODO Check endianness?
close(column_file_descriptor);
return header;
@ -1428,8 +1340,8 @@ int obi_unmap_header(OBIDMS_column_header_p header)
// TODO to be rewritten in an optimized and safe way
index_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const char* element_name)
{
char* elements_names;
char* name;
char* elements_names;
char* name;
index_t element_index;
elements_names = strdup((column->header)->elements_names);
@ -1468,8 +1380,8 @@ index_t obi_column_get_element_index_from_name(OBIDMS_column_p column, const cha
char* obi_column_format_date(time_t date)
{
char* formatted_time;
struct tm* tmp;
char* formatted_time;
struct tm* tmp;
formatted_time = (char*) malloc(FORMATTED_TIME_LENGTH*sizeof(char));