From 2f154fa49d24dbf4665426257a33f8337829ea9d Mon Sep 17 00:00:00 2001 From: Sven Schnelle Date: Mon, 2 Nov 2020 14:48:20 +0100 Subject: [PATCH] cmsfs-fuse: fix pointer block level calculation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adding one to the pointer per block value results in a wrong calculation of pointer block levels. When writing a file that would result in about 454MB size, the code would calculate that it needs a two level pointer directory but correct would be a three level pointer directory. This causes an invalid filesystem state: besides missing all the records of one top level pointer directory entry, it would also record a higher record number in the FST than what is present in the pointer blocks. Note that this bug only hits when the file is about 454MB and the write is stopped (means the file is closed) - if file writing continues the problem doesn't happen because at some point in time cmsfs-fuse would switch to three levels of pointer blocks anyways as the file grows. Signed-off-by: Sven Schnelle Signed-off-by: Jan Höppner --- cmsfs-fuse/cmsfs-fuse.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmsfs-fuse/cmsfs-fuse.c b/cmsfs-fuse/cmsfs-fuse.c index d3f3175e..89e42ebe 100644 --- a/cmsfs-fuse/cmsfs-fuse.c +++ b/cmsfs-fuse/cmsfs-fuse.c @@ -2050,7 +2050,7 @@ static int update_dir_levels(int blocks) if (blocks < 2) return 0; - while (blocks / (PTRS_PER_BLOCK + 1)) { + while (blocks / PTRS_PER_BLOCK) { levels++; blocks /= PTRS_PER_BLOCK; } @@ -3103,7 +3103,7 @@ static void update_levels(struct file *f) return; } - while (blocks / (per_block + 1)) { + while (blocks / per_block) { levels++; blocks /= per_block; }