Example #1
0
        public void ShouldGetFileInfoWithMultipleHardLinks()
        {
            var path = IOPath.GetTempPath();

            path = IOPath.Combine(path, IOPath.GetRandomFileName());

            var file = IOFile.Create(path);

            file.Close();

            var linkPath = IOPath.GetTempPath();

            linkPath = IOPath.Combine(linkPath, IOPath.GetRandomFileName());

            CFile.CreateHardLink(linkPath, path);

            try
            {
                var fileInfo = new CFileInfo(path);
                Assert.That(fileInfo.LinkCount, Is.EqualTo(2), "LinkCount");
            }
            finally
            {
                IOFile.Delete(path);
                IOFile.Delete(linkPath);
            }
        }
Example #2
0
        public void ShouldIgnoreFileInDirectoryThatDoesNotExist()
        {
            var fileInfo = new CFileInfo("C:\\I\\do\\not\\exist.txt");

            Assert.That(fileInfo.FileIndex, Is.EqualTo(0));
            Assert.That(fileInfo.LinkCount, Is.EqualTo(0));
            Assert.That(fileInfo.VolumeSerialNumber, Is.EqualTo(0));
        }
Example #3
0
        public void ShouldIgnoreFileThatDoesNotExist()
        {
            var path = IOPath.GetTempPath();

            path = IOPath.Combine(path, IOPath.GetRandomFileName());
            var fileInfo = new CFileInfo(path);

            Assert.That(fileInfo.FileIndex, Is.EqualTo(0));
            Assert.That(fileInfo.LinkCount, Is.EqualTo(0));
            Assert.That(fileInfo.VolumeSerialNumber, Is.EqualTo(0));
        }
Example #4
0
        public void ShouldGetFileInfo()
        {
            var path = IOPath.GetTempPath();

            path = IOPath.Combine(path, IOPath.GetRandomFileName());
            var file = IOFile.Create(path);

            file.Close();
            try
            {
                var fileInfo = new CFileInfo(path);
                BY_HANDLE_FILE_INFORMATION kernelFileInfo;
                using (file = IOFile.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    try
                    {
                        CFileInfo.GetFileInformationByHandle(file.SafeFileHandle, out kernelFileInfo);
                    }
                    finally
                    {
                        file.Close();
                    }
                }

                Assert.That(fileInfo.LinkCount, Is.EqualTo(kernelFileInfo.NumberOfLinks), "LinkCount");
                Assert.That(fileInfo.VolumeSerialNumber, Is.EqualTo(kernelFileInfo.VolumeSerialNumber), "VolumeSerialNumber");

                UInt64 fileIndex = kernelFileInfo.FileIndexHigh;
                fileIndex  = fileIndex << 32;
                fileIndex |= kernelFileInfo.FileIndexLow;

                Assert.That(fileInfo.FileIndex, Is.EqualTo(fileIndex), "FileIndex");

                fileIndex = fileInfo.FileIndex;
                var upperIndex = (uint)((fileIndex >> 32) & 0xffffffff);
                Assert.That(kernelFileInfo.FileIndexHigh, Is.EqualTo(upperIndex));

                var lowerIndex = (uint)(fileIndex & 0xffffffff);
                Assert.That(kernelFileInfo.FileIndexLow, Is.EqualTo(lowerIndex));
            }
            finally
            {
                IOFile.Delete(path);
            }
        }