"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "libntfs-3g/mst.c" between
ntfs-3g_ntfsprogs-2016.2.22.tgz and ntfs-3g_ntfsprogs-2017.3.23.tgz

About: NTFS-3G is a read-write NTFS driver for Linux and other operating systems. It provides safe handling of the Windows XP, Windows Server 2003, Windows 2000, Windows Vista, Windows Server 2008, Windows 7 and Windows 8 NTFS file systems.

mst.c  (ntfs-3g_ntfsprogs-2016.2.22.tgz):mst.c  (ntfs-3g_ntfsprogs-2017.3.23.tgz)
skipping to change at line 34 skipping to change at line 34
#include "config.h" #include "config.h"
#endif #endif
#ifdef HAVE_ERRNO_H #ifdef HAVE_ERRNO_H
#include <errno.h> #include <errno.h>
#endif #endif
#include "mst.h" #include "mst.h"
#include "logging.h" #include "logging.h"
/*
* Basic validation of a NTFS multi-sector record. The record size must be a
* multiple of the logical sector size; and the update sequence array must be
* properly aligned, of the expected length, and must end before the last le16
* in the first logical sector.
*/
static BOOL
is_valid_record(u32 size, u16 usa_ofs, u16 usa_count)
{
return size % NTFS_BLOCK_SIZE == 0 &&
usa_ofs % 2 == 0 &&
usa_count == 1 + (size / NTFS_BLOCK_SIZE) &&
usa_ofs + ((u32)usa_count * 2) <= NTFS_BLOCK_SIZE - 2;
}
/** /**
* ntfs_mst_post_read_fixup - deprotect multi sector transfer protected data * ntfs_mst_post_read_fixup - deprotect multi sector transfer protected data
* @b: pointer to the data to deprotect * @b: pointer to the data to deprotect
* @size: size in bytes of @b * @size: size in bytes of @b
* *
* Perform the necessary post read multi sector transfer fixups and detect the * Perform the necessary post read multi sector transfer fixups and detect the
* presence of incomplete multi sector transfers. - In that case, overwrite the * presence of incomplete multi sector transfers. - In that case, overwrite the
* magic of the ntfs record header being processed with "BAAD" (in memory only!) * magic of the ntfs record header being processed with "BAAD" (in memory only!)
* and abort processing. * and abort processing.
* *
skipping to change at line 60 skipping to change at line 75
int ntfs_mst_post_read_fixup_warn(NTFS_RECORD *b, const u32 size, int ntfs_mst_post_read_fixup_warn(NTFS_RECORD *b, const u32 size,
BOOL warn) BOOL warn)
{ {
u16 usa_ofs, usa_count, usn; u16 usa_ofs, usa_count, usn;
u16 *usa_pos, *data_pos; u16 *usa_pos, *data_pos;
ntfs_log_trace("Entering\n"); ntfs_log_trace("Entering\n");
/* Setup the variables. */ /* Setup the variables. */
usa_ofs = le16_to_cpu(b->usa_ofs); usa_ofs = le16_to_cpu(b->usa_ofs);
/* Decrement usa_count to get number of fixups. */ usa_count = le16_to_cpu(b->usa_count);
usa_count = le16_to_cpu(b->usa_count) - 1;
/* Size and alignment checks. */ if (!is_valid_record(size, usa_ofs, usa_count)) {
if (size & (NTFS_BLOCK_SIZE - 1) || usa_ofs & 1 ||
(u32)(usa_ofs + (usa_count * 2)) > size ||
(size >> NTFS_BLOCK_SIZE_BITS) != usa_count) {
errno = EINVAL; errno = EINVAL;
if (warn) { if (warn) {
ntfs_log_perror("%s: magic: 0x%08lx size: %ld " ntfs_log_perror("%s: magic: 0x%08lx size: %ld "
" usa_ofs: %d usa_count: %u", " usa_ofs: %d usa_count: %u",
__FUNCTION__, __FUNCTION__,
(long)le32_to_cpu(*(le32 *)b), (long)le32_to_cpu(*(le32 *)b),
(long)size, (int)usa_ofs, (long)size, (int)usa_ofs,
(unsigned int)usa_count); (unsigned int)usa_count);
} }
return -1; return -1;
skipping to change at line 94 skipping to change at line 106
* consistency the wrong endianness it doesn't make any difference. * consistency the wrong endianness it doesn't make any difference.
*/ */
usn = *usa_pos; usn = *usa_pos;
/* /*
* Position in protected data of first u16 that needs fixing up. * Position in protected data of first u16 that needs fixing up.
*/ */
data_pos = (u16*)b + NTFS_BLOCK_SIZE/sizeof(u16) - 1; data_pos = (u16*)b + NTFS_BLOCK_SIZE/sizeof(u16) - 1;
/* /*
* Check for incomplete multi sector transfer(s). * Check for incomplete multi sector transfer(s).
*/ */
while (usa_count--) { while (--usa_count) {
if (*data_pos != usn) { if (*data_pos != usn) {
/* /*
* Incomplete multi sector transfer detected! )-: * Incomplete multi sector transfer detected! )-:
* Set the magic to "BAAD" and return failure. * Set the magic to "BAAD" and return failure.
* Note that magic_BAAD is already converted to le32. * Note that magic_BAAD is already converted to le32.
*/ */
errno = EIO; errno = EIO;
ntfs_log_perror("Incomplete multi-sector transfer: " ntfs_log_perror("Incomplete multi-sector transfer: "
"magic: 0x%08x size: %d usa_ofs: %d usa_count: " "magic: 0x%08x size: %d usa_ofs: %d usa_count: "
" %d data: %d usn: %d", le32_to_cpu(*(le32 *)b) , size, " %d data: %d usn: %d", le32_to_cpu(*(le32 *)b) , size,
usa_ofs, usa_count, *data_pos, usn); usa_ofs, usa_count, *data_pos, usn);
b->magic = magic_BAAD; b->magic = magic_BAAD;
return -1; return -1;
} }
data_pos += NTFS_BLOCK_SIZE/sizeof(u16); data_pos += NTFS_BLOCK_SIZE/sizeof(u16);
} }
/* Re-setup the variables. */ /* Re-setup the variables. */
usa_count = le16_to_cpu(b->usa_count) - 1; usa_count = le16_to_cpu(b->usa_count);
data_pos = (u16*)b + NTFS_BLOCK_SIZE/sizeof(u16) - 1; data_pos = (u16*)b + NTFS_BLOCK_SIZE/sizeof(u16) - 1;
/* Fixup all sectors. */ /* Fixup all sectors. */
while (usa_count--) { while (--usa_count) {
/* /*
* Increment position in usa and restore original data from * Increment position in usa and restore original data from
* the usa into the data buffer. * the usa into the data buffer.
*/ */
*data_pos = *(++usa_pos); *data_pos = *(++usa_pos);
/* Increment position in data as well. */ /* Increment position in data as well. */
data_pos += NTFS_BLOCK_SIZE/sizeof(u16); data_pos += NTFS_BLOCK_SIZE/sizeof(u16);
} }
return 0; return 0;
} }
skipping to change at line 174 skipping to change at line 186
/* Sanity check + only fixup if it makes sense. */ /* Sanity check + only fixup if it makes sense. */
if (!b || ntfs_is_baad_record(b->magic) || if (!b || ntfs_is_baad_record(b->magic) ||
ntfs_is_hole_record(b->magic)) { ntfs_is_hole_record(b->magic)) {
errno = EINVAL; errno = EINVAL;
ntfs_log_perror("%s: bad argument", __FUNCTION__); ntfs_log_perror("%s: bad argument", __FUNCTION__);
return -1; return -1;
} }
/* Setup the variables. */ /* Setup the variables. */
usa_ofs = le16_to_cpu(b->usa_ofs); usa_ofs = le16_to_cpu(b->usa_ofs);
/* Decrement usa_count to get number of fixups. */ usa_count = le16_to_cpu(b->usa_count);
usa_count = le16_to_cpu(b->usa_count) - 1;
/* Size and alignment checks. */ if (!is_valid_record(size, usa_ofs, usa_count)) {
if (size & (NTFS_BLOCK_SIZE - 1) || usa_ofs & 1 ||
(u32)(usa_ofs + (usa_count * 2)) > size ||
(size >> NTFS_BLOCK_SIZE_BITS) != usa_count) {
errno = EINVAL; errno = EINVAL;
ntfs_log_perror("%s", __FUNCTION__); ntfs_log_perror("%s", __FUNCTION__);
return -1; return -1;
} }
/* Position of usn in update sequence array. */ /* Position of usn in update sequence array. */
usa_pos = (le16*)((u8*)b + usa_ofs); usa_pos = (le16*)((u8*)b + usa_ofs);
/* /*
* Cyclically increment the update sequence number * Cyclically increment the update sequence number
* (skipping 0 and -1, i.e. 0xffff). * (skipping 0 and -1, i.e. 0xffff).
*/ */
usn = le16_to_cpup(usa_pos) + 1; usn = le16_to_cpup(usa_pos) + 1;
if (usn == 0xffff || !usn) if (usn == 0xffff || !usn)
usn = 1; usn = 1;
le_usn = cpu_to_le16(usn); le_usn = cpu_to_le16(usn);
*usa_pos = le_usn; *usa_pos = le_usn;
/* Position in data of first le16 that needs fixing up. */ /* Position in data of first le16 that needs fixing up. */
data_pos = (le16*)b + NTFS_BLOCK_SIZE/sizeof(le16) - 1; data_pos = (le16*)b + NTFS_BLOCK_SIZE/sizeof(le16) - 1;
/* Fixup all sectors. */ /* Fixup all sectors. */
while (usa_count--) { while (--usa_count) {
/* /*
* Increment the position in the usa and save the * Increment the position in the usa and save the
* original data from the data buffer into the usa. * original data from the data buffer into the usa.
*/ */
*(++usa_pos) = *data_pos; *(++usa_pos) = *data_pos;
/* Apply fixup to data. */ /* Apply fixup to data. */
*data_pos = le_usn; *data_pos = le_usn;
/* Increment position in data as well. */ /* Increment position in data as well. */
data_pos += NTFS_BLOCK_SIZE/sizeof(le16); data_pos += NTFS_BLOCK_SIZE/sizeof(le16);
} }
skipping to change at line 226 skipping to change at line 235
* Perform the necessary post write multi sector transfer fixup, not checking * Perform the necessary post write multi sector transfer fixup, not checking
* for any errors, because we assume we have just used * for any errors, because we assume we have just used
* ntfs_mst_pre_write_fixup(), thus the data will be fine or we would never * ntfs_mst_pre_write_fixup(), thus the data will be fine or we would never
* have gotten here. * have gotten here.
*/ */
void ntfs_mst_post_write_fixup(NTFS_RECORD *b) void ntfs_mst_post_write_fixup(NTFS_RECORD *b)
{ {
u16 *usa_pos, *data_pos; u16 *usa_pos, *data_pos;
u16 usa_ofs = le16_to_cpu(b->usa_ofs); u16 usa_ofs = le16_to_cpu(b->usa_ofs);
u16 usa_count = le16_to_cpu(b->usa_count) - 1; u16 usa_count = le16_to_cpu(b->usa_count);
ntfs_log_trace("Entering\n"); ntfs_log_trace("Entering\n");
/* Position of usn in update sequence array. */ /* Position of usn in update sequence array. */
usa_pos = (u16*)b + usa_ofs/sizeof(u16); usa_pos = (u16*)b + usa_ofs/sizeof(u16);
/* Position in protected data of first u16 that needs fixing up. */ /* Position in protected data of first u16 that needs fixing up. */
data_pos = (u16*)b + NTFS_BLOCK_SIZE/sizeof(u16) - 1; data_pos = (u16*)b + NTFS_BLOCK_SIZE/sizeof(u16) - 1;
/* Fixup all sectors. */ /* Fixup all sectors. */
while (usa_count--) { while (--usa_count) {
/* /*
* Increment position in usa and restore original data from * Increment position in usa and restore original data from
* the usa into the data buffer. * the usa into the data buffer.
*/ */
*data_pos = *(++usa_pos); *data_pos = *(++usa_pos);
/* Increment position in data as well. */ /* Increment position in data as well. */
data_pos += NTFS_BLOCK_SIZE/sizeof(u16); data_pos += NTFS_BLOCK_SIZE/sizeof(u16);
} }
} }
 End of changes. 9 change blocks. 
18 lines changed or deleted 27 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS