Skip to contentSkip to conversation

Fix some problems with vvfat in R/W mode

PATCH Applied Hervé Poussineau 2 participants 4 messages Oct 10, 2022 – Oct 21, 2022 Block layer

lore
Share & tools
lore
#0 lore raw

v2 cover Fix some problems with vvfat in R/W mode

Hi,

When testing vvfat in read-write mode, I came across some blocking problems when using Windows guests.
This patchset is not here to fix all problems of vvfat, but only the main ones I encountered.

First patch allows setting/resetting the 'volume dirty' flag on boosector, and the second one allows creating file names with spaces.

Hervé

Changes since v1:
- updated patch 1 with remarks (modify in-memory copy, add comment about FAT32)

Hervé Poussineau (2):
vvfat: allow some writes to bootsector
vvfat: allow spaces in file names

 block/vvfat.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)
Signature · 1 line
2.36.2
#1 lore raw

PATCH v2 1/2 vvfat: allow some writes to bootsector

'reserved1' field in bootsector is used to mark volume dirty, or need to verify. Allow writes to bootsector which only changes the 'reserved1' field.

This fixes I/O errors on Windows guests.

Resolves: https://bugs.launchpad.net/qemu/+bug/1889421

---
 block/vvfat.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)
block/vvfat.c +25 -1
index d6dd919683d..ae53f0d7283 100644
@@ -2993,11 +2993,35 @@ DLOG(checkpoint());
 
     vvfat_close_current_file(s);
 
+    if (sector_num == s->offset_to_bootsector && nb_sectors == 1) {
+        /*
+         * Write on bootsector. Allow only changing the reserved1 field,
+         * used to mark volume dirtiness
+         */
+        unsigned char *bootsector = s->first_sectors
+                                    + s->offset_to_bootsector * 0x200;
+        /*
+         * LATER TODO: if FAT32, this is wrong (see init_directories(),
+         * which always creates a FAT16 bootsector)
+         */
+        const int reserved1_offset = offsetof(bootsector_t, u.fat16.reserved1);
+
+        for (i = 0; i < 0x200; i++) {
+            if (i != reserved1_offset && bootsector[i] != buf[i]) {
+                fprintf(stderr, "Tried to write to protected bootsector\n");
+                return -1;
+            }
+        }
+
+        /* Update bootsector with the only updatable byte, and return success */
+        bootsector[reserved1_offset] = buf[reserved1_offset];
+        return 0;
+    }
+
     /*
      * Some sanity checks:
      * - do not allow writing to the boot sector
      */
-
     if (sector_num < s->offset_to_fat)
         return -1;
 
Signature · 1 line
2.36.2
#2 lore raw

PATCH v2 2/2 vvfat: allow spaces in file names

In reply to Hervé Poussineau

In R/W mode, files with spaces were never created on host side.

Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1176

Fixes c79e243ed67683d6d06692bd7040f7394da178b0
---
 block/vvfat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/vvfat.c +1 -1
index ae53f0d7283..392eab5168b 100644
@@ -499,7 +499,7 @@ static bool valid_filename(const unsigned char *name)
               (c >= 'A' && c <= 'Z') ||
               (c >= 'a' && c <= 'z') ||
               c > 127 ||
-              strchr("$%'-_@~`!(){}^#&.+,;=[]", c) != NULL))
+              strchr(" $%'-_@~`!(){}^#&.+,;=[]", c) != NULL))
         {
             return false;
         }
Signature · 1 line
2.36.2
Applied
#3 lore raw
In reply to Hervé Poussineau

Am 10.10.2022 um 19:55 hat Hervé Poussineau geschrieben:

Quoted 7 lines

Hi,

When testing vvfat in read-write mode, I came across some blocking problems when using Windows guests.
This patchset is not here to fix all problems of vvfat, but only the main ones I encountered.

Quoted 8 lines

First patch allows setting/resetting the 'volume dirty' flag on boosector, and the second one allows creating file names with spaces.

Hervé

Changes since v1:
- updated patch 1 with remarks (modify in-memory copy, add comment about FAT32)

Thanks, applied to the block branch.

Kevin