From fbeefe3b7e66df7212a407f601163d9b5e81480e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 17 Jun 2021 12:10:16 -0700 Subject: [PATCH] s3: VFS: syncops: Remove direct system calls and use OpenDir()/smb_vfs_fsync_sync()/TALLOC_FREE() to sync a directory. syncops is now *really* stackable. Signed-off-by: Jeremy Allison Reviewed-by: Noel Power --- source3/modules/vfs_syncops.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/source3/modules/vfs_syncops.c b/source3/modules/vfs_syncops.c index c3f11cf67e9..c0ef4c3b81e 100644 --- a/source3/modules/vfs_syncops.c +++ b/source3/modules/vfs_syncops.c @@ -74,19 +74,24 @@ static char *parent_dir(TALLOC_CTX *mem_ctx, const char *name) static void syncops_sync_directory(connection_struct *conn, char *dname) { -#ifdef O_DIRECTORY - int fd = open(dname, O_DIRECTORY|O_RDONLY); - if (fd != -1) { - fsync(fd); - close(fd); - } -#else - DIR *d = opendir(dname); - if (d != NULL) { - fsync(dirfd(d)); - closedir(d); + struct smb_Dir *dir_hnd = NULL; + struct files_struct *dirfsp = NULL; + struct smb_filename smb_dname = { .base_name = dname }; + + dir_hnd = OpenDir(talloc_tos(), + conn, + &smb_dname, + "*", + 0); + if (dir_hnd == NULL) { + return; } -#endif + + dirfsp = dir_hnd_fetch_fsp(dir_hnd); + + smb_vfs_fsync_sync(dirfsp); + + TALLOC_FREE(dir_hnd); } /* -- 2.47.2