[Development] QStorageInfo

Rutledge Shawn Shawn.Rutledge at digia.com
Tue Aug 26 11:22:32 CEST 2014


On 26 Aug 2014, at 8:19 AM, Bo Thorsen wrote:
> Which is probably the way people will have to go about doing it. Since 
> this distinction isn't reliably available on Linux and it is on Windows, 
> then the proper way would be to be able to get the native handle on the 
> drive to call Windows methods on it.

But see again what I wrote a couple of days ago: QStorageInfo should not report that a network drive is NTFS.  On Linux, an NFS mount has fileSystemType "nfs".  On OS X, if I mount a Windows drive and run the storageview example, that drive has fileSystemType "smbfs".

So even after over-simplifying, we already have API which is inconsistent on Windows compared to the other platforms.  This is making the problem of how to identify network drives worse, so IMO some kind of fix needs to be done.  I wrote up https://bugreports.qt-project.org/browse/QTBUG-40980 but I didn't find a Windows API to directly give us that string: the network protocol used to mount the drive.  see http://stackoverflow.com/questions/10800616/determine-protocol-of-a-network-drive

This version of the patch was the last one which had RemoteVolume as a VolumeTypeFlag:

https://codereview.qt-project.org/#/c/73945/41/src/corelib/io/qvolumeinfo.h

and here

https://codereview.qt-project.org/#/c/73945/41/src/corelib/io/qvolumeinfo_win.cpp

is how to use GetDriveType on Windows.  (Even the current version uses it internally and doesn't expose the result.)  And here (line 318)

https://codereview.qt-project.org/#/c/73945/41/src/corelib/io/qvolumeinfo_unix.cpp 

is a (primitive) way of consulting a list of known network types on Linux.  It's unfortunate to need such a list at all, but if there really is no other way to find out, maybe it's not so bad?  I don't worry much about the maintenance burden because new filesystem sharing protocols are not invented very often, and anyone can submit a patch to add a new one to the list.

After the harrowing review process (92 rounds of patches over 9 months!) the VolumeTypeFlag didn't end up in the final patch.  It's a credit to Ivan that he had the patience to finally get the current form of QStorageInfo into 5.4 branch at all.  But obviously some users have a need to distinguish network drives from local ones anyway, so IMO there's nothing wrong with writing another patch to make this info available again.  Of course trying to distinguish all the other types: internal, removable, optical, and RAM drives, would probably be futile on many platforms.  We have several bools already, so how about adding a bool isRemote() accessor?

If we don't do that, then we know what to expect: some developers will try to make their own lists of network drive types (incomplete of course) and check the fileSystemType against the list.  (And it won't even work on Windows.)  In a global way of thinking it's much worse to impose this burden than to take it upon ourselves.  And yet on Windows  GetDriveType can already tell us whether it's a network volume or not.  That is what the original poster is asking for, and it doesn't seem so hard to provide.




More information about the Development mailing list