The thing you need to do is to manually set the kHasCustomIcon flag in
the corresponding FolderInfo structure. The only problem is that when
the folder (ex. /Volumes/Test) is not mounted, all finder info will be
stored using HFS+ extended attributes (looks like folders themselves
do not have resource forks). And when a volume is being mounted on the
folder, all extended info will be stored in a resource file (prefixed
with "._") and all extended info set before mount will be discarded.
So, the solution is the following:
1. Create folder for mounting (ex. /Volumes/Test)
2. Mount your FS with -onoping_diskarb flag. The finder will not show
the volume.
3. Set the kHasCustomIcon flag on your folder (see listing below).
4. Notify DiskArbitration about newly mounted VFS.
An example routine for setting kHasCustomIcon property from C code is
shown below. The routine for "pinging" DiskArbitration
(ping_diskarb()) is taken from macfuse sources. The original one
cannot be used because you need to set kHasCustomIcon just after the
VFS mounts and before it appears in Finder.
//------------------------------------------
//Here comes the listing
//------------------------------------------
#include <stdio.h>
#include <CoreServices/CoreServices.h>
#include <sys/mount.h>
#include <DiskArbitration/DiskArbitration.h>
extern "C" kern_return_t DiskArbInit(void)
__attribute__((weak_import));
extern "C" kern_return_t DiskArbDiskAppearedWithMountpointPing_auto(
char *disk,
unsigned flags,
char *mountpoint
) __attribute__((weak_import));
static int
ping_diskarb(char *mntpath)
{
int ret;
struct statfs sb;
enum {
kDiskArbDiskAppearedEjectableMask = 1 << 1,
kDiskArbDiskAppearedWholeDiskMask = 1 << 2,
kDiskArbDiskAppearedNetworkDiskMask = 1 << 3
};
ret = statfs(mntpath, &sb);
if (ret < 0) {
return ret;
}
if (!DiskArbInit || !DiskArbDiskAppearedWithMountpointPing_auto) {
return 0;
}
ret = DiskArbInit();
/* we ignore the return value from DiskArbInit() */
ret = DiskArbDiskAppearedWithMountpointPing_auto(
sb.f_mntfromname,
(kDiskArbDiskAppearedEjectableMask |
kDiskArbDiskAppearedNetworkDiskMask),
mntpath);
/* we ignore the return value from the ping */
return 0;
}
OSStatus IconizeAndShowVfs(char *path)
{
FSRef ref;
OSStatus st = FSPathMakeRef((const UInt8*)path, &ref, 0);
if (st != KERN_SUCCESS)
return st;
FSCatalogInfo info;
st = FSGetCatalogInfo(&ref, kFSCatInfoFinderInfo, &info, 0, 0, 0);
if (st != KERN_SUCCESS)
return st;
((FolderInfo*)info.finderInfo)->finderFlags = kHasCustomIcon;
st = FSSetCatalogInfo(&ref, kFSCatInfoFinderInfo, &info);
if (st != KERN_SUCCESS)
return st;
ping_diskarb(path);
return KERN_SUCCESS;
}
int main (int argc, char * const argv[]) {
if (argc < 2)
{
printf("Usage: iconizer <mount path>\n");
return 1;
}
OSStatus st = IconizeAndShowVfs(argv[1]);
if (st != KERN_SUCCESS)
printf("Cannot iconize with status %d!\n", st);
return 0;
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"macfuse-devel" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/macfuse-devel?hl=en
-~----------~----~----~----~------~----~------~--~---