Ejemplo n.º 1
0
        public override void Cleanup(
            Object FileNode0,
            Object FileDesc,
            String FileName,
            UInt32 Flags)
        {
            FileNode FileNode     = (FileNode)FileNode0;
            FileNode MainFileNode = null != FileNode.MainFileNode ?
                                    FileNode.MainFileNode : FileNode;

            if (0 != (Flags & CleanupSetArchiveBit))
            {
                if (0 == (MainFileNode.FileInfo.FileAttributes & (UInt32)FileAttributes.Directory))
                {
                    MainFileNode.FileInfo.FileAttributes |= (UInt32)FileAttributes.Archive;
                }
            }

            if (0 != (Flags & (CleanupSetLastAccessTime | CleanupSetLastWriteTime | CleanupSetChangeTime)))
            {
                UInt64 SystemTime = (UInt64)DateTime.Now.ToFileTimeUtc();

                if (0 != (Flags & CleanupSetLastAccessTime))
                {
                    MainFileNode.FileInfo.LastAccessTime = SystemTime;
                }
                if (0 != (Flags & CleanupSetLastWriteTime))
                {
                    MainFileNode.FileInfo.LastWriteTime = SystemTime;
                }
                if (0 != (Flags & CleanupSetChangeTime))
                {
                    MainFileNode.FileInfo.ChangeTime = SystemTime;
                }
            }

            if (0 != (Flags & CleanupSetAllocationSize))
            {
                UInt64 AllocationUnit = MEMFS_SECTOR_SIZE * MEMFS_SECTORS_PER_ALLOCATION_UNIT;
                UInt64 AllocationSize = (FileNode.FileInfo.FileSize + AllocationUnit - 1) /
                                        AllocationUnit * AllocationUnit;
                SetFileSizeInternal(FileNode, AllocationSize, true);
            }

            if (0 != (Flags & CleanupDelete) && !FileNodeMap.HasChild(FileNode))
            {
                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 */
                    }
                    FileNodeMap.Remove(StreamNode);
                }
                FileNodeMap.Remove(FileNode);
            }
        }
Ejemplo n.º 2
0
        public override Boolean GetStreamEntry(
            Object FileNode0,
            Object FileDesc,
            ref Object Context,
            out String StreamName,
            out UInt64 StreamSize,
            out UInt64 StreamAllocationSize)
        {
            FileNode             FileNode   = (FileNode)FileNode0;
            IEnumerator <String> Enumerator = (IEnumerator <String>)Context;

            if (null == Enumerator)
            {
                if (null != FileNode.MainFileNode)
                {
                    FileNode = FileNode.MainFileNode;
                }

                List <String> StreamFileNames = new List <String>();
                if (0 == (FileNode.FileInfo.FileAttributes & (UInt32)FileAttributes.Directory))
                {
                    StreamFileNames.Add(FileNode.FileName);
                }
                StreamFileNames.AddRange(FileNodeMap.GetStreamFileNames(FileNode));
                Context = Enumerator = StreamFileNames.GetEnumerator();
            }

            while (Enumerator.MoveNext())
            {
                String   FullFileName   = Enumerator.Current;
                FileNode StreamFileNode = FileNodeMap.Get(FullFileName);
                if (null != StreamFileNode)
                {
                    int Index = FullFileName.IndexOf(':');
                    if (0 > Index)
                    {
                        StreamName = "";
                    }
                    else
                    {
                        StreamName = FullFileName.Substring(Index + 1);
                    }
                    StreamSize           = StreamFileNode.FileInfo.FileSize;
                    StreamAllocationSize = StreamFileNode.FileInfo.AllocationSize;
                    return(true);
                }
            }

            StreamName           = default(String);
            StreamSize           = default(UInt64);
            StreamAllocationSize = default(UInt64);
            return(false);
        }
Ejemplo n.º 3
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);
        }