Exemple #1
0
        private NTStatus OpenFileStream(out Stream stream, string path, FileAccess fileAccess, ShareAccess shareAccess, CreateOptions openOptions)
        {
            stream = null;
            FileShare   fileShare         = NTFileStoreHelper.ToFileShare(shareAccess);
            FileOptions fileOptions       = ToFileOptions(openOptions);
            string      fileShareString   = fileShare.ToString().Replace(", ", "|");
            string      fileOptionsString = ToFileOptionsString(fileOptions);

            try
            {
                stream = m_fileSystem.OpenFile(path, FileMode.Open, fileAccess, fileShare, fileOptions);
            }
            catch (Exception ex)
            {
                if (ex is IOException || ex is UnauthorizedAccessException)
                {
                    NTStatus status = ToNTStatus(ex);
                    Log(Severity.Verbose, "OpenFile: Cannot open '{0}', Access={1}, Share={2}. NTStatus: {3}.", path, fileAccess, fileShareString, status);
                    return(status);
                }
                else
                {
                    throw;
                }
            }

            Log(Severity.Information, "OpenFileStream: Opened '{0}', Access={1}, Share={2}, FileOptions={3}", path, fileAccess, fileShareString, fileOptionsString);
            return(NTStatus.STATUS_SUCCESS);
        }
Exemple #2
0
        private NTStatus OpenFileStream(out Stream stream, string path, FileAccess fileAccess, ShareAccess shareAccess, CreateOptions openOptions)
        {
            stream = null;
            // When FILE_OPEN_REPARSE_POINT is specified, the operation should continue normally if the file is not a reparse point.
            // FILE_OPEN_REPARSE_POINT is a hint that the caller does not intend to actually read the file, with the exception
            // of a file copy operation (where the caller will attempt to simply copy the reparse point).
            bool      openReparsePoint = (openOptions & CreateOptions.FILE_OPEN_REPARSE_POINT) > 0;
            bool      disableBuffering = (openOptions & CreateOptions.FILE_NO_INTERMEDIATE_BUFFERING) > 0;
            bool      buffered         = (openOptions & CreateOptions.FILE_SEQUENTIAL_ONLY) > 0 && !disableBuffering && !openReparsePoint;
            FileShare fileShare        = NTFileStoreHelper.ToFileShare(shareAccess);
            string    fileShareString  = fileShare.ToString().Replace(", ", "|");

            try
            {
                stream = m_fileSystem.OpenFile(path, FileMode.Open, fileAccess, fileShare);
            }
            catch (Exception ex)
            {
                NTStatus status = ToNTStatus(ex);
                Log(Severity.Verbose, "OpenFile: Cannot open '{0}', Access={1}, Share={2}. NTStatus: {3}.", path, fileAccess, fileShareString, status);
                return(status);
            }

            Log(Severity.Information, "OpenFileStream: Opened '{0}', Access={1}, Share={2}, Buffered={3}", path, fileAccess, fileShareString, buffered);
            if (buffered)
            {
                stream = new PrefetchedStream(stream);
            }

            return(NTStatus.STATUS_SUCCESS);
        }