]> www.infradead.org Git - users/jedix/linux-maple.git/commit
clean ufs_trunc_direct() up a bit...
authorAl Viro <viro@zeniv.linux.org.uk>
Mon, 13 Mar 2023 16:40:40 +0000 (12:40 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Fri, 18 Oct 2024 21:35:31 +0000 (17:35 -0400)
commit64f30e80d653c4d5aa0a7f1390789348af0cf8f2
tree22ba01747bdb2b7b15eebc2a42d53d2c9efb402e
parentdb57044217d609d1d60854e958e28f5d3684d5bc
clean ufs_trunc_direct() up a bit...

For short files (== no indirect blocks needed) UFS allows the last
block to be a partial one.  That creates some complications for
truncation down to "short file" lengths.  ufs_trunc_direct() is
called when we'd already made sure that new EOF is not in a hole;
nothing needs to be done if we are extending the file and in
case we are shrinking the file it needs to
* shrink or free the old final block.
* free all full direct blocks between the new and old EOF.
* possibly shrink the new final block.

The logics is needlessly complicated by trying to keep all cases
handled by the same sequence of operations.
if not shrinking
nothing to do
else if number of full blocks unchanged
free the tail of possibly partial last block
else
free the tail of (currently full) new last block
free all present (full) blocks in between
free the (possibly partial) old last block

is easier to follow than the result of trying to unify these
cases.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
fs/ufs/inode.c