From: Kitae Kim Date: Thu, 12 Dec 2013 06:02:42 +0000 (+0900) Subject: virtio-9p: fix compiliation error and source clean-up. X-Git-Tag: Tizen_Studio_1.3_Release_p2.3.1~394^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=170164b00b2c291f1f3bee989af3d9f43e557d8d;p=sdk%2Femulator%2Fqemu.git virtio-9p: fix compiliation error and source clean-up. The previous commit comes from qemu 1.2 version. This commit resolves compiliation errors and clean sources up. Change-Id: I5463b08aaccaa40a431dd7ee965bcf6d0faf3c01 Signed-off-by: Kitae Kim --- diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h index 75ad11f91a..339113066d 100644 --- a/fsdev/file-op-9p.h +++ b/fsdev/file-op-9p.h @@ -18,7 +18,6 @@ #include #include #include -#include #ifdef CONFIG_LINUX #include #endif diff --git a/fsdev/qemu-fsdev.c b/fsdev/qemu-fsdev.c index ccfec139ab..b54adceb40 100644 --- a/fsdev/qemu-fsdev.c +++ b/fsdev/qemu-fsdev.c @@ -26,8 +26,10 @@ static FsDriverTable FsDrivers[] = { #ifdef CONFIG_OPEN_BY_HANDLE { .name = "handle", .ops = &handle_ops}, #endif +#ifdef CONFIG_LINUX { .name = "synth", .ops = &synth_ops}, { .name = "proxy", .ops = &proxy_ops}, +#endif }; int qemu_fsdev_add(QemuOpts *opts) diff --git a/hw/9pfs/virtio-9p-local.c b/hw/9pfs/virtio-9p-local.c index 24e2cdaead..3b4967777c 100644 --- a/hw/9pfs/virtio-9p-local.c +++ b/hw/9pfs/virtio-9p-local.c @@ -44,6 +44,10 @@ #define VIRTFS_META_DIR ".virtfs_metadata" +#ifdef CONFIG_DARWIN +#define AT_REMOVEDIR 0x200 +#endif + static const char *local_mapped_attr_path(FsContext *ctx, const char *path, char *buffer) { @@ -151,22 +155,30 @@ static int local_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf) stbuf->st_rdev = tmp_dev; } #else - if (getxattr(rpath(fs_ctx, path, 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, - sizeof(gid_t), 0, 0) > 0) { - stbuf->st_gid = tmp_gid; - } - if (getxattr(rpath(fs_ctx, path, 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, - sizeof(dev_t)) > 0) { - stbuf->st_rdev = tmp_dev; - } + /* + * extra two parameters on Mac OS X. + * first one is position which specifies an offset within the extended attribute. + * i.e. extended attribute means "user.virtfs.uid". Currently, it is only used with + * resource fork attribute and all other extended attributes, it is reserved and should be zero. + * 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, + sizeof(uid_t), 0, 0) > 0) { + stbuf->st_uid = tmp_uid; + } + if (getxattr(rpath(fs_ctx, path, 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", + &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, + sizeof(dev_t), 0, 0) > 0) { + stbuf->st_rdev = tmp_dev; + } #endif } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) { local_mapped_file_attr(fs_ctx, path, stbuf); @@ -269,50 +281,72 @@ static int local_set_xattr(const char *path, FsCred *credp) { int err; +#ifdef CONFIG_LINUX if (credp->fc_uid != -1) { err = setxattr(path, "user.virtfs.uid", &credp->fc_uid, sizeof(uid_t), -#ifdef CONFIG_LINUX 0); -#else - 0, 0); -#endif if (err) { return err; } } if (credp->fc_gid != -1) { err = setxattr(path, "user.virtfs.gid", &credp->fc_gid, sizeof(gid_t), -#ifdef CONFIG_LINUX 0); -#else - 0, 0); -#endif if (err) { return err; } } if (credp->fc_mode != -1) { err = setxattr(path, "user.virtfs.mode", &credp->fc_mode, -#ifdef CONFIG_LINUX sizeof(mode_t), 0); -#else - sizeof(mode_t), 0, 0); -#endif if (err) { return err; } } if (credp->fc_rdev != -1) { err = setxattr(path, "user.virtfs.rdev", &credp->fc_rdev, -#ifdef CONFIG_LINUX sizeof(dev_t), 0); + if (err) { + return err; + } + } #else - sizeof(dev_t), 0, 0); -#endif + /* + * In case of setxattr on OS X, position parameter has been added. + * Its purpose is the same as getxattr. Last parameter options is the same as flags on Linux. + * XATTR_NOFOLLOW / XATTR_CREATE / XATTR_REPLACE + */ + if (credp->fc_uid != -1) { + err = setxattr(path, "user.virtfs.uid", &credp->fc_uid, sizeof(uid_t), + 0, 0); if (err) { return err; } } + if (credp->fc_gid != -1) { + err = setxattr(path, "user.virtfs.gid", &credp->fc_gid, sizeof(gid_t), + 0, 0); + if (err) { + return err; + } + } + if (credp->fc_mode != -1) { + err = setxattr(path, "user.virtfs.mode", &credp->fc_mode, + sizeof(mode_t), 0, 0); + if (err) { + return err; + } + } + if (credp->fc_rdev != -1) { + err = setxattr(path, "user.virtfs.rdev", &credp->fc_rdev, + sizeof(dev_t), 0, 0); + if (err) { + return err; + } + } + +#endif + return 0; } @@ -1151,7 +1185,9 @@ static int local_ioc_getversion(FsContext *ctx, V9fsPath *path, static int local_init(FsContext *ctx) { int err = 0; +#ifdef FS_IOC_GETVERSION struct statfs stbuf; +#endif if (ctx->export_flags & V9FS_SM_PASSTHROUGH) { ctx->xops = passthrough_xattr_ops; diff --git a/hw/9pfs/virtio-9p-posix-acl.c b/hw/9pfs/virtio-9p-posix-acl.c index 7b979b87bd..4c74721ad7 100644 --- a/hw/9pfs/virtio-9p-posix-acl.c +++ b/hw/9pfs/virtio-9p-posix-acl.c @@ -26,11 +26,11 @@ static ssize_t mp_pacl_getxattr(FsContext *ctx, const char *path, const char *name, void *value, size_t size) { -#ifdef CONFIG_LINUX char buffer[PATH_MAX]; +#ifdef CONFIG_LINUX return lgetxattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS, value, size); #else - return 0; + return getxattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS, value, size, 0, XATTR_NOFOLLOW); #endif } @@ -56,21 +56,22 @@ static ssize_t mp_pacl_listxattr(FsContext *ctx, const char *path, static int mp_pacl_setxattr(FsContext *ctx, const char *path, const char *name, void *value, size_t size, int flags) { -#ifdef CONFIG_LINUX char buffer[PATH_MAX]; +#ifdef CONFIG_LINUX return lsetxattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS, value, size, flags); #else - return 0; + return setxattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS, value, + size, 0, flags | XATTR_NOFOLLOW); #endif } static int mp_pacl_removexattr(FsContext *ctx, const char *path, const char *name) { -#ifdef CONFIG_LINUX int ret; char buffer[PATH_MAX]; +#ifdef CONFIG_LINUX ret = lremovexattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS); if (ret == -1 && errno == ENODATA) { /* @@ -81,20 +82,29 @@ static int mp_pacl_removexattr(FsContext *ctx, errno = 0; ret = 0; } - return ret; #else - return 0; + ret = removexattr(rpath(ctx, path, buffer), MAP_ACL_ACCESS, XATTR_NOFOLLOW); + if (ret == -1 && errno == ENODATA) { + /* + * We don't get ENODATA error when trying to remove a + * posix acl that is not present. So don't throw the error + * even in case of mapped security model + */ + errno = 0; + ret = 0; + } #endif + return ret; } static ssize_t mp_dacl_getxattr(FsContext *ctx, const char *path, const char *name, void *value, size_t size) { -#ifdef CONFIG_LINUX char buffer[PATH_MAX]; +#ifdef CONFIG_LINUX return lgetxattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT, value, size); #else - return 0; + return getxattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT, value, size, 0, XATTR_NOFOLLOW); #endif } @@ -120,21 +130,22 @@ static ssize_t mp_dacl_listxattr(FsContext *ctx, const char *path, static int mp_dacl_setxattr(FsContext *ctx, const char *path, const char *name, void *value, size_t size, int flags) { -#ifdef CONFIG_LINUX char buffer[PATH_MAX]; +#ifdef CONFIG_LINUX return lsetxattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT, value, size, flags); #else - return 0; + return setxattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT, value, + size, 0, flags | XATTR_NOFOLLOW); #endif } static int mp_dacl_removexattr(FsContext *ctx, const char *path, const char *name) { -#ifdef CONFIG_LINUX int ret; char buffer[PATH_MAX]; +#ifdef CONFIG_LINUX ret = lremovexattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT); if (ret == -1 && errno == ENODATA) { /* @@ -145,10 +156,20 @@ static int mp_dacl_removexattr(FsContext *ctx, errno = 0; ret = 0; } - return ret; #else - return 0; + ret = removexattr(rpath(ctx, path, buffer), MAP_ACL_DEFAULT, XATTR_NOFOLLOW); + if (ret == -1 && errno == ENODATA) { + /* + * We don't get ENODATA error when trying to remove a + * posix acl that is not present. So don't throw the error + * even in case of mapped security model + */ + errno = 0; + ret = 0; + } #endif + + return ret; } diff --git a/hw/9pfs/virtio-9p-xattr-user.c b/hw/9pfs/virtio-9p-xattr-user.c index c5d1f47b7e..f22fac1129 100644 --- a/hw/9pfs/virtio-9p-xattr-user.c +++ b/hw/9pfs/virtio-9p-xattr-user.c @@ -33,7 +33,7 @@ static ssize_t mp_user_getxattr(FsContext *ctx, const char *path, #ifdef CONFIG_LINUX return lgetxattr(rpath(ctx, path, buffer), name, value, size); #else - return getxattr(rpath(ctx, path, buffer), name, value, size, 0, XATTR_NOFOLLOW); + return getxattr(rpath(ctx, path, buffer), name, value, size, 0, XATTR_NOFOLLOW); #endif } @@ -85,7 +85,7 @@ static int mp_user_setxattr(FsContext *ctx, const char *path, const char *name, #ifdef CONFIG_LINUX return lsetxattr(rpath(ctx, path, buffer), name, value, size, flags); #else - return setxattr(rpath(ctx, path, buffer), name, value, size, 0, flags | XATTR_NOFOLLOW); + return setxattr(rpath(ctx, path, buffer), name, value, size, 0, flags | XATTR_NOFOLLOW); #endif } @@ -104,7 +104,7 @@ static int mp_user_removexattr(FsContext *ctx, #ifdef CONFIG_LINUX return lremovexattr(rpath(ctx, path, buffer), name); #else - return removexattr(rpath(ctx, path, buffer), name, XATTR_NOFOLLOW); + return removexattr(rpath(ctx, path, buffer), name, XATTR_NOFOLLOW); #endif } diff --git a/hw/9pfs/virtio-9p-xattr.c b/hw/9pfs/virtio-9p-xattr.c index 29e228816c..3018bae9b7 100644 --- a/hw/9pfs/virtio-9p-xattr.c +++ b/hw/9pfs/virtio-9p-xattr.c @@ -77,7 +77,7 @@ ssize_t v9fs_list_xattr(FsContext *ctx, const char *path, #ifdef CONFIG_LINUX xattr_len = llistxattr(rpath(ctx, path, buffer), value, 0); #else - xattr_len = listxattr(rpath(ctx, path, buffer), value, 0, XATTR_NOFOLLOW); + xattr_len = listxattr(rpath(ctx, path, buffer), value, 0, XATTR_NOFOLLOW); #endif if (xattr_len <= 0) { return xattr_len; @@ -88,7 +88,7 @@ ssize_t v9fs_list_xattr(FsContext *ctx, const char *path, #ifdef CONFIG_LINUX xattr_len = llistxattr(rpath(ctx, path, buffer), orig_value, xattr_len); #else - xattr_len = listxattr(rpath(ctx, path, buffer), orig_value, xattr_len, XATTR_NOFOLLOW); + xattr_len = listxattr(rpath(ctx, path, buffer), orig_value, xattr_len, XATTR_NOFOLLOW); #endif /* store the orig pointer */ diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c index ba5a174b45..dfc773836b 100644 --- a/hw/9pfs/virtio-9p.c +++ b/hw/9pfs/virtio-9p.c @@ -867,7 +867,7 @@ static void stat_to_v9stat_dotl(V9fsState *s, const struct stat *stbuf, v9lstat->st_ctime_sec = stbuf->st_ctime; v9lstat->st_ctime_nsec = stbuf->st_ctim.tv_nsec; #else // darwin - v9lstat->st_atime_sec = stbuf->st_atimespec.tv_sec; + v9lstat->st_atime_sec = stbuf->st_atimespec.tv_sec; v9lstat->st_atime_nsec = stbuf->st_atimespec.tv_nsec; v9lstat->st_mtime_sec = stbuf->st_mtimespec.tv_sec; v9lstat->st_mtime_nsec = stbuf->st_mtimespec.tv_nsec; @@ -1612,6 +1612,10 @@ static int v9fs_do_readdir_with_stat(V9fsPDU *pdu, dent = g_malloc(sizeof(struct dirent)); while (1) { +#ifndef CONFIG_LINUX + uint64_t d_offset = 0; + d_offset = v9fs_co_telldir(pdu, fidp); +#endif v9fs_path_init(&path); err = v9fs_co_readdir_r(pdu, fidp, dent, &result); if (err || !result) { @@ -1642,7 +1646,11 @@ static int v9fs_do_readdir_with_stat(V9fsPDU *pdu, count += len; v9fs_stat_free(&v9stat); v9fs_path_free(&path); +#ifdef CONFIG_LINUX saved_dir_pos = dent->d_off; +#else + saved_dir_pos = d_offset; +#endif } out: g_free(dent); @@ -1798,16 +1806,16 @@ static int v9fs_do_readdir(V9fsPDU *pdu, dent = g_malloc(sizeof(struct dirent)); while (1) { +#ifndef CONFIG_LINUX + uint64_t d_offset = 0; + d_offset = v9fs_co_telldir(pdu, fidp); +#endif + err = v9fs_co_readdir_r(pdu, fidp, dent, &result); if (err || !result) { break; } -#ifdef CONFIG_DARWIN - uint64_t d_offset = 0; - d_offset = v9fs_co_telldir(pdu, fidp); -#endif - v9fs_string_init(&name); v9fs_string_sprintf(&name, "%s", dent->d_name); if ((count + v9fs_readdir_data_size(&name)) > max_count) { @@ -1829,13 +1837,15 @@ static int v9fs_do_readdir(V9fsPDU *pdu, qid.version = 0; /* 11 = 7 + 4 (7 = start offset, 4 = space for storing count) */ - len = pdu_marshal(pdu, 11 + count, "Qqbs", #ifdef CONFIG_LINUX + len = pdu_marshal(pdu, 11 + count, "Qqbs", &qid, dent->d_off, + dent->d_type, &name); #else - &qid, d_offset, -#endif + len = pdu_marshal(pdu, 11 + count, "Qqbs", + &qid, d_offset, dent->d_type, &name); +#endif if (len < 0) { v9fs_co_seekdir(pdu, fidp, saved_dir_pos); v9fs_string_free(&name); @@ -1847,7 +1857,7 @@ static int v9fs_do_readdir(V9fsPDU *pdu, #ifdef CONFIG_LINUX saved_dir_pos = dent->d_off; #else - saved_dir_pos = d_offset; + saved_dir_pos = d_offset; #endif } g_free(dent); @@ -2746,9 +2756,15 @@ static int v9fs_fill_statfs(V9fsState *s, V9fsPDU *pdu, struct statfs *stbuf) f_bavail = stbuf->f_bavail/bsize_factor; f_files = stbuf->f_files; f_ffree = stbuf->f_ffree; +#ifdef CONFIG_LINUX fsid_val = (unsigned int) stbuf->f_fsid.__val[0] | (unsigned long long)stbuf->f_fsid.__val[1] << 32; f_namelen = stbuf->f_namelen; +#else + fsid_val = (unsigned int) stbuf->f_fsid.val[0] | + (unsigned long long)stbuf->f_fsid.val[1] << 32; + f_namelen = 255; +#endif return pdu_marshal(pdu, offset, "ddqqqqqqd", f_type, f_bsize, f_blocks, f_bfree, diff --git a/hw/9pfs/virtio-9p.h b/hw/9pfs/virtio-9p.h index 607334c7fa..1d6eedb7d8 100644 --- a/hw/9pfs/virtio-9p.h +++ b/hw/9pfs/virtio-9p.h @@ -224,9 +224,7 @@ typedef struct V9fsState CoRwlock rename_lock; int32_t root_fid; Error *migration_blocker; -#ifdef CONFIG_LINUX V9fsConf fsconf; -#endif } V9fsState; typedef struct V9fsStatState {