diff --git a/cmdline/elem.c b/cmdline/elem.c index 660294a9..9ec6305e 100644 --- a/cmdline/elem.c +++ b/cmdline/elem.c @@ -1171,7 +1171,7 @@ static struct snapraid_chunk* fs_file2chunk_get_unlock(struct snapraid_disk* dis return chunk; } -struct snapraid_file* fs_par2file_get(struct snapraid_disk* disk, block_off_t parity_pos, block_off_t* file_pos) +struct snapraid_file* fs_par2file_maybe(struct snapraid_disk* disk, block_off_t parity_pos, block_off_t* file_pos) { struct snapraid_chunk* chunk; struct snapraid_file* file; @@ -1358,8 +1358,8 @@ struct snapraid_block* fs_par2block_get(struct snapraid_disk* disk, block_off_t struct snapraid_file* file; block_off_t file_pos; - file = fs_par2file_get(disk, parity_pos, &file_pos); - if (!file) + file = fs_par2file_maybe(disk, parity_pos, &file_pos); + if (file == 0) return BLOCK_EMPTY; return fs_file2block_get(file, file_pos); diff --git a/cmdline/elem.h b/cmdline/elem.h index cbf13585..11bee14a 100644 --- a/cmdline/elem.h +++ b/cmdline/elem.h @@ -934,7 +934,25 @@ struct snapraid_block* fs_file2block_get(struct snapraid_file* file, block_off_t * Get the file position from the parity position. * Return 0 if no file is using it. */ -struct snapraid_file* fs_par2file_get(struct snapraid_disk* disk, block_off_t parity_pos, block_off_t* file_pos); +struct snapraid_file* fs_par2file_maybe(struct snapraid_disk* disk, block_off_t parity_pos, block_off_t* file_pos); + +/** + * Get the file position from the parity position. + */ +static inline struct snapraid_file* fs_par2file_get(struct snapraid_disk* disk, block_off_t parity_pos, block_off_t* file_pos) +{ + struct snapraid_file* ret; + + ret = fs_par2file_maybe(disk, parity_pos, file_pos); + if (ret == 0) { + /* LCOV_EXCL_START */ + log_fatal("Internal inconsistency when deresolving parity position '%u' in disk '%s'\n", parity_pos, disk->name); + os_abort(); + /* LCOV_EXCL_STOP */ + } + + return ret; +} /** * Get the parity position from the file position.