@@ -117,36 +117,55 @@ static void local_mapped_file_attr(FsContext *ctx, const char *path,
fclose(fp);
}
-static int local_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf)
+static int local_do_getxattr(int fd, const char *path,
+ const char *name, void *value, size_t size)
{
- int err;
- char *buffer;
- char *path = fs_path->data;
-
- buffer = rpath(fs_ctx, path);
- err = lstat(buffer, stbuf);
- if (err) {
- goto err_out;
+ if (path) {
+ return getxattr(path, name, value, size);
+ } else {
+ return fgetxattr(fd, name, value, size);
}
- if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
+}
+
+static void local_mapped_attr(int fd, char *path, struct stat *stbuf)
+{
/* Actual credentials are part of extended attrs */
uid_t tmp_uid;
gid_t tmp_gid;
mode_t tmp_mode;
dev_t tmp_dev;
- if (getxattr(buffer, "user.virtfs.uid", &tmp_uid, sizeof(uid_t)) > 0) {
+
+ if (local_do_getxattr(fd, path, "user.virtfs.uid", &tmp_uid,
+ sizeof(uid_t)) > 0) {
stbuf->st_uid = le32_to_cpu(tmp_uid);
}
- if (getxattr(buffer, "user.virtfs.gid", &tmp_gid, sizeof(gid_t)) > 0) {
+ if (local_do_getxattr(fd, path, "user.virtfs.gid", &tmp_gid,
+ sizeof(gid_t)) > 0) {
stbuf->st_gid = le32_to_cpu(tmp_gid);
}
- if (getxattr(buffer, "user.virtfs.mode",
- &tmp_mode, sizeof(mode_t)) > 0) {
+ if (local_do_getxattr(fd, path, "user.virtfs.mode", &tmp_mode,
+ sizeof(mode_t)) > 0) {
stbuf->st_mode = le32_to_cpu(tmp_mode);
}
- if (getxattr(buffer, "user.virtfs.rdev", &tmp_dev, sizeof(dev_t)) > 0) {
+ if (local_do_getxattr(fd, path, "user.virtfs.rdev", &tmp_dev,
+ sizeof(dev_t)) > 0) {
stbuf->st_rdev = le64_to_cpu(tmp_dev);
}
+}
+
+static int local_lstat(FsContext *fs_ctx, V9fsPath *fs_path, struct stat *stbuf)
+{
+ int err;
+ char *buffer;
+ char *path = fs_path->data;
+
+ buffer = rpath(fs_ctx, path);
+ err = lstat(buffer, stbuf);
+ if (err) {
+ goto err_out;
+ }
+ if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
+ local_mapped_attr(-1, buffer, stbuf);
} else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
local_mapped_file_attr(fs_ctx, path, stbuf);
}
@@ -622,24 +641,7 @@ static int local_fstat(FsContext *fs_ctx, int fid_type,
return err;
}
if (fs_ctx->export_flags & V9FS_SM_MAPPED) {
- /* Actual credentials are part of extended attrs */
- uid_t tmp_uid;
- gid_t tmp_gid;
- mode_t tmp_mode;
- dev_t tmp_dev;
-
- if (fgetxattr(fd, "user.virtfs.uid", &tmp_uid, sizeof(uid_t)) > 0) {
- stbuf->st_uid = le32_to_cpu(tmp_uid);
- }
- if (fgetxattr(fd, "user.virtfs.gid", &tmp_gid, sizeof(gid_t)) > 0) {
- stbuf->st_gid = le32_to_cpu(tmp_gid);
- }
- if (fgetxattr(fd, "user.virtfs.mode", &tmp_mode, sizeof(mode_t)) > 0) {
- stbuf->st_mode = le32_to_cpu(tmp_mode);
- }
- if (fgetxattr(fd, "user.virtfs.rdev", &tmp_dev, sizeof(dev_t)) > 0) {
- stbuf->st_rdev = le64_to_cpu(tmp_dev);
- }
+ local_mapped_attr(fd, NULL, stbuf);
} else if (fs_ctx->export_flags & V9FS_SM_MAPPED_FILE) {
errno = EOPNOTSUPP;
return -1;
This does not change functionality. Signed-off-by: Greg Kurz <groug@kaod.org> --- hw/9pfs/9p-local.c | 68 +++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 33 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