Merge branch 'tizen_qemu_2.0' into tizen
[sdk/emulator/qemu.git] / hw / 9pfs / virtio-9p-local-maru.c
index 71c6a51..3a265a0 100644 (file)
@@ -82,21 +82,21 @@ uint64_t hostBytesPerSector = -1;
 #define AT_REMOVEDIR 0x200
 #endif
 
-static const char *local_mapped_attr_path(FsContext *ctx,
-                                          const char *path, char *buffer)
+static char *local_mapped_attr_path(FsContext *ctx, const char *path)
 {
     char *dir_name;
     char *tmp_path = g_strdup(path);
     char *base_name = basename(tmp_path);
+    char *buffer;
 
     /* NULL terminate the directory */
     dir_name = tmp_path;
     *(base_name - 1) = '\0';
 #ifndef CONFIG_WIN32
-    snprintf(buffer, PATH_MAX, "%s/%s/%s/%s",
+    buffer = g_strdup_printf("%s/%s/%s/%s",
              ctx->fs_root, dir_name, VIRTFS_META_DIR, base_name);
 #else
-    snprintf(buffer, PATH_MAX, "%s\\%s\\%s\\%s",
+    buffer = g_strdup_printf("%s\\%s\\%s\\%s",
              ctx->fs_root, dir_name, VIRTFS_META_DIR, base_name);
     while(buffer[strlen(buffer)-1] == '\\'){
         buffer[strlen(buffer)-1] = '\0';
@@ -151,10 +151,11 @@ static void local_mapped_file_attr(FsContext *ctx, const char *path,
     TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
     FILE *fp;
     char buf[ATTR_MAX];
-    char attr_path[PATH_MAX];
+    char *attr_path;
 
-    local_mapped_attr_path(ctx, path, attr_path);
+    attr_path = local_mapped_attr_path(ctx, path);
     fp = local_fopen(attr_path, "r");
+    g_free(attr_path);
     if (!fp) {
         return;
     }
@@ -179,11 +180,12 @@ static int local_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf)
 {
     TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
     int err;
-    char buffer[PATH_MAX];
+    char *buffer;
     char *path = fs_path->data;
+    buffer = rpath(fs_ctx, path);
 
 #ifndef CONFIG_WIN32
-    err =  lstat(rpath(fs_ctx, path, buffer), stbuf);
+    err =  lstat(buffer, stbuf);
     if (err) {
         return err;
     }
@@ -194,19 +196,19 @@ static int local_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf)
         mode_t tmp_mode;
         dev_t tmp_dev;
 #ifdef CONFIG_LINUX
-        if (getxattr(rpath(fs_ctx, path, buffer), "user.virtfs.uid", &tmp_uid,
+        if (getxattr(buffer, "user.virtfs.uid", &tmp_uid,
                     sizeof(uid_t)) > 0) {
             stbuf->st_uid = tmp_uid;
         }
-        if (getxattr(rpath(fs_ctx, path, buffer), "user.virtfs.gid", &tmp_gid,
+        if (getxattr(buffer, "user.virtfs.gid", &tmp_gid,
                     sizeof(gid_t)) > 0) {
             stbuf->st_gid = tmp_gid;
         }
-        if (getxattr(rpath(fs_ctx, path, buffer), "user.virtfs.mode",
+        if (getxattr(buffer, "user.virtfs.mode",
                     &tmp_mode, sizeof(mode_t)) > 0) {
             stbuf->st_mode = tmp_mode;
         }
-        if (getxattr(rpath(fs_ctx, path, buffer), "user.virtfs.rdev", &tmp_dev,
+        if (getxattr(buffer, "user.virtfs.rdev", &tmp_dev,
                     sizeof(dev_t)) > 0) {
             stbuf->st_rdev = tmp_dev;
         }
@@ -219,19 +221,19 @@ static int local_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf)
         *  second one is options which specify option for retrieving extended attributes:
         *  (XATTR_NOFOLLOW, XATTR_SHOWCOMPRESSION)
         */
-        if (getxattr(rpath(fs_ctx, path, buffer), "user.virtfs.uid", &tmp_uid,
+        if (getxattr(buffer, "user.virtfs.uid", &tmp_uid,
                     sizeof(uid_t), 0, 0) > 0) {
             stbuf->st_uid = tmp_uid;
         }
-        if (getxattr(rpath(fs_ctx, path, buffer), "user.virtfs.gid", &tmp_gid,
+        if (getxattr(buffer, "user.virtfs.gid", &tmp_gid,
                     sizeof(gid_t), 0, 0) > 0) {
             stbuf->st_gid = tmp_gid;
         }
-        if (getxattr(rpath(fs_ctx, path, buffer), "user.virtfs.mode",
+        if (getxattr(buffer, "user.virtfs.mode",
                     &tmp_mode, sizeof(mode_t), 0, 0) > 0) {
             stbuf->st_mode = tmp_mode;
         }
-        if (getxattr(rpath(fs_ctx, path, buffer), "user.virtfs.rdev", &tmp_dev,
+        if (getxattr(buffer, "user.virtfs.rdev", &tmp_dev,
                     sizeof(dev_t), 0, 0) > 0) {
             stbuf->st_rdev = tmp_dev;
         }
@@ -240,7 +242,7 @@ static int local_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf)
         local_mapped_file_attr(fs_ctx, path, stbuf);
     }
 #else
-    const char * pathname = rpath(fs_ctx, path, buffer);
+    const char * pathname = buffer;
     if (hostBytesPerSector == -1) {
         DWORD BytesPerSector;
         TCHAR tmpName[PATH_MAX] = {0};
@@ -257,6 +259,7 @@ static int local_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf)
     /* Modify the permission to 777 except the directories. */
     stbuf->st_mode = stbuf->st_mode | 0777;
 #endif
+    g_free(buffer);
     return err;
 }
 
@@ -290,10 +293,12 @@ static int local_set_mapped_file_attr(FsContext *ctx,
     FILE *fp;
     int ret = 0;
     char buf[ATTR_MAX];
-    char attr_path[PATH_MAX];
+    char *attr_path;
     int uid = -1, gid = -1, mode = -1, rdev = -1;
 
-    fp = local_fopen(local_mapped_attr_path(ctx, path, attr_path), "r");
+    attr_path = local_mapped_attr_path(ctx, path);
+    fp = local_fopen(attr_path, "r");
+    g_free(attr_path);
     if (!fp) {
         goto create_map_file;
     }
@@ -435,20 +440,22 @@ static int local_post_create_passthrough(FsContext *fs_ctx, const char *path,
                                          FsCred *credp)
 {
 #ifndef CONFIG_WIN32
-    char buffer[PATH_MAX];
+    char *buffer = rpath(fs_ctx, path);
 
-    if (lchown(rpath(fs_ctx, path, buffer), credp->fc_uid,
+    if (lchown(buffer, credp->fc_uid,
                 credp->fc_gid) < 0) {
         /*
          * If we fail to change ownership and if we are
          * using security model none. Ignore the error
          */
         if ((fs_ctx->export_flags & V9FS_SEC_MASK) != V9FS_SM_NONE) {
+            g_free(buffer);
             return -1;
         }
     }
 
-    if (chmod(rpath(fs_ctx, path, buffer), credp->fc_mode & 07777) < 0) {
+    if (chmod(buffer, credp->fc_mode & 07777) < 0) {
+        g_free(buffer);
         return -1;
     }
 #endif
@@ -461,13 +468,15 @@ static ssize_t local_readlink(FsContext *fs_ctx, V9fsPath *fs_path,
     TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
     ssize_t tsize = -1;
 #ifndef CONFIG_WIN32
-    char buffer[PATH_MAX];
+    char *buffer;
     char *path = fs_path->data;
+    buffer = rpath(fs_ctx, path);
 
     if ((fs_ctx->export_flags & V9FS_SM_MAPPED) ||
         (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE)) {
         int fd;
-        fd = open(rpath(fs_ctx, path, buffer), O_RDONLY | O_NOFOLLOW);
+        fd = open(buffer, O_RDONLY | O_NOFOLLOW);
+        g_free(buffer);
         if (fd == -1) {
             return -1;
         }
@@ -478,7 +487,8 @@ static ssize_t local_readlink(FsContext *fs_ctx, V9fsPath *fs_path,
         return tsize;
     } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
                (fs_ctx->export_flags & V9FS_SM_NONE)) {
-        tsize = readlink(rpath(fs_ctx, path, buffer), buf, bufsz);
+        tsize = readlink(buffer, buf, bufsz);
+        g_free(buffer);
     }
 #endif
     return tsize;
@@ -500,14 +510,16 @@ static int local_open(FsContext *ctx, V9fsPath *fs_path,
                       int flags, V9fsFidOpenState *fs)
 {
     TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
-    char buffer[PATH_MAX];
+    char *buffer;
     char *path = fs_path->data;
+    buffer = rpath(ctx, path);
 #ifdef CONFIG_WIN32
     flags |= O_BINARY;
 #endif
 
-    fs->fd = open(rpath(ctx, path, buffer), flags | O_NOFOLLOW);
+    fs->fd = open(buffer, flags | O_NOFOLLOW);
 
+    g_free(buffer);
     return fs->fd;
 }
 
@@ -515,10 +527,12 @@ static int local_opendir(FsContext *ctx,
                          V9fsPath *fs_path, V9fsFidOpenState *fs)
 {
     TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
-    char buffer[PATH_MAX];
+    char *buffer;
     char *path = fs_path->data;
+    buffer = rpath(ctx, path);
 
-    fs->dir = opendir(rpath(ctx, path, buffer));
+    fs->dir = opendir(buffer);
+    g_free(buffer);
     if (!fs->dir) {
         return -1;
     }
@@ -626,19 +640,23 @@ static int local_chmod(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp)
 {
     TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
 #ifndef CONFIG_WIN32
-    char buffer[PATH_MAX];
+    char *buffer;
+    int ret = -1;
     char *path = fs_path->data;
+    buffer = rpath(fs_ctx, path);
 
     if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
-        return local_set_xattr(rpath(fs_ctx, path, buffer), credp);
+        ret = local_set_xattr(buffer, credp);
     } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
+        g_free(buffer);
         return local_set_mapped_file_attr(fs_ctx, path, credp);
     } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
                (fs_ctx->export_flags & V9FS_SM_NONE)) {
-        return chmod(rpath(fs_ctx, path, buffer), credp->fc_mode);
+        ret = chmod(buffer, credp->fc_mode);
     }
+    g_free(buffer);
 #endif
-    return -1;
+    return ret;
 }
 
 static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
@@ -650,27 +668,28 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
     char *path;
     int serrno = 0;
     V9fsString fullname;
-    char buffer[PATH_MAX];
+    char *buffer;
 
     v9fs_string_init(&fullname);
     v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name);
     path = fullname.data;
+    buffer = rpath(fs_ctx, path);
 
     /* Determine the security model */
     if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
-        err = mknod(rpath(fs_ctx, path, buffer),
+        err = mknod(buffer,
                 SM_LOCAL_MODE_BITS|S_IFREG, 0);
         if (err == -1) {
             goto out;
         }
-        err = local_set_xattr(rpath(fs_ctx, path, buffer), credp);
+        err = local_set_xattr(buffer, credp);
         if (err == -1) {
             serrno = errno;
             goto err_end;
         }
     } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
 
-        err = mknod(rpath(fs_ctx, path, buffer),
+        err = mknod(buffer,
                     SM_LOCAL_MODE_BITS|S_IFREG, 0);
         if (err == -1) {
             goto out;
@@ -682,7 +701,7 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
         }
     } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
                (fs_ctx->export_flags & V9FS_SM_NONE)) {
-        err = mknod(rpath(fs_ctx, path, buffer), credp->fc_mode,
+        err = mknod(buffer, credp->fc_mode,
                 credp->fc_rdev);
         if (err == -1) {
             goto out;
@@ -696,8 +715,9 @@ static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
     goto out;
 
 err_end:
-    remove(rpath(fs_ctx, path, buffer));
+    remove(buffer);
     errno = serrno;
+    g_free(buffer);
 out:
     v9fs_string_free(&fullname);
 #endif
@@ -712,7 +732,7 @@ static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir_path,
     int err = -1;
     int serrno = 0;
     V9fsString fullname;
-    char buffer[PATH_MAX];
+    char *buffer;
 
     v9fs_string_init(&fullname);
 #ifndef CONFIG_WIN32
@@ -724,22 +744,23 @@ static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir_path,
     }
 #endif
     path = fullname.data;
+    buffer = rpath(fs_ctx, path);
 
 #ifndef CONFIG_WIN32
     /* Determine the security model */
     if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
-        err = mkdir(rpath(fs_ctx, path, buffer), SM_LOCAL_DIR_MODE_BITS);
+        err = mkdir(buffer, SM_LOCAL_DIR_MODE_BITS);
         if (err == -1) {
             goto out;
         }
         credp->fc_mode = credp->fc_mode|S_IFDIR;
-        err = local_set_xattr(rpath(fs_ctx, path, buffer), credp);
+        err = local_set_xattr(buffer, credp);
         if (err == -1) {
             serrno = errno;
             goto err_end;
         }
     } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
-        err = mkdir(rpath(fs_ctx, path, buffer), SM_LOCAL_DIR_MODE_BITS);
+        err = mkdir(buffer, SM_LOCAL_DIR_MODE_BITS);
         if (err == -1) {
             goto out;
         }
@@ -751,7 +772,7 @@ static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir_path,
         }
     } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
                (fs_ctx->export_flags & V9FS_SM_NONE)) {
-        err = mkdir(rpath(fs_ctx, path, buffer), credp->fc_mode);
+        err = mkdir(buffer, credp->fc_mode);
         if (err == -1) {
             goto out;
         }
@@ -762,13 +783,14 @@ static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir_path,
         }
     }
 #else
-    err = mkdir(rpath(fs_ctx, path, buffer));
+    err = mkdir(buffer);
 #endif
     goto out;
 
 err_end:
-    remove(rpath(fs_ctx, path, buffer));
+    remove(buffer);
     errno = serrno;
+    g_free(buffer);
 out:
     v9fs_string_free(&fullname);
     return err;
@@ -854,7 +876,7 @@ static int local_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name,
     int err = -1;
     int serrno = 0;
     V9fsString fullname;
-    char buffer[PATH_MAX];
+    char *buffer;
 
     /*
      * Mark all the open to not follow symlinks
@@ -869,10 +891,11 @@ static int local_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name,
     flags |= O_BINARY;
 #endif
     path = fullname.data;
+    buffer = rpath(fs_ctx, path);
 
     /* Determine the security model */
     if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
-        fd = open(rpath(fs_ctx, path, buffer), flags, SM_LOCAL_MODE_BITS);
+        fd = open(buffer, flags, SM_LOCAL_MODE_BITS);
         if (fd == -1) {
             err = fd;
             goto out;
@@ -880,14 +903,14 @@ static int local_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name,
 #ifndef CONFIG_WIN32
         credp->fc_mode = credp->fc_mode|S_IFREG;
         /* Set cleint credentials in xattr */
-        err = local_set_xattr(rpath(fs_ctx, path, buffer), credp);
+        err = local_set_xattr(buffer, credp);
         if (err == -1) {
             serrno = errno;
             goto err_end;
         }
 #endif
     } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
-        fd = open(rpath(fs_ctx, path, buffer), flags, SM_LOCAL_MODE_BITS);
+        fd = open(buffer, flags, SM_LOCAL_MODE_BITS);
         if (fd == -1) {
             err = fd;
             goto out;
@@ -901,7 +924,7 @@ static int local_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name,
         }
     } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
                (fs_ctx->export_flags & V9FS_SM_NONE)) {
-        fd = open(rpath(fs_ctx, path, buffer), flags, credp->fc_mode);
+        fd = open(buffer, flags, credp->fc_mode);
         if (fd == -1) {
             err = fd;
             goto out;
@@ -918,8 +941,9 @@ static int local_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name,
 
 err_end:
     close(fd);
-    remove(rpath(fs_ctx, path, buffer));
+    remove(buffer);
     errno = serrno;
+    g_free(buffer);
 out:
     v9fs_string_free(&fullname);
     return err;
@@ -934,19 +958,20 @@ static int local_symlink(FsContext *fs_ctx, const char *oldpath,
     int serrno = 0;
     char *newpath;
     V9fsString fullname;
-    char buffer[PATH_MAX];
+    char *buffer;
 
     int flags = O_CREAT|O_EXCL|O_RDWR|O_NOFOLLOW;
 
     v9fs_string_init(&fullname);
     v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name);
     newpath = fullname.data;
+    buffer = rpath(fs_ctx, newpath);
 
     /* Determine the security model */
     if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
         int fd;
         ssize_t oldpath_size, write_size;
-        fd = open(rpath(fs_ctx, newpath, buffer), flags, SM_LOCAL_MODE_BITS);
+        fd = open(buffer, flags, SM_LOCAL_MODE_BITS);
         if (fd == -1) {
             err = fd;
             goto out;
@@ -966,7 +991,7 @@ static int local_symlink(FsContext *fs_ctx, const char *oldpath,
         close(fd);
         /* Set cleint credentials in symlink's xattr */
         credp->fc_mode = credp->fc_mode|S_IFLNK;
-        err = local_set_xattr(rpath(fs_ctx, newpath, buffer), credp);
+        err = local_set_xattr(buffer, credp);
         if (err == -1) {
             serrno = errno;
             goto err_end;
@@ -974,7 +999,7 @@ static int local_symlink(FsContext *fs_ctx, const char *oldpath,
     } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
         int fd;
         ssize_t oldpath_size, write_size;
-        fd = open(rpath(fs_ctx, newpath, buffer), flags, SM_LOCAL_MODE_BITS);
+        fd = open(buffer, flags, SM_LOCAL_MODE_BITS);
         if (fd == -1) {
             err = fd;
             goto out;
@@ -1001,11 +1026,11 @@ static int local_symlink(FsContext *fs_ctx, const char *oldpath,
         }
     } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
                (fs_ctx->export_flags & V9FS_SM_NONE)) {
-        err = symlink(oldpath, rpath(fs_ctx, newpath, buffer));
+        err = symlink(oldpath, buffer);
         if (err) {
             goto out;
         }
-        err = lchown(rpath(fs_ctx, newpath, buffer), credp->fc_uid,
+        err = lchown(buffer, credp->fc_uid,
                      credp->fc_gid);
         if (err == -1) {
             /*
@@ -1022,8 +1047,9 @@ static int local_symlink(FsContext *fs_ctx, const char *oldpath,
     goto out;
 
 err_end:
-    remove(rpath(fs_ctx, newpath, buffer));
+    remove(buffer);
     errno = serrno;
+    g_free(buffer);
 out:
     v9fs_string_free(&fullname);
 #endif
@@ -1037,13 +1063,16 @@ static int local_link(FsContext *ctx, V9fsPath *oldpath,
     int ret = 0;
 #ifndef CONFIG_WIN32
     V9fsString newpath;
-    char buffer[PATH_MAX], buffer1[PATH_MAX];
+    char *buffer, *buffer1;
 
     v9fs_string_init(&newpath);
     v9fs_string_sprintf(&newpath, "%s/%s", dirpath->data, name);
 
-    ret = link(rpath(ctx, oldpath->data, buffer),
-               rpath(ctx, newpath.data, buffer1));
+    buffer = rpath(ctx, oldpath->data);
+    buffer1 = rpath(ctx, newpath.data);
+    ret = link(buffer, buffer1);
+    g_free(buffer);
+    g_free(buffer1);
 
     /* now link the virtfs_metadata files */
     if (!ret && (ctx->export_flags & V9FS_SM_MAPPED_FILE)) {
@@ -1052,8 +1081,11 @@ static int local_link(FsContext *ctx, V9fsPath *oldpath,
         if (ret < 0) {
             goto err_out;
         }
-        ret = link(local_mapped_attr_path(ctx, oldpath->data, buffer),
-                   local_mapped_attr_path(ctx, newpath.data, buffer1));
+        buffer = local_mapped_attr_path(ctx, oldpath->data);
+        buffer1 = local_mapped_attr_path(ctx, newpath.data);
+        ret = link(buffer, buffer1);
+        g_free(buffer);
+        g_free(buffer1);
         if (ret < 0 && errno != ENOENT) {
             goto err_out;
         }
@@ -1067,21 +1099,23 @@ err_out:
 static int local_truncate(FsContext *ctx, V9fsPath *fs_path, off_t size)
 {
     TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
-    char buffer[PATH_MAX];
+    char *buffer;
+    int ret = -1;
     char *path = fs_path->data;
+    buffer = rpath(ctx, path);
 #ifndef CONFIG_WIN32
-    return truncate(rpath(ctx, path, buffer), size);
+    ret = truncate(buffer, size);
 #else
-    int ret;
-    int fd = open(rpath(ctx, path, buffer), O_RDWR | O_BINARY | O_NOFOLLOW);
+    int fd = open(buffer, O_RDWR | O_BINARY | O_NOFOLLOW);
     if(fd < 0) {
         ret = -1;
     } else {
         ret = ftruncate(fd, size);
         close(fd);
     }
-    return ret;
 #endif
+    g_free(buffer);
+    return ret;
 }
 
 static int local_rename(FsContext *ctx, const char *oldpath,
@@ -1089,7 +1123,7 @@ static int local_rename(FsContext *ctx, const char *oldpath,
 {
     TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
     int err;
-    char buffer[PATH_MAX], buffer1[PATH_MAX];
+    char *buffer, *buffer1;
 
     if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
         err = local_create_mapped_attr_dir(ctx, newpath);
@@ -1097,22 +1131,32 @@ static int local_rename(FsContext *ctx, const char *oldpath,
             return err;
         }
         /* rename the .virtfs_metadata files */
-        err = rename(local_mapped_attr_path(ctx, oldpath, buffer),
-                     local_mapped_attr_path(ctx, newpath, buffer1));
+        buffer = local_mapped_attr_path(ctx, oldpath);
+        buffer1 = local_mapped_attr_path(ctx, newpath);
+        err = rename(buffer, buffer1);
+        g_free(buffer);
+        g_free(buffer1);
         if (err < 0 && errno != ENOENT) {
             return err;
         }
     }
+    buffer = rpath(ctx, oldpath);
+    buffer1 = rpath(ctx, newpath);
 #ifndef CONFIG_WIN32
-    return rename(rpath(ctx, oldpath, buffer), rpath(ctx, newpath, buffer1));
+    err = rename(buffer, buffer1);
+    g_free(buffer);
+    g_free(buffer1);
+    return err;
 #else
-    if (!MoveFileEx((LPCTSTR)rpath(ctx, oldpath, buffer),
-                    (LPCTSTR)rpath(ctx, newpath, buffer1), MOVEFILE_REPLACE_EXISTING)){
+    if (!MoveFileEx((LPCTSTR)buffer,
+                    (LPCTSTR)buffer1, MOVEFILE_REPLACE_EXISTING)){
         err = -(GetLastError());
         ERR("[%d][ >> %s] err: %d\n", __LINE__, __func__, err);
     } else {
         err = 0;
     }
+    g_free(buffer);
+    g_free(buffer1);
     return err;
 #endif
 }
@@ -1121,19 +1165,20 @@ static int local_chown(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp)
 {
     TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
 #ifndef CONFIG_WIN32
-    char buffer[PATH_MAX];
+    char *buffer;
     char *path = fs_path->data;
+    buffer = rpath(fs_ctx, path);
 
     if ((credp->fc_uid == -1 && credp->fc_gid == -1) ||
         (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
         (fs_ctx->export_flags & V9FS_SM_NONE)) {
-        return lchown(rpath(fs_ctx, path, buffer),
-                      credp->fc_uid, credp->fc_gid);
+        return lchown(buffer, credp->fc_uid, credp->fc_gid);
     } else if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
-        return local_set_xattr(rpath(fs_ctx, path, buffer), credp);
+        return local_set_xattr(buffer, credp);
     } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
         return local_set_mapped_file_attr(fs_ctx, path, credp);
     }
+    g_free(buffer);
 #endif
     return -1;
 }
@@ -1196,12 +1241,16 @@ static int local_utimensat(FsContext *s, V9fsPath *fs_path,
                            const struct timespec *buf)
 {
     TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
-    char buffer[PATH_MAX];
+    char *buffer;
+    int ret;
     char *path = fs_path->data;
+    buffer = rpath(s, path);
 #ifndef CONFIG_WIN32
-    return qemu_utimens(rpath(s, path, buffer), buf);
+    ret = qemu_utimens(buffer, buf);
+    g_free(buffer);
+    return ret;
 #else
-    const char * r_path = rpath(s, path, buffer);
+    const char * r_path = buffer;
     struct timeval tv[2], tv_now;
     struct stat st;
     int i;
@@ -1244,14 +1293,15 @@ static int local_remove(FsContext *ctx, const char *path)
     TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
     int err;
     struct stat stbuf;
-    char buffer[PATH_MAX];
+    char *buffer = rpath(ctx, path);
 
     if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
 #ifndef CONFIG_WIN32
-        err =  lstat(rpath(ctx, path, buffer), &stbuf);
+        err =  lstat(buffer, &stbuf);
 #else
-        err = _stat(rpath(ctx, path, buffer), &stbuf);
+        err = _stat(buffer, &stbuf);
 #endif
+        g_free(buffer);
         if (err) {
             goto err_out;
         }
@@ -1278,7 +1328,9 @@ static int local_remove(FsContext *ctx, const char *path)
          * Now remove the name from parent directory
          * .virtfs_metadata directory
          */
-        err = remove(local_mapped_attr_path(ctx, path, buffer));
+        buffer = local_mapped_attr_path(ctx, path);
+        err = remove(buffer);
+        g_free(buffer);
         if (err < 0 && errno != ENOENT) {
             /*
              * We didn't had the .virtfs_metadata file. May be file created
@@ -1287,7 +1339,9 @@ static int local_remove(FsContext *ctx, const char *path)
             goto err_out;
         }
     }
-    return remove(rpath(ctx, path, buffer));
+    buffer = rpath(ctx, path);
+    err = remove(buffer);
+    g_free(buffer);
 err_out:
     return err;
 }
@@ -1321,11 +1375,12 @@ static int local_fsync(FsContext *ctx, int fid_type,
 static int local_statfs(FsContext *s, V9fsPath *fs_path, struct statfs *stbuf)
 {
     TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
-    char buffer[PATH_MAX];
+    char *buffer;
     char *path = fs_path->data;
+    buffer = rpath(s, path);
 
 #ifndef CONFIG_WIN32
-    return statfs(rpath(s, path, buffer), stbuf);
+    return statfs(buffer, stbuf);
 #else
     DWORD VolumeSerialNumber,
           MaximumComponentLength,
@@ -1345,7 +1400,7 @@ static int local_statfs(FsContext *s, V9fsPath *fs_path, struct statfs *stbuf)
     TCHAR VolumeNameBuffer[PATH_MAX] = {0};
     TCHAR FileSystemNameBuffer[PATH_MAX] = {0};
 
-    strncpy(tmpName, rpath(s, path, buffer), 3 > PATH_MAX ? PATH_MAX : 3);
+    strncpy(tmpName, buffer, 3 > PATH_MAX ? PATH_MAX : 3);
     tmpName[4 > PATH_MAX ? PATH_MAX : 4] = '\0';
     LPCTSTR RootPathName = (LPCTSTR)tmpName;
 
@@ -1508,7 +1563,7 @@ static int local_unlinkat(FsContext *ctx, V9fsPath *dir,
     TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
     int ret;
     V9fsString fullname;
-    char buffer[PATH_MAX];
+    char *buffer;
 
     v9fs_string_init(&fullname);
 
@@ -1549,7 +1604,9 @@ static int local_unlinkat(FsContext *ctx, V9fsPath *dir,
          * Now remove the name from parent directory
          * .virtfs_metadata directory.
          */
-        ret = remove(local_mapped_attr_path(ctx, fullname.data, buffer));
+        buffer = local_mapped_attr_path(ctx, fullname.data);
+        ret = remove(buffer);
+        g_free(buffer);
         if (ret < 0 && errno != ENOENT) {
             /*
              * We didn't had the .virtfs_metadata file. May be file created
@@ -1559,15 +1616,17 @@ static int local_unlinkat(FsContext *ctx, V9fsPath *dir,
         }
     }
     /* Remove the name finally */
+    buffer = rpath(ctx, fullname.data);
 #ifndef CONFIG_WIN32
-    ret = remove(rpath(ctx, fullname.data, buffer));
+    ret = remove(buffer);
 #else
     if (flags == AT_REMOVEDIR) { // is dir
-        ret = rmdir(rpath(ctx, fullname.data, buffer));
+        ret = rmdir(buffer);
     } else { //is file
-        ret = remove(rpath(ctx, fullname.data, buffer));
+        ret = remove(buffer);
     }
 #endif
+    g_free(buffer);
     v9fs_string_free(&fullname);
 
 err_out: