예제 #1
0
        public NTStatus GetFileInformation(out FileInformation result, object handle, FileInformationClass informationClass)
        {
            switch (informationClass)
            {
            case FileInformationClass.FileBasicInformation:
            {
                FileBasicInformation information = new FileBasicInformation();
                information.FileAttributes = FileAttributes.Temporary;
                result = information;
                return(NTStatus.STATUS_SUCCESS);
            }

            case FileInformationClass.FileStandardInformation:
            {
                FileStandardInformation information = new FileStandardInformation();
                information.DeletePending = false;
                result = information;
                return(NTStatus.STATUS_SUCCESS);
            }

            case FileInformationClass.FileNetworkOpenInformation:
            {
                FileNetworkOpenInformation information = new FileNetworkOpenInformation();
                information.FileAttributes = FileAttributes.Temporary;
                result = information;
                return(NTStatus.STATUS_SUCCESS);
            }

            default:
                result = null;
                return(NTStatus.STATUS_INVALID_INFO_CLASS);
            }
        }
예제 #2
0
 public FileAllInformation(byte[] buffer, int offset)
 {
     BasicInformation     = new FileBasicInformation(buffer, offset + 0);
     StandardInformation  = new FileStandardInformation(buffer, offset + 40);
     InternalInformation  = new FileInternalInformation(buffer, offset + 64);
     EaInformation        = new FileEaInformation(buffer, offset + 72);
     AccessInformation    = new FileAccessInformation(buffer, offset + 76);
     PositionInformation  = new FilePositionInformation(buffer, offset + 80);
     ModeInformation      = new FileModeInformation(buffer, offset + 88);
     AlignmentInformation = new FileAlignmentInformation(buffer, offset + 92);
     NameInformation      = new FileNameInformation(buffer, offset + 96);
 }
예제 #3
0
 public FileAllInformation()
 {
     BasicInformation     = new FileBasicInformation();
     StandardInformation  = new FileStandardInformation();
     InternalInformation  = new FileInternalInformation();
     EaInformation        = new FileEaInformation();
     AccessInformation    = new FileAccessInformation();
     PositionInformation  = new FilePositionInformation();
     ModeInformation      = new FileModeInformation();
     AlignmentInformation = new FileAlignmentInformation();
     NameInformation      = new FileNameInformation();
 }
예제 #4
0
        public NTStatus GetFileInformation(out FileInformation result, object handle, FileInformationClass informationClass)
        {
            FileHandle      fileHandle = (FileHandle)handle;
            string          path       = fileHandle.Path;
            FileSystemEntry entry;

            try
            {
                entry = m_fileSystem.GetEntry(path);
            }
            catch (Exception ex)
            {
                NTStatus status = ToNTStatus(ex);
                Log(Severity.Verbose, "GetFileInformation on '{0}' failed. {1}", path, status);
                result = null;
                return(status);
            }

            if (entry == null)
            {
                result = null;
                return(NTStatus.STATUS_NO_SUCH_FILE);
            }

            switch (informationClass)
            {
            case FileInformationClass.FileBasicInformation:
            {
                FileBasicInformation information = new FileBasicInformation();
                information.CreationTime   = entry.CreationTime;
                information.LastAccessTime = entry.LastAccessTime;
                information.LastWriteTime  = entry.LastWriteTime;
                information.ChangeTime     = entry.LastWriteTime;
                information.FileAttributes = GetFileAttributes(entry);
                result = information;
                return(NTStatus.STATUS_SUCCESS);
            }

            case FileInformationClass.FileStandardInformation:
            {
                FileStandardInformation information = new FileStandardInformation();
                information.AllocationSize = (long)GetAllocationSize(entry.Size);
                information.EndOfFile      = (long)entry.Size;
                information.Directory      = entry.IsDirectory;
                information.DeletePending  = fileHandle.DeleteOnClose;
                result = information;
                return(NTStatus.STATUS_SUCCESS);
            }

            case FileInformationClass.FileInternalInformation:
            {
                FileInternalInformation information = new FileInternalInformation();
                result = information;
                return(NTStatus.STATUS_SUCCESS);
            }

            case FileInformationClass.FileEaInformation:
            {
                FileEaInformation information = new FileEaInformation();
                information.EaSize = 0;
                result             = information;
                return(NTStatus.STATUS_SUCCESS);
            }

            case FileInformationClass.FileAccessInformation:
            {
                result = null;
                return(NTStatus.STATUS_NOT_IMPLEMENTED);
            }

            case FileInformationClass.FileNameInformation:
            {
                FileNameInformation information = new FileNameInformation();
                information.FileName = entry.Name;
                result = information;
                return(NTStatus.STATUS_SUCCESS);
            }

            case FileInformationClass.FilePositionInformation:
            {
                result = null;
                return(NTStatus.STATUS_NOT_IMPLEMENTED);
            }

            case FileInformationClass.FileFullEaInformation:
            {
                result = null;
                return(NTStatus.STATUS_NOT_IMPLEMENTED);
            }

            case FileInformationClass.FileModeInformation:
            {
                result = null;
                return(NTStatus.STATUS_NOT_IMPLEMENTED);
            }

            case FileInformationClass.FileAlignmentInformation:
            {
                result = null;
                return(NTStatus.STATUS_NOT_IMPLEMENTED);
            }

            case FileInformationClass.FileAllInformation:
            {
                FileAllInformation information = new FileAllInformation();
                information.BasicInformation.CreationTime      = entry.CreationTime;
                information.BasicInformation.LastAccessTime    = entry.LastAccessTime;
                information.BasicInformation.LastWriteTime     = entry.LastWriteTime;
                information.BasicInformation.ChangeTime        = entry.LastWriteTime;
                information.BasicInformation.FileAttributes    = GetFileAttributes(entry);
                information.StandardInformation.AllocationSize = (long)GetAllocationSize(entry.Size);
                information.StandardInformation.EndOfFile      = (long)entry.Size;
                information.StandardInformation.Directory      = entry.IsDirectory;
                information.StandardInformation.DeletePending  = fileHandle.DeleteOnClose;
                information.NameInformation.FileName           = entry.Name;
                result = information;
                return(NTStatus.STATUS_SUCCESS);
            }

            case FileInformationClass.FileAlternateNameInformation:
            {
                result = null;
                return(NTStatus.STATUS_NOT_IMPLEMENTED);
            }

            case FileInformationClass.FileStreamInformation:
            {
                // This information class is used to enumerate the data streams of a file or a directory.
                // A buffer of FileStreamInformation data elements is returned by the server.
                FileStreamInformation information = new FileStreamInformation();
                FileStreamEntry       streamEntry = new FileStreamEntry();
                streamEntry.StreamSize           = (long)entry.Size;
                streamEntry.StreamAllocationSize = (long)GetAllocationSize(entry.Size);
                streamEntry.StreamName           = "::$DATA";
                information.Entries.Add(streamEntry);
                result = information;
                return(NTStatus.STATUS_SUCCESS);
            }

            case FileInformationClass.FilePipeInformation:
            {
                result = null;
                return(NTStatus.STATUS_NOT_IMPLEMENTED);
            }

            case FileInformationClass.FilePipeLocalInformation:
            {
                result = null;
                return(NTStatus.STATUS_NOT_IMPLEMENTED);
            }

            case FileInformationClass.FilePipeRemoteInformation:
            {
                result = null;
                return(NTStatus.STATUS_NOT_IMPLEMENTED);
            }

            case FileInformationClass.FileCompressionInformation:
            {
                result = null;
                return(NTStatus.STATUS_NOT_IMPLEMENTED);
            }

            case FileInformationClass.FileNetworkOpenInformation:
            {
                FileNetworkOpenInformation information = new FileNetworkOpenInformation();
                information.CreationTime   = entry.CreationTime;
                information.LastAccessTime = entry.LastAccessTime;
                information.LastWriteTime  = entry.LastWriteTime;
                information.ChangeTime     = entry.LastWriteTime;
                information.AllocationSize = (long)GetAllocationSize(entry.Size);
                information.EndOfFile      = (long)entry.Size;
                information.FileAttributes = GetFileAttributes(entry);
                result = information;
                return(NTStatus.STATUS_SUCCESS);
            }

            case FileInformationClass.FileAttributeTagInformation:
            {
                result = null;
                return(NTStatus.STATUS_NOT_IMPLEMENTED);
            }

            default:
                result = null;
                return(NTStatus.STATUS_INVALID_INFO_CLASS);
            }
        }
예제 #5
0
        public NTStatus SetFileInformation(object handle, FileInformation information)
        {
            FileHandle fileHandle = (FileHandle)handle;

            if (information is FileBasicInformation)
            {
                FileBasicInformation basicInformation = (FileBasicInformation)information;
                bool isHidden   = ((basicInformation.FileAttributes & FileAttributes.Hidden) > 0);
                bool isReadonly = (basicInformation.FileAttributes & FileAttributes.ReadOnly) > 0;
                bool isArchived = (basicInformation.FileAttributes & FileAttributes.Archive) > 0;
                try
                {
                    m_fileSystem.SetAttributes(fileHandle.Path, isHidden, isReadonly, isArchived);
                }
                catch (Exception ex)
                {
                    NTStatus status = ToNTStatus(ex);
                    Log(Severity.Verbose, "SetFileInformation: Failed to set file attributes on '{0}'. {1}.", fileHandle.Path, status);
                    return(status);
                }

                try
                {
                    m_fileSystem.SetDates(fileHandle.Path, basicInformation.CreationTime, basicInformation.LastWriteTime, basicInformation.LastAccessTime);
                }
                catch (Exception ex)
                {
                    NTStatus status = ToNTStatus(ex);
                    Log(Severity.Verbose, "SetFileInformation: Failed to set file dates on '{0}'. {1}.", fileHandle.Path, status);
                    return(status);
                }
                return(NTStatus.STATUS_SUCCESS);
            }
            else if (information is FileRenameInformationType2)
            {
                FileRenameInformationType2 renameInformation = (FileRenameInformationType2)information;
                string newFileName = renameInformation.FileName;
                if (!newFileName.StartsWith(@"\"))
                {
                    newFileName = @"\" + newFileName;
                }

                if (fileHandle.Stream != null)
                {
                    fileHandle.Stream.Close();
                }

                // Note: it's possible that we just want to upcase / downcase a filename letter.
                try
                {
                    if (renameInformation.ReplaceIfExists && (m_fileSystem.GetEntry(newFileName) != null))
                    {
                        m_fileSystem.Delete(newFileName);
                    }
                    m_fileSystem.Move(fileHandle.Path, newFileName);
                    Log(Severity.Information, "SetFileInformation: Renamed '{0}' to '{1}'", fileHandle.Path, newFileName);
                }
                catch (Exception ex)
                {
                    NTStatus status = ToNTStatus(ex);
                    Log(Severity.Verbose, "SetFileInformation: Cannot rename '{0}' to '{1}'. {2}.", fileHandle.Path, newFileName, status);
                    return(status);
                }
                fileHandle.Path = newFileName;
                return(NTStatus.STATUS_SUCCESS);
            }
            else if (information is FileDispositionInformation)
            {
                if (((FileDispositionInformation)information).DeletePending)
                {
                    // We're supposed to delete the file on close, but it's too late to report errors at this late stage
                    if (fileHandle.Stream != null)
                    {
                        fileHandle.Stream.Close();
                    }

                    try
                    {
                        m_fileSystem.Delete(fileHandle.Path);
                        Log(Severity.Information, "SetFileInformation: Deleted '{0}'", fileHandle.Path);
                    }
                    catch (Exception ex)
                    {
                        NTStatus status = ToNTStatus(ex);
                        Log(Severity.Information, "SetFileInformation: Error deleting '{0}'. {1}.", fileHandle.Path, status);
                        return(status);
                    }
                }
                return(NTStatus.STATUS_SUCCESS);
            }
            else if (information is FileAllocationInformation)
            {
                long allocationSize = ((FileAllocationInformation)information).AllocationSize;
                try
                {
                    fileHandle.Stream.SetLength(allocationSize);
                }
                catch (Exception ex)
                {
                    NTStatus status = ToNTStatus(ex);
                    Log(Severity.Verbose, "SetFileInformation: Cannot set allocation for '{0}'. {1}.", fileHandle.Path, status);
                    return(status);
                }
                return(NTStatus.STATUS_SUCCESS);
            }
            else if (information is FileEndOfFileInformation)
            {
                long endOfFile = ((FileEndOfFileInformation)information).EndOfFile;
                try
                {
                    fileHandle.Stream.SetLength(endOfFile);
                }
                catch (Exception ex)
                {
                    NTStatus status = ToNTStatus(ex);
                    Log(Severity.Verbose, "SetFileInformation: Cannot set end of file for '{0}'. {1}.", fileHandle.Path, status);
                    return(status);
                }
                return(NTStatus.STATUS_SUCCESS);
            }
            else
            {
                return(NTStatus.STATUS_NOT_IMPLEMENTED);
            }
        }