More NTFS bugs

Jun 2, 2011 at 12:55 AM
Edited Jun 2, 2011 at 12:58 AM

I found another bug. It is successfully copying all 9000+ files now so that bug was fixed, I just tried running an installler (WinRar SFX) to test it and it threw the error below. Im using changeset 24b459f0d86b.

I left about 12000 files and started the installer. It started having problems writing files and directories and DokanDiscUtils console started showing that error. (Even when all activity had stopped the console kept rewriting the error.) I may try uploading the NTFS image if you want to look at it. (Its ~50mb image). Dokan cant even start it because DiscUtils throws the error while opening.


EDIT: Uploading to dropbox now.... When it finishes ill post a link


System.IO.IOException was unhandled�

Message=Invalid NTFS attribute - non-contiguous data runs�


StackTrace:� � � �

� � � �at DiscUtils.Ntfs.NonResidentAttributeBuffer..ctor(File file, NtfsAttribute attribute) in C:\Users\Adam\Downloads\DiscUtilsSrc-0.10\src\Ntfs\NonResidentAttributeBuffer.cs:line 45

� � � �at DiscUtils.Ntfs.NtfsAttribute.get_RawBuffer() in C:\Users\Adam\Downloads\DiscUtilsSrc-0.10\src\Ntfs\NtfsAttribute.cs:line 122

� � � �at DiscUtils.Ntfs.NtfsAttributeBuffer.Read(Int64 pos, Byte[] buffer, Int32 offset, Int32 count) in C:\Users\Adam\Downloads\DiscUtilsSrc-0.10\src\Ntfs\NtfsAttributeBuffer.cs:line 120

� � � �at DiscUtils.BufferStream.Read(Byte[] buffer, Int32 offset, Int32 count) in C:\Users\Adam\Downloads\DiscUtilsSrc-0.10\src\BufferStream.cs:line 119

� � � �at DiscUtils.Utilities.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 length) in C:\Users\Adam\Downloads\DiscUtilsSrc-0.10\src\Utilities.cs:line 759

� � � �at DiscUtils.Utilities.ReadFully(Stream stream, Int32 count) in C:\Users\Adam\Downloads\DiscUtilsSrc-0.10\src\Utilities.cs:line 783

� � � �at DiscUtils.Ntfs.MasterFileTable.GetRecord(Int64 index, Boolean ignoreMagic, Boolean ignoreBitmap) in C:\Users\Adam\Downloads\DiscUtilsSrc-0.10\src\Ntfs\MasterFileTable.cs:line 348

� � � �at DiscUtils.Ntfs.MasterFileTable.GetRecord(Int64 index, Boolean ignoreMagic) in C:\Users\Adam\Downloads\DiscUtilsSrc-0.10\src\Ntfs\MasterFileTable.cs:line 332

� � � �at DiscUtils.Ntfs.NtfsFileSystem.GetFile(Int64 index) in C:\Users\Adam\Downloads\DiscUtilsSrc-0.10\src\Ntfs\NtfsFileSystem.cs:line 1775

� � � �at DiscUtils.Ntfs.NtfsFileSystem..ctor(Stream stream) in C:\Users\Adam\Downloads\DiscUtilsSrc-0.10\src\Ntfs\NtfsFileSystem.cs:line 80

� � � �at Tester.Module1.Main() in C:\Users\Adam\Documents\Visual Studio 2010\Projects\DokanDiscUtilsBridge\Tester\Module1.vb:line 90

� � � �at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)

� � � �at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)

� � � �at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()

� � � �at System.Threading.ThreadHelper.ThreadStart_Context(Object state)

� � � �at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)

� � � �at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)

� � � �at System.Threading.ThreadHelper.ThreadStart()�
Jun 4, 2011 at 5:43 AM

Apologies for the delay - I've been busy with work for a couple of weeks.

A link to the disk would be very useful.

Something you could try locally, is to mount the disk in Windows (using the 'Attach VHD...' option in Disk Management for example), and run 'chkdsk /v' on the disk - will help figure out if the disk is corrupt, or just DiscUtils is confused.



Jun 4, 2011 at 4:39 PM

Heres the link: (The code used to generate the NTFS is in the source of the bridge. Files were added via explorer. The installer worked fine for a while before starting throw errors)

Its a raw NTFS partition so cant be easily mounted in windows. (Linux would be able to loopmount or dd it to a device.)

Thats why im building DokanDiscUtilsBridge. So filesystems can be loopmounted on windows similar to linux.

Jun 4, 2011 at 5:33 PM

Thanks - that file system has gotten pretty badly corrupted.  Some basic low-level stuff (the cluster allocation bitmap) is nothing like it should be.

I'll see if I can figure out what could cause it.

I did notice this in your code is not protected by a SyncLock (GetFileInformation in bridge.vb):

  If p1.DirectoryExists(filename) Then info.IsDirectory = True

It's pretty unlikely this would cause the problem, but may be something you want to take a look at.




Jun 4, 2011 at 5:35 PM

Ok, ill look into that. Is there any writable filesystems in DiscUtils besides NTFS?

Jun 4, 2011 at 6:21 PM

Also - noticed you could do with adding this line to FindFiles:

fileinfo.Length = fi.Length

Directory listings look better then.

I couldn't reproduce the NTFS corruption though - installing winrar into z:\ worked for me.  (Although winrar.exe won't run - but I assume that's a dokan or dokanbridge problem)

Can you start with a new clean file system and figure out some repro steps?




Jun 4, 2011 at 6:28 PM

Ok, I thought i did have that line....

The package i installed was a winrar SFX archive. I installed it after copying ~9000 files, then deleting them.

Jun 4, 2011 at 8:24 PM

Some reason i cant generate  a new filesystem using DiscUtils. When it runs CreateTestNTFS it creates it then stops on a error that shows mft as null. (NTFSFileSystem.cs:1775)

I can restart the bridge and it loads the filesystem but appears to be corrupt. (It wont show filenames and throws MANY "Not a valid Win32 time" errors.)

Jun 5, 2011 at 11:03 AM

Not sure if it's the cause of what you're seeing, but it looks like CreateTestNTFS has a problem...

        Using fs As FileStream = File.Create(filename)
            Dim cap As Long = 50 * 1024 * 1024
            Using floppy As Ntfs.NtfsFileSystem = Ntfs.NtfsFileSystem.Format(fs, "TEST NTFS", Geometry.FromCapacity(cap), 0, Geometry.FromCapacity(cap).TotalSectors)
                ' Use stream...
                Using s As Stream = floppy.OpenFile("foo.txt", FileMode.Create)
                    Dim ts As New StreamWriter(s)
                    ts.AutoFlush = True
                    ts.Write("Hello World!")
                    Return floppy
                End Using
            End Using
        End Using

The Using blocks on fs and floppy are disposing the underlying file stream and the file system before it's actually returned - so you're handing back a 'disposed' object, which probably isn't your goal.

Jun 5, 2011 at 2:01 PM

I didnt even think of that... Ill try removing the using blocks and try again.... (That may be causing problems with corruption too. :S)

Jun 5, 2011 at 3:29 PM

That fixed the problem with not loading the MFT. Now to find out why its thowing all these Not a Valid Win32 Filetime errors.... Directoy listings are empty because of it. :S