Commit Graph

5178 Commits (0038d946bead4b9d3e7c2cb0d4e20bb44e06ee97)
 

Author SHA1 Message Date
CodingKoopa 0038d946be win32_io.c: fix variable name + comment
This fixes a compiler error only manifesting in debug mode.
2024-03-08 19:08:39 -05:00
CodingKoopa 1a3def37c5 win32_io.c: fix variable name
This fixes a compiler error only manifesting in debug mode.
2024-03-08 19:07:49 -05:00
CodingKoopa 11543cd632 readme: add windows instructions 2024-03-08 18:53:56 -05:00
CodingKoopa e2f2bfbe78 ntfsclone.c: use setmode from header
Fixes linker error:

/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: ntfsclone.o: in function `open_image':
/cygdrive/e/Documents/Programs/ntfs-3g/ntfsprogs/ntfsclone.c:2385:(.text.startup+0x34e): undefined reference to `setmode'
2024-03-08 04:20:02 -05:00
CodingKoopa 69c2377280 ntfsusermap.c: provide mode with mkdir
The desired mkdir does not seem to exist on Cygwin.

Fixes compiler error:

ntfsusermap.c: In function ‘outputmap’:
ntfsusermap.c:817:25: error: too few arguments to function ‘mkdir’
  817 |                         mkdir(fullname);
      |                         ^~~~~
In file included from /usr/include/sys/_default_fcntl.h:212,
                 from /usr/include/sys/fcntl.h:3,
                 from /usr/include/fcntl.h:13,
                 from ntfsusermap.c:113:
/usr/include/sys/stat.h:140:9: note: declared here
  140 | int     mkdir (const char *_path, mode_t __mode );
      |         ^~~~~
2024-03-08 06:37:05 +00:00
CodingKoopa 9e0b9ec23a ntfsprogs: provide WINAPI definition
Copied from a header in the public domain.

Fixes compiler error:

ntfsusermap.c:149:13: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘LookupAccountNameA’
  149 | BOOL WINAPI LookupAccountNameA(const char*, const char*, void*,
      |             ^~~~~~~~~~~~~~~~~~
ntfsusermap.c:151:13: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘GetUserNameA’
  151 | BOOL WINAPI GetUserNameA(char*, u32*);
      |             ^~~~~~~~~~~~
2024-03-08 06:31:19 +00:00
CodingKoopa f196023841 utils.h: remove compat macros
It might be worth figuring out a more proper fix than this.

Fixes compiler error:

In file included from ntfswipe.c:63:
ntfswipe.c: In function ‘version’:
utils.h:113:58: error: expected expression before ‘)’ token
  113 |                 ntfs_utils_reformat(_b,MAX_FMT,fmt), args); } while (0)
      |                                                          ^
../include/ntfs-3g/logging.h:95:40: note: in expansion of macro ‘ntfs_log_redirect’
   95 | #define ntfs_log_info(FORMAT, ARGS...) ntfs_log_redirect(__FUNCTION__,__FILE__,__LINE__,NTFS_LOG_LEVEL_INFO,NULL,FORMAT,##ARGS)
      |                                        ^~~~~~~~~~~~~~~~~
2024-03-08 06:25:49 +00:00
CodingKoopa d43ede9b7d libntfs-3g: link to ntdll.dll on Windows
win32_io.c uses some symbols from this DLL.

Fixes linker error (among others):

/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: .libs/libntfs_3g_la-win32_io.o: in function `ntfs_device_win32_pio':
/cygdrive/e/Documents/Programs/ntfs-3g/libntfs-3g/win32_io.c:1386:(.text+0x274): undefined reference to `NtWriteFile'
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /cygdrive/e/Documents/Programs/ntfs-3g/libntfs-3g/win32_io.c:1391:(.text+0x348): undefined reference to `NtReadFile'
2024-03-08 06:23:21 +00:00
CodingKoopa 6261aa3c0c win32_io.c: switch to _get_osfhandle from get_osfhandle
_get_osfhandle is what is documented. The alternative might have been removed.

Fixes linker error:

/cygdrive/e/Documents/Programs/ntfs-3g/libntfs-3g/win32_io.c:1990:(.text+0x21a5): undefined reference to `get_osfhandle'
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: .libs/libntfs_3g_la-win32_io.o: in function `ntfs_win32_ftruncate':
/cygdrive/e/Documents/Programs/ntfs-3g/libntfs-3g/win32_io.c:2054:(.text+0x223a): undefined reference to `get_osfhandle'
2024-03-08 06:18:29 +00:00
CodingKoopa 64f3464378 device_io.h: forward declare ntfs_device struct.
Fixes compiler error:

win32_io.c:2037:5: error: conflicting types for 'ntfs_device_win32_ftruncate'; have 'int(struct ntfs_device *, s64)' {aka 'int(struct ntfs_device *, long int)'}
 2037 | int ntfs_device_win32_ftruncate(struct ntfs_device *dev, s64 size)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../include/ntfs-3g/device.h:30,
                 from win32_io.c:77:
../include/ntfs-3g/device_io.h:75:5: note: previous declaration of 'ntfs_device_win32_ftruncate' with type 'int(struct ntfs_device *, s64)' {aka 'int(struct ntfs_device *, long int)'}
   75 | int ntfs_device_win32_ftruncate(struct ntfs_device*, s64);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
2024-03-08 06:13:18 +00:00
CodingKoopa ecfe5e1af3 win32_io.c: use stat on Cygwin
Fixes compiler error (among others):

win32_io.c: In function 'ntfs_device_win32_stat':
win32_io.c:1804:31: error: invalid application of 'sizeof' to incomplete type 'struct stat64'
 1804 |         memset(buf, 0, sizeof(struct stat));
      |                               ^~~~~~
2024-03-08 06:09:12 +00:00
CodingKoopa 7d1c1ad3ca win32_io.c: make NTSTATUS signed
bcrypt.h defines this as a long, which causes a conflict. On LLP64, long and
u32 are the same size, but have different signedness. Signed seems to be
the prevailing view of the type.

Fixes compiler error:

win32_io.c:174:13: error: conflicting types for 'NTSTATUS'; have 'u32' {aka 'unsigned int'}
  174 | typedef u32 NTSTATUS; /* do not let the compiler choose the size */
      |             ^~~~~~~~
In file included from /usr/include/w32api/wincrypt.h:846,
                 from /usr/include/w32api/windows.h:95,
                 from win32_io.c:31:
/usr/include/w32api/bcrypt.h:27:16: note: previous declaration of 'NTSTATUS' with type 'NTSTATUS' {aka 'int'}
   27 |   typedef LONG NTSTATUS,*PNTSTATUS;
      |                ^~~~~~~~
2024-03-08 06:07:04 +00:00
CodingKoopa 22dac966ba win32_io.c: undefine all enum constants
Some of the STATUS enum constants conflict with those from winnt.h.
This change undefines all of them to be safe.

Fixes compiler error:

In file included from /usr/include/w32api/minwindef.h:163,
                 from /usr/include/w32api/windef.h:9,
                 from /usr/include/w32api/windows.h:69,
                 from win32_io.c:31:
win32_io.c:132:4: error: expected identifier before '(' token
  132 |    STATUS_INVALID_HANDLE =       0xC0000008,
      |    ^~~~~~~~~~~~~~~~~~~~~
2024-03-08 05:59:20 +00:00
CodingKoopa 9038bb8dca win32_io.c: use different BOOL workaround
Fixes compiler error:

In file included from ../include/ntfs-3g/logging.h:34,
                 from ../include/ntfs-3g/debug.h:29,
                 from win32_io.c:73:
../include/ntfs-3g/types.h:114:3: error: conflicting types for 'BOOL'; have 'enum <anonymous>'
  114 | } BOOL;
      |   ^~~~
In file included from /usr/include/w32api/windef.h:9,
                 from /usr/include/w32api/windows.h:69,
                 from win32_io.c:31:
/usr/include/w32api/minwindef.h:131:15: note: previous declaration of 'BOOL' with type 'BOOL' {aka 'int'}
  131 |   typedef int BOOL;
      |               ^~~~

This leverages the fact that, in minwindef.h, the definition is guarded like so:

#if !defined(__OBJC__) && !defined(__OBJC_BOOL) && !defined(__objc_INCLUDE_GNU) && !defined(_NO_BOOL_TYPEDEF)
  typedef int BOOL;
#endif
2024-03-08 05:52:33 +00:00
CodingKoopa 13d341356b win32_io.c: rm GUID type definition
This conflicts with the GUID defined in the Windows headers, and we don't seem to use this one.

Fixes compiler error (could also be fixed by redefining Windows' GUID):

win32_io.c:55:3: error: conflicting types for 'GUID'; have 'struct <anonymous>'
   55 | } GUID;
      |   ^~~~
In file included from /usr/include/w32api/winnt.h:648,
                 from /usr/include/w32api/minwindef.h:163,
                 from /usr/include/w32api/windef.h:9,
                 from /usr/include/w32api/windows.h:69,
                 from win32_io.c:31:
/usr/include/w32api/guiddef.h:24:3: note: previous declaration of 'GUID' with type 'GUID'
   24 | } GUID;
      |   ^~~~
2024-03-08 05:43:51 +00:00
Dave Murphy fcd27ddb2d
remove bogus __timespec_defined 2024-02-24 09:39:29 +00:00
Dave Murphy ba086d6f1a
guard syslog.h 2024-02-24 09:39:28 +00:00
Erik Larsson 75dcdc2cf3 unistr.c: Fix use-after-free in 'ntfs_uppercase_mbs'.
If 'utf8_to_unicode' throws an error due to an invalid UTF-8 sequence,
then 'n' will be less than 0 and the loop will terminate without storing
anything in '*t'. After the loop the uppercase string's allocation is
freed, however after it is freed it is unconditionally accessed through
'*t', which points into the freed allocation, for the purpose of NULL-
terminating the string. This leads to a use-after-free.
Fixed by only NULL-terminating the string when no error has been thrown.

Thanks for Jeffrey Bencteux for reporting this issue:
https://github.com/tuxera/ntfs-3g/issues/84
2023-06-13 17:47:15 +03:00
Erik Larsson 6b3f096069 ntfsprogs/Makefile.am: Only install manpages for 'extras' when enabled.
We used to always install all the manpages, but some are specific to the
'extras' enabled with the configure option '--enable-extras'.
Fixed by only installing the 'extras' manpages when '--enable-extras' is
active.

Also since this commit touches the list of manpages a bit of cleanup was
done to make sure there's only one manpage per line (helps to minimize
diffs) and also that the manpages are sorted in alphabetical order in
ntfsprogs/Makefile.am to avoid future confusion.

Thanks to user 'opty77' for reporting this issue:
https://github.com/tuxera/ntfs-3g/issues/82
2023-05-28 08:21:34 +03:00
Erik Larsson 233658e5a1 attrib.c: Fix another instance of errno not being set on error. 2023-05-19 12:20:54 +03:00
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
Erik Larsson 241ddb3860 index.c: Fix crash when a reparse tag cannot be found in the index.
When 'remove_reparse_index', called by 'ntfs_delete_reparse_index',
fails to look up a reparse key in the index, it leaves the
'ntfs_index_context' without a populated 'INDEX_BLOCK *ib' field.

This causes 'remove_reparse_index' to fail but the index entry is then
marked dirty unconditionally in 'ntfs_index_entry_mark_dirty', called by
'ntfs_delete_reparse_index', even though 'ib' may be NULL.

The following 'ntfs_index_ctx_put' call then starts to write out the
dirty 'INDEX_BLOCK', which causes a crash.

Fixed by only marking the index block dirty in if it's non-NULL.

Thanks to Stephen Greenham <sg@solarisfire.com> for reporting this issue
and providing debug information.
2023-05-03 10:44:57 +02:00
Erik Larsson 01b9bddc0c attrib.c: Fix errno not being set on NULL character in attribute name.
This is an error condition as we jump to err_out, but there's no errno
value set to accompany it. Fixed by setting EIO.
2023-05-03 09:57:34 +02:00
Erik Larsson e73d481a76 mkntfs.c: Enable microsecond-precision volume creation time.
Previously the creation time was filled in with seconds (obtained using
time(NULL)) but the microsecond part was left zeroed. Fixed by using
gettimeofday when available.
2022-12-12 18:51:12 +02:00
Sam James 71ecccf279 configure.ac: fix bashism in fuse check
configure scripts need to be runnable with a POSIX-compliant /bin/sh.

On many (but not all!) systems, /bin/sh is provided by Bash, so errors
like this aren't spotted. Notably Debian defaults to /bin/sh provided
by dash which doesn't tolerate such bashisms as '=='.

This retains compatibility with bash.

Fixes configure warnings/errors like:
```
checking Windows OS... no
./configure: 13360: test: xinternal: unexpected operator
checking for pthread_create in -lpthread... yes
checking Solaris OS... no
```

Signed-off-by: Sam James <sam@gentoo.org>
2022-11-08 13:54:36 +02:00
Jean-Pierre André 78414d9361 Configured for version 2022.10.3 2022-10-03 11:10:36 +02:00
Jean-Pierre André 76c3a799a9 Avoided merging runlists with no runs
Runlists with no runs are tolerated though not expected. However merging
such runlists is problematic as there is no significant vcn to examine.
So avoid merging them, and just return the other runlist.
2022-09-14 08:31:31 +02:00
Jean-Pierre André 18bfc67611 Rejected zero-sized runs
A zero-size run is the universal way to indentify the end of a runlist,
so we must reject zero-sized runs when decompressing a runlist. A
zero-size data run is an error, and a zero-size hole is simply ignored.
2022-09-14 08:29:58 +02:00
Jean-Pierre André 875a1d4e90 Configured for version 2022.5.17
This is a security release. The soname is unchanged as no API has changed.
2022-05-17 08:34:26 +02:00
Jean-Pierre André fb28eef6f1 Hardened the checking of directory offset requested by a readdir
When asked for the next directory entries, make sure the chunk offset
is within valid values, otherwise return no more entries in chunk.
2022-05-10 10:48:18 +02:00
Jean-Pierre André 7f81935f32 Returned an error code when the --help or --version options are used
Accepting --help or --version options may leave the ntfs-3g process in an
unclean state, so reject them while processing options. Also reject
them in libfuse-lite.
2022-05-10 10:44:34 +02: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é 96412e28e5 Fixed possible out-of-buffer condition in ntfsck
A bad usa_count could lead to an out-of-buffer condition. Just avoid
the issue and report the error, still not fix it.
2022-05-10 10:30:24 +02:00
Jean-Pierre André 5ce8941bf4 Made sure there is no null character in an attribute name (bis)
When copying an attribute name which contains a null, it is truncated
and this may lead to accessing non-allocated bytes when relying on the
expected name length. Such (illegal) names must therefore be rejected.
2021-11-05 08:41:20 +01:00
Jean-Pierre André 6efc1305c1 Made sure the client log data does not overflow from restart page
Strengthen the consistency check of the length of restart pages, and
check that log client records are within such a restart page.
2021-10-20 09:53:28 +02:00
Jean-Pierre André 60717a846d Avoided allocating and reading an attribute beyond its full size
Before reading a full attribute value for internal use, its expected
length has been checked to be < 0x40000. However the allocated size
in the runlist may be much bigger as a consequence of a bug or malice.
To prevent malloc'ing excessive size, restrict the size of the last
run to read to the needed length.
2021-09-21 10:56:06 +02:00
Jean-Pierre André 838b6e35b4 Made sure there is no null character in an attribute name
When copying an attribute name which contains a null, it is truncated
and this may lead to accessing non-allocated bytes when relying on the
expected name length. Such names must therefore be rejected.
2021-09-21 10:54:50 +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é 92b9fbc6fe Updated the urls present in the ntfsprogs manuals
The urls now point at Github
2021-08-30 10:42:14 +02:00
Jean-Pierre André 399ba862c9 Updated the urls present in ntfs-3g code
The urls now point at Github
2021-08-30 09:27:33 +02:00
Jean-Pierre André 84739d9e4d Updated the ntfs-3g manual
Reordered the options alphabetically and updated the urls.
2021-08-30 09:20:48 +02:00
Jean-Pierre André 88c4a19c5a Updated the README
Added a recommendation to use ntfs-3g packaged by a distribution, and
inserted a link to the Wiki.
2021-08-25 08:50:03 +02:00
Jean-Pierre André 31ac7e4f0f Configured for version 2021.8.22 2021-08-22 17:05:00 +02:00
Jean-Pierre André a213e6352b Defined Github as the host for documentation
Documentation and support is now on github.com/tuxera
2021-08-22 17:01:39 +02:00
Jean-Pierre André 21b49600ea Configured for version 2021.8.14 2021-08-14 08:44:08 +02:00
Jean-Pierre André 1261e6b60a Fixed the detection of the end of attribute list
The recent detection of a truncated attribute list entry overlooked the
normal detection of the end of list. Moreover the check for name
overflow is to be done later and not needed at this stage.
2021-07-26 08:49:45 +02:00
Jean-Pierre André a337c4c1eb Renamed ntfs_index_entry_consistent() as ntfs_index_entry_inconsistent()
The original name was error prone when checking the condition.
2021-07-19 09:23:23 +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é bb4456d339 Redesigned the INDEX_ROOT consistency checks
By ordering the values from smallest to biggest, there is less chance
to be caught by an arithmetic overflow.
2021-07-19 09:23:23 +02:00
Jean-Pierre André 81725f6a54 Made sure the requested compression block size is supported
Compressed files can only be opened if NTFS version < 3.0, and
the only supported compression block size is 16 clusters long.
2021-07-19 09:23:23 +02:00