Commit Graph

5052 Commits

Author SHA1 Message Date
Erik Larsson
9dee659190 ntfsrecover.c: Fix compiler warning about uninitialized 'savebuf' usage.
The previous fix for the warning referred to 'prevbuf' being used
uninitialized and this is also what the compiler says. However
initializing 'prevbuf' doesn't make the warning go away and further
testing revealed that it is really 'savebuf' being possibly used prior
to initialization that is the source of the warning (the incorrect
warning message is probably an optimization-related gcc bug). So replace
previous ineffective fix with explicit initialization of 'savebuf'.
2016-02-16 09:38:12 +01:00
Erik Larsson
62b5c91420 Fix compiler warnings about mismatching printf format / argument type.
For 64-bit (e.g. x86_64) Linux the 64-bit wide types resolve to long,
not long long as is the case in 32-bit (e.g. i386) Linux. So we need an
explicit cast to long long for 64-bit types since the format string must
specify the 'll' modifier in order to print 64-bit values.
2016-02-16 09:30:49 +01:00
Jean-Pierre André
1ae297378c Version 2016.2.15 2016-02-15 16:32:03 +01:00
Jean-Pierre André
4f6fb651c2 Silenced a compiler warning for possibly uninitialized pointer
Some compilers issue a warning when a pointer is initialized in
both alternatives of a condition. Force an extra initialization
to avoid such warnings.
2016-02-15 12:07:28 +01:00
Jean-Pierre André
941ec4762f Silenced a compiler warning for different types
Some compilers issue a warning when the alternatives in a "? :"
expression have different signedness.
2016-02-15 12:02:10 +01:00
Jean-Pierre André
d2197785f4 Avoided pointer cast when checking record types
Some compilers issue warning when casting a pointer to a pointer to
a different type.
When checking a record magic, there is no need to cast pointers.
2016-02-15 11:54:33 +01:00
Jean-Pierre André
f655192f26 Updated the drivers copyrights
Extend the copyright to 2016
2016-02-12 17:24:27 +01:00
Jean-Pierre André
6548d91f73 Closed the volume when a resizing is done
Closing the volume is the way to sync the MFT to disk. When not doing
so, the MFT runlists in $DATA and $Bitmap are not synced if they have
been updated in the second resizing stage relative to runlists which
have grown outside their original MFT record.
2016-02-12 17:13:21 +01:00
Jean-Pierre André
5edb3ec920 Closed the bad sector inode after updating the list
Unlike in most cases, the bad sector inode has to be closed if it
was updated and required MFT extents (when there are a lot of bad
sectors and some of them were outside the truncated partition).
Not doing so causes the inode to not be fully synced to device.
2016-02-12 17:03:53 +01:00
Erik Larsson
a207d4e86a endians.h: Cast the result of const endianness macros to the right type.
This fixes compiler warnings emitted when you compare an le32 value with
e.g. 'const_cpu_to_le32(-1)' on a little-endian system, because
previously the expansion of the macro expression 'const_cpu_to_le32(-1)'
would be '(-1)' on a little-endian system but '(u32)((((u32)(-1) &
0xff000000u) >> 24) | (((u32)(-1) & 0x00ff0000u) >>  8) | (((u32)(-1) &
0x0000ff00u) <<  8) | (((u32)(-1) & 0x000000ffu) << 24))' on a
big-endian system, i.e. the type of the expanded expression would be
'int' (signed) in the little-endian case but 'u32' (unsigned) in the
big-endian case.

With this commit the type of the expanded expression will be 'le32' in
both the little-endian and the big-endian case.
2016-02-11 14:19:41 +01:00
Erik Larsson
f463919310 ntfs-3g_common.h: Fix improper type for 'dmtime' in ntfs_fuse_context_t.
This field is always assigned a signed value, and compared to other
signed values (ntfs_time values are signed little-endian 32-bit
integers).

This fixes two compiler warnings about signed/unsigned comparison.
2016-02-11 14:06:53 +01: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
33cb3087b5 efs.c: Fix incorrect type of local variables 'newsize' and 'oldsize'.
These variable are only ever assigned to/from s64 values, so their type
should be s64, not u64. This fixes a compiler warning about
signed/unsigned comparison.
2016-02-08 18:42:53 +01:00
Erik Larsson
0b378fd177 ntfslabel.c: Fix incorrect label buffer being NULL-terminated.
The UTF-16LE label buffer containing the result of mbs2ucs is the one
that should be NULL-terminated when the label is longer than permitted.
Not the input buffer, which is a function parameter assumed to be
NULL-terminated anyway.
2016-02-08 18:32:24 +01:00
Erik Larsson
a2efc3ec9f Change type of all LSN struct members in ntfsrecover.h to leLSN.
This is done to match the type of the LSN struct members in layout.h.
The effect of this change is that while these members were declared with
the le64 type previously, leLSN resolves to sle64. I.e. what was
previously unsigned fields are now signed.

Following this change we also need to switch over a few macros from
unsigned to signed versions in the code that uses these struct
definitions.
2016-01-29 12:36:06 +01:00
Erik Larsson
ee4c48f4b1 playlog.c: Use const macro for byteswapping const expression. 2016-01-29 10:49:52 +01:00
Erik Larsson
81fce3b70e playlog.c: Fix improper byteswapping macros used for sle64 members. 2016-01-29 10:49:25 +01:00
Erik Larsson
9893ea9ee6 Merge endianness fixes.
Conflicts:
	libntfs-3g/attrib.c
2016-01-28 09:22:42 +01:00
Erik Larsson
e37258bf01 ntfscmp.c: Fix missing byteswap of little-endian attribute type value. 2016-01-28 09:11:55 +01:00
Erik Larsson
8aca3d4800 ntfsmove.c: Fix multiple cases of raw usage of little-endian fields.
There were multiple cases of little-endian fields being used as
CPU-endian without byte swapping. This would result in incorrect
behaviour on big-endian systems.
2016-01-27 15:28:55 +01:00
Erik Larsson
8daa92717e ntfsdump_logfile.c: Fix use of wrong byteswapping macro for le16 field. 2016-01-27 15:26:51 +01:00
Erik Larsson
0741f54b2e ntfsdump_logfile.c: Fix incorrectly parenthesized expression.
On big-endian systems the result of the '!=' operation would be
endian-swapped rather than the first argument (which must have been the
intended action).
2016-01-27 15:24:52 +01:00
Erik Larsson
55dafda732 ntfsck.c: Fix comparing le32 values as u32.
This is harmless except when we do strict endianness checking, in which
case this results in a compile error. Fixed by converting values to
CPU endianness before comparing them.
2016-01-27 15:23:13 +01:00
Erik Larsson
ec18534f31 ntfsck.c: Fix comparison between little-endian and native-endian data.
This comparison would yield the wrong result on big-endian systems.
2016-01-27 15:21:05 +01:00
Erik Larsson
ef09702b0c ntfstruncate.c: Fix mixed endianness usage of variable 'i'.
In 'dump_resident_attr_val', 'i' was sometimes used as a native-endian
'int'-precision string length value and sometimes used as a little-
endian 16-bit flags value. This type of mixed usage is bad practice and
results in a hard error when strict endianness checking is used.

Fixed by introducing new variable 'flags' to hold the little-endian 16-
bit flags value.
2016-01-26 10:28:38 +01:00
Erik Larsson
7e9003b147 ntfstruncate.c: Fix incorrect type for CPU-endian value in 'ucstos'. 2016-01-26 10:19:44 +01:00
Erik Larsson
1b67b943df ntfstruncate.c: Fix conflicting endianness for variable 'attr_type'.
If the attribute type is specified by the user, 'attr_type' was assigned
a CPU-endian value, however if the attribute type was not specified it
would be assigned the attribute type AT_DATA, which is a little-endian
value. The rest of the code seems to assume that 'attr_type' is
CPU-endian, so this is clearly a bug.

Resolved by fixing the endianness of the variable at little-endian,
converting the input value to little-endian when specified.
2016-01-26 10:18:51 +01:00
Erik Larsson
efa876d31b ntfstruncate.c: Fix mixed endianness usage of variable 'u'.
In 'dump_attr_record' the variable 'u' was first used to store a
CPU-endian 32-bit value, and then to store a 16-bit little-endian value.
This is bad practice and results in a hard error when strict endian type
checking is used.

Fixed by storing the 16-bit little-endian flags value in a new variable
'flags'.
2016-01-26 10:03:36 +01:00
Erik Larsson
02ce4947df ntfs-3g.c: Fix raw usage of inode time fields without byteswapping. 2016-01-26 07:55:45 +01:00
Erik Larsson
701cd61cca volume.c: Fix passing bad pointer type to ntfs_is_[baad|mft]_recordp. 2016-01-25 11:31:12 +01:00
Erik Larsson
8aa2769d70 mst.c: Fix mixed native/little-endian usage of variable 'usn'. 2016-01-25 11:30:13 +01:00
Erik Larsson
84f042e739 reparse.c: Fix big-endian bug when converting file name to lowercase.
When looking up the lowercase equivalent of a Unicode character in
ntfs_fix_file_name, no byte swapping was performed on the ntfschar used
as index into the 'locase' array. This would lead to very strange
results on big-endian systems.
2016-01-04 10:19:05 +01:00
Erik Larsson
75da0ce302 Fix inverted usage of endian conversion macros.
This is mostly a semantic issue since the end result would be the same.
2016-01-04 10:08:15 +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
f076fae75a Fix endianness issues in log and terminal output.
This commit addresses issues where little-endian variables are emitted
raw to a log or output stream which is to be interpreted by the user.

Outputting data in non-native endianness can cause confusion for anybody
attempting to debug issues with a file system.
2015-12-21 23:31:09 +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
Erik Larsson
58bb59487c endians.h: Add const endian conversion macros for s{l,b}e{16,32,64}. 2015-12-21 23:05:36 +01:00
Jean-Pierre André
5efc87cce8 Fixed accessing next log buffer only when it exists
Do not locate the next log buffer until it is known to exist.
2015-12-01 11:12:53 +01:00
Jean-Pierre André
ca70766dc4 Fixed reporting action states when restart page appears outdated
If start buffer is more recent than restart, we update committed LSN
with last record LSN of block (last_end_lsn) while applying action but
forget about it while printing records with -f for investigation
purpose.

Note that while applying actions we use start_buffer to calculate
latest page out of block 2 and block 3 and then from latest take
committed LSN. For -f we don't need buffers so we just compare
directly with committed LSN from restart.

(contributed by Rakesh Pandit)
2015-12-01 11:10:48 +01:00
Jean-Pierre André
f7cbf30d54 Rejected invalid null reparse tag
The null reparse tag is considered invalid by Windows, so do the same.
2015-12-01 11:06:11 +01:00
Jean-Pierre André
4d5ce43ab9 Fixed returning the trimming count to fstrim(8)
When used with the option -v, fstrim(8) reported the maximum trimming count
because the correct value was not returned to the ioctl call.
2015-12-01 11:00:24 +01:00
Jean-Pierre André
730776b0e5 Defined reparse tag for system compression
The new compression formats used by Windows 10 uses reparse data, and
a new reparse tag which it is useful to define even though these formats
is not yet supported by ntfs-3g.
2015-12-01 10:56:01 +01:00
Jean-Pierre André
aeb1d7fb74 Fixed special case of decompressing a runlist
When the unreadable directory has an ATTRIBUTE_LIST attribute and an
INDEX_ALLOCATION attribute occupying split over several extents, the first
of which defines a single cluster, the first INDEX_ALLOCATION extent has
lowest_vcn=0 and highest_vcn=0, and the second one has lowest_vcn=1.

This unusual case, which can be created by the combination of a small
volume and near-full MFT records, triggers some special-case behavior in
ntfs_mapping_pairs_decompress_i(). That behavior is incorrect if the
attribute's first extent only contains a single cluster, since in that case
highest_vcn=0 as well.

This configuration has been tested on Windows and it *is* able to
successfully read the directory.  This supports the hypothesis that the
volume is valid and NTFS-3g has a bug on the read side.

This bug could, in theory, occur with any non-resident attribute, not just
INDEX_ALLOCATION attributes.

(Contributed by Eric Biggers)
2015-11-20 16:17:48 +01:00
Jean-Pierre André
f85b82c8e1 Fixed headers of log play functions in playlog
The functions were made static with a textual description.
2015-11-20 16:14:16 +01:00
Jean-Pierre André
aade4c46b6 Fixed missing error return in playlog
No error was returned from reading a protected record which is part of
an unreadable raw cluster.
2015-11-20 16:11:15 +01:00
Jean-Pierre André
3c964b6af3 Fixed truncating an extended bad cluster list in ntfsresize
This fixes the case where the original bad cluster list requires extents.
The list is processed globally, no relocation is done, and the list is
truncated, possibly fitting into fewer extents.
2015-11-20 16:04:47 +01:00
Jean-Pierre André
ede1808ba6 Removed obsolete code from playlog
The code for dealing with new MFT records had been made more general
2015-11-12 15:46:33 +01:00
Jean-Pierre André
22b59548d9 Subdivided the replay functions in playlog
Partially unnested play_redos() and play_undos()
2015-11-12 15:44:47 +01:00
Jean-Pierre André
fe3e16243a Fixed a memory leak in ntfsrecover
A buffer was left leaking memory in reset_logfile()
2015-11-12 15:41:44 +01:00
Jean-Pierre André
1aa9882810 Silenced a compiler warning (cosmetic)
An argument to ntfs_index_remove() is now unused
2015-11-12 15:39:20 +01:00