From b14e65d1652c5c21b7ec6f6f30312f8d2ab5ec3a Mon Sep 17 00:00:00 2001 From: ChulHo Song Date: Tue, 20 Oct 2015 20:22:03 +0900 Subject: [PATCH] 9pfs: fix bug of reading host directory path On Windows host, if the user selected the root directory as Host Directory Sharing path, the emulator launching failure could occur. There was a code that remove the last backslash of entered path on Windows implementation. By the way, stat() function could not read the path when root path like 'c:\' had entered and been removed the last backslash(the result was 'c:'). So we change the code to remove the backslash only if the entered path is not a root directory. We should check the stat() working mechanism about reading pathes including backslash on Windows later. Change-Id: I7a155520af1f008f927e6dc67408e930c0f73ab1 Signed-off-by: ChulHo Song Signed-off-by: Sooyoung Ha (cherry picked from commit 20be828e348259146208ee67f13c1b340a8eaff8) --- hw/9pfs/virtio-9p-local-maru.c | 3 +++ hw/9pfs/virtio-9p.h | 13 ++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/hw/9pfs/virtio-9p-local-maru.c b/hw/9pfs/virtio-9p-local-maru.c index f452c87e55..5d0e495d5b 100644 --- a/hw/9pfs/virtio-9p-local-maru.c +++ b/hw/9pfs/virtio-9p-local-maru.c @@ -250,6 +250,9 @@ err_out: GetDiskFreeSpace(RootPathName, NULL, &BytesPerSector, NULL, NULL); hostBytesPerSector = BytesPerSector; } + /* TODO + * We should check how this works. + */ err = stat(pathname, stbuf); /* Modify the permission to 777 except the directories. */ diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h index 701f387d67..fd23f6d259 100644 --- a/hw/9pfs/virtio-9p.h +++ b/hw/9pfs/virtio-9p.h @@ -126,10 +126,17 @@ static inline char *rpath(FsContext *ctx, const char *path) return g_strdup_printf("%s/%s", ctx->fs_root, path); #else char *buffer; + unsigned int len; - buffer = g_strdup_printf("%s\\%s", ctx->fs_root, path); - while(buffer[strlen(buffer)-1] == '\\'){ - buffer[strlen(buffer)-1] = '\0'; + buffer = g_strdup_printf("%s\\%s", ctx->fs_root, path); + len = strlen(buffer); + + // TODO : need to remove backslash?? + while (len && buffer[len-1] == '\\') { + if (len > 1 && buffer[len-2] == ':') { + return buffer; + } + buffer[--len] = '\0'; } return buffer; #endif -- 2.34.1