[fa.info-mac] EjectNotify hook

info-mac@uw-beaver (12/07/84)

From: Gus Fernandez <FERNANDEZ@SUMEX-AIM.ARPA>

Subject: EjectNotify hook.
To: info-mac@SUMEX-AIM.ARPA.#Internet

I pulled this off of compuserve. Although I have not tried it, I have no
soubt that it does work. There are two minor inacuracies, however...
COMMAND-SHIFT 1-4 ARE documented in the Macintosh user manual. ((although it
is indeed something you usually learn first from a friend.)
Also, Any developemnt language worth its salt will let you modify low core.
His hook, for example, can be implemented in LISA PASCAL as follows.
 
PROGRAM EjectSample;

   CONST EjectHook = $338;

   VAR TRIX:^ProcPtr;

   Function EjectNotify(DriveNum,P2:INTEGER):BOOLEAN;

      BEGIN
	   {Your code here}
      END;


   BEGIN {Main program}
      {Init code}
      TRIX := POINTER(EjectHook);
      TRIX^ := @EjectNotify;
      {Rest of program}
   END.


Does anyone know what the second parameter might be? My initial guess is that
it might be the VolRefNum of the disk to be ejected but I am probably wrong.
I wish Apple would document these hooks!

-----------------------------------------------------

One of the undocumented, but widely known, features of the Macintosh is the
ability to eject a diskette from a drive by pressing command-shift-1 for
the internal drive or command-shift-2 for the external drive.  These
commands are implemented at a very low level in the file system and require
no support from an application program in order to work.

For some types of system and utility programs this could be a major
headache.  Suddenly a diskette that was in a drive is no longer there, and 
the file system provides no apparent way to notifiy a program that the
eject has occurred.

In fact, there is a method which I have not seen documented anywhere yet.
There is a low memory location called EjectNotify at $338 which where a
procedure pointer can be stored to a routine to be called when the user
presses command-shift-1 or -2, but before the eject actually happens.

This user written procedure should have the Pascal header:

Function EjectNotification (DriveNumber, P2: Integer): Boolean;

The drivenumber to be ejected (either 1 or 2) will be passed in the first
parameter, and the second parameter is a mystery to me.  It always seems
to contain a value of 3, but I don't know what this means...

The user procedure should return a value in the boolean.  True means allow
the eject to happen, false means ignore the request.

This method can only be used from Assembler or Consulair C, since this
implementation of C provides the capability of modifying variables in low
memory.

This function is used by the Finder to ensure that the disk directory and
the desktop file are properly updated prior to ejecting the disk, and even
to disallow the eject in some circumstances.

It is also used in the routines SFGetFile and SFPutFile to ensure that the
user does not sneek something in behind the routine's back.  It doesn't
achieve it's objective, because the user can always eject the disk with a
paperclip, and the operating system never seems to know about that type of
action.

I hope that this info is useful to someone.  I am using this procedure in
version 1.3 of Fedit, and it works.  If the above documentation is unclear,
please leave me a message or Email and I will try to clarify.

            John Mitchell     75126,3533
-------