summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2008-08-27 15:06:14 -0700
committerJeremy Allison <jra@samba.org>2008-08-27 15:06:14 -0700
commit1cae2ac905cc3e4b6e4c92ec4d64c582cfad8fea (patch)
treec382f2b7aca79306cb45ed77732edcc696857c22 /source3
parent34c073c35192850710582b3f558c9fb761e2c24f (diff)
downloadsamba-1cae2ac905cc3e4b6e4c92ec4d64c582cfad8fea.tar.gz
samba-1cae2ac905cc3e4b6e4c92ec4d64c582cfad8fea.tar.bz2
samba-1cae2ac905cc3e4b6e4c92ec4d64c582cfad8fea.zip
Add st_birthtime and friends for accurate create times on systems that support it (*BSD and MacOSX).
Should have done this ages ago, sorry. Jeremy. (This used to be commit 4c3a9558906f213948c3bdc081be73f8fed148cb)
Diffstat (limited to 'source3')
-rw-r--r--source3/configure.in90
-rw-r--r--source3/include/proto.h1
-rw-r--r--source3/lib/time.c40
-rw-r--r--source3/smbd/reply.c7
4 files changed, 124 insertions, 14 deletions
diff --git a/source3/configure.in b/source3/configure.in
index 9436fed1ff..bc5a827b8c 100644
--- a/source3/configure.in
+++ b/source3/configure.in
@@ -1354,6 +1354,96 @@ if test x"$samba_cv_stat_hires_notimespec" = x"yes" ; then
[whether struct stat has sub-second timestamps without struct timespec])
fi
+AC_CACHE_CHECK([whether struct stat has st_birthtimespec], samba_cv_stat_st_birthtimespec,
+ [
+ AC_TRY_COMPILE(
+ [
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+ ],
+ [
+ struct timespec t;
+ struct stat s = {0};
+ t = s.st_birthtimespec;
+ ],
+ samba_cv_stat_st_birthtimespec=yes, samba_cv_stat_birthtimespec=no)
+ ])
+
+if test x"$samba_cv_stat_st_birthtimespec" = x"yes" ; then
+ AC_DEFINE(HAVE_STAT_ST_BIRTHTIMESPEC, 1, [whether struct stat contains st_birthtimespec])
+fi
+
+AC_CACHE_CHECK([whether struct stat has st_birthtimensec], samba_cv_stat_st_birthtimensec,
+ [
+ AC_TRY_COMPILE(
+ [
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+ ],
+ [
+ struct timespec t;
+ struct stat s = {0};
+ t.tv_nsec = s.st_birthtimensec;
+ ],
+ samba_cv_stat_st_birthtimensec=yes, samba_cv_stat_birthtimensec=no)
+ ])
+
+if test x"$samba_cv_stat_st_birthtimensec" = x"yes" ; then
+ AC_DEFINE(HAVE_STAT_ST_BIRTHTIMENSEC, 1, [whether struct stat contains st_birthtimensec])
+fi
+
+AC_CACHE_CHECK([whether struct stat has st_birthtime], samba_cv_stat_st_birthtime,
+ [
+ AC_TRY_COMPILE(
+ [
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+# include <sys/time.h>
+# else
+# include <time.h>
+# endif
+#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+ ],
+ [
+ struct time_t t;
+ struct stat s = {0};
+ t = s.st_birthtime;
+ ],
+ samba_cv_stat_st_birthtime=yes, samba_cv_stat_birthtime=no)
+ ])
+
+if test x"$samba_cv_stat_st_birthtime" = x"yes" ; then
+ AC_DEFINE(HAVE_STAT_ST_BIRTHTIME, 1, [whether struct stat contains st_birthtime])
+fi
+
#####################################
# needed for SRV lookups
AC_CHECK_LIB(resolv, dn_expand)
diff --git a/source3/include/proto.h b/source3/include/proto.h
index d3a8dbbc7f..2145a892c6 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -1185,7 +1185,6 @@ void srv_put_dos_date2(char *buf,int offset, time_t unixdate);
void srv_put_dos_date3(char *buf,int offset,time_t unixdate);
void put_long_date_timespec(char *p, struct timespec ts);
void put_long_date(char *p, time_t t);
-time_t get_create_time(const SMB_STRUCT_STAT *st,bool fake_dirs);
struct timespec get_create_timespec(const SMB_STRUCT_STAT *st,bool fake_dirs);
struct timespec get_atimespec(const SMB_STRUCT_STAT *pst);
void set_atimespec(SMB_STRUCT_STAT *pst, struct timespec ts);
diff --git a/source3/lib/time.c b/source3/lib/time.c
index 9db88b3fc8..3cf0cb4f64 100644
--- a/source3/lib/time.c
+++ b/source3/lib/time.c
@@ -826,14 +826,10 @@ void put_long_date(char *p, time_t t)
structure.
****************************************************************************/
-time_t get_create_time(const SMB_STRUCT_STAT *st,bool fake_dirs)
+static time_t calc_create_time(const SMB_STRUCT_STAT *st)
{
time_t ret, ret1;
- if(S_ISDIR(st->st_mode) && fake_dirs) {
- return (time_t)315493200L; /* 1/1/1980 */
- }
-
ret = MIN(st->st_ctime, st->st_mtime);
ret1 = MIN(ret, st->st_atime);
@@ -848,12 +844,36 @@ time_t get_create_time(const SMB_STRUCT_STAT *st,bool fake_dirs)
return ret;
}
-struct timespec get_create_timespec(const SMB_STRUCT_STAT *st,bool fake_dirs)
+/****************************************************************************
+ Return the 'create time' from a stat struct if it exists (birthtime) or else
+ use the best approximation.
+****************************************************************************/
+
+struct timespec get_create_timespec(const SMB_STRUCT_STAT *pst,bool fake_dirs)
{
- struct timespec ts;
- ts.tv_sec = get_create_time(st, fake_dirs);
- ts.tv_nsec = 0;
- return ts;
+ struct timespec ret;
+
+ if(S_ISDIR(pst->st_mode) && fake_dirs) {
+ ret.tv_sec = 315493200L; /* 1/1/1980 */
+ ret.tv_nsec = 0;
+ return ret;
+ }
+
+#if defined(HAVE_STAT_ST_BIRTHTIMESPEC)
+ return pst->st_birthtimespec;
+#elif defined(HAVE_STAT_ST_BIRTHTIMENSEC)
+ ret.tv_sec = pst->st_birthtime;
+ ret.tv_nsec = pst->st_birthtimenspec;
+ return ret;
+#elif defined(HAVE_STAT_ST_BIRTHTIME)
+ ret.tv_sec = pst->st_birthtime;
+ ret.tv_nsec = 0;
+ return ret;
+#else
+ ret.tv_sec = calc_create_time(pst);
+ ret.tv_nsec = 0;
+ return ret;
+#endif
}
/****************************************************************************
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 06aa835cb0..ff38ac88cf 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -7126,6 +7126,7 @@ void reply_getattrE(struct smb_request *req)
SMB_STRUCT_STAT sbuf;
int mode;
files_struct *fsp;
+ struct timespec create_ts;
START_PROFILE(SMBgetattrE);
@@ -7160,9 +7161,9 @@ void reply_getattrE(struct smb_request *req)
reply_outbuf(req, 11, 0);
- srv_put_dos_date2((char *)req->outbuf, smb_vwv0,
- get_create_time(&sbuf,
- lp_fake_dir_create_times(SNUM(conn))));
+ create_ts = get_create_timespec(&sbuf,
+ lp_fake_dir_create_times(SNUM(conn)));
+ srv_put_dos_date2((char *)req->outbuf, smb_vwv0, create_ts.tv_sec);
srv_put_dos_date2((char *)req->outbuf, smb_vwv2, sbuf.st_atime);
/* Should we check pending modtime here ? JRA */
srv_put_dos_date2((char *)req->outbuf, smb_vwv4, sbuf.st_mtime);