示例#1
0
        public override Boolean ReadDirectoryEntry(
            Object FileNode0,
            Object FileDesc,
            String Pattern,
            String Marker,
            ref Object Context,
            out String FileName,
            out FileInfo FileInfo)
        {
            FileNode             FileNode   = (FileNode)FileNode0;
            IEnumerator <String> Enumerator = (IEnumerator <String>)Context;

            if (null == Enumerator)
            {
                List <String> ChildrenFileNames = new List <String>();
                if ("\\" != FileNode.FileName)
                {
                    /* if this is not the root directory add the dot entries */
                    if (null == Marker)
                    {
                        ChildrenFileNames.Add(".");
                    }
                    if (null == Marker || "." == Marker)
                    {
                        ChildrenFileNames.Add("..");
                    }
                }
                ChildrenFileNames.AddRange(FileNodeMap.GetChildrenFileNames(FileNode,
                                                                            "." != Marker && ".." != Marker ? Marker : null));
                Context = Enumerator = ChildrenFileNames.GetEnumerator();
            }

            while (Enumerator.MoveNext())
            {
                String FullFileName = Enumerator.Current;
                if ("." == FullFileName)
                {
                    FileName = ".";
                    FileInfo = FileNode.GetFileInfo();
                    return(true);
                }
                else if (".." == FullFileName)
                {
                    Int32    Result     = STATUS_SUCCESS;
                    FileNode ParentNode = FileNodeMap.GetParent(FileNode.FileName, ref Result);
                    if (null != ParentNode)
                    {
                        FileName = "..";
                        FileInfo = ParentNode.GetFileInfo();
                        return(true);
                    }
                }
                else
                {
                    FileNode ChildFileNode = FileNodeMap.Get(FullFileName);
                    if (null != ChildFileNode)
                    {
                        FileName = Path.GetFileName(FullFileName);
                        FileInfo = ChildFileNode.GetFileInfo();
                        return(true);
                    }
                }
            }

            FileName = default(String);
            FileInfo = default(FileInfo);
            return(false);
        }
示例#2
0
        public override Int32 Create(
            String FileName,
            UInt32 CreateOptions,
            UInt32 GrantedAccess,
            UInt32 FileAttributes,
            Byte[] SecurityDescriptor,
            UInt64 AllocationSize,
            out Object FileNode0,
            out Object FileDesc,
            out FileInfo FileInfo,
            out String NormalizedName)
        {
            FileNode0      = default(Object);
            FileDesc       = default(Object);
            FileInfo       = default(FileInfo);
            NormalizedName = default(String);

            FileNode FileNode;
            FileNode ParentNode;
            Int32    Result = STATUS_SUCCESS;

            FileNode = FileNodeMap.Get(FileName);
            if (null != FileNode)
            {
                return(STATUS_OBJECT_NAME_COLLISION);
            }
            ParentNode = FileNodeMap.GetParent(FileName, ref Result);
            if (null == ParentNode)
            {
                return(Result);
            }

            if (0 != (CreateOptions & FILE_DIRECTORY_FILE))
            {
                AllocationSize = 0;
            }
            if (FileNodeMap.Count() >= MaxFileNodes)
            {
                return(STATUS_CANNOT_MAKE);
            }
            if (AllocationSize > MaxFileSize)
            {
                return(STATUS_DISK_FULL);
            }

            if ("\\" != ParentNode.FileName)
            {
                /* normalize name */
                FileName = ParentNode.FileName + "\\" + Path.GetFileName(FileName);
            }
            FileNode = new FileNode(FileName);
            FileNode.MainFileNode            = FileNodeMap.GetMain(FileName);
            FileNode.FileInfo.FileAttributes = 0 != (FileAttributes & (UInt32)System.IO.FileAttributes.Directory) ?
                                               FileAttributes : FileAttributes | (UInt32)System.IO.FileAttributes.Archive;
            FileNode.FileSecurity = SecurityDescriptor;
            if (0 != AllocationSize)
            {
                Result = SetFileSizeInternal(FileNode, AllocationSize, true);
                if (0 > Result)
                {
                    return(Result);
                }
            }
            FileNodeMap.Insert(FileNode);

            Interlocked.Increment(ref FileNode.OpenCount);
            FileNode0      = FileNode;
            FileInfo       = FileNode.GetFileInfo();
            NormalizedName = FileNode.FileName;

            return(STATUS_SUCCESS);
        }
示例#3
0
        private Int32 SetFileSizeInternal(
            FileNode FileNode,
            UInt64 NewSize,
            Boolean SetAllocationSize)
        {
            if (SetAllocationSize)
            {
                if (FileNode.FileInfo.AllocationSize != NewSize)
                {
                    if (NewSize > MaxFileSize)
                    {
                        return(STATUS_DISK_FULL);
                    }

                    byte[] FileData = null;
                    if (0 != NewSize)
                    {
                        try
                        {
                            FileData = new byte[NewSize];
                        }
                        catch
                        {
                            return(STATUS_INSUFFICIENT_RESOURCES);
                        }
                    }
                    int CopyLength = (int)Math.Min(FileNode.FileInfo.AllocationSize, NewSize);
                    if (0 != CopyLength)
                    {
                        Array.Copy(FileNode.FileData, FileData, CopyLength);
                    }

                    FileNode.FileData = FileData;
                    FileNode.FileInfo.AllocationSize = NewSize;
                    if (FileNode.FileInfo.FileSize > NewSize)
                    {
                        FileNode.FileInfo.FileSize = NewSize;
                    }
                }
            }
            else
            {
                if (FileNode.FileInfo.FileSize != NewSize)
                {
                    if (FileNode.FileInfo.AllocationSize < NewSize)
                    {
                        UInt64 AllocationUnit = MEMFS_SECTOR_SIZE * MEMFS_SECTORS_PER_ALLOCATION_UNIT;
                        UInt64 AllocationSize = (NewSize + AllocationUnit - 1) / AllocationUnit * AllocationUnit;
                        Int32  Result         = SetFileSizeInternal(FileNode, AllocationSize, true);
                        if (0 > Result)
                        {
                            return(Result);
                        }
                    }

                    if (FileNode.FileInfo.FileSize < NewSize)
                    {
                        int CopyLength = (int)(NewSize - FileNode.FileInfo.FileSize);
                        if (0 != CopyLength)
                        {
                            Array.Clear(FileNode.FileData, (int)FileNode.FileInfo.FileSize, CopyLength);
                        }
                    }
                    FileNode.FileInfo.FileSize = NewSize;
                }
            }

            return(STATUS_SUCCESS);
        }
示例#4
0
 public void Insert(FileNode FileNode)
 {
     Set.Add(FileNode.FileName);
     Map.Add(FileNode.FileName, FileNode);
     TouchParent(FileNode);
 }