From 9de8b4d75206f13bdfb7851754164fe37fac2630 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 25 Apr 2021 18:25:50 +0100 Subject: [PATCH] Implement timestamps for Atari ST. --- setter/src/atarist/CMakeLists.txt | 2 +- setter/src/atarist/time.c | 93 +++++++++++++++++++++++++++++++ setter/src/atarist/tostime.h | 60 ++++++++++++++++++++ 3 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 setter/src/atarist/time.c create mode 100644 setter/src/atarist/tostime.h diff --git a/setter/src/atarist/CMakeLists.txt b/setter/src/atarist/CMakeLists.txt index 367a3e0..cf949a4 100644 --- a/setter/src/atarist/CMakeLists.txt +++ b/setter/src/atarist/CMakeLists.txt @@ -26,4 +26,4 @@ if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "MiNT") return() endif() -add_sources(attr.c attr.h 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) +add_sources(attr.c attr.h deleted.c dirdepth.c filename.c files.c frag.c links.c os.c perms.c rsrcfork.c sparse.c time.c tostime.h volume.c xattr.c) diff --git a/setter/src/atarist/time.c b/setter/src/atarist/time.c new file mode 100644 index 0000000..d8a8feb --- /dev/null +++ b/setter/src/atarist/time.c @@ -0,0 +1,93 @@ +/**************************************************************************** +Aaru Data Preservation Suite +----------------------------------------------------------------------------- + + Author(s) : Natalia Portillo + +--[ 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 . + +----------------------------------------------------------------------------- +Copyright (C) 2011-2021 Natalia Portillo +*****************************************************************************/ + +#include +#include +#include +#include +#include + +#include "../include/defs.h" +#include "../log.h" +#include "tostime.h" + +void Timestamps(const char* path) +{ + char driveNo = path[0] - '@'; + unsigned int rc, wRc = 0, cRc = 0, tRc = 0; + int handle; + char message[300]; + int i; + _DOSTIME timestamp; + + if(driveNo > 32) driveNo -= 32; + + Dsetdrv(driveNo); + Dsetpath("\\"); + + rc = Dcreate("TIMES"); + + if(rc != E_OK) + { + log_write("Cannot create working directory.\n"); + return; + } + + Dsetpath("TIMES"); + + log_write("Creating timestamped files.\n"); + + for(i = 0; i < KNOWN_ATARI_TIMES; i++) + { + rc = Fcreate(atari_times[i].filename, 0); + + if(rc > 0) + { + memset(message, 0, 300); + sprintf(message, + DATETIME_FORMAT, + YEAR(atari_times[i].date), + MONTH(atari_times[i].date), + DAY(atari_times[i].date), + HOUR(atari_times[i].time), + MINUTE(atari_times[i].time), + SECOND(atari_times[i].time), + atari_times[i].definition); + + timestamp.date = atari_times[i].date; + timestamp.time = atari_times[i].time; + + wRc = Fwrite(handle, strlen(message), message); + tRc = Fdatime(×tamp, handle, 1); + cRc = Fclose(handle); + } + + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", + atari_times[i].filename, + rc, + wRc, + cRc, + tRc); + } +} diff --git a/setter/src/atarist/tostime.h b/setter/src/atarist/tostime.h new file mode 100644 index 0000000..f2a198b --- /dev/null +++ b/setter/src/atarist/tostime.h @@ -0,0 +1,60 @@ +/**************************************************************************** +Aaru Data Preservation Suite +----------------------------------------------------------------------------- + + Author(s) : Natalia Portillo + +--[ 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 . + +----------------------------------------------------------------------------- +Copyright (C) 2011-2021 Natalia Portillo +*****************************************************************************/ + +#ifndef AARU_FSTESTER_SETTER_SRC_ATARI_TIME_H_ +#define AARU_FSTESTER_SETTER_SRC_ATARI_TIME_H_ + +#define DATETIME_FORMAT "This file is dated %04d/%02d/%02d %02d:%02d:%02d for %s\n" + +#define YEAR(t) ((((t)&0xFE00) >> 9) + 1980) +#define MONTH(t) (((t)&0x01E0) >> 5) +#define DAY(t) ((t)&0x001F) +#define HOUR(t) (((t)&0xF800) >> 11) +#define MINUTE(t) (((t)&0x07E0) >> 5) +#define SECOND(t) (((t)&0x001F) << 1) + +typedef struct +{ + char filename[9]; + unsigned short date; + unsigned short time; + char definition[13]; +} atari_time_tests_t; + +#define KNOWN_ATARI_TIMES 12 + +#define MAX_TIME 0xBF7D +#define MAX_DATE 0xFF9F +#define Y1K_DATE 0x2621 +#define Y2K_DATE 0x2821 +#define MIN_DATE 0x0021 + +static const atari_time_tests_t atari_times[KNOWN_ATARI_TIMES] = { + {"MAXWTIME", MAX_DATE, MAX_TIME, "last written"}, + {"MINWTIME", MIN_DATE, 0, "last written"}, + {"Y19WTIME", Y1K_DATE, MAX_TIME, "last written"}, + {"Y2KWTIME", Y2K_DATE, MAX_TIME, "last written"}, +}; + +#endif // AARU_FSTESTER_SETTER_SRC_ATARI_TIME_H_