示例#1
0
        public virtual NT_STATUS Create(UserContext userContext, string name, SearchFlag searchFlag, FileMode fileMode, FileAccess fileAccess, FileShare fileShare, FileAttributes attributes, out MTPFileContext fileContext)
        {
            if (IsDirectory)
            {
                fileContext = new MTPFileContext(this);

                return(NT_STATUS.OK);
            }

            fileContext = null;
            return(NT_STATUS.NOT_IMPLEMENTED);
        }
示例#2
0
        public override NT_STATUS Create(UserContext UserContext, string Name, SearchFlag SearchFlags, FileMode Mode, FileAccess Access, FileShare Share, FileAttributes Attributes, out FileContext fileContext)
        {
            lock (this)
            {
                FSItem item = _topItem.GetItem(Name);

                if (item != null)
                {
                    MTPFileContext mtpFileContext;
                    NT_STATUS      status = item.Create(UserContext, Name, SearchFlags, Mode, Access, Share, Attributes, out mtpFileContext);
                    fileContext = mtpFileContext;
                    return(status);
                }

                fileContext = null;
                return(NT_STATUS.NO_SUCH_FILE);
            }
        }
示例#3
0
        public override NT_STATUS Create(UserContext userContext, string name, SearchFlag searchFlag, FileMode fileMode, FileAccess fileAccess, FileShare fileShare, FileAttributes attributes, out MTPFileContext fileContext)
        {
            if (!IsDirectory)
            {
                if (fileMode == FileMode.Open)
                {
                    fileContext = new MTPFileContext(this);

                    using (BinaryReader reader = new BinaryReader(_content.OpenRead()))
                    {
                        _data = reader.ReadBytes((int)_content.Size);
                    }

                    return(NT_STATUS.OK);
                }
                else
                {
                    fileContext = null;
                    return(NT_STATUS.NOT_IMPLEMENTED);
                }
            }

            return(base.Create(userContext, name, searchFlag, fileMode, fileAccess, fileShare, attributes, out fileContext));
        }
        public override NT_STATUS Create(UserContext UserContext, string Name, SearchFlag Flags, FileMode Mode, FileAccess Access, FileShare Share, FileAttributes Attributes, out FileContext FileObject)
        {
            FileObject = null;

            string PathName = root + Name;

            try
            {
                switch (Mode)
                {
                case FileMode.Open:                     // Both work only if the file exists
                case FileMode.Truncate:
                    switch (Flags)
                    {
                    case SearchFlag.FileAndDir:
                        if (phone.Exists(PathName))
                        {
                            if (!phone.IsDirectory(PathName))
                            {
                                //FIXME: Implement FileMode and FileShare
                                FileObject = new MyFileContext(Name, false, iPhoneFile.Open(phone, PathName, Access));
                                return(NT_STATUS.OK);
                            }
                            else
                            {
                                FileObject = new MyFileContext(Name, true, null);
                                return(NT_STATUS.OK);
                            }
                        }
                        return(NT_STATUS.NO_SUCH_FILE);

                    case SearchFlag.File:
                        if (phone.Exists(PathName) && !phone.IsDirectory(PathName))
                        {
                            //FIXME: Implement FileMode and FileShare
                            FileObject = new MyFileContext(Name, false, iPhoneFile.Open(phone, PathName, Access));
                            return(NT_STATUS.OK);
                        }
                        return(NT_STATUS.NO_SUCH_FILE);;

                    case SearchFlag.Dir:
                        if (phone.Exists(PathName) && phone.IsDirectory(PathName))
                        {
                            FileObject = new MyFileContext(Name, true, null);
                            return(NT_STATUS.OK);
                        }
                        return(NT_STATUS.OBJECT_PATH_NOT_FOUND);

                    default:
                        return(NT_STATUS.INVALID_PARAMETER);
                    }

                case FileMode.CreateNew:
                    // Works only if the file does not exists
                    if (phone.Exists(PathName))
                    {
                        return(NT_STATUS.OBJECT_NAME_COLLISION);    // Access denied as it is already there
                    }
                    if (Access == FileAccess.Read)                  // Office 2003 makes the stupid call of: "CreateNew with Read access", C# refuse to execute it!
                    {
                        Access = FileAccess.ReadWrite;
                    }
                    //FIXME: Implement FileMode and FileShare
                    FileObject = new MyFileContext(Name, false, iPhoneFile.Open(phone, PathName, Access));
                    return(NT_STATUS.OK);

                case FileMode.Create:
                case FileMode.OpenOrCreate:
                    // Use existing file if possible otherwise create new
                    FileObject = new MyFileContext(Name, false, iPhoneFile.Open(phone, PathName, Access));
                    return(NT_STATUS.OK);

                default:
                    return(NT_STATUS.INVALID_PARAMETER);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Warning->Exception when opening filestream: " + ex.Message);
                return(NT_STATUS.NO_SUCH_FILE);
            }
        }
示例#5
0
        public override NT_STATUS Create(UserContext UserContext, string Name, SearchFlag Flags, FileMode Mode, FileAccess Access, FileShare Share, FileAttributes Attributes, out FileContext FileObject)
        {
            FileObject = null;

            string PathName = root + Name;

            try
            {
                switch (Mode)
                {
                    case FileMode.Open:			// Both work only if the file exists
                    case FileMode.Truncate:
                        switch (Flags)
                        {
                            case SearchFlag.FileAndDir:
                                if (phone.Exists(PathName))
                                {
                                    if (!phone.IsDirectory(PathName))
                                    {
                                        //FIXME: Implement FileMode and FileShare
                                        FileObject = new MyFileContext(Name, false, iPhoneFile.Open(phone, PathName, Access));
                                        return NT_STATUS.OK;
                                    }
                                    else
                                    {
                                        FileObject = new MyFileContext(Name, true, null);
                                        return NT_STATUS.OK;
                                    }
                                }
                                return NT_STATUS.NO_SUCH_FILE;
                            case SearchFlag.File:
                                if (phone.Exists(PathName) && !phone.IsDirectory(PathName))
                                {
                                    //FIXME: Implement FileMode and FileShare
                                    FileObject = new MyFileContext(Name, false, iPhoneFile.Open(phone, PathName, Access));
                                    return NT_STATUS.OK;
                                }
                                return NT_STATUS.NO_SUCH_FILE; ;
                            case SearchFlag.Dir:
                                if (phone.Exists(PathName) && phone.IsDirectory(PathName))
                                {
                                    FileObject = new MyFileContext(Name, true, null);
                                    return NT_STATUS.OK;
                                }
                                return NT_STATUS.OBJECT_PATH_NOT_FOUND;
                            default:
                                return NT_STATUS.INVALID_PARAMETER;
                        }

                    case FileMode.CreateNew:
                        // Works only if the file does not exists
                        if (phone.Exists(PathName))
                            return NT_STATUS.OBJECT_NAME_COLLISION;	// Access denied as it is already there

                        if (Access == FileAccess.Read)              // Office 2003 makes the stupid call of: "CreateNew with Read access", C# refuse to execute it!
                            Access = FileAccess.ReadWrite;
                        //FIXME: Implement FileMode and FileShare
                        FileObject = new MyFileContext(Name, false, iPhoneFile.Open(phone,PathName, Access));
                        return NT_STATUS.OK;

                    case FileMode.Create:
                    case FileMode.OpenOrCreate:
                        // Use existing file if possible otherwise create new
                        FileObject = new MyFileContext(Name, false, iPhoneFile.Open(phone,PathName, Access));
                        return NT_STATUS.OK;
                    default:
                        return NT_STATUS.INVALID_PARAMETER;
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Warning->Exception when opening filestream: " + ex.Message);
                return NT_STATUS.NO_SUCH_FILE;
            }
        }