Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Getting free disk space?

Posted on 1998-04-27
5
Medium Priority
?
283 Views
Last Modified: 2013-12-26
Hi all-

I've been trying to figure out how to get my program to:
a) Figure out how much free disk space there is on the Startup volume
   and
b) Figure out how much free disk space there is available on all of the computer's (writable) hard disks (maybe by looking at a list of the mounted volumes and getting the free space on each one, then adding it up)

I've spent altogether too much time searching Inside Macintosh, and I haven't gotten very far.  I've found out about the "Drive Queue" (Inside Macintosh: Files / Chapter 2 - File Manager / Data Organization in Memory / The Drive Queue) and the "GetVInfo" function (Inside Macintosh: Files / Chapter 2 - File Manager / File Manager ReferenceHigh-Level Volume Access Routines / Obtaining Volume  Information / GetVInfo), but neither of those seem to solve this problem.

If it makes a difference, I'm using CodeWarrior Pro 2 with PowerPlant.

Any help/tips/pointers would be very much appreciated!

Thanks,

Ian
0
Comment
Question by:icrew
  • 2
  • 2
5 Comments
 

Author Comment

by:icrew
ID: 1291378
Adjusted points to 500
0
 
LVL 2

Accepted Solution

by:
roov earned 500 total points
ID: 1291379
Ian,

Try using GetVInfo.
The API is:
anErr = GetVInfo(drvNum, volName, vRefNum, freeBytes);

To iterate all volumes, use:
OSErr GetIndVolume(short index,
                           short* vRefNum,
                           Str32 name)
{
      ParamBlockRec pb;
      OSErr err;
      
      pb.volumeParam.ioCompletion = NULL;
      pb.volumeParam.ioNamePtr = name;
      pb.volumeParam.ioVolIndex = index;
      
      err= PBGetVInfo(&pb,false);
      
      *vRefNum = pb.volumeParam.ioVRefNum;
      return err;
}


0
 
LVL 2

Expert Comment

by:WileyKat
ID: 1291380
That's not quite what I would have done, but if it works, great. If not, I have an idea or two.
0
 

Author Comment

by:icrew
ID: 1291381
Actually, I already solved this problem.  THe function I came up with follows.  Thanks for your help, though.

Ian

/*****************************************************************/
/*GetFreeSpace*/
/*****************************************************************/
OSErr GetFreeSpace (double *bytesFree, double *sysBytesFree) {
      OSErr error;
      HParamBlockRec tempVolInfo;
      
      *bytesFree = 0;  //set the number of bytes free to 0.
      
      Str255 tempVolName/*, tempVolSize*/;
      short tempVolRef;
      long tempFreeBytes;
      
      tempVolInfo.volumeParam.ioNamePtr = nil;
      tempVolInfo.volumeParam.ioVolIndex = 1;
      
      error = PBHGetVInfo(&tempVolInfo, false);
      
      while (error == noErr) {
            //check to make sure (as much as we can) that the volume is local and writable before adding
            //to the available disk space.            

            //Get the Driver reference numbers for AppleShare and Floppies.
            short afpRefNum;
            short floppyRefNum;
            error = OpenDriver ("\p.AFPTranslator", &afpRefNum);
            if (error != noErr) afpRefNum = -1;
            error = OpenDriver ("\p.Sony", &floppyRefNum);
            if (error != noErr) floppyRefNum = -1;

            //Get the VRefNum of the System (boot) disk
            short sysVRefNum;
            long sysDirID; //don't really need this, but FindFolder does.
            
            error = FindFolder (kOnSystemDisk, kSystemFolderType, kDontCreateFolder, &sysVRefNum, &sysDirID);
            if (error != noErr) return error;  //if we can't find the system folder, this is pretty useless.
                  
            if ((tempVolInfo.volumeParam.ioVAtrb & ((1<<7)|(1<<15))) ||
                  (tempVolInfo.volumeParam.ioVDRefNum == afpRefNum) ||
                  (tempVolInfo.volumeParam.ioVDRefNum == floppyRefNum)) {
                  /*it's (a) locked, (b) an appleshare volume, or (c) a floppy, so we skip it*/
            }
            else {
                  //if the volume is writable
                  error = GetVInfo(tempVolInfo.volumeParam.ioVDrvInfo, tempVolName, &tempVolRef, &tempFreeBytes);
                  
                  if (error == noErr) {
                        *bytesFree += tempFreeBytes;                        
                        if (tempVolRef == sysVRefNum) {
                              //SignalPStr_("\pthis is the system volume");
                              *sysBytesFree = tempFreeBytes;
                        }
                  }
                  else {
                        return error;
                  }
            }
            
            //go on to the next volume
            tempVolInfo.volumeParam.ioVolIndex++;
            error = PBHGetVInfo(&tempVolInfo, false);
      }
      
      if (error == nsvErr) {
            //this just means that we've looked at all of the avialable volumes
            return noErr;
      }
      else {
            return error;
      }
}

0
 
LVL 2

Expert Comment

by:WileyKat
ID: 1291382
Nice code.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses
Course of the Month5 days, 20 hours left to enroll

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question