public Memfs( Boolean CaseInsensitive, UInt32 MaxFileNodes, UInt32 MaxFileSize, String RootSddl) { this.FileNodeMap = new FileNodeMap(CaseInsensitive); this.MaxFileNodes = MaxFileNodes; this.MaxFileSize = MaxFileSize; /* * Create root directory. */ FileNode RootNode = new FileNode("\\"); RootNode.FileInfo.FileAttributes = (UInt32)FileAttributes.Directory; if (null == RootSddl) { RootSddl = "O:BAG:BAD:P(A;;FA;;;SY)(A;;FA;;;BA)(A;;FA;;;WD)"; } RawSecurityDescriptor RootSecurityDescriptor = new RawSecurityDescriptor(RootSddl); RootNode.FileSecurity = new Byte[RootSecurityDescriptor.BinaryLength]; RootSecurityDescriptor.GetBinaryForm(RootNode.FileSecurity, 0); FileNodeMap.Insert(RootNode); }
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); }
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); }