Message ID | 20250320074924.8080-2-jgross@suse.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | 9pfs: add some file operation hooks | expand |
On 2025-03-20 03:49, Juergen Gross wrote: > Add a file operations fstat hook to the 9pfs frontend. > > Signed-off-by: Juergen Gross <jgross@suse.com> > --- > @@ -950,6 +952,32 @@ static int write_9pfs(struct file *file, const void *buf, size_t nbytes) > return ret; > } > > +static int fstat_9pfs(struct file *file, struct stat *buf) > +{ > + struct file_9pfs *f9pfs = file->filedata; > + struct p9_stat stat; > + int ret; > + > + ret = p9_stat(f9pfs->dev, f9pfs->fid, &stat); > + if ( ret ) > + { > + errno = EIO; > + return -1; > + } > + > + buf->st_mode = (stat.qid[0] == QID_TYPE_DIR) ? S_IFDIR : S_IFREG; > + buf->st_mode = stat.mode & 0777; I think you want `|= stat.mode & 0x777` here. Regards, Jason
On 20.03.25 15:28, Jason Andryuk wrote: > On 2025-03-20 03:49, Juergen Gross wrote: >> Add a file operations fstat hook to the 9pfs frontend. >> >> Signed-off-by: Juergen Gross <jgross@suse.com> >> --- > >> @@ -950,6 +952,32 @@ static int write_9pfs(struct file *file, const void *buf, >> size_t nbytes) >> return ret; >> } >> +static int fstat_9pfs(struct file *file, struct stat *buf) >> +{ >> + struct file_9pfs *f9pfs = file->filedata; >> + struct p9_stat stat; >> + int ret; >> + >> + ret = p9_stat(f9pfs->dev, f9pfs->fid, &stat); >> + if ( ret ) >> + { >> + errno = EIO; >> + return -1; >> + } >> + >> + buf->st_mode = (stat.qid[0] == QID_TYPE_DIR) ? S_IFDIR : S_IFREG; >> + buf->st_mode = stat.mode & 0777; > > I think you want `|= stat.mode & 0x777` here. Indeed. Thanks for catching this one. Juergen
On 2025-03-20 10:35, Jürgen Groß wrote: > On 20.03.25 15:28, Jason Andryuk wrote: >> On 2025-03-20 03:49, Juergen Gross wrote: >>> Add a file operations fstat hook to the 9pfs frontend. >>> >>> Signed-off-by: Juergen Gross <jgross@suse.com> >>> --- >> >>> @@ -950,6 +952,32 @@ static int write_9pfs(struct file *file, const >>> void *buf, size_t nbytes) >>> return ret; >>> } >>> +static int fstat_9pfs(struct file *file, struct stat *buf) >>> +{ >>> + struct file_9pfs *f9pfs = file->filedata; >>> + struct p9_stat stat; >>> + int ret; >>> + >>> + ret = p9_stat(f9pfs->dev, f9pfs->fid, &stat); >>> + if ( ret ) >>> + { >>> + errno = EIO; >>> + return -1; >>> + } >>> + >>> + buf->st_mode = (stat.qid[0] == QID_TYPE_DIR) ? S_IFDIR : S_IFREG; >>> + buf->st_mode = stat.mode & 0777; >> >> I think you want `|= stat.mode & 0x777` here. > > Indeed. Thanks for catching this one. With that, Reviewed-by: Jason Andryuk <jason.andryuk@amd.com> Regards, Jason
diff --git a/9pfront.c b/9pfront.c index 1741d600..a65fe26d 100644 --- a/9pfront.c +++ b/9pfront.c @@ -85,6 +85,8 @@ struct file_9pfs { #define P9_QID_SIZE 13 +#define QID_TYPE_DIR 0x80 /* Applies to qid[0]. */ + struct p9_header { uint32_t size; uint8_t cmd; @@ -950,6 +952,32 @@ static int write_9pfs(struct file *file, const void *buf, size_t nbytes) return ret; } +static int fstat_9pfs(struct file *file, struct stat *buf) +{ + struct file_9pfs *f9pfs = file->filedata; + struct p9_stat stat; + int ret; + + ret = p9_stat(f9pfs->dev, f9pfs->fid, &stat); + if ( ret ) + { + errno = EIO; + return -1; + } + + buf->st_mode = (stat.qid[0] == QID_TYPE_DIR) ? S_IFDIR : S_IFREG; + buf->st_mode = stat.mode & 0777; + buf->st_atime = stat.atime; + buf->st_mtime = stat.mtime; + buf->st_size = stat.length; + buf->st_uid = stat.n_uid; + buf->st_gid = stat.n_gid; + + free_stat(&stat); + + return 0; +} + static int close_9pfs(struct file *file) { struct file_9pfs *f9pfs = file->filedata; @@ -1296,6 +1324,7 @@ static const struct file_ops ops_9pfs = { .read = read_9pfs, .write = write_9pfs, .close = close_9pfs, + .fstat = fstat_9pfs, }; __attribute__((constructor))
Add a file operations fstat hook to the 9pfs frontend. Signed-off-by: Juergen Gross <jgross@suse.com> --- 9pfront.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)