home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 7
/
FreshFishVol7.bin
/
bbs
/
disk
/
amicdrom-1.13.lha
/
AmiCDROM
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-09-11
|
30KB
|
1,051 lines
/* main.c:
*
* Interactive test program for the ISO- and Rock-Ridge-support
* routines.
*
* ----------------------------------------------------------------------
* This code is (C) Copyright 1993,1994 by Frank Munkert.
* All rights reserved.
* This software may be freely distributed and redistributed for
* non-commercial purposes, provided this notice is included.
* ----------------------------------------------------------------------
* History:
*
* 17-Feb-94 fmu Fixed typo.
* 28-Nov-93 fmu Improved "cdrom d" command.
* 12-Oct-93 fmu "Show path table" function removed.
* 09-Oct-93 fmu Open utility.library.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dos/var.h>
#include <devices/trackdisk.h>
#include <clib/alib_protos.h>
#include <clib/dos_protos.h>
#include <clib/exec_protos.h>
#include "cdrom.h"
#include "iso9660.h"
#include "rock.h"
#include "hfs.h"
#ifdef LATTICE
#include <pragmas/dos_pragmas.h>
#include <pragmas/exec_pragmas.h>
extern struct Library *SysBase, *DOSBase;
#endif
#define STD_BUFFERS 10
#define FILE_BUFFERS 5
#ifdef DEBUG_SECTORS
void dbprintf (char *p_dummy, ...)
{
}
#endif
CDROM *cd = NULL;
char g_the_device[80];
int g_the_unit;
int g_trackdisk = 0;
t_ulong g_memory_type = MEMF_CHIP;
struct UtilityBase *UtilityBase;
void Cleanup (void)
{
if (cd)
Cleanup_CDROM (cd);
if (UtilityBase)
CloseLibrary ((struct Library*) UtilityBase);
}
void Usage (void)
{
fprintf (stderr,
"Usage: cdrom command [parameters]\n"
"Commands:\n"
" a Show information on CDROM drive\n"
" b Read table of contents\n"
" c name Show contents of file 'name'\n"
" d[rl] dir Show contents of directory 'dir' (use ISO names)\n"
" r=also show subdirectories, l=show additional information\n"
" e[r[l|L]] dir Show contents of directory 'dir' (use Rock Ridge names)\n"
" r=also show subdirectories, l=show system use field names\n"
" L=show names and contents of system use fields\n"
" f dir name Change to directory 'dir' and try to find object 'name'\n"
" i Check which protocol is used\n"
" j [01] 0=start audio, 1=stop motor\n"
" l Find offset of last session\n"
" m num Read catalog node 'num' (MacHFS only)\n"
" o name Try to open object 'name'\n"
" r Read contents of root directory\n"
" s num [cnt] Read 'cnt' sectors, starting at sector 'num'\n"
" t name Try to open parent of object 'name'\n"
" v Read primary volume descriptor\n"
" x dens [length] Select mode: dens=density code,\n"
" length=block length (default: 2048)\n"
" z Send test unit ready command\n"
" T Test trackdisk device\n"
"Use \":\" as the name of the root directory\n"
);
exit (1);
}
char *MKSTR (char *p_in, int p_length, char *p_out)
{
char *res = p_out;
int len = p_length;
int i;
while (len && p_in[len-1] == ' ')
len--;
for (i=0; i<len; i++)
*p_out++ = *p_in++;
*p_out = 0;
return res;
}
void Show_Flags (unsigned char p_flags)
{
if (p_flags & 1)
printf ("existence ");
if (p_flags & 2)
printf ("directory ");
if (p_flags & 4)
printf ("associated ");
if (p_flags & 8)
printf ("record ");
if (p_flags & 16)
printf ("protection ");
if (p_flags & 128)
printf ("multi-extent ");
}
void Show_Directory_Record (directory_record *p_dir)
{
char buf[256];
printf ("Extended Attr Record Length: %d\n", (int) p_dir->ext_attr_length);
printf ("Location of Extent: %lu\n", p_dir->extent_loc_m);
printf ("Data Length: %lu\n", p_dir->data_length_m);
printf ("Recording Date and Time: %02d.%02d.19%02d %02d:%02d:%02d %+d\n",
(int) p_dir->day, (int) p_dir->month, (int) p_dir->year,
(int) p_dir->hour, (int) p_dir->minute, (int) p_dir->second,
(int) p_dir->tz);
printf ("Flags: %d (", (int) p_dir->flags);
Show_Flags (p_dir->flags);
printf (")\n");
printf ("File Unit Size: %d\n", (int) p_dir->file_unit_size);
printf ("Gap Size: %d\n", (int) p_dir->gap_size);
printf ("Volume Sequence Number: %hu\n", p_dir->sequence_m);
printf ("File Identifier: ");
if (p_dir->file_id[0] == 0)
printf ("(00)\n");
else if (p_dir->file_id[0] == 1)
printf ("(01)\n");
else
printf ("%s\n", MKSTR (p_dir->file_id, p_dir->file_id_length, buf));
}
void Find_Block_Starting_With (CDROM *p_cd, int p_val)
{
unsigned long sec = 0;
int cmp;
int i;
for (;;) {
if (!Read_Sector (p_cd, sec)) {
fprintf (stderr, "cannot read sector 16\n");
exit (1);
}
for (i=0; i<4; i++) {
cmp = p_cd->buffer[i<<9] * 256 + p_cd->buffer[(i<<9)+1];
if (cmp == p_val)
printf ("sector %lu, block %d\n", sec, i);
}
sec++;
}
}
void Show_Primary_Volume_Descriptor (CDROM *p_cd)
{
prim_vol_desc *pvd;
char buf[129];
int blk;
t_mdb mdb;
t_hdr_node hdr;
int skip;
t_ulong offset;
int protocol;
t_bool hfs;
hfs = Uses_HFS_Protocol (p_cd, &skip);
protocol = Which_Protocol (p_cd, TRUE, &skip, &offset);
if (protocol == PRO_UNKNOWN) {
printf ("Unknown protocol\n");
return;
}
if (protocol == PRO_HIGH_SIERRA) {
printf ("High sierra protocol (not supported)\n");
}
if ((protocol == PRO_ROCK || protocol == PRO_ISO) && hfs)
printf ("Multi-platform disk: HFS & ISO\n");
if (protocol == PRO_ROCK)
printf ("Rock Ridge extensions available, skip size = %d\n", skip);
if (protocol == PRO_ISO)
printf ("Data track offset = %lu\n", offset);
if (protocol == PRO_ISO || protocol == PRO_ROCK) {
if (!Read_Sector (p_cd, 16 + offset)) {
fprintf (stderr, "cannot read sector %lu\n", 16 + offset);
exit (1);
}
pvd = (prim_vol_desc *) p_cd->buffer;
printf ("--- ISO-9660: ---\n");
printf ("Volume Descriptor Type: %d\n", (int) pvd->type);
printf ("Standard Identifier: %s\n", MKSTR (pvd->id,5,buf));
printf ("Volume Descriptor Version: %d\n", (int) pvd->version);
printf ("System Identifier: %s\n", MKSTR (pvd->system_id,32,buf));
printf ("Volume Identifier: %s\n", MKSTR (pvd->volume_id,32,buf));
printf ("Volume Space Size: %lu\n", pvd->space_size_m);
printf ("Volume Set Size: %hu\n", pvd->set_size_m);
printf ("Volume Sequence Number: %hu\n", pvd->sequence_m);
printf ("Logical Block Size: %hu\n", pvd->block_size_m);
printf ("Path Table Size: %lu\n", pvd->path_size_m);
printf ("Location of Occ of M Path Table: %lu\n", pvd->m_table);
printf ("Location of Occ of Opt M Path T: %lu\n", pvd->opt_m_table);
printf ("Volume Set Identifier: %s\n",
MKSTR (pvd->volume_set_id,128,buf));
printf ("Publisher Identifier: %s\n",
MKSTR (pvd->publisher_id,128,buf));
printf ("Data Preparer Identifier: %s\n",
MKSTR (pvd->data_preparer,128,buf));
printf ("Application Identifier: %s\n",
MKSTR (pvd->application_id,128,buf));
printf ("Copyright File Identifier: %s\n",
MKSTR (pvd->copyright,37,buf));
printf ("Abstract File Identifier: %s\n",
MKSTR (pvd->abstract_file_id,37,buf));
printf ("Bibliographic File Identifier: %s\n",
MKSTR (pvd->bibliographic_id,37,buf));
printf ("File Structure Version: %d\n",
(int) pvd->file_structure_version);
printf ("ROOT DIRECTORY RECORD:\n");
Show_Directory_Record (&pvd->root);
}
if (hfs) {
if ((blk = HFS_Find_Master_Directory_Block (p_cd, &mdb)) < 0) {
printf ("No master directory block found\n");
exit (1);
}
printf ("--- MacHFS: ---\n");
printf ("Master directory block located at block %d\n", blk);
printf ("Vol