Commit graph

57 commits

Author SHA1 Message Date
Trevor Thompson 430ce0a9e3 [NTFS] - Fix some formatting / style issues, per CR-123.
svn path=/branches/GSoC_2016/NTFS/; revision=75290
2017-12-10 11:15:00 +01:00
Trevor Thompson 5ab24a5aae [NTFS] - Add a few fixes and improvements, most from CR-123:
-Add ATTR_RECORD_ALIGNMENT define to replace magic value of 8 when we need to adjust an attribute's beginning or length.
-Don't use int's.
-GetPackedByteCount() - Remove unused "bytes" variable.

svn path=/branches/GSoC_2016/NTFS/; revision=75288
2017-12-10 11:14:58 +01:00
Trevor Thompson 68a48b2758 [NTFS] - Add some fixes and improvements to mft.c from CR-123:
FindAttribute() - Use * sizeof(WCHAR) in place bit-shifting wizardry.
IncreaseMftSize() - Remove two useless casts. Return error code if WriteAttribute() fails.
SetNonResidentAttributeDataLength() - Assert that AttrContext parameter describes a NonResident attribute. When migrating a resident attribute to non-resident, don't leak memory if FsRtlInitializeLargeMcb() throws an exception, and don't mark the attribute as non-resident until after the Mcb is initialized.
InternalSetResidentAttributeLength() and SetResidentAttributeLength() - Assert that AttrContext parameter describes a resident attribute.
AddNewMftEntry() - Simplify math of backing up and restoring reserved bits by changing BitmapData to PUCHAR type. Don't attempt to modify a volume with more than 2^32 clusters.
AddFixupArray() - Use ULONG in place of int.

svn path=/branches/GSoC_2016/NTFS/; revision=75284
2017-12-10 11:14:56 +01:00
Trevor Thompson 34696e49fc [NTFS] - Add some fixes and improvements to finfo.c from CR-123:
NtfsSetEndOfFile() - Make fileNameAttribute and filename variables uppercase. Don't leak FileRecord if we can't truncate the file. Don't leak memory if there's no FileName attribute.

svn path=/branches/GSoC_2016/NTFS/; revision=75283
2017-12-10 11:14:55 +01:00
Trevor Thompson 39a06fae0d [NTFS] - Add some fixes and improvements to create.c, dirctl.c and fcb.c from CR-123:
-NtfsOpenFile() - Replace an ExFreePool() with ExFreePoolWithTag().
-NtfsCreateFile() - Fix broken cast with BooleanFlagOn() macro.
-NtfsAddFilenameToDirectory() - Remove an extra cast. Return an error if we fail to allocate I30IndexRoot. 
-NtfsGetNextPathElement(), NtfsWSubString(), NtfsGetFCBForFile() - Use PCWSTR in place of const PWCHAR or PWCHAR  where it makes sense.

svn path=/branches/GSoC_2016/NTFS/; revision=75281
2017-12-10 11:14:53 +01:00
Trevor Thompson 7e9acb7dda [NTFS] - Add some fixes and improvements to btree.c from CR-123:
-CompareTreeKeys() - Assert that the first key isn't the dummy key.
-CreateIndexRootFromBTree() - Assert that CurrentKey->IndexEntry->Length isn't 0.
-DumpBTreeKey() - Use sizeof(WCHAR) in place of magic 2.
-NtfsInsertKey() - Check for allocation failure of NewKey.

svn path=/branches/GSoC_2016/NTFS/; revision=75280
2017-12-10 11:14:51 +01:00
Trevor Thompson e5cc846555 [NTFS] - Add some fixes and improvements to attribute.c from CR-123:
-AddFileName() - Don't use dedicated buffer for FileNameNoPath, just point into FileObject->FileName's buffer. Don't use RtlCopyUnicodeString(), just update pointers.
-AddRun() - Fix an SEH2_YIELD with missing return statement.
-FreeClusters() - Use ULONG_MAX in place of 0xffffffff.
-NtfsDumpIndexRootAttribute() - Use consistent UpperCase naming convention. Use BooleanFlagOn() macro where appropriate. Replace magic 8 with sizeof(ULONGLONG).
-GetFileNameAttributeLength() - Add documentation.

svn path=/branches/GSoC_2016/NTFS/; revision=75279
2017-12-10 11:14:50 +01:00
Trevor Thompson f5b7f90f23 [NTFS] - Fix UpdateFileNameRecord() when the file being updated resides in $INDEX_ROOT. Also, don't attempt to read beyond size of index root attribute, and check return value after reading.
svn path=/branches/GSoC_2016/NTFS/; revision=75278
2017-12-10 11:14:48 +01:00
Trevor Thompson 612facc28f [NTFS] - Fix AddFileName() when the file path is two or more directories deep.
svn path=/branches/GSoC_2016/NTFS/; revision=75277
2017-12-10 11:14:47 +01:00
Trevor Thompson 16204ed3a7 [NTFS] - Fix gcc build. Fix CompareTreeKeys(): Don't consider Key1 a possible dummy key. Don't assume filenames are the same length.
svn path=/branches/GSoC_2016/NTFS/; revision=75228
2017-12-10 11:14:45 +01:00
Trevor Thompson 2dc4938549 [NTFS] - Fix a couple of issues spotted by Thomas: Maintain alphabetical ordering of CMakeLists.txt, fix casts to BOOLEAN with BooleanFlagOn macro.
svn path=/branches/GSoC_2016/NTFS/; revision=75224
2017-12-10 11:14:43 +01:00
Trevor Thompson 54f5c3b6ec [NTFS] - Begin to implement B-Trees. Allow for creating several new files in a directory.
NtfsAddFilenameToDirectory() - Add CaseSensitive parameter. Update to use new B-Tree code: First, the index is read and converted to a B-Tree in memory. Next, a key for the new file is inserted into the tree. Finally, the tree is converted back to an index root attribute which is written to disk.
+btree.c - Includes functions related to B-Trees (AKA B*Trees).
ntfs.h - Added several structures for representing B-Trees in memory.
Known limitations: For simplicity, only trees with a depth of one are currently supported (i.e. an ordered list of filenames). Directories that have or will require an index allocation to store all their filenames are still TODO. As a consequence, the user will only be able to create about 6 files in a directory.

svn path=/branches/GSoC_2016/NTFS/; revision=75223
2017-12-10 11:14:42 +01:00
Trevor Thompson 38c947b7ab [NTFS] - Add some minor fixes and improvements:
Improve, add, or fix some DPRINTs. In particular, ULONG's should use %lu, not %u. Also, don't be silent about filesystem corruption.
NtfsFindMftRecord() - move CaseSensitive parameter before output parameter in parameter list.

svn path=/branches/GSoC_2016/NTFS/; revision=75199
2017-12-10 11:14:40 +01:00
Trevor Thompson e4aab26781 [NTFS] - Fix creation of files with long filenames.
svn path=/branches/GSoC_2016/NTFS/; revision=75193
2017-12-10 11:14:39 +01:00
Trevor Thompson 8bb62e20d3 [NTFS] - In the NtfsAddFilenameToDirectory() function, rename DirectoryContext parameter to the more descriptive, and accurate, IndexRootContext (to simplify the next commit).
svn path=/branches/GSoC_2016/NTFS/; revision=75192
2017-12-10 11:14:37 +01:00
Trevor Thompson 948e91907a [NTFS] - Fix a mistake with AddFileName() from my last commit. Also, move CaseSensitive parameter before output parameters in the parameter list of several functions.
svn path=/branches/GSoC_2016/NTFS/; revision=75191
2017-12-10 11:14:35 +01:00
Trevor Thompson 032be02954 [NTFS] - Fix POSIX rules. Fix accessing long filenames created in Windows when 8dot3 name creation is disabled.
Whether or not a filename should be interpreted as case-sensitive is dependent on a flag passed to the driver when a file is created (opened); it's separate from the namespace associated with the file being accessed.

svn path=/branches/GSoC_2016/NTFS/; revision=75178
2017-12-10 11:14:34 +01:00
Trevor Thompson 98ddf610bc [NTFS] - Fix IncreaseMftSize(); check IrpContext to see if waiting for exclusive access to the MFT is allowed. As pointed out by Pierre.
svn path=/branches/GSoC_2016/NTFS/; revision=75170
2017-12-10 11:14:32 +01:00
Trevor Thompson 9ab86116a9 [NTFS] - Add support for expanding the master file table. Fix a bug with BrowseIndexEntries(). Improve diagnostic output.
-AddNewMftEntry() - Increase size of MFT as needed. Fix math for bitmap length. Don't assign file records to MFT indices 0x10 - 0x17; In Windows, these records aren't used unless they have to be, even though they are marked as unused in the bitmap.
+IncreaseMftSize() - Adds room for additional file records in the master file table.
-BrowseIndexEntries() - allow for the rare situation when a non-system file has an MFT index of 0x10.

svn path=/branches/GSoC_2016/NTFS/; revision=75056
2017-12-10 11:14:30 +01:00
Trevor Thompson 1417f286e0 [NTFS] - Restructure some code in preparation for the next commit:
-SetAttributeDataLength() has been split into two functions, SetNonResidentAttributeDataLength() and SetResidentAttributeDataLength(). This should improve code readibility and allows for resizing an attribute when there's no FileObject associated with it.
-Added "MftDataOffset" member to DEVICE_EXTENSION, which stores the offset of the Mft's $DATA attribute. (I'm starting to think it's better to add a member for offset to NTFS_ATTR_CONTEXT directly, but I'll save that level of restructuring for a future commit.)

svn path=/branches/GSoC_2016/NTFS/; revision=75055
2017-12-10 11:14:29 +01:00
Trevor Thompson 9dce6f4db1 [NTFS] - Add some improvements to the previous commit, as suggested by Thomas.
svn path=/branches/GSoC_2016/NTFS/; revision=75054
2017-12-10 11:14:27 +01:00
Trevor Thompson e0048b1362 [NTFS] - Add the most basic support for file creation. Expand diagnostic output, especially in NtfsDumpIndexRootAttribute(). Replace an ExFreePool() with ExFreePoolWithTag().
AddFileName() - Add a parameter to receive the Mft index of the parent directory. Fix so the name of the file will be stored in the attribute, not the name of the directory.
NtfsCreateFile() - Open a file that was successfully created, instead of assuming failure.
NtfsCreateFileRecord() - Add the filename attribute of the created file to the parent directory's index.
+NtfsAddFilenameToDirectory() - Adds a $FILE_NAME attribute to a given directory index. Presently, a file can be created in an empty directory only.
AddNewMftEntry() - Add a parameter to receive the mft index where the new entry was stored.

svn path=/branches/GSoC_2016/NTFS/; revision=74970
2017-12-10 11:14:26 +01:00
Trevor Thompson 4ca9151300 [NTFS] - Decrease debug spam
svn path=/branches/GSoC_2016/NTFS/; revision=74694
2017-12-10 11:14:24 +01:00
Trevor Thompson 037d88201d [NTFS] - Disable write support by default. Enable it via the registry.
[BOOTDATA] - Add a commented-out section to hivesys.inf which can add the required key to enable NTFS write support.

svn path=/branches/GSoC_2016/NTFS/; revision=74685
2017-12-10 11:14:22 +01:00
Trevor Thompson 7f762aac01 [NTFS] - Add support for changing a file's size via SetEndOfFile():
-Handle IRP_MJ_SET_INFORMATION IRP requests.
+NtfsSetEndOfFile() - Sets the end of file (file size) for a given file.
+NtfsSetInformation() - Sets the specified file information. At this point, only FileEndOfFileInformation is fully implemented. FileAllocationInformation is handled the same way and not truly implemented, but this works well enough for SetEndOfFile().
Overwriting a file in NTFS should now work in the majority of use cases.

svn path=/branches/GSoC_2016/NTFS/; revision=74675
2017-12-10 11:14:21 +01:00
Trevor Thompson 58402b6730 [NTFS] - Fix a bug with last commit, as spotted by Pierre.
svn path=/branches/GSoC_2016/NTFS/; revision=74525
2017-12-10 11:14:19 +01:00
Trevor Thompson c25b9747a1 [NTFS] - Expand support for resizing resident attributes and fix NtfsAllocateClusters().
-Modify SetAttributeDataLength() to allow a resident attribute to migrate to non-resident if the attribute grows too large to remain resident.
-Fix values returned by NtfsAllocateClusters() in case of error; return error codes, not 0.

svn path=/branches/GSoC_2016/NTFS/; revision=74524
2017-12-10 11:14:18 +01:00
Trevor Thompson 52b9f46776 [NTFS] - Commit early results of a small restructuring effort:
-Add a new member to the NTFS_ATTR_CONTEXT struct, a LARGE_MCB. This allows an attribute context to describe the cluster mapping of a non-resident file while allowing that mapping to change dynamically, without the context itself needing to be resized. This fixes problems which sometimes arose from resizing files.
-Remove hacky code from NtfsWriteFile() for dealing with "stale" contexts. This fixes that issue.
-Update SetDataAttributeLength(), PrepareAttributeContext(), ReleaseAttributeContext(), FreeClusters(), and AddRun() for the new member.
-Update ReadAttribute() and WriteAttribute() to work with the changed structure. A very-soon-to-come commit will overhaul these functions so they'll operate directly on the LARGE_MCB, instead of converting to and from a packed list of data runs. (Sparse files are broken until then.)
-Rename "RunBufferOffset" to "RunBufferSize" in several places where appropriate.
-Fix, improve, and add some comments.

svn path=/branches/GSoC_2016/NTFS/; revision=74523
2017-12-10 11:14:16 +01:00
Trevor Thompson 0409b3161e [NTFS] Add support for creating new MFT entries:
+AddStandardInformation(), +AddData(), +AddFileName() - Add attributes to a file record
+NtfsCreateFileRecord() - Creates a new file record and saves it to the MFT.
+AddNewMftEntry() - Adds a file record to the MFT.
NtfsCreateFile() - Modified to create a file record on a file-creation request (file creation is still unsupported; the created file needs to be added to the parent's directory index).
+SetFileRecordEnd() - Establishes a new file record size
UpdateFileRecord() - Improved documentation
InternalSetResidentAttributeLength() - Updated to use SetFileRecordEnd().

svn path=/branches/GSoC_2016/NTFS/; revision=74321
2017-12-10 11:14:14 +01:00
Trevor Thompson 7643831d56 [NTFS]
+NtfsDumpFileRecord() - Provides diagnostic information about a file record.

svn path=/branches/GSoC_2016/NTFS/; revision=72424
2017-12-10 11:14:13 +01:00
Trevor Thompson 6ab3072098 [NTFS]
*UpdateFileRecord() - Fix a DPRINT

svn path=/branches/GSoC_2016/NTFS/; revision=72423
2017-12-10 11:14:11 +01:00
Trevor Thompson 8b893c8e30 [NTFS]
Add some fixes to attrib.c, as suggested by Pierre Schweitzer:
*ConvertLargeMCBToDataRuns() - Use MS portable type, ULONG, for variable i.
*FreeClusters(), AddRun() - Check for invalid parameter before allocating memory, and confirm the memory is allocated.
*ConvertDataRunsToLargeMCB(), AddRun() - Avoid code duplication by using ExRaiseStatus() in try block, and return accurate status via _SEH2_GetExceptionCode().

svn path=/branches/GSoC_2016/NTFS/; revision=72422
2017-12-10 11:14:10 +01:00
Trevor Thompson 920e2f0216 [NTFS]
+FreeClusters(). Fix a DPRINT.

svn path=/branches/GSoC_2016/NTFS/; revision=71968
2017-12-10 11:14:08 +01:00
Trevor Thompson ed1b4bf9bc [NTFS]
Address some minor issues with attrib.c: Fix gcc build. Fix formatting.

svn path=/branches/GSoC_2016/NTFS/; revision=71957
2017-12-10 11:14:07 +01:00
Trevor Thompson d09e1398f8 [NTFS]
*AddRun() - Don't leak RunBuffer when encountering errors.
Handle exception from FsRtlAddLargeMcbEntry().

svn path=/branches/GSoC_2016/NTFS/; revision=71945
2017-12-10 11:14:05 +01:00
Trevor Thompson afe40eb054 [NTFS]
Implement AddRun(). Add support functions and documentation.
+ConvertDataRunsToLargeMCB()
+ConvertLargeMCBToDataRuns()
*SetAttributeDataLength(), *NtfsWriteFile() - Update for AddRun() implementation. Add hack to SetAttributeDataLength() to allow notepad.exe to save files until freeing clusters is implemented.

svn path=/branches/GSoC_2016/NTFS/; revision=71942
2017-12-10 11:14:03 +01:00
Trevor Thompson a135ef5864 [NTFS]
Various minor changes to fix GCC build.

svn path=/branches/GSoC_2016/NTFS/; revision=71922
2017-12-10 11:14:02 +01:00
Trevor Thompson 63e83c7ffc [NTFS]
Add support functions, fix warning from previous commit.
+NtfsDumpDataRuns(), +NtfsDumpDataRunData() - Provide diagnostic output.
+GetPackedByteCount() - Used to encode data runs.

svn path=/branches/GSoC_2016/NTFS/; revision=71921
2017-12-10 11:14:00 +01:00
Trevor Thompson 268a139e63 [NTFS]
UpdateFileRecord() - Remove fixup array before returning.

svn path=/branches/GSoC_2016/NTFS/; revision=71920
2017-12-10 11:13:58 +01:00
Trevor Thompson 7c576a836f [NTFS]
Add error-checking to InternalGetNextAttribute(); don't crash if CurrAttr->Length is invalid.

svn path=/branches/GSoC_2016/NTFS/; revision=71897
2017-12-10 11:13:57 +01:00
Trevor Thompson de5cff4b37 [NTFS]
Fix broken check for free disk space in NtfsAllocateClusters().

svn path=/branches/GSoC_2016/NTFS/; revision=71858
2017-12-10 11:13:55 +01:00
Trevor Thompson 7a6e9bcdf6 [NTFS]
Simplify GetLastClusterInDataRun() and clean up NtfsAllocateClusters(). No functional changes.

svn path=/branches/GSoC_2016/NTFS/; revision=71857
2017-12-10 11:13:54 +01:00
Trevor Thompson c08d37d182 [NTFS]
Simplify and optimize InternalSetResidentAttributeLength(), as suggested by Pierre.

svn path=/branches/GSoC_2016/NTFS/; revision=71837
2017-12-10 11:13:52 +01:00
Trevor Thompson 7eb1264f5f [NTFS]
Fix copy-paste error in SetAttributeDataLength()

svn path=/branches/GSoC_2016/NTFS/; revision=71832
2017-12-10 11:13:50 +01:00
Trevor Thompson 760cdfb5aa [NTFS]
Add ability to write to resident attributes.
SetAttributeDataLength() - Check if the file is memory mapped before truncating
+InternalSetResidentAttributeLength() - Used by SetAttributeDataLength()

svn path=/branches/GSoC_2016/NTFS/; revision=71820
2017-12-10 11:13:49 +01:00
Trevor Thompson 25fdabd8ca [NTFS]
Fix typo in NtfsAllocateClusters(), spotted by ThFabba.

svn path=/branches/GSoC_2016/NTFS/; revision=71697
2017-12-10 11:13:35 +01:00
Trevor Thompson 77fc65dc0e [NTFS]
Lay some groundwork for extending allocation size.
+AddRun() - Unimplemented
+GetLastClusterInDataRun()
+NtfsAllocateClusters()

svn path=/branches/GSoC_2016/NTFS/; revision=71696
2017-12-10 11:13:33 +01:00
Trevor Thompson 84a1280fd6 [NTFS]
Allow for an existing file to be opened with FILE_OVERWRITE, FILE_OVERWRITE_IF, or FILE_SUPERSEDE dispositions, and truncate that file. This allows for a file to be opened and saved in Notepad.exe [provided that file is non-resident and its allocation size doesn't need to change].

svn path=/branches/GSoC_2016/NTFS/; revision=71680
2017-12-10 11:13:31 +01:00
Trevor Thompson f47efca89f [NTFS]
Remove unused parameter from SetAttributeDataLength.

svn path=/branches/GSoC_2016/NTFS/; revision=71677
2017-12-10 11:13:30 +01:00
Trevor Thompson a7a2c0d734 [NTFS]
Update a file's size in the relevant $FILE_NAME attribute of the index entry in the parent directory.
+UpdateFileNameRecord() - Searches a parent directory for the proper index entry, then updates the file sizes in that entry.
+UpdateIndexEntryFileNameSize() - Recursively searches directory index and applies the size update.

svn path=/branches/GSoC_2016/NTFS/; revision=71664
2017-12-10 11:13:28 +01:00