From 3401952ce080054a40a6fa00f0c8a22e825516c5 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 19 Apr 2021 03:10:52 +0100 Subject: [PATCH] Implement volume information for AmigaOS. --- setter/src/amiga/volume.c | 115 +++++++++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 1 deletion(-) diff --git a/setter/src/amiga/volume.c b/setter/src/amiga/volume.c index c1ab83d..6f8e6a4 100644 --- a/setter/src/amiga/volume.c +++ b/setter/src/amiga/volume.c @@ -22,9 +22,122 @@ Aaru Data Preservation Suite Copyright (C) 2011-2021 Natalia Portillo *****************************************************************************/ +#include +#include +#include +#include + #include "../include/defs.h" +#include "../log.h" void GetVolumeInfo(const char* path, size_t* clusterSize) { - // TODO + BPTR pathLock; + struct InfoData info; + int rc; + long long total, free; + unsigned char type[255]; + int pos = 0; + unsigned char typeByte; + + *clusterSize = 0; + + memset(&info, 0, sizeof(struct InfoData)); + + pathLock = Lock((CONST_STRPTR)path, SHARED_LOCK); + + if(!pathLock) + { + printf("Error %ld obtaining lock for the requested path\n", IoErr()); + + return; + } + + rc = Info(pathLock, &info); + + if(!rc) + { + printf("Error %ld obtaining lock for the requested path\n", IoErr()); + + return; + } + + *clusterSize = info.id_BytesPerBlock; + + total = info.id_NumBlocks * (long long)info.id_BytesPerBlock; + free = (info.id_NumBlocks - info.id_NumBlocksUsed) * (long long)info.id_BytesPerBlock; + + memset(type, 0, 255); + + typeByte = info.id_DiskType >> 24; + + if(typeByte < 0x20) + { + type[pos++] = '\\'; + + if(typeByte <= 7) type[pos++] = typeByte + 0x30; + else + { + type[pos++] = (typeByte / 8) + 0x30; + type[pos++] = (typeByte % 8) + 0x30; + } + } + else + type[pos++] = typeByte; + + typeByte = (info.id_DiskType >> 16) & 0xFF; + + if(typeByte < 0x20) + { + type[pos++] = '\\'; + + if(typeByte <= 7) type[pos++] = typeByte + 0x30; + else + { + type[pos++] = (typeByte / 8) + 0x30; + type[pos++] = (typeByte % 8) + 0x30; + } + } + else + type[pos++] = typeByte; + + typeByte = (info.id_DiskType >> 8) & 0xFF; + + if(typeByte < 0x20) + { + type[pos++] = '\\'; + + if(typeByte <= 7) type[pos++] = typeByte + 0x30; + else + { + type[pos++] = (typeByte / 8) + 0x30; + type[pos++] = (typeByte % 8) + 0x30; + } + } + else + type[pos++] = typeByte; + + typeByte = info.id_DiskType & 0xFF; + + if(typeByte < 0x20) + { + type[pos++] = '\\'; + + if(typeByte <= 7) type[pos++] = typeByte + 0x30; + else + { + type[pos++] = (typeByte / 8) + 0x30; + type[pos++] = (typeByte % 8) + 0x30; + } + } + else + type[pos++] = typeByte; + + log_write("Volume information:\n"); + + log_write("\tPath: %s\n", path); + log_write("\tDOS type: '%s'\n", type); + log_write("\t%d bytes per block\n", info.id_BytesPerBlock); + log_write("\t%ld blocks (%lld bytes)\n", info.id_NumBlocks, total); + log_write("\t%ld blocks free (%lld bytes)\n", info.id_NumBlocks - info.id_NumBlocksUsed, free); }