List of all Volumes

A user of one of my soft under Catalina reported me strange things. To clarify the problem, I sent him a small app with a code like :

[code]Dim iNbre, DerVol as Int16
Dim VolAbsPath(-1) as String

DerVol = FolderItem.LastDriveIndex
For iNbre = 0 to DerVol
VolAbsPath.AddRow FolderItem.DriveAt(iNbre).Name
Next iNbre

TextAreaVols.Value = String.FromArray(VolAbsPath, EndOfLine)
[/code]

He answered me that he click a first time the button (which contains the code above) and the result was :

MP2013 vm Backup2013 Win10-MP2013 TRANSFER_13 Sonstiges home MP2013_Kopie - Daten MP2013_Kopie Recovery MP2013 MP2013 - Daten MP2013 MP2013 - Daten
And without doing anything click again the button later and the result was :

MP2013 vm Backup2013 Win10-MP2013 TRANSFER_13 Sonstiges home MP2013_Kopie - Daten MP2013_Kopie

I don’t use TimeMachine. Are those volumes (Recovery and the volumes after) volumes of Time machine ? There are not on the desktop of the mac (neither than vm and home). Xojo see them a time and not the time after ???
I suppose there is no Xojo instruction to get only the “normal” Volumes which are on the Desktop ? Maybe should I get the permission of the volumes and ignore those with specific permissions ?

Chances are they’re just not mounted such that they’re visible to Finder. Installer packages will sometimes do this if they’re installing software from other vendors that is code signed into a DMG.

From the list seen above, I think you can catch for volume names “home” and “Recovery” to exclude them within your code.
No idea yet about “vm”, for example.

Aren’t these invisible by default ?

In the Script Editor, type: list disks
you will get:

{“Macintosh HD”, “home”, “net”}

Only “Macintosh HD” is a mass storage device. The other two are invisibles (by the Finder).

Ugh, where does “LastDriveIndex” and “DriveAt” come from? Not from the new Xojo API, I hope? Because, drive is not the same as volume, and this appears to mean volumes, not drives.

Hi, Xojo Help FolderItem.DriveAt .
You’re pointing that a drive is a physical disk (or usb stick or etc.) which can be internal or external. And a disk can be partitioned in many volumes. That’ts it ?
If I enter list disks in Script Editor I get :

{"MBtom-HD1", "VM", "MBtom-HD2", "home", "net"}

and in Xojo my loop above returns :

MBtom-HD1 vm MBtom-HD2 home net
I have an internal SSD which is partitioned in 2 volumes “MBtom-HD1” and “MBtom-HD2”.

Script Editor instruction should be “list volumes” as Xojo instructions should be “VolumeAt” and “LastVolumeIndex”.

Yes. That that’s not clear to whoever came up with the names at Xojo makes me shake my head in disbelief.

And I agree that AppleScript gets this wrong, too. Though, as an excuse, back in the early 90s disks were still near-equivalent to volumes, though even then the term volume was already clearly defined and used. Still, shame on them, too, for this misnomer.

Besides that, the “normal” way to get the volumes on a Mac would be to use https://developer.apple.com/documentation/foundation/nsfilemanager/1409626-mountedvolumeurlsincludingresour with the NSVolumeEnumerationSkipHiddenVolumes option.

However, that doesn’t unify or sort out the new volume types since Catalina and Big Sur. The first error in Xojo’s implementation seems to be that they do not suppress the hidden volumes, unless you can test the hidden property and sort them out yourselves (that’d be the better solution as long as it’s documented to be aware of that)?

The more annoying part is that eben with the NSVolumeEnumerationSkipHiddenVolumes option you’ll get the extra volumes on Big Sur that you surely are not interested in and that the Finder hides to the user. In a way, to support low level functionality, it would still be useful if Xojo would return them, but then Xojo needs to provide a way to determine their new volume types that tell you whether it’s part of a Volume Group, and of which kind.

I must admit that I have not figured out how to tell them apart myself, yet. Does someone know which API to use to get the Volume Group identifications?

Actually, I now realize that my code that would turn up all the hidden volumes was written poorly, based on wrong assumptions I made when I wrote this under Catalina. These assumptions do not fit with Big Sur any more.

But the gist of it is: The aforementioned NSWorkspace method is the right one to identify just the vols as the Finder sees them.

I have working code in ObjC and Xojo with MBS. Doing this with declares is a bit more work, though. Do you use MBS? Then I can supply you with a solution.

No I don’t use MBS. I know there are wonderful AddOns but I develop in my sparetime asking some donations for my softwares but I don’t receive many money then I just buy Xojo.

This volume problem is not so important for me. I just check in one of my softwares if many volume have the same name to alert the user that if he quit the application (then I save the path) he may reload the same item from another disk (if there is exactly the same volume and the same subfolders).

Okay. It’s also possible to do that with the old macOSlib code (which I updated to work on 64 bit).

And to all the others who may be interested in this, including the Xojo engineers, possibly, here’s some ObjC code that shows how to see all volumes, and then look at the various flags (hidden, browsable) to determine the relevant properties of each volume:

[code]static void listVols()
{
NSArray<NSString*> keys = @[NSURLNameKey,NSURLVolumeIsBrowsableKey/,NSURLVolumeIsAutomountedKey*/,NSURLVolumeIsRootFileSystemKey,NSURLIsHiddenKey];
NSArray<NSURL*> *vols = [NSFileManager.defaultManager mountedVolumeURLsIncludingResourceValuesForKeys:keys options:0];

NSMutableArray <NSString*> *lines = [NSMutableArray new];
for (NSURL *url in vols) {
	NSDictionary<NSURLResourceKey,id> *dict = [url resourceValuesForKeys:keys error:NULL];
	NSMutableArray <NSString*> *props = [NSMutableArray new];
	for (NSString *key in keys) {
		if ([key isEqualToString:NSURLNameKey]) continue;
		[props addObject:[NSString stringWithFormat:@" %@: %@", key, dict[key]]];
	}
	[lines addObject:[NSString stringWithFormat:@"-- %@ (%@) --\

%@", dict[NSURLNameKey], url.path, [props componentsJoinedByString:@" |"]]];
}

NSLog(@"\

%@", [lines componentsJoinedByString:@"
"]);
}
[/code]

On my Big Sur system (with two visible volumes: System and Shared), this prints:

-- System (/) -- NSURLVolumeIsBrowsableKey: 1 | NSURLVolumeIsRootFileSystemKey: 1 | NSURLIsHiddenKey: 0 -- VM (/System/Volumes/VM) -- NSURLVolumeIsBrowsableKey: 0 | NSURLVolumeIsRootFileSystemKey: 0 | NSURLIsHiddenKey: 0 -- Preboot (/System/Volumes/Preboot) -- NSURLVolumeIsBrowsableKey: 0 | NSURLVolumeIsRootFileSystemKey: 0 | NSURLIsHiddenKey: 0 -- Update (/System/Volumes/Update) -- NSURLVolumeIsBrowsableKey: 0 | NSURLVolumeIsRootFileSystemKey: 0 | NSURLIsHiddenKey: 0 -- xarts (/xarts) -- NSURLVolumeIsBrowsableKey: 0 | NSURLVolumeIsRootFileSystemKey: 0 | NSURLIsHiddenKey: 0 -- iSCPreboot (/System/Volumes/iSCPreboot) -- NSURLVolumeIsBrowsableKey: 0 | NSURLVolumeIsRootFileSystemKey: 0 | NSURLIsHiddenKey: 0 -- Hardware (/System/Volumes/Hardware) -- NSURLVolumeIsBrowsableKey: 0 | NSURLVolumeIsRootFileSystemKey: 0 | NSURLIsHiddenKey: 0 -- Shared (/Volumes/Shared) -- NSURLVolumeIsBrowsableKey: 1 | NSURLVolumeIsRootFileSystemKey: 0 | NSURLIsHiddenKey: 0 -- home (/System/Volumes/Data/home) -- NSURLVolumeIsBrowsableKey: 0 | NSURLVolumeIsRootFileSystemKey: 0 | NSURLIsHiddenKey: 1

So, as you can see, the hidden property is not really helpful. Instead, it’s the NSURLVolumeIsBrowsableKey that identifies whether the Finder shows it.
Also, this doesn’t include the linked " - Data" volumes, which is probably a good idea when using FolderItem to look at the contents of a volume as the Finder sees it.

Don’t forget you also have shell script options as well.

set volumes to do shell script "ls /volumes/"

or

set volumes to do shell script "diskutil list"

It does
http://documentation.xojo.com/api/files/folderitem.html
Shared Properties
DriveCount LastDriveIndex
Shared Methods
DriveAt

[quote=497644:@Detlef Kahner]From the list seen above, I think you can catch for volume names “home” and “Recovery” to exclude them within your code.
No idea yet about “vm”, for example.[/quote]
Unless the user happens to have named one of its volumes “Home” or “Recovery”.

That’s a valid point, but the user may mount that same volume only after you’ve saved the path (e.g. “tomorrow”) and you won’t notice he has 2 volumes named the same when you save.
Normally, you should consider GetSaveInfo and GetRelative for this.

1 Like

You may also use the low level statfs call. See declare not working in 64-bit

The person who reported me the problem wrote me again :

When Time Machine is working, my program see the “hidden” disks which have the same name as the “normal” disks. As soon as Time machine finished its job, the problem of double disk with same name disappeared.
Disk Util never see the double disks that my application see.

As mentioned above, there is a problem with the instruction volume . I think it should be Disk or Drive or ??? with a optional Flag to see or not the hidden disks (then in one case only the disks we seen in the Finder, and in the other case all the disks).

If I could see this behaviour (I’m not on Catalina (no pun intended :stuck_out_tongue:)), I’d inspect the duplicate volumes properties. I’m sure there’s something to differentiate between the original one and the Time Machine “copies” (like the mount point, a read-only status, etc.).

Since this happens on someone else’s computer, I’d try one of these:
• If you know the person well enough, ask for remote debugging to its computer
• Make a quick app which logs each property of both disks (e.g. to a file) and ask the person to open this app while the behaviour happens. Then (s)he returns the file to you
• If someone else has Catalina and Time Machine, this behaviour must also occur (otherwise, it’s a bug to your person’s computer). You should be able to reproduce the behaviour quite easily and examine the properties of each similar volume.

If you can put the results here, I’m sure someone would find a difference (or you, before even posting the results here).

I did some test on my Mac and I send her a test program (made with Xojo). It seems that volume with .Visible and .IsReadable to False don’t appear on the desktop and in the dialogbox to choose folder (or file).
Then I ignore them, and I ignore too the second disk (#1) named “vm”. We don’t see it neither but its flag .Visible and .IsReadable are True .