summaryrefslogtreecommitdiff
path: root/block/vvfat.c
diff options
context:
space:
mode:
authorHervé Poussineau <hpoussin@reactos.org>2017-05-22 23:11:59 +0200
committerKevin Wolf <kwolf@redhat.com>2017-07-10 13:18:05 +0200
commitf82d92bb028a1d674bab4ccc7e6cde6c04956230 (patch)
treef8778e418c6b5f96c673291829b89efb0b2bd71c /block/vvfat.c
parent92e28d82209b0ff49db801e9a56a400cc1f44967 (diff)
downloadqemu-f82d92bb028a1d674bab4ccc7e6cde6c04956230.tar.gz
vvfat: always create . and .. entries at first and in that order
readdir() doesn't always return . and .. entries at first and in that order. This leads to not creating them at first in the directory, which raises some errors on file system checking utilities like MS-DOS Scandisk. Specification: "FAT: General overview of on-disk format" v1.03, page 25 Fixes: https://bugs.launchpad.net/qemu/+bug/1599539 Signed-off-by: Hervé Poussineau <hpoussin@reactos.org> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/vvfat.c')
-rw-r--r--block/vvfat.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/block/vvfat.c b/block/vvfat.c
index 676cacb76b..0c6d0f407f 100644
--- a/block/vvfat.c
+++ b/block/vvfat.c
@@ -727,6 +727,12 @@ static int read_directory(BDRVVVFATState* s, int mapping_index)
i = mapping->info.dir.first_dir_index =
first_cluster == 0 ? 0 : s->directory.next;
+ if (first_cluster != 0) {
+ /* create the top entries of a subdirectory */
+ (void)create_short_and_long_name(s, i, ".", 1);
+ (void)create_short_and_long_name(s, i, "..", 1);
+ }
+
/* actually read the directory, and allocate the mappings */
while((entry=readdir(dir))) {
unsigned int length=strlen(dirname)+2+strlen(entry->d_name);
@@ -748,8 +754,11 @@ static int read_directory(BDRVVVFATState* s, int mapping_index)
}
/* create directory entry for this file */
- direntry=create_short_and_long_name(s, i, entry->d_name,
- is_dot || is_dotdot);
+ if (!is_dot && !is_dotdot) {
+ direntry = create_short_and_long_name(s, i, entry->d_name, 0);
+ } else {
+ direntry = array_get(&(s->directory), is_dot ? i : i + 1);
+ }
direntry->attributes=(S_ISDIR(st.st_mode)?0x10:0x20);
direntry->reserved[0]=direntry->reserved[1]=0;
direntry->ctime=fat_datetime(st.st_ctime,1);