summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>1998-01-24 08:49:21 +0000
committerJeremy Allison <jra@samba.org>1998-01-24 08:49:21 +0000
commit4f650dab6f867bda2beeeda71b2b97e75834853f (patch)
treeb67637d60b942fc454301cbc614c91613901284a /source3
parenta215c98602c0849819a50de6b13f8c41824ef08a (diff)
downloadsamba-4f650dab6f867bda2beeeda71b2b97e75834853f.tar.gz
samba-4f650dab6f867bda2beeeda71b2b97e75834853f.tar.bz2
samba-4f650dab6f867bda2beeeda71b2b97e75834853f.zip
Added get_create_time() function to time.c.
This gets the minimum timestamp associated with a file. reply.c and trans2.c then return this as the create time. Designed to fix problems with VC++ and others. Jeremy. (This used to be commit e3d5f6196d6eff707c78941696a368216e2a7410)
Diffstat (limited to 'source3')
-rw-r--r--source3/include/proto.h1
-rw-r--r--source3/lib/time.c19
-rw-r--r--source3/smbd/reply.c2
-rw-r--r--source3/smbd/trans2.c15
4 files changed, 30 insertions, 7 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 3d478b9246..f422b8fc90 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -1338,6 +1338,7 @@ time_t make_unix_date(void *date_ptr);
time_t make_unix_date2(void *date_ptr);
time_t make_unix_date3(void *date_ptr);
char *timestring(void );
+time_t get_create_time(struct stat *st);
/*The following definitions come from trans2.c */
diff --git a/source3/lib/time.c b/source3/lib/time.c
index 5e6d01215f..f60af60c7a 100644
--- a/source3/lib/time.c
+++ b/source3/lib/time.c
@@ -480,3 +480,22 @@ char *timestring(void )
return(TimeBuf);
}
+/****************************************************************************
+ return the best approximation to a 'create time' under UNIX from a stat
+ structure.
+****************************************************************************/
+
+time_t get_create_time(struct stat *st)
+{
+ time_t ret = MIN(st->st_ctime, st->st_mtime);
+ time_t ret1 = MIN(ret, st->st_atime);
+
+ if(ret1 != (time_t)0)
+ return ret1;
+
+ /*
+ * One of ctime, mtime or atime was zero (probably atime).
+ * Just return MIN(ctime, mtime).
+ */
+ return ret;
+}
diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c
index 746c79db21..4703dea475 100644
--- a/source3/smbd/reply.c
+++ b/source3/smbd/reply.c
@@ -3916,7 +3916,7 @@ int reply_getattrE(char *inbuf,char *outbuf)
/* Convert the times into dos times. Set create
date to be last modify date as UNIX doesn't save
this */
- put_dos_date2(outbuf,smb_vwv0,sbuf.st_mtime);
+ put_dos_date2(outbuf,smb_vwv0,get_create_time(&sbuf));
put_dos_date2(outbuf,smb_vwv2,sbuf.st_atime);
put_dos_date2(outbuf,smb_vwv4,sbuf.st_mtime);
if (mode & aDIR)
diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c
index 56843e0423..eb8356cc53 100644
--- a/source3/smbd/trans2.c
+++ b/source3/smbd/trans2.c
@@ -362,7 +362,7 @@ static int get_lanman2_dir_entry(int cnum,char *path_mask,int dirtype,int info_l
size = sbuf.st_size;
mdate = sbuf.st_mtime;
adate = sbuf.st_atime;
- cdate = sbuf.st_ctime;
+ cdate = get_create_time(&sbuf);
if(mode & aDIR)
size = 0;
@@ -1114,7 +1114,7 @@ static int call_trans2qfilepathinfo(char *inbuf, char *outbuf, int length,
case SMB_INFO_STANDARD:
case SMB_INFO_QUERY_EA_SIZE:
data_size = (info_level==1?22:26);
- put_dos_date2(pdata,l1_fdateCreation,sbuf.st_ctime); /* create = inode mod */
+ put_dos_date2(pdata,l1_fdateCreation,get_create_time(&sbuf));
put_dos_date2(pdata,l1_fdateLastAccess,sbuf.st_atime); /* access time */
put_dos_date2(pdata,l1_fdateLastWrite,sbuf.st_mtime); /* write time */
SIVAL(pdata,l1_cbFile,size);
@@ -1125,7 +1125,7 @@ static int call_trans2qfilepathinfo(char *inbuf, char *outbuf, int length,
case SMB_INFO_QUERY_EAS_FROM_LIST:
data_size = 24;
- put_dos_date2(pdata,0,sbuf.st_ctime); /* create time = inode mod time */
+ put_dos_date2(pdata,0,get_create_time(&sbuf));
put_dos_date2(pdata,4,sbuf.st_atime);
put_dos_date2(pdata,8,sbuf.st_mtime);
SIVAL(pdata,12,size);
@@ -1143,14 +1143,17 @@ static int call_trans2qfilepathinfo(char *inbuf, char *outbuf, int length,
case SMB_QUERY_FILE_BASIC_INFO:
data_size = 36; /* w95 returns 40 bytes not 36 - why ?. */
- put_long_date(pdata,sbuf.st_ctime); /* create time = inode mod time */
+ put_long_date(pdata,get_create_time(&sbuf));
put_long_date(pdata+8,sbuf.st_atime); /* access time */
put_long_date(pdata+16,sbuf.st_mtime); /* write time */
put_long_date(pdata+24,sbuf.st_mtime); /* change time */
SIVAL(pdata,32,mode);
DEBUG(5,("SMB_QFBI - "));
- DEBUG(5,("create: %s ", ctime(&sbuf.st_ctime)));
+ {
+ time_t create_time = get_create_time(&sbuf);
+ DEBUG(5,("create: %s ", ctime(&create_time)));
+ }
DEBUG(5,("access: %s ", ctime(&sbuf.st_atime)));
DEBUG(5,("write: %s ", ctime(&sbuf.st_mtime)));
DEBUG(5,("change: %s ", ctime(&sbuf.st_mtime)));
@@ -1204,7 +1207,7 @@ static int call_trans2qfilepathinfo(char *inbuf, char *outbuf, int length,
break;
case SMB_QUERY_FILE_ALL_INFO:
- put_long_date(pdata,sbuf.st_ctime); /* create time = inode mod time */
+ put_long_date(pdata,get_create_time(&sbuf));
put_long_date(pdata+8,sbuf.st_atime); /* access time */
put_long_date(pdata+16,sbuf.st_mtime); /* write time */
put_long_date(pdata+24,sbuf.st_mtime); /* change time */