Re: Determining if a file is local
Re: Determining if a file is local
- Subject: Re: Determining if a file is local
- From: Ryan McGann <email@hidden>
- Date: Fri, 26 Jun 2009 18:11:33 -0700
Hi,
I'm trying to determine whether a given file is mounted on a local
drive, or
a network drive.
I've been using statfs64(), checking f_flags & MNT_LOCAL. This seems
to work
in most cases, but it turns out that if I mount a dmg from a network
drive,
f_flags says it is local.
Does anyone know of a way to determine if a file inside a mounted
dmg is
ultimately local or remote?
This isn't exactly easy, nor do I know if it's right, but this is what
we do:
- First check the easy case (statfs)
- If that indicates a local volume, use DiskArb to get the BSD device
name for the volume
- in IOKit, find a block storage device with the same BSD device name
(IOKit property "BSD Name")
- Iterate up the IOKit device tree until you find a disk image device
in the IOKit
- Look at its "Protocol Characteristics" property, and check the
value of the "Virtual Interface Location" key. This is the path to the
disk image. Perform statfs on that path.
It's not trivial, but it's reliable—we've tested that it works on Time
Capsule devices, 3rd party NAS devices, etc. I don't have the code on
me and the algorithm is from memory so it might be slightly off, but
you can get the jist of it by looking in IORegistryExplorer.
Ryan
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden