diff --git a/include/ntfs-3g/endians.h b/include/ntfs-3g/endians.h index a010b1a2..e425f4d7 100644 --- a/include/ntfs-3g/endians.h +++ b/include/ntfs-3g/endians.h @@ -320,4 +320,6 @@ #define be16_cmpz(a) (!(a)) +#define le16_andz(a, b) (!((a) & (b))) + #endif /* defined _NTFS_ENDIANS_H */ diff --git a/libntfs-3g/acls.c b/libntfs-3g/acls.c index a6eb51ac..78034054 100644 --- a/libntfs-3g/acls.c +++ b/libntfs-3g/acls.c @@ -687,12 +687,12 @@ BOOL ntfs_valid_descr(const char *securattr, unsigned int attrsz) * but "Dr Watson" has SE_DACL_PRESENT though no DACL */ && (!offdacl - || ((phead->control & SE_DACL_PRESENT) + || (!le16_andz(phead->control, SE_DACL_PRESENT) && ((pdacl->revision == ACL_REVISION) || (pdacl->revision == ACL_REVISION_DS)))) /* same for SACL */ && (!offsacl - || ((phead->control & SE_SACL_PRESENT) + || (!le16_andz(phead->control, SE_SACL_PRESENT) && ((psacl->revision == ACL_REVISION) || (psacl->revision == ACL_REVISION_DS))))) { /* diff --git a/libntfs-3g/attrib.c b/libntfs-3g/attrib.c index c209c08a..48276277 100644 --- a/libntfs-3g/attrib.c +++ b/libntfs-3g/attrib.c @@ -357,7 +357,7 @@ void ntfs_attr_init(ntfs_attr *na, const BOOL non_resident, na->data_flags = data_flags; if (non_resident) NAttrSetNonResident(na); - if (data_flags & ATTR_COMPRESSION_MASK) + if (!le16_andz(data_flags, ATTR_COMPRESSION_MASK)) NAttrSetCompressed(na); if (encrypted) NAttrSetEncrypted(na); @@ -366,7 +366,7 @@ void ntfs_attr_init(ntfs_attr *na, const BOOL non_resident, na->allocated_size = allocated_size; na->data_size = data_size; na->initialized_size = initialized_size; - if ((data_flags & ATTR_COMPRESSION_MASK) || sparse) { + if (!le16_andz(data_flags, ATTR_COMPRESSION_MASK) || sparse) { ntfs_volume *vol = na->ni->vol; na->compressed_size = compressed_size; @@ -479,7 +479,7 @@ ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type, /* a file may be sparse though its unnamed data is not (cf $UsnJrnl) */ if (le32_eq(na->type, AT_DATA) && na->name == AT_UNNAMED && - (((a->flags & ATTR_IS_SPARSE) && !NAttrSparse(na)) || + ((!le16_andz(a->flags, ATTR_IS_SPARSE) && !NAttrSparse(na)) || (!(a->flags & ATTR_IS_ENCRYPTED) != !NAttrEncrypted(na)))) { errno = EIO; ntfs_log_perror("Inode %lld has corrupt attribute flags " @@ -489,7 +489,7 @@ ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type, } if (a->non_resident) { - if ((a->flags & ATTR_COMPRESSION_MASK) + if (!le16_andz(a->flags, ATTR_COMPRESSION_MASK) && !a->compression_unit) { errno = EIO; ntfs_log_perror("Compressed inode %lld attr 0x%x has " @@ -498,8 +498,8 @@ ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type, goto put_err_out; } ntfs_attr_init(na, TRUE, a->flags, - a->flags & ATTR_IS_ENCRYPTED, - a->flags & ATTR_IS_SPARSE, + !le16_andz(a->flags, ATTR_IS_ENCRYPTED), + !le16_andz(a->flags, ATTR_IS_SPARSE), sle64_to_cpu(a->allocated_size), sle64_to_cpu(a->data_size), sle64_to_cpu(a->initialized_size), @@ -508,8 +508,8 @@ ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type, } else { s64 l = le32_to_cpu(a->value_length); ntfs_attr_init(na, FALSE, a->flags, - a->flags & ATTR_IS_ENCRYPTED, - a->flags & ATTR_IS_SPARSE, (l + 7) & ~7, l, l, + !le16_andz(a->flags, ATTR_IS_ENCRYPTED), + !le16_andz(a->flags, ATTR_IS_SPARSE), (l + 7) & ~7, l, l, !le16_cmpz(cs) ? (l + 7) & ~7 : 0, 0); } ntfs_attr_put_search_ctx(ctx); @@ -942,7 +942,7 @@ static s64 ntfs_attr_pread_i(ntfs_attr *na, const s64 pos, s64 count, void *b) /* Sanity checking arguments is done in ntfs_attr_pread(). */ - if ((na->data_flags & ATTR_COMPRESSION_MASK) && NAttrNonResident(na)) { + if (!le16_andz(na->data_flags, ATTR_COMPRESSION_MASK) && NAttrNonResident(na)) { if (le16_eq(na->data_flags & ATTR_COMPRESSION_MASK, ATTR_IS_COMPRESSED)) return ntfs_compressed_attr_pread(na, pos, count, b); @@ -973,7 +973,7 @@ static s64 ntfs_attr_pread_i(ntfs_attr *na, const s64 pos, s64 count, void *b) max_read = na->data_size; max_init = na->initialized_size; if (na->ni->vol->efs_raw - && (na->data_flags & ATTR_IS_ENCRYPTED) + && !le16_andz(na->data_flags, ATTR_IS_ENCRYPTED) && NAttrNonResident(na)) { if (na->data_size != na->initialized_size) { ntfs_log_error("uninitialized encrypted file not supported\n"); @@ -1031,7 +1031,7 @@ res_err_out: * restored */ if (na->ni->vol->efs_raw && - (na->data_flags & ATTR_IS_ENCRYPTED) && + !le16_andz(na->data_flags, ATTR_IS_ENCRYPTED) && ((pos + count) > max_init-2)) { efs_padding_length = 511 - ((na->data_size - 1) & 511); if (pos+count == max_init) { @@ -1303,7 +1303,7 @@ static int ntfs_attr_fill_hole(ntfs_attr *na, s64 count, s64 *ofs, * not be desirable for files which can * be updated */ - if (na->data_flags & ATTR_COMPRESSION_MASK) + if (!le16_andz(na->data_flags, ATTR_COMPRESSION_MASK)) lcn_seek_from = rlc->lcn + rlc->length; else lcn_seek_from = rlc->lcn + (from_vcn - rlc->vcn); @@ -1326,7 +1326,7 @@ static int ntfs_attr_fill_hole(ntfs_attr *na, s64 count, s64 *ofs, need = ((*ofs + to_write - 1) >> vol->cluster_size_bits) + 1 + (*rl)->vcn - from_vcn; - if ((na->data_flags & ATTR_COMPRESSION_MASK) + if (!le16_andz(na->data_flags, ATTR_COMPRESSION_MASK) && (need < na->compression_block_clusters)) { /* * for a compressed file, be sure to allocate the full @@ -1358,7 +1358,7 @@ static int ntfs_attr_fill_hole(ntfs_attr *na, s64 count, s64 *ofs, lcn_seek_from, DATA_ZONE); if (!rlc) goto err_out; - if (na->data_flags & (ATTR_COMPRESSION_MASK | ATTR_IS_SPARSE)) + if (!le16_andz(na->data_flags, ATTR_COMPRESSION_MASK | ATTR_IS_SPARSE)) na->compressed_size += need << vol->cluster_size_bits; *rl = ntfs_runlists_merge(na->rl, rlc); @@ -1367,7 +1367,7 @@ static int ntfs_attr_fill_hole(ntfs_attr *na, s64 count, s64 *ofs, * For a compressed attribute, we must be sure there are two * available entries, so reserve them before it gets too late. */ - if (*rl && (na->data_flags & ATTR_COMPRESSION_MASK)) { + if (*rl && !le16_andz(na->data_flags, ATTR_COMPRESSION_MASK)) { runlist_element *oldrl = na->rl; na->rl = *rl; *rl = ntfs_rl_extend(na,*rl,2); @@ -1817,7 +1817,7 @@ s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b) * access denied, which is what Windows NT4 does, too. * Moreover a file cannot be both encrypted and compressed. */ - if ((na->data_flags & ATTR_IS_ENCRYPTED) + if (!le16_andz(na->data_flags, ATTR_IS_ENCRYPTED) && (compressed || !vol->efs_raw)) { errno = EACCES; goto errno_set; @@ -2023,7 +2023,7 @@ s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count, const void *b) } na->initialized_size = pos + count; #if CACHE_NIDATA_SIZE - if (na->ni->mrec->flags & MFT_RECORD_IS_DIRECTORY + if (!le16_andz(na->ni->mrec->flags, MFT_RECORD_IS_DIRECTORY) ? le32_eq(na->type, AT_INDEX_ROOT) && na->name == NTFS_INDEX_I30 : le32_eq(na->type, AT_DATA) && na->name == AT_UNNAMED) { na->ni->data_size = na->data_size; @@ -2479,7 +2479,7 @@ retry: if (!NVolReadOnly(vol)) { failed = ntfs_compressed_close(na, rl, ofs, &update_from); #if CACHE_NIDATA_SIZE - if (na->ni->mrec->flags & MFT_RECORD_IS_DIRECTORY + if (!le16_andz(na->ni->mrec->flags, MFT_RECORD_IS_DIRECTORY) ? le32_eq(na->type, AT_INDEX_ROOT) && na->name == NTFS_INDEX_I30 : le32_eq(na->type, AT_DATA) && na->name == AT_UNNAMED) { na->ni->data_size = na->data_size; @@ -3860,7 +3860,7 @@ int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, goto put_err_out; } } - if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY + if (!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY) ? le32_eq(type, AT_INDEX_ROOT) && name == NTFS_INDEX_I30 : le32_eq(type, AT_DATA) && name == AT_UNNAMED) { ni->data_size = size; @@ -3950,7 +3950,7 @@ int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, dataruns_size = (dataruns_size + 7) & ~7; length = offsetof(ATTR_RECORD, compressed_size) + ((sizeof(ntfschar) * name_len + 7) & ~7) + dataruns_size + - ((flags & (ATTR_IS_COMPRESSED | ATTR_IS_SPARSE)) ? + (!le16_andz(flags, ATTR_IS_COMPRESSED | ATTR_IS_SPARSE) ? sizeof(a->compressed_size) : 0); if (ntfs_make_room_for_attr(ctx->mrec, (u8*) ctx->attr, length)) { err = errno; @@ -3964,13 +3964,13 @@ int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type, a->non_resident = 1; a->name_length = name_len; a->name_offset = cpu_to_le16(offsetof(ATTR_RECORD, compressed_size) + - ((flags & (ATTR_IS_COMPRESSED | ATTR_IS_SPARSE)) ? + (!le16_andz(flags, ATTR_IS_COMPRESSED | ATTR_IS_SPARSE) ? sizeof(a->compressed_size) : 0)); a->flags = flags; a->instance = m->next_attr_instance; a->lowest_vcn = cpu_to_sle64(lowest_vcn); a->mapping_pairs_offset = cpu_to_le16(length - dataruns_size); - a->compression_unit = (flags & ATTR_IS_COMPRESSED) + a->compression_unit = !le16_andz(flags, ATTR_IS_COMPRESSED) ? STANDARD_COMPRESSION_UNIT : 0; /* If @lowest_vcn == 0, than setup empty attribute. */ if (!lowest_vcn) { @@ -4997,14 +4997,14 @@ static int ntfs_resident_attr_resize_i(ntfs_attr *na, const s64 newsize, /* Update attribute size everywhere. */ na->data_size = na->initialized_size = newsize; na->allocated_size = (newsize + 7) & ~7; - if ((na->data_flags & ATTR_COMPRESSION_MASK) + if (!le16_andz(na->data_flags, ATTR_COMPRESSION_MASK) || NAttrSparse(na)) na->compressed_size = na->allocated_size; - if (na->ni->mrec->flags & MFT_RECORD_IS_DIRECTORY + if (!le16_andz(na->ni->mrec->flags, MFT_RECORD_IS_DIRECTORY) ? le32_eq(na->type, AT_INDEX_ROOT) && na->name == NTFS_INDEX_I30 : le32_eq(na->type, AT_DATA) && na->name == AT_UNNAMED) { na->ni->data_size = na->data_size; - if (((na->data_flags & ATTR_COMPRESSION_MASK) + if ((!le16_andz(na->data_flags, ATTR_COMPRESSION_MASK) || NAttrSparse(na)) && NAttrNonResident(na)) na->ni->allocated_size @@ -5291,7 +5291,7 @@ static int ntfs_attr_make_resident(ntfs_attr *na, ntfs_attr_search_ctx *ctx) if (ntfs_attr_can_be_resident(vol, na->type)) return -1; - if (na->data_flags & ATTR_IS_ENCRYPTED) { + if (!le16_andz(na->data_flags, ATTR_IS_ENCRYPTED)) { ntfs_log_trace("Making encrypted streams resident is not " "implemented yet.\n"); errno = EOPNOTSUPP; @@ -5494,7 +5494,7 @@ static int ntfs_attr_update_meta(ATTR_RECORD *a, ntfs_attr *na, MFT_RECORD *m, } /* Attribute no longer sparse. */ - if (!sparse && (a->flags & ATTR_IS_SPARSE) && + if (!sparse && !le16_andz(a->flags, ATTR_IS_SPARSE) && !(a->flags & ATTR_IS_COMPRESSED)) { NAttrClearSparse(na); @@ -5515,7 +5515,7 @@ static int ntfs_attr_update_meta(ATTR_RECORD *a, ntfs_attr *na, MFT_RECORD *m, /* Update compressed size if required. */ if (NAttrFullyMapped(na) - && (sparse || (na->data_flags & ATTR_COMPRESSION_MASK))) { + && (sparse || !le16_andz(na->data_flags, ATTR_COMPRESSION_MASK))) { s64 new_compr_size; new_compr_size = ntfs_rl_get_compressed_size(na->ni->vol, na->rl); @@ -5530,7 +5530,7 @@ static int ntfs_attr_update_meta(ATTR_RECORD *a, ntfs_attr *na, MFT_RECORD *m, * allocated size in the index. */ if (le32_eq(na->type, AT_DATA) && na->name == AT_UNNAMED) { - if (sparse || (na->data_flags & ATTR_COMPRESSION_MASK)) + if (sparse || !le16_andz(na->data_flags, ATTR_COMPRESSION_MASK)) na->ni->allocated_size = na->compressed_size; else na->ni->allocated_size = na->allocated_size; @@ -5888,7 +5888,7 @@ retry: cur_max_mp_size = le32_to_cpu(m->bytes_allocated) - le32_to_cpu(m->bytes_in_use) - (offsetof(ATTR_RECORD, compressed_size) + - (((na->data_flags & ATTR_COMPRESSION_MASK) + ((!le16_andz(na->data_flags, ATTR_COMPRESSION_MASK) || NAttrSparse(na)) ? sizeof(a->compressed_size) : 0)) - ((sizeof(ntfschar) * na->name_len + 7) & ~7); @@ -6015,7 +6015,7 @@ static int ntfs_non_resident_attr_shrink(ntfs_attr *na, const s64 newsize) } /* The first cluster outside the new allocation. */ - if (na->data_flags & ATTR_COMPRESSION_MASK) + if (!le16_andz(na->data_flags, ATTR_COMPRESSION_MASK)) /* * For compressed files we must keep full compressions blocks, * but currently we do not decompress/recompress the last @@ -6094,7 +6094,7 @@ static int ntfs_non_resident_attr_shrink(ntfs_attr *na, const s64 newsize) ctx->attr->initialized_size = cpu_to_sle64(newsize); } /* Update data size in the index. */ - if (na->ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { + if (!le16_andz(na->ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)) { if (le32_eq(na->type, AT_INDEX_ROOT) && na->name == NTFS_INDEX_I30) { na->ni->data_size = na->data_size; na->ni->allocated_size = na->allocated_size; @@ -6326,7 +6326,7 @@ static int ntfs_non_resident_attr_expand_i(ntfs_attr *na, const s64 newsize, na->data_size = newsize; ctx->attr->data_size = cpu_to_sle64(newsize); /* Update data size in the index. */ - if (na->ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { + if (!le16_andz(na->ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)) { if (le32_eq(na->type, AT_INDEX_ROOT) && na->name == NTFS_INDEX_I30) { na->ni->data_size = na->data_size; na->ni->allocated_size = na->allocated_size; @@ -6438,7 +6438,7 @@ static int ntfs_attr_truncate_i(ntfs_attr *na, const s64 newsize, * Encrypted attributes are not supported. We return access denied, * which is what Windows NT4 does, too. */ - if ((na->data_flags & ATTR_IS_ENCRYPTED) && !na->ni->vol->efs_raw) { + if (!le16_andz(na->data_flags, ATTR_IS_ENCRYPTED) && !na->ni->vol->efs_raw) { errno = EACCES; ntfs_log_trace("Cannot truncate encrypted attribute\n"); goto out; diff --git a/libntfs-3g/dir.c b/libntfs-3g/dir.c index 528e7ad9..47451544 100644 --- a/libntfs-3g/dir.c +++ b/libntfs-3g/dir.c @@ -311,7 +311,7 @@ u64 ntfs_inode_lookup_by_name(ntfs_inode *dir_ni, * The last entry cannot contain a name. It can however contain * a pointer to a child node in the B+tree so we just break out. */ - if (ie->ie_flags & INDEX_ENTRY_END) + if (!le16_andz(ie->ie_flags, INDEX_ENTRY_END)) break; if (!le16_to_cpu(ie->length)) { @@ -450,7 +450,7 @@ descend_into_child_node: * The last entry cannot contain a name. It can however contain * a pointer to a child node in the B+tree so we just break out. */ - if (ie->ie_flags & INDEX_ENTRY_END) + if (!le16_andz(ie->ie_flags, INDEX_ENTRY_END)) break; if (!le16_to_cpu(ie->length)) { @@ -487,7 +487,7 @@ descend_into_child_node: * We have finished with this index buffer without success. Check for * the presence of a child node. */ - if (ie->ie_flags & INDEX_ENTRY_NODE) { + if (!le16_andz(ie->ie_flags, INDEX_ENTRY_NODE)) { if ((ia->index.ih_flags & NODE_MASK) == LEAF_NODE) { ntfs_log_error("Index entry with child node found in a leaf " "node in directory inode %lld.\n", @@ -1244,7 +1244,7 @@ int ntfs_readdir(ntfs_inode *dir_ni, s64 *pos, index_end) goto dir_err_out; /* The last entry cannot contain a name. */ - if (ie->ie_flags & INDEX_ENTRY_END) + if (!le16_andz(ie->ie_flags, INDEX_ENTRY_END)) break; if (!le16_to_cpu(ie->length)) @@ -1400,7 +1400,7 @@ find_next_index_buffer: goto dir_err_out; } /* The last entry cannot contain a name. */ - if (ie->ie_flags & INDEX_ENTRY_END) + if (!le16_andz(ie->ie_flags, INDEX_ENTRY_END)) break; if (!le16_to_cpu(ie->length)) @@ -1690,7 +1690,7 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid, fn->last_data_change_time = ni->last_data_change_time; 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) + if (!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)) fn->data_size = fn->allocated_size = const_cpu_to_le64(0); else { fn->data_size = cpu_to_sle64(ni->data_size); @@ -2184,7 +2184,7 @@ static int ntfs_link_i(ntfs_inode *ni, ntfs_inode *dir_ni, const ntfschar *name, fn->file_name_length = name_len; fn->file_name_type = nametype; fn->file_attributes = ni->flags; - if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { + if (!le16_andz(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); } else { diff --git a/libntfs-3g/index.c b/libntfs-3g/index.c index e9bf6b22..d372c3e1 100644 --- a/libntfs-3g/index.c +++ b/libntfs-3g/index.c @@ -222,7 +222,7 @@ static u8 *ntfs_ie_get_end(INDEX_HEADER *ih) static int ntfs_ie_end(INDEX_ENTRY *ie) { - return ie->ie_flags & INDEX_ENTRY_END || le16_cmpz(ie->length); + return !le16_andz(ie->ie_flags, INDEX_ENTRY_END) || le16_cmpz(ie->length); } /** @@ -376,7 +376,7 @@ static INDEX_ENTRY *ntfs_ie_dup_novcn(INDEX_ENTRY *ie) ntfs_log_trace("Entering\n"); - if (ie->ie_flags & INDEX_ENTRY_NODE) + if (!le16_andz(ie->ie_flags, INDEX_ENTRY_NODE)) size -= sizeof(VCN); dup = ntfs_malloc(size); @@ -1077,7 +1077,7 @@ static int ntfs_ib_cut_tail(ntfs_index_context *icx, INDEX_BLOCK *ib, ies_end = (char *)ntfs_ie_get_end(&ib->index); ie_last = ntfs_ie_get_last((INDEX_ENTRY *)ies_start, ies_end); - if (ie_last->ie_flags & INDEX_ENTRY_NODE) + if (!le16_andz(ie_last->ie_flags, INDEX_ENTRY_NODE)) ntfs_ie_set_vcn(ie_last, ntfs_ie_get_vcn(ie)); memcpy(ie, ie_last, le16_to_cpu(ie_last->length)); @@ -1816,7 +1816,7 @@ int ntfs_index_rm(ntfs_index_context *icx) else ih = &icx->ib->index; - if (icx->entry->ie_flags & INDEX_ENTRY_NODE) { + if (!le16_andz(icx->entry->ie_flags, INDEX_ENTRY_NODE)) { ret = ntfs_index_rm_node(icx); @@ -1955,7 +1955,7 @@ static INDEX_ENTRY *ntfs_index_walk_down(INDEX_ENTRY *ie, entry = ictx->entry; } else entry = (INDEX_ENTRY*)NULL; - } while (entry && (entry->ie_flags & INDEX_ENTRY_NODE)); + } while (entry && !le16_andz(entry->ie_flags, INDEX_ENTRY_NODE)); return (entry); } @@ -2006,7 +2006,7 @@ static INDEX_ENTRY *ntfs_index_walk_up(INDEX_ENTRY *ie, } ictx->entry = entry; } while (entry && (ictx->pindex > 0) - && (entry->ie_flags & INDEX_ENTRY_END)); + && !le16_andz(entry->ie_flags, INDEX_ENTRY_END)); } else entry = (INDEX_ENTRY*)NULL; return (entry); @@ -2050,7 +2050,7 @@ INDEX_ENTRY *ntfs_index_next(INDEX_ENTRY *ie, ntfs_index_context *ictx) * if this happens, walk up */ - if (ie->ie_flags & INDEX_ENTRY_END) + if (!le16_andz(ie->ie_flags, INDEX_ENTRY_END)) next = ntfs_index_walk_up(ie, ictx); else { /* @@ -2064,20 +2064,20 @@ INDEX_ENTRY *ntfs_index_next(INDEX_ENTRY *ie, ntfs_index_context *ictx) /* walk down if it has a subnode */ - if (flags & INDEX_ENTRY_NODE) { + if (!le16_andz(flags, INDEX_ENTRY_NODE)) { next = ntfs_index_walk_down(next,ictx); } else { /* walk up it has no subnode, nor data */ - if (flags & INDEX_ENTRY_END) { + if (!le16_andz(flags, INDEX_ENTRY_END)) { next = ntfs_index_walk_up(next, ictx); } } } /* return NULL if stuck at end of a block */ - if (next && (next->ie_flags & INDEX_ENTRY_END)) + if (next && !le16_andz(next->ie_flags, INDEX_ENTRY_END)) next = (INDEX_ENTRY*)NULL; return (next); } diff --git a/libntfs-3g/inode.c b/libntfs-3g/inode.c index 2d01578f..b1c5f739 100644 --- a/libntfs-3g/inode.c +++ b/libntfs-3g/inode.c @@ -259,8 +259,8 @@ get_size: } else { if (ctx->attr->non_resident) { ni->data_size = sle64_to_cpu(ctx->attr->data_size); - if (ctx->attr->flags & - (ATTR_IS_COMPRESSED | ATTR_IS_SPARSE)) + if (!le16_andz(ctx->attr->flags, + (ATTR_IS_COMPRESSED | ATTR_IS_SPARSE))) ni->allocated_size = sle64_to_cpu( ctx->attr->compressed_size); else @@ -872,7 +872,7 @@ static int ntfs_inode_sync_file_name(ntfs_inode *ni, ntfs_inode *dir_ni) fnx->file_attributes = (fnx->file_attributes & ~FILE_ATTR_VALID_FLAGS) | (ni->flags & FILE_ATTR_VALID_FLAGS); - if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) + if (!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)) fnx->data_size = fnx->allocated_size = const_cpu_to_le64(0); else { @@ -956,7 +956,7 @@ static int ntfs_inode_sync_in_dir(ntfs_inode *ni, ntfs_inode *dir_ni) ntfs_log_enter("Entering for inode %lld\n", (long long)ni->mft_no); /* Update STANDARD_INFORMATION. */ - if ((ni->mrec->flags & MFT_RECORD_IN_USE) && ni->nr_extents != -1 && + if (!le16_andz(ni->mrec->flags, MFT_RECORD_IN_USE) && ni->nr_extents != -1 && ntfs_inode_sync_standard_information(ni)) { if (!err || errno == EIO) { err = errno; @@ -966,7 +966,7 @@ static int ntfs_inode_sync_in_dir(ntfs_inode *ni, ntfs_inode *dir_ni) } /* Update FILE_NAME's in the index. */ - if ((ni->mrec->flags & MFT_RECORD_IN_USE) && ni->nr_extents != -1 && + if (!le16_andz(ni->mrec->flags, MFT_RECORD_IN_USE) && ni->nr_extents != -1 && NInoFileNameTestAndClearDirty(ni) && ntfs_inode_sync_file_name(ni, dir_ni)) { if (!err || errno == EIO) { @@ -980,7 +980,7 @@ static int ntfs_inode_sync_in_dir(ntfs_inode *ni, ntfs_inode *dir_ni) } /* Write out attribute list from cache to disk. */ - if ((ni->mrec->flags & MFT_RECORD_IN_USE) && ni->nr_extents != -1 && + if (!le16_andz(ni->mrec->flags, MFT_RECORD_IN_USE) && ni->nr_extents != -1 && NInoAttrList(ni) && NInoAttrListTestAndClearDirty(ni)) { ntfs_attr *na; diff --git a/libntfs-3g/mft.c b/libntfs-3g/mft.c index 4263fbc6..3ea07816 100644 --- a/libntfs-3g/mft.c +++ b/libntfs-3g/mft.c @@ -1443,7 +1443,7 @@ found_free_rec: /* Sanity check that the mft record is really not in use. */ if (!forced_mft_data && (ntfs_is_file_record(m->magic) - && (m->flags & MFT_RECORD_IN_USE))) { + && !le16_andz(m->flags, MFT_RECORD_IN_USE))) { ntfs_log_error("Inode %lld is used but it wasn't marked in " "$MFT bitmap. Fixed.\n", (long long)bit); free(m); @@ -1747,7 +1747,7 @@ found_free_rec: goto undo_mftbmp_alloc; } /* Sanity check that the mft record is really not in use. */ - if (ntfs_is_file_record(m->magic) && (m->flags & MFT_RECORD_IN_USE)) { + if (ntfs_is_file_record(m->magic) && !le16_andz(m->flags, MFT_RECORD_IN_USE)) { ntfs_log_error("Inode %lld is used but it wasn't marked in " "$MFT bitmap. Fixed.\n", (long long)bit); free(m); diff --git a/libntfs-3g/reparse.c b/libntfs-3g/reparse.c index 86d8c5e6..d4111ab5 100644 --- a/libntfs-3g/reparse.c +++ b/libntfs-3g/reparse.c @@ -169,7 +169,7 @@ static u64 ntfs_fix_file_name(ntfs_inode *dir_ni, ntfschar *uname, * We generally only get the first matching candidate, * so we still have to check whether this is a real match */ - if (icx->entry && (icx->entry->ie_flags & INDEX_ENTRY_END)) + if (icx->entry && !le16_andz(icx->entry->ie_flags, INDEX_ENTRY_END)) /* get next entry if reaching end of block */ entry = ntfs_index_next(icx->entry, icx); else @@ -252,11 +252,11 @@ static char *search_absolute(ntfs_volume *vol, ntfschar *path, path[start++] = const_cpu_to_le16('/'); } } while (ni - && (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) + && !le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY) && !(ni->flags & FILE_ATTR_REPARSE_POINT) && (start < count)); if (ni - && ((ni->mrec->flags & MFT_RECORD_IS_DIRECTORY ? isdir : !isdir) + && ((!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY) ? isdir : !isdir) || (ni->flags & FILE_ATTR_REPARSE_POINT))) if (ntfs_ucstombs(path, count, &target, 0) < 0) { if (target) { @@ -358,8 +358,8 @@ static char *search_relative(ntfs_inode *ni, ntfschar *path, int count) } else { pos += lth; if (!morelinks - && (ni->mrec->flags ^ curni->mrec->flags) - & MFT_RECORD_IS_DIRECTORY) + && !le16_andz(ni->mrec->flags ^ curni->mrec->flags, + MFT_RECORD_IS_DIRECTORY)) ok = FALSE; if (ntfs_inode_close(curni)) ok = FALSE; diff --git a/libntfs-3g/security.c b/libntfs-3g/security.c index 1c34546c..c49ee9c1 100644 --- a/libntfs-3g/security.c +++ b/libntfs-3g/security.c @@ -873,7 +873,7 @@ static le32 setsecurityattr(ntfs_volume *vol, * lookup() may return a node with no data, * if so get next */ - if (entry->ie_flags & INDEX_ENTRY_END) + if (!le16_andz(entry->ie_flags, INDEX_ENTRY_END)) entry = ntfs_index_next(entry,xsdh); do { collision = FALSE; @@ -1685,7 +1685,7 @@ static struct CACHED_PERMISSIONS *enter_cache(struct SECURITY_CONTEXT *scx, } else { cacheentry = (struct CACHED_PERMISSIONS*)NULL; #if CACHE_LEGACY_SIZE - if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { + if (!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)) { struct CACHED_PERMISSIONS_LEGACY wanted; struct CACHED_PERMISSIONS_LEGACY *legacy; @@ -1768,7 +1768,7 @@ static struct CACHED_PERMISSIONS *fetch_cache(struct SECURITY_CONTEXT *scx, #if CACHE_LEGACY_SIZE else { cacheentry = (struct CACHED_PERMISSIONS*)NULL; - if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { + if (!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)) { struct CACHED_PERMISSIONS_LEGACY wanted; struct CACHED_PERMISSIONS_LEGACY *legacy; @@ -3214,7 +3214,7 @@ int ntfs_set_ntfs_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, * For safety, invalidate even if updating * failed. */ - if ((ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) + if (!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY) && le32_cmpz(ni->security_id)) { struct CACHED_PERMISSIONS_LEGACY legacy; @@ -3450,7 +3450,7 @@ int ntfs_allowed_access(struct SECURITY_CONTEXT *scx, if (!scx->mapping[MAPUSERS] || (!scx->uid && (!(accesstype & S_IEXEC) - || (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)))) + || !le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)))) allow = 1; else { perm = ntfs_get_perm(scx, ni, accesstype); @@ -4390,7 +4390,7 @@ int ntfs_get_ntfs_attrib(ntfs_inode *ni, char *value, size_t size) outsize = 0; /* default to no data and no error */ if (ni) { attrib = le32_to_cpu(ni->flags); - if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) + if (!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)) attrib |= const_le32_to_cpu(FILE_ATTR_DIRECTORY); else attrib &= ~const_le32_to_cpu(FILE_ATTR_DIRECTORY); @@ -4429,7 +4429,7 @@ int ntfs_set_ntfs_attrib(ntfs_inode *ni, memcpy(&attrib,value,sizeof(FILE_ATTR_FLAGS)); settable = FILE_ATTR_SETTABLE; res = 0; - if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { + if (!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)) { /* * Accept changing compression for a directory * and set index root accordingly @@ -4737,7 +4737,7 @@ static BOOL mergesecurityattr(ntfs_volume *vol, const char *oldattr, & (SE_DACL_PRESENT | SE_DACL_DEFAULTED | SE_DACL_PROTECTED); - if (newhead->control & SE_DACL_AUTO_INHERIT_REQ) + if (!le16_andz(newhead->control, SE_DACL_AUTO_INHERIT_REQ)) control |= SE_DACL_AUTO_INHERITED; } else control |= oldhead->control @@ -4769,7 +4769,7 @@ static BOOL mergesecurityattr(ntfs_volume *vol, const char *oldattr, & (SE_SACL_PRESENT | SE_SACL_DEFAULTED | SE_SACL_PROTECTED); - if (newhead->control & SE_SACL_AUTO_INHERIT_REQ) + if (!le16_andz(newhead->control, SE_SACL_AUTO_INHERIT_REQ)) control |= SE_SACL_AUTO_INHERITED; } else control |= oldhead->control @@ -4932,7 +4932,7 @@ int ntfs_set_file_security(struct SECURITY_API *scapi, && le32_cmpz(phead->group) && !(phead->control & SE_GROUP_DEFAULTED)); if (!missing - && (phead->control & SE_SELF_RELATIVE) + && !le16_andz(phead->control, SE_SELF_RELATIVE) && ntfs_valid_descr(attr, attrsz)) { ni = ntfs_pathname_to_inode(scapi->security.vol, NULL, path); @@ -4987,7 +4987,7 @@ int ntfs_get_file_attributes(struct SECURITY_API *scapi, const char *path) ni = ntfs_pathname_to_inode(scapi->security.vol, NULL, path); if (ni) { attrib = le32_to_cpu(ni->flags); - if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) + if (!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)) attrib |= const_le32_to_cpu(FILE_ATTR_DIRECTORY); else attrib &= ~const_le32_to_cpu(FILE_ATTR_DIRECTORY); @@ -5034,7 +5034,7 @@ BOOL ntfs_set_file_attributes(struct SECURITY_API *scapi, ni = ntfs_pathname_to_inode(scapi->security.vol, NULL, path); if (ni) { settable = FILE_ATTR_SETTABLE; - if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { + if (!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)) { /* * Accept changing compression for a directory * and set index root accordingly @@ -5079,7 +5079,7 @@ BOOL ntfs_read_directory(struct SECURITY_API *scapi, if (scapi && (scapi->magic == MAGIC_API) && callback) { ni = ntfs_pathname_to_inode(scapi->security.vol, NULL, path); if (ni) { - if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { + if (!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)) { pos = 0; ntfs_readdir(ni,&pos,context,callback); ok = !ntfs_inode_close(ni); diff --git a/libntfs-3g/volume.c b/libntfs-3g/volume.c index cccec09b..829ceb36 100644 --- a/libntfs-3g/volume.c +++ b/libntfs-3g/volume.c @@ -329,8 +329,8 @@ mft_has_no_attr_list: goto io_error_exit; } /* $MFT must be uncompressed and unencrypted. */ - if (a->flags & ATTR_COMPRESSION_MASK || - a->flags & ATTR_IS_ENCRYPTED) { + if (!le16_andz(a->flags, ATTR_COMPRESSION_MASK) || + !le16_andz(a->flags, ATTR_IS_ENCRYPTED)) { ntfs_log_error("$MFT must be uncompressed and " "unencrypted.\n"); goto io_error_exit; @@ -962,7 +962,7 @@ ntfs_volume *ntfs_device_mount(struct ntfs_device *dev, ntfs_mount_flags flags) s = "mft record"; mrec = (MFT_RECORD*)(m + i * vol->mft_record_size); - if (mrec->flags & MFT_RECORD_IN_USE) { + if (!le16_andz(mrec->flags, MFT_RECORD_IN_USE)) { if (ntfs_is_baad_recordp(mrec)) { ntfs_log_error("$MFT error: Incomplete multi " "sector transfer detected in " @@ -976,7 +976,7 @@ 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 (!le16_andz(mrec2->flags, MFT_RECORD_IN_USE)) { if (ntfs_is_baad_recordp(mrec2)) { ntfs_log_error("$MFTMirr error: Incomplete " "multi sector transfer " diff --git a/ntfsprogs/mkntfs.c b/ntfsprogs/mkntfs.c index c0e2f453..e0305f98 100644 --- a/ntfsprogs/mkntfs.c +++ b/ntfsprogs/mkntfs.c @@ -1470,19 +1470,19 @@ static int insert_positioned_attr_in_mft_record(MFT_RECORD *m, goto err_out; } a = ctx->attr; - if (flags & ATTR_COMPRESSION_MASK) { + if (!le16_andz(flags, ATTR_COMPRESSION_MASK)) { ntfs_log_error("Compressed attributes not supported yet.\n"); /* FIXME: Compress attribute into a temporary buffer, set */ /* val accordingly and save the compressed size. */ err = -EOPNOTSUPP; goto err_out; } - if (flags & (ATTR_IS_ENCRYPTED | ATTR_IS_SPARSE)) { + if (!le16_andz(flags, ATTR_IS_ENCRYPTED | ATTR_IS_SPARSE)) { ntfs_log_error("Encrypted/sparse attributes not supported.\n"); err = -EOPNOTSUPP; goto err_out; } - if (flags & ATTR_COMPRESSION_MASK) { + if (!le16_andz(flags, ATTR_COMPRESSION_MASK)) { hdr_size = 72; /* FIXME: This compression stuff is all wrong. Never mind for */ /* now. (AIA) */ @@ -1561,8 +1561,8 @@ static int insert_positioned_attr_in_mft_record(MFT_RECORD *m, a->data_size = cpu_to_sle64(val_len); if (name_len) memcpy((char*)a + hdr_size, uname, name_len << 1); - if (flags & ATTR_COMPRESSION_MASK) { - if (flags & ATTR_COMPRESSION_MASK & ~ATTR_IS_COMPRESSED) { + if (!le16_andz(flags, ATTR_COMPRESSION_MASK)) { + if (!le16_andz(flags, ATTR_COMPRESSION_MASK & ~ATTR_IS_COMPRESSED)) { ntfs_log_error("Unknown compression format. Reverting " "to standard compression.\n"); a->flags &= ~ATTR_COMPRESSION_MASK; @@ -1661,14 +1661,14 @@ static int insert_non_resident_attr_in_mft_record(MFT_RECORD *m, goto err_out; } a = ctx->attr; - if (flags & ATTR_COMPRESSION_MASK) { + if (!le16_andz(flags, ATTR_COMPRESSION_MASK)) { ntfs_log_error("Compressed attributes not supported yet.\n"); /* FIXME: Compress attribute into a temporary buffer, set */ /* val accordingly and save the compressed size. */ err = -EOPNOTSUPP; goto err_out; } - if (flags & (ATTR_IS_ENCRYPTED | ATTR_IS_SPARSE)) { + if (!le16_andz(flags, ATTR_IS_ENCRYPTED | ATTR_IS_SPARSE)) { ntfs_log_error("Encrypted/sparse attributes not supported.\n"); err = -EOPNOTSUPP; goto err_out; @@ -1684,7 +1684,7 @@ static int insert_non_resident_attr_in_mft_record(MFT_RECORD *m, } else { rl = NULL; } - if (flags & ATTR_COMPRESSION_MASK) { + if (!le16_andz(flags, ATTR_COMPRESSION_MASK)) { hdr_size = 72; /* FIXME: This compression stuff is all wrong. Never mind for */ /* now. (AIA) */ @@ -1758,8 +1758,8 @@ static int insert_non_resident_attr_in_mft_record(MFT_RECORD *m, a->initialized_size = cpu_to_sle64(val_len); if (name_len) memcpy((char*)a + hdr_size, uname, name_len << 1); - if (flags & ATTR_COMPRESSION_MASK) { - if (flags & ATTR_COMPRESSION_MASK & ~ATTR_IS_COMPRESSED) { + if (!le16_andz(flags, ATTR_COMPRESSION_MASK)) { + if (!le16_andz(flags, ATTR_COMPRESSION_MASK & ~ATTR_IS_COMPRESSED)) { ntfs_log_error("Unknown compression format. Reverting " "to standard compression.\n"); a->flags &= ~ATTR_COMPRESSION_MASK; @@ -4301,7 +4301,7 @@ static BOOL create_file_volume(MFT_RECORD *m, leMFT_REF root_ref, err = add_attr_vol_name(m, g_vol->vol_name, g_vol->vol_name ? strlen(g_vol->vol_name) : 0); if (!err) { - if (fl & VOLUME_IS_DIRTY) + if (!le16_andz(fl, VOLUME_IS_DIRTY)) ntfs_log_quiet("Setting the volume dirty so check " "disk runs on next reboot into " "Windows.\n"); diff --git a/ntfsprogs/ntfsck.c b/ntfsprogs/ntfsck.c index 9b21079f..67832488 100644 --- a/ntfsprogs/ntfsck.c +++ b/ntfsprogs/ntfsck.c @@ -469,7 +469,7 @@ static ATTR_REC *check_attr_record(ATTR_REC *attr_rec, MFT_RECORD *mft_rec, // todo: instance is unique. // Check flags. - if (attr_rec->flags & ~(const_cpu_to_le16(0xc0ff))) { + if (!le16_andz(attr_rec->flags, ~(const_cpu_to_le16(0xc0ff)))) { check_failed("Attribute %lld:0x%x Unknown flags (0x%x).\n", (long long)current_mft_record, (int)attr_type, (int)le16_to_cpu(attr_rec->flags)); @@ -858,7 +858,7 @@ int main(int argc, char **argv) replay_log(vol); - if (vol->flags & VOLUME_IS_DIRTY) + if (!le16_andz(vol->flags, VOLUME_IS_DIRTY)) ntfs_log_warning("Volume is dirty.\n"); check_volume(vol); diff --git a/ntfsprogs/ntfsclone.c b/ntfsprogs/ntfsclone.c index dfbccddb..e236634c 100644 --- a/ntfsprogs/ntfsclone.c +++ b/ntfsprogs/ntfsclone.c @@ -2161,7 +2161,7 @@ static void mount_volume(unsigned long new_mntflag) exit(1); } - if (vol->flags & VOLUME_IS_DIRTY) + if (!le16_andz(vol->flags, VOLUME_IS_DIRTY)) if (opt.force-- <= 0) err_exit(dirty_volume_msg, opt.volume); diff --git a/ntfsprogs/ntfscp.c b/ntfsprogs/ntfscp.c index 187ec0de..a8a875b8 100644 --- a/ntfsprogs/ntfscp.c +++ b/ntfsprogs/ntfscp.c @@ -612,13 +612,13 @@ static int set_sizes(struct ALLOC_CONTEXT *alctx, ntfs_attr_search_ctx *ctx) 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); - if (na->data_flags & ATTR_IS_SPARSE) + if (!le16_andz(na->data_flags, ATTR_IS_SPARSE)) attr->compressed_size = cpu_to_le64(na->compressed_size); /* Copy the unnamed data attribute sizes to inode */ if (le32_eq(opts.attribute, AT_DATA) && !na->name_len) { ni = na->ni; ni->data_size = na->data_size; - if (na->data_flags & ATTR_IS_SPARSE) { + if (!le16_andz(na->data_flags, ATTR_IS_SPARSE)) { ni->allocated_size = na->compressed_size; ni->flags |= FILE_ATTR_SPARSE_FILE; } else @@ -865,7 +865,7 @@ int main(int argc, char *argv[]) return 1; } - if ((vol->flags & VOLUME_IS_DIRTY) && !opts.force) + if (!le16_andz(vol->flags, VOLUME_IS_DIRTY) && !opts.force) goto umount; NVolSetCompression(vol); /* allow compression */ @@ -961,7 +961,7 @@ int main(int argc, char *argv[]) free(parent_dirname); } /* The destination is a directory. */ - if ((out->mrec->flags & MFT_RECORD_IS_DIRECTORY) && !opts.inode) { + if (!le16_andz(out->mrec->flags, MFT_RECORD_IS_DIRECTORY) && !opts.inode) { char *filename; char *overwrite_filename; int overwrite_filename_len; @@ -1107,7 +1107,7 @@ int main(int argc, char *argv[]) } offset += bw; } - if ((na->data_flags & ATTR_COMPRESSION_MASK) + if (!le16_andz(na->data_flags, ATTR_COMPRESSION_MASK) && ntfs_attr_pclose(na)) ntfs_log_perror("ERROR: ntfs_attr_pclose failed"); ntfs_log_verbose("Syncing.\n"); diff --git a/ntfsprogs/ntfsdump_logfile.c b/ntfsprogs/ntfsdump_logfile.c index f63102ca..807e0644 100644 --- a/ntfsprogs/ntfsdump_logfile.c +++ b/ntfsprogs/ntfsdump_logfile.c @@ -563,11 +563,11 @@ static void dump_log_record(LOG_RECORD *lr) else { int _b = 0; - if (lr->flags & LOG_RECORD_MULTI_PAGE) { + if (!le16_andz(lr->flags, LOG_RECORD_MULTI_PAGE)) { ntfs_log_info(" LOG_RECORD_MULTI_PAGE"); _b = 1; } - if (lr->flags & ~LOG_RECORD_MULTI_PAGE) { + if (!le16_andz(lr->flags, ~LOG_RECORD_MULTI_PAGE)) { if (_b) ntfs_log_info(" |"); ntfs_log_info(" Unknown flags"); diff --git a/ntfsprogs/ntfsfallocate.c b/ntfsprogs/ntfsfallocate.c index 5e721edc..f78053da 100644 --- a/ntfsprogs/ntfsfallocate.c +++ b/ntfsprogs/ntfsfallocate.c @@ -545,7 +545,7 @@ static int ntfs_merge_allocation(ntfs_attr *na, runlist_element *rl, err = ntfs_inner_zero(na, rl); } if (!err) { - if (na->data_flags & ATTR_IS_SPARSE) { + if (!le16_andz(na->data_flags, ATTR_IS_SPARSE)) { na->compressed_size += size; if (na->compressed_size >= na->allocated_size) { na->data_flags &= ~ATTR_IS_SPARSE; @@ -709,14 +709,14 @@ static int ntfs_full_allocation(ntfs_attr *na, ntfs_attr_search_ctx *ctx, = cpu_to_le64(na->initialized_size); attr->allocated_size = cpu_to_le64(na->allocated_size); - if (na->data_flags & ATTR_IS_SPARSE) + if (!le16_andz(na->data_flags, ATTR_IS_SPARSE)) attr->compressed_size = cpu_to_le64(na->compressed_size); /* Copy the unnamed data attribute sizes to inode */ if (le32_eq(attr_type, AT_DATA) && !attr_name_len) { ni = na->ni; ni->data_size = na->data_size; - if (na->data_flags & ATTR_IS_SPARSE) { + if (!le16_andz(na->data_flags, ATTR_IS_SPARSE)) { ni->allocated_size = na->compressed_size; ni->flags |= FILE_ATTR_SPARSE_FILE; @@ -754,7 +754,7 @@ static int ntfs_fallocate(ntfs_inode *ni, s64 alloc_offs, s64 alloc_len) err = -1; } else { errmess = (const char*)NULL; - if (na->data_flags & ATTR_IS_COMPRESSED) { + if (!le16_andz(na->data_flags, ATTR_IS_COMPRESSED)) { errmess= "Cannot fallocate a compressed file"; } @@ -850,7 +850,7 @@ int main(int argc, char **argv) err_exit(vol, "Failed to mount %s: %s\n", dev_name, strerror(errno)); - if ((vol->flags & VOLUME_IS_DIRTY) && !opts.force) + if (!le16_andz(vol->flags, VOLUME_IS_DIRTY) && !opts.force) err_exit(vol, "Volume is dirty, please run chkdsk.\n"); if (ntfs_volume_get_free_space(vol)) diff --git a/ntfsprogs/ntfsfix.c b/ntfsprogs/ntfsfix.c index 77c82471..5954f80c 100644 --- a/ntfsprogs/ntfsfix.c +++ b/ntfsprogs/ntfsfix.c @@ -298,7 +298,7 @@ static int set_dirty_flag(ntfs_volume *vol) /* Porting note: We test for the current state of VOLUME_IS_DIRTY. This * should actually be more appropriate than testing for NVolWasDirty. */ - if (vol->flags & VOLUME_IS_DIRTY) + if (!le16_andz(vol->flags, VOLUME_IS_DIRTY)) return 0; ntfs_log_info("Setting required flags on partition... "); /* @@ -483,7 +483,7 @@ static int fix_mftmirr(ntfs_volume *vol) use_mirr = FALSE; mrec = (MFT_RECORD*)(m + i * vol->mft_record_size); - if (mrec->flags & MFT_RECORD_IN_USE) { + if (!le16_andz(mrec->flags, MFT_RECORD_IN_USE)) { if (ntfs_is_baad_record(mrec->magic)) { ntfs_log_info(FAILED); ntfs_log_error("$MFT error: Incomplete multi " @@ -501,7 +501,7 @@ static int fix_mftmirr(ntfs_volume *vol) } } mrec2 = (MFT_RECORD*)(m2 + i * vol->mft_record_size); - if (mrec2->flags & MFT_RECORD_IN_USE) { + if (!le16_andz(mrec2->flags, MFT_RECORD_IN_USE)) { if (ntfs_is_baad_record(mrec2->magic)) { ntfs_log_info(FAILED); ntfs_log_error("$MFTMirr error: Incomplete " @@ -920,7 +920,7 @@ static BOOL self_mapped_selfloc_condition(struct MFT_SELF_LOCATED *selfloc) >> vol->cluster_size_bits; a = find_unnamed_attr(mft1,AT_DATA); if (a - && (mft1->flags & MFT_RECORD_IN_USE) + && !le16_andz(mft1->flags, MFT_RECORD_IN_USE) && ((VCN)le64_to_cpu(a->lowest_vcn) == lowest_vcn) && (le64_to_cpu(mft1->base_mft_record) == selfloc->mft_ref0) @@ -973,7 +973,7 @@ static BOOL spare_record_selfloc_condition(struct MFT_SELF_LOCATED *selfloc) && !ntfs_mst_post_read_fixup((NTFS_RECORD*)mft2, vol->mft_record_size)) { if (le64_cmpz(mft2->base_mft_record) - && (mft2->flags & MFT_RECORD_IN_USE) + && !le16_andz(mft2->flags, MFT_RECORD_IN_USE) && !find_unnamed_attr(mft2,AT_ATTRIBUTE_LIST) && !find_unnamed_attr(mft2,AT_FILE_NAME)) { ok = TRUE; diff --git a/ntfsprogs/ntfsinfo.c b/ntfsprogs/ntfsinfo.c index 08d9e885..66f60464 100644 --- a/ntfsprogs/ntfsinfo.c +++ b/ntfsprogs/ntfsinfo.c @@ -421,9 +421,9 @@ static void ntfs_dump_volume(ntfs_volume *vol) printf("\tVolume Name: %s\n", vol->vol_name); printf("\tVolume State: %lu\n", vol->state); printf("\tVolume Flags: 0x%04x", (int)vol->flags); - if (vol->flags & VOLUME_IS_DIRTY) + if (!le16_andz(vol->flags, VOLUME_IS_DIRTY)) printf(" DIRTY"); - if (vol->flags & VOLUME_MODIFIED_BY_CHKDSK) + if (!le16_andz(vol->flags, VOLUME_MODIFIED_BY_CHKDSK)) printf(" MODIFIED_BY_CHKDSK"); printf("\n"); printf("\tVolume Version: %u.%u\n", vol->major_ver, vol->minor_ver); @@ -983,7 +983,7 @@ static void ntfs_dump_security_descriptor(SECURITY_DESCRIPTOR_ATTR *sec_desc, printf("%s\tControl:\t\t 0x%04x\n", indent, le16_to_cpu(sec_desc->control)); - if (~sec_desc->control & SE_SELF_RELATIVE) { + if (!le16_andz(~sec_desc->control, SE_SELF_RELATIVE)) { SECURITY_DESCRIPTOR *sd = (SECURITY_DESCRIPTOR *)sec_desc; printf("%s\tOwner SID pointer:\t %p\n", indent, sd->owner); @@ -1011,8 +1011,8 @@ static void ntfs_dump_security_descriptor(SECURITY_DESCRIPTOR_ATTR *sec_desc, printf("%s\tGroup SID:\t\t missing\n", indent); printf("%s\tSystem ACL:\t\t ", indent); - if (sec_desc->control & SE_SACL_PRESENT) { - if (sec_desc->control & SE_SACL_DEFAULTED) { + if (!le16_andz(sec_desc->control, SE_SACL_PRESENT)) { + if (!le16_andz(sec_desc->control, SE_SACL_DEFAULTED)) { printf("defaulted"); } printf("\n"); @@ -1024,8 +1024,8 @@ static void ntfs_dump_security_descriptor(SECURITY_DESCRIPTOR_ATTR *sec_desc, } printf("%s\tDiscretionary ACL:\t ", indent); - if (sec_desc->control & SE_DACL_PRESENT) { - if (sec_desc->control & SE_SACL_DEFAULTED) { + if (!le16_andz(sec_desc->control, SE_DACL_PRESENT)) { + if (!le16_andz(sec_desc->control, SE_SACL_DEFAULTED)) { printf("defaulted"); } printf("\n"); @@ -1131,28 +1131,28 @@ static void ntfs_dump_attr_volume_information(ATTR_RECORD *attr) printf("\tVolume Version:\t\t %d.%d\n", vol_information->major_ver, vol_information->minor_ver); printf("\tVolume Flags:\t\t "); - if (vol_information->flags & VOLUME_IS_DIRTY) + if (!le16_andz(vol_information->flags, VOLUME_IS_DIRTY)) printf("DIRTY "); - if (vol_information->flags & VOLUME_RESIZE_LOG_FILE) + if (!le16_andz(vol_information->flags, VOLUME_RESIZE_LOG_FILE)) printf("RESIZE_LOG "); - if (vol_information->flags & VOLUME_UPGRADE_ON_MOUNT) + if (!le16_andz(vol_information->flags, VOLUME_UPGRADE_ON_MOUNT)) printf("UPG_ON_MOUNT "); - if (vol_information->flags & VOLUME_MOUNTED_ON_NT4) + if (!le16_andz(vol_information->flags, VOLUME_MOUNTED_ON_NT4)) printf("MOUNTED_NT4 "); - if (vol_information->flags & VOLUME_DELETE_USN_UNDERWAY) + if (!le16_andz(vol_information->flags, VOLUME_DELETE_USN_UNDERWAY)) printf("DEL_USN "); - if (vol_information->flags & VOLUME_REPAIR_OBJECT_ID) + if (!le16_andz(vol_information->flags, VOLUME_REPAIR_OBJECT_ID)) printf("REPAIR_OBJID "); - if (vol_information->flags & VOLUME_CHKDSK_UNDERWAY) + if (!le16_andz(vol_information->flags, VOLUME_CHKDSK_UNDERWAY)) printf("CHKDSK_UNDERWAY "); - if (vol_information->flags & VOLUME_MODIFIED_BY_CHKDSK) + if (!le16_andz(vol_information->flags, VOLUME_MODIFIED_BY_CHKDSK)) printf("MOD_BY_CHKDSK "); - if (vol_information->flags & VOLUME_FLAGS_MASK) { + if (!le16_andz(vol_information->flags, VOLUME_FLAGS_MASK)) { printf("(0x%04x)\n", (unsigned)le16_to_cpu(vol_information->flags)); } else printf("none set (0x0000)\n"); - if (vol_information->flags & (~VOLUME_FLAGS_MASK)) + if (!le16_andz(vol_information->flags, ~VOLUME_FLAGS_MASK)) printf("\t\t\t\t Unknown Flags: 0x%04x\n", le16_to_cpu(vol_information->flags & (~VOLUME_FLAGS_MASK))); @@ -1358,8 +1358,8 @@ static void ntfs_dump_attribute_header(ntfs_attr_search_ctx *ctx, (long long)sle64_to_cpu(a->initialized_size), (unsigned long long) sle64_to_cpu(a->initialized_size)); - if (a->compression_unit || a->flags & ATTR_IS_COMPRESSED || - a->flags & ATTR_IS_SPARSE) + if (a->compression_unit || !le16_andz(a->flags, ATTR_IS_COMPRESSED) || + !le16_andz(a->flags, ATTR_IS_SPARSE)) printf("\tCompressed size:\t %llu (0x%llx)\n", (signed long long) sle64_to_cpu(a->compressed_size), @@ -1614,7 +1614,7 @@ static int ntfs_dump_index_entries(INDEX_ENTRY *entry, INDEX_ATTR_TYPE type) int numb_entries = 1; while (1) { if (!opts.verbose) { - if (entry->ie_flags & INDEX_ENTRY_END) + if (!le16_andz(entry->ie_flags, INDEX_ENTRY_END)) break; entry = (INDEX_ENTRY *)((u8 *)entry + le16_to_cpu(entry->length)); @@ -1630,11 +1630,11 @@ static int ntfs_dump_index_entries(INDEX_ENTRY *entry, INDEX_ATTR_TYPE type) ntfs_log_verbose("\t\tIndex entry flags:\t 0x%02x\n", (unsigned)le16_to_cpu(entry->ie_flags)); - if (entry->ie_flags & INDEX_ENTRY_NODE) + if (!le16_andz(entry->ie_flags, INDEX_ENTRY_NODE)) ntfs_log_verbose("\t\tSubnode VCN:\t\t %lld (0x%llx)\n", (long long)ntfs_ie_get_vcn(entry), (long long)ntfs_ie_get_vcn(entry)); - if (entry->ie_flags & INDEX_ENTRY_END) + if (!le16_andz(entry->ie_flags, INDEX_ENTRY_END)) break; switch (type) { @@ -2189,20 +2189,20 @@ static void ntfs_dump_inode_general_info(ntfs_inode *inode) printf("MFT Record Flags:\t "); if (!le16_cmpz(inode_flags)) { - if (MFT_RECORD_IN_USE & inode_flags) { + if (!le16_andz(MFT_RECORD_IN_USE, inode_flags)) { printf("IN_USE "); inode_flags &= ~MFT_RECORD_IN_USE; } - if (MFT_RECORD_IS_DIRECTORY & inode_flags) { + if (!le16_andz(MFT_RECORD_IS_DIRECTORY, inode_flags)) { printf("DIRECTORY "); inode_flags &= ~MFT_RECORD_IS_DIRECTORY; } /* The meaning of IS_4 is illusive but not its existence. */ - if (MFT_RECORD_IS_4 & inode_flags) { + if (!le16_andz(MFT_RECORD_IS_4, inode_flags)) { printf("IS_4 "); inode_flags &= ~MFT_RECORD_IS_4; } - if (MFT_RECORD_IS_VIEW_INDEX & inode_flags) { + if (!le16_andz(MFT_RECORD_IS_VIEW_INDEX, inode_flags)) { printf("VIEW_INDEX "); inode_flags &= ~MFT_RECORD_IS_VIEW_INDEX; } diff --git a/ntfsprogs/ntfsls.c b/ntfsprogs/ntfsls.c index 909e7bb9..5954d0d9 100644 --- a/ntfsprogs/ntfsls.c +++ b/ntfsprogs/ntfsls.c @@ -671,7 +671,7 @@ int main(int argc, char **argv) pos = 0; memset(&dirent, 0, sizeof(dirent)); dirent.vol = vol; - if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) { + if (!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)) { if (opts.recursive) readdir_recursive(ni, &pos, &dirent); else diff --git a/ntfsprogs/ntfsmftalloc.c b/ntfsprogs/ntfsmftalloc.c index d18cf3c9..e7b0860d 100644 --- a/ntfsprogs/ntfsmftalloc.c +++ b/ntfsprogs/ntfsmftalloc.c @@ -236,11 +236,11 @@ static void dump_mft_record(MFT_RECORD *m) u = le16_to_cpu(m->attrs_offset); ntfs_log_info("First attribute offset = %u (0x%x)\n", u, u); ntfs_log_info("Flags = %u: ", le16_to_cpu(m->flags)); - if (m->flags & MFT_RECORD_IN_USE) + if (!le16_andz(m->flags, MFT_RECORD_IN_USE)) ntfs_log_info("MFT_RECORD_IN_USE"); else ntfs_log_info("MFT_RECORD_NOT_IN_USE"); - if (m->flags & MFT_RECORD_IS_DIRECTORY) + if (!le16_andz(m->flags, MFT_RECORD_IS_DIRECTORY)) ntfs_log_info(" | MFT_RECORD_IS_DIRECTORY"); ntfs_log_info("\n"); u = le32_to_cpu(m->bytes_in_use); diff --git a/ntfsprogs/ntfsresize.c b/ntfsprogs/ntfsresize.c index f6223181..36365dc9 100644 --- a/ntfsprogs/ntfsresize.c +++ b/ntfsprogs/ntfsresize.c @@ -735,11 +735,11 @@ static void collect_resize_constraints(ntfs_resize_t *resize, runlist *rl) if (inode != FILE_MFTMirr) supported = 1; - } else if (flags & ATTR_IS_SPARSE) { + } else if (!le16_andz(flags, ATTR_IS_SPARSE)) { llcn = &resize->last_sparse; supported = 1; - } else if (flags & ATTR_IS_COMPRESSED) { + } else if (!le16_andz(flags, ATTR_IS_COMPRESSED)) { llcn = &resize->last_compressed; supported = 1; @@ -2777,7 +2777,7 @@ static ntfs_volume *mount_volume(void) } vol = check_volume(); - if (vol->flags & VOLUME_IS_DIRTY) + if (!le16_andz(vol->flags, VOLUME_IS_DIRTY)) if (opt.force-- <= 0) err_exit("Volume is scheduled for check.\nRun chkdsk /f" " and please try again, or see option -f.\n"); @@ -3004,7 +3004,7 @@ static ATTR_RECORD *get_unnamed_attr(expand_t *expand, ATTR_TYPES type, + (inum << vol->mft_record_size_bits) + expand->byte_increment; got = ntfs_mst_pread(vol->dev, pos, 1, vol->mft_record_size, mrec); - if ((got == 1) && (mrec->flags & MFT_RECORD_IN_USE)) { + if ((got == 1) && !le16_andz(mrec->flags, MFT_RECORD_IN_USE)) { a = find_attr(expand->mrec, type, NULL, 0); found = a && le32_eq(a->type, type) && !a->name_length; } @@ -3039,7 +3039,7 @@ static ATTR_RECORD *read_and_get_attr(expand_t *expand, ATTR_TYPES type, + (inum << vol->mft_record_size_bits) + expand->byte_increment; got = ntfs_mst_pread(vol->dev, pos, 1, vol->mft_record_size, mrec); - if ((got == 1) && (mrec->flags & MFT_RECORD_IN_USE)) { + if ((got == 1) && !le16_andz(mrec->flags, MFT_RECORD_IN_USE)) { a = find_attr(expand->mrec, type, name, namelen); } if (!a) { @@ -3242,7 +3242,7 @@ static int check_expand_constraints(expand_t *expand) volinfo = (VOLUME_INFORMATION*) (le16_to_cpu(a->value_offset) + (char*)a); flags = volinfo->flags; - if ((flags & VOLUME_IS_DIRTY) && (opt.force-- <= 0)) { + if (!le16_andz(flags, VOLUME_IS_DIRTY) && (opt.force-- <= 0)) { err_printf("Volume is scheduled for check.\nRun chkdsk /f" " and please try again, or see option -f.\n"); res = -1; @@ -4054,7 +4054,7 @@ static int rebase_inode(expand_t *expand, const runlist_element *prl, + ((inum - jnum) << vol->mft_record_size_bits); if ((ntfs_mst_pread(vol->dev, pos, 1, vol->mft_record_size, mrec) == 1) - && (mrec->flags & MFT_RECORD_IN_USE)) { + && !le16_andz(mrec->flags, MFT_RECORD_IN_USE)) { switch (inum) { case FILE_Bitmap : case FILE_Boot : @@ -4128,7 +4128,7 @@ static int rebase_all_inodes(expand_t *expand) << vol->cluster_size_bits; got = ntfs_mst_pread(vol->dev, pos, 1, vol->mft_record_size, mrec); - if ((got == 1) && (mrec->flags & MFT_RECORD_IN_USE)) { + if ((got == 1) && !le16_andz(mrec->flags, MFT_RECORD_IN_USE)) { pos = expand->mft_lcn << vol->cluster_size_bits; if (opt.verbose) ntfs_log_verbose("Rebasing inode %lld cluster 0x%llx\n", diff --git a/ntfsprogs/ntfstruncate.c b/ntfsprogs/ntfstruncate.c index 4f5c6a9b..f911619d 100644 --- a/ntfsprogs/ntfstruncate.c +++ b/ntfsprogs/ntfstruncate.c @@ -364,46 +364,46 @@ static void dump_resident_attr_val(ATTR_TYPES type, char *val, u32 val_len) return; } j = 0; - if (i & VOLUME_MODIFIED_BY_CHKDSK) { + if (!le16_andz(i, VOLUME_MODIFIED_BY_CHKDSK)) { j = 1; printf("VOLUME_MODIFIED_BY_CHKDSK"); } - if (i & VOLUME_REPAIR_OBJECT_ID) { + if (!le16_andz(i, VOLUME_REPAIR_OBJECT_ID)) { if (j) printf(" | "); else j = 0; printf("VOLUME_REPAIR_OBJECT_ID"); } - if (i & VOLUME_DELETE_USN_UNDERWAY) { + if (!le16_andz(i, VOLUME_DELETE_USN_UNDERWAY)) { if (j) printf(" | "); else j = 0; printf("VOLUME_DELETE_USN_UNDERWAY"); } - if (i & VOLUME_MOUNTED_ON_NT4) { + if (!le16_andz(i, VOLUME_MOUNTED_ON_NT4)) { if (j) printf(" | "); else j = 0; printf("VOLUME_MOUNTED_ON_NT4"); } - if (i & VOLUME_UPGRADE_ON_MOUNT) { + if (!le16_andz(i, VOLUME_UPGRADE_ON_MOUNT)) { if (j) printf(" | "); else j = 0; printf("VOLUME_UPGRADE_ON_MOUNT"); } - if (i & VOLUME_RESIZE_LOG_FILE) { + if (!le16_andz(i, VOLUME_RESIZE_LOG_FILE)) { if (j) printf(" | "); else j = 0; printf("VOLUME_RESIZE_LOG_FILE"); } - if (i & VOLUME_IS_DIRTY) { + if (!le16_andz(i, VOLUME_IS_DIRTY)) { if (j) printf(" | "); else @@ -514,7 +514,7 @@ static void dump_non_resident_attr(ATTR_RECORD *a) l = sle64_to_cpu(a->initialized_size); printf("Initialized size = %lli (0x%llx)\n", (long long)l, (unsigned long long)l); - if (a->flags & ATTR_COMPRESSION_MASK) { + if (!le16_andz(a->flags, ATTR_COMPRESSION_MASK)) { l = sle64_to_cpu(a->compressed_size); printf("Compressed size = %lli (0x%llx)\n", (long long)l, (unsigned long long)l); @@ -584,12 +584,12 @@ static void dump_attr_record(MFT_RECORD *m, ATTR_RECORD *a) printf("NONE"); else { int first = TRUE; - if (u & ATTR_COMPRESSION_MASK) { - if (u & ATTR_IS_COMPRESSED) { + if (!le16_andz(u, ATTR_COMPRESSION_MASK)) { + if (!le16_andz(u, ATTR_IS_COMPRESSED)) { printf("ATTR_IS_COMPRESSED"); first = FALSE; } - if ((u & ATTR_COMPRESSION_MASK) & ~ATTR_IS_COMPRESSED) { + if (!le16_andz(u & ATTR_COMPRESSION_MASK, ~ATTR_IS_COMPRESSED)) { if (!first) printf(" | "); else @@ -597,14 +597,14 @@ static void dump_attr_record(MFT_RECORD *m, ATTR_RECORD *a) printf("ATTR_UNKNOWN_COMPRESSION"); } } - if (u & ATTR_IS_ENCRYPTED) { + if (!le16_andz(u, ATTR_IS_ENCRYPTED)) { if (!first) printf(" | "); else first = FALSE; printf("ATTR_IS_ENCRYPTED"); } - if (u & ATTR_IS_SPARSE) { + if (!le16_andz(u, ATTR_IS_SPARSE)) { if (!first) printf(" | "); else @@ -645,11 +645,11 @@ static void dump_mft_record(MFT_RECORD *m) u = le16_to_cpu(m->attrs_offset); printf("First attribute offset = %u (0x%x)\n", u, u); printf("Flags = %u: ", le16_to_cpu(m->flags)); - if (m->flags & MFT_RECORD_IN_USE) + if (!le16_andz(m->flags, MFT_RECORD_IN_USE)) printf("MFT_RECORD_IN_USE"); else printf("MFT_RECORD_NOT_IN_USE"); - if (m->flags & MFT_RECORD_IS_DIRECTORY) + if (!le16_andz(m->flags, MFT_RECORD_IS_DIRECTORY)) printf(" | MFT_RECORD_IS_DIRECTORY"); printf("\n"); u = le32_to_cpu(m->bytes_in_use); diff --git a/ntfsprogs/ntfsundelete.c b/ntfsprogs/ntfsundelete.c index 7340dc50..483c3a7b 100644 --- a/ntfsprogs/ntfsundelete.c +++ b/ntfsprogs/ntfsundelete.c @@ -1278,8 +1278,8 @@ static int get_data(struct ufile *file, ntfs_volume *vol) } data->resident = !rec->non_resident; - data->compressed = (rec->flags & ATTR_IS_COMPRESSED) ? 1 : 0; - data->encrypted = (rec->flags & ATTR_IS_ENCRYPTED) ? 1 : 0; + data->compressed = !le16_andz(rec->flags, ATTR_IS_COMPRESSED) ? 1 : 0; + data->encrypted = !le16_andz(rec->flags, ATTR_IS_ENCRYPTED) ? 1 : 0; if (rec->name_length) { data->uname = (ntfschar *)((char *)rec + @@ -1973,7 +1973,7 @@ static int undelete_file(ntfs_volume *vol, long long inode) * list_record(). Otherwise, when undeleting, a file will always be * listed as 0% recoverable even if successfully undeleted. +mabs */ - if (file->mft->flags & MFT_RECORD_IN_USE) { + if (!le16_andz(file->mft->flags, MFT_RECORD_IN_USE)) { ntfs_log_error("Record is in use by the mft\n"); if (!opts.force) { free(buffer); diff --git a/ntfsprogs/ntfswipe.c b/ntfsprogs/ntfswipe.c index 1db11ca2..95087526 100644 --- a/ntfsprogs/ntfswipe.c +++ b/ntfsprogs/ntfswipe.c @@ -771,7 +771,7 @@ static s64 wipe_attribute(ntfs_volume *vol, int byte, enum action act, if (!offset) return 0; - if (na->data_flags & ATTR_IS_ENCRYPTED) + if (!le16_andz(na->data_flags, ATTR_IS_ENCRYPTED)) offset = (((offset - 1) >> 10) + 1) << 10; size = (vol->cluster_size - offset) % vol->cluster_size; @@ -831,7 +831,7 @@ static s64 wipe_attr_tail(ntfs_inode *ni, ntfschar *name, int namelen, goto close_attr; } - if (na->data_flags & ATTR_COMPRESSION_MASK) + if (!le16_andz(na->data_flags, ATTR_COMPRESSION_MASK)) wiped = wipe_compressed_attribute(vol, byte, act, na); else wiped = wipe_attribute(vol, byte, act, na); @@ -2142,7 +2142,7 @@ int main(int argc, char *argv[]) if (!vol) goto free; - if ((vol->flags & VOLUME_IS_DIRTY) && !opts.force) + if (!le16_andz(vol->flags, VOLUME_IS_DIRTY) && !opts.force) goto umount; if (opts.info) { diff --git a/ntfsprogs/utils.c b/ntfsprogs/utils.c index 1f81e001..3ab815dd 100644 --- a/ntfsprogs/utils.c +++ b/ntfsprogs/utils.c @@ -303,7 +303,7 @@ ntfs_volume * utils_mount_volume(const char *device, unsigned long flags) * libntfs-3g does not record whether the volume log file was dirty * before mount, so we can only warn if the VOLUME_IS_DIRTY flag is set * in VOLUME_INFORMATION. */ - if (vol->flags & VOLUME_IS_DIRTY) { + if (!le16_andz(vol->flags, VOLUME_IS_DIRTY)) { if (!(flags & NTFS_MNT_RECOVER)) { ntfs_log_error("%s", dirty_volume_msg); ntfs_umount(vol, FALSE); diff --git a/src/lowntfs-3g.c b/src/lowntfs-3g.c index 9af07034..f5bc98f4 100644 --- a/src/lowntfs-3g.c +++ b/src/lowntfs-3g.c @@ -602,7 +602,7 @@ static int ntfs_fuse_getstat(struct SECURITY_CONTEXT *scx, memset(stbuf, 0, sizeof(struct stat)); withusermapping = (scx->mapping[MAPUSERS] != (struct MAPPING*)NULL); - if ((ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) + if (!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY) || (ni->flags & FILE_ATTR_REPARSE_POINT)) { if (ni->flags & FILE_ATTR_REPARSE_POINT) { char *target; @@ -1266,7 +1266,7 @@ static void ntfs_fuse_open(fuse_req_t req, fuse_ino_t ino, if ((res >= 0) && (fi->flags & (O_WRONLY | O_RDWR))) { /* mark a future need to compress the last chunk */ - if (na->data_flags & ATTR_COMPRESSION_MASK) + if (!le16_andz(na->data_flags, ATTR_COMPRESSION_MASK)) state |= CLOSE_COMPRESSED; #ifdef HAVE_SETXATTR /* extended attributes interface required */ /* mark a future need to fixup encrypted inode */ @@ -1346,7 +1346,7 @@ static void ntfs_fuse_read(fuse_req_t req, fuse_ino_t ino, size_t size, /* limit reads at next 512 byte boundary for encrypted attributes */ if (ctx->efs_raw && max_read - && (na->data_flags & ATTR_IS_ENCRYPTED) + && !le16_andz(na->data_flags, ATTR_IS_ENCRYPTED) && NAttrNonResident(na)) { max_read = ((na->data_size+511) & ~511) + 2; } @@ -1595,7 +1595,7 @@ static int ntfs_fuse_trunc(struct SECURITY_CONTEXT *scx, fuse_ino_t ino, * zero, which is optimized as creating a hole when possible. */ oldsize = na->data_size; - if ((na->data_flags & ATTR_COMPRESSION_MASK) + if (!le16_andz(na->data_flags, ATTR_COMPRESSION_MASK) && (size > na->initialized_size)) { char zero = 0; if (ntfs_attr_pwrite(na, size - 1, 1, &zero) <= 0) @@ -2091,7 +2091,7 @@ static int ntfs_fuse_newlink(fuse_req_t req __attribute__((unused)), } /* Do not accept linking to a directory (except for renaming) */ - if (e && (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)) { + if (e && !le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)) { errno = EPERM; res = -errno; goto exit; @@ -2213,7 +2213,7 @@ static int ntfs_fuse_rm(fuse_req_t req, fuse_ino_t parent, const char *name, #if defined(__sun) && defined (__SVR4) /* on Solaris : deny unlinking directories */ if (rm_type - == (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY ? RM_LINK : RM_DIR)) { + == (!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY) ? RM_LINK : RM_DIR)) { errno = EPERM; res = -errno; goto exit; @@ -2677,7 +2677,7 @@ static void ntfs_fuse_bmap(fuse_req_t req, fuse_ino_t ino, size_t blocksize, goto close_inode; } - if ((na->data_flags & (ATTR_COMPRESSION_MASK | ATTR_IS_ENCRYPTED)) + if (!le16_andz(na->data_flags, ATTR_COMPRESSION_MASK | ATTR_IS_ENCRYPTED) || !NAttrNonResident(na)) { ret = -EINVAL; goto close_attr; @@ -3064,7 +3064,7 @@ static void ntfs_fuse_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name, rsize = na->data_size; if (ctx->efs_raw && rsize - && (na->data_flags & ATTR_IS_ENCRYPTED) + && !le16_andz(na->data_flags, ATTR_IS_ENCRYPTED) && NAttrNonResident(na)) rsize = ((na->data_size + 511) & ~511) + 2; if (size) { diff --git a/src/ntfs-3g.c b/src/ntfs-3g.c index 8cfe3a6b..9c591f72 100644 --- a/src/ntfs-3g.c +++ b/src/ntfs-3g.c @@ -696,7 +696,7 @@ static int ntfs_fuse_getattr(const char *org_path, struct stat *stbuf) goto exit; } #endif - if (((ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) + if ((!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY) || (ni->flags & FILE_ATTR_REPARSE_POINT)) && !stream_name_len) { if (ni->flags & FILE_ATTR_REPARSE_POINT) { @@ -790,7 +790,7 @@ static int ntfs_fuse_getattr(const char *org_path, struct stat *stbuf) /* encrypted named stream */ /* round size up to next 512 byte boundary */ if (ctx->efs_raw && stream_name_len && - (na->data_flags & ATTR_IS_ENCRYPTED) && + !le16_andz(na->data_flags, ATTR_IS_ENCRYPTED) && NAttrNonResident(na)) stbuf->st_size = ((na->data_size+511) & ~511)+2; #endif /* HAVE_SETXATTR */ @@ -1203,7 +1203,7 @@ static int ntfs_fuse_open(const char *org_path, if ((res >= 0) && (fi->flags & (O_WRONLY | O_RDWR))) { /* mark a future need to compress the last chunk */ - if (na->data_flags & ATTR_COMPRESSION_MASK) + if (!le16_andz(na->data_flags, ATTR_COMPRESSION_MASK)) fi->fh |= CLOSE_COMPRESSED; #ifdef HAVE_SETXATTR /* extended attributes interface required */ /* mark a future need to fixup encrypted inode */ @@ -1264,7 +1264,7 @@ static int ntfs_fuse_read(const char *org_path, char *buf, size_t size, /* limit reads at next 512 byte boundary for encrypted attributes */ if (ctx->efs_raw && max_read - && (na->data_flags & ATTR_IS_ENCRYPTED) + && !le16_andz(na->data_flags, ATTR_IS_ENCRYPTED) && NAttrNonResident(na)) { max_read = ((na->data_size+511) & ~511) + 2; } @@ -1462,7 +1462,7 @@ static int ntfs_fuse_trunc(const char *org_path, off_t size, * zero, which is optimized as creating a hole when possible. */ oldsize = na->data_size; - if ((na->data_flags & ATTR_COMPRESSION_MASK) + if (!le16_andz(na->data_flags, ATTR_COMPRESSION_MASK) && (size > na->initialized_size)) { char zero = 0; if (ntfs_attr_pwrite(na, size - 1, 1, &zero) <= 0) @@ -2494,7 +2494,7 @@ static int ntfs_fuse_bmap(const char *path, size_t blocksize, uint64_t *idx) goto close_inode; } - if ((na->data_flags & (ATTR_COMPRESSION_MASK | ATTR_IS_ENCRYPTED)) + if (!le16_andz(na->data_flags, ATTR_COMPRESSION_MASK | ATTR_IS_ENCRYPTED) || !NAttrNonResident(na)) { ret = -EINVAL; goto close_attr; @@ -2915,7 +2915,7 @@ static int ntfs_fuse_getxattr(const char *path, const char *name, rsize = na->data_size; if (ctx->efs_raw && rsize - && (na->data_flags & ATTR_IS_ENCRYPTED) + && !le16_andz(na->data_flags, ATTR_IS_ENCRYPTED) && NAttrNonResident(na)) rsize = ((na->data_size + 511) & ~511) + 2; if (size) {