On Freitag, 28. Januar 2022 01:56:03 CET Will Cohen wrote:
> From: Keno Fischer <[email protected]>
>
> Signed-off-by: Keno Fischer <[email protected]>
> Signed-off-by: Michael Roitzsch <[email protected]>
> [Will Cohen: - Note lack of f_namelen and f_frsize on Darwin]
> Signed-off-by: Will Cohen <[email protected]>
> ---
> hw/9pfs/9p-proxy.c | 18 +++++++++++++++---
> hw/9pfs/9p-synth.c | 2 ++
> hw/9pfs/9p.c | 16 ++++++++++++++--
> 3 files changed, 31 insertions(+), 5 deletions(-)
>
> diff --git a/hw/9pfs/9p-proxy.c b/hw/9pfs/9p-proxy.c
> index 09bd9f1464..f5aade21b5 100644
> --- a/hw/9pfs/9p-proxy.c
> +++ b/hw/9pfs/9p-proxy.c
> @@ -123,10 +123,16 @@ static void prstatfs_to_statfs(struct statfs *stfs,
> ProxyStatFS *prstfs) stfs->f_bavail = prstfs->f_bavail;
> stfs->f_files = prstfs->f_files;
> stfs->f_ffree = prstfs->f_ffree;
> +#ifdef CONFIG_DARWIN
> + /* f_namelen and f_frsize do not exist on Darwin */
> + stfs->f_fsid.val[0] = prstfs->f_fsid[0] & 0xFFFFFFFFU;
> + stfs->f_fsid.val[1] = prstfs->f_fsid[1] >> 32 & 0xFFFFFFFFU;
> +#else
> stfs->f_fsid.__val[0] = prstfs->f_fsid[0] & 0xFFFFFFFFU;
> stfs->f_fsid.__val[1] = prstfs->f_fsid[1] >> 32 & 0xFFFFFFFFU;
> stfs->f_namelen = prstfs->f_namelen;
> stfs->f_frsize = prstfs->f_frsize;
> +#endif
> }
>
> /* Converts proxy_stat structure to VFS stat structure */
> @@ -143,12 +149,18 @@ static void prstat_to_stat(struct stat *stbuf,
> ProxyStat *prstat) stbuf->st_size = prstat->st_size;
> stbuf->st_blksize = prstat->st_blksize;
> stbuf->st_blocks = prstat->st_blocks;
> - stbuf->st_atim.tv_sec = prstat->st_atim_sec;
Like already mentioned in v2: please assign some value to
stbuf->st_atim.tv_sec as well, i.e. don't just delete it.
On most systems there is a workaround in place like:
#define st_atime st_atim.tv_sec /* Backward compatibility */
#define st_mtime st_mtim.tv_sec
#define st_ctime st_ctim.tv_sec
In that case your changes would work, but I would not rely on that.
Best regards,
Christian Schoenebeck
> - stbuf->st_atim.tv_nsec = prstat->st_atim_nsec;
> + stbuf->st_atime = prstat->st_atim_sec;
> stbuf->st_mtime = prstat->st_mtim_sec;
> - stbuf->st_mtim.tv_nsec = prstat->st_mtim_nsec;
> stbuf->st_ctime = prstat->st_ctim_sec;
> +#ifdef CONFIG_DARWIN
> + stbuf->st_atimespec.tv_nsec = prstat->st_atim_nsec;
> + stbuf->st_mtimespec.tv_nsec = prstat->st_mtim_nsec;
> + stbuf->st_ctimespec.tv_nsec = prstat->st_ctim_nsec;
> +#else
> + stbuf->st_atim.tv_nsec = prstat->st_atim_nsec;
> + stbuf->st_mtim.tv_nsec = prstat->st_mtim_nsec;
> stbuf->st_ctim.tv_nsec = prstat->st_ctim_nsec;
> +#endif
> }
>
> /*
> diff --git a/hw/9pfs/9p-synth.c b/hw/9pfs/9p-synth.c
> index b38088e066..4a4a776d06 100644
> --- a/hw/9pfs/9p-synth.c
> +++ b/hw/9pfs/9p-synth.c
> @@ -427,7 +427,9 @@ static int synth_statfs(FsContext *s, V9fsPath *fs_path,
> stbuf->f_bsize = 512;
> stbuf->f_blocks = 0;
> stbuf->f_files = synth_node_count;
> +#ifndef CONFIG_DARWIN
> stbuf->f_namelen = NAME_MAX;
> +#endif
> return 0;
> }
>
> diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c
> index 9c63e14b28..1563d7b7c6 100644
> --- a/hw/9pfs/9p.c
> +++ b/hw/9pfs/9p.c
> @@ -1313,11 +1313,17 @@ static int stat_to_v9stat_dotl(V9fsPDU *pdu, const
> struct stat *stbuf, v9lstat->st_blksize = stat_to_iounit(pdu, stbuf);
> v9lstat->st_blocks = stbuf->st_blocks;
> v9lstat->st_atime_sec = stbuf->st_atime;
> - v9lstat->st_atime_nsec = stbuf->st_atim.tv_nsec;
> v9lstat->st_mtime_sec = stbuf->st_mtime;
> - v9lstat->st_mtime_nsec = stbuf->st_mtim.tv_nsec;
> v9lstat->st_ctime_sec = stbuf->st_ctime;
> +#ifdef CONFIG_DARWIN
> + v9lstat->st_atime_nsec = stbuf->st_atimespec.tv_nsec;
> + v9lstat->st_mtime_nsec = stbuf->st_mtimespec.tv_nsec;
> + v9lstat->st_ctime_nsec = stbuf->st_ctimespec.tv_nsec;
> +#else
> + v9lstat->st_atime_nsec = stbuf->st_atim.tv_nsec;
> + v9lstat->st_mtime_nsec = stbuf->st_mtim.tv_nsec;
> v9lstat->st_ctime_nsec = stbuf->st_ctim.tv_nsec;
> +#endif
> /* Currently we only support BASIC fields in stat */
> v9lstat->st_result_mask = P9_STATS_BASIC;
>
> @@ -3519,9 +3525,15 @@ static int v9fs_fill_statfs(V9fsState *s, V9fsPDU
> *pdu, struct statfs *stbuf) f_bavail = stbuf->f_bavail / bsize_factor;
> f_files = stbuf->f_files;
> f_ffree = stbuf->f_ffree;
> +#ifdef CONFIG_DARWIN
> + fsid_val = (unsigned int)stbuf->f_fsid.val[0] |
> + (unsigned long long)stbuf->f_fsid.val[1] << 32;
> + f_namelen = NAME_MAX;
> +#else
> fsid_val = (unsigned int) stbuf->f_fsid.__val[0] |
> (unsigned long long)stbuf->f_fsid.__val[1] << 32;
> f_namelen = stbuf->f_namelen;
> +#endif
>
> return pdu_marshal(pdu, offset, "ddqqqqqqd",
> f_type, f_bsize, f_blocks, f_bfree,