Commit 8bb5ae6c authored by Loic Hausammann's avatar Loic Hausammann
Browse files

Logger: change names (io_ -> logger_io_)

parent db0d9862
......@@ -92,7 +92,7 @@ void header_change_offset_direction(struct header *h, enum logger_offset_directi
/* Skip file format and version numbers */
size_t offset = LOGGER_VERSION_SIZE + 2 * sizeof(int);
io_write_data(h->log->log.map, LOGGER_NUMBER_SIZE, &new_value, offset);
logger_io_write_data(h->log->log.map, LOGGER_NUMBER_SIZE, &new_value, offset);
}
/**
......@@ -110,31 +110,31 @@ void header_read(struct header *h, struct logger_logfile *log) {
/* read file format */
char file_format[STRING_SIZE];
offset = io_read_data(map, LOGGER_VERSION_SIZE, &file_format, offset);
offset = logger_io_read_data(map, LOGGER_VERSION_SIZE, &file_format, offset);
if (strcmp(file_format, "SWIFT_LOGGER"))
error("Wrong file format (%s)", file_format);
/* Read major version number */
offset = io_read_data(map, sizeof(int), &h->major_version, offset);
offset = logger_io_read_data(map, sizeof(int), &h->major_version, offset);
/* Read minor version number */
offset = io_read_data(map, sizeof(int), &h->minor_version, offset);
offset = logger_io_read_data(map, sizeof(int), &h->minor_version, offset);
if (h->log->reader->verbose > 0)
message("File version %i.%i", h->major_version, h->minor_version);
/* read the offset directions */
offset = io_read_data(map, LOGGER_NUMBER_SIZE, &h->offset_direction, offset);
offset = logger_io_read_data(map, LOGGER_NUMBER_SIZE, &h->offset_direction, offset);
if (!header_is_forward(h) && !header_is_backward(h) &&
!header_is_corrupted(h))
error("Wrong offset value in the header (%i)", h->offset_direction);
/* read offset to first record */
offset = io_read_data(map, LOGGER_OFFSET_SIZE, &h->offset_first_record, offset);
offset = logger_io_read_data(map, LOGGER_OFFSET_SIZE, &h->offset_first_record, offset);
/* read the size of the strings */
offset = io_read_data(map, LOGGER_NUMBER_SIZE, &h->string_length, offset);
offset = logger_io_read_data(map, LOGGER_NUMBER_SIZE, &h->string_length, offset);
/* check if value defined in this file is large enough. */
if (STRING_SIZE < h->string_length) {
......@@ -142,7 +142,7 @@ void header_read(struct header *h, struct logger_logfile *log) {
}
/* read the number of masks. */
offset = io_read_data(map, LOGGER_NUMBER_SIZE, &h->number_mask, offset);
offset = logger_io_read_data(map, LOGGER_NUMBER_SIZE, &h->number_mask, offset);
/* allocate the masks memory. */
h->masks = malloc(sizeof(struct mask_data) * h->number_mask);
......@@ -150,13 +150,13 @@ void header_read(struct header *h, struct logger_logfile *log) {
/* loop over all masks. */
for (size_t i = 0; i < h->number_mask; i++) {
/* read the mask name. */
offset = io_read_data(map, h->string_length, h->masks[i].name, offset);
offset = logger_io_read_data(map, h->string_length, h->masks[i].name, offset);
/* set the mask value. */
h->masks[i].mask = 1 << i;
/* read the mask data size. */
offset = io_read_data(map, LOGGER_NUMBER_SIZE, &h->masks[i].size, offset);
offset = logger_io_read_data(map, LOGGER_NUMBER_SIZE, &h->masks[i].size, offset);
}
/* Check the logfile header's size */
......
......@@ -40,17 +40,17 @@ void logger_index_init(struct logger_index *index, struct logger_reader *reader,
char *filename) {
/* Open file. */
index->data = io_mmap_file(filename, &index->file_size);
index->data = logger_io_mmap_file(filename, &index->file_size);
/* Read the double time. */
size_t offset = 0;
offset = io_read_data(index->data, sizeof(double), &index->time, offset);
offset = logger_io_read_data(index->data, sizeof(double), &index->time, offset);
/* Read the integer time. */
offset = io_read_data(index->data, sizeof(integertime_t), &index->int_time, offset);
offset = logger_io_read_data(index->data, sizeof(integertime_t), &index->int_time, offset);
/* Read the number of particles. */
offset = io_read_data(index->data, swift_type_count * sizeof(long long),
offset = logger_io_read_data(index->data, swift_type_count * sizeof(long long),
&index->number_particles, offset);
/* Count total number of particles. */
......@@ -70,7 +70,7 @@ void logger_index_init(struct logger_index *index, struct logger_reader *reader,
void logger_index_free(struct logger_index *index) {
/* unmap file */
io_munmap_file(index->data, index->file_size);
logger_io_munmap_file(index->data, index->file_size);
/* Set variables to default value. */
index->total_number_particles = 0;
......
......@@ -31,10 +31,10 @@ struct logger_reader;
struct logger_index_data {
/* The particle's id */
long long id;
uint64_t id;
/* The particle's offset */
size_t offset;
uint64_t offset;
};
/**
......
......@@ -32,7 +32,7 @@
*
* @return file size.
*/
size_t io_get_file_size(int fd) {
size_t logger_io_get_file_size(int fd) {
struct stat s;
int status = fstat(fd, &s);
if (status != 0) error("Unable to get file size (%s)", strerror(errno));
......@@ -42,20 +42,20 @@ size_t io_get_file_size(int fd) {
/**
* @brief Map a file.
*
* #io_munmap_file should be called to unmap the file.
* #logger_io_munmap_file should be called to unmap the file.
*
* @param filename file to read.
* @param file_size (out) size of the file.
*
*/
void *io_mmap_file(char *filename, size_t *file_size) {
void *logger_io_mmap_file(char *filename, size_t *file_size) {
/* open the file. */
int fd = open(filename, O_RDWR);
if (fd == -1)
error("Unable to open file %s (%s)", filename, strerror(errno));
/* get the file size. */
*file_size = io_get_file_size(fd);
*file_size = logger_io_get_file_size(fd);
/* map the memory. */
void *map = mmap(NULL, *file_size, PROT_WRITE | PROT_READ, MAP_SHARED, fd, 0);
......@@ -76,7 +76,7 @@ void *io_mmap_file(char *filename, size_t *file_size) {
* @param file_size The file size.
*
*/
void io_munmap_file(void *map, size_t file_size) {
void logger_io_munmap_file(void *map, size_t file_size) {
/* unmap */
if (munmap(map, file_size) != 0) {
error("Unable to unmap the file (%s)", strerror(errno));
......
......@@ -29,9 +29,9 @@
#include <stdio.h>
#include <stdlib.h>
size_t io_get_file_size(int fd);
void *io_mmap_file(char *filename, size_t *file_size);
void io_munmap_file(void *map, size_t file_size);
size_t logger_io_get_file_size(int fd);
void *logger_io_mmap_file(char *filename, size_t *file_size);
void logger_io_munmap_file(void *map, size_t file_size);
/**
* @brief read a mask with its offset.
......@@ -45,7 +45,7 @@ void io_munmap_file(void *map, size_t file_size);
*
* @return offset after the record header.
*/
__attribute__((always_inline)) INLINE static size_t io_read_mask(
__attribute__((always_inline)) INLINE static size_t logger_io_read_mask(
const struct header *h, void *data, size_t offset, size_t *mask,
size_t *diff_offset) {
/* read mask */
......@@ -75,7 +75,7 @@ __attribute__((always_inline)) INLINE static size_t io_read_mask(
* @return offset after the data written.
*/
__attribute__((always_inline)) INLINE static size_t io_read_data(
__attribute__((always_inline)) INLINE static size_t logger_io_read_data(
void *data, const size_t size, void *p, size_t offset) {
memcpy(p, data + offset, size);
return offset + size;
......@@ -91,7 +91,7 @@ __attribute__((always_inline)) INLINE static size_t io_read_data(
*
* @return offset after the data written.
*/
__attribute__((always_inline)) INLINE static size_t io_write_data(
__attribute__((always_inline)) INLINE static size_t logger_io_write_data(
void *data, const size_t size, const void *p, size_t offset) {
memcpy(data + offset, p, size);
......
......@@ -42,7 +42,7 @@ void logger_logfile_init(
/* Open file, map it and get its size. */
if (reader->verbose > 1)
message("Mapping the log file.");
log->log.map = io_mmap_file(filename, &log->log.file_size);
log->log.map = logger_io_mmap_file(filename, &log->log.file_size);
/* Read the header. */
if (reader->verbose > 1)
......@@ -87,7 +87,7 @@ void logger_logfile_init(
* @param log The #logger_logfile.
*/
void logger_logfile_free(struct logger_logfile *log) {
io_munmap_file(log->log.map, log->log.file_size);
logger_io_munmap_file(log->log.map, log->log.file_size);
}
......
......@@ -99,7 +99,7 @@ size_t logger_particle_read_field(struct logger_particle *part, void *map,
}
/* read the data */
offset = io_read_data(map, size, p, offset);
offset = logger_io_read_data(map, size, p, offset);
/* Split the required fields */
if (strcmp("consts", field) == 0) {
......@@ -142,7 +142,7 @@ size_t logger_particle_read(struct logger_particle *part, const struct logger_re
logger_particle_init(part);
/* Read the record mask */
offset = io_read_mask(h, map, offset, &mask, &h_offset);
offset = logger_io_read_mask(h, map, offset, &mask, &h_offset);
/* Check if it is not a time record */
if (mask != 127) error("Unexpected mask: %lu", mask);
......
......@@ -44,7 +44,7 @@ size_t time_read(integertime_t *int_time, double *time, const struct logger_read
*time = 0;
/* read record header */
offset = io_read_mask(h, map, offset, &mask, &prev_offset);
offset = logger_io_read_mask(h, map, offset, &mask, &prev_offset);
#ifdef SWIFT_DEBUG_CHECKS
......@@ -57,8 +57,8 @@ size_t time_read(integertime_t *int_time, double *time, const struct logger_read
#endif
/* read the record */
offset = io_read_data(map, sizeof(unsigned long long int), int_time, offset);
offset = io_read_data(map, sizeof(double), time, offset);
offset = logger_io_read_data(map, sizeof(unsigned long long int), int_time, offset);
offset = logger_io_read_data(map, sizeof(double), time, offset);
return offset;
}
......@@ -82,7 +82,7 @@ size_t time_offset_first_record(const struct header *h) {
if (i == -1) error("Time mask not present in the log file header");
size_t mask = 0;
io_read_mask(h, map, offset, &mask, NULL);
logger_io_read_mask(h, map, offset, &mask, NULL);
if (mask != h->masks[i].mask) error("Log file should begin by timestep");
......
......@@ -59,7 +59,7 @@ int _tools_get_next_record_forward(const struct header *h, void *map,
size_t diff_offset = 0;
/* read offset */
*offset = io_read_mask(h, map, *offset, NULL, &diff_offset);
*offset = logger_io_read_mask(h, map, *offset, NULL, &diff_offset);
if (diff_offset == 0) return -1;
......@@ -90,7 +90,7 @@ int _tools_get_next_record_backward(const struct header *h, void *map,
while (current_offset < file_size) {
size_t mask = 0;
size_t prev_offset;
current_offset = io_read_mask(h, map, current_offset, &mask, &prev_offset);
current_offset = logger_io_read_mask(h, map, current_offset, &mask, &prev_offset);
prev_offset = current_offset - prev_offset - record_header;
if (*offset == prev_offset) {
......@@ -120,12 +120,12 @@ size_t tools_reverse_offset(const struct header *h, void *map, size_t offset) {
const size_t cur_offset = offset;
/* read mask + offset */
offset = io_read_mask(h, map, offset, &mask, &prev_offset);
offset = logger_io_read_mask(h, map, offset, &mask, &prev_offset);
/* write offset of zero (in case it is the last record) */
const size_t zero = 0;
offset -= LOGGER_OFFSET_SIZE;
offset = io_write_data(map, LOGGER_OFFSET_SIZE, &zero, offset);
offset = logger_io_write_data(map, LOGGER_OFFSET_SIZE, &zero, offset);
/* set offset after current record */
offset += header_get_record_size_from_mask(h, mask);
......@@ -140,12 +140,12 @@ size_t tools_reverse_offset(const struct header *h, void *map, size_t offset) {
/* modify previous offset */
size_t abs_prev_offset = cur_offset - prev_offset + LOGGER_MASK_SIZE;
abs_prev_offset = io_write_data(map, LOGGER_OFFSET_SIZE, &prev_offset, abs_prev_offset);
abs_prev_offset = logger_io_write_data(map, LOGGER_OFFSET_SIZE, &prev_offset, abs_prev_offset);
#ifdef SWIFT_DEBUG_CHECKS
size_t prev_mask = 0;
abs_prev_offset -= LOGGER_MASK_SIZE + LOGGER_OFFSET_SIZE;
abs_prev_offset = io_read_mask(h, map, abs_prev_offset, &prev_mask, NULL);
abs_prev_offset = logger_io_read_mask(h, map, abs_prev_offset, &prev_mask, NULL);
if (prev_mask != mask)
error("Unexpected mask: %lu (at %lu), got %lu (at %lu)", mask, offset,
......@@ -181,7 +181,7 @@ size_t tools_check_record_consistency(const struct logger_reader *reader, size_t
size_t pointed_offset;
/* read mask + offset */
offset = io_read_mask(h, map, offset, &mask, &pointed_offset);
offset = logger_io_read_mask(h, map, offset, &mask, &pointed_offset);
/* get absolute offset */
if (header_is_forward(h))
......@@ -204,7 +204,7 @@ size_t tools_check_record_consistency(const struct logger_reader *reader, size_t
/* read mask of the pointed record */
size_t pointed_mask = 0;
pointed_offset = io_read_mask(h, map, pointed_offset, &pointed_mask, NULL);
pointed_offset = logger_io_read_mask(h, map, pointed_offset, &pointed_mask, NULL);
/* check masks */
if (pointed_mask != mask)
......
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