Example #1
0
        private void UnmountDrive()
        {
            if (mNFS == null)
            {
                throw new ApplicationException("NFS object is null!");
            }

            mNFS.UnMountDevice();
            if (rbDisk.Checked)
            {
                DokanNet.DokanUnmount(MountPoint.ToCharArray()[0]);
            }
            else
            {
                DokanNet.DokanRemoveMountPoint(MountPoint);
            }
            cboxLocalDrive.Enabled    = true;
            cboxRemoteDevices.Enabled = true;
            btnMount.Enabled          = true;
            btnUnmount.Enabled        = false;
            tbDriveLabel.Enabled      = true;
            rbDisk.Enabled            = true;
            rbFolder.Enabled          = true;
            btnSelectFolder.Enabled   = true;
            chkAutoMount.Enabled      = true;
            chkNoCache.Enabled        = true;
            btnClearCache.Enabled     = false;
        }
        public int WriteFileDelegate(string filename, byte[] buffer, ref uint writtenBytes, long offset, DokanFileInfo info)
        {
            var client         = _clientList.ResolveByPath(filename);
            var globalFileName = filename;

            filename = _clientList.ToLocalPath(filename);
            var appContext = info.TryGetApplicationContext(client, filename, globalFileName);

            if (appContext == null || appContext.MetaData == null)
            {
                return(-DokanNet.ERROR_FILE_NOT_FOUND);
            }
            info.IsDirectory = appContext.MetaData.Is_Dir;

            if (info.IsDirectory)
            {
                return(-1);
            }
            DokanNet.DokanResetTimeout(60000, info);
            if (appContext.ChunkedUpload == null) // start chunked upload
            {
                appContext.ChunkedUpload = client.StartChunkedUpload(buffer);
                writtenBytes             = (uint)buffer.Length;
            }
            else // continue chunked upload
            {
                appContext.ChunkedUpload = client.AppendChunkedUpload(appContext.ChunkedUpload, buffer);
                writtenBytes             = (uint)buffer.Length;
            }
            return(0);
        }
Example #3
0
 public void Dispose()
 {
     if (_root == null)
     {
         return;
     }
     try
     {
         if (DokanNet.DokanUnmount(_driveLetter) == 0)
         {
             ServiceRegistration.Get <ILogger>().Error("Dokan: Failed to unmount drive '{0}'", _driveLetter);
         }
         else
         {
             ServiceRegistration.Get <ILogger>().Info("Dokan: Successfully unmounted drive '{0}'", _driveLetter);
         }
     }
     catch (Exception e)
     {
         ServiceRegistration.Get <ILogger>().Error("Dokan: Error unmounting drive '{0}'", e, _driveLetter);
     }
     lock (_syncObj)
         _root.Dispose();
     _root = null;
 }
Example #4
0
        private void mountButton_Click(object sender, EventArgs e)
        {
            if (!mounted)
            {
                DokanNet.DokanUnmount(settings.Mount[0]);
                settings.Username = userTxt.Text;
                settings.Password = passwordTxt.Text;
                settings.Mount    = driveCombo.Text;
                this.Hide();

                if (!Connect())
                {
                    this.Show();
                    MessageBox.Show("OcurriĆ³ un error, por favor revise sus datos");
                }
            }
            else
            {
                try
                {
                    DokanNet.DokanUnmount(settings.Mount[0]);
                    enableControls();
                }
                catch
                {
                    Console.WriteLine("Drive not mounted");
                }
            }
        }
Example #5
0
        public int WriteFile(string filename, byte[] buffer, ref uint writtenBytes, long offset, DokanFileInfo info)
        {
            WriteTrace("writefile", filename, offset);

            StartCommunication();

            FileUploader fileUploader = info.Context as FileUploader;

            if (fileUploader == null)
            {
                WriteTrace("writefile", filename, "no uploader found");
                return(-DokanNet.ERROR_ACCESS_DENIED);
            }

            DokanNet.DokanResetTimeout(1000 * 30, info);

            fileUploader.WriteAsync(buffer).Wait();

            writtenBytes = (uint)buffer.Length;

            if (fileUploader.IsFinished())
            {
                OnUploadComplete(fileUploader, filename);
            }

            WriteTrace("writefile", filename, writtenBytes, fileUploader.Id, fileUploader.IsFinished());

            return(DokanNet.DOKAN_SUCCESS);
        }
Example #6
0
            public void Start()
            {
                System.IO.Directory.SetCurrentDirectory(Application.StartupPath);
                int ret = DokanNet.DokanMain(opt_, sshfs_);

                if (ret < 0)
                {
                    string msg = "Dokan Error";
                    switch (ret)
                    {
                    case DokanNet.DOKAN_ERROR:
                        msg = "Dokan Error";
                        break;

                    case DokanNet.DOKAN_DRIVE_LETTER_ERROR:
                        msg = "Dokan drive letter error";
                        break;

                    case DokanNet.DOKAN_DRIVER_INSTALL_ERROR:
                        msg = "Dokan driver install error";
                        break;

                    case DokanNet.DOKAN_MOUNT_ERROR:
                        msg = "Dokan drive letter assign error";
                        break;

                    case DokanNet.DOKAN_START_ERROR:
                        msg = "Dokan driver error ,please reboot";
                        break;
                    }
                    MessageBox.Show(msg, "Error");
                    Application.Exit();
                }
                Debug.WriteLine("DokanNet.Main end");
            }
Example #7
0
        protected static bool Prepare(char driveLetter)
        {
            ILogger logger = ServiceRegistration.Get <ILogger>();

            // First check if the configured driveLetter refers to a Dokan drive, then do an unmount to remove a possibly
            // lost Dokan mount from a formerly crashed MediaPortal
            if (IsDokanDrive(driveLetter))
            {
                if (DokanNet.DokanUnmount(driveLetter) == 1)
                {
                    logger.Info("Dokan: Successfully unmounted remote resource drive '{0}' from former unclean shutdown", driveLetter);
                }
                else
                {
                    logger.Warn("Dokan: Could not unmount orphaned DOKAN drive '{0}' from former unclean shutdown", driveLetter);
                }
            }

            if (DriveInUse(driveLetter))
            {
                logger.Warn("Dokan: Drive letter '{0}' is already in use", driveLetter);
                return(false);
            }
            return(true);
        }
Example #8
0
        protected void Run()
        {
            ILogger logger = ServiceRegistration.Get <ILogger>();

            try
            {
                DokanOptions opt = new DokanOptions
                {
                    DriveLetter = _driveLetter,
                    VolumeLabel = VOLUME_LABEL,
                    //UseKeepAlive = true,
                    //DebugMode = true,
                    //ThreadCount = 5,
                    //UseAltStream = true,
                    //UseStdErr = true
                };

                // DokanMain will return when a "DokanUnmount" call is done from ResMount thread (or in case of errors?)
                int result = DokanNet.DokanMain(opt, this);
                if (result == DokanNet.DOKAN_SUCCESS)
                {
                    logger.Debug("Dokan: DokanMain returned successfully");
                }
                else
                {
                    logger.Warn("Dokan: DokanMain returned with error code {0} - remote resources may not be available in this session", result);
                }
            }
            catch (Exception e)
            {
                logger.Error("Dokan: Error mounting virtual filesystem at drive '{0}' (is DOKAN not installed?)", e, _driveLetter);
            }
        }
Example #9
0
        /// <summary>
        /// This method is called when the service gets a request to start.
        /// </summary>
        /// <param name="args">Any command line arguments</param>
        public void OnStart(string[] args)
        {
            _log.Trace("Service start");

            List <DropNetClient> dropNetClients;

            do
            {
                _log.Trace("Reading configuration...");
                Thread.Sleep(15000);
                //initialize from config including list of client accounts
                _config        = new ApplicationConfig();
                dropNetClients = (from ClientAccount account in _config.ClientAccounts select new DropNetClient(_config.ApplicationKey, _config.ApplicationSecret, account.Key, account.Secret)).ToList();
            } while (dropNetClients.Count < 1);
            _dokanThread = new Thread(() => DokanNet.DokanMain(new DokanOptions {
                DebugMode      = false,
                MountPoint     = string.Format("{0}:\\", _config.DriveLetter),
                ThreadCount    = 0,
                UseKeepAlive   = true,
                RemovableDrive = true,
                NetworkDrive   = true
            },
                                                               new DropboxImplementation(dropNetClients)));
            _dokanThread.Start();
        }
Example #10
0
        public void TestDokanTest()
        {
            //for (int retries = 0; retries < 2; retries++)
            {
                DokanOptions opt         = new DokanOptions();
                var          FileSystem  = new LocalFileSystem(@"C:\temp\temp2");
                var          FileSystem2 = new SftpFileSystem("192.168.1.36", 22, "ubuntu", "ubuntu", 1000);
                var          FileSystem3 = new FtpFileSystem("192.168.1.36", 21, "ubuntu", "ubuntu", 1000);
                FileSystem.Mount("/MountedFolder/sftp", FileSystem2);
                FileSystem.Mount("/MountedFolder/ftp", FileSystem3);
                opt.MountPoint     = @"m:\";
                opt.DebugMode      = true;
                opt.UseStdErr      = true;
                opt.NetworkDrive   = true;
                opt.RemovableDrive = false;
                opt.VolumeLabel    = "Test";

                Thread.GetDomain().ProcessExit += new EventHandler(delegate(object sender, EventArgs e)
                {
                    DokanNet.DokanUnmount('m');
                });

                int status = DokanNet.DokanMain(opt, new FileSystemProxyDokanOperations(FileSystem));
                switch (status)
                {
                case DokanNet.DOKAN_DRIVE_LETTER_ERROR:
                    Console.WriteLine("Drvie letter error");
                    break;

                case DokanNet.DOKAN_DRIVER_INSTALL_ERROR:
                    Console.WriteLine("Driver install error");
                    break;

                case DokanNet.DOKAN_MOUNT_ERROR:
                    Console.WriteLine("Mount error");
                    //Thread.Sleep(2000);
                    //continue;
                    break;

                case DokanNet.DOKAN_START_ERROR:
                    Console.WriteLine("Start error");
                    break;

                case DokanNet.DOKAN_ERROR:
                    Console.WriteLine("Unknown error");
                    break;

                case DokanNet.DOKAN_SUCCESS:
                    Console.WriteLine("Success");
                    break;

                default:
                    Console.WriteLine("Unknown status: %d", status);
                    break;
                }
                Console.ReadKey();
                //break;
            }
        }
Example #11
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;
        }
Example #12
0
        private void OnApplicationExit(object sender, EventArgs e)
        {
            //Cleanup so that the icon will be removed when the application is closed
            TrayIcon.Visible = false;

            DokanNet.DokanUnmount(driveLetter.Value);
            driveLetter = null;
        }
Example #13
0
        static void Main(string[] args)
        {
            DokanOptions opt = new DokanOptions();

            opt.DebugMode   = true;
            opt.DriveLetter = 'n';
            opt.ThreadCount = 5;
            DokanNet.DokanMain(opt, new Mirror("C:"));
        }
Example #14
0
        static void Main(string[] args)
        {
            DokanOptions opt = new DokanOptions();

            opt.DriveLetter = 'r';
            opt.DebugMode   = true;
            opt.UseStdErr   = true;
            opt.VolumeLabel = "RFS";
            DokanNet.DokanMain(opt, new RFS());
        }
Example #15
0
        static void Main(string[] args)
        {
            DokanOptions opt = new DokanOptions();

            opt.DebugMode   = false;
            opt.DriveLetter = 'm';
            // Leave to default
            opt.ThreadCount = 1;
            opt.VolumeLabel = "MEMFS";
            DokanNet.DokanMain(opt, new MemFSje());
        }
Example #16
0
        static void Main()
        {
            Console.WriteLine("Connecting to GridFS");
            var gfs = new GridFs(
                Settings["MongoDBConnectionString"],
                Settings["GridFSDB"],
                Settings["PrefixPath"]
                );

            var opt = new DokanOptions {
#if DEBUG
                DebugMode = true,
#endif
                MountPoint  = Settings["MountPoint"],
                ThreadCount = 1,
            };

            Console.WriteLine("Mounting {0}", Settings["MountPoint"]);
            AppDomain.CurrentDomain.ProcessExit += CurrentDomainProcessExit;
            var status = DokanNet.DokanMain(opt, gfs);

            gfs.Dispose();

            switch (status)
            {
            case DokanNet.DOKAN_DRIVE_LETTER_ERROR:
                Console.WriteLine("Drvie letter error");
                break;

            case DokanNet.DOKAN_DRIVER_INSTALL_ERROR:
                Console.WriteLine("Driver install error");
                break;

            case DokanNet.DOKAN_MOUNT_ERROR:
                Console.WriteLine("Mount error");
                break;

            case DokanNet.DOKAN_START_ERROR:
                Console.WriteLine("Start error");
                break;

            case DokanNet.DOKAN_ERROR:
                Console.WriteLine("Unknown error");
                break;

            case DokanNet.DOKAN_SUCCESS:
                Console.WriteLine("Success");
                break;

            default:
                Console.WriteLine("Unknown status: {0}", status);
                break;
            }
        }
Example #17
0
        static void StartDokan(object opt)
        {
            // Start dokan
            int status;

            try
            {
                Debug("Dokan thread: Starting main loop");
                status = DokanNet.DokanMain(opt as DokanOptions, new Server(serverVersion));
                Debug("Dokan thread: Main loop ended");
            }
            catch (Exception ex)
            {
                Log(ex.ToString());
                return;
            }

            switch (status)
            {
            case DokanNet.DOKAN_DRIVE_LETTER_ERROR:
                Log("Dokan: Bad Drive letter");
                break;

            case DokanNet.DOKAN_DRIVER_INSTALL_ERROR:
                Log("Dokan: Can't install driver");
                break;

            case DokanNet.DOKAN_MOUNT_ERROR:
                Log("Can't assign a drive letter or mount point");
                break;

            case -6: // DOKAN_MOUNT_POINT_ERROR
                Log("Mount point is invalid");
                break;

            case DokanNet.DOKAN_START_ERROR:
                Log("Dokan: Driver something wrong");
                break;

            case DokanNet.DOKAN_ERROR:
                Log("Dokan: General Error");
                break;

            case DokanNet.DOKAN_SUCCESS:
                Log("Dokan: Success");
                break;

            default:
                Log("Unknown status: " + status);
                break;
            }
        }
Example #18
0
        private void salirToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                DokanNet.DokanUnmount(settings.Mount[0]);
            }
            catch
            {
                Console.WriteLine("Drive not mounted");
            }

            Application.Exit();
        }
Example #19
0
        public static void _DokanMount(object _wm)
        {
            WinMounter           wm  = (WinMounter)_wm;
            DokanOptions         opt = new DokanOptions();
            PutioDokanOperations ops = new PutioDokanOperations(wm);

            opt.DebugMode   = false;
            opt.DriveLetter = ops.Mounter.DriveLetter;
            opt.ThreadCount = 5;
            opt.VolumeLabel = "put.io";
            // opt.NetworkDrive = true;
            DokanNet.DokanMain(opt, ops);
        }
Example #20
0
 /// <summary>
 /// ē‚¹å‡»č®¾ē½®ęŒ‰é’®
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnSetDiskPosition_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(tbDiskPostion.Text))
     {
         LocalDiskPathHelper.SetPath(tbDiskPostion.Text);
         DokanNet.DokanRemoveMountPoint("l:\\");
         MountDisk();
         MessageBox.Show(@"č®¾ē½®ęˆåŠŸ");
     }
     else
     {
         MessageBox.Show(@"čÆ·ē‚¹å‡»å·¦ä¾§ēš„č¾“å…„ę”†é€‰ę‹©ę–‡ä»¶å¤¹ļ¼");
     }
 }
Example #21
0
        static void Main(string[] args)
        {
            //args = new string[] { @"C:\VPC\SmartOs\" };
            if (args.Length == 0)
            {
                Console.WriteLine("Usage: ZfsSharp.exe <a directory containing VHD, VDI, or ZFS files>");
                return;
            }

            using (var zfs = new Zfs(args[0]))
            {
                DokanOptions opt = new DokanOptions();
                opt.MountPoint  = "z:\\";
                opt.DebugMode   = true;
                opt.UseStdErr   = true;
                opt.VolumeLabel = "ZFS";
                int status = DokanNet.DokanMain(opt, new ZfsDokan(zfs));
                switch (status)
                {
                case DokanNet.DOKAN_DRIVE_LETTER_ERROR:
                    Console.WriteLine("Drvie letter error");
                    break;

                case DokanNet.DOKAN_DRIVER_INSTALL_ERROR:
                    Console.WriteLine("Driver install error");
                    break;

                case DokanNet.DOKAN_MOUNT_ERROR:
                    Console.WriteLine("Mount error");
                    break;

                case DokanNet.DOKAN_START_ERROR:
                    Console.WriteLine("Start error");
                    break;

                case DokanNet.DOKAN_ERROR:
                    Console.WriteLine("Unknown error");
                    break;

                case DokanNet.DOKAN_SUCCESS:
                    Console.WriteLine("Success");
                    break;

                default:
                    Console.WriteLine("Unknown status: {0}", status);
                    break;
                }
            }
        }
Example #22
0
        /// <summary>
        /// Mounts the <see cref="Drive"/>.
        /// </summary>
        /// <returns></returns>
        public string Mount()
        {
            string result;

            var fTPSClient = new FTPSClient();

            fTPSClient.LogCommand     += new LogCommandEventHandler(OnFTPSClientLogCommand);
            fTPSClient.LogServerReply += new LogServerReplyEventHandler(OnFTPSClientLogServerReply);

            var dokanFtpClient = new DokanFtpClient(fTPSClient, options);

            dokanFtpClient.MethodCall += new LogEventHandler(OnFtpClientMethodCall);
            dokanFtpClient.Debug      += new LogEventHandler(OnFtpClientDebug);

            var status = DokanNet.DokanMain(options.GetDokanOptions(), dokanFtpClient);

            switch (status)
            {
            case DokanNet.DOKAN_DRIVE_LETTER_ERROR:
                result = "Drive letter error";
                break;

            case DokanNet.DOKAN_DRIVER_INSTALL_ERROR:
                result = "Driver install error";
                break;

            case DokanNet.DOKAN_MOUNT_ERROR:
                result = "Mount error";
                break;

            case DokanNet.DOKAN_START_ERROR:
                result = "Start error";
                break;

            case DokanNet.DOKAN_ERROR:
                result = "Unknown error";
                break;

            case DokanNet.DOKAN_SUCCESS:
                result = "Success";
                break;

            default:
                result = string.Format("Unknown status: %d", status);
                break;
            }

            return(result);
        }
Example #23
0
        private void Unmount()
        {
            Debug.WriteLine(string.Format("SSHFS Trying unmount : {0}", opt.DriveLetter));

            if (DokanNet.DokanUnmount(opt.DriveLetter) < 0)
            {
                // If DokanUmount failed, call sshfs.Unmount to disconnect.
                ;// sshfs.Unmount(null);
            }
            // This should be called from Dokan, but not called.
            // Call here explicitly.
            sshfs.Unmount(null);
            unmount.Visible = false;
            mount.Visible   = true;
        }
        public void W()
        {
            DokanOptions opt = new DokanOptions();

            opt.DebugMode   = true;
            opt.DriveLetter = m_driveletter;
            opt.ThreadCount = 1;
            opt.VolumeLabel = REDDY.FSIDList[REDDY.mountedidx].get_drive_name();

            _userlayer = new WUserLayer(_mountedfsid);
            _userlayer.Init_IFSD();
            DokanNet.DokanMain(opt, _userlayer);
            DEFS.DEBUG("DOKAN", "done with DokanMain() dokan drive: " + m_driveletter);
            System.Threading.Thread.Sleep(10000);
        }
Example #25
0
        static void Main(string[] args)
        {
            // AllinOne te = new AllinOne();

            //Console.ReadLine();

            DokanOptions opt = new DokanOptions();

            opt.MountPoint     = "r:\\";
            opt.DebugMode      = true;
            opt.UseStdErr      = true;
            opt.VolumeLabel    = "SjtuPan";
            opt.RemovableDrive = true;
            int status = DokanNet.DokanMain(opt, new StarPanOperations());



            switch (status)
            {
            case DokanNet.DOKAN_DRIVE_LETTER_ERROR:
                Console.WriteLine("Drvie letter error");
                break;

            case DokanNet.DOKAN_DRIVER_INSTALL_ERROR:
                Console.WriteLine("Driver install error");
                break;

            case DokanNet.DOKAN_MOUNT_ERROR:
                Console.WriteLine("Mount error");
                break;

            case DokanNet.DOKAN_START_ERROR:
                Console.WriteLine("Start error");
                break;

            case DokanNet.DOKAN_ERROR:
                Console.WriteLine("Unknown error");
                break;

            case DokanNet.DOKAN_SUCCESS:
                Console.WriteLine("Success");
                break;

            default:
                Console.WriteLine("Unknown status: %d", status);
                break;
            }
        }
Example #26
0
        /// <summary>
        /// Reads buffer from backing stream
        /// </summary>
        /// <param name="buffer">Buffer that will hold </param>
        /// <param name="offset">Offset in a backing stream to start reading from</param>
        /// <param name="count">Maximum bytes to be read from stream</param>
        /// <returns>Number of bytes actually read</returns>
        public override int Read(byte[] buffer, int offset, int count)
        {
            // make sure we're not reading beyond the end of file
            if (offset > Length)
            {
                _log.Trace("Trying to read beyond the end of file.");
                return(0);
            }
            if (offset <= Length && (offset + count - 1) > Length)
            {
                count = (int)Length - offset;
                _log.Trace("This chunk is longer than our file stream. Trimed it down to {0} ({1}).", offset, count);
            }

            if (!_cacheMap.IsCached(offset, count))
            {
                _log.Trace(String.Format("Chunk {0} ({1}) is not cached", offset, count));
                var chunkList = _cacheMap.GetMissingChunks(offset, count);
                _log.Trace(String.Format("Will download {0} chunks", chunkList.Count));
                foreach (var chunk in chunkList)
                {
                    _log.Trace("Chunk #{0}", chunk);
                }
                var doneEvents = new ManualResetEvent[chunkList.Count];
                for (var i = 0; i < chunkList.Count; i++)
                {
                    var cachedFileChunk = chunkList[i];
                    doneEvents[i] = cachedFileChunk.DoneEvent;
                    ThreadPool.QueueUserWorkItem(DownloadChunk, cachedFileChunk);
                }
                do
                {
                    DokanNet.DokanResetTimeout(15000, _dokanInfo); // keep extending our time so OS will know we're still alive
                } while (!WaitHandle.WaitAll(doneEvents, 5000));
            }
            else
            {
                _log.Trace(String.Format("Chunk {0} ({1}) is cached, reading it", offset, count));
            }
            lock (_innerStream)
            {
                _innerStream.Position = _readPosition;
                _innerStream.Seek(offset, SeekOrigin.Begin);
                var read = _innerStream.Read(buffer, 0, count);
                _readPosition = _innerStream.Position;
                return(read);
            }
        }
Example #27
0
        static void Main(string[] args)
        {
            DokanOptions opt = new DokanOptions();

            opt.DriveLetter  = 'r';
            opt.NetworkDrive = true;
            opt.DebugMode    = false;
            opt.UseAltStream = false;
            opt.UseKeepAlive = true;
            opt.UseStdErr    = true;
            opt.VolumeLabel  = "MSSQLFS";

            String Server = "", Database = "", User = "", Password = "";

            opt.DriveLetter = (System.Configuration.ConfigurationSettings.AppSettings["drive"] != null) ?System.Configuration.ConfigurationSettings.AppSettings["drive"][0] : 'r';
            Server          = System.Configuration.ConfigurationSettings.AppSettings["server"];
            Database        = System.Configuration.ConfigurationSettings.AppSettings["database"];
            User            = System.Configuration.ConfigurationSettings.AppSettings["user"];
            Password        = System.Configuration.ConfigurationSettings.AppSettings["password"];
            foreach (String arg in args)
            {
                if (Regex.Match(arg, "/drive:.").Success)
                {
                    opt.DriveLetter = Regex.Split(arg, "/drive:")[1][0];
                }
                if (Regex.Match(arg, "/server:*").Success)
                {
                    Server = Regex.Split(arg, "/server:")[1];
                }
                if (Regex.Match(arg, "/database:*").Success)
                {
                    Database = Regex.Split(arg, "/database:")[1];
                }
                if (Regex.Match(arg, "/user:*").Success)
                {
                    User = Regex.Split(arg, "/user:"******"/password:*").Success)
                {
                    Password = Regex.Split(arg, "/password:"******"Data Source={0};Initial Catalog={1};Integrated Security=False;User ID={2};Password={3};Pooling=true;Min Pool Size=1;Max Pool Size=5;Connect Timeout=500", Server, Database, User, Password);

            DokanNet.DokanMain(opt, new MSSQLFS(ConnString));
        }
Example #28
0
        static void Main(string[] args)
        {
            DokanOptions opt = new DokanOptions();

            opt.MountPoint  = ConfigurationManager.AppSettings["DriveLetter"];
            opt.DebugMode   = true;
            opt.UseStdErr   = true;
            opt.VolumeLabel = "AZURE";

            // in case the volume has already been mounted
            DokanNet.DokanUnmount(opt.MountPoint[0]);

            int status = DokanNet.DokanMain(opt, new AzureOperations(ConfigurationManager.AppSettings["AzureConnectionString"], "test"));

            switch (status)
            {
            case DokanNet.DOKAN_DRIVE_LETTER_ERROR:
                Trace.WriteLine("Drive letter error");
                break;

            case DokanNet.DOKAN_DRIVER_INSTALL_ERROR:
                Trace.WriteLine("Driver install error");
                break;

            case DokanNet.DOKAN_MOUNT_ERROR:
                Trace.WriteLine("Mount error");
                break;

            case DokanNet.DOKAN_START_ERROR:
                Trace.WriteLine("Start error");
                break;

            case DokanNet.DOKAN_ERROR:
                Trace.WriteLine("Unknown error");
                break;

            case DokanNet.DOKAN_SUCCESS:
                Trace.WriteLine("Success");
                break;

            default:
                Trace.WriteLine(string.Format("Unknown status: %d", status));
                break;
            }
        }
Example #29
0
 private void desmontarToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (mounted)
     {
         DokanNet.DokanUnmount(settings.Mount[0]);
         mounted = false;
         enableControls();
     }
     else
     {
         this.Hide();
         if (!Connect())
         {
             this.Show();
             MessageBox.Show("OcurriĆ³ un error, por favor revise sus datos");
         }
     }
 }
Example #30
0
        // runs itself.  for a GUI program this needs to be invoked on a thread
        // other than the gui's main one!
        public bool exec()
        {
            Stats = new CFSStats();
            DokanOptions opt = new DokanOptions();

            opt.MountPoint     = Config.MountPoint;
            opt.DebugMode      = Logger.UsuallyDebugging && Logger.getLogger().isConsole();
            opt.UseStdErr      = Logger.UsuallyDebugging && Logger.getLogger().isConsole();
            opt.VolumeLabel    = "ChunkFS-" + Config.Name;
            opt.FileSystemName = "CFS";
            int status = DokanNet.DokanMain(opt, this);

            switch (status)
            {
            case DokanNet.DOKAN_DRIVE_LETTER_ERROR:
                Logger.getLogger().log("Drive letter error");
                break;

            case DokanNet.DOKAN_DRIVER_INSTALL_ERROR:
                Logger.getLogger().log("Driver install error");
                break;

            case DokanNet.DOKAN_MOUNT_ERROR:
                Logger.getLogger().log("Mount error");
                break;

            case DokanNet.DOKAN_START_ERROR:
                Logger.getLogger().log("Start error");
                break;

            case DokanNet.DOKAN_ERROR:
                Logger.getLogger().log("Unknown error");
                break;

            case DokanNet.DOKAN_SUCCESS:
                Logger.getLogger().log("Success");
                break;

            default:
                Logger.getLogger().log("Unknown status: " + status);
                break;
            }
            return(true);
        }
Example #31
0
        static void StartDokan(object opt)
        {
            // Start dokan
            Debug("Dokan thread: Starting main loop");
            int status = DokanNet.DokanMain(opt as DokanOptions, new Server(serverVersion));

            Debug("Dokan thread: Main loop ended");

            switch (status)
            {
            case DokanNet.DOKAN_DRIVE_LETTER_ERROR:
                Console.WriteLine("Dokan: Bad Drive letter");
                break;

            case DokanNet.DOKAN_DRIVER_INSTALL_ERROR:
                Console.WriteLine("Dokan: Can't install driver");
                break;

            case DokanNet.DOKAN_MOUNT_ERROR:
                Console.WriteLine("Can't assign a drive letter or mount point");
                break;

            case -6: // DOKAN_MOUNT_POINT_ERROR
                Console.WriteLine("Mount point is invalid");
                break;

            case DokanNet.DOKAN_START_ERROR:
                Console.WriteLine("Dokan: Driver something wrong");
                break;

            case DokanNet.DOKAN_ERROR:
                Console.WriteLine("Dokan: General Error");
                break;

            case DokanNet.DOKAN_SUCCESS:
                Console.WriteLine("Dokan: Success");
                break;

            default:
                Console.WriteLine("Unknown status: {0}", status);
                break;
            }
        }
Example #32
0
        public DokanError CreateFile(string filename, DokanNet.FileAccess access, FileShare share,
            FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info)
        {
            DokanError ret = DokanError.ErrorSuccess;

            if (filename.EndsWith(":SSHFSProperty.Cache"))
            {
                System.Diagnostics.Debug.WriteLine("SSHFS.Cache: " + filename);

                filename = filename.Remove(filename.IndexOf(":SSHFSProperty.Cache"));
                CacheEntry entry = cache_.Lookup(filename);
                entry.RemoveAllCache();
                return DokanError.ErrorSuccess;
            }

            if (mode == FileMode.Open || mode == FileMode.OpenOrCreate)
            {
                CacheEntry entry = cache_.Lookup(filename);

                if (mode == FileMode.OpenOrCreate)
                {
                    if (entry.Parrent != null)
                        entry.Parrent.RemoveFindFilesCache();
                }

                if (entry.CreateFileRet == DokanError.Undefined)
                {
                    ret = ope_.CreateFile(filename, access, share, mode, options, attributes, info);
                    entry.CreateFileRet = ret;
                }
                else
                {
                    ret = entry.CreateFileRet;
                }
            }
            else
            {
                ret = ope_.CreateFile(filename, access, share, mode, options, attributes, info);

                if (mode == FileMode.Create || mode == FileMode.CreateNew)
                {
                    CacheEntry entry = cache_.Lookup(filename);
                    if (entry.Parrent != null)
                        entry.Parrent.RemoveFindFilesCache();
                }
            }
            return ret;
        }
 NtStatus IDokanOperations.CreateFile(string fileName, DokanNet.FileAccess access, FileShare share, FileMode mode, FileOptions options, FileAttributes attributes, DokanFileInfo info)
 {
     return Operations.CreateFile(fileName, access, share, mode, options, attributes, info);
 }
Example #34
0
        public DokanError CreateFile(
            string filename,
            DokanNet.FileAccess access,
            FileShare share,
            FileMode mode,
            FileOptions options,
            FileAttributes attributes,
            DokanFileInfo info)
        {

            Debug("CreateFile {0}", filename);
            try
            {
                string path = GetPath(filename);
                ChannelSftp channel = GetChannel();

                if (CheckAltStream(path))
                    return DokanError.ErrorSuccess;

                switch (mode)
                {
                    case FileMode.Open:
                        {
                            Debug("Open");
                            if (isExist(path, info))
                                return DokanError.ErrorSuccess;
                            else
                                return DokanError.ErrorFileNotFound;
                        }
                    case FileMode.CreateNew:
                        {
                            Debug("CreateNew");
                            if (isExist(path, info))
                                return DokanError.ErrorAlreadyExists;

                            Debug("CreateNew put 0 byte");
                            Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                            stream.Close();
                            return DokanError.ErrorSuccess;
                        }
                    case FileMode.Create:
                        {
                            Debug("Create put 0 byte");
                            Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                            stream.Close();
                            return DokanError.ErrorSuccess;
                        }
                    case FileMode.OpenOrCreate:
                        {
                            Debug("OpenOrCreate");

                            if (!isExist(path, info))
                            {
                                Debug("OpenOrCreate put 0 byte");
                                Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                                stream.Close();
                            }
                            return DokanError.ErrorSuccess;
                        }
                    case FileMode.Truncate:
                        {
                            Debug("Truncate");

                            if (!isExist(path, info))
                                return DokanError.ErrorFileNotFound;

                            Debug("Truncate put 0 byte");
                            Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                            stream.Close();
                            return DokanError.ErrorSuccess;
                        }
                    case FileMode.Append:
                        {
                            Debug("Append");

                            if (isExist(path, info))
                                return DokanError.ErrorSuccess;

                            Debug("Append put 0 byte");
                            Tamir.SharpSsh.java.io.OutputStream stream = channel.put(path);
                            stream.Close();
                            return DokanError.ErrorSuccess;
                        }
                    default:
                        Debug("Error unknown FileMode {0}", mode);
                        return DokanError.ErrorError;
                }

            }
            catch (SftpException e)
            {
                Debug(e.ToString());
                return DokanError.ErrorFileNotFound;
            }
            catch (Exception e)
            {
                connectionError_ = true;
                Debug(e.ToString());
                Reconnect();
                return DokanError.ErrorFileNotFound;
            }
        }