Fix some problems with vvfat in R/W mode
PATCH 1/2 vvfat: allow some writes to bootsector
In reply to Hervé Poussineau'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 | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
block/vvfat.c +17 -1
@@ -2993,11 +2993,27 @@ 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 +*/ +const unsigned char *initial = s->first_sectors + + s->offset_to_bootsector *0x200 ; +for (i =0 ; i <0x200 ; i++) { + if (i != offsetof(bootsector_t, u.fat16.reserved1) && + initial[i] != buf[i]) { +fprintf (stderr,"Tried to write to protected bootsector\n" ); +return -1 ; + } + } +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
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é
Hervé Poussineau (2):
vvfat: allow some writes to bootsector
vvfat: allow spaces in file names
block/vvfat.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
Signature · 1 line
2.36.2
PATCH 2/2 vvfat: allow spaces in file names
In R/W mode, files with spaces were never created on host side.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1176
--- block/vvfat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
block/vvfat.c +1 -1
@@ -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
Re: [PATCH 2/2] vvfat: allow spaces in file names
Quoted 14 lines · 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 c79e243ed67683d6d06692bd7040f7394da178b0Signed-off-by Hervé Poussineau <[email protected]>--- block/vvfat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)block/vvfat.c +0
-0
block/vvfat.c static bool valid_filename(const unsigned char *name) · line 505
Quoted 8 lines
block/vvfat.c +1
-1@@ -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; }
Re: [PATCH 2/2] vvfat: allow spaces in file names
In reply to Hervé PoussineauAm 03.09.2022 um 18:23 hat Hervé Poussineau geschrieben:
Quoted 5 lines
In R/W mode, files with spaces were never created on host side.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1176
Fixes c79e243ed67683d6d06692bd7040f7394da178b0Signed-off-by Hervé Poussineau <[email protected]>
Re: [PATCH 1/2] vvfat: allow some writes to bootsector
In reply to Hervé PoussineauAm 03.09.2022 um 18:23 hat Hervé Poussineau geschrieben:
Quoted 18 lines
'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
Signed-off-by Hervé Poussineau <[email protected]>--- block/vvfat.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)block/vvfat.c +0
-0@@ -2993,11 +2993,27 @@ DLOG(checkpoint());vvfat_close_current_file (s);
block/vvfat.c DLOG(checkpoint()); · line 3004
Quoted 10 lines
block/vvfat.c +9
-0+if (sector_num == s->offset_to_bootsector && nb_sectors ==1 ) { +/* +* Write on bootsector. Allow only changing the reserved1 field, +* used to mark volume dirtiness +*/ +const unsigned char *initial = s->first_sectors + + s->offset_to_bootsector *0x200 ; +for (i =0 ; i <0x200 ; i++) { + if (i != offsetof(bootsector_t, u.fat16.reserved1) &&
I think you need to check the FAT version (s->fat_type) before accessing u.fat16. For FAT32, the "reserved" field is at a different offset (but seems to have the same meaning).
block/vvfat.c DLOG(checkpoint()); · line 3011
Quoted 7 lines
block/vvfat.c +7
-0+ initial[i] != buf[i]) { +fprintf (stderr,"Tried to write to protected bootsector\n" ); +return -1 ; + } + } +return 0 ; + }
Should we update s->first_sectors with the new value so that the guest would actually read back what it wrote instead of having the change disappear magically?
block/vvfat.c DLOG(checkpoint()); · line 3018
Quoted 7 lines
block/vvfat.c +0
-1/* * Some sanity checks: * - do not allow writing to the boot sector */ -if (sector_num < s->offset_to_fat)return -1 ;
Kevin
Re: [PATCH 1/2] vvfat: allow some writes to bootsector
Le 29/09/2022 à 16:10, Kevin Wolf a écrit :
Quoted 20 lines
Am 03.09.2022 um 18:23 hat Hervé Poussineau geschrieben:
Quoted 19 lines
'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
Signed-off-by Hervé Poussineau <[email protected]>--- block/vvfat.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)block/vvfat.c +0
-0@@ -2993,11 +2993,27 @@ DLOG(checkpoint());vvfat_close_current_file (s);
Quoted 13 lines
block/vvfat.c DLOG(checkpoint()); · line 3004
Quoted 9 lines
block/vvfat.c +9
-0+if (sector_num == s->offset_to_bootsector && nb_sectors ==1 ) { +/* +* Write on bootsector. Allow only changing the reserved1 field, +* used to mark volume dirtiness +*/ +const unsigned char *initial = s->first_sectors + + s->offset_to_bootsector *0x200 ; +for (i =0 ; i <0x200 ; i++) { + if (i != offsetof(bootsector_t, u.fat16.reserved1) &&I think you need to check the FAT version (
s->fat_type) before accessing u.fat16. For FAT32, the "reserved" field is at a different offset (but seems to have the same meaning).
I didn't do this, because only fat16 part of bootsector is ever used. In init_directories(), only fat16 part is initialized, with the comment:
/* LATER TODO: if FAT32, this is wrong */
I wanted to be consistent between init_directories() and the check.
Quoted 9 lines
block/vvfat.c DLOG(checkpoint()); · line 3011
Quoted 8 lines
block/vvfat.c +7
-0+ initial[i] != buf[i]) { +fprintf (stderr,"Tried to write to protected bootsector\n" ); +return -1 ; + } + } +return 0 ; + }
Quoted 3 lines
Should we update
s->first_sectorswith the new value so that the guest would actually read back what it wrote instead of having the change disappear magically?
Windows guests don't seem to care if the written value disappears. They only want the write to succeed.
Quoted 11 lines
block/vvfat.c DLOG(checkpoint()); · line 3018
Quoted 8 lines
block/vvfat.c +0
-1/* * Some sanity checks: * - do not allow writing to the boot sector */ -if (sector_num < s->offset_to_fat)return -1 ;Kevin
Re: [PATCH 1/2] vvfat: allow some writes to bootsector
Am 29.09.2022 um 21:53 hat Hervé Poussineau geschrieben:
Quoted 33 lines
Le 29/09/2022 à 16:10, Kevin Wolf a écrit :
Quoted 23 lines
Am 03.09.2022 um 18:23 hat Hervé Poussineau geschrieben:
Quoted 22 lines
'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
Signed-off-by Hervé Poussineau <[email protected]>--- block/vvfat.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)block/vvfat.c +5
-0@@ -2993,11 +2993,27 @@ 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 +*/ Quoted 8 lines
block/vvfat.c DLOG(checkpoint()); · line 3004
Quoted 4 lines
block/vvfat.c +4
-0+const unsigned char *initial = s->first_sectors + + s->offset_to_bootsector *0x200 ; +for (i =0 ; i <0x200 ; i++) { + if (i != offsetof(bootsector_t, u.fat16.reserved1) &&I think you need to check the FAT version (
s->fat_type) before accessing u.fat16. For FAT32, the "reserved" field is at a different offset (but seems to have the same meaning).
Quoted 4 lines
I didn't do this, because only fat16 part of bootsector is ever used. In
init_directories(), only fat16 part is initialized, with the comment:/* LATER TODO: if FAT32, this is wrong */I wanted to be consistent between
init_directories()and the check.
Oh, indeed. I guess this means FAT32 is completely broken... Fair enough, though maybe we could add a similar comment here, then.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
block/vvfat.c +7
-0+ initial[i] != buf[i]) { +fprintf (stderr,"Tried to write to protected bootsector\n" ); +return -1 ; + } + } +return 0 ; + }
Quoted 6 lines
Quoted 3 lines
Should we update
s->first_sectorswith the new value so that the guest would actually read back what it wrote instead of having the change disappear magically?Windows guests don't seem to care if the written value disappears. They only want the write to succeed.
But it would be arguably more correct, wouldn't it? Some other OS might care.
Kevin