From 06cd06d1802758472f75fb0e1170c753bc190430 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 19 Apr 2021 04:18:43 +0100 Subject: [PATCH] Implement sparse files for AmigaOS. --- setter/src/amiga/sparse.c | 100 +++++++++++++++++++++++++++++++++++++- 1 file changed, 99 insertions(+), 1 deletion(-) diff --git a/setter/src/amiga/sparse.c b/setter/src/amiga/sparse.c index 743d704..8a61e58 100644 --- a/setter/src/amiga/sparse.c +++ b/setter/src/amiga/sparse.c @@ -22,9 +22,107 @@ Aaru Data Preservation Suite Copyright (C) 2011-2021 Natalia Portillo *****************************************************************************/ +#include + +#include "../include/consts.h" #include "../include/defs.h" +#include "../log.h" void Sparse(const char* path) { - // TODO + BPTR pathLock; + BPTR dirLock; + int ret; + int rc, wRc, cRc; + BPTR h; + int i; + + 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) "SPARSE"); + + if(!dirLock) + { + log_write("Error %d creating working directory.\n", IoErr()); + return; + } + + CurrentDir(dirLock); + + log_write("Creating sparse files.\n"); + + h = Open((CONST_STRPTR) "SMALL", MODE_NEWFILE); + rc = 0; + wRc = 0; + cRc = 0; + if(!h) rc = IoErr(); + else + { + for(i = 0; i < 4096; i += CLAUNIA_SIZE) + { + ret = Write(h, clauniaBytes, CLAUNIA_SIZE); + if(ret < 0) + { + wRc = IoErr(); + break; + } + } + + Seek(h, 8192, OFFSET_CURRENT); + + for(i = 4096 + 8192; i < 4096 * 4; i += CLAUNIA_SIZE) + { + ret = Write(h, clauniaBytes, CLAUNIA_SIZE); + if(ret < 0) + { + wRc = IoErr(); + break; + } + } + + ret = Close(h); + if(!ret) cRc = IoErr(); + } + + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "SMALL", 4096 * 4, rc, wRc, cRc); + + h = Open((CONST_STRPTR) "BIG", MODE_NEWFILE); + rc = 0; + wRc = 0; + cRc = 0; + if(!h) rc = IoErr(); + else + { + for(i = 0; i < 4096 * 8; i += CLAUNIA_SIZE) + { + ret = Write(h, clauniaBytes, CLAUNIA_SIZE); + if(ret < 0) + { + wRc = IoErr(); + break; + } + } + + Seek(h, 81920, OFFSET_CURRENT); + + for(i = 32768 + 81920; i < 4096 * 30; i += CLAUNIA_SIZE) + { + ret = Write(h, clauniaBytes, CLAUNIA_SIZE); + if(ret < 0) + { + wRc = IoErr(); + break; + } + } + } + + log_write("\tFile name = \"%s\", size = %d, rc = %d, wRc = %d, cRc = %d\n", "BIG", 4096 * 30, rc, wRc, cRc); }