Esempio n. 1
0
 public int Cleanup(string filename, DokanFileInfo info)
 {
     lock (_syncObj)
     {
         FileHandle handle = (FileHandle)info.Context;
         if (handle != null)
         {
             handle.Cleanup();
         }
         return(DokanNet.DOKAN_SUCCESS);
     }
 }
Esempio n. 2
0
 public void CloseFile(string filename, DokanFileInfo info)
 {
     lock (_syncObj)
     {
         FileHandle handle = info.Context as FileHandle;
         if (handle != null)
         {
             handle.Resource.RemoveFileHandle(handle);
         }
         info.Context = null;
     }
 }
Esempio n. 3
0
 public int CloseFile(string filename, DokanFileInfo info)
 {
     lock (_syncObj)
     {
         FileHandle handle = (FileHandle)info.Context;
         if (handle != null)
         {
             handle.Resource.RemoveFileHandle(handle);
         }
         info.Context = null;
         return(DokanNet.DOKAN_SUCCESS);
     }
 }
Esempio n. 4
0
 public int OpenDirectory(string filename, DokanFileInfo info)
 {
     lock (_syncObj)
     {
         VirtualFileSystemResource resource = ParseFileName(filename);
         if (resource == null || !(resource is VirtualBaseDirectory))
         {
             return(-DokanNet.ERROR_PATH_NOT_FOUND);
         }
         FileHandle handle = new FileHandle(resource);
         info.Context = handle;
         resource.AddFileHandle(handle);
         return(DokanNet.DOKAN_SUCCESS);
     }
 }
Esempio n. 5
0
 public int CreateFile(string filename, FileAccess access, FileShare share, FileMode mode, FileOptions options, DokanFileInfo info)
 {
     lock (_syncObj)
     {
         VirtualFileSystemResource resource = ParseFileName(filename);
         if (resource == null)
         {
             return(-DokanNet.ERROR_FILE_NOT_FOUND);
         }
         FileHandle handle = new FileHandle(resource);
         info.Context = handle;
         resource.AddFileHandle(handle);
         if (resource is VirtualBaseDirectory)
         {
             info.IsDirectory = true; // Necessary for the Dokan driver to set this, see docs
         }
         return(DokanNet.DOKAN_SUCCESS);
     }
 }
Esempio n. 6
0
 public NtStatus CreateFile(string filename, FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info)
 {
     lock (_syncObj)
     {
         VirtualFileSystemResource resource = ParseFileName(filename);
         if (resource == null)
         {
             return(DokanResult.Error);
         }
         FileHandle handle = new FileHandle(resource);
         info.Context = handle;
         resource.AddFileHandle(handle);
         if (resource is VirtualBaseDirectory)
         {
             info.IsDirectory = true;
         }
         return(DokanResult.Success);
     }
 }
Esempio n. 7
0
        public NtStatus ReadFile(string filename, byte[] buffer, out int bytesRead, long offset, DokanFileInfo info)
        {
            FileHandle handle = info.Context as FileHandle;
            Stream     stream;

            bytesRead = 0;
            lock (_syncObj)
            {
                if (handle == null)
                {
                    return(DokanResult.FileNotFound);
                }
                try
                {
                    stream = handle.GetOrOpenStream();
                    if (stream == null)
                    {
                        return(DokanResult.FileNotFound);
                    }
                }
                catch (Exception e)
                {
                    ServiceRegistration.Get <ILogger>().Warn("Dokan: Error creating file stream of resource '{0}'", e, handle.Resource);
                    return(DokanResult.Error);
                }
            }
            // Do the reading outside the lock - might block when not enough bytes are available
            try
            {
                stream.Seek(offset, SeekOrigin.Begin);
                bytesRead = stream.Read(buffer, 0, buffer.Length);
                return(DokanResult.Success);
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Warn("Dokan: Error reading from stream of resource '{0}'", ex, handle.Resource);
                return(DokanResult.Error);
            }
        }
Esempio n. 8
0
        public int ReadFile(string filename, byte[] buffer, ref uint readBytes, long offset, DokanFileInfo info)
        {
            FileHandle handle = (FileHandle)info.Context;
            Stream     stream;

            lock (_syncObj)
            {
                if (handle == null)
                {
                    return(-DokanNet.ERROR_FILE_NOT_FOUND);
                }
                try
                {
                    stream = handle.GetOrOpenStream();
                    if (stream == null)
                    {
                        return(-DokanNet.ERROR_FILE_NOT_FOUND);
                    }
                }
                catch (Exception e)
                {
                    ServiceRegistration.Get <ILogger>().Warn("Dokan: Error creating file stream of resource '{0}'", e, handle.Resource);
                    return(DokanNet.DOKAN_ERROR);
                }
            }
            // Do the reading outside the lock - might block when not enough bytes are available
            try
            {
                stream.Seek(offset, SeekOrigin.Begin);
                readBytes = (uint)stream.Read(buffer, 0, buffer.Length);
                return(DokanNet.DOKAN_SUCCESS);
            }
            catch (Exception e)
            {
                ServiceRegistration.Get <ILogger>().Warn("Dokan: Error reading from stream of resource '{0}'", e, handle.Resource);
                return(DokanNet.DOKAN_ERROR);
            }
        }
 public void RemoveFileHandle(FileHandle handle)
 {
   _fileHandles.Remove(handle);
 }
 public void AddFileHandle(FileHandle handle)
 {
   _fileHandles.Add(handle);
 }
Esempio n. 11
0
 public void RemoveFileHandle(FileHandle handle)
 {
     _fileHandles.Remove(handle);
 }
Esempio n. 12
0
 public void AddFileHandle(FileHandle handle)
 {
     _fileHandles.Add(handle);
 }
Esempio n. 13
0
 public int OpenDirectory(string filename, DokanFileInfo info)
 {
   lock (_syncObj)
   {
     VirtualFileSystemResource resource = ParseFileName(filename);
     if (resource == null || !(resource is VirtualBaseDirectory))
       return -DokanNet.ERROR_PATH_NOT_FOUND;
     FileHandle handle = new FileHandle(resource);
     info.Context = handle;
     resource.AddFileHandle(handle);
     return DokanNet.DOKAN_SUCCESS;
   }
 }
Esempio n. 14
0
 public int CreateFile(string filename, FileAccess access, FileShare share, FileMode mode, FileOptions options, DokanFileInfo info)
 {
   lock (_syncObj)
   {
     VirtualFileSystemResource resource = ParseFileName(filename);
     if (resource == null)
       return -DokanNet.ERROR_FILE_NOT_FOUND;
     FileHandle handle = new FileHandle(resource);
     info.Context = handle;
     resource.AddFileHandle(handle);
     if (resource is VirtualBaseDirectory)
       info.IsDirectory = true; // Necessary for the Dokan driver to set this, see docs
     return DokanNet.DOKAN_SUCCESS;
   }
 }