Commit Graph

5081 Commits

Author SHA1 Message Date
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
Jean-Pierre André
59c90f039d Defined the last logfile block as preceding block 4 in ntfsrecover
When block 2 or block 3 points backward to block 4, it is not clear
whether the log file only consists of block 2 or block 3 or the log
file has just wrapped around. The latter is now assumed.
2015-11-12 15:31:24 +01:00
Jean-Pierre André
f7bc5249bc Alleviated constraints relative to reparse points
Some constraints put on reparse points of unknown type (e.g. they cannot
be deleted) are not acceptable to archivers. This patch removes some
constraints.
2015-11-09 16:22:16 +01:00
Jean-Pierre André
fb0afd41c8 Decoded the full list of bad clusters in ntfsclone and ntfsresize
When the bad cluster list required extent, ntfsclone and ntfsresize
did not process the extents, leading to unexpected read errors and
unmatching bitmaps. This fix enables the full list to be taken into
account.
2015-11-09 16:16:39 +01:00
Jean-Pierre André
34d29fe0b0 Fixed reparse data check for non-Microsoft tags
Windows requires non-Microsoft reparse points (identified by having bit
31 of the reparse tag clear) to have a 16-byte GUID following the regular
reparse point header.  This GUID is not, and cannot, be included in the
"reparse data length" field.

(Contributed by Eric Biggers)
2015-11-09 16:14:31 +01:00
Jean-Pierre André
37bd6661d4 Fixed getting space for making an index non resident
Under some rare condition there is no space in an MFT entry to make
an index non-resident, and the index root has to be moved to an extent.
This fix cares for the situation when the attribute list was inserted
beforehand.
2015-11-09 16:09:52 +01:00
Jean-Pierre André
1aaaa8fac1 Wrote as much data as possible in compressed attribute pwrite
When writing to compressed data, the function ntfs_attr_pwrite()
cannot cross a compression block border. This is a problem for archivers
which rely on libntfs-3g, so the function is now wrapped in another one
which restarts the writing as needed.
2015-11-09 16:00:31 +01:00
Jean-Pierre André
cba621e822 Silenced a compiler warning in ntfswipe (cosmetic)
Avoid a signed-to-unsigned compare warning
2015-11-09 15:58:00 +01:00
Jean-Pierre André
e736fea196 Fixed relocating the MFT runlists in ntfsresize
The MFT has two runlists which may be partially stored in extents.
When these runlists have to be relocated, the relocations must be done
after the old runlists are not needed any more to read the data of
standard files, but before the MFT may be needed to extend the runlists
of standard files. Before doing so the MFT runlists have to be refreshed
from device in order to collect the updates which cannot be done in
memory during the first stage.
2015-11-09 15:44:33 +01:00
Jean-Pierre André
0cb0173bbc Implemented recovery of updates committed by Windows
ntfsrecover applies to the metadata the updates which were requested on
Windows but could not be completed because they were interrupted by
some event such as a power failure, a hardware crash, a software crash
or the device being unplugged. Doing so, the file system is restored
to the latest consistent state.

No update to libntfs-3g is required by this implementation.
2015-11-09 13:18:58 +01:00
Erik Larsson
9191d85e28 Use appropriate little-endian/big-endian types in struct definitions.
On-disk struct definitions used native types (u16/u32/u64/s16/s32/s64),
which doesn't say anything about the intended interpretation of the
data. The intention of having little-endian-specific types and
big-endian-specific types must have been to clarify interpretation of
data and intentions in the code. Therefore it seems reasonable to use
these types in struct definitions to clarify what data represention is
used to encode field data.

Because some struct members in layout.h are big-endian, this change also
means moving the duplicated definitions for big-endian byteswapping
macros and big-endian types found in acls.h and security.h to the
appropriate locations in endians.h and types.h respectively in order to
make them available for the struct definitions in layout.h.
2015-10-03 12:58:08 +02:00
Jean-Pierre André
80e500c6ef Protected against opendir reinitialization in lownfs-3g
Under some condition (probably interference with another process), the
directory list gets reinitialized by releasedir() and opendir() at the
beginning of a partial buffer. So in readdir() skip to the requested
offset. This is a step towards implementing seekdir().
2015-09-30 09:35:17 +02:00
Jean-Pierre André
2f373dee56 ntfsprogs Builds on Windows use macroes to translate printing formats,
and these macroes redefined "buf" in a way which causes trouble when
"buf" has another meaning. Use "_b" instead.
2015-09-30 09:08:35 +02:00
Jean-Pierre André
800660f728 Displayed reparse point information in ntfsinfo
Added displaying of reparse point data and decode known formats.
2015-09-30 09:05:47 +02:00
Jean-Pierre André
9f22e17a16 Improved the check for a valid $MFTMirr
The test for a valid $MFTMirr could segfault on a badly damaged partition.
Add safety checks.
2015-09-30 09:02:15 +02:00
Jean-Pierre André
94f8d2128e Fixed a wrong test report in ntfsfix
When used with the "no-action" option, the test for self-located MFT
still reported the partition to have been repaired. Adapt the report to
only tell repairing is possible.
2015-09-30 08:54:27 +02:00
Jean-Pierre André
4a4ec8c1c6 Fixed a bad sanity check in ntfsfix
Fix misordered checks to avoid potential segfaults on badly damaged partitions.
2015-09-30 08:51:20 +02:00
Jean-Pierre André
267357899f Made secaudit to load the library based on its generic name
When compiled autonomously without the automatically generated dynamic
link stubs, use a generic library name instead of a version dependent one.
(obsolete compile mode rarely used).
2015-09-30 08:44:56 +02:00
Jean-Pierre André
9c2657b4ae Made use of fuse module cache on OpenIndiana
The fuse cache does not handle properly hard-linked files, so ntfs-3g
traditionally disables it by using a null time-out. With an upgrade of
the fuse kernel module on OpenIndiana, cacheing of non hard-linked files
is now possible, so use it.
2015-09-30 08:36:37 +02:00
Jean-Pierre André
5ebe36f10a Mentioned the starting sector when it overflows in mkntfs
In an NTFS boot sector, the first sector of the partition is limited to
32 bits and it may overflow on large disks. This field is only used for
booting on the partition and it is ignored by ntfs-3g, but the warning
in mkntfs mislead users, so improve it.
2015-09-30 08:25:25 +02:00
Jean-Pierre André
8a3c3c477c Used incremental offsets when reading a directory in lowntfs-3g
Using incremental offsets avoids misinterpreting readdir() as rewinddir().
It also makes possible to implement seekdir() [not done yet]
2015-09-30 08:18:13 +02:00
Jean-Pierre André
2c11aaa2aa Fixed the range of valid subauthority counts in a SID
ntfs_valid_sid() required that the subauthority count be between 1 and 8
inclusively.  However, Windows permits more than 8 subauthorities as well
as 0 subauthorities:

  - The install.wim file for the latest Windows 10 build contains a file
    whose DACL contains a SID with 10 subauthorities.
    ntfs_set_ntfs_acl() was failing on this file.

  - The IsValidSid() function on Windows returns true for subauthority
    less than or equal to 15, including 0.

There was actually already a another SID validation function that had the
Windows-compatible behavior, so I merged the two together.

Contributed by Eric Biggers
2015-07-14 08:37:01 +02:00