public override Int32 Open( String fileName, UInt32 createOptions, UInt32 grantedAccess, out Object fileNode, out Object fileDesc0, out FileInfo fileInfo, out String normalizedName) { fileNode = default(Object); normalizedName = default(String); FileDescriptor fileDesc = null; try { string path = GetWritePath(fileName); if (Directory.Exists(path)) { fileDesc = new FileDescriptor(fileName, new DirectoryInfo(path), true); path = GetReadOnlyPath(fileName); if (Directory.Exists(path)) { fileDesc.ReadOnlyDirInfo = new DirectoryInfo(path); } } else if (File.Exists(path)) { fileDesc = new FileDescriptor(fileName, new FileStream( path, FileMode.Open, (FileSystemRights)grantedAccess, FileShare.Read | FileShare.Write | FileShare.Delete, 4096, 0), true); } else { path = GetReadOnlyPath(fileName); if (Directory.Exists(path)) { fileDesc = new FileDescriptor(fileName, new DirectoryInfo(path), false); } else if (File.Exists(path)) { fileDesc = new FileDescriptor(fileName, new FileStream( path, FileMode.Open, (FileSystemRights)grantedAccess, FileShare.Read | FileShare.Write | FileShare.Delete, 4096, 0), false); } else { throw new FileNotFoundException(); } } fileDesc0 = fileDesc; return(fileDesc.GetFileInfo(out fileInfo)); } catch { if (fileDesc != null) { fileDesc.Dispose(); } throw; } }
public override Boolean ReadDirectoryEntry( Object fileNode, Object fileDesc0, String pattern, String marker, ref Object context, out String fileName, out FileInfo fileInfo) { FileDescriptor fileDesc = (FileDescriptor)fileDesc0; if (null == fileDesc.FileSystemInfos) { if (null != pattern) { pattern = pattern.Replace('<', '*').Replace('>', '?').Replace('"', '.'); } else { pattern = "*"; } SortedList list = new SortedList(); if (fileDesc.IsWriteable()) { if (null != fileDesc.WriteDirInfo && null != fileDesc.WriteDirInfo.Parent) { list.Add(".", fileDesc.WriteDirInfo); list.Add("..", fileDesc.WriteDirInfo.Parent); } } else { if (null != fileDesc.ReadOnlyDirInfo && null != fileDesc.ReadOnlyDirInfo.Parent) { list.Add(".", fileDesc.ReadOnlyDirInfo); list.Add("..", fileDesc.ReadOnlyDirInfo.Parent); } } if (fileDesc.WriteDirInfo != null) { IEnumerable e = fileDesc.WriteDirInfo.EnumerateFileSystemInfos(pattern); foreach (FileSystemInfo info in e) { list.Add(info.Name, info); } } if (fileDesc.ReadOnlyDirInfo != null) { IEnumerable e = fileDesc.ReadOnlyDirInfo.EnumerateFileSystemInfos(pattern); foreach (FileSystemInfo info in e) { if (!list.ContainsKey(info.Name)) { list.Add(info.Name, info); } } } fileDesc.FileSystemInfos = new DictionaryEntry[list.Count]; list.CopyTo(fileDesc.FileSystemInfos, 0); } int index; if (null == context) { index = 0; if (null != marker) { index = Array.BinarySearch(fileDesc.FileSystemInfos, new DictionaryEntry(marker, null), Utils._DirectoryEntryComparer); if (0 <= index) { index++; } else { index = ~index; } } } else { index = (int)context; } if (fileDesc.FileSystemInfos.Length > index) { context = index + 1; fileName = (String)fileDesc.FileSystemInfos[index].Key; Utils.GetFileInfoFromFileSystemInfo( (FileSystemInfo)fileDesc.FileSystemInfos[index].Value, out fileInfo); return(true); } else { fileName = default(String); fileInfo = default(FileInfo); return(false); } }
public override Int32 Create( String fileName, UInt32 createOptions, UInt32 grantedAccess, UInt32 fileAttributes, Byte[] securityDescriptor, UInt64 allocationSize, out Object fileNode, out Object fileDesc0, out FileInfo fileInfo, out String normalizedName) { fileNode = default(Object); normalizedName = default(String); FileDescriptor fileDesc = null; try { var path = GetWritePath(fileName); // directory or file? if (0 == (createOptions & FILE_DIRECTORY_FILE)) { // file FileSecurity Security = null; if (null != securityDescriptor) { Security = new FileSecurity(); Security.SetSecurityDescriptorBinaryForm(securityDescriptor); } fileDesc = new FileDescriptor(fileName, new FileStream( path, FileMode.CreateNew, (FileSystemRights)grantedAccess | FileSystemRights.WriteAttributes, FileShare.Read | FileShare.Write | FileShare.Delete, 4096, 0, Security), true); fileDesc.SetFileAttributes(fileAttributes | (UInt32)System.IO.FileAttributes.Archive); } else { // directory if (Directory.Exists(path)) { Utils.ThrowIoExceptionWithNtStatus(STATUS_OBJECT_NAME_COLLISION); } DirectorySecurity Security = null; if (null != securityDescriptor) { Security = new DirectorySecurity(); Security.SetSecurityDescriptorBinaryForm(securityDescriptor); } fileDesc = new FileDescriptor(fileName, Directory.CreateDirectory(path, Security), true); fileDesc.SetFileAttributes(fileAttributes); } // assign the file descriptor fileDesc0 = fileDesc; return(fileDesc.GetFileInfo(out fileInfo)); } catch { if (null != fileDesc) { fileDesc.Dispose(); } throw; } }