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


Overriding the Standard Initialization Interface

The disk initialization dialog box provides an easy-to-use, standard interface for initializing and reinitializing disks. However, if you wish, you can use three low-level Disk Initialization Manager functions that accomplish the three stages of disk initialization without presenting any user interface. The three functions are DIFormat, DIVerify, and DIZero. The DIFormat function attempts to format the disk, the DIVerify function verifies whether the format was successful, and the DIZero function updates the newly initialized volume's characteristics and attempts to spare any bad blocks on the disk.

Listing 5-3 shows how to reinitialize a disk without using the standard interface. The low-level functions work only if the disk is not already mounted in the disk drive. Therefore, Listing 5-3 uses high-level File Manager calls to unmount the volume and to remember the volume's name, so that it can be restored later. Because you are no longer using the standard interface, you must define the DoError procedure so that you can alert the user about an error.

Listing 5-3 Reinitializing a validly formatted disk without using the standard interface

PROCEDURE DoEraseDisk (driveNum: Integer);
VAR
   myErr:         OSErr;                     {result code}
   volName:       Str255;                    {name of volume}
   oldVRefNum:    Integer;                   {to unmount volume}
   oldFreeBytes:  LongInt;                   {for GetVInfo call}
BEGIN
   DILoad;                                   {load Disk Init. Manager}
   myErr := GetVInfo(driveNum, @volName, oldVRefNum, oldFreeBytes);
                                             {remember name of volume}
   IF myErr = noErr THEN
      myErr := UnmountVol(@volName, oldVRefNum);
                                             {unmount the disk}
   IF myErr = noErr THEN
      myErr := DIFormat(driveNum);           {format the disk}
   IF myErr = noErr THEN
      myErr := DIVerify(driveNum);           {verify format}
   IF myErr = noErr THEN
      myErr := DIZero(driveNum, volName);    {update volume information}
   IF myErr <> noErr THEN
      DoError(myErr);                        {respond to error}
   DIUnload;                                 {unload Disk Init. Manager}
END;
If you wish, you can also respond to a user's insertion of an uninitialized or damaged disk by simply formatting the disk without using the standard interface. Listing 5-4 defines a procedure for this purpose. Listing 5-4 differs from Listing 5-3 only in that it does not begin by unmounting the volume (because the File Manager does not mount uninitialized or damaged disks).

Listing 5-4 Initializing an uninitialized disk without using the standard interface

PROCEDURE DoInitDisk (driveNum: Integer; volName: Str255);
VAR
   myErr:         OSErr;                     {result code}
BEGIN
   DILoad;                                   {load Disk Init. Manager}
   myErr := DIFormat(driveNum);              {format the disk}
   IF myErr = noErr THEN
      myErr := DIVerify(driveNum);           {verify format}
   IF myErr = noErr THEN
      myErr := DIZero(driveNum, volName);    {update volume information}
   IF myErr <> noErr THEN
      DoError(myErr);                        {respond to error}
   DIUnload;                                 {unload Disk Init. Manager}
END;

Previous Book Contents Book Index Next

© Apple Computer, Inc.
2 JUL 1996