Re: [Q] Determining startup volume
Re: [Q] Determining startup volume
- Subject: Re: [Q] Determining startup volume
- From: Chris Ridd <email@hidden>
- Date: Sat, 19 Oct 2002 09:52:18 +0100
On 19/10/02 8:17 am, Mark de Jong <email@hidden> wrote:
>
Hi!
>
>
Is there a way to determine if a given path or URL is on the startup
>
volume? I saw the "mountedLocalVolumePaths" and
>
"mountedRemoveableMedia" messages in "NSWorkspace", however, they don't
>
seem to be exactly what I'm looking for.
>
>
The best solution would be to limit an "NSOpenPanel" to the startup
>
volume, but I'm not sure how to determine if a given path is on the
>
startup volume.
>
>
Any suggestions? I didn't see anything in NSURL, either ... but I could
>
have missed it.
Try the POSIX API. Use stat to get the device number (st_dev) for "/" (I
think that equates to your startup volume) and your given path. If they're
on the same device the device numbers should be the same. If not...
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
int main(int argc, char **argv)
{
struct stat sb;
if (argc != 2) {
fprintf(stderr, "Usage: %s filename\n", argv[0]);
return 1;
}
if (stat("/", &sb) == 0) {
printf("/ device is %ld\n", (long)(sb.st_dev));
}
if (stat(argv[1], &sb) == 0) {
printf("%s device is %ld\n", argv[1], (long)(sb.st_dev));
}
return 0;
}
Cheers,
Chris
_______________________________________________
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.