Why does dokan repeat CreateFile, ReadFile?

188 views
Skip to first unread message

고민석

unread,
Oct 7, 2020, 10:24:37 PM10/7/20
to Dokan
Hello.
My name is Ko.

Thanks for me to use dokan dll.

I'm C# developer. 
I make network drive use ftp/sftp.

I'm following your code.

I debug this sample, to many stop a few methods.
method name [CreateFile , ReadFile]
Therefore my sftp server was overload stats.
I use not cache.

Then, this sample not open txt file.
check this issue. plz.

thanks for your interest.

Adrien JUND

unread,
Oct 8, 2020, 3:05:50 AM10/8/20
to do...@googlegroups.com
Hi!

The CreateFile and readfile comes from applications on your system that tries to read data from the dokan virtual drive. You can print the process ID from the dokan info structure parameter.
Or use procmon software to see filesystem activity which might be more easy.

Best regards 
Liryna 

--
You received this message because you are subscribed to the Google Groups "Dokan" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dokan+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dokan/29f2bc34-ad58-49e9-9967-027e13f28b9bn%40googlegroups.com.

Ko

unread,
Oct 11, 2020, 9:22:04 PM10/11/20
to Dokan
Thanks for your resend.

I understand your advice.
Then my project read many times 'ReadFile' method.
Your sample didn't call 'ReadFile' method before did not open file.

I made 'CreateFile' method on your 'CreateFile' method.
Why my project called this Method?

I send my source. Can you check my source??..

manager is my sftp control class.

         private string GetPath(string fileName)
        {
            return "/" + fileName.Replace(@"\", "/");
        }

        public NtStatus CreateFile(string fileName, DokanNet.FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, IDokanFileInfo info)
        {
            fileName = GetPath(fileName);

            try
            {
                if (info.IsDirectory)
                {
                    switch (mode)
                    {
                        case FileMode.Open:
                            try
                            {
                                if (manager.IsDirectory(fileName))
                                    return NtStatus.Success;
                                else
                                    return NtStatus.ObjectPathNotFound;

                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.ToString());
                                return NtStatus.ObjectPathNotFound;
                            }
                        case FileMode.CreateNew:
                            try
                            {
                                if (manager.MakeDirectory(fileName))
                                    return NtStatus.Success;
                                else
                                    return NtStatus.Error;
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex.ToString());
                                return NtStatus.Error;
                            }
                        default:
                            return NtStatus.Error;
                    }
                }
                else
                {
                    switch (mode)
                    {
                        case FileMode.Open:
                            if (manager.IsExist(fileName))
                                return NtStatus.Success;
                            else
                                return NtStatus.ObjectPathNotFound;


                        case FileMode.CreateNew:
                            if (manager.IsExist(fileName))
                                return NtStatus.ObjectNameCollision;

                            
                            return NtStatus.Success;
                        case FileMode.Create:
                            return NtStatus.Success;
                        case FileMode.OpenOrCreate:
                            return NtStatus.Success;
                        case FileMode.Truncate:
                            if (!manager.IsExist(fileName))
                                return NtStatus.ObjectNameNotFound;

                            return NtStatus.Success;
                        case FileMode.Append:
                            if (manager.IsExist(fileName))
                                return NtStatus.Success;

                            return NtStatus.Success;
                        default:
                            return NtStatus.Error;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString() + "---------------");
                return NtStatus.ObjectPathNotFound;
            }
        }


        public NtStatus FindFiles(string fileName, out IList<FileInformation> files, IDokanFileInfo info)
        {
            fileName = GetPath(fileName);
            files = new List<FileInformation>();
            var fileList = manager.FindFiles(fileName);
            try
            {
                foreach (FileInfos fileInfo in fileList)
                {
                    FileInformation fi = new FileInformation
                    {
                        Attributes = Path.HasExtension(fileInfo.FileName) ? FileAttributes.Normal : FileAttributes.Directory,
                        FileName = fileInfo.FileName,
                        Length = fileInfo.Length,
                        LastWriteTime = fileInfo.LastWriteTime,
                        LastAccessTime = fileInfo.LastAccessTime,
                        CreationTime = fileInfo.CreationTime
                    };

                    if (fi.FileName.StartsWith("."))
                    {
                        fi.Attributes |= FileAttributes.Hidden;
                    }
                    files.Add(fi);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString() + "---------------");
            }

            return NtStatus.Success;
        }

        public NtStatus GetFileInformation(string fileName, out FileInformation fileInfo, IDokanFileInfo info)
        {
            fileName = GetPath(fileName);
            fileInfo = new FileInformation();
            try
            {
                FileInfos infos = manager.GetFileInfo(fileName);
                fileInfo.FileName = infos.FileName;
                fileInfo.Attributes = Path.HasExtension(fileInfo.FileName) ? FileAttributes.Normal : FileAttributes.Directory;
                fileInfo.Length = infos.Length;
                fileInfo.CreationTime = infos.CreationTime;
                fileInfo.LastAccessTime = infos.LastAccessTime;
                fileInfo.LastWriteTime = infos.LastWriteTime;
            }
            catch (SftpException ex)
            {
                Console.WriteLine(ex.ToString() + "---------------");
                return NtStatus.Error;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                return NtStatus.Error;
            }
            return NtStatus.Success;
        }

        public NtStatus ReadFile(string fileName, byte[] buffer, out int bytesRead, long offset, IDokanFileInfo info)
        {
            bytesRead = 0;
            if (info.IsDirectory)
                return NtStatus.Error;

            if (info.IsDirectory)
                return NtStatus.Error;

            fileName = GetPath(fileName);
            try
            {
                buffer = manager.ReadFile(fileName);
                bytesRead = buffer.Length;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            return NtStatus.Success;
        }
2020년 10월 8일 목요일 오후 4시 5분 50초 UTC+9에 Liryna님이 작성:

Adrien JUND

unread,
Oct 12, 2020, 2:19:10 AM10/12/20
to do...@googlegroups.com
The prototype of your CreateFile looks to be correct.
Are you sure your class implement the interface correctly? Does the mount happen? 

Ko

unread,
Oct 12, 2020, 3:11:41 AM10/12/20
to Dokan
Hi.

Yes. I'm sure.

public class MountWorker
    {
        private IDokanOperations dokanOperation_;
        private string mountPoint_;
        private string thisPath_;

        public MountWorker(IDokanOperations dokanOperation,  string mountPoint, string thisPath)
        {
            dokanOperation_ = dokanOperation;
            mountPoint_ = mountPoint;
            thisPath_ = thisPath;
        }

        public void Start()
        {
            System.IO.Directory.SetCurrentDirectory(thisPath_);
            try
            {
                dokanOperation_.Mount(mountPoint_, DokanOptions.AltStream, 0);
            }
            catch (DokanException ex)
            {
                Console.WriteLine(ex.ToString());
            }

        }
    }

This class did mount.
2020년 10월 12일 월요일 오후 3시 19분 10초 UTC+9에 Liryna님이 작성:

Ko

unread,
Oct 12, 2020, 3:15:59 AM10/12/20
to Dokan
I used a sftp lib, name is 'Recni.SshNet'.   

2020년 10월 12일 월요일 오후 4시 11분 41초 UTC+9에 Ko님이 작성:

Adrien JUND

unread,
Oct 12, 2020, 4:20:31 AM10/12/20
to do...@googlegroups.com
Could you share more code in a zip/git for us to be able to help you properly? 

Ko

unread,
Oct 12, 2020, 9:22:22 AM10/12/20
to Dokan
https://drive.google.com/file/d/1oVKk9woCJmgxURhPCB1KIFCCr4qLji9k/view?usp=sharing

My source.
Solution is in 'MyNetDrive' folder.

I'm sorry to bother you.

Thanks.

2020년 10월 12일 월요일 오후 5시 20분 31초 UTC+9에 Liryna님이 작성:

Adrien JUND

unread,
Oct 12, 2020, 4:10:58 PM10/12/20
to do...@googlegroups.com

Thanks Looking at the code quickly I do not see anything special.

Could you more explain the issue you have ?
If that is about the number of call of CreateFile and Readfile, there is nothing special you can do about it.

You can use IDokanFileInfo info to track the Context / ProcessId if that can help you.

Ko

unread,
Oct 12, 2020, 8:10:16 PM10/12/20
to Dokan
Hi.

I checked my source and your source.
I found something else.

You did 'FindFiles' or 'GetFileInformation' , you add ' fileinfo.attributes |= FileAttributes.Offline' 
So, did not repeat ReadFile.


2020년 10월 13일 화요일 오전 5시 10분 58초 UTC+9에 Liryna님이 작성:
Reply all
Reply to author
Forward
0 new messages