OSDN Git Service

android-x86/external-ntfs-3g.git
8 years agoFixed segmentation fault on empty $LogFile in ntfsrecover
Jean-Pierre André [Wed, 4 May 2016 07:24:51 +0000 (09:24 +0200)]
Fixed segmentation fault on empty $LogFile in ntfsrecover

ntfsrecover -f -v <log file> receives a SIGSEGV because of trying to
read memory outside allocated buffer because of no sanity checks on
restart page header values. This happens on an empty $LogFile because
of no basic checks present. Attached patch adds basic checks similar
to those inside logfile library and allows tool to exit with more
suitable message.
(contributed by Rakesh Pandit)

8 years agoFixed a missing "break" in ntfssecaudit.c
Jean-Pierre André [Wed, 4 May 2016 07:19:39 +0000 (09:19 +0200)]
Fixed a missing "break" in ntfssecaudit.c

A missing "break" in a case construct could be troublesome.
(suggested by Ulf Zibis)

8 years agoFixed indentation in ntfssecaudit.c (cosmetic)
Jean-Pierre André [Wed, 4 May 2016 07:15:43 +0000 (09:15 +0200)]
Fixed indentation in ntfssecaudit.c (cosmetic)

There was an abusive indentation.

8 years agounistr.c: Unify the two defines NOREVBOM and ALLOW_BROKEN_SURROGATES.
Erik Larsson [Tue, 12 Apr 2016 15:02:40 +0000 (17:02 +0200)]
unistr.c: Unify the two defines NOREVBOM and ALLOW_BROKEN_SURROGATES.

In the mailing list discussion we came to the conclusion that there
doesn't seem to be any reason to keep these declarations separate since
they address the same issue, namely libntfs-3g's tolerance for bad
Unicode data in filenames and other UTF-16 strings in the file system,
so merge the two defines into the new define ALLOW_BROKEN_UNICODE.

8 years agounistr.c: Enable encoding broken UTF-16 into broken UTF-8, A.K.A. WTF-8.
Erik Larsson [Fri, 8 Apr 2016 03:39:48 +0000 (05:39 +0200)]
unistr.c: Enable encoding broken UTF-16 into broken UTF-8, A.K.A. WTF-8.

Windows filenames may contain invalid UTF-16 sequences (specifically
broken surrogate pairs), which cannot be converted to UTF-8 if we do
strict conversion.

This patch enables encoding broken UTF-16 into similarly broken UTF-8 by
encoding any surrogate character that don't have a match into a separate
3-byte UTF-8 sequence.

This is "sort of" valid UTF-8, but not valid Unicode since the code
points used for surrogate pair encoding are not supposed to occur in a
valid Unicode string... but on the other hand the source UTF-16 data is
also broken, so we aren't really making things any worse.

This format is sometimes referred to as WTF-8 (Wobbly Translation
Format, 8-bit encoding) and is a common solution to represent broken
UTF-16 as UTF-8.

It is a lossless round-trip conversion, i.e converting from broken
UTF-16 to "WTF-8" and back to UTF-16 yields the same broken UTF-16
sequence. Because of this property it enables accessing these files
by filename through ntfs-3g and the ntfsprogs (e.g. ls -la works as
expected).

To disable this behaviour you can pass the preprocessor/compiler flag
'-DALLOW_BROKEN_SURROGATES=0' when building ntfs-3g.

8 years agoDeleted file secaudit.h
Jean-Pierre André [Thu, 7 Apr 2016 07:36:01 +0000 (09:36 +0200)]
Deleted file secaudit.h

The declarations for compiling secaudit on Windows are not used any more
and can be dropped.

8 years agoRemoved declarations for using acls.c outside ntfs-3g
Jean-Pierre André [Thu, 7 Apr 2016 07:32:26 +0000 (09:32 +0200)]
Removed declarations for using acls.c outside ntfs-3g

The declarations for using acls.c within secaudit on Windows are not used
any more and can be dropped.

8 years agoAdapted secaudit and usermap (now ntfssecaudit and ntfsusermap) to ntfsprogs
Jean-Pierre André [Thu, 7 Apr 2016 07:20:23 +0000 (09:20 +0200)]
Adapted secaudit and usermap (now ntfssecaudit and ntfsusermap) to ntfsprogs

These tools were originally developed for running on Windows and later
ported to libntfs-3g. This patch makes them similar to other ntfsprogs
tools, dropping the native Windows interfaces and using libntfs-3g on
all platforms.

There is no change in usage or supported features, only the command
names have changed.

8 years agoMoved secaudit and usermap to directory ntfsprogs
Jean-Pierre André [Thu, 7 Apr 2016 07:07:13 +0000 (09:07 +0200)]
Moved secaudit and usermap to directory ntfsprogs

These tools were developped before the ntfsprogs were merged into ntfs-3g,
redesigning them like the ntfsprogs make the code simpler.

Note : at this stage secaudit and usermap cannot be built any more.

8 years agoFixed indentation in ntfsclone help text (cosmetic)
Jean-Pierre André [Wed, 6 Apr 2016 09:09:35 +0000 (11:09 +0200)]
Fixed indentation in ntfsclone help text (cosmetic)

The tabs in source code appear differently in actual output.

8 years agoFixed a spelling error in ntfsresize manual (cosmetic)
Jean-Pierre André [Wed, 6 Apr 2016 09:07:30 +0000 (11:07 +0200)]
Fixed a spelling error in ntfsresize manual (cosmetic)

an other -> another

8 years agoMoved general declarations from ntfsrecover.h to logfile.h
Jean-Pierre André [Wed, 6 Apr 2016 09:03:31 +0000 (11:03 +0200)]
Moved general declarations from ntfsrecover.h to logfile.h

The declarations related to the log file structure are now grouped
in logfile.h, those specific to the recovery process are kept in
ntfsrecover.h

8 years agoAdded a usn field to RESTART_PAGE_HEADER
Jean-Pierre André [Wed, 6 Apr 2016 08:58:25 +0000 (10:58 +0200)]
Added a usn field to RESTART_PAGE_HEADER

Prepare merging ntfsrecover.h into logfile.h by adding a usn field to
RESTART_PAGE_HEADER. As this changes the record size, ignore the new
field in existing code.

8 years agoRenamed reserved fields in ntfsrecover the same way as in logfile.h
Jean-Pierre André [Wed, 6 Apr 2016 08:54:51 +0000 (10:54 +0200)]
Renamed reserved fields in ntfsrecover the same way as in logfile.h

Prepare merging ntfsrecover.h into logfile.h by naming reserved fields
the same way.

8 years agoRenamed record_length as log_record_header_length in ntfsrecover.h
Jean-Pierre André [Wed, 6 Apr 2016 08:52:18 +0000 (10:52 +0200)]
Renamed record_length as log_record_header_length in ntfsrecover.h

Prepare merging ntfsrecover.h into logfile.h by naming the record
header length the same way.

8 years agoRenamed restart_offset as restart_area_offset in ntfsrecover.h
Jean-Pierre André [Wed, 6 Apr 2016 08:50:31 +0000 (10:50 +0200)]
Renamed restart_offset as restart_area_offset in ntfsrecover.h

Prepare merging ntfsrecover.h into logfile.h by renaming the restart
offset the same way.

8 years agoRedefined target_vcn on 64 bits in ntfsrecover.h
Jean-Pierre André [Wed, 6 Apr 2016 08:45:30 +0000 (10:45 +0200)]
Redefined target_vcn on 64 bits in ntfsrecover.h

In a log record, the target vcn has to be stored on 64 bits

8 years agoRedefined file_offset on 64 bits in ntfsrecover.h
Jean-Pierre André [Wed, 6 Apr 2016 08:40:28 +0000 (10:40 +0200)]
Redefined file_offset on 64 bits in ntfsrecover.h

The log file offsets are apparently stored on 64 bits, though the file
size is unlikely to reach 2MB.

8 years agoUnfolded record headers in ntfsrecover the same way as in logfile.h
Jean-Pierre André [Wed, 6 Apr 2016 08:38:06 +0000 (10:38 +0200)]
Unfolded record headers in ntfsrecover the same way as in logfile.h

Prepare merging ntfsrecover.h into logfile.h by unfolding the record
headers the same way.

8 years agoTypedef'ed new structs in ntfsrecover the same way as in logfile.h
Jean-Pierre André [Wed, 6 Apr 2016 08:34:46 +0000 (10:34 +0200)]
Typedef'ed new structs in ntfsrecover the same way as in logfile.h

Prepare merging ntfsrecover.h into logfile.h by declaring new structs
the same was as in logfile.h

8 years agoTypedef'ed old structs in ntfsrecover the same way as in logfile.h
Jean-Pierre André [Wed, 6 Apr 2016 08:32:39 +0000 (10:32 +0200)]
Typedef'ed old structs in ntfsrecover the same way as in logfile.h

Prepare merging ntfsrecover.h into logfile.h by declaring duplicated
structs the same way

8 years agoRedefined ntfsrecover enums as little-endian values
Jean-Pierre André [Wed, 6 Apr 2016 08:26:46 +0000 (10:26 +0200)]
Redefined ntfsrecover enums as little-endian values

Rather than cpu-endian values, use little-endian ones in ntfsrecover
for similarity with layout.h

8 years agoMade a full check for whether a user extended attribute is allowed
Jean-Pierre André [Wed, 6 Apr 2016 08:17:27 +0000 (10:17 +0200)]
Made a full check for whether a user extended attribute is allowed

User extended attributes should only be set on files and directories,
not on symlinks, sockets, devices, etc. For safety they are also
forbidden on metadata files, but should be allowed on the root
directory. For files based on reparse points, requests are made
to the plugin to determine the type.

8 years agoTranslated directory separators when running ntfscluster on Windows
Jean-Pierre André [Wed, 6 Apr 2016 08:11:08 +0000 (10:11 +0200)]
Translated directory separators when running ntfscluster on Windows

Use \ as a directory separator when running on Windows.

8 years agoReturned an error code for an exclusive access violation on Windows
Jean-Pierre André [Wed, 6 Apr 2016 08:08:01 +0000 (10:08 +0200)]
Returned an error code for an exclusive access violation on Windows

Translate to Windows error code STATUS_SHARING_VIOLATION to Unix error
code EBUSY.

8 years agoFixed the maximum size of an ACL
Jean-Pierre André [Wed, 6 Apr 2016 08:02:23 +0000 (10:02 +0200)]
Fixed the maximum size of an ACL

Define the maximum size of an ACL as results from the maximum number of
sub-authorities defined in layout.h

8 years agoUsed a more portable way to force alignment in security.h
Jean-Pierre André [Wed, 6 Apr 2016 07:57:59 +0000 (09:57 +0200)]
Used a more portable way to force alignment in security.h

Defining an array of zero elements does not force alignment on some CPUs,
insert a filler.

8 years agoEnabled fallback to read-only mount when volume is hibernated
Jean-Pierre André [Wed, 6 Apr 2016 07:51:47 +0000 (09:51 +0200)]
Enabled fallback to read-only mount when volume is hibernated

When a volume is found hibernated (or prepared for fast restarting),
it is force-mounted as read-only.

8 years agoAllowed kernel cacheing by lowntfs-3g when not using Posix ACLs
Jean-Pierre André [Wed, 6 Apr 2016 07:44:59 +0000 (09:44 +0200)]
Allowed kernel cacheing by lowntfs-3g when not using Posix ACLs

Kernel cacheing of file attributes is usually not used by ntfs-3g,
because it has defects when dealing with hard linked files and directory
permission checks. Kernel cacheing is however possible when using
lowntfs-3g and not using Posix ACLs.

8 years agoFixed bad test in fuse mount
Jean-Pierre André [Wed, 6 Apr 2016 07:42:16 +0000 (09:42 +0200)]
Fixed bad test in fuse mount

Apply a fix from the full fuse library

8 years agoSilenced fixup warnings when allocating a new MFT record
Jean-Pierre André [Wed, 6 Apr 2016 07:32:18 +0000 (09:32 +0200)]
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.

8 years agoAdded clarification about creating a partition to the ntfsclone manual
Jean-Pierre André [Wed, 6 Apr 2016 07:27:07 +0000 (09:27 +0200)]
Added clarification about creating a partition to the ntfsclone manual

Try to make clear the option --output feeds data into a partition, but
does not create the partition.

8 years agoUsed plugins to process reparse points
Jean-Pierre André [Wed, 6 Apr 2016 07:10:35 +0000 (09:10 +0200)]
Used plugins to process reparse points

The new "system compression" files used by Windows 10 make use of reparse
points to record the compression parameters, and a specific named data
stream is used to store the compressed data. With this patch, processing
of reparse points can be done by an external plugin only loaded as needed.
Junctions and symlinks, which are also based on reparse points, are now
processed by "internal plugins".

8 years agoAdded an option for preserving the full log file in ntfsclone
Jean-Pierre André [Wed, 6 Apr 2016 06:51:36 +0000 (08:51 +0200)]
Added an option for preserving the full log file in ntfsclone

Usually, only a few pages of the Windows log file are saved in an
ntfsclone image. This is inappropriate for building reference images
for recovering the log, and the --full-logfile option serves that
purpose.

8 years agoReworked decisions to undo related to unreadable records
Jean-Pierre André [Wed, 6 Apr 2016 06:44:38 +0000 (08:44 +0200)]
Reworked decisions to undo related to unreadable records

When an INDX or MFT record could not be read while undoing the creation
of this record, there is nothing to do. However if this was undoing the
deletion of the last entry in an index, a new void index block has to be
created.

8 years agoVersion 2016.2.22
Jean-Pierre André [Mon, 22 Feb 2016 07:28:50 +0000 (08:28 +0100)]
Version 2016.2.22

8 years agoFix compilation errors on OpenIndiana caused by missing limit macros.
Erik Larsson [Tue, 16 Feb 2016 19:43:00 +0000 (20:43 +0100)]
Fix compilation errors on OpenIndiana caused by missing limit macros.

8 years agoendians.h: Fix bad assumption of valid __BYTE_ORDER__ values.
Erik Larsson [Tue, 16 Feb 2016 19:29:56 +0000 (20:29 +0100)]
endians.h: Fix bad assumption of valid __BYTE_ORDER__ values.

On the OpenIndiana Hipster distribution, compiling with GCC 4.9 would
fail because __BYTE_ORDER__ was defined but not to any of the values
assumed to be associated with this define (__LITTLE_ENDIAN__ or
__BIG_ENDIAN__). Instead it was defined to either
__ORDER_LITTLE_ENDIAN__ or __ORDER_BIG_ENDIAN__. This caused
compilation to fail.

Fixed by checking that all referenced defines are in fact defined
before using them and adding an additional #elif clause for this newly
discovered condition.

8 years agontfsrecover.c: Fix compiler warning about uninitialized 'savebuf' usage.
Erik Larsson [Tue, 16 Feb 2016 08:38:12 +0000 (09:38 +0100)]
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'.

8 years agoFix compiler warnings about mismatching printf format / argument type.
Erik Larsson [Tue, 16 Feb 2016 08:30:49 +0000 (09:30 +0100)]
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.

8 years agoVersion 2016.2.15
Jean-Pierre André [Mon, 15 Feb 2016 15:32:03 +0000 (16:32 +0100)]
Version 2016.2.15

8 years agoSilenced a compiler warning for possibly uninitialized pointer
Jean-Pierre André [Mon, 15 Feb 2016 11:07:28 +0000 (12:07 +0100)]
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.

8 years agoSilenced a compiler warning for different types
Jean-Pierre André [Mon, 15 Feb 2016 11:02:10 +0000 (12:02 +0100)]
Silenced a compiler warning for different types

Some compilers issue a warning when the alternatives in a "? :"
expression have different signedness.

8 years agoAvoided pointer cast when checking record types
Jean-Pierre André [Mon, 15 Feb 2016 10:54:33 +0000 (11:54 +0100)]
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.

8 years agoUpdated the drivers copyrights
Jean-Pierre André [Fri, 12 Feb 2016 16:24:27 +0000 (17:24 +0100)]
Updated the drivers copyrights

Extend the copyright to 2016

8 years agoClosed the volume when a resizing is done
Jean-Pierre André [Fri, 12 Feb 2016 16:13:21 +0000 (17:13 +0100)]
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.

8 years agoClosed the bad sector inode after updating the list
Jean-Pierre André [Fri, 12 Feb 2016 16:03:53 +0000 (17:03 +0100)]
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.

8 years agoendians.h: Cast the result of const endianness macros to the right type.
Erik Larsson [Thu, 11 Feb 2016 13:19:41 +0000 (14:19 +0100)]
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.

8 years agontfs-3g_common.h: Fix improper type for 'dmtime' in ntfs_fuse_context_t.
Erik Larsson [Thu, 11 Feb 2016 13:06:53 +0000 (14:06 +0100)]
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.

8 years agomft.c: Fix compiler warning about mismatching format/argument type.
Erik Larsson [Thu, 11 Feb 2016 12:52:59 +0000 (13:52 +0100)]
mft.c: Fix compiler warning about mismatching format/argument type.

The expression is promoted to 'int' implicitly so we explicitly cast it
to 'u8'.

8 years agoefs.c: Fix incorrect type of local variables 'newsize' and 'oldsize'.
Erik Larsson [Mon, 8 Feb 2016 17:42:53 +0000 (18:42 +0100)]
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.

8 years agontfslabel.c: Fix incorrect label buffer being NULL-terminated.
Erik Larsson [Mon, 8 Feb 2016 17:32:24 +0000 (18:32 +0100)]
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.

8 years agoChange type of all LSN struct members in ntfsrecover.h to leLSN.
Erik Larsson [Fri, 29 Jan 2016 11:36:06 +0000 (12:36 +0100)]
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.

8 years agoplaylog.c: Use const macro for byteswapping const expression.
Erik Larsson [Fri, 29 Jan 2016 09:49:52 +0000 (10:49 +0100)]
playlog.c: Use const macro for byteswapping const expression.

8 years agoplaylog.c: Fix improper byteswapping macros used for sle64 members.
Erik Larsson [Fri, 29 Jan 2016 09:49:25 +0000 (10:49 +0100)]
playlog.c: Fix improper byteswapping macros used for sle64 members.

8 years agoMerge endianness fixes.
Erik Larsson [Thu, 28 Jan 2016 08:22:42 +0000 (09:22 +0100)]
Merge endianness fixes.

Conflicts:
libntfs-3g/attrib.c

8 years agontfscmp.c: Fix missing byteswap of little-endian attribute type value.
Erik Larsson [Thu, 28 Jan 2016 08:11:55 +0000 (09:11 +0100)]
ntfscmp.c: Fix missing byteswap of little-endian attribute type value.

8 years agontfsmove.c: Fix multiple cases of raw usage of little-endian fields.
Erik Larsson [Wed, 27 Jan 2016 14:28:55 +0000 (15:28 +0100)]
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.

8 years agontfsdump_logfile.c: Fix use of wrong byteswapping macro for le16 field.
Erik Larsson [Wed, 27 Jan 2016 14:26:51 +0000 (15:26 +0100)]
ntfsdump_logfile.c: Fix use of wrong byteswapping macro for le16 field.

8 years agontfsdump_logfile.c: Fix incorrectly parenthesized expression.
Erik Larsson [Wed, 27 Jan 2016 14:24:52 +0000 (15:24 +0100)]
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).

8 years agontfsck.c: Fix comparing le32 values as u32.
Erik Larsson [Wed, 27 Jan 2016 14:23:13 +0000 (15:23 +0100)]
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.

8 years agontfsck.c: Fix comparison between little-endian and native-endian data.
Erik Larsson [Wed, 27 Jan 2016 14:21:05 +0000 (15:21 +0100)]
ntfsck.c: Fix comparison between little-endian and native-endian data.

This comparison would yield the wrong result on big-endian systems.

8 years agontfstruncate.c: Fix mixed endianness usage of variable 'i'.
Erik Larsson [Tue, 26 Jan 2016 09:28:38 +0000 (10:28 +0100)]
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.

8 years agontfstruncate.c: Fix incorrect type for CPU-endian value in 'ucstos'.
Erik Larsson [Tue, 26 Jan 2016 09:19:44 +0000 (10:19 +0100)]
ntfstruncate.c: Fix incorrect type for CPU-endian value in 'ucstos'.

8 years agontfstruncate.c: Fix conflicting endianness for variable 'attr_type'.
Erik Larsson [Tue, 26 Jan 2016 09:18:51 +0000 (10:18 +0100)]
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.

8 years agontfstruncate.c: Fix mixed endianness usage of variable 'u'.
Erik Larsson [Tue, 26 Jan 2016 09:03:36 +0000 (10:03 +0100)]
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'.

8 years agontfs-3g.c: Fix raw usage of inode time fields without byteswapping.
Erik Larsson [Tue, 26 Jan 2016 06:55:45 +0000 (07:55 +0100)]
ntfs-3g.c: Fix raw usage of inode time fields without byteswapping.

8 years agovolume.c: Fix passing bad pointer type to ntfs_is_[baad|mft]_recordp.
Erik Larsson [Mon, 25 Jan 2016 10:31:12 +0000 (11:31 +0100)]
volume.c: Fix passing bad pointer type to ntfs_is_[baad|mft]_recordp.

8 years agomst.c: Fix mixed native/little-endian usage of variable 'usn'.
Erik Larsson [Mon, 25 Jan 2016 10:30:13 +0000 (11:30 +0100)]
mst.c: Fix mixed native/little-endian usage of variable 'usn'.

8 years agoreparse.c: Fix big-endian bug when converting file name to lowercase.
Erik Larsson [Mon, 4 Jan 2016 09:19:05 +0000 (10:19 +0100)]
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.

8 years agoFix inverted usage of endian conversion macros.
Erik Larsson [Mon, 4 Jan 2016 09:08:15 +0000 (10:08 +0100)]
Fix inverted usage of endian conversion macros.

This is mostly a semantic issue since the end result would be the same.

8 years agoFix incorrect usage of native/little-endian types, signed types, etc.
Erik Larsson [Mon, 21 Dec 2015 22:55:31 +0000 (23:55 +0100)]
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.

8 years agoFix endianness issues in log and terminal output.
Erik Larsson [Mon, 21 Dec 2015 22:31:09 +0000 (23:31 +0100)]
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.

8 years agoFix code to use const_cpu_to_X/const_X_to_cpu macros for constants.
Erik Larsson [Mon, 21 Dec 2015 22:21:00 +0000 (23:21 +0100)]
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.

8 years agoendians.h: Add const endian conversion macros for s{l,b}e{16,32,64}.
Erik Larsson [Mon, 21 Dec 2015 22:05:36 +0000 (23:05 +0100)]
endians.h: Add const endian conversion macros for s{l,b}e{16,32,64}.

8 years agoFixed accessing next log buffer only when it exists
Jean-Pierre André [Tue, 1 Dec 2015 10:12:53 +0000 (11:12 +0100)]
Fixed accessing next log buffer only when it exists

Do not locate the next log buffer until it is known to exist.

8 years agoFixed reporting action states when restart page appears outdated
Jean-Pierre André [Tue, 1 Dec 2015 10:10:48 +0000 (11:10 +0100)]
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)

8 years agoRejected invalid null reparse tag
Jean-Pierre André [Tue, 1 Dec 2015 10:06:11 +0000 (11:06 +0100)]
Rejected invalid null reparse tag

The null reparse tag is considered invalid by Windows, so do the same.

8 years agoFixed returning the trimming count to fstrim(8)
Jean-Pierre André [Tue, 1 Dec 2015 10:00:24 +0000 (11:00 +0100)]
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.

8 years agoDefined reparse tag for system compression
Jean-Pierre André [Tue, 1 Dec 2015 09:56:01 +0000 (10:56 +0100)]
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.

8 years agoFixed special case of decompressing a runlist
Jean-Pierre André [Fri, 20 Nov 2015 15:17:48 +0000 (16:17 +0100)]
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)

8 years agoFixed headers of log play functions in playlog
Jean-Pierre André [Fri, 20 Nov 2015 15:14:16 +0000 (16:14 +0100)]
Fixed headers of log play functions in playlog

The functions were made static with a textual description.

8 years agoFixed missing error return in playlog
Jean-Pierre André [Fri, 20 Nov 2015 15:11:15 +0000 (16:11 +0100)]
Fixed missing error return in playlog

No error was returned from reading a protected record which is part of
an unreadable raw cluster.

8 years agoFixed truncating an extended bad cluster list in ntfsresize
Jean-Pierre André [Fri, 20 Nov 2015 15:04:47 +0000 (16:04 +0100)]
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.

8 years agoRemoved obsolete code from playlog
Jean-Pierre André [Thu, 12 Nov 2015 14:46:33 +0000 (15:46 +0100)]
Removed obsolete code from playlog

The code for dealing with new MFT records had been made more general

8 years agoSubdivided the replay functions in playlog
Jean-Pierre André [Thu, 12 Nov 2015 14:44:47 +0000 (15:44 +0100)]
Subdivided the replay functions in playlog

Partially unnested play_redos() and play_undos()

8 years agoFixed a memory leak in ntfsrecover
Jean-Pierre André [Thu, 12 Nov 2015 14:41:44 +0000 (15:41 +0100)]
Fixed a memory leak in ntfsrecover

A buffer was left leaking memory in reset_logfile()

8 years agoSilenced a compiler warning (cosmetic)
Jean-Pierre André [Thu, 12 Nov 2015 14:39:20 +0000 (15:39 +0100)]
Silenced a compiler warning (cosmetic)

An argument to ntfs_index_remove() is now unused

8 years agoDefined the last logfile block as preceding block 4 in ntfsrecover
Jean-Pierre André [Thu, 12 Nov 2015 14:31:24 +0000 (15:31 +0100)]
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.

8 years agoAlleviated constraints relative to reparse points
Jean-Pierre André [Mon, 9 Nov 2015 15:22:16 +0000 (16:22 +0100)]
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.

8 years agoDecoded the full list of bad clusters in ntfsclone and ntfsresize
Jean-Pierre André [Mon, 9 Nov 2015 15:16:39 +0000 (16:16 +0100)]
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.

8 years agoFixed reparse data check for non-Microsoft tags
Jean-Pierre André [Mon, 9 Nov 2015 15:14:31 +0000 (16:14 +0100)]
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)

8 years agoFixed getting space for making an index non resident
Jean-Pierre André [Mon, 9 Nov 2015 15:09:52 +0000 (16:09 +0100)]
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.

8 years agoWrote as much data as possible in compressed attribute pwrite
Jean-Pierre André [Mon, 9 Nov 2015 15:00:31 +0000 (16:00 +0100)]
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.

8 years agoSilenced a compiler warning in ntfswipe (cosmetic)
Jean-Pierre André [Mon, 9 Nov 2015 14:58:00 +0000 (15:58 +0100)]
Silenced a compiler warning in ntfswipe (cosmetic)

Avoid a signed-to-unsigned compare warning

8 years agoFixed relocating the MFT runlists in ntfsresize
Jean-Pierre André [Mon, 9 Nov 2015 14:44:33 +0000 (15:44 +0100)]
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.

8 years agoImplemented recovery of updates committed by Windows
Jean-Pierre André [Mon, 9 Nov 2015 12:18:58 +0000 (13:18 +0100)]
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.

8 years agoUse appropriate little-endian/big-endian types in struct definitions.
Erik Larsson [Sat, 3 Oct 2015 10:58:08 +0000 (12:58 +0200)]
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.

8 years agoProtected against opendir reinitialization in lownfs-3g
Jean-Pierre André [Wed, 30 Sep 2015 07:35:17 +0000 (09:35 +0200)]
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().

8 years agontfsprogs Builds on Windows use macroes to translate printing formats,
Jean-Pierre André [Wed, 30 Sep 2015 07:08:35 +0000 (09:08 +0200)]
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.