Solved

free disk space

Posted on 2001-08-07
1
653 Views
Last Modified: 2013-12-26
i need a function in c that takes as a parameter a pathname. using this the function needs to return the free disk space in bytes of the volume that contains the passed in path.

i have used the sample code from FullPath.c, which i found included with the Metroworks compiler as well as on Apple's website itself. however, this code does not work with macOS8.6.

i need this routine to work with macOS8.6 and 9.0.
my routine only uses carbon compatible stuff and yet it fails.

--------------- here is what i tried (note: some things are defined elsewhere UINT32, UINT64, etc)

UINT32 diskFreeSpace( const TCHAR *szPath ) {
     OSErr result;
     FSSpec spec;
     AliasHandle alias;
     Boolean wasChanged;
     Str32 nullString;
     FSVolumeInfo volInfo;
     UINT64 freeBytes = 0;
     nullString[ 0 ] = 0;
     result = NewAliasMinimalFromFullPath( strlen( szPath ), szPath, nullString, nullString, &alias );
printf( "NewAliasMinimalFromFullPath (result = %d)\n", result );
     if( result == noErr ) {
          result = ResolveAlias(NULL, alias, &spec, &wasChanged);
printf( "ResolveAlias (result = %d)\n", result );
          if( spec.vRefNum == 0 ) {
               spec.parID = 0;
               spec.name[0] =  0;
          }
          DisposeHandle((Handle)alias);
          result = FSGetVolumeInfo( spec.vRefNum, 0, NULL, kFSVolInfoBlocks, &volInfo, NULL, NULL );
printf( "FSGetVolumeInfo (result = %d)\n", result );
          if( result == noErr ) {
printf( "blocksize = %d\nfreeblocks = %d\n", volInfo.blockSize, volInfo.freeBlocks );
               freeBytes = (UINT64)(volInfo.blockSize) * (UINT64)(volInfo.freeBlocks);
               if( freeBytes > (UINT64)0xffffffff ) return (UINT32)0xffffffff;
               return (UINT32)freeBytes;
          }
     }
     return 0;
}

----------------- this is the (correct) output on macOS9.0

path = "Macintosh HD:Desktop Folder:FreeSpaceTest:"
NewAliasMinimalFromFullPath (result = 0)
ResolveAlias (result = 0)
FSGetVolumeInfo (result = 0)
blocksize = 4096
freeblocks = 4421296

----------------- this is the (failed) output on macOS8.6

path = "Macintosh HD:Desktop Folder:FreeSpaceTest:"
NewAliasMinimalFromFullPath (result = 0)
ResolveAlias (result = 0)
FSGetVolumeInfo (result = -50)

0
Comment
Question by:musashi
[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
1 Comment
 

Accepted Solution

by:
dioncrannitch earned 300 total points
ID: 7084855
I think the problem here is that FSGetVolumeInfo (and all the other FSXXX calls) only works on Mac OS 9 and higher. You can tell because in the header information it says it is available "in InterfaceLib 9.0 and later".

I use PBXGetVolInfoSync like this:

     paramBlock.ioNamePtr = nil;
     paramBlock.ioVRefNum = vRef;
     paramBlock.ioXVersion = 0;
     paramBlock.ioVolIndex = 0;

     result = PBXGetVolInfoSync(&paramBlock);
     if (result == noErr)
          freeBytes = paramBlock.ioVFreeBytes;

which should work on 8.5 and higher.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

707 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