#include <grp.h>
#include <sys/socket.h>
#include <sys/un.h>
-#include <attr/xattr.h>
+#include "qemu-xattr.h"
#include <unistd.h>
#include <linux/fs.h>
#ifdef CONFIG_LINUX_MAGIC_H
int handle_bytes;
};
-#ifdef CONFIG_OPEN_BY_HANDLE
static inline int name_to_handle(int dirfd, const char *name,
struct file_handle *fh, int *mnt_id, int flags)
{
{
return open_by_handle_at(mountfd, (struct file_handle *)fh, flags);
}
-#else
-
-struct file_handle {
- unsigned int handle_bytes;
- int handle_type;
- unsigned char handle[0];
-};
-
-#ifndef AT_EMPTY_PATH
-#define AT_EMPTY_PATH 0x1000 /* Allow empty relative pathname */
-#endif
-#ifndef O_PATH
-#define O_PATH 010000000
-#endif
-
-static inline int name_to_handle(int dirfd, const char *name,
- struct file_handle *fh, int *mnt_id, int flags)
-{
- errno = ENOSYS;
- return -1;
-}
-
-static inline int open_by_handle(int mountfd, const char *fh, int flags)
-{
- errno = ENOSYS;
- return -1;
-}
-#endif
static int handle_update_file_cred(int dirfd, const char *name, FsCred *credp)
{
int fd, ret;
- fd = openat(dirfd, name, O_NONBLOCK | O_NOFOLLOW);;
+ fd = openat(dirfd, name, O_NONBLOCK | O_NOFOLLOW);
if (fd < 0) {
return fd;
}
- ret = fchmod(fd, credp->fc_mode & 07777);
+ ret = fchownat(fd, "", credp->fc_uid, credp->fc_gid, AT_EMPTY_PATH);
if (ret < 0) {
goto err_out;
}
- ret = fchownat(fd, "", credp->fc_uid, credp->fc_gid, AT_EMPTY_PATH);
+ ret = fchmod(fd, credp->fc_mode & 07777);
err_out:
close(fd);
return ret;
return ret;
}
-static int handle_fstat(FsContext *fs_ctx, V9fsFidOpenState *fs,
- struct stat *stbuf)
+static int handle_fstat(FsContext *fs_ctx, int fid_type,
+ V9fsFidOpenState *fs, struct stat *stbuf)
{
- return fstat(fs->fd, stbuf);
+ int fd;
+
+ if (fid_type == P9_FID_DIR) {
+ fd = dirfd(fs->dir);
+ } else {
+ fd = fs->fd;
+ }
+ return fstat(fd, stbuf);
}
static int handle_open2(FsContext *fs_ctx, V9fsPath *dir_path, const char *name,
return -1;
}
-static int handle_fsync(FsContext *ctx, V9fsFidOpenState *fs, int datasync)
+static int handle_fsync(FsContext *ctx, int fid_type,
+ V9fsFidOpenState *fs, int datasync)
{
+ int fd;
+
+ if (fid_type == P9_FID_DIR) {
+ fd = dirfd(fs->dir);
+ } else {
+ fd = fs->fd;
+ }
+
if (datasync) {
- return qemu_fdatasync(fs->fd);
+ return qemu_fdatasync(fd);
} else {
- return fsync(fs->fd);
+ return fsync(fd);
}
}
}
fh = g_malloc(sizeof(struct file_handle) + data->handle_bytes);
fh->handle_bytes = data->handle_bytes;
- /* add a "./" at the begining of the path */
+ /* add a "./" at the beginning of the path */
snprintf(buffer, PATH_MAX, "./%s", name);
/* flag = 0 imply don't follow symlink */
ret = name_to_handle(dirfd, buffer, fh, &mnt_id, 0);
{
int dirfd, ret;
struct handle_data *data = (struct handle_data *)ctx->private;
+ int rflags;
dirfd = open_by_handle(data->mountfd, dir->data, O_PATH);
if (dirfd < 0) {
return dirfd;
}
- ret = unlinkat(dirfd, name, flags);
+ rflags = 0;
+ if (flags & P9_DOTL_AT_REMOVEDIR) {
+ rflags |= AT_REMOVEDIR;
+ }
+
+ ret = unlinkat(dirfd, name, rflags);
+
close(dirfd);
return ret;
}
return ret;
}
+static int handle_parse_opts(QemuOpts *opts, struct FsDriverEntry *fse)
+{
+ const char *sec_model = qemu_opt_get(opts, "security_model");
+ const char *path = qemu_opt_get(opts, "path");
+
+ if (sec_model) {
+ fprintf(stderr, "Invalid argument security_model specified with handle fsdriver\n");
+ return -1;
+ }
+
+ if (!path) {
+ fprintf(stderr, "fsdev: No path specified.\n");
+ return -1;
+ }
+ fse->path = g_strdup(path);
+ return 0;
+
+}
+
FileOperations handle_ops = {
+ .parse_opts = handle_parse_opts,
.init = handle_init,
.lstat = handle_lstat,
.readlink = handle_readlink,