Exemple #1
0
        public override Int32 Overwrite(
            Object FileNode0,
            Object FileDesc,
            UInt32 FileAttributes,
            Boolean ReplaceFileAttributes,
            UInt64 AllocationSize,
            out FileInfo FileInfo)
        {
            FileInfo = default(FileInfo);

            FileNode FileNode = (FileNode)FileNode0;
            Int32    Result;

            List <String> StreamFileNames = new List <String>(FileNodeMap.GetStreamFileNames(FileNode));

            foreach (String StreamFileName in StreamFileNames)
            {
                FileNode StreamNode = FileNodeMap.Get(StreamFileName);
                if (null == StreamNode)
                {
                    continue; /* should not happen */
                }
                if (0 == StreamNode.OpenCount)
                {
                    FileNodeMap.Remove(StreamNode);
                }
            }

            Result = SetFileSizeInternal(FileNode, AllocationSize, true);
            if (0 > Result)
            {
                return(Result);
            }
            if (ReplaceFileAttributes)
            {
                FileNode.FileInfo.FileAttributes = FileAttributes | (UInt32)System.IO.FileAttributes.Archive;
            }
            else
            {
                FileNode.FileInfo.FileAttributes |= FileAttributes | (UInt32)System.IO.FileAttributes.Archive;
            }
            FileNode.FileInfo.FileSize           = 0;
            FileNode.FileInfo.LastAccessTime     =
                FileNode.FileInfo.LastWriteTime  =
                    FileNode.FileInfo.ChangeTime = (UInt64)DateTime.Now.ToFileTimeUtc();

            FileInfo = FileNode.GetFileInfo();

            return(STATUS_SUCCESS);
        }
Exemple #2
0
        public override Int32 CanDelete(
            Object FileNode0,
            Object FileDesc,
            String FileName)
        {
            FileNode FileNode = (FileNode)FileNode0;

            if (FileNodeMap.HasChild(FileNode))
            {
                return(STATUS_DIRECTORY_NOT_EMPTY);
            }

            return(STATUS_SUCCESS);
        }
Exemple #3
0
        public override Int32 Rename(
            Object FileNode0,
            Object FileDesc,
            String FileName,
            String NewFileName,
            Boolean ReplaceIfExists)
        {
            FileNode FileNode = (FileNode)FileNode0;
            FileNode NewFileNode;

            NewFileNode = FileNodeMap.Get(NewFileName);
            if (null != NewFileNode && FileNode != NewFileNode)
            {
                if (!ReplaceIfExists)
                {
                    return(STATUS_OBJECT_NAME_COLLISION);
                }
                if (0 != (NewFileNode.FileInfo.FileAttributes & (UInt32)FileAttributes.Directory))
                {
                    return(STATUS_ACCESS_DENIED);
                }
            }

            if (null != NewFileNode && FileNode != NewFileNode)
            {
                FileNodeMap.Remove(NewFileNode);
            }

            List <String> DescendantFileNames = new List <String>(FileNodeMap.GetDescendantFileNames(FileNode));

            foreach (String DescendantFileName in DescendantFileNames)
            {
                FileNode DescendantFileNode = FileNodeMap.Get(DescendantFileName);
                if (null == DescendantFileNode)
                {
                    continue; /* should not happen */
                }
                FileNodeMap.Remove(DescendantFileNode);
                DescendantFileNode.FileName =
                    NewFileName + DescendantFileNode.FileName.Substring(FileName.Length);
                FileNodeMap.Insert(DescendantFileNode);
            }

            return(STATUS_SUCCESS);
        }
Exemple #4
0
        public override Int32 GetReparsePointByName(
            String FileName,
            Boolean IsDirectory,
            ref Byte[] ReparseData)
        {
            FileNode FileNode;

            FileNode = FileNodeMap.Get(FileName);
            if (null == FileNode)
            {
                return(STATUS_OBJECT_NAME_NOT_FOUND);
            }

            if (0 == (FileNode.FileInfo.FileAttributes & (UInt32)FileAttributes.ReparsePoint))
            {
                return(STATUS_NOT_A_REPARSE_POINT);
            }

            ReparseData = FileNode.ReparseData;

            return(STATUS_SUCCESS);
        }
Exemple #5
0
        public override Int32 GetSecurityByName(
            String FileName,
            out UInt32 FileAttributes /* or ReparsePointIndex */,
            ref Byte[] SecurityDescriptor)
        {
            FileNode FileNode = FileNodeMap.Get(FileName);

            if (null == FileNode)
            {
                Int32 Result = STATUS_OBJECT_NAME_NOT_FOUND;
                if (FindReparsePoint(FileName, out FileAttributes))
                {
                    Result = STATUS_REPARSE;
                }
                else
                {
                    FileNodeMap.GetParent(FileName, ref Result);
                }
                return(Result);
            }

            UInt32 FileAttributesMask = ~(UInt32)0;

            if (null != FileNode.MainFileNode)
            {
                FileAttributesMask = ~(UInt32)System.IO.FileAttributes.Directory;
                FileNode           = FileNode.MainFileNode;
            }
            FileAttributes = FileNode.FileInfo.FileAttributes & FileAttributesMask;
            if (null != SecurityDescriptor)
            {
                SecurityDescriptor = FileNode.FileSecurity;
            }

            return(STATUS_SUCCESS);
        }
Exemple #6
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);
        }
Exemple #7
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);
        }