From e30bc98cd219020e0d93772a87d1fcb75466b47f Mon Sep 17 00:00:00 2001 From: Stuart Caie Date: Wed, 17 May 2023 17:11:41 +0000 Subject: [PATCH 01/40] Add "next" to struct AdfNativeFunctions, use static init --- src/adf_env.c | 6 +----- src/adf_env.h | 2 +- src/generic/adf_nativ.c | 21 ++++++++++----------- src/generic/adf_nativ.h | 3 ++- src/linux/adf_nativ.c | 21 ++++++++++----------- src/linux/adf_nativ.h | 4 +++- src/win32/adf_nativ.c | 20 ++++++++++---------- src/win32/adf_nativ.h | 4 +++- 8 files changed, 40 insertions(+), 41 deletions(-) diff --git a/src/adf_env.c b/src/adf_env.c index 84df93c5..e58c3194 100644 --- a/src/adf_env.c +++ b/src/adf_env.c @@ -187,10 +187,7 @@ void adfEnvInitDefault() /* sprintf(str,"ADFlib %s (%s)",adfGetVersionNumber(),adfGetVersionDate()); (*adfEnv.vFct)(str); */ - adfEnv.nativeFct=(struct AdfNativeFunctions*)malloc(sizeof(struct AdfNativeFunctions)); - if (!adfEnv.nativeFct) (*adfEnv.wFct)("adfInitDefaultEnv : malloc"); - - adfInitNativeFct(); + adfEnv.nativeFct = adfInitNativeFct(); } @@ -200,7 +197,6 @@ void adfEnvInitDefault() */ void adfEnvCleanUp() { - free(adfEnv.nativeFct); } diff --git a/src/adf_env.h b/src/adf_env.h index e226edd9..a05da6e5 100644 --- a/src/adf_env.h +++ b/src/adf_env.h @@ -60,7 +60,7 @@ struct AdfEnv { BOOL useDirCache; - void *nativeFct; + struct AdfNativeFunctions *nativeFct; }; diff --git a/src/generic/adf_nativ.c b/src/generic/adf_nativ.c index 65e55ba2..b608d140 100644 --- a/src/generic/adf_nativ.c +++ b/src/generic/adf_nativ.c @@ -28,6 +28,14 @@ #include"adf_err.h" #include "adf_env.h" +struct AdfNativeFunctions adfGenericNativeDevice = { + NULL, + &myInitDevice, + &myReleaseDevice, + &myReadSector, + &myWriteSector, + &myIsDevNative +}; /* * myInitDevice @@ -108,19 +116,10 @@ RETCODE myReleaseDevice ( struct AdfDevice * const dev ) * adfInitNativeFct * */ -void adfInitNativeFct() -{ - struct AdfNativeFunctions * nFct = - ( struct AdfNativeFunctions * ) adfEnv.nativeFct; - - nFct->adfInitDevice = myInitDevice ; - nFct->adfNativeReadSector = myReadSector ; - nFct->adfNativeWriteSector = myWriteSector ; - nFct->adfReleaseDevice = myReleaseDevice ; - nFct->adfIsDevNative = myIsDevNative; +struct AdfNativeFunctions *adfInitNativeFct() { + return &adfGenericNativeDevice; } - /* * myIsDevNative * diff --git a/src/generic/adf_nativ.h b/src/generic/adf_nativ.h index ea7b6c1c..7af42f58 100644 --- a/src/generic/adf_nativ.h +++ b/src/generic/adf_nativ.h @@ -42,6 +42,7 @@ struct AdfNativeDevice { }; struct AdfNativeFunctions { + struct AdfNativeFunctions *next; /* called by adfMount() */ RETCODE (*adfInitDevice)( struct AdfDevice * const dev, @@ -67,7 +68,7 @@ struct AdfNativeFunctions { BOOL (*adfIsDevNative)( const char * const devName ); }; -void adfInitNativeFct(); +struct AdfNativeFunctions *adfInitNativeFct(); RETCODE myInitDevice ( struct AdfDevice * const dev, const char * const name, diff --git a/src/linux/adf_nativ.c b/src/linux/adf_nativ.c index a737bd53..8a82040f 100644 --- a/src/linux/adf_nativ.c +++ b/src/linux/adf_nativ.c @@ -36,6 +36,14 @@ #include "adf_nativ.h" #include "adf_env.h" +struct AdfNativeFunctions adfLinuxNativeDevice = { + NULL, + &adfLinuxInitDevice, + &adfLinuxReleaseDevice, + &adfLinuxReadSector, + &adfLinuxWriteSector, + &adfLinuxIsDevNative +}; /* * adfLinuxInitDevice @@ -172,19 +180,10 @@ RETCODE adfLinuxWriteSector ( struct AdfDevice * const dev, * adfInitNativeFct * */ -void adfInitNativeFct() -{ - struct AdfNativeFunctions * nFct = - ( struct AdfNativeFunctions * ) adfEnv.nativeFct; - - nFct->adfInitDevice = adfLinuxInitDevice; - nFct->adfNativeReadSector = adfLinuxReadSector; - nFct->adfNativeWriteSector = adfLinuxWriteSector; - nFct->adfReleaseDevice = adfLinuxReleaseDevice; - nFct->adfIsDevNative = adfLinuxIsDevNative; +struct AdfNativeFunctions *adfInitNativeFct() { + return &adfLinuxNativeDevice; } - /* * adfLinuxIsDevNative * diff --git a/src/linux/adf_nativ.h b/src/linux/adf_nativ.h index 3e2f57c7..50e638ca 100644 --- a/src/linux/adf_nativ.h +++ b/src/linux/adf_nativ.h @@ -42,6 +42,8 @@ struct AdfNativeDevice { }; struct AdfNativeFunctions { + struct AdfNativeFunctions *next; + RETCODE (*adfInitDevice)( struct AdfDevice * const dev, const char * const name, const BOOL ro ); @@ -61,7 +63,7 @@ struct AdfNativeFunctions { BOOL (*adfIsDevNative)( const char * const devName ); }; -void adfInitNativeFct(); +struct AdfNativeFunctions *adfInitNativeFct(); RETCODE adfLinuxInitDevice ( struct AdfDevice * const dev, const char * const name, diff --git a/src/win32/adf_nativ.c b/src/win32/adf_nativ.c index 69cad726..2127f6c9 100644 --- a/src/win32/adf_nativ.c +++ b/src/win32/adf_nativ.c @@ -37,6 +37,14 @@ #include "adf_env.h" #include "nt4_dev.h" +struct AdfNativeFunctions adfWindowsNativeDevice = { + NULL, + &Win32InitDevice, + &Win32ReleaseDevice, + &Win32ReadSector, + &Win32WriteSector, + &Win32IsDevNative +}; RETCODE Win32InitDevice ( struct AdfDevice * const dev, const char * const lpstrName, @@ -145,16 +153,8 @@ RETCODE Win32ReleaseDevice ( struct AdfDevice * const dev ) } -void adfInitNativeFct() -{ - struct AdfNativeFunctions * nFct = - ( struct AdfNativeFunctions * ) adfEnv.nativeFct; - - nFct->adfInitDevice = Win32InitDevice; - nFct->adfNativeReadSector = Win32ReadSector; - nFct->adfNativeWriteSector = Win32WriteSector; - nFct->adfReleaseDevice = Win32ReleaseDevice; - nFct->adfIsDevNative = Win32IsDevNative; +struct AdfNativeFunctions *adfInitNativeFct() { + return &adfWindowsNativeDevice; } diff --git a/src/win32/adf_nativ.h b/src/win32/adf_nativ.h index 32685469..c531ecb2 100644 --- a/src/win32/adf_nativ.h +++ b/src/win32/adf_nativ.h @@ -41,6 +41,8 @@ struct AdfNativeDevice { }; struct AdfNativeFunctions { + struct AdfNativeFunctions *next; + RETCODE (*adfInitDevice)( struct AdfDevice * const dev, const char * const name, const BOOL ro ); @@ -60,7 +62,7 @@ struct AdfNativeFunctions { BOOL (*adfIsDevNative)( const char * const devName ); }; -void adfInitNativeFct(); +struct AdfNativeFunctions *adfInitNativeFct(); RETCODE Win32InitDevice ( struct AdfDevice * const dev, const char * const name, From 17a037c0c36c8dc11057e35736d262967f70433c Mon Sep 17 00:00:00 2001 From: Stuart Caie Date: Wed, 17 May 2023 17:24:43 +0000 Subject: [PATCH 02/40] Loop through possible native devices to pick one --- src/adf_dev.c | 22 +++++++++++++--------- src/adf_dev.h | 8 ++++---- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/adf_dev.c b/src/adf_dev.c index 2c8c125c..f2dca845 100644 --- a/src/adf_dev.c +++ b/src/adf_dev.c @@ -66,12 +66,19 @@ struct AdfDevice * adfOpenDev ( const char * const filename, dev->readOnly = ro; /* switch between dump files and real devices */ - struct AdfNativeFunctions * nFct = adfEnv.nativeFct; - dev->isNativeDev = ( *nFct->adfIsDevNative )( filename ); + struct AdfNativeFunctions * nFct; + dev->isNativeDev = FALSE; + for (nFct = adfEnv.nativeFct; nFct; nFct = nFct->next) { + if (nFct->adfIsDevNative(filename)) { + dev->nativeFct = nFct; + dev->isNativeDev = TRUE; + break; + } + } RETCODE rc; if ( dev->isNativeDev ) - rc = ( *nFct->adfInitDevice )( dev, filename, ro ); + rc = dev->nativeFct->adfInitDevice( dev, filename, ro ); else rc = adfInitDumpDevice ( dev, filename, ro ); if ( rc != RC_OK ) { @@ -130,8 +137,7 @@ void adfCloseDev ( struct AdfDevice * const dev ) } if ( dev->isNativeDev ) { - struct AdfNativeFunctions * const nFct = adfEnv.nativeFct; - ( *nFct->adfReleaseDevice )( dev ); + dev->nativeFct->adfReleaseDevice( dev ); } else adfReleaseDumpDevice ( dev ); @@ -303,8 +309,7 @@ RETCODE adfReadBlockDev ( struct AdfDevice * const dev, /*printf("pSect R =%ld\n",pSect);*/ if ( dev->isNativeDev ) { - struct AdfNativeFunctions * const nFct = adfEnv.nativeFct; - rc = (*nFct->adfNativeReadSector)( dev, pSect, size, buf ); + rc = dev->nativeFct->adfNativeReadSector( dev, pSect, size, buf ); } else rc = adfReadDumpSector( dev, pSect, size, buf ); /*printf("rc=%ld\n",rc);*/ @@ -321,8 +326,7 @@ RETCODE adfWriteBlockDev ( struct AdfDevice * const dev, /*printf("nativ=%d\n",dev->isNativeDev);*/ if ( dev->isNativeDev ) { - struct AdfNativeFunctions * const nFct = adfEnv.nativeFct; - rc = (*nFct->adfNativeWriteSector)( dev, pSect, size, buf ); + rc = dev->nativeFct->adfNativeWriteSector( dev, pSect, size, buf ); } else rc = adfWriteDumpSector ( dev, pSect, size, buf ); diff --git a/src/adf_dev.h b/src/adf_dev.h index d08cf3e6..9dddc445 100644 --- a/src/adf_dev.h +++ b/src/adf_dev.h @@ -36,10 +36,10 @@ struct AdfDevice { uint32_t sectors; BOOL isNativeDev; - union { - void *nativeDev; - FILE *fd; - }; + struct AdfNativeFunctions *nativeFct; + void *nativeDev; /* for use by native functions */ + + FILE *fd; }; From f733ea8ef724b8e04eeb7503eec0c1750652ed07 Mon Sep 17 00:00:00 2001 From: Stuart Caie Date: Wed, 17 May 2023 17:39:22 +0000 Subject: [PATCH 03/40] Add adfAddNativeDriver() and adfRemoveNativeDriver() --- src/adf_env.c | 17 +++++++++++++++++ src/adf_env.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/src/adf_env.c b/src/adf_env.c index e58c3194..2bc44586 100644 --- a/src/adf_env.c +++ b/src/adf_env.c @@ -284,6 +284,23 @@ char* adfGetVersionDate() return(ADFLIB_DATE); } +void adfAddNativeDriver(struct AdfNativeFunctions *driver) { + if (driver) { + driver->next = adfEnv.nativeFct; + adfEnv.nativeFct = driver; + } +} +void adfRemoveNativeDriver(struct AdfNativeFunctions *driver) { + if (driver) { + struct AdfNativeFunctions *nFct = (struct AdfNativeFunctions *) &(adfEnv.nativeFct); + for (; nFct; nFct = nFct->next) { + if (nFct->next == driver) { + nFct->next = driver->next; + return; + } + } + } +} diff --git a/src/adf_env.h b/src/adf_env.h index a05da6e5..edfc7d62 100644 --- a/src/adf_env.h +++ b/src/adf_env.h @@ -71,6 +71,8 @@ PREFIX void adfEnvCleanUp(); PREFIX void adfChgEnvProp(int prop, void *new); PREFIX char* adfGetVersionNumber(); PREFIX char* adfGetVersionDate(); +PREFIX void adfAddNativeDriver(struct AdfNativeFunctions *driver); +PREFIX void adfRemoveNativeDriver(struct AdfNativeFunctions *driver); extern struct AdfEnv adfEnv; From b58b8150eaa6e8160074c8cea65b9dbd92163d0c Mon Sep 17 00:00:00 2001 From: Stuart Caie Date: Wed, 17 May 2023 18:14:51 +0000 Subject: [PATCH 04/40] add ramdisk driver for tests --- tests/ramdisk.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/ramdisk.h | 14 ++++++++ 2 files changed, 101 insertions(+) create mode 100644 tests/ramdisk.c create mode 100644 tests/ramdisk.h diff --git a/tests/ramdisk.c b/tests/ramdisk.c new file mode 100644 index 00000000..d6bab492 --- /dev/null +++ b/tests/ramdisk.c @@ -0,0 +1,87 @@ +/* + * ramdisk.c + * + * $Id$ + * + * This file is part of ADFLib. + * + * ADFLib 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 2 of the License, or + * (at your option) any later version. + * + * ADFLib 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 Foobar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include +#include +#include "ramdisk.h" + +uint8_t ramdiskData[RAMDISK_SIZE]; + +static RETCODE ramdiskInit( struct AdfDevice * const dev, + const char * const name, + const BOOL ro ) +{ + dev->readOnly = ro; + dev->heads = 2; + dev->sectors = 11; + dev->cylinders = 80; + dev->size = RAMDISK_SIZE; + return RC_OK; +} + + +static RETCODE ramdiskRelease ( struct AdfDevice * const dev ) +{ + return RC_OK; +} + + +static RETCODE ramdiskReadSector ( struct AdfDevice * const dev, + const uint32_t n, + const unsigned size, + uint8_t * const buf ) +{ + unsigned int offset = n * 512; + if (offset > RAMDISK_SIZE || (offset + size) > RAMDISK_SIZE) { + return RC_ERROR; + } + memcpy(buf, &ramdiskData[offset], size); + return RC_OK; +} + +static RETCODE ramdiskWriteSector ( struct AdfDevice * const dev, + const uint32_t n, + const unsigned size, + const uint8_t * const buf ) +{ + unsigned int offset = n * 512; + if (offset > RAMDISK_SIZE || (offset + size) > RAMDISK_SIZE) { + return RC_ERROR; + } + memcpy(&ramdiskData[offset], buf, size); + return RC_OK; +} + +static BOOL ramdiskIsDevNative ( const char * const devName ) +{ + return strcmp(devName, RAMDISK_DEVICE_NAME) == 0; +} + +struct AdfNativeFunctions ramdiskDevice = { + NULL, + &ramdiskInit, + &ramdiskRelease, + &ramdiskReadSector, + &ramdiskWriteSector, + &ramdiskIsDevNative +}; diff --git a/tests/ramdisk.h b/tests/ramdisk.h new file mode 100644 index 00000000..8da2e78b --- /dev/null +++ b/tests/ramdisk.h @@ -0,0 +1,14 @@ +#ifndef RAMDISK_H +#define RAMDISK_H + +#include "adf_err.h" +#include "adf_nativ.h" + +#define RAMDISK_SIZE (2 * 11 * 80 * 512) +#define RAMDISK_DEVICE_NAME "RAM:" + +extern uint8_t ramdiskData[RAMDISK_SIZE]; + +extern struct AdfNativeFunctions ramdiskDevice; + +#endif From d9ba109992c9e5143f633f5a1b6c7fc88d0fa4c7 Mon Sep 17 00:00:00 2001 From: Stuart Caie Date: Wed, 17 May 2023 18:15:48 +0000 Subject: [PATCH 05/40] use ramdisk in slowest test --- tests/CMakeLists.txt | 3 ++- tests/Makefile.am | 2 +- tests/test_file_overwrite.c | 9 +++------ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index aa48b114..65fc7b79 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -66,7 +66,8 @@ add_executable ( test_file_write_chunks test_util.c ) add_executable ( test_file_overwrite - test_file_overwrite.c ) + test_file_overwrite.c + ramdisk.c ) add_executable ( test_file_overwrite2 test_file_overwrite2.c diff --git a/tests/Makefile.am b/tests/Makefile.am index a81589ee..f8acd4fb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -62,7 +62,7 @@ test_file_write_chunks_CFLAGS = $(CHECK_CFLAGS) test_file_write_chunks_LDADD = $(ADFLIBS) $(CHECK_LIBS) test_file_write_chunks_DEPENDENCIES = $(top_builddir)/src/libadf.la -test_file_overwrite_SOURCES = test_file_overwrite.c +test_file_overwrite_SOURCES = test_file_overwrite.c ramdisk.c ramdisk.h test_file_overwrite_CFLAGS = $(CHECK_CFLAGS) test_file_overwrite_LDADD = $(ADFLIBS) $(CHECK_LIBS) test_file_overwrite_DEPENDENCIES = $(top_builddir)/src/libadf.la diff --git a/tests/test_file_overwrite.c b/tests/test_file_overwrite.c index 203ffa86..b5dcbbab 100644 --- a/tests/test_file_overwrite.c +++ b/tests/test_file_overwrite.c @@ -6,13 +6,13 @@ #endif #include "adflib.h" +#include "ramdisk.h" //#include "adf_util.h" typedef struct test_data_s { struct AdfDevice * device; struct AdfVolume * vol; - char * adfname; char * volname; uint8_t fstype; // 0 - OFS, 1 - FFS unsigned nVolumeBlocks; @@ -234,7 +234,6 @@ void test_file_write ( test_data_t * const tdata ) START_TEST ( test_file_write_ofs ) { test_data_t test_data = { - .adfname = "test_file_overwrite_ofs.adf", .volname = "Test_file_overwrite_ofs", .fstype = 0, // OFS .openMode = "w", @@ -248,7 +247,6 @@ START_TEST ( test_file_write_ofs ) START_TEST ( test_file_write_ffs ) { test_data_t test_data = { - .adfname = "test_file_overwrite_ffs.adf", .volname = "Test_file_overwrite_ffs", .fstype = 1, // FFS .openMode = "w", @@ -287,6 +285,7 @@ int main ( void ) SRunner * sr = srunner_create ( s ); adfEnvInitDefault(); + adfAddNativeDriver(&ramdiskDevice); srunner_run_all ( sr, CK_VERBOSE ); //CK_NORMAL ); adfEnvCleanUp(); @@ -300,7 +299,7 @@ int main ( void ) void setup ( test_data_t * const tdata ) { - tdata->device = adfCreateDumpDevice ( tdata->adfname, 80, 2, 11 ); + tdata->device = adfOpenDev(RAMDISK_DEVICE_NAME, FALSE); if ( ! tdata->device ) { //return; exit(1); @@ -322,6 +321,4 @@ void teardown ( test_data_t * const tdata ) { //adfUnMount ( tdata->vol ); adfUnMountDev ( tdata->device ); - if ( unlink ( tdata->adfname ) != 0 ) - perror (""); } From 3b6c2a7d77b297f7a800c110eab8103feb96507a Mon Sep 17 00:00:00 2001 From: t-m Date: Wed, 24 Jan 2024 22:09:07 +0100 Subject: [PATCH 06/40] adf_natif: fix/reorder code (so that it compiles). --- src/linux/adf_nativ.c | 20 +++++++++++--------- src/win32/adf_nativ.c | 27 +++++++++++++++------------ 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/linux/adf_nativ.c b/src/linux/adf_nativ.c index bdc9c414..d09b5f63 100644 --- a/src/linux/adf_nativ.c +++ b/src/linux/adf_nativ.c @@ -37,15 +37,6 @@ #include "adf_env.h" -struct AdfNativeFunctions adfLinuxNativeDevice = { - NULL, - &adfLinuxInitDevice, - &adfLinuxReleaseDevice, - &adfLinuxReadSector, - &adfLinuxWriteSector, - &adfLinuxIsDevNative -}; - struct AdfNativeDevice { int fd; }; @@ -198,6 +189,17 @@ static BOOL adfLinuxIsDevNative ( const char * const devName ) return ( ( sb.st_mode & S_IFMT ) == S_IFBLK ); } + +struct AdfNativeFunctions adfLinuxNativeDevice = { + NULL, + &adfLinuxInitDevice, + &adfLinuxReleaseDevice, + &adfLinuxReadSector, + &adfLinuxWriteSector, + &adfLinuxIsDevNative +}; + + /* * adfInitNativeFct * diff --git a/src/win32/adf_nativ.c b/src/win32/adf_nativ.c index 0c5337e1..7b07f45b 100644 --- a/src/win32/adf_nativ.c +++ b/src/win32/adf_nativ.c @@ -37,14 +37,6 @@ #include "adf_env.h" #include "nt4_dev.h" -struct AdfNativeFunctions adfWindowsNativeDevice = { - NULL, - &Win32InitDevice, - &Win32ReleaseDevice, - &Win32ReadSector, - &Win32WriteSector, - &Win32IsDevNative -}; struct AdfNativeDevice { void *hDrv; @@ -161,11 +153,22 @@ static RETCODE Win32ReleaseDevice ( struct AdfDevice * const dev ) } -struct AdfNativeFunctions *adfInitNativeFct() { - return &adfWindowsNativeDevice; -} - static BOOL Win32IsDevNative ( const char * const devName ) { return devName[0] == '|'; } + + +struct AdfNativeFunctions adfWindowsNativeDevice = { + NULL, + &Win32InitDevice, + &Win32ReleaseDevice, + &Win32ReadSector, + &Win32WriteSector, + &Win32IsDevNative +}; + + +struct AdfNativeFunctions *adfInitNativeFct() { + return &adfWindowsNativeDevice; +} From b961b15cc593ec8817b68fe7ff6a054f821d7975 Mon Sep 17 00:00:00 2001 From: t-m Date: Wed, 24 Jan 2024 22:26:48 +0100 Subject: [PATCH 07/40] Make ramdisk a standard native device. --- src/CMakeLists.txt | 4 +++- src/Makefile.am | 2 ++ tests/ramdisk.c => src/adf_dev_ramdisk.c | 2 +- tests/ramdisk.h => src/adf_dev_ramdisk.h | 4 ++-- tests/CMakeLists.txt | 3 +-- tests/Makefile.am | 2 +- tests/test_file_overwrite.c | 2 +- 7 files changed, 11 insertions(+), 8 deletions(-) rename tests/ramdisk.c => src/adf_dev_ramdisk.c (98%) rename tests/ramdisk.h => src/adf_dev_ramdisk.h (81%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ce94ad05..b5b3377a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -58,6 +58,8 @@ add_library ( adf adf_dev.h adf_dev_hd.c adf_dev_hd.h + adf_dev_ramdisk.c + adf_dev_ramdisk.h adf_dir.c adf_dir.h adf_env.c @@ -92,7 +94,7 @@ add_library ( adf set_target_properties ( adf PROPERTIES #PUBLIC_HEADER "adflib.h" - PUBLIC_HEADER "adf_bitm.h;adf_blk.h;adf_cache.h;adf_dev_dump.h;adf_dev_flop.h;adf_dev.h;adf_dev_hd.h;adf_dir.h;adf_env.h;adf_err.h;adf_file_block.h;adf_file.h;adf_file_util.h;adflib.h;adf_link.h;adf_nativ.h;adf_raw.h;adf_salv.h;adf_str.h;adf_types.h;adf_util.h;adf_version.h;adf_vol.h;debug_util.h;defendian.h;hd_blk.h;prefix.h" + PUBLIC_HEADER "adf_bitm.h;adf_blk.h;adf_cache.h;adf_dev_dump.h;adf_dev_flop.h;adf_dev.h;adf_dev_hd.h;adf_dev_ramdisk.h;adf_dir.h;adf_env.h;adf_err.h;adf_file_block.h;adf_file.h;adf_file_util.h;adflib.h;adf_link.h;adf_nativ.h;adf_raw.h;adf_salv.h;adf_str.h;adf_types.h;adf_util.h;adf_version.h;adf_vol.h;debug_util.h;defendian.h;hd_blk.h;prefix.h" #PRIVATE_HEADER ... VERSION ${CMAKE_PROJECT_VERSION} # SOVERSION ${PROJECT_VERSION_MAJOR} diff --git a/src/Makefile.am b/src/Makefile.am index 434a9f60..e059cf44 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,6 +18,7 @@ libadf_la_SOURCES = \ adf_dev_dump.c \ adf_dev_flop.c \ adf_dev_hd.c \ + adf_dev_ramdisk.c \ adf_dir.c \ adf_env.c \ adf_file_block.c \ @@ -40,6 +41,7 @@ adfinc_HEADERS = \ adf_dev_flop.h \ adf_dev.h \ adf_dev_hd.h \ + adf_dev_ramdisk.h \ adf_dir.h \ adf_env.h \ adf_err.h \ diff --git a/tests/ramdisk.c b/src/adf_dev_ramdisk.c similarity index 98% rename from tests/ramdisk.c rename to src/adf_dev_ramdisk.c index d6bab492..a1487f6f 100644 --- a/tests/ramdisk.c +++ b/src/adf_dev_ramdisk.c @@ -23,7 +23,7 @@ #include #include -#include "ramdisk.h" +#include "adf_dev_ramdisk.h" uint8_t ramdiskData[RAMDISK_SIZE]; diff --git a/tests/ramdisk.h b/src/adf_dev_ramdisk.h similarity index 81% rename from tests/ramdisk.h rename to src/adf_dev_ramdisk.h index 8da2e78b..5a2d2e52 100644 --- a/tests/ramdisk.h +++ b/src/adf_dev_ramdisk.h @@ -1,5 +1,5 @@ -#ifndef RAMDISK_H -#define RAMDISK_H +#ifndef ADF_DEV_RAMDISK_H +#define ADF_DEV_RAMDISK_H #include "adf_err.h" #include "adf_nativ.h" diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5be0ecb7..519fd6e1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -68,8 +68,7 @@ add_executable ( test_file_write_chunks test_util.c ) add_executable ( test_file_overwrite - test_file_overwrite.c - ramdisk.c ) + test_file_overwrite.c ) add_executable ( test_file_overwrite2 test_file_overwrite2.c diff --git a/tests/Makefile.am b/tests/Makefile.am index 97a62f42..02b76e91 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -58,7 +58,7 @@ test_file_write_chunks_CFLAGS = $(CHECK_CFLAGS) test_file_write_chunks_LDADD = $(ADFLIBS) $(CHECK_LIBS) test_file_write_chunks_DEPENDENCIES = $(top_builddir)/src/libadf.la -test_file_overwrite_SOURCES = test_file_overwrite.c ramdisk.c ramdisk.h +test_file_overwrite_SOURCES = test_file_overwrite.c test_file_overwrite_CFLAGS = $(CHECK_CFLAGS) test_file_overwrite_LDADD = $(ADFLIBS) $(CHECK_LIBS) test_file_overwrite_DEPENDENCIES = $(top_builddir)/src/libadf.la diff --git a/tests/test_file_overwrite.c b/tests/test_file_overwrite.c index 3aa0b219..63e98dbc 100644 --- a/tests/test_file_overwrite.c +++ b/tests/test_file_overwrite.c @@ -6,7 +6,7 @@ #endif #include "adflib.h" -#include "ramdisk.h" +#include "adf_dev_ramdisk.h" //#include "adf_util.h" From 8276c28b1965a1f7ce07e103a92585cb77d5537f Mon Sep 17 00:00:00 2001 From: t-m Date: Thu, 25 Jan 2024 12:38:49 +0100 Subject: [PATCH 08/40] ramdiskInit: update/correct setting read-only mode. --- src/adf_dev_ramdisk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/adf_dev_ramdisk.c b/src/adf_dev_ramdisk.c index a1487f6f..88374e47 100644 --- a/src/adf_dev_ramdisk.c +++ b/src/adf_dev_ramdisk.c @@ -29,9 +29,9 @@ uint8_t ramdiskData[RAMDISK_SIZE]; static RETCODE ramdiskInit( struct AdfDevice * const dev, const char * const name, - const BOOL ro ) + const AdfAccessMode mode ) { - dev->readOnly = ro; + dev->readOnly = ( mode != ADF_ACCESS_MODE_READWRITE ); dev->heads = 2; dev->sectors = 11; dev->cylinders = 80; From 025dc8125956bff1ba64b7a0489f2516aaf2684b Mon Sep 17 00:00:00 2001 From: t-m Date: Mon, 29 Jan 2024 23:34:55 +0100 Subject: [PATCH 09/40] adf_nativ / generic: fix/reorder code (so that it compiles). --- src/generic/adf_nativ.c | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/src/generic/adf_nativ.c b/src/generic/adf_nativ.c index e3778eea..f400cfbb 100644 --- a/src/generic/adf_nativ.c +++ b/src/generic/adf_nativ.c @@ -28,14 +28,6 @@ #include"adf_err.h" #include "adf_env.h" -struct AdfNativeFunctions adfGenericNativeDevice = { - NULL, - &myInitDevice, - &myReleaseDevice, - &myReadSector, - &myWriteSector, - &myIsDevNative -}; /* * myInitDevice @@ -97,9 +89,21 @@ RETCODE myReleaseDevice ( struct AdfDevice * const dev ) */ BOOL myIsDevNative ( const char * const devName ) { +// return (strncmp(devName,"/dev/",5)==0); return FALSE; } + +struct AdfNativeFunctions adfGenericNativeDevice = { + NULL, + &myInitDevice, + &myReleaseDevice, + &myReadSector, + &myWriteSector, + &myIsDevNative +}; + + /* * adfInitNativeFct * @@ -108,12 +112,4 @@ struct AdfNativeFunctions *adfInitNativeFct() { return &adfGenericNativeDevice; } -/* - * myIsDevNative - * - */ -BOOL myIsDevNative ( const char * const devName ) -{ - return (strncmp(devName,"/dev/",5)==0); -} /*##########################################################################*/ From 90be1e28d0cac212c4d06c8e1935990ad49624ca Mon Sep 17 00:00:00 2001 From: t-m Date: Mon, 29 Jan 2024 23:36:12 +0100 Subject: [PATCH 10/40] adf_dev: properly split opened and mounted device state. Changes in the API(!): to use a device, it must be: 1. opened (adfOpenDev) - block level access only (not info about volumes) 2. mounted (adfMountDev) - volume information is read and available (the volumes can be mounted) 3. unmounted (adfUnMountDev) - volume information becomes unavailable (like after adfOpenDev() ) 4. closed (adfCloseDev) - all information about a device is destroyed This order must be preserved (except that an opened device can be mounted and unmounted many times). Before only adfMountDev / adfUnMountDev was sufficient - now it is not, opening and closing device in client code is mandatory! --- src/adf_dev.c | 100 ++++++++++++++++++++++----------------------- src/adf_dev.h | 12 +++--- src/adf_dev_dump.c | 1 + src/adf_dev_flop.c | 2 + src/adf_dev_hd.c | 2 + 5 files changed, 62 insertions(+), 55 deletions(-) diff --git a/src/adf_dev.c b/src/adf_dev.c index c3582a10..2d33429d 100644 --- a/src/adf_dev.c +++ b/src/adf_dev.c @@ -40,17 +40,13 @@ /* * adfOpenDev * - * open a device without mounting it, used by adfMountDev() or - * for partitioning/formatting with adfCreateFlop/Hd + * open a device without reading any data (ie. without finding volumes) * - * Note that: - * - an opened device must be closed with adfCloseDev() - * before mounting it with adfMountDev() - * - * WARNING: IT IS NOT CHECKING WHETHER THERE IS ANY EXISTING FILESYSTEM - * ON THE DEVICE, IT DOES NOT LOAD ROOTBLOCK ETC. - * IF UNSURE USE adfMountDev() FIRST TO CHECK IF FILESYSTEM STRUCTURES - * EXIST ALREADY ON THE DEVICE(!) + * An opened device either has to be mounted (to be used with functions + * requiring volume data) or only functions using block access on the device + * level (with adfRead/WriteBlockDev) can be used + * (ie. this applies to adfCreateFlop/Hd); in general this level of access + * is for: partitioning / formatting / creating file system data */ struct AdfDevice * adfOpenDev ( const char * const filename, const AdfAccessMode mode ) @@ -87,8 +83,10 @@ struct AdfDevice * adfOpenDev ( const char * const filename, } dev->devType = adfDevType ( dev ); + dev->nVol = 0; dev->volList = NULL; + dev->mounted = FALSE; /* if ( dev->devType == DEVTYPE_FLOPDD ) { @@ -117,23 +115,14 @@ struct AdfDevice * adfOpenDev ( const char * const filename, * adfCloseDev * * Closes/releases an opened device. - * Called by adfUnMountDev() */ void adfCloseDev ( struct AdfDevice * const dev ) { if ( ! dev ) return; - // free volume list - //if ( dev->volList ) { - if ( dev->nVol > 0 ) { - for ( int i = 0 ; i < dev->nVol ; i++ ) { - free ( dev->volList[i]->volName ); - free ( dev->volList[i] ); - } - free ( dev->volList ); - dev->nVol = 0; - } + if ( dev->mounted ) + adfUnMountDev ( dev ); if ( dev->isNativeDev ) { dev->nativeFct->adfReleaseDevice( dev ); @@ -234,58 +223,54 @@ void adfDeviceInfo ( struct AdfDevice * dev ) * * adfInitDevice() must fill dev->size ! */ -struct AdfDevice * adfMountDev ( const char * const filename, - const AdfAccessMode mode ) +RETCODE adfMountDev ( struct AdfDevice * dev ) { - RETCODE rc; - uint8_t buf[512]; + if ( dev == NULL ) + return RC_ERROR; - struct AdfDevice * dev = adfOpenDev ( filename, mode ); - if ( ! dev ) { - //(*adfEnv.eFct)("adfMountDev : malloc error"); - return NULL; - } + RETCODE rc; switch( dev->devType ) { case DEVTYPE_FLOPDD: - case DEVTYPE_FLOPHD: - if ( adfMountFlop ( dev ) != RC_OK ) { - adfCloseDev ( dev ); - return NULL; + case DEVTYPE_FLOPHD: { + rc = adfMountFlop ( dev ); + if ( rc != RC_OK ) + return rc; } break; - case DEVTYPE_HARDDISK: + case DEVTYPE_HARDDISK: { + uint8_t buf[512]; rc = adfReadBlockDev ( dev, 0, 512, buf ); /* BV ...from here*/ if( rc != RC_OK ) { - adfCloseDev ( dev ); - (*adfEnv.eFct)("adfMountDev : adfReadDumpSector failed"); - return NULL; + adfEnv.eFct ( "adfMountDev : adfReadBlockDev 0 (bootblock) failed"); + return rc; } /* a file with the first three bytes equal to 'DOS' */ if (!dev->isNativeDev && strncmp("DOS",(char*)buf,3)==0) { - if ( adfMountHdFile ( dev ) != RC_OK ) { - adfCloseDev ( dev ); - return NULL; - } + rc = adfMountHdFile ( dev ); + if ( rc != RC_OK ) + return rc; } - else if ( adfMountHd ( dev ) != RC_OK ) { - adfCloseDev ( dev ); - return NULL; /* BV ...to here.*/ + else { + rc = adfMountHd ( dev ); + if ( rc != RC_OK ) + return rc; /* BV ...to here.*/ + } } - break; + break; default: (*adfEnv.eFct)("adfMountDev : unknown device type"); - adfCloseDev ( dev ); - return NULL; /* BV */ + return RC_ERROR; /* BV */ } - return dev; + dev->mounted = TRUE; + return RC_OK; } @@ -295,7 +280,22 @@ struct AdfDevice * adfMountDev ( const char * const filename, */ void adfUnMountDev ( struct AdfDevice * const dev ) { - adfCloseDev ( dev ); + if ( ! dev->mounted ) + return; + + // free volume list + //if ( dev->volList ) { + if ( dev->nVol > 0 ) { + for ( int i = 0 ; i < dev->nVol ; i++ ) { + free ( dev->volList[i]->volName ); + free ( dev->volList[i] ); + } + free ( dev->volList ); + dev->nVol = 0; + } + + dev->volList = NULL; + dev->mounted = FALSE; } diff --git a/src/adf_dev.h b/src/adf_dev.h index a15eaaf3..87164739 100644 --- a/src/adf_dev.h +++ b/src/adf_dev.h @@ -28,9 +28,6 @@ struct AdfDevice { BOOL readOnly; uint32_t size; /* in bytes */ - int nVol; /* partitions */ - struct AdfVolume** volList; - uint32_t cylinders; /* geometry */ uint32_t heads; uint32_t sectors; @@ -40,6 +37,12 @@ struct AdfDevice { void *nativeDev; /* for use by native functions */ FILE *fd; + + BOOL mounted; + + // stuff available when mounted + int nVol; /* partitions */ + struct AdfVolume** volList; }; @@ -50,8 +53,7 @@ PREFIX void adfCloseDev ( struct AdfDevice * const dev ); PREFIX int adfDevType ( struct AdfDevice * dev ); PREFIX void adfDeviceInfo ( struct AdfDevice * dev ); -PREFIX struct AdfDevice * adfMountDev ( const char * const filename, - const AdfAccessMode mode ); +PREFIX RETCODE adfMountDev ( struct AdfDevice * dev ); PREFIX void adfUnMountDev ( struct AdfDevice * const dev ); //struct AdfDevice* adfCreateDev(char* filename, int32_t cylinders, int32_t heads, int32_t sectors); diff --git a/src/adf_dev_dump.c b/src/adf_dev_dump.c index ca4a3c67..dde8c1cf 100644 --- a/src/adf_dev_dump.c +++ b/src/adf_dev_dump.c @@ -239,6 +239,7 @@ struct AdfDevice * adfCreateDumpDevice ( const char * const filename, dev->nVol = 0; dev->isNativeDev = FALSE; dev->readOnly = FALSE; + dev->mounted = FALSE; return(dev); } diff --git a/src/adf_dev_flop.c b/src/adf_dev_flop.c index 7c344c88..9e710a70 100644 --- a/src/adf_dev_flop.c +++ b/src/adf_dev_flop.c @@ -127,5 +127,7 @@ RETCODE adfCreateFlop ( struct AdfDevice * const dev, else dev->devType=DEVTYPE_FLOPHD; + dev->mounted = TRUE; + return RC_OK; } diff --git a/src/adf_dev_hd.c b/src/adf_dev_hd.c index 642bb44f..fddb956d 100644 --- a/src/adf_dev_hd.c +++ b/src/adf_dev_hd.c @@ -390,6 +390,8 @@ vol=dev->volList[0]; printf("0first=%ld last=%ld root=%ld\n",vol->firstBlock, vol->lastBlock, vol->rootBlock); */ + dev->mounted = TRUE; + return adfCreateHdHeader ( dev, (int) n, partList ); } From b545e4dd10dbf53e0b1da6cec1566baa846896b5 Mon Sep 17 00:00:00 2001 From: t-m Date: Mon, 29 Jan 2024 23:48:15 +0100 Subject: [PATCH 11/40] tests: properly open/mount/umount/close adf devices (changed API). --- tests/test_file_append.c | 1 + tests/test_file_create.c | 1 + tests/test_file_overwrite.c | 1 + tests/test_file_overwrite2.c | 2 ++ tests/test_file_seek.c | 1 + tests/test_file_seek_after_write.c | 1 + tests/test_file_truncate.c | 1 + tests/test_file_truncate2.c | 1 + tests/test_file_write.c | 1 + tests/test_file_write_chunks.c | 1 + 10 files changed, 11 insertions(+) diff --git a/tests/test_file_append.c b/tests/test_file_append.c index cbbfbdee..bb8224a6 100644 --- a/tests/test_file_append.c +++ b/tests/test_file_append.c @@ -268,5 +268,6 @@ void teardown ( test_data_t * const tdata ) { //adfUnMount ( tdata->vol ); adfUnMountDev ( tdata->device ); + adfCloseDev ( tdata->device ); unlink ( tdata->adfname ); } diff --git a/tests/test_file_create.c b/tests/test_file_create.c index 01314a2e..e7e03425 100644 --- a/tests/test_file_create.c +++ b/tests/test_file_create.c @@ -272,5 +272,6 @@ void teardown ( test_data_t * const tdata ) { //adfUnMount ( tdata->vol ); adfUnMountDev ( tdata->device ); + adfCloseDev ( tdata->device ); unlink ( tdata->adfname ); } diff --git a/tests/test_file_overwrite.c b/tests/test_file_overwrite.c index 63e98dbc..4a12e131 100644 --- a/tests/test_file_overwrite.c +++ b/tests/test_file_overwrite.c @@ -325,4 +325,5 @@ void teardown ( test_data_t * const tdata ) { //adfUnMount ( tdata->vol ); adfUnMountDev ( tdata->device ); + adfCloseDev ( tdata->device ); } diff --git a/tests/test_file_overwrite2.c b/tests/test_file_overwrite2.c index e538667a..95c59ca2 100644 --- a/tests/test_file_overwrite2.c +++ b/tests/test_file_overwrite2.c @@ -412,6 +412,8 @@ void teardown ( test_data_t * const tdata ) //adfUnMount ( tdata->vol ); adfUnMountDev ( tdata->device ); + adfCloseDev ( tdata->device ); + //printf ("unlinkuing the file %s\n", tdata->adfname ); //fflush(stdout); if ( unlink ( tdata->adfname ) != 0 ) diff --git a/tests/test_file_seek.c b/tests/test_file_seek.c index 9a3acd98..2413d712 100644 --- a/tests/test_file_seek.c +++ b/tests/test_file_seek.c @@ -274,6 +274,7 @@ void teardown ( test_data_t * const tdata ) //adfUnMount ( tdata->vol ); adfUnMountDev ( tdata->device ); + adfCloseDev ( tdata->device ); if ( unlink ( tdata->adfname ) != 0 ) perror("error deleting the image"); } diff --git a/tests/test_file_seek_after_write.c b/tests/test_file_seek_after_write.c index 1e8bdb66..d6751df6 100644 --- a/tests/test_file_seek_after_write.c +++ b/tests/test_file_seek_after_write.c @@ -343,6 +343,7 @@ void teardown ( test_data_t * const tdata ) //adfUnMount ( tdata->vol ); adfUnMountDev ( tdata->device ); + adfCloseDev ( tdata->device ); if ( unlink ( tdata->adfname ) != 0 ) perror("error deleting the image"); } diff --git a/tests/test_file_truncate.c b/tests/test_file_truncate.c index afeea19d..7957b302 100644 --- a/tests/test_file_truncate.c +++ b/tests/test_file_truncate.c @@ -482,6 +482,7 @@ void teardown ( test_data_t * const tdata ) //adfUnMount ( tdata->vol ); adfUnMountDev ( tdata->device ); + adfCloseDev ( tdata->device ); if ( unlink ( tdata->adfname ) != 0 ) perror("error deleting the image"); } diff --git a/tests/test_file_truncate2.c b/tests/test_file_truncate2.c index 3c0fa974..363a5412 100644 --- a/tests/test_file_truncate2.c +++ b/tests/test_file_truncate2.c @@ -359,6 +359,7 @@ void teardown ( test_data_t * const tdata ) //adfUnMount ( tdata->vol ); adfUnMountDev ( tdata->device ); + adfCloseDev ( tdata->device ); if ( unlink ( tdata->adfname ) != 0 ) perror("error deleting the image"); } diff --git a/tests/test_file_write.c b/tests/test_file_write.c index 44d042a7..d4f19353 100644 --- a/tests/test_file_write.c +++ b/tests/test_file_write.c @@ -339,5 +339,6 @@ void teardown ( test_data_t * const tdata ) //adfUnMount ( tdata->vol ); adfUnMountDev ( tdata->device ); + adfCloseDev ( tdata->device ); unlink ( tdata->adfname ); } diff --git a/tests/test_file_write_chunks.c b/tests/test_file_write_chunks.c index 5ca0c695..3429a907 100644 --- a/tests/test_file_write_chunks.c +++ b/tests/test_file_write_chunks.c @@ -396,5 +396,6 @@ void teardown ( test_data_t * const tdata ) //adfUnMount ( tdata->vol ); adfUnMountDev ( tdata->device ); + adfCloseDev ( tdata->device ); unlink ( tdata->adfname ); } From c0b0c2da381bda35ecb36825031666c686fbb924 Mon Sep 17 00:00:00 2001 From: t-m Date: Mon, 29 Jan 2024 23:50:40 +0100 Subject: [PATCH 12/40] regtests: properly open/mount/umount/close adf devices (changed API). --- regtests/Test/access.c | 11 +++++- regtests/Test/bitmap_read_segfault.c | 14 ++++++-- regtests/Test/bitmap_recreate.c | 44 +++++++++++++++++------- regtests/Test/bootdisk.c | 3 ++ regtests/Test/bootdisk2.c | 1 + regtests/Test/cache_crash.c | 25 ++++++++------ regtests/Test/cache_test.c | 3 +- regtests/Test/comment.c | 11 +++++- regtests/Test/del_test.c | 19 +++++++--- regtests/Test/dir_test.c | 19 +++++++--- regtests/Test/dir_test2.c | 19 +++++++--- regtests/Test/dir_test_chdir.c | 15 ++++++-- regtests/Test/dirc.c | 3 +- regtests/Test/dirc_test.c | 3 +- regtests/Test/dispsect.c | 11 +++++- regtests/Test/file_read_hard_link_test.c | 15 ++++++-- regtests/Test/file_seek_after_write.c | 1 + regtests/Test/file_seek_test.c | 15 ++++++-- regtests/Test/file_seek_test2.c | 17 +++++++-- regtests/Test/file_test.c | 44 ++++++++++++++++++------ regtests/Test/file_test2.c | 21 +++++++---- regtests/Test/file_test2a.c | 3 +- regtests/Test/file_test3.c | 26 +++++++++++--- regtests/Test/fl_test.c | 23 ++++++++++--- regtests/Test/fl_test2.c | 18 +++++++--- regtests/Test/flfile_test.c | 2 ++ regtests/Test/floppy_overfilling_test.c | 1 + regtests/Test/hardfile.c | 17 ++++++--- regtests/Test/hardfile2.c | 3 +- regtests/Test/hd_test.c | 40 ++++++++++++++++----- regtests/Test/hd_test2.c | 25 +++++++++++--- regtests/Test/hd_test3.c | 27 ++++++++++++--- regtests/Test/progbar.c | 3 ++ regtests/Test/readonly.c | 23 +++++++++---- regtests/Test/rename.c | 43 ++++++++++++++++++++--- regtests/Test/rename2.c | 3 ++ regtests/Test/undel.c | 11 +++++- regtests/Test/undel2.c | 16 +++++++-- regtests/Test/undel3.c | 16 +++++++-- 39 files changed, 485 insertions(+), 129 deletions(-) diff --git a/regtests/Test/access.c b/regtests/Test/access.c index c2af6597..fce31a28 100644 --- a/regtests/Test/access.c +++ b/regtests/Test/access.c @@ -43,18 +43,26 @@ int main(int argc, char *argv[]) if (adfCreateFlop( hd, "empty", FSMASK_FFS|FSMASK_DIRCACHE )!=RC_OK) { fprintf(stderr, "can't create floppy\n"); adfUnMountDev(hd); + adfCloseDev(hd); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } fic = adfFileOpen ( vol, "file_1a", ADF_FILE_MODE_WRITE ); - if (!fic) { adfUnMount(vol); adfUnMountDev(hd); adfEnvCleanUp(); exit(1); } + if (!fic) { + adfUnMount(vol); + adfUnMountDev(hd); + adfCloseDev(hd); + adfEnvCleanUp(); + exit(1); + } adfFileWrite ( fic, 1, buf ); adfFileClose ( fic ); @@ -95,6 +103,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/bitmap_read_segfault.c b/regtests/Test/bitmap_read_segfault.c index 4530e421..74c97b5c 100644 --- a/regtests/Test/bitmap_read_segfault.c +++ b/regtests/Test/bitmap_read_segfault.c @@ -39,11 +39,18 @@ int main ( const int argc, // adfSetEnvFct(0,0,MyVer,0); BOOL error_status = FALSE; - struct AdfDevice * const dev = adfMountDev ( argv[1], ADF_ACCESS_MODE_READONLY ); + struct AdfDevice * const dev = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READONLY ); + if ( ! dev ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + argv[1] ); + adfEnvCleanUp(); + exit(1); + } + RETCODE rc = adfMountDev ( dev ); if ( dev == NULL ) { log_error ( stderr, "can't mount device %s\n", argv[1] ); error_status = TRUE; - goto clean_up; + goto close_dev; } /*** crash happens here, on mounting the volume, in adfReadBitmap() ***/ @@ -62,6 +69,9 @@ int main ( const int argc, umount_dev: adfUnMountDev ( dev ); +close_dev: + adfCloseDev ( dev ); + clean_up: adfEnvCleanUp(); diff --git a/regtests/Test/bitmap_recreate.c b/regtests/Test/bitmap_recreate.c index 40db5c8e..df1fa143 100644 --- a/regtests/Test/bitmap_recreate.c +++ b/regtests/Test/bitmap_recreate.c @@ -74,14 +74,21 @@ int main ( const int argc, // adfSetEnvFct(0,0,MyVer,0); /* mount the original image */ - struct AdfDevice * const devOrig = adfMountDev ( adfOrig, - ADF_ACCESS_MODE_READONLY ); - if ( devOrig == NULL ) { - log_error ( stderr, "can't mount device %s\n", adfOrig ); + struct AdfDevice * devOrig = adfOpenDev ( adfOrig, ADF_ACCESS_MODE_READONLY ); + if ( ! devOrig ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + adfOrig ); error_status = TRUE; goto clean_up; } + RETCODE rc = adfMountDev ( devOrig ); + if ( rc != RC_OK ) { + log_error ( stderr, "can't mount device %s\n", adfOrig ); + error_status = TRUE; + goto close_dev_orig; + } + struct AdfVolume * const volOrig = adfMount ( devOrig, 0, ADF_ACCESS_MODE_READONLY ); if ( volOrig == NULL ) { @@ -92,13 +99,20 @@ int main ( const int argc, /* mount the image copy (for updating) */ - struct AdfDevice * const devUpdate = adfMountDev ( adfUpdate, - ADF_ACCESS_MODE_READWRITE ); + struct AdfDevice * const devUpdate = adfOpenDev ( adfUpdate, + ADF_ACCESS_MODE_READWRITE ); + if ( ! devUpdate ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + adfUpdate ); + error_status = TRUE; + goto umount_vol_orig; + } - if ( devUpdate == NULL ) { + rc = adfMountDev ( devUpdate ); + if ( rc != RC_OK ) { log_error ( stderr, "can't mount device %s\n", adfUpdate ); error_status = TRUE; - goto umount_vol_orig; + goto close_dev_updated; } struct AdfVolume * volUpdate = adfMount ( devUpdate, 0, @@ -111,7 +125,7 @@ int main ( const int argc, /* update the block allocation bitmap */ - RETCODE rc = adfRemount ( volUpdate, ADF_ACCESS_MODE_READWRITE ); + rc = adfRemount ( volUpdate, ADF_ACCESS_MODE_READWRITE ); if ( rc != RC_OK ) { log_error ( stderr, "error remounting read-write, volume %d\n", 0 ); @@ -124,14 +138,16 @@ int main ( const int argc, if ( rc != RC_OK ) { adfEnv.eFct ( "Invalid RootBlock, volume %s, sector %u - aborting...", volUpdate->volName, volUpdate->rootBlock ); - return rc; + error_status = TRUE; + goto umount_vol_updated; } rc = adfReconstructBitmap ( volUpdate, &root ); if ( rc != RC_OK ) { adfEnv.eFct ( "Error rebuilding the bitmap (%d), volume %s", rc, volUpdate->volName ); - return rc; + error_status = TRUE; + goto umount_vol_updated; } /* @@ -167,15 +183,17 @@ int main ( const int argc, umount_vol_updated: adfUnMount ( volUpdate ); - umount_dev_updated: adfUnMountDev ( devUpdate ); +close_dev_updated: + adfCloseDev ( devUpdate ); umount_vol_orig: adfUnMount ( volOrig ); - umount_dev_orig: adfUnMountDev ( devOrig ); +close_dev_orig: + adfCloseDev ( devOrig ); clean_up: adfEnvCleanUp(); diff --git a/regtests/Test/bootdisk.c b/regtests/Test/bootdisk.c index a2b5cc4c..4124a9ba 100644 --- a/regtests/Test/bootdisk.c +++ b/regtests/Test/bootdisk.c @@ -54,12 +54,14 @@ int main(int argc, char *argv[]) if (adfCreateFlop( hd, "empty", FSMASK_FFS|FSMASK_DIRCACHE )!=RC_OK) { fprintf(stderr, "can't create floppy\n"); adfUnMountDev(hd); + adfCloseDev(hd); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -70,6 +72,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/bootdisk2.c b/regtests/Test/bootdisk2.c index 02bb27f1..823415a1 100644 --- a/regtests/Test/bootdisk2.c +++ b/regtests/Test/bootdisk2.c @@ -46,6 +46,7 @@ int main(int argc, char *argv[]) vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } diff --git a/regtests/Test/cache_crash.c b/regtests/Test/cache_crash.c index 51fba51b..508ad8ab 100644 --- a/regtests/Test/cache_crash.c +++ b/regtests/Test/cache_crash.c @@ -13,18 +13,21 @@ int main(int argc, char *argv[]) { if (argc <= 1) return 1; adfEnvInitDefault(); - if ((dev = adfMountDev(argv[1], ADF_ACCESS_MODE_READONLY))) { - if ((vol = adfMount(dev, 0, ADF_ACCESS_MODE_READONLY))) { - /* use dir cache (enables the crash) */ - adfChgEnvProp(PR_USEDIRC, &true); - /* read all directory entries (crash happens here) */ - list = adfGetRDirEnt(vol, vol->curDirPtr, TRUE); - /* success! we didn't crash */ - ok = TRUE; - if (list) adfFreeDirList(list); - adfUnMount(vol); + if (dev = adfOpenDev(argv[1], ADF_ACCESS_MODE_READONLY)) { + if (adfMountDev(dev) == RC_OK) { + if ((vol = adfMount(dev, 0, ADF_ACCESS_MODE_READONLY))) { + /* use dir cache (enables the crash) */ + adfChgEnvProp(PR_USEDIRC, &true); + /* read all directory entries (crash happens here) */ + list = adfGetRDirEnt(vol, vol->curDirPtr, TRUE); + /* success! we didn't crash */ + ok = TRUE; + if (list) adfFreeDirList(list); + adfUnMount(vol); + } + adfUnMountDev(dev); } - adfUnMountDev(dev); + adfCloseDev(dev); } adfEnvCleanUp(); return ok ? 0 : 1; diff --git a/regtests/Test/cache_test.c b/regtests/Test/cache_test.c index 853c1a7c..f85eaaf4 100644 --- a/regtests/Test/cache_test.c +++ b/regtests/Test/cache_test.c @@ -45,6 +45,7 @@ int main(int argc, char *argv[]) vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -98,7 +99,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); - + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/comment.c b/regtests/Test/comment.c index 55f9a06d..22449942 100644 --- a/regtests/Test/comment.c +++ b/regtests/Test/comment.c @@ -44,18 +44,26 @@ int main(int argc, char *argv[]) if (adfCreateFlop( hd, "empty", FSMASK_FFS|FSMASK_DIRCACHE )!=RC_OK) { fprintf(stderr, "can't create floppy\n"); adfUnMountDev(hd); + adfCloseDev(hd); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } fic = adfFileOpen ( vol, "file_1a", ADF_FILE_MODE_WRITE ); - if (!fic) { adfUnMount(vol); adfUnMountDev(hd); adfEnvCleanUp(); exit(1); } + if (!fic) { + adfUnMount(vol); + adfUnMountDev(hd); + adfCloseDev(hd); + adfEnvCleanUp(); + exit(1); + } adfFileWrite ( fic, 1, buf ); adfFileClose ( fic ); @@ -98,6 +106,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/del_test.c b/regtests/Test/del_test.c index 3fe095be..92db7b69 100644 --- a/regtests/Test/del_test.c +++ b/regtests/Test/del_test.c @@ -28,23 +28,32 @@ int main(int argc, char *argv[]) return 1; } - struct AdfDevice *hd; struct AdfVolume *vol; struct AdfList *list, *head; SECTNUM nSect; adfEnvInitDefault(); - /* mount existing device */ - hd = adfMountDev( argv[1], ADF_ACCESS_MODE_READWRITE ); - if (!hd) { + /* open and mount existing device */ + struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + if ( ! hd ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + argv[1] ); + adfEnvCleanUp(); + exit(1); + } + + RETCODE rc = adfMountDev ( hd ); + if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); + adfCloseDev(hd); adfEnvCleanUp(); exit(1); } vol = adfMount(hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -113,7 +122,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); - + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/dir_test.c b/regtests/Test/dir_test.c index 0e6032e4..7e88add6 100644 --- a/regtests/Test/dir_test.c +++ b/regtests/Test/dir_test.c @@ -37,7 +37,6 @@ int main(int argc, char *argv[]) return 1; } - struct AdfDevice *hd; struct AdfVolume *vol; struct AdfList *list, *cell; @@ -45,17 +44,27 @@ int main(int argc, char *argv[]) // adfSetEnvFct(0,0,MyVer,0); - /* mount existing device */ + /* open and mount existing device */ /* testffs.adf */ - hd = adfMountDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); - if (!hd) { + struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + if ( ! hd ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + argv[1] ); + adfEnvCleanUp(); + exit(1); + } + + RETCODE rc = adfMountDev ( hd ); + if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); + adfCloseDev(hd); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -108,7 +117,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); - + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/dir_test2.c b/regtests/Test/dir_test2.c index 784c1708..23eeef5b 100644 --- a/regtests/Test/dir_test2.c +++ b/regtests/Test/dir_test2.c @@ -28,7 +28,6 @@ int main(int argc, char *argv[]) return 1; } - struct AdfDevice *hd; struct AdfVolume *vol; struct AdfList *list, *cell; @@ -36,16 +35,26 @@ int main(int argc, char *argv[]) // adfSetEnvFct(0,0,MyVer,0); - /* mount existing device */ - hd = adfMountDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); - if (!hd) { + /* open and mount existing device */ + struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + if ( ! hd ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + argv[1] ); + adfEnvCleanUp(); + exit(1); + } + + RETCODE rc = adfMountDev ( hd ); + if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); + adfCloseDev(hd); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -86,7 +95,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); - + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/dir_test_chdir.c b/regtests/Test/dir_test_chdir.c index 45ab58a2..dd46cbaf 100644 --- a/regtests/Test/dir_test_chdir.c +++ b/regtests/Test/dir_test_chdir.c @@ -90,11 +90,20 @@ int run_chdir_tests ( chdir_test_t * test_data ) test_data->image ); //#endif - struct AdfDevice * const dev = adfMountDev ( test_data->image, - ADF_ACCESS_MODE_READONLY ); + struct AdfDevice * const dev = adfOpenDev ( test_data->image, + ADF_ACCESS_MODE_READONLY ); if ( ! dev ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + test_data->image ); + adfEnvCleanUp(); + exit(1); + } + + RETCODE rc = adfMountDev ( dev ); + if ( rc != RC_OK ) { fprintf ( stderr, "Cannot mount image %s - aborting the test...\n", test_data->image ); + adfCloseDev ( dev ); return 1; } @@ -103,6 +112,7 @@ int run_chdir_tests ( chdir_test_t * test_data ) fprintf ( stderr, "Cannot mount volume 0 from image %s - aborting the test...\n", test_data->image ); adfUnMountDev ( dev ); + adfCloseDev ( dev ); return 1; } @@ -123,6 +133,7 @@ int run_chdir_tests ( chdir_test_t * test_data ) //adfToRootDir ( vol ); adfUnMount ( vol ); adfUnMountDev ( dev ); + adfCloseDev ( dev ); return nerrors; } diff --git a/regtests/Test/dirc.c b/regtests/Test/dirc.c index 3baf4158..1d0bb526 100644 --- a/regtests/Test/dirc.c +++ b/regtests/Test/dirc.c @@ -42,6 +42,7 @@ int main(int argc, char *argv[]) vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -77,7 +78,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); - + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/dirc_test.c b/regtests/Test/dirc_test.c index 3c3ef9e5..59adc44a 100644 --- a/regtests/Test/dirc_test.c +++ b/regtests/Test/dirc_test.c @@ -41,6 +41,7 @@ int main(int argc, char *argv[]) vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -59,7 +60,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); - + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/dispsect.c b/regtests/Test/dispsect.c index dfe88323..ac455de2 100644 --- a/regtests/Test/dispsect.c +++ b/regtests/Test/dispsect.c @@ -50,18 +50,26 @@ int main(int argc, char *argv[]) if (adfCreateFlop( hd, "empty", FSMASK_FFS|FSMASK_DIRCACHE )!=RC_OK) { fprintf(stderr, "can't create floppy\n"); adfUnMountDev(hd); + adfCloseDev(hd); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } fic = adfFileOpen ( vol, "file_1a", ADF_FILE_MODE_WRITE ); - if (!fic) { adfUnMount(vol); adfUnMountDev(hd); adfEnvCleanUp(); exit(1); } + if (!fic) { + adfUnMount(vol); + adfUnMountDev(hd); + adfCloseDev(hd); + adfEnvCleanUp(); + exit(1); + } adfFileWrite ( fic, 1, buf ); adfFileClose ( fic ); @@ -117,6 +125,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/file_read_hard_link_test.c b/regtests/Test/file_read_hard_link_test.c index 15a9b47c..6d459e0a 100644 --- a/regtests/Test/file_read_hard_link_test.c +++ b/regtests/Test/file_read_hard_link_test.c @@ -109,11 +109,20 @@ int test_hlink_read ( reading_test_t * test_data ) test_data->real_file ); #endif - struct AdfDevice * const dev = adfMountDev ( test_data->image_filename, - ADF_ACCESS_MODE_READONLY ); + struct AdfDevice * const dev = adfOpenDev ( test_data->image_filename, + ADF_ACCESS_MODE_READONLY ); if ( ! dev ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + test_data->image_filename ); + adfEnvCleanUp(); + exit(1); + } + + RETCODE rc = adfMountDev ( dev ); + if ( rc != RC_OK ) { fprintf ( stderr, "Cannot mount image %s - aborting the test...\n", test_data->image_filename ); + adfCloseDev ( dev ); return 1; } @@ -122,6 +131,7 @@ int test_hlink_read ( reading_test_t * test_data ) fprintf ( stderr, "Cannot mount volume 0 from image %s - aborting the test...\n", test_data->image_filename ); adfUnMountDev ( dev ); + adfCloseDev ( dev ); return 1; } @@ -168,6 +178,7 @@ int test_hlink_read ( reading_test_t * test_data ) //adfToRootDir ( vol ); adfUnMount ( vol ); adfUnMountDev ( dev ); + adfCloseDev ( dev ); return status; } diff --git a/regtests/Test/file_seek_after_write.c b/regtests/Test/file_seek_after_write.c index 693d50cf..9f077461 100644 --- a/regtests/Test/file_seek_after_write.c +++ b/regtests/Test/file_seek_after_write.c @@ -377,6 +377,7 @@ unsigned test_seek_after_write ( const test_data_t * const test_data ) adfUnMount ( vol ); umount_device: adfUnMountDev ( device ); + adfCloseDev ( device ); if ( unlink ( adfname ) != 0 ) perror ("error deleting the image"); return errors; diff --git a/regtests/Test/file_seek_test.c b/regtests/Test/file_seek_test.c index 9a368888..368660ba 100644 --- a/regtests/Test/file_seek_test.c +++ b/regtests/Test/file_seek_test.c @@ -134,11 +134,20 @@ int run_single_seek_tests ( reading_test_t * test_data ) fflush ( stdout ); #endif - struct AdfDevice * const dev = adfMountDev ( test_data->image_filename, - ADF_ACCESS_MODE_READONLY ); + struct AdfDevice * const dev = adfOpenDev ( test_data->image_filename, + ADF_ACCESS_MODE_READONLY ); if ( ! dev ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + test_data->image_filename ); + adfEnvCleanUp(); + exit(1); + } + + RETCODE rc = adfMountDev ( dev ); + if ( rc != RC_OK ) { fprintf ( stderr, "Cannot mount image %s - aborting the test...\n", test_data->image_filename ); + adfCloseDev ( dev ); return 1; } @@ -147,6 +156,7 @@ int run_single_seek_tests ( reading_test_t * test_data ) fprintf ( stderr, "Cannot mount volume 0 from image %s - aborting the test...\n", test_data->image_filename ); adfUnMountDev ( dev ); + adfCloseDev ( dev ); return 1; } #if TEST_VERBOSITY > 0 @@ -184,6 +194,7 @@ int run_single_seek_tests ( reading_test_t * test_data ) cleanup: adfUnMount ( vol ); adfUnMountDev ( dev ); + adfCloseDev ( dev ); return status; } diff --git a/regtests/Test/file_seek_test2.c b/regtests/Test/file_seek_test2.c index f5f2196a..b9aca01c 100644 --- a/regtests/Test/file_seek_test2.c +++ b/regtests/Test/file_seek_test2.c @@ -82,19 +82,29 @@ int run_multiple_seek_tests ( test_file_t * test_data ) test_data->filename_local ); #endif - struct AdfDevice * const dev = adfMountDev ( test_data->image_filename, - ADF_ACCESS_MODE_READONLY ); + struct AdfDevice * const dev = adfOpenDev ( test_data->image_filename, + ADF_ACCESS_MODE_READONLY ); if ( ! dev ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + test_data->image_filename ); + adfEnvCleanUp(); + exit(1); + } + + RETCODE rc = adfMountDev ( dev ); + if ( rc != RC_OK ) { fprintf ( stderr, "Cannot mount image %s - aborting the test...\n", test_data->image_filename ); + adfCloseDev ( dev ); return 1; } struct AdfVolume * const vol = adfMount ( dev, 0, ADF_ACCESS_MODE_READONLY ); if ( ! vol ) { - printf ( "Cannot mount volume 0 from image %s - aborting the test...\n", + fprintf ( stderr, "Cannot mount volume 0 from image %s - aborting the test...\n", test_data->image_filename ); adfUnMountDev ( dev ); + adfCloseDev ( dev ); return 1; } #if TEST_VERBOSITY > 0 @@ -135,6 +145,7 @@ int run_multiple_seek_tests ( test_file_t * test_data ) cleanup: adfUnMount ( vol ); adfUnMountDev ( dev ); + adfCloseDev ( dev ); return status; } diff --git a/regtests/Test/file_test.c b/regtests/Test/file_test.c index 01d8a609..486ff801 100644 --- a/regtests/Test/file_test.c +++ b/regtests/Test/file_test.c @@ -1,5 +1,5 @@ /* - * dir_test.c + * file_test.c */ @@ -28,7 +28,6 @@ int main(int argc, char *argv[]) return 1; } - struct AdfDevice *hd; struct AdfVolume *vol; struct AdfFile *file; unsigned char buf[600]; @@ -38,16 +37,26 @@ int main(int argc, char *argv[]) // adfSetEnvFct(0,0,MyVer,0); - /* mount existing device : FFS */ - hd = adfMountDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); - if (!hd) { + /* open and mount existing device : FFS */ + struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + if ( ! hd ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + argv[1] ); + adfEnvCleanUp(); + exit(1); + } + + RETCODE rc = adfMountDev ( hd ); + if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); + adfCloseDev(hd); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -74,10 +83,12 @@ int main(int argc, char *argv[]) file = adfFileOpen ( vol, "emptyfile", ADF_FILE_MODE_READ ); if (!file) { - adfUnMount(vol); adfUnMountDev(hd); + adfUnMount(vol); + adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't open file\n"); - exit(1); - } + exit(1); + } n = adfFileRead ( file, 2, buf ); @@ -85,19 +96,30 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); + adfCloseDev(hd); /* ofs */ - hd = adfMountDev ( argv[2], ADF_ACCESS_MODE_READWRITE ); - if (!hd) { + hd = adfOpenDev ( argv[2], ADF_ACCESS_MODE_READWRITE ); + if ( ! hd ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + argv[2] ); + adfEnvCleanUp(); + exit(1); + } + + rc = adfMountDev ( hd ); + if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); + adfCloseDev(hd); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -124,7 +146,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); - + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/file_test2.c b/regtests/Test/file_test2.c index 7d298601..c6cbe5e9 100644 --- a/regtests/Test/file_test2.c +++ b/regtests/Test/file_test2.c @@ -1,5 +1,5 @@ /* - * dir_test.c + * file_test2.c */ @@ -28,7 +28,6 @@ int main(int argc, char *argv[]) return 1; } - struct AdfDevice *hd; struct AdfVolume *vol; struct AdfFile *file; unsigned char buf[600]; @@ -39,16 +38,26 @@ int main(int argc, char *argv[]) // adfSetEnvFct(0,0,MyVer,0); - /* mount existing device : FFS */ - hd = adfMountDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); - if (!hd) { + /* open and mount existing device : FFS */ + struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + if ( ! hd ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + argv[1] ); + adfEnvCleanUp(); + exit(1); + } + + RETCODE rc = adfMountDev ( hd ); + if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); + adfCloseDev(hd); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -106,7 +115,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); - + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/file_test2a.c b/regtests/Test/file_test2a.c index e4650af4..23552412 100644 --- a/regtests/Test/file_test2a.c +++ b/regtests/Test/file_test2a.c @@ -46,6 +46,7 @@ int main(int argc, char *argv[]) vol = adfMount ( hd, 1, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -103,7 +104,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); - + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/file_test3.c b/regtests/Test/file_test3.c index e167efce..f384bc8b 100644 --- a/regtests/Test/file_test3.c +++ b/regtests/Test/file_test3.c @@ -28,7 +28,6 @@ int main(int argc, char *argv[]) return 1; } - struct AdfDevice *hd; struct AdfVolume *vol; struct AdfFile *file; unsigned char buf[600]; @@ -39,10 +38,29 @@ int main(int argc, char *argv[]) // adfSetEnvFct(0,0,MyVer,0); - /* mount existing device : OFS */ - hd = adfMountDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + /* open and mount existing device : OFS */ + struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + if ( ! hd ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + argv[1] ); + adfEnvCleanUp(); + exit(1); + } + + RETCODE rc = adfMountDev ( hd ); + if ( rc != RC_OK ) { + fprintf(stderr, "can't mount device\n"); + adfCloseDev(hd); + adfEnvCleanUp(); exit(1); + } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); + if (!vol) { + adfUnMountDev(hd); + adfCloseDev(hd); + fprintf(stderr, "can't mount volume\n"); + adfEnvCleanUp(); exit(1); + } adfVolumeInfo(vol); @@ -97,7 +115,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); - + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/fl_test.c b/regtests/Test/fl_test.c index 323230f3..e2e0f2b4 100644 --- a/regtests/Test/fl_test.c +++ b/regtests/Test/fl_test.c @@ -1,5 +1,5 @@ /* - * hd_test.c + * fl_test.c */ @@ -23,7 +23,6 @@ void MyVer(char *msg) int main(int argc, char *argv[]) { (void) argc, (void) argv; - struct AdfDevice *hd; struct AdfVolume *vol; FILE* boot; unsigned char bootcode[1024]; @@ -32,16 +31,26 @@ int main(int argc, char *argv[]) // adfSetEnvFct(0,0,MyVer,0); - /* mount existing device */ - hd = adfMountDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); - if (!hd) { + /* open and mount existing device */ + struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + if ( ! hd ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + argv[1] ); + adfEnvCleanUp(); + exit(1); + } + + RETCODE rc = adfMountDev ( hd ); + if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); + adfCloseDev(hd); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -50,6 +59,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); + adfCloseDev(hd); putchar('\n'); @@ -67,6 +77,7 @@ int main(int argc, char *argv[]) vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -74,6 +85,7 @@ int main(int argc, char *argv[]) boot=fopen(argv[2],"rb"); if (!boot) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -85,6 +97,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/fl_test2.c b/regtests/Test/fl_test2.c index 83d73f5a..c631499b 100644 --- a/regtests/Test/fl_test2.c +++ b/regtests/Test/fl_test2.c @@ -23,7 +23,6 @@ void MyVer(char *msg) int main(int argc, char *argv[]) { (void) argc, (void) argv; - struct AdfDevice *hd; struct AdfVolume *vol; struct AdfList *list, *cell; @@ -31,16 +30,26 @@ int main(int argc, char *argv[]) // adfSetEnvFct(0,0,MyVer,0); - /* mount existing device */ - hd = adfMountDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); - if (!hd) { + /* open and mount existing device */ + struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + if ( ! hd ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + argv[1] ); + adfEnvCleanUp(); + exit(1); + } + + RETCODE rc = adfMountDev ( hd ); + if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); + adfCloseDev(hd); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -57,6 +66,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/flfile_test.c b/regtests/Test/flfile_test.c index 9cea34ba..8c2f8808 100644 --- a/regtests/Test/flfile_test.c +++ b/regtests/Test/flfile_test.c @@ -45,6 +45,7 @@ int main(int argc, char *argv[]) vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -97,6 +98,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/floppy_overfilling_test.c b/regtests/Test/floppy_overfilling_test.c index 7cf902bc..f44f29b8 100644 --- a/regtests/Test/floppy_overfilling_test.c +++ b/regtests/Test/floppy_overfilling_test.c @@ -159,6 +159,7 @@ int test_floppy_overfilling ( test_data_t * const tdata ) adfUnMount ( vol ); adfUnMountDev ( device ); + adfCloseDev ( device ); #if TEST_VERBOSITY > 0 printf (" -> %s\n", status ? "ERROR" : "OK" ); diff --git a/regtests/Test/hardfile.c b/regtests/Test/hardfile.c index 83bd8b1c..144e33f5 100644 --- a/regtests/Test/hardfile.c +++ b/regtests/Test/hardfile.c @@ -23,7 +23,6 @@ void MyVer(char *msg) int main(int argc, char *argv[]) { (void) argc, (void) argv; - struct AdfDevice *hd; struct AdfVolume *vol; struct AdfList *list, *cell; @@ -31,9 +30,18 @@ int main(int argc, char *argv[]) adfEnvInitDefault(); - hd = adfMountDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); - if (!hd) { + struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + if ( ! hd ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + argv[1] ); + adfEnvCleanUp(); + exit(1); + } + + RETCODE rc = adfMountDev ( hd ); + if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); + adfCloseDev(hd); adfEnvCleanUp(); exit(1); } @@ -43,6 +51,7 @@ int main(int argc, char *argv[]) vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -58,7 +67,7 @@ int main(int argc, char *argv[]) /* unmounts */ adfUnMount(vol); adfUnMountDev(hd); - + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/hardfile2.c b/regtests/Test/hardfile2.c index 67a4e39a..6fcd325e 100644 --- a/regtests/Test/hardfile2.c +++ b/regtests/Test/hardfile2.c @@ -42,6 +42,7 @@ int main(int argc, char *argv[]) vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -57,7 +58,7 @@ int main(int argc, char *argv[]) /* unmounts */ adfUnMount(vol); adfUnMountDev(hd); - + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/hd_test.c b/regtests/Test/hd_test.c index dfed6d7a..f3523d78 100644 --- a/regtests/Test/hd_test.c +++ b/regtests/Test/hd_test.c @@ -28,16 +28,24 @@ int main(int argc, char *argv[]) return 1; } - struct AdfDevice *hd; struct AdfVolume *vol, *vol2; /* initialisation */ adfEnvInitDefault(); /*** a real harddisk ***/ - hd = adfMountDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); - if (!hd) { + struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + if ( ! hd ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + argv[1] ); + adfEnvCleanUp(); + exit(1); + } + + RETCODE rc = adfMountDev ( hd ); + if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); + adfCloseDev(hd); adfEnvCleanUp(); exit(1); } adfDeviceInfo(hd); @@ -46,7 +54,8 @@ int main(int argc, char *argv[]) vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); - fprintf(stderr, "can't mount volume\n"); + adfCloseDev(hd); + fprintf(stderr, "can't mount volume 0\n"); adfEnvCleanUp(); exit(1); } adfVolumeInfo(vol); @@ -54,7 +63,8 @@ int main(int argc, char *argv[]) vol2 = adfMount(hd, 1, ADF_ACCESS_MODE_READWRITE ); if (!vol2) { adfUnMountDev(hd); - fprintf(stderr, "can't mount volume\n"); + adfCloseDev(hd); + fprintf(stderr, "can't mount volume 1\n"); adfEnvCleanUp(); exit(1); } adfVolumeInfo(vol2); @@ -63,12 +73,22 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMount(vol2); adfUnMountDev(hd); + adfCloseDev(hd); /*** a dump of a zip disk ***/ - hd = adfMountDev( argv[2], ADF_ACCESS_MODE_READWRITE ); - if (!hd) { + hd = adfOpenDev ( argv[2], ADF_ACCESS_MODE_READWRITE ); + if ( ! hd ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + argv[2] ); + adfEnvCleanUp(); + exit(1); + } + + rc = adfMountDev ( hd ); + if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); + adfCloseDev(hd); adfEnvCleanUp(); exit(1); } adfDeviceInfo(hd); @@ -76,13 +96,15 @@ int main(int argc, char *argv[]) vol = adfMount(hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } adfVolumeInfo(vol); - adfUnMount(vol); - adfUnMountDev(hd); + adfUnMount(vol); + adfUnMountDev(hd); + adfCloseDev(hd); /* clean up */ adfEnvCleanUp(); diff --git a/regtests/Test/hd_test2.c b/regtests/Test/hd_test2.c index ce6e0840..fecd4763 100644 --- a/regtests/Test/hd_test2.c +++ b/regtests/Test/hd_test2.c @@ -50,13 +50,20 @@ int main(int argc, char *argv[]) part1.volType = FSMASK_FFS|FSMASK_DIRCACHE; partList[0] = &part1; - adfCreateHd ( hd, 1, (const struct Partition * const * const) partList ); + RETCODE rc = adfCreateHd ( hd, 1, (const struct Partition * const * const) partList ); free(partList); free(part1.volName); + if ( rc != RC_OK ) { + adfUnMountDev(hd); + adfCloseDev(hd); + fprintf ( stderr, "adfCreateHd returned error %d\n", rc ); + adfEnvCleanUp(); exit(1); + } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -64,12 +71,21 @@ int main(int argc, char *argv[]) adfVolumeInfo(vol); adfUnMount(vol); adfUnMountDev(hd); + adfCloseDev(hd); /* mount the created device */ + hd = adfOpenDev ( tmpdevname, ADF_ACCESS_MODE_READWRITE ); + if ( ! hd ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + tmpdevname ); + adfEnvCleanUp(); + exit(1); + } - hd = adfMountDev ( tmpdevname, ADF_ACCESS_MODE_READWRITE ); - if (!hd) { + rc = adfMountDev ( hd ); + if ( rc != RC_OK ) { + adfCloseDev(hd); fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); } @@ -79,6 +95,7 @@ int main(int argc, char *argv[]) vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -87,7 +104,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); - + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/hd_test3.c b/regtests/Test/hd_test3.c index 89675153..d898f015 100644 --- a/regtests/Test/hd_test3.c +++ b/regtests/Test/hd_test3.c @@ -59,14 +59,21 @@ int main(int argc, char *argv[]) partList[0] = &part1; partList[1] = &part2; - adfCreateHd ( hd, 2, (const struct Partition * const * const) partList ); + RETCODE rc = adfCreateHd ( hd, 2, (const struct Partition * const * const) partList ); free(partList); free(part1.volName); free(part2.volName); + if ( rc != RC_OK ) { + adfUnMountDev(hd); + adfCloseDev(hd); + fprintf ( stderr, "adfCreateHd returned error %d\n", rc ); + adfEnvCleanUp(); exit(1); + } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -74,6 +81,7 @@ int main(int argc, char *argv[]) if (!vol2) { adfUnMount(vol); adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -84,12 +92,21 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMount(vol2); adfUnMountDev(hd); + adfCloseDev(hd); /* mount the created device */ - - hd = adfMountDev ( tmpdevname, ADF_ACCESS_MODE_READWRITE ); - if (!hd) { + hd = adfOpenDev ( tmpdevname, ADF_ACCESS_MODE_READWRITE ); + if ( ! hd ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + tmpdevname ); + adfEnvCleanUp(); + exit(1); + } + + rc = adfMountDev ( hd ); + if ( rc != RC_OK ) { + adfCloseDev(hd); fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); } @@ -97,7 +114,7 @@ int main(int argc, char *argv[]) adfDeviceInfo(hd); adfUnMountDev(hd); - + adfCloseDev(hd); adfEnvCleanUp(); return 0; diff --git a/regtests/Test/progbar.c b/regtests/Test/progbar.c index 3c61b9eb..9c5d7187 100644 --- a/regtests/Test/progbar.c +++ b/regtests/Test/progbar.c @@ -47,12 +47,14 @@ puts("\ncreate floppy"); if (adfCreateFlop( hd, "empty", FSMASK_FFS|FSMASK_DIRCACHE )!=RC_OK) { fprintf(stderr, "can't create floppy\n"); adfUnMountDev(hd); + adfCloseDev(hd); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -61,6 +63,7 @@ puts("\ncreate floppy"); adfUnMount(vol); adfUnMountDev(hd); + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/readonly.c b/regtests/Test/readonly.c index 1d9e4b1a..dac4858f 100644 --- a/regtests/Test/readonly.c +++ b/regtests/Test/readonly.c @@ -1,5 +1,5 @@ /* - * del_test.c + * readonly.c */ @@ -28,26 +28,35 @@ int main(int argc, char *argv[]) return 1; } - struct AdfDevice *hd; struct AdfVolume *vol; struct AdfList *list; adfEnvInitDefault(); - /* mount existing device */ - hd = adfMountDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); - if (!hd) { + /* open and mount existing device */ + struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + if ( ! hd ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + argv[1] ); + adfEnvCleanUp(); + exit(1); + } + + RETCODE rc = adfMountDev ( hd ); + if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); + adfCloseDev(hd); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } - + adfVolumeInfo(vol); list = adfGetDirEnt(vol,vol->curDirPtr); @@ -114,7 +123,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); - + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/rename.c b/regtests/Test/rename.c index 4f3f0d5b..dd8bdff9 100644 --- a/regtests/Test/rename.c +++ b/regtests/Test/rename.c @@ -43,12 +43,14 @@ int main(int argc, char *argv[]) if (adfCreateFlop( hd, "empty", FSMASK_FFS|FSMASK_DIRCACHE )!=RC_OK) { fprintf(stderr, "can't create floppy\n"); adfUnMountDev(hd); + adfCloseDev(hd); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -56,22 +58,46 @@ int main(int argc, char *argv[]) adfVolumeInfo(vol); fic = adfFileOpen ( vol, "file_1a", ADF_FILE_MODE_WRITE ); - if (!fic) { adfUnMount(vol); adfUnMountDev(hd); adfEnvCleanUp(); exit(1); } + if (!fic) { + adfUnMount(vol); + adfUnMountDev(hd); + adfCloseDev(hd); + adfEnvCleanUp(); + exit(1); + } adfFileWrite ( fic, 1, buf ); adfFileClose ( fic ); fic = adfFileOpen ( vol, "file_24", ADF_FILE_MODE_WRITE ); - if (!fic) { adfUnMount(vol); adfUnMountDev(hd); adfEnvCleanUp(); exit(1); } + if (!fic) { + adfUnMount(vol); + adfUnMountDev(hd); + adfCloseDev(hd); + adfEnvCleanUp(); + exit(1); + } adfFileWrite ( fic, 1, buf ); adfFileClose ( fic ); fic = adfFileOpen ( vol, "dir_1a", ADF_FILE_MODE_WRITE ); - if (!fic) { adfUnMount(vol); adfUnMountDev(hd); adfEnvCleanUp(); exit(1); } + if (!fic) { + adfUnMount(vol); + adfUnMountDev(hd); + adfCloseDev(hd); + adfEnvCleanUp(); + exit(1); + } adfFileWrite ( fic, 1, buf ); adfFileClose ( fic ); fic = adfFileOpen ( vol, "dir_5u", ADF_FILE_MODE_WRITE ); - if (!fic) { adfUnMount(vol); adfUnMountDev(hd); adfEnvCleanUp(); exit(1); } + if (!fic) { + adfUnMount(vol); + adfUnMountDev(hd); + adfCloseDev(hd); + adfEnvCleanUp(); + exit(1); + } adfFileWrite ( fic, 1, buf ); adfFileClose ( fic ); @@ -113,7 +139,13 @@ int main(int argc, char *argv[]) puts("Create dir_5u, Rename dir_3 into toto"); /* fic = adfOpenFile ( vol, "dir_5u", ADF_FILE_MODE_WRITE ); - if (!fic) { adfUnMount(vol); adfUnMountDev(hd); adfEnvCleanUp(); exit(1); } + if (!fic) { + adfUnMount(vol); + adfUnMountDev(hd); + adfCloseDev(hd); + adfEnvCleanUp(); + exit(1); + } adfWriteFile(fic,1,buf); adfCloseFile(fic); */ @@ -137,6 +169,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/rename2.c b/regtests/Test/rename2.c index e75ab9cd..cf6731df 100644 --- a/regtests/Test/rename2.c +++ b/regtests/Test/rename2.c @@ -39,12 +39,14 @@ int main(int argc, char *argv[]) if (adfCreateFlop( hd, "empty", FSMASK_FFS|FSMASK_DIRCACHE )!=RC_OK) { fprintf(stderr, "can't create floppy\n"); adfUnMountDev(hd); + adfCloseDev(hd); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -122,6 +124,7 @@ printf("[dir = %ld]\n",883L); adfUnMount(vol); adfUnMountDev(hd); + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/undel.c b/regtests/Test/undel.c index 32f64b05..c4137ba9 100644 --- a/regtests/Test/undel.c +++ b/regtests/Test/undel.c @@ -46,18 +46,26 @@ int main(int argc, char *argv[]) if (adfCreateFlop( hd, "empty", FSMASK_FFS|FSMASK_DIRCACHE )!=RC_OK) { fprintf(stderr, "can't create floppy\n"); adfUnMountDev(hd); + adfCloseDev(hd); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } fic = adfFileOpen ( vol, "file_1a", ADF_FILE_MODE_WRITE ); - if (!fic) { adfUnMount(vol); adfUnMountDev(hd); adfEnvCleanUp(); exit(1); } + if (!fic) { + adfUnMount(vol); + adfUnMountDev(hd); + adfCloseDev(hd); + adfEnvCleanUp(); + exit(1); + } adfFileWrite ( fic, 1, buf ); adfFileClose ( fic ); @@ -113,6 +121,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/undel2.c b/regtests/Test/undel2.c index d6265cc3..e137b4df 100644 --- a/regtests/Test/undel2.c +++ b/regtests/Test/undel2.c @@ -23,7 +23,6 @@ void MyVer(char *msg) int main(int argc, char *argv[]) { (void) argc, (void) argv; - struct AdfDevice *hd; struct AdfVolume *vol; struct AdfList *list, *cell; struct GenBlock *block; @@ -36,9 +35,18 @@ int main(int argc, char *argv[]) adfChgEnvProp(PR_USEDIRC,&true); - hd = adfMountDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); - if (!hd) { + struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + if ( ! hd ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + argv[1] ); + adfEnvCleanUp(); + exit(1); + } + + RETCODE rc = adfMountDev ( hd ); + if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); + adfCloseDev(hd); adfEnvCleanUp(); exit(1); } @@ -47,6 +55,7 @@ int main(int argc, char *argv[]) vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -107,6 +116,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); + adfCloseDev(hd); adfEnvCleanUp(); diff --git a/regtests/Test/undel3.c b/regtests/Test/undel3.c index 69d54547..40229b75 100644 --- a/regtests/Test/undel3.c +++ b/regtests/Test/undel3.c @@ -23,7 +23,6 @@ void MyVer(char *msg) int main(int argc, char *argv[]) { (void) argc; - struct AdfDevice *hd; struct AdfVolume *vol; struct AdfList *list, *cell; struct GenBlock *block; @@ -36,9 +35,18 @@ int main(int argc, char *argv[]) adfChgEnvProp(PR_USEDIRC,&true); - hd = adfMountDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); - if (!hd) { + struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + if ( ! hd ) { + fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", + argv[1] ); + adfEnvCleanUp(); + exit(1); + } + + RETCODE rc = adfMountDev ( hd ); + if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); + adfCloseDev(hd); adfEnvCleanUp(); exit(1); } @@ -47,6 +55,7 @@ int main(int argc, char *argv[]) vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { adfUnMountDev(hd); + adfCloseDev(hd); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -104,6 +113,7 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMountDev(hd); + adfCloseDev(hd); adfEnvCleanUp(); From f0eff2fa387b1cd9251aa9141e62078b3e09cfe1 Mon Sep 17 00:00:00 2001 From: t-m Date: Mon, 29 Jan 2024 23:51:11 +0100 Subject: [PATCH 13/40] examples: properly open/mount/umount/close adf devices (changed API). --- examples/adf_bitmap.c | 15 ++++++++++++--- examples/adf_floppy_create.c | 1 + examples/adf_floppy_format.c | 16 +++++++++------- examples/adf_show_metadata.c | 15 ++++++++++++--- examples/unadf.c | 13 ++++++++++--- 5 files changed, 44 insertions(+), 16 deletions(-) diff --git a/examples/adf_bitmap.c b/examples/adf_bitmap.c index 07602935..dd4dc027 100644 --- a/examples/adf_bitmap.c +++ b/examples/adf_bitmap.c @@ -74,7 +74,7 @@ int main ( int argc, printf ( "\nOpening image/device:\t'%s' (%s)\n", adfname, devMode ? "read-only" : "read-write" ); - struct AdfDevice * const dev = adfMountDev ( adfname, devMode ); + struct AdfDevice * const dev = adfOpenDev ( adfname, devMode ); if ( ! dev ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", adfname ); @@ -82,13 +82,20 @@ int main ( int argc, goto env_cleanup; } + RETCODE rc = adfMountDev ( dev ); + if ( rc != RC_OK ) { + fprintf ( stderr, "Cannot get volume info for file/device '%s' - aborting...\n", + adfname ); + goto dev_cleanup; + } + int vol_id = 0; struct AdfVolume * const vol = adfMount ( dev, vol_id, ADF_ACCESS_MODE_READONLY ); if ( ! vol ) { fprintf ( stderr, "Cannot mount volume %d - aborting...\n", vol_id ); status = 1; - goto dev_cleanup; + goto dev_mount_cleanup; } unsigned volSizeBlocks = adfVolGetBlockNum ( vol ); @@ -110,8 +117,10 @@ int main ( int argc, adfUnMount ( vol ); -dev_cleanup: +dev_mount_cleanup: adfUnMountDev ( dev ); +dev_cleanup: + adfCloseDev ( dev ); env_cleanup: adfEnvCleanUp(); diff --git a/examples/adf_floppy_create.c b/examples/adf_floppy_create.c index ff606e8b..a4914883 100644 --- a/examples/adf_floppy_create.c +++ b/examples/adf_floppy_create.c @@ -68,6 +68,7 @@ int main ( int argc, printf ( "Done!\n" ); adfUnMountDev ( device ); + adfCloseDev ( device ); adfEnvCleanUp(); return 0; diff --git a/examples/adf_floppy_format.c b/examples/adf_floppy_format.c index 68563969..5d6fa854 100644 --- a/examples/adf_floppy_format.c +++ b/examples/adf_floppy_format.c @@ -30,19 +30,21 @@ int main ( int argc, adfEnvInitDefault(); - struct AdfDevice * device = adfMountDev ( adfname, ADF_ACCESS_MODE_READWRITE ); - if ( device ) { + struct AdfDevice * const device = adfOpenDev ( adfname, ADF_ACCESS_MODE_READWRITE ); + if ( device == NULL ) { + fprintf ( stderr, "Cannot open floppy disk %s - aborting...\n", adfname ); + return 1; + } + + RETCODE rc = adfMountDev ( device ); + if ( rc == RC_OK ) { fprintf ( stderr, "The floppy disk %s already contains a filesystem - aborting...\n", adfname ); adfUnMountDev ( device ); + adfCloseDev ( device ); return 1; } - device = adfOpenDev ( adfname, ADF_ACCESS_MODE_READWRITE ); - if ( ! device ) { - fprintf ( stderr, "Cannot open floppy disk %s - aborting...\n", adfname ); - return 1; - } //adfDeviceInfo ( device ); diff --git a/examples/adf_show_metadata.c b/examples/adf_show_metadata.c index 761c9dac..493e593c 100644 --- a/examples/adf_show_metadata.c +++ b/examples/adf_show_metadata.c @@ -45,7 +45,7 @@ int main ( int argc, adfEnvInitDefault(); printf ( "\nOpening image/device:\t'%s'\n", adfname ); - struct AdfDevice * const dev = adfMountDev ( adfname, ADF_ACCESS_MODE_READONLY ); + struct AdfDevice * const dev = adfOpenDev ( adfname, ADF_ACCESS_MODE_READONLY ); if ( ! dev ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", adfname ); @@ -53,13 +53,20 @@ int main ( int argc, goto env_cleanup; } + RETCODE rc = adfMountDev ( dev ); + if ( rc != RC_OK ) { + fprintf ( stderr, "Cannot get volume info for file/device '%s' - aborting...\n", + adfname ); + goto dev_cleanup; + } + int vol_id = 0; struct AdfVolume * const vol = adfMount ( dev, vol_id, ADF_ACCESS_MODE_READONLY ); if ( ! vol ) { fprintf ( stderr, "Cannot mount volume %d - aborting...\n", vol_id ); status = 1; - goto dev_cleanup; + goto dev_mount_cleanup; } printf ( "Mounted volume:\t\t%d\n", vol_id ); @@ -73,8 +80,10 @@ int main ( int argc, adfUnMount ( vol ); -dev_cleanup: +dev_mount_cleanup: adfUnMountDev ( dev ); +dev_cleanup: + adfCloseDev ( dev ); env_cleanup: adfEnvCleanUp(); diff --git a/examples/unadf.c b/examples/unadf.c index 9890c982..32a8f18e 100644 --- a/examples/unadf.c +++ b/examples/unadf.c @@ -93,9 +93,15 @@ int main(int argc, char *argv[]) { adfEnvInitDefault(); parse_args(argc, argv); + /* open device */ + if (!(dev = adfOpenDev(adf_file, ADF_ACCESS_MODE_READONLY))) { + fprintf(stderr, "%s: can't open device\n", adf_file); + goto error_handler; + } + /* mount device */ - if (!(dev = adfMountDev(adf_file, ADF_ACCESS_MODE_READONLY))) { - fprintf(stderr, "%s: can't mount as device\n", adf_file); + if (adfMountDev(dev) != RC_OK) { + fprintf(stderr, "%s: can't mount device\n", adf_file); goto error_handler; } if (!pipe_mode) { @@ -166,7 +172,8 @@ int main(int argc, char *argv[]) { error_handler: if (vol) adfUnMount(vol); - if (dev) adfUnMountDev(dev); + if (dev && dev->mounted) adfUnMountDev(dev); + if (dev) adfCloseDev(dev); if (file_list) freeList(file_list); adfEnvCleanUp(); return 0; From 954bbddccce64c9852220a277589104234afe308 Mon Sep 17 00:00:00 2001 From: t-m Date: Tue, 30 Jan 2024 09:41:46 +0100 Subject: [PATCH 14/40] adf_dev: make const things const. --- src/adf_dev.c | 6 +++--- src/adf_dev.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/adf_dev.c b/src/adf_dev.c index 2d33429d..36e125ec 100644 --- a/src/adf_dev.c +++ b/src/adf_dev.c @@ -139,7 +139,7 @@ void adfCloseDev ( struct AdfDevice * const dev ) * returns the type of a device * only based of the field 'dev->size' */ -int adfDevType ( struct AdfDevice * dev ) +int adfDevType ( const struct AdfDevice * const dev ) { if( (dev->size==512*11*2*80) || /* BV */ (dev->size==512*11*2*81) || /* BV */ @@ -165,7 +165,7 @@ int adfDevType ( struct AdfDevice * dev ) * * can be used before adfCreateVol() or adfMount() */ -void adfDeviceInfo ( struct AdfDevice * dev ) +void adfDeviceInfo ( const struct AdfDevice * const dev ) { const char * devTypeInfo = NULL; switch ( dev->devType ) { @@ -223,7 +223,7 @@ void adfDeviceInfo ( struct AdfDevice * dev ) * * adfInitDevice() must fill dev->size ! */ -RETCODE adfMountDev ( struct AdfDevice * dev ) +RETCODE adfMountDev ( struct AdfDevice * const dev ) { if ( dev == NULL ) return RC_ERROR; diff --git a/src/adf_dev.h b/src/adf_dev.h index 87164739..3b9d0e15 100644 --- a/src/adf_dev.h +++ b/src/adf_dev.h @@ -50,10 +50,10 @@ PREFIX struct AdfDevice * adfOpenDev ( const char * const filename, const AdfAccessMode mode ); PREFIX void adfCloseDev ( struct AdfDevice * const dev ); -PREFIX int adfDevType ( struct AdfDevice * dev ); -PREFIX void adfDeviceInfo ( struct AdfDevice * dev ); +PREFIX int adfDevType ( const struct AdfDevice * const dev ); +PREFIX void adfDeviceInfo ( const struct AdfDevice * const dev ); -PREFIX RETCODE adfMountDev ( struct AdfDevice * dev ); +PREFIX RETCODE adfMountDev ( struct AdfDevice * const dev ); PREFIX void adfUnMountDev ( struct AdfDevice * const dev ); //struct AdfDevice* adfCreateDev(char* filename, int32_t cylinders, int32_t heads, int32_t sectors); From bc70d8cfb6c67573416a7b95191cba10cf133389 Mon Sep 17 00:00:00 2001 From: t-m Date: Tue, 30 Jan 2024 09:54:27 +0100 Subject: [PATCH 15/40] regtests / cache_crash: suppress a warning. --- regtests/Test/cache_crash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regtests/Test/cache_crash.c b/regtests/Test/cache_crash.c index 508ad8ab..0d05f0f6 100644 --- a/regtests/Test/cache_crash.c +++ b/regtests/Test/cache_crash.c @@ -13,7 +13,7 @@ int main(int argc, char *argv[]) { if (argc <= 1) return 1; adfEnvInitDefault(); - if (dev = adfOpenDev(argv[1], ADF_ACCESS_MODE_READONLY)) { + if ((dev = adfOpenDev(argv[1], ADF_ACCESS_MODE_READONLY))) { if (adfMountDev(dev) == RC_OK) { if ((vol = adfMount(dev, 0, ADF_ACCESS_MODE_READONLY))) { /* use dir cache (enables the crash) */ From 516fea0d7918a42b0efee8f0abdd258274369b74 Mon Sep 17 00:00:00 2001 From: t-m Date: Tue, 30 Jan 2024 10:01:37 +0100 Subject: [PATCH 16/40] Move adfCreateHdFile() from adf_dev_dump to adf_dev_hd. --- src/adf_dev_dump.c | 31 ------------------------------- src/adf_dev_dump.h | 4 ---- src/adf_dev_hd.c | 31 +++++++++++++++++++++++++++++++ src/adf_dev_hd.h | 4 ++++ 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/adf_dev_dump.c b/src/adf_dev_dump.c index dde8c1cf..1a6cb8b6 100644 --- a/src/adf_dev_dump.c +++ b/src/adf_dev_dump.c @@ -135,37 +135,6 @@ RETCODE adfReleaseDumpDevice ( struct AdfDevice * const dev ) } -/* - * adfCreateHdFile - * - */ -RETCODE adfCreateHdFile ( struct AdfDevice * const dev, - const char * const volName, - const uint8_t volType ) -{ - if (dev==NULL) { - (*adfEnv.eFct)("adfCreateHdFile : dev==NULL"); - return RC_ERROR; - } - dev->volList = (struct AdfVolume **) malloc (sizeof(struct Volume *)); - if (!dev->volList) { - (*adfEnv.eFct)("adfCreateHdFile : unknown device type"); - return RC_ERROR; - } - - dev->volList[0] = adfCreateVol( dev, 0L, dev->cylinders, volName, volType ); - if (dev->volList[0]==NULL) { - free(dev->volList); - return RC_ERROR; - } - - dev->nVol = 1; - dev->devType = DEVTYPE_HARDFILE; - - return RC_OK; -} - - /* * adfCreateDumpDevice * diff --git a/src/adf_dev_dump.h b/src/adf_dev_dump.h index cd585c14..52f8e656 100644 --- a/src/adf_dev_dump.h +++ b/src/adf_dev_dump.h @@ -34,10 +34,6 @@ PREFIX struct AdfDevice * adfCreateDumpDevice ( const char * const filename, const uint32_t heads, const uint32_t sec ); -PREFIX RETCODE adfCreateHdFile ( struct AdfDevice * const dev, - const char * const volName, - const uint8_t volType ); - RETCODE adfInitDumpDevice ( struct AdfDevice * const dev, const char * const name, const AdfAccessMode mode ); diff --git a/src/adf_dev_hd.c b/src/adf_dev_hd.c index fddb956d..37cb5fe6 100644 --- a/src/adf_dev_hd.c +++ b/src/adf_dev_hd.c @@ -396,6 +396,37 @@ printf("0first=%ld last=%ld root=%ld\n",vol->firstBlock, } +/* + * adfCreateHdFile + * + */ +RETCODE adfCreateHdFile ( struct AdfDevice * const dev, + const char * const volName, + const uint8_t volType ) +{ + if (dev==NULL) { + (*adfEnv.eFct)("adfCreateHdFile : dev==NULL"); + return RC_ERROR; + } + dev->volList = (struct AdfVolume **) malloc (sizeof(struct Volume *)); + if (!dev->volList) { + (*adfEnv.eFct)("adfCreateHdFile : unknown device type"); + return RC_ERROR; + } + + dev->volList[0] = adfCreateVol( dev, 0L, dev->cylinders, volName, volType ); + if (dev->volList[0]==NULL) { + free(dev->volList); + return RC_ERROR; + } + + dev->nVol = 1; + dev->devType = DEVTYPE_HARDFILE; + + return RC_OK; +} + + /* * ReadRDSKblock * diff --git a/src/adf_dev_hd.h b/src/adf_dev_hd.h index 3e685cf2..717f863a 100644 --- a/src/adf_dev_hd.h +++ b/src/adf_dev_hd.h @@ -45,6 +45,10 @@ PREFIX RETCODE adfCreateHd ( struct AdfDevice * const dev, const unsigned n, const struct Partition * const * const partList ); +PREFIX RETCODE adfCreateHdFile ( struct AdfDevice * const dev, + const char * const volName, + const uint8_t volType ); + RETCODE adfReadRDSKblock ( struct AdfDevice * const dev, struct bRDSKblock * const blk ); From c781e979e511347d084c52e3b2ee487eb1cdbddd Mon Sep 17 00:00:00 2001 From: t-m Date: Tue, 30 Jan 2024 10:03:58 +0100 Subject: [PATCH 17/40] adfCreateHdFile: correct error info. --- src/adf_dev_hd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/adf_dev_hd.c b/src/adf_dev_hd.c index 37cb5fe6..1510c3f3 100644 --- a/src/adf_dev_hd.c +++ b/src/adf_dev_hd.c @@ -409,8 +409,8 @@ RETCODE adfCreateHdFile ( struct AdfDevice * const dev, return RC_ERROR; } dev->volList = (struct AdfVolume **) malloc (sizeof(struct Volume *)); - if (!dev->volList) { - (*adfEnv.eFct)("adfCreateHdFile : unknown device type"); + if ( dev->volList == NULL ) { + adfEnv.eFct ( "adfCreateHdFile : malloc" ); return RC_ERROR; } From 9391c1da0040fdbc39248675e49a2cb830ff580f Mon Sep 17 00:00:00 2001 From: t-m Date: Thu, 8 Feb 2024 17:52:51 +0100 Subject: [PATCH 18/40] Make generic device API, lclevy#73 The main change is creating a generic API for all already existing types of devices (files (dumps), real/native devices for Linux and Win32, and ramdisk). The main concept is creating a generic device driver interface, defined in adf_dev_driver.h, which requires implementing just a few functions to make a valid driver. Making it simple and generic, provides also a simple way to implement new types of devices, also as a part of the client code. It also allows better and more efficient testing, for instance, by simple replacement of slow ADF devices (like files) with more efficient ones (like ramdisk). These device drivers can be "activated" or "deactivated" as needed (using adfAdd/RemoveDeviceDriver, see adf_device_drivers.h). This is done for flexibility (a user can easily add a custom driver developed in his own client code), but also for security (an application working only on ADF files does not need a driver for real block devices). By default, only "dump" (ADF files) and "ramdisk" are activated. --- examples/adf_floppy_create.c | 4 +- examples/tests/adf-floppy-test.sh | 9 +- examples/tests/adf-show-metadata-test.sh | 3 +- regtests/Test/access.c | 2 +- regtests/Test/bootdisk.c | 2 +- regtests/Test/comment.c | 2 +- regtests/Test/dispsect.c | 2 +- regtests/Test/file_seek_after_write.c | 2 +- regtests/Test/fl_test.c | 2 +- regtests/Test/floppy_overfilling_test.c | 2 +- regtests/Test/hardfile2.c | 4 +- regtests/Test/hd_test2.c | 3 +- regtests/Test/hd_test3.c | 3 +- regtests/Test/progbar.c | 3 +- regtests/Test/rename.c | 3 +- regtests/Test/rename2.c | 3 +- regtests/Test/undel.c | 3 +- src/CMakeLists.txt | 3 + src/Makefile.am | 3 + src/adf_dev.c | 130 ++++++------------ src/adf_dev.h | 47 +++++-- src/adf_dev_driver.h | 71 ++++++++++ src/adf_dev_drivers.c | 122 +++++++++++++++++ src/adf_dev_drivers.h | 43 ++++++ src/adf_dev_dump.c | 167 ++++++++++++++++------- src/adf_dev_dump.h | 24 +--- src/adf_dev_hd.c | 2 +- src/adf_dev_ramdisk.c | 83 +++++++---- src/adf_dev_ramdisk.h | 10 +- src/adf_env.c | 26 +--- src/adf_env.h | 4 - src/adf_nativ.h | 35 +---- src/generic/adf_nativ.c | 34 ++--- src/linux/adf_nativ.c | 125 ++++++++++------- src/win32/adf_nativ.c | 107 +++++++++------ tests/test_file_append.c | 2 +- tests/test_file_create.c | 2 +- tests/test_file_overwrite.c | 6 +- tests/test_file_overwrite2.c | 2 +- tests/test_file_seek.c | 2 +- tests/test_file_seek_after_write.c | 6 +- tests/test_file_truncate.c | 6 +- tests/test_file_truncate2.c | 6 +- tests/test_file_write.c | 2 +- tests/test_file_write_chunks.c | 4 +- 45 files changed, 713 insertions(+), 413 deletions(-) create mode 100644 src/adf_dev_driver.h create mode 100644 src/adf_dev_drivers.c create mode 100644 src/adf_dev_drivers.h diff --git a/examples/adf_floppy_create.c b/examples/adf_floppy_create.c index a4914883..8468a69f 100644 --- a/examples/adf_floppy_create.c +++ b/examples/adf_floppy_create.c @@ -57,8 +57,8 @@ int main ( int argc, adfEnvInitDefault(); - struct AdfDevice * device = adfCreateDumpDevice ( adfname, tracks, HEADS, - sectors_per_track ); + struct AdfDevice * device = adfCreateDev ( "dump", adfname, tracks, HEADS, + sectors_per_track ); if ( ! device ) { fprintf ( stderr, "Error creating floppy (%s) disk image %s.\n", floppy_type, adfname ); diff --git a/examples/tests/adf-floppy-test.sh b/examples/tests/adf-floppy-test.sh index 40759f5c..7a4ac0e4 100755 --- a/examples/tests/adf-floppy-test.sh +++ b/examples/tests/adf-floppy-test.sh @@ -11,7 +11,8 @@ compare_with <$actual 2>/dev/null compare_with <adfname; - struct AdfDevice * const device = adfCreateDumpDevice ( adfname, 80, 2, 11 ); + struct AdfDevice * const device = adfCreateDev ( "dump", adfname, 80, 2, 11 ); if ( ! device ) return 1; adfCreateFlop ( device, test_data->volname, test_data->fstype ); diff --git a/regtests/Test/fl_test.c b/regtests/Test/fl_test.c index e2e0f2b4..12e833ba 100644 --- a/regtests/Test/fl_test.c +++ b/regtests/Test/fl_test.c @@ -64,7 +64,7 @@ int main(int argc, char *argv[]) putchar('\n'); /* create and mount one device */ - hd = adfCreateDumpDevice("fl_test-newdev", 80, 2, 11); + hd = adfCreateDev ( "dump", "fl_test-newdev", 80, 2, 11 ); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); diff --git a/regtests/Test/floppy_overfilling_test.c b/regtests/Test/floppy_overfilling_test.c index f44f29b8..b4f1854d 100644 --- a/regtests/Test/floppy_overfilling_test.c +++ b/regtests/Test/floppy_overfilling_test.c @@ -101,7 +101,7 @@ int test_floppy_overfilling ( test_data_t * const tdata ) fstype_info [ tdata->fstype ], tdata->blocksize ); #endif - struct AdfDevice * device = adfCreateDumpDevice ( tdata->adfname, 80, 2, 11 ); + struct AdfDevice * device = adfCreateDev ( "dump", tdata->adfname, 80, 2, 11 ); if ( ! device ) return 1; adfCreateFlop ( device, "OverfillTest", tdata->fstype ); diff --git a/regtests/Test/hardfile2.c b/regtests/Test/hardfile2.c index 6fcd325e..1c87a340 100644 --- a/regtests/Test/hardfile2.c +++ b/regtests/Test/hardfile2.c @@ -22,14 +22,14 @@ void MyVer(char *msg) */ int main(int argc, char *argv[]) { - struct AdfDevice *hd; struct AdfVolume *vol; struct AdfList *list, *cell; adfEnvInitDefault(); /* create and mount one device : 4194304 bytes */ - hd = adfCreateDumpDevice("hardfile2-newdev", 256, 2, 32); + struct AdfDevice * const hd = adfCreateDev ( "dump", "hardfile2-newdev", + 256, 2, 32 ); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); diff --git a/regtests/Test/hd_test2.c b/regtests/Test/hd_test2.c index fecd4763..08b146ce 100644 --- a/regtests/Test/hd_test2.c +++ b/regtests/Test/hd_test2.c @@ -23,7 +23,6 @@ void MyVer(char *msg) int main(int argc, char *argv[]) { (void) argc, (void) argv; - struct AdfDevice *hd; struct AdfVolume *vol; struct Partition part1; struct Partition **partList; @@ -33,7 +32,7 @@ int main(int argc, char *argv[]) const char tmpdevname[] = "hd_test2-newdev"; /* a zip disk */ - hd = adfCreateDumpDevice ( tmpdevname, 2891, 1, 68 ); + struct AdfDevice * hd = adfCreateDev ( "dump", tmpdevname, 2891, 1, 68 ); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); diff --git a/regtests/Test/hd_test3.c b/regtests/Test/hd_test3.c index d898f015..4873aff4 100644 --- a/regtests/Test/hd_test3.c +++ b/regtests/Test/hd_test3.c @@ -23,7 +23,6 @@ void MyVer(char *msg) int main(int argc, char *argv[]) { (void) argc, (void) argv; - struct AdfDevice *hd; struct AdfVolume *vol, *vol2; struct Partition part1; struct Partition part2; @@ -35,7 +34,7 @@ int main(int argc, char *argv[]) /* an harddisk, "b"=7.5Mb, "h"=74.5mb */ - hd = adfCreateDumpDevice ( tmpdevname, 980, 10, 17 ); + struct AdfDevice * hd = adfCreateDev ( "dump", tmpdevname, 980, 10, 17 ); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); diff --git a/regtests/Test/progbar.c b/regtests/Test/progbar.c index 9c5d7187..b1eadac1 100644 --- a/regtests/Test/progbar.c +++ b/regtests/Test/progbar.c @@ -23,7 +23,6 @@ void MyVer(char *msg) int main(int argc, char *argv[]) { (void) argc, (void) argv; - struct AdfDevice *hd; struct AdfVolume *vol; BOOL true = TRUE; @@ -36,7 +35,7 @@ int main(int argc, char *argv[]) /* create and mount one device */ puts("\ncreate dumpdevice"); - hd = adfCreateDumpDevice("progbar-newdev", 80, 2, 11); + struct AdfDevice * const hd = adfCreateDev ( "dump", "progbar-newdev", 80, 2, 11 ); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); diff --git a/regtests/Test/rename.c b/regtests/Test/rename.c index dd8bdff9..e5d07f3e 100644 --- a/regtests/Test/rename.c +++ b/regtests/Test/rename.c @@ -23,7 +23,6 @@ void MyVer(char *msg) int main(int argc, char *argv[]) { (void) argc, (void) argv; - struct AdfDevice *hd; struct AdfVolume *vol; struct AdfFile *fic; unsigned char buf[1]; @@ -32,7 +31,7 @@ int main(int argc, char *argv[]) adfEnvInitDefault(); /* create and mount one device */ - hd = adfCreateDumpDevice("rename-newdev", 80, 2, 11); + struct AdfDevice * const hd = adfCreateDev ( "dump", "rename-newdev", 80, 2, 11 ); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); diff --git a/regtests/Test/rename2.c b/regtests/Test/rename2.c index cf6731df..33847d06 100644 --- a/regtests/Test/rename2.c +++ b/regtests/Test/rename2.c @@ -23,14 +23,13 @@ void MyVer(char *msg) int main(int argc, char *argv[]) { (void) argc, (void) argv; - struct AdfDevice *hd; struct AdfVolume *vol; struct AdfList *list, *cell; adfEnvInitDefault(); /* create and mount one device */ - hd = adfCreateDumpDevice("rename2-newdev", 80, 2, 11); + struct AdfDevice * const hd = adfCreateDev ( "dump", "rename2-newdev", 80, 2, 11 ); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); diff --git a/regtests/Test/undel.c b/regtests/Test/undel.c index c4137ba9..e30af14b 100644 --- a/regtests/Test/undel.c +++ b/regtests/Test/undel.c @@ -22,7 +22,6 @@ void MyVer(char *msg) int main(int argc, char *argv[]) { (void) argc, (void) argv; - struct AdfDevice *hd; struct AdfVolume *vol; struct AdfFile *fic; unsigned char buf[1]; @@ -35,7 +34,7 @@ int main(int argc, char *argv[]) adfChgEnvProp(PR_USEDIRC,&true); /* create and mount one device */ - hd = adfCreateDumpDevice("undel-newdev", 80, 2, 11); + struct AdfDevice * const hd = adfCreateDev ( "dump", "undel-newdev", 80, 2, 11 ); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b5b3377a..257c8e7e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,6 +51,9 @@ add_library ( adf adf_cache.c adf_cache.h adf_dev.c + adf_dev_driver.h + adf_dev_drivers.c + adf_dev_drivers.h adf_dev_dump.c adf_dev_dump.h adf_dev_flop.c diff --git a/src/Makefile.am b/src/Makefile.am index e059cf44..b926a928 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,6 +15,7 @@ libadf_la_SOURCES = \ adf_bitm.c \ adf_cache.c \ adf_dev.c \ + adf_dev_drivers.c \ adf_dev_dump.c \ adf_dev_flop.c \ adf_dev_hd.c \ @@ -37,6 +38,8 @@ adfinc_HEADERS = \ adf_bitm.h \ adf_blk.h \ adf_cache.h \ + adf_dev_driver.h \ + adf_dev_drivers.h \ adf_dev_dump.h \ adf_dev_flop.h \ adf_dev.h \ diff --git a/src/adf_dev.c b/src/adf_dev.c index 36e125ec..56cd2ca4 100644 --- a/src/adf_dev.c +++ b/src/adf_dev.c @@ -27,87 +27,46 @@ #include "adf_dev.h" -#include "adf_dev_dump.h" +#include "adf_dev_drivers.h" #include "adf_dev_flop.h" #include "adf_dev_hd.h" #include "adf_env.h" -#include "adf_nativ.h" #include #include -/* - * adfOpenDev - * - * open a device without reading any data (ie. without finding volumes) - * - * An opened device either has to be mounted (to be used with functions - * requiring volume data) or only functions using block access on the device - * level (with adfRead/WriteBlockDev) can be used - * (ie. this applies to adfCreateFlop/Hd); in general this level of access - * is for: partitioning / formatting / creating file system data - */ -struct AdfDevice * adfOpenDev ( const char * const filename, - const AdfAccessMode mode ) +struct AdfDevice * adfCreateDev ( const char * const driverName, + const char * const name, + const uint32_t cylinders, + const uint32_t heads, + const uint32_t sectors ) { - struct AdfDevice * dev = ( struct AdfDevice * ) - malloc ( sizeof ( struct AdfDevice ) ); - if ( ! dev ) { - (*adfEnv.eFct)("adfOpenDev : malloc error"); + const struct AdfDeviceDriver * const driver = adfGetDeviceDriverByName ( driverName ); + if ( driver == NULL || driver->createDev == NULL ) return NULL; - } + return driver->createDev ( name, cylinders, heads, sectors ); +} - dev->readOnly = ( mode != ADF_ACCESS_MODE_READWRITE ); - /* switch between dump files and real devices */ - struct AdfNativeFunctions * nFct; - dev->isNativeDev = FALSE; - for (nFct = adfEnv.nativeFct; nFct; nFct = nFct->next) { - if (nFct->adfIsDevNative(filename)) { - dev->nativeFct = nFct; - dev->isNativeDev = TRUE; - break; - } - } - - RETCODE rc; - if ( dev->isNativeDev ) - rc = dev->nativeFct->adfInitDevice( dev, filename, mode ); - else - rc = adfInitDumpDevice ( dev, filename, mode ); - if ( rc != RC_OK ) { - ( *adfEnv.eFct )( "adfOpenDev : device init error" ); - free ( dev ); +struct AdfDevice * adfOpenDev ( const char * const name, + const AdfAccessMode mode ) +{ + const struct AdfDeviceDriver * const driver = adfGetDeviceDriverByDevName ( name ); + if ( driver == NULL || driver->openDev == NULL ) return NULL; - } - - dev->devType = adfDevType ( dev ); - - dev->nVol = 0; - dev->volList = NULL; - dev->mounted = FALSE; + return driver->openDev ( name, mode ); +} - /* - if ( dev->devType == DEVTYPE_FLOPDD ) { - device->sectors = 11; - device->heads = 2; - fdtype = "DD"; - } else if ( dev->devType == DEVTYPE_FLOPHD ) { - device->sectors = 22; - device->heads = 2; - fdtype = "HD"; - } else if ( dev->devType == DEVTYPE_HARDDISK ) { - fprintf ( stderr, "adfOpenDev(): harddisk devices not implemented - aborting...\n" ); - return 1; - } else { - fprintf ( stderr, "adfOpenDev(): unknown device type - aborting...\n" ); - return 1; - } - device->cylinders = device->size / ( device->sectors * device->heads * 512 ); - */ - return dev; +struct AdfDevice * adfOpenDevWithDriver ( const char * const driverName, + const char * const name, + const AdfAccessMode mode ) +{ + const struct AdfDeviceDriver * const driver = adfGetDeviceDriverByName ( driverName ); + if ( driver == NULL || driver->openDev == NULL ) + return NULL; + return driver->openDev ( name, mode ); } @@ -118,18 +77,13 @@ struct AdfDevice * adfOpenDev ( const char * const filename, */ void adfCloseDev ( struct AdfDevice * const dev ) { - if ( ! dev ) + if ( dev == NULL ) return; if ( dev->mounted ) adfUnMountDev ( dev ); - if ( dev->isNativeDev ) { - dev->nativeFct->adfReleaseDevice( dev ); - } else - adfReleaseDumpDevice ( dev ); - - free ( dev ); + dev->drv->closeDev ( dev ); } @@ -185,8 +139,8 @@ void adfDeviceInfo ( const struct AdfDevice * const dev ) devTypeInfo = "unknown device type!"; } - printf ( "\nADF device info:\n Type:\t\t%s, %s\n", devTypeInfo, - dev->isNativeDev ? "real (native device!)" : "file (image)" ); + printf ( "\nADF device info:\n Type:\t\t%s\n Driver:\t%s\n", + devTypeInfo, dev->drv->name ); printf ( " Geometry:\n" " Cylinders\t%d\n" @@ -251,7 +205,9 @@ RETCODE adfMountDev ( struct AdfDevice * const dev ) } /* a file with the first three bytes equal to 'DOS' */ - if (!dev->isNativeDev && strncmp("DOS",(char*)buf,3)==0) { + if ( ! dev->drv->isNative() && + strncmp ( "DOS", (char *) buf, 3 ) == 0 ) + { rc = adfMountHdFile ( dev ); if ( rc != RC_OK ) return rc; @@ -304,15 +260,12 @@ RETCODE adfReadBlockDev ( struct AdfDevice * const dev, const uint32_t size, uint8_t * const buf ) { - RETCODE rc; - -/*printf("pSect R =%ld\n",pSect);*/ - if ( dev->isNativeDev ) { - rc = dev->nativeFct->adfNativeReadSector( dev, pSect, size, buf ); - } else - rc = adfReadDumpSector( dev, pSect, size, buf ); -/*printf("rc=%ld\n",rc);*/ +/* printf("pSect R =%ld\n",pSect); + RETCODE rc = dev->drv->readSector ( dev, pSect, size, buf ); + printf("rc=%ld\n",rc); return rc; +*/ + return dev->drv->readSector ( dev, pSect, size, buf ); } @@ -321,13 +274,6 @@ RETCODE adfWriteBlockDev ( struct AdfDevice * const dev, const uint32_t size, const uint8_t * const buf ) { - RETCODE rc; - /*printf("nativ=%d\n",dev->isNativeDev);*/ - if ( dev->isNativeDev ) { - rc = dev->nativeFct->adfNativeWriteSector( dev, pSect, size, buf ); - } else - rc = adfWriteDumpSector ( dev, pSect, size, buf ); - - return rc; + return dev->drv->writeSector ( dev, pSect, size, buf ); } diff --git a/src/adf_dev.h b/src/adf_dev.h index 3b9d0e15..d87e3d57 100644 --- a/src/adf_dev.h +++ b/src/adf_dev.h @@ -4,9 +4,11 @@ #include "adf_types.h" #include "adf_err.h" +#include "adf_dev_driver.h" #include "adf_vol.h" #include "prefix.h" + #include struct Partition { @@ -24,6 +26,7 @@ struct Partition { #define DEVTYPE_HARDFILE 4 struct AdfDevice { + char * name; int devType; /* see below */ BOOL readOnly; uint32_t size; /* in bytes */ @@ -32,12 +35,9 @@ struct AdfDevice { uint32_t heads; uint32_t sectors; - BOOL isNativeDev; - struct AdfNativeFunctions *nativeFct; - void *nativeDev; /* for use by native functions */ - - FILE *fd; - + const struct AdfDeviceDriver * drv; + void * drvData; /* driver-specific device data, + (private, use only in the driver code!) */ BOOL mounted; // stuff available when mounted @@ -46,17 +46,48 @@ struct AdfDevice { }; -PREFIX struct AdfDevice * adfOpenDev ( const char * const filename, +/* + * adfCreateDev and adfOpenDev + * + * creates or open an ADF device without reading any data (ie. without finding volumes) + * + * An created/opened device either has to be mounted (to be used with functions + * requiring volume data) or only functions using block access on the device + * level (with adfRead/WriteBlockDev) can be used + * (ie. this applies to adfCreateFlop/Hd); in general this level of access + * is for: partitioning / formatting / creating file system data / cloning + * the whole device on _device_ block level - and similar. + */ + +PREFIX struct AdfDevice * adfCreateDev ( const char * const driverName, + const char * const name, + const uint32_t cylinders, + const uint32_t heads, + const uint32_t sectors ); + +PREFIX struct AdfDevice * adfOpenDev ( const char * const name, const AdfAccessMode mode ); + +/* + * adfOpenDevWithDriver + * + * allows to avoid automatic driver selection done in adfOpenDev and enforce + * opening a file/device with the driver specified by its name + * (esp. useful for custom, user-implemented device drivers) + */ +PREFIX struct AdfDevice * adfOpenDevWithDriver ( const char * const driverName, + const char * const name, + const AdfAccessMode mode ); + PREFIX void adfCloseDev ( struct AdfDevice * const dev ); + PREFIX int adfDevType ( const struct AdfDevice * const dev ); PREFIX void adfDeviceInfo ( const struct AdfDevice * const dev ); PREFIX RETCODE adfMountDev ( struct AdfDevice * const dev ); PREFIX void adfUnMountDev ( struct AdfDevice * const dev ); -//struct AdfDevice* adfCreateDev(char* filename, int32_t cylinders, int32_t heads, int32_t sectors); RETCODE adfReadBlockDev ( struct AdfDevice * const dev, const uint32_t pSect, diff --git a/src/adf_dev_driver.h b/src/adf_dev_driver.h new file mode 100644 index 00000000..ea615fff --- /dev/null +++ b/src/adf_dev_driver.h @@ -0,0 +1,71 @@ +/* + * adf_dev_driver.h + * + * $ID$ + * + * This file is part of ADFLib. + * + * ADFLib 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 2 of the License, or + * (at your option) any later version. + * + * ADFLib 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 Foobar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef ADF_DEV_DRIVER_H +#define ADF_DEV_DRIVER_H + +#include "adf_dev.h" + +struct AdfDeviceDriver { + const char * const name; /* driver name / id */ + void * data; /* private driver-specific data */ + + + /* at least one of these two "factories" is required */ + + struct AdfDevice * (*createDev)( const char * const name, + const uint32_t cylinders, + const uint32_t heads, + const uint32_t sectors ); + + struct AdfDevice * (*openDev) ( const char * const name, + const AdfAccessMode mode ); + + /* required */ + + RETCODE (*closeDev)(struct AdfDevice * const dev); + + RETCODE (*readSector)( struct AdfDevice * const dev, + const uint32_t n, + const unsigned size, + uint8_t * const buf ); + + RETCODE (*writeSector)( struct AdfDevice * const dev, + const uint32_t n, + const unsigned size, + const uint8_t * const buf ); + + BOOL (*isNative)( void ); /* should return true only on a native block device driver; + used only in adfMountDev() to determine which method + should be used to mount the device + (check if there is a better way so that this can be removed */ + + + /* optional (can be NULL); should help to match device string with the driver */ + + BOOL (*isDevice)( const char * const name ); +}; + +#endif /* ADF_DEV_DRIVER_H */ + +/*#######################################################################################*/ diff --git a/src/adf_dev_drivers.c b/src/adf_dev_drivers.c new file mode 100644 index 00000000..e3185044 --- /dev/null +++ b/src/adf_dev_drivers.c @@ -0,0 +1,122 @@ +/* + * adf_device_drivers.c + * + * $Id$ + * + * This file is part of ADFLib. + * + * ADFLib 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 2 of the License, or + * (at your option) any later version. + * + * ADFLib 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 Foobar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ +#include "adf_dev_drivers.h" + +#include +#include + + +struct AdfDeviceDriverListNode { + struct AdfDeviceDriverListNode * next; + const struct AdfDeviceDriver * driver; +}; + +static struct AdfDeviceDriverListNode * adfDeviceDrivers = NULL; + + +RETCODE adfAddDeviceDriver ( const struct AdfDeviceDriver * const driver ) +{ + struct AdfDeviceDriverListNode * newNode = + malloc ( sizeof ( struct AdfDeviceDriverListNode ) ); + if ( newNode == NULL ) + return RC_MALLOC; + + newNode->next = NULL; + newNode->driver = driver; + + if ( adfDeviceDrivers == NULL ) + adfDeviceDrivers = newNode; + else { + struct AdfDeviceDriverListNode * node = adfDeviceDrivers; + for ( ; node->next != NULL ; node = node->next ); + node->next = newNode; + } + + //fprintf (stderr, "Added driver %s\n", newNode->driver->name ); + + return RC_OK; +} + + +RETCODE adfRemoveDeviceDriver ( const struct AdfDeviceDriver * const driver ) +{ + struct AdfDeviceDriverListNode + *node = adfDeviceDrivers, + *prev = NULL; + + for ( ; node != NULL ; prev = node, node = node->next ) { + if ( node->driver == driver ) { + if ( prev == NULL ) { + adfDeviceDrivers = node->next; + } else { + prev->next = node->next; + } + free ( node ); + return RC_OK; + } + } + + return RC_ERROR; +} + + +void adfRemoveDeviceDrivers ( void ) +{ + struct AdfDeviceDriverListNode + *node = adfDeviceDrivers, + *next = NULL; + + for ( ; node != NULL ; node = next ) { + //fprintf (stderr, "Removing driver %s\n", node->driver->name ); + //fflush(stderr); + next = node->next; + free ( node ); + } +} + + +const struct AdfDeviceDriver * adfGetDeviceDriverByName ( const char * const name ) +{ + for ( struct AdfDeviceDriverListNode * node = adfDeviceDrivers ; + node != NULL ; node = node->next ) + if ( strcmp ( node->driver->name, name ) == 0 ) + return node->driver; + return NULL; +} + + +const struct AdfDeviceDriver * adfGetDeviceDriverByDevName ( const char * const name ) +{ + for ( struct AdfDeviceDriverListNode * node = adfDeviceDrivers ; + node != NULL ; node = node->next ) + { + if ( node->driver->isDevice == NULL ) + continue; + + if ( node->driver->isDevice ( name ) ) + return node->driver; + } + + /* if nothing matched -> default to dump file */ + return adfGetDeviceDriverByName ( "dump" ); +} diff --git a/src/adf_dev_drivers.h b/src/adf_dev_drivers.h new file mode 100644 index 00000000..c3ca6678 --- /dev/null +++ b/src/adf_dev_drivers.h @@ -0,0 +1,43 @@ +/* + * adf_dev_drivers.h + * + * $ID$ + * + * This file is part of ADFLib. + * + * ADFLib 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 2 of the License, or + * (at your option) any later version. + * + * ADFLib 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 Foobar; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef ADF_DEV_DRIVERS_H +#define ADF_DEV_DRIVERS_H + +#include "adf_dev_driver.h" + +#include "adf_err.h" + + +RETCODE adfAddDeviceDriver ( const struct AdfDeviceDriver * const driver ); + +RETCODE adfRemoveDeviceDriver ( const struct AdfDeviceDriver * const driver ); + +void adfRemoveDeviceDrivers ( void ); + +const struct AdfDeviceDriver * adfGetDeviceDriverByName ( const char * const driverName ); +const struct AdfDeviceDriver * adfGetDeviceDriverByDevName ( const char * const deviceName ); + +#endif /* ADF_DEV_DRIVERS_H */ + +/*#######################################################################################*/ diff --git a/src/adf_dev_dump.c b/src/adf_dev_dump.c index 1a6cb8b6..4195d7b3 100644 --- a/src/adf_dev_dump.c +++ b/src/adf_dev_dump.c @@ -29,6 +29,7 @@ #include "adf_blk.h" #include "adf_env.h" +#include "adf_err.h" #include #include @@ -36,41 +37,74 @@ #include +struct DevDumpData { + FILE * fd; +}; + + /* - * adfInitDumpDevice + * adfDevDumpOpen * */ -RETCODE adfInitDumpDevice ( struct AdfDevice * const dev, - const char * const name, - const AdfAccessMode mode ) +static struct AdfDevice * adfDevDumpOpen ( const char * const name, + const AdfAccessMode mode ) { + struct AdfDevice * dev = ( struct AdfDevice * ) + malloc ( sizeof ( struct AdfDevice ) ); + if ( dev == NULL ) { + adfEnv.eFct ( "adfDevDumpOpen : malloc error" ); + return NULL; + } + dev->readOnly = ( mode != ADF_ACCESS_MODE_READWRITE ); + + dev->drvData = malloc ( sizeof ( struct DevDumpData ) ); + if ( dev->drvData == NULL ) { + adfEnv.eFct("adfDevDumpOpen : malloc data error"); + free ( dev ); + return NULL; + } + + FILE ** const fd = &( ( (struct DevDumpData *) dev->drvData )->fd ); + errno = 0; if ( ! dev->readOnly ) { - dev->fd = fopen ( name, "rb+" ); + *fd = fopen ( name, "rb+" ); /* force read only */ - if ( ! dev->fd && ( errno == EACCES || errno == EROFS ) ) { - dev->fd = fopen ( name, "rb" ); + if ( *fd == NULL && ( errno == EACCES || errno == EROFS ) ) { + *fd = fopen ( name, "rb" ); dev->readOnly = TRUE; - if ( dev->fd ) - (*adfEnv.wFct)("myInitDevice : fopen, read-only mode forced"); + if ( *fd != NULL ) + adfEnv.wFct("adfDevDumpOpen : fopen, read-only mode forced"); } } else /* read only requested */ - dev->fd = fopen ( name, "rb" ); + *fd = fopen ( name, "rb" ); - if ( ! dev->fd ) { - (*adfEnv.eFct)("myInitDevice : fopen"); - return RC_ERROR; + if ( *fd == NULL ) { + adfEnv.eFct ( "adfDevDumpOpen : fopen" ); + free ( dev->drvData ); + free ( dev ); + return NULL; } /* determines size */ - fseek ( dev->fd, 0, SEEK_END ); - dev->size = (uint32_t) ftell ( dev->fd ); - fseek ( dev->fd, 0, SEEK_SET ); + fseek ( *fd, 0, SEEK_END ); + dev->size = (uint32_t) ftell ( *fd ); + fseek ( *fd, 0, SEEK_SET ); - return RC_OK; + dev->devType = adfDevType ( dev ); + + dev->nVol = 0; + dev->volList = NULL; + dev->mounted = FALSE; + + dev->drv = &adfDeviceDriverDump; + + dev->name = strdup ( name ); + + return dev; } @@ -78,18 +112,19 @@ RETCODE adfInitDumpDevice ( struct AdfDevice * const dev, * adfReadDumpSector * */ -RETCODE adfReadDumpSector ( struct AdfDevice * const dev, - const uint32_t n, - const unsigned size, - uint8_t * const buf ) +static RETCODE adfReadDumpSector ( struct AdfDevice * const dev, + const uint32_t n, + const unsigned size, + uint8_t * const buf ) { /*puts("adfReadDumpSector");*/ - int pos = fseek ( dev->fd, 512 * n, SEEK_SET ); + FILE * const fd = ( (struct DevDumpData *) dev->drvData )->fd; + int pos = fseek ( fd, 512 * n, SEEK_SET ); /*printf("nnn=%ld size=%d\n",n,size);*/ if ( pos == -1 ) return RC_ERROR; - size_t bytes_read = fread ( buf, 1, size, dev->fd ); + size_t bytes_read = fread ( buf, 1, size, fd ); /*puts("123");*/ if ( bytes_read != size ) { /*printf("rr=%d\n",r);*/ @@ -105,16 +140,17 @@ RETCODE adfReadDumpSector ( struct AdfDevice * const dev, * adfWriteDumpSector * */ -RETCODE adfWriteDumpSector ( struct AdfDevice * const dev, - const uint32_t n, - const unsigned size, - const uint8_t * const buf ) +static RETCODE adfWriteDumpSector ( struct AdfDevice * const dev, + const uint32_t n, + const unsigned size, + const uint8_t * const buf ) { - int r = fseek ( dev->fd, 512 * n, SEEK_SET ); + FILE * const fd = ( (struct DevDumpData *) dev->drvData )->fd; + int r = fseek ( fd, 512 * n, SEEK_SET ); if (r==-1) return RC_ERROR; - if ( fwrite ( buf, 1, size, dev->fd ) != (unsigned int) size ) + if ( fwrite ( buf, 1, size, fd ) != (unsigned int) size ) return RC_ERROR; /*puts("adfWriteDumpSector");*/ return RC_OK; @@ -125,25 +161,31 @@ RETCODE adfWriteDumpSector ( struct AdfDevice * const dev, * adfReleaseDumpDevice * */ -RETCODE adfReleaseDumpDevice ( struct AdfDevice * const dev ) +static RETCODE adfReleaseDumpDevice ( struct AdfDevice * const dev ) { - fclose ( dev->fd ); + fclose ( ( (struct DevDumpData *) dev->drvData )->fd ); + + if ( dev->mounted ) + adfUnMountDev ( dev ); - //free ( dev ); // this is done externally - maybe should be moved here? + free ( dev->drvData ); + free ( dev->name ); + free ( dev ); return RC_OK; } + /* * adfCreateDumpDevice * * returns NULL if failed */ -struct AdfDevice * adfCreateDumpDevice ( const char * const filename, - const uint32_t cylinders, - const uint32_t heads, - const uint32_t sectors ) +static struct AdfDevice * adfCreateDumpDevice ( const char * const filename, + const uint32_t cylinders, + const uint32_t heads, + const uint32_t sectors ) { uint8_t buf[LOGICAL_BLOCK_SIZE]; /* int32_t i;*/ @@ -156,8 +198,18 @@ struct AdfDevice * adfCreateDumpDevice ( const char * const filename, return NULL; } - dev->fd = fopen ( filename, "wb" ); - if ( ! dev->fd ) { + dev->drvData = malloc ( sizeof ( struct DevDumpData ) ); + if ( dev->drvData == NULL ) { + adfEnv.eFct("adfDevDumpOpen : malloc data error"); + free ( dev ); + return NULL; + } + + FILE ** fd = &( ( (struct DevDumpData *) dev->drvData )->fd ); + + *fd = fopen ( filename, "wb" ); + if ( *fd == NULL ) { + free ( dev->drvData ); free ( dev ); (*adfEnv.eFct)("adfCreateDumpDevice : fopen"); return NULL; @@ -168,27 +220,30 @@ struct AdfDevice * adfCreateDumpDevice ( const char * const filename, */ long lastBlockOffset = ( ( cylinders * heads * sectors ) - 1 ) * LOGICAL_BLOCK_SIZE; - r = fseek ( dev->fd, lastBlockOffset, SEEK_SET ); + r = fseek ( *fd, lastBlockOffset, SEEK_SET ); if (r==-1) { - fclose ( dev->fd ); + fclose ( *fd ); + free ( dev->drvData ); free ( dev ); (*adfEnv.eFct)("adfCreateDumpDevice : fseek"); return NULL; } memset ( buf, 0, LOGICAL_BLOCK_SIZE ); - size_t blocksWritten = fwrite ( buf, LOGICAL_BLOCK_SIZE, 1, dev->fd ); + size_t blocksWritten = fwrite ( buf, LOGICAL_BLOCK_SIZE, 1, *fd ); if ( blocksWritten != 1 ) { - fclose ( dev->fd ); + fclose ( *fd ); + free ( dev->drvData ); free ( dev ); (*adfEnv.eFct)("adfCreateDumpDevice : fwrite"); return NULL; } - fclose ( dev->fd ); + fclose ( *fd ); - dev->fd = fopen ( filename, "rb+" ); - if ( ! dev->fd ) { + *fd = fopen ( filename, "rb+" ); + if ( ! *fd ) { + free ( dev->drvData ); free ( dev ); (*adfEnv.eFct)("adfCreateDumpDevice : fopen"); return NULL; @@ -206,11 +261,31 @@ struct AdfDevice * adfCreateDumpDevice ( const char * const filename, dev->devType = DEVTYPE_HARDDISK; dev->nVol = 0; - dev->isNativeDev = FALSE; dev->readOnly = FALSE; dev->mounted = FALSE; + dev->drv = &adfDeviceDriverDump; + + dev->name = strdup ( filename ); + return(dev); } +static BOOL adfDevDumpIsNativeDevice ( void ) +{ + return FALSE; +} + +const struct AdfDeviceDriver adfDeviceDriverDump = { + .name = "dump", + .data = NULL, + .createDev = adfCreateDumpDevice, + .openDev = adfDevDumpOpen, // adfOpenDev + adfInitDumpDevice + .closeDev = adfReleaseDumpDevice, + .readSector = adfReadDumpSector, + .writeSector = adfWriteDumpSector, + .isNative = adfDevDumpIsNativeDevice, + .isDevice = NULL +}; + /*##################################################################################*/ diff --git a/src/adf_dev_dump.h b/src/adf_dev_dump.h index 52f8e656..c2e52978 100644 --- a/src/adf_dev_dump.h +++ b/src/adf_dev_dump.h @@ -26,29 +26,9 @@ * */ -#include "adf_dev.h" -#include "adf_err.h" +#include "adf_dev_driver.h" -PREFIX struct AdfDevice * adfCreateDumpDevice ( const char * const filename, - const uint32_t cyl, - const uint32_t heads, - const uint32_t sec ); - -RETCODE adfInitDumpDevice ( struct AdfDevice * const dev, - const char * const name, - const AdfAccessMode mode ); - -RETCODE adfReadDumpSector ( struct AdfDevice * const dev, - const uint32_t n, - const unsigned size, - uint8_t * const buf ); - -RETCODE adfWriteDumpSector ( struct AdfDevice * const dev, - const uint32_t n, - const unsigned size, - const uint8_t * const buf ); - -RETCODE adfReleaseDumpDevice ( struct AdfDevice * const dev ); +extern const struct AdfDeviceDriver adfDeviceDriverDump; #endif /* ADF_DUMP_H */ /*##########################################################################*/ diff --git a/src/adf_dev_hd.c b/src/adf_dev_hd.c index 1510c3f3..1220e7bf 100644 --- a/src/adf_dev_hd.c +++ b/src/adf_dev_hd.c @@ -103,7 +103,7 @@ RETCODE adfMountHdFile ( struct AdfDevice * const dev ) vol->rootBlock = (int32_t) ( ( size / 512 ) / 2 ); /*printf("root=%ld\n",vol->rootBlock);*/ do { - adfReadDumpSector ( dev, (uint32_t) vol->rootBlock, 512, buf ); + dev->drv->readSector ( dev, (uint32_t) vol->rootBlock, 512, buf ); found = swapLong(buf)==T_HEADER && swapLong(buf+508)==ST_ROOT; if (!found) (vol->rootBlock)--; diff --git a/src/adf_dev_ramdisk.c b/src/adf_dev_ramdisk.c index 88374e47..1db30ec1 100644 --- a/src/adf_dev_ramdisk.c +++ b/src/adf_dev_ramdisk.c @@ -23,25 +23,51 @@ #include #include -#include "adf_dev_ramdisk.h" -uint8_t ramdiskData[RAMDISK_SIZE]; +#include "adf_dev_ramdisk.h" +#include "adf_env.h" -static RETCODE ramdiskInit( struct AdfDevice * const dev, - const char * const name, - const AdfAccessMode mode ) +static struct AdfDevice * ramdiskCreate ( const char * const name, + const uint32_t cylinders, + const uint32_t heads, + const uint32_t sectors ) { - dev->readOnly = ( mode != ADF_ACCESS_MODE_READWRITE ); - dev->heads = 2; - dev->sectors = 11; - dev->cylinders = 80; - dev->size = RAMDISK_SIZE; - return RC_OK; + struct AdfDevice * dev = ( struct AdfDevice * ) + malloc ( sizeof ( struct AdfDevice ) ); + if ( dev == NULL ) { + adfEnv.eFct("ramdiskCreate : malloc error"); + return NULL; + } + + dev->readOnly = FALSE; // ( mode != ADF_ACCESS_MODE_READWRITE ); + dev->heads = heads; + dev->sectors = sectors; + dev->cylinders = cylinders; + dev->size = cylinders * heads * sectors * 512; + + dev->drvData = malloc ( dev->size ); + if ( dev->drvData == NULL ) { + adfEnv.eFct("ramdiskCreate : malloc data error"); + free ( dev ); + return NULL; + } + + dev->devType = adfDevType ( dev ); + dev->nVol = 0; + dev->volList = NULL; + dev->mounted = FALSE; + dev->name = strdup ( name ); + dev->drv = &adfDeviceDriverRamdisk; + + return dev; } static RETCODE ramdiskRelease ( struct AdfDevice * const dev ) { + free ( dev->drvData ); + free ( dev->name ); + free ( dev ); return RC_OK; } @@ -52,10 +78,12 @@ static RETCODE ramdiskReadSector ( struct AdfDevice * const dev, uint8_t * const buf ) { unsigned int offset = n * 512; - if (offset > RAMDISK_SIZE || (offset + size) > RAMDISK_SIZE) { + if ( offset > dev->size || + (offset + size) > dev->size) + { return RC_ERROR; } - memcpy(buf, &ramdiskData[offset], size); + memcpy ( buf, &( (uint8_t *) (dev->drvData) )[offset], size ); return RC_OK; } @@ -65,23 +93,30 @@ static RETCODE ramdiskWriteSector ( struct AdfDevice * const dev, const uint8_t * const buf ) { unsigned int offset = n * 512; - if (offset > RAMDISK_SIZE || (offset + size) > RAMDISK_SIZE) { + if ( offset > dev->size || + (offset + size) > dev->size ) + { return RC_ERROR; } - memcpy(&ramdiskData[offset], buf, size); + memcpy ( &( (uint8_t *) (dev->drvData) )[offset], buf, size ); return RC_OK; } -static BOOL ramdiskIsDevNative ( const char * const devName ) + +static BOOL ramdiskIsDevNative ( void ) { - return strcmp(devName, RAMDISK_DEVICE_NAME) == 0; + return FALSE; } -struct AdfNativeFunctions ramdiskDevice = { - NULL, - &ramdiskInit, - &ramdiskRelease, - &ramdiskReadSector, - &ramdiskWriteSector, - &ramdiskIsDevNative + +const struct AdfDeviceDriver adfDeviceDriverRamdisk = { + .name = "ramdisk", + .data = NULL, + .createDev = ramdiskCreate, + .openDev = NULL, + .closeDev = ramdiskRelease, + .readSector = ramdiskReadSector, + .writeSector = ramdiskWriteSector, + .isNative = ramdiskIsDevNative, + .isDevice = NULL }; diff --git a/src/adf_dev_ramdisk.h b/src/adf_dev_ramdisk.h index 5a2d2e52..fbff1b60 100644 --- a/src/adf_dev_ramdisk.h +++ b/src/adf_dev_ramdisk.h @@ -1,14 +1,8 @@ #ifndef ADF_DEV_RAMDISK_H #define ADF_DEV_RAMDISK_H -#include "adf_err.h" -#include "adf_nativ.h" +#include "adf_dev_driver.h" -#define RAMDISK_SIZE (2 * 11 * 80 * 512) -#define RAMDISK_DEVICE_NAME "RAM:" - -extern uint8_t ramdiskData[RAMDISK_SIZE]; - -extern struct AdfNativeFunctions ramdiskDevice; +extern const struct AdfDeviceDriver adfDeviceDriverRamdisk; #endif diff --git a/src/adf_env.c b/src/adf_env.c index 437ccd10..a88b6ada 100644 --- a/src/adf_env.c +++ b/src/adf_env.c @@ -28,7 +28,9 @@ #include "adf_env.h" #include "adf_blk.h" -#include "adf_nativ.h" +#include "adf_dev_drivers.h" +#include "adf_dev_dump.h" +#include "adf_dev_ramdisk.h" #include "adf_version.h" #include "defendian.h" @@ -80,7 +82,8 @@ void adfEnvInitDefault() /* sprintf(str,"ADFlib %s (%s)",adfGetVersionNumber(),adfGetVersionDate()); (*adfEnv.vFct)(str); */ - adfEnv.nativeFct = adfInitNativeFct(); + adfAddDeviceDriver ( &adfDeviceDriverDump ); + adfAddDeviceDriver ( &adfDeviceDriverRamdisk ); } @@ -90,6 +93,7 @@ void adfEnvInitDefault() */ void adfEnvCleanUp() { + adfRemoveDeviceDrivers(); } @@ -179,24 +183,6 @@ char* adfGetVersionDate() return(ADFLIB_DATE); } -void adfAddNativeDriver(struct AdfNativeFunctions *driver) { - if (driver) { - driver->next = adfEnv.nativeFct; - adfEnv.nativeFct = driver; - } -} -void adfRemoveNativeDriver(struct AdfNativeFunctions *driver) { - if (driver) { - struct AdfNativeFunctions *nFct = (struct AdfNativeFunctions *) &(adfEnv.nativeFct); - for (; nFct; nFct = nFct->next) { - if (nFct->next == driver) { - nFct->next = driver->next; - return; - } - } - } -} - /*##################################################################################*/ static void rwHeadAccess ( SECTNUM physical, diff --git a/src/adf_env.h b/src/adf_env.h index b16ea9f9..082dffba 100644 --- a/src/adf_env.h +++ b/src/adf_env.h @@ -65,8 +65,6 @@ struct AdfEnv { BOOL useProgressBar; BOOL useDirCache; - - struct AdfNativeFunctions *nativeFct; }; @@ -81,8 +79,6 @@ PREFIX void adfEnvCleanUp(); PREFIX void adfChgEnvProp(int prop, void *new); PREFIX char* adfGetVersionNumber(); PREFIX char* adfGetVersionDate(); -PREFIX void adfAddNativeDriver(struct AdfNativeFunctions *driver); -PREFIX void adfRemoveNativeDriver(struct AdfNativeFunctions *driver); PREFIX extern struct AdfEnv adfEnv; diff --git a/src/adf_nativ.h b/src/adf_nativ.h index 9d84fef4..7f1e8425 100644 --- a/src/adf_nativ.h +++ b/src/adf_nativ.h @@ -24,37 +24,8 @@ #ifndef ADF_NATIV_H #define ADF_NATIV_H -#include"adf_dev.h" +#include "adf_dev_driver.h" -struct AdfNativeFunctions { - struct AdfNativeFunctions *next; +extern const struct AdfDeviceDriver adfDeviceDriverNative; - /* called by adfMount() */ - RETCODE (*adfInitDevice)( struct AdfDevice * const dev, - const char * const name, - const AdfAccessMode mode ); - - /* called by adfUnMount() */ - RETCODE (*adfReleaseDevice)(struct AdfDevice * const dev); - - /* called by adfReadBlock() */ - RETCODE (*adfNativeReadSector)( struct AdfDevice * const dev, - const uint32_t n, - const unsigned size, - uint8_t * const buf ); - - /* called by adfWriteBlock() */ - RETCODE (*adfNativeWriteSector)( struct AdfDevice * const dev, - const uint32_t n, - const unsigned size, - const uint8_t * const buf ); - - /* called by adfMount() */ - BOOL (*adfIsDevNative)( const char * const devName ); -}; - -struct AdfNativeFunctions *adfInitNativeFct(); - -#endif /* ADF_NATIV_H */ - -/*#######################################################################################*/ +#endif diff --git a/src/generic/adf_nativ.c b/src/generic/adf_nativ.c index f400cfbb..a2ea0d13 100644 --- a/src/generic/adf_nativ.c +++ b/src/generic/adf_nativ.c @@ -87,29 +87,29 @@ RETCODE myReleaseDevice ( struct AdfDevice * const dev ) * myIsDevNative * */ -BOOL myIsDevNative ( const char * const devName ) +static BOOL myIsDevNative(void) { -// return (strncmp(devName,"/dev/",5)==0); return FALSE; } +static BOOL myIsDevice ( const char * const devName ) +{ + (void) devName; + return FALSE; +} -struct AdfNativeFunctions adfGenericNativeDevice = { - NULL, - &myInitDevice, - &myReleaseDevice, - &myReadSector, - &myWriteSector, - &myIsDevNative -}; +const struct AdfDeviceDriver adfDeviceDriverNative = { + .name = "native generic", + .data = NULL, + .createDev = NULL, + .openDev = myInitDevice, + .closeDev = myReleaseDevice, + .readSector = myReadSector, + .writeSector = myWriteSector, + .isNative = myIsDevNative, + .isDevice = myIsDevice +}; -/* - * adfInitNativeFct - * - */ -struct AdfNativeFunctions *adfInitNativeFct() { - return &adfGenericNativeDevice; -} /*##########################################################################*/ diff --git a/src/linux/adf_nativ.c b/src/linux/adf_nativ.c index d09b5f63..a458e3dc 100644 --- a/src/linux/adf_nativ.c +++ b/src/linux/adf_nativ.c @@ -26,7 +26,7 @@ #include #include #include -//#include +#include #include #include #include @@ -41,39 +41,51 @@ struct AdfNativeDevice { int fd; }; +static BOOL adfLinuxIsBlockDevice ( const char * const devName ); + /* * adfLinuxInitDevice * - * must fill 'dev->size' */ -static RETCODE adfLinuxInitDevice ( struct AdfDevice * const dev, - const char * const name, - const AdfAccessMode mode ) +static struct AdfDevice * adfLinuxInitDevice ( const char * const name, + const AdfAccessMode mode ) { - struct AdfNativeDevice * nDev = ( struct AdfNativeDevice * ) - malloc ( sizeof ( struct AdfNativeDevice ) ); - - if ( ! nDev ) { - (*adfEnv.eFct)("adfLinuxInitDevice : malloc"); - return RC_ERROR; + if ( ! adfLinuxIsBlockDevice ( name ) ) { + return NULL; } - dev->nativeDev = nDev; + struct AdfDevice * dev = ( struct AdfDevice * ) + malloc ( sizeof ( struct AdfDevice ) ); + if ( dev == NULL ) { + (*adfEnv.eFct)("adfLinuxInitDevice : malloc error"); + return NULL; + } dev->readOnly = ( mode != ADF_ACCESS_MODE_READWRITE ); + + dev->drvData = malloc ( sizeof ( struct AdfNativeDevice ) ); + if ( dev->drvData == NULL ) { + adfEnv.eFct("adfLinuxInitDevice : malloc data error"); + free ( dev ); + return NULL; + } + + int * const fd = &( ( (struct AdfNativeDevice *) dev->drvData )->fd ); + if ( ! dev->readOnly ) { - nDev->fd = open ( name, O_RDWR ); - dev->readOnly = ( nDev->fd < 0 ) ? TRUE : FALSE; + *fd = open ( name, O_RDWR ); + dev->readOnly = ( *fd < 0 ) ? TRUE : FALSE; } if ( dev->readOnly ) { - nDev->fd = open ( name, O_RDONLY ); + *fd = open ( name, O_RDONLY ); } - if ( nDev->fd < 0 ) { + if ( *fd < 0 ) { (*adfEnv.eFct)("adfLinuxInitDevice : cannot open device"); - free ( nDev ); - return RC_ERROR; + free ( dev->drvData ); + free ( dev ); + return NULL; } unsigned long long size = 0; @@ -88,17 +100,17 @@ static RETCODE adfLinuxInitDevice ( struct AdfDevice * const dev, size = blocks * 512; } */ - if ( ioctl ( nDev->fd, BLKGETSIZE64, &size ) < 0 ) { + if ( ioctl ( *fd, BLKGETSIZE64, &size ) < 0 ) { // fall-back to lseek - size = ( unsigned long long ) lseek ( nDev->fd, 0, SEEK_END ); - lseek ( nDev->fd, 0, SEEK_SET ); + size = ( unsigned long long ) lseek ( *fd, 0, SEEK_END ); + lseek ( *fd, 0, SEEK_SET ); } dev->size = (uint32_t) size; // https://docs.kernel.org/userspace-api/ioctl/hdio.html struct hd_geometry geom; - if ( ioctl ( nDev->fd, HDIO_GETGEO, &geom ) == 0 ) { + if ( ioctl ( *fd, HDIO_GETGEO, &geom ) == 0 ) { dev->heads = geom.heads; dev->sectors = geom.sectors; dev->cylinders = geom.cylinders; @@ -108,6 +120,14 @@ static RETCODE adfLinuxInitDevice ( struct AdfDevice * const dev, dev->sectors = dev->size / 4; dev->cylinders = dev->size / ( dev->sectors * dev->heads * 512 ); } + + dev->devType = adfDevType ( dev ); + dev->nVol = 0; + dev->volList = NULL; + dev->mounted = FALSE; + dev->name = strdup ( name ); + dev->drv = &adfDeviceDriverNative; + return RC_OK; } @@ -119,9 +139,10 @@ static RETCODE adfLinuxInitDevice ( struct AdfDevice * const dev, */ static RETCODE adfLinuxReleaseDevice ( struct AdfDevice * const dev ) { - struct AdfNativeDevice * nDev = ( struct AdfNativeDevice * ) dev->nativeDev; - close ( nDev->fd ); - free ( nDev ); + close ( ( (struct AdfNativeDevice *) dev->drvData )->fd ); + free ( dev->drvData ); + free ( dev->name ); + free ( dev ); return RC_OK; } @@ -135,14 +156,14 @@ static RETCODE adfLinuxReadSector ( struct AdfDevice * const dev, const unsigned size, uint8_t * const buf ) { - struct AdfNativeDevice * nDev = ( struct AdfNativeDevice * ) dev->nativeDev; + const int fd = ( (struct AdfNativeDevice *) dev->drvData )->fd; off_t offset = n * 512; - if ( lseek ( nDev->fd, offset, SEEK_SET ) != offset ) { + if ( lseek ( fd, offset, SEEK_SET ) != offset ) { return RC_ERROR; } - if ( read ( nDev->fd, buf, (size_t) size ) != (ssize_t) size ) + if ( read ( fd, buf, (size_t) size ) != (ssize_t) size ) return RC_ERROR; return RC_OK; @@ -158,14 +179,14 @@ static RETCODE adfLinuxWriteSector ( struct AdfDevice * const dev, const unsigned size, const uint8_t * const buf ) { - struct AdfNativeDevice * nDev = ( struct AdfNativeDevice * ) dev->nativeDev; + const int fd = ( (struct AdfNativeDevice *) dev->drvData )->fd; off_t offset = n * 512; - if ( lseek ( nDev->fd, offset, SEEK_SET ) != offset ) { + if ( lseek ( fd, offset, SEEK_SET ) != offset ) { return RC_ERROR; } - if ( write ( nDev->fd, (void *) buf, (size_t) size ) != size ) + if ( write ( fd, (void *) buf, (size_t) size ) != size ) return RC_ERROR; return RC_OK; @@ -176,34 +197,38 @@ static RETCODE adfLinuxWriteSector ( struct AdfDevice * const dev, * adfLinuxIsDevNative * */ -static BOOL adfLinuxIsDevNative ( const char * const devName ) +static BOOL adfLinuxIsDevNative ( void ) +{ + return TRUE; +} + + +/* + * adfLinuxIsBlockDevice + * + */ +static BOOL adfLinuxIsBlockDevice ( const char * const devName ) { //return ( strncmp ( devName, "/dev/", 5 ) == 0 ); struct stat sb; if ( lstat ( devName, &sb ) == -1 ) { - perror ( "adfLinuxIsDevNative: lstat" ); - exit ( EXIT_FAILURE ); + adfEnv.eFct ( "adfLinuxIsBlockDevice : lstat '%s' failed", devName ); + return FALSE; } return ( ( sb.st_mode & S_IFMT ) == S_IFBLK ); } -struct AdfNativeFunctions adfLinuxNativeDevice = { - NULL, - &adfLinuxInitDevice, - &adfLinuxReleaseDevice, - &adfLinuxReadSector, - &adfLinuxWriteSector, - &adfLinuxIsDevNative +const struct AdfDeviceDriver adfDeviceDriverNative = { + .name = "native linux", + .data = NULL, + .createDev = NULL, + .openDev = adfLinuxInitDevice, + .closeDev = adfLinuxReleaseDevice, + .readSector = adfLinuxReadSector, + .writeSector = adfLinuxWriteSector, + .isNative = adfLinuxIsDevNative, + .isDevice = adfLinuxIsBlockDevice }; - - -/* - * adfInitNativeFct - * - */ -struct AdfNativeFunctions *adfInitNativeFct() { - return &adfLinuxNativeDevice; -} diff --git a/src/win32/adf_nativ.c b/src/win32/adf_nativ.c index 7b07f45b..048fafd0 100644 --- a/src/win32/adf_nativ.c +++ b/src/win32/adf_nativ.c @@ -42,25 +42,38 @@ struct AdfNativeDevice { void *hDrv; }; - +static BOOL Win32IsDevice ( const char * const devName ); static RETCODE Win32ReleaseDevice ( struct AdfDevice * const dev ); -static RETCODE Win32InitDevice ( struct AdfDevice * const dev, - const char * const lpstrName, - const AdfAccessMode mode ) +static struct AdfDevice * Win32InitDevice ( const char * const lpstrName, + const AdfAccessMode mode ) { - struct AdfNativeDevice * nDev = ( struct AdfNativeDevice * ) - malloc ( sizeof(struct AdfNativeDevice) ); - if (!nDev) { - (*adfEnv.eFct)("Win32InitDevice : malloc"); - return RC_ERROR; /* BV */ + if ( ! Win32IsDevice ( lpstrName ) ) { + return NULL; + } + + struct AdfDevice * dev = malloc ( sizeof ( struct AdfDevice ) ); + if ( dev == NULL ) { + adfEnv.eFct ( "Win32InitDevice : malloc error" ); + return NULL; + } + + dev->readOnly = ( mode != ADF_ACCESS_MODE_READWRITE ); + + dev->drvData = malloc ( sizeof ( struct AdfNativeDevice ) ); + if ( dev->drvData == NULL ) { + adfEnv.eFct("Win32InitDevice : malloc data error"); + free ( dev ); + return NULL; } /* convert device name to something usable by Win32 functions */ if (strlen(lpstrName) != 3) { (*adfEnv.eFct)("Win32InitDevice : invalid drive specifier"); - return RC_ERROR; /* BV */ + free ( dev->drvData ); + free ( dev ); + return NULL; } char strTempName[3]; @@ -68,25 +81,27 @@ static RETCODE Win32InitDevice ( struct AdfDevice * const dev, strTempName[1] = lpstrName[2]; strTempName[2] = '\0'; - nDev->hDrv = NT4OpenDrive(strTempName); - - if (nDev->hDrv == NULL) { + void ** const hDrv = &( ( (struct AdfNativeDevice *) dev->drvData )->hDrv ); + *hDrv = NT4OpenDrive ( strTempName ); + if ( *hDrv == NULL ) { (*adfEnv.eFct)("Win32InitDevice : NT4OpenDrive"); - return RC_ERROR; /* BV */ + free ( dev->drvData ); + free ( dev ); + return NULL; } NT4DriveGeometry_t geometry; - if ( ! NT4GetDriveGeometry ( nDev->hDrv, &geometry ) ) { + if ( ! NT4GetDriveGeometry ( *hDrv, &geometry ) ) { (*adfEnv.eFct)("Win32InitDevice : error getting drive geometry"); Win32ReleaseDevice ( dev ); - return RC_ERROR; + return NULL; } // no support for disks with non 512-byte sectors (-> to improve?) if ( geometry.bytesPerSector != 512 ) { (*adfEnv.eFct)("Win32InitDevice : non 512-byte sector size"); Win32ReleaseDevice ( dev ); - return RC_ERROR; + return NULL; } dev->cylinders = geometry.cylinders; @@ -99,9 +114,14 @@ static RETCODE Win32InitDevice ( struct AdfDevice * const dev, geometry.sectorsPerTrack * geometry.bytesPerSector; - dev->nativeDev = nDev; + dev->devType = adfDevType ( dev ); + dev->nVol = 0; + dev->volList = NULL; + dev->mounted = FALSE; + dev->name = strdup ( lpstrName ); + dev->drv = &adfDeviceDriverNative; - return RC_OK; + return dev; } @@ -110,10 +130,9 @@ static RETCODE Win32ReadSector ( struct AdfDevice * const dev, const unsigned size, uint8_t * const buf ) { - struct AdfNativeDevice * tDev = - ( struct AdfNativeDevice * ) dev->nativeDev; + void ** const hDrv = &( ( (struct AdfNativeDevice *) dev->drvData )->hDrv ); - if (! NT4ReadSector(tDev->hDrv, (long) n, size, buf)) { + if ( ! NT4ReadSector( *hDrv, (long) n, size, buf ) ) { (*adfEnv.eFct)("Win32InitDevice : NT4ReadSector"); return RC_ERROR; /* BV */ } @@ -127,10 +146,9 @@ static RETCODE Win32WriteSector ( struct AdfDevice * const dev, const unsigned size, const uint8_t * const buf ) { - struct AdfNativeDevice * tDev = - ( struct AdfNativeDevice * ) dev->nativeDev; + void ** const hDrv = &( ( (struct AdfNativeDevice *) dev->drvData )->hDrv ); - if (! NT4WriteSector(tDev->hDrv, (long) n, size, buf)) { + if ( ! NT4WriteSector ( *hDrv, (long) n, size, buf) ) { (*adfEnv.eFct)("Win32InitDevice : NT4WriteSector"); return RC_ERROR; /* BV */ } @@ -141,34 +159,37 @@ static RETCODE Win32WriteSector ( struct AdfDevice * const dev, static RETCODE Win32ReleaseDevice ( struct AdfDevice * const dev ) { - struct AdfNativeDevice * nDev = - ( struct AdfNativeDevice * ) dev->nativeDev; + void ** const hDrv = &( ( (struct AdfNativeDevice *) dev->drvData )->hDrv ); - if (! NT4CloseDrive(nDev->hDrv)) + if ( ! NT4CloseDrive ( *hDrv ) ) return RC_ERROR; /* BV */ - - free(nDev); + free ( dev->name ); + free ( dev->drvData ); + free ( dev ); return RC_OK; } +static BOOL Win32IsDevNative ( void ) +{ + return TRUE; +} -static BOOL Win32IsDevNative ( const char * const devName ) + +static BOOL Win32IsDevice ( const char * const devName ) { return devName[0] == '|'; } -struct AdfNativeFunctions adfWindowsNativeDevice = { - NULL, - &Win32InitDevice, - &Win32ReleaseDevice, - &Win32ReadSector, - &Win32WriteSector, - &Win32IsDevNative +const struct AdfDeviceDriver adfDeviceDriverNative = { + .name = "native win32", + .data = NULL, + .createDev = NULL, + .openDev = Win32InitDevice, + .closeDev = Win32ReleaseDevice, + .readSector = Win32ReadSector, + .writeSector = Win32WriteSector, + .isNative = Win32IsDevNative, + .isDevice = Win32IsDevice }; - - -struct AdfNativeFunctions *adfInitNativeFct() { - return &adfWindowsNativeDevice; -} diff --git a/tests/test_file_append.c b/tests/test_file_append.c index bb8224a6..4626b2d2 100644 --- a/tests/test_file_append.c +++ b/tests/test_file_append.c @@ -246,7 +246,7 @@ int main ( void ) void setup ( test_data_t * const tdata ) { - tdata->device = adfCreateDumpDevice ( tdata->adfname, 80, 2, 11 ); + tdata->device = adfCreateDev ( "dump", tdata->adfname, 80, 2, 11 ); if ( ! tdata->device ) { //return; exit(1); diff --git a/tests/test_file_create.c b/tests/test_file_create.c index e7e03425..a933c927 100644 --- a/tests/test_file_create.c +++ b/tests/test_file_create.c @@ -250,7 +250,7 @@ int main ( void ) void setup ( test_data_t * const tdata ) { - tdata->device = adfCreateDumpDevice ( tdata->adfname, 80, 2, 11 ); + tdata->device = adfCreateDev ( "dump", tdata->adfname, 80, 2, 11 ); if ( ! tdata->device ) { //return; exit(1); diff --git a/tests/test_file_overwrite.c b/tests/test_file_overwrite.c index 4a12e131..84aabaea 100644 --- a/tests/test_file_overwrite.c +++ b/tests/test_file_overwrite.c @@ -289,7 +289,6 @@ int main ( void ) SRunner * sr = srunner_create ( s ); adfEnvInitDefault(); - adfAddNativeDriver(&ramdiskDevice); srunner_run_all ( sr, CK_VERBOSE ); //CK_NORMAL ); adfEnvCleanUp(); @@ -303,8 +302,9 @@ int main ( void ) void setup ( test_data_t * const tdata ) { - tdata->device = adfOpenDev(RAMDISK_DEVICE_NAME, FALSE); - if ( ! tdata->device ) { + tdata->device = adfCreateDev ( "ramdisk", "test_ramdisk", 80, 2, 11 ); + if ( tdata->device == NULL ) { + fprintf ( stderr, "Error creating device\n"); //return; exit(1); } diff --git a/tests/test_file_overwrite2.c b/tests/test_file_overwrite2.c index 95c59ca2..d357f4b1 100644 --- a/tests/test_file_overwrite2.c +++ b/tests/test_file_overwrite2.c @@ -380,7 +380,7 @@ int main ( void ) void setup ( test_data_t * const tdata ) { - tdata->device = adfCreateDumpDevice ( tdata->adfname, 80, 2, 11 ); + tdata->device = adfCreateDev ( "dump", tdata->adfname, 80, 2, 11 ); if ( ! tdata->device ) { //return; exit(1); diff --git a/tests/test_file_seek.c b/tests/test_file_seek.c index 2413d712..3e987655 100644 --- a/tests/test_file_seek.c +++ b/tests/test_file_seek.c @@ -244,7 +244,7 @@ int main ( void ) void setup ( test_data_t * const tdata ) { - tdata->device = adfCreateDumpDevice ( tdata->adfname, 80, 2, 11 ); + tdata->device = adfCreateDev ( "dump", tdata->adfname, 80, 2, 11 ); if ( tdata->device == NULL ) { //return; exit(1); diff --git a/tests/test_file_seek_after_write.c b/tests/test_file_seek_after_write.c index d6751df6..8ef0a816 100644 --- a/tests/test_file_seek_after_write.c +++ b/tests/test_file_seek_after_write.c @@ -313,7 +313,7 @@ int main ( void ) void setup ( test_data_t * const tdata ) { - tdata->device = adfCreateDumpDevice ( tdata->adfname, 80, 2, 11 ); + tdata->device = adfCreateDev ( "ramdisk", tdata->adfname, 80, 2, 11 ); if ( tdata->device == NULL ) { //return; exit(1); @@ -344,6 +344,6 @@ void teardown ( test_data_t * const tdata ) //adfUnMount ( tdata->vol ); adfUnMountDev ( tdata->device ); adfCloseDev ( tdata->device ); - if ( unlink ( tdata->adfname ) != 0 ) - perror("error deleting the image"); + //if ( unlink ( tdata->adfname ) != 0 ) + // perror("error deleting the image"); } diff --git a/tests/test_file_truncate.c b/tests/test_file_truncate.c index 7957b302..cfd9ddd6 100644 --- a/tests/test_file_truncate.c +++ b/tests/test_file_truncate.c @@ -452,7 +452,7 @@ int main ( void ) void setup ( test_data_t * const tdata ) { - tdata->device = adfCreateDumpDevice ( tdata->adfname, 80, 2, 11 ); + tdata->device = adfCreateDev ( "ramdisk", tdata->adfname, 80, 2, 11 ); if ( ! tdata->device ) { //return; exit(1); @@ -483,6 +483,6 @@ void teardown ( test_data_t * const tdata ) //adfUnMount ( tdata->vol ); adfUnMountDev ( tdata->device ); adfCloseDev ( tdata->device ); - if ( unlink ( tdata->adfname ) != 0 ) - perror("error deleting the image"); + //if ( unlink ( tdata->adfname ) != 0 ) + // perror("error deleting the image"); } diff --git a/tests/test_file_truncate2.c b/tests/test_file_truncate2.c index 363a5412..15bb435b 100644 --- a/tests/test_file_truncate2.c +++ b/tests/test_file_truncate2.c @@ -329,7 +329,7 @@ int main ( void ) void setup ( test_data_t * const tdata ) { - tdata->device = adfCreateDumpDevice ( tdata->adfname, 80, 2, 11 ); + tdata->device = adfCreateDev ( "ramdisk", tdata->adfname, 80, 2, 11 ); if ( ! tdata->device ) { //return; exit(1); @@ -360,6 +360,6 @@ void teardown ( test_data_t * const tdata ) //adfUnMount ( tdata->vol ); adfUnMountDev ( tdata->device ); adfCloseDev ( tdata->device ); - if ( unlink ( tdata->adfname ) != 0 ) - perror("error deleting the image"); + //if ( unlink ( tdata->adfname ) != 0 ) + // perror("error deleting the image"); } diff --git a/tests/test_file_write.c b/tests/test_file_write.c index d4f19353..e6caa0cf 100644 --- a/tests/test_file_write.c +++ b/tests/test_file_write.c @@ -309,7 +309,7 @@ int main ( void ) void setup ( test_data_t * const tdata ) { - tdata->device = adfCreateDumpDevice ( tdata->adfname, 80, 2, 11 ); + tdata->device = adfCreateDev ( "dump", tdata->adfname, 80, 2, 11 ); if ( ! tdata->device ) { //return; exit(1); diff --git a/tests/test_file_write_chunks.c b/tests/test_file_write_chunks.c index 3429a907..1ae8483f 100644 --- a/tests/test_file_write_chunks.c +++ b/tests/test_file_write_chunks.c @@ -366,7 +366,7 @@ int main ( void ) void setup ( test_data_t * const tdata ) { - tdata->device = adfCreateDumpDevice ( tdata->adfname, 80, 2, 11 ); + tdata->device = adfCreateDev ( "ramdisk", tdata->adfname, 80, 2, 11 ); if ( ! tdata->device ) { //return; exit(1); @@ -397,5 +397,5 @@ void teardown ( test_data_t * const tdata ) //adfUnMount ( tdata->vol ); adfUnMountDev ( tdata->device ); adfCloseDev ( tdata->device ); - unlink ( tdata->adfname ); + //unlink ( tdata->adfname ); } From a5b067c8e2c976f138783aff03f0572a46a33539 Mon Sep 17 00:00:00 2001 From: t-m Date: Sat, 10 Feb 2024 13:16:53 +0100 Subject: [PATCH 19/40] Cmake cross mingw configure script: update GCC version. --- util/cmake_shared_configure_cross_mingw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/cmake_shared_configure_cross_mingw b/util/cmake_shared_configure_cross_mingw index 259a76ba..a2dda7e7 100755 --- a/util/cmake_shared_configure_cross_mingw +++ b/util/cmake_shared_configure_cross_mingw @@ -3,6 +3,6 @@ # Generate configuration to build a shared library cross-compiling for Windows (with MinGW) # -CC=i686-w64-mingw32-gcc-10 util/cmake_shared_configure \ +CC=i686-w64-mingw32-gcc-12 util/cmake_shared_configure \ -DADFLIB_ENABLE_NATIVE_DEV:BOOL=ON \ $@ From dd8019159066990d5629bd75d60ddb0de348d6bc Mon Sep 17 00:00:00 2001 From: t-m Date: Sat, 10 Feb 2024 21:16:48 +0100 Subject: [PATCH 20/40] adf dev: rename functions (scheme: libnamespaceSubsysFunction). --- src/adf_dev.c | 30 +++++++++++++++--------------- src/adf_dev.h | 24 ++++++++++++------------ src/adf_dev_dump.c | 2 +- src/adf_dev_hd.c | 16 ++++++++-------- src/adf_vol.c | 4 ++-- 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/adf_dev.c b/src/adf_dev.c index 56cd2ca4..553f9e42 100644 --- a/src/adf_dev.c +++ b/src/adf_dev.c @@ -36,7 +36,7 @@ #include -struct AdfDevice * adfCreateDev ( const char * const driverName, +struct AdfDevice * adfDevCreate ( const char * const driverName, const char * const name, const uint32_t cylinders, const uint32_t heads, @@ -49,7 +49,7 @@ struct AdfDevice * adfCreateDev ( const char * const driverName, } -struct AdfDevice * adfOpenDev ( const char * const name, +struct AdfDevice * adfDevOpen ( const char * const name, const AdfAccessMode mode ) { const struct AdfDeviceDriver * const driver = adfGetDeviceDriverByDevName ( name ); @@ -59,7 +59,7 @@ struct AdfDevice * adfOpenDev ( const char * const name, } -struct AdfDevice * adfOpenDevWithDriver ( const char * const driverName, +struct AdfDevice * adfDevOpenWithDriver ( const char * const driverName, const char * const name, const AdfAccessMode mode ) { @@ -71,17 +71,17 @@ struct AdfDevice * adfOpenDevWithDriver ( const char * const driverName, /* - * adfCloseDev + * adfDevClose * * Closes/releases an opened device. */ -void adfCloseDev ( struct AdfDevice * const dev ) +void adfDevClose ( struct AdfDevice * const dev ) { if ( dev == NULL ) return; if ( dev->mounted ) - adfUnMountDev ( dev ); + adfDevUnMount ( dev ); dev->drv->closeDev ( dev ); } @@ -112,14 +112,14 @@ int adfDevType ( const struct AdfDevice * const dev ) /* - * adfDeviceInfo + * adfDevInfo * * display information about the device and its volumes * for demonstration purpose only since the output is stdout ! * * can be used before adfCreateVol() or adfMount() */ -void adfDeviceInfo ( const struct AdfDevice * const dev ) +void adfDevInfo ( const struct AdfDevice * const dev ) { const char * devTypeInfo = NULL; switch ( dev->devType ) { @@ -171,13 +171,13 @@ void adfDeviceInfo ( const struct AdfDevice * const dev ) /* - * adfMountDev + * adfDevMount * * mount a dump file (.adf) or a real device (uses adf_nativ.c and .h) * * adfInitDevice() must fill dev->size ! */ -RETCODE adfMountDev ( struct AdfDevice * const dev ) +RETCODE adfDevMount ( struct AdfDevice * const dev ) { if ( dev == NULL ) return RC_ERROR; @@ -196,7 +196,7 @@ RETCODE adfMountDev ( struct AdfDevice * const dev ) case DEVTYPE_HARDDISK: { uint8_t buf[512]; - rc = adfReadBlockDev ( dev, 0, 512, buf ); + rc = adfDevReadBlock ( dev, 0, 512, buf ); /* BV ...from here*/ if( rc != RC_OK ) { @@ -231,10 +231,10 @@ RETCODE adfMountDev ( struct AdfDevice * const dev ) /* - * adfUnMountDev + * adfDevUnMount * */ -void adfUnMountDev ( struct AdfDevice * const dev ) +void adfDevUnMount ( struct AdfDevice * const dev ) { if ( ! dev->mounted ) return; @@ -255,7 +255,7 @@ void adfUnMountDev ( struct AdfDevice * const dev ) } -RETCODE adfReadBlockDev ( struct AdfDevice * const dev, +RETCODE adfDevReadBlock ( struct AdfDevice * const dev, const uint32_t pSect, const uint32_t size, uint8_t * const buf ) @@ -269,7 +269,7 @@ RETCODE adfReadBlockDev ( struct AdfDevice * const dev, } -RETCODE adfWriteBlockDev ( struct AdfDevice * const dev, +RETCODE adfDevWriteBlock ( struct AdfDevice * const dev, const uint32_t pSect, const uint32_t size, const uint8_t * const buf ) diff --git a/src/adf_dev.h b/src/adf_dev.h index d87e3d57..1f2e5722 100644 --- a/src/adf_dev.h +++ b/src/adf_dev.h @@ -47,54 +47,54 @@ struct AdfDevice { /* - * adfCreateDev and adfOpenDev + * adfDevCreate and adfDevOpen * * creates or open an ADF device without reading any data (ie. without finding volumes) * * An created/opened device either has to be mounted (to be used with functions * requiring volume data) or only functions using block access on the device - * level (with adfRead/WriteBlockDev) can be used + * level (with adfDevRead/WriteBlock) can be used * (ie. this applies to adfCreateFlop/Hd); in general this level of access * is for: partitioning / formatting / creating file system data / cloning * the whole device on _device_ block level - and similar. */ -PREFIX struct AdfDevice * adfCreateDev ( const char * const driverName, +PREFIX struct AdfDevice * adfDevCreate ( const char * const driverName, const char * const name, const uint32_t cylinders, const uint32_t heads, const uint32_t sectors ); -PREFIX struct AdfDevice * adfOpenDev ( const char * const name, +PREFIX struct AdfDevice * adfDevOpen ( const char * const name, const AdfAccessMode mode ); /* - * adfOpenDevWithDriver + * adfDevOpenWithDriver * * allows to avoid automatic driver selection done in adfOpenDev and enforce * opening a file/device with the driver specified by its name * (esp. useful for custom, user-implemented device drivers) */ -PREFIX struct AdfDevice * adfOpenDevWithDriver ( const char * const driverName, +PREFIX struct AdfDevice * adfDevOpenWithDriver ( const char * const driverName, const char * const name, const AdfAccessMode mode ); -PREFIX void adfCloseDev ( struct AdfDevice * const dev ); +PREFIX void adfDevClose ( struct AdfDevice * const dev ); PREFIX int adfDevType ( const struct AdfDevice * const dev ); -PREFIX void adfDeviceInfo ( const struct AdfDevice * const dev ); +PREFIX void adfDevInfo ( const struct AdfDevice * const dev ); -PREFIX RETCODE adfMountDev ( struct AdfDevice * const dev ); -PREFIX void adfUnMountDev ( struct AdfDevice * const dev ); +PREFIX RETCODE adfDevMount ( struct AdfDevice * const dev ); +PREFIX void adfDevUnMount ( struct AdfDevice * const dev ); -RETCODE adfReadBlockDev ( struct AdfDevice * const dev, +RETCODE adfDevReadBlock ( struct AdfDevice * const dev, const uint32_t pSect, const uint32_t size, uint8_t * const buf ); -RETCODE adfWriteBlockDev ( struct AdfDevice * const dev, +RETCODE adfDevWriteBlock ( struct AdfDevice * const dev, const uint32_t pSect, const uint32_t size, const uint8_t * const buf ); diff --git a/src/adf_dev_dump.c b/src/adf_dev_dump.c index 4195d7b3..3eb9a5b8 100644 --- a/src/adf_dev_dump.c +++ b/src/adf_dev_dump.c @@ -166,7 +166,7 @@ static RETCODE adfReleaseDumpDevice ( struct AdfDevice * const dev ) fclose ( ( (struct DevDumpData *) dev->drvData )->fd ); if ( dev->mounted ) - adfUnMountDev ( dev ); + adfDevUnMount ( dev ); free ( dev->drvData ); free ( dev->name ); diff --git a/src/adf_dev_hd.c b/src/adf_dev_hd.c index 1220e7bf..85f808df 100644 --- a/src/adf_dev_hd.c +++ b/src/adf_dev_hd.c @@ -436,7 +436,7 @@ RETCODE adfReadRDSKblock ( struct AdfDevice * const dev, { uint8_t buf[256]; - RETCODE rc = adfReadBlockDev ( dev, 0, 256, buf ); + RETCODE rc = adfDevReadBlock ( dev, 0, 256, buf ); if ( rc != RC_OK ) return rc; @@ -504,7 +504,7 @@ RETCODE adfWriteRDSKblock ( struct AdfDevice * const dev, newSum = adfNormalSum(buf, 8, LOGICAL_BLOCK_SIZE); swLong(buf+8, newSum); - return adfWriteBlockDev ( dev, 0, LOGICAL_BLOCK_SIZE, buf ); + return adfDevWriteBlock ( dev, 0, LOGICAL_BLOCK_SIZE, buf ); } @@ -518,7 +518,7 @@ RETCODE adfReadPARTblock ( struct AdfDevice * const dev, { uint8_t buf[ sizeof(struct bPARTblock) ]; - RETCODE rc = adfReadBlockDev ( dev, (uint32_t) nSect, + RETCODE rc = adfDevReadBlock ( dev, (uint32_t) nSect, sizeof(struct bPARTblock), buf ); if ( rc != RC_OK ) return rc; @@ -584,7 +584,7 @@ RETCODE adfWritePARTblock ( struct AdfDevice * const dev, swLong(buf+8, newSum); /* *(int32_t*)(buf+8) = swapLong((uint8_t*)&newSum);*/ - return adfWriteBlockDev ( dev, (uint32_t) nSect, LOGICAL_BLOCK_SIZE, buf ); + return adfDevWriteBlock ( dev, (uint32_t) nSect, LOGICAL_BLOCK_SIZE, buf ); } /* @@ -597,7 +597,7 @@ RETCODE adfReadFSHDblock ( struct AdfDevice * const dev, { uint8_t buf[sizeof(struct bFSHDblock)]; - RETCODE rc = adfReadBlockDev ( dev, (uint32_t) nSect, sizeof(struct bFSHDblock), buf ); + RETCODE rc = adfDevReadBlock ( dev, (uint32_t) nSect, sizeof(struct bFSHDblock), buf ); if ( rc != RC_OK ) return rc; @@ -652,7 +652,7 @@ RETCODE adfWriteFSHDblock ( struct AdfDevice * const dev, swLong(buf+8, newSum); /* *(int32_t*)(buf+8) = swapLong((uint8_t*)&newSum);*/ - return adfWriteBlockDev ( dev, (uint32_t) nSect, LOGICAL_BLOCK_SIZE, buf ); + return adfDevWriteBlock ( dev, (uint32_t) nSect, LOGICAL_BLOCK_SIZE, buf ); } @@ -666,7 +666,7 @@ RETCODE adfReadLSEGblock ( struct AdfDevice * const dev, { uint8_t buf[sizeof(struct bLSEGblock)]; - RETCODE rc = adfReadBlockDev ( dev, (uint32_t) nSect, + RETCODE rc = adfDevReadBlock ( dev, (uint32_t) nSect, sizeof(struct bLSEGblock), buf ); if ( rc != RC_OK ) return rc; @@ -722,7 +722,7 @@ RETCODE adfWriteLSEGblock ( struct AdfDevice * const dev, swLong(buf+8,newSum); /* *(int32_t*)(buf+8) = swapLong((uint8_t*)&newSum);*/ - return adfWriteBlockDev ( dev, (uint32_t) nSect, LOGICAL_BLOCK_SIZE, buf ); + return adfDevWriteBlock ( dev, (uint32_t) nSect, LOGICAL_BLOCK_SIZE, buf ); } /*##########################################################################*/ diff --git a/src/adf_vol.c b/src/adf_vol.c index 728c0184..9915f99d 100644 --- a/src/adf_vol.c +++ b/src/adf_vol.c @@ -489,7 +489,7 @@ RETCODE adfReadBlock ( struct AdfVolume * const vol, return RC_BLOCKOUTOFRANGE; } - RETCODE rc = adfReadBlockDev ( vol->dev, pSect, 512, buf ); + RETCODE rc = adfDevReadBlock ( vol->dev, pSect, 512, buf ); if ( rc != RC_OK ) { adfEnv.eFct ( "adfReadBlock: error reading block %d, volume '%s'", nSect, vol->volName ); @@ -529,7 +529,7 @@ RETCODE adfWriteBlock ( struct AdfVolume * const vol, return RC_BLOCKOUTOFRANGE; } - RETCODE rc = adfWriteBlockDev ( vol->dev, pSect, 512, buf ); + RETCODE rc = adfDevWriteBlock ( vol->dev, pSect, 512, buf ); if ( rc != RC_OK ) { adfEnv.eFct ( "adfWriteBlock: error writing block %d, volume '%s'", nSect, vol->volName ); From 68eb871b6e068cbab3b5050c8eb43d038d22d375 Mon Sep 17 00:00:00 2001 From: t-m Date: Sat, 10 Feb 2024 21:19:44 +0100 Subject: [PATCH 21/40] examples: use renamed adf dev functions. --- examples/adf_bitmap.c | 8 ++++---- examples/adf_floppy_create.c | 8 ++++---- examples/adf_floppy_format.c | 14 +++++++------- examples/adf_show_metadata.c | 10 +++++----- examples/unadf.c | 8 ++++---- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/examples/adf_bitmap.c b/examples/adf_bitmap.c index dd4dc027..60cef598 100644 --- a/examples/adf_bitmap.c +++ b/examples/adf_bitmap.c @@ -74,7 +74,7 @@ int main ( int argc, printf ( "\nOpening image/device:\t'%s' (%s)\n", adfname, devMode ? "read-only" : "read-write" ); - struct AdfDevice * const dev = adfOpenDev ( adfname, devMode ); + struct AdfDevice * const dev = adfDevOpen ( adfname, devMode ); if ( ! dev ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", adfname ); @@ -82,7 +82,7 @@ int main ( int argc, goto env_cleanup; } - RETCODE rc = adfMountDev ( dev ); + RETCODE rc = adfDevMount ( dev ); if ( rc != RC_OK ) { fprintf ( stderr, "Cannot get volume info for file/device '%s' - aborting...\n", adfname ); @@ -118,9 +118,9 @@ int main ( int argc, adfUnMount ( vol ); dev_mount_cleanup: - adfUnMountDev ( dev ); + adfDevUnMount ( dev ); dev_cleanup: - adfCloseDev ( dev ); + adfDevClose ( dev ); env_cleanup: adfEnvCleanUp(); diff --git a/examples/adf_floppy_create.c b/examples/adf_floppy_create.c index 8468a69f..3742cec0 100644 --- a/examples/adf_floppy_create.c +++ b/examples/adf_floppy_create.c @@ -57,18 +57,18 @@ int main ( int argc, adfEnvInitDefault(); - struct AdfDevice * device = adfCreateDev ( "dump", adfname, tracks, HEADS, + struct AdfDevice * device = adfDevCreate ( "dump", adfname, tracks, HEADS, sectors_per_track ); if ( ! device ) { fprintf ( stderr, "Error creating floppy (%s) disk image %s.\n", floppy_type, adfname ); return 1; } - adfDeviceInfo ( device ); + adfDevInfo ( device ); printf ( "Done!\n" ); - adfUnMountDev ( device ); - adfCloseDev ( device ); + adfDevUnMount ( device ); + adfDevClose ( device ); adfEnvCleanUp(); return 0; diff --git a/examples/adf_floppy_format.c b/examples/adf_floppy_format.c index 5d6fa854..e3d1b09e 100644 --- a/examples/adf_floppy_format.c +++ b/examples/adf_floppy_format.c @@ -30,18 +30,18 @@ int main ( int argc, adfEnvInitDefault(); - struct AdfDevice * const device = adfOpenDev ( adfname, ADF_ACCESS_MODE_READWRITE ); + struct AdfDevice * const device = adfDevOpen ( adfname, ADF_ACCESS_MODE_READWRITE ); if ( device == NULL ) { fprintf ( stderr, "Cannot open floppy disk %s - aborting...\n", adfname ); return 1; } - RETCODE rc = adfMountDev ( device ); + RETCODE rc = adfDevMount ( device ); if ( rc == RC_OK ) { fprintf ( stderr, "The floppy disk %s already contains a filesystem - aborting...\n", adfname ); - adfUnMountDev ( device ); - adfCloseDev ( device ); + adfDevUnMount ( device ); + adfDevClose ( device ); return 1; } @@ -64,18 +64,18 @@ int main ( int argc, } device->cylinders = device->size / ( device->sectors * device->heads * 512 ); - adfDeviceInfo ( device ); + adfDevInfo ( device ); printf ( "Formatting floppy (%s) disk '%s'...\n", fdtype, adfname ); if ( adfCreateFlop ( device, label, (unsigned char) type ) != RC_OK ) { fprintf ( stderr, "Error formatting the disk image '%s'!", adfname ); - adfCloseDev ( device ); + adfDevClose ( device ); adfEnvCleanUp(); return 1; } printf ( "Done!\n" ); - adfCloseDev ( device ); + adfDevClose ( device ); adfEnvCleanUp(); return 0; diff --git a/examples/adf_show_metadata.c b/examples/adf_show_metadata.c index 493e593c..48f50622 100644 --- a/examples/adf_show_metadata.c +++ b/examples/adf_show_metadata.c @@ -45,7 +45,7 @@ int main ( int argc, adfEnvInitDefault(); printf ( "\nOpening image/device:\t'%s'\n", adfname ); - struct AdfDevice * const dev = adfOpenDev ( adfname, ADF_ACCESS_MODE_READONLY ); + struct AdfDevice * const dev = adfDevOpen ( adfname, ADF_ACCESS_MODE_READONLY ); if ( ! dev ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", adfname ); @@ -53,7 +53,7 @@ int main ( int argc, goto env_cleanup; } - RETCODE rc = adfMountDev ( dev ); + RETCODE rc = adfDevMount ( dev ); if ( rc != RC_OK ) { fprintf ( stderr, "Cannot get volume info for file/device '%s' - aborting...\n", adfname ); @@ -81,9 +81,9 @@ int main ( int argc, adfUnMount ( vol ); dev_mount_cleanup: - adfUnMountDev ( dev ); + adfDevUnMount ( dev ); dev_cleanup: - adfCloseDev ( dev ); + adfDevClose ( dev ); env_cleanup: adfEnvCleanUp(); @@ -93,7 +93,7 @@ int main ( int argc, static void show_device_metadata ( struct AdfDevice * const dev ) { - adfDeviceInfo ( dev ); + adfDevInfo ( dev ); } diff --git a/examples/unadf.c b/examples/unadf.c index 32a8f18e..fb6aef2e 100644 --- a/examples/unadf.c +++ b/examples/unadf.c @@ -94,13 +94,13 @@ int main(int argc, char *argv[]) { parse_args(argc, argv); /* open device */ - if (!(dev = adfOpenDev(adf_file, ADF_ACCESS_MODE_READONLY))) { + if (!(dev = adfDevOpen(adf_file, ADF_ACCESS_MODE_READONLY))) { fprintf(stderr, "%s: can't open device\n", adf_file); goto error_handler; } /* mount device */ - if (adfMountDev(dev) != RC_OK) { + if (adfDevMount(dev) != RC_OK) { fprintf(stderr, "%s: can't mount device\n", adf_file); goto error_handler; } @@ -172,8 +172,8 @@ int main(int argc, char *argv[]) { error_handler: if (vol) adfUnMount(vol); - if (dev && dev->mounted) adfUnMountDev(dev); - if (dev) adfCloseDev(dev); + if (dev && dev->mounted) adfDevUnMount(dev); + if (dev) adfDevClose(dev); if (file_list) freeList(file_list); adfEnvCleanUp(); return 0; From cbbf801fa2155ab663ba49895bf89f2c1cae6a19 Mon Sep 17 00:00:00 2001 From: t-m Date: Sat, 10 Feb 2024 21:21:00 +0100 Subject: [PATCH 22/40] tests: use renamed adf dev functions. --- regtests/Test/access.c | 20 ++++++------- regtests/Test/bitmap_read_segfault.c | 8 ++--- regtests/Test/bitmap_recreate.c | 16 +++++----- regtests/Test/bootdisk.c | 16 +++++----- regtests/Test/cache_crash.c | 8 ++--- regtests/Test/comment.c | 20 ++++++------- regtests/Test/del_test.c | 14 ++++----- regtests/Test/dir_test.c | 14 ++++----- regtests/Test/dir_test2.c | 14 ++++----- regtests/Test/dir_test_chdir.c | 14 ++++----- regtests/Test/dispsect.c | 20 ++++++------- regtests/Test/file_read_hard_link_test.c | 14 ++++----- regtests/Test/file_seek_after_write.c | 6 ++-- regtests/Test/file_seek_test.c | 14 ++++----- regtests/Test/file_seek_test2.c | 14 ++++----- regtests/Test/file_test.c | 32 ++++++++++---------- regtests/Test/file_test2.c | 14 ++++----- regtests/Test/file_test3.c | 14 ++++----- regtests/Test/fl_test.c | 30 +++++++++---------- regtests/Test/fl_test2.c | 14 ++++----- regtests/Test/floppy_overfilling_test.c | 6 ++-- regtests/Test/hardfile.c | 16 +++++----- regtests/Test/hd_test.c | 37 ++++++++++++------------ regtests/Test/hd_test2.c | 33 ++++++++++----------- regtests/Test/hd_test3.c | 32 ++++++++++---------- regtests/Test/progbar.c | 16 +++++----- regtests/Test/readonly.c | 14 ++++----- regtests/Test/rename.c | 32 ++++++++++---------- regtests/Test/rename2.c | 16 +++++----- regtests/Test/undel.c | 20 ++++++------- regtests/Test/undel2.c | 16 +++++----- regtests/Test/undel3.c | 16 +++++----- tests/test_file_append.c | 6 ++-- tests/test_file_create.c | 6 ++-- tests/test_file_overwrite.c | 6 ++-- tests/test_file_overwrite2.c | 6 ++-- tests/test_file_seek.c | 6 ++-- tests/test_file_seek_after_write.c | 6 ++-- tests/test_file_truncate.c | 6 ++-- tests/test_file_truncate2.c | 6 ++-- tests/test_file_write.c | 6 ++-- tests/test_file_write_chunks.c | 6 ++-- 42 files changed, 314 insertions(+), 316 deletions(-) diff --git a/regtests/Test/access.c b/regtests/Test/access.c index 7b9c0dc1..4ef94097 100644 --- a/regtests/Test/access.c +++ b/regtests/Test/access.c @@ -32,25 +32,25 @@ int main(int argc, char *argv[]) adfEnvInitDefault(); /* create and mount one device */ - hd = adfCreateDev ( "dump", "access-newdev", 80, 2, 11 ); + hd = adfDevCreate ( "dump", "access-newdev", 80, 2, 11 ); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); } - adfDeviceInfo(hd); + adfDevInfo ( hd ); if (adfCreateFlop( hd, "empty", FSMASK_FFS|FSMASK_DIRCACHE )!=RC_OK) { fprintf(stderr, "can't create floppy\n"); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -58,8 +58,8 @@ int main(int argc, char *argv[]) fic = adfFileOpen ( vol, "file_1a", ADF_FILE_MODE_WRITE ); if (!fic) { adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } @@ -102,8 +102,8 @@ int main(int argc, char *argv[]) adfFreeDirList(list); adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); diff --git a/regtests/Test/bitmap_read_segfault.c b/regtests/Test/bitmap_read_segfault.c index 74c97b5c..a99ab499 100644 --- a/regtests/Test/bitmap_read_segfault.c +++ b/regtests/Test/bitmap_read_segfault.c @@ -39,14 +39,14 @@ int main ( const int argc, // adfSetEnvFct(0,0,MyVer,0); BOOL error_status = FALSE; - struct AdfDevice * const dev = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READONLY ); + struct AdfDevice * const dev = adfDevOpen ( argv[1], ADF_ACCESS_MODE_READONLY ); if ( ! dev ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", argv[1] ); adfEnvCleanUp(); exit(1); } - RETCODE rc = adfMountDev ( dev ); + RETCODE rc = adfDevMount ( dev ); if ( dev == NULL ) { log_error ( stderr, "can't mount device %s\n", argv[1] ); error_status = TRUE; @@ -67,10 +67,10 @@ int main ( const int argc, adfUnMount ( vol ); umount_dev: - adfUnMountDev ( dev ); + adfDevUnMount ( dev ); close_dev: - adfCloseDev ( dev ); + adfDevClose ( dev ); clean_up: adfEnvCleanUp(); diff --git a/regtests/Test/bitmap_recreate.c b/regtests/Test/bitmap_recreate.c index df1fa143..621876f5 100644 --- a/regtests/Test/bitmap_recreate.c +++ b/regtests/Test/bitmap_recreate.c @@ -74,7 +74,7 @@ int main ( const int argc, // adfSetEnvFct(0,0,MyVer,0); /* mount the original image */ - struct AdfDevice * devOrig = adfOpenDev ( adfOrig, ADF_ACCESS_MODE_READONLY ); + struct AdfDevice * devOrig = adfDevOpen ( adfOrig, ADF_ACCESS_MODE_READONLY ); if ( ! devOrig ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", adfOrig ); @@ -82,7 +82,7 @@ int main ( const int argc, goto clean_up; } - RETCODE rc = adfMountDev ( devOrig ); + RETCODE rc = adfDevMount ( devOrig ); if ( rc != RC_OK ) { log_error ( stderr, "can't mount device %s\n", adfOrig ); error_status = TRUE; @@ -99,7 +99,7 @@ int main ( const int argc, /* mount the image copy (for updating) */ - struct AdfDevice * const devUpdate = adfOpenDev ( adfUpdate, + struct AdfDevice * const devUpdate = adfDevOpen ( adfUpdate, ADF_ACCESS_MODE_READWRITE ); if ( ! devUpdate ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", @@ -108,7 +108,7 @@ int main ( const int argc, goto umount_vol_orig; } - rc = adfMountDev ( devUpdate ); + rc = adfDevMount ( devUpdate ); if ( rc != RC_OK ) { log_error ( stderr, "can't mount device %s\n", adfUpdate ); error_status = TRUE; @@ -184,16 +184,16 @@ int main ( const int argc, umount_vol_updated: adfUnMount ( volUpdate ); umount_dev_updated: - adfUnMountDev ( devUpdate ); + adfDevUnMount ( devUpdate ); close_dev_updated: - adfCloseDev ( devUpdate ); + adfDevClose ( devUpdate ); umount_vol_orig: adfUnMount ( volOrig ); umount_dev_orig: - adfUnMountDev ( devOrig ); + adfDevUnMount ( devOrig ); close_dev_orig: - adfCloseDev ( devOrig ); + adfDevClose ( devOrig ); clean_up: adfEnvCleanUp(); diff --git a/regtests/Test/bootdisk.c b/regtests/Test/bootdisk.c index 12db9e14..892a27d3 100644 --- a/regtests/Test/bootdisk.c +++ b/regtests/Test/bootdisk.c @@ -43,25 +43,25 @@ int main(int argc, char *argv[]) adfEnvInitDefault(); /* create and mount one device */ - hd = adfCreateDev ( "dump", "bootdisk-newdev", 80, 2, 11 ); + hd = adfDevCreate ( "dump", "bootdisk-newdev", 80, 2, 11 ); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); } - adfDeviceInfo(hd); + adfDevInfo ( hd ); if (adfCreateFlop( hd, "empty", FSMASK_FFS|FSMASK_DIRCACHE )!=RC_OK) { fprintf(stderr, "can't create floppy\n"); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose (hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -71,8 +71,8 @@ int main(int argc, char *argv[]) adfVolumeInfo(vol); adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); diff --git a/regtests/Test/cache_crash.c b/regtests/Test/cache_crash.c index 0d05f0f6..73fc0648 100644 --- a/regtests/Test/cache_crash.c +++ b/regtests/Test/cache_crash.c @@ -13,8 +13,8 @@ int main(int argc, char *argv[]) { if (argc <= 1) return 1; adfEnvInitDefault(); - if ((dev = adfOpenDev(argv[1], ADF_ACCESS_MODE_READONLY))) { - if (adfMountDev(dev) == RC_OK) { + if ((dev = adfDevOpen(argv[1], ADF_ACCESS_MODE_READONLY))) { + if (adfDevMount(dev) == RC_OK) { if ((vol = adfMount(dev, 0, ADF_ACCESS_MODE_READONLY))) { /* use dir cache (enables the crash) */ adfChgEnvProp(PR_USEDIRC, &true); @@ -25,9 +25,9 @@ int main(int argc, char *argv[]) { if (list) adfFreeDirList(list); adfUnMount(vol); } - adfUnMountDev(dev); + adfDevUnMount(dev); } - adfCloseDev(dev); + adfDevClose(dev); } adfEnvCleanUp(); return ok ? 0 : 1; diff --git a/regtests/Test/comment.c b/regtests/Test/comment.c index 940cf425..326e1b22 100644 --- a/regtests/Test/comment.c +++ b/regtests/Test/comment.c @@ -33,25 +33,25 @@ int main(int argc, char *argv[]) adfEnvInitDefault(); /* create and mount one device */ - hd = adfCreateDev ( "dump", "comment-newdev", 80, 2, 11 ); + hd = adfDevCreate ( "dump", "comment-newdev", 80, 2, 11 ); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); } - adfDeviceInfo(hd); + adfDevInfo ( hd ); if (adfCreateFlop( hd, "empty", FSMASK_FFS|FSMASK_DIRCACHE )!=RC_OK) { fprintf(stderr, "can't create floppy\n"); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -59,8 +59,8 @@ int main(int argc, char *argv[]) fic = adfFileOpen ( vol, "file_1a", ADF_FILE_MODE_WRITE ); if (!fic) { adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } @@ -105,8 +105,8 @@ int main(int argc, char *argv[]) adfFreeDirList(list); adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); diff --git a/regtests/Test/del_test.c b/regtests/Test/del_test.c index 92db7b69..72d5f891 100644 --- a/regtests/Test/del_test.c +++ b/regtests/Test/del_test.c @@ -35,7 +35,7 @@ int main(int argc, char *argv[]) adfEnvInitDefault(); /* open and mount existing device */ - struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + struct AdfDevice * hd = adfDevOpen ( argv[1], ADF_ACCESS_MODE_READWRITE ); if ( ! hd ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", argv[1] ); @@ -43,17 +43,17 @@ int main(int argc, char *argv[]) exit(1); } - RETCODE rc = adfMountDev ( hd ); + RETCODE rc = adfDevMount ( hd ); if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); - adfCloseDev(hd); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } vol = adfMount(hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -121,8 +121,8 @@ int main(int argc, char *argv[]) adfVolumeInfo(vol); adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); diff --git a/regtests/Test/dir_test.c b/regtests/Test/dir_test.c index 7e88add6..34ebd1c2 100644 --- a/regtests/Test/dir_test.c +++ b/regtests/Test/dir_test.c @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) /* open and mount existing device */ /* testffs.adf */ - struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + struct AdfDevice * hd = adfDevOpen ( argv[1], ADF_ACCESS_MODE_READWRITE ); if ( ! hd ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", argv[1] ); @@ -54,17 +54,17 @@ int main(int argc, char *argv[]) exit(1); } - RETCODE rc = adfMountDev ( hd ); + RETCODE rc = adfDevMount ( hd ); if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); - adfCloseDev(hd); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -116,8 +116,8 @@ int main(int argc, char *argv[]) status += test_softlink_realname ( vol, "slink_dir1", "dir_1" ); adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); diff --git a/regtests/Test/dir_test2.c b/regtests/Test/dir_test2.c index 23eeef5b..2972e1a0 100644 --- a/regtests/Test/dir_test2.c +++ b/regtests/Test/dir_test2.c @@ -36,7 +36,7 @@ int main(int argc, char *argv[]) // adfSetEnvFct(0,0,MyVer,0); /* open and mount existing device */ - struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + struct AdfDevice * hd = adfDevOpen ( argv[1], ADF_ACCESS_MODE_READWRITE ); if ( ! hd ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", argv[1] ); @@ -44,17 +44,17 @@ int main(int argc, char *argv[]) exit(1); } - RETCODE rc = adfMountDev ( hd ); + RETCODE rc = adfDevMount ( hd ); if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); - adfCloseDev(hd); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -94,8 +94,8 @@ int main(int argc, char *argv[]) putchar('\n'); adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); diff --git a/regtests/Test/dir_test_chdir.c b/regtests/Test/dir_test_chdir.c index dd46cbaf..55203514 100644 --- a/regtests/Test/dir_test_chdir.c +++ b/regtests/Test/dir_test_chdir.c @@ -90,7 +90,7 @@ int run_chdir_tests ( chdir_test_t * test_data ) test_data->image ); //#endif - struct AdfDevice * const dev = adfOpenDev ( test_data->image, + struct AdfDevice * const dev = adfDevOpen ( test_data->image, ADF_ACCESS_MODE_READONLY ); if ( ! dev ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", @@ -99,11 +99,11 @@ int run_chdir_tests ( chdir_test_t * test_data ) exit(1); } - RETCODE rc = adfMountDev ( dev ); + RETCODE rc = adfDevMount ( dev ); if ( rc != RC_OK ) { fprintf ( stderr, "Cannot mount image %s - aborting the test...\n", test_data->image ); - adfCloseDev ( dev ); + adfDevClose ( dev ); return 1; } @@ -111,8 +111,8 @@ int run_chdir_tests ( chdir_test_t * test_data ) if ( ! vol ) { fprintf ( stderr, "Cannot mount volume 0 from image %s - aborting the test...\n", test_data->image ); - adfUnMountDev ( dev ); - adfCloseDev ( dev ); + adfDevUnMount ( dev ); + adfDevClose ( dev ); return 1; } @@ -132,8 +132,8 @@ int run_chdir_tests ( chdir_test_t * test_data ) //clean_up: //adfToRootDir ( vol ); adfUnMount ( vol ); - adfUnMountDev ( dev ); - adfCloseDev ( dev ); + adfDevUnMount ( dev ); + adfDevClose ( dev ); return nerrors; } diff --git a/regtests/Test/dispsect.c b/regtests/Test/dispsect.c index b32bd844..d65525b0 100644 --- a/regtests/Test/dispsect.c +++ b/regtests/Test/dispsect.c @@ -39,25 +39,25 @@ int main(int argc, char *argv[]) adfChgEnvProp(PR_USE_RWACCESS,&true); /* create and mount one device */ - hd = adfCreateDev ( "dump", "dispsect-newdev", 80, 2, 11 ); + hd = adfDevCreate ( "dump", "dispsect-newdev", 80, 2, 11 ); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); } - adfDeviceInfo(hd); + adfDevInfo ( hd ); if (adfCreateFlop( hd, "empty", FSMASK_FFS|FSMASK_DIRCACHE )!=RC_OK) { fprintf(stderr, "can't create floppy\n"); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -65,8 +65,8 @@ int main(int argc, char *argv[]) fic = adfFileOpen ( vol, "file_1a", ADF_FILE_MODE_WRITE ); if (!fic) { adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } @@ -124,8 +124,8 @@ int main(int argc, char *argv[]) adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); diff --git a/regtests/Test/file_read_hard_link_test.c b/regtests/Test/file_read_hard_link_test.c index 6d459e0a..bd7aef3c 100644 --- a/regtests/Test/file_read_hard_link_test.c +++ b/regtests/Test/file_read_hard_link_test.c @@ -109,7 +109,7 @@ int test_hlink_read ( reading_test_t * test_data ) test_data->real_file ); #endif - struct AdfDevice * const dev = adfOpenDev ( test_data->image_filename, + struct AdfDevice * const dev = adfDevOpen ( test_data->image_filename, ADF_ACCESS_MODE_READONLY ); if ( ! dev ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", @@ -118,11 +118,11 @@ int test_hlink_read ( reading_test_t * test_data ) exit(1); } - RETCODE rc = adfMountDev ( dev ); + RETCODE rc = adfDevMount ( dev ); if ( rc != RC_OK ) { fprintf ( stderr, "Cannot mount image %s - aborting the test...\n", test_data->image_filename ); - adfCloseDev ( dev ); + adfDevClose ( dev ); return 1; } @@ -130,8 +130,8 @@ int test_hlink_read ( reading_test_t * test_data ) if ( ! vol ) { fprintf ( stderr, "Cannot mount volume 0 from image %s - aborting the test...\n", test_data->image_filename ); - adfUnMountDev ( dev ); - adfCloseDev ( dev ); + adfDevUnMount ( dev ); + adfDevClose ( dev ); return 1; } @@ -177,8 +177,8 @@ int test_hlink_read ( reading_test_t * test_data ) clean_up: //adfToRootDir ( vol ); adfUnMount ( vol ); - adfUnMountDev ( dev ); - adfCloseDev ( dev ); + adfDevUnMount ( dev ); + adfDevClose ( dev ); return status; } diff --git a/regtests/Test/file_seek_after_write.c b/regtests/Test/file_seek_after_write.c index 5c450b5c..44166f3a 100644 --- a/regtests/Test/file_seek_after_write.c +++ b/regtests/Test/file_seek_after_write.c @@ -239,7 +239,7 @@ unsigned test_seek_after_write ( const test_data_t * const test_data ) { // create device const char * const adfname = test_data->adfname; - struct AdfDevice * const device = adfCreateDev ( "dump", adfname, 80, 2, 11 ); + struct AdfDevice * const device = adfDevCreate ( "dump", adfname, 80, 2, 11 ); if ( ! device ) return 1; adfCreateFlop ( device, test_data->volname, test_data->fstype ); @@ -376,8 +376,8 @@ unsigned test_seek_after_write ( const test_data_t * const test_data ) umount_volume: adfUnMount ( vol ); umount_device: - adfUnMountDev ( device ); - adfCloseDev ( device ); + adfDevUnMount ( device ); + adfDevClose ( device ); if ( unlink ( adfname ) != 0 ) perror ("error deleting the image"); return errors; diff --git a/regtests/Test/file_seek_test.c b/regtests/Test/file_seek_test.c index 368660ba..8b54eea6 100644 --- a/regtests/Test/file_seek_test.c +++ b/regtests/Test/file_seek_test.c @@ -134,7 +134,7 @@ int run_single_seek_tests ( reading_test_t * test_data ) fflush ( stdout ); #endif - struct AdfDevice * const dev = adfOpenDev ( test_data->image_filename, + struct AdfDevice * const dev = adfDevOpen ( test_data->image_filename, ADF_ACCESS_MODE_READONLY ); if ( ! dev ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", @@ -143,11 +143,11 @@ int run_single_seek_tests ( reading_test_t * test_data ) exit(1); } - RETCODE rc = adfMountDev ( dev ); + RETCODE rc = adfDevMount ( dev ); if ( rc != RC_OK ) { fprintf ( stderr, "Cannot mount image %s - aborting the test...\n", test_data->image_filename ); - adfCloseDev ( dev ); + adfDevClose ( dev ); return 1; } @@ -155,8 +155,8 @@ int run_single_seek_tests ( reading_test_t * test_data ) if ( ! vol ) { fprintf ( stderr, "Cannot mount volume 0 from image %s - aborting the test...\n", test_data->image_filename ); - adfUnMountDev ( dev ); - adfCloseDev ( dev ); + adfDevUnMount ( dev ); + adfDevClose ( dev ); return 1; } #if TEST_VERBOSITY > 0 @@ -193,8 +193,8 @@ int run_single_seek_tests ( reading_test_t * test_data ) cleanup: adfUnMount ( vol ); - adfUnMountDev ( dev ); - adfCloseDev ( dev ); + adfDevUnMount ( dev ); + adfDevClose ( dev ); return status; } diff --git a/regtests/Test/file_seek_test2.c b/regtests/Test/file_seek_test2.c index b9aca01c..ff825356 100644 --- a/regtests/Test/file_seek_test2.c +++ b/regtests/Test/file_seek_test2.c @@ -82,7 +82,7 @@ int run_multiple_seek_tests ( test_file_t * test_data ) test_data->filename_local ); #endif - struct AdfDevice * const dev = adfOpenDev ( test_data->image_filename, + struct AdfDevice * const dev = adfDevOpen ( test_data->image_filename, ADF_ACCESS_MODE_READONLY ); if ( ! dev ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", @@ -91,11 +91,11 @@ int run_multiple_seek_tests ( test_file_t * test_data ) exit(1); } - RETCODE rc = adfMountDev ( dev ); + RETCODE rc = adfDevMount ( dev ); if ( rc != RC_OK ) { fprintf ( stderr, "Cannot mount image %s - aborting the test...\n", test_data->image_filename ); - adfCloseDev ( dev ); + adfDevClose ( dev ); return 1; } @@ -103,8 +103,8 @@ int run_multiple_seek_tests ( test_file_t * test_data ) if ( ! vol ) { fprintf ( stderr, "Cannot mount volume 0 from image %s - aborting the test...\n", test_data->image_filename ); - adfUnMountDev ( dev ); - adfCloseDev ( dev ); + adfDevUnMount ( dev ); + adfDevClose ( dev ); return 1; } #if TEST_VERBOSITY > 0 @@ -144,8 +144,8 @@ int run_multiple_seek_tests ( test_file_t * test_data ) cleanup: adfUnMount ( vol ); - adfUnMountDev ( dev ); - adfCloseDev ( dev ); + adfDevUnMount ( dev ); + adfDevClose ( dev ); return status; } diff --git a/regtests/Test/file_test.c b/regtests/Test/file_test.c index 486ff801..289d7d9a 100644 --- a/regtests/Test/file_test.c +++ b/regtests/Test/file_test.c @@ -38,7 +38,7 @@ int main(int argc, char *argv[]) // adfSetEnvFct(0,0,MyVer,0); /* open and mount existing device : FFS */ - struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + struct AdfDevice * hd = adfDevOpen ( argv[1], ADF_ACCESS_MODE_READWRITE ); if ( ! hd ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", argv[1] ); @@ -46,17 +46,17 @@ int main(int argc, char *argv[]) exit(1); } - RETCODE rc = adfMountDev ( hd ); + RETCODE rc = adfDevMount ( hd ); if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); - adfCloseDev(hd); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -84,8 +84,8 @@ int main(int argc, char *argv[]) file = adfFileOpen ( vol, "emptyfile", ADF_FILE_MODE_READ ); if (!file) { adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't open file\n"); exit(1); } @@ -95,13 +95,13 @@ int main(int argc, char *argv[]) adfFileClose ( file ); adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); /* ofs */ - hd = adfOpenDev ( argv[2], ADF_ACCESS_MODE_READWRITE ); + hd = adfDevOpen ( argv[2], ADF_ACCESS_MODE_READWRITE ); if ( ! hd ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", argv[2] ); @@ -109,17 +109,17 @@ int main(int argc, char *argv[]) exit(1); } - rc = adfMountDev ( hd ); + rc = adfDevMount ( hd ); if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); - adfCloseDev(hd); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -145,8 +145,8 @@ int main(int argc, char *argv[]) adfFileClose ( file ); adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); diff --git a/regtests/Test/file_test2.c b/regtests/Test/file_test2.c index c6cbe5e9..b088fbe8 100644 --- a/regtests/Test/file_test2.c +++ b/regtests/Test/file_test2.c @@ -39,7 +39,7 @@ int main(int argc, char *argv[]) // adfSetEnvFct(0,0,MyVer,0); /* open and mount existing device : FFS */ - struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + struct AdfDevice * hd = adfDevOpen ( argv[1], ADF_ACCESS_MODE_READWRITE ); if ( ! hd ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", argv[1] ); @@ -47,17 +47,17 @@ int main(int argc, char *argv[]) exit(1); } - RETCODE rc = adfMountDev ( hd ); + RETCODE rc = adfDevMount ( hd ); if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); - adfCloseDev(hd); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -114,8 +114,8 @@ int main(int argc, char *argv[]) adfFileClose ( file ); adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); diff --git a/regtests/Test/file_test3.c b/regtests/Test/file_test3.c index f384bc8b..db09ba72 100644 --- a/regtests/Test/file_test3.c +++ b/regtests/Test/file_test3.c @@ -39,7 +39,7 @@ int main(int argc, char *argv[]) // adfSetEnvFct(0,0,MyVer,0); /* open and mount existing device : OFS */ - struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + struct AdfDevice * hd = adfDevOpen ( argv[1], ADF_ACCESS_MODE_READWRITE ); if ( ! hd ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", argv[1] ); @@ -47,17 +47,17 @@ int main(int argc, char *argv[]) exit(1); } - RETCODE rc = adfMountDev ( hd ); + RETCODE rc = adfDevMount ( hd ); if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); - adfCloseDev(hd); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -114,8 +114,8 @@ int main(int argc, char *argv[]) adfFileClose ( file ); adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); diff --git a/regtests/Test/fl_test.c b/regtests/Test/fl_test.c index 12e833ba..840529f7 100644 --- a/regtests/Test/fl_test.c +++ b/regtests/Test/fl_test.c @@ -32,7 +32,7 @@ int main(int argc, char *argv[]) // adfSetEnvFct(0,0,MyVer,0); /* open and mount existing device */ - struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + struct AdfDevice * hd = adfDevOpen ( argv[1], ADF_ACCESS_MODE_READWRITE ); if ( ! hd ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", argv[1] ); @@ -40,17 +40,17 @@ int main(int argc, char *argv[]) exit(1); } - RETCODE rc = adfMountDev ( hd ); + RETCODE rc = adfDevMount ( hd ); if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); - adfCloseDev(hd); + adfDevClose(hd); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -58,34 +58,34 @@ int main(int argc, char *argv[]) adfVolumeInfo(vol); adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); putchar('\n'); /* create and mount one device */ - hd = adfCreateDev ( "dump", "fl_test-newdev", 80, 2, 11 ); + hd = adfDevCreate ( "dump", "fl_test-newdev", 80, 2, 11 ); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); } - adfDeviceInfo(hd); + adfDevInfo(hd); adfCreateFlop( hd, "empty", FSMASK_FFS|FSMASK_DIRCACHE ); vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } boot=fopen(argv[2],"rb"); if (!boot) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -96,8 +96,8 @@ int main(int argc, char *argv[]) adfVolumeInfo(vol); adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); diff --git a/regtests/Test/fl_test2.c b/regtests/Test/fl_test2.c index c631499b..78327c0b 100644 --- a/regtests/Test/fl_test2.c +++ b/regtests/Test/fl_test2.c @@ -31,7 +31,7 @@ int main(int argc, char *argv[]) // adfSetEnvFct(0,0,MyVer,0); /* open and mount existing device */ - struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + struct AdfDevice * hd = adfDevOpen ( argv[1], ADF_ACCESS_MODE_READWRITE ); if ( ! hd ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", argv[1] ); @@ -39,17 +39,17 @@ int main(int argc, char *argv[]) exit(1); } - RETCODE rc = adfMountDev ( hd ); + RETCODE rc = adfDevMount ( hd ); if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); - adfCloseDev(hd); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -65,8 +65,8 @@ int main(int argc, char *argv[]) freeList(list); adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); diff --git a/regtests/Test/floppy_overfilling_test.c b/regtests/Test/floppy_overfilling_test.c index b4f1854d..23667584 100644 --- a/regtests/Test/floppy_overfilling_test.c +++ b/regtests/Test/floppy_overfilling_test.c @@ -101,7 +101,7 @@ int test_floppy_overfilling ( test_data_t * const tdata ) fstype_info [ tdata->fstype ], tdata->blocksize ); #endif - struct AdfDevice * device = adfCreateDev ( "dump", tdata->adfname, 80, 2, 11 ); + struct AdfDevice * device = adfDevCreate ( "dump", tdata->adfname, 80, 2, 11 ); if ( ! device ) return 1; adfCreateFlop ( device, "OverfillTest", tdata->fstype ); @@ -158,8 +158,8 @@ int test_floppy_overfilling ( test_data_t * const tdata ) bytes_written, tdata->max_errors ); adfUnMount ( vol ); - adfUnMountDev ( device ); - adfCloseDev ( device ); + adfDevUnMount ( device ); + adfDevClose ( device ); #if TEST_VERBOSITY > 0 printf (" -> %s\n", status ? "ERROR" : "OK" ); diff --git a/regtests/Test/hardfile.c b/regtests/Test/hardfile.c index 144e33f5..fd2b8687 100644 --- a/regtests/Test/hardfile.c +++ b/regtests/Test/hardfile.c @@ -30,7 +30,7 @@ int main(int argc, char *argv[]) adfEnvInitDefault(); - struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + struct AdfDevice * hd = adfDevOpen ( argv[1], ADF_ACCESS_MODE_READWRITE ); if ( ! hd ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", argv[1] ); @@ -38,20 +38,20 @@ int main(int argc, char *argv[]) exit(1); } - RETCODE rc = adfMountDev ( hd ); + RETCODE rc = adfDevMount ( hd ); if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); - adfCloseDev(hd); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } - adfDeviceInfo(hd); + adfDevInfo(hd); /* mount the 2 partitions */ vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -66,8 +66,8 @@ int main(int argc, char *argv[]) /* unmounts */ adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); diff --git a/regtests/Test/hd_test.c b/regtests/Test/hd_test.c index f3523d78..78d9f5a3 100644 --- a/regtests/Test/hd_test.c +++ b/regtests/Test/hd_test.c @@ -34,7 +34,7 @@ int main(int argc, char *argv[]) adfEnvInitDefault(); /*** a real harddisk ***/ - struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + struct AdfDevice * hd = adfDevOpen ( argv[1], ADF_ACCESS_MODE_READWRITE ); if ( ! hd ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", argv[1] ); @@ -42,19 +42,19 @@ int main(int argc, char *argv[]) exit(1); } - RETCODE rc = adfMountDev ( hd ); + RETCODE rc = adfDevMount ( hd ); if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); - adfCloseDev(hd); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } - adfDeviceInfo(hd); + adfDevInfo(hd); /* mount the 2 partitions */ vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume 0\n"); adfEnvCleanUp(); exit(1); } @@ -62,8 +62,8 @@ int main(int argc, char *argv[]) vol2 = adfMount(hd, 1, ADF_ACCESS_MODE_READWRITE ); if (!vol2) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume 1\n"); adfEnvCleanUp(); exit(1); } @@ -72,12 +72,11 @@ int main(int argc, char *argv[]) /* unmounts */ adfUnMount(vol); adfUnMount(vol2); - adfUnMountDev(hd); - adfCloseDev(hd); - + adfDevUnMount ( hd ); + adfDevClose ( hd ); /*** a dump of a zip disk ***/ - hd = adfOpenDev ( argv[2], ADF_ACCESS_MODE_READWRITE ); + hd = adfDevOpen ( argv[2], ADF_ACCESS_MODE_READWRITE ); if ( ! hd ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", argv[2] ); @@ -85,26 +84,26 @@ int main(int argc, char *argv[]) exit(1); } - rc = adfMountDev ( hd ); + rc = adfDevMount ( hd ); if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); - adfCloseDev(hd); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } - adfDeviceInfo(hd); + adfDevInfo(hd); vol = adfMount(hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } adfVolumeInfo(vol); adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); /* clean up */ adfEnvCleanUp(); diff --git a/regtests/Test/hd_test2.c b/regtests/Test/hd_test2.c index 08b146ce..b1202f39 100644 --- a/regtests/Test/hd_test2.c +++ b/regtests/Test/hd_test2.c @@ -32,13 +32,13 @@ int main(int argc, char *argv[]) const char tmpdevname[] = "hd_test2-newdev"; /* a zip disk */ - struct AdfDevice * hd = adfCreateDev ( "dump", tmpdevname, 2891, 1, 68 ); + struct AdfDevice * hd = adfDevCreate ( "dump", tmpdevname, 2891, 1, 68 ); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); } - adfDeviceInfo(hd); + adfDevInfo(hd); partList = (struct Partition**)malloc(sizeof(struct Partition*)); if (!partList) exit(1); @@ -53,28 +53,27 @@ int main(int argc, char *argv[]) free(partList); free(part1.volName); if ( rc != RC_OK ) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf ( stderr, "adfCreateHd returned error %d\n", rc ); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } adfVolumeInfo(vol); adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); - + adfDevUnMount ( hd ); + adfDevClose ( hd ); /* mount the created device */ - hd = adfOpenDev ( tmpdevname, ADF_ACCESS_MODE_READWRITE ); + hd = adfDevOpen ( tmpdevname, ADF_ACCESS_MODE_READWRITE ); if ( ! hd ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", tmpdevname ); @@ -82,19 +81,19 @@ int main(int argc, char *argv[]) exit(1); } - rc = adfMountDev ( hd ); + rc = adfDevMount ( hd ); if ( rc != RC_OK ) { - adfCloseDev(hd); + adfDevClose ( hd ); fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); } - adfDeviceInfo(hd); + adfDevInfo(hd); vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -102,8 +101,8 @@ int main(int argc, char *argv[]) adfVolumeInfo(vol); adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); diff --git a/regtests/Test/hd_test3.c b/regtests/Test/hd_test3.c index 4873aff4..f6e49eeb 100644 --- a/regtests/Test/hd_test3.c +++ b/regtests/Test/hd_test3.c @@ -34,13 +34,13 @@ int main(int argc, char *argv[]) /* an harddisk, "b"=7.5Mb, "h"=74.5mb */ - struct AdfDevice * hd = adfCreateDev ( "dump", tmpdevname, 980, 10, 17 ); + struct AdfDevice * hd = adfDevCreate ( "dump", tmpdevname, 980, 10, 17 ); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); } - adfDeviceInfo(hd); + adfDevInfo(hd); partList = (struct Partition**)malloc(sizeof(struct Partition*)*2); if (!partList) exit(1); @@ -63,24 +63,24 @@ int main(int argc, char *argv[]) free(part1.volName); free(part2.volName); if ( rc != RC_OK ) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf ( stderr, "adfCreateHd returned error %d\n", rc ); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } vol2 = adfMount ( hd, 1, ADF_ACCESS_MODE_READWRITE ); if (!vol2) { adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -90,12 +90,12 @@ int main(int argc, char *argv[]) adfUnMount(vol); adfUnMount(vol2); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); /* mount the created device */ - hd = adfOpenDev ( tmpdevname, ADF_ACCESS_MODE_READWRITE ); + hd = adfDevOpen ( tmpdevname, ADF_ACCESS_MODE_READWRITE ); if ( ! hd ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", tmpdevname ); @@ -103,17 +103,17 @@ int main(int argc, char *argv[]) exit(1); } - rc = adfMountDev ( hd ); + rc = adfDevMount ( hd ); if ( rc != RC_OK ) { - adfCloseDev(hd); + adfDevClose ( hd ); fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); } - adfDeviceInfo(hd); + adfDevInfo(hd); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); return 0; diff --git a/regtests/Test/progbar.c b/regtests/Test/progbar.c index b1eadac1..c9575547 100644 --- a/regtests/Test/progbar.c +++ b/regtests/Test/progbar.c @@ -35,25 +35,25 @@ int main(int argc, char *argv[]) /* create and mount one device */ puts("\ncreate dumpdevice"); - struct AdfDevice * const hd = adfCreateDev ( "dump", "progbar-newdev", 80, 2, 11 ); + struct AdfDevice * const hd = adfDevCreate ( "dump", "progbar-newdev", 80, 2, 11 ); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); } - adfDeviceInfo(hd); + adfDevInfo ( hd ); puts("\ncreate floppy"); if (adfCreateFlop( hd, "empty", FSMASK_FFS|FSMASK_DIRCACHE )!=RC_OK) { fprintf(stderr, "can't create floppy\n"); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -61,8 +61,8 @@ puts("\ncreate floppy"); adfVolumeInfo(vol); adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); diff --git a/regtests/Test/readonly.c b/regtests/Test/readonly.c index dac4858f..92a60616 100644 --- a/regtests/Test/readonly.c +++ b/regtests/Test/readonly.c @@ -34,7 +34,7 @@ int main(int argc, char *argv[]) adfEnvInitDefault(); /* open and mount existing device */ - struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + struct AdfDevice * hd = adfDevOpen ( argv[1], ADF_ACCESS_MODE_READWRITE ); if ( ! hd ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", argv[1] ); @@ -42,17 +42,17 @@ int main(int argc, char *argv[]) exit(1); } - RETCODE rc = adfMountDev ( hd ); + RETCODE rc = adfDevMount ( hd ); if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); - adfCloseDev(hd); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -122,8 +122,8 @@ int main(int argc, char *argv[]) adfVolumeInfo(vol); adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); diff --git a/regtests/Test/rename.c b/regtests/Test/rename.c index e5d07f3e..f1d15051 100644 --- a/regtests/Test/rename.c +++ b/regtests/Test/rename.c @@ -31,25 +31,25 @@ int main(int argc, char *argv[]) adfEnvInitDefault(); /* create and mount one device */ - struct AdfDevice * const hd = adfCreateDev ( "dump", "rename-newdev", 80, 2, 11 ); + struct AdfDevice * const hd = adfDevCreate ( "dump", "rename-newdev", 80, 2, 11 ); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); } - adfDeviceInfo(hd); + adfDevInfo(hd); if (adfCreateFlop( hd, "empty", FSMASK_FFS|FSMASK_DIRCACHE )!=RC_OK) { fprintf(stderr, "can't create floppy\n"); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -59,8 +59,8 @@ int main(int argc, char *argv[]) fic = adfFileOpen ( vol, "file_1a", ADF_FILE_MODE_WRITE ); if (!fic) { adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } @@ -70,8 +70,8 @@ int main(int argc, char *argv[]) fic = adfFileOpen ( vol, "file_24", ADF_FILE_MODE_WRITE ); if (!fic) { adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } @@ -81,8 +81,8 @@ int main(int argc, char *argv[]) fic = adfFileOpen ( vol, "dir_1a", ADF_FILE_MODE_WRITE ); if (!fic) { adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } @@ -92,8 +92,8 @@ int main(int argc, char *argv[]) fic = adfFileOpen ( vol, "dir_5u", ADF_FILE_MODE_WRITE ); if (!fic) { adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } @@ -167,8 +167,8 @@ int main(int argc, char *argv[]) adfFreeDirList(list); adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); diff --git a/regtests/Test/rename2.c b/regtests/Test/rename2.c index 33847d06..187c8702 100644 --- a/regtests/Test/rename2.c +++ b/regtests/Test/rename2.c @@ -29,7 +29,7 @@ int main(int argc, char *argv[]) adfEnvInitDefault(); /* create and mount one device */ - struct AdfDevice * const hd = adfCreateDev ( "dump", "rename2-newdev", 80, 2, 11 ); + struct AdfDevice * const hd = adfDevCreate ( "dump", "rename2-newdev", 80, 2, 11 ); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); @@ -37,20 +37,20 @@ int main(int argc, char *argv[]) if (adfCreateFlop( hd, "empty", FSMASK_FFS|FSMASK_DIRCACHE )!=RC_OK) { fprintf(stderr, "can't create floppy\n"); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } - adfDeviceInfo(hd); + adfDevInfo(hd); adfVolumeInfo(vol); @@ -122,8 +122,8 @@ printf("[dir = %ld]\n",883L); adfFreeDirList(list); adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); diff --git a/regtests/Test/undel.c b/regtests/Test/undel.c index e30af14b..33813a1f 100644 --- a/regtests/Test/undel.c +++ b/regtests/Test/undel.c @@ -34,25 +34,25 @@ int main(int argc, char *argv[]) adfChgEnvProp(PR_USEDIRC,&true); /* create and mount one device */ - struct AdfDevice * const hd = adfCreateDev ( "dump", "undel-newdev", 80, 2, 11 ); + struct AdfDevice * const hd = adfDevCreate ( "dump", "undel-newdev", 80, 2, 11 ); if (!hd) { fprintf(stderr, "can't mount device\n"); adfEnvCleanUp(); exit(1); } - adfDeviceInfo(hd); + adfDevInfo ( hd ); if (adfCreateFlop( hd, "empty", FSMASK_FFS|FSMASK_DIRCACHE )!=RC_OK) { fprintf(stderr, "can't create floppy\n"); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -60,8 +60,8 @@ int main(int argc, char *argv[]) fic = adfFileOpen ( vol, "file_1a", ADF_FILE_MODE_WRITE ); if (!fic) { adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } @@ -119,8 +119,8 @@ int main(int argc, char *argv[]) adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); diff --git a/regtests/Test/undel2.c b/regtests/Test/undel2.c index e137b4df..e00989e4 100644 --- a/regtests/Test/undel2.c +++ b/regtests/Test/undel2.c @@ -35,7 +35,7 @@ int main(int argc, char *argv[]) adfChgEnvProp(PR_USEDIRC,&true); - struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + struct AdfDevice * hd = adfDevOpen ( argv[1], ADF_ACCESS_MODE_READWRITE ); if ( ! hd ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", argv[1] ); @@ -43,19 +43,19 @@ int main(int argc, char *argv[]) exit(1); } - RETCODE rc = adfMountDev ( hd ); + RETCODE rc = adfDevMount ( hd ); if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); - adfCloseDev(hd); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } - adfDeviceInfo(hd); + adfDevInfo ( hd ); vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -115,8 +115,8 @@ int main(int argc, char *argv[]) adfFileClose ( file ); adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); diff --git a/regtests/Test/undel3.c b/regtests/Test/undel3.c index 40229b75..14bbeba6 100644 --- a/regtests/Test/undel3.c +++ b/regtests/Test/undel3.c @@ -35,7 +35,7 @@ int main(int argc, char *argv[]) adfChgEnvProp(PR_USEDIRC,&true); - struct AdfDevice * hd = adfOpenDev ( argv[1], ADF_ACCESS_MODE_READWRITE ); + struct AdfDevice * hd = adfDevOpen ( argv[1], ADF_ACCESS_MODE_READWRITE ); if ( ! hd ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", argv[1] ); @@ -43,19 +43,19 @@ int main(int argc, char *argv[]) exit(1); } - RETCODE rc = adfMountDev ( hd ); + RETCODE rc = adfDevMount ( hd ); if ( rc != RC_OK ) { fprintf(stderr, "can't mount device\n"); - adfCloseDev(hd); + adfDevClose ( hd ); adfEnvCleanUp(); exit(1); } - adfDeviceInfo(hd); + adfDevInfo ( hd ); vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -112,8 +112,8 @@ int main(int argc, char *argv[]) adfFileClose ( file ); adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); diff --git a/tests/test_file_append.c b/tests/test_file_append.c index 4626b2d2..b3e01814 100644 --- a/tests/test_file_append.c +++ b/tests/test_file_append.c @@ -246,7 +246,7 @@ int main ( void ) void setup ( test_data_t * const tdata ) { - tdata->device = adfCreateDev ( "dump", tdata->adfname, 80, 2, 11 ); + tdata->device = adfDevCreate ( "dump", tdata->adfname, 80, 2, 11 ); if ( ! tdata->device ) { //return; exit(1); @@ -267,7 +267,7 @@ void setup ( test_data_t * const tdata ) void teardown ( test_data_t * const tdata ) { //adfUnMount ( tdata->vol ); - adfUnMountDev ( tdata->device ); - adfCloseDev ( tdata->device ); + adfDevUnMount ( tdata->device ); + adfDevClose ( tdata->device ); unlink ( tdata->adfname ); } diff --git a/tests/test_file_create.c b/tests/test_file_create.c index a933c927..85be8441 100644 --- a/tests/test_file_create.c +++ b/tests/test_file_create.c @@ -250,7 +250,7 @@ int main ( void ) void setup ( test_data_t * const tdata ) { - tdata->device = adfCreateDev ( "dump", tdata->adfname, 80, 2, 11 ); + tdata->device = adfDevCreate ( "dump", tdata->adfname, 80, 2, 11 ); if ( ! tdata->device ) { //return; exit(1); @@ -271,7 +271,7 @@ void setup ( test_data_t * const tdata ) void teardown ( test_data_t * const tdata ) { //adfUnMount ( tdata->vol ); - adfUnMountDev ( tdata->device ); - adfCloseDev ( tdata->device ); + adfDevUnMount ( tdata->device ); + adfDevClose ( tdata->device ); unlink ( tdata->adfname ); } diff --git a/tests/test_file_overwrite.c b/tests/test_file_overwrite.c index 84aabaea..2b2d2b03 100644 --- a/tests/test_file_overwrite.c +++ b/tests/test_file_overwrite.c @@ -302,7 +302,7 @@ int main ( void ) void setup ( test_data_t * const tdata ) { - tdata->device = adfCreateDev ( "ramdisk", "test_ramdisk", 80, 2, 11 ); + tdata->device = adfDevCreate ( "ramdisk", "test_ramdisk", 80, 2, 11 ); if ( tdata->device == NULL ) { fprintf ( stderr, "Error creating device\n"); //return; @@ -324,6 +324,6 @@ void setup ( test_data_t * const tdata ) void teardown ( test_data_t * const tdata ) { //adfUnMount ( tdata->vol ); - adfUnMountDev ( tdata->device ); - adfCloseDev ( tdata->device ); + adfDevUnMount ( tdata->device ); + adfDevClose ( tdata->device ); } diff --git a/tests/test_file_overwrite2.c b/tests/test_file_overwrite2.c index d357f4b1..b4b9fe4c 100644 --- a/tests/test_file_overwrite2.c +++ b/tests/test_file_overwrite2.c @@ -380,7 +380,7 @@ int main ( void ) void setup ( test_data_t * const tdata ) { - tdata->device = adfCreateDev ( "dump", tdata->adfname, 80, 2, 11 ); + tdata->device = adfDevCreate ( "dump", tdata->adfname, 80, 2, 11 ); if ( ! tdata->device ) { //return; exit(1); @@ -411,8 +411,8 @@ void teardown ( test_data_t * const tdata ) tdata->buffer = NULL; //adfUnMount ( tdata->vol ); - adfUnMountDev ( tdata->device ); - adfCloseDev ( tdata->device ); + adfDevUnMount ( tdata->device ); + adfDevClose ( tdata->device ); //printf ("unlinkuing the file %s\n", tdata->adfname ); //fflush(stdout); diff --git a/tests/test_file_seek.c b/tests/test_file_seek.c index 3e987655..172ab8b9 100644 --- a/tests/test_file_seek.c +++ b/tests/test_file_seek.c @@ -244,7 +244,7 @@ int main ( void ) void setup ( test_data_t * const tdata ) { - tdata->device = adfCreateDev ( "dump", tdata->adfname, 80, 2, 11 ); + tdata->device = adfDevCreate ( "dump", tdata->adfname, 80, 2, 11 ); if ( tdata->device == NULL ) { //return; exit(1); @@ -273,8 +273,8 @@ void teardown ( test_data_t * const tdata ) tdata->buffer = NULL; //adfUnMount ( tdata->vol ); - adfUnMountDev ( tdata->device ); - adfCloseDev ( tdata->device ); + adfDevUnMount ( tdata->device ); + adfDevClose ( tdata->device ); if ( unlink ( tdata->adfname ) != 0 ) perror("error deleting the image"); } diff --git a/tests/test_file_seek_after_write.c b/tests/test_file_seek_after_write.c index 8ef0a816..c308aaf1 100644 --- a/tests/test_file_seek_after_write.c +++ b/tests/test_file_seek_after_write.c @@ -313,7 +313,7 @@ int main ( void ) void setup ( test_data_t * const tdata ) { - tdata->device = adfCreateDev ( "ramdisk", tdata->adfname, 80, 2, 11 ); + tdata->device = adfDevCreate ( "ramdisk", tdata->adfname, 80, 2, 11 ); if ( tdata->device == NULL ) { //return; exit(1); @@ -342,8 +342,8 @@ void teardown ( test_data_t * const tdata ) tdata->buffer = NULL; //adfUnMount ( tdata->vol ); - adfUnMountDev ( tdata->device ); - adfCloseDev ( tdata->device ); + adfDevUnMount ( tdata->device ); + adfDevClose ( tdata->device ); //if ( unlink ( tdata->adfname ) != 0 ) // perror("error deleting the image"); } diff --git a/tests/test_file_truncate.c b/tests/test_file_truncate.c index cfd9ddd6..73a896f8 100644 --- a/tests/test_file_truncate.c +++ b/tests/test_file_truncate.c @@ -452,7 +452,7 @@ int main ( void ) void setup ( test_data_t * const tdata ) { - tdata->device = adfCreateDev ( "ramdisk", tdata->adfname, 80, 2, 11 ); + tdata->device = adfDevCreate ( "ramdisk", tdata->adfname, 80, 2, 11 ); if ( ! tdata->device ) { //return; exit(1); @@ -481,8 +481,8 @@ void teardown ( test_data_t * const tdata ) tdata->buffer = NULL; //adfUnMount ( tdata->vol ); - adfUnMountDev ( tdata->device ); - adfCloseDev ( tdata->device ); + adfDevUnMount ( tdata->device ); + adfDevClose ( tdata->device ); //if ( unlink ( tdata->adfname ) != 0 ) // perror("error deleting the image"); } diff --git a/tests/test_file_truncate2.c b/tests/test_file_truncate2.c index 15bb435b..ceb88165 100644 --- a/tests/test_file_truncate2.c +++ b/tests/test_file_truncate2.c @@ -329,7 +329,7 @@ int main ( void ) void setup ( test_data_t * const tdata ) { - tdata->device = adfCreateDev ( "ramdisk", tdata->adfname, 80, 2, 11 ); + tdata->device = adfDevCreate ( "ramdisk", tdata->adfname, 80, 2, 11 ); if ( ! tdata->device ) { //return; exit(1); @@ -358,8 +358,8 @@ void teardown ( test_data_t * const tdata ) tdata->buffer = NULL; //adfUnMount ( tdata->vol ); - adfUnMountDev ( tdata->device ); - adfCloseDev ( tdata->device ); + adfDevUnMount ( tdata->device ); + adfDevClose ( tdata->device ); //if ( unlink ( tdata->adfname ) != 0 ) // perror("error deleting the image"); } diff --git a/tests/test_file_write.c b/tests/test_file_write.c index e6caa0cf..ff1b186d 100644 --- a/tests/test_file_write.c +++ b/tests/test_file_write.c @@ -309,7 +309,7 @@ int main ( void ) void setup ( test_data_t * const tdata ) { - tdata->device = adfCreateDev ( "dump", tdata->adfname, 80, 2, 11 ); + tdata->device = adfDevCreate ( "dump", tdata->adfname, 80, 2, 11 ); if ( ! tdata->device ) { //return; exit(1); @@ -338,7 +338,7 @@ void teardown ( test_data_t * const tdata ) tdata->buffer = NULL; //adfUnMount ( tdata->vol ); - adfUnMountDev ( tdata->device ); - adfCloseDev ( tdata->device ); + adfDevUnMount ( tdata->device ); + adfDevClose ( tdata->device ); unlink ( tdata->adfname ); } diff --git a/tests/test_file_write_chunks.c b/tests/test_file_write_chunks.c index 1ae8483f..dbfa960a 100644 --- a/tests/test_file_write_chunks.c +++ b/tests/test_file_write_chunks.c @@ -366,7 +366,7 @@ int main ( void ) void setup ( test_data_t * const tdata ) { - tdata->device = adfCreateDev ( "ramdisk", tdata->adfname, 80, 2, 11 ); + tdata->device = adfDevCreate ( "ramdisk", tdata->adfname, 80, 2, 11 ); if ( ! tdata->device ) { //return; exit(1); @@ -395,7 +395,7 @@ void teardown ( test_data_t * const tdata ) tdata->buffer = NULL; //adfUnMount ( tdata->vol ); - adfUnMountDev ( tdata->device ); - adfCloseDev ( tdata->device ); + adfDevUnMount ( tdata->device ); + adfDevClose ( tdata->device ); //unlink ( tdata->adfname ); } From fa701c464da9674d7aa29518e9d3b3e818e0d8f2 Mon Sep 17 00:00:00 2001 From: t-m Date: Sat, 10 Feb 2024 21:59:12 +0100 Subject: [PATCH 23/40] Cmake cross mingw configure script: disable tests. Cannot run them where built... Also, it detects Linux version of Check framework, so tests/ do not even compile. (Anyway - this script is just an example ). --- util/cmake_shared_configure_cross_mingw | 1 + 1 file changed, 1 insertion(+) diff --git a/util/cmake_shared_configure_cross_mingw b/util/cmake_shared_configure_cross_mingw index a2dda7e7..ed4c63a6 100755 --- a/util/cmake_shared_configure_cross_mingw +++ b/util/cmake_shared_configure_cross_mingw @@ -5,4 +5,5 @@ CC=i686-w64-mingw32-gcc-12 util/cmake_shared_configure \ -DADFLIB_ENABLE_NATIVE_DEV:BOOL=ON \ + -DADFLIB_ENABLE_TESTS:BOOL=OFF \ $@ From 4c0aa2629932a5c88b3735f4d7ff06b52b5cad14 Mon Sep 17 00:00:00 2001 From: t-m Date: Sat, 10 Feb 2024 22:04:17 +0100 Subject: [PATCH 24/40] Cmake: make MinGW be detected when cross-compiling. --- src/CMakeLists.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 257c8e7e..ffa4079a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,11 +5,10 @@ if ( ADFLIB_BUILD_DLL ) add_compile_definitions ( _EXPORTING ) endif ( ADFLIB_BUILD_DLL ) - if ( ADFLIB_ENABLE_NATIVE_DEV ) # Useful info (note that CYGWIN went from WIN32 to UNIX...): # https://gitlab.kitware.com/cmake/community/-/wikis/doc/tutorials/How-To-Write-Platform-Checks - if ( WIN32 OR CYGWIN OR MINGW OR MSYS ) + if ( WIN32 OR CYGWIN OR MINGW OR MSYS OR CMAKE_C_PLATFORM_ID STREQUAL "MinGW") set ( ADFLIB_NATIVE_DEV_DIR win32 ) set ( ADFLIB_NATIVE_DEV_SRC win32/adf_nativ.c @@ -128,3 +127,12 @@ install ( TARGETS adf # DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/adf" DESTINATION FALSE ) + + +# Cmake debugging - list all defined variables +# (from: https://stackoverflow.com/questions/9298278/cmake-print-out-all-accessible-variables-in-a-script ) +#get_cmake_property(_variableNames VARIABLES) +#list (SORT _variableNames) +#foreach (_variableName ${_variableNames}) +# message(STATUS "${_variableName}=${${_variableName}}") +#endforeach() From 55830a815134a9a93c4d8f1510701e01177136fc Mon Sep 17 00:00:00 2001 From: t-m Date: Sat, 10 Feb 2024 22:17:50 +0100 Subject: [PATCH 25/40] Rename adf_dev_dump to adf_dev_driver_dump, lclevy#73 --- src/CMakeLists.txt | 6 +++--- src/Makefile.am | 4 ++-- src/{adf_dev_dump.c => adf_dev_driver_dump.c} | 4 ++-- src/{adf_dev_dump.h => adf_dev_driver_dump.h} | 0 src/adf_dev_hd.c | 2 +- src/adf_env.c | 2 +- src/adflib.h | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) rename src/{adf_dev_dump.c => adf_dev_driver_dump.c} (99%) rename src/{adf_dev_dump.h => adf_dev_driver_dump.h} (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ffa4079a..6e0f5180 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,10 +51,10 @@ add_library ( adf adf_cache.h adf_dev.c adf_dev_driver.h + adf_dev_driver_dump.c + adf_dev_driver_dump.h adf_dev_drivers.c adf_dev_drivers.h - adf_dev_dump.c - adf_dev_dump.h adf_dev_flop.c adf_dev_flop.h adf_dev.h @@ -96,7 +96,7 @@ add_library ( adf set_target_properties ( adf PROPERTIES #PUBLIC_HEADER "adflib.h" - PUBLIC_HEADER "adf_bitm.h;adf_blk.h;adf_cache.h;adf_dev_dump.h;adf_dev_flop.h;adf_dev.h;adf_dev_hd.h;adf_dev_ramdisk.h;adf_dir.h;adf_env.h;adf_err.h;adf_file_block.h;adf_file.h;adf_file_util.h;adflib.h;adf_link.h;adf_nativ.h;adf_raw.h;adf_salv.h;adf_str.h;adf_types.h;adf_util.h;adf_version.h;adf_vol.h;debug_util.h;defendian.h;hd_blk.h;prefix.h" + PUBLIC_HEADER "adf_bitm.h;adf_blk.h;adf_cache.h;adf_dev_driver_dump.h;adf_dev_flop.h;adf_dev.h;adf_dev_hd.h;adf_dev_ramdisk.h;adf_dir.h;adf_env.h;adf_err.h;adf_file_block.h;adf_file.h;adf_file_util.h;adflib.h;adf_link.h;adf_nativ.h;adf_raw.h;adf_salv.h;adf_str.h;adf_types.h;adf_util.h;adf_version.h;adf_vol.h;debug_util.h;defendian.h;hd_blk.h;prefix.h" #PRIVATE_HEADER ... VERSION ${CMAKE_PROJECT_VERSION} # SOVERSION ${PROJECT_VERSION_MAJOR} diff --git a/src/Makefile.am b/src/Makefile.am index b926a928..7d5cc18f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,8 +15,8 @@ libadf_la_SOURCES = \ adf_bitm.c \ adf_cache.c \ adf_dev.c \ + adf_dev_driver_dump.c \ adf_dev_drivers.c \ - adf_dev_dump.c \ adf_dev_flop.c \ adf_dev_hd.c \ adf_dev_ramdisk.c \ @@ -39,8 +39,8 @@ adfinc_HEADERS = \ adf_blk.h \ adf_cache.h \ adf_dev_driver.h \ + adf_dev_driver_dump.h \ adf_dev_drivers.h \ - adf_dev_dump.h \ adf_dev_flop.h \ adf_dev.h \ adf_dev_hd.h \ diff --git a/src/adf_dev_dump.c b/src/adf_dev_driver_dump.c similarity index 99% rename from src/adf_dev_dump.c rename to src/adf_dev_driver_dump.c index 3eb9a5b8..4708002a 100644 --- a/src/adf_dev_dump.c +++ b/src/adf_dev_driver_dump.c @@ -1,7 +1,7 @@ /* * ADF Library * - * adf_dump.c + * adf_dev_driver_dump.c * * $Id$ * @@ -25,7 +25,7 @@ * */ -#include "adf_dev_dump.h" +#include "adf_dev_driver_dump.h" #include "adf_blk.h" #include "adf_env.h" diff --git a/src/adf_dev_dump.h b/src/adf_dev_driver_dump.h similarity index 100% rename from src/adf_dev_dump.h rename to src/adf_dev_driver_dump.h diff --git a/src/adf_dev_hd.c b/src/adf_dev_hd.c index 85f808df..8eb93f4a 100644 --- a/src/adf_dev_hd.c +++ b/src/adf_dev_hd.c @@ -28,7 +28,7 @@ #include "adf_dev_hd.h" -#include "adf_dev_dump.h" +#include "adf_dev_driver_dump.h" #include "adf_env.h" #include "adf_raw.h" #include "adf_util.h" diff --git a/src/adf_env.c b/src/adf_env.c index a88b6ada..2489d6d9 100644 --- a/src/adf_env.c +++ b/src/adf_env.c @@ -29,7 +29,7 @@ #include "adf_blk.h" #include "adf_dev_drivers.h" -#include "adf_dev_dump.h" +#include "adf_dev_driver_dump.h" #include "adf_dev_ramdisk.h" #include "adf_version.h" #include "defendian.h" diff --git a/src/adflib.h b/src/adflib.h index c9486c87..b2364cd8 100644 --- a/src/adflib.h +++ b/src/adflib.h @@ -57,7 +57,7 @@ extern "C" { #include "adf_dev_hd.h" /* dump device */ -#include "adf_dev_dump.h" +#include "adf_dev_driver_dump.h" /* env */ #include "adf_env.h" From d7e1f80e292e42de0830ed7fad430e8cf5d80e50 Mon Sep 17 00:00:00 2001 From: t-m Date: Sat, 10 Feb 2024 22:26:32 +0100 Subject: [PATCH 26/40] Rename adf_dev_ramdisk to adf_dev_driver_ramdisk, lclevy#73 --- src/CMakeLists.txt | 6 +++--- src/Makefile.am | 4 ++-- src/{adf_dev_ramdisk.c => adf_dev_driver_ramdisk.c} | 4 ++-- src/{adf_dev_ramdisk.h => adf_dev_driver_ramdisk.h} | 0 src/adf_env.c | 2 +- src/adflib.h | 3 ++- 6 files changed, 10 insertions(+), 9 deletions(-) rename src/{adf_dev_ramdisk.c => adf_dev_driver_ramdisk.c} (98%) rename src/{adf_dev_ramdisk.h => adf_dev_driver_ramdisk.h} (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6e0f5180..6bd90e41 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -53,6 +53,8 @@ add_library ( adf adf_dev_driver.h adf_dev_driver_dump.c adf_dev_driver_dump.h + adf_dev_driver_ramdisk.c + adf_dev_driver_ramdisk.h adf_dev_drivers.c adf_dev_drivers.h adf_dev_flop.c @@ -60,8 +62,6 @@ add_library ( adf adf_dev.h adf_dev_hd.c adf_dev_hd.h - adf_dev_ramdisk.c - adf_dev_ramdisk.h adf_dir.c adf_dir.h adf_env.c @@ -96,7 +96,7 @@ add_library ( adf set_target_properties ( adf PROPERTIES #PUBLIC_HEADER "adflib.h" - PUBLIC_HEADER "adf_bitm.h;adf_blk.h;adf_cache.h;adf_dev_driver_dump.h;adf_dev_flop.h;adf_dev.h;adf_dev_hd.h;adf_dev_ramdisk.h;adf_dir.h;adf_env.h;adf_err.h;adf_file_block.h;adf_file.h;adf_file_util.h;adflib.h;adf_link.h;adf_nativ.h;adf_raw.h;adf_salv.h;adf_str.h;adf_types.h;adf_util.h;adf_version.h;adf_vol.h;debug_util.h;defendian.h;hd_blk.h;prefix.h" + PUBLIC_HEADER "adf_bitm.h;adf_blk.h;adf_cache.h;adf_dev_driver_dump.h;adf_dev_driver_ramdisk.h;adf_dev_flop.h;adf_dev.h;adf_dev_hd.h;adf_dir.h;adf_env.h;adf_err.h;adf_file_block.h;adf_file.h;adf_file_util.h;adflib.h;adf_link.h;adf_nativ.h;adf_raw.h;adf_salv.h;adf_str.h;adf_types.h;adf_util.h;adf_version.h;adf_vol.h;debug_util.h;defendian.h;hd_blk.h;prefix.h" #PRIVATE_HEADER ... VERSION ${CMAKE_PROJECT_VERSION} # SOVERSION ${PROJECT_VERSION_MAJOR} diff --git a/src/Makefile.am b/src/Makefile.am index 7d5cc18f..b4f3ce36 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,10 +16,10 @@ libadf_la_SOURCES = \ adf_cache.c \ adf_dev.c \ adf_dev_driver_dump.c \ + adf_dev_driver_ramdisk.c \ adf_dev_drivers.c \ adf_dev_flop.c \ adf_dev_hd.c \ - adf_dev_ramdisk.c \ adf_dir.c \ adf_env.c \ adf_file_block.c \ @@ -40,11 +40,11 @@ adfinc_HEADERS = \ adf_cache.h \ adf_dev_driver.h \ adf_dev_driver_dump.h \ + adf_dev_driver_ramdisk.h \ adf_dev_drivers.h \ adf_dev_flop.h \ adf_dev.h \ adf_dev_hd.h \ - adf_dev_ramdisk.h \ adf_dir.h \ adf_env.h \ adf_err.h \ diff --git a/src/adf_dev_ramdisk.c b/src/adf_dev_driver_ramdisk.c similarity index 98% rename from src/adf_dev_ramdisk.c rename to src/adf_dev_driver_ramdisk.c index 1db30ec1..05ab4612 100644 --- a/src/adf_dev_ramdisk.c +++ b/src/adf_dev_driver_ramdisk.c @@ -1,5 +1,5 @@ /* - * ramdisk.c + * adf_dev_driver_ramdisk.c * * $Id$ * @@ -24,7 +24,7 @@ #include #include -#include "adf_dev_ramdisk.h" +#include "adf_dev_driver_ramdisk.h" #include "adf_env.h" static struct AdfDevice * ramdiskCreate ( const char * const name, diff --git a/src/adf_dev_ramdisk.h b/src/adf_dev_driver_ramdisk.h similarity index 100% rename from src/adf_dev_ramdisk.h rename to src/adf_dev_driver_ramdisk.h diff --git a/src/adf_env.c b/src/adf_env.c index 2489d6d9..0ab45b9a 100644 --- a/src/adf_env.c +++ b/src/adf_env.c @@ -30,7 +30,7 @@ #include "adf_blk.h" #include "adf_dev_drivers.h" #include "adf_dev_driver_dump.h" -#include "adf_dev_ramdisk.h" +#include "adf_dev_driver_ramdisk.h" #include "adf_version.h" #include "defendian.h" diff --git a/src/adflib.h b/src/adflib.h index b2364cd8..97b45358 100644 --- a/src/adflib.h +++ b/src/adflib.h @@ -56,8 +56,9 @@ extern "C" { #include "adf_dev_flop.h" #include "adf_dev_hd.h" -/* dump device */ +/* device drivers */ #include "adf_dev_driver_dump.h" +#include "adf_dev_driver_ramdisk.h" /* env */ #include "adf_env.h" From 3e814607ed1056ff956a1fc950fc604a113ca30c Mon Sep 17 00:00:00 2001 From: t-m Date: Sat, 10 Feb 2024 22:35:57 +0100 Subject: [PATCH 27/40] adf vol: correct included header. --- src/adf_vol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adf_vol.c b/src/adf_vol.c index 9915f99d..fa8637b6 100644 --- a/src/adf_vol.c +++ b/src/adf_vol.c @@ -30,8 +30,8 @@ #include "adf_bitm.h" #include "adf_cache.h" +#include "adf_dev.h" #include "adf_env.h" -#include "adf_nativ.h" #include "adf_raw.h" #include "adf_util.h" From 577682c7bbc1502690ffba8567b1d630c059acad Mon Sep 17 00:00:00 2001 From: t-m Date: Sat, 10 Feb 2024 22:38:33 +0100 Subject: [PATCH 28/40] test file overwrite: remove renamed header (already in adflib.h). --- tests/test_file_overwrite.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_file_overwrite.c b/tests/test_file_overwrite.c index 2b2d2b03..2722d06d 100644 --- a/tests/test_file_overwrite.c +++ b/tests/test_file_overwrite.c @@ -6,7 +6,6 @@ #endif #include "adflib.h" -#include "adf_dev_ramdisk.h" //#include "adf_util.h" From 51bf4b58a877f0be8ccf52b27c89ed2279e6f955 Mon Sep 17 00:00:00 2001 From: t-m Date: Sat, 10 Feb 2024 22:46:14 +0100 Subject: [PATCH 29/40] Rename adf_nativ to adf_dev_driver_nativ, lclevy#73 --- src/CMakeLists.txt | 12 ++++++------ src/Makefile.am | 8 ++++---- src/{adf_nativ.h => adf_dev_driver_nativ.h} | 0 src/generic/{adf_nativ.c => adf_dev_driver_nativ.c} | 4 ++-- src/linux/{adf_nativ.c => adf_dev_driver_nativ.c} | 4 ++-- src/win32/{adf_nativ.c => adf_dev_driver_nativ.c} | 5 ++--- 6 files changed, 16 insertions(+), 17 deletions(-) rename src/{adf_nativ.h => adf_dev_driver_nativ.h} (100%) rename src/generic/{adf_nativ.c => adf_dev_driver_nativ.c} (97%) rename src/linux/{adf_nativ.c => adf_dev_driver_nativ.c} (98%) rename src/win32/{adf_nativ.c => adf_dev_driver_nativ.c} (97%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6bd90e41..85871bd0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -11,21 +11,21 @@ if ( ADFLIB_ENABLE_NATIVE_DEV ) if ( WIN32 OR CYGWIN OR MINGW OR MSYS OR CMAKE_C_PLATFORM_ID STREQUAL "MinGW") set ( ADFLIB_NATIVE_DEV_DIR win32 ) set ( ADFLIB_NATIVE_DEV_SRC - win32/adf_nativ.c + win32/adf_dev_driver_nativ.c win32/nt4_dev.c win32/nt4_dev.h ) else() if ( UNIX AND CMAKE_SYSTEM_NAME STREQUAL "Linux" ) set ( ADFLIB_NATIVE_DEV_DIR linux ) - set ( ADFLIB_NATIVE_DEV_SRC linux/adf_nativ.c ) + set ( ADFLIB_NATIVE_DEV_SRC linux/adf_dev_driver_nativ.c ) else() set ( ADFLIB_NATIVE_DEV_DIR generic ) - set ( ADFLIB_NATIVE_DEV_SRC generic/adf_nativ.c ) + set ( ADFLIB_NATIVE_DEV_SRC generic/adf_dev_driver_nativ.c ) endif() endif() else() set ( ADFLIB_NATIVE_DEV_DIR generic ) - set ( ADFLIB_NATIVE_DEV_SRC generic/adf_nativ.c ) + set ( ADFLIB_NATIVE_DEV_SRC generic/adf_dev_driver_nativ.c ) endif() message ( STATUS "Native device directory: ${ADFLIB_NATIVE_DEV_DIR}" ) message ( STATUS "Native device sources: ${ADFLIB_NATIVE_DEV_SRC}" ) @@ -89,14 +89,14 @@ add_library ( adf defendian.h hd_blk.h prefix.h - adf_nativ.h + adf_dev_driver_nativ.h ${ADFLIB_NATIVE_DEV_SRC} ${ADFLIB_DEBUG_MODULES} ) set_target_properties ( adf PROPERTIES #PUBLIC_HEADER "adflib.h" - PUBLIC_HEADER "adf_bitm.h;adf_blk.h;adf_cache.h;adf_dev_driver_dump.h;adf_dev_driver_ramdisk.h;adf_dev_flop.h;adf_dev.h;adf_dev_hd.h;adf_dir.h;adf_env.h;adf_err.h;adf_file_block.h;adf_file.h;adf_file_util.h;adflib.h;adf_link.h;adf_nativ.h;adf_raw.h;adf_salv.h;adf_str.h;adf_types.h;adf_util.h;adf_version.h;adf_vol.h;debug_util.h;defendian.h;hd_blk.h;prefix.h" + PUBLIC_HEADER "adf_bitm.h;adf_blk.h;adf_cache.h;adf_dev_driver_dump.h;adf_dev_driver_nativ.h;adf_dev_driver_ramdisk.h;adf_dev_flop.h;adf_dev.h;adf_dev_hd.h;adf_dir.h;adf_env.h;adf_err.h;adf_file_block.h;adf_file.h;adf_file_util.h;adflib.h;adf_link.h;adf_raw.h;adf_salv.h;adf_str.h;adf_types.h;adf_util.h;adf_version.h;adf_vol.h;debug_util.h;defendian.h;hd_blk.h;prefix.h" #PRIVATE_HEADER ... VERSION ${CMAKE_PROJECT_VERSION} # SOVERSION ${PROJECT_VERSION_MAJOR} diff --git a/src/Makefile.am b/src/Makefile.am index b4f3ce36..52a3cd91 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -40,6 +40,7 @@ adfinc_HEADERS = \ adf_cache.h \ adf_dev_driver.h \ adf_dev_driver_dump.h \ + adf_dev_driver_nativ.h \ adf_dev_driver_ramdisk.h \ adf_dev_drivers.h \ adf_dev_flop.h \ @@ -52,7 +53,6 @@ adfinc_HEADERS = \ adf_file.h \ adf_file_util.h \ adf_link.h \ - adf_nativ.h \ adf_raw.h \ adf_salv.h \ adf_str.h \ @@ -68,12 +68,12 @@ adfinc_HEADERS = \ libadf_la_LDFLAGS = -version-info $(ADFLIB_LT_VERSION) if NATIVE_GENERIC -libadf_la_SOURCES += generic/adf_nativ.c +libadf_la_SOURCES += generic/adf_dev_driver_nativ.c endif if NATIVE_LINUX -libadf_la_SOURCES += linux/adf_nativ.c +libadf_la_SOURCES += linux/adf_dev_driver_nativ.c endif if NATIVE_WIN32 -libadf_la_SOURCES += win32/adf_nativ.c win32/nt4_dev.c win32/nt4_dev.h +libadf_la_SOURCES += win32/adf_dev_driver_nativ.c win32/nt4_dev.c win32/nt4_dev.h AM_CFLAGS += -I$(srcdir)/win32 endif diff --git a/src/adf_nativ.h b/src/adf_dev_driver_nativ.h similarity index 100% rename from src/adf_nativ.h rename to src/adf_dev_driver_nativ.h diff --git a/src/generic/adf_nativ.c b/src/generic/adf_dev_driver_nativ.c similarity index 97% rename from src/generic/adf_nativ.c rename to src/generic/adf_dev_driver_nativ.c index a2ea0d13..aec7c942 100644 --- a/src/generic/adf_nativ.c +++ b/src/generic/adf_dev_driver_nativ.c @@ -1,5 +1,5 @@ /* - * adf_nativ.c + * generic/adf_dev_driver_nativ.c * * $Id$ * @@ -24,7 +24,7 @@ #include #include -#include"adf_nativ.h" +#include "adf_dev_driver_nativ.h" #include"adf_err.h" #include "adf_env.h" diff --git a/src/linux/adf_nativ.c b/src/linux/adf_dev_driver_nativ.c similarity index 98% rename from src/linux/adf_nativ.c rename to src/linux/adf_dev_driver_nativ.c index a458e3dc..0d9da3ff 100644 --- a/src/linux/adf_nativ.c +++ b/src/linux/adf_dev_driver_nativ.c @@ -1,5 +1,5 @@ /* - * adf_nativ.c + * linux/adf_dev_driver_nativ.c * * $Id$ * @@ -33,7 +33,7 @@ #include #include "adf_err.h" -#include "adf_nativ.h" +#include "adf_dev_driver_nativ.h" #include "adf_env.h" diff --git a/src/win32/adf_nativ.c b/src/win32/adf_dev_driver_nativ.c similarity index 97% rename from src/win32/adf_nativ.c rename to src/win32/adf_dev_driver_nativ.c index 048fafd0..1a9c6a8b 100644 --- a/src/win32/adf_nativ.c +++ b/src/win32/adf_dev_driver_nativ.c @@ -1,4 +1,4 @@ -/* Win32/adf_nativ.c - Win32 specific drive-access routines for ADFLib +/* Win32/adf_dev_driver_nativ.c - Win32 specific drive-access routines for ADFLib * * Modified for Win32 by Dan Sutherland * @@ -32,8 +32,7 @@ #include "adf_str.h" #include "adf_err.h" - -#include "adf_nativ.h" +#include "adf_dev_driver_nativ.h" #include "adf_env.h" #include "nt4_dev.h" From 9e264a64cda263b670f8b4506b8c5a362ebc2fd0 Mon Sep 17 00:00:00 2001 From: t-m Date: Sat, 10 Feb 2024 22:57:51 +0100 Subject: [PATCH 30/40] regtests / Cmake: compile hardfile2.c. The test script for hardfile2 seems missing, though... --- regtests/Test/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/regtests/Test/CMakeLists.txt b/regtests/Test/CMakeLists.txt index 1b3fddc8..1fa5debd 100644 --- a/regtests/Test/CMakeLists.txt +++ b/regtests/Test/CMakeLists.txt @@ -71,6 +71,9 @@ TARGET_LINK_LIBRARIES ( rename adf ) add_executable ( hardfile hardfile.c ) TARGET_LINK_LIBRARIES ( hardfile adf ) +add_executable ( hardfile2 hardfile2.c ) +TARGET_LINK_LIBRARIES ( hardfile2 adf ) + add_executable ( rename2 rename2.c ) TARGET_LINK_LIBRARIES ( rename2 adf ) From 1abcd057c149e47f7481c474eb8459577ed084c7 Mon Sep 17 00:00:00 2001 From: t-m Date: Sat, 10 Feb 2024 23:00:10 +0100 Subject: [PATCH 31/40] regtests / hardfile2: use renamed adf dev functions. --- regtests/Test/hardfile2.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/regtests/Test/hardfile2.c b/regtests/Test/hardfile2.c index 1c87a340..b29c1f2b 100644 --- a/regtests/Test/hardfile2.c +++ b/regtests/Test/hardfile2.c @@ -28,7 +28,7 @@ int main(int argc, char *argv[]) adfEnvInitDefault(); /* create and mount one device : 4194304 bytes */ - struct AdfDevice * const hd = adfCreateDev ( "dump", "hardfile2-newdev", + struct AdfDevice * const hd = adfDevCreate ( "dump", "hardfile2-newdev", 256, 2, 32 ); if (!hd) { fprintf(stderr, "can't mount device\n"); @@ -37,12 +37,12 @@ int main(int argc, char *argv[]) adfCreateHdFile( hd, "empty", FSMASK_FFS|FSMASK_DIRCACHE ); - adfDeviceInfo(hd); + adfDevInfo ( hd ); vol = adfMount ( hd, 0, ADF_ACCESS_MODE_READWRITE ); if (!vol) { - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); fprintf(stderr, "can't mount volume\n"); adfEnvCleanUp(); exit(1); } @@ -57,8 +57,8 @@ int main(int argc, char *argv[]) /* unmounts */ adfUnMount(vol); - adfUnMountDev(hd); - adfCloseDev(hd); + adfDevUnMount ( hd ); + adfDevClose ( hd ); adfEnvCleanUp(); From 4b2f5b4110779920c74ce0f009935691b79b1cf5 Mon Sep 17 00:00:00 2001 From: t-m Date: Sat, 10 Feb 2024 23:00:45 +0100 Subject: [PATCH 32/40] debian / rules: build the default native device driver. --- debian/rules | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/debian/rules b/debian/rules index 284364b6..10e2f8bd 100755 --- a/debian/rules +++ b/debian/rules @@ -19,5 +19,5 @@ export DH_VERBOSE = 1 # dh $@ --parallel --with autotools_dev dh $@ --with autoreconf -override_dh_auto_configure: - dh_auto_configure -- --enable-native-generic +#override_dh_auto_configure: +# dh_auto_configure -- --enable-native-generic From fc40aa3d1d072059b7583fd09c14772590335a67 Mon Sep 17 00:00:00 2001 From: t-m Date: Sun, 11 Feb 2024 23:43:00 +0100 Subject: [PATCH 33/40] adfMountHd: do not abort if FSHD or LSEG blocks cannot be read. So far, the code was aborting on error reading FSHD and going on an infinite loop on error reading LSEG. Since apparently these blocks are not needed to access partitions/volumes: http://lclevy.free.fr/adflib/adf_info.html#p64 these errors can be ignored (but are reported). --- src/adf_dev_hd.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/adf_dev_hd.c b/src/adf_dev_hd.c index 8eb93f4a..483b6355 100644 --- a/src/adf_dev_hd.c +++ b/src/adf_dev_hd.c @@ -134,8 +134,6 @@ RETCODE adfMountHd ( struct AdfDevice * const dev ) { struct bRDSKblock rdsk; struct bPARTblock part; - struct bFSHDblock fshd; - struct bLSEGblock lseg; int32_t next; struct AdfList *vList, *listRoot; int i; @@ -220,25 +218,39 @@ RETCODE adfMountHd ( struct AdfDevice * const dev ) } freeList(listRoot); + /* The code below seems to only check if the FSHD and LSEG blocks can be + read. These blocks are not required to access partitions/volumes: + http://lclevy.free.fr/adflib/adf_info.html#p64 */ + + struct bFSHDblock fshd; next = rdsk.fileSysHdrList; while( next!=-1 ) { rc = adfReadFSHDblock ( dev, next, &fshd ); if ( rc != RC_OK ) { + /* for ( i = 0 ; i < dev->nVol ; i++ ) free ( dev->volList[i] ); - free(dev->volList); - (*adfEnv.eFct)("adfMount : adfReadFSHDblock"); - return rc; + free(dev->volList); */ + adfEnv.wFct ("adfMountHd : adfReadFSHDblock error, device %s, sector %d", + dev->name, next ); + //return rc; + break; } next = fshd.next; } + struct bLSEGblock lseg; next = fshd.segListBlock; while( next!=-1 ) { rc = adfReadLSEGblock ( dev, next, &lseg ); if ( rc != RC_OK ) { - (*adfEnv.wFct)("adfMount : adfReadLSEGblock"); - // abort here ? + /*for ( i = 0 ; i < dev->nVol ; i++ ) + free ( dev->volList[i] ); + free(dev->volList); */ + adfEnv.wFct ("adfMountHd : adfReadLSEGblock error, device %s, sector %s", + dev->name, next ); + //return rc; + break; } next = lseg.next; } From 7de79cdf7b2af954fc6fbd298e7479557a0b1c8b Mon Sep 17 00:00:00 2001 From: t-m Date: Mon, 12 Feb 2024 16:39:54 +0100 Subject: [PATCH 34/40] adfDevInfo: correct output (align columns). --- src/adf_dev.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/adf_dev.c b/src/adf_dev.c index 553f9e42..7743bd15 100644 --- a/src/adf_dev.c +++ b/src/adf_dev.c @@ -153,15 +153,10 @@ void adfDevInfo ( const struct AdfDevice * const dev ) dev->nVol ); for ( int i = 0 ; i < dev->nVol ; i++ ) { - if ( dev->volList[i]->volName ) - printf(" %2d %7d %7d \"%s\"", i, - dev->volList[i]->firstBlock, - dev->volList[i]->lastBlock, - dev->volList[i]->volName); - else - printf(" %2d %7d %7d\n", i, - dev->volList[i]->firstBlock, - dev->volList[i]->lastBlock); + printf ( " %2d %9d %9d \"%s\"", i, + dev->volList[i]->firstBlock, + dev->volList[i]->lastBlock, + dev->volList[i]->volName ? dev->volList[i]->volName : "" ); if ( dev->volList[i]->mounted ) printf(" mounted"); putchar('\n'); From 8ab6e74805e7dec0303f0f543d9e29d9bfa91763 Mon Sep 17 00:00:00 2001 From: t-m Date: Mon, 12 Feb 2024 16:47:12 +0100 Subject: [PATCH 35/40] adf_show_metadata: add parameter for selecting volume. --- examples/adf_show_metadata.c | 95 +++++++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 28 deletions(-) diff --git a/examples/adf_show_metadata.c b/examples/adf_show_metadata.c index 48f50622..194827dc 100644 --- a/examples/adf_show_metadata.c +++ b/examples/adf_show_metadata.c @@ -15,40 +15,47 @@ char* basename(char* path); #include "adf_show_metadata_file.h" -static void show_device_metadata ( struct AdfDevice * const dev ); +struct args { + const char * adfname; + int vol_id; + const char * path; +}; -static void show_dentry_metadata ( struct AdfVolume * const vol, - char * const path ); +int parse_args ( const int argc, + const char * const * const argv, + struct args * const args ); + +void show_device_metadata ( struct AdfDevice * const dev ); + +void show_dentry_metadata ( struct AdfVolume * const vol, + const char * const path ); void usage ( void ) { - printf ( "adf_show_metadata - show metadata of an adf device or a file/directory\n\n" - "Usage: adf_show_metadata adf_device [path]\n\n" + printf ( "\nadf_show_metadata - show metadata of an adf device or a file/directory\n\n" + "Usage: adf_show_metadata adf_device [vol] [path]\n\n" "where:\n adf_device - an adf file (image) or a native (real) device\n" + " vol - (optional) partition/volume number\n" " path - (optional) a file/directory inside the ADF device\n\n" "(using adflib version %s)\n", adfGetVersionNumber() ); } -int main ( int argc, - char ** argv ) +int main ( const int argc, + const char * const * const argv ) { - if ( argc < 2 ) { - usage(); - return 1; - } - char * const adfname = argv[1]; - char * const path = ( argc == 3 ) ? argv[2] : NULL; - int status = 0; + struct args args; + if ( ( status = parse_args (argc, argv, &args ) ) != 0 ) + return status; adfEnvInitDefault(); - printf ( "\nOpening image/device:\t'%s'\n", adfname ); - struct AdfDevice * const dev = adfDevOpen ( adfname, ADF_ACCESS_MODE_READONLY ); + printf ( "\nOpening image/device:\t'%s'\n", args.adfname ); + struct AdfDevice * const dev = adfDevOpen ( args.adfname, ADF_ACCESS_MODE_READONLY ); if ( ! dev ) { fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n", - adfname ); + args.adfname ); status = 1; goto env_cleanup; } @@ -56,25 +63,28 @@ int main ( int argc, RETCODE rc = adfDevMount ( dev ); if ( rc != RC_OK ) { fprintf ( stderr, "Cannot get volume info for file/device '%s' - aborting...\n", - adfname ); + args.adfname ); goto dev_cleanup; } - int vol_id = 0; - struct AdfVolume * const vol = adfMount ( dev, vol_id, ADF_ACCESS_MODE_READONLY ); + if ( args.vol_id < 0 ) { + show_device_metadata ( dev ); + goto dev_cleanup; + } + + struct AdfVolume * const vol = adfMount ( dev, args.vol_id, ADF_ACCESS_MODE_READONLY ); if ( ! vol ) { fprintf ( stderr, "Cannot mount volume %d - aborting...\n", - vol_id ); + args.vol_id ); status = 1; goto dev_mount_cleanup; } - printf ( "Mounted volume:\t\t%d\n", vol_id ); + printf ( "Mounted volume:\t\t%d\n", args.vol_id ); - if ( path ) { + if ( args.path != NULL ) { //printf ( "Show file / dirtory info\n" ); - show_dentry_metadata ( vol, path ); + show_dentry_metadata ( vol, args.path ); } else { - show_device_metadata ( dev ); show_volume_metadata ( vol ); } @@ -91,14 +101,43 @@ int main ( int argc, } -static void show_device_metadata ( struct AdfDevice * const dev ) +int parse_args ( const int argc, + const char * const * const argv, + struct args * const args ) +{ + if ( argc < 2 ) { + usage(); + return 1; + } + + args->adfname = argv[1]; + + if ( argc < 3 ) { + args->vol_id = -1; + return 0; + } + + char * endptr; + long vol_id_l = strtol (argv[2], &endptr, 10); + if ( *endptr != 0 ) { + fprintf ( stderr, "Invalid volume '%s'\n", argv[2] ); + return 1; + } + args->vol_id = (int) vol_id_l; + + args->path = ( argc >= 4 ) ? argv[3] : NULL; + return 0; +} + + +void show_device_metadata ( struct AdfDevice * const dev ) { adfDevInfo ( dev ); } -static void show_dentry_metadata ( struct AdfVolume * const vol, - char * const path ) +void show_dentry_metadata ( struct AdfVolume * const vol, + const char * const path ) { printf ( "\nPath:\t\t%s\n", path ); const char * path_relative = path; From 90f23e0d0037a6943eb4eae1bb84323704613351 Mon Sep 17 00:00:00 2001 From: t-m Date: Mon, 12 Feb 2024 16:49:20 +0100 Subject: [PATCH 36/40] adf_raw / adfReadBootBlock: add detecting PFS volumes. --- src/adf_raw.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/adf_raw.c b/src/adf_raw.c index 48ed0a7b..74064464 100644 --- a/src/adf_raw.c +++ b/src/adf_raw.c @@ -206,6 +206,10 @@ RETCODE adfReadBootBlock ( struct AdfVolume * const vol, swapEndian((uint8_t*)boot,SWBL_BOOT); #endif if ( strncmp ( "DOS", boot->dosType, 3 ) != 0 ) { + if ( strncmp ( "PFS", boot->dosType, 3 ) == 0 ) { + adfEnv.wFct("adfReadBootBlock : PFS volume found - not supported..."); + return RC_ERROR; + } adfEnv.wFct("adfReadBootBlock : DOS id not found"); return RC_ERROR; } From 321afbddf5fa9c4478108c82b4d006c8df39479e Mon Sep 17 00:00:00 2001 From: t-m Date: Tue, 13 Feb 2024 17:42:37 +0100 Subject: [PATCH 37/40] myIsDevNative: remove unused variable. --- src/generic/adf_dev_driver_nativ.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/generic/adf_dev_driver_nativ.c b/src/generic/adf_dev_driver_nativ.c index da46f93c..a29ebc1c 100644 --- a/src/generic/adf_dev_driver_nativ.c +++ b/src/generic/adf_dev_driver_nativ.c @@ -89,9 +89,6 @@ RETCODE myReleaseDevice ( struct AdfDevice * const dev ) */ static BOOL myIsDevNative(void) { - /* Quiet unused parameter warning */ - (void)(devName); - return FALSE; } From 18b25539d7a3ca16e5ff6810028d93317827a226 Mon Sep 17 00:00:00 2001 From: t-m Date: Tue, 13 Feb 2024 18:34:44 +0100 Subject: [PATCH 38/40] Update adf-floppy-test (updated adf_show_metadata). --- examples/tests/adf-floppy-test.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/examples/tests/adf-floppy-test.sh b/examples/tests/adf-floppy-test.sh index 7a4ac0e4..d15c4b6e 100755 --- a/examples/tests/adf-floppy-test.sh +++ b/examples/tests/adf-floppy-test.sh @@ -42,13 +42,11 @@ Formatting floppy (DD) disk '$tmpdir/testflopdd1.adf'... Done! EOF -$adf_show_metadata $tmpdir/testflopdd1.adf | grep -v \ - -e Created: -e 'Last access:' -e checkSum: -e calculated -e days: \ - -e mins: -e ticks: -e coDays: -e coMins -e coTicks >$actual + +$adf_show_metadata $tmpdir/testflopdd1.adf >$actual compare_with <$actual +compare_with < Date: Tue, 13 Feb 2024 18:39:57 +0100 Subject: [PATCH 39/40] Update adf-show-metadata-test (updated adf_show_metadata). --- examples/tests/adf-show-metadata-test.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/tests/adf-show-metadata-test.sh b/examples/tests/adf-show-metadata-test.sh index 8d3c9241..b227d70f 100755 --- a/examples/tests/adf-show-metadata-test.sh +++ b/examples/tests/adf-show-metadata-test.sh @@ -8,7 +8,6 @@ $adf_show_metadata "$basedir/arccsh.adf" >$actual compare_with <$actual +compare_with <$actual +$adf_show_metadata "$basedir/arccsh.adf" 0 CSH >$actual compare_with <$actual +$adf_show_metadata "$basedir/arccsh.adf" 0 c/ >$actual compare_with <$actual +$adf_show_metadata "$basedir/arccsh.adf" 0 l >$actual compare_with < Date: Tue, 13 Feb 2024 18:46:54 +0100 Subject: [PATCH 40/40] Update test_examples_basic (updated adf_show_metadata). --- examples/tests/test_examples_basic.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/tests/test_examples_basic.sh b/examples/tests/test_examples_basic.sh index a6f31c17..d33b616f 100755 --- a/examples/tests/test_examples_basic.sh +++ b/examples/tests/test_examples_basic.sh @@ -53,9 +53,10 @@ run_cmd() CMDS[0]="unadf -r $TEST_ADF" CMDS[1]="adf_show_metadata $TEST_ADF" -CMDS[2]="adf_show_metadata $TEST_ADF CSH" -CMDS[3]="adf_show_metadata $TEST_ADF c/" -CMDS[4]="adf_show_metadata $TEST_ADF l" +CMDS[2]="adf_show_metadata $TEST_ADF 0" +CMDS[2]="adf_show_metadata $TEST_ADF 0 CSH" +CMDS[3]="adf_show_metadata $TEST_ADF 0 c/" +CMDS[4]="adf_show_metadata $TEST_ADF 0 l" CMDS[5]="adf_floppy_create testflopdd1.adf dd" CMDS[6]="adf_floppy_format testflopdd1.adf TestFlopDD1 1" CMDS[7]="adf_show_metadata testflopdd1.adf"