@@ -259,11 +259,7 @@ static int handle_fstat(FsContext *fs_ctx, int fid_type,
{
int fd;
- if (fid_type == P9_FID_DIR) {
- fd = dirfd(fs->dir.stream);
- } else {
- fd = fs->fd;
- }
+ fd = v9fs_get_fd_fid(fid_type, fs);
return fstat(fd, stbuf);
}
@@ -406,11 +402,7 @@ static int handle_fsync(FsContext *ctx, int fid_type,
{
int fd;
- if (fid_type == P9_FID_DIR) {
- fd = dirfd(fs->dir.stream);
- } else {
- fd = fs->fd;
- }
+ fd = v9fs_get_fd_fid(fid_type, fs);
if (datasync) {
return qemu_fdatasync(fd);
@@ -630,11 +630,7 @@ static int local_fstat(FsContext *fs_ctx, int fid_type,
{
int err, fd;
- if (fid_type == P9_FID_DIR) {
- fd = dirfd(fs->dir.stream);
- } else {
- fd = fs->fd;
- }
+ fd = v9fs_get_fd_fid(fid_type, fs);
err = fstat(fd, stbuf);
if (err) {
@@ -1001,11 +997,7 @@ static int local_fsync(FsContext *ctx, int fid_type,
{
int fd;
- if (fid_type == P9_FID_DIR) {
- fd = dirfd(fs->dir.stream);
- } else {
- fd = fs->fd;
- }
+ fd = v9fs_get_fd_fid(fid_type, fs);
if (datasync) {
return qemu_fdatasync(fd);
@@ -788,11 +788,7 @@ static int proxy_fstat(FsContext *fs_ctx, int fid_type,
{
int fd;
- if (fid_type == P9_FID_DIR) {
- fd = dirfd(fs->dir.stream);
- } else {
- fd = fs->fd;
- }
+ fd = v9fs_get_fd_fid(fid_type, fs);
return fstat(fd, stbuf);
}
@@ -933,11 +929,7 @@ static int proxy_fsync(FsContext *ctx, int fid_type,
{
int fd;
- if (fid_type == P9_FID_DIR) {
- fd = dirfd(fs->dir.stream);
- } else {
- fd = fs->fd;
- }
+ fd = v9fs_get_fd_fid(fid_type, fs);
if (datasync) {
return qemu_fdatasync(fd);
@@ -240,6 +240,19 @@ static int v9fs_reopen_fid(V9fsPDU *pdu, V9fsFidState *f)
return err;
}
+int v9fs_get_fd_fid(int fid_type, V9fsFidOpenState *fs)
+{
+ int fd = -1;
+
+ if (fid_type == P9_FID_DIR) {
+ fd = dirfd(fs->dir.stream);
+ } else if (fid_type == P9_FID_FILE) {
+ fd = fs->fd;
+ }
+
+ return fd;
+}
+
static V9fsFidState *get_fid(V9fsPDU *pdu, int32_t fid)
{
int err;
@@ -202,6 +202,8 @@ union V9fsFidOpenState {
void *private;
};
+extern int v9fs_get_fd_fid(int fid_type, V9fsFidOpenState *fs);
+
struct V9fsFidState
{
int fid_type;
This will be used by all file descriptor based ops. Signed-off-by: Greg Kurz <groug@kaod.org> --- hw/9pfs/9p-handle.c | 12 ++---------- hw/9pfs/9p-local.c | 12 ++---------- hw/9pfs/9p-proxy.c | 12 ++---------- hw/9pfs/9p.c | 13 +++++++++++++ hw/9pfs/9p.h | 2 ++ 5 files changed, 21 insertions(+), 30 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