home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 4
/
FreshFish_May-June1994.bin
/
useful
/
dist
/
disk
/
cdrom
/
amicdrom
/
device.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-20
|
42KB
|
1,487 lines
/* device.c:
*
* Handler for ISO-9660 (+ Rock Ridge) + HFS CDROM filing system.
* Based on DOSDEV V1.10 (2 Nov 87) by Matthew Dillon.
*
* ----------------------------------------------------------------------
* 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:
*
* 20-Apr-94 fmu Improved implementation of ACTION_INHIBIT.
* 17-Apr-94 fmu Fixed bug concerning TRACKDISK disk change recognition.
* 12-Apr-94 fmu Adapted ACTION_CURRENT_VOLUME to new filehandle
* management.
* 09-Apr-94 fmu Volume management: locks and filehandles will not
* be forgotten if a CDROM is removed from the drive.
* 06-Feb-94 dmb - Full support for ACTION_INHIBIT
* - Change Check_Disk() for trackdisk support
* 05-Jan-93 fmu - Retry displaying CD-DA icon if WB is not open.
* - id_UnitNumber of InfoData set to SCSI unit number.
* - Added Make_FSSM().
* 01-Jan-93 fmu Support for symbolic links on RockRidge disks.
* 11-Dec-93 fmu - ACTION_FLUSH always returns DOSTRUE.
* - ISO volume names are mapped to lowercase if
* the option LOWERCASE has been selected.
* 26-Nov-93 fmu Some packets are now handled even if no disk
* is inserted.
* 21-Nov-93 fmu - User programmable diskchange check interval.
* - Better support for ACTION_INHIBIT.
* - Handles filenames with ';'.
* 15-Nov-93 fmu Missing return value for 'handler' inserted.
* 14-Nov-93 fmu Added ACTION_USER packet for 'cdcontrol' program.
* 15-Oct-93 fmu Adapted to new VOLUME structure.
* 10-Oct-93 fmu - Creates volume node for 'no DOS' disks.
* - Volume node now contains the correct volume
* creation date.
* 09-Oct-93 fmu - New format for mountlist startup field.
* - SAS/C support.
* - Debug process assembly tag adapted to small
* memory model.
* - Get_Startup moved to file devsupp.c.
* 03-Oct-93 fmu - New buffering options 'S' and 'C'.
* - Fixed bug in cdlock.
* - Fixed bug in ACTION_CURRENT_VOLUME.
* 27-Sep-93 fmu Added ACTION_SAME_LOCK
* 25-Sep-93 fmu - Send 'disk inserted' / 'disk removed' event via
* input.device if disk has been changed.
* - Corrected bug in ACTION_DISK_INFO.
* 24-Sep-93 fmu - Added fast memory option 'F'.
* - Added ACTION_IS_FILESYSTEM.
* - Added 'write protected' error for write actions.
* - Added ACTION_CURRENT_VOLUME.
* - Unload handler code after ACTION_DIE.
* - Immediately terminate program if called from CLI.
* - Added library version number.
* - Set volume label to "Unnamed" for disks without name.
* 16-Sep-93 fmu Added code to detect whether a lock stems from the
* current volume or from another volume which has
* been removed from the drive.
*/
/*
* Debugging routines are disabled by simply attempting to open the
* file "debugoff", turned on again with "debugon". No prefix may be
* attached to these names (you must be CD'd to TEST:).
*
* See Documentation for a detailed discussion.
*/
#include <stdlib.h>
#include <string.h>
#if defined(_DCC) && !defined(REGISTERED)
#define abs
#endif
#include "device.h"
#include "intui.h"
#include "devsupp.h"
#include "cdcontrol.h"
#include "params.h"
#include "rock.h"
/*
* Since this code might be called several times in a row without being
* unloaded, you CANNOT ASSUME GLOBALS HAVE BEEN ZERO'D!! This also goes
* for any global/static assignments that might be changed by running the
* code.
*/
PROC *DosProc; /* Our Process */
DEVNODE *DosNode; /* Our DOS node.. created by DOS for us */
DEVLIST *DevList; /* Device List structure for our volume node */
#if !defined(_DCC) || defined(REGISTERED)
EXECLIB *SysBase; /* EXEC library base */
#endif
DOSLIB *DOSBase; /* DOS library base for debug process */
LIB *UtilityBase; /* Utility library for miscellaneous tasks */
CDROM *g_cd;
VOLUME *g_volume;
CDROM_OBJ *g_top_level_obj;
char *g_vol_name;
PORT *g_timer_mp; /* timer message port */
struct timerequest *g_timer_io; /* timer i/o request */
ULONG g_timer_sigbit;
ULONG g_dos_sigbit;
char g_device[80]; /* SCSI device name */
short g_unit; /* SCSI unit */
short g_use_rock_ridge; /* Use Rock Ridge flag 'R' */
short g_map_to_lowercase; /* Map to lower case flag 'L' */
int g_trackdisk; /* Use trackdisk calls instead of SCSI-direct */
int g_std_buffers; /* Number of buffers for standard SCSI access */
int g_file_buffers; /* Number of buffers for contiguous reads */
t_bool g_show_version_numbers; /* Show version numbers */
int g_scan_interval; /* Time between successive diskchange checks */
t_bool g_disk_inserted; /* Is a disk inserted? */
char g_play_cdda_command[80];/* Command invoked if appicon is activated */
int g_inhibited; /* Number of active INHIBIT(TRUE) packets */
struct MsgPort *DosTask;
#if !defined(NDEBUG) || defined(DEBUG_SECTORS)
/* DEBUGGING */
PORT *Dbport; /* owned by the debug process */
PORT *Dback; /* owned by the DOS device driver */
short DBDisable;
MSG DummyMsg; /* Dummy message that debug proc can use */
#endif
void *dosalloc(ulong);
void dosfree (ulong *);
void btos(LONG, char *);
void *NextNode (NODE *);
void *GetHead (LIST *);
LOCK *cdlock(CDROM_OBJ *, int);
void cdunlock (LOCK *);
CDROM_OBJ *getlockfile (LONG);
char *typetostr (int);
void returnpacket(struct DosPacket *);
int packetsqueued (void);
int Check_For_Volume_Name_Prefix (char *);
void Fill_FileInfoBlock (FIB *, CDROM_INFO *, VOLUME *);
void Mount (void);
void Unmount (int);
int Mount_Check (void);
void Check_Disk (void);
void Send_Timer_Request (void);
void Cleanup_Timer_Device (void);
int Open_Timer_Device (void);
void Send_Event (int);
void Remove_Seglist (void);
BPTR Make_FSSM (void);
/*
* Don't call the entry point main(). This way, if you make a mistake
* with the compile options you'll get a link error.
*/
#if defined(LATTICE)
int __saveds handler (void)
#elif defined(_DCC) && !defined(REGISTERED)
int _main (void)
#elif defined(_DCC) && defined(REGISTERED)
__geta4 int handler (void)
#else
int handler (void)
#endif
{
register PACKET *packet;
register short error;
MSG *msg;
ubyte notdone = 1;
char buf[256];
void *tmp;
ULONG signals;
ubyte playing = FALSE;
/*
* Initialize all global variables. SysBase MUST be initialized before
* we can make Exec calls. The DOS library is opened for the debug
* process only.
*/
#if !defined(_DCC) || defined(REGISTERED)
SysBase = *(EXECLIB **) 4L;
#endif
DosProc = (PROC *) FindTask(NULL);
if (DosProc->pr_CLI)
return RETURN_FAIL;
DOSBase = (DOSLIB *) OpenLibrary ((UBYTE *) "dos.library",37);
UtilityBase = (LIB *) OpenLibrary ((UBYTE *) "utility.library",37);
BUG2(DBDisable = 0;) /* Init. globals */
BUG2(Dbport = Dback = NULL;)
DevList = NULL;
{
WaitPort(&DosProc->pr_MsgPort); /* Get Startup Packet */
msg = GetMsg(&DosProc->pr_MsgPort);
packet = (PACKET *)msg->mn_Node.ln_Name;
/*
* Loading DosNode->dn_Task causes DOS *NOT* to startup a new
* instance of the device driver for every reference. E.G. if
* you were writing a CON device you would want this field to
* be NULL.
*/
DosNode = BTOC(packet->dp_Arg3);
Init_Intui ();
if (UtilityBase && DOSBase && Get_Startup (packet->dp_Arg2)) {
packet->dp_Res1 = DOS_TRUE;
packet->dp_Res2 = 0;
/*
* Set dn_Task field which tells DOS not to startup a new
* process on every reference.
*/
DosNo