vvfat: Fix vvfat_write() for writes before the root directory
commitb9b8860d24676ec59c878d5206ea6bcfc87af798
authorKevin Wolf <kwolf@redhat.com>
Thu, 9 Dec 2021 15:22:31 +0000 (9 16:22 +0100)
committerKevin Wolf <kwolf@redhat.com>
Fri, 14 Jan 2022 11:03:16 +0000 (14 12:03 +0100)
treed3b1718b95421bbb1eb333d26c00bb9ab66c54f1
parent2db9b9e96f0b57ceaa49666d9b8a573290114fdf
vvfat: Fix vvfat_write() for writes before the root directory

The calculation in sector2cluster() is done relative to the offset of
the root directory. Any writes to blocks before the start of the root
directory (in particular, writes to the FAT) result in negative values,
which are not handled correctly in vvfat_write().

This changes sector2cluster() to return a signed value, and makes sure
that vvfat_write() doesn't try to find mappings for negative cluster
number. It clarifies the code in vvfat_write() to make it more obvious
that the cluster numbers can be negative.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Message-Id: <20211209152231.23756-1-kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block/vvfat.c