diff --git a/elem.h b/elem.h index c402b64b..8a241ce1 100644 --- a/elem.h +++ b/elem.h @@ -30,7 +30,7 @@ /** * Invalid position. */ -#define POS_INVALID -1 +#define POS_INVALID ((block_off_t)-1) /** * Basic block position type. @@ -40,8 +40,9 @@ typedef uint32_t block_off_t; /** * Basic data position type. + * It's signed as file size and offset are usually signed. */ -typedef uint64_t data_off_t; +typedef int64_t data_off_t; /** * Filter for paths. @@ -76,7 +77,7 @@ struct snapraid_file { data_off_t size; /**< Size of the file. */ struct snapraid_block* blockvec; /**< All the blocks of the file. */ block_off_t blockmax; /**< Number of blocks. */ - uint64_t mtime; /**< Modification time. */ + int64_t mtime; /**< Modification time. */ uint64_t inode; /**< Inode. */ int is_present; /**< If it's seen as present. */ int is_filtered; /**< If it's filtered out. */ diff --git a/handle.c b/handle.c index 851b559f..50f53a74 100644 --- a/handle.c +++ b/handle.c @@ -251,7 +251,7 @@ int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, un read_ret = read(handle->f, block_buffer, read_size); #endif - if (read_ret != read_size) { + if (read_ret != (ssize_t)read_size) { /* conversion is safe because block_size is always small */ fprintf(stderr, "Error reading file '%s'. %s.\n", handle->path, strerror(errno)); return -1; } @@ -284,7 +284,7 @@ int handle_write(struct snapraid_handle* handle, struct snapraid_block* block, u write_ret = write(handle->f, block_buffer, write_size); #endif - if (write_ret != write_size) { + if (write_ret != (ssize_t)write_size) { /* conversion is safe because block_size is always small */ fprintf(stderr, "Error writing file '%s'. %s.\n", handle->path, strerror(errno)); return -1; } @@ -295,28 +295,4 @@ int handle_write(struct snapraid_handle* handle, struct snapraid_block* block, u return 0; } -int handle_readahead(struct snapraid_handle* handle, struct snapraid_block* block, unsigned block_size) -{ -#if HAVE_POSIX_FADVISE - data_off_t offset; - unsigned read_size; - int ret; - /* do nothing if the file is different */ - if (handle->file != block->file) - return 0; - - offset = block_file_pos(block) * (data_off_t)block_size; - - read_size = block_file_size(block, block_size); - - /* advise access of the next block */ - ret = posix_fadvise(handle->f, offset, read_size, POSIX_FADV_WILLNEED); - if (ret != 0) { - fprintf(stderr, "Error advising file '%s'. %s.\n", handle->path, strerror(errno)); - return -1; - } -#endif - - return 0; -} diff --git a/handle.h b/handle.h index 2c48e77f..19833201 100644 --- a/handle.h +++ b/handle.h @@ -61,12 +61,5 @@ int handle_read(struct snapraid_handle* handle, struct snapraid_block* block, un */ int handle_write(struct snapraid_handle* handle, struct snapraid_block* block, unsigned char* block_buffer, unsigned block_size); -/** - * Readahead optimization where available. - * \note - * It doesn't seem to give any speed improvement over posix_fadvise(POSIX_FADV_SEQUENTIAL). - */ -int handle_readahead(struct snapraid_handle* handle, struct snapraid_block* block, unsigned block_size); - #endif diff --git a/parity.c b/parity.c index e4f85fd5..5bec0b66 100644 --- a/parity.c +++ b/parity.c @@ -193,7 +193,7 @@ int parity_write(const char* path, int f, block_off_t pos, unsigned char* block_ write_ret = write(f, block_buffer, block_size); #endif - if (write_ret != block_size) { + if (write_ret != (ssize_t)block_size) { /* conversion is safe because block_size is always small */ if (errno == ENOSPC) { fprintf(stderr, "Failed to grow parity file '%s' due lack of space.\n", path); } else { @@ -225,7 +225,7 @@ int parity_read(const char* path, int f, block_off_t pos, unsigned char* block_b read_ret = read(f, block_buffer, block_size); #endif - if (read_ret != block_size) { + if (read_ret != (ssize_t)block_size) { /* conversion is safe because block_size is always small */ fprintf(stderr, "Error reading file '%s'. %s.\n", path, strerror(errno)); return -1; } diff --git a/portable.h b/portable.h index 9dbd93f8..91be3991 100644 --- a/portable.h +++ b/portable.h @@ -129,8 +129,8 @@ */ struct windows_stat { uint64_t st_ino; - uint64_t st_size; - uint64_t st_mtime; + int64_t st_size; + int64_t st_mtime; uint32_t st_mode; };