Re: Getting the free disk space and aquamon.
Re: Getting the free disk space and aquamon.
- Subject: Re: Getting the free disk space and aquamon.
- From: Buzz Andersen <email@hidden>
- Date: Fri, 20 Dec 2002 14:12:47 -0700
I'm trying to figure out how to get the free disk space of the boot
"disk", NOT the boot "partition". Can anyone help on this one I've
racked my brains for days over this one and haven't gotten anywhere.
Here is some code that *might* help you, but I must warn you: it
contains dreaded Carbon API calls :-). I've actually been
experimenting a lot lately with wrapping Carbon File Manager API code
to overcome some of the limitations of NSFileManager/NSFileHandle for
dealing with the OS X file system, and this is something I developed as
part of my efforts. I guess the only caveat is that (at least I
*think*--correct me if I'm wrong) this will probably only work with HFS
formatted disks (as opposed to Unix File System), but that should cover
most people anyway ;-).
Also, any Carbon gurus who want to point out glaring stupidity, feel
free :-).
#include <Carbon/Carbon.h>
- (unsigned long long) getVolumeTotalBytesForPath: (NSString *) path {
[path retain];
int vRefNum = [self _getVolumeNumberForPath: path];
unsigned long long returnValue = 0;
OSErr osErr;
FSVolumeInfo info;
osErr = FSGetVolumeInfo (vRefNum, 0, NULL, kFSVolInfoSizes, &info,
NULL, NULL);
if (osErr == noErr) {
returnValue = info.totalBytes;
}
[path release];
return returnValue;
}
- (int) _getVolumeNumberForPath: (NSString *) path {
[path retain];
FSRef pathRef;
FSPathMakeRef([path UTF8String], &pathRef, NULL);
OSErr osErr;
FSCatalogInfo catInfo;
osErr = FSGetCatalogInfo(&pathRef, kFSCatInfoVolume, &catInfo,
NULL, NULL, NULL);
int returnValue = 0;
if(osErr == noErr) {
returnValue = catInfo.volume;
}
[path release];
return returnValue;
}
--
Buzz Andersen
email: email@hidden
web:
http://www.scifihifi.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.