Under Windows: AlbumRoots uuid(s)?

Paul Norman paul at paulanorman.info
Tue May 2 11:32:55 BST 2023


Hi,

Turns out there may be no direct MS Windows call it seems for 
associating an earlier VSN (Volume Serial Label) with its drive letter. 
I was hoping that there might be a DigiKam .dll reference.

Here is a FreePascal unit for deriving this though.
The logic may be of use for any one else doing SQL on the Sqlite3 DB(s) 
and needing to do this in another programming language as well.

 >>>

unit VSN_to_Driveletter;

{$mode ObjFPC}{$H+}

interface

uses
   {$IFDEF UNIX} {$IFDEF UseCThreads}
   cthreads, {$ENDIF} {$ENDIF}
   Classes, strutils, math, SysUtils, Windows, FileUtil;

function FindVolumeSerial(const Drive: PChar): string;
function matchSerialToDriveLetter(serialNumberRequested:string):string;

implementation


function FindVolumeSerial(const Drive: PChar): string;
{ Adapted from:
http://delphi.about.com/od/windowsshellapi/a/volumeserial.htm
VSN - volume serial number
}
   var
     VolumeSerialNumber: DWORD = 0;
     MaximumComponentLength: DWORD = 0;
     FileSystemFlags: DWORD = 0;
     SerialNumber: string;

   begin
     FindVolumeSerial := '';

     // Function apparently returns true if all requested info is 
retrieved (not 0 as MSDN suggests)
     if GetVolumeInformation(Drive, nil, 0, @VolumeSerialNumber, 
MaximumComponentLength,
       FileSystemFlags, nil, 0) then
       FindVolumeSerial := IntToHex(HiWord(VolumeSerialNumber), 4) + '-' 
+ IntToHex(LoWord(VolumeSerialNumber), 4);
                                                                     // 
strictly correct to use - for Windows
   end;

function matchSerialToDriveLetter(serialNumberRequested:string): string;
var
   Drive: char;
   DriveLetter, processSerial: string;

begin

{Adapted from
http://delphi.about.com/cs/adptips1999/a/bltip0599_5.htm
VSN - volume serial number
}

   serialNumberRequested := 
stringreplace(trim(serialNumberRequested),'-','',[rfReplaceAll]);

  matchSerialToDriveLetter := #0 ;  // default - no VSN matched a drive 
letter - Not Available
                                     // replace here with whatever you need
   for Drive := 'A' to 'Z' do
    begin
     DriveLetter := Drive + ':\';
       processSerial := 
StringReplace(FindVolumeSerial(PChar(DriveLetter)),'-','',[]);

       if (UpperCase(serialNumberRequested) = UpperCase(processSerial)) 
and (processSerial <> '') then
            exit (DriveLetter);  // associated drive letter found for VSN
    end;
end;

{
https://www.phind.com/search?cache=2d76e113-646a-42ed-b0bb-5a2874969310

https://superuser.com/questions/1646947/get-hard-drive-serial-number-based-on-drive-letter-on-windows-command-line-not

https://www.phind.com/search?cache=d2628ed7-066e-4570-9446-a826ad66d147

https://forum.lazarus.freepascal.org/index.php?topic=18860.0

http://delphi.about.com/od/windowsshellapi/a/volumeserial.htm
}

end.

<<<

Kind regards,

Paul


On 28/04/2023 2:46 am, Paul A. Norman wrote:
> So far my research suggests that this Album Root reference: 
> volumeid:?uuid=4261fb3f
> is actually a Windows NTFS 0x based number which may be called by some 
> – not so much a UUID, but:
>
> c:> fsutil fsinfo volumeinfo e:
> "Volume Serial Number : 0x4261fb3f
>
> There is also:
>
> c:> fsutil fsinfo volumeinfo e:
> "NTFS Volume Serial Number : 0x164262164261fb3f
>
> ... which finishes with the same eight digits as the Volume Serial Number
>
> And again the more usually used ...
>
> E:>>mountvol.exe
> ...
> \\?\Volume{dd637aff-5761-4467-80c3-bfcb62c500e8}\
> E:\
>
> It seems to be a non trivial matter under Windows, to find the drive 
> letter associated with a “Volume Serial Number” as Digikam is using.
>
> Some background...
>
> https://www.digital-detective.net/documents/Volume%20Serial%20Numbers.pdf
>
> I can do a small FreePascal utility for this, but just needed to ask 
> first again, how or where is Digikam storing the root drive letter, or 
> how is it getting it from the “Volume Serial Number” = 
> volumeid:?uuid=xxxxxxxx
> stored as the album root(s) under Windows OS please?
>
> TIA
>
> Kind regards,
> Paul
>
>
> On 25/04/2023 7:02 pm, Paul Norman wrote:Volume Serial Number
>
> Apologies...
>
> done somehow in .ccp somewhere? :-)
>
> done somehow in .cpp somewhere?
>
> On 25/04/2023 3:01 pm, Paul Norman wrote:
>
> Hi,
>
> Under Windows you can normally do things like:
>
> E:>>mountvol.exe
> ...
> \\?\Volume{dd637aff-5761-4467-80c3-bfcb62c500e8}\
> E:\
>
> And then ...
>
> start \\?\Volume{dd637aff-5761-4467-80c3-bfcb62c500e8}\
>
> And it would open the appropriate volume in File Explorer in my case E:\
>
> My entry in Digikam for the same drive shows in digikam4.> AlbumRoots as:
>
> Identifier
> volumeid:?uuid=4261fb3f
>
> And obviously
>
> start \\?\Volume{4261fb3f}\
>
> — Is not going to work.
>
> How is:
>
> Digikam > Settings > Configure - digikam > Collections
>
> from only volumeid:?uuid=4261fb3f achieving showing drive E: as the 
> root please?
>
> Using Digikam as our prime DAM, I want to be able to query the Sqlite 
> (from Lazarus - FreePascal https://www.lazarus-ide.org/ ) and get the 
> path to any image please.
> — I can do this so far using digikam4.db.> Albums and a lookup from 
> there on AlbumRoots > albumRoot , with digikam4.db.> Images > album 
> (etc.) and that gets me right up to getting the correct drive letter 
> (or \\?\Volume{<uuid>}\) under Windows.
>
> I have not yet found anything in the Digikam data .db(s), 
> digikam_systemrc or digikamrc, to cross-reference 
> volumeid:?uuid=4261fb3f with, and assume it must be being done somehow 
> in .ccp somewhere?
>
> Any pointers appreciated please.
>
> Kindest regards,
>
> Paul
> ------------------------------------------------------------------------
> https://PaulANorman.info <https://PaulANorman.info>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/digikam-users/attachments/20230502/887405fb/attachment.htm>


More information about the Digikam-users mailing list