public FuserFileHandler GetFileHandler(string filename, ref FuserDefinition.FUSER_FILE_INFO rawHFile)
        {
            FuserFileHandler ret = null;

            if (rawHFile.Context != 0)
            {
                int index = (int)rawHFile.Context; // TODO: remove casting
                lock (this.handlers) {
                    if (index > 0 && index <= this.ListHandlerMaxID)
                    {
                        PVCStoredHandle sh = this.handlers[index];
                        if (sh != null)
                        {
                            ret = CreateFileHandler(filename, sh.FileHandle, rawHFile);
                        }
                    }
                }
            }


            if (ret == null)
            {
                ret = RegisterFileHandler(filename, ref rawHFile);
            }
            return(ret);
        }
Ejemplo n.º 2
0
        public int CreateFile(IntPtr rawFilname, uint rawAccessMode, uint rawShare, uint rawCreationDisposition, uint rawFlagsAndAttributes, ref FuserDefinition.FUSER_FILE_INFO rawHFile)
        {
            try {
                FuserFileHandler hFile = this.hManager.RegisterFileHandler(GetFilename(rawFilname), ref rawHFile);


                FuserFileAccess access = FuserFileAccess.None;
                FileAttributes  newFileAttr;

                try {
                    newFileAttr = (FileAttributes)rawFlagsAndAttributes;
                } catch {
                    newFileAttr = 0;
                }

                FileShare   share   = FileShare.None;
                FileMode    mode    = FileMode.Open;
                FileOptions options = FileOptions.None;


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


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

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

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

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

                case FuserDefinition.CREATE_ALWAYS:
                    mode = FileMode.Create;
                    break;

                case FuserDefinition.OPEN_EXISTING:
                    mode = FileMode.Open;
                    break;

                case FuserDefinition.OPEN_ALWAYS:
                    mode = FileMode.OpenOrCreate;
                    break;

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

                Win32Returncode ret = this.fsDevice.CreateFile(hFile, access, share, mode, options, newFileAttr);

                if (hFile.IsDirectory)
                {
                    rawHFile.IsDirectory = 1;
                    // TODO: directory problem
                    //rawFlagsAndAttributes |= 0x02000000;
                }

                if (ret != Win32Returncode.SUCCESS)
                {
                    this.hManager.RemoveFileHandler(ref rawHFile);
                }

                return(ConvReturnCodeToInt(ret));
            } catch (Exception e) {
                this.hManager.RemoveFileHandler(ref rawHFile);
                this.fsDevice.LogErrorMessage("CreateFile", e.Message);
                return(ConvReturnCodeToInt(Win32Returncode.ERROR_FILE_NOT_FOUND));
            }
        }