Beispiel #1
0
        private static OpenFileResult TryOpenDirectory(
            string directoryPath,
            FileDesiredAccess desiredAccess,
            FileShare shareMode,
            FileMode fileMode,
            FileFlagsAndAttributes flagsAndAttributes,
            out SafeFileHandle handle)
        {
            Contract.Requires(!string.IsNullOrEmpty(directoryPath));

            if (flagsAndAttributes.HasFlag(FileFlagsAndAttributes.FileFlagOpenReparsePoint) &&
                IsSymlink(directoryPath))
            {
                return(TryOpenSymlink(directoryPath, desiredAccess, shareMode, fileMode, out handle));
            }

            try
            {
                FileStream fs = new FileStream(directoryPath, fileMode, FileDesiredAccessToFileAccess(desiredAccess), shareMode, DefaultBufferSize, FileFlagsAndAttributesToFileOptions(flagsAndAttributes | FileFlagsAndAttributes.FileFlagBackupSemantics));
                handle = fs.SafeFileHandle;
                return(OpenFileResult.Create(NativeIOConstants.ErrorSuccess, fileMode, handleIsValid: true, openingById: false));
            }
            catch (Exception ex)
            {
                handle = null;
                int nativeErrorCode = (int)NativeErrorCodeForException(ex);
                Logger.Log.StorageTryOpenDirectoryFailure(Events.StaticContext, directoryPath, nativeErrorCode);
                return(OpenFileResult.Create(nativeErrorCode, fileMode, handleIsValid: false, openingById: false));
            }
        }
Beispiel #2
0
        /// <inheritdoc />
        public OpenFileResult TryCreateOrOpenFile(
            string path,
            FileDesiredAccess desiredAccess,
            FileShare shareMode,
            FileMode creationDisposition,
            FileFlagsAndAttributes flagsAndAttributes,
            out SafeFileHandle handle)
        {
            if (flagsAndAttributes.HasFlag(FileFlagsAndAttributes.FileFlagOpenReparsePoint) &&
                IsSymlink(path))
            {
                return(TryOpenSymlink(path, desiredAccess, shareMode, creationDisposition, out handle));
            }

            try
            {
                FileStream fs = new FileStream(path, creationDisposition, FileDesiredAccessToFileAccess(desiredAccess), shareMode, DefaultBufferSize, FileFlagsAndAttributesToFileOptions(flagsAndAttributes));
                handle = fs.SafeFileHandle;
                return(OpenFileResult.Create(NativeIOConstants.ErrorSuccess, creationDisposition, handleIsValid: true, openingById: false));
            }
            catch (Exception ex)
            {
                handle = null;
                var errorCode = NativeErrorCodeForException(ex);
                Logger.Log.StorageTryOpenOrCreateFileFailure(Events.StaticContext, path, (int)creationDisposition, (int)errorCode);
                return(OpenFileResult.Create((int)errorCode, creationDisposition, handleIsValid: false, openingById: false));
            }
        }
Beispiel #3
0
 /// <inheritdoc />
 public OpenFileResult TryCreateOrOpenFile(
     string path,
     FileDesiredAccess desiredAccess,
     FileShare shareMode,
     FileMode creationDisposition,
     FileFlagsAndAttributes flagsAndAttributes,
     out SafeFileHandle handle)
 {
     return(TryOpen(
                path,
                desiredAccess,
                shareMode,
                creationDisposition,
                flagsAndAttributes.HasFlag(FileFlagsAndAttributes.FileFlagOpenReparsePoint) && IsSymlink(path),
                out handle));
 }
Beispiel #4
0
        private OpenFileResult TryOpenDirectory(
            string directoryPath,
            FileDesiredAccess desiredAccess,
            FileShare shareMode,
            FileMode fileMode,
            FileFlagsAndAttributes flagsAndAttributes,
            out SafeFileHandle handle)
        {
            Contract.Requires(!string.IsNullOrEmpty(directoryPath));

            return(TryOpen(
                       directoryPath,
                       desiredAccess,
                       shareMode,
                       fileMode,
                       flagsAndAttributes.HasFlag(FileFlagsAndAttributes.FileFlagOpenReparsePoint) && IsSymlink(directoryPath),
                       out handle));
        }
Beispiel #5
0
        => 0;     // TODO: Task #1272136 (FileContentTable)

        /// <nodoc />
        private static FileOptions FileFlagsAndAttributesToFileOptions(FileFlagsAndAttributes flagsAndAttributes) =>
        s_fileOptionsFlags.Aggregate(FileOptions.None, (acc, kvp) => flagsAndAttributes.HasFlag(kvp.Key) ? acc | kvp.Value : acc);