From: Jeremy Allison Date: Mon, 12 Jul 2021 22:37:20 +0000 (-0700) Subject: s3: lib: Add sys_fstatat() wrapper. X-Git-Tag: talloc-2.3.3~70 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8804d240fac3ffe58a5c43b23c842fa6bde61e27;p=thirdparty%2Fsamba.git s3: lib: Add sys_fstatat() wrapper. Does the usual things we need with fake_dir_create_times. Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme --- diff --git a/source3/include/proto.h b/source3/include/proto.h index 4485cb43419..938a71e8083 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -214,6 +214,11 @@ int sys_fstat(int fd, SMB_STRUCT_STAT *sbuf, bool fake_dir_create_times); int sys_lstat(const char *fname,SMB_STRUCT_STAT *sbuf, bool fake_dir_create_times); +int sys_fstatat(int fd, + const char *pathname, + SMB_STRUCT_STAT *sbuf, + int flags, + bool fake_dir_create_times); int sys_posix_fallocate(int fd, off_t offset, off_t len); int sys_fallocate(int fd, uint32_t mode, off_t offset, off_t len); void kernel_flock(int fd, uint32_t share_access, uint32_t access_mask); diff --git a/source3/lib/system.c b/source3/lib/system.c index ad525737c5b..5d57ffadda1 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -369,6 +369,32 @@ int sys_lstat(const char *fname,SMB_STRUCT_STAT *sbuf, return ret; } +/******************************************************************* + An fstatat() wrapper. +********************************************************************/ + +int sys_fstatat(int fd, + const char *pathname, + SMB_STRUCT_STAT *sbuf, + int flags, + bool fake_dir_create_times) +{ + int ret; + struct stat statbuf; + + ret = fstatat(fd, pathname, &statbuf, flags); + if (ret != 0) { + return -1; + } + + /* we always want directories to appear zero size */ + if (S_ISDIR(statbuf.st_mode)) { + statbuf.st_size = 0; + } + init_stat_ex_from_stat(sbuf, &statbuf, fake_dir_create_times); + return 0; +} + /******************************************************************* An posix_fallocate() wrapper. ********************************************************************/