9pfs: fix bug of reading host directory path
authorChulHo Song <ch81.song@samsung.com>
Tue, 20 Oct 2015 11:22:03 +0000 (20:22 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Fri, 13 Nov 2015 04:56:56 +0000 (13:56 +0900)
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 <ch81.song@samsung.com>
Signed-off-by: Sooyoung Ha <yoosah.ha@samsung.com>
(cherry picked from commit 20be828e348259146208ee67f13c1b340a8eaff8)

hw/9pfs/virtio-9p-local-maru.c
hw/9pfs/virtio-9p.h

index f452c87e55fcfd5818af9a7e1d67b8d7d679d599..5d0e495d5b06e6ee528a2ad4b9a0fd92f035d72a 100644 (file)
@@ -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. */
index 701f387d6795161a553abaf4c40ef22c0edc1108..fd23f6d259646e427d884924a4fd9562126088f2 100644 (file)
@@ -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