aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hw/9pfs/9p-local.c198
1 files changed, 0 insertions, 198 deletions
diff --git a/hw/9pfs/9p-local.c b/hw/9pfs/9p-local.c
index b9d4e99851..432a30c3c1 100644
--- a/hw/9pfs/9p-local.c
+++ b/hw/9pfs/9p-local.c
@@ -84,48 +84,6 @@ static void unlinkat_preserve_errno(int dirfd, const char *path, int flags)
#define VIRTFS_META_DIR ".virtfs_metadata"
-static char *local_mapped_attr_path(FsContext *ctx, const char *path)
-{
- int dirlen;
- const char *name = strrchr(path, '/');
- if (name) {
- dirlen = name - path;
- ++name;
- } else {
- name = path;
- dirlen = 0;
- }
- return g_strdup_printf("%s/%.*s/%s/%s", ctx->fs_root,
- dirlen, path, VIRTFS_META_DIR, name);
-}
-
-static FILE *local_fopen(const char *path, const char *mode)
-{
- int fd, o_mode = 0;
- FILE *fp;
- int flags = O_NOFOLLOW;
- /*
- * only supports two modes
- */
- if (mode[0] == 'r') {
- flags |= O_RDONLY;
- } else if (mode[0] == 'w') {
- flags |= O_WRONLY | O_TRUNC | O_CREAT;
- o_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
- } else {
- return NULL;
- }
- fd = open(path, flags, o_mode);
- if (fd == -1) {
- return NULL;
- }
- fp = fdopen(fd, mode);
- if (!fp) {
- close(fd);
- }
- return fp;
-}
-
static FILE *local_fopenat(int dirfd, const char *name, const char *mode)
{
int fd, o_mode = 0;
@@ -238,135 +196,6 @@ out:
return err;
}
-static int local_create_mapped_attr_dir(FsContext *ctx, const char *path)
-{
- int err;
- char *attr_dir;
- char *tmp_path = g_strdup(path);
-
- attr_dir = g_strdup_printf("%s/%s/%s",
- ctx->fs_root, dirname(tmp_path), VIRTFS_META_DIR);
-
- err = mkdir(attr_dir, 0700);
- if (err < 0 && errno == EEXIST) {
- err = 0;
- }
- g_free(attr_dir);
- g_free(tmp_path);
- return err;
-}
-
-static int local_set_mapped_file_attr(FsContext *ctx,
- const char *path, FsCred *credp)
-{
- FILE *fp;
- int ret = 0;
- char buf[ATTR_MAX];
- char *attr_path;
- int uid = -1, gid = -1, mode = -1, rdev = -1;
-
- attr_path = local_mapped_attr_path(ctx, path);
- fp = local_fopen(attr_path, "r");
- if (!fp) {
- goto create_map_file;
- }
- memset(buf, 0, ATTR_MAX);
- while (fgets(buf, ATTR_MAX, fp)) {
- if (!strncmp(buf, "virtfs.uid", 10)) {
- uid = atoi(buf+11);
- } else if (!strncmp(buf, "virtfs.gid", 10)) {
- gid = atoi(buf+11);
- } else if (!strncmp(buf, "virtfs.mode", 11)) {
- mode = atoi(buf+12);
- } else if (!strncmp(buf, "virtfs.rdev", 11)) {
- rdev = atoi(buf+12);
- }
- memset(buf, 0, ATTR_MAX);
- }
- fclose(fp);
- goto update_map_file;
-
-create_map_file:
- ret = local_create_mapped_attr_dir(ctx, path);
- if (ret < 0) {
- goto err_out;
- }
-
-update_map_file:
- fp = local_fopen(attr_path, "w");
- if (!fp) {
- ret = -1;
- goto err_out;
- }
-
- if (credp->fc_uid != -1) {
- uid = credp->fc_uid;
- }
- if (credp->fc_gid != -1) {
- gid = credp->fc_gid;
- }
- if (credp->fc_mode != -1) {
- mode = credp->fc_mode;
- }
- if (credp->fc_rdev != -1) {
- rdev = credp->fc_rdev;
- }
-
-
- if (uid != -1) {
- fprintf(fp, "virtfs.uid=%d\n", uid);
- }
- if (gid != -1) {
- fprintf(fp, "virtfs.gid=%d\n", gid);
- }
- if (mode != -1) {
- fprintf(fp, "virtfs.mode=%d\n", mode);
- }
- if (rdev != -1) {
- fprintf(fp, "virtfs.rdev=%d\n", rdev);
- }
- fclose(fp);
-
-err_out:
- g_free(attr_path);
- return ret;
-}
-
-static int local_set_xattr(const char *path, FsCred *credp)
-{
- int err;
-
- if (credp->fc_uid != -1) {
- uint32_t tmp_uid = cpu_to_le32(credp->fc_uid);
- err = setxattr(path, "user.virtfs.uid", &tmp_uid, sizeof(uid_t), 0);
- if (err) {
- return err;
- }
- }
- if (credp->fc_gid != -1) {
- uint32_t tmp_gid = cpu_to_le32(credp->fc_gid);
- err = setxattr(path, "user.virtfs.gid", &tmp_gid, sizeof(gid_t), 0);
- if (err) {
- return err;
- }
- }
- if (credp->fc_mode != -1) {
- uint32_t tmp_mode = cpu_to_le32(credp->fc_mode);
- err = setxattr(path, "user.virtfs.mode", &tmp_mode, sizeof(mode_t), 0);
- if (err) {
- return err;
- }
- }
- if (credp->fc_rdev != -1) {
- uint64_t tmp_rdev = cpu_to_le64(credp->fc_rdev);
- err = setxattr(path, "user.virtfs.rdev", &tmp_rdev, sizeof(dev_t), 0);
- if (err) {
- return err;
- }
- }
- return 0;
-}
-
static int local_set_mapped_file_attrat(int dirfd, const char *name,
FsCred *credp)
{
@@ -516,33 +345,6 @@ static int local_set_xattrat(int dirfd, const char *path, FsCred *credp)
return 0;
}
-static int local_post_create_passthrough(FsContext *fs_ctx, const char *path,
- FsCred *credp)
-{
- char *buffer;
-
- buffer = rpath(fs_ctx, path);
- 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) {
- goto err;
- }
- }
-
- if (chmod(buffer, credp->fc_mode & 07777) < 0) {
- goto err;
- }
-
- g_free(buffer);
- return 0;
-err:
- g_free(buffer);
- return -1;
-}
-
static int local_set_cred_passthrough(FsContext *fs_ctx, int dirfd,
const char *name, FsCred *credp)
{