Skip to content

Commit 22ed581

Browse files
committed
nilfs-resize: fix abnormal minimum size error output for sizes less than 4KiB
If we specify a device size less than 4096 bytes, an insufficient size error will occur, but due to an underflow in calculating the number of segments, the output of the required number of segments and required size will become abnormal: $ sudo nilfs-resize /dev/loop0 1024 Partition size = 8796093023232 bytes. Shrink the filesystem size from 8796093022720 bytes to 1024 bytes. Error: the filesystem does not have enough free space. At least 18446741984637458845 more segments (922337203713998848 bytes) are required. Aborted. Fix this issue by preventing underflow when calculating the number of segments. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
1 parent 4110360 commit 22ed581

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

sbin/nilfs-resize.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,14 +1246,22 @@ static int nilfs_shrink_online(struct nilfs *nilfs, const char *device,
12461246
if (unlikely(ret < 0))
12471247
return -1;
12481248

1249-
newsb2off = NILFS_SB2_OFFSET_BYTES(newsize);
1250-
newnsegs = (newsb2off >> layout.blocksize_bits) /
1251-
layout.blocks_per_segment;
1252-
12531249
myprintf("Partition size = %llu bytes.\n"
12541250
"Shrink the filesystem size from %llu bytes to %llu bytes.\n",
12551251
devsize, layout.devsize, newsize);
12561252

1253+
if (newsize >= 4096) {
1254+
newsb2off = NILFS_SB2_OFFSET_BYTES(newsize);
1255+
newnsegs = (newsb2off >> layout.blocksize_bits) /
1256+
layout.blocks_per_segment;
1257+
} else {
1258+
/*
1259+
* Set dummy parameters to make the size check below fail
1260+
* while avoiding underflow.
1261+
*/
1262+
newnsegs = 0;
1263+
}
1264+
12571265
ret = nilfs_resize_check_free_space(nilfs, newnsegs);
12581266
if (ret < 0)
12591267
goto out;

0 commit comments

Comments
 (0)