diff --git a/setter/src/amiga/CMakeLists.txt b/setter/src/amiga/CMakeLists.txt index b936c3b..d013663 100644 --- a/setter/src/amiga/CMakeLists.txt +++ b/setter/src/amiga/CMakeLists.txt @@ -33,7 +33,7 @@ project( add_definitions(-D__USE_INLINE__) -set(PLATFORM_SOURCES attr.c deleted.c dirdepth.c filename.c files.c frag.c links.c os.c perms.c perms.h rsrcfork.c sparse.c time.c volume.c xattr.c) +set(PLATFORM_SOURCES attr.c deleted.c dirdepth.c filename.c files.c frag.c links.c os.c perms.c perms.h rsrcfork.c sparse.c time.c time.h volume.c xattr.c) set(EXECUTABLE_NAME "fssetter-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}") diff --git a/setter/src/amiga/time.c b/setter/src/amiga/time.c index 2aed506..c39dd94 100644 --- a/setter/src/amiga/time.c +++ b/setter/src/amiga/time.c @@ -22,9 +22,82 @@ Aaru Data Preservation Suite Copyright (C) 2011-2021 Natalia Portillo *****************************************************************************/ +#include +#include +#include + +#include "time.h" + #include "../include/defs.h" +#include "../log.h" void Timestamps(const char* path) { - // TODO + BPTR pathLock; + BPTR dirLock; + int ret; + BPTR h; + int rc, wRc, cRc, tRc; + struct DateStamp times; + int i; + char buffer[256]; + + pathLock = Lock((CONST_STRPTR)path, SHARED_LOCK); + + if(!pathLock) + { + log_write("Error %d changing to specified path.\n", IoErr()); + return; + } + + CurrentDir(pathLock); + + dirLock = CreateDir((CONST_STRPTR) "TIMES"); + + if(!dirLock) + { + log_write("Error %d creating working directory.\n", IoErr()); + return; + } + + CurrentDir(dirLock); + + log_write("Creating timestamped files.\n"); + + for(i = 0; i < KNOWN_AMIGA_TIMES; i++) + { + memset(×, 0, sizeof(struct DateStamp)); + h = Open((CONST_STRPTR)amiga_times[i].filename, MODE_NEWFILE); + rc = 0; + wRc = 0; + cRc = 0; + tRc = 0; + + if(!h) rc = IoErr(); + else + { + times.ds_Days = amiga_times[i].days; + times.ds_Minute = amiga_times[i].minutes; + times.ds_Tick = amiga_times[i].ticks; + + memset(buffer, 0, 255); + snprintf(buffer, 255, DATETIME_FORMAT, amiga_times[i].message); + + ret = Write(h, buffer, 255); + if(ret < 0) wRc = IoErr(); + + ret = Close(h); + if(!ret) cRc = IoErr(); + + ret = SetFileDate((CONST_STRPTR)amiga_times[i].filename, ×); + if(!ret) tRc = IoErr(); + } + + log_write("\tFile name = \"%s\", rc = %d, wRc = %d, cRc = %d, tRc = %d\n", + amiga_times[i].filename, + rc, + wRc, + cRc, + tRc); + } } diff --git a/setter/src/amiga/time.h b/setter/src/amiga/time.h new file mode 100644 index 0000000..86458b6 --- /dev/null +++ b/setter/src/amiga/time.h @@ -0,0 +1,51 @@ +/**************************************************************************** +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_AMIGA_TIME_H_ +#define AARU_FSTESTER_SETTER_SRC_AMIGA_TIME_H_ + +#define DATETIME_FORMAT "This file is dated %s\n" +#define MAXDATETIME "5881588/01/20 23:59:59.98" +#define MINDATETIME "-5877633/01/01 00:00:00" +#define ZERODATETIME "1978/01/01 00:00:00" +#define Y2KDATETIME "2000/01/01 00:00:00" +#define Y1KDATETIME "1999/12/31 23:59:59" + +typedef struct +{ + char* filename; + char message[32]; + LONG days; + LONG minutes; + LONG ticks; +} amiga_time_tests_t; + +#define KNOWN_AMIGA_TIMES 5 + +static const amiga_time_tests_t amiga_times[KNOWN_AMIGA_TIMES] = { + "MAX", MAXDATETIME, 0x7FFFFFFF, 1439, 2999, "MIN", MINDATETIME, 0xFFFFFFFF, 0, + 0, "ZERO", ZERODATETIME, 0, 0, 0, "Y2K", Y2KDATETIME, 8035, + 0, 0, "Y1K", Y1KDATETIME, 8034, 1439, 2950}; + +#endif // AARU_FSTESTER_SETTER_SRC_AMIGA_TIME_H_