mirror of
https://github.com/aaru-dps/fstester.git
synced 2025-12-16 19:24:39 +00:00
Implement Timestamps() for UNIX et al.
This commit is contained in:
275
setter/unix.c
275
setter/unix.c
@@ -48,6 +48,7 @@ Copyright (C) 2011-2018 Natalia Portillo
|
||||
#include <sys/types.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <unistd.h>
|
||||
#include <utime.h>
|
||||
|
||||
void GetOsInfo()
|
||||
{
|
||||
@@ -519,7 +520,279 @@ void Filenames(const char *path)
|
||||
|
||||
void Timestamps(const char *path)
|
||||
{
|
||||
// TODO: Implement
|
||||
char message[300];
|
||||
int ret;
|
||||
time_t ftLastAccessTime;
|
||||
time_t ftLastWriteTime;
|
||||
FILE * h;
|
||||
int rc, wRc, cRc, tRc;
|
||||
struct utimbuf times;
|
||||
|
||||
ret = chdir(path);
|
||||
|
||||
if(ret)
|
||||
{
|
||||
printf("Error %d changing to specified path.\n", errno);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = mkdir("TIMES", 0755);
|
||||
|
||||
if(ret)
|
||||
{
|
||||
printf("Error %d creating working directory.\n", errno);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = chdir("TIMES");
|
||||
|
||||
if(ret)
|
||||
{
|
||||
printf("Error %d changing to working directory.\n", errno);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("Creating timestamped files.\n");
|
||||
|
||||
memset(×, 0, sizeof(struct utimbuf));
|
||||
h = fopen("MAXATIME", "w+");
|
||||
rc = 0;
|
||||
wRc = 0;
|
||||
cRc = 0;
|
||||
tRc = 0;
|
||||
if(h == NULL) { rc = errno; }
|
||||
else
|
||||
{
|
||||
memset(&message, 0, 300);
|
||||
sprintf((char *)message, DATETIME_FORMAT, MAXDATETIME, "access");
|
||||
times.actime = MAXTIMESTAMP;
|
||||
|
||||
ret = fprintf(h, message);
|
||||
if(ret < 0) { wRc = errno; }
|
||||
|
||||
ret = fclose(h);
|
||||
if(ret) { cRc = errno; }
|
||||
|
||||
ret = utime("MAXATIME", ×);
|
||||
if(ret) { tRc = errno; }
|
||||
}
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MAXATIME", rc, wRc, cRc, tRc);
|
||||
|
||||
memset(×, 0, sizeof(struct utimbuf));
|
||||
h = fopen("MAXMTIME", "w+");
|
||||
rc = 0;
|
||||
wRc = 0;
|
||||
cRc = 0;
|
||||
tRc = 0;
|
||||
if(h == NULL) { rc = errno; }
|
||||
else
|
||||
{
|
||||
memset(&message, 0, 300);
|
||||
sprintf((char *)message, DATETIME_FORMAT, MAXDATETIME, "modification");
|
||||
times.modtime = MAXTIMESTAMP;
|
||||
|
||||
ret = fprintf(h, message);
|
||||
if(ret < 0) { wRc = errno; }
|
||||
|
||||
ret = fclose(h);
|
||||
if(ret) { cRc = errno; }
|
||||
|
||||
ret = utime("MAXMTIME", ×);
|
||||
if(ret) { tRc = errno; }
|
||||
}
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MAXMTIME", rc, wRc, cRc, tRc);
|
||||
|
||||
memset(×, 0, sizeof(struct utimbuf));
|
||||
h = fopen("MINATIME", "w+");
|
||||
rc = 0;
|
||||
wRc = 0;
|
||||
cRc = 0;
|
||||
tRc = 0;
|
||||
if(h == NULL) { rc = errno; }
|
||||
else
|
||||
{
|
||||
memset(&message, 0, 300);
|
||||
sprintf((char *)message, DATETIME_FORMAT, MINDATETIME, "access");
|
||||
times.actime = MINTIMESTAMP;
|
||||
|
||||
ret = fprintf(h, message);
|
||||
if(ret < 0) { wRc = errno; }
|
||||
|
||||
ret = fclose(h);
|
||||
if(ret) { cRc = errno; }
|
||||
|
||||
ret = utime("MINATIME", ×);
|
||||
if(ret) { tRc = errno; }
|
||||
}
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MINATIME", rc, wRc, cRc, tRc);
|
||||
|
||||
memset(×, 0, sizeof(struct utimbuf));
|
||||
h = fopen("MINMTIME", "w+");
|
||||
rc = 0;
|
||||
wRc = 0;
|
||||
cRc = 0;
|
||||
tRc = 0;
|
||||
if(h == NULL) { rc = errno; }
|
||||
else
|
||||
{
|
||||
memset(&message, 0, 300);
|
||||
sprintf((char *)message, DATETIME_FORMAT, MINDATETIME, "modification");
|
||||
times.modtime = MINTIMESTAMP;
|
||||
|
||||
ret = fprintf(h, message);
|
||||
if(ret < 0) { wRc = errno; }
|
||||
|
||||
ret = fclose(h);
|
||||
if(ret) { cRc = errno; }
|
||||
|
||||
ret = utime("MINMTIME", ×);
|
||||
if(ret) { tRc = errno; }
|
||||
}
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MINMTIME", rc, wRc, cRc, tRc);
|
||||
|
||||
memset(×, 0, sizeof(struct utimbuf));
|
||||
h = fopen("Y1KATIME", "w+");
|
||||
rc = 0;
|
||||
wRc = 0;
|
||||
cRc = 0;
|
||||
tRc = 0;
|
||||
if(h == NULL) { rc = errno; }
|
||||
else
|
||||
{
|
||||
memset(&message, 0, 300);
|
||||
sprintf((char *)message, DATETIME_FORMAT, Y1KDATETIME, "access");
|
||||
times.actime = Y1KTIMESTAMP;
|
||||
|
||||
ret = fprintf(h, message);
|
||||
if(ret < 0) { wRc = errno; }
|
||||
|
||||
ret = fclose(h);
|
||||
if(ret) { cRc = errno; }
|
||||
|
||||
ret = utime("Y1KATIME", ×);
|
||||
if(ret) { tRc = errno; }
|
||||
}
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y1KATIME", rc, wRc, cRc, tRc);
|
||||
|
||||
memset(×, 0, sizeof(struct utimbuf));
|
||||
h = fopen("Y1KMTIME", "w+");
|
||||
rc = 0;
|
||||
wRc = 0;
|
||||
cRc = 0;
|
||||
tRc = 0;
|
||||
if(h == NULL) { rc = errno; }
|
||||
else
|
||||
{
|
||||
memset(&message, 0, 300);
|
||||
sprintf((char *)message, DATETIME_FORMAT, Y1KDATETIME, "modification");
|
||||
times.modtime = Y1KTIMESTAMP;
|
||||
|
||||
ret = fprintf(h, message);
|
||||
if(ret < 0) { wRc = errno; }
|
||||
|
||||
ret = fclose(h);
|
||||
if(ret) { cRc = errno; }
|
||||
|
||||
ret = utime("Y1KMTIME", ×);
|
||||
if(ret) { tRc = errno; }
|
||||
}
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y1KMTIME", rc, wRc, cRc, tRc);
|
||||
|
||||
memset(×, 0, sizeof(struct utimbuf));
|
||||
h = fopen("Y2KATIME", "w+");
|
||||
rc = 0;
|
||||
wRc = 0;
|
||||
cRc = 0;
|
||||
tRc = 0;
|
||||
if(h == NULL) { rc = errno; }
|
||||
else
|
||||
{
|
||||
memset(&message, 0, 300);
|
||||
sprintf((char *)message, DATETIME_FORMAT, Y2KDATETIME, "access");
|
||||
times.actime = Y2KTIMESTAMP;
|
||||
|
||||
ret = fprintf(h, message);
|
||||
if(ret < 0) { wRc = errno; }
|
||||
|
||||
ret = fclose(h);
|
||||
if(ret) { cRc = errno; }
|
||||
|
||||
ret = utime("Y2KATIME", ×);
|
||||
if(ret) { tRc = errno; }
|
||||
}
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y2KATIME", rc, wRc, cRc, tRc);
|
||||
|
||||
memset(×, 0, sizeof(struct utimbuf));
|
||||
h = fopen("Y2KMTIME", "w+");
|
||||
rc = 0;
|
||||
wRc = 0;
|
||||
cRc = 0;
|
||||
tRc = 0;
|
||||
if(h == NULL) { rc = errno; }
|
||||
else
|
||||
{
|
||||
memset(&message, 0, 300);
|
||||
sprintf((char *)message, DATETIME_FORMAT, Y1KDATETIME, "modification");
|
||||
times.modtime = Y2KTIMESTAMP;
|
||||
|
||||
ret = fprintf(h, message);
|
||||
if(ret < 0) { wRc = errno; }
|
||||
|
||||
ret = fclose(h);
|
||||
if(ret) { cRc = errno; }
|
||||
|
||||
ret = utime("Y2KMTIME", ×);
|
||||
if(ret) { tRc = errno; }
|
||||
}
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y2KMTIME", rc, wRc, cRc, tRc);
|
||||
|
||||
memset(×, 0, sizeof(struct utimbuf));
|
||||
h = fopen("LESSATIME", "w+");
|
||||
rc = 0;
|
||||
wRc = 0;
|
||||
cRc = 0;
|
||||
tRc = 0;
|
||||
if(h == NULL) { rc = errno; }
|
||||
else
|
||||
{
|
||||
memset(&message, 0, 300);
|
||||
sprintf((char *)message, DATETIME_FORMAT, LESSDATETIME, "access");
|
||||
times.actime = LESSTIMESTAMP;
|
||||
|
||||
ret = fprintf(h, message);
|
||||
if(ret < 0) { wRc = errno; }
|
||||
|
||||
ret = fclose(h);
|
||||
if(ret) { cRc = errno; }
|
||||
|
||||
ret = utime("LESSATIME", ×);
|
||||
if(ret) { tRc = errno; }
|
||||
}
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "LESSATIME", rc, wRc, cRc, tRc);
|
||||
|
||||
memset(×, 0, sizeof(struct utimbuf));
|
||||
h = fopen("LESSMTIME", "w+");
|
||||
rc = 0;
|
||||
wRc = 0;
|
||||
cRc = 0;
|
||||
tRc = 0;
|
||||
if(h == NULL) { rc = errno; }
|
||||
else
|
||||
{
|
||||
memset(&message, 0, 300);
|
||||
sprintf((char *)message, DATETIME_FORMAT, LESSDATETIME, "modification");
|
||||
times.modtime = LESSTIMESTAMP;
|
||||
|
||||
ret = fprintf(h, message);
|
||||
if(ret < 0) { wRc = errno; }
|
||||
|
||||
ret = fclose(h);
|
||||
if(ret) { cRc = errno; }
|
||||
|
||||
ret = utime("LESSMTIME", ×);
|
||||
if(ret) { tRc = errno; }
|
||||
}
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "LESSMTIME", rc, wRc, cRc, tRc);
|
||||
}
|
||||
|
||||
void DirectoryDepth(const char *path)
|
||||
|
||||
@@ -375,6 +375,18 @@
|
||||
#define ST_NODIRATIME 2048
|
||||
#endif
|
||||
|
||||
#define DATETIME_FORMAT "This file is dated %s for %s\n"
|
||||
#define LESSDATETIME "2106/02/07 06:28:15 or unknown"
|
||||
#define MAXDATETIME "2038/01/19 03:14:07"
|
||||
#define MINDATETIME "1970/01/01 00:00:00"
|
||||
#define Y2KDATETIME "2000/01/01 00:00:00"
|
||||
#define Y1KDATETIME "1999/12/31 23:59:59"
|
||||
#define LESSTIMESTAMP 0xFFFFFFFF
|
||||
#define MAXTIMESTAMP 0x7FFFFFFF
|
||||
#define MINTIMESTAMP 0x00000000
|
||||
#define Y2KTIMESTAMP 0x386D4380
|
||||
#define Y1KTIMESTAMP 0x386D437F
|
||||
|
||||
#endif
|
||||
|
||||
#endif // SETTER_UNIX_H
|
||||
|
||||
Reference in New Issue
Block a user