Exemple #1
0
        public int WriteFileProxy(
            IntPtr rawFileName,
            IntPtr rawBuffer,
            uint rawNumberOfBytesToWrite,
            ref uint rawNumberOfBytesWritten,
            long rawOffset,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);

                Byte[] buf = new Byte[rawNumberOfBytesToWrite];
                Marshal.Copy(rawBuffer, buf, 0, (int)rawNumberOfBytesToWrite);

                uint bytesWritten = 0;
                int  ret          = operations_.WriteFile(
                    file, buf, ref bytesWritten, rawOffset, GetFileInfo(ref rawFileInfo));
                if (ret == 0)
                {
                    rawNumberOfBytesWritten = bytesWritten;
                }
                return(ret);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return(-1);
            }
        }
Exemple #2
0
        public int CloseFileProxy(
            IntPtr rawFileName,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string        file = GetFileName(rawFileName);
                DokanFileInfo info = GetFileInfo(ref rawFileInfo);

                int ret = operations_.CloseFile(file, info);

                rawFileInfo.Context = 0;

                lock (infoTableLock_)
                {
                    infoTable_.Remove(info.InfoId);
                }
                return(ret);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return(-1);
            }
        }
        public static bool DokanResetTimeout(uint timeout, DokanFileInfo fileinfo)
        {
            DOKAN_FILE_INFO rawFileInfo = new DOKAN_FILE_INFO();

            rawFileInfo.DokanContext = fileinfo.DokanContext;
            return(Dokan.DokanResetTimeout(timeout, ref rawFileInfo));
        }
Exemple #4
0
        public int ReadFileProxy(
            IntPtr rawFileName,
            IntPtr rawBuffer,
            uint rawBufferLength,
            ref uint rawReadLength,
            long rawOffset,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);

                byte[] buf = new Byte[rawBufferLength];

                uint readLength = 0;
                int  ret        = operations_.ReadFile(
                    file, buf, ref readLength, rawOffset, GetFileInfo(ref rawFileInfo));
                if (ret == 0)
                {
                    rawReadLength = readLength;
                    Marshal.Copy(buf, 0, rawBuffer, (int)rawBufferLength);
                }
                return(ret);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return(-1);
            }
        }
Exemple #5
0
        public int FindFilesProxy(
            IntPtr rawFileName,
            IntPtr rawFillFindData, // function pointer
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);

                ArrayList files = new ArrayList();
                int       ret   = operations_.FindFiles(file, files, GetFileInfo(ref rawFileInfo));

                FILL_FIND_DATA fill = (FILL_FIND_DATA)Marshal.GetDelegateForFunctionPointer(
                    rawFillFindData, typeof(FILL_FIND_DATA));

                if (ret == 0)
                {
                    IEnumerator entry = files.GetEnumerator();
                    while (entry.MoveNext())
                    {
                        FileInformation fi   = (FileInformation)(entry.Current);
                        WIN32_FIND_DATA data = new WIN32_FIND_DATA();
                        //ZeroMemory(&data, sizeof(WIN32_FIND_DATAW));

                        data.dwFileAttributes = fi.Attributes;

                        data.ftCreationTime.dwHighDateTime =
                            (int)(fi.CreationTime.ToFileTime() >> 32);
                        data.ftCreationTime.dwLowDateTime =
                            (int)(fi.CreationTime.ToFileTime() & 0xffffffff);

                        data.ftLastAccessTime.dwHighDateTime =
                            (int)(fi.LastAccessTime.ToFileTime() >> 32);
                        data.ftLastAccessTime.dwLowDateTime =
                            (int)(fi.LastAccessTime.ToFileTime() & 0xffffffff);

                        data.ftLastWriteTime.dwHighDateTime =
                            (int)(fi.LastWriteTime.ToFileTime() >> 32);
                        data.ftLastWriteTime.dwLowDateTime =
                            (int)(fi.LastWriteTime.ToFileTime() & 0xffffffff);

                        data.nFileSizeLow =
                            (uint)(fi.Length & 0xffffffff);
                        data.nFileSizeHigh =
                            (uint)(fi.Length >> 32);

                        data.cFileName = fi.FileName;

                        fill(ref data, ref rawFileInfo);
                    }
                }
                return(ret);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return(-1);
            }
        }
Exemple #6
0
 public int SetFileSecurity(
     IntPtr rawFileName,
     ref SECURITY_INFORMATION rawSecurityInformation,
     ref SECURITY_DESCRIPTOR rawSecurityDescriptor,
     ref uint rawSecurityDescriptorLengthNeeded,
     ref DOKAN_FILE_INFO rawFileInfo)
 {
     return(-1);
 }
Exemple #7
0
 private void ConvertFileInfo(ref DOKAN_FILE_INFO rawInfo, DokanFileInfo info)
 {
     info.IsDirectory      = rawInfo.IsDirectory == 1;
     info.ProcessId        = rawInfo.ProcessId;
     info.PagingIo         = rawInfo.PagingIo == 1;
     info.DeleteOnClose    = rawInfo.DeleteOnClose == 1;
     info.SynchronousIo    = rawInfo.SynchronousIo == 1;
     info.Nocache          = rawInfo.Nocache == 1;
     info.WriteToEndOfFile = rawInfo.WriteToEndOfFile == 1;
 }
Exemple #8
0
 private void ConvertFileInfo(ref DOKAN_FILE_INFO rawInfo, DokanFileInfo info)
 {
     info.IsDirectory = rawInfo.IsDirectory == 1;
     info.ProcessId = rawInfo.ProcessId;
     info.PagingIo = rawInfo.PagingIo == 1;
     info.DeleteOnClose = rawInfo.DeleteOnClose == 1;
     info.SynchronousIo = rawInfo.SynchronousIo == 1;
     info.Nocache = rawInfo.Nocache == 1;
     info.WriteToEndOfFile = rawInfo.WriteToEndOfFile == 1;
 }
Exemple #9
0
 public int UnmountProxy(
     ref DOKAN_FILE_INFO rawFileInfo)
 {
     try
     {
         return(operations_.Unmount(GetFileInfo(ref rawFileInfo)));
     }
     catch (Exception e)
     {
         Console.Error.WriteLine(e.ToString());
         return(-1);
     }
 }
Exemple #10
0
 public int DeleteDirectoryProxy(
     IntPtr rawFileName,
     ref DOKAN_FILE_INFO rawFileInfo)
 {
     try
     {
         string file = GetFileName(rawFileName);
         return(operations_.DeleteDirectory(file, GetFileInfo(ref rawFileInfo)));
     }
     catch (Exception e)
     {
         Console.Error.WriteLine(e.ToString());
         return(-1);
     }
 }
Exemple #11
0
        private DokanFileInfo GetNewFileInfo(ref DOKAN_FILE_INFO rawFileInfo)
        {
            DokanFileInfo fileInfo = new DokanFileInfo(rawFileInfo.DokanContext);

            lock (infoTableLock_)
            {
                fileInfo.InfoId = ++infoId_;

                rawFileInfo.Context = fileInfo.InfoId;
                ConvertFileInfo(ref rawFileInfo, fileInfo);
                // to avoid GC
                infoTable_[fileInfo.InfoId] = fileInfo;
            }
            return(fileInfo);
        }
Exemple #12
0
        private DokanFileInfo GetNewFileInfo(ref DOKAN_FILE_INFO rawFileInfo)
        {
            DokanFileInfo fileInfo = new DokanFileInfo(rawFileInfo.DokanContext);

            lock (infoTableLock_)
            {
                fileInfo.InfoId = ++infoId_;

                rawFileInfo.Context = fileInfo.InfoId;
                ConvertFileInfo(ref rawFileInfo, fileInfo);
                // to avoid GC
                infoTable_[fileInfo.InfoId] = fileInfo;
            }
            return fileInfo;
        }
Exemple #13
0
 public int FlushFileBuffersProxy(
     IntPtr rawFileName,
     ref DOKAN_FILE_INFO rawFileInfo)
 {
     try
     {
         string file = GetFileName(rawFileName);
         int    ret  = operations_.FlushFileBuffers(file, GetFileInfo(ref rawFileInfo));
         return(ret);
     }
     catch (Exception e)
     {
         Console.Error.WriteLine(e.ToString());
         return(-1);
     }
 }
Exemple #14
0
        public int SetFileTimeProxy(
            IntPtr rawFileName,
            ref ComTypes.FILETIME rawCreationTime,
            ref ComTypes.FILETIME rawLastAccessTime,
            ref ComTypes.FILETIME rawLastWriteTime,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);

                long time;

                time = ((long)rawCreationTime.dwHighDateTime << 32) + (uint)rawCreationTime.dwLowDateTime;
                DateTime ctime = DateTime.FromFileTime(time);

                if (time == 0)
                {
                    ctime = DateTime.MinValue;
                }

                time = ((long)rawLastAccessTime.dwHighDateTime << 32) + (uint)rawLastAccessTime.dwLowDateTime;
                DateTime atime = DateTime.FromFileTime(time);

                if (time == 0)
                {
                    atime = DateTime.MinValue;
                }

                time = ((long)rawLastWriteTime.dwHighDateTime << 32) + (uint)rawLastWriteTime.dwLowDateTime;
                DateTime mtime = DateTime.FromFileTime(time);

                if (time == 0)
                {
                    mtime = DateTime.MinValue;
                }

                return(operations_.SetFileTime(
                           file, ctime, atime, mtime, GetFileInfo(ref rawFileInfo)));
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return(-1);
            }
        }
Exemple #15
0
        public int SetAllocationSizeProxy(
            IntPtr rawFileName,
            long rawLength,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);

                return(operations_.SetAllocationSize(file, rawLength, GetFileInfo(ref rawFileInfo)));
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return(-1);
            }
        }
Exemple #16
0
        public int GetFileInformationProxy(
            IntPtr rawFileName,
            ref BY_HANDLE_FILE_INFORMATION rawHandleFileInformation,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);

                FileInformation fi = new FileInformation();

                int ret = operations_.GetFileInformation(file, fi, GetFileInfo(ref rawFileInfo));

                if (ret == 0)
                {
                    rawHandleFileInformation.dwFileAttributes = (uint)fi.Attributes;

                    rawHandleFileInformation.ftCreationTime.dwHighDateTime =
                        (int)(fi.CreationTime.ToFileTime() >> 32);
                    rawHandleFileInformation.ftCreationTime.dwLowDateTime =
                        (int)(fi.CreationTime.ToFileTime() & 0xffffffff);

                    rawHandleFileInformation.ftLastAccessTime.dwHighDateTime =
                        (int)(fi.LastAccessTime.ToFileTime() >> 32);
                    rawHandleFileInformation.ftLastAccessTime.dwLowDateTime =
                        (int)(fi.LastAccessTime.ToFileTime() & 0xffffffff);

                    rawHandleFileInformation.ftLastWriteTime.dwHighDateTime =
                        (int)(fi.LastWriteTime.ToFileTime() >> 32);
                    rawHandleFileInformation.ftLastWriteTime.dwLowDateTime =
                        (int)(fi.LastWriteTime.ToFileTime() & 0xffffffff);

                    rawHandleFileInformation.nFileSizeLow =
                        (uint)(fi.Length & 0xffffffff);
                    rawHandleFileInformation.nFileSizeHigh =
                        (uint)(fi.Length >> 32);
                }

                return(ret);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return(-1);
            }
        }
Exemple #17
0
        public int SetFileAttributesProxy(
            IntPtr rawFileName,
            uint rawAttributes,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);

                FileAttributes attr = (FileAttributes)rawAttributes;
                return(operations_.SetFileAttributes(file, attr, GetFileInfo(ref rawFileInfo)));
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return(-1);
            }
        }
Exemple #18
0
        private DokanFileInfo GetFileInfo(ref DOKAN_FILE_INFO rawFileInfo)
        {
            DokanFileInfo fileInfo = null;
            lock (infoTableLock_)
            {
                if (rawFileInfo.Context != 0)
                {
                    infoTable_.TryGetValue(rawFileInfo.Context, out fileInfo);
                }

                if (fileInfo == null)
                {
                    // bug?
                    fileInfo = new DokanFileInfo(rawFileInfo.DokanContext);
                }
                ConvertFileInfo(ref rawFileInfo, fileInfo);
            }
            return fileInfo;
        }
Exemple #19
0
        private DokanFileInfo GetFileInfo(ref DOKAN_FILE_INFO rawFileInfo)
        {
            DokanFileInfo fileInfo = null;

            lock (infoTableLock_)
            {
                if (rawFileInfo.Context != 0)
                {
                    infoTable_.TryGetValue(rawFileInfo.Context, out fileInfo);
                }

                if (fileInfo == null)
                {
                    // bug?
                    fileInfo = new DokanFileInfo(rawFileInfo.DokanContext);
                }
                ConvertFileInfo(ref rawFileInfo, fileInfo);
            }
            return(fileInfo);
        }
Exemple #20
0
 public int GetDiskFreeSpaceProxy(
     ref ulong rawFreeBytesAvailable,
     ref ulong rawTotalNumberOfBytes,
     ref ulong rawTotalNumberOfFreeBytes,
     ref DOKAN_FILE_INFO rawFileInfo)
 {
     try
     {
         return(operations_.GetDiskFreeSpace(
                    ref rawFreeBytesAvailable,
                    ref rawTotalNumberOfBytes,
                    ref rawTotalNumberOfFreeBytes,
                    GetFileInfo(ref rawFileInfo)));
     }
     catch (Exception e)
     {
         Console.Error.WriteLine(e.ToString());
         return(-1);
     }
 }
Exemple #21
0
        public int MoveFileProxy(
            IntPtr rawFileName,
            IntPtr rawNewFileName,
            int rawReplaceIfExisting,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file    = GetFileName(rawFileName);
                string newfile = GetFileName(rawNewFileName);

                return(operations_.MoveFile(
                           file, newfile, rawReplaceIfExisting != 0 ? true : false,
                           GetFileInfo(ref rawFileInfo)));
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return(-1);
            }
        }
Exemple #22
0
        public int GetVolumeInformationProxy(
            IntPtr rawVolumeNameBuffer,
            uint rawVolumeNameSize,
            ref uint rawVolumeSerialNumber,
            ref uint rawMaximumComponentLength,
            ref uint rawFileSystemFlags,
            IntPtr rawFileSystemNameBuffer,
            uint rawFileSystemNameSize,
            ref DOKAN_FILE_INFO FileInfo)
        {
            byte[] volume = System.Text.Encoding.Unicode.GetBytes(options_.VolumeLabel);
            Marshal.Copy(volume, 0, rawVolumeNameBuffer, Math.Min((int)rawVolumeNameSize, volume.Length));
            rawVolumeSerialNumber     = 0x19831116;
            rawMaximumComponentLength = 256;

            // FILE_CASE_SENSITIVE_SEARCH |
            // FILE_CASE_PRESERVED_NAMES |
            // FILE_UNICODE_ON_DISK
            rawFileSystemFlags = 7;

            byte[] sys = System.Text.Encoding.Unicode.GetBytes("DOKAN");
            Marshal.Copy(sys, 0, rawFileSystemNameBuffer, Math.Min((int)rawFileSystemNameSize, sys.Length));
            return(0);
        }
Exemple #23
0
        public int ReadFileProxy(
            IntPtr rawFileName,
            IntPtr rawBuffer,
            uint rawBufferLength,
            ref uint rawReadLength,
            long rawOffset,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);

                byte[] buf = new Byte[rawBufferLength];

                uint readLength = 0;
                int ret = operations_.ReadFile(
                    file, buf, ref readLength, rawOffset, GetFileInfo(ref rawFileInfo));
                if (ret == 0)
                {
                    rawReadLength = readLength;
                    Marshal.Copy(buf, 0, rawBuffer, (int)rawBufferLength);
                }
                return ret;

            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return -1;
            }
        }
Exemple #24
0
        public int CreateFileProxy(
            IntPtr rawFileName,
            uint rawAccessMode,
            uint rawShare,
            uint rawCreationDisposition,
            uint rawFlagsAndAttributes,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);

                DokanFileInfo info = GetNewFileInfo(ref rawFileInfo);
                
                FileAccess access = FileAccess.Read;
                FileShare share = FileShare.None;
                FileMode mode = FileMode.Open;
                FileOptions options = FileOptions.None;

                if ((rawAccessMode & FILE_READ_DATA) != 0 && (rawAccessMode & FILE_WRITE_DATA) != 0)
                {
                    access = FileAccess.ReadWrite;
                }
                else if ((rawAccessMode & FILE_WRITE_DATA) != 0)
                {
                    access = FileAccess.Write;
                }
                else
                {
                    access = FileAccess.Read;
                }

                if ((rawShare & FILE_SHARE_READ) != 0)
                {
                    share = FileShare.Read;
                }

                if ((rawShare & FILE_SHARE_WRITE) != 0)
                {
                    share |= FileShare.Write;
                }

                if ((rawShare & FILE_SHARE_DELETE) != 0)
                {
                    share |= FileShare.Delete;
                }

                switch (rawCreationDisposition)
                {
                    case CREATE_NEW:
                        mode = FileMode.CreateNew;
                        break;
                    case CREATE_ALWAYS:
                        mode = FileMode.Create;
                        break;
                    case OPEN_EXISTING:
                        mode = FileMode.Open;
                        break;
                    case OPEN_ALWAYS:
                        mode = FileMode.OpenOrCreate;
                        break;
                    case TRUNCATE_EXISTING:
                        mode = FileMode.Truncate;
                        break;
                }

                int ret = operations_.CreateFile(file, access, share, mode, options, info);

                if (info.IsDirectory)
                    rawFileInfo.IsDirectory = 1;

                return ret;
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return -2;
            }

        }
Exemple #25
0
        public int CloseFileProxy(
            IntPtr rawFileName,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);
                DokanFileInfo info = GetFileInfo(ref rawFileInfo);

                int ret = operations_.CloseFile(file, info);

                rawFileInfo.Context = 0;

                lock (infoTableLock_)
                {
                    infoTable_.Remove(info.InfoId);
                }
                return ret;

            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return -1;
            }
        }
Exemple #26
0
        public int CreateFileProxy(
            IntPtr rawFileName,
            uint rawAccessMode,
            uint rawShare,
            uint rawCreationDisposition,
            uint rawFlagsAndAttributes,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);

                DokanFileInfo info = GetNewFileInfo(ref rawFileInfo);

                FileAccess  access  = FileAccess.Read;
                FileShare   share   = FileShare.None;
                FileMode    mode    = FileMode.Open;
                FileOptions options = FileOptions.None;

                if ((rawAccessMode & FILE_READ_DATA) != 0 && (rawAccessMode & FILE_WRITE_DATA) != 0)
                {
                    access = FileAccess.ReadWrite;
                }
                else if ((rawAccessMode & FILE_WRITE_DATA) != 0)
                {
                    access = FileAccess.Write;
                }
                else
                {
                    access = FileAccess.Read;
                }

                if ((rawShare & FILE_SHARE_READ) != 0)
                {
                    share = FileShare.Read;
                }

                if ((rawShare & FILE_SHARE_WRITE) != 0)
                {
                    share |= FileShare.Write;
                }

                if ((rawShare & FILE_SHARE_DELETE) != 0)
                {
                    share |= FileShare.Delete;
                }

                switch (rawCreationDisposition)
                {
                case CREATE_NEW:
                    mode = FileMode.CreateNew;
                    break;

                case CREATE_ALWAYS:
                    mode = FileMode.Create;
                    break;

                case OPEN_EXISTING:
                    mode = FileMode.Open;
                    break;

                case OPEN_ALWAYS:
                    mode = FileMode.OpenOrCreate;
                    break;

                case TRUNCATE_EXISTING:
                    mode = FileMode.Truncate;
                    break;
                }

                int ret = operations_.CreateFile(file, access, share, mode, options, info);

                if (info.IsDirectory)
                {
                    rawFileInfo.IsDirectory = 1;
                }

                return(ret);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return(-2);
            }
        }
Exemple #27
0
        public int WriteFileProxy(IntPtr rawFileName, IntPtr rawBuffer, uint rawNumberOfBytesToWrite, ref uint rawNumberOfBytesWritten, long rawOffset, ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);

                Byte[] buf = new Byte[rawNumberOfBytesToWrite];
                Marshal.Copy(rawBuffer, buf, 0, (int)rawNumberOfBytesToWrite);

                var Stream = ((IDokanFile)GetFileInfo(ref rawFileInfo).Context).Stream;

                Stream.Position = rawOffset;
                Stream.Write(buf, 0, (int)rawNumberOfBytesToWrite);

                rawNumberOfBytesWritten = rawNumberOfBytesToWrite;
                return 0;

            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return -1;
            }
        }
Exemple #28
0
        public int GetFileInformationProxy(
            IntPtr rawFileName,
            ref BY_HANDLE_FILE_INFORMATION rawHandleFileInformation,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
          
            try
            {
                string file = GetFileName(rawFileName);

                FileInformation fi = new FileInformation();

                int ret = operations_.GetFileInformation(file, ref fi, GetFileInfo(ref rawFileInfo));

                if (ret == 0)
                {
                    rawHandleFileInformation.dwFileAttributes = (uint)fi.Attributes;

                    rawHandleFileInformation.ftCreationTime.dwHighDateTime =
                        (int)(fi.CreationTime.ToFileTime() >> 32);
                    rawHandleFileInformation.ftCreationTime.dwLowDateTime =
                        (int)(fi.CreationTime.ToFileTime() & 0xffffffff);

                    rawHandleFileInformation.ftLastAccessTime.dwHighDateTime =
                        (int)(fi.LastAccessTime.ToFileTime() >> 32);
                    rawHandleFileInformation.ftLastAccessTime.dwLowDateTime =
                        (int)(fi.LastAccessTime.ToFileTime() & 0xffffffff);

                    rawHandleFileInformation.ftLastWriteTime.dwHighDateTime =
                        (int)(fi.LastWriteTime.ToFileTime() >> 32);
                    rawHandleFileInformation.ftLastWriteTime.dwLowDateTime =
                        (int)(fi.LastWriteTime.ToFileTime() & 0xffffffff);

                    rawHandleFileInformation.nFileSizeLow =
                        (uint)(fi.Length & 0xffffffff);
                    rawHandleFileInformation.nFileSizeHigh =
                        (uint)(fi.Length >> 32);
                }

                return ret;

            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return -1;
            }

        }
Exemple #29
0
        public int CreateFileProxy(
            IntPtr rawFileName,
            uint rawAccessMode,
            uint rawShare,
            uint rawCreationDisposition,
            uint rawFlagsAndAttributes,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);

                DokanFileInfo info = GetNewFileInfo(ref rawFileInfo);

                FileAccess  access  = FileAccess.Read;
                FileShare   share   = FileShare.None;
                FileMode    mode    = FileMode.Open;
                FileOptions options = FileOptions.None;

                if ((rawAccessMode & FILE_READ_DATA) != 0 && (rawAccessMode & FILE_WRITE_DATA) != 0)
                {
                    access = FileAccess.ReadWrite;
                }
                else if ((rawAccessMode & FILE_WRITE_DATA) != 0)
                {
                    access = FileAccess.Write;
                }
                else
                {
                    access = FileAccess.Read;
                }

                if ((rawShare & FILE_SHARE_READ) != 0)
                {
                    share = FileShare.Read;
                }

                if ((rawShare & FILE_SHARE_WRITE) != 0)
                {
                    share |= FileShare.Write;
                }

                if ((rawShare & FILE_SHARE_DELETE) != 0)
                {
                    share |= FileShare.Delete;
                }

                if ((rawFlagsAndAttributes & FILE_FLAG_DELETE_ON_CLOSE) != 0)
                {
                    options |= FileOptions.DeleteOnClose;
                }

                if ((rawFlagsAndAttributes & FILE_FLAG_WRITE_THROUGH) != 0)
                {
                    options |= FileOptions.WriteThrough;
                }

                if ((rawFlagsAndAttributes & FILE_FLAG_SEQUENTIAL_SCAN) != 0)
                {
                    options |= FileOptions.SequentialScan;
                }

                if ((rawFlagsAndAttributes & FILE_FLAG_RANDOM_ACCESS) != 0)
                {
                    options |= FileOptions.RandomAccess;
                }

                if ((rawFlagsAndAttributes & FILE_FLAG_OVERLAPPED) != 0)
                {
                    options |= FileOptions.Asynchronous;
                }
                // TODO: supports FileOptions.Encrypted

                switch (rawCreationDisposition)
                {
                case CREATE_NEW:
                    mode = FileMode.CreateNew;
                    break;

                case CREATE_ALWAYS:
                    mode = FileMode.Create;
                    break;

                case OPEN_EXISTING:
                    mode = FileMode.Open;
                    break;

                case OPEN_ALWAYS:
                    mode = FileMode.OpenOrCreate;
                    break;

                case TRUNCATE_EXISTING:
                    mode = FileMode.Truncate;
                    break;
                }

                int ret = operations_.CreateFile(file, access, share, mode, options, info);

                if (info.IsDirectory)
                {
                    rawFileInfo.IsDirectory = 1;
                }

                return(ret);
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return(-2);
            }
        }
Exemple #30
0
        public int GetFileInformationProxy(
            IntPtr rawFileName,
            ref BY_HANDLE_FILE_INFORMATION rawHandleFileInformation,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);

                var fi = operations_.GetFileInformation(file, GetFileInfo(ref rawFileInfo));

                rawHandleFileInformation.dwFileAttributes = (uint)fi.Attributes;

                rawHandleFileInformation.ftCreationTime.dwHighDateTime = (int)(fi.CreationTime.ToFileTime() >> 32);
                rawHandleFileInformation.ftCreationTime.dwLowDateTime = (int)(fi.CreationTime.ToFileTime() & 0xffffffff);
                rawHandleFileInformation.ftLastAccessTime.dwHighDateTime = (int)(fi.LastAccessTime.ToFileTime() >> 32);
                rawHandleFileInformation.ftLastAccessTime.dwLowDateTime = (int)(fi.LastAccessTime.ToFileTime() & 0xffffffff);
                rawHandleFileInformation.ftLastWriteTime.dwHighDateTime = (int)(fi.LastWriteTime.ToFileTime() >> 32);
                rawHandleFileInformation.ftLastWriteTime.dwLowDateTime = (int)(fi.LastWriteTime.ToFileTime() & 0xffffffff);
                rawHandleFileInformation.nFileSizeLow = (uint)(fi.Length & 0xffffffff);
                rawHandleFileInformation.nFileSizeHigh = (uint)(fi.Length >> 32);

                return 0;

            }
            catch (FileNotFoundException e)
            {
                return DokanNet.ERROR_FILE_NOT_FOUND;
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return -1;
            }
        }
Exemple #31
0
        public int OpenDirectoryProxy(
            IntPtr rawFileName,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);

                DokanFileInfo info = GetNewFileInfo(ref rawFileInfo);
                operations_.OpenDirectory(file, info);

                return 0;

            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return -1;
            }
        }
Exemple #32
0
        public int FindFilesWithPatternProxy(
            IntPtr rawFileName,
			IntPtr rawSearchPattern,
            IntPtr rawFillFindData, // function pointer
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);
                string searchPattern = GetFileName(rawSearchPattern);
                var files = operations_.FindFilesWithPattern(file, searchPattern, GetFileInfo(ref rawFileInfo));

                FILL_FIND_DATA fill = (FILL_FIND_DATA)Marshal.GetDelegateForFunctionPointer(
                    rawFillFindData, typeof(FILL_FIND_DATA));

                foreach (var fi in files)
                {
                    var data = new WIN32_FIND_DATA();
                    //ZeroMemory(&data, sizeof(WIN32_FIND_DATAW));

                    data.dwFileAttributes = fi.Attributes;

                    data.ftCreationTime.dwHighDateTime = (int)(fi.CreationTime.ToFileTime() >> 32);
                    data.ftCreationTime.dwLowDateTime = (int)(fi.CreationTime.ToFileTime() & 0xffffffff);
                    data.ftLastAccessTime.dwHighDateTime = (int)(fi.LastAccessTime.ToFileTime() >> 32);
                    data.ftLastAccessTime.dwLowDateTime = (int)(fi.LastAccessTime.ToFileTime() & 0xffffffff);
                    data.ftLastWriteTime.dwHighDateTime = (int)(fi.LastWriteTime.ToFileTime() >> 32);
                    data.ftLastWriteTime.dwLowDateTime = (int)(fi.LastWriteTime.ToFileTime() & 0xffffffff);
                    data.nFileSizeLow = (uint)(fi.Length & 0xffffffff);
                    data.nFileSizeHigh = (uint)(fi.Length >> 32);

                    data.cFileName = fi.FileName;

                    fill(ref data, ref rawFileInfo);
                }

                return 0;
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return -1;
            }
        }
Exemple #33
0
        public int FlushFileBuffersProxy(
            IntPtr rawFileName,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);
                ((IDokanFile)GetFileInfo(ref rawFileInfo).Context).Stream.Flush();
                return 0;

            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return -1;
            }
        }
Exemple #34
0
 public static extern bool DokanResetTimeout(uint timeout, ref DOKAN_FILE_INFO rawFileInfo);
Exemple #35
0
        public int CloseFileProxy(
            IntPtr rawFileName,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);
                var info = GetFileInfo(ref rawFileInfo);
                if (info.Context == null) return DokanNet.ERROR_FILE_NOT_FOUND;

                ((IDokanFile)info.Context).Stream.Close();
                rawFileInfo.Context = 0;

                lock (infoTableLock_)
                {
                    infoTable_.Remove(info.InfoId);
                }
                return 0;

            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return -1;
            }
        }
Exemple #36
0
        public int CleanupProxy(
            IntPtr rawFileName,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);
                operations_.Cleanup(file, GetFileInfo(ref rawFileInfo));
                return 0;

            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return -1;
            }
        }
Exemple #37
0
        public int WriteFileProxy(
            IntPtr rawFileName,
            IntPtr rawBuffer,
            uint rawNumberOfBytesToWrite,
            ref uint rawNumberOfBytesWritten,
            long rawOffset,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);

                Byte[] buf = new Byte[rawNumberOfBytesToWrite];
                Marshal.Copy(rawBuffer, buf, 0, (int)rawNumberOfBytesToWrite);

                uint bytesWritten = 0;
                int ret = operations_.WriteFile(
                    file, buf, ref bytesWritten, rawOffset, GetFileInfo(ref rawFileInfo));
                if (ret == 0)
                    rawNumberOfBytesWritten = bytesWritten;
                return ret;

            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return -1;
            }
        }
Exemple #38
0
        public int ReadFileProxy(
            IntPtr rawFileName,
            IntPtr rawBuffer,
            uint rawBufferLength,
            ref uint rawReadLength,
            long rawOffset,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);

                byte[] buf = new Byte[rawBufferLength];

                var Stream = ((IDokanFile)(GetFileInfo(ref rawFileInfo).Context)).Stream;

                Stream.Position = rawOffset;
                rawReadLength = (uint)Stream.Read(buf, 0, (int)rawBufferLength);
                Marshal.Copy(buf, 0, rawBuffer, (int)rawBufferLength);
                return 0;

            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return -1;
            }
        }
Exemple #39
0
        public int FlushFileBuffersProxy(
            IntPtr rawFileName,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);
                int ret = operations_.FlushFileBuffers(file, GetFileInfo(ref rawFileInfo));
                return ret;

            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return -1;
            }
        }
Exemple #40
0
        public int SetAllocationSizeProxy(IntPtr rawFileName, long rawLength, ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);

                operations_.SetAllocationSize(file, rawLength, GetFileInfo(ref rawFileInfo));
                return 0;
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return -1;
            }
        }
Exemple #41
0
        public int FindFilesProxy(
            IntPtr rawFileName,
            IntPtr rawFillFindData, // function pointer
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            String S;
            try
            {
                string file = GetFileName(rawFileName);

                ArrayList files = new ArrayList();
                int ret = operations_.FindFiles(file, files, GetFileInfo(ref rawFileInfo));

                FILL_FIND_DATA fill = (FILL_FIND_DATA)Marshal.GetDelegateForFunctionPointer(
                    rawFillFindData, typeof(FILL_FIND_DATA));

                if (ret == 0)
                {
                    IEnumerator entry = files.GetEnumerator();
                    while (entry.MoveNext())
                    {
                        FileInformation fi = (FileInformation)(entry.Current);
                        S = fi.FileName;
                        WIN32_FIND_DATA data = new WIN32_FIND_DATA();
                        //ZeroMemory(&data, sizeof(WIN32_FIND_DATAW));

                        data.dwFileAttributes = fi.Attributes;

                        data.ftCreationTime.dwHighDateTime =
                            (int)(fi.CreationTime.ToFileTime() >> 32);
                        data.ftCreationTime.dwLowDateTime =
                            (int)(fi.CreationTime.ToFileTime() & 0xffffffff);

                        data.ftLastAccessTime.dwHighDateTime =
                            (int)(fi.LastAccessTime.ToFileTime() >> 32);
                        data.ftLastAccessTime.dwLowDateTime =
                            (int)(fi.LastAccessTime.ToFileTime() & 0xffffffff);

                        data.ftLastWriteTime.dwHighDateTime =
                            (int)(fi.LastWriteTime.ToFileTime() >> 32);
                        data.ftLastWriteTime.dwLowDateTime =
                            (int)(fi.LastWriteTime.ToFileTime() & 0xffffffff);

                        data.nFileSizeLow =
                            (uint)(fi.Length & 0xffffffff);
                        data.nFileSizeHigh =
                            (uint)(fi.Length >> 32);

                        data.cFileName = fi.FileName;

                        fill(ref data, ref rawFileInfo);
                    }

                }
                return ret;

            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return -1;
            }

        }
Exemple #42
0
 public static extern bool DokanResetTimeout(uint timeout, ref DOKAN_FILE_INFO rawFileInfo);
Exemple #43
0
        public int SetFileAttributesProxy(
            IntPtr rawFileName,
            uint rawAttributes,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);

                FileAttributes attr = (FileAttributes)rawAttributes;
                return operations_.SetFileAttributes(file, attr, GetFileInfo(ref rawFileInfo));

            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return -1;
            }
        }
Exemple #44
0
        public int SetFileTimeProxy(
            IntPtr rawFileName,
            ref ComTypes.FILETIME rawCreationTime,
            ref ComTypes.FILETIME rawLastAccessTime,
            ref ComTypes.FILETIME rawLastWriteTime,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);

                long time;

                time = ((long)rawCreationTime.dwHighDateTime << 32) + (uint)rawCreationTime.dwLowDateTime;
                DateTime ctime = DateTime.FromFileTime(time);
                
                if (time == 0)
                    ctime = DateTime.MinValue;

                time = ((long)rawLastAccessTime.dwHighDateTime << 32) + (uint)rawLastAccessTime.dwLowDateTime;
                DateTime atime = DateTime.FromFileTime(time);

                if (time == 0)
                    atime = DateTime.MinValue;

                time = ((long)rawLastWriteTime.dwHighDateTime << 32) + (uint)rawLastWriteTime.dwLowDateTime;
                DateTime mtime = DateTime.FromFileTime(time);

                if (time == 0)
                    mtime = DateTime.MinValue;

                return operations_.SetFileTime(
                    file, ctime, atime, mtime, GetFileInfo(ref rawFileInfo));

            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return -1;
            }
        }
Exemple #45
0
 public int UnmountProxy(
     ref DOKAN_FILE_INFO rawFileInfo)
 {
     try
     {
         return operations_.Unmount(GetFileInfo(ref rawFileInfo));
     }
     catch (Exception e)
     {
         Console.Error.WriteLine(e.ToString());
         return -1;
     }
 }
Exemple #46
0
        public int GetVolumeInformationProxy(
            IntPtr rawVolumeNameBuffer,
            uint rawVolumeNameSize,
            ref uint rawVolumeSerialNumber,
            ref uint rawMaximumComponentLength,
            ref uint rawFileSystemFlags,
            IntPtr rawFileSystemNameBuffer,
            uint rawFileSystemNameSize,
            ref DOKAN_FILE_INFO FileInfo)
        {
            byte[] volume = System.Text.Encoding.Unicode.GetBytes(options_.VolumeLabel);
            Marshal.Copy(volume, 0, rawVolumeNameBuffer, Math.Min((int)rawVolumeNameSize, volume.Length));
            rawVolumeSerialNumber = 0x19831116;
            rawMaximumComponentLength = 256;

            // FILE_CASE_SENSITIVE_SEARCH | 
            // FILE_CASE_PRESERVED_NAMES |
            // FILE_UNICODE_ON_DISK
            rawFileSystemFlags = 7;

            byte[] sys = System.Text.Encoding.Unicode.GetBytes("DOKAN");
            Marshal.Copy(sys, 0, rawFileSystemNameBuffer, Math.Min((int)rawFileSystemNameSize, sys.Length));
            return DokanNet.DOKAN_SUCCESS;
        }
Exemple #47
0
 public int DeleteDirectoryProxy(
     IntPtr rawFileName,
     ref DOKAN_FILE_INFO rawFileInfo)
 {
     var FileInfo = GetFileInfo(ref rawFileInfo);
     return HandleExceptions(() =>
     {
         string file = GetFileName(rawFileName);
         operations_.DeleteDirectory(file, FileInfo);
     });
 }
Exemple #48
0
 public int GetDiskFreeSpaceProxy(
     ref ulong rawFreeBytesAvailable,
     ref ulong rawTotalNumberOfBytes,
     ref ulong rawTotalNumberOfFreeBytes,
     ref DOKAN_FILE_INFO rawFileInfo)
 {
     try
     {
         return operations_.GetDiskFreeSpace(
             ref rawFreeBytesAvailable,
             ref rawTotalNumberOfBytes,
             ref rawTotalNumberOfFreeBytes,
             GetFileInfo(ref rawFileInfo));
     }
     catch (Exception e)
     {
         Console.Error.WriteLine(e.ToString());
         return -1;
     }
 }
Exemple #49
0
        public int UnlockFileProxy(
            IntPtr rawFileName,
            long rawByteOffset,
            long rawLength,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);
                return operations_.UnlockFile(
                    file, rawByteOffset, rawLength, GetFileInfo(ref rawFileInfo));

            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return -1;
            }
        }
Exemple #50
0
        public int MoveFileProxy(
            IntPtr rawFileName,
            IntPtr rawNewFileName,
            int rawReplaceIfExisting,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);
                string newfile = GetFileName(rawNewFileName);

                return operations_.MoveFile(
                    file, newfile, rawReplaceIfExisting != 0 ? true : false,
                    GetFileInfo(ref rawFileInfo));

            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return -1;
            }
        }
Exemple #51
0
        public int DeleteDirectoryProxy(
            IntPtr rawFileName,
            ref DOKAN_FILE_INFO rawFileInfo)
        {
            try
            {
                string file = GetFileName(rawFileName);
                return operations_.DeleteDirectory(file, GetFileInfo(ref rawFileInfo));

            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.ToString());
                return -1;
            }
        }
Exemple #52
-1
 public int SetFileSecurity(
     IntPtr rawFileName,
     ref SECURITY_INFORMATION rawSecurityInformation,
     ref SECURITY_DESCRIPTOR rawSecurityDescriptor,
     ref uint rawSecurityDescriptorLengthNeeded,
     ref DOKAN_FILE_INFO rawFileInfo)
 {
     return -1;
 }