From e6431ce2a9a0f1cbd6ac6aed717227f7a4f4f102 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sun, 25 Apr 2021 19:56:05 +0100 Subject: [PATCH] Implement links for Atari ST. --- setter/src/atarist/links.c | 69 +++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/setter/src/atarist/links.c b/setter/src/atarist/links.c index 3f9456f..239ec83 100644 --- a/setter/src/atarist/links.c +++ b/setter/src/atarist/links.c @@ -22,8 +22,75 @@ Aaru Data Preservation Suite Copyright (C) 2011-2021 Natalia Portillo *****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include + #include "../include/defs.h" +#include "../log.h" void Links(const char* path) -{ // TODO: MiNT. MagiC? +{ + long** cookieJar = _p_cookies; + long cookie; + int rc; + FILE* h; + char driveNo = path[0] - '@'; + + // Check for a cookie jar + if(*cookieJar == 0) return; + + // Check if MiNT or MagiC + rc = (Getcookie(C_MiNT, &cookie) == E_OK) || (Getcookie(C_MagX, &cookie) == E_OK) || + (Getcookie(C_MgMc, &cookie) == E_OK) || (Getcookie(C_MgMx, &cookie) == E_OK) || + (Getcookie(C_MgPC, &cookie) == E_OK); + + if(rc == 0) return; + + if(driveNo > 32) driveNo -= 32; + + Dsetdrv(driveNo); + Dsetpath("\\"); + + rc = Dcreate("LINKS"); + + if(rc != E_OK) + { + log_write("Error %d creating working directory.\n", rc); + return; + } + + rc = Dsetpath("LINKS"); + + if(rc != E_OK) + { + log_write("Error %d changing to working directory.\n", rc); + return; + } + + log_write("Creating links.\n"); + + h = fopen("TARGET", "w+"); + + if(h == NULL) + { + log_write("Error %d creating target file.\n", errno); + return; + } + + fprintf(h, "This is the target for the links.\n"); + + fclose(h); + + rc = Flink("TARGET", "HARD"); + + if(rc != E_OK) log_write("Error %d creating hard link.\n", errno); + + rc = Fsymlink("TARGET", "SYMBOLIC"); + + if(rc != E_OK) log_write("Error %d creating symbolic link.\n", errno); }