Re: Determining if a file is local
Re: Determining if a file is local
- Subject: Re: Determining if a file is local
- From: Terry Lambert <email@hidden>
- Date: Fri, 26 Jun 2009 17:06:49 -0700
On Jun 26, 2009, at 6:34 AM, Tim Murison wrote:
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?
Recursively ascend the mount list until you hit / or a network drive.
I'm not sure I understand what you mean.
The type of thing that I'm stymied by is (from mount):
/dev/disk2s2 on /Volumes/installer.pkg (hfs, local, nodev, nosuid,
read-only, noowners, mounted by timm)
This is what mount shows when I mount a dmg from the network
containing
installer.pkg. If I look at installer.pkg or any of the files inside
it and
follow the mount list up, I'll hit "/Volumes/installer.pkg". I
haven't found
anyway to determine where this was mounted from, short of calling
"hdiutil
info".
You have two choices:
(1) You can use the IORegistry interfaces to get at the device tree,
which lists devices for disk images; if you do this, you will need to
translate the volume UUID into a mount point. How you get that for a
given mount point is pretty self-explanatory.
(2) You have to use "hdiutil info -plist".
man popen
You want to parse into memory the:
<dict>
<key>images</key>
<array>
<dict>
<key>image-path</key>
<string>...some path to a .dmg</string>
<key>system-entities</key>
<array>
<dict>
<key>dev-entry</key>
<string>/dev/ ...some device node matching a mounted device...</
string>
</dict>
</array>
</dict>
</array>
</dict>
elements, which will be a list of the mounted disk images. You can
use property list management code to do this, and to pull out the
properties, or you can use your favorite XML parser, or you can roll
your own.
Then you will want to check each of the mount points of each FS to see
if they match any of the <dev-entry> keys, and if so, that's a disk
image. Then you pick the longest matching prefix of the path you got
back from your list of mounted devices, and you pick the longest
matching one; that will be the volume where the disk image resides.
Since you can mount a disk image in a disk image, you will have to
repeat these steps recursively until you either hit a network mount or
the root of the FS.
-- Terry
_______________________________________________
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