From: Volker Lendecke Date: Fri, 24 Jan 2025 15:37:42 +0000 (+0100) Subject: vfs: Implement snapper_gmt_fstatat() X-Git-Tag: tevent-0.17.0~461 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8e5fa089b35dd544ae9eb7abae124827d96854f0;p=thirdparty%2Fsamba.git vfs: Implement snapper_gmt_fstatat() Make snapper_gmt_stat() and snapper_gmt_lstat() use that. Signed-off-by: Volker Lendecke Reviewed-by: Anoop C S --- diff --git a/source3/modules/vfs_snapper.c b/source3/modules/vfs_snapper.c index 1a3f98bc246..6a693012eb7 100644 --- a/source3/modules/vfs_snapper.c +++ b/source3/modules/vfs_snapper.c @@ -2004,76 +2004,62 @@ static int snapper_gmt_linkat(vfs_handle_struct *handle, flags); } -static int snapper_gmt_stat(vfs_handle_struct *handle, - struct smb_filename *smb_fname) +static int snapper_gmt_fstatat(struct vfs_handle_struct *handle, + const struct files_struct *dirfsp, + const struct smb_filename *smb_fname, + SMB_STRUCT_STAT *sbuf, + int flags) { - time_t timestamp; - char *stripped, *tmp; - int ret, saved_errno; + struct smb_filename *tmp_fname = NULL; + int ret; - if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, - smb_fname, - ×tamp, &stripped)) { - return -1; - } - if (timestamp == 0) { - return SMB_VFS_NEXT_STAT(handle, smb_fname); + if (smb_fname->twrp == 0) { + return SMB_VFS_NEXT_FSTATAT( + handle, dirfsp, smb_fname, sbuf, flags); } - tmp = smb_fname->base_name; - smb_fname->base_name = snapper_gmt_convert(talloc_tos(), handle, - stripped, timestamp); - TALLOC_FREE(stripped); + tmp_fname = cp_smb_filename(talloc_tos(), smb_fname); + if (tmp_fname == NULL) { + errno = ENOMEM; + return -1; + } - if (smb_fname->base_name == NULL) { - smb_fname->base_name = tmp; + tmp_fname->base_name = snapper_gmt_convert(tmp_fname, + handle, + smb_fname->base_name, + smb_fname->twrp); + if (tmp_fname->base_name == NULL) { + TALLOC_FREE(tmp_fname); + errno = ENOMEM; return -1; } - ret = SMB_VFS_NEXT_STAT(handle, smb_fname); - saved_errno = errno; + ret = SMB_VFS_NEXT_FSTATAT(handle, dirfsp, tmp_fname, sbuf, flags); - TALLOC_FREE(smb_fname->base_name); - smb_fname->base_name = tmp; + { + int err = errno; + TALLOC_FREE(tmp_fname); + errno = err; + } - errno = saved_errno; return ret; } +static int snapper_gmt_stat(vfs_handle_struct *handle, + struct smb_filename *smb_fname) +{ + return snapper_gmt_fstatat( + handle, handle->conn->cwd_fsp, smb_fname, &smb_fname->st, 0); +} + static int snapper_gmt_lstat(vfs_handle_struct *handle, struct smb_filename *smb_fname) { - time_t timestamp; - char *stripped, *tmp; - int ret, saved_errno; - - if (!snapper_gmt_strip_snapshot(talloc_tos(), handle, - smb_fname, - ×tamp, &stripped)) { - return -1; - } - if (timestamp == 0) { - return SMB_VFS_NEXT_LSTAT(handle, smb_fname); - } - - tmp = smb_fname->base_name; - smb_fname->base_name = snapper_gmt_convert(talloc_tos(), handle, - stripped, timestamp); - TALLOC_FREE(stripped); - - if (smb_fname->base_name == NULL) { - smb_fname->base_name = tmp; - return -1; - } - - ret = SMB_VFS_NEXT_LSTAT(handle, smb_fname); - saved_errno = errno; - - TALLOC_FREE(smb_fname->base_name); - smb_fname->base_name = tmp; - - errno = saved_errno; - return ret; + return snapper_gmt_fstatat(handle, + handle->conn->cwd_fsp, + smb_fname, + &smb_fname->st, + AT_SYMLINK_NOFOLLOW); } static int snapper_gmt_openat(struct vfs_handle_struct *handle, @@ -2625,6 +2611,7 @@ static struct vfs_fn_pointers snapper_fns = { .symlinkat_fn = snapper_gmt_symlinkat, .stat_fn = snapper_gmt_stat, .lstat_fn = snapper_gmt_lstat, + .fstatat_fn = snapper_gmt_fstatat, .openat_fn = snapper_gmt_openat, .unlinkat_fn = snapper_gmt_unlinkat, .fchmod_fn = snapper_gmt_fchmod,