[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 10/13] vvfat: Fix wrong checks for cluster mappings invariant
From: |
Kevin Wolf |
Subject: |
[PULL 10/13] vvfat: Fix wrong checks for cluster mappings invariant |
Date: |
Mon, 5 Aug 2024 23:08:48 +0200 |
From: Amjad Alsharafi <amjadsharafi10@gmail.com>
How this `abort` was intended to check for was:
- if the `mapping->first_mapping_index` is not the same as
`first_mapping_index`, which **should** happen only in one case,
when we are handling the first mapping, in that case
`mapping->first_mapping_index == -1`, in all other cases, the other
mappings after the first should have the condition `true`.
- From above, we know that this is the first mapping, so if the offset
is not `0`, then abort, since this is an invalid state.
The issue was that `first_mapping_index` is not set if we are
checking from the middle, the variable `first_mapping_index` is
only set if we passed through the check `cluster_was_modified` with the
first mapping, and in the same function call we checked the other
mappings.
One approach is to go into the loop even if `cluster_was_modified`
is not true so that we will be able to set `first_mapping_index` for the
first mapping, but since `first_mapping_index` is only used here,
another approach is to just check manually for the
`mapping->first_mapping_index != -1` since we know that this is the
value for the only entry where `offset == 0` (i.e. first mapping).
Signed-off-by: Amjad Alsharafi <amjadsharafi10@gmail.com>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Message-ID:
<b0fbca3ee208c565885838f6a7deeaeb23f4f9c2.1721470238.git.amjadsharafi10@gmail.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/vvfat.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/block/vvfat.c b/block/vvfat.c
index cfde468c2e..e3a83fbc88 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -1880,7 +1880,6 @@ get_cluster_count_for_direntry(BDRVVVFATState* s,
direntry_t* direntry, const ch
uint32_t cluster_num = begin_of_direntry(direntry);
uint32_t offset = 0;
- int first_mapping_index = -1;
mapping_t* mapping = NULL;
const char* basename2 = NULL;
@@ -1942,14 +1941,9 @@ get_cluster_count_for_direntry(BDRVVVFATState* s,
direntry_t* direntry, const ch
if (strcmp(basename, basename2))
copy_it = 1;
- first_mapping_index = array_index(&(s->mapping),
mapping);
- }
-
- if (mapping->first_mapping_index != first_mapping_index
- && mapping->info.file.offset > 0) {
- abort();
- copy_it = 1;
}
+ assert(mapping->first_mapping_index == -1
+ || mapping->info.file.offset > 0);
/* need to write out? */
if (!was_modified && is_file(direntry)) {
--
2.45.2
- [PULL 00/13] Block layer patches, Kevin Wolf, 2024/08/05
- [PULL 01/13] qapi-block-core: Clean up blockdev-snapshot-internal-sync doc, Kevin Wolf, 2024/08/05
- [PULL 02/13] block-copy: Fix missing graph lock, Kevin Wolf, 2024/08/05
- [PULL 05/13] scsi-block: Don't skip callback for sgio error status/driver_status, Kevin Wolf, 2024/08/05
- [PULL 06/13] scsi-disk: Add warning comments that host_status errors take a shortcut, Kevin Wolf, 2024/08/05
- [PULL 03/13] block/graph-lock: Make WITH_GRAPH_RDLOCK_GUARD() fully checked, Kevin Wolf, 2024/08/05
- [PULL 04/13] scsi-disk: Use positive return value for status in dma_readv/writev, Kevin Wolf, 2024/08/05
- [PULL 08/13] vvfat: Fix bug in writing to middle of file, Kevin Wolf, 2024/08/05
- [PULL 07/13] scsi-disk: Always report RESERVATION_CONFLICT to guest, Kevin Wolf, 2024/08/05
- [PULL 10/13] vvfat: Fix wrong checks for cluster mappings invariant,
Kevin Wolf <=
- [PULL 09/13] vvfat: Fix usage of `info.file.offset`, Kevin Wolf, 2024/08/05
- [PULL 13/13] iotests/024: exclude 'backing file format' field from the output, Kevin Wolf, 2024/08/05
- [PULL 11/13] vvfat: Fix reading files with non-continuous clusters, Kevin Wolf, 2024/08/05
- [PULL 12/13] iotests: Add `vvfat` tests, Kevin Wolf, 2024/08/05
- Re: [PULL 00/13] Block layer patches, Richard Henderson, 2024/08/06