diff --git a/libntfs-3g/attrib.c b/libntfs-3g/attrib.c index 73f7937d..2180d3a5 100644 --- a/libntfs-3g/attrib.c +++ b/libntfs-3g/attrib.c @@ -163,7 +163,7 @@ s64 ntfs_get_attribute_value(const ntfs_volume *vol, * attribute. Windows does not complain about invalid flags and chkdsk * does not detect or fix them so we need to cope with it, too. */ - if (a->type != AT_ATTRIBUTE_LIST && a->flags) { + if (!le32_eq(a->type, AT_ATTRIBUTE_LIST) && a->flags) { ntfs_log_error("Non-zero (%04x) attribute flags. Cannot handle " "this yet.\n", le16_to_cpu(a->flags)); errno = EOPNOTSUPP; @@ -1838,7 +1838,7 @@ s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b) * only ATTR_IS_COMPRESSED compression mode is supported. */ if (compressed - && ((na->type != AT_DATA) + && (!le32_eq(na->type, AT_DATA) || (!le16_eq(na->data_flags & ATTR_COMPRESSION_MASK, ATTR_IS_COMPRESSED)))) { errno = EOPNOTSUPP; @@ -2773,7 +2773,7 @@ static int ntfs_attr_find(const ATTR_TYPES type, const ntfschar *name, le32_to_cpu(ctx->mrec->bytes_allocated)) break; ctx->attr = a; - if (((type != AT_UNUSED) && (le32_to_cpu(a->type) > + if ((!le32_eq(type, AT_UNUSED) && (le32_to_cpu(a->type) > le32_to_cpu(type))) || le32_eq(a->type, AT_END)) { errno = ENOENT; @@ -2784,7 +2784,7 @@ static int ntfs_attr_find(const ATTR_TYPES type, const ntfschar *name, /* If this is an enumeration return this attribute. */ if (le32_eq(type, AT_UNUSED)) return 0; - if (a->type != type) + if (!le32_eq(a->type, type)) continue; /* * If @name is AT_UNNAMED we want an unnamed attribute. @@ -3072,10 +3072,10 @@ find_attr_list_attr: break; next_al_entry = (ATTR_LIST_ENTRY*)((u8*)al_entry + le16_to_cpu(al_entry->length)); - if (type != AT_UNUSED) { + if (!le32_eq(type, AT_UNUSED)) { if (le32_to_cpu(al_entry->type) > le32_to_cpu(type)) goto not_found; - if (type != al_entry->type) + if (!le32_eq(type, al_entry->type)) continue; } al_name_len = al_entry->name_length; @@ -3191,7 +3191,7 @@ do_next_attr_loop: * attribute list entry and the attribute record, there is * corruption so we break and return error EIO. */ - if (al_entry->type != a->type) + if (!le32_eq(al_entry->type, a->type)) break; if (!ntfs_names_are_equal((ntfschar*)((char*)a + le16_to_cpu(a->name_offset)), @@ -3683,7 +3683,7 @@ int ntfs_attr_can_be_resident(const ntfs_volume *vol, const ATTR_TYPES type) errno = EINVAL; return -1; } - if (type != AT_INDEX_ALLOCATION) + if (!le32_eq(type, AT_INDEX_ALLOCATION)) return 0; ntfs_log_trace("Attribute can't be resident\n"); @@ -3851,7 +3851,7 @@ int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, base_ni = ni->base_ni; else base_ni = ni; - if (type != AT_ATTRIBUTE_LIST && NInoAttrList(base_ni)) { + if (!le32_eq(type, AT_ATTRIBUTE_LIST) && NInoAttrList(base_ni)) { if (ntfs_attrlist_entry_add(ni, a)) { err = errno; ntfs_attr_record_resize(m, a, 0); @@ -3990,7 +3990,7 @@ int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, base_ni = ni->base_ni; else base_ni = ni; - if (type != AT_ATTRIBUTE_LIST && NInoAttrList(base_ni)) { + if (!le32_eq(type, AT_ATTRIBUTE_LIST) && NInoAttrList(base_ni)) { if (ntfs_attrlist_entry_add(ni, a)) { err = errno; ntfs_log_perror("Failed add attr entry to attrlist"); @@ -4057,7 +4057,7 @@ int ntfs_attr_record_rm(ntfs_attr_search_ctx *ctx) if (ntfs_attr_record_resize(ctx->mrec, ctx->attr, 0)) { ntfs_log_trace("Couldn't remove attribute record. Bug or damaged MFT " "record.\n"); - if (NInoAttrList(base_ni) && type != AT_ATTRIBUTE_LIST) + if (NInoAttrList(base_ni) && !le32_eq(type, AT_ATTRIBUTE_LIST)) if (ntfs_attrlist_entry_add(ni, ctx->attr)) ntfs_log_trace("Rollback failed. Leaving inconstant " "metadata.\n"); @@ -4070,7 +4070,7 @@ int ntfs_attr_record_rm(ntfs_attr_search_ctx *ctx) * Remove record from $ATTRIBUTE_LIST if present and we don't want * delete $ATTRIBUTE_LIST itself. */ - if (NInoAttrList(base_ni) && type != AT_ATTRIBUTE_LIST) { + if (NInoAttrList(base_ni) && !le32_eq(type, AT_ATTRIBUTE_LIST)) { if (ntfs_attrlist_entry_rm(ctx)) { ntfs_log_trace("Couldn't delete record from " "$ATTRIBUTE_LIST.\n"); @@ -5777,7 +5777,7 @@ retry: ntfs_inode_mark_dirty(ctx->ntfs_ino); if ((ctx->ntfs_ino->nr_extents == -1 || NInoAttrList(ctx->ntfs_ino)) && - ctx->attr->type != AT_ATTRIBUTE_LIST) { + !le32_eq(ctx->attr->type, AT_ATTRIBUTE_LIST)) { ctx->al_entry->lowest_vcn = cpu_to_sle64(stop_vcn); ntfs_attrlist_mark_dirty(ctx->ntfs_ino); } @@ -6809,7 +6809,7 @@ int ntfs_attr_remove(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name, na = ntfs_attr_open(ni, type, name, name_len); if (!na) { /* do not log removal of non-existent stream */ - if (type != AT_DATA) { + if (!le32_eq(type, AT_DATA)) { ntfs_log_perror("Failed to open attribute 0x%02x of inode " "0x%llx", type, (unsigned long long)ni->mft_no); } diff --git a/libntfs-3g/inode.c b/libntfs-3g/inode.c index aa7681dd..d888adb1 100644 --- a/libntfs-3g/inode.c +++ b/libntfs-3g/inode.c @@ -1428,7 +1428,7 @@ int ntfs_inode_badclus_bad(u64 mft_no, ATTR_RECORD *attr) if (mft_no != FILE_BadClus) return 0; - if (attr->type != AT_DATA) + if (!le32_eq(attr->type, AT_DATA)) return 0; if ((ustr = ntfs_str2ucs("$Bad", &len)) == NULL) { diff --git a/ntfsprogs/mkntfs.c b/ntfsprogs/mkntfs.c index 021c0b50..3d77ed98 100644 --- a/ntfsprogs/mkntfs.c +++ b/ntfsprogs/mkntfs.c @@ -1233,7 +1233,7 @@ static int mkntfs_attr_find(const ATTR_TYPES type, const ntfschar *name, le32_to_cpu(ctx->mrec->bytes_allocated)) break; ctx->attr = a; - if (((type != AT_UNUSED) && (le32_to_cpu(a->type) > + if ((!le32_eq(type, AT_UNUSED) && (le32_to_cpu(a->type) > le32_to_cpu(type))) || le32_eq(a->type, AT_END)) { errno = ENOENT; @@ -1244,7 +1244,7 @@ static int mkntfs_attr_find(const ATTR_TYPES type, const ntfschar *name, /* If this is an enumeration return this attribute. */ if (le32_eq(type, AT_UNUSED)) return 0; - if (a->type != type) + if (!le32_eq(a->type, type)) continue; /* * If @name is AT_UNNAMED we want an unnamed attribute. @@ -1930,7 +1930,7 @@ static int add_attr_std_info(MFT_RECORD *m, const FILE_ATTR_FLAGS flags, si.version_number = cpu_to_le32(0); si.class_id = cpu_to_le32(0); si.security_id = security_id; - if (si.security_id != const_cpu_to_le32(0)) + if (!le32_eq(si.security_id, const_cpu_to_le32(0))) sd_size = 72; /* FIXME: $Quota support... */ si.owner_id = cpu_to_le32(0); @@ -2279,7 +2279,7 @@ static int add_attr_index_root(MFT_RECORD *m, const char *name, r->type = le32_eq(indexed_attr_type, AT_FILE_NAME) ? AT_FILE_NAME : const_cpu_to_le32(0); if (le32_eq(indexed_attr_type, AT_FILE_NAME) && - collation_rule != COLLATION_FILE_NAME) { + !le32_eq(collation_rule, COLLATION_FILE_NAME)) { free(r); ntfs_log_error("add_attr_index_root: indexed attribute is $FILE_NAME " "but collation rule is not COLLATION_FILE_NAME.\n"); diff --git a/ntfsprogs/ntfscat.c b/ntfsprogs/ntfscat.c index d96739c2..351faaca 100644 --- a/ntfsprogs/ntfscat.c +++ b/ntfsprogs/ntfscat.c @@ -201,7 +201,7 @@ static int parse_options(int argc, char **argv) } break; case 'a': - if (opts.attr != cpu_to_le32(-1)) { + if (!le32_eq(opts.attr, 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 (!le32_eq(opts.attr, cpu_to_le32(-1))) attr = opts.attr; result = cat(vol, inode, attr, opts.attr_name, opts.attr_name_len); diff --git a/ntfsprogs/ntfsclone.c b/ntfsprogs/ntfsclone.c index 11c6d217..90ded142 100644 --- a/ntfsprogs/ntfsclone.c +++ b/ntfsprogs/ntfsclone.c @@ -650,7 +650,7 @@ static s64 is_critical_metadata(ntfs_walk_clusters_ctx *image, runlist *rl) } } - if (image->ctx->attr->type != AT_DATA) + if (!le32_eq(image->ctx->attr->type, AT_DATA)) return rl->length; return 0; @@ -1117,7 +1117,7 @@ static void wipe_index_allocation_timestamps(ntfs_inode *ni, ATTR_RECORD *attr) return; } - if (indexr->type != AT_FILE_NAME) + if (!le32_eq(indexr->type, AT_FILE_NAME)) goto out_indexr; name = (ntfschar *)((u8 *)attr + le16_to_cpu(attr->name_offset)); @@ -1281,7 +1281,7 @@ static void wipe_resident_data(ntfs_walk_clusters_ctx *image) if (image->ni->mft_no <= LAST_METADATA_INODE) return; - if (a->type != AT_DATA) + if (!le32_eq(a->type, AT_DATA)) return; for (i = 0; i < le32_to_cpu(a->value_length); i++) { @@ -1727,7 +1727,7 @@ static void walk_runs(struct ntfs_walk_cluster *walk) } else { if ((walk->image->ni->mft_no <= LAST_METADATA_INODE) - || (walk->image->ctx->attr->type != AT_DATA)) + || !le32_eq(walk->image->ctx->attr->type, AT_DATA)) walk->image->inuse += lcn_length; } } diff --git a/ntfsprogs/ntfscmp.c b/ntfsprogs/ntfscmp.c index 3996f25e..bef7e601 100644 --- a/ntfsprogs/ntfscmp.c +++ b/ntfsprogs/ntfscmp.c @@ -770,7 +770,7 @@ static int new_attribute(ntfs_attr_search_ctx *ctx, if (!ctx->attr->non_resident) return 1; - if (prev_atype != ctx->attr->type) + if (!le32_eq(prev_atype, ctx->attr->type)) return 1; if (new_name(ctx, prev_name)) diff --git a/ntfsprogs/ntfscp.c b/ntfsprogs/ntfscp.c index bfbdc477..187ec0de 100644 --- a/ntfsprogs/ntfscp.c +++ b/ntfsprogs/ntfscp.c @@ -194,7 +194,7 @@ static int parse_options(int argc, char **argv) } break; case 'a': - if (opts.attribute != AT_DATA) { + if (!le32_eq(opts.attribute, AT_DATA)) { ntfs_log_error("You can specify only one " "attribute.\n"); err++; diff --git a/ntfsprogs/ntfsdecrypt.c b/ntfsprogs/ntfsdecrypt.c index 51bffe3d..15837d40 100644 --- a/ntfsprogs/ntfsdecrypt.c +++ b/ntfsprogs/ntfsdecrypt.c @@ -1178,7 +1178,7 @@ static ntfs_fek *ntfs_df_array_fek_get(EFS_DF_ARRAY_HEADER *df_array, (u8*)df_header + le32_to_cpu(df_header->df_length))) { df_cred = (EFS_DF_CREDENTIAL_HEADER*)((u8*)df_header + le32_to_cpu(df_header->cred_header_offset)); - if (df_cred->type != NTFS_CRED_TYPE_CERT_THUMBPRINT) { + if (!le32_eq(df_cred->type, NTFS_CRED_TYPE_CERT_THUMBPRINT)) { ntfs_log_debug("Credential type is not certificate " "thumbprint, skipping DF entry.\n"); continue; diff --git a/ntfsprogs/ntfsfix.c b/ntfsprogs/ntfsfix.c index 920e1441..fc55cc61 100644 --- a/ntfsprogs/ntfsfix.c +++ b/ntfsprogs/ntfsfix.c @@ -739,13 +739,13 @@ static ATTR_RECORD *find_unnamed_attr(MFT_RECORD *mrec, ATTR_TYPES type) /* fetch the requested attribute */ offset = le16_to_cpu(mrec->attrs_offset); a = (ATTR_RECORD*)((char*)mrec + offset); - while ((a->type != AT_END) - && ((a->type != type) || a->name_length) + while (!le32_eq(a->type, AT_END) + && (!le32_eq(a->type, type) || a->name_length) && (offset < le32_to_cpu(mrec->bytes_in_use))) { offset += le32_to_cpu(a->length); a = (ATTR_RECORD*)((char*)mrec + offset); } - if ((a->type != type) + if (!le32_eq(a->type, type) || a->name_length) a = (ATTR_RECORD*)NULL; return (a); @@ -861,7 +861,7 @@ static BOOL attrlist_selfloc_condition(struct MFT_SELF_LOCATED *selfloc) levcn = cpu_to_le64(vcn); while ((length > 0) && al->length - && ((al->type != AT_DATA) + && (!le32_eq(al->type, AT_DATA) || ((leVCN)al->lowest_vcn != levcn))) { length -= le16_to_cpu(al->length); al = (ATTR_LIST_ENTRY*) diff --git a/ntfsprogs/ntfsresize.c b/ntfsprogs/ntfsresize.c index 4f38aba8..1c69dca1 100644 --- a/ntfsprogs/ntfsresize.c +++ b/ntfsprogs/ntfsresize.c @@ -1877,7 +1877,7 @@ static void relocate_run(ntfs_resize_t *resize, runlist **rl, int run) /* Do not free the relocated MFT start */ if ((resize->mref != FILE_MFT) - || (resize->ctx->attr->type != AT_DATA) + || !le32_eq(resize->ctx->attr->type, AT_DATA) || run || !resize->new_mft_start) free(relocate_rl); @@ -1933,7 +1933,7 @@ static int is_mftdata(ntfs_resize_t *resize) * the other files. */ - if (resize->ctx->attr->type != AT_DATA) + if (!le32_eq(resize->ctx->attr->type, AT_DATA)) return 0; if (resize->mref == 0) @@ -2101,7 +2101,7 @@ static void relocate_inodes(ntfs_resize_t *resize) err_exit("Could not read the base record of MFT\n"); } while (!ntfs_attrs_walk(resize->ctx) - && (resize->ctx->attr->type != AT_DATA)) { } + && !le32_eq(resize->ctx->attr->type, AT_DATA)) { } if (le32_eq(resize->ctx->attr->type, AT_DATA)) { le64 high_le; @@ -2962,8 +2962,8 @@ static ATTR_RECORD *find_attr(MFT_RECORD *mrec, ATTR_TYPES type, offset = le16_to_cpu(mrec->attrs_offset); a = (ATTR_RECORD*)((char*)mrec + offset); attrname = (ntfschar*)((char*)a + le16_to_cpu(a->name_offset)); - while ((a->type != AT_END) - && ((a->type != type) + while (!le32_eq(a->type, AT_END) + && (!le32_eq(a->type, type) || (a->name_length != namelen) || (namelen && memcmp(attrname,name,2*namelen))) && (offset < le32_to_cpu(mrec->bytes_in_use))) { @@ -2973,7 +2973,7 @@ static ATTR_RECORD *find_attr(MFT_RECORD *mrec, ATTR_TYPES type, attrname = (ntfschar*)((char*)a + le16_to_cpu(a->name_offset)); } - if ((a->type != type) + if (!le32_eq(a->type, type) || (a->name_length != namelen) || (namelen && memcmp(attrname,name,2*namelen))) a = (ATTR_RECORD*)NULL; @@ -3009,7 +3009,7 @@ static ATTR_RECORD *get_unnamed_attr(expand_t *expand, ATTR_TYPES type, found = a && le32_eq(a->type, type) && !a->name_length; } /* not finding the attribute list is not an error */ - if (!found && (type != AT_ATTRIBUTE_LIST)) { + if (!found && !le32_eq(type, AT_ATTRIBUTE_LIST)) { err_printf("Could not find attribute 0x%lx in inode %lld\n", (long)le32_to_cpu(type), (long long)inum); a = (ATTR_RECORD*)NULL; @@ -3869,7 +3869,7 @@ static int rebase_runlists(expand_t *expand, s64 inum) mrec = expand->mrec; offset = le16_to_cpu(mrec->attrs_offset); a = (ATTR_RECORD*)((char*)mrec + offset); - while (!res && (a->type != AT_END) + while (!res && !le32_eq(a->type, AT_END) && (offset < le32_to_cpu(mrec->bytes_in_use))) { if (a->non_resident) { rl = ntfs_mapping_pairs_decompress(expand->vol, a, @@ -3954,7 +3954,7 @@ static runlist_element *rebase_runlists_meta(expand_t *expand, s64 inum) allocated_size = lth << vol->cluster_size_bits; offset = le16_to_cpu(mrec->attrs_offset); a = (ATTR_RECORD*)((char*)mrec + offset); - while (!res && (a->type != AT_END) + while (!res && !le32_eq(a->type, AT_END) && (offset < le32_to_cpu(mrec->bytes_in_use))) { if (a->non_resident) { keeprl = FALSE; @@ -3965,7 +3965,7 @@ static runlist_element *rebase_runlists_meta(expand_t *expand, s64 inum) for (prl=rl; prl->length; prl++) if (prl->lcn >= 0) { prl->lcn += expand->cluster_increment; - if ((a->type != AT_DATA) + if (!le32_eq(a->type, AT_DATA) && set_bitmap(expand,prl)) res = -1; }