dokan-dotnet: Unable to specify files inode
This code https://github.com/dokan-dev/dokan-dotnet/blob/master/DokanNet/DokanOperationProxy.cs#L507 Causes the inode for two completly different files to be the same if they just have the same filename.
I’m running Python scripts that copy files around on my drive.
And python’s os.path.samefile
checks if the file’s inode and deviceID are different. Which they aren’t if the files happen to have the same name.
In my case I am trying to copy a file to a different directory. So it indeed has the same name and thus the same inode. But they are still seperate files.
My proposed solution would be to provide the ability to set the inode in the FileInformation struct but keep it optional.
What could be done is have JUST GetFileInformation
return a different FileInformation struct than everywhere else which contains the full path instead of just the filename.
In my case I’m storing the FileInformation struct directly in my file node because I don’t need to generate a new one everytime.
Instead of
public NtStatus GetFileInformation(string filename, out FileInformation fileInfo, DokanFileInfo info)
{
var node = GetNode(filename, info);
if (node == null)
{
fileInfo = new FileInformation();
return DokanResult.FileNotFound;
}
fileInfo = node.fileInfo;
return DokanResult.Success;
}
I would need to
public NtStatus GetFileInformation(string filename, out FileInformation fileInfo, DokanFileInfo info)
{
var node = GetNode(filename, info);
if (node == null)
{
fileInfo = new FileInformation();
return DokanResult.FileNotFound;
}
fileInfo = new FileInformation
{
FileName = filename,
Attributes = node.fileInfo.Attributes,
CreationTime = node.fileInfo.CreationTime,
LastAccessTime = node.fileInfo.LastAccessTime,
LastWriteTime = node.fileInfo.LastWriteTime,
Length = node.fileInfo.Length
};
return DokanResult.Success;
}
But that would make GetFileInformation
from now on always return a wrong FileName.
Which is btw what the Mirror sample is already doing.
About this issue
- Original URL
- State: open
- Created 6 years ago
- Comments: 21 (11 by maintainers)
For reference (as I already forgot most of the stuff I was looking at back then)
Hash is calculated and used here: https://github.com/dokan-dev/dokan-dotnet/blob/fa556dfc3631eb8feed374322f4285cf17194f88/DokanNet/DokanOperationProxy.cs#L547
This https://github.com/dokan-dev/dokan-dotnet/blob/fa556dfc3631eb8feed374322f4285cf17194f88/DokanNet/DokanOperationProxy.cs#L515 should really just return a struct mirroring the
BY_HANDLE_FILE_INFORMATION
contents in a C# format, we can basically keep most things but just add 64bit(?) number for fileIndex (inode) and dwNumberOfLinksWe need to communicate a way to the users to still let them generate hash from filename, to make sure new users won’t be confused? Might aswell just mention a
//(uint)(fi.FileName?.GetHashCode() ?? 0)
in comments in the new struct.