Recent

Author Topic: [RESOLVED] Significant Discrepancy in FindAllFiles in 64-bit code vs 32-bit code  (Read 4176 times)

ASBzone

  • Hero Member
  • *****
  • Posts: 678
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
On this machine, I'm running Lazarus 1.8.4 with FPC 3.0.4

I have the 32-bit edition installed, plus cross-compile to 64-bit.

I've tested the code generation from several Windows 10 x64 systems, and I've tested the resulting executables on Windows 10, Windows Server 2012-R2, and Windows Server 2016, and the results are similar.   (Identical on same platforms)

The 32-bit compiled code finds less files which clearly exist as compared to a DIR command or other file manipulation.
The 64-bit compiled code finds all the same files.

The 32-bit list is much smaller (when I use larger search criteria).   I found this while testing output from my 32-bit and 64-bit utility...

It affects FindFirstFileExW as well.

Please see the attached sample code.

« Last Edit: November 30, 2018, 03:23:49 pm by ASBzone »
-ASB: https://www.BrainWaveCC.com/

Lazarus v2.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Significant Discrepancy in FindAllFiles in 64-bit code vs 32-bit code
« Reply #1 on: November 29, 2018, 07:26:55 pm »
The system32 folder is a bit of a strange one.
64-bit processes will find other files there than 32-bit processes.

Bart

ASBzone

  • Hero Member
  • *****
  • Posts: 678
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: Significant Discrepancy in FindAllFiles in 64-bit code vs 32-bit code
« Reply #2 on: November 30, 2018, 05:01:55 am »
@Bart, I was so ready to contest that statement, but I tested with a different utility -- compiled in C++ -- and it turns out that you are quite correct.

Which is somewhat comforting, since I didn't want to think that I had broken utilities out there.

So, then, there is nothing to fix, eh?    :-[
-ASB: https://www.BrainWaveCC.com/

Lazarus v2.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)

440bx

  • Hero Member
  • *****
  • Posts: 3945
Re: Significant Discrepancy in FindAllFiles in 64-bit code vs 32-bit code
« Reply #3 on: November 30, 2018, 05:37:52 am »
As Bart mentioned, the Windows system folders are special cases.  The results will be different depending on the bitness of the program. 

The difference is likely due to file system redirection.  You can temporarily disable redirection using Windows APIs.  Once redirection is disabled, the results between the two programs will be much closer (I hesitate to say the same because Windows has a way of doing unexpected things behind a program's back.)

check out:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365743(v=vs.85).aspx

HTH
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

ASBzone

  • Hero Member
  • *****
  • Posts: 678
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: Significant Discrepancy in FindAllFiles in 64-bit code vs 32-bit code
« Reply #4 on: November 30, 2018, 05:43:15 am »
So, then, there is nothing to fix, eh?    :-[

I ran my utility against the entire Windows folder, to see if this was just limited to System32 or what.

I only tracked for files up to 1000 bytes, just to make it fast.

Thanks again for that insight, @Bart.  Now I just have to do some digging at Microsoft to see why that approach was taken.

(My attachments are too big, unfortunately -- just accept that there was a huge file discrepancy: 46117 files via 32-bit code, 46314 files via 64-bit code)
-ASB: https://www.BrainWaveCC.com/

Lazarus v2.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)

ASBzone

  • Hero Member
  • *****
  • Posts: 678
  • Automation leads to relaxation...
    • Free Console Utilities for Windows (and a few for Linux) from BrainWaveCC
Re: Significant Discrepancy in FindAllFiles in 64-bit code vs 32-bit code
« Reply #5 on: November 30, 2018, 05:47:09 am »
check out:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365743(v=vs.85).aspx

HTH


It does indeed help!

I had forgotten all about WOW64 redirection, and didn't even consider it would apply here.   Now, I just have to add the code to adjust for that when the 32-bit version is running so that I can accurately track changes on a disk.

Good stuff.  Thank you kindly.
-ASB: https://www.BrainWaveCC.com/

Lazarus v2.2.7-ada7a90186 / FPC v3.2.3-706-gaadb53e72c
(Windows 64-bit install w/Win32 and Linux/Arm cross-compiles via FpcUpDeluxe on both instances)

My Systems: Windows 10/11 Pro x64 (Current)

CCRDude

  • Hero Member
  • *****
  • Posts: 596
You can also use the SysNative folder in a 32 bit application to access the 64 bit system folder :)

 

TinyPortal © 2005-2018