Пример #1
0
        internal NtStatus ZwCreateFileProxy(string rawFileName, IntPtr SecurityContext, uint rawDesiredAccess, uint rawFileAttributes, uint rawShareAccess, uint rawCreateDisposition, uint rawCreateOptions, DokanFileInfo dokanFileInfo)
        {
            try
            {
                FileOptions    fileOptions            = 0;
                FileAttributes fileAttributes         = 0;
                int            fileAttributesAndFlags = 0;
                int            creationDisposition    = 0;
                DokanNativeMethods.DokanMapKernelToUserCreateFileFlags(rawFileAttributes, rawCreateOptions, rawCreateDisposition, ref fileAttributesAndFlags, ref creationDisposition);

                foreach (FileOptions fileOption in Enum.GetValues(typeof(FileOptions)))
                {
                    if (((FileOptions)(fileAttributesAndFlags & 0xffffc000) & fileOption) == fileOption)
                    {
                        fileOptions |= fileOption;
                    }
                }

                foreach (FileAttributes fileAttribute in Enum.GetValues(typeof(FileAttributes)))
                {
                    if (((FileAttributes)(fileAttributesAndFlags & 0x3fff) & fileAttribute) == fileAttribute)
                    {
                        fileAttributes |= fileAttribute;
                    }
                }

                NtStatus result = _operations.CreateFile(rawFileName, (FileAccess)rawDesiredAccess, (FileShare)rawShareAccess, (FileMode)creationDisposition, fileOptions, fileAttributes, dokanFileInfo);
                return(result);
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Warn("Dokan exception: ", ex);
                return(DokanResult.Unsuccessful);
            }
        }
Пример #2
0
 public WindowsIdentity GetRequestor()
 {
     try
     {
         return(new WindowsIdentity(DokanNativeMethods.DokanOpenRequestorToken(this)));
     }
     catch
     {
         return(null);
     }
 }
Пример #3
0
 private static bool DokanRemoveMountPoint(string mountPoint)
 {
     return(DokanNativeMethods.DokanRemoveMountPoint(mountPoint));
 }
Пример #4
0
        protected void Run()
        {
            ILogger logger = ServiceRegistration.Get <ILogger>();

            try
            {
                var dokanOperationProxy = new Proxy(this);
                var dokanOptions        = new DOKAN_OPTIONS
                {
                    Version     = DOKAN_VERSION,
                    MountPoint  = _mountPoint,
                    ThreadCount = THREAD_COUNT,
                    Options     = (uint)DokanOptions.FixedDrive,
                    Timeout     = 0
                };

                DOKAN_OPERATIONS dokanOperations = new DOKAN_OPERATIONS();
                dokanOperations.ZwCreateFile         = dokanOperationProxy.ZwCreateFileProxy;
                dokanOperations.Cleanup              = dokanOperationProxy.CleanupProxy;
                dokanOperations.CloseFile            = dokanOperationProxy.CloseFileProxy;
                dokanOperations.ReadFile             = dokanOperationProxy.ReadFileProxy;
                dokanOperations.WriteFile            = dokanOperationProxy.WriteFileProxy;
                dokanOperations.FlushFileBuffers     = dokanOperationProxy.FlushFileBuffersProxy;
                dokanOperations.GetFileInformation   = dokanOperationProxy.GetFileInformationProxy;
                dokanOperations.FindFiles            = dokanOperationProxy.FindFilesProxy;
                dokanOperations.SetFileAttributes    = dokanOperationProxy.SetFileAttributesProxy;
                dokanOperations.SetFileTime          = dokanOperationProxy.SetFileTimeProxy;
                dokanOperations.DeleteFile           = dokanOperationProxy.DeleteFileProxy;
                dokanOperations.DeleteDirectory      = dokanOperationProxy.DeleteDirectoryProxy;
                dokanOperations.MoveFile             = dokanOperationProxy.MoveFileProxy;
                dokanOperations.SetEndOfFile         = dokanOperationProxy.SetEndOfFileProxy;
                dokanOperations.SetAllocationSize    = dokanOperationProxy.SetAllocationSizeProxy;
                dokanOperations.LockFile             = dokanOperationProxy.LockFileProxy;
                dokanOperations.UnlockFile           = dokanOperationProxy.UnlockFileProxy;
                dokanOperations.GetDiskFreeSpace     = dokanOperationProxy.GetDiskFreeSpaceProxy;
                dokanOperations.GetVolumeInformation = dokanOperationProxy.GetVolumeInformationProxy;
                dokanOperations.Mounted              = dokanOperationProxy.MountedProxy;
                dokanOperations.Unmounted            = dokanOperationProxy.UnmountedProxy;
                dokanOperations.GetFileSecurity      = dokanOperationProxy.GetFileSecurityProxy;
                dokanOperations.SetFileSecurity      = dokanOperationProxy.SetFileSecurityProxy;
                dokanOperations.FindStreams          = dokanOperationProxy.FindStreamsProxy;

                // DokanMain will return when a "DokanUnmount" call is done from ResMount thread (or in case of errors?)
                int status = DokanNativeMethods.DokanMain(ref dokanOptions, ref dokanOperations);

                switch (status)
                {
                case DOKAN_SUCCESS:
                    logger.Info("Dokan: DokanMain returned successfully!");
                    break;

                case DOKAN_ERROR:
                    logger.Warn("Dokan: DokanMain returned with error code {0} - General Error. Remote resources may not be available in this session", status);
                    break;

                case DOKAN_DRIVE_LETTER_ERROR:
                    logger.Warn("Dokan: DokanMain returned with error code {0} - Bad Drive letter. Remote resources may not be available in this session", status);
                    break;

                case DOKAN_DRIVER_INSTALL_ERROR:
                    logger.Warn("Dokan: DokanMain returned with error code {0} - Can not install driver. Remote resources may not be available in this session", status);
                    break;

                case DOKAN_MOUNT_ERROR:
                    logger.Warn("Dokan: DokanMain returned with error code {0} - Can not assign mount point. Remote resources may not be available in this session", status);
                    break;

                case DOKAN_START_ERROR:
                    logger.Warn("Dokan: DokanMain returned with error code {0} - Driver something wrong. Remote resources may not be available in this session", status);
                    break;

                case DOKAN_MOUNT_POINT_ERROR:
                    logger.Warn("Dokan: DokanMain returned with error code {0} - Mount point is invalid. Remote resources may not be available in this session", status);
                    break;

                case DOKAN_VERSION_ERROR:
                    logger.Warn("Dokan: DokanMain returned with error code {0} - Requested an incompatible version. Remote resources may not be available in this session", status);
                    break;
                }
            }
            catch (Exception e)
            {
                logger.Error("Dokan: Error mounting virtual filesystem at '{0}' (is DOKAN not installed?)", e, _mountPoint);
            }
        }
Пример #5
0
 public bool TryResetTimeout(int milliseconds)
 {
     return(DokanNativeMethods.DokanResetTimeout((uint)milliseconds, this));
 }