From: Jeremy Allison Date: Thu, 17 Jun 2021 19:10:16 +0000 (-0700) Subject: s3: VFS: syncops: Remove direct system calls and use OpenDir()/smb_vfs_fsync_sync... X-Git-Tag: tevent-0.11.0~235 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fbeefe3b7e66df7212a407f601163d9b5e81480e;p=thirdparty%2Fsamba.git 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 --- 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); } /*