I like to find a way to identify network volumes, and whether they're run by certain servers, e.g. specifically whether they're on a Synology or QNAP NAS.
Reason is that Synology and QNAP, while apparently supporting the Spotlight-over-SMB API, both come with a lot of bugs, requiring me to work around them when searching on those volumes with the macOS Spotlight API.
I could, of course, ask the user to "configure" each mounted volume in my software, but I'd rather do this automagically, if possible, as it's less prone to user mistakes.
So, my question is: Is there a way to learn a bit more about the server of a mounted network volume? E.g., if I could learn its IP address, I could try to connect to it via http protocol and then maybe get a useful response that identifies it as being from Synology.
I've tried to find some data in the IORegistry, but that doesn't seem to store anything about network vols. The statfs
function doesn't seem to give me anything for that either, nor do the various fcntl
calls as far as I could tell.
I also checked with the DA apis, e.g.:
DASessionRef daSession = DASessionCreate (NULL);
CFURLRef furl = CFURLCreateWithFileSystemPath(NULL, CFSTR("/Volumes/TheNAS"), kCFURLPOSIXPathStyle, true);
DADiskRef daDisk = DADiskCreateFromVolumePath (NULL, daSession, furl);
if (daDisk) {
CFDictionaryRef daInfo = DADiskCopyDescription (daDisk);
NSLog(@"%@", daInfo);
}
However, this only prints basic information:
DAVolumeKind = smbfs;
DAVolumeMountable = 1;
DAVolumeName = TheNAS;
DAVolumeNetwork = 1;
DAVolumePath = "file:///Volumes/TheNAS/";
Where, then, does Finder's "Get Info" get the smb path from, for example? Similarly, where does the mount
command get the paths from?
Example of bugs with Synology's and QNAP's Spotlight search.
This is how you'd search for a file by partial name:
mdfind -onlyin /Volumes/TheNAS "kMDItemFSName=='*ubname*'c"
The "c" means that it should be case-insensitive, whereas the "*" are placeholders.
Synology doesn't handle the "c" option at all, though, meaning that if the case does not match, the file name won't be found. QNAP also ignores this option, but at least always ignores case, meaning that names with non-matching case will still be found.
Worse on QNAP, though, is that partial words in a name won't ever be found. So, if you have a file name "Substring", the above search example won't find it. OTOH, Synology can handle partial words in names, at least.
On Synology, the only work-around for finding names without matching case is to use the wildcard search, i.e. like this:
mdfind -onlyin /Volumes/TheNAS "*=='ubname'"
OTOH, on QNAP this won't help (i.e. I am not able to find partial word matches at all using Spotlight), while on Synology I can use the wildcard work-around, even though this will also give false positives because it'll also include matches for content and other metadata I was not asking for.
So, it's all a mess, sadly. Wouldn't it have been nice if Apple had provided a test suite that 3rd parties could use to validate their Spotlight services?