Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Files /
Chapter 5 - Disk Initialization Manager / Using the Disk Initialization Manager


Erasing Initialized Disks

You can use the standard interface provided by the DIBadMount function to reinitialize disks that are already initialized correctly. Doing so permanently erases their contents, but does not change their names.

To reinitialize a disk, call DIBadMount with the high word of the event message equal to the result code noErr. The DIBadMount function presents the standard interface to initialize the disk in the drive whose number is specified by the low word of the event message. However, because the Disk Initialization Manager cannot know why your application wishes to reinitialize a disk, it cannot provide the initial text for the disk initialization dialog box. Therefore, your application must use the Dialog Manager's ParamText procedure to create a customized message, as illustrated in Listing 5-2.

If you need to reinitialize a valid disk but do not have access to the event message from when the disk was formatted, you can artificially create an event message by setting the event message to an integer representing the drive number, as follows:

myEvent.message := driveNum;
Doing so sets each of the high-order bits of the artificial event message to 0, which is desired because the constant noErr is equal to 0.

Listing 5-2 defines a procedure for displaying a disk initialization dialog box that allows the user to reinitialize the disk in the drive specified by driveNum. The disk initialization dialog box displays the text specified in the myString parameter. The procedure in Listing 5-2 in turn calls a procedure named DoError. You must define DoError to
process the result code if the initialization did not successfully complete. The disk initialization dialog box does alert the user if the operation is not successfully completed, and the disk is ejected. However, your application might need to know that a formerly mounted disk is no longer mounted because reinitialization failed.

Listing 5-2 Reinitializing a valid disk

PROCEDURE DoEraseDisk (driveNum: Integer; myString: Str255);
VAR
   myPoint:          Point;            
   myErr:            Integer;          {result code}
BEGIN
   DILoad;                             {load Disk Initialization Manager}
   ParamText(myString, '', '', '');    {set dialog text}
   SetPt(myPoint, 120, 120);           {set top left of dialog box}
   myErr := DIBadMount(myPoint, driveNum);
                                       {allow user to confirm erase}
   IF myErr <> noErr THEN
      DoError(myErr);                  {respond to error, if necessary}
   DIUnload;                           {unload Disk Initialization Manager}
END;

Previous Book Contents Book Index Next

© Apple Computer, Inc.
2 JUL 1996