Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Getting free disk space?

Posted on 1998-04-27
5
Medium Priority
?
276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

722 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