Re: Volume Tracking in Cocoa without Carbon?
Re: Volume Tracking in Cocoa without Carbon?
- Subject: Re: Volume Tracking in Cocoa without Carbon?
- From: Marc De Scheemaecker <email@hidden>
- Date: Wed, 16 May 2001 17:07:57 +0200 (CEST)
Hi,
I have included a little sample program that will list the mounted volumes.
For more information, see the man pages of getmntinfo and getfsstat.
--Marc
On Mon, 14 May 2001, Max Cantor wrote:
>
A hackish way of doing this would be to simply list the
>
directories in the /Volumes directory. Its not the most
>
beautiful or elegant solution, and it wont give you the startup
>
disk.
>
>
-Max
>
>
On Monday, May 14, 2001, at 02:48 PM, G. 'Andrew' Tapolow wrote:
>
>
> Hello,
>
>
>
> I'm looking for a method to get a list of mounted volumes (and
>
> theoretically their icons). At the same time I am looking for
>
> something like system even messages for disk mount and disk
>
> eject. I know where these were in the Mac OS APIs and thus know
>
> where I could look for them in Carbon. However, my goal is to
>
> work these into a Cocoa (obj-c) only app through Project
>
> Builder and have had no luck finding NSObjects or the
>
> appropriate framework through header files or documentation.
*** Sample code:
#include <stdio.h>
#include <stdlib.h>
#include <sys/param.h>
#include <sys/ucred.h>
#include <sys/mount.h>
int main(int argc, char* argv[])
{
struct statfs* mnts;
int i, mnt_count;
mnt_count = getmntinfo(&mnts, MNT_WAIT);
if (mnt_count <= 0) {
fprintf(stderr, "Could not get mount info\n");
return 1;
}
for (i = 0; i < mnt_count; i++) {
printf("i: %s of type %s is mounted on %s\n", i,
mnts[i].f_mntfromname, mnts[i].f_fstypename,
mnts[i].f_mntonname);
}
return 0;
}