Commit Graph

53 Commits (edge)

Author SHA1 Message Date
Erik Larsson 1565b01e21 mft.c: Fix broken free MFT records accounting during bitmap extension.
When the bitmap needs extending, 'vol->free_mft_records' is incremented
by 8*8=64 records. This is due to the bitmap's initialized area being
extended 8 bytes at a time.
However the way 'vol->free_mft_records' is being initialized is that all
the bits that are currently allocated to the MFT bitmap are already
taken into account at initialization time. This leads to a value for
'vol->free_mft_records' that is larger than the actual available number
of MFT records.

For example if there are 20 used MFT records and the bitmap has a 4096
byte allocation where 16 bytes are initialized, the number of free MFT
records are ((8 * 16) - 20) + (8 * (4096 - 16)) = 32748 records
available.
If we now expand the bitmap by 8 initialized bytes, we'd be adding 64
MFT entries according to the logic in the function
'ntfs_mft_bitmap_extend_initialized'.
However we are expanding it within the bounds of the existing allocation
where there is (4096 - 16) bytes free, so they shouldn't be added at all
at this stage.

The result is that our internal accounting is that we have 32748 + 64 =
32812 available MFT records, but in reality we will have 32748 records
available all the time until we expand the allocation beyond 4096 bytes.

Fixed by incrementing 'vol->free_mft_records' when the allocation is
expanded, not when the initialized size is.
2023-05-09 11:25:10 +03:00
Jean-Pierre André bce5734a75 Fixed operation on little endian data
Forcing an even usa_of, in a recent security patch, must be made on cpu
endian data.
2022-05-10 10:40:17 +02:00
Jean-Pierre André a8818cf779 Used a default usn when the former one cannot be retrieved
When creating a new MFT record, the former seq_no and usn are retrieved
to avoid the new one to be mistaken for the former one.
This may not be possible when the record is used for the first time
or after some bad error. In such situation use default values.
2021-09-21 10:53:16 +02:00
Jean-Pierre André 45141516d7 Renamed ntfs_attr_consistent() as ntfs_attr_inconsistent()
The original name was error prone while checking the condition.
2021-07-19 09:23:23 +02:00
Jean-Pierre André 7f45544ed7 Added and grouped generic attribute checks
Checked that attributes are [non-]resident when they have to be, and
grouped consistency checks on each of them in a dedicated function.
Consequenly request the checks where needed and remove existing index
checks.
2021-07-12 08:31:18 +02:00
Jean-Pierre André 8adc9c6184 Hardened consistency checks of MFT records
Check the record is properly aligned and does not flow beyond the
expected end of the record.
2021-05-17 15:35:02 +03:00
Jean-Pierre André bb0168e56b Rejected updates of uninitialized MFTMirr
Reject updating uninitialized MFTMirr because it leads to endless
recursions as updating the MFTMirr entry of MFT implies further updating
MFTMirr.
This is probably specific to ntfsfix, as mounts are normally rejected
when MFTMirr does not match MFT.
2021-05-17 15:33:41 +03:00
Jean-Pierre André 1f8b751341 Double-checked whether record 15 is an extent of MFT
When extents are needed to store the runlist of the MFT, the first one
must be located in record 15 so that its location can be determined from
the part in the base extent. As this record is always marked in use,
determining whether it is not really in use requires a specific logic.
2018-02-13 09:06:49 +01:00
Jean-Pierre André 366c20e8a2 Silenced fixup warnings when allocating a new MFT record
When creating a new MFT record, do not issue a warning if the current
record has bad fixups. These warnings are meaningless, difficult to
interpret and cause unneeded worries.
2016-04-06 09:32:18 +02:00
Erik Larsson abb2266147 mft.c: Fix compiler warning about mismatching format/argument type.
The expression is promoted to 'int' implicitly so we explicitly cast it
to 'u8'.
2016-02-11 13:52:59 +01:00
Erik Larsson 9893ea9ee6 Merge endianness fixes.
Conflicts:
	libntfs-3g/attrib.c
2016-01-28 09:22:42 +01:00
Erik Larsson 9cf04fd2cd Fix incorrect usage of native/little-endian types, signed types, etc.
This is harmless with regard to code generation but if we turn on strict
type checking these type mismatches will result in errors.
2015-12-21 23:55:31 +01:00
Erik Larsson dfa4a6647f Fix code to use const_cpu_to_X/const_X_to_cpu macros for constants.
This enables the compiler to optimize this code in cases where compiler
support for endianness swapping is not present.
2015-12-21 23:21:00 +01:00
Jean-Pierre André e24ea68632 Removed a temporary debug comment (cosmetic)
The comment was a left over from some debugging action.
2015-04-17 10:56:34 +02:00
Jean-Pierre André b249246e9f Defended against reusing data from an invalid MFT record
An unused MFT record may show a bad length, leading to fetch fixups from
unallocated memory when allocating the record to a new file. So check
the length before applying the fixups. Such records have been found after
the MFT has been reallocated by a defragmenter, and they are not cleaned
by chkdsk.
2015-04-17 10:41:04 +02:00
Jean-Pierre André e6c46d4fa0 Used MFT record 15 for the first extent to MFT:DATA
When the runlist of the data attribute of MFT has to be split across
several extents, the location of each extent has to be known from the
runlist present in previous extents. So, force the first extent into
record 15 to avoid a bad layout.
2014-03-11 10:16:26 +01:00
Jean-Pierre André 08bf2b5bcb Avoided logging meaningless fixup errors in ntfsclone and ntfsresize
Logging of fixup errors for uninitialized inodes cause unnecessary
worries and suspicion of malfunctions in ntfs-3g. This patch silences
these loggings in ntfsclone and ntfsresize which have to analyze all
inodes, including the uninitialized ones.
2011-09-23 11:28:42 +02:00
Jean-Pierre André 5cd49257b0 Removed unneeded variables as warned by gcc 4.6 2011-07-05 12:17:29 +02:00
jpandre d78add4e8f Developed time stamping up to 100ns resolution 2010-01-04 08:24:44 +00:00
jpandre d75f69d80e Cached inode data for subsequent use 2009-12-18 08:12:23 +00:00
jpandre 2db43fc118 Included <limits.h> explicitly, needed in some environments 2009-12-15 18:25:15 +00:00
jpandre 20fb2395fd Simplified tracking of forced time stamps 2009-11-26 13:34:42 +00:00
jpandre 5e650c0c91 Developped getting and setting NTFS times 2009-07-09 15:20:14 +00:00
jpandre 717da2a52c Fixed endianness oddities 2009-04-20 15:23:52 +00:00
jpandre 03755a9ba5 Adapted to ntfs-3g-2009.4.4 2009-04-03 06:53:12 +00:00
jpandre 2a1d75a3da Adapted to ntfs-3g.2009.3.8 2009-03-27 09:10:00 +00:00
jpandre 93b695f1cc Adapted to ntfs-3g-2009.2.1 2009-02-12 20:32:21 +00:00
jpandre 2dc7362ba9 Improved computation of runlist for fragmented files O(n) instead of O(n*n) 2009-02-03 17:12:04 +00:00
jpandre 6faf38df12 Adapted to ntfs-3g.1.5130 2008-12-01 15:29:23 +00:00
jpandre e5286c09d6 Adapted to ntfs-3g.1.2926-RC 2008-09-19 13:39:38 +00:00
szaka 5dbdb30df8 add tabulated logging for the most common ntfs_mft_* functions 2008-06-30 11:18:49 +00:00
szaka a6d8c6b1a6 new: use tabulated logging; add ntfs_log_enter() and ntfs_log_leave()
and convert the most commonly used functions
2008-06-30 00:13:23 +00:00
szaka 1098244bbf copyright update 2008-06-29 23:13:32 +00:00
jpandre 7c05f13884 Adapted to ntfs-3g-1.2531 2008-05-30 07:40:22 +00:00
jpandre a8dc8655d0 Adjusted to v 1.1030 2007-10-29 16:28:33 +00:00
jpandre cd8e66dc3a Code cleaning : fixed machine-dependent casts when fprintf'ing with %lld 2007-10-09 09:05:06 +00:00
jpandre 13a68a1864 Upgraded to v1.1004 2007-10-06 14:48:10 +00:00
szaka a97c661efe statfs optimization: O(1) free cluster calculation (David Fox, Szabolcs Szakacsits) 2007-09-12 20:51:06 +00:00
szaka 817e052b80 ntfs_mft_bitmap_find_free_rec: log errno 2007-07-21 22:20:26 +00:00
szaka 75649971f9 ntfs_mft_bitmap_find_free_rec: logging cleanup 2007-07-21 22:18:49 +00:00
szaka 8636d42841 ntfs_mft_records_read, ntfs_file_record_read: log all errors 2007-07-20 22:42:19 +00:00
szaka 58e31d44eb ntfs_mft_bitmap_extend_allocation: remove redundant cluster allocation 2007-07-20 22:02:50 +00:00
szaka 6f083fc36f ntfs_mft_bitmap_extend_allocation: rename ret to err to match similar function 2007-07-20 21:52:07 +00:00
szaka fa961c737b ntfs_mft_record_layout: log all errors 2007-07-16 20:39:26 +00:00
szaka d405b5b371 ntfs_mft_record_init(): log errno 2007-07-15 18:17:35 +00:00
szaka 7c926367b9 ntfs_mft_record_format(): cleanup 2007-07-15 16:44:42 +00:00
szaka 0cee6bc4bb remove redundant ntfs_attr_get_search_ctx() error logging 2007-07-13 20:05:48 +00:00
szaka 115306462a ntfs_mft_data_extend_allocation: log errno 2007-07-11 22:55:22 +00:00
szaka 638436ad44 fix: file creation always gave "I/O error" if $MFT Bitmap wasn't up-to-date 2007-05-31 23:52:41 +00:00
szaka 58987ffe0c ntfs_mft_record_alloc(): factor out ntfs_mft_record_init() 2007-05-31 23:07:29 +00:00