@@ -144,6 +144,7 @@ struct FileOperations
int (*futimens)(FsContext *, int, V9fsFidOpenState *,
const struct timespec *);
int (*fchown)(FsContext *, int, V9fsFidOpenState *, FsCred *);
+ int (*fchmod)(FsContext *, int, V9fsFidOpenState *, FsCred *);
void *opaque;
};
@@ -218,6 +218,15 @@ static int handle_chmod(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp)
return ret;
}
+static int handle_fchmod(FsContext *fs_ctx, int fid_type, V9fsFidOpenState *fs,
+ FsCred *credp)
+{
+ int fd;
+
+ fd = v9fs_get_fd_fid(fid_type, fs);
+ return fchmod(fd, credp->fc_mode);
+}
+
static int handle_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
const char *name, FsCred *credp)
{
@@ -726,4 +735,5 @@ FileOperations handle_ops = {
.ftruncate = handle_ftruncate,
.futimens = handle_futimens,
.fchown = handle_fchown,
+ .fchmod = handle_fchmod,
};
@@ -516,6 +516,26 @@ static int local_chmod(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp)
return ret;
}
+static int local_fchmod(FsContext *fs_ctx, int fid_type, V9fsFidOpenState *fs,
+ FsCred *credp)
+{
+ int ret = -1;
+ int fd;
+
+ fd = v9fs_get_fd_fid(fid_type, fs);
+
+ if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
+ ret = local_set_xattr(fd, NULL, credp);
+ } else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
+ errno = ENOTSUP;
+ return -1;
+ } else if ((fs_ctx->export_flags & V9FS_SM_PASSTHROUGH) ||
+ (fs_ctx->export_flags & V9FS_SM_NONE)) {
+ ret = fchmod(fd, credp->fc_mode);
+ }
+ return ret;
+}
+
static int local_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
const char *name, FsCred *credp)
{
@@ -1336,4 +1356,5 @@ FileOperations local_ops = {
.ftruncate = local_ftruncate,
.futimens = local_futimens,
.fchown = local_fchown,
+ .fchmod = local_fchmod,
};
@@ -743,6 +743,15 @@ static int proxy_chmod(FsContext *fs_ctx, V9fsPath *fs_path, FsCred *credp)
return retval;
}
+static int proxy_fchmod(FsContext *fs_ctx, int fid_type, V9fsFidOpenState *fs,
+ FsCred *credp)
+{
+ int fd;
+
+ fd = v9fs_get_fd_fid(fid_type, fs);
+ return fchmod(fd, credp->fc_mode);
+}
+
static int proxy_mknod(FsContext *fs_ctx, V9fsPath *dir_path,
const char *name, FsCred *credp)
{
@@ -1241,4 +1250,5 @@ FileOperations proxy_ops = {
.ftruncate = proxy_ftruncate,
.futimens = proxy_futimens,
.fchown = proxy_fchown,
+ .fchmod = proxy_fchmod,
};
@@ -357,6 +357,13 @@ static int synth_chmod(FsContext *fs_ctx, V9fsPath *path, FsCred *credp)
return -1;
}
+static int synth_fchmod(FsContext *fs_ctx, int fid_type, V9fsFidOpenState *fs,
+ FsCred *credp)
+{
+ errno = EPERM;
+ return -1;
+}
+
static int synth_mknod(FsContext *fs_ctx, V9fsPath *path,
const char *buf, FsCred *credp)
{
@@ -590,4 +597,5 @@ FileOperations synth_ops = {
.ftruncate = synth_ftruncate,
.futimens = synth_futimens,
.fchown = synth_fchown,
+ .fchmod = synth_fchmod,
};
@@ -1221,6 +1221,19 @@ static int v9fs_do_chown(V9fsPDU *pdu, V9fsFidState *fidp, uid_t uid, gid_t gid)
return err;
}
+static int v9fs_do_chmod(V9fsPDU *pdu, V9fsFidState *fidp, mode_t mode)
+{
+ int err;
+
+ if (fid_has_file(fidp)) {
+ err = v9fs_co_fchmod(pdu, fidp, mode);
+ } else {
+ err = v9fs_co_chmod(pdu, &fidp->path, mode);
+ }
+
+ return err;
+}
+
/* Attribute flags */
#define P9_ATTR_MODE (1 << 0)
#define P9_ATTR_UID (1 << 1)
@@ -1254,7 +1267,7 @@ static void v9fs_setattr(void *opaque)
goto out_nofid;
}
if (v9iattr.valid & P9_ATTR_MODE) {
- err = v9fs_co_chmod(pdu, &fidp->path, v9iattr.mode);
+ err = v9fs_do_chmod(pdu, fidp, v9iattr.mode);
if (err < 0) {
goto out;
}
@@ -2754,9 +2767,8 @@ static void v9fs_wstat(void *opaque)
err = -EIO;
goto out;
}
- err = v9fs_co_chmod(pdu, &fidp->path,
- v9mode_to_mode(v9stat.mode,
- &v9stat.extension));
+ err = v9fs_do_chmod(pdu, fidp, v9mode_to_mode(v9stat.mode,
+ &v9stat.extension));
if (err < 0) {
goto out;
}
@@ -112,6 +112,27 @@ int v9fs_co_chmod(V9fsPDU *pdu, V9fsPath *path, mode_t mode)
return err;
}
+int v9fs_co_fchmod(V9fsPDU *pdu, V9fsFidState *fidp, mode_t mode)
+{
+ int err;
+ FsCred cred;
+ V9fsState *s = pdu->s;
+
+ if (v9fs_request_cancelled(pdu)) {
+ return -EINTR;
+ }
+ cred_init(&cred);
+ cred.fc_mode = mode;
+ v9fs_co_run_in_worker(
+ {
+ err = s->ops->fchmod(&s->ctx, fidp->fid_type, &fidp->fs, &cred);
+ if (err < 0) {
+ err = -errno;
+ }
+ });
+ return err;
+}
+
int v9fs_co_utimensat(V9fsPDU *pdu, V9fsPath *path,
struct timespec times[2])
{
@@ -97,5 +97,6 @@ extern int v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, mode_t,
extern int v9fs_co_ftruncate(V9fsPDU *, V9fsFidState *, off_t);
extern int v9fs_co_futimens(V9fsPDU *, V9fsFidState *, struct timespec [2]);
extern int v9fs_co_fchown(V9fsPDU *, V9fsFidState *, uid_t, gid_t);
+extern int v9fs_co_fchmod(V9fsPDU *, V9fsFidState *, mode_t);
#endif
This allows fchmod() in the guest to stay functional even if the file was unlinked. Signed-off-by: Greg Kurz <groug@kaod.org> --- fsdev/file-op-9p.h | 1 + hw/9pfs/9p-handle.c | 10 ++++++++++ hw/9pfs/9p-local.c | 21 +++++++++++++++++++++ hw/9pfs/9p-proxy.c | 10 ++++++++++ hw/9pfs/9p-synth.c | 8 ++++++++ hw/9pfs/9p.c | 20 ++++++++++++++++---- hw/9pfs/cofs.c | 21 +++++++++++++++++++++ hw/9pfs/coth.h | 1 + 8 files changed, 88 insertions(+), 4 deletions(-) ------------------------------------------------------------------------------ Attend Shape: An AT&T Tech Expo July 15-16. Meet us at AT&T Park in San Francisco, CA to explore cutting-edge tech and listen to tech luminaries present their vision of the future. This family event has something for everyone, including kids. Get more information and register today. http://sdm.link/attshape