mirror of
https://github.com/aaru-dps/fstester.git
synced 2025-12-16 19:24:39 +00:00
Set DOS timestamps using a for loop instead of repeating code.
This commit is contained in:
@@ -6,7 +6,7 @@ project(fssetter-dos
|
||||
DESCRIPTION "Filesystem test creator for DOS"
|
||||
LANGUAGES C)
|
||||
|
||||
set(PLATFORM_SOURCES attr.c deleted.c dirdepth.c filename.c files.c frag.c links.c os.c perms.c rsrcfork.c sparse.c time.c volume.c xattr.c dos.c attr.h)
|
||||
set(PLATFORM_SOURCES attr.c deleted.c dirdepth.c filename.c files.c frag.c links.c os.c perms.c rsrcfork.c sparse.c time.h time.c volume.c xattr.c dos.c attr.h)
|
||||
|
||||
set(EXECUTABLE_NAME "fssetter")
|
||||
|
||||
|
||||
@@ -42,8 +42,7 @@ Copyright (C) 2011-2021 Natalia Portillo
|
||||
|
||||
#include "../include/defs.h"
|
||||
#include "dos.h"
|
||||
|
||||
#define DATETIME_FORMAT "This file is dated %04d/%02d/%02d %02d:%02d:%02d for %s\n"
|
||||
#include "time.h"
|
||||
|
||||
void Timestamps(const char* path)
|
||||
{
|
||||
@@ -53,11 +52,7 @@ void Timestamps(const char* path)
|
||||
int handle;
|
||||
char message[300];
|
||||
union REGS regs;
|
||||
unsigned short maxtime = 0xBF7D;
|
||||
unsigned short maxdate = 0xFF9F;
|
||||
unsigned short y1kdate = 0x2621;
|
||||
unsigned short y2kdate = 0x2821;
|
||||
unsigned short mindate = 0x0021;
|
||||
int i;
|
||||
|
||||
if(driveNo > 32) driveNo -= 32;
|
||||
|
||||
@@ -76,341 +71,36 @@ void Timestamps(const char* path)
|
||||
|
||||
printf("Creating timestamped files.\n");
|
||||
|
||||
rc = _dos_creatnew("MAXCTIME", _A_NORMAL, &handle);
|
||||
|
||||
if(!rc)
|
||||
for(i = 0; i < KNOWN_DOS_TIMES; i++)
|
||||
{
|
||||
memset(&message, 0, 300);
|
||||
sprintf(&message,
|
||||
DATETIME_FORMAT,
|
||||
YEAR(maxdate),
|
||||
MONTH(maxdate),
|
||||
DAY(maxdate),
|
||||
HOUR(maxtime),
|
||||
MINUTE(maxtime),
|
||||
SECOND(maxtime),
|
||||
"creation");
|
||||
rc = _dos_creatnew(dos_times[i].filename, _A_NORMAL, &handle);
|
||||
|
||||
wRc = _dos_write(handle, &message, strlen(message), &actionTaken);
|
||||
memset(®s, 0, sizeof(regs));
|
||||
regs.w.bx = handle;
|
||||
regs.w.cx = maxtime;
|
||||
regs.w.dx = maxdate;
|
||||
regs.w.ax = 0x5707;
|
||||
int86(0x21, ®s, ®s);
|
||||
tRc = regs.w.ax;
|
||||
cRc = _dos_close(handle);
|
||||
if(!rc)
|
||||
{
|
||||
memset(message, 0, 300);
|
||||
sprintf(message,
|
||||
DATETIME_FORMAT,
|
||||
YEAR(dos_times[i].date),
|
||||
MONTH(dos_times[i].date),
|
||||
DAY(dos_times[i].date),
|
||||
HOUR(dos_times[i].time),
|
||||
MINUTE(dos_times[i].time),
|
||||
SECOND(dos_times[i].time),
|
||||
dos_times[i].definition);
|
||||
|
||||
wRc = _dos_write(handle, message, strlen(message), &actionTaken);
|
||||
memset(®s, 0, sizeof(regs));
|
||||
regs.w.bx = handle;
|
||||
regs.w.cx = dos_times[i].time;
|
||||
regs.w.dx = dos_times[i].date;
|
||||
regs.w.ax = dos_times[i].function;
|
||||
int86(0x21, ®s, ®s);
|
||||
tRc = regs.w.ax;
|
||||
cRc = _dos_close(handle);
|
||||
}
|
||||
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", dos_times[i].filename, rc, wRc, cRc, tRc);
|
||||
}
|
||||
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MAXCTIME", rc, wRc, cRc, tRc);
|
||||
|
||||
rc = _dos_creatnew("MINCTIME", _A_NORMAL, &handle);
|
||||
|
||||
if(!rc)
|
||||
{
|
||||
memset(&message, 0, 300);
|
||||
sprintf(&message,
|
||||
DATETIME_FORMAT,
|
||||
YEAR(mindate),
|
||||
MONTH(mindate),
|
||||
DAY(mindate),
|
||||
HOUR(0),
|
||||
MINUTE(0),
|
||||
SECOND(0),
|
||||
"creation");
|
||||
|
||||
wRc = _dos_write(handle, &message, strlen(message), &actionTaken);
|
||||
memset(®s, 0, sizeof(regs));
|
||||
regs.w.bx = handle;
|
||||
regs.w.cx = 0;
|
||||
regs.w.dx = mindate;
|
||||
regs.w.ax = 0x5707;
|
||||
int86(0x21, ®s, ®s);
|
||||
tRc = regs.w.ax;
|
||||
cRc = _dos_close(handle);
|
||||
}
|
||||
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MINCTIME", rc, wRc, cRc, tRc);
|
||||
|
||||
rc = _dos_creatnew("Y19CTIME", _A_NORMAL, &handle);
|
||||
|
||||
if(!rc)
|
||||
{
|
||||
memset(&message, 0, 300);
|
||||
sprintf(&message,
|
||||
DATETIME_FORMAT,
|
||||
YEAR(y1kdate),
|
||||
MONTH(y1kdate),
|
||||
DAY(y1kdate),
|
||||
HOUR(maxtime),
|
||||
MINUTE(maxtime),
|
||||
SECOND(maxtime),
|
||||
"creation");
|
||||
|
||||
wRc = _dos_write(handle, &message, strlen(message), &actionTaken);
|
||||
memset(®s, 0, sizeof(regs));
|
||||
regs.w.bx = handle;
|
||||
regs.w.cx = maxtime;
|
||||
regs.w.dx = y1kdate;
|
||||
regs.w.ax = 0x5707;
|
||||
int86(0x21, ®s, ®s);
|
||||
tRc = regs.w.ax;
|
||||
cRc = _dos_close(handle);
|
||||
}
|
||||
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y19CTIME", rc, wRc, cRc, tRc);
|
||||
|
||||
rc = _dos_creatnew("Y2KCTIME", _A_NORMAL, &handle);
|
||||
|
||||
if(!rc)
|
||||
{
|
||||
memset(&message, 0, 300);
|
||||
sprintf(&message,
|
||||
DATETIME_FORMAT,
|
||||
YEAR(y2kdate),
|
||||
MONTH(y2kdate),
|
||||
DAY(y2kdate),
|
||||
HOUR(0),
|
||||
MINUTE(0),
|
||||
SECOND(0),
|
||||
"creation");
|
||||
|
||||
wRc = _dos_write(handle, &message, strlen(message), &actionTaken);
|
||||
memset(®s, 0, sizeof(regs));
|
||||
regs.w.bx = handle;
|
||||
regs.w.cx = 0;
|
||||
regs.w.dx = y2kdate;
|
||||
regs.w.ax = 0x5707;
|
||||
int86(0x21, ®s, ®s);
|
||||
tRc = regs.w.ax;
|
||||
cRc = _dos_close(handle);
|
||||
}
|
||||
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y19CTIME", rc, wRc, cRc, tRc);
|
||||
|
||||
rc = _dos_creatnew("MAXWTIME", _A_NORMAL, &handle);
|
||||
|
||||
if(!rc)
|
||||
{
|
||||
memset(&message, 0, 300);
|
||||
sprintf(&message,
|
||||
DATETIME_FORMAT,
|
||||
YEAR(maxdate),
|
||||
MONTH(maxdate),
|
||||
DAY(maxdate),
|
||||
HOUR(maxtime),
|
||||
MINUTE(maxtime),
|
||||
SECOND(maxtime),
|
||||
"last written");
|
||||
|
||||
wRc = _dos_write(handle, &message, strlen(message), &actionTaken);
|
||||
memset(®s, 0, sizeof(regs));
|
||||
regs.w.bx = handle;
|
||||
regs.w.cx = maxtime;
|
||||
regs.w.dx = maxdate;
|
||||
regs.w.ax = 0x5701;
|
||||
int86(0x21, ®s, ®s);
|
||||
tRc = regs.w.ax;
|
||||
cRc = _dos_close(handle);
|
||||
}
|
||||
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MAXWTIME", rc, wRc, cRc, tRc);
|
||||
|
||||
rc = _dos_creatnew("MINWTIME", _A_NORMAL, &handle);
|
||||
|
||||
if(!rc)
|
||||
{
|
||||
memset(&message, 0, 300);
|
||||
sprintf(&message,
|
||||
DATETIME_FORMAT,
|
||||
YEAR(mindate),
|
||||
MONTH(mindate),
|
||||
DAY(mindate),
|
||||
HOUR(0),
|
||||
MINUTE(0),
|
||||
SECOND(0),
|
||||
"last written");
|
||||
|
||||
wRc = _dos_write(handle, &message, strlen(message), &actionTaken);
|
||||
memset(®s, 0, sizeof(regs));
|
||||
regs.w.bx = handle;
|
||||
regs.w.cx = 0;
|
||||
regs.w.dx = mindate;
|
||||
regs.w.ax = 0x5701;
|
||||
int86(0x21, ®s, ®s);
|
||||
tRc = regs.w.ax;
|
||||
cRc = _dos_close(handle);
|
||||
}
|
||||
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MINWTIME", rc, wRc, cRc, tRc);
|
||||
|
||||
rc = _dos_creatnew("Y19WTIME", _A_NORMAL, &handle);
|
||||
|
||||
if(!rc)
|
||||
{
|
||||
memset(&message, 0, 300);
|
||||
sprintf(&message,
|
||||
DATETIME_FORMAT,
|
||||
YEAR(y1kdate),
|
||||
MONTH(y1kdate),
|
||||
DAY(y1kdate),
|
||||
HOUR(maxtime),
|
||||
MINUTE(maxtime),
|
||||
SECOND(maxtime),
|
||||
"last written");
|
||||
|
||||
wRc = _dos_write(handle, &message, strlen(message), &actionTaken);
|
||||
memset(®s, 0, sizeof(regs));
|
||||
regs.w.bx = handle;
|
||||
regs.w.cx = maxtime;
|
||||
regs.w.dx = y1kdate;
|
||||
regs.w.ax = 0x5701;
|
||||
int86(0x21, ®s, ®s);
|
||||
tRc = regs.w.ax;
|
||||
cRc = _dos_close(handle);
|
||||
}
|
||||
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y19WTIME", rc, wRc, cRc, tRc);
|
||||
|
||||
rc = _dos_creatnew("Y2KWTIME", _A_NORMAL, &handle);
|
||||
|
||||
if(!rc)
|
||||
{
|
||||
memset(&message, 0, 300);
|
||||
sprintf(&message,
|
||||
DATETIME_FORMAT,
|
||||
YEAR(y2kdate),
|
||||
MONTH(y2kdate),
|
||||
DAY(y2kdate),
|
||||
HOUR(0),
|
||||
MINUTE(0),
|
||||
SECOND(0),
|
||||
"last written");
|
||||
|
||||
wRc = _dos_write(handle, &message, strlen(message), &actionTaken);
|
||||
memset(®s, 0, sizeof(regs));
|
||||
regs.w.bx = handle;
|
||||
regs.w.cx = 0;
|
||||
regs.w.dx = y2kdate;
|
||||
regs.w.ax = 0x5701;
|
||||
int86(0x21, ®s, ®s);
|
||||
tRc = regs.w.ax;
|
||||
cRc = _dos_close(handle);
|
||||
}
|
||||
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y2KWTIME", rc, wRc, cRc, tRc);
|
||||
|
||||
rc = _dos_creatnew("MAXATIME", _A_NORMAL, &handle);
|
||||
|
||||
if(!rc)
|
||||
{
|
||||
memset(&message, 0, 300);
|
||||
sprintf(&message,
|
||||
DATETIME_FORMAT,
|
||||
YEAR(maxdate),
|
||||
MONTH(maxdate),
|
||||
DAY(maxdate),
|
||||
HOUR(0),
|
||||
MINUTE(0),
|
||||
SECOND(0),
|
||||
"last access");
|
||||
|
||||
wRc = _dos_write(handle, &message, strlen(message), &actionTaken);
|
||||
memset(®s, 0, sizeof(regs));
|
||||
regs.w.bx = handle;
|
||||
regs.w.cx = 0;
|
||||
regs.w.dx = maxdate;
|
||||
regs.w.ax = 0x5705;
|
||||
int86(0x21, ®s, ®s);
|
||||
tRc = regs.w.ax;
|
||||
cRc = _dos_close(handle);
|
||||
}
|
||||
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MAXATIME", rc, wRc, cRc, tRc);
|
||||
|
||||
rc = _dos_creatnew("MINATIME", _A_NORMAL, &handle);
|
||||
|
||||
if(!rc)
|
||||
{
|
||||
memset(&message, 0, 300);
|
||||
sprintf(&message,
|
||||
DATETIME_FORMAT,
|
||||
YEAR(mindate),
|
||||
MONTH(mindate),
|
||||
DAY(mindate),
|
||||
HOUR(0),
|
||||
MINUTE(0),
|
||||
SECOND(0),
|
||||
"last access");
|
||||
|
||||
wRc = _dos_write(handle, &message, strlen(message), &actionTaken);
|
||||
memset(®s, 0, sizeof(regs));
|
||||
regs.w.bx = handle;
|
||||
regs.w.cx = 0;
|
||||
regs.w.dx = mindate;
|
||||
regs.w.ax = 0x5705;
|
||||
int86(0x21, ®s, ®s);
|
||||
tRc = regs.w.ax;
|
||||
cRc = _dos_close(handle);
|
||||
}
|
||||
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "MINATIME", rc, wRc, cRc, tRc);
|
||||
|
||||
rc = _dos_creatnew("Y19ATIME", _A_NORMAL, &handle);
|
||||
|
||||
if(!rc)
|
||||
{
|
||||
memset(&message, 0, 300);
|
||||
sprintf(&message,
|
||||
DATETIME_FORMAT,
|
||||
YEAR(y1kdate),
|
||||
MONTH(y1kdate),
|
||||
DAY(y1kdate),
|
||||
HOUR(0),
|
||||
MINUTE(0),
|
||||
SECOND(0),
|
||||
"last access");
|
||||
|
||||
wRc = _dos_write(handle, &message, strlen(message), &actionTaken);
|
||||
memset(®s, 0, sizeof(regs));
|
||||
regs.w.bx = handle;
|
||||
regs.w.cx = 0;
|
||||
regs.w.dx = y1kdate;
|
||||
regs.w.ax = 0x5705;
|
||||
int86(0x21, ®s, ®s);
|
||||
tRc = regs.w.ax;
|
||||
cRc = _dos_close(handle);
|
||||
}
|
||||
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y19ATIME", rc, wRc, cRc, tRc);
|
||||
|
||||
rc = _dos_creatnew("Y2KATIME", _A_NORMAL, &handle);
|
||||
|
||||
if(!rc)
|
||||
{
|
||||
memset(&message, 0, 300);
|
||||
sprintf(&message,
|
||||
DATETIME_FORMAT,
|
||||
YEAR(y2kdate),
|
||||
MONTH(y2kdate),
|
||||
DAY(y2kdate),
|
||||
HOUR(0),
|
||||
MINUTE(0),
|
||||
SECOND(0),
|
||||
"last access");
|
||||
|
||||
wRc = _dos_write(handle, &message, strlen(message), &actionTaken);
|
||||
memset(®s, 0, sizeof(regs));
|
||||
regs.w.bx = handle;
|
||||
regs.w.cx = 0;
|
||||
regs.w.dx = y2kdate;
|
||||
regs.w.ax = 0x5705;
|
||||
int86(0x21, ®s, ®s);
|
||||
tRc = regs.w.ax;
|
||||
cRc = _dos_close(handle);
|
||||
}
|
||||
|
||||
printf("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", "Y2KATIME", rc, wRc, cRc, tRc);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
77
setter/src/dos/time.h
Normal file
77
setter/src/dos/time.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/****************************************************************************
|
||||
Aaru Data Preservation Suite
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
Filename : time.h
|
||||
Author(s) : Natalia Portillo
|
||||
|
||||
--[ Description ] -----------------------------------------------------------
|
||||
|
||||
Contains DOS definitions
|
||||
|
||||
--[ License ] ---------------------------------------------------------------
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2021 Natalia Portillo
|
||||
*****************************************************************************/
|
||||
|
||||
#if defined(__DOS__) || defined(MSDOS)
|
||||
|
||||
#ifndef SETTER_SRC_DOS_TIME_H_
|
||||
#define SETTER_SRC_DOS_TIME_H_
|
||||
|
||||
#include <dos.h>
|
||||
|
||||
#define DATETIME_FORMAT "This file is dated %04d/%02d/%02d %02d:%02d:%02d for %s\n"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char filename[9];
|
||||
unsigned short date;
|
||||
unsigned short time;
|
||||
unsigned short function;
|
||||
char definition[13];
|
||||
} dos_time_tests_t;
|
||||
|
||||
#define KNOWN_DOS_TIMES 12
|
||||
|
||||
#define WIN_SET_CREATION_DATE_AND_TIME 0x5707
|
||||
#define DOS_SET_LAST_WRITTEN_DATE_AND_TIME 0x5701
|
||||
#define WIN_SET_LAST_ACCESS_DATE_AND_TIME 0x5705
|
||||
|
||||
#define MAX_TIME 0xBF7D
|
||||
#define MAX_DATE 0xFF9F
|
||||
#define Y1K_DATE 0x2621
|
||||
#define Y2K_DATE 0x2821
|
||||
#define MIN_DATE 0x0021
|
||||
|
||||
static const dos_time_tests_t dos_times[KNOWN_DOS_TIMES] = {
|
||||
{"MAXCTIME",MAX_DATE, MAX_TIME, WIN_SET_CREATION_DATE_AND_TIME, "creation"},
|
||||
{"MINCTIME",MIN_DATE, 0, WIN_SET_CREATION_DATE_AND_TIME, "creation"},
|
||||
{"Y19CTIME",Y1K_DATE, MAX_TIME, WIN_SET_CREATION_DATE_AND_TIME, "creation"},
|
||||
{"Y2KCTIME",Y2K_DATE, MAX_TIME, WIN_SET_CREATION_DATE_AND_TIME, "creation"},
|
||||
{"MAXWTIME",MAX_DATE, MAX_TIME, DOS_SET_LAST_WRITTEN_DATE_AND_TIME, "last written"},
|
||||
{"MINWTIME",MIN_DATE, 0, DOS_SET_LAST_WRITTEN_DATE_AND_TIME, "last written"},
|
||||
{"Y19WTIME",Y1K_DATE, MAX_TIME, DOS_SET_LAST_WRITTEN_DATE_AND_TIME, "last written"},
|
||||
{"Y2KWTIME",Y2K_DATE, MAX_TIME, DOS_SET_LAST_WRITTEN_DATE_AND_TIME, "last written"},
|
||||
{"MAXATIME",MAX_DATE, MAX_TIME, WIN_SET_LAST_ACCESS_DATE_AND_TIME, "last access"},
|
||||
{"MINATIME",MIN_DATE, 0, WIN_SET_LAST_ACCESS_DATE_AND_TIME, "last access"},
|
||||
{"Y19ATIME",Y1K_DATE, MAX_TIME, WIN_SET_LAST_ACCESS_DATE_AND_TIME, "last access"},
|
||||
{"Y2KATIME",Y2K_DATE, MAX_TIME, WIN_SET_LAST_ACCESS_DATE_AND_TIME, "last access"},
|
||||
};
|
||||
|
||||
#endif // SETTER_SRC_DOS_TIME_H_
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user