The header size is now directly read in the file when a column or an
array is opened.
This commit is contained in:
@ -191,11 +191,10 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
|
||||
obiversion_t new_version_number;
|
||||
char* version_file_name;
|
||||
int version_file_descriptor;
|
||||
bool little_endian;
|
||||
int lock_mode;
|
||||
|
||||
new_version_number = 0;
|
||||
loc_size = sizeof(bool) + sizeof(obiversion_t);
|
||||
loc_size = sizeof(obiversion_t);
|
||||
|
||||
// Select the correct lockf operation according to the blocking mode
|
||||
if (block)
|
||||
@ -252,24 +251,6 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Read the endianness of the file
|
||||
if (read(version_file_descriptor, &little_endian, sizeof(bool)) < sizeof(bool))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError reading the endianness of a version file");
|
||||
close(version_file_descriptor);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Check if endianness is correct
|
||||
if (little_endian != obi_is_little_endian())
|
||||
{
|
||||
obi_set_errno(OBICOL_BAD_ENDIAN_ERROR);
|
||||
obidebug(1, "\nEndianness of a version file is incorrect");
|
||||
close(version_file_descriptor);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Read the current version number
|
||||
if (read(version_file_descriptor, &new_version_number, sizeof(obiversion_t)) < sizeof(obiversion_t))
|
||||
{
|
||||
@ -282,14 +263,6 @@ static obiversion_t obi_get_new_version_number(OBIDMS_column_directory_p column_
|
||||
new_version_number++;
|
||||
|
||||
// Write the new version number
|
||||
if (lseek(version_file_descriptor, sizeof(bool), SEEK_SET) != sizeof(bool))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError writing a new version number in a version file");
|
||||
close(version_file_descriptor);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (write(version_file_descriptor, &new_version_number, sizeof(obiversion_t)) < sizeof(obiversion_t))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
@ -328,9 +301,8 @@ static obiversion_t create_version_file(OBIDMS_column_directory_p column_directo
|
||||
obiversion_t version_number;
|
||||
char* version_file_name;
|
||||
int version_file_descriptor;
|
||||
bool little_endian;
|
||||
|
||||
loc_size = sizeof(bool) + sizeof(obiversion_t);
|
||||
loc_size = sizeof(obiversion_t);
|
||||
version_number = 0;
|
||||
|
||||
version_file_name = build_version_file_name(column_directory->column_name);
|
||||
@ -376,17 +348,6 @@ static obiversion_t create_version_file(OBIDMS_column_directory_p column_directo
|
||||
return -1;
|
||||
}
|
||||
|
||||
little_endian = obi_is_little_endian();
|
||||
|
||||
// Write endianness
|
||||
if (write(version_file_descriptor, &little_endian, sizeof(bool)) < sizeof(bool))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError writing endianness of a version file");
|
||||
close(version_file_descriptor);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Write version number
|
||||
if (write(version_file_descriptor, &version_number, sizeof(obiversion_t)) < sizeof(obiversion_t))
|
||||
{
|
||||
@ -444,9 +405,8 @@ obiversion_t obi_get_latest_version_number(OBIDMS_column_directory_p column_dire
|
||||
obiversion_t latest_version_number;
|
||||
char * version_file_name;
|
||||
int version_file_descriptor;
|
||||
bool little_endian;
|
||||
|
||||
loc_size = sizeof(bool) + sizeof(obiversion_t);
|
||||
loc_size = sizeof(obiversion_t);
|
||||
latest_version_number = 0;
|
||||
|
||||
version_file_name = build_version_file_name(column_directory->column_name);
|
||||
@ -483,24 +443,6 @@ obiversion_t obi_get_latest_version_number(OBIDMS_column_directory_p column_dire
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Read the endianness
|
||||
if (read(version_file_descriptor, &little_endian, sizeof(bool)) < sizeof(bool))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError reading the endianness of a version file");
|
||||
close(version_file_descriptor);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Verify the endianness
|
||||
if (little_endian != obi_is_little_endian())
|
||||
{
|
||||
obi_set_errno(OBICOL_BAD_ENDIAN_ERROR);
|
||||
obidebug(1, "\nEndianness of a version file is incorrect");
|
||||
close(version_file_descriptor);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Read the latest version number
|
||||
if (read(version_file_descriptor, &latest_version_number, sizeof(obiversion_t)) < sizeof(obiversion_t))
|
||||
{
|
||||
@ -731,7 +673,6 @@ OBIDMS_column_p obi_create_column(OBIDMS_p dms,
|
||||
new_column->writable = true;
|
||||
|
||||
header = new_column->header;
|
||||
header->little_endian = obi_is_little_endian();
|
||||
header->header_size = header_size;
|
||||
header->data_size = data_size;
|
||||
header->line_count = nb_lines;
|
||||
@ -793,9 +734,6 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Calculate the header size
|
||||
header_size = obi_get_platform_header_size();
|
||||
|
||||
// Get the latest version number if it has the value -1 (not given by user)
|
||||
if (version_number == -1)
|
||||
{
|
||||
@ -836,6 +774,16 @@ OBIDMS_column_p obi_open_column(OBIDMS_p dms,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Read the header size
|
||||
if (read(column_file_descriptor, &header_size, sizeof(size_t)) < sizeof(size_t))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError reading the header size to open a column");
|
||||
close(column_file_descriptor);
|
||||
free(column);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Fill the column structure
|
||||
column->dms = dms;
|
||||
column->column_directory = column_directory;
|
||||
@ -1265,9 +1213,6 @@ OBIDMS_column_header_p obi_column_get_header_from_name(OBIDMS_p dms, const char*
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Calculate the header size
|
||||
header_size = obi_get_platform_header_size(); // TODO read in header itself
|
||||
|
||||
// Get the latest version number
|
||||
version_number = obi_get_latest_version_number(column_directory);
|
||||
if (version_number < 0)
|
||||
@ -1295,6 +1240,15 @@ OBIDMS_column_header_p obi_column_get_header_from_name(OBIDMS_p dms, const char*
|
||||
|
||||
free(column_file_name);
|
||||
|
||||
// Read the header size
|
||||
if (read(column_file_descriptor, &header_size, sizeof(size_t)) < sizeof(size_t))
|
||||
{
|
||||
obi_set_errno(OBICOL_UNKNOWN_ERROR);
|
||||
obidebug(1, "\nError reading the header size to read a header");
|
||||
close(column_file_descriptor);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Fill the header structure
|
||||
header = mmap(NULL,
|
||||
header_size,
|
||||
|
Reference in New Issue
Block a user