Exemplo n.º 1
0
        private static Int32 GetSecurity(
            IntPtr FileSystemPtr,
            ref FullContext FullContext,
            IntPtr SecurityDescriptor,
            IntPtr PSecurityDescriptorSize)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                Object FileNode, FileDesc;
                Byte[] SecurityDescriptorBytes;
                Int32  Result;
                Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
                SecurityDescriptorBytes = ByteBufferNotNull;
                Result = FileSystem.GetSecurity(
                    FileNode,
                    FileDesc,
                    ref SecurityDescriptorBytes);
                if (0 <= Result)
                {
                    Result = Api.CopySecurityDescriptor(SecurityDescriptorBytes,
                                                        SecurityDescriptor, PSecurityDescriptorSize);
                }
                return(Result);
            }
            catch (Exception ex)
            {
                return(ExceptionHandler(FileSystem, ex));
            }
        }
Exemplo n.º 2
0
        private static Int32 GetReparsePoint(
            IntPtr FileSystemPtr,
            ref FullContext FullContext,
            String FileName,
            IntPtr Buffer,
            IntPtr PSize)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                Byte[] ReparseData;
                Object FileNode, FileDesc;
                Int32  Result;
                Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
                ReparseData = null;
                Result      = FileSystem.GetReparsePoint(
                    FileNode,
                    FileDesc,
                    FileName,
                    ref ReparseData);
                if (0 <= Result)
                {
                    Result = Api.CopyReparsePoint(ReparseData, Buffer, PSize);
                }
                return(Result);
            }
            catch (Exception ex)
            {
                return(ExceptionHandler(FileSystem, ex));
            }
        }
Exemplo n.º 3
0
        private static Int32 Read(
            IntPtr FileSystemPtr,
            ref FullContext FullContext,
            IntPtr Buffer,
            UInt64 Offset,
            UInt32 Length,
            out UInt32 PBytesTransferred)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                Object FileNode, FileDesc;
                Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
                return(FileSystem.Read(
                           FileNode,
                           FileDesc,
                           Buffer,
                           Offset,
                           Length,
                           out PBytesTransferred));
            }
            catch (Exception ex)
            {
                PBytesTransferred = default(UInt32);
                return(ExceptionHandler(FileSystem, ex));
            }
        }
Exemplo n.º 4
0
        private static Int32 ReadDirectory(
            IntPtr FileSystemPtr,
            ref FullContext FullContext,
            String Pattern,
            String Marker,
            IntPtr Buffer,
            UInt32 Length,
            out UInt32 PBytesTransferred)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                Object FileNode, FileDesc;
                Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
                return(FileSystem.ReadDirectory(
                           FileNode,
                           FileDesc,
                           Pattern,
                           Marker,
                           Buffer,
                           Length,
                           out PBytesTransferred));
            }
            catch (Exception ex)
            {
                PBytesTransferred = default(UInt32);
                return(ExceptionHandler(FileSystem, ex));
            }
        }
Exemplo n.º 5
0
        private static Int32 SetBasicInfo(
            IntPtr FileSystemPtr,
            ref FullContext FullContext,
            UInt32 FileAttributes,
            UInt64 CreationTime,
            UInt64 LastAccessTime,
            UInt64 LastWriteTime,
            UInt64 ChangeTime,
            out FileInfo FileInfo)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                Object FileNode, FileDesc;
                Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
                return(FileSystem.SetBasicInfo(
                           FileNode,
                           FileDesc,
                           FileAttributes,
                           CreationTime,
                           LastAccessTime,
                           LastWriteTime,
                           ChangeTime,
                           out FileInfo));
            }
            catch (Exception ex)
            {
                FileInfo = default(FileInfo);
                return(ExceptionHandler(FileSystem, ex));
            }
        }
Exemplo n.º 6
0
        private static Int32 DeleteReparsePoint(
            IntPtr FileSystemPtr,
            ref FullContext FullContext,
            String FileName,
            IntPtr Buffer,
            UIntPtr Size)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                Object FileNode, FileDesc;
                Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
                return(FileSystem.DeleteReparsePoint(
                           FileNode,
                           FileDesc,
                           FileName,
                           Buffer,
                           Size));
            }
            catch (Exception ex)
            {
                return(ExceptionHandler(FileSystem, ex));
            }
        }
Exemplo n.º 7
0
        private static Int32 Overwrite(
            IntPtr FileSystemPtr,
            ref FullContext FullContext,
            UInt32 FileAttributes,
            Boolean ReplaceFileAttributes,
            UInt64 AllocationSize,
            IntPtr Ea,
            UInt32 EaLength,
            out FileInfo FileInfo)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                Object FileNode, FileDesc;
                Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
                return(FileSystem.OverwriteEx(
                           FileNode,
                           FileDesc,
                           FileAttributes,
                           ReplaceFileAttributes,
                           AllocationSize,
                           Ea,
                           EaLength,
                           out FileInfo));
            }
            catch (Exception ex)
            {
                FileInfo = default(FileInfo);
                return(ExceptionHandler(FileSystem, ex));
            }
        }
Exemplo n.º 8
0
        private static Int32 Rename(
            IntPtr FileSystemPtr,
            ref FullContext FullContext,
            String FileName,
            String NewFileName,
            Boolean ReplaceIfExists)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                Object FileNode, FileDesc;
                Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
                return(FileSystem.Rename(
                           FileNode,
                           FileDesc,
                           FileName,
                           NewFileName,
                           ReplaceIfExists));
            }
            catch (Exception ex)
            {
                return(ExceptionHandler(FileSystem, ex));
            }
        }
Exemplo n.º 9
0
        private static Int32 SetFileSize(
            IntPtr FileSystemPtr,
            ref FullContext FullContext,
            UInt64 NewSize,
            Boolean SetAllocationSize,
            out FileInfo FileInfo)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                Object FileNode, FileDesc;
                Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
                return(FileSystem.SetFileSize(
                           FileNode,
                           FileDesc,
                           NewSize,
                           SetAllocationSize,
                           out FileInfo));
            }
            catch (Exception ex)
            {
                FileInfo = default(FileInfo);
                return(ExceptionHandler(FileSystem, ex));
            }
        }
Exemplo n.º 10
0
        private static Int32 ResolveReparsePoints(
            IntPtr FileSystemPtr,
            String FileName,
            UInt32 ReparsePointIndex,
            Boolean ResolveLastPathComponent,
            out IoStatusBlock PIoStatus,
            IntPtr Buffer,
            IntPtr PSize)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                return(FileSystem.ResolveReparsePoints(
                           FileName,
                           ReparsePointIndex,
                           ResolveLastPathComponent,
                           out PIoStatus,
                           Buffer,
                           PSize));
            }
            catch (Exception ex)
            {
                PIoStatus = default(IoStatusBlock);
                return(ExceptionHandler(FileSystem, ex));
            }
        }
Exemplo n.º 11
0
        private static Int32 GetEa(
            IntPtr FileSystemPtr,
            ref FullContext FullContext,
            IntPtr Ea,
            UInt32 EaLength,
            out UInt32 PBytesTransferred)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                Object FileNode, FileDesc;
                Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
                return(FileSystem.GetEa(
                           FileNode,
                           FileDesc,
                           Ea,
                           EaLength,
                           out PBytesTransferred));
            }
            catch (Exception ex)
            {
                PBytesTransferred = default(UInt32);
                return(ExceptionHandler(FileSystem, ex));
            }
        }
Exemplo n.º 12
0
        private static Int32 SetEa(
            IntPtr FileSystemPtr,
            ref FullContext FullContext,
            IntPtr Ea,
            UInt32 EaLength,
            out FileInfo FileInfo)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                Object FileNode, FileDesc;
                Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
                return(FileSystem.SetEa(
                           FileNode,
                           FileDesc,
                           Ea,
                           EaLength,
                           out FileInfo));
            }
            catch (Exception ex)
            {
                FileInfo = default(FileInfo);
                return(ExceptionHandler(FileSystem, ex));
            }
        }
Exemplo n.º 13
0
        private static Int32 Control(
            IntPtr FileSystemPtr,
            ref FullContext FullContext,
            UInt32 ControlCode,
            IntPtr InputBuffer, UInt32 InputBufferLength,
            IntPtr OutputBuffer, UInt32 OutputBufferLength,
            out UInt32 PBytesTransferred)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                Object FileNode, FileDesc;
                Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
                return(FileSystem.Control(
                           FileNode,
                           FileDesc,
                           ControlCode,
                           InputBuffer,
                           InputBufferLength,
                           OutputBuffer,
                           OutputBufferLength,
                           out PBytesTransferred));
            }
            catch (Exception ex)
            {
                PBytesTransferred = default(UInt32);
                return(ExceptionHandler(FileSystem, ex));
            }
        }
Exemplo n.º 14
0
        private static Int32 GetDirInfoByName(
            IntPtr FileSystemPtr,
            ref FullContext FullContext,
            String FileName,
            out DirInfo DirInfo)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                Object FileNode, FileDesc;
                String NormalizedName;
                Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
                DirInfo = default(DirInfo);
                Int32 Result = FileSystem.GetDirInfoByName(
                    FileNode,
                    FileDesc,
                    FileName,
                    out NormalizedName,
                    out DirInfo.FileInfo);
                DirInfo.SetFileNameBuf(NormalizedName);
                return(Result);
            }
            catch (Exception ex)
            {
                DirInfo = default(DirInfo);
                return(ExceptionHandler(FileSystem, ex));
            }
        }
Exemplo n.º 15
0
        private static Int32 GetReparsePointByName(
            IntPtr FileSystem,
            IntPtr Context,
            String FileName,
            Boolean IsDirectory,
            IntPtr Buffer,
            IntPtr PSize)
        {
            FileSystemBase self = (FileSystemBase)GCHandle.FromIntPtr(Context).Target;

            try
            {
                Byte[] ReparseData;
                Int32  Result;
                ReparseData = null;
                Result      = self.GetReparsePointByName(
                    FileName,
                    IsDirectory,
                    ref ReparseData);
                if (0 <= Result)
                {
                    Result = Api.CopyReparsePoint(ReparseData, Buffer, PSize);
                }
                return(Result);
            }
            catch (Exception ex)
            {
                return(self.ExceptionHandler(ex));
            }
        }
Exemplo n.º 16
0
        private static Int32 Write(
            IntPtr FileSystemPtr,
            ref FullContext FullContext,
            IntPtr Buffer,
            UInt64 Offset,
            UInt32 Length,
            Boolean WriteToEndOfFile,
            Boolean ConstrainedIo,
            out UInt32 PBytesTransferred,
            out FileInfo FileInfo)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                Object FileNode, FileDesc;
                Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
                return(FileSystem.Write(
                           FileNode,
                           FileDesc,
                           Buffer,
                           Offset,
                           Length,
                           WriteToEndOfFile,
                           ConstrainedIo,
                           out PBytesTransferred,
                           out FileInfo));
            }
            catch (Exception ex)
            {
                PBytesTransferred = default(UInt32);
                FileInfo          = default(FileInfo);
                return(ExceptionHandler(FileSystem, ex));
            }
        }
Exemplo n.º 17
0
 private static Int32 ExceptionHandler(
     FileSystemBase FileSystem,
     Exception ex)
 {
     try
     {
         return(FileSystem.ExceptionHandler(ex));
     }
     catch
     {
         return(unchecked ((Int32)0xc00000e9) /*STATUS_UNEXPECTED_IO_ERROR*/);
     }
 }
Exemplo n.º 18
0
        private static Int32 Create(
            IntPtr FileSystemPtr,
            String FileName,
            UInt32 CreateOptions,
            UInt32 GrantedAccess,
            UInt32 FileAttributes,
            IntPtr SecurityDescriptor,
            UInt64 AllocationSize,
            IntPtr ExtraBuffer,
            UInt32 ExtraLength,
            Boolean ExtraBufferIsReparsePoint,
            ref FullContext FullContext,
            ref OpenFileInfo OpenFileInfo)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                Object FileNode, FileDesc;
                String NormalizedName;
                Int32  Result;
                Result = FileSystem.CreateEx(
                    FileName,
                    CreateOptions,
                    GrantedAccess,
                    FileAttributes,
                    Api.MakeSecurityDescriptor(SecurityDescriptor),
                    AllocationSize,
                    ExtraBuffer,
                    ExtraLength,
                    ExtraBufferIsReparsePoint,
                    out FileNode,
                    out FileDesc,
                    out OpenFileInfo.FileInfo,
                    out NormalizedName);
                if (0 <= Result)
                {
                    if (null != NormalizedName)
                    {
                        OpenFileInfo.SetNormalizedName(NormalizedName);
                    }
                    Api.SetFullContext(ref FullContext, FileNode, FileDesc);
                }
                return(Result);
            }
            catch (Exception ex)
            {
                return(ExceptionHandler(FileSystem, ex));
            }
        }
Exemplo n.º 19
0
        private static Int32 GetVolumeInfo(
            IntPtr FileSystemPtr,
            out VolumeInfo VolumeInfo)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                return(FileSystem.GetVolumeInfo(
                           out VolumeInfo));
            }
            catch (Exception ex)
            {
                VolumeInfo = default(VolumeInfo);
                return(ExceptionHandler(FileSystem, ex));
            }
        }
Exemplo n.º 20
0
        private static void Close(
            IntPtr FileSystemPtr,
            ref FullContext FullContext)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                Object FileNode, FileDesc;
                Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
                FileSystem.Close(
                    FileNode,
                    FileDesc);
                Api.DisposeFullContext(ref FullContext);
            }
            catch (Exception ex)
            {
                ExceptionHandler(FileSystem, ex);
            }
        }
Exemplo n.º 21
0
        private static Int32 SetSecurity(
            IntPtr FileSystemPtr,
            ref FullContext FullContext,
            UInt32 SecurityInformation,
            IntPtr ModificationDescriptor)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                Object FileNode, FileDesc;
                AccessControlSections Sections;
                Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
                Sections = AccessControlSections.None;
                if (0 != (SecurityInformation & 1 /*OWNER_SECURITY_INFORMATION*/))
                {
                    Sections |= AccessControlSections.Owner;
                }
                if (0 != (SecurityInformation & 2 /*GROUP_SECURITY_INFORMATION*/))
                {
                    Sections |= AccessControlSections.Group;
                }
                if (0 != (SecurityInformation & 4 /*DACL_SECURITY_INFORMATION*/))
                {
                    Sections |= AccessControlSections.Access;
                }
                if (0 != (SecurityInformation & 8 /*SACL_SECURITY_INFORMATION*/))
                {
                    Sections |= AccessControlSections.Audit;
                }
                return(FileSystem.SetSecurity(
                           FileNode,
                           FileDesc,
                           Sections,
                           Api.MakeSecurityDescriptor(ModificationDescriptor)));
            }
            catch (Exception ex)
            {
                return(ExceptionHandler(FileSystem, ex));
            }
        }
Exemplo n.º 22
0
        private static Int32 CanDelete(
            IntPtr FileSystemPtr,
            ref FullContext FullContext,
            String FileName)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                Object FileNode, FileDesc;
                Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
                return(FileSystem.CanDelete(
                           FileNode,
                           FileDesc,
                           FileName));
            }
            catch (Exception ex)
            {
                return(ExceptionHandler(FileSystem, ex));
            }
        }
Exemplo n.º 23
0
        private static Int32 GetSecurityByName(
            IntPtr FileSystemPtr,
            String FileName,
            IntPtr PFileAttributes /* or ReparsePointIndex */,
            IntPtr SecurityDescriptor,
            IntPtr PSecurityDescriptorSize)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                UInt32 FileAttributes;
                Byte[] SecurityDescriptorBytes = null;
                Int32  Result;
                if (IntPtr.Zero != PSecurityDescriptorSize)
                {
                    SecurityDescriptorBytes = ByteBufferNotNull;
                }
                Result = FileSystem.GetSecurityByName(
                    FileName,
                    out FileAttributes,
                    ref SecurityDescriptorBytes);
                if (0 <= Result && 260 /*STATUS_REPARSE*/ != Result)
                {
                    if (IntPtr.Zero != PFileAttributes)
                    {
                        Marshal.WriteInt32(PFileAttributes, (Int32)FileAttributes);
                    }
                    Result = Api.CopySecurityDescriptor(SecurityDescriptorBytes,
                                                        SecurityDescriptor, PSecurityDescriptorSize);
                }
                return(Result);
            }
            catch (Exception ex)
            {
                return(ExceptionHandler(FileSystem, ex));
            }
        }
Exemplo n.º 24
0
        private static Int32 Open(
            IntPtr FileSystemPtr,
            String FileName,
            UInt32 CreateOptions,
            UInt32 GrantedAccess,
            ref FullContext FullContext,
            ref OpenFileInfo OpenFileInfo)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                Object FileNode, FileDesc;
                String NormalizedName;
                Int32  Result;
                Result = FileSystem.Open(
                    FileName,
                    CreateOptions,
                    GrantedAccess,
                    out FileNode,
                    out FileDesc,
                    out OpenFileInfo.FileInfo,
                    out NormalizedName);
                if (0 <= Result)
                {
                    if (null != NormalizedName)
                    {
                        OpenFileInfo.SetNormalizedName(NormalizedName);
                    }
                    Api.SetFullContext(ref FullContext, FileNode, FileDesc);
                }
                return(Result);
            }
            catch (Exception ex)
            {
                return(ExceptionHandler(FileSystem, ex));
            }
        }
Exemplo n.º 25
0
        private static Int32 GetReparsePointByName(
            IntPtr FileSystem,
            IntPtr Context,
            String FileName,
            Boolean IsDirectory,
            IntPtr Buffer,
            ref UIntPtr Size)
        {
            FileSystemBase self = (FileSystemBase)GCHandle.FromIntPtr(Context).Target;

            try
            {
                return(self.GetReparsePointByName(
                           FileName,
                           IsDirectory,
                           Buffer,
                           ref Size));
            }
            catch (Exception ex)
            {
                return(self.ExceptionHandler(ex));
            }
        }
Exemplo n.º 26
0
        private static void Cleanup(
            IntPtr FileSystemPtr,
            ref FullContext FullContext,
            String FileName,
            UInt32 Flags)
        {
            FileSystemBase FileSystem = (FileSystemBase)Api.GetUserContext(FileSystemPtr);

            try
            {
                Object FileNode, FileDesc;
                Api.GetFullContext(ref FullContext, out FileNode, out FileDesc);
                FileSystem.Cleanup(
                    FileNode,
                    FileDesc,
                    FileName,
                    Flags);
            }
            catch (Exception ex)
            {
                ExceptionHandler(FileSystem, ex);
            }
        }
Exemplo n.º 27
0
 /* ctor/dtor */
 /// <summary>
 /// Creates an instance of the FileSystemHost class.
 /// </summary>
 /// <param name="FileSystem">The file system to host.</param>
 public FileSystemHost(FileSystemBase FileSystem)
 {
     _VolumeParams.Flags = VolumeParams.UmFileContextIsFullContext;
     _FileSystem         = FileSystem;
 }