2 * Virtio 9p backend for Maru
3 * Based on hw/9pfs/virtio-9p-local.c:
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
8 * Sooyoung Ha <yoosah.ha@samsung.com>
9 * YeongKyoon Lee <yeongkyoon.lee@samsung.com>
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
30 #include "qemu/osdep.h"
32 #include "fsdev/qemu-fsdev.h" /* local_ops */
35 #include <arpa/inet.h>
38 #include <sys/socket.h>
40 #include "qemu/xattr.h"
42 #include "qemu/cutils.h"
43 #include "qemu/error-report.h"
48 #ifdef CONFIG_LINUX_MAGIC_H
49 #include <linux/magic.h>
52 #include <sys/ioctl.h>
55 #include "tizen/src/util/new_debug_ch.h"
56 DECLARE_DEBUG_CHANNEL(9pfs_local);
58 #ifndef XFS_SUPER_MAGIC
59 #define XFS_SUPER_MAGIC 0x58465342
61 #ifndef EXT2_SUPER_MAGIC
62 #define EXT2_SUPER_MAGIC 0xEF53
64 #ifndef REISERFS_SUPER_MAGIC
65 #define REISERFS_SUPER_MAGIC 0x52654973
67 #ifndef BTRFS_SUPER_MAGIC
68 #define BTRFS_SUPER_MAGIC 0x9123683E
72 #ifndef MSDOS_SUPER_MAGIC
73 #define MSDOS_SUPER_MAGIC 0x4d44
75 #ifndef NTFS_SUPER_MAGIC
76 #define NTFS_SUPER_MAGIC 0x5346544e
79 uint64_t hostBytesPerSector = -1;
82 #define VIRTFS_META_DIR ".virtfs_metadata"
85 #define AT_REMOVEDIR 0x200
88 static char *local_mapped_attr_path(FsContext *ctx, const char *path)
91 const char *name = strrchr(path, '/');
100 return g_strdup_printf("%s/%.*s/%s/%s", ctx->fs_root,
101 dirlen, path, VIRTFS_META_DIR, name);
103 char *buffer = g_strdup_printf("%s\\%.*s\\%s\\%s", ctx->fs_root,
104 dirlen, path, VIRTFS_META_DIR, name);
105 while(buffer[strlen(buffer)-1] == '\\'){
106 buffer[strlen(buffer)-1] = '\0';
112 static FILE *local_fopen(const char *path, const char *mode)
114 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
120 int flags = O_NOFOLLOW;
122 * only supports two modes
124 if (mode[0] == 'r') {
126 } else if (mode[0] == 'w') {
127 flags |= O_WRONLY | O_TRUNC | O_CREAT;
129 o_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
135 fd = open(path, flags, o_mode);
137 fd = open(path, flags | O_BINARY);
142 fp = fdopen(fd, mode);
151 static void local_mapped_file_attr(FsContext *ctx, const char *path,
154 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
159 attr_path = local_mapped_attr_path(ctx, path);
160 fp = local_fopen(attr_path, "r");
165 memset(buf, 0, ATTR_MAX);
166 while (fgets(buf, ATTR_MAX, fp)) {
167 if (!strncmp(buf, "virtfs.uid", 10)) {
168 stbuf->st_uid = atoi(buf+11);
169 } else if (!strncmp(buf, "virtfs.gid", 10)) {
170 stbuf->st_gid = atoi(buf+11);
171 } else if (!strncmp(buf, "virtfs.mode", 11)) {
172 stbuf->st_mode = atoi(buf+12);
173 } else if (!strncmp(buf, "virtfs.rdev", 11)) {
174 stbuf->st_rdev = atoi(buf+12);
176 memset(buf, 0, ATTR_MAX);
182 static int local_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf)
184 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
187 char *path = fs_path->data;
189 buffer = rpath(fs_ctx, path);
191 err = lstat(buffer, stbuf);
195 if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
196 /* Actual credentials are part of extended attrs */
202 if (getxattr(buffer, "user.virtfs.uid", &tmp_uid, sizeof(uid_t)) > 0) {
203 stbuf->st_uid = le32_to_cpu(tmp_uid);
205 if (getxattr(buffer, "user.virtfs.gid", &tmp_gid, sizeof(gid_t)) > 0) {
206 stbuf->st_gid = le32_to_cpu(tmp_gid);
208 if (getxattr(buffer, "user.virtfs.mode",
209 &tmp_mode, sizeof(mode_t)) > 0) {
210 stbuf->st_mode = le32_to_cpu(tmp_mode);
212 if (getxattr(buffer, "user.virtfs.rdev", &tmp_dev, sizeof(dev_t)) > 0) {
213 stbuf->st_rdev = le64_to_cpu(tmp_dev);
217 * extra two parameters on Mac OS X.
218 * first one is position which specifies an offset within the extended attribute.
219 * i.e. extended attribute means "user.virtfs.uid". Currently, it is only used with
220 * resource fork attribute and all other extended attributes, it is reserved and should be zero.
221 * second one is options which specify option for retrieving extended attributes:
222 * (XATTR_NOFOLLOW, XATTR_SHOWCOMPRESSION)
224 if (getxattr(buffer, "user.virtfs.uid", &tmp_uid, sizeof(uid_t), 0, 0) > 0) {
225 stbuf->st_uid = le32_to_cpu(tmp_uid);
227 if (getxattr(buffer, "user.virtfs.gid", &tmp_gid, sizeof(gid_t), 0, 0) > 0) {
228 stbuf->st_gid = le32_to_cpu(tmp_gid);
230 if (getxattr(buffer, "user.virtfs.mode", &tmp_mode, sizeof(mode_t), 0, 0) > 0) {
231 stbuf->st_mode = le32_to_cpu(tmp_mode);
233 if (getxattr(buffer, "user.virtfs.rdev", &tmp_dev, sizeof(dev_t), 0, 0) > 0) {
234 stbuf->st_rdev = le64_to_cpu(tmp_dev);
237 } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
238 local_mapped_file_attr(fs_ctx, path, stbuf);
243 const char * pathname = buffer;
244 if (hostBytesPerSector == -1) {
245 DWORD BytesPerSector;
246 TCHAR tmpName[PATH_MAX] = {0};
248 strncpy(tmpName, pathname, 3 > PATH_MAX ? PATH_MAX : 3);
249 tmpName[4 > PATH_MAX ? PATH_MAX : 4] = '\0';
250 LPCTSTR RootPathName = (LPCTSTR)tmpName;
252 GetDiskFreeSpace(RootPathName, NULL, &BytesPerSector, NULL, NULL);
253 hostBytesPerSector = BytesPerSector;
256 * We should check how this works.
258 err = stat(pathname, stbuf);
260 /* Modify the permission to 777 except the directories. */
261 stbuf->st_mode = stbuf->st_mode | 0777;
267 static int local_create_mapped_attr_dir(FsContext *ctx, const char *path)
269 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
272 char *tmp_path = g_strdup(path);
275 attr_dir = g_strdup_printf("%s/%s/%s",
276 ctx->fs_root, dirname(tmp_path), VIRTFS_META_DIR);
278 err = mkdir(attr_dir, 0700);
280 attr_dir = g_strdup_printf("%s\\%s\\%s",
281 ctx->fs_root, dirname(tmp_path), VIRTFS_META_DIR);
282 err = mkdir(attr_dir);
284 if (err < 0 && errno == EEXIST) {
292 static int local_set_mapped_file_attr(FsContext *ctx,
293 const char *path, FsCred *credp)
295 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
300 int uid = -1, gid = -1, mode = -1, rdev = -1;
302 attr_path = local_mapped_attr_path(ctx, path);
303 fp = local_fopen(attr_path, "r");
305 goto create_map_file;
307 memset(buf, 0, ATTR_MAX);
308 while (fgets(buf, ATTR_MAX, fp)) {
309 if (!strncmp(buf, "virtfs.uid", 10)) {
311 } else if (!strncmp(buf, "virtfs.gid", 10)) {
313 } else if (!strncmp(buf, "virtfs.mode", 11)) {
315 } else if (!strncmp(buf, "virtfs.rdev", 11)) {
318 memset(buf, 0, ATTR_MAX);
321 goto update_map_file;
324 ret = local_create_mapped_attr_dir(ctx, path);
330 fp = local_fopen(attr_path, "w");
336 if (credp->fc_uid != -1) {
339 if (credp->fc_gid != -1) {
343 if (credp->fc_mode != (mode_t)-1) {
344 mode = credp->fc_mode;
347 mode = credp->fc_mode;
349 if (credp->fc_rdev != -1) {
350 rdev = credp->fc_rdev;
355 fprintf(fp, "virtfs.uid=%d\n", uid);
358 fprintf(fp, "virtfs.gid=%d\n", gid);
361 fprintf(fp, "virtfs.mode=%d\n", mode);
364 fprintf(fp, "virtfs.rdev=%d\n", rdev);
374 static int local_set_xattr(const char *path, FsCred *credp)
379 if (credp->fc_uid != -1) {
380 uint32_t tmp_uid = cpu_to_le32(credp->fc_uid);
381 err = setxattr(path, "user.virtfs.uid", &tmp_uid, sizeof(uid_t), 0);
386 if (credp->fc_gid != -1) {
387 uint32_t tmp_gid = cpu_to_le32(credp->fc_gid);
388 err = setxattr(path, "user.virtfs.gid", &tmp_gid, sizeof(gid_t), 0);
393 if (credp->fc_mode != -1) {
394 uint32_t tmp_mode = cpu_to_le32(credp->fc_mode);
395 err = setxattr(path, "user.virtfs.mode", &tmp_mode, sizeof(mode_t), 0);
400 if (credp->fc_rdev != -1) {
401 uint64_t tmp_rdev = cpu_to_le64(credp->fc_rdev);
402 err = setxattr(path, "user.virtfs.rdev", &tmp_rdev, sizeof(dev_t), 0);
409 * In case of setxattr on OS X, position parameter has been added.
410 * Its purpose is the same as getxattr. Last parameter options is the same as flags on Linux.
411 * XATTR_NOFOLLOW / XATTR_CREATE / XATTR_REPLACE
413 if (credp->fc_uid != -1) {
414 err = setxattr(path, "user.virtfs.uid", &credp->fc_uid, sizeof(uid_t),
420 if (credp->fc_gid != -1) {
421 err = setxattr(path, "user.virtfs.gid", &credp->fc_gid, sizeof(gid_t),
427 if (credp->fc_mode != (mode_t)-1) {
428 err = setxattr(path, "user.virtfs.mode", &credp->fc_mode,
429 sizeof(mode_t), 0, 0);
434 if (credp->fc_rdev != -1) {
435 err = setxattr(path, "user.virtfs.rdev", &credp->fc_rdev,
436 sizeof(dev_t), 0, 0);
447 static int local_post_create_passthrough(FsContext *fs_ctx, const char *path,
451 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
454 buffer = rpath(fs_ctx, path);
455 if (lchown(buffer, credp->fc_uid, credp->fc_gid) < 0) {
457 * If we fail to change ownership and if we are
458 * using security model none. Ignore the error
460 if ((fs_ctx->export_flags & V9FS_SEC_MASK) != V9FS_SM_NONE) {
465 if (chmod(buffer, credp->fc_mode & 07777) < 0) {
475 /* chown doesn't matter with the Windows environment. */
480 static ssize_t local_readlink(FsContext *fs_ctx, V9fsPath *fs_path,
481 char *buf, size_t bufsz)
483 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
487 char *path = fs_path->data;
489 if ((fs_ctx->export_flags & V9FS_SM_MAPPED) ||
490 (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE)) {
492 buffer = rpath(fs_ctx, path);
493 fd = open(buffer, O_RDONLY | O_NOFOLLOW);
499 tsize = read(fd, (void *)buf, bufsz);
500 } while (tsize == -1 && errno == EINTR);
502 } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
503 (fs_ctx->export_flags & V9FS_SM_NONE)) {
504 buffer = rpath(fs_ctx, path);
505 tsize = readlink(buffer, buf, bufsz);
512 static int local_close(FsContext *ctx, V9fsFidOpenState *fs)
514 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
515 return close(fs->fd);
518 static int local_closedir(FsContext *ctx, V9fsFidOpenState *fs)
520 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
521 return closedir(fs->dir);
524 static int local_open(FsContext *ctx, V9fsPath *fs_path,
525 int flags, V9fsFidOpenState *fs)
527 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
529 char *path = fs_path->data;
531 buffer = rpath(ctx, path);
535 fs->fd = open(buffer, flags | O_NOFOLLOW);
540 static int local_opendir(FsContext *ctx,
541 V9fsPath *fs_path, V9fsFidOpenState *fs)
543 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
545 char *path = fs_path->data;
547 buffer = rpath(ctx, path);
548 fs->dir = opendir(buffer);
556 static void local_rewinddir(FsContext *ctx, V9fsFidOpenState *fs)
558 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
562 static off_t local_telldir(FsContext *ctx, V9fsFidOpenState *fs)
564 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
565 return telldir(fs->dir);
568 static int local_readdir_r(FsContext *ctx, V9fsFidOpenState *fs,
569 struct dirent *entry,
570 struct dirent **result)
572 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
577 ret = readdir_r(fs->dir, entry, result);
578 if (ctx->export_flags & V9FS_SM_MAPPED) {
579 entry->d_type = DT_UNKNOWN;
580 } else if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
581 if (!ret && *result != NULL &&
582 !strcmp(entry->d_name, VIRTFS_META_DIR)) {
583 /* skp the meta data directory */
586 entry->d_type = DT_UNKNOWN;
590 *result = readdir(fs->dir);
591 ret = (ret == errno ? 0 : errno);
593 if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
594 if (!ret && *result != NULL &&
595 !strcmp(entry->d_name, VIRTFS_META_DIR)) {
596 /* skp the meta data directory */
604 static void local_seekdir(FsContext *ctx, V9fsFidOpenState *fs, off_t off)
606 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
607 seekdir(fs->dir, off);
610 static ssize_t local_preadv(FsContext *ctx, V9fsFidOpenState *fs,
611 const struct iovec *iov,
612 int iovcnt, off_t offset)
615 return preadv(fs->fd, iov, iovcnt, offset);
617 int err = lseek(fs->fd, offset, SEEK_SET);
621 return readv(fs->fd, iov, iovcnt);
626 static ssize_t local_pwritev(FsContext *ctx, V9fsFidOpenState *fs,
627 const struct iovec *iov,
628 int iovcnt, off_t offset)
633 ret = pwritev(fs->fd, iov, iovcnt, offset);
635 int err = lseek(fs->fd, offset, SEEK_SET);
639 ret = writev(fs->fd, iov, iovcnt);
642 #ifdef CONFIG_SYNC_FILE_RANGE
643 if (ret > 0 && ctx->export_flags & V9FS_IMMEDIATE_WRITEOUT) {
645 * Initiate a writeback. This is not a data integrity sync.
646 * We want to ensure that we don't leave dirty pages in the cache
647 * after write when writeout=immediate is sepcified.
649 sync_file_range(fs->fd, offset, ret,
650 SYNC_FILE_RANGE_WAIT_BEFORE | SYNC_FILE_RANGE_WRITE);
656 static int local_chmod(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp)
658 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
662 char *path = fs_path->data;
664 if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
665 buffer = rpath(fs_ctx, path);
666 ret = local_set_xattr(buffer, credp);
668 } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
669 return local_set_mapped_file_attr(fs_ctx, path, credp);
670 } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
671 (fs_ctx->export_flags & V9FS_SM_NONE)) {
672 buffer = rpath(fs_ctx, path);
673 ret = chmod(buffer, credp->fc_mode);
682 static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
683 const char *name, FsCred *credp)
685 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
693 v9fs_string_init(&fullname);
694 v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name);
695 path = fullname.data;
697 /* Determine the security model */
698 if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
699 buffer = rpath(fs_ctx, path);
700 err = mknod(buffer, SM_LOCAL_MODE_BITS|S_IFREG, 0);
704 err = local_set_xattr(buffer, credp);
709 } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
711 buffer = rpath(fs_ctx, path);
712 err = mknod(buffer, SM_LOCAL_MODE_BITS|S_IFREG, 0);
716 err = local_set_mapped_file_attr(fs_ctx, path, credp);
721 } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
722 (fs_ctx->export_flags & V9FS_SM_NONE)) {
723 buffer = rpath(fs_ctx, path);
724 err = mknod(buffer, credp->fc_mode, credp->fc_rdev);
728 err = local_post_create_passthrough(fs_ctx, path, credp);
741 v9fs_string_free(&fullname);
748 static int local_mkdir(FsContext *fs_ctx, V9fsPath *dir_path,
749 const char *name, FsCred *credp)
751 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
760 v9fs_string_init(&fullname);
762 v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name);
764 v9fs_string_sprintf(&fullname, "%s\\%s", dir_path->data, name);
765 while((fullname.data)[strlen(fullname.data)-1] == '\\'){
766 (fullname.data)[strlen(fullname.data)-1] = '\0';
769 path = fullname.data;
772 /* Determine the security model */
773 if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
774 buffer = rpath(fs_ctx, path);
775 err = mkdir(buffer, SM_LOCAL_DIR_MODE_BITS);
779 credp->fc_mode = credp->fc_mode|S_IFDIR;
780 err = local_set_xattr(buffer, credp);
785 } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
786 buffer = rpath(fs_ctx, path);
787 err = mkdir(buffer, SM_LOCAL_DIR_MODE_BITS);
791 credp->fc_mode = credp->fc_mode|S_IFDIR;
792 err = local_set_mapped_file_attr(fs_ctx, path, credp);
797 } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
798 (fs_ctx->export_flags & V9FS_SM_NONE)) {
799 buffer = rpath(fs_ctx, path);
800 err = mkdir(buffer, credp->fc_mode);
804 err = local_post_create_passthrough(fs_ctx, path, credp);
811 buffer = rpath(fs_ctx, path);
823 v9fs_string_free(&fullname);
827 static int local_fstat(FsContext *fs_ctx, int fid_type,
828 V9fsFidOpenState *fs, struct stat *stbuf)
830 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
833 if (fid_type == P9_FID_DIR) {
843 err = fstat(fd, stbuf);
847 if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
849 /* Actual credentials are part of extended attrs */
856 if (fgetxattr(fd, "user.virtfs.uid", &tmp_uid, sizeof(uid_t)) > 0) {
857 stbuf->st_uid = le32_to_cpu(tmp_uid);
859 if (fgetxattr(fd, "user.virtfs.gid", &tmp_gid, sizeof(gid_t)) > 0) {
860 stbuf->st_gid = le32_to_cpu(tmp_gid);
862 if (fgetxattr(fd, "user.virtfs.mode", &tmp_mode, sizeof(mode_t)) > 0) {
863 stbuf->st_mode = le32_to_cpu(tmp_mode);
865 if (fgetxattr(fd, "user.virtfs.rdev", &tmp_dev, sizeof(dev_t)) > 0) {
866 stbuf->st_rdev = le64_to_cpu(tmp_dev);
869 if (fgetxattr(fd, "user.virtfs.uid",
870 &tmp_uid, sizeof(uid_t), 0, 0) > 0) {
871 stbuf->st_uid = le32_to_cpu(tmp_uid);
873 if (fgetxattr(fd, "user.virtfs.gid",
874 &tmp_gid, sizeof(gid_t), 0, 0) > 0) {
875 stbuf->st_gid = le32_to_cpu(tmp_gid);
877 if (fgetxattr(fd, "user.virtfs.mode",
878 &tmp_mode, sizeof(mode_t), 0, 0) > 0) {
879 stbuf->st_mode = le32_to_cpu(tmp_mode);
881 if (fgetxattr(fd, "user.virtfs.rdev",
882 &tmp_dev, sizeof(dev_t), 0, 0) > 0) {
883 stbuf->st_rdev = le64_to_cpu(tmp_dev);
887 } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
894 static int local_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name,
895 int flags, FsCred *credp, V9fsFidOpenState *fs)
897 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
906 * Mark all the open to not follow symlinks
910 v9fs_string_init(&fullname);
912 v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name);
914 v9fs_string_sprintf(&fullname, "%s\\%s", dir_path->data, name);
917 path = fullname.data;
919 /* Determine the security model */
920 if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
921 buffer = rpath(fs_ctx, path);
922 fd = open(buffer, flags, SM_LOCAL_MODE_BITS);
928 credp->fc_mode = credp->fc_mode|S_IFREG;
929 /* Set cleint credentials in xattr */
930 err = local_set_xattr(buffer, credp);
936 } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
937 buffer = rpath(fs_ctx, path);
938 fd = open(buffer, flags, SM_LOCAL_MODE_BITS);
943 credp->fc_mode = credp->fc_mode|S_IFREG;
944 /* Set client credentials in .virtfs_metadata directory files */
945 err = local_set_mapped_file_attr(fs_ctx, path, credp);
950 } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
951 (fs_ctx->export_flags & V9FS_SM_NONE)) {
952 buffer = rpath(fs_ctx, path);
953 fd = open(buffer, flags, credp->fc_mode);
958 err = local_post_create_passthrough(fs_ctx, path, credp);
974 v9fs_string_free(&fullname);
979 static int local_symlink(FsContext *fs_ctx, const char *oldpath,
980 V9fsPath *dir_path, const char *name, FsCred *credp)
982 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
990 v9fs_string_init(&fullname);
991 v9fs_string_sprintf(&fullname, "%s/%s", dir_path->data, name);
992 newpath = fullname.data;
994 /* Determine the security model */
995 if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
997 ssize_t oldpath_size, write_size;
998 buffer = rpath(fs_ctx, newpath);
999 fd = open(buffer, O_CREAT|O_EXCL|O_RDWR|O_NOFOLLOW, SM_LOCAL_MODE_BITS);
1004 /* Write the oldpath (target) to the file. */
1005 oldpath_size = strlen(oldpath);
1007 write_size = write(fd, (void *)oldpath, oldpath_size);
1008 } while (write_size == -1 && errno == EINTR);
1010 if (write_size != oldpath_size) {
1017 /* Set cleint credentials in symlink's xattr */
1018 credp->fc_mode = credp->fc_mode|S_IFLNK;
1019 err = local_set_xattr(buffer, credp);
1024 } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
1026 ssize_t oldpath_size, write_size;
1027 buffer = rpath(fs_ctx, newpath);
1028 fd = open(buffer, O_CREAT|O_EXCL|O_RDWR|O_NOFOLLOW, SM_LOCAL_MODE_BITS);
1033 /* Write the oldpath (target) to the file. */
1034 oldpath_size = strlen(oldpath);
1036 write_size = write(fd, (void *)oldpath, oldpath_size);
1037 } while (write_size == -1 && errno == EINTR);
1039 if (write_size != oldpath_size) {
1046 /* Set cleint credentials in symlink's xattr */
1047 credp->fc_mode = credp->fc_mode|S_IFLNK;
1048 err = local_set_mapped_file_attr(fs_ctx, newpath, credp);
1053 } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
1054 (fs_ctx->export_flags & V9FS_SM_NONE)) {
1055 buffer = rpath(fs_ctx, newpath);
1056 err = symlink(oldpath, buffer);
1060 err = lchown(buffer, credp->fc_uid, credp->fc_gid);
1063 * If we fail to change ownership and if we are
1064 * using security model none. Ignore the error
1066 if ((fs_ctx->export_flags & V9FS_SEC_MASK) != V9FS_SM_NONE) {
1080 v9fs_string_free(&fullname);
1085 static int local_link(FsContext *ctx, V9fsPath *oldpath,
1086 V9fsPath *dirpath, const char *name)
1088 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
1089 #ifndef CONFIG_WIN32
1092 char *buffer, *buffer1;
1094 v9fs_string_init(&newpath);
1095 v9fs_string_sprintf(&newpath, "%s/%s", dirpath->data, name);
1097 buffer = rpath(ctx, oldpath->data);
1098 buffer1 = rpath(ctx, newpath.data);
1099 ret = link(buffer, buffer1);
1103 /* now link the virtfs_metadata files */
1104 if (!ret && (ctx->export_flags & V9FS_SM_MAPPED_FILE)) {
1105 /* Link the .virtfs_metadata files. Create the metada directory */
1106 ret = local_create_mapped_attr_dir(ctx, newpath.data);
1110 buffer = local_mapped_attr_path(ctx, oldpath->data);
1111 buffer1 = local_mapped_attr_path(ctx, newpath.data);
1112 ret = link(buffer, buffer1);
1115 if (ret < 0 && errno != ENOENT) {
1120 v9fs_string_free(&newpath);
1127 static int local_truncate(FsContext *ctx, V9fsPath *fs_path, off_t size)
1129 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
1132 char *path = fs_path->data;
1134 buffer = rpath(ctx, path);
1135 #ifndef CONFIG_WIN32
1136 ret = truncate(buffer, size);
1138 int fd = open(buffer, O_RDWR | O_BINARY | O_NOFOLLOW);
1142 ret = ftruncate(fd, size);
1150 static int local_rename(FsContext *ctx, const char *oldpath,
1151 const char *newpath)
1153 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
1155 char *buffer, *buffer1;
1157 if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
1158 err = local_create_mapped_attr_dir(ctx, newpath);
1162 /* rename the .virtfs_metadata files */
1163 buffer = local_mapped_attr_path(ctx, oldpath);
1164 buffer1 = local_mapped_attr_path(ctx, newpath);
1165 err = rename(buffer, buffer1);
1168 if (err < 0 && errno != ENOENT) {
1173 buffer = rpath(ctx, oldpath);
1174 buffer1 = rpath(ctx, newpath);
1175 #ifndef CONFIG_WIN32
1176 err = rename(buffer, buffer1);
1181 if (!MoveFileEx((LPCTSTR)buffer,
1182 (LPCTSTR)buffer1, MOVEFILE_REPLACE_EXISTING)){
1183 err = -(GetLastError());
1184 LOG_SEVERE("[%d][ >> %s] err: %d\n", __LINE__, __func__, err);
1194 static int local_chown(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp)
1196 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
1197 #ifndef CONFIG_WIN32
1200 char *path = fs_path->data;
1202 if ((credp->fc_uid == -1 && credp->fc_gid == -1) ||
1203 (fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
1204 (fs_ctx->export_flags & V9FS_SM_NONE)) {
1205 buffer = rpath(fs_ctx, path);
1206 ret = lchown(buffer, credp->fc_uid, credp->fc_gid);
1208 } else if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
1209 buffer = rpath(fs_ctx, path);
1210 ret = local_set_xattr(buffer, credp);
1212 } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
1213 return local_set_mapped_file_attr(fs_ctx, path, credp);
1221 /* The function that change file last access and modification times for WIN32 */
1222 static int win_utimes (const char *filename, const struct timeval tv[2])
1224 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
1226 FILETIME LastAccessTime, LastWriteTime;
1228 ULARGE_INTEGER tmpTime;
1230 ULONGLONG WindowsUnixTimeGap = 11644473600; // between 1601.01.01 and 1970.01.01
1231 ULONGLONG WindowsSecond = 10000000; // 1sec / 100nanosec
1235 HANDLE hFile = CreateFile(filename, FILE_WRITE_ATTRIBUTES,
1236 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
1237 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL);
1238 if (hFile == INVALID_HANDLE_VALUE) {
1239 if (GetFileAttributes(filename) & FILE_ATTRIBUTE_DIRECTORY) {
1246 if (!tv) { // case of NULL
1247 GetSystemTimeAsFileTime(&LastAccessTime);
1248 LastWriteTime = LastAccessTime;
1250 tmpTime.QuadPart = UInt32x32To64(WindowsUnixTimeGap + tv[0].tv_sec, WindowsSecond)
1251 + tv[0].tv_usec * 10;
1252 LastAccessTime.dwHighDateTime = tmpTime.HighPart;
1253 LastAccessTime.dwLowDateTime = tmpTime.LowPart;
1255 tmpTime.QuadPart = UInt32x32To64(WindowsUnixTimeGap + tv[1].tv_sec, WindowsSecond)
1256 + tv[1].tv_usec * 10;
1257 LastWriteTime.dwHighDateTime = tmpTime.HighPart;
1258 LastWriteTime.dwLowDateTime = tmpTime.LowPart;
1260 if (!SetFileTime(hFile, NULL, &LastAccessTime, &LastWriteTime)) {
1274 static int local_utimensat(FsContext *s, V9fsPath *fs_path,
1275 const struct timespec *buf)
1277 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
1279 char *path = fs_path->data;
1281 buffer = rpath(s, path);
1282 #ifndef CONFIG_WIN32
1284 ret = qemu_utimens(buffer, buf);
1288 const char * r_path = buffer;
1289 struct timeval tv[2], tv_now;
1293 /* happy if special cases */
1294 if (buf[0].tv_nsec == UTIME_OMIT && buf[1].tv_nsec == UTIME_OMIT) {
1297 if (buf[0].tv_nsec == UTIME_NOW && buf[1].tv_nsec == UTIME_NOW) {
1298 return win_utimes(r_path, NULL);
1301 /* prepare for hard cases */
1302 if (buf[0].tv_nsec == UTIME_NOW || buf[1].tv_nsec == UTIME_NOW) {
1303 gettimeofday(&tv_now, NULL);
1305 if (buf[0].tv_nsec == UTIME_OMIT || buf[1].tv_nsec == UTIME_OMIT) {
1309 for (i = 0; i < 2; i++) {
1310 if (buf[i].tv_nsec == UTIME_NOW) {
1311 tv[i].tv_sec = tv_now.tv_sec;
1312 tv[i].tv_usec = tv_now.tv_usec;
1313 } else if (buf[i].tv_nsec == UTIME_OMIT) {
1314 tv[i].tv_sec = (i == 0) ? st.st_atime : st.st_mtime;
1317 tv[i].tv_sec = buf[i].tv_sec;
1318 tv[i].tv_usec = buf[i].tv_nsec / 1000;
1322 return win_utimes(r_path, &tv[0]);
1326 static int local_remove(FsContext *ctx, const char *path)
1328 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
1333 if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
1334 buffer = rpath(ctx, path);
1335 #ifndef CONFIG_WIN32
1336 err = lstat(buffer, &stbuf);
1338 err = stat(buffer, &stbuf);
1345 * If directory remove .virtfs_metadata contained in the
1348 if (S_ISDIR(stbuf.st_mode)) {
1349 #ifndef CONFIG_WIN32
1350 buffer = g_strdup_printf("%s/%s/%s", ctx->fs_root,
1351 path, VIRTFS_META_DIR);
1353 buffer = g_strdup_printf("%s\\%s\\%s", ctx->fs_root,
1354 path, VIRTFS_META_DIR);
1356 err = remove(buffer);
1358 if (err < 0 && errno != ENOENT) {
1360 * We didn't had the .virtfs_metadata file. May be file created
1361 * in non-mapped mode ?. Ignore ENOENT.
1367 * Now remove the name from parent directory
1368 * .virtfs_metadata directory
1370 buffer = local_mapped_attr_path(ctx, path);
1371 err = remove(buffer);
1373 if (err < 0 && errno != ENOENT) {
1375 * We didn't had the .virtfs_metadata file. May be file created
1376 * in non-mapped mode ?. Ignore ENOENT.
1382 buffer = rpath(ctx, path);
1383 err = remove(buffer);
1389 static int local_fsync(FsContext *ctx, int fid_type,
1390 V9fsFidOpenState *fs, int datasync)
1392 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
1395 if (fid_type == P9_FID_DIR) {
1396 #ifndef CONFIG_WIN32
1397 fd = dirfd(fs->dir);
1405 #ifndef CONFIG_WIN32
1407 return qemu_fdatasync(fd);
1416 static int local_statfs(FsContext *s, V9fsPath *fs_path, struct statfs *stbuf)
1418 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
1420 char *path = fs_path->data;
1422 buffer = rpath(s, path);
1423 LOG_TRACE("[%d][%s] statfs(%s)\n", __LINE__, __func__, buffer);
1424 #ifndef CONFIG_WIN32
1426 ret = statfs(buffer, stbuf);
1430 DWORD VolumeSerialNumber,
1431 MaximumComponentLength,
1434 DWORD SectorsPerCluster,
1436 NumberOfFreeClusters,
1437 TotalNumberOfClusters,
1440 ULARGE_INTEGER TotalNumberOfBytes,
1441 TotalNumberOfFreeBytes,
1442 FreeBytesAvailableToCaller;
1444 TCHAR tmpName[PATH_MAX] = {0};
1445 TCHAR VolumeNameBuffer[PATH_MAX] = {0};
1446 TCHAR FileSystemNameBuffer[PATH_MAX] = {0};
1448 strncpy(tmpName, buffer, 3 > PATH_MAX ? PATH_MAX : 3);
1449 tmpName[4 > PATH_MAX ? PATH_MAX : 4] = '\0';
1450 LPCTSTR RootPathName = (LPCTSTR)tmpName;
1453 if (RootPathName == NULL) {
1454 LOG_SEVERE("[%d][%s] >> err = %d\n", __LINE__, __func__, GetLastError());
1459 if (!GetVolumeInformation(RootPathName, (LPTSTR)&VolumeNameBuffer, PATH_MAX,
1460 &VolumeSerialNumber, &MaximumComponentLength, &FileSystemFlags,
1461 (LPTSTR)&FileSystemNameBuffer, PATH_MAX)) {
1462 LOG_SEVERE("[%d][%s] >> err = %d\n", __LINE__, __func__, GetLastError());
1466 if (!GetDiskFreeSpace(RootPathName, &SectorsPerCluster, &BytesPerSector,
1467 &NumberOfFreeClusters, &TotalNumberOfClusters)) {
1468 SectorsPerCluster = 1;
1470 NumberOfFreeClusters = 0;
1471 TotalNumberOfClusters = 0;
1474 BytesPerCluster = SectorsPerCluster * BytesPerSector;
1475 TotalNumberOfBytes.QuadPart = Int32x32To64(TotalNumberOfClusters, BytesPerCluster);
1476 TotalNumberOfFreeBytes.QuadPart = Int32x32To64(NumberOfFreeClusters, BytesPerCluster);
1477 FreeBytesAvailableToCaller=TotalNumberOfFreeBytes;
1479 if (!strcmp(FileSystemNameBuffer, "NTFS")) {
1480 stbuf->f_type = NTFS_SUPER_MAGIC;
1482 /* need to check more about other filesystems (ex CD) */
1484 stbuf->f_type = MSDOS_SUPER_MAGIC;
1486 stbuf->f_bsize = BytesPerSector;
1487 stbuf->f_blocks = TotalNumberOfBytes.QuadPart / BytesPerSector;
1488 stbuf->f_bfree = TotalNumberOfFreeBytes.QuadPart / BytesPerSector;
1489 stbuf->f_bavail = FreeBytesAvailableToCaller.QuadPart / BytesPerSector;
1490 stbuf->f_files = stbuf->f_blocks / SectorsPerCluster;
1491 stbuf->f_ffree = stbuf->f_bfree / SectorsPerCluster;
1492 stbuf->f_fsid.val[0] = HIWORD(VolumeSerialNumber);
1493 stbuf->f_fsid.val[1] = LOWORD(VolumeSerialNumber);
1494 stbuf->f_namelen = MaximumComponentLength;
1495 stbuf->f_spare[0] = 0;
1496 stbuf->f_spare[1] = 0;
1497 stbuf->f_spare[2] = 0;
1498 stbuf->f_spare[3] = 0;
1499 stbuf->f_spare[4] = 0;
1500 stbuf->f_spare[5] = 0;
1506 static ssize_t local_lgetxattr(FsContext *ctx, V9fsPath *fs_path,
1507 const char *name, void *value, size_t size)
1509 #ifndef CONFIG_WIN32
1510 char *path = fs_path->data;
1512 return v9fs_get_xattr(ctx, path, name, value, size);
1514 /* xattr doesn't support on Windows */
1519 static ssize_t local_llistxattr(FsContext *ctx, V9fsPath *fs_path,
1520 void *value, size_t size)
1522 #ifndef CONFIG_WIN32
1523 char *path = fs_path->data;
1525 return v9fs_list_xattr(ctx, path, value, size);
1527 /* xattr doesn't support on Windows */
1532 static int local_lsetxattr(FsContext *ctx, V9fsPath *fs_path, const char *name,
1533 void *value, size_t size, int flags)
1535 #ifndef CONFIG_WIN32
1536 char *path = fs_path->data;
1538 return v9fs_set_xattr(ctx, path, name, value, size, flags);
1540 /* xattr doesn't support on Windows */
1545 static int local_lremovexattr(FsContext *ctx, V9fsPath *fs_path,
1548 #ifndef CONFIG_WIN32
1549 char *path = fs_path->data;
1551 return v9fs_remove_xattr(ctx, path, name);
1553 /* xattr doesn't support on Windows */
1558 static int local_name_to_path(FsContext *ctx, V9fsPath *dir_path,
1559 const char *name, V9fsPath *target)
1561 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
1563 #ifndef CONFIG_WIN32
1564 v9fs_string_sprintf((V9fsString *)target, "%s/%s",
1565 dir_path->data, name);
1567 v9fs_string_sprintf((V9fsString *)target, "%s\\%s",
1568 dir_path->data, name);
1569 while((target->data)[strlen(target->data)-1] == '\\'){
1570 (target->data)[strlen(target->data)-1] = '\0';
1574 v9fs_string_sprintf((V9fsString *)target, "%s", name);
1576 /* Bump the size for including terminating NULL */
1581 static int local_renameat(FsContext *ctx, V9fsPath *olddir,
1582 const char *old_name, V9fsPath *newdir,
1583 const char *new_name)
1585 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
1587 V9fsString old_full_name, new_full_name;
1589 v9fs_string_init(&old_full_name);
1590 v9fs_string_init(&new_full_name);
1592 #ifndef CONFIG_WIN32
1593 v9fs_string_sprintf(&old_full_name, "%s/%s", olddir->data, old_name);
1594 v9fs_string_sprintf(&new_full_name, "%s/%s", newdir->data, new_name);
1596 v9fs_string_sprintf(&old_full_name, "%s\\%s", olddir->data, old_name);
1597 v9fs_string_sprintf(&new_full_name, "%s\\%s", newdir->data, new_name);
1600 ret = local_rename(ctx, old_full_name.data, new_full_name.data);
1601 v9fs_string_free(&old_full_name);
1602 v9fs_string_free(&new_full_name);
1606 static int local_unlinkat(FsContext *ctx, V9fsPath *dir,
1607 const char *name, int flags)
1609 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
1611 V9fsString fullname;
1614 v9fs_string_init(&fullname);
1616 #ifndef CONFIG_WIN32
1617 v9fs_string_sprintf(&fullname, "%s/%s", dir->data, name);
1619 v9fs_string_sprintf(&fullname, "%s\\%s", dir->data, name);
1620 while(fullname.data[strlen(fullname.data)-1] == '\\'){
1621 fullname.data[strlen(fullname.data)-1] = '\0';
1624 if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
1625 #ifdef CONFIG_VIRTFS_DARWIN
1626 if (flags == AT_REMOVEDIR) {
1628 * If directory remove .virtfs_metadata contained in the
1631 #ifndef CONFIG_WIN32
1632 buffer = g_strdup_printf("%s/%s/%s", ctx->fs_root,
1633 fullname.data, VIRTFS_META_DIR);
1635 buffer = g_strdup_printf("%s\\%s\\%s", ctx->fs_root,
1636 fullname.data, VIRTFS_META_DIR);
1638 ret = remove(buffer);
1640 if (ret < 0 && errno != ENOENT) {
1642 * We didn't had the .virtfs_metadata file. May be file created
1643 * in non-mapped mode ?. Ignore ENOENT.
1650 * Now remove the name from parent directory
1651 * .virtfs_metadata directory.
1653 buffer = local_mapped_attr_path(ctx, fullname.data);
1654 ret = remove(buffer);
1656 if (ret < 0 && errno != ENOENT) {
1658 * We didn't had the .virtfs_metadata file. May be file created
1659 * in non-mapped mode ?. Ignore ENOENT.
1664 /* Remove the name finally */
1665 buffer = rpath(ctx, fullname.data);
1666 #ifndef CONFIG_WIN32
1667 ret = remove(buffer);
1669 if (flags == AT_REMOVEDIR) { // is dir
1670 ret = rmdir(buffer);
1672 ret = remove(buffer);
1678 v9fs_string_free(&fullname);
1682 #ifdef FS_IOC_GETVERSION
1683 static int local_ioc_getversion(FsContext *ctx, V9fsPath *path,
1684 mode_t st_mode, uint64_t *st_gen)
1686 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
1687 #ifndef CONFIG_WIN32
1690 V9fsFidOpenState fid_open;
1693 * Do not try to open special files like device nodes, fifos etc
1694 * We can get fd for regular files and directories only
1696 if (!S_ISREG(st_mode) && !S_ISDIR(st_mode)) {
1700 err = local_open(ctx, path, O_RDONLY, &fid_open);
1704 err = ioctl(fid_open.fd, FS_IOC_GETVERSION, st_gen);
1705 local_close(ctx, &fid_open);
1714 static int local_init(FsContext *ctx)
1716 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
1718 #ifdef FS_IOC_GETVERSION
1719 struct statfs stbuf;
1722 #ifndef CONFIG_WIN32
1723 if (ctx->export_flags & V9FS_SM_PASSTHROUGH) {
1724 ctx->xops = passthrough_xattr_ops;
1725 } else if (ctx->export_flags & V9FS_SM_MAPPED) {
1726 ctx->xops = mapped_xattr_ops;
1727 } else if (ctx->export_flags & V9FS_SM_NONE) {
1728 ctx->xops = none_xattr_ops;
1729 } else if (ctx->export_flags & V9FS_SM_MAPPED_FILE) {
1731 * xattr operation for mapped-file and passthrough
1734 ctx->xops = passthrough_xattr_ops;
1739 ctx->export_flags |= V9FS_PATHNAME_FSCONTEXT;
1740 #ifdef FS_IOC_GETVERSION
1742 * use ioc_getversion only if the iocl is definied
1744 err = statfs(ctx->fs_root, &stbuf);
1746 switch (stbuf.f_type) {
1747 case EXT2_SUPER_MAGIC:
1748 case BTRFS_SUPER_MAGIC:
1749 case REISERFS_SUPER_MAGIC:
1750 case XFS_SUPER_MAGIC:
1751 ctx->exops.get_st_gen = local_ioc_getversion;
1759 static int local_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse)
1761 LOG_TRACE("[%d][ Enter >> %s]\n", __LINE__, __func__);
1762 const char *sec_model = qemu_opt_get(opts, "security_model");
1763 const char *path = qemu_opt_get(opts, "path");
1766 error_report("Security model not specified, local fs needs security model");
1767 error_printf("valid options are:"
1768 "\tsecurity_model=[passthrough|mapped-xattr|mapped-file|none]\n");
1772 if (!strcmp(sec_model, "passthrough")) {
1773 fse->export_flags |= V9FS_SM_PASSTHROUGH;
1774 } else if (!strcmp(sec_model, "mapped") ||
1775 !strcmp(sec_model, "mapped-xattr")) {
1776 fse->export_flags |= V9FS_SM_MAPPED;
1777 } else if (!strcmp(sec_model, "none")) {
1778 fse->export_flags |= V9FS_SM_NONE;
1779 } else if (!strcmp(sec_model, "mapped-file")) {
1780 fse->export_flags |= V9FS_SM_MAPPED_FILE;
1782 error_report("Invalid security model %s specified", sec_model);
1783 error_printf("valid options are:"
1784 "\t[passthrough|mapped-xattr|mapped-file|none]\n");
1789 error_report("fsdev: No path specified");
1792 fse->path = g_strdup(path);
1797 FileOperations local_ops = {
1798 .parse_opts = local_parse_opts,
1800 .lstat = local_lstat,
1801 .readlink = local_readlink,
1802 .close = local_close,
1803 .closedir = local_closedir,
1805 .opendir = local_opendir,
1806 .rewinddir = local_rewinddir,
1807 .telldir = local_telldir,
1808 .readdir_r = local_readdir_r,
1809 .seekdir = local_seekdir,
1810 .preadv = local_preadv,
1811 .pwritev = local_pwritev,
1812 .chmod = local_chmod,
1813 .mknod = local_mknod,
1814 .mkdir = local_mkdir,
1815 .fstat = local_fstat,
1816 .open2 = local_open2,
1817 .symlink = local_symlink,
1819 .truncate = local_truncate,
1820 .rename = local_rename,
1821 .chown = local_chown,
1822 .utimensat = local_utimensat,
1823 .remove = local_remove,
1824 .fsync = local_fsync,
1825 .statfs = local_statfs,
1826 .lgetxattr = local_lgetxattr,
1827 .llistxattr = local_llistxattr,
1828 .lsetxattr = local_lsetxattr,
1829 .lremovexattr = local_lremovexattr,
1830 .name_to_path = local_name_to_path,
1831 .renameat = local_renameat,
1832 .unlinkat = local_unlinkat,