home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 10 / Fresh_Fish_10_2352.bin / useful / disk / cdrom / amicdrom / src / device.c < prev    next >
C/C++ Source or Header  |  1994-11-03  |  46KB  |  1,602 lines

  1. /* device.c:
  2.  *
  3.  * Handler for ISO-9660 (+ Rock Ridge) + HFS CDROM filing system.
  4.  * Based on DOSDEV V1.10 (2 Nov 87) by Matthew Dillon.
  5.  *
  6.  * ----------------------------------------------------------------------
  7.  * This code is (C) Copyright 1993,1994 by Frank Munkert.
  8.  * All rights reserved.
  9.  * This software may be freely distributed and redistributed for
  10.  * non-commercial purposes, provided this notice is included.
  11.  * ----------------------------------------------------------------------
  12.  * History:
  13.  *
  14.  * 03-Nov-94   fmu   Truncate file names to 30 characters.
  15.  * 12-Oct-94   fmu   Return startup packet even if the scsi device cannot
  16.  *                   be opened immediately.
  17.  * 01-Sep-94   fmu   - Added ACTION_EXAMINE_FH.
  18.  *             - Added ACTION_PARENT_FH.
  19.  *             - Added ACTION_MAKE_LINK (-> error message).
  20.  *             - Automatically remove volume if all locks on the
  21.  *               the volume have been freed.
  22.  * 17-May-94   fmu   New option MAYBELOWERCASE (=ML).
  23.  * 20-Apr-94   fmu   Improved implementation of ACTION_INHIBIT.
  24.  * 17-Apr-94   fmu   Fixed bug concerning TRACKDISK disk change recognition.
  25.  * 12-Apr-94   fmu   Adapted ACTION_CURRENT_VOLUME to new filehandle
  26.  *             management.
  27.  * 09-Apr-94   fmu   Volume management: locks and filehandles will not
  28.  *                   be forgotten if a CDROM is removed from the drive.
  29.  * 06-Feb-94   dmb   - Full support for ACTION_INHIBIT
  30.  *                   - Change Check_Disk() for trackdisk support
  31.  * 05-Jan-93   fmu   - Retry displaying CD-DA icon if WB is not open.
  32.  *                   - id_UnitNumber of InfoData set to SCSI unit number.
  33.  *                   - Added Make_FSSM().
  34.  * 01-Jan-93   fmu   Support for symbolic links on RockRidge disks.
  35.  * 11-Dec-93   fmu   - ACTION_FLUSH always returns DOSTRUE.
  36.  *                   - ISO volume names are mapped to lowercase if
  37.  *                     the option LOWERCASE has been selected.
  38.  * 26-Nov-93   fmu   Some packets are now handled even if no disk
  39.  *                   is inserted.
  40.  * 21-Nov-93   fmu   - User programmable diskchange check interval.
  41.  *                   - Better support for ACTION_INHIBIT.
  42.  *                   - Handles filenames with ';'.
  43.  * 15-Nov-93   fmu   Missing return value for 'handler' inserted.
  44.  * 14-Nov-93   fmu   Added ACTION_USER packet for 'cdcontrol' program.
  45.  * 15-Oct-93   fmu   Adapted to new VOLUME structure.
  46.  * 10-Oct-93   fmu   - Creates volume node for 'no DOS' disks.
  47.  *             - Volume node now contains the correct volume
  48.  *               creation date.
  49.  * 09-Oct-93   fmu   - New format for mountlist startup field.
  50.  *             - SAS/C support.
  51.  *             - Debug process assembly tag adapted to small
  52.  *               memory model.
  53.  *             - Get_Startup moved to file devsupp.c.
  54.  * 03-Oct-93   fmu   - New buffering options 'S' and 'C'.
  55.  *                   - Fixed bug in cdlock.
  56.  *             - Fixed bug in ACTION_CURRENT_VOLUME.
  57.  * 27-Sep-93   fmu   Added ACTION_SAME_LOCK
  58.  * 25-Sep-93   fmu   - Send 'disk inserted' / 'disk removed' event via
  59.  *                     input.device if disk has been changed.
  60.  *                   - Corrected bug in ACTION_DISK_INFO.
  61.  * 24-Sep-93   fmu   - Added fast memory option 'F'.
  62.  *                   - Added ACTION_IS_FILESYSTEM.
  63.  *                   - Added 'write protected' error for write actions.
  64.  *                   - Added ACTION_CURRENT_VOLUME.
  65.  *                   - Unload handler code after ACTION_DIE.
  66.  *                   - Immediately terminate program if called from CLI.
  67.  *                   - Added library version number.
  68.  *                   - Set volume label to "Unnamed" for disks without name.
  69.  * 16-Sep-93   fmu   Added code to detect whether a lock stems from the
  70.  *                   current volume or from another volume which has
  71.  *                   been removed from the drive.
  72.  */
  73.  
  74. /*
  75.  *  Debugging routines are disabled by simply attempting to open the
  76.  *  file "debugoff", turned on again with "debugon".  No prefix may be
  77.  *  attached to these names (you must be CD'd to TEST:).
  78.  *
  79.  *  See Documentation for a detailed discussion.
  80.  */
  81.  
  82. #include <stdlib.h>
  83. #include <string.h>
  84.  
  85. #include "device.h"
  86. #include "intui.h"
  87. #include "devsupp.h"
  88. #include "cdcontrol.h"
  89. #include "params.h"
  90. #include "rock.h"
  91.  
  92. #ifdef __GNUC__
  93. struct Library *ixemulbase;
  94. #endif
  95.  
  96. /*
  97.  *  Since this code might be called several times in a row without being
  98.  *  unloaded, you CANNOT ASSUME GLOBALS HAVE BEEN ZERO'D!!  This also goes
  99.  *  for any global/static assignments that might be changed by running the
  100.  *  code.
  101.  */
  102.  
  103. PROC    *DosProc;     /* Our Process                        */
  104. DEVNODE *DosNode;     /* Our DOS node.. created by DOS for us            */
  105. DEVLIST *DevList;     /* Device List structure for our volume node       */
  106.  
  107. EXECLIB *SysBase;     /* EXEC library base                */
  108. DOSLIB    *DOSBase;     /* DOS library base for debug process        */
  109. LIB    *UtilityBase; /* Utility library for miscellaneous tasks     */
  110.  
  111. CDROM   *g_cd;
  112. VOLUME  *g_volume;
  113. CDROM_OBJ *g_top_level_obj;
  114. char    *g_vol_name;
  115.  
  116. PORT *g_timer_mp;           /*  timer message port        */
  117. struct timerequest *g_timer_io; /*  timer i/o request        */
  118. ULONG g_timer_sigbit;
  119. ULONG g_dos_sigbit;
  120.  
  121. char    g_device[80];        /* SCSI device name */
  122. short    g_unit;            /* SCSI unit */
  123. short    g_use_rock_ridge;    /* Use Rock Ridge flag 'R' */
  124. short    g_maybe_map_to_lowercase;/* Conditional map to lower case flag 'ML' */
  125. short    g_map_to_lowercase;    /* Map to lower case flag 'L' */
  126. int     g_trackdisk;        /* Use trackdisk calls instead of SCSI-direct */
  127.  
  128. int    g_std_buffers;        /* Number of buffers for standard SCSI access */
  129. int    g_file_buffers;        /* Number of buffers for contiguous reads */
  130.  
  131. t_bool    g_show_version_numbers; /* Show version numbers */
  132.  
  133. int    g_scan_interval;    /* Time between successive diskchange checks */
  134. int     g_scan_time;        /* Countdown for diskchange */
  135.  
  136. t_bool    g_disk_inserted;    /* Is a disk inserted? */
  137.  
  138. char    g_play_cdda_command[80];/* Command invoked if appicon is activated */
  139.  
  140. int    g_inhibited;        /* Number of active INHIBIT(TRUE) packets */
  141.  
  142. int     g_time;            /* Current time */
  143.  
  144. ubyte   playing;        /* CD-DA play status */
  145.  
  146. struct MsgPort *DosTask;
  147.  
  148. #if !defined(NDEBUG) || defined(DEBUG_SECTORS)
  149.             /*    DEBUGGING            */
  150. PORT *Dbport;        /*    owned by the debug process    */
  151. PORT *Dback;        /*    owned by the DOS device driver    */
  152. short DBDisable;
  153. MSG DummyMsg;        /*    Dummy message that debug proc can use    */
  154. #endif
  155.  
  156. void *dosalloc(ulong);
  157. void dosfree (ulong *);
  158. void btos(LONG, char *);
  159. void *NextNode (NODE *);
  160. void *GetHead (LIST *);
  161. LOCK *cdlock(CDROM_OBJ *, int);
  162. void cdunlock (LOCK *);
  163. CDROM_OBJ *getlockfile (LONG);
  164. char *typetostr (int);
  165. void returnpacket(struct DosPacket *);
  166. int packetsqueued (void);
  167. int Check_For_Volume_Name_Prefix (char *);
  168. void Fill_FileInfoBlock (FIB *, CDROM_INFO *, VOLUME *);
  169. void Mount (void);
  170. void Unmount (int);
  171. int Mount_Check (void);
  172. void Check_Disk (void);
  173. void Send_Timer_Request (void);
  174. void Cleanup_Timer_Device (void);
  175. int Open_Timer_Device (void);
  176. void Send_Event (int);
  177. void Remove_Seglist (void);
  178. BPTR Make_FSSM (void);
  179. void Install_TD_Interrupt (void);
  180. void Uninstall_TD_Interrupt (void);
  181. void Remove_Volume_Node (DEVLIST*);
  182.  
  183. /*
  184.  *  Don't call the entry point main().  This way, if you make a mistake
  185.  *  with the compile options you'll get a link error.
  186.  */
  187.  
  188. #ifdef __GNUC__
  189. asm(".text; jmp pc@(_handler-.+2)");
  190. #endif
  191.  
  192. #if defined(LATTICE)
  193. int __saveds handler (void)
  194. #else
  195. int handler (void)
  196. #endif
  197. {
  198.     register PACKET *packet;
  199.     register short   error;
  200.     MSG     *msg;
  201.     ubyte   notdone = 1;
  202.     char    buf[256];
  203.     void    *tmp;
  204.     ULONG   signals;
  205.     
  206.     playing = FALSE;
  207.  
  208.     /*
  209.      *    Initialize all global variables. SysBase MUST be initialized before
  210.      *  we can make Exec calls. The DOS library is opened for the debug
  211.      *  process only.
  212.      */
  213.  
  214.     SysBase = *(EXECLIB **) 4L;
  215.     DosProc = (PROC *) FindTask(NULL);
  216.     if (DosProc->pr_CLI)
  217.       return RETURN_FAIL;
  218.     DOSBase = (DOSLIB *) OpenLibrary ((UBYTE *) "dos.library",37);
  219. #ifdef __GNUC__
  220.     ixemulbase = OpenLibrary ("ixemul.library", 0);
  221. #endif
  222.     UtilityBase = (LIB *) OpenLibrary ((UBYTE *) "utility.library",37);
  223.  
  224.     BUG2(DBDisable = 0;)                /*  Init. globals    */
  225.     BUG2(Dbport = Dback = NULL;)
  226.     DevList = NUL