Пример #1
0
        public DokanError CreateDirectory(string fileName, DokanFileInfo info)
        {
            //Console.WriteLine("CreateDirectory: {0}", fileName);

            if (fileName == "\\")
            {
                return DokanError.ErrorSuccess;
            }

            if (fileName.EndsWith("\\"))
            {
                fileName = fileName.Substring(0, fileName.Length - 1);
            }

            Directory dir = new Directory(Util.GetPathDirectory(fileName));
            if (!dir.Exists())
            {
                return DokanError.ErrorPathNotFound;
            }

            String name = Util.GetPathFileName(fileName);

            if (dir.Contains(name))
            {
                return DokanError.ErrorAlreadyExists;
            }

            dir.CreateDirectory(name);

            return DokanError.ErrorSuccess;
        }
Пример #2
0
        public void Cleanup(string fileName, DokanFileInfo info)
        {
            #if TRACE
            if (info.Context != null)
                Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "{0}('{1}', {2} - entering",
                    "Cleanup", fileName, ToTrace(info)));
            #endif

            if (info.Context != null && info.Context is FileStream)
            {
                (info.Context as FileStream).Dispose();
            }
            info.Context = null;

            if (info.DeleteOnClose)
            {
                if (info.IsDirectory)
                {
                    Directory.Delete(GetPath(fileName));
                }
                else
                {
                    File.Delete(GetPath(fileName));
                }
            }
            Trace("Cleanup", fileName, info, DokanResult.Success);
        }
Пример #3
0
        public DokanError CloseFile(string fileName, DokanFileInfo info)
        {
            //Console.WriteLine("CloseFile: {0}", fileName);

            // 可能打开文件时有 deleteOnClose 标记(Windows 8+)
            if (info.Context != null)
            {
                File f = (File)info.Context;
                if (f.flagDeleteOnClose)
                {
                    Directory dir = new Directory(Util.GetPathDirectory(f.path));
                    if (!dir.Exists())
                    {
                        return DokanError.ErrorSuccess;
                    }

                    String name = Util.GetPathFileName(f.path);

                    if (!dir.Contains(name))
                    {
                        return DokanError.ErrorSuccess;
                    }

                    dir.Delete(name);
                }
            }

            return DokanError.ErrorSuccess;
        }
Пример #4
0
        private string ToTrace(DokanFileInfo info)
        {
            var context = info.Context != null ? "<" + info.Context.GetType().Name + ">" : "<null>";

            return string.Format(CultureInfo.InvariantCulture, "{{{0}, {1}, {2}, {3}, {4}, #{5}, {6}, {7}}}",
                context, info.DeleteOnClose, info.IsDirectory, info.NoCache, info.PagingIo, info.ProcessId, info.SynchronousIo, info.WriteToEndOfFile);
        }
Пример #5
0
        public DokanError CreateFile(string fileName, DokanNet.FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info)
        {
            info.DeleteOnClose = (options & FileOptions.DeleteOnClose) != 0;
            //Console.WriteLine("CreateFile: {0}, mode = {1}", fileName, mode);

            if (fileName == "\\")
            {
                return DokanError.ErrorSuccess;
            }

            Directory dir = new Directory(Util.GetPathDirectory(fileName));
            if (!dir.Exists())
            {
                return DokanError.ErrorPathNotFound;
            }

            String name = Util.GetPathFileName(fileName);

            if (name.Length == 0)
            {
                return DokanError.ErrorInvalidName;
            }
            if (name.IndexOfAny(Path.GetInvalidFileNameChars()) > -1)
            {
                return DokanError.ErrorInvalidName;
            }

            // dokan API 要求在目标文件是目录时候,设置 info.IsDirectory = true
            if (dir.Contains(name) && (dir.GetItemInfo(name).attribute & FileAttributes.Directory) != 0)
            {
                info.IsDirectory = true;
                return DokanError.ErrorSuccess;
            }

            try
            {
                File f = new File(fileName, mode);
                f.flagDeleteOnClose = info.DeleteOnClose;
                info.Context = f;
            }
            catch (FileNotFoundException)
            {
                return DokanError.ErrorFileNotFound;
            }
            catch (IOException)
            {
                return DokanError.ErrorAlreadyExists;
            }
            catch (NotImplementedException)
            {
                return DokanError.ErrorAccessDenied;
            }
            catch (Exception)
            {
                return DokanError.ErrorError;
            }

            return DokanError.ErrorSuccess;
        }
Пример #6
0
 public NtStatus FindFiles(string fileName, out IList<FileInformation> files, DokanFileInfo info)
 {
     //Console.Error.WriteLine("Attempted to findfiles for {0}", fileName);
     //files = filesIndex.Select(fi => fi.FileInformation).ToList();
     //files.Add(new FileInformation() { Attributes = FileAttributes.Directory, FileName = "\\" });
     files = new List<FileInformation>();
     return NtStatus.Success;
 }
Пример #7
0
        DokanError IDokanOperations.CreateDirectory(string fileName, DokanFileInfo info)
        {
            SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName);
            if (drive != null)
                return GetSubSystemOperations(drive).CreateDirectory(fileName, info);

            return DokanError.ErrorAccessDenied;
        }
Пример #8
0
 public void CloseFile(string fileName, DokanFileInfo info)
 {
     if (info.Context != null && info.Context is Stream)
     {
         (info.Context as Stream).Dispose();
     }
     info.Context = null;
 }
Пример #9
0
 public DokanError CloseFile(string fileName, DokanFileInfo info)
 {
     if (info.Context != null && info.Context is FileStream)
     {
         (info.Context as FileStream).Dispose();
     }
     info.Context = null;
     return DokanError.ErrorSuccess; // could recreate cleanup code hear but this is not called sometimes
 }
Пример #10
0
 public DokanError CreateFile(
     string filename,
     FileAccess access,
     System.IO.FileShare share,
     System.IO.FileMode mode,
     System.IO.FileOptions options,
     System.IO.FileAttributes attributes,
     DokanFileInfo info)
 {
     return DokanError.ErrorSuccess;
 }
Пример #11
0
        private NtStatus Trace(string method, string fileName, DokanFileInfo info,
                                  FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes,
                                  NtStatus result)
        {
#if TRACE
            Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0}('{1}', {2}, [{3}], [{4}], [{5}], [{6}], [{7}]) -> {8}",
                method, fileName, ToTrace(info), access, share, mode, options, attributes, result));
#endif

            return result;
        }
Пример #12
0
        private NtStatus Trace(string method, string fileName, DokanFileInfo info, NtStatus result, params string[] parameters)
        {
            var extraParameters = parameters != null && parameters.Length > 0 ? ", " + string.Join(", ", parameters) : string.Empty;

#if TRACE
            Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "{0}('{1}', {2}{3}) -> {4}",
                method, fileName, ToTrace(info), extraParameters, result));
#endif

            return result;
        }
Пример #13
0
 public NtStatus CreateFile(
     string filename,
     FileAccess access,
     System.IO.FileShare share,
     System.IO.FileMode mode,
     System.IO.FileOptions options,
     System.IO.FileAttributes attributes,
     DokanFileInfo info)
 {
     return DokanResult.Success;
 }
Пример #14
0
        private NtStatus Trace(string method, string fileName, DokanFileInfo info,
            FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes,
            NtStatus result)
        {
#if TRACE
            logger.Debug(
                DokanFormat(
                    $"{method}('{fileName}', {info}, [{access}], [{share}], [{mode}], [{options}], [{attributes}]) -> {result}"));
#endif

            return result;
        }
Пример #15
0
        public void Cleanup(string fileName, DokanFileInfo info)
        {
            if (info.Context != null && info.Context is Stream)
            {
                (info.Context as Stream).Dispose();
            }
            info.Context = null;

            if (info.DeleteOnClose)
            {
                // do nothig
            }
        }
Пример #16
0
 public NtStatus CreateFile(
     string filename,
     FileAccess access,
     System.IO.FileShare share,
     System.IO.FileMode mode,
     System.IO.FileOptions options,
     System.IO.FileAttributes attributes,
     DokanFileInfo info)
 {
     if (info.IsDirectory && mode == System.IO.FileMode.CreateNew)
         return DokanResult.AccessDenied;
     return DokanResult.Success;
 }
Пример #17
0
        private NtStatus Trace(string method, string fileName, DokanFileInfo info, NtStatus result,
            params object[] parameters)
        {
#if TRACE
            var extraParameters = parameters != null && parameters.Length > 0
                ? ", " + string.Join(", ", parameters.Select(x => string.Format(DefaultFormatProvider, "{0}", x)))
                : string.Empty;

            logger.Debug(DokanFormat($"{method}('{fileName}', {info}{extraParameters}) -> {result}"));
#endif

            return result;
        }
Пример #18
0
        public DokanError CreateDirectory(string fileName, DokanFileInfo info)
        {
            if (Directory.Exists(GetPath(fileName)))
                return DokanError.ErrorAlreadyExists;

            try
            {
                Directory.CreateDirectory(GetPath(fileName));
                return DokanError.ErrorSuccess;
            }
            catch (UnauthorizedAccessException)
            {
                return DokanError.ErrorAccessDenied;
            }
        }
Пример #19
0
        public DokanError CloseFile(string fileName, DokanFileInfo info)
        {
            log.Info(String.Format("CloseFile call - {0}", fileName));

            if (info.Context is RFIDContext)
            {
                RFIDContext ctx = info.Context as RFIDContext;
                if (ctx.WriteCacheOnClose)
                {
                    return WriteCacheToCard(fileName);
                }
            }

            return DokanError.ErrorSuccess;
        }
Пример #20
0
        public NtStatus CreateDirectory(string fileName, DokanFileInfo info)
        {
            if (Directory.Exists(GetPath(fileName)))
                return Trace("CreateDirectory", fileName, info, DokanResult.FileExists);

            try
            {
                Directory.CreateDirectory(GetPath(fileName));
                return Trace("CreateDirectory", fileName, info, DokanResult.Success);
            }
            catch (UnauthorizedAccessException)
            {
                return Trace("CreateDirectory", fileName, info, DokanResult.AccessDenied);
            }
        }
Пример #21
0
        public void CloseFile(string fileName, DokanFileInfo info)
        {
            #if TRACE
            if (info.Context != null)
                Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "{0}('{1}', {2} - entering",
                    "CloseFile", fileName, ToTrace(info)));
            #endif

            if (info.Context != null && info.Context is FileStream)
            {
                (info.Context as FileStream).Dispose();
            }
            info.Context = null;
            Trace("CloseFile", fileName, info, DokanResult.Success); // could recreate cleanup code here but this is not called sometimes
        }
Пример #22
0
        public DokanError Cleanup(string fileName, DokanFileInfo info)
        {
            log.Info(String.Format("Cleanup call - {0}", fileName));

            if (info.DeleteOnClose)
            {
                if (info.IsDirectory)
                {
                    DeleteDirectory(fileName, info);
                }
                else
                {
                    DeleteFile(fileName, info);
                }
            }

            return DokanError.ErrorSuccess;
        }
Пример #23
0
        public NtStatus CreateDirectory(string fileName, DokanFileInfo info)
        {
            //Debug.Print("CreateDirectory. filename : {0}", fileName);

            fileName = ToUnixStylePath(fileName);

            if (sftpClient.Exists(fileName))
                return DokanResult.FileExists;

            try
            {
                sftpClient.CreateDirectory(fileName);
                return DokanResult.Success;
            }
            catch (Renci.SshNet.Common.SshException)
            {
                return DokanResult.AccessDenied;
            }
        }
Пример #24
0
        DokanError IDokanOperations.CloseFile(string fileName, DokanFileInfo info)
        {
            SftpDrive drive = this.GetDriveByMountPoint(fileName, out fileName);
            LogFSActionInit("CloseFile", fileName, drive, "");
            if (drive != null)
            {
                LogFSActionSuccess("CloseFile", fileName, drive, "NonVFS close");
                return GetSubSystemOperations(drive).CloseFile(fileName, info);
            }

            if (info.Context != null)
            {
                drive = info.Context as SftpDrive;
                info.Context = null;
            }

            LogFSActionSuccess("CloseFile", fileName, drive, "VFS close");
            return DokanError.ErrorSuccess;
        }
Пример #25
0
        public DokanError Cleanup(string fileName, DokanFileInfo info)
        {
            if (info.Context != null && info.Context is FileStream)
            {
                (info.Context as FileStream).Dispose();
            }
            info.Context = null;

            if (info.DeleteOnClose)
            {
                if (info.IsDirectory)
                {
                    Directory.Delete(GetPath(fileName));
                }
                else
                {
                    File.Delete(GetPath(fileName));
                }
            }
            return DokanError.ErrorSuccess;
        }
Пример #26
0
        private static void Addto(FILL_FIND_DATA fill, DokanFileInfo rawFileInfo, FileInformation fi)
        {
            Debug.Assert(!String.IsNullOrEmpty(fi.FileName));
            long ctime = fi.CreationTime.ToFileTime();
            long atime = fi.LastAccessTime.ToFileTime();
            long mtime = fi.LastWriteTime.ToFileTime();
            var data = new WIN32_FIND_DATA
            {
                dwFileAttributes = fi.Attributes,
                ftCreationTime =
                                   {
                                       dwHighDateTime = (int) (ctime >> 32),
                                       dwLowDateTime = (int) (ctime & 0xffffffff)
                                   },
                ftLastAccessTime =
                                   {
                                       dwHighDateTime = (int) (atime >> 32),
                                       dwLowDateTime = (int) (atime & 0xffffffff)
                                   },
                ftLastWriteTime =
                                   {
                                       dwHighDateTime = (int) (mtime >> 32),
                                       dwLowDateTime = (int) (mtime & 0xffffffff)
                                   },
                nFileSizeLow = (uint)(fi.Length & 0xffffffff),
                nFileSizeHigh = (uint)(fi.Length >> 32),
                cFileName = fi.FileName
            };
            //ZeroMemory(&data, sizeof(WIN32_FIND_DATAW));

            fill(ref data, rawFileInfo);
        }
Пример #27
0
 ////
 public int WriteFileProxy(string rawFileName, byte[] rawBuffer,
                           uint rawNumberOfBytesToWrite, ref int rawNumberOfBytesWritten, long rawOffset,
                           DokanFileInfo rawFileInfo)
 {
     try
     {
         return (int)_operations.WriteFile(rawFileName, rawBuffer,
                                            out rawNumberOfBytesWritten, rawOffset,
                                            rawFileInfo);
     }
     catch
     {
     #if DEBUG
         throw;
     #else
         return ERROR_INVALID_FUNCTION;
     #endif
     }
 }
Пример #28
0
 public int UnmountProxy(DokanFileInfo rawFileInfo)
 {
     try
     {
         return (int)_operations.Unmount(rawFileInfo);
     }
     catch
     {
     #if DEBUG
         throw;
     #else
         return ERROR_INVALID_FUNCTION;
     #endif
     }
 }
Пример #29
0
 ////
 public int UnlockFileProxy(string rawFileName, long rawByteOffset,
                            long rawLength, DokanFileInfo rawFileInfo)
 {
     try
     {
         return
             (int)
             _operations.UnlockFile(rawFileName, rawByteOffset, rawLength, rawFileInfo);
     }
     catch
     {
     #if DEBUG
         throw;
     #else
         return ERROR_INVALID_FUNCTION;
     #endif
     }
 }
Пример #30
0
        ////
        public int SetFileTimeProxy(string rawFileName,
                                   ref FILETIME rawCreationTime,
                                   ref FILETIME rawLastAccessTime,
                                   ref FILETIME rawLastWriteTime,
                                    DokanFileInfo rawFileInfo)
        {
            var ctime = (rawCreationTime.dwLowDateTime != 0 || rawCreationTime.dwHighDateTime != 0) && (rawCreationTime.dwLowDateTime != -1 || rawCreationTime.dwHighDateTime != -1)
                            ? DateTime.FromFileTime(((long)rawCreationTime.dwHighDateTime << 32) |
                                                    (uint)rawCreationTime.dwLowDateTime)
                                  : (DateTime?)null;
            var atime = (rawLastAccessTime.dwLowDateTime != 0 || rawLastAccessTime.dwHighDateTime != 0) && (rawLastAccessTime.dwLowDateTime != -1 || rawLastAccessTime.dwHighDateTime != -1)
                                  ? DateTime.FromFileTime(((long)rawLastAccessTime.dwHighDateTime << 32) |
                                                          (uint)rawLastAccessTime.dwLowDateTime)
                                  : (DateTime?)null;
            var mtime = (rawLastWriteTime.dwLowDateTime != 0 || rawLastWriteTime.dwHighDateTime != 0) && (rawLastWriteTime.dwLowDateTime != -1 || rawLastWriteTime.dwHighDateTime != -1)
                                  ? DateTime.FromFileTime(((long)rawLastWriteTime.dwHighDateTime << 32) |
                                                          (uint)rawLastWriteTime.dwLowDateTime)
                                  : (DateTime?)null;

            try
            {
                return (int)_operations.SetFileTime(rawFileName, ctime, atime,
                                                     mtime, rawFileInfo);
            }
            catch
            {
            #if DEBUG
                throw;
            #else
                return ERROR_INVALID_FUNCTION;
            #endif
            }
        }