diff --git a/include/ntfs-3g/endians.h b/include/ntfs-3g/endians.h index b0d1e63a..8b374968 100644 --- a/include/ntfs-3g/endians.h +++ b/include/ntfs-3g/endians.h @@ -312,4 +312,6 @@ #define le16_cmpz(a) (!(a)) +#define le32_cmpz(a) (!(a)) + #endif /* defined _NTFS_ENDIANS_H */ diff --git a/libntfs-3g/acls.c b/libntfs-3g/acls.c index 202230fa..a6eb51ac 100644 --- a/libntfs-3g/acls.c +++ b/libntfs-3g/acls.c @@ -2532,7 +2532,7 @@ static int buildacls(char *secattr, int offs, mode_t mode, int isdir, } } denials &= ~grants; - if (denials) { + if (!le32_cmpz(denials)) { pdace->type = ACCESS_DENIED_ACE_TYPE; pdace->size = cpu_to_le16(usidsz + 8); pdace->mask = denials; @@ -2619,7 +2619,7 @@ static int buildacls(char *secattr, int offs, mode_t mode, int isdir, denials |= FILE_READ; } denials &= ~(grants | OWNER_RIGHTS); - if (denials) { + if (!le32_cmpz(denials)) { pdace->type = ACCESS_DENIED_ACE_TYPE; pdace->size = cpu_to_le16(gsidsz + 8); pdace->mask = denials; @@ -2935,7 +2935,7 @@ static int merge_permissions(BOOL isdir, perm = 0; /* build owner permission */ - if (owner) { + if (!le32_cmpz(owner)) { if (isdir) { /* exec if any of list, traverse */ if (owner & DIR_GEXEC) @@ -2959,7 +2959,7 @@ static int merge_permissions(BOOL isdir, } } /* build group permission */ - if (group) { + if (!le32_cmpz(group)) { if (isdir) { /* exec if any of list, traverse */ if (group & DIR_GEXEC) @@ -2983,7 +2983,7 @@ static int merge_permissions(BOOL isdir, } } /* build world permission */ - if (world) { + if (!le32_cmpz(world)) { if (isdir) { /* exec if any of list, traverse */ if (world & DIR_GEXEC) @@ -3007,7 +3007,7 @@ static int merge_permissions(BOOL isdir, } } /* build special permission flags */ - if (special) { + if (!le32_cmpz(special)) { if (special & FILE_APPEND_DATA) perm |= S_ISUID; if (special & FILE_WRITE_DATA) diff --git a/libntfs-3g/attrib.c b/libntfs-3g/attrib.c index 55cee66c..9687bac3 100644 --- a/libntfs-3g/attrib.c +++ b/libntfs-3g/attrib.c @@ -3522,7 +3522,7 @@ ATTR_DEF *ntfs_attr_find_in_attrdef(const ntfs_volume *vol, return NULL; } for (ad = vol->attrdef; (u8*)ad - (u8*)vol->attrdef < - vol->attrdef_len && ad->type; ++ad) { + vol->attrdef_len && !le32_cmpz(ad->type); ++ad) { /* We haven't found it yet, carry on searching. */ if (le32_to_cpu(ad->type) < le32_to_cpu(type)) continue; diff --git a/libntfs-3g/dir.c b/libntfs-3g/dir.c index 4624fc31..f34b139c 100644 --- a/libntfs-3g/dir.c +++ b/libntfs-3g/dir.c @@ -1516,7 +1516,7 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid, * JPA Depending on available inherited security descriptor, * Write STANDARD_INFORMATION v1.2 (no inheritance) or v3 */ - if (securid) + if (!le32_cmpz(securid)) si_len = sizeof(STANDARD_INFORMATION); else si_len = offsetof(STANDARD_INFORMATION, v1_end); @@ -1529,7 +1529,7 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid, si->last_data_change_time = ni->last_data_change_time; si->last_mft_change_time = ni->last_mft_change_time; si->last_access_time = ni->last_access_time; - if (securid) { + if (!le32_cmpz(securid)) { set_nino_flag(ni, v3_Extensions); ni->owner_id = si->owner_id = 0; ni->security_id = si->security_id = securid; diff --git a/libntfs-3g/security.c b/libntfs-3g/security.c index 932713f0..46ad78d8 100644 --- a/libntfs-3g/security.c +++ b/libntfs-3g/security.c @@ -772,7 +772,7 @@ static le32 entersecurityattr(ntfs_volume *vol, * the last byte overflows on a wrong block. */ - if (securid) { + if (!le32_cmpz(securid)) { gap = (-size) & (ALIGN_SDS_ENTRY - 1); offs += gap + size; if ((offs + attrsz + sizeof(SECURITY_DESCRIPTOR_HEADER) - 1) @@ -1012,7 +1012,7 @@ static int update_secur_descr(ntfs_volume *vol, securid = setsecurityattr(vol, (const SECURITY_DESCRIPTOR_RELATIVE*)newattr, (s64)newattrsz); - if (securid) { + if (!le32_cmpz(securid)) { na = ntfs_attr_open(ni, AT_STANDARD_INFORMATION, AT_UNNAMED, 0); if (na) { @@ -1088,7 +1088,7 @@ static int upgrade_secur_desc(ntfs_volume *vol, securid = setsecurityattr(vol, (const SECURITY_DESCRIPTOR_RELATIVE*)attr, (s64)attrsz); - if (securid) { + if (!le32_cmpz(securid)) { na = ntfs_attr_open(ni, AT_STANDARD_INFORMATION, AT_UNNAMED, 0); if (na) { @@ -1595,7 +1595,7 @@ static struct CACHED_PERMISSIONS *enter_cache(struct SECURITY_CONTEXT *scx, /* cacheing is only possible if a security_id has been defined */ if (test_nino_flag(ni, v3_Extensions) - && ni->security_id) { + && !le32_cmpz(ni->security_id)) { /* * Immediately test the most frequent situation * where the entry exists @@ -1747,7 +1747,7 @@ static struct CACHED_PERMISSIONS *fetch_cache(struct SECURITY_CONTEXT *scx, /* cacheing is only possible if a security_id has been defined */ cacheentry = (struct CACHED_PERMISSIONS*)NULL; if (test_nino_flag(ni, v3_Extensions) - && (ni->security_id)) { + && !le32_cmpz(ni->security_id)) { securindex = le32_to_cpu(ni->security_id); index1 = securindex >> CACHE_PERMISSIONS_BITS; index2 = securindex & ((1 << CACHE_PERMISSIONS_BITS) - 1); @@ -1882,7 +1882,7 @@ static char *getsecurityattr(ntfs_volume *vol, ntfs_inode *ni) * attribute */ if (test_nino_flag(ni, v3_Extensions) - && vol->secure_ni && ni->security_id) { + && vol->secure_ni && !le32_cmpz(ni->security_id)) { /* get v3.x descriptor in $Secure */ securid.security_id = ni->security_id; securattr = retrievesecurityattr(vol,securid); @@ -2841,7 +2841,7 @@ le32 ntfs_alloc_securid(struct SECURITY_CONTEXT *scx, securid = setsecurityattr(scx->vol, (const SECURITY_DESCRIPTOR_RELATIVE*)newattr, newattrsz); - if (securid) { + if (!le32_cmpz(securid)) { /* update cache, for subsequent use */ wanted.securid = securid; ntfs_enter_cache(scx->vol->securid_cache, @@ -3957,7 +3957,7 @@ static le32 build_inherited_id(struct SECURITY_CONTEXT *scx, * do not test SE_DACL_PRESENT (wrong for "DR Watson") */ pnhead->dacl = const_cpu_to_le32(0); - if (pphead->dacl) { + if (!le32_cmpz(pphead->dacl)) { offpacl = le32_to_cpu(pphead->dacl); ppacl = (const ACL*)&parentattr[offpacl]; pnacl = (ACL*)&newattr[pos]; @@ -3974,7 +3974,7 @@ static le32 build_inherited_id(struct SECURITY_CONTEXT *scx, * locate and inherit SACL */ pnhead->sacl = const_cpu_to_le32(0); - if (pphead->sacl) { + if (!le32_cmpz(pphead->sacl)) { offpacl = le32_to_cpu(pphead->sacl); ppacl = (const ACL*)&parentattr[offpacl]; pnacl = (ACL*)&newattr[pos]; @@ -4037,7 +4037,7 @@ le32 ntfs_inherited_id(struct SECURITY_CONTEXT *scx, * the current process owns the parent directory */ if (test_nino_flag(dir_ni, v3_Extensions) - && dir_ni->security_id) { + && !le32_cmpz(dir_ni->security_id)) { cached = fetch_cache(scx, dir_ni); if (cached && (cached->uid == scx->uid) && (cached->gid == scx->gid)) @@ -4058,7 +4058,7 @@ le32 ntfs_inherited_id(struct SECURITY_CONTEXT *scx, * Store the result into cache for further use * if the current process owns the parent directory */ - if (securid) { + if (!le32_cmpz(securid)) { cached = fetch_cache(scx, dir_ni); if (cached && (cached->uid == scx->uid) @@ -4558,7 +4558,7 @@ static BOOL feedsecurityattr(const char *attr, u32 selection, size = sizeof(SECURITY_DESCRIPTOR_RELATIVE); /* locate DACL if requested and available */ - if (phead->dacl && (selection & DACL_SECURITY_INFORMATION)) { + if (!le32_cmpz(phead->dacl) && (selection & DACL_SECURITY_INFORMATION)) { offdacl = le32_to_cpu(phead->dacl); pdacl = (const ACL*)&attr[offdacl]; daclsz = le16_to_cpu(pdacl->size); @@ -4590,7 +4590,7 @@ static BOOL feedsecurityattr(const char *attr, u32 selection, offgroup = gsidsz = 0; /* locate SACL if requested and available */ - if (phead->sacl && (selection & SACL_SECURITY_INFORMATION)) { + if (!le32_cmpz(phead->sacl) && (selection & SACL_SECURITY_INFORMATION)) { /* find end of SACL */ offsacl = le32_to_cpu(phead->sacl); psacl = (const ACL*)&attr[offsacl]; @@ -4717,8 +4717,8 @@ static BOOL mergesecurityattr(ntfs_volume *vol, const char *oldattr, * copy new DACL if selected * or keep old DACL if any */ - if ((selection & DACL_SECURITY_INFORMATION) ? - newhead->dacl : oldhead->dacl) { + if (!le32_cmpz((selection & DACL_SECURITY_INFORMATION) ? + newhead->dacl : oldhead->dacl)) { if (selection & DACL_SECURITY_INFORMATION) { offdacl = le32_to_cpu(newhead->dacl); pdacl = (const ACL*)&newattr[offdacl]; @@ -4749,8 +4749,8 @@ static BOOL mergesecurityattr(ntfs_volume *vol, const char *oldattr, * copy new SACL if selected * or keep old SACL if any */ - if ((selection & SACL_SECURITY_INFORMATION) ? - newhead->sacl : oldhead->sacl) { + if (!le32_cmpz((selection & SACL_SECURITY_INFORMATION) ? + newhead->sacl : oldhead->sacl)) { if (selection & SACL_SECURITY_INFORMATION) { offsacl = le32_to_cpu(newhead->sacl); psacl = (const ACL*)&newattr[offsacl]; @@ -4781,8 +4781,8 @@ static BOOL mergesecurityattr(ntfs_volume *vol, const char *oldattr, * copy new OWNER if selected * or keep old OWNER if any */ - if ((selection & OWNER_SECURITY_INFORMATION) ? - newhead->owner : oldhead->owner) { + if (!le32_cmpz((selection & OWNER_SECURITY_INFORMATION) ? + newhead->owner : oldhead->owner)) { if (selection & OWNER_SECURITY_INFORMATION) { offowner = le32_to_cpu(newhead->owner); powner = (const SID*)&newattr[offowner]; @@ -4804,8 +4804,8 @@ static BOOL mergesecurityattr(ntfs_volume *vol, const char *oldattr, * copy new GROUP if selected * or keep old GROUP if any */ - if ((selection & GROUP_SECURITY_INFORMATION) ? - newhead->group : oldhead->group) { + if (!le32_cmpz((selection & GROUP_SECURITY_INFORMATION) ? + newhead->group : oldhead->group)) { if (selection & GROUP_SECURITY_INFORMATION) { offgroup = le32_to_cpu(newhead->group); pgroup = (const SID*)&newattr[offgroup]; @@ -4874,7 +4874,7 @@ int ntfs_get_file_security(struct SECURITY_API *scapi, if (feedsecurityattr(attr,selection, buf,buflen,psize)) { if (test_nino_flag(ni, v3_Extensions) - && ni->security_id) + && !le32_cmpz(ni->security_id)) res = le32_to_cpu( ni->security_id); else diff --git a/ntfsprogs/ntfsdecrypt.c b/ntfsprogs/ntfsdecrypt.c index 15837d40..1de81596 100644 --- a/ntfsprogs/ntfsdecrypt.c +++ b/ntfsprogs/ntfsdecrypt.c @@ -1246,14 +1246,14 @@ static ntfs_fek *ntfs_inode_fek_get(ntfs_inode *inode, * iterate through the DDF or DRF array, respectively. */ if (df_type == DF_TYPE_DDF) { - if (efs->offset_to_ddf_array) + if (!le32_cmpz(efs->offset_to_ddf_array)) df_array = (EFS_DF_ARRAY_HEADER*)((u8*)efs + le32_to_cpu(efs->offset_to_ddf_array)); else ntfs_log_error("There are no entries in the DDF " "array.\n"); } else if (df_type == DF_TYPE_DRF) { - if (efs->offset_to_drf_array) + if (!le32_cmpz(efs->offset_to_drf_array)) df_array = (EFS_DF_ARRAY_HEADER*)((u8*)efs + le32_to_cpu(efs->offset_to_drf_array)); else diff --git a/ntfsprogs/ntfsinfo.c b/ntfsprogs/ntfsinfo.c index caec40a3..983bf4ae 100644 --- a/ntfsprogs/ntfsinfo.c +++ b/ntfsprogs/ntfsinfo.c @@ -582,7 +582,7 @@ static void ntfs_dump_flags(const char *indent, ATTR_TYPES type, le32 flags) printf(" VIEW_INDEX"); flags &= ~FILE_ATTR_VIEW_INDEX_PRESENT; } - if (flags) + if (!le32_cmpz(flags)) printf(" UNKNOWN: 0x%08x", (unsigned int)le32_to_cpu(flags)); /* Print all the flags in hex. */ printf(" (0x%08x)\n", (unsigned)le32_to_cpu(original_flags)); @@ -813,10 +813,10 @@ static void ntfs_dump_filename(const char *indent, (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 && - file_name_attr->reparse_point_tag) + !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)); - else if (file_name_attr->reparse_point_tag) { + else if (!le32_cmpz(file_name_attr->reparse_point_tag)) { printf("%sEA Length:\t\t %d (0x%x)\n", indent, (unsigned) le16_to_cpu(file_name_attr->packed_ea_size), (unsigned) @@ -994,7 +994,7 @@ static void ntfs_dump_security_descriptor(SECURITY_DESCRIPTOR_ATTR *sec_desc, return; } - if (sec_desc->owner) { + if (!le32_cmpz(sec_desc->owner)) { sid = ntfs_sid_to_mbs((SID *)((char *)sec_desc + le32_to_cpu(sec_desc->owner)), NULL, 0); printf("%s\tOwner SID:\t\t %s\n", indent, sid); @@ -1002,7 +1002,7 @@ static void ntfs_dump_security_descriptor(SECURITY_DESCRIPTOR_ATTR *sec_desc, } else printf("%s\tOwner SID:\t\t missing\n", indent); - if (sec_desc->group) { + if (!le32_cmpz(sec_desc->group)) { sid = ntfs_sid_to_mbs((SID *)((char *)sec_desc + le32_to_cpu(sec_desc->group)), NULL, 0); printf("%s\tGroup SID:\t\t %s\n", indent, sid); @@ -1217,7 +1217,7 @@ static void ntfs_dump_sds(ATTR_RECORD *attr, ntfs_inode *ni) * FIXME: The right way is based on the indexes, so we couldn't * miss real entries. For now, dump until it makes sense. */ - while (sd->length && sd->hash && + while (!le32_cmpz(sd->length) && !le32_cmpz(sd->hash) && le64_to_cpu(sd->offset) < (u64)data_size && le32_to_cpu(sd->length) < (u64)data_size && le64_to_cpu(sd->offset) + @@ -1689,7 +1689,7 @@ static INDEX_ATTR_TYPE get_index_attr_type(ntfs_inode *ni, ATTR_RECORD *attr, if (!attr->name_length) return INDEX_ATTR_UNKNOWN; - if (index_root->type) { + if (!le32_cmpz(index_root->type)) { if (le32_eq(index_root->type, AT_FILE_NAME)) return INDEX_ATTR_DIRECTORY_I30; else @@ -2063,7 +2063,7 @@ static void ntfs_dump_attr_ea(ATTR_RECORD *attr, ntfs_volume *vol) else printf("\n"); } - if (ea->next_entry_offset) { + if (!le32_cmpz(ea->next_entry_offset)) { offset += le32_to_cpu(ea->next_entry_offset); ea = (const EA_ATTR*)((const u8*)ea + le32_to_cpu(ea->next_entry_offset)); diff --git a/ntfsprogs/ntfsresize.c b/ntfsprogs/ntfsresize.c index 1c69dca1..0bcc36c5 100644 --- a/ntfsprogs/ntfsresize.c +++ b/ntfsprogs/ntfsresize.c @@ -3622,7 +3622,7 @@ static int copy_boot(expand_t *expand) /* the hidden sectors are needed to boot into windows */ memcpy(&hidden_sectors_le,&bs->bpb.hidden_sectors,4); /* alignment messed up on the Sparc */ - if (hidden_sectors_le) { + if (!le32_cmpz(hidden_sectors_le)) { hidden_sectors = le32_to_cpu(hidden_sectors_le); if (hidden_sectors >= expand->sector_increment) hidden_sectors -= expand->sector_increment; diff --git a/ntfsprogs/ntfstruncate.c b/ntfsprogs/ntfstruncate.c index ba4379ea..4f5c6a9b 100644 --- a/ntfsprogs/ntfstruncate.c +++ b/ntfsprogs/ntfstruncate.c @@ -542,10 +542,10 @@ static void dump_attr_record(MFT_RECORD *m, ATTR_RECORD *a) return; } u = le32_to_cpu(a->type); - for (i = 0; attr_defs[i].type; i++) + for (i = 0; !le32_cmpz(attr_defs[i].type); i++) if (le32_to_cpu(attr_defs[i].type) >= u) break; - if (attr_defs[i].type) { + if (!le32_cmpz(attr_defs[i].type)) { // printf("type = 0x%x\n", le32_to_cpu(attr_defs[i].type)); // { char *p = (char*)attr_defs[i].name; // printf("name = %c%c%c%c%c\n", *p, p[1], p[2], p[3], p[4]);