diff --git a/include/ntfs-3g/endians.h b/include/ntfs-3g/endians.h index e425f4d7..30cc2bd3 100644 --- a/include/ntfs-3g/endians.h +++ b/include/ntfs-3g/endians.h @@ -322,4 +322,6 @@ #define le16_andz(a, b) (!((a) & (b))) +#define le32_andz(a, b) (!((a) & (b))) + #endif /* defined _NTFS_ENDIANS_H */ diff --git a/libntfs-3g/acls.c b/libntfs-3g/acls.c index 78034054..d11cb6c0 100644 --- a/libntfs-3g/acls.c +++ b/libntfs-3g/acls.c @@ -766,15 +766,15 @@ int ntfs_inherit_acl(const ACL *oldacl, ACL *newacl, if ((poldace->flags & selection) && (!fordir || (poldace->flags & NO_PROPAGATE_INHERIT_ACE) - || (poldace->mask & (GENERIC_ALL | GENERIC_READ - | GENERIC_WRITE | GENERIC_EXECUTE))) + || !le32_andz(poldace->mask, GENERIC_ALL | GENERIC_READ + | GENERIC_WRITE | GENERIC_EXECUTE)) && !ntfs_same_sid(&poldace->sid, ownersid) && !ntfs_same_sid(&poldace->sid, groupsid)) { pnewace = (ACCESS_ALLOWED_ACE*) ((char*)newacl + dst); memcpy(pnewace,poldace,acesz); /* reencode GENERIC_ALL */ - if (pnewace->mask & GENERIC_ALL) { + if (!le32_andz(pnewace->mask, GENERIC_ALL)) { pnewace->mask &= ~GENERIC_ALL; if (fordir) pnewace->mask |= OWNER_RIGHTS @@ -793,7 +793,7 @@ int ntfs_inherit_acl(const ACL *oldacl, ACL *newacl, | const_cpu_to_le32(0x40); } /* reencode GENERIC_READ (+ EXECUTE) */ - if (pnewace->mask & GENERIC_READ) { + if (!le32_andz(pnewace->mask, GENERIC_READ)) { if (fordir) pnewace->mask |= OWNER_RIGHTS | DIR_READ @@ -810,7 +810,7 @@ int ntfs_inherit_acl(const ACL *oldacl, ACL *newacl, | FILE_WRITE_ATTRIBUTES); } /* reencode GENERIC_WRITE */ - if (pnewace->mask & GENERIC_WRITE) { + if (!le32_andz(pnewace->mask, GENERIC_WRITE)) { if (fordir) pnewace->mask |= OWNER_RIGHTS | DIR_WRITE; @@ -916,8 +916,8 @@ int ntfs_inherit_acl(const ACL *oldacl, ACL *newacl, && !(poldace->flags & NO_PROPAGATE_INHERIT_ACE) && !ntfs_same_sid(&poldace->sid, ownersid) && !ntfs_same_sid(&poldace->sid, groupsid)) { - if ((poldace->mask & (GENERIC_ALL | GENERIC_READ - | GENERIC_WRITE | GENERIC_EXECUTE))) + if (!le32_andz(poldace->mask, GENERIC_ALL | GENERIC_READ + | GENERIC_WRITE | GENERIC_EXECUTE)) pnewace->flags |= INHERIT_ONLY_ACE; else pnewace->flags &= ~INHERIT_ONLY_ACE; @@ -2938,23 +2938,23 @@ static int merge_permissions(BOOL isdir, if (!le32_cmpz(owner)) { if (isdir) { /* exec if any of list, traverse */ - if (owner & DIR_GEXEC) + if (!le32_andz(owner, DIR_GEXEC)) perm |= S_IXUSR; /* write if any of addfile, adddir, delchild */ - if (owner & DIR_GWRITE) + if (!le32_andz(owner, DIR_GWRITE)) perm |= S_IWUSR; /* read if any of list */ - if (owner & DIR_GREAD) + if (!le32_andz(owner, DIR_GREAD)) perm |= S_IRUSR; } else { /* exec if execute or generic execute */ - if (owner & FILE_GEXEC) + if (!le32_andz(owner, FILE_GEXEC)) perm |= S_IXUSR; /* write if any of writedata or generic write */ - if (owner & FILE_GWRITE) + if (!le32_andz(owner, FILE_GWRITE)) perm |= S_IWUSR; /* read if any of readdata or generic read */ - if (owner & FILE_GREAD) + if (!le32_andz(owner, FILE_GREAD)) perm |= S_IRUSR; } } @@ -2962,23 +2962,23 @@ static int merge_permissions(BOOL isdir, if (!le32_cmpz(group)) { if (isdir) { /* exec if any of list, traverse */ - if (group & DIR_GEXEC) + if (!le32_andz(group, DIR_GEXEC)) perm |= S_IXGRP; /* write if any of addfile, adddir, delchild */ - if (group & DIR_GWRITE) + if (!le32_andz(group, DIR_GWRITE)) perm |= S_IWGRP; /* read if any of list */ - if (group & DIR_GREAD) + if (!le32_andz(group, DIR_GREAD)) perm |= S_IRGRP; } else { /* exec if execute */ - if (group & FILE_GEXEC) + if (!le32_andz(group, FILE_GEXEC)) perm |= S_IXGRP; /* write if any of writedata, appenddata */ - if (group & FILE_GWRITE) + if (!le32_andz(group, FILE_GWRITE)) perm |= S_IWGRP; /* read if any of readdata */ - if (group & FILE_GREAD) + if (!le32_andz(group, FILE_GREAD)) perm |= S_IRGRP; } } @@ -2986,33 +2986,33 @@ static int merge_permissions(BOOL isdir, if (!le32_cmpz(world)) { if (isdir) { /* exec if any of list, traverse */ - if (world & DIR_GEXEC) + if (!le32_andz(world, DIR_GEXEC)) perm |= S_IXOTH; /* write if any of addfile, adddir, delchild */ - if (world & DIR_GWRITE) + if (!le32_andz(world, DIR_GWRITE)) perm |= S_IWOTH; /* read if any of list */ - if (world & DIR_GREAD) + if (!le32_andz(world, DIR_GREAD)) perm |= S_IROTH; } else { /* exec if execute */ - if (world & FILE_GEXEC) + if (!le32_andz(world, FILE_GEXEC)) perm |= S_IXOTH; /* write if any of writedata, appenddata */ - if (world & FILE_GWRITE) + if (!le32_andz(world, FILE_GWRITE)) perm |= S_IWOTH; /* read if any of readdata */ - if (world & FILE_GREAD) + if (!le32_andz(world, FILE_GREAD)) perm |= S_IROTH; } } /* build special permission flags */ if (!le32_cmpz(special)) { - if (special & FILE_APPEND_DATA) + if (!le32_andz(special, FILE_APPEND_DATA)) perm |= S_ISUID; - if (special & FILE_WRITE_DATA) + if (!le32_andz(special, FILE_WRITE_DATA)) perm |= S_ISGID; - if (special & FILE_READ_DATA) + if (!le32_andz(special, FILE_READ_DATA)) perm |= S_ISVTX; } return (perm); @@ -3306,7 +3306,7 @@ static int build_owngrp_permissions(const char *securattr, if (!(pace->flags & INHERIT_ONLY_ACE)) { if ((ntfs_same_sid(usid, &pace->sid) || ntfs_same_sid(ownersid, &pace->sid)) - && (pace->mask & WRITE_OWNER)) { + && !le32_andz(pace->mask, WRITE_OWNER)) { if (pace->type == ACCESS_ALLOWED_ACE_TYPE) { allowown |= pace->mask; ownpresent = TRUE; @@ -3497,7 +3497,7 @@ static int build_ownadmin_permissions(const char *securattr, && !(~pace->mask & (ROOT_OWNER_UNMARK | ROOT_GROUP_UNMARK))) { if ((ntfs_same_sid(usid, &pace->sid) || ntfs_same_sid(ownersid, &pace->sid)) - && (((pace->mask & WRITE_OWNER) && firstapply))) { + && ((!le32_andz(pace->mask, WRITE_OWNER) && firstapply))) { if (pace->type == ACCESS_ALLOWED_ACE_TYPE) { allowown |= pace->mask; isforeign &= ~1; @@ -3576,7 +3576,7 @@ const SID *ntfs_acl_owner(const char *securattr) nace = 0; do { pace = (const ACCESS_ALLOWED_ACE*)&securattr[offace]; - if ((pace->mask & WRITE_OWNER) + if (!le32_andz(pace->mask, WRITE_OWNER) && (pace->type == ACCESS_ALLOWED_ACE_TYPE) && ntfs_is_user_sid(&pace->sid)) found = TRUE; diff --git a/libntfs-3g/attrib.c b/libntfs-3g/attrib.c index 331d40c3..32f4e6c5 100644 --- a/libntfs-3g/attrib.c +++ b/libntfs-3g/attrib.c @@ -86,7 +86,7 @@ ntfschar TXF_DATA[] = { const_cpu_to_le16('$'), static int NAttrFlag(ntfs_attr *na, FILE_ATTR_FLAGS flag) { if (le32_eq(na->type, AT_DATA) && na->name == AT_UNNAMED) - return (na->ni->flags & flag); + return !le32_andz(na->ni->flags, flag); return 0; } @@ -468,7 +468,7 @@ ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type, * or cluster size > 4K or compression is disabled */ a->flags &= ~ATTR_COMPRESSION_MASK; - if ((ni->flags & FILE_ATTR_COMPRESSED) + if (!le32_andz(ni->flags, FILE_ATTR_COMPRESSED) && (ni->vol->major_ver >= 3) && NVolCompression(ni->vol) && (ni->vol->cluster_size <= MAX_COMPRESSION_CLUSTER_SIZE)) @@ -4296,7 +4296,7 @@ int ntfs_attr_add(ntfs_inode *ni, ATTR_TYPES type, } add_attr_record: - if ((ni->flags & FILE_ATTR_COMPRESSED) + if (!le32_andz(ni->flags, FILE_ATTR_COMPRESSED) && (ni->vol->major_ver >= 3) && NVolCompression(ni->vol) && (ni->vol->cluster_size <= MAX_COMPRESSION_CLUSTER_SIZE) @@ -4843,7 +4843,7 @@ int ntfs_attr_make_non_resident(ntfs_attr *na, goto cluster_free_err_out; } /* Calculate new offsets for the name and the mapping pairs array. */ - if (na->ni->flags & FILE_ATTR_COMPRESSED) + if (!le32_andz(na->ni->flags, FILE_ATTR_COMPRESSED)) name_ofs = (sizeof(ATTR_REC) + 7) & ~7; else name_ofs = (sizeof(ATTR_REC) - sizeof(a->compressed_size) + 7) & ~7; @@ -5349,7 +5349,7 @@ static int ntfs_attr_make_resident(ntfs_attr *na, ntfs_attr_search_ctx *ctx) && (na->ni->vol->major_ver >= 3) && NVolCompression(na->ni->vol) && (na->ni->vol->cluster_size <= MAX_COMPRESSION_CLUSTER_SIZE) - && (na->ni->flags & FILE_ATTR_COMPRESSED)) { + && !le32_andz(na->ni->flags, FILE_ATTR_COMPRESSED)) { a->flags |= ATTR_IS_COMPRESSED; na->data_flags = a->flags; } diff --git a/libntfs-3g/dir.c b/libntfs-3g/dir.c index 6de349de..ac65626a 100644 --- a/libntfs-3g/dir.c +++ b/libntfs-3g/dir.c @@ -925,16 +925,16 @@ static u32 ntfs_dir_entry_type(ntfs_inode *dir_ni, MFT_REF mref, dt_type = NTFS_DT_UNKNOWN; ni = ntfs_inode_open(dir_ni->vol, mref); if (ni) { - if ((attributes & FILE_ATTR_REPARSE_POINT) + if (!le32_andz(attributes, FILE_ATTR_REPARSE_POINT) && ntfs_possible_symlink(ni)) dt_type = NTFS_DT_LNK; else - if ((attributes & FILE_ATTR_SYSTEM) + if (!le32_andz(attributes, FILE_ATTR_SYSTEM) && !(attributes & FILE_ATTR_I30_INDEX_PRESENT)) dt_type = ntfs_interix_types(ni); else - dt_type = (attributes - & FILE_ATTR_I30_INDEX_PRESENT + dt_type = (!le32_andz(attributes, + FILE_ATTR_I30_INDEX_PRESENT) ? NTFS_DT_DIR : NTFS_DT_REG); if (ntfs_inode_close(ni)) { /* anything special worth doing ? */ @@ -987,13 +987,13 @@ static int ntfs_filldir(ntfs_inode *dir_ni, s64 *pos, u8 ivcn_bits, /* Skip root directory self reference entry. */ if (MREF_LE(ie->indexed_file) == FILE_root) return 0; - if ((ie->key.file_name.file_attributes - & (FILE_ATTR_REPARSE_POINT | FILE_ATTR_SYSTEM)) + if (!le32_andz(ie->key.file_name.file_attributes, + FILE_ATTR_REPARSE_POINT | FILE_ATTR_SYSTEM) && !metadata) dt_type = ntfs_dir_entry_type(dir_ni, mref, ie->key.file_name.file_attributes); - else if (ie->key.file_name.file_attributes - & FILE_ATTR_I30_INDEX_PRESENT) + else if (!le32_andz(ie->key.file_name.file_attributes, + FILE_ATTR_I30_INDEX_PRESENT)) dt_type = NTFS_DT_DIR; else dt_type = NTFS_DT_REG; @@ -1500,7 +1500,7 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid, return NULL; } - if (dir_ni->flags & FILE_ATTR_REPARSE_POINT) { + if (!le32_andz(dir_ni->flags, FILE_ATTR_REPARSE_POINT)) { errno = EOPNOTSUPP; return NULL; } @@ -1552,7 +1552,7 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid, * unless NTFS version < 3.0 or cluster size > 4K * or compression has been disabled */ - if ((dir_ni->flags & FILE_ATTR_COMPRESSED) + if (!le32_andz(dir_ni->flags, FILE_ATTR_COMPRESSED) && (dir_ni->vol->major_ver >= 3) && NVolCompression(dir_ni->vol) && (dir_ni->vol->cluster_size <= MAX_COMPRESSION_CLUSTER_SIZE) @@ -2157,7 +2157,7 @@ static int ntfs_link_i(ntfs_inode *ni, ntfs_inode *dir_ni, const ntfschar *name, goto err_out; } - if ((ni->flags & FILE_ATTR_REPARSE_POINT) + if (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT) && !ntfs_possible_symlink(ni)) { err = EOPNOTSUPP; goto err_out; diff --git a/libntfs-3g/efs.c b/libntfs-3g/efs.c index 7663a16e..af9eb211 100644 --- a/libntfs-3g/efs.c +++ b/libntfs-3g/efs.c @@ -79,7 +79,7 @@ int ntfs_get_efs_info(ntfs_inode *ni, char *value, size_t size) s64 attr_size = 0; if (ni) { - if (ni->flags & FILE_ATTR_ENCRYPTED) { + if (!le32_andz(ni->flags, FILE_ATTR_ENCRYPTED)) { efs_info = (EFS_ATTR_HEADER*)ntfs_attr_readall(ni, AT_LOGGED_UTILITY_STREAM,(ntfschar*)NULL, 0, &attr_size); @@ -222,8 +222,8 @@ int ntfs_set_efs_info(ntfs_inode *ni, const char *value, size_t size, res = 0; if (ni && value && size) { - if (ni->flags & (FILE_ATTR_ENCRYPTED | FILE_ATTR_COMPRESSED)) { - if (ni->flags & FILE_ATTR_ENCRYPTED) { + if (!le32_andz(ni->flags, FILE_ATTR_ENCRYPTED | FILE_ATTR_COMPRESSED)) { + if (!le32_andz(ni->flags, FILE_ATTR_ENCRYPTED)) { ntfs_log_trace("Inode %lld already encrypted\n", (long long)ni->mft_no); errno = EEXIST; diff --git a/libntfs-3g/index.c b/libntfs-3g/index.c index 32b6d902..80decf25 100644 --- a/libntfs-3g/index.c +++ b/libntfs-3g/index.c @@ -1857,7 +1857,7 @@ int ntfs_index_remove(ntfs_inode *dir_ni, ntfs_inode *ni, if (ntfs_index_lookup(key, keylen, icx)) goto err_out; - if ((((FILE_NAME_ATTR *)icx->data)->file_attributes & + if (!le32_andz(((FILE_NAME_ATTR *)icx->data)->file_attributes, FILE_ATTR_REPARSE_POINT) && !ntfs_possible_symlink(ni)) { errno = EOPNOTSUPP; diff --git a/libntfs-3g/inode.c b/libntfs-3g/inode.c index fefccc37..0043fc7b 100644 --- a/libntfs-3g/inode.c +++ b/libntfs-3g/inode.c @@ -807,7 +807,7 @@ static int ntfs_inode_sync_file_name(ntfs_inode *ni, ntfs_inode *dir_ni) } /* Collect the reparse tag, if any */ reparse_tag = cpu_to_le32(0); - if (ni->flags & FILE_ATTR_REPARSE_POINT) { + if (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) { if (!ntfs_attr_lookup(AT_REPARSE_POINT, NULL, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) { rpp = (REPARSE_POINT*)((u8 *)ctx->attr + diff --git a/libntfs-3g/reparse.c b/libntfs-3g/reparse.c index b0f7c9b4..4589fdee 100644 --- a/libntfs-3g/reparse.c +++ b/libntfs-3g/reparse.c @@ -257,7 +257,7 @@ static char *search_absolute(ntfs_volume *vol, ntfschar *path, && (start < count)); if (ni && ((!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY) ? isdir : !isdir) - || (ni->flags & FILE_ATTR_REPARSE_POINT))) + || (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)))) if (ntfs_ucstombs(path, count, &target, 0) < 0) { if (target) { free(target); @@ -347,7 +347,7 @@ static char *search_relative(ntfs_inode *ni, ntfschar *path, int count) if (!curni) ok = FALSE; else { - if (curni->flags & FILE_ATTR_REPARSE_POINT) + if (!le32_andz(curni->flags, FILE_ATTR_REPARSE_POINT)) morelinks = TRUE; if (ok && ((pos + lth) < count)) { path[pos + lth] = const_cpu_to_le16('/'); @@ -786,8 +786,8 @@ char *ntfs_make_symlink(ntfs_inode *ni, const char *mnt_point, } break; case ABS_TARGET : - if (symlink_data->flags - & const_cpu_to_le32(1)) { + if (!le32_andz(symlink_data->flags, + const_cpu_to_le32(1))) { target = ntfs_get_abslink(vol, p, lth/2, mnt_point, isdir); @@ -796,8 +796,8 @@ char *ntfs_make_symlink(ntfs_inode *ni, const char *mnt_point, } break; case REL_TARGET : - if (symlink_data->flags - & const_cpu_to_le32(1)) { + if (!le32_andz(symlink_data->flags, + const_cpu_to_le32(1))) { target = ntfs_get_rellink(ni, p, lth/2); if (target) @@ -1081,7 +1081,7 @@ int ntfs_get_ntfs_reparse_data(ntfs_inode *ni, char *value, size_t size) attr_size = 0; /* default to no data and no error */ if (ni) { - if (ni->flags & FILE_ATTR_REPARSE_POINT) { + if (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) { reparse_attr = (REPARSE_POINT*)ntfs_attr_readall(ni, AT_REPARSE_POINT,(ntfschar*)NULL, 0, &attr_size); if (reparse_attr) { diff --git a/libntfs-3g/security.c b/libntfs-3g/security.c index 143376c0..afdc6612 100644 --- a/libntfs-3g/security.c +++ b/libntfs-3g/security.c @@ -4435,9 +4435,9 @@ int ntfs_set_ntfs_attrib(ntfs_inode *ni, * and set index root accordingly */ settable |= FILE_ATTR_COMPRESSED; - if ((ni->flags ^ cpu_to_le32(attrib)) - & FILE_ATTR_COMPRESSED) { - if (ni->flags & FILE_ATTR_COMPRESSED) + if (!le32_andz(ni->flags ^ cpu_to_le32(attrib), + FILE_ATTR_COMPRESSED)) { + if (!le32_andz(ni->flags, FILE_ATTR_COMPRESSED)) dirflags = const_cpu_to_le16(0); else dirflags = ATTR_IS_COMPRESSED; @@ -5040,9 +5040,9 @@ BOOL ntfs_set_file_attributes(struct SECURITY_API *scapi, * and set index root accordingly */ settable |= FILE_ATTR_COMPRESSED; - if ((ni->flags ^ cpu_to_le32(attrib)) - & FILE_ATTR_COMPRESSED) { - if (ni->flags & FILE_ATTR_COMPRESSED) + if (!le32_andz(ni->flags ^ cpu_to_le32(attrib), + FILE_ATTR_COMPRESSED)) { + if (!le32_andz(ni->flags, FILE_ATTR_COMPRESSED)) dirflags = const_cpu_to_le16(0); else dirflags = ATTR_IS_COMPRESSED; diff --git a/ntfsprogs/ntfsinfo.c b/ntfsprogs/ntfsinfo.c index 66f60464..5862444d 100644 --- a/ntfsprogs/ntfsinfo.c +++ b/ntfsprogs/ntfsinfo.c @@ -514,71 +514,71 @@ static void ntfs_dump_flags(const char *indent, ATTR_TYPES type, le32 flags) const le32 original_flags = flags; printf("%sFile attributes:\t", indent); - if (flags & FILE_ATTR_READONLY) { + if (!le32_andz(flags, FILE_ATTR_READONLY)) { printf(" READONLY"); flags &= ~FILE_ATTR_READONLY; } - if (flags & FILE_ATTR_HIDDEN) { + if (!le32_andz(flags, FILE_ATTR_HIDDEN)) { printf(" HIDDEN"); flags &= ~FILE_ATTR_HIDDEN; } - if (flags & FILE_ATTR_SYSTEM) { + if (!le32_andz(flags, FILE_ATTR_SYSTEM)) { printf(" SYSTEM"); flags &= ~FILE_ATTR_SYSTEM; } - if (flags & FILE_ATTR_DIRECTORY) { + if (!le32_andz(flags, FILE_ATTR_DIRECTORY)) { printf(" DIRECTORY"); flags &= ~FILE_ATTR_DIRECTORY; } - if (flags & FILE_ATTR_ARCHIVE) { + if (!le32_andz(flags, FILE_ATTR_ARCHIVE)) { printf(" ARCHIVE"); flags &= ~FILE_ATTR_ARCHIVE; } - if (flags & FILE_ATTR_DEVICE) { + if (!le32_andz(flags, FILE_ATTR_DEVICE)) { printf(" DEVICE"); flags &= ~FILE_ATTR_DEVICE; } - if (flags & FILE_ATTR_NORMAL) { + if (!le32_andz(flags, FILE_ATTR_NORMAL)) { printf(" NORMAL"); flags &= ~FILE_ATTR_NORMAL; } - if (flags & FILE_ATTR_TEMPORARY) { + if (!le32_andz(flags, FILE_ATTR_TEMPORARY)) { printf(" TEMPORARY"); flags &= ~FILE_ATTR_TEMPORARY; } - if (flags & FILE_ATTR_SPARSE_FILE) { + if (!le32_andz(flags, FILE_ATTR_SPARSE_FILE)) { printf(" SPARSE_FILE"); flags &= ~FILE_ATTR_SPARSE_FILE; } - if (flags & FILE_ATTR_REPARSE_POINT) { + if (!le32_andz(flags, FILE_ATTR_REPARSE_POINT)) { printf(" REPARSE_POINT"); flags &= ~FILE_ATTR_REPARSE_POINT; } - if (flags & FILE_ATTR_COMPRESSED) { + if (!le32_andz(flags, FILE_ATTR_COMPRESSED)) { printf(" COMPRESSED"); flags &= ~FILE_ATTR_COMPRESSED; } - if (flags & FILE_ATTR_OFFLINE) { + if (!le32_andz(flags, FILE_ATTR_OFFLINE)) { printf(" OFFLINE"); flags &= ~FILE_ATTR_OFFLINE; } - if (flags & FILE_ATTR_NOT_CONTENT_INDEXED) { + if (!le32_andz(flags, FILE_ATTR_NOT_CONTENT_INDEXED)) { printf(" NOT_CONTENT_INDEXED"); flags &= ~FILE_ATTR_NOT_CONTENT_INDEXED; } - if (flags & FILE_ATTR_ENCRYPTED) { + if (!le32_andz(flags, FILE_ATTR_ENCRYPTED)) { printf(" ENCRYPTED"); flags &= ~FILE_ATTR_ENCRYPTED; } /* We know that FILE_ATTR_I30_INDEX_PRESENT only exists on $FILE_NAME, and in case we are wrong, let it appear as UNKNOWN */ if (le32_eq(type, AT_FILE_NAME)) { - if (flags & FILE_ATTR_I30_INDEX_PRESENT) { + if (!le32_andz(flags, FILE_ATTR_I30_INDEX_PRESENT)) { printf(" I30_INDEX"); flags &= ~FILE_ATTR_I30_INDEX_PRESENT; } } - if (flags & FILE_ATTR_VIEW_INDEX_PRESENT) { + if (!le32_andz(flags, FILE_ATTR_VIEW_INDEX_PRESENT)) { printf(" VIEW_INDEX"); flags &= ~FILE_ATTR_VIEW_INDEX_PRESENT; } @@ -812,7 +812,7 @@ static void ntfs_dump_filename(const char *indent, (unsigned)file_name_attr->file_name_length, (unsigned)file_name_attr->file_name_length); ntfs_dump_flags(indent, AT_FILE_NAME, file_name_attr->file_attributes); - if (file_name_attr->file_attributes & FILE_ATTR_REPARSE_POINT && + if (!le32_andz(file_name_attr->file_attributes, FILE_ATTR_REPARSE_POINT) && !le32_cmpz(file_name_attr->reparse_point_tag)) printf("%sReparse point tag:\t 0x%x\n", indent, (unsigned) le32_to_cpu(file_name_attr->reparse_point_tag)); diff --git a/ntfsprogs/ntfsundelete.c b/ntfsprogs/ntfsundelete.c index 443b2a72..1c00dcf3 100644 --- a/ntfsprogs/ntfsundelete.c +++ b/ntfsprogs/ntfsundelete.c @@ -1578,17 +1578,17 @@ static void dump_record(struct ufile *file) ntfs_log_quiet("Filename: (%d) %s\n", f->name_space, f->name); ntfs_log_quiet("File Flags: "); - if (f->flags & FILE_ATTR_SYSTEM) + if (!le32_andz(f->flags, FILE_ATTR_SYSTEM)) ntfs_log_quiet("System "); - if (f->flags & FILE_ATTR_DIRECTORY) + if (!le32_andz(f->flags, FILE_ATTR_DIRECTORY)) ntfs_log_quiet("Directory "); - if (f->flags & FILE_ATTR_SPARSE_FILE) + if (!le32_andz(f->flags, FILE_ATTR_SPARSE_FILE)) ntfs_log_quiet("Sparse "); - if (f->flags & FILE_ATTR_REPARSE_POINT) + if (!le32_andz(f->flags, FILE_ATTR_REPARSE_POINT)) ntfs_log_quiet("Reparse "); - if (f->flags & FILE_ATTR_COMPRESSED) + if (!le32_andz(f->flags, FILE_ATTR_COMPRESSED)) ntfs_log_quiet("Compressed "); - if (f->flags & FILE_ATTR_ENCRYPTED) + if (!le32_andz(f->flags, FILE_ATTR_ENCRYPTED)) ntfs_log_quiet("Encrypted "); if (!(f->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_DIRECTORY | FILE_ATTR_SPARSE_FILE | FILE_ATTR_REPARSE_POINT | diff --git a/src/lowntfs-3g.c b/src/lowntfs-3g.c index c6cf2fb3..e292fb0a 100644 --- a/src/lowntfs-3g.c +++ b/src/lowntfs-3g.c @@ -603,8 +603,8 @@ static int ntfs_fuse_getstat(struct SECURITY_CONTEXT *scx, memset(stbuf, 0, sizeof(struct stat)); withusermapping = (scx->mapping[MAPUSERS] != (struct MAPPING*)NULL); if (!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY) - || (ni->flags & FILE_ATTR_REPARSE_POINT)) { - if (ni->flags & FILE_ATTR_REPARSE_POINT) { + || !le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) { + if (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) { char *target; int attr_size; @@ -662,7 +662,7 @@ static int ntfs_fuse_getstat(struct SECURITY_CONTEXT *scx, * also include 2 bytes for padding info */ if (ctx->efs_raw - && (ni->flags & FILE_ATTR_ENCRYPTED) + && !le32_andz(ni->flags, FILE_ATTR_ENCRYPTED) && ni->data_size) stbuf->st_size = ((ni->data_size + 511) & ~511) + 2; #endif /* HAVE_SETXATTR */ @@ -672,7 +672,7 @@ static int ntfs_fuse_getstat(struct SECURITY_CONTEXT *scx, */ stbuf->st_blocks = (ni->allocated_size + 511) >> 9; stbuf->st_nlink = le16_to_cpu(ni->mrec->link_count); - if (ni->flags & FILE_ATTR_SYSTEM) { + if (!le32_andz(ni->flags, FILE_ATTR_SYSTEM)) { na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); if (!na) { stbuf->st_ino = ni->mft_no; @@ -896,7 +896,7 @@ static void ntfs_fuse_readlink(fuse_req_t req, fuse_ino_t ino) /* * Reparse point : analyze as a junction point */ - if (ni->flags & FILE_ATTR_REPARSE_POINT) { + if (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) { int attr_size; errno = 0; @@ -1272,7 +1272,7 @@ static void ntfs_fuse_open(fuse_req_t req, fuse_ino_t ino, /* mark a future need to fixup encrypted inode */ if (ctx->efs_raw && le16_andz(na->data_flags, ATTR_IS_ENCRYPTED) - && (ni->flags & FILE_ATTR_ENCRYPTED)) + && !le32_andz(ni->flags, FILE_ATTR_ENCRYPTED)) state |= CLOSE_ENCRYPTED; #endif /* HAVE_SETXATTR */ /* mark a future need to update the mtime */ @@ -1974,14 +1974,14 @@ static int ntfs_fuse_create(fuse_req_t req, fuse_ino_t parent, const char *name, } set_archive(ni); /* mark a need to compress the end of file */ - if (fi && (ni->flags & FILE_ATTR_COMPRESSED)) { + if (fi && !le32_andz(ni->flags, FILE_ATTR_COMPRESSED)) { state |= CLOSE_COMPRESSED; } #ifdef HAVE_SETXATTR /* extended attributes interface required */ /* mark a future need to fixup encrypted inode */ if (fi && ctx->efs_raw - && (ni->flags & FILE_ATTR_ENCRYPTED)) + && !le32_andz(ni->flags, FILE_ATTR_ENCRYPTED)) state |= CLOSE_ENCRYPTED; #endif /* HAVE_SETXATTR */ if (fi && ctx->dmtime) @@ -2891,7 +2891,7 @@ static void ntfs_fuse_listxattr(fuse_req_t req, fuse_ino_t ino, size_t size) goto out; } /* Return with no result for symlinks, fifo, etc. */ - if (ni->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT)) + if (!le32_andz(ni->flags, FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT)) goto exit; /* otherwise file must be readable */ #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) @@ -3040,7 +3040,7 @@ static void ntfs_fuse_getxattr(fuse_req_t req, fuse_ino_t ino, const char *name, goto out; } /* Return with no result for symlinks, fifo, etc. */ - if (ni->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT)) { + if (!le32_andz(ni->flags, FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT)) { res = -ENODATA; goto exit; } @@ -3237,7 +3237,7 @@ static void ntfs_fuse_setxattr(fuse_req_t req, fuse_ino_t ino, const char *name, break; default : /* User xattr not allowed for symlinks, fifo, etc. */ - if (ni->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT)) { + if (!le32_andz(ni->flags, FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT)) { res = -EPERM; goto exit; } @@ -3306,7 +3306,7 @@ static void ntfs_fuse_setxattr(fuse_req_t req, fuse_ino_t ino, const char *name, res = -errno; else { if (ctx->efs_raw - && (ni->flags & FILE_ATTR_ENCRYPTED)) { + && !le32_andz(ni->flags, FILE_ATTR_ENCRYPTED)) { if (ntfs_efs_fixup_attribute(NULL,na)) res = -errno; } @@ -3482,7 +3482,7 @@ static void ntfs_fuse_removexattr(fuse_req_t req, fuse_ino_t ino, const char *na break; default : /* User xattr not allowed for symlinks, fifo, etc. */ - if (ni->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT)) { + if (!le32_andz(ni->flags, FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT)) { res = -EPERM; goto exit; } diff --git a/src/ntfs-3g.c b/src/ntfs-3g.c index b82fe843..8042af78 100644 --- a/src/ntfs-3g.c +++ b/src/ntfs-3g.c @@ -697,9 +697,9 @@ static int ntfs_fuse_getattr(const char *org_path, struct stat *stbuf) } #endif if ((!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY) - || (ni->flags & FILE_ATTR_REPARSE_POINT)) + || !le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) && !stream_name_len) { - if (ni->flags & FILE_ATTR_REPARSE_POINT) { + if (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) { char *target; int attr_size; @@ -752,7 +752,7 @@ static int ntfs_fuse_getattr(const char *org_path, struct stat *stbuf) * also include 2 bytes for padding info */ if (ctx->efs_raw - && (ni->flags & FILE_ATTR_ENCRYPTED) + && (!le32_andz(ni->flags, FILE_ATTR_ENCRYPTED)) && ni->data_size) stbuf->st_size = ((ni->data_size + 511) & ~511) + 2; #endif /* HAVE_SETXATTR */ @@ -762,7 +762,7 @@ static int ntfs_fuse_getattr(const char *org_path, struct stat *stbuf) */ stbuf->st_blocks = (ni->allocated_size + 511) >> 9; stbuf->st_nlink = le16_to_cpu(ni->mrec->link_count); - if (ni->flags & FILE_ATTR_SYSTEM || stream_name_len) { + if (!le32_andz(ni->flags, FILE_ATTR_SYSTEM) || stream_name_len) { na = ntfs_attr_open(ni, AT_DATA, stream_name, stream_name_len); if (!na) { @@ -925,7 +925,7 @@ static int ntfs_fuse_readlink(const char *org_path, char *buf, size_t buf_size) /* * Reparse point : analyze as a junction point */ - if (ni->flags & FILE_ATTR_REPARSE_POINT) { + if (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) { char *target; int attr_size; @@ -1209,7 +1209,7 @@ static int ntfs_fuse_open(const char *org_path, /* mark a future need to fixup encrypted inode */ if (ctx->efs_raw && le16_andz(na->data_flags, ATTR_IS_ENCRYPTED) - && (ni->flags & FILE_ATTR_ENCRYPTED)) + && !le32_andz(ni->flags, FILE_ATTR_ENCRYPTED)) fi->fh |= CLOSE_ENCRYPTED; #endif /* HAVE_SETXATTR */ /* mark a future need to update the mtime */ @@ -1768,14 +1768,14 @@ static int ntfs_fuse_create(const char *org_path, mode_t typemode, dev_t dev, } set_archive(ni); /* mark a need to compress the end of file */ - if (fi && (ni->flags & FILE_ATTR_COMPRESSED)) { + if (fi && !le32_andz(ni->flags, FILE_ATTR_COMPRESSED)) { fi->fh |= CLOSE_COMPRESSED; } #ifdef HAVE_SETXATTR /* extended attributes interface required */ /* mark a future need to fixup encrypted inode */ if (fi && ctx->efs_raw - && (ni->flags & FILE_ATTR_ENCRYPTED)) + && !le32_andz(ni->flags, FILE_ATTR_ENCRYPTED)) fi->fh |= CLOSE_ENCRYPTED; #endif /* HAVE_SETXATTR */ /* mark a need to update the mtime */ @@ -1842,12 +1842,12 @@ static int ntfs_fuse_create_stream(const char *path, && fi && (fi->flags & (O_WRONLY | O_RDWR))) { /* mark a future need to compress the last block */ - if (ni->flags & FILE_ATTR_COMPRESSED) + if (!le32_andz(ni->flags, FILE_ATTR_COMPRESSED)) fi->fh |= CLOSE_COMPRESSED; #ifdef HAVE_SETXATTR /* extended attributes interface required */ /* mark a future need to fixup encrypted inode */ if (ctx->efs_raw - && (ni->flags & FILE_ATTR_ENCRYPTED)) + && !le32_andz(ni->flags, FILE_ATTR_ENCRYPTED)) fi->fh |= CLOSE_ENCRYPTED; #endif /* HAVE_SETXATTR */ if (ctx->dmtime) @@ -2689,7 +2689,7 @@ static int ntfs_fuse_listxattr(const char *path, char *list, size_t size) if (!ni) return -errno; /* Return with no result for symlinks, fifo, etc. */ - if (ni->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT)) + if (!le32_andz(ni->flags, FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT)) goto exit; /* otherwise file must be readable */ #if !KERNELPERMS | (POSIXACLS & !KERNELACLS) @@ -2891,7 +2891,7 @@ static int ntfs_fuse_getxattr(const char *path, const char *name, if (!ni) return -errno; /* Return with no result for symlinks, fifo, etc. */ - if (ni->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT)) { + if (!le32_andz(ni->flags, FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT)) { res = -ENODATA; goto exit; } @@ -3080,7 +3080,7 @@ static int ntfs_fuse_setxattr(const char *path, const char *name, #else /* User xattr not allowed for symlinks, fifo, etc. */ if ((namespace == XATTRNS_USER) - && (ni->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT))) { + && (!le32_andz(ni->flags, FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT))) { res = -EPERM; goto exit; } @@ -3136,7 +3136,7 @@ static int ntfs_fuse_setxattr(const char *path, const char *name, res = -errno; else { if (ctx->efs_raw - && (ni->flags & FILE_ATTR_ENCRYPTED)) { + && !le32_andz(ni->flags, FILE_ATTR_ENCRYPTED)) { if (ntfs_efs_fixup_attribute(NULL,na)) res = -errno; } @@ -3317,7 +3317,7 @@ static int ntfs_fuse_removexattr(const char *path, const char *name) #else /* User xattr not allowed for symlinks, fifo, etc. */ if ((namespace == XATTRNS_USER) - && (ni->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT))) { + && (!le32_andz(ni->flags, FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT))) { res = -EPERM; goto exit; } diff --git a/src/ntfs-3g_common.c b/src/ntfs-3g_common.c index 38ccd742..a85f8aff 100644 --- a/src/ntfs-3g_common.c +++ b/src/ntfs-3g_common.c @@ -736,7 +736,7 @@ int ntfs_fuse_listxattr_common(ntfs_inode *ni, ntfs_attr_search_ctx *actx, } #else /* XATTR_MAPPINGS */ /* List efs info xattr for encrypted files */ - if (ni->vol->efs_raw && (ni->flags & FILE_ATTR_ENCRYPTED)) { + if (ni->vol->efs_raw && !le32_andz(ni->flags, FILE_ATTR_ENCRYPTED)) { ret += sizeof(nf_ns_alt_xattr_efsinfo); if ((size_t)ret <= size) { memcpy(to, nf_ns_alt_xattr_efsinfo,