I have an application that needs to find any mounted CDs and get
their TOCs.
It pretty much works under Panther, but in Tiger I get the following
problem:
When calling FSGetVolumeInfo and iterating over the volumes, the
first time I call it, it works fine. It returns me the volRef
numbers -100, -101 (for the 2 drives I always have mounted), and -112
(for example) for the currently mounted CD.
Then I eject the CD, and load a different CD, and run that code again
(during the same run of the program).
The I get -100, -101, and -112 *again*! And -112 is no longer a
valid ref number.
If I quit the program and re-launch it correctly identifies -113 as
the new CD's volume reference.
This problem is not limited to CDs - it also occurs when mounting/
dismounting iPods, for example.
My guess is that once I call FSGetVolumeInfo, it caches the volumes
for the lifespan of the current process.
Is this a bug in Tiger? And can anyone think of any way around it?
Is there any way to flush the File Manager's cache of volume
information?
Thanks,
-Arshad
Here's the code I'm using (approximately):
while (1) /* bug occurs when the code runs more than once
during the process' lifetime */
{
char x[1024];
gets(x); /* this makes it prompt me, if I hit enter it will
re-scan for volumes */
findalltocs();
printf("Reading....\n");
result = noErr;
short ref = GetDefaultAudioCDRefNum();
printf("ref : %d\n", ref);
for (volumeIndex = 1; result == noErr || result != nsvErr;
volumeIndex++)
{
FSVolumeRefNum actualVolume;
HFSUniStr255 volumeName;
FSVolumeInfo volumeInfo;
bzero((void *) &volumeInfo, sizeof(volumeInfo));
result = FSGetVolumeInfo(kFSInvalidVolumeRefNum,
volumeIndex,
&actualVolume,
kFSVolInfoFSInfo,
&volumeInfo,
&volumeName,
NULL);
printf("Vol %d %d\n", volumeIndex, actualVolume); /*
actual volume is the volume ref */
...
}
}