Skip to content

Commit

Permalink
Merge pull request #75 from t-w/devices
Browse files Browse the repository at this point in the history
Improve devices API, update adf_show_metadata
  • Loading branch information
t-w authored Feb 13, 2024
2 parents b4640bf + 4528704 commit d18f831
Show file tree
Hide file tree
Showing 86 changed files with 1,955 additions and 1,045 deletions.
4 changes: 2 additions & 2 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,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
15 changes: 12 additions & 3 deletions examples/adf_bitmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,28 @@ 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 = adfDevOpen ( adfname, devMode );
if ( ! dev ) {
fprintf ( stderr, "Cannot open file/device '%s' - aborting...\n",
adfname );
status = 1;
goto env_cleanup;
}

RETCODE rc = adfDevMount ( 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 );
Expand All @@ -112,8 +119,10 @@ int main ( int argc,

adfUnMount ( vol );

dev_mount_cleanup:
adfDevUnMount ( dev );
dev_cleanup:
adfUnMountDev ( dev );
adfDevClose ( dev );
env_cleanup:
adfEnvCleanUp();

Expand Down
9 changes: 5 additions & 4 deletions examples/adf_floppy_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,18 @@ int main ( int argc,

adfEnvInitDefault();

struct AdfDevice * device = adfCreateDumpDevice ( adfname, tracks, HEADS,
sectors_per_track );
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 );
adfDevUnMount ( device );
adfDevClose ( device );
adfEnvCleanUp();

return 0;
Expand Down
24 changes: 13 additions & 11 deletions examples/adf_floppy_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,22 @@ int main ( int argc,

adfEnvInitDefault();

struct AdfDevice * device = adfMountDev ( adfname, ADF_ACCESS_MODE_READWRITE );
if ( device ) {
fprintf ( stderr, "The floppy disk %s already contains a filesystem - aborting...\n",
adfname );
adfUnMountDev ( device );
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;
}

device = adfOpenDev ( adfname, ADF_ACCESS_MODE_READWRITE );
if ( ! device ) {
fprintf ( stderr, "Cannot open floppy disk %s - aborting...\n", adfname );
RETCODE rc = adfDevMount ( device );
if ( rc == RC_OK ) {
fprintf ( stderr, "The floppy disk %s already contains a filesystem - aborting...\n",
adfname );
adfDevUnMount ( device );
adfDevClose ( device );
return 1;
}


//adfDeviceInfo ( device );

char *fdtype;
Expand All @@ -62,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;
Expand Down
108 changes: 78 additions & 30 deletions examples/adf_show_metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,81 +15,129 @@ 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 = adfMountDev ( 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;
}

int vol_id = 0;
struct AdfVolume * const vol = adfMount ( dev, vol_id, ADF_ACCESS_MODE_READONLY );
RETCODE rc = adfDevMount ( dev );
if ( rc != RC_OK ) {
fprintf ( stderr, "Cannot get volume info for file/device '%s' - aborting...\n",
args.adfname );
goto dev_cleanup;
}

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_cleanup;
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 );
}

adfUnMount ( vol );

dev_mount_cleanup:
adfDevUnMount ( dev );
dev_cleanup:
adfUnMountDev ( dev );
adfDevClose ( dev );
env_cleanup:
adfEnvCleanUp();

return status;
}


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 )
{
adfDeviceInfo ( 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;
Expand Down
26 changes: 19 additions & 7 deletions examples/tests/adf-floppy-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ compare_with <<EOF
Creating floppy disk image: '$tmpdir/testflopdd1.adf'
ADF device info:
Type: floppy dd, file (image)
Type: floppy dd
Driver: dump
Geometry:
Cylinders 80
Heads 2
Expand All @@ -27,7 +28,8 @@ $adf_floppy_format $tmpdir/testflopdd1.adf TestFlopDD1 1 >$actual 2>/dev/null
compare_with <<EOF
ADF device info:
Type: floppy dd, file (image)
Type: floppy dd
Driver: dump
Geometry:
Cylinders 80
Heads 2
Expand All @@ -40,16 +42,15 @@ 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 <<EOF
Opening image/device: '$tmpdir/testflopdd1.adf'
Mounted volume: 0
ADF device info:
Type: floppy dd, file (image)
Type: floppy dd
Driver: dump
Geometry:
Cylinders 80
Heads 2
Expand All @@ -59,6 +60,16 @@ ADF device info:
idx first bl. last bl. name
0 0 1759 "TestFlopDD1" mounted
EOF


$adf_show_metadata $tmpdir/testflopdd1.adf 0 | grep -v \
-e Created: -e 'Last access:' -e checkSum: -e calculated -e days: \
-e mins: -e ticks: -e coDays: -e coMins -e coTicks >$actual
compare_with <<EOF
Opening image/device: '$tmpdir/testflopdd1.adf'
Mounted volume: 0
ADF volume info:
Name: TestFlopDD1
Expand Down Expand Up @@ -101,4 +112,5 @@ Bitmap block pointers (bmPages) (non-zero):
bmpages [ 0 ]: 0x371 881
EOF


read status < $status && test "x$status" = xsuccess
Loading

0 comments on commit d18f831

Please sign in to comment.