• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Obtain available disk space?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Obtain available disk space?


  • Subject: Re: Obtain available disk space?
  • From: Darkshadow <email@hidden>
  • Date: Mon, 7 Nov 2005 05:05:53 -0500


On Nov 6, 2005, at 9:01 PM, Will Mason wrote:

getfsstat(2) will tell you everything about free and used space on all mounted volumes, however determining which mounted file system is the "main partition" is up to you. Perhaps someone else can offer advice on how to determine which is the main partition.

 Cheers,
 Will

----- Original Message ----

Hi,
I am looking for an API to obtain the amount of disk space left on
the main partition of a system. I link against carbon too, so that is
ok if it is carbon calls. Can anyone lead me in the right direction,
or even better have a function that already does this?

Cheers
~J


If you have the path of a file on the partition you want to look at, then this code will do it:

Standard disclaimer, typed in Mail, not tested.

#import <sys/param.h>
#import <sys/mount.h>

- (NSNumber *)freeSpaceFromFileOnDrive(NSString *)filePath
{
	struct statfs fs;
	long blocksize
	unsigned long spaceFree;
	int dummy;

	(void)getbsize( &dummy, &blocksize );

	if ( (statfs( [filePath fileSystemRepresentation], &fs )) < 0 )
		return [NSNumber numberWithUnsignedLong:0];

spaceFree = (fs.f_bsize < blocksize) ? (fs.f_bavail / (blocksize / fs_fbsize)) : (fs.f_bavail * (fs.f_bsize / blocksize));

	return [NSNumber numberWithUnsignedLong:spaceFree];
}

Hope that helps,

Darkshadow
(aka Michael Nickerson)


Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: Obtain available disk space? (From: Will Mason <email@hidden>)

  • Prev by Date: Re: Trouble with MakeFSSpec
  • Next by Date: Start an application with a panel
  • Previous by thread: Re: Obtain available disk space?
  • Next by thread: AMViewAnimation—An NSView Category for Easy Animation
  • Index(es):
    • Date
    • Thread