Пример #1
0
        public void CannotAccessDeletedFile()
        {
            ulong  volumeSerial;
            FileId fileId;
            string path = GetFullPath("F");

            using (FileStream fs = File.Create(path))
            {
                volumeSerial = FileUtilities.GetVolumeSerialNumberByHandle(fs.SafeFileHandle);
                fileId       = FileUtilities.ReadFileUsnByHandle(fs.SafeFileHandle).Value.FileId;
            }

            File.Delete(path);

            VolumeMap map = CreateMapOfAllLocalVolumes();

            using (FileAccessor accessor = map.CreateFileAccessor())
            {
                SafeFileHandle handle;
                FileAccessor.OpenFileByIdResult openResult = accessor.TryOpenFileById(
                    volumeSerial,
                    fileId,
                    FileDesiredAccess.GenericRead,
                    FileShare.ReadWrite,
                    FileFlagsAndAttributes.None,
                    out handle);
                using (handle)
                {
                    XAssert.AreEqual(FileAccessor.OpenFileByIdResult.FailedToFindFile, openResult);
                    XAssert.IsNull(handle);
                }
            }
        }
        /// <summary>
        /// Creates an instance of <see cref="FileContentTableAccessorWin"/>
        /// </summary>
        /// <param name="volumeMap">Volume map.</param>
        public FileContentTableAccessorWin(VolumeMap volumeMap)
        {
            Contract.Requires(volumeMap != null);

            m_volumeMap    = volumeMap;
            m_fileAccessor = m_volumeMap.CreateFileAccessor();
        }
Пример #3
0
        public void CanAccessMultipleFilesById()
        {
            var fileIdAndVolumeSerialPairs = new List <Tuple <FileId, ulong> >();

            for (int i = 0; i < 3; i++)
            {
                string path = GetFullPath("F" + i);
                using (FileStream fs = File.Create(path))
                {
                    fs.WriteByte((byte)i);

                    ulong  volumeSerial = FileUtilities.GetVolumeSerialNumberByHandle(fs.SafeFileHandle);
                    FileId fileId       = FileUtilities.ReadFileUsnByHandle(fs.SafeFileHandle).Value.FileId;
                    fileIdAndVolumeSerialPairs.Add(Tuple.Create(fileId, volumeSerial));
                }
            }

            VolumeMap map = CreateMapOfAllLocalVolumes();

            using (FileAccessor accessor = map.CreateFileAccessor())
            {
                for (int i = 0; i < fileIdAndVolumeSerialPairs.Count; i++)
                {
                    Tuple <FileId, ulong> fileIdAndVolumeSerial = fileIdAndVolumeSerialPairs[i];

                    SafeFileHandle handle;
                    FileAccessor.OpenFileByIdResult openResult = accessor.TryOpenFileById(
                        fileIdAndVolumeSerial.Item2,
                        fileIdAndVolumeSerial.Item1,
                        FileDesiredAccess.GenericRead,
                        FileShare.ReadWrite,
                        FileFlagsAndAttributes.None,
                        out handle);
                    using (handle)
                    {
                        XAssert.AreEqual(openResult, FileAccessor.OpenFileByIdResult.Succeeded);
                        XAssert.IsNotNull(handle);

                        using (var fileStream = new FileStream(handle, FileAccess.Read))
                        {
                            XAssert.AreEqual(i, fileStream.ReadByte());
                        }
                    }
                }
            }
        }