From b409aaa371d765cee6ffef2472864a8c16691c91 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Fri, 12 Mar 2021 00:58:36 +0000 Subject: [PATCH] Merge OS/2 volume information code. --- setter/src/os2/32bit/volume.c | 113 ---------------------------- setter/src/os2/{16bit => }/volume.c | 47 +++++++++--- 2 files changed, 38 insertions(+), 122 deletions(-) delete mode 100644 setter/src/os2/32bit/volume.c rename setter/src/os2/{16bit => }/volume.c (73%) diff --git a/setter/src/os2/32bit/volume.c b/setter/src/os2/32bit/volume.c deleted file mode 100644 index d2b2512..0000000 --- a/setter/src/os2/32bit/volume.c +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** -Aaru Data Preservation Suite ------------------------------------------------------------------------------ - -Filename : os2_32.c -Author(s) : Natalia Portillo - ---[ Description ] ----------------------------------------------------------- - -Contains 32-bit OS/2 code - ---[ 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 -*****************************************************************************/ - -#if(defined(__I386__) || defined(__i386__) || defined(__THW_INTEL) || defined(_M_I386)) && \ - (defined(__OS2__) || defined(__os2__)) && !defined(__DOS__) - -#define INCL_DOSMISC -#define INCL_DOSFILEMGR - -#include -#include -#include -#include - -#include "../os2.h" -#include "include/consts.h" -#include "include/defs.h" - -void GetVolumeInfo(const char* path, size_t* clusterSize) -{ - APIRET rc; - BYTE bData[64]; - ULONG cbData = sizeof(bData); - PFSALLOCATE pfsAllocateBuffer; - ULONG driveNo = path[0] - '@'; - char* fsdName; - PFSINFO pfsInfo; - - if(driveNo > 32) driveNo -= 32; - - *clusterSize = 0; - - rc = DosQueryFSAttach((PSZ)path, 0, FSAIL_QUERYNAME, (PVOID)&bData, &cbData); - - printf("Volume information:\n"); - printf("\tPath: %s\n", path); - printf("\tDrive number: %d\n", driveNo - 1); - - if(rc) { printf("Error %d requesting volume information.\n", rc); } - else - { - fsdName = &bData[8 + (USHORT)bData[2] + 1]; - printf("\tFSD name: %s\n", fsdName); - } - - pfsAllocateBuffer = (PFSALLOCATE)malloc(sizeof(FSALLOCATE)); - rc = DosQueryFSInfo(driveNo, FSIL_ALLOC, (PBYTE)pfsAllocateBuffer, sizeof(FSALLOCATE)); - - if(rc) { printf("Error %d requesting volume information.\n", rc); } - else - { - printf("\tBytes per sector: %u\n", pfsAllocateBuffer->cbSector); - printf("\tSectors per cluster: %lu (%lu bytes)\n", - pfsAllocateBuffer->cSectorUnit, - pfsAllocateBuffer->cSectorUnit * pfsAllocateBuffer->cbSector); - printf("\tClusters: %lu (%lu bytes)\n", - pfsAllocateBuffer->cUnit, - pfsAllocateBuffer->cSectorUnit * pfsAllocateBuffer->cbSector * pfsAllocateBuffer->cUnit); - printf("\tFree clusters: %lu (%lu bytes)\n", - pfsAllocateBuffer->cUnitAvail, - pfsAllocateBuffer->cSectorUnit * pfsAllocateBuffer->cbSector * pfsAllocateBuffer->cUnitAvail); - - *clusterSize = pfsAllocateBuffer->cSectorUnit * pfsAllocateBuffer->cbSector; - } - - free(pfsAllocateBuffer); - - pfsInfo = (PFSINFO)malloc(sizeof(FSINFO)); - rc = DosQueryFSInfo(driveNo, FSIL_VOLSER, (PBYTE)pfsInfo, sizeof(FSINFO)); - - if(rc) { printf("Error %d requesting volume information.\n", rc); } - else - { - printf("\tVolume label: %s\n", pfsInfo->vol.szVolLabel); - printf("\tVolume created on %d/%02d/%02d %02d:%02d:%02d\n", - pfsInfo->fdateCreation.year + 1980, - pfsInfo->fdateCreation.month - 1, - pfsInfo->fdateCreation.day, - pfsInfo->ftimeCreation.hours, - pfsInfo->ftimeCreation.minutes, - pfsInfo->ftimeCreation.twosecs * 2); - } - - free(pfsInfo); -} - -#endif diff --git a/setter/src/os2/16bit/volume.c b/setter/src/os2/volume.c similarity index 73% rename from setter/src/os2/16bit/volume.c rename to setter/src/os2/volume.c index 6929f31..118795d 100644 --- a/setter/src/os2/16bit/volume.c +++ b/setter/src/os2/volume.c @@ -38,41 +38,64 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include -#include "../os2.h" #include "include/consts.h" #include "include/defs.h" +#include "os2.h" void GetVolumeInfo(const char* path, size_t* clusterSize) { - USHORT rc; + APIRET rc; BYTE bData[64]; - USHORT cbData = sizeof(bData); PFSALLOCATE pfsAllocateBuffer; - USHORT driveNo = path[0] - '@'; char* fsdName; PFSINFO pfsInfo; +// 16 bit +#if(defined(__I86__) || defined(__i86__) || defined(_M_I86)) + USHORT cbData = sizeof(bData); + USHORT driveNo = path[0] - '@'; +#else // 32 bit + ULONG cbData = sizeof(bData); + ULONG driveNo = path[0] - '@'; +#endif + if(driveNo > 32) driveNo -= 32; *clusterSize = 0; +// 16 bit +#if(defined(__I86__) || defined(__i86__) || defined(_M_I86)) rc = DosQFSAttach((PSZ)path, 0, FSAIL_QUERYNAME, (PVOID)&bData, &cbData, 0); +#else // 32 bit + rc = DosQueryFSAttach((PSZ)path, 0, FSAIL_QUERYNAME, (PVOID)&bData, &cbData); +#endif printf("Volume information:\n"); printf("\tPath: %s\n", path); printf("\tDrive number: %d\n", driveNo - 1); - if(rc) { printf("Error %d requesting volume information.\n", rc); } + if(rc) printf("Error %d requesting volume information.\n", rc); else { +// 16 bit +#if(defined(__I86__) || defined(__i86__) || defined(_M_I86)) fsdName = &bData[4 + (USHORT)bData[2] + 1 + 2]; +#else // 32 bit + fsdName = &bData[8 + (USHORT)bData[2] + 1]; +#endif printf("\tFSD name: %s\n", fsdName); } pfsAllocateBuffer = (PFSALLOCATE)malloc(sizeof(FSALLOCATE)); - rc = DosQFSInfo(driveNo, 1, (PBYTE)pfsAllocateBuffer, sizeof(FSALLOCATE)); - if(rc) { printf("Error %d requesting volume information.\n", rc); } +// 16 bit +#if(defined(__I86__) || defined(__i86__) || defined(_M_I86)) + rc = DosQFSInfo(driveNo, 1, (PBYTE)pfsAllocateBuffer, sizeof(FSALLOCATE)); +#else // 32 bit + rc = DosQueryFSInfo(driveNo, FSIL_ALLOC, (PBYTE)pfsAllocateBuffer, sizeof(FSALLOCATE)); +#endif + + if(rc) printf("Error %d requesting volume information.\n", rc); else { printf("\tBytes per sector: %u\n", pfsAllocateBuffer->cbSector); @@ -92,9 +115,15 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) free(pfsAllocateBuffer); pfsInfo = (PFSINFO)malloc(sizeof(FSINFO)); - rc = DosQFSInfo(driveNo, 2, (PBYTE)pfsInfo, sizeof(FSINFO)); - if(rc) { printf("Error %d requesting volume information.\n", rc); } +// 16 bit +#if(defined(__I86__) || defined(__i86__) || defined(_M_I86)) + rc = DosQFSInfo(driveNo, 2, (PBYTE)pfsInfo, sizeof(FSINFO)); +#else // 32 bit + rc = DosQueryFSInfo(driveNo, FSIL_VOLSER, (PBYTE)pfsInfo, sizeof(FSINFO)); +#endif + + if(rc) printf("Error %d requesting volume information.\n", rc); else { printf("\tVolume label: %s\n", pfsInfo->vol.szVolLabel);