From dfa4a6647fa5ac094bb1edfe23019750b0ea403c Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Mon, 21 Dec 2015 23:21:00 +0100 Subject: [PATCH 01/18] 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. --- include/ntfs-3g/layout.h | 2 +- libntfs-3g/acls.c | 2 +- libntfs-3g/attrib.c | 6 ++-- libntfs-3g/bootsect.c | 4 +-- libntfs-3g/dir.c | 8 ++--- libntfs-3g/index.c | 8 ++--- libntfs-3g/inode.c | 2 +- libntfs-3g/mft.c | 20 +++++------ libntfs-3g/unistr.c | 4 +-- ntfsprogs/mkntfs.c | 75 +++++++++++++++++++------------------- ntfsprogs/ntfscat.c | 6 ++-- ntfsprogs/ntfswipe.c | 22 ++++++------ src/secaudit.c | 78 ++++++++++++++++++++++------------------ src/secaudit.h | 60 +++++++++++++++---------------- 14 files changed, 154 insertions(+), 143 deletions(-) diff --git a/include/ntfs-3g/layout.h b/include/ntfs-3g/layout.h index 9bee6e75..a7766aca 100644 --- a/include/ntfs-3g/layout.h +++ b/include/ntfs-3g/layout.h @@ -836,7 +836,7 @@ typedef enum { FILE_ATTR_READONLY = const_cpu_to_le32(0x00000001), FILE_ATTR_HIDDEN = const_cpu_to_le32(0x00000002), FILE_ATTR_SYSTEM = const_cpu_to_le32(0x00000004), - /* Old DOS volid. Unused in NT. = cpu_to_le32(0x00000008), */ + /* Old DOS volid. Unused in NT. = const_cpu_to_le32(0x00000008), */ FILE_ATTR_DIRECTORY = const_cpu_to_le32(0x00000010), /* FILE_ATTR_DIRECTORY is not considered valid in NT. It is reserved diff --git a/libntfs-3g/acls.c b/libntfs-3g/acls.c index 51a7e7f5..858cd818 100644 --- a/libntfs-3g/acls.c +++ b/libntfs-3g/acls.c @@ -790,7 +790,7 @@ int ntfs_inherit_acl(const ACL *oldacl, ACL *newacl, | FILE_READ | FILE_WRITE | FILE_EXEC - | cpu_to_le32(0x40); + | const_cpu_to_le32(0x40); } /* reencode GENERIC_READ (+ EXECUTE) */ if (pnewace->mask & GENERIC_READ) { diff --git a/libntfs-3g/attrib.c b/libntfs-3g/attrib.c index 77b1f03a..1b6619ae 100644 --- a/libntfs-3g/attrib.c +++ b/libntfs-3g/attrib.c @@ -3828,7 +3828,7 @@ int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, a->non_resident = 0; a->name_length = name_len; a->name_offset = (name_len - ? cpu_to_le16(offsetof(ATTR_RECORD, resident_end)) + ? const_cpu_to_le16(offsetof(ATTR_RECORD, resident_end)) : const_cpu_to_le16(0)); a->flags = data_flags; a->instance = m->next_attr_instance; @@ -3974,7 +3974,7 @@ int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, ? STANDARD_COMPRESSION_UNIT : 0; /* If @lowest_vcn == 0, than setup empty attribute. */ if (!lowest_vcn) { - a->highest_vcn = cpu_to_sle64(-1); + a->highest_vcn = const_cpu_to_sle64(-1); a->allocated_size = 0; a->data_size = 0; a->initialized_size = 0; @@ -4874,7 +4874,7 @@ int ntfs_attr_make_non_resident(ntfs_attr *na, a->name_offset = cpu_to_le16(name_ofs); /* Setup the fields specific to non-resident attributes. */ - a->lowest_vcn = cpu_to_sle64(0); + a->lowest_vcn = const_cpu_to_sle64(0); a->highest_vcn = cpu_to_sle64((new_allocated_size - 1) >> vol->cluster_size_bits); diff --git a/libntfs-3g/bootsect.c b/libntfs-3g/bootsect.c index 92c8505d..e185fe3f 100644 --- a/libntfs-3g/bootsect.c +++ b/libntfs-3g/bootsect.c @@ -65,7 +65,7 @@ BOOL ntfs_boot_sector_is_ntfs(NTFS_BOOT_SECTOR *b) ntfs_log_debug("Beginning bootsector check.\n"); ntfs_log_debug("Checking OEMid, NTFS signature.\n"); - if (b->oem_id != cpu_to_le64(0x202020205346544eULL)) { /* "NTFS " */ + if (b->oem_id != const_cpu_to_le64(0x202020205346544eULL)) { /* "NTFS " */ ntfs_log_error("NTFS signature is missing.\n"); goto not_ntfs; } @@ -140,7 +140,7 @@ BOOL ntfs_boot_sector_is_ntfs(NTFS_BOOT_SECTOR *b) } } - if (b->end_of_sector_marker != cpu_to_le16(0xaa55)) + if (b->end_of_sector_marker != const_cpu_to_le16(0xaa55)) ntfs_log_debug("Warning: Bootsector has invalid end of sector " "marker.\n"); diff --git a/libntfs-3g/dir.c b/libntfs-3g/dir.c index 8633c7d9..a3500aab 100644 --- a/libntfs-3g/dir.c +++ b/libntfs-3g/dir.c @@ -1599,11 +1599,11 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid, ir->clusters_per_index_block = ni->vol->indx_record_size >> NTFS_BLOCK_SIZE_BITS; - ir->index.entries_offset = cpu_to_le32(sizeof(INDEX_HEADER)); + ir->index.entries_offset = const_cpu_to_le32(sizeof(INDEX_HEADER)); ir->index.index_length = cpu_to_le32(index_len); ir->index.allocated_size = cpu_to_le32(index_len); ie = (INDEX_ENTRY*)((u8*)ir + sizeof(INDEX_ROOT)); - ie->length = cpu_to_le16(sizeof(INDEX_ENTRY_HEADER)); + ie->length = const_cpu_to_le16(sizeof(INDEX_ENTRY_HEADER)); ie->key_length = 0; ie->ie_flags = INDEX_ENTRY_END; /* Add INDEX_ROOT attribute to inode. */ @@ -1711,7 +1711,7 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid, goto err_out; } /* Set hard links count and directory flag. */ - ni->mrec->link_count = cpu_to_le16(1); + ni->mrec->link_count = const_cpu_to_le16(1); if (S_ISDIR(type)) ni->mrec->flags |= MFT_RECORD_IS_DIRECTORY; ntfs_inode_mark_dirty(ni); @@ -1970,7 +1970,7 @@ search: * (Windows also does so), however delete the name if it were * in an extent, to avoid leaving an attribute list. */ - if ((ni->mrec->link_count == cpu_to_le16(1)) && !actx->base_ntfs_ino) { + if ((ni->mrec->link_count == const_cpu_to_le16(1)) && !actx->base_ntfs_ino) { /* make sure to not loop to another search */ looking_for_dos_name = FALSE; } else { diff --git a/libntfs-3g/index.c b/libntfs-3g/index.c index d498dde4..0b6538e3 100644 --- a/libntfs-3g/index.c +++ b/libntfs-3g/index.c @@ -811,11 +811,11 @@ static INDEX_BLOCK *ntfs_ib_alloc(VCN ib_vcn, u32 ib_size, return NULL; ib->magic = magic_INDX; - ib->usa_ofs = cpu_to_le16(sizeof(INDEX_BLOCK)); + ib->usa_ofs = const_cpu_to_le16(sizeof(INDEX_BLOCK)); ib->usa_count = cpu_to_le16(ib_size / NTFS_BLOCK_SIZE + 1); /* Set USN to 1 */ - *(u16 *)((char *)ib + le16_to_cpu(ib->usa_ofs)) = cpu_to_le16(1); - ib->lsn = cpu_to_le64(0); + *(u16 *)((char *)ib + le16_to_cpu(ib->usa_ofs)) = const_cpu_to_le16(1); + ib->lsn = const_cpu_to_le64(0); ib->index_block_vcn = cpu_to_sle64(ib_vcn); @@ -1160,7 +1160,7 @@ retry : ie = ntfs_ie_get_first(&ir->index); ie->ie_flags |= INDEX_ENTRY_NODE; - ie->length = cpu_to_le16(sizeof(INDEX_ENTRY_HEADER) + sizeof(VCN)); + ie->length = const_cpu_to_le16(sizeof(INDEX_ENTRY_HEADER) + sizeof(VCN)); ir->index.ih_flags = LARGE_INDEX; ir->index.index_length = cpu_to_le32(le32_to_cpu(ir->index.entries_offset) diff --git a/libntfs-3g/inode.c b/libntfs-3g/inode.c index a4a01348..c4da274c 100644 --- a/libntfs-3g/inode.c +++ b/libntfs-3g/inode.c @@ -806,7 +806,7 @@ static int ntfs_inode_sync_file_name(ntfs_inode *ni, ntfs_inode *dir_ni) goto err_out; } /* Collect the reparse tag, if any */ - reparse_tag = cpu_to_le32(0); + reparse_tag = const_cpu_to_le32(0); if (ni->flags & FILE_ATTR_REPARSE_POINT) { if (!ntfs_attr_lookup(AT_REPARSE_POINT, NULL, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { diff --git a/libntfs-3g/mft.c b/libntfs-3g/mft.c index ac4c610b..761c2b9d 100644 --- a/libntfs-3g/mft.c +++ b/libntfs-3g/mft.c @@ -355,7 +355,7 @@ int ntfs_mft_record_layout(const ntfs_volume *vol, const MFT_REF mref, * Set the NTFS 3.1+ specific fields while we know that the * volume version is 3.1+. */ - mrec->reserved = cpu_to_le16(0); + mrec->reserved = const_cpu_to_le16(0); mrec->mft_record_number = cpu_to_le32(MREF(mref)); } mrec->magic = magic_FILE; @@ -363,7 +363,7 @@ int ntfs_mft_record_layout(const ntfs_volume *vol, const MFT_REF mref, mrec->usa_count = cpu_to_le16(vol->mft_record_size / NTFS_BLOCK_SIZE + 1); else { - mrec->usa_count = cpu_to_le16(1); + mrec->usa_count = const_cpu_to_le16(1); ntfs_log_error("Sector size is bigger than MFT record size. " "Setting usa_count to 1. If Windows chkdsk " "reports this as corruption, please email %s " @@ -372,14 +372,14 @@ int ntfs_mft_record_layout(const ntfs_volume *vol, const MFT_REF mref, "Thank you.\n", NTFS_DEV_LIST); } /* Set the update sequence number to 1. */ - *(u16*)((u8*)mrec + le16_to_cpu(mrec->usa_ofs)) = cpu_to_le16(1); - mrec->lsn = cpu_to_le64(0ull); - mrec->sequence_number = cpu_to_le16(1); - mrec->link_count = cpu_to_le16(0); + *(u16*)((u8*)mrec + le16_to_cpu(mrec->usa_ofs)) = const_cpu_to_le16(1); + mrec->lsn = const_cpu_to_le64(0ull); + mrec->sequence_number = const_cpu_to_le16(1); + mrec->link_count = const_cpu_to_le16(0); /* Aligned to 8-byte boundary. */ mrec->attrs_offset = cpu_to_le16((le16_to_cpu(mrec->usa_ofs) + (le16_to_cpu(mrec->usa_count) << 1) + 7) & ~7); - mrec->flags = cpu_to_le16(0); + mrec->flags = const_cpu_to_le16(0); /* * Using attrs_offset plus eight bytes (for the termination attribute), * aligned to 8-byte boundary. @@ -387,11 +387,11 @@ int ntfs_mft_record_layout(const ntfs_volume *vol, const MFT_REF mref, mrec->bytes_in_use = cpu_to_le32((le16_to_cpu(mrec->attrs_offset) + 8 + 7) & ~7); mrec->bytes_allocated = cpu_to_le32(vol->mft_record_size); - mrec->base_mft_record = cpu_to_le64((MFT_REF)0); - mrec->next_attr_instance = cpu_to_le16(0); + mrec->base_mft_record = const_cpu_to_le64((MFT_REF)0); + mrec->next_attr_instance = const_cpu_to_le16(0); a = (ATTR_RECORD*)((u8*)mrec + le16_to_cpu(mrec->attrs_offset)); a->type = AT_END; - a->length = cpu_to_le32(0); + a->length = const_cpu_to_le32(0); /* Finally, clear the unused part of the mft record. */ memset((u8*)a + 8, 0, vol->mft_record_size - ((u8*)a + 8 - (u8*)mrec)); return 0; diff --git a/libntfs-3g/unistr.c b/libntfs-3g/unistr.c index e12d21e7..bfcfc672 100644 --- a/libntfs-3g/unistr.c +++ b/libntfs-3g/unistr.c @@ -360,7 +360,7 @@ ntfschar *ntfs_ucsndup(const ntfschar *s, u32 maxlen) dst = ntfs_malloc((len + 1) * sizeof(ntfschar)); if (dst) { memcpy(dst, s, len * sizeof(ntfschar)); - dst[len] = cpu_to_le16(L'\0'); + dst[len] = const_cpu_to_le16(L'\0'); } return dst; } @@ -1050,7 +1050,7 @@ int ntfs_mbstoucs(const char *ins, ntfschar **outs) } #endif /* Now write the NULL character. */ - ucs[o] = cpu_to_le16(L'\0'); + ucs[o] = const_cpu_to_le16(L'\0'); *outs = ucs; return o; err_out: diff --git a/ntfsprogs/mkntfs.c b/ntfsprogs/mkntfs.c index a7b1fd23..7d942a27 100644 --- a/ntfsprogs/mkntfs.c +++ b/ntfsprogs/mkntfs.c @@ -1552,7 +1552,7 @@ static int insert_positioned_attr_in_mft_record(MFT_RECORD *m, a->instance = m->next_attr_instance; m->next_attr_instance = cpu_to_le16((le16_to_cpu(m->next_attr_instance) + 1) & 0xffff); - a->lowest_vcn = cpu_to_le64(0); + a->lowest_vcn = const_cpu_to_le64(0); a->highest_vcn = cpu_to_sle64(highest_vcn - 1LL); a->mapping_pairs_offset = cpu_to_le16(hdr_size + ((name_len + 7) & ~7)); memset(a->reserved1, 0, sizeof(a->reserved1)); @@ -1571,7 +1571,7 @@ static int insert_positioned_attr_in_mft_record(MFT_RECORD *m, a->compression_unit = 4; inited_size = val_len; /* FIXME: Set the compressed size. */ - a->compressed_size = cpu_to_le64(0); + a->compressed_size = const_cpu_to_le64(0); /* FIXME: Write out the compressed data. */ /* FIXME: err = build_mapping_pairs_compressed(); */ err = -EOPNOTSUPP; @@ -1745,7 +1745,7 @@ static int insert_non_resident_attr_in_mft_record(MFT_RECORD *m, a->instance = m->next_attr_instance; m->next_attr_instance = cpu_to_le16((le16_to_cpu(m->next_attr_instance) + 1) & 0xffff); - a->lowest_vcn = cpu_to_le64(0); + a->lowest_vcn = const_cpu_to_le64(0); for (i = 0; rl[i].length; i++) ; a->highest_vcn = cpu_to_sle64(rl[i].vcn - 1); @@ -1767,7 +1767,7 @@ static int insert_non_resident_attr_in_mft_record(MFT_RECORD *m, } a->compression_unit = 4; /* FIXME: Set the compressed size. */ - a->compressed_size = cpu_to_le64(0); + a->compressed_size = const_cpu_to_le64(0); /* FIXME: Write out the compressed data. */ /* FIXME: err = build_mapping_pairs_compressed(); */ err = -EOPNOTSUPP; @@ -1926,17 +1926,17 @@ static int add_attr_std_info(MFT_RECORD *m, const FILE_ATTR_FLAGS flags, si.last_mft_change_time = si.creation_time; si.last_access_time = si.creation_time; si.file_attributes = flags; /* already LE */ - si.maximum_versions = cpu_to_le32(0); - si.version_number = cpu_to_le32(0); - si.class_id = cpu_to_le32(0); + si.maximum_versions = const_cpu_to_le32(0); + si.version_number = const_cpu_to_le32(0); + si.class_id = const_cpu_to_le32(0); si.security_id = security_id; if (si.security_id != const_cpu_to_le32(0)) sd_size = 72; /* FIXME: $Quota support... */ - si.owner_id = cpu_to_le32(0); - si.quota_charged = cpu_to_le64(0ULL); + si.owner_id = const_cpu_to_le32(0); + si.quota_charged = const_cpu_to_le64(0ULL); /* FIXME: $UsnJrnl support... Not needed on fresh w2k3-volume */ - si.usn = cpu_to_le64(0ULL); + si.usn = const_cpu_to_le64(0ULL); /* NTFS 1.2: size of si = 48, NTFS 3.[01]: size of si = 72 */ err = insert_resident_attr_in_mft_record(m, AT_STANDARD_INFORMATION, NULL, 0, CASE_SENSITIVE, const_cpu_to_le16(0), @@ -2055,7 +2055,7 @@ static int add_attr_file_name(MFT_RECORD *m, const leMFT_REF parent_dir, } if (packed_ea_size) { fn->packed_ea_size = cpu_to_le16(packed_ea_size); - fn->reserved = cpu_to_le16(0); + fn->reserved = const_cpu_to_le16(0); } else { fn->reparse_point_tag = cpu_to_le32(reparse_point_tag); } @@ -2481,12 +2481,12 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name, } /* Setup header. */ ia_val->magic = magic_INDX; - ia_val->usa_ofs = cpu_to_le16(sizeof(INDEX_ALLOCATION)); + ia_val->usa_ofs = const_cpu_to_le16(sizeof(INDEX_ALLOCATION)); if (index_block_size >= NTFS_BLOCK_SIZE) { ia_val->usa_count = cpu_to_le16(index_block_size / NTFS_BLOCK_SIZE + 1); } else { - ia_val->usa_count = cpu_to_le16(1); + ia_val->usa_count = const_cpu_to_le16(1); ntfs_log_error("Sector size is bigger than index block size. " "Setting usa_count to 1. If Windows chkdsk " "reports this as corruption, please email %s " @@ -2496,9 +2496,9 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name, } /* Set USN to 1. */ *(le16*)((char*)ia_val + le16_to_cpu(ia_val->usa_ofs)) = - cpu_to_le16(1); - ia_val->lsn = cpu_to_le64(0); - ia_val->index_block_vcn = cpu_to_le64(0); + const_cpu_to_le16(1); + ia_val->lsn = const_cpu_to_le64(0); + ia_val->index_block_vcn = const_cpu_to_le64(0); ia_val->index.ih_flags = LEAF_NODE; /* Align to 8-byte boundary. */ ia_val->index.entries_offset = cpu_to_le32((sizeof(INDEX_HEADER) + @@ -2541,7 +2541,7 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name, } /* Set VCN pointer to 0LL. */ *(leVCN*)((char*)re + cpu_to_le16(re->length) - sizeof(VCN)) = - cpu_to_le64(0); + const_cpu_to_le64(0); err = ntfs_mst_pre_write_fixup((NTFS_RECORD*)ia_val, index_block_size); if (err) { err = -errno; @@ -2930,8 +2930,8 @@ static int initialize_quota(MFT_RECORD *m) idx_entry_q1_data->flags = QUOTA_FLAG_DEFAULT_LIMITS; idx_entry_q1_data->bytes_used = const_cpu_to_le64(0x00); idx_entry_q1_data->change_time = mkntfs_time(); - idx_entry_q1_data->threshold = cpu_to_sle64(-1); - idx_entry_q1_data->limit = cpu_to_sle64(-1); + idx_entry_q1_data->threshold = const_cpu_to_sle64(-1); + idx_entry_q1_data->limit = const_cpu_to_sle64(-1); idx_entry_q1_data->exceeded_time = const_cpu_to_le64(0); err = insert_index_entry_in_res_dir_index(idx_entry_q1, q1_size, m, NTFS_INDEX_Q, 2, AT_UNUSED); @@ -2957,8 +2957,8 @@ static int initialize_quota(MFT_RECORD *m) idx_entry_q2_data->flags = QUOTA_FLAG_DEFAULT_LIMITS; idx_entry_q2_data->bytes_used = const_cpu_to_le64(0x00); idx_entry_q2_data->change_time = mkntfs_time(); - idx_entry_q2_data->threshold = cpu_to_sle64(-1); - idx_entry_q2_data->limit = cpu_to_sle64(-1); + idx_entry_q2_data->threshold = const_cpu_to_sle64(-1); + idx_entry_q2_data->limit = const_cpu_to_sle64(-1); idx_entry_q2_data->exceeded_time = const_cpu_to_le64(0); idx_entry_q2_data->sid.revision = 1; idx_entry_q2_data->sid.sub_authority_count = 2; @@ -3133,8 +3133,8 @@ do_next: ie->indexed_file = file_ref; ie->length = cpu_to_le16(i); ie->key_length = cpu_to_le16(file_name_size); - ie->ie_flags = cpu_to_le16(0); - ie->reserved = cpu_to_le16(0); + ie->ie_flags = const_cpu_to_le16(0); + ie->reserved = const_cpu_to_le16(0); memcpy((char*)&ie->key.file_name, (char*)file_name, file_name_size); return 0; } @@ -3189,7 +3189,7 @@ static int create_hardlink_res(MFT_RECORD *m_parent, const leMFT_REF ref_parent, } if (packed_ea_size) { fn->packed_ea_size = cpu_to_le16(packed_ea_size); - fn->reserved = cpu_to_le16(0); + fn->reserved = const_cpu_to_le16(0); } else { fn->reparse_point_tag = cpu_to_le32(reparse_point_tag); } @@ -3304,7 +3304,7 @@ static int create_hardlink(INDEX_BLOCK *idx, const leMFT_REF ref_parent, } if (packed_ea_size) { fn->packed_ea_size = cpu_to_le16(packed_ea_size); - fn->reserved = cpu_to_le16(0); + fn->reserved = const_cpu_to_le16(0); } else { fn->reparse_point_tag = cpu_to_le32(reparse_point_tag); } @@ -3332,7 +3332,7 @@ static int create_hardlink(INDEX_BLOCK *idx, const leMFT_REF ref_parent, m_file->link_count = cpu_to_le16(i + 1); /* Add the file_name to @m_file. */ i = insert_resident_attr_in_mft_record(m_file, AT_FILE_NAME, NULL, 0, - CASE_SENSITIVE, cpu_to_le16(0), + CASE_SENSITIVE, const_cpu_to_le16(0), RESIDENT_ATTR_IS_INDEXED, (u8*)fn, fn_size); if (i < 0) { ntfs_log_error("create_hardlink failed adding file name attribute: " @@ -3388,9 +3388,10 @@ static int index_obj_id_insert(MFT_RECORD *m, const GUID *guid, if (!idx_entry_new) return -errno; idx_entry_new->data_offset = cpu_to_le16(data_ofs); - idx_entry_new->data_length = cpu_to_le16(sizeof(OBJ_ID_INDEX_DATA)); + idx_entry_new->data_length = + const_cpu_to_le16(sizeof(OBJ_ID_INDEX_DATA)); idx_entry_new->length = cpu_to_le16(idx_size); - idx_entry_new->key_length = cpu_to_le16(sizeof(GUID)); + idx_entry_new->key_length = const_cpu_to_le16(sizeof(GUID)); idx_entry_new->key.object_id = *guid; oi = (OBJ_ID_INDEX_DATA*)((u8*)idx_entry_new + data_ofs); oi->mft_reference = ref; @@ -4406,7 +4407,7 @@ static BOOL mkntfs_create_root_structures(void) return FALSE; } if (i == 0 || i > 23) - m->sequence_number = cpu_to_le16(1); + m->sequence_number = const_cpu_to_le16(1); else m->sequence_number = cpu_to_le16(i); } @@ -4423,7 +4424,7 @@ static BOOL mkntfs_create_root_structures(void) "\n"); return FALSE; } - m->flags = cpu_to_le16(0); + m->flags = const_cpu_to_le16(0); m->sequence_number = cpu_to_le16(i); } } @@ -4453,22 +4454,22 @@ static BOOL mkntfs_create_root_structures(void) if (i == 0 || i == 1 || i == 2 || i == 6 || i == 8 || i == 10) { add_attr_std_info(m, file_attrs, - cpu_to_le32(0x0100)); + const_cpu_to_le32(0x0100)); } else if (i == 9) { file_attrs |= FILE_ATTR_VIEW_INDEX_PRESENT; add_attr_std_info(m, file_attrs, - cpu_to_le32(0x0101)); + const_cpu_to_le32(0x0101)); } else if (i == 11) { add_attr_std_info(m, file_attrs, - cpu_to_le32(0x0101)); + const_cpu_to_le32(0x0101)); } else if (i == 24 || i == 25 || i == 26) { file_attrs |= FILE_ATTR_ARCHIVE; file_attrs |= FILE_ATTR_VIEW_INDEX_PRESENT; add_attr_std_info(m, file_attrs, - cpu_to_le32(0x0101)); + const_cpu_to_le32(0x0101)); } else { add_attr_std_info(m, file_attrs, - cpu_to_le32(0x00)); + const_cpu_to_le32(0x00)); } } /* The root directory mft reference. */ @@ -4693,7 +4694,7 @@ static BOOL mkntfs_create_root_structures(void) * Leave zero for now as NT4 leaves it zero, too. If want it later, see * ../libntfs/bootsect.c for how to calculate it. */ - bs->checksum = cpu_to_le32(0); + bs->checksum = const_cpu_to_le32(0); /* Make sure the bootsector is ok. */ if (!ntfs_boot_sector_is_ntfs(bs)) { free(bs); @@ -4997,7 +4998,7 @@ static int mkntfs_redirect(struct mkntfs_options *opts2) g_vol->upcase_len * sizeof(ntfschar)); /* keep the version fields as zero */ memset(g_upcaseinfo, 0, sizeof(struct UPCASEINFO)); - g_upcaseinfo->len = cpu_to_le32(sizeof(struct UPCASEINFO)); + g_upcaseinfo->len = const_cpu_to_le32(sizeof(struct UPCASEINFO)); g_upcaseinfo->crc = cpu_to_le64(upcase_crc); g_vol->attrdef = ntfs_malloc(sizeof(attrdef_ntfs3x_array)); if (!g_vol->attrdef) { diff --git a/ntfsprogs/ntfscat.c b/ntfsprogs/ntfscat.c index 2ae1f9cd..e3a58284 100644 --- a/ntfsprogs/ntfscat.c +++ b/ntfsprogs/ntfscat.c @@ -183,7 +183,7 @@ static int parse_options(int argc, char **argv) opterr = 0; /* We'll handle the errors, thank you. */ opts.inode = -1; - opts.attr = cpu_to_le32(-1); + opts.attr = const_cpu_to_le32(-1); opts.attr_name = NULL; opts.attr_name_len = 0; @@ -201,7 +201,7 @@ static int parse_options(int argc, char **argv) } break; case 'a': - if (opts.attr != cpu_to_le32(-1)) { + if (opts.attr != const_cpu_to_le32(-1)) { ntfs_log_error("You must specify exactly one " "attribute.\n"); } else if (parse_attribute(optarg, &attr) > 0) { @@ -432,7 +432,7 @@ int main(int argc, char *argv[]) } attr = AT_DATA; - if (opts.attr != cpu_to_le32(-1)) + if (opts.attr != const_cpu_to_le32(-1)) attr = opts.attr; result = cat(vol, inode, attr, opts.attr_name, opts.attr_name_len); diff --git a/ntfsprogs/ntfswipe.c b/ntfsprogs/ntfswipe.c index 658aaac0..55803057 100644 --- a/ntfsprogs/ntfswipe.c +++ b/ntfsprogs/ntfswipe.c @@ -1011,14 +1011,14 @@ static s64 wipe_mft(ntfs_volume *vol, int byte, enum action act) rec->magic = magic_FILE; rec->usa_ofs = cpu_to_le16(usa_offset); rec->usa_count = cpu_to_le16((u16) usa_size); - rec->sequence_number = cpu_to_le16(0x0001); + rec->sequence_number = const_cpu_to_le16(0x0001); rec->attrs_offset = cpu_to_le16(attrs_offset); rec->bytes_in_use = cpu_to_le32(bytes_in_use); rec->bytes_allocated = cpu_to_le32(vol->mft_record_size); - rec->next_attr_instance = cpu_to_le16(0x0001); + rec->next_attr_instance = const_cpu_to_le16(0x0001); // End marker. - *((le32*) (((u8*) rec) + attrs_offset)) = cpu_to_le32(0xFFFFFFFF); + *((le32*) (((u8*) rec) + attrs_offset)) = const_cpu_to_le32(0xFFFFFFFF); } result = ntfs_attr_mst_pwrite(vol->mft_na, vol->mft_record_size * i, @@ -1795,7 +1795,7 @@ static int destroy_record(ntfs_volume *nv, const s64 record, } } } - ctx->attr->value_length = cpu_to_le32(0); + ctx->attr->value_length = const_cpu_to_le32(0); if (!opts.noaction) { if (ntfs_mft_records_write(nv, MK_MREF(record, 0), 1LL, ctx->mrec) != 0) { @@ -1863,7 +1863,7 @@ static int destroy_record(ntfs_volume *nv, const s64 record, } } } - ctx->attr->value_length = cpu_to_le32(0); + ctx->attr->value_length = const_cpu_to_le32(0); if ( !opts.noaction ) { if (ntfs_mft_records_write(nv, MK_MREF(record, 0), @@ -1953,12 +1953,12 @@ static int destroy_record(ntfs_volume *nv, const s64 record, } } } - ctx->attr->lowest_vcn = cpu_to_le64(0); - ctx->attr->highest_vcn = cpu_to_le64(0); - ctx->attr->allocated_size = cpu_to_le64(0); - ctx->attr->data_size = cpu_to_le64(0); - ctx->attr->initialized_size = cpu_to_le64(0); - ctx->attr->compressed_size = cpu_to_le64(0); + ctx->attr->lowest_vcn = const_cpu_to_le64(0); + ctx->attr->highest_vcn = const_cpu_to_le64(0); + ctx->attr->allocated_size = const_cpu_to_le64(0); + ctx->attr->data_size = const_cpu_to_le64(0); + ctx->attr->initialized_size = const_cpu_to_le64(0); + ctx->attr->compressed_size = const_cpu_to_le64(0); if (!opts.noaction) { if (ntfs_mft_records_write(nv, MK_MREF (record, 0), diff --git a/src/secaudit.c b/src/secaudit.c index 8ffb2a91..25516264 100644 --- a/src/secaudit.c +++ b/src/secaudit.c @@ -3072,15 +3072,17 @@ void tryposix(struct POSIX_SECURITY *pxdesc) { le32 owner_sid[] = /* S-1-5-21-3141592653-589793238-462843383-1016 */ { - cpu_to_le32(0x501), cpu_to_le32(0x05000000), cpu_to_le32(21), - cpu_to_le32(DEFSECAUTH1), cpu_to_le32(DEFSECAUTH2), - cpu_to_le32(DEFSECAUTH3), cpu_to_le32(1016) + const_cpu_to_le32(0x501), const_cpu_to_le32(0x05000000), + const_cpu_to_le32(21), const_cpu_to_le32(DEFSECAUTH1), + const_cpu_to_le32(DEFSECAUTH2), const_cpu_to_le32(DEFSECAUTH3), + const_cpu_to_le32(1016) } ; le32 group_sid[] = /* S-1-5-21-3141592653-589793238-462843383-513 */ { - cpu_to_le32(0x501), cpu_to_le32(0x05000000), cpu_to_le32(21), - cpu_to_le32(DEFSECAUTH1), cpu_to_le32(DEFSECAUTH2), - cpu_to_le32(DEFSECAUTH3), cpu_to_le32(513) + const_cpu_to_le32(0x501), const_cpu_to_le32(0x05000000), + const_cpu_to_le32(21), const_cpu_to_le32(DEFSECAUTH1), + const_cpu_to_le32(DEFSECAUTH2), const_cpu_to_le32(DEFSECAUTH3), + const_cpu_to_le32(513) } ; char *attr; @@ -3228,9 +3230,9 @@ static char *build_dummy_descr(BOOL isdir __attribute__((unused)), pacl = (ACL*)&attr[pos]; pacl->revision = ACL_REVISION; pacl->alignment1 = 0; - pacl->size = cpu_to_le16(0); /* fixed later */ + pacl->size = const_cpu_to_le16(0); /* fixed later */ pacl->ace_count = cpu_to_le16(cnt); - pacl->alignment2 = cpu_to_le16(0); + pacl->alignment2 = const_cpu_to_le16(0); /* enter the ACEs */ @@ -3257,8 +3259,8 @@ static char *build_dummy_descr(BOOL isdir __attribute__((unused)), /* append usid and gsid if defined */ /* positions of ACL, USID and GSID into header */ - pnhead->owner = cpu_to_le32(0); - pnhead->group = cpu_to_le32(0); + pnhead->owner = const_cpu_to_le32(0); + pnhead->group = const_cpu_to_le32(0); if (usid) { memcpy(&attr[pos], usid, usidsz); pnhead->owner = cpu_to_le32(pos); @@ -3268,13 +3270,14 @@ static char *build_dummy_descr(BOOL isdir __attribute__((unused)), pnhead->group = cpu_to_le32(pos + usidsz); } /* positions of DACL and SACL into header */ - pnhead->sacl = cpu_to_le32(0); + pnhead->sacl = const_cpu_to_le32(0); if (cnt) { pacl->size = cpu_to_le16(aclsz); pnhead->dacl = - cpu_to_le32(sizeof(SECURITY_DESCRIPTOR_RELATIVE)); + const_cpu_to_le32(sizeof( + SECURITY_DESCRIPTOR_RELATIVE)); } else - pnhead->dacl = cpu_to_le32(0); + pnhead->dacl = const_cpu_to_le32(0); if (!ntfs_valid_descr(attr,pos+usidsz+gsidsz)) { printf("** Bad sample descriptor\n"); free(attr); @@ -3309,33 +3312,38 @@ void check_samples() #endif le32 owner1[] = /* S-1-5-21-1833069642-4243175381-1340018762-1003 */ { - cpu_to_le32(0x501), cpu_to_le32(0x05000000), cpu_to_le32(21), - cpu_to_le32(1833069642), cpu_to_le32(4243175381), - cpu_to_le32(1340018762), cpu_to_le32(1003) + const_cpu_to_le32(0x501), const_cpu_to_le32(0x05000000), + const_cpu_to_le32(21), const_cpu_to_le32(1833069642), + const_cpu_to_le32(4243175381), const_cpu_to_le32(1340018762), + const_cpu_to_le32(1003) } ; le32 group1[] = /* S-1-5-21-1833069642-4243175381-1340018762-513 */ { - cpu_to_le32(0x501), cpu_to_le32(0x05000000), cpu_to_le32(21), - cpu_to_le32(1833069642), cpu_to_le32(4243175381), - cpu_to_le32(1340018762), cpu_to_le32(513) + const_cpu_to_le32(0x501), const_cpu_to_le32(0x05000000), + const_cpu_to_le32(21), const_cpu_to_le32(1833069642), + const_cpu_to_le32(4243175381), const_cpu_to_le32(1340018762), + const_cpu_to_le32(513) } ; le32 group2[] = /* S-1-5-21-1607551490-981732888-1819828000-513 */ { - cpu_to_le32(0x501), cpu_to_le32(0x05000000), cpu_to_le32(21), - cpu_to_le32(1607551490), cpu_to_le32(981732888), - cpu_to_le32(1819828000), cpu_to_le32(513) + const_cpu_to_le32(0x501), const_cpu_to_le32(0x05000000), + const_cpu_to_le32(21), const_cpu_to_le32(1607551490), + const_cpu_to_le32(981732888), const_cpu_to_le32(1819828000), + const_cpu_to_le32(513) } ; le32 owner3[] = /* S-1-5-21-3141592653-589793238-462843383-1016 */ { - cpu_to_le32(0x501), cpu_to_le32(0x05000000), cpu_to_le32(21), - cpu_to_le32(DEFSECAUTH1), cpu_to_le32(DEFSECAUTH2), - cpu_to_le32(DEFSECAUTH3), cpu_to_le32(1016) + const_cpu_to_le32(0x501), const_cpu_to_le32(0x05000000), + const_cpu_to_le32(21), const_cpu_to_le32(DEFSECAUTH1), + const_cpu_to_le32(DEFSECAUTH2), const_cpu_to_le32(DEFSECAUTH3), + const_cpu_to_le32(1016) } ; le32 group3[] = /* S-1-5-21-3141592653-589793238-462843383-513 */ { - cpu_to_le32(0x501), cpu_to_le32(0x05000000), cpu_to_le32(21), - cpu_to_le32(DEFSECAUTH1), cpu_to_le32(DEFSECAUTH2), - cpu_to_le32(DEFSECAUTH3), cpu_to_le32(513) + const_cpu_to_le32(0x501), const_cpu_to_le32(0x05000000), + const_cpu_to_le32(21), const_cpu_to_le32(DEFSECAUTH1), + const_cpu_to_le32(DEFSECAUTH2), const_cpu_to_le32(DEFSECAUTH3), + const_cpu_to_le32(513) } ; #if POSIXACLS @@ -4169,15 +4177,17 @@ void selftests(void) { le32 owner_sid[] = /* S-1-5-21-3141592653-589793238-462843383-1016 */ { - cpu_to_le32(0x501), cpu_to_le32(0x05000000), cpu_to_le32(21), - cpu_to_le32(DEFSECAUTH1), cpu_to_le32(DEFSECAUTH2), - cpu_to_le32(DEFSECAUTH3), cpu_to_le32(1016) + const_cpu_to_le32(0x501), const_cpu_to_le32(0x05000000), + const_cpu_to_le32(21), const_cpu_to_le32(DEFSECAUTH1), + const_cpu_to_le32(DEFSECAUTH2), const_cpu_to_le32(DEFSECAUTH3), + const_cpu_to_le32(1016) } ; le32 group_sid[] = /* S-1-5-21-3141592653-589793238-462843383-513 */ { - cpu_to_le32(0x501), cpu_to_le32(0x05000000), cpu_to_le32(21), - cpu_to_le32(DEFSECAUTH1), cpu_to_le32(DEFSECAUTH2), - cpu_to_le32(DEFSECAUTH3), cpu_to_le32(513) + const_cpu_to_le32(0x501), const_cpu_to_le32(0x05000000), + const_cpu_to_le32(21), const_cpu_to_le32(DEFSECAUTH1), + const_cpu_to_le32(DEFSECAUTH2), const_cpu_to_le32(DEFSECAUTH3), + const_cpu_to_le32(513) } ; #if POSIXACLS #ifdef STSC diff --git a/src/secaudit.h b/src/secaudit.h index a8ad163f..9edaf02b 100644 --- a/src/secaudit.h +++ b/src/secaudit.h @@ -216,8 +216,8 @@ typedef DWORD *LPDWORD; #define SE_SACL_PROTECTED const_cpu_to_le16(0x2000) #define SE_DACL_AUTO_INHERITED const_cpu_to_le16(0x400) #define SE_SACL_AUTO_INHERITED const_cpu_to_le16(0x800) -#define SE_DACL_AUTO_INHERIT_REQ cpu_to_le16(0x100) -#define SE_SACL_AUTO_INHERIT_REQ cpu_to_le16(0x200) +#define SE_DACL_AUTO_INHERIT_REQ const_cpu_to_le16(0x100) +#define SE_SACL_AUTO_INHERIT_REQ const_cpu_to_le16(0x200) typedef le16 ntfschar; @@ -326,10 +326,10 @@ typedef enum { OWNER_SECURITY_INFORMATION = 1, // The owner identifier of the object is being referenced. } SECURITY_INFORMATION; -#define STANDARD_RIGHTS_READ cpu_to_le32(0x20000) -#define STANDARD_RIGHTS_WRITE cpu_to_le32(0x20000) -#define STANDARD_RIGHTS_EXECUTE cpu_to_le32(0x20000) -#define STANDARD_RIGHTS_REQUIRED cpu_to_le32(0xf0000) +#define STANDARD_RIGHTS_READ const_cpu_to_le32(0x20000) +#define STANDARD_RIGHTS_WRITE const_cpu_to_le32(0x20000) +#define STANDARD_RIGHTS_EXECUTE const_cpu_to_le32(0x20000) +#define STANDARD_RIGHTS_REQUIRED const_cpu_to_le32(0xf0000) #endif @@ -452,39 +452,39 @@ enum { #ifndef WIN32 -#define DELETE cpu_to_le32(0x00010000L) -#define READ_CONTROL cpu_to_le32(0x00020000L) -#define WRITE_DAC cpu_to_le32(0x00040000L) -#define WRITE_OWNER cpu_to_le32(0x00080000L) -#define SYNCHRONIZE cpu_to_le32(0x00100000L) +#define DELETE const_cpu_to_le32(0x00010000L) +#define READ_CONTROL const_cpu_to_le32(0x00020000L) +#define WRITE_DAC const_cpu_to_le32(0x00040000L) +#define WRITE_OWNER const_cpu_to_le32(0x00080000L) +#define SYNCHRONIZE const_cpu_to_le32(0x00100000L) -#define FILE_READ_DATA cpu_to_le32( 0x0001 ) // file & pipe -#define FILE_LIST_DIRECTORY cpu_to_le32( 0x0001 ) // directory +#define FILE_READ_DATA const_cpu_to_le32(0x0001) // file & pipe +#define FILE_LIST_DIRECTORY const_cpu_to_le32(0x0001) // directory -#define FILE_WRITE_DATA cpu_to_le32( 0x0002 ) // file & pipe -#define FILE_ADD_FILE cpu_to_le32( 0x0002 ) // directory +#define FILE_WRITE_DATA const_cpu_to_le32(0x0002) // file & pipe +#define FILE_ADD_FILE const_cpu_to_le32(0x0002) // directory -#define FILE_APPEND_DATA cpu_to_le32( 0x0004 ) // file -#define FILE_ADD_SUBDIRECTORY cpu_to_le32( 0x0004 ) // directory -#define FILE_CREATE_PIPE_INSTANCE cpu_to_le32( 0x0004 ) // named pipe +#define FILE_APPEND_DATA const_cpu_to_le32(0x0004) // file +#define FILE_ADD_SUBDIRECTORY const_cpu_to_le32(0x0004) // directory +#define FILE_CREATE_PIPE_INSTANCE const_cpu_to_le32(0x0004) // named pipe -#define FILE_READ_EA cpu_to_le32( 0x0008 ) // file & directory +#define FILE_READ_EA const_cpu_to_le32(0x0008) // file & directory -#define FILE_WRITE_EA cpu_to_le32( 0x0010 ) // file & directory +#define FILE_WRITE_EA const_cpu_to_le32(0x0010) // file & directory -#define FILE_EXECUTE cpu_to_le32( 0x0020 ) // file -#define FILE_TRAVERSE cpu_to_le32( 0x0020 ) // directory +#define FILE_EXECUTE const_cpu_to_le32(0x0020) // file +#define FILE_TRAVERSE const_cpu_to_le32(0x0020) // directory -#define FILE_DELETE_CHILD cpu_to_le32( 0x0040 ) // directory +#define FILE_DELETE_CHILD const_cpu_to_le32(0x0040) // directory -#define FILE_READ_ATTRIBUTES cpu_to_le32( 0x0080 ) // all +#define FILE_READ_ATTRIBUTES const_cpu_to_le32(0x0080) // all -#define FILE_WRITE_ATTRIBUTES cpu_to_le32( 0x0100 ) // all +#define FILE_WRITE_ATTRIBUTES const_cpu_to_le32(0x0100) // all #define FILE_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | \ - cpu_to_le32(0x1FF)) + const_cpu_to_le32(0x1FF)) #define FILE_GENERIC_READ (STANDARD_RIGHTS_READ |\ FILE_READ_DATA |\ @@ -506,10 +506,10 @@ enum { FILE_EXECUTE |\ SYNCHRONIZE) -#define GENERIC_READ cpu_to_le32(0x80000000L) -#define GENERIC_WRITE cpu_to_le32(0x40000000L) -#define GENERIC_EXECUTE cpu_to_le32(0x20000000L) -#define GENERIC_ALL cpu_to_le32(0x10000000L) +#define GENERIC_READ const_cpu_to_le32(0x80000000L) +#define GENERIC_WRITE const_cpu_to_le32(0x40000000L) +#define GENERIC_EXECUTE const_cpu_to_le32(0x20000000L) +#define GENERIC_ALL const_cpu_to_le32(0x10000000L) #define OBJECT_INHERIT_ACE (0x1) From f076fae75a242606ae0cbfdceb2280c06c2f1a0f Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Mon, 21 Dec 2015 23:31:09 +0100 Subject: [PATCH 02/18] 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. --- libntfs-3g/attrib.c | 70 ++++++++++++++++++------------------ libntfs-3g/compress.c | 2 +- libntfs-3g/lcnalloc.c | 2 +- libntfs-3g/mst.c | 2 +- ntfsprogs/ntfsck.c | 2 +- ntfsprogs/ntfscmp.c | 4 +-- ntfsprogs/ntfsdump_logfile.c | 2 +- ntfsprogs/ntfsinfo.c | 4 +-- ntfsprogs/ntfsmove.c | 2 +- ntfsprogs/ntfstruncate.c | 4 +-- ntfsprogs/utils.c | 10 +++--- 11 files changed, 52 insertions(+), 52 deletions(-) diff --git a/libntfs-3g/attrib.c b/libntfs-3g/attrib.c index 1b6619ae..63212062 100644 --- a/libntfs-3g/attrib.c +++ b/libntfs-3g/attrib.c @@ -96,7 +96,7 @@ static void NAttrSetFlag(ntfs_attr *na, FILE_ATTR_FLAGS flag) na->ni->flags |= flag; else ntfs_log_trace("Denied setting flag %d for not unnamed data " - "attribute\n", flag); + "attribute\n", le32_to_cpu(flag)); } static void NAttrClearFlag(ntfs_attr *na, FILE_ATTR_FLAGS flag) @@ -405,7 +405,7 @@ ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type, le16 cs; ntfs_log_enter("Entering for inode %lld, attr 0x%x.\n", - (unsigned long long)ni->mft_no, type); + (unsigned long long)ni->mft_no, le32_to_cpu(type)); if (!ni || !ni->vol || !ni->mrec) { errno = EINVAL; @@ -484,7 +484,7 @@ ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type, errno = EIO; ntfs_log_perror("Inode %lld has corrupt attribute flags " "(0x%x <> 0x%x)",(unsigned long long)ni->mft_no, - a->flags, na->ni->flags); + le16_to_cpu(a->flags), le32_to_cpu(na->ni->flags)); goto put_err_out; } @@ -494,7 +494,7 @@ ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type, errno = EIO; ntfs_log_perror("Compressed inode %lld attr 0x%x has " "no compression unit", - (unsigned long long)ni->mft_no, type); + (unsigned long long)ni->mft_no, le32_to_cpu(type)); goto put_err_out; } ntfs_attr_init(na, TRUE, a->flags, @@ -561,7 +561,7 @@ int ntfs_attr_map_runlist(ntfs_attr *na, VCN vcn) ntfs_attr_search_ctx *ctx; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, vcn 0x%llx.\n", - (unsigned long long)na->ni->mft_no, na->type, (long long)vcn); + (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)vcn); lcn = ntfs_rl_vcn_to_lcn(na->rl, vcn); if (lcn >= 0 || lcn == LCN_HOLE || lcn == LCN_ENOENT) @@ -704,7 +704,7 @@ int ntfs_attr_map_whole_runlist(ntfs_attr *na) int not_mapped; ntfs_log_enter("Entering for inode %llu, attr 0x%x.\n", - (unsigned long long)na->ni->mft_no, na->type); + (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type)); /* avoid multiple full runlist mappings */ if (NAttrFullyMapped(na)) { @@ -831,7 +831,7 @@ LCN ntfs_attr_vcn_to_lcn(ntfs_attr *na, const VCN vcn) return (LCN)LCN_EINVAL; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (unsigned long - long)na->ni->mft_no, na->type); + long)na->ni->mft_no, le32_to_cpu(na->type)); retry: /* Convert vcn to lcn. If that fails map the runlist and retry once. */ lcn = ntfs_rl_vcn_to_lcn(na->rl, vcn); @@ -883,7 +883,7 @@ runlist_element *ntfs_attr_find_vcn(ntfs_attr *na, const VCN vcn) } ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, vcn %llx\n", - (unsigned long long)na->ni->mft_no, na->type, + (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)vcn); retry: rl = na->rl; @@ -1176,7 +1176,7 @@ s64 ntfs_attr_pread(ntfs_attr *na, const s64 pos, s64 count, void *b) ntfs_log_enter("Entering for inode %lld attr 0x%x pos %lld count " "%lld\n", (unsigned long long)na->ni->mft_no, - na->type, (long long)pos, (long long)count); + le32_to_cpu(na->type), (long long)pos, (long long)count); ret = ntfs_attr_pread_i(na, pos, count, b); @@ -1800,7 +1800,7 @@ s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b) BOOL compressed; ntfs_log_enter("Entering for inode %lld, attr 0x%x, pos 0x%llx, count " - "0x%llx.\n", (long long)na->ni->mft_no, na->type, + "0x%llx.\n", (long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)pos, (long long)count); if (!na || !na->ni || !na->ni->vol || !b || pos < 0 || count < 0) { @@ -2349,7 +2349,7 @@ int ntfs_attr_pclose(ntfs_attr *na) BOOL compressed; ntfs_log_enter("Entering for inode 0x%llx, attr 0x%x.\n", - na->ni->mft_no, na->type); + na->ni->mft_no, le32_to_cpu(na->type)); if (!na || !na->ni || !na->ni->vol) { errno = EINVAL; @@ -2568,7 +2568,7 @@ s64 ntfs_attr_mst_pread(ntfs_attr *na, const s64 pos, const s64 bk_cnt, BOOL warn; ntfs_log_trace("Entering for inode 0x%llx, attr type 0x%x, pos 0x%llx.\n", - (unsigned long long)na->ni->mft_no, na->type, + (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)pos); if (bk_cnt < 0 || bk_size % NTFS_BLOCK_SIZE) { errno = EINVAL; @@ -2624,7 +2624,7 @@ s64 ntfs_attr_mst_pwrite(ntfs_attr *na, const s64 pos, s64 bk_cnt, s64 written, i; ntfs_log_trace("Entering for inode 0x%llx, attr type 0x%x, pos 0x%llx.\n", - (unsigned long long)na->ni->mft_no, na->type, + (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)pos); if (bk_cnt < 0 || bk_size % NTFS_BLOCK_SIZE) { errno = EINVAL; @@ -2742,7 +2742,7 @@ static int ntfs_attr_find(const ATTR_TYPES type, const ntfschar *name, ntfschar *upcase; u32 upcase_len; - ntfs_log_trace("attribute type 0x%x.\n", type); + ntfs_log_trace("attribute type 0x%x.\n", le32_to_cpu(type)); if (ctx->ntfs_ino) { vol = ctx->ntfs_ino->vol; @@ -2967,7 +2967,7 @@ static int ntfs_external_attr_find(ATTR_TYPES type, const ntfschar *name, ni = ctx->ntfs_ino; base_ni = ctx->base_ntfs_ino; ntfs_log_trace("Entering for inode %lld, attribute type 0x%x.\n", - (unsigned long long)ni->mft_no, type); + (unsigned long long)ni->mft_no, le32_to_cpu(type)); if (!base_ni) { /* First call happens with the base mft record. */ base_ni = ctx->base_ntfs_ino = ctx->ntfs_ino; @@ -3350,7 +3350,7 @@ int ntfs_attr_lookup(const ATTR_TYPES type, const ntfschar *name, ntfs_inode *base_ni; int ret = -1; - ntfs_log_enter("Entering for attribute type 0x%x\n", type); + ntfs_log_enter("Entering for attribute type 0x%x\n", le32_to_cpu(type)); if (!ctx || !ctx->mrec || !ctx->attr || (name && name != AT_UNNAMED && (!ctx->ntfs_ino || !(vol = ctx->ntfs_ino->vol) || @@ -3518,7 +3518,7 @@ ATTR_DEF *ntfs_attr_find_in_attrdef(const ntfs_volume *vol, if (!vol || !vol->attrdef || !type) { errno = EINVAL; - ntfs_log_perror("%s: type=%d", __FUNCTION__, type); + ntfs_log_perror("%s: type=%d", __FUNCTION__, le32_to_cpu(type)); return NULL; } for (ad = vol->attrdef; (u8*)ad - (u8*)vol->attrdef < @@ -3533,7 +3533,7 @@ ATTR_DEF *ntfs_attr_find_in_attrdef(const ntfs_volume *vol, break; } errno = ENOENT; - ntfs_log_perror("%s: type=%d", __FUNCTION__, type); + ntfs_log_perror("%s: type=%d", __FUNCTION__, le32_to_cpu(type)); return NULL; } @@ -3594,7 +3594,7 @@ int ntfs_attr_size_bounds_check(const ntfs_volume *vol, const ATTR_TYPES type, ((max_size > 0) && (size > max_size))) { errno = ERANGE; ntfs_log_perror("Attr type %d size check failed (min,size,max=" - "%lld,%lld,%lld)", type, (long long)min_size, + "%lld,%lld,%lld)", le32_to_cpu(type), (long long)min_size, (long long)size, (long long)max_size); return -1; } @@ -3774,7 +3774,7 @@ int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, ntfs_inode *base_ni; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, flags 0x%x.\n", - (long long) ni->mft_no, (unsigned) type, (unsigned) data_flags); + (long long) ni->mft_no, (unsigned) le32_to_cpu(type), (unsigned) le16_to_cpu(data_flags)); if (!ni || (!name && name_len)) { errno = EINVAL; @@ -3907,8 +3907,8 @@ int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, lowest_vcn %lld, " "dataruns_size %d, flags 0x%x.\n", - (long long) ni->mft_no, (unsigned) type, - (long long) lowest_vcn, dataruns_size, (unsigned) flags); + (long long) ni->mft_no, (unsigned) le32_to_cpu(type), + (long long) lowest_vcn, dataruns_size, (unsigned) le16_to_cpu(flags)); if (!ni || dataruns_size <= 0 || (!name && name_len)) { errno = EINVAL; @@ -3935,7 +3935,7 @@ int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, if (!ntfs_attr_find(type, name, name_len, CASE_SENSITIVE, NULL, 0, ctx)) { err = EEXIST; - ntfs_log_perror("Attribute 0x%x already present", type); + ntfs_log_perror("Attribute 0x%x already present", le32_to_cpu(type)); goto put_err_out; } if (errno != ENOENT) { @@ -4196,7 +4196,7 @@ int ntfs_attr_add(ntfs_inode *ni, ATTR_TYPES type, } ntfs_log_trace("Entering for inode %lld, attr %x, size %lld.\n", - (long long)ni->mft_no, type, (long long)size); + (long long)ni->mft_no, le32_to_cpu(type), (long long)size); if (ni->nr_extents == -1) ni = ni->base_ni; @@ -4418,7 +4418,7 @@ int ntfs_attr_rm(ntfs_attr *na) } ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", - (long long) na->ni->mft_no, na->type); + (long long) na->ni->mft_no, le32_to_cpu(na->type)); /* Free cluster allocation. */ if (NAttrNonResident(na)) { @@ -4766,7 +4766,7 @@ int ntfs_attr_make_non_resident(ntfs_attr *na, int mp_size, mp_ofs, name_ofs, arec_size, err; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (unsigned long - long)na->ni->mft_no, na->type); + long)na->ni->mft_no, le32_to_cpu(na->type)); /* Some preliminary sanity checking. */ if (NAttrNonResident(na)) { @@ -4960,7 +4960,7 @@ static int ntfs_resident_attr_resize_i(ntfs_attr *na, const s64 newsize, int err, ret = STATUS_ERROR; ntfs_log_trace("Inode 0x%llx attr 0x%x new size %lld\n", - (unsigned long long)na->ni->mft_no, na->type, + (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)newsize); /* Get the attribute record that needs modification. */ @@ -5263,7 +5263,7 @@ static int ntfs_attr_make_resident(ntfs_attr *na, ntfs_attr_search_ctx *ctx) s64 arec_size, bytes_read; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (unsigned long - long)na->ni->mft_no, na->type); + long)na->ni->mft_no, le32_to_cpu(na->type)); /* Should be called for the first extent of the attribute. */ if (sle64_to_cpu(a->lowest_vcn)) { @@ -5425,7 +5425,7 @@ static int ntfs_attr_update_meta(ATTR_RECORD *a, ntfs_attr *na, MFT_RECORD *m, int sparse, ret = 0; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x\n", - (unsigned long long)na->ni->mft_no, na->type); + (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type)); if (a->lowest_vcn) goto out; @@ -5568,7 +5568,7 @@ retry: } ntfs_log_trace("Entering for inode %llu, attr 0x%x\n", - (unsigned long long)na->ni->mft_no, na->type); + (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type)); if (!NAttrNonResident(na)) { errno = EINVAL; @@ -5997,7 +5997,7 @@ static int ntfs_non_resident_attr_shrink(ntfs_attr *na, const s64 newsize) int err; ntfs_log_trace("Inode 0x%llx attr 0x%x new size %lld\n", (unsigned long long) - na->ni->mft_no, na->type, (long long)newsize); + na->ni->mft_no, le32_to_cpu(na->type), (long long)newsize); vol = na->ni->vol; @@ -6155,7 +6155,7 @@ static int ntfs_non_resident_attr_expand_i(ntfs_attr *na, const s64 newsize, int err; ntfs_log_trace("Inode %lld, attr 0x%x, new size %lld old size %lld\n", - (unsigned long long)na->ni->mft_no, na->type, + (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)newsize, (long long)na->data_size); vol = na->ni->vol; @@ -6426,7 +6426,7 @@ static int ntfs_attr_truncate_i(ntfs_attr *na, const s64 newsize, } ntfs_log_enter("Entering for inode %lld, attr 0x%x, size %lld\n", - (unsigned long long)na->ni->mft_no, na->type, + (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)newsize); if (na->data_size == newsize) { @@ -6811,7 +6811,7 @@ int ntfs_attr_remove(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name, /* do not log removal of non-existent stream */ if (type != AT_DATA) { ntfs_log_perror("Failed to open attribute 0x%02x of inode " - "0x%llx", type, (unsigned long long)ni->mft_no); + "0x%llx", le32_to_cpu(type), (unsigned long long)ni->mft_no); } return -1; } @@ -6819,7 +6819,7 @@ int ntfs_attr_remove(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name, ret = ntfs_attr_rm(na); if (ret) ntfs_log_perror("Failed to remove attribute 0x%02x of inode " - "0x%llx", type, (unsigned long long)ni->mft_no); + "0x%llx", le32_to_cpu(type), (unsigned long long)ni->mft_no); ntfs_attr_close(na); return ret; diff --git a/libntfs-3g/compress.c b/libntfs-3g/compress.c index f1070aa2..45cd9346 100644 --- a/libntfs-3g/compress.c +++ b/libntfs-3g/compress.c @@ -719,7 +719,7 @@ s64 ntfs_compressed_attr_pread(ntfs_attr *na, s64 pos, s64 count, void *b) unsigned int nr_cbs, cb_clusters; ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, pos 0x%llx, count 0x%llx.\n", - (unsigned long long)na->ni->mft_no, na->type, + (unsigned long long)na->ni->mft_no, le32_to_cpu(na->type), (long long)pos, (long long)count); data_flags = na->data_flags; compression = na->ni->flags & FILE_ATTR_COMPRESSED; diff --git a/libntfs-3g/lcnalloc.c b/libntfs-3g/lcnalloc.c index e84d2431..486e3510 100644 --- a/libntfs-3g/lcnalloc.c +++ b/libntfs-3g/lcnalloc.c @@ -676,7 +676,7 @@ int ntfs_cluster_free(ntfs_volume *vol, ntfs_attr *na, VCN start_vcn, s64 count) ntfs_log_enter("Entering for inode 0x%llx, attr 0x%x, count 0x%llx, " "vcn 0x%llx.\n", (unsigned long long)na->ni->mft_no, - na->type, (long long)count, (long long)start_vcn); + le32_to_cpu(na->type), (long long)count, (long long)start_vcn); rl = ntfs_attr_find_vcn(na, start_vcn); if (!rl) { diff --git a/libntfs-3g/mst.c b/libntfs-3g/mst.c index b7937b7a..88d5e7e6 100644 --- a/libntfs-3g/mst.c +++ b/libntfs-3g/mst.c @@ -101,7 +101,7 @@ int ntfs_mst_post_read_fixup_warn(NTFS_RECORD *b, const u32 size, errno = EIO; ntfs_log_perror("Incomplete multi-sector transfer: " "magic: 0x%08x size: %d usa_ofs: %d usa_count:" - " %d data: %d usn: %d", *(le32 *)b, size, + " %d data: %d usn: %d", le32_to_cpu(*(le32 *)b), size, usa_ofs, usa_count, *data_pos, usn); b->magic = magic_BAAD; return -1; diff --git a/ntfsprogs/ntfsck.c b/ntfsprogs/ntfsck.c index 27816019..ead2e9c8 100644 --- a/ntfsprogs/ntfsck.c +++ b/ntfsprogs/ntfsck.c @@ -610,7 +610,7 @@ static BOOL check_file_record(u8 *buffer, u16 buflen) // We should know all the flags. if (mft_rec->flags>0xf) { check_failed("Unknown MFT record flags (0x%x).\n", - (unsigned int)mft_rec->flags); + (unsigned int)le16_to_cpu(mft_rec->flags)); } // todo: flag in_use must be on. diff --git a/ntfsprogs/ntfscmp.c b/ntfsprogs/ntfscmp.c index 469d1d9a..97aa17dd 100644 --- a/ntfsprogs/ntfscmp.c +++ b/ntfsprogs/ntfscmp.c @@ -394,7 +394,7 @@ static void print_inode_ni(ntfs_inode *ni) static void print_attribute_type(ATTR_TYPES atype) { - printf("attribute 0x%x", atype); + printf("attribute 0x%x", le32_to_cpu(atype)); } static void print_attribute_name(char *name) @@ -781,7 +781,7 @@ static int new_attribute(ntfs_attr_search_ctx *ctx, print_attribute_ctx(ctx); printf("record %llu lowest_vcn %lld: SKIPPED\n", (unsigned long long)ctx->ntfs_ino->mft_no, - (long long)ctx->attr->lowest_vcn); + (long long)sle64_to_cpu(ctx->attr->lowest_vcn)); } return 0; diff --git a/ntfsprogs/ntfsdump_logfile.c b/ntfsprogs/ntfsdump_logfile.c index 279ebac2..b5b73f40 100644 --- a/ntfsprogs/ntfsdump_logfile.c +++ b/ntfsprogs/ntfsdump_logfile.c @@ -557,7 +557,7 @@ static void dump_log_record(LOG_RECORD *lr) (unsigned int)le32_to_cpu(lr->record_type)); ntfs_log_info("transaction_id = 0x%x\n", (unsigned int)le32_to_cpu(lr->transaction_id)); - ntfs_log_info("flags = 0x%x:", lr->flags); + ntfs_log_info("flags = 0x%x:", le16_to_cpu(lr->flags)); if (!lr->flags) ntfs_log_info(" NONE\n"); else { diff --git a/ntfsprogs/ntfsinfo.c b/ntfsprogs/ntfsinfo.c index 817eadc4..54f28bb8 100644 --- a/ntfsprogs/ntfsinfo.c +++ b/ntfsprogs/ntfsinfo.c @@ -420,7 +420,7 @@ static void ntfs_dump_volume(ntfs_volume *vol) printf("\tDevice state: %lu\n", vol->dev->d_state); printf("\tVolume Name: %s\n", vol->vol_name); printf("\tVolume State: %lu\n", vol->state); - printf("\tVolume Flags: 0x%04x", (int)vol->flags); + printf("\tVolume Flags: 0x%04x", (int)le16_to_cpu(vol->flags)); if (vol->flags & VOLUME_IS_DIRTY) printf(" DIRTY"); if (vol->flags & VOLUME_MODIFIED_BY_CHKDSK) @@ -1695,7 +1695,7 @@ static INDEX_ATTR_TYPE get_index_attr_type(ntfs_inode *ni, ATTR_RECORD *attr, else /* weird, this should be illegal */ ntfs_log_error("Unknown index attribute type: 0x%0X\n", - index_root->type); + le32_to_cpu(index_root->type)); return INDEX_ATTR_UNKNOWN; } diff --git a/ntfsprogs/ntfsmove.c b/ntfsprogs/ntfsmove.c index 571808fd..0e11d48a 100644 --- a/ntfsprogs/ntfsmove.c +++ b/ntfsprogs/ntfsmove.c @@ -830,7 +830,7 @@ static s64 move_file(ntfs_volume *vol, ntfs_inode *ino, u64 loc, int flags) while ((rec = find_attribute(AT_UNUSED, ctx))) { utils_attr_get_name(vol, rec, buffer, MAX_PATH); - ntfs_log_info("\tAttribute 0x%02x %s is ", rec->type, buffer); + ntfs_log_info("\tAttribute 0x%02x %s is ", le32_to_cpu(rec->type), buffer); if (rec->non_resident) { ntfs_log_info("non-resident. Moving it.\n"); diff --git a/ntfsprogs/ntfstruncate.c b/ntfsprogs/ntfstruncate.c index f561690f..886a8c37 100644 --- a/ntfsprogs/ntfstruncate.c +++ b/ntfsprogs/ntfstruncate.c @@ -358,7 +358,7 @@ static void dump_resident_attr_val(ATTR_TYPES type, char *val, u32 val_len) VOL_INF(val)->minor_ver); i = VOL_INF(val)->flags; #undef VOL_INF - printf("Volume flags = 0x%x: ", i); + printf("Volume flags = 0x%x: ", le16_to_cpu(i)); if (!i) { printf("NONE\n"); return; @@ -776,7 +776,7 @@ int main(int argc, char **argv) err = ntfs_attr_truncate(na, new_len); if (err) err_exit("Failed to truncate attribute 0x%x: %s\n", - (unsigned int)attr_type, strerror(errno)); + (unsigned int)le32_to_cpu(attr_type), strerror(errno)); if (!opts.quiet && opts.verbose > 1) { ntfs_log_verbose("Dumping mft record after calling " diff --git a/ntfsprogs/utils.c b/ntfsprogs/utils.c index 7ac31163..636ccd9a 100644 --- a/ntfsprogs/utils.c +++ b/ntfsprogs/utils.c @@ -458,11 +458,11 @@ ATTR_RECORD * find_attribute(const ATTR_TYPES type, ntfs_attr_search_ctx *ctx) } if (ntfs_attr_lookup(type, NULL, 0, 0, 0, NULL, 0, ctx) != 0) { - ntfs_log_debug("find_attribute didn't find an attribute of type: 0x%02x.\n", type); + ntfs_log_debug("find_attribute didn't find an attribute of type: 0x%02x.\n", le32_to_cpu(type)); return NULL; /* None / no more of that type */ } - ntfs_log_debug("find_attribute found an attribute of type: 0x%02x.\n", type); + ntfs_log_debug("find_attribute found an attribute of type: 0x%02x.\n", le32_to_cpu(type)); return ctx->attr; } @@ -499,9 +499,9 @@ ATTR_RECORD * find_first_attribute(const ATTR_TYPES type, MFT_RECORD *mft) rec = find_attribute(type, ctx); ntfs_attr_put_search_ctx(ctx); if (rec) - ntfs_log_debug("find_first_attribute: found attr of type 0x%02x.\n", type); + ntfs_log_debug("find_first_attribute: found attr of type 0x%02x.\n", le32_to_cpu(type)); else - ntfs_log_debug("find_first_attribute: didn't find attr of type 0x%02x.\n", type); + ntfs_log_debug("find_first_attribute: didn't find attr of type 0x%02x.\n", le32_to_cpu(type)); return rec; } @@ -659,7 +659,7 @@ int utils_attr_get_name(ntfs_volume *vol, ATTR_RECORD *attr, char *buffer, int b } len = snprintf(buffer, bufsize, "%s", name); } else { - ntfs_log_error("Unknown attribute type 0x%02x\n", attr->type); + ntfs_log_error("Unknown attribute type 0x%02x\n", le32_to_cpu(attr->type)); len = snprintf(buffer, bufsize, ""); } From 9cf04fd2cd1905692d0842106d3c707495aafa61 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Mon, 21 Dec 2015 23:55:31 +0100 Subject: [PATCH 03/18] 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. --- include/ntfs-3g/inode.h | 2 +- include/ntfs-3g/ntfstime.h | 2 +- libntfs-3g/attrib.c | 18 +++++++++--------- libntfs-3g/attrlist.c | 8 ++++---- libntfs-3g/dir.c | 12 ++++++------ libntfs-3g/efs.c | 4 ++-- libntfs-3g/index.c | 14 +++++++------- libntfs-3g/inode.c | 28 ++++++++++++++-------------- libntfs-3g/logfile.c | 8 ++++---- libntfs-3g/mft.c | 8 ++++---- libntfs-3g/mst.c | 10 +++++----- libntfs-3g/unistr.c | 2 +- ntfsprogs/mkntfs.c | 20 ++++++++++---------- ntfsprogs/ntfsck.c | 4 ++-- ntfsprogs/ntfsclone.c | 22 +++++++++++----------- ntfsprogs/ntfscmp.c | 2 +- ntfsprogs/ntfscp.c | 10 +++++----- ntfsprogs/ntfsdecrypt.c | 2 +- ntfsprogs/ntfsdump_logfile.c | 10 +++++----- ntfsprogs/ntfsfallocate.c | 8 ++++---- ntfsprogs/ntfsfix.c | 24 ++++++++++++------------ ntfsprogs/ntfslabel.c | 4 ++-- ntfsprogs/ntfsmftalloc.c | 2 +- ntfsprogs/ntfsresize.c | 34 +++++++++++++++++----------------- ntfsprogs/ntfstruncate.c | 2 +- ntfsprogs/ntfswipe.c | 12 ++++++------ ntfsprogs/sd.c | 8 ++++---- src/lowntfs-3g.c | 12 ++++++------ src/ntfs-3g.c | 14 +++++++------- 29 files changed, 153 insertions(+), 153 deletions(-) diff --git a/include/ntfs-3g/inode.h b/include/ntfs-3g/inode.h index 5a6f7da6..8d58d245 100644 --- a/include/ntfs-3g/inode.h +++ b/include/ntfs-3g/inode.h @@ -197,7 +197,7 @@ extern int ntfs_inode_nidata_hash(const struct CACHED_GENERIC *item); extern ntfs_inode *ntfs_extent_inode_open(ntfs_inode *base_ni, - const MFT_REF mref); + const leMFT_REF mref); extern int ntfs_inode_attach_all_extents(ntfs_inode *ni); diff --git a/include/ntfs-3g/ntfstime.h b/include/ntfs-3g/ntfstime.h index 236c0fb4..f3a89dd8 100644 --- a/include/ntfs-3g/ntfstime.h +++ b/include/ntfs-3g/ntfstime.h @@ -102,7 +102,7 @@ static __inline__ ntfs_time timespec2ntfs(struct timespec spec) units = (s64)spec.tv_sec * 10000000 + NTFS_TIME_OFFSET + spec.tv_nsec/100; - return (cpu_to_le64(units)); + return (cpu_to_sle64(units)); } /* diff --git a/libntfs-3g/attrib.c b/libntfs-3g/attrib.c index 63212062..82e50210 100644 --- a/libntfs-3g/attrib.c +++ b/libntfs-3g/attrib.c @@ -452,7 +452,7 @@ ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type, * does not detect or fix them so we need to cope with it, too. */ if (type == AT_ATTRIBUTE_LIST) - a->flags = 0; + a->flags = const_cpu_to_le16(0); if ((type == AT_DATA) && (a->non_resident ? !a->initialized_size : !a->value_length)) { @@ -643,7 +643,7 @@ static int ntfs_attr_map_partial_runlist(ntfs_attr *na, VCN vcn) rl = na->rl; if (rl) { na->rl = rl; - highest_vcn = le64_to_cpu(a->highest_vcn); + highest_vcn = sle64_to_cpu(a->highest_vcn); if (highest_vcn < needed) { /* corruption detection on unchanged runlists */ if (newrunlist @@ -1040,7 +1040,7 @@ res_err_out: count--; total2++; } else { - *(u16*)((u8*)b+count-2) = cpu_to_le16(efs_padding_length); + *(le16*)((u8*)b+count-2) = cpu_to_le16(efs_padding_length); count -= 2; total2 +=2; } @@ -3975,9 +3975,9 @@ int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, /* If @lowest_vcn == 0, than setup empty attribute. */ if (!lowest_vcn) { a->highest_vcn = const_cpu_to_sle64(-1); - a->allocated_size = 0; - a->data_size = 0; - a->initialized_size = 0; + a->allocated_size = const_cpu_to_sle64(0); + a->data_size = const_cpu_to_sle64(0); + a->initialized_size = const_cpu_to_sle64(0); /* Set empty mapping pairs. */ *((u8*)a + le16_to_cpu(a->mapping_pairs_offset)) = 0; } @@ -4891,7 +4891,7 @@ int ntfs_attr_make_non_resident(ntfs_attr *na, if ((a->flags & ATTR_COMPRESSION_MASK) == ATTR_IS_COMPRESSED) { /* support only ATTR_IS_COMPRESSED compression mode */ a->compression_unit = STANDARD_COMPRESSION_UNIT; - a->compressed_size = const_cpu_to_le64(0); + a->compressed_size = const_cpu_to_sle64(0); } else { a->compression_unit = 0; a->flags &= ~ATTR_COMPRESSION_MASK; @@ -5337,7 +5337,7 @@ static int ntfs_attr_make_resident(ntfs_attr *na, ntfs_attr_search_ctx *ctx) /* Convert the attribute record to describe a resident attribute. */ a->non_resident = 0; - a->flags = 0; + a->flags = const_cpu_to_le16(0); a->value_length = cpu_to_le32(na->data_size); a->value_offset = cpu_to_le16(val_ofs); /* @@ -6762,7 +6762,7 @@ int ntfs_attr_shrink_size(ntfs_inode *ni, ntfschar *stream_name, if (a->non_resident && (sle64_to_cpu(a->initialized_size) > offset)) { - a->initialized_size = cpu_to_le64(offset); + a->initialized_size = cpu_to_sle64(offset); a->data_size = a->initialized_size; } res = 0; diff --git a/libntfs-3g/attrlist.c b/libntfs-3g/attrlist.c index 9c62f316..29d40859 100644 --- a/libntfs-3g/attrlist.c +++ b/libntfs-3g/attrlist.c @@ -107,7 +107,7 @@ int ntfs_attrlist_need(ntfs_inode *ni) int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr) { ATTR_LIST_ENTRY *ale; - MFT_REF mref; + leMFT_REF mref; ntfs_attr *na = NULL; ntfs_attr_search_ctx *ctx; u8 *new_al; @@ -150,7 +150,7 @@ int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr) if (!ntfs_attr_lookup(attr->type, (attr->name_length) ? (ntfschar*) ((u8*)attr + le16_to_cpu(attr->name_offset)) : AT_UNNAMED, attr->name_length, CASE_SENSITIVE, - (attr->non_resident) ? le64_to_cpu(attr->lowest_vcn) : + (attr->non_resident) ? sle64_to_cpu(attr->lowest_vcn) : 0, (attr->non_resident) ? NULL : ((u8*)attr + le16_to_cpu(attr->value_offset)), (attr->non_resident) ? 0 : le32_to_cpu(attr->value_length), ctx)) { @@ -193,7 +193,7 @@ int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr) if (attr->non_resident) ale->lowest_vcn = attr->lowest_vcn; else - ale->lowest_vcn = 0; + ale->lowest_vcn = const_cpu_to_sle64(0); ale->mft_reference = mref; ale->instance = attr->instance; memcpy(ale->name, (u8 *)attr + le16_to_cpu(attr->name_offset), @@ -265,7 +265,7 @@ int ntfs_attrlist_entry_rm(ntfs_attr_search_ctx *ctx) ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, lowest_vcn %lld.\n", (long long) ctx->ntfs_ino->mft_no, (unsigned) le32_to_cpu(ctx->al_entry->type), - (long long) le64_to_cpu(ctx->al_entry->lowest_vcn)); + (long long) sle64_to_cpu(ctx->al_entry->lowest_vcn)); if (!NInoAttrList(base_ni)) { ntfs_log_trace("Attribute list isn't present.\n"); diff --git a/libntfs-3g/dir.c b/libntfs-3g/dir.c index a3500aab..9041eec2 100644 --- a/libntfs-3g/dir.c +++ b/libntfs-3g/dir.c @@ -384,7 +384,7 @@ u64 ntfs_inode_lookup_by_name(ntfs_inode *dir_ni, } /* Get the starting vcn of the index_block holding the child node. */ - vcn = sle64_to_cpup((u8*)ie + le16_to_cpu(ie->length) - 8); + vcn = sle64_to_cpup((sle64*)((u8*)ie + le16_to_cpu(ie->length) - 8)); descend_into_child_node: @@ -496,7 +496,7 @@ descend_into_child_node: goto close_err_out; } /* Child node present, descend into it. */ - vcn = sle64_to_cpup((u8*)ie + le16_to_cpu(ie->length) - 8); + vcn = sle64_to_cpup((sle64*)((u8*)ie + le16_to_cpu(ie->length) - 8)); if (vcn >= 0) goto descend_into_child_node; ntfs_log_error("Negative child node vcn in directory inode " @@ -1531,7 +1531,7 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid, si->last_access_time = ni->last_access_time; if (securid) { set_nino_flag(ni, v3_Extensions); - ni->owner_id = si->owner_id = 0; + ni->owner_id = si->owner_id = const_cpu_to_le32(0); ni->security_id = si->security_id = securid; ni->quota_charged = si->quota_charged = const_cpu_to_le64(0); ni->usn = si->usn = const_cpu_to_le64(0); @@ -1604,7 +1604,7 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid, ir->index.allocated_size = cpu_to_le32(index_len); ie = (INDEX_ENTRY*)((u8*)ir + sizeof(INDEX_ROOT)); ie->length = const_cpu_to_le16(sizeof(INDEX_ENTRY_HEADER)); - ie->key_length = 0; + ie->key_length = const_cpu_to_le16(0); ie->ie_flags = INDEX_ENTRY_END; /* Add INDEX_ROOT attribute to inode. */ if (ntfs_attr_add(ni, AT_INDEX_ROOT, NTFS_INDEX_I30, 4, @@ -1691,7 +1691,7 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid, fn->last_mft_change_time = ni->last_mft_change_time; fn->last_access_time = ni->last_access_time; if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) - fn->data_size = fn->allocated_size = const_cpu_to_le64(0); + fn->data_size = fn->allocated_size = const_cpu_to_sle64(0); else { fn->data_size = cpu_to_sle64(ni->data_size); fn->allocated_size = cpu_to_sle64(ni->allocated_size); @@ -2186,7 +2186,7 @@ static int ntfs_link_i(ntfs_inode *ni, ntfs_inode *dir_ni, const ntfschar *name, fn->file_attributes = ni->flags; if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { fn->file_attributes |= FILE_ATTR_I30_INDEX_PRESENT; - fn->data_size = fn->allocated_size = const_cpu_to_le64(0); + fn->data_size = fn->allocated_size = const_cpu_to_sle64(0); } else { fn->allocated_size = cpu_to_sle64(ni->allocated_size); fn->data_size = cpu_to_sle64(ni->data_size); diff --git a/libntfs-3g/efs.c b/libntfs-3g/efs.c index 7957005b..14a2cb51 100644 --- a/libntfs-3g/efs.c +++ b/libntfs-3g/efs.c @@ -420,8 +420,8 @@ int ntfs_efs_fixup_attribute(ntfs_attr_search_ctx *ctx, ntfs_attr *na) NInoSetDirty(ni); NInoFileNameSetDirty(ni); - ctx->attr->data_size = cpu_to_le64(newsize); - if (le64_to_cpu(ctx->attr->initialized_size) > newsize) + ctx->attr->data_size = cpu_to_sle64(newsize); + if (sle64_to_cpu(ctx->attr->initialized_size) > newsize) ctx->attr->initialized_size = ctx->attr->data_size; ctx->attr->flags |= ATTR_IS_ENCRYPTED; if (close_ctx) diff --git a/libntfs-3g/index.c b/libntfs-3g/index.c index 0b6538e3..0ca91de0 100644 --- a/libntfs-3g/index.c +++ b/libntfs-3g/index.c @@ -191,9 +191,9 @@ void ntfs_index_ctx_reinit(ntfs_index_context *icx) }; } -static VCN *ntfs_ie_get_vcn_addr(INDEX_ENTRY *ie) +static leVCN *ntfs_ie_get_vcn_addr(INDEX_ENTRY *ie) { - return (VCN *)((u8 *)ie + le16_to_cpu(ie->length) - sizeof(VCN)); + return (leVCN *)((u8 *)ie + le16_to_cpu(ie->length) - sizeof(leVCN)); } /** @@ -338,7 +338,7 @@ static void ntfs_ie_delete(INDEX_HEADER *ih, INDEX_ENTRY *ie) static void ntfs_ie_set_vcn(INDEX_ENTRY *ie, VCN vcn) { - *ntfs_ie_get_vcn_addr(ie) = cpu_to_le64(vcn); + *ntfs_ie_get_vcn_addr(ie) = cpu_to_sle64(vcn); } /** @@ -814,14 +814,14 @@ static INDEX_BLOCK *ntfs_ib_alloc(VCN ib_vcn, u32 ib_size, ib->usa_ofs = const_cpu_to_le16(sizeof(INDEX_BLOCK)); ib->usa_count = cpu_to_le16(ib_size / NTFS_BLOCK_SIZE + 1); /* Set USN to 1 */ - *(u16 *)((char *)ib + le16_to_cpu(ib->usa_ofs)) = const_cpu_to_le16(1); - ib->lsn = const_cpu_to_le64(0); + *(le16 *)((char *)ib + le16_to_cpu(ib->usa_ofs)) = const_cpu_to_le16(1); + ib->lsn = const_cpu_to_sle64(0); ib->index_block_vcn = cpu_to_sle64(ib_vcn); ib->index.entries_offset = cpu_to_le32((ih_size + le16_to_cpu(ib->usa_count) * 2 + 7) & ~7); - ib->index.index_length = 0; + ib->index.index_length = const_cpu_to_le32(0); ib->index.allocated_size = cpu_to_le32(ib_size - (sizeof(INDEX_BLOCK) - ih_size)); ib->index.ih_flags = node_type; @@ -2042,7 +2042,7 @@ static INDEX_ENTRY *ntfs_index_walk_up(INDEX_ENTRY *ie, INDEX_ENTRY *ntfs_index_next(INDEX_ENTRY *ie, ntfs_index_context *ictx) { INDEX_ENTRY *next; - int flags; + le16 flags; /* * lookup() may have returned an invalid node diff --git a/libntfs-3g/inode.c b/libntfs-3g/inode.c index c4da274c..a43714cc 100644 --- a/libntfs-3g/inode.c +++ b/libntfs-3g/inode.c @@ -570,7 +570,7 @@ int ntfs_inode_close(ntfs_inode *ni) * Note, extent inodes are never closed directly. They are automatically * disposed off by the closing of the base inode. */ -ntfs_inode *ntfs_extent_inode_open(ntfs_inode *base_ni, const MFT_REF mref) +ntfs_inode *ntfs_extent_inode_open(ntfs_inode *base_ni, const leMFT_REF mref) { u64 mft_no = MREF_LE(mref); VCN extent_vcn; @@ -874,7 +874,7 @@ static int ntfs_inode_sync_file_name(ntfs_inode *ni, ntfs_inode *dir_ni) (ni->flags & FILE_ATTR_VALID_FLAGS); if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) fnx->data_size = fnx->allocated_size - = const_cpu_to_le64(0); + = const_cpu_to_sle64(0); else { fnx->allocated_size = cpu_to_sle64(ni->allocated_size); fnx->data_size = cpu_to_sle64(ni->data_size); @@ -1168,7 +1168,7 @@ int ntfs_inode_add_attrlist(ntfs_inode *ni) if (ctx->attr->non_resident) ale->lowest_vcn = ctx->attr->lowest_vcn; else - ale->lowest_vcn = 0; + ale->lowest_vcn = const_cpu_to_sle64(0); ale->mft_reference = MK_LE_MREF(ni->mft_no, le16_to_cpu(ni->mrec->sequence_number)); ale->instance = ctx->attr->instance; @@ -1206,7 +1206,7 @@ int ntfs_inode_add_attrlist(ntfs_inode *ni) /* Add $ATTRIBUTE_LIST to mft record. */ if (ntfs_resident_attr_record_add(ni, - AT_ATTRIBUTE_LIST, NULL, 0, NULL, 0, 0) < 0) { + AT_ATTRIBUTE_LIST, NULL, 0, NULL, 0, const_cpu_to_le16(0)) < 0) { err = errno; ntfs_log_perror("Couldn't add $ATTRIBUTE_LIST to MFT"); goto rollback; @@ -1477,18 +1477,18 @@ int ntfs_inode_get_times(ntfs_inode *ni, char *value, size_t size) le16_to_cpu(ctx->attr->value_offset)); if (value && (size >= 8)) { times = (u64*)value; - times[0] = le64_to_cpu(std_info->creation_time); + times[0] = sle64_to_cpu(std_info->creation_time); ret = 8; if (size >= 16) { - times[1] = le64_to_cpu(std_info->last_data_change_time); + times[1] = sle64_to_cpu(std_info->last_data_change_time); ret = 16; } if (size >= 24) { - times[2] = le64_to_cpu(std_info->last_access_time); + times[2] = sle64_to_cpu(std_info->last_access_time); ret = 24; } if (size >= 32) { - times[3] = le64_to_cpu(std_info->last_mft_change_time); + times[3] = sle64_to_cpu(std_info->last_mft_change_time); ret = 32; } } else @@ -1551,16 +1551,16 @@ int ntfs_inode_set_times(ntfs_inode *ni, const char *value, size_t size, * return sub-second times in getattr() */ set_nino_flag(ni, TimesSet); - std_info->creation_time = cpu_to_le64(times[0]); + std_info->creation_time = cpu_to_sle64(times[0]); ni->creation_time = std_info->creation_time; if (size >= 16) { - std_info->last_data_change_time = cpu_to_le64(times[1]); + std_info->last_data_change_time = cpu_to_sle64(times[1]); ni->last_data_change_time = std_info->last_data_change_time; } if (size >= 24) { - std_info->last_access_time = cpu_to_le64(times[2]); + std_info->last_access_time = cpu_to_sle64(times[2]); ni->last_access_time = std_info->last_access_time; } @@ -1578,13 +1578,13 @@ int ntfs_inode_set_times(ntfs_inode *ni, const char *value, size_t size, fn = (FILE_NAME_ATTR*)((u8 *)ctx->attr + le16_to_cpu(ctx->attr->value_offset)); fn->creation_time - = cpu_to_le64(times[0]); + = cpu_to_sle64(times[0]); if (size >= 16) fn->last_data_change_time - = cpu_to_le64(times[1]); + = cpu_to_sle64(times[1]); if (size >= 24) fn->last_access_time - = cpu_to_le64(times[2]); + = cpu_to_sle64(times[2]); fn->last_mft_change_time = now; cnt++; } diff --git a/libntfs-3g/logfile.c b/libntfs-3g/logfile.c index 336bdd28..dfe5b7d4 100644 --- a/libntfs-3g/logfile.c +++ b/libntfs-3g/logfile.c @@ -90,10 +90,10 @@ static BOOL ntfs_check_restart_page_header(RESTART_PAGE_HEADER *rp, s64 pos) * Windows 8, and we will refuse to mount. * Nevertheless, do all the relevant checks before rejecting. */ - if (((rp->major_ver != const_cpu_to_le16(1)) - || (rp->minor_ver != const_cpu_to_le16(1))) - && ((rp->major_ver != const_cpu_to_le16(2)) - || (rp->minor_ver != const_cpu_to_le16(0)))) { + if (((rp->major_ver != const_cpu_to_sle16(1)) + || (rp->minor_ver != const_cpu_to_sle16(1))) + && ((rp->major_ver != const_cpu_to_sle16(2)) + || (rp->minor_ver != const_cpu_to_sle16(0)))) { ntfs_log_error("$LogFile version %i.%i is not " "supported.\n (This driver supports version " "1.1 and 2.0 only.)\n", diff --git a/libntfs-3g/mft.c b/libntfs-3g/mft.c index 761c2b9d..a88391fb 100644 --- a/libntfs-3g/mft.c +++ b/libntfs-3g/mft.c @@ -372,8 +372,8 @@ int ntfs_mft_record_layout(const ntfs_volume *vol, const MFT_REF mref, "Thank you.\n", NTFS_DEV_LIST); } /* Set the update sequence number to 1. */ - *(u16*)((u8*)mrec + le16_to_cpu(mrec->usa_ofs)) = const_cpu_to_le16(1); - mrec->lsn = const_cpu_to_le64(0ull); + *(le16*)((u8*)mrec + le16_to_cpu(mrec->usa_ofs)) = const_cpu_to_le16(1); + mrec->lsn = const_cpu_to_sle64(0ll); mrec->sequence_number = const_cpu_to_le16(1); mrec->link_count = const_cpu_to_le16(0); /* Aligned to 8-byte boundary. */ @@ -1510,7 +1510,7 @@ found_free_rec: ntfs_inode_mark_dirty(ni); /* Initialize time, allocated and data size in ntfs_inode struct. */ ni->data_size = ni->allocated_size = 0; - ni->flags = 0; + ni->flags = const_cpu_to_le32(0); ni->creation_time = ni->last_data_change_time = ni->last_mft_change_time = ni->last_access_time = ntfs_current_time(); @@ -1814,7 +1814,7 @@ found_free_rec: ntfs_inode_mark_dirty(ni); /* Initialize time, allocated and data size in ntfs_inode struct. */ ni->data_size = ni->allocated_size = 0; - ni->flags = 0; + ni->flags = const_cpu_to_le32(0); ni->creation_time = ni->last_data_change_time = ni->last_mft_change_time = ni->last_access_time = ntfs_current_time(); diff --git a/libntfs-3g/mst.c b/libntfs-3g/mst.c index 88d5e7e6..9a164390 100644 --- a/libntfs-3g/mst.c +++ b/libntfs-3g/mst.c @@ -157,7 +157,7 @@ int ntfs_mst_post_read_fixup(NTFS_RECORD *b, const u32 size) int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size) { u16 usa_ofs, usa_count, usn; - u16 *usa_pos, *data_pos; + le16 *usa_pos, *data_pos; ntfs_log_trace("Entering\n"); @@ -181,7 +181,7 @@ int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size) return -1; } /* Position of usn in update sequence array. */ - usa_pos = (u16*)((u8*)b + usa_ofs); + usa_pos = (le16*)((u8*)b + usa_ofs); /* * Cyclically increment the update sequence number * (skipping 0 and -1, i.e. 0xffff). @@ -191,8 +191,8 @@ int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size) usn = 1; usn = cpu_to_le16(usn); *usa_pos = usn; - /* Position in data of first u16 that needs fixing up. */ - data_pos = (u16*)b + NTFS_BLOCK_SIZE/sizeof(u16) - 1; + /* Position in data of first le16 that needs fixing up. */ + data_pos = (le16*)b + NTFS_BLOCK_SIZE/sizeof(le16) - 1; /* Fixup all sectors. */ while (usa_count--) { /* @@ -203,7 +203,7 @@ int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size) /* Apply fixup to data. */ *data_pos = usn; /* Increment position in data as well. */ - data_pos += NTFS_BLOCK_SIZE/sizeof(u16); + data_pos += NTFS_BLOCK_SIZE/sizeof(le16); } return 0; } diff --git a/libntfs-3g/unistr.c b/libntfs-3g/unistr.c index bfcfc672..a56c0b8c 100644 --- a/libntfs-3g/unistr.c +++ b/libntfs-3g/unistr.c @@ -244,7 +244,7 @@ int ntfs_names_full_collate(const ntfschar *name1, const u32 name1_len, */ int ntfs_ucsncmp(const ntfschar *s1, const ntfschar *s2, size_t n) { - ntfschar c1, c2; + u16 c1, c2; size_t i; #ifdef DEBUG diff --git a/ntfsprogs/mkntfs.c b/ntfsprogs/mkntfs.c index 7d942a27..8fec2dfd 100644 --- a/ntfsprogs/mkntfs.c +++ b/ntfsprogs/mkntfs.c @@ -1552,7 +1552,7 @@ static int insert_positioned_attr_in_mft_record(MFT_RECORD *m, a->instance = m->next_attr_instance; m->next_attr_instance = cpu_to_le16((le16_to_cpu(m->next_attr_instance) + 1) & 0xffff); - a->lowest_vcn = const_cpu_to_le64(0); + a->lowest_vcn = const_cpu_to_sle64(0); a->highest_vcn = cpu_to_sle64(highest_vcn - 1LL); a->mapping_pairs_offset = cpu_to_le16(hdr_size + ((name_len + 7) & ~7)); memset(a->reserved1, 0, sizeof(a->reserved1)); @@ -1571,7 +1571,7 @@ static int insert_positioned_attr_in_mft_record(MFT_RECORD *m, a->compression_unit = 4; inited_size = val_len; /* FIXME: Set the compressed size. */ - a->compressed_size = const_cpu_to_le64(0); + a->compressed_size = const_cpu_to_sle64(0); /* FIXME: Write out the compressed data. */ /* FIXME: err = build_mapping_pairs_compressed(); */ err = -EOPNOTSUPP; @@ -1745,7 +1745,7 @@ static int insert_non_resident_attr_in_mft_record(MFT_RECORD *m, a->instance = m->next_attr_instance; m->next_attr_instance = cpu_to_le16((le16_to_cpu(m->next_attr_instance) + 1) & 0xffff); - a->lowest_vcn = const_cpu_to_le64(0); + a->lowest_vcn = const_cpu_to_sle64(0); for (i = 0; rl[i].length; i++) ; a->highest_vcn = cpu_to_sle64(rl[i].vcn - 1); @@ -1767,7 +1767,7 @@ static int insert_non_resident_attr_in_mft_record(MFT_RECORD *m, } a->compression_unit = 4; /* FIXME: Set the compressed size. */ - a->compressed_size = const_cpu_to_le64(0); + a->compressed_size = const_cpu_to_sle64(0); /* FIXME: Write out the compressed data. */ /* FIXME: err = build_mapping_pairs_compressed(); */ err = -EOPNOTSUPP; @@ -2497,8 +2497,8 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name, /* Set USN to 1. */ *(le16*)((char*)ia_val + le16_to_cpu(ia_val->usa_ofs)) = const_cpu_to_le16(1); - ia_val->lsn = const_cpu_to_le64(0); - ia_val->index_block_vcn = const_cpu_to_le64(0); + ia_val->lsn = const_cpu_to_sle64(0); + ia_val->index_block_vcn = const_cpu_to_sle64(0); ia_val->index.ih_flags = LEAF_NODE; /* Align to 8-byte boundary. */ ia_val->index.entries_offset = cpu_to_le32((sizeof(INDEX_HEADER) + @@ -2541,7 +2541,7 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name, } /* Set VCN pointer to 0LL. */ *(leVCN*)((char*)re + cpu_to_le16(re->length) - sizeof(VCN)) = - const_cpu_to_le64(0); + const_cpu_to_sle64(0); err = ntfs_mst_pre_write_fixup((NTFS_RECORD*)ia_val, index_block_size); if (err) { err = -errno; @@ -2932,7 +2932,7 @@ static int initialize_quota(MFT_RECORD *m) idx_entry_q1_data->change_time = mkntfs_time(); idx_entry_q1_data->threshold = const_cpu_to_sle64(-1); idx_entry_q1_data->limit = const_cpu_to_sle64(-1); - idx_entry_q1_data->exceeded_time = const_cpu_to_le64(0); + idx_entry_q1_data->exceeded_time = const_cpu_to_sle64(0); err = insert_index_entry_in_res_dir_index(idx_entry_q1, q1_size, m, NTFS_INDEX_Q, 2, AT_UNUSED); free(idx_entry_q1); @@ -2959,7 +2959,7 @@ static int initialize_quota(MFT_RECORD *m) idx_entry_q2_data->change_time = mkntfs_time(); idx_entry_q2_data->threshold = const_cpu_to_sle64(-1); idx_entry_q2_data->limit = const_cpu_to_sle64(-1); - idx_entry_q2_data->exceeded_time = const_cpu_to_le64(0); + idx_entry_q2_data->exceeded_time = const_cpu_to_sle64(0); idx_entry_q2_data->sid.revision = 1; idx_entry_q2_data->sid.sub_authority_count = 2; for (i = 0; i < 5; i++) @@ -4965,7 +4965,7 @@ static int mkntfs_redirect(struct mkntfs_options *opts2) goto done; } /* Initialize the random number generator with the current time. */ - srandom(le64_to_cpu(mkntfs_time())/10000000); + srandom(sle64_to_cpu(mkntfs_time())/10000000); /* Allocate and initialize ntfs_volume structure g_vol. */ g_vol = ntfs_volume_alloc(); if (!g_vol) { diff --git a/ntfsprogs/ntfsck.c b/ntfsprogs/ntfsck.c index ead2e9c8..fee0dc3a 100644 --- a/ntfsprogs/ntfsck.c +++ b/ntfsprogs/ntfsck.c @@ -247,7 +247,7 @@ static BOOL verify_boot_sector(struct ntfs_device *dev, ntfs_volume *rawvol) * * Assumes dev is open. */ -static runlist *load_runlist(ntfs_volume *rawvol, s64 offset_to_file_record, u32 attr_type, u32 size_of_file_record) +static runlist *load_runlist(ntfs_volume *rawvol, s64 offset_to_file_record, ATTR_TYPES attr_type, u32 size_of_file_record) { u8 *buf; u16 attrs_offset; @@ -789,7 +789,7 @@ static void check_volume(ntfs_volume *vol) static int reset_dirty(ntfs_volume *vol) { - u16 flags; + le16 flags; if (!(vol->flags | VOLUME_IS_DIRTY)) return 0; diff --git a/ntfsprogs/ntfsclone.c b/ntfsprogs/ntfsclone.c index 1504c252..2ed9b8e4 100644 --- a/ntfsprogs/ntfsclone.c +++ b/ntfsprogs/ntfsclone.c @@ -898,7 +898,7 @@ static void gap_to_cluster(s64 gap) static void image_skip_clusters(s64 count) { if (opt.save_image && count > 0) { - s64 count_buf; + sle64 count_buf; char buff[1 + sizeof(count)]; buff[0] = CMD_GAP; @@ -1012,7 +1012,7 @@ static void restore_image(void) progress_init(&progress, p_counter, opt.std_out ? sle64_to_cpu(image_hdr.nr_clusters) + 1 : - sle64_to_cpu(image_hdr.inuse) + 1, + le64_to_cpu(image_hdr.inuse) + 1, 100); if (opt.new_serial) @@ -1032,7 +1032,7 @@ static void restore_image(void) if (cmd == CMD_GAP) { if (!image_is_host_endian) { - le64 lecount; + sle64 lecount; /* little endian image, on any computer */ if (read_all(&fd_in, &lecount, @@ -1083,7 +1083,7 @@ static void restore_image(void) static void wipe_index_entry_timestams(INDEX_ENTRY *e) { static const struct timespec zero_time = { .tv_sec = 0, .tv_nsec = 0 }; - le64 timestamp = timespec2ntfs(zero_time); + sle64 timestamp = timespec2ntfs(zero_time); /* FIXME: can fall into infinite loop if corrupted */ while (!(e->ie_flags & INDEX_ENTRY_END)) { @@ -1193,7 +1193,7 @@ out_indexr: free(indexr); } -static void wipe_index_root_timestamps(ATTR_RECORD *attr, le64 timestamp) +static void wipe_index_root_timestamps(ATTR_RECORD *attr, sle64 timestamp) { INDEX_ENTRY *entry; INDEX_ROOT *iroot; @@ -1256,7 +1256,7 @@ static void wipe_timestamps(ntfs_walk_clusters_ctx *image) { static const struct timespec zero_time = { .tv_sec = 0, .tv_nsec = 0 }; ATTR_RECORD *a = image->ctx->attr; - le64 timestamp = timespec2ntfs(zero_time); + sle64 timestamp = timespec2ntfs(zero_time); if (a->type == AT_FILE_NAME) WIPE_TIMESTAMPS(FILE_NAME_ATTR, a, timestamp); @@ -2097,10 +2097,10 @@ static void print_image_info(void) sle64_to_cpu(image_hdr.nr_clusters) * le32_to_cpu(image_hdr.cluster_size)); Printf("Image device size : %lld bytes\n", - (long long)sle64_to_cpu(image_hdr.device_size)); + (long long)le64_to_cpu(image_hdr.device_size)); print_disk_usage(" ", le32_to_cpu(image_hdr.cluster_size), sle64_to_cpu(image_hdr.nr_clusters), - sle64_to_cpu(image_hdr.inuse)); + le64_to_cpu(image_hdr.inuse)); Printf("Offset to image data : %u (0x%x) bytes\n", (unsigned)le32_to_cpu(image_hdr.offset_to_image_data), (unsigned)le32_to_cpu(image_hdr.offset_to_image_data)); @@ -2402,7 +2402,7 @@ static s64 open_image(void) free(dummy_buf); } } - return sle64_to_cpu(image_hdr.device_size); + return le64_to_cpu(image_hdr.device_size); } static s64 open_volume(void) @@ -2432,9 +2432,9 @@ static void initialise_image_hdr(s64 device_size, s64 inuse) image_hdr.major_ver = NTFSCLONE_IMG_VER_MAJOR; image_hdr.minor_ver = NTFSCLONE_IMG_VER_MINOR; image_hdr.cluster_size = cpu_to_le32(vol->cluster_size); - image_hdr.device_size = cpu_to_sle64(device_size); + image_hdr.device_size = cpu_to_le64(device_size); image_hdr.nr_clusters = cpu_to_sle64(vol->nr_clusters); - image_hdr.inuse = cpu_to_sle64(inuse); + image_hdr.inuse = cpu_to_le64(inuse); image_hdr.offset_to_image_data = cpu_to_le32((sizeof(image_hdr) + IMAGE_HDR_ALIGN - 1) & -IMAGE_HDR_ALIGN); } diff --git a/ntfsprogs/ntfscmp.c b/ntfsprogs/ntfscmp.c index 97aa17dd..3ac73365 100644 --- a/ntfsprogs/ntfscmp.c +++ b/ntfsprogs/ntfscmp.c @@ -830,7 +830,7 @@ static int cmp_attributes(ntfs_inode *ni1, ntfs_inode *ni2) int old_ret1, ret1 = 0, ret2 = 0; int errno1 = 0, errno2 = 0; char *prev_name = NULL, *name1 = NULL, *name2 = NULL; - ATTR_TYPES old_atype1, prev_atype = 0, atype1, atype2; + ATTR_TYPES old_atype1, prev_atype = const_cpu_to_le32(0), atype1, atype2; ntfs_attr_search_ctx *ctx1, *ctx2; if (!(ctx1 = attr_get_search_ctx(ni1))) diff --git a/ntfsprogs/ntfscp.c b/ntfsprogs/ntfscp.c index 87a7da30..feee4061 100644 --- a/ntfsprogs/ntfscp.c +++ b/ntfsprogs/ntfscp.c @@ -609,11 +609,11 @@ static int set_sizes(struct ALLOC_CONTEXT *alctx, ntfs_attr_search_ctx *ctx) /* Feed the sizes into the attribute */ attr = ctx->attr; attr->non_resident = 1; - attr->data_size = cpu_to_le64(na->data_size); - attr->initialized_size = cpu_to_le64(na->initialized_size); - attr->allocated_size = cpu_to_le64(na->allocated_size); + attr->data_size = cpu_to_sle64(na->data_size); + attr->initialized_size = cpu_to_sle64(na->initialized_size); + attr->allocated_size = cpu_to_sle64(na->allocated_size); if (na->data_flags & ATTR_IS_SPARSE) - attr->compressed_size = cpu_to_le64(na->compressed_size); + attr->compressed_size = cpu_to_sle64(na->compressed_size); /* Copy the unnamed data attribute sizes to inode */ if ((opts.attribute == AT_DATA) && !na->name_len) { ni = na->ni; @@ -806,7 +806,7 @@ static ntfs_inode *ntfs_new_file(ntfs_inode *dir_ni, filename); return NULL; } - ni = ntfs_create(dir_ni, 0, ufilename, ufilename_len, S_IFREG); + ni = ntfs_create(dir_ni, const_cpu_to_le32(0), ufilename, ufilename_len, S_IFREG); free(ufilename); return ni; } diff --git a/ntfsprogs/ntfsdecrypt.c b/ntfsprogs/ntfsdecrypt.c index ab58cbd9..cbde912a 100644 --- a/ntfsprogs/ntfsdecrypt.c +++ b/ntfsprogs/ntfsdecrypt.c @@ -1049,7 +1049,7 @@ static ntfs_fek *ntfs_fek_import_from_raw(u8 *fek_buf, unsigned fek_size) gcry_error_t err; ntfs_desx_ctx *ctx; - key_size = le32_to_cpup(fek_buf); + key_size = le32_to_cpup((le32*) fek_buf); ntfs_log_debug("key_size 0x%x\n", key_size); if (key_size + 16 > fek_size) { ntfs_log_debug("Invalid FEK. It was probably decrypted with " diff --git a/ntfsprogs/ntfsdump_logfile.c b/ntfsprogs/ntfsdump_logfile.c index b5b73f40..7fe22b3d 100644 --- a/ntfsprogs/ntfsdump_logfile.c +++ b/ntfsprogs/ntfsdump_logfile.c @@ -542,11 +542,11 @@ static void dump_log_record(LOG_RECORD *lr) { unsigned int i; ntfs_log_info("this lsn = 0x%llx\n", - (unsigned long long)le64_to_cpu(lr->this_lsn)); + (unsigned long long)sle64_to_cpu(lr->this_lsn)); ntfs_log_info("client previous lsn = 0x%llx\n", (unsigned long long) - le64_to_cpu(lr->client_previous_lsn)); + sle64_to_cpu(lr->client_previous_lsn)); ntfs_log_info("client undo next lsn = 0x%llx\n", (unsigned long long) - le64_to_cpu(lr->client_undo_next_lsn)); + sle64_to_cpu(lr->client_undo_next_lsn)); ntfs_log_info("client data length = 0x%x\n", (unsigned int)le32_to_cpu(lr->client_data_length)); ntfs_log_info("client_id.seq_number = 0x%x\n", @@ -628,14 +628,14 @@ rcrd_pass_loc: "CHKD"); // TODO: I am here... (AIA) ntfs_log_info("copy.last_lsn/file_offset = 0x%llx\n", (unsigned long long) - le64_to_cpu(rcrd->copy.last_lsn)); + sle64_to_cpu(rcrd->copy.last_lsn)); ntfs_log_info("flags = 0x%x\n", (unsigned int)le32_to_cpu(rcrd->flags)); ntfs_log_info("page count = %i\n", le16_to_cpu(rcrd->page_count)); ntfs_log_info("page position = %i\n", le16_to_cpu(rcrd->page_position)); ntfs_log_info("header.next_record_offset = 0x%llx\n", (unsigned long long) le64_to_cpu(rcrd->header.packed.next_record_offset)); ntfs_log_info("header.last_end_lsn = 0x%llx\n", (unsigned long long) - le64_to_cpu(rcrd->header.packed.last_end_lsn)); + sle64_to_cpu(rcrd->header.packed.last_end_lsn)); /* * Where does the 0x40 come from? Is it just usa_offset + * usa_client * 2 + 7 & ~7 or is it derived from somewhere? diff --git a/ntfsprogs/ntfsfallocate.c b/ntfsprogs/ntfsfallocate.c index 1b243ae6..83c68234 100644 --- a/ntfsprogs/ntfsfallocate.c +++ b/ntfsprogs/ntfsfallocate.c @@ -704,14 +704,14 @@ static int ntfs_full_allocation(ntfs_attr *na, ntfs_attr_search_ctx *ctx, } else { /* Feed the sizes into the attribute */ attr = ctx->attr; - attr->data_size = cpu_to_le64(na->data_size); + attr->data_size = cpu_to_sle64(na->data_size); attr->initialized_size - = cpu_to_le64(na->initialized_size); + = cpu_to_sle64(na->initialized_size); attr->allocated_size - = cpu_to_le64(na->allocated_size); + = cpu_to_sle64(na->allocated_size); if (na->data_flags & ATTR_IS_SPARSE) attr->compressed_size - = cpu_to_le64(na->compressed_size); + = cpu_to_sle64(na->compressed_size); /* Copy the unnamed data attribute sizes to inode */ if ((attr_type == AT_DATA) && !attr_name_len) { ni = na->ni; diff --git a/ntfsprogs/ntfsfix.c b/ntfsprogs/ntfsfix.c index 59b8a98f..568fd9ae 100644 --- a/ntfsprogs/ntfsfix.c +++ b/ntfsprogs/ntfsfix.c @@ -781,7 +781,7 @@ static BOOL short_mft_selfloc_condition(struct MFT_SELF_LOCATED *selfloc) a = find_unnamed_attr(mft0,AT_DATA); if (a && a->non_resident - && (((le64_to_cpu(a->highest_vcn) + 1) + && (((sle64_to_cpu(a->highest_vcn) + 1) << vol->cluster_size_bits) == (SELFLOC_LIMIT*vol->mft_record_size))) { rl = ntfs_mapping_pairs_decompress(vol, a, NULL); @@ -841,13 +841,13 @@ static BOOL attrlist_selfloc_condition(struct MFT_SELF_LOCATED *selfloc) rl = ntfs_mapping_pairs_decompress(vol, a, NULL); if (rl && (rl->lcn >= 0) - && (le64_to_cpu(a->data_size) < vol->cluster_size) + && (sle64_to_cpu(a->data_size) < vol->cluster_size) && (ntfs_pread(vol->dev, rl->lcn << vol->cluster_size_bits, vol->cluster_size, attrlist) == vol->cluster_size)) { selfloc->attrlist_lcn = rl->lcn; al = attrlist; - length = le64_to_cpu(a->data_size); + length = sle64_to_cpu(a->data_size); } } else { al = (ATTR_LIST_ENTRY*) @@ -858,7 +858,7 @@ static BOOL attrlist_selfloc_condition(struct MFT_SELF_LOCATED *selfloc) /* search for a data attribute defining entry 16 */ vcn = (SELFLOC_LIMIT*vol->mft_record_size) >> vol->cluster_size_bits; - levcn = cpu_to_le64(vcn); + levcn = cpu_to_sle64(vcn); while ((length > 0) && al->length && ((al->type != AT_DATA) @@ -921,7 +921,7 @@ static BOOL self_mapped_selfloc_condition(struct MFT_SELF_LOCATED *selfloc) a = find_unnamed_attr(mft1,AT_DATA); if (a && (mft1->flags & MFT_RECORD_IN_USE) - && ((VCN)le64_to_cpu(a->lowest_vcn) == lowest_vcn) + && ((VCN)sle64_to_cpu(a->lowest_vcn) == lowest_vcn) && (le64_to_cpu(mft1->base_mft_record) == selfloc->mft_ref0) && ((u16)MSEQNO(selfloc->mft_ref1) @@ -1020,9 +1020,9 @@ static int fix_selfloc_conditions(struct MFT_SELF_LOCATED *selfloc) mft1->sequence_number = const_cpu_to_le16(SELFLOC_LIMIT - 1); a = find_unnamed_attr(mft1,AT_DATA); if (a) { - a->allocated_size = const_cpu_to_le64(0); - a->data_size = const_cpu_to_le64(0); - a->initialized_size = const_cpu_to_le64(0); + a->allocated_size = const_cpu_to_sle64(0); + a->data_size = const_cpu_to_sle64(0); + a->initialized_size = const_cpu_to_sle64(0); } else res = -1; /* bug : it has been found earlier */ @@ -1189,8 +1189,8 @@ static int try_fix_boot(ntfs_volume *vol, char *full_bs, ntfs_log_perror("Error reading alternate bootsector"); } else { bs = (NTFS_BOOT_SECTOR*)full_bs; - got_sectors = le64_to_cpu(bs->number_of_sectors); - bs->number_of_sectors = cpu_to_le64(fix_sectors); + got_sectors = sle64_to_cpu(bs->number_of_sectors); + bs->number_of_sectors = cpu_to_sle64(fix_sectors); /* alignment problem on Sparc, even doing memcpy() */ sector_size_le = cpu_to_le16(sector_size); if (!memcmp(§or_size_le, &bs->bpb.bytes_per_sector,2) @@ -1325,7 +1325,7 @@ static int check_alternate_boot(ntfs_volume *vol) br = ntfs_pread(vol->dev, 0, vol->sector_size, full_bs); if (br == vol->sector_size) { bs = (NTFS_BOOT_SECTOR*)full_bs; - got_sectors = le64_to_cpu(bs->number_of_sectors); + got_sectors = sle64_to_cpu(bs->number_of_sectors); actual_sectors = ntfs_device_size_get(vol->dev, vol->sector_size); if (actual_sectors > got_sectors) { @@ -1453,7 +1453,7 @@ static int fix_startup(struct ntfs_device *dev, unsigned long flags) if (!ntfs_boot_sector_is_ntfs(bs) /* get the bootsector data, only fails when inconsistent */ || (ntfs_boot_sector_parse(vol, bs) < 0)) { - shown_sectors = le64_to_cpu(bs->number_of_sectors); + shown_sectors = sle64_to_cpu(bs->number_of_sectors); /* boot sector is wrong, try the alternate boot sector */ if (try_alternate_boot(vol, full_bs, sector_size, shown_sectors)) { diff --git a/ntfsprogs/ntfslabel.c b/ntfsprogs/ntfslabel.c index c0494ab5..77a34f08 100644 --- a/ntfsprogs/ntfslabel.c +++ b/ntfsprogs/ntfslabel.c @@ -299,7 +299,7 @@ static int set_new_serial(ntfs_volume *vol) serial_number = cpu_to_le64(sn); } if (!change_serial(vol, 0, serial_number, bs, oldbs)) { - number_of_sectors = le64_to_cpu(bs->number_of_sectors); + number_of_sectors = sle64_to_cpu(bs->number_of_sectors); if (!change_serial(vol, number_of_sectors, serial_number, bs, oldbs)) { ntfs_log_info("New serial number : %016llx\n", @@ -389,7 +389,7 @@ static int change_label(ntfs_volume *vol, char *label) (unsigned)(label_len - (0x100 / sizeof(ntfschar)))); label_len = 0x100 / sizeof(ntfschar); - label[label_len] = const_cpu_to_le16(0); + label[label_len] = 0; } if(!opts.noaction) diff --git a/ntfsprogs/ntfsmftalloc.c b/ntfsprogs/ntfsmftalloc.c index 246ab54a..96f7f79d 100644 --- a/ntfsprogs/ntfsmftalloc.c +++ b/ntfsprogs/ntfsmftalloc.c @@ -229,7 +229,7 @@ static void dump_mft_record(MFT_RECORD *m) ntfs_log_info("Update sequence array offset = %u (0x%x)\n", u, u); ntfs_log_info("Update sequence array size = %u\n", le16_to_cpu(m->usa_count)); ntfs_log_info("$LogFile sequence number (lsn) = %llu\n", - (unsigned long long)le64_to_cpu(m->lsn)); + (unsigned long long)sle64_to_cpu(m->lsn)); ntfs_log_info("Sequence number = %u\n", le16_to_cpu(m->sequence_number)); ntfs_log_info("Reference (hard link) count = %u\n", le16_to_cpu(m->link_count)); diff --git a/ntfsprogs/ntfsresize.c b/ntfsprogs/ntfsresize.c index ce3b9f54..1c1bff5f 100644 --- a/ntfsprogs/ntfsresize.c +++ b/ntfsprogs/ntfsresize.c @@ -1412,7 +1412,7 @@ static void replace_later(ntfs_resize_t *resize, runlist *rl, runlist *head_rl) delayed->type = a->type; delayed->attr_name = attr_name; delayed->name_len = name_len; - delayed->lowest_vcn = le64_to_cpu(a->lowest_vcn); + delayed->lowest_vcn = sle64_to_cpu(a->lowest_vcn); delayed->rl = rl; delayed->head_rl = head_rl; delayed->next = resize->delayed_runlists; @@ -2058,7 +2058,7 @@ static void relocate_inodes(ntfs_resize_t *resize) s64 nr_mft_records; MFT_REF mref; VCN highest_vcn; - u64 length; + s64 length; printf("Relocating needed data ...\n"); @@ -2103,11 +2103,11 @@ static void relocate_inodes(ntfs_resize_t *resize) while (!ntfs_attrs_walk(resize->ctx) && (resize->ctx->attr->type != AT_DATA)) { } if (resize->ctx->attr->type == AT_DATA) { - le64 high_le; + sle64 high_le; high_le = resize->ctx->attr->highest_vcn; - if (le64_to_cpu(high_le) < length) - length = le64_to_cpu(high_le) + 1; + if (sle64_to_cpu(high_le) < length) + length = sle64_to_cpu(high_le) + 1; } else { err_exit("Could not find the DATA of MFT\n"); } @@ -3064,7 +3064,7 @@ static s64 get_data_size(expand_t *expand, s64 inum) /* get the size of unnamed $DATA */ a = get_unnamed_attr(expand, AT_DATA, inum); if (a && a->non_resident) - size = le64_to_cpu(a->allocated_size); + size = sle64_to_cpu(a->allocated_size); if (!size) { err_printf("Bad record %lld, could not get its size\n", (long long)inum); @@ -3092,7 +3092,7 @@ static u8 *get_mft_bitmap(expand_t *expand) /* get the runlist of unnamed bitmap */ a = get_unnamed_attr(expand, AT_BITMAP, FILE_MFT); ok = TRUE; - bitmap_size = le64_to_cpu(a->allocated_size); + bitmap_size = sle64_to_cpu(a->allocated_size); if (a && a->non_resident && ((bitmap_size << (vol->mft_record_size_bits + 3)) @@ -3615,10 +3615,10 @@ static int copy_boot(expand_t *expand) if (buf) { /* set the new volume parameters in the bootsector */ bs = (NTFS_BOOT_SECTOR*)expand->bootsector; - bs->number_of_sectors = cpu_to_le64(expand->new_sectors); - bs->mft_lcn = cpu_to_le64(expand->mft_lcn); + bs->number_of_sectors = cpu_to_sle64(expand->new_sectors); + bs->mft_lcn = cpu_to_sle64(expand->mft_lcn); mftmirr_lcn = vol->mftmirr_lcn + expand->cluster_increment; - bs->mftmirr_lcn = cpu_to_le64(mftmirr_lcn); + bs->mftmirr_lcn = cpu_to_sle64(mftmirr_lcn); /* the hidden sectors are needed to boot into windows */ memcpy(&hidden_sectors_le,&bs->bpb.hidden_sectors,4); /* alignment messed up on the Sparc */ @@ -3984,11 +3984,11 @@ static runlist_element *rebase_runlists_meta(expand_t *expand, s64 inum) rl[1].length = 0; if (set_bitmap(expand,rl)) res = -1; - a->data_size = cpu_to_le64(data_size); + a->data_size = cpu_to_sle64(data_size); a->initialized_size = a->data_size; a->allocated_size - = cpu_to_le64(allocated_size); - a->highest_vcn = cpu_to_le64(lth - 1); + = cpu_to_sle64(allocated_size); + a->highest_vcn = cpu_to_sle64(lth - 1); } /* expand the named data for $BadClus */ if ((a->type == AT_DATA) @@ -4004,11 +4004,11 @@ static runlist_element *rebase_runlists_meta(expand_t *expand, s64 inum) prl[1].vcn = lth; } else prl->vcn = lth; - a->data_size = cpu_to_le64(data_size); + a->data_size = cpu_to_sle64(data_size); /* do not change the initialized size */ a->allocated_size - = cpu_to_le64(allocated_size); - a->highest_vcn = cpu_to_le64(lth - 1); + = cpu_to_sle64(allocated_size); + a->highest_vcn = cpu_to_sle64(lth - 1); } if (!res && update_runlist(expand,inum,a,rl)) res = -1; @@ -4212,7 +4212,7 @@ static ntfs_volume *get_volume_data(expand_t *expand, struct ntfs_device *dev, && ntfs_boot_sector_is_ntfs(bs) && !ntfs_boot_sector_parse(vol, bs)) { expand->original_sectors - = le64_to_cpu(bs->number_of_sectors); + = sle64_to_cpu(bs->number_of_sectors); expand->mrec = (MFT_RECORD*) ntfs_malloc(vol->mft_record_size); if (expand->mrec diff --git a/ntfsprogs/ntfstruncate.c b/ntfsprogs/ntfstruncate.c index 886a8c37..90b88998 100644 --- a/ntfsprogs/ntfstruncate.c +++ b/ntfsprogs/ntfstruncate.c @@ -638,7 +638,7 @@ static void dump_mft_record(MFT_RECORD *m) printf("Update sequence array offset = %u (0x%x)\n", u, u); printf("Update sequence array size = %u\n", le16_to_cpu(m->usa_count)); printf("$LogFile sequence number (lsn) = %llu\n", - (unsigned long long)le64_to_cpu(m->lsn)); + (unsigned long long)sle64_to_cpu(m->lsn)); printf("Sequence number = %u\n", le16_to_cpu(m->sequence_number)); printf("Reference (hard link) count = %u\n", le16_to_cpu(m->link_count)); diff --git a/ntfsprogs/ntfswipe.c b/ntfsprogs/ntfswipe.c index 55803057..ad794172 100644 --- a/ntfsprogs/ntfswipe.c +++ b/ntfsprogs/ntfswipe.c @@ -1953,12 +1953,12 @@ static int destroy_record(ntfs_volume *nv, const s64 record, } } } - ctx->attr->lowest_vcn = const_cpu_to_le64(0); - ctx->attr->highest_vcn = const_cpu_to_le64(0); - ctx->attr->allocated_size = const_cpu_to_le64(0); - ctx->attr->data_size = const_cpu_to_le64(0); - ctx->attr->initialized_size = const_cpu_to_le64(0); - ctx->attr->compressed_size = const_cpu_to_le64(0); + ctx->attr->lowest_vcn = const_cpu_to_sle64(0); + ctx->attr->highest_vcn = const_cpu_to_sle64(0); + ctx->attr->allocated_size = const_cpu_to_sle64(0); + ctx->attr->data_size = const_cpu_to_sle64(0); + ctx->attr->initialized_size = const_cpu_to_sle64(0); + ctx->attr->compressed_size = const_cpu_to_sle64(0); if (!opts.noaction) { if (ntfs_mft_records_write(nv, MK_MREF (record, 0), diff --git a/ntfsprogs/sd.c b/ntfsprogs/sd.c index 4e3af978..a60a8288 100644 --- a/ntfsprogs/sd.c +++ b/ntfsprogs/sd.c @@ -187,7 +187,7 @@ void init_root_sd(u8 **sd_val, int *sd_val_len) sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT; sd->owner = const_cpu_to_le32(0x1014); sd->group = const_cpu_to_le32(0x1020); - sd->sacl = 0; + sd->sacl = const_cpu_to_le32(0); sd->dacl = const_cpu_to_le32(sizeof(SECURITY_DESCRIPTOR_RELATIVE)); //acl @@ -196,7 +196,7 @@ void init_root_sd(u8 **sd_val, int *sd_val_len) acl->alignment1 = 0; acl->size = const_cpu_to_le16(0x1000); acl->ace_count = const_cpu_to_le16(0x08); - acl->alignment2 = 0; + acl->alignment2 = const_cpu_to_le16(0); //ace1 ace = (ACCESS_ALLOWED_ACE*)((u8*)acl + sizeof(ACL)); @@ -436,7 +436,7 @@ void init_secure_sds(char *sd_val) acl->alignment1 = 0x00; acl->size = const_cpu_to_le16(0x34); acl->ace_count = const_cpu_to_le16(0x02); - acl->alignment2 = 0x00; + acl->alignment2 = const_cpu_to_le16(0x00); //ace1 ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); @@ -532,7 +532,7 @@ void init_secure_sds(char *sd_val) acl->alignment1 = 0x00; acl->size = const_cpu_to_le16(0x34); acl->ace_count = const_cpu_to_le16(0x02); - acl->alignment2 = 0x00; + acl->alignment2 = const_cpu_to_le16(0x00); //ace1 ace = (ACCESS_ALLOWED_ACE*)((char*)acl + sizeof(ACL)); diff --git a/src/lowntfs-3g.c b/src/lowntfs-3g.c index 3ff8b9de..8ce3d9f6 100644 --- a/src/lowntfs-3g.c +++ b/src/lowntfs-3g.c @@ -270,10 +270,10 @@ static void ntfs_fuse_update_times(ntfs_inode *ni, ntfs_time_update_flags mask) if (ctx->atime == ATIME_DISABLED) mask &= ~NTFS_UPDATE_ATIME; else if (ctx->atime == ATIME_RELATIVE && mask == NTFS_UPDATE_ATIME && - (le64_to_cpu(ni->last_access_time) - >= le64_to_cpu(ni->last_data_change_time)) && - (le64_to_cpu(ni->last_access_time) - >= le64_to_cpu(ni->last_mft_change_time))) + (sle64_to_cpu(ni->last_access_time) + >= sle64_to_cpu(ni->last_data_change_time)) && + (sle64_to_cpu(ni->last_access_time) + >= sle64_to_cpu(ni->last_mft_change_time))) return; ntfs_inode_update_times(ni, mask); } @@ -1416,8 +1416,8 @@ static void ntfs_fuse_write(fuse_req_t req, fuse_ino_t ino, const char *buf, res = total; if ((res > 0) && (!ctx->dmtime - || (le64_to_cpu(ntfs_current_time()) - - le64_to_cpu(ni->last_data_change_time)) > ctx->dmtime)) + || (sle64_to_cpu(ntfs_current_time()) + - sle64_to_cpu(ni->last_data_change_time)) > ctx->dmtime)) ntfs_fuse_update_times(na->ni, NTFS_UPDATE_MCTIME); exit: if (na) diff --git a/src/ntfs-3g.c b/src/ntfs-3g.c index de0f920e..dc2d4454 100644 --- a/src/ntfs-3g.c +++ b/src/ntfs-3g.c @@ -232,10 +232,10 @@ static void ntfs_fuse_update_times(ntfs_inode *ni, ntfs_time_update_flags mask) if (ctx->atime == ATIME_DISABLED) mask &= ~NTFS_UPDATE_ATIME; else if (ctx->atime == ATIME_RELATIVE && mask == NTFS_UPDATE_ATIME && - (le64_to_cpu(ni->last_access_time) - >= le64_to_cpu(ni->last_data_change_time)) && - (le64_to_cpu(ni->last_access_time) - >= le64_to_cpu(ni->last_mft_change_time))) + (sle64_to_cpu(ni->last_access_time) + >= sle64_to_cpu(ni->last_data_change_time)) && + (sle64_to_cpu(ni->last_access_time) + >= sle64_to_cpu(ni->last_mft_change_time))) return; ntfs_inode_update_times(ni, mask); } @@ -1339,8 +1339,8 @@ static int ntfs_fuse_write(const char *org_path, const char *buf, size_t size, res = total; if ((res > 0) && (!ctx->dmtime - || (le64_to_cpu(ntfs_current_time()) - - le64_to_cpu(ni->last_data_change_time)) > ctx->dmtime)) + || (sle64_to_cpu(ntfs_current_time()) + - sle64_to_cpu(ni->last_data_change_time)) > ctx->dmtime)) ntfs_fuse_update_times(na->ni, NTFS_UPDATE_MCTIME); exit: if (na) @@ -1709,7 +1709,7 @@ static int ntfs_fuse_create(const char *org_path, mode_t typemode, dev_t dev, * have to build a security attribute later. */ if (!ctx->security.mapping[MAPUSERS]) - securid = 0; + securid = const_cpu_to_le32(0); else if (ctx->inherit) securid = ntfs_inherited_id(&security, From 75da0ce302f2b40f52cd178c54f699522f1d6f4e Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Mon, 4 Jan 2016 10:08:15 +0100 Subject: [PATCH 04/18] Fix inverted usage of endian conversion macros. This is mostly a semantic issue since the end result would be the same. --- ntfsprogs/mkntfs.c | 2 +- ntfsprogs/ntfstruncate.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ntfsprogs/mkntfs.c b/ntfsprogs/mkntfs.c index 8fec2dfd..affbb919 100644 --- a/ntfsprogs/mkntfs.c +++ b/ntfsprogs/mkntfs.c @@ -2540,7 +2540,7 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name, goto err_out; } /* Set VCN pointer to 0LL. */ - *(leVCN*)((char*)re + cpu_to_le16(re->length) - sizeof(VCN)) = + *(leVCN*)((char*)re + le16_to_cpu(re->length) - sizeof(VCN)) = const_cpu_to_sle64(0); err = ntfs_mst_pre_write_fixup((NTFS_RECORD*)ia_val, index_block_size); if (err) { diff --git a/ntfsprogs/ntfstruncate.c b/ntfsprogs/ntfstruncate.c index 90b88998..9cd44c76 100644 --- a/ntfsprogs/ntfstruncate.c +++ b/ntfsprogs/ntfstruncate.c @@ -563,12 +563,12 @@ static void dump_attr_record(MFT_RECORD *m, ATTR_RECORD *a) printf("Length of resident part = %u (0x%x)\n", u, u); printf("Attribute is %sresident\n", a->non_resident ? "non-" : ""); printf("Name length = %u unicode characters\n", a->name_length); - printf("Name offset = %u (0x%x)\n", cpu_to_le16(a->name_offset), - cpu_to_le16(a->name_offset)); + printf("Name offset = %u (0x%x)\n", le16_to_cpu(a->name_offset), + le16_to_cpu(a->name_offset)); u = a->flags; if (a->name_length) { if (ucstos(s, (ntfschar*)((char*)a + - cpu_to_le16(a->name_offset)), + le16_to_cpu(a->name_offset)), min((int)sizeof(s), a->name_length + 1)) == -1) { ntfs_log_error("Could not convert Unicode string to single " From 84f042e73962e5e0a7162051d5f1814e41ef396e Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Mon, 4 Jan 2016 10:19:05 +0100 Subject: [PATCH 05/18] 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. --- libntfs-3g/reparse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libntfs-3g/reparse.c b/libntfs-3g/reparse.c index 7b96902c..ee14efbe 100644 --- a/libntfs-3g/reparse.c +++ b/libntfs-3g/reparse.c @@ -195,7 +195,7 @@ static u64 ntfs_fix_file_name(ntfs_inode *dir_ni, ntfschar *uname, uname[i] = found->file_name[i]; } else { for (i=0; ifile_name_length; i++) - uname[i] = vol->locase[found->file_name[i]]; + uname[i] = vol->locase[le16_to_cpu(found->file_name[i])]; } } } From 8aa2769d702374cd582685cb25a6b703f07865e1 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Mon, 25 Jan 2016 11:30:13 +0100 Subject: [PATCH 06/18] mst.c: Fix mixed native/little-endian usage of variable 'usn'. --- libntfs-3g/mst.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libntfs-3g/mst.c b/libntfs-3g/mst.c index 9a164390..9dff7738 100644 --- a/libntfs-3g/mst.c +++ b/libntfs-3g/mst.c @@ -157,6 +157,7 @@ int ntfs_mst_post_read_fixup(NTFS_RECORD *b, const u32 size) int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size) { u16 usa_ofs, usa_count, usn; + le16 le_usn; le16 *usa_pos, *data_pos; ntfs_log_trace("Entering\n"); @@ -189,8 +190,8 @@ int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size) usn = le16_to_cpup(usa_pos) + 1; if (usn == 0xffff || !usn) usn = 1; - usn = cpu_to_le16(usn); - *usa_pos = usn; + le_usn = cpu_to_le16(usn); + *usa_pos = le_usn; /* Position in data of first le16 that needs fixing up. */ data_pos = (le16*)b + NTFS_BLOCK_SIZE/sizeof(le16) - 1; /* Fixup all sectors. */ @@ -201,7 +202,7 @@ int ntfs_mst_pre_write_fixup(NTFS_RECORD *b, const u32 size) */ *(++usa_pos) = *data_pos; /* Apply fixup to data. */ - *data_pos = usn; + *data_pos = le_usn; /* Increment position in data as well. */ data_pos += NTFS_BLOCK_SIZE/sizeof(le16); } From 701cd61cca83d504ad5cf14d908e49b32aad18be Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Mon, 25 Jan 2016 11:31:12 +0100 Subject: [PATCH 07/18] volume.c: Fix passing bad pointer type to ntfs_is_[baad|mft]_recordp. --- libntfs-3g/volume.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libntfs-3g/volume.c b/libntfs-3g/volume.c index edd76979..dc9aa9ab 100644 --- a/libntfs-3g/volume.c +++ b/libntfs-3g/volume.c @@ -963,13 +963,13 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, ntfs_mount_flags flags) mrec = (MFT_RECORD*)(m + i * vol->mft_record_size); if (mrec->flags & MFT_RECORD_IN_USE) { - if (ntfs_is_baad_recordp(mrec)) { + if (ntfs_is_baad_recordp(&mrec->magic)) { ntfs_log_error("$MFT error: Incomplete multi " "sector transfer detected in " "'%s'.\n", s); goto io_error_exit; } - if (!ntfs_is_mft_recordp(mrec)) { + if (!ntfs_is_mft_recordp(&mrec->magic)) { ntfs_log_error("$MFT error: Invalid mft " "record for '%s'.\n", s); goto io_error_exit; @@ -977,13 +977,13 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, ntfs_mount_flags flags) } mrec2 = (MFT_RECORD*)(m2 + i * vol->mft_record_size); if (mrec2->flags & MFT_RECORD_IN_USE) { - if (ntfs_is_baad_recordp(mrec2)) { + if (ntfs_is_baad_recordp(&mrec2->magic)) { ntfs_log_error("$MFTMirr error: Incomplete " "multi sector transfer " "detected in '%s'.\n", s); goto io_error_exit; } - if (!ntfs_is_mft_recordp(mrec2)) { + if (!ntfs_is_mft_recordp(&mrec2->magic)) { ntfs_log_error("$MFTMirr error: Invalid mft " "record for '%s'.\n", s); goto io_error_exit; From 02ce4947dfdb5aa9ed936f8187faa47f506d4d20 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Tue, 26 Jan 2016 07:55:45 +0100 Subject: [PATCH 08/18] ntfs-3g.c: Fix raw usage of inode time fields without byteswapping. --- src/ntfs-3g.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ntfs-3g.c b/src/ntfs-3g.c index dc2d4454..1e56de72 100644 --- a/src/ntfs-3g.c +++ b/src/ntfs-3g.c @@ -568,7 +568,7 @@ static int ntfs_macfuse_getxtimes(const char *org_path, } /* We have no backup timestamp in NTFS. */ - crtime->tv_sec = ni->creation_time; + crtime->tv_sec = sle64_to_cpu(ni->creation_time); exit: if (ntfs_inode_close(ni)) set_fuse_error(&res); @@ -590,7 +590,7 @@ int ntfs_macfuse_setcrtime(const char *path, const struct timespec *tv) return -errno; if (tv) { - ni->creation_time = tv->tv_sec; + ni->creation_time = cpu_to_sle64(tv->tv_sec); ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME); } @@ -632,7 +632,7 @@ int ntfs_macfuse_setchgtime(const char *path, const struct timespec *tv) return -errno; if (tv) { - ni->last_mft_change_time = tv->tv_sec; + ni->last_mft_change_time = cpu_to_sle64(tv->tv_sec); ntfs_fuse_update_times(ni, 0); } From efa876d31becaf8fb55c314a36ecc2618896bb6f Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Tue, 26 Jan 2016 10:03:36 +0100 Subject: [PATCH 09/18] 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'. --- ntfsprogs/ntfstruncate.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ntfsprogs/ntfstruncate.c b/ntfsprogs/ntfstruncate.c index 9cd44c76..bfd19e0d 100644 --- a/ntfsprogs/ntfstruncate.c +++ b/ntfsprogs/ntfstruncate.c @@ -531,6 +531,7 @@ static void dump_attr_record(MFT_RECORD *m, ATTR_RECORD *a) unsigned int u; char s[0x200]; int i; + ATTR_FLAGS flags; printf("-- Beginning dump of attribute record at offset 0x%x. --\n", (unsigned)((u8*)a - (u8*)m)); @@ -565,7 +566,7 @@ static void dump_attr_record(MFT_RECORD *m, ATTR_RECORD *a) printf("Name length = %u unicode characters\n", a->name_length); printf("Name offset = %u (0x%x)\n", le16_to_cpu(a->name_offset), le16_to_cpu(a->name_offset)); - u = a->flags; + flags = a->flags; if (a->name_length) { if (ucstos(s, (ntfschar*)((char*)a + le16_to_cpu(a->name_offset)), @@ -579,17 +580,17 @@ static void dump_attr_record(MFT_RECORD *m, ATTR_RECORD *a) } printf("Name = %s\n", s); } - printf("Attribute flags = 0x%x: ", le16_to_cpu(u)); - if (!u) + printf("Attribute flags = 0x%x: ", le16_to_cpu(flags)); + if (!flags) printf("NONE"); else { int first = TRUE; - if (u & ATTR_COMPRESSION_MASK) { - if (u & ATTR_IS_COMPRESSED) { + if (flags & ATTR_COMPRESSION_MASK) { + if (flags & ATTR_IS_COMPRESSED) { printf("ATTR_IS_COMPRESSED"); first = FALSE; } - if ((u & ATTR_COMPRESSION_MASK) & ~ATTR_IS_COMPRESSED) { + if ((flags & ATTR_COMPRESSION_MASK) & ~ATTR_IS_COMPRESSED) { if (!first) printf(" | "); else @@ -597,14 +598,14 @@ static void dump_attr_record(MFT_RECORD *m, ATTR_RECORD *a) printf("ATTR_UNKNOWN_COMPRESSION"); } } - if (u & ATTR_IS_ENCRYPTED) { + if (flags & ATTR_IS_ENCRYPTED) { if (!first) printf(" | "); else first = FALSE; printf("ATTR_IS_ENCRYPTED"); } - if (u & ATTR_IS_SPARSE) { + if (flags & ATTR_IS_SPARSE) { if (!first) printf(" | "); else From 1b67b943df224cd340248476476e6f7dc55dd501 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Tue, 26 Jan 2016 10:18:51 +0100 Subject: [PATCH 10/18] 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. --- ntfsprogs/ntfstruncate.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/ntfsprogs/ntfstruncate.c b/ntfsprogs/ntfstruncate.c index bfd19e0d..f64bdbee 100644 --- a/ntfsprogs/ntfstruncate.c +++ b/ntfsprogs/ntfstruncate.c @@ -75,7 +75,7 @@ BOOL success = FALSE; char *dev_name; s64 inode; -u32 attr_type; +ATTR_TYPES attr_type; ntfschar *attr_name = NULL; u32 attr_name_len; s64 new_len; @@ -236,7 +236,7 @@ static void parse_options(int argc, char *argv[]) if (*s2 || !ul || (ul >= ULONG_MAX && errno == ERANGE)) err_exit("Invalid attribute type %s: %s\n", s, strerror(errno)); - attr_type = ul; + attr_type = cpu_to_le32(ul); /* Get the attribute name, if specified. */ s = argv[optind++]; @@ -258,7 +258,7 @@ static void parse_options(int argc, char *argv[]) attr_name_len = 0; } } - ntfs_log_verbose("attribute type = 0x%x\n", (unsigned int)attr_type); + ntfs_log_verbose("attribute type = 0x%x\n", (unsigned int)le32_to_cpu(attr_type)); if (attr_name == AT_UNNAMED) ntfs_log_verbose("attribute name = \"\" (UNNAMED)\n"); else @@ -666,7 +666,7 @@ static void dump_mft_record(MFT_RECORD *m) a = (ATTR_RECORD*)((char*)m + le16_to_cpu(m->attrs_offset)); printf("-- Beginning dump of attributes within mft record. --\n"); while ((char*)a < (char*)m + le32_to_cpu(m->bytes_in_use)) { - if (a->type == cpu_to_le32(attr_type)) + if (a->type == attr_type) dump_attr_record(m, a); if (a->type == AT_END) break; @@ -765,7 +765,7 @@ int main(int argc, char **argv) na = ntfs_attr_open(ni, attr_type, attr_name, attr_name_len); if (!na) err_exit("Failed to open attribute 0x%x: %s\n", - (unsigned int)attr_type, strerror(errno)); + (unsigned int)le32_to_cpu(attr_type), strerror(errno)); if (!opts.quiet && opts.verbose > 1) { ntfs_log_verbose("Dumping mft record before calling " From 7e9003b1470d67c7fe2e5765bd6c50325dc62a41 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Tue, 26 Jan 2016 10:19:44 +0100 Subject: [PATCH 11/18] ntfstruncate.c: Fix incorrect type for CPU-endian value in 'ucstos'. --- ntfsprogs/ntfstruncate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ntfsprogs/ntfstruncate.c b/ntfsprogs/ntfstruncate.c index f64bdbee..990c3aa1 100644 --- a/ntfsprogs/ntfstruncate.c +++ b/ntfsprogs/ntfstruncate.c @@ -286,7 +286,7 @@ static void parse_options(int argc, char *argv[]) */ static int ucstos(char *dest, const ntfschar *src, int maxlen) { - ntfschar u; + u16 u; int i; /* Need one byte for null terminator. */ From ef09702b0c4a171dc2cf1a21b88ff56d7abb2488 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Tue, 26 Jan 2016 10:28:38 +0100 Subject: [PATCH 12/18] 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. --- ntfsprogs/ntfstruncate.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/ntfsprogs/ntfstruncate.c b/ntfsprogs/ntfstruncate.c index 990c3aa1..e9970558 100644 --- a/ntfsprogs/ntfstruncate.c +++ b/ntfsprogs/ntfstruncate.c @@ -314,6 +314,7 @@ static void dump_resident_attr_val(ATTR_TYPES type, char *val, u32 val_len) const char *todo = "This is still work in progress."; char *buf; int i, j; + VOLUME_FLAGS flags; u32 u; switch (type) { @@ -356,54 +357,54 @@ static void dump_resident_attr_val(ATTR_TYPES type, char *val, u32 val_len) #define VOL_INF(x) ((VOLUME_INFORMATION *)(x)) printf("NTFS version %i.%i\n", VOL_INF(val)->major_ver, VOL_INF(val)->minor_ver); - i = VOL_INF(val)->flags; + flags = VOL_INF(val)->flags; #undef VOL_INF - printf("Volume flags = 0x%x: ", le16_to_cpu(i)); - if (!i) { + printf("Volume flags = 0x%x: ", le16_to_cpu(flags)); + if (!flags) { printf("NONE\n"); return; } j = 0; - if (i & VOLUME_MODIFIED_BY_CHKDSK) { + if (flags & VOLUME_MODIFIED_BY_CHKDSK) { j = 1; printf("VOLUME_MODIFIED_BY_CHKDSK"); } - if (i & VOLUME_REPAIR_OBJECT_ID) { + if (flags & VOLUME_REPAIR_OBJECT_ID) { if (j) printf(" | "); else j = 0; printf("VOLUME_REPAIR_OBJECT_ID"); } - if (i & VOLUME_DELETE_USN_UNDERWAY) { + if (flags & VOLUME_DELETE_USN_UNDERWAY) { if (j) printf(" | "); else j = 0; printf("VOLUME_DELETE_USN_UNDERWAY"); } - if (i & VOLUME_MOUNTED_ON_NT4) { + if (flags & VOLUME_MOUNTED_ON_NT4) { if (j) printf(" | "); else j = 0; printf("VOLUME_MOUNTED_ON_NT4"); } - if (i & VOLUME_UPGRADE_ON_MOUNT) { + if (flags & VOLUME_UPGRADE_ON_MOUNT) { if (j) printf(" | "); else j = 0; printf("VOLUME_UPGRADE_ON_MOUNT"); } - if (i & VOLUME_RESIZE_LOG_FILE) { + if (flags & VOLUME_RESIZE_LOG_FILE) { if (j) printf(" | "); else j = 0; printf("VOLUME_RESIZE_LOG_FILE"); } - if (i & VOLUME_IS_DIRTY) { + if (flags & VOLUME_IS_DIRTY) { if (j) printf(" | "); else From ec18534f318bf3f9f22d8cd3670cf1d3e612873d Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Wed, 27 Jan 2016 15:21:05 +0100 Subject: [PATCH 13/18] ntfsck.c: Fix comparison between little-endian and native-endian data. This comparison would yield the wrong result on big-endian systems. --- ntfsprogs/ntfsck.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ntfsprogs/ntfsck.c b/ntfsprogs/ntfsck.c index fee0dc3a..c1087c7c 100644 --- a/ntfsprogs/ntfsck.c +++ b/ntfsprogs/ntfsck.c @@ -608,7 +608,7 @@ static BOOL check_file_record(u8 *buffer, u16 buflen) // We should know all the flags. - if (mft_rec->flags>0xf) { + if (le16_to_cpu(mft_rec->flags) > 0xf) { check_failed("Unknown MFT record flags (0x%x).\n", (unsigned int)le16_to_cpu(mft_rec->flags)); } From 55dafda73224cdf13fcee617e31e882e1c4827df Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Wed, 27 Jan 2016 15:23:13 +0100 Subject: [PATCH 14/18] 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. --- ntfsprogs/ntfsck.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ntfsprogs/ntfsck.c b/ntfsprogs/ntfsck.c index c1087c7c..d49f3f96 100644 --- a/ntfsprogs/ntfsck.c +++ b/ntfsprogs/ntfsck.c @@ -584,7 +584,7 @@ static BOOL check_file_record(u8 *buffer, u16 buflen) ATTR_REC *attr_rec; // check record magic - assert_u32_equal(mft_rec->magic, magic_FILE, "FILE record magic"); + assert_u32_equal(le32_to_cpu(mft_rec->magic), le32_to_cpu(magic_FILE), "FILE record magic"); // todo: records 16-23 must be filled in order. // todo: what to do with magic_BAAD? From 0741f54b2ebab594dc58db6ca2bfb3c8f549e785 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Wed, 27 Jan 2016 15:24:52 +0100 Subject: [PATCH 15/18] 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). --- ntfsprogs/ntfsdump_logfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ntfsprogs/ntfsdump_logfile.c b/ntfsprogs/ntfsdump_logfile.c index 7fe22b3d..0d49aace 100644 --- a/ntfsprogs/ntfsdump_logfile.c +++ b/ntfsprogs/ntfsdump_logfile.c @@ -306,8 +306,8 @@ static void restart_header_sanity(RESTART_PAGE_HEADER *rstr, u8 *buf) "size. Cannot handle this yet.\n"); } /* Abort if the version number is not 1.1. */ - if (sle16_to_cpu(rstr->major_ver != 1) || - sle16_to_cpu(rstr->minor_ver != 1)) + if (sle16_to_cpu(rstr->major_ver) != 1 || + sle16_to_cpu(rstr->minor_ver) != 1) log_err_exit(buf, "Unknown $LogFile version %i.%i. Only know " "how to handle version 1.1.\n", sle16_to_cpu(rstr->major_ver), From 8daa92717e72a96ffc18e9cc228cadc24a5dd81b Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Wed, 27 Jan 2016 15:26:51 +0100 Subject: [PATCH 16/18] ntfsdump_logfile.c: Fix use of wrong byteswapping macro for le16 field. --- ntfsprogs/ntfsdump_logfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ntfsprogs/ntfsdump_logfile.c b/ntfsprogs/ntfsdump_logfile.c index 0d49aace..f300a5fc 100644 --- a/ntfsprogs/ntfsdump_logfile.c +++ b/ntfsprogs/ntfsdump_logfile.c @@ -633,7 +633,7 @@ rcrd_pass_loc: ntfs_log_info("page count = %i\n", le16_to_cpu(rcrd->page_count)); ntfs_log_info("page position = %i\n", le16_to_cpu(rcrd->page_position)); ntfs_log_info("header.next_record_offset = 0x%llx\n", (unsigned long long) - le64_to_cpu(rcrd->header.packed.next_record_offset)); + le16_to_cpu(rcrd->header.packed.next_record_offset)); ntfs_log_info("header.last_end_lsn = 0x%llx\n", (unsigned long long) sle64_to_cpu(rcrd->header.packed.last_end_lsn)); /* @@ -648,7 +648,7 @@ rcrd_pass_loc: client++; lr = (LOG_RECORD*)((u8*)lr + 0x70); } while (((u8*)lr + 0x70 <= (u8*)rcrd + - le64_to_cpu(rcrd->header.packed.next_record_offset))); + le16_to_cpu(rcrd->header.packed.next_record_offset))); pass++; goto rcrd_pass_loc; From 8aca3d4800488fd35d0204f394bab64c88f1abdd Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Wed, 27 Jan 2016 15:28:55 +0100 Subject: [PATCH 17/18] 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. --- ntfsprogs/ntfsmove.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ntfsprogs/ntfsmove.c b/ntfsprogs/ntfsmove.c index 0e11d48a..123041dd 100644 --- a/ntfsprogs/ntfsmove.c +++ b/ntfsprogs/ntfsmove.c @@ -319,10 +319,10 @@ static int resize_nonres_attr(MFT_RECORD *m, ATTR_RECORD *a, const u32 new_size) int old_size; u8 *ptr; - old_size = a->length; - file_size = m->bytes_in_use; + old_size = le32_to_cpu(a->length); + file_size = le32_to_cpu(m->bytes_in_use); this_attr = p2n(a)-p2n(m); - next_attr = this_attr + a->length; + next_attr = this_attr + le32_to_cpu(a->length); tail_size = file_size - next_attr; ptr = (u8*) m; @@ -337,8 +337,8 @@ static int resize_nonres_attr(MFT_RECORD *m, ATTR_RECORD *a, const u32 new_size) memmove(ptr + this_attr + new_size, ptr + next_attr, tail_size); - a->length = new_size; - m->bytes_in_use += new_size - old_size; + a->length = cpu_to_le32(new_size); + m->bytes_in_use = cpu_to_le32(le32_to_cpu(m->bytes_in_use) + (new_size - old_size)); return 0; } @@ -355,7 +355,7 @@ static int calc_attr_length(ATTR_RECORD *rec, int runlength) if (!rec->non_resident) return -1; - size = rec->mapping_pairs_offset + runlength + 7; + size = le16_to_cpu(rec->mapping_pairs_offset) + runlength + 7; size &= 0xFFF8; return size; } @@ -492,7 +492,7 @@ static int dont_move(ntfs_inode *ino) return 1; } - name = (FILE_NAME_ATTR*) ((u8*)rec + rec->value_offset); + name = (FILE_NAME_ATTR*) ((u8*)rec + le16_to_cpu(rec->value_offset)); if (ntfs_names_are_equal(ntldr, 5, name->file_name, name->file_name_length, IGNORE_CASE, ino->vol->upcase, ino->vol->upcase_len)) { ntfs_log_error("ntldr\n"); @@ -727,10 +727,10 @@ static s64 move_datarun(ntfs_volume *vol, ntfs_inode *ino, ATTR_RECORD *rec, } // wipe orig runs - memset(((u8*)rec) +rec->mapping_pairs_offset, 0, need_to - rec->mapping_pairs_offset); + memset(((u8*)rec) + le16_to_cpu(rec->mapping_pairs_offset), 0, need_to - le16_to_cpu(rec->mapping_pairs_offset)); // update data runs - ntfs_mapping_pairs_build(vol, ((u8*)rec) + rec->mapping_pairs_offset, + ntfs_mapping_pairs_build(vol, ((u8*)rec) + le16_to_cpu(rec->mapping_pairs_offset), need_to, from, 0, NULL); // commit From e37258bf01737a6bb3c9872e380e0e0cd2aa68d0 Mon Sep 17 00:00:00 2001 From: Erik Larsson Date: Thu, 28 Jan 2016 09:11:55 +0100 Subject: [PATCH 18/18] ntfscmp.c: Fix missing byteswap of little-endian attribute type value. --- ntfsprogs/ntfscmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ntfsprogs/ntfscmp.c b/ntfsprogs/ntfscmp.c index 3ac73365..555e4017 100644 --- a/ntfsprogs/ntfscmp.c +++ b/ntfsprogs/ntfscmp.c @@ -722,7 +722,7 @@ static void vprint_attribute(ATTR_TYPES atype, char *name) if (!opt.verbose) return; - printf("0x%x", atype); + printf("0x%x", le32_to_cpu(atype)); if (name) printf(":%s", name); printf(" ");