ZTree.com  | ZEN  | About...  

 Index   Back

Need more info   [Zeta]

By: Ben Kent       
Date: Sep 22,2023 at 08:06
In Response to: Need more info (Kim Henkel)

> > My long path testing directories still exist

> Is this a single root-level 1275 character pathname, or a series of
> child paths?
> Would be great if you could share a script to repro it here, thanks.


Kim

NTFS, like most file systems that I know of have a 255 limit on directory entry names, so I'm testing in a multi level branch, to get past the ZMAX_PATH limit.




Here are listings of the problem branch, not all of the objects will be needed to show the error.

At here, I had to split the path because of the Forum word length limits
C:\Users\user1\Documents\_Working\ZTree\LongName\
.\x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000
.\10000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000
.\1000000000000000000000000000000000000000000000000000000000000000
.\10000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000
.\10000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000
.\10000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000
.\1000000000000000000000000000000000000000000000000000000000000000
.\1000000000000000000000000000000000000000000000000000000000000000

Direstories
12345678
d00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000
qwertyui

Files
1.txt
12.txt
123.txt
1234.txt
1a.txt
f00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000
t0000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000.txt



To create the objects over ZMAX_PATH, I use the powershell below to call the CreateFileW(), CreateFileW() and CloseHandle() API's, I 'm sure you could do the same using C.

To cause the crash, DW, *, get the "Error: File/path name too long [206]", dismiss the error, cursor down until on the over ZMAX_PATH directory, which for a second or two shows "Directory not logged", then BANG.

Also, I think, if I make a Alt-ZLog with the over ZMAX_PATH directory in memory, then ZTree will crash when loading the ZLog file, I haven’t done a proper testing round for that issue.


One way to handle the issue would be to not log (i.e. skip) over ZMAX_PATH directories, and use the - (minus symbol) marker in the left hand column of the Directory Window, to let the user know that there a directories in the file system that are not logged.
The help file states this for - (minus symbol), the text would need adjusting, if the skip logging of over ZMAX_PATH directories logic was implemented.
"Files in the directory are logged. All its files are in memory, but some or all of its subdirectories have been unlogged and removed from the display with the Shift-Numpad-minus command."

=================================
$signature = @'
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern IntPtr CreateFileW(
string filename,
System.IO.FileAccess access,
System.IO.FileShare share,
IntPtr securityAttributes,
System.IO.FileMode creationDisposition,
uint flagsAndAttributes,
IntPtr templateFile);

[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool CreateDirectoryW(String path, IntPtr securityAttributes);

// From https://social.technet.microsoft.com/For...ysical-disk?forum=winserverpowershell
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool ReadFile(IntPtr hFile, [Out] byte[] lpBuffer, uint nNumberOfBytesToRead, ref int lpNumberOfBytesRead, IntPtr lpOverlapped);

[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError=true)]
public static extern bool CloseHandle(IntPtr hObject);

[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError=true)]
public static extern uint GetFileSize(IntPtr hFile, IntPtr lpFileSizeHigh);

[DllImport("Kernel32.dll", SetLastError = true)]
public static extern uint GetLastError();

[StructLayout(LayoutKind.Sequential)]
public class SECURITY_ATTRIBUTES
{
internal int nLength = 0;
// don't remove null, or it will fail to set the default ACL, making the folder inaccessible and non-removeable
public IntPtr? pSecurityDescriptor = null;
//or
// unsafe is available if compile with /unsafe flag, https://docs.microsoft.com/en-us/dotnet/csharp/misc/cs0227
//internal unsafe byte* pSecurityDescriptor = null;
internal int bInheritHandle = 0;
public IntPtr lpSecurityDescriptor;
};

'@

$Kernel32 = Add-Type -MemberDefinition $signature -Name 'CreateFile' -Namespace 'pinvoke' -PassThru


$dirpath = 'C:\...';
$filepath = 'C:\...';

$CreateResult = $Kernel32[0]::CreateDirectoryW($dirpath, [System.IntPtr]::Zero);
Write-Host "CreateResult=$CreateResult";

$FileHandle = $Kernel32[0]::CreateFileW($filepath, [System.IO.FileAccess]::Read, [System.IO.FileShare]::None, [System.IntPtr]::Zero, [System.IO.FileMode]::OpenOrCreate, [System.UInt32]0x02000000, [System.IntPtr]::Zero);
Write-Host "FileHandle=$FileHandle";

$CloseResult = $Kernel32[0]::CloseHandle($FileHandle)
Write-Host "CloseResult=$CloseResult"
=================================


Ben

269 views      
 

Messages in this Thread

 
96,664 Postings in 12,235 Threads, 350 registered users, 208 users online (0 registered, 208 guests)
Index | Admin contact |   Forum Time: Jun 22, 2024 - 6:09 pm UTC  |  Hits:65,461,999  (85,804 Today )
RSS Feed