Compare commits

...

48 Commits

Author SHA1 Message Date
Erik Larsson 11a3997a0d Merge tag '2021.8.22' into edge.strict_endians
Conflicts:
	libntfs-3g/attrib.c
	libntfs-3g/bootsect.c
	ntfsprogs/ntfsfix.c
2021-09-06 15:12:08 +02:00
Erik Larsson a00610ed15 Merge branch 'edge' into edge.strict_endians
Conflicts:
	include/ntfs-3g/layout.h
	libntfs-3g/acls.c
	libntfs-3g/attrib.c
	libntfs-3g/bootsect.c
	libntfs-3g/dir.c
	libntfs-3g/mft.c
	libntfs-3g/reparse.c
	ntfsprogs/ntfsinfo.c
	ntfsprogs/ntfsresize.c
	ntfsprogs/playlog.c
	src/lowntfs-3g.c
	src/ntfs-3g_common.c
2021-03-05 14:48:11 +02:00
Erik Larsson 3b26cf925a Merge tag '2017.3.23' into edge.strict_endians 2017-03-23 10:41:56 +01:00
Erik Larsson 26ed262ae4 Merge tag '2017.2.15' into edge.strict_endians
Conflicts:
	include/ntfs-3g/layout.h
	include/ntfs-3g/logfile.h
	libntfs-3g/reparse.c
	libntfs-3g/unistr.c
	ntfsprogs/ntfsdump_logfile.c
	ntfsprogs/ntfsfix.c
	ntfsprogs/ntfsinfo.c
	ntfsprogs/ntfsrecover.c
	ntfsprogs/ntfsresize.c
	ntfsprogs/playlog.c
	src/lowntfs-3g.c
	src/ntfs-3g.c
2017-03-21 05:41:54 +01:00
Erik Larsson c9b795489e Merge version 2016.2.22 into the strict endians branch.
Conflicts:
	libntfs-3g/volume.c
2016-02-22 09:40:35 +01:00
Erik Larsson 3e3ef8901c Fixes for making strict endians branch compile after merge. 2016-02-05 18:04:22 +01:00
Erik Larsson 34bb449324 Merge branch 'edge' into edge.strict_endians
Conflicts:
	libntfs-3g/dir.c
	libntfs-3g/index.c
	libntfs-3g/runlist.c
	ntfsprogs/ntfsfix.c
	ntfsprogs/ntfsinfo.c
2016-02-05 18:02:02 +01:00
Erik Larsson 760ddd62cf Merge endianness fixes required for the strict endians code to compile.
Conflicts:
	libntfs-3g/attrib.c
	libntfs-3g/dir.c
	libntfs-3g/logfile.c
	libntfs-3g/volume.c
	ntfsprogs/ntfscp.c
	ntfsprogs/ntfsdump_logfile.c
	ntfsprogs/ntfsfallocate.c
	ntfsprogs/ntfsfix.c
	ntfsprogs/ntfsinfo.c
	ntfsprogs/ntfsresize.c
	ntfsprogs/ntfstruncate.c
2016-01-28 09:21:09 +01:00
Erik Larsson 1984a714e5 Enable strict checking of endian-specific types.
Strict checking of endian-specific types mean that types that have a
fixed endianness in the data representation of the value are now defined
as complex types, enabling the compiler to catch mixed usage of these
types with native-endian types. This allows us to catch most issues
relating to usage on big-endian systems since we cannot anymore assign a
fixed-endian value to a native-endian variable and vice-versa without a
compiler error.

The downside is that we aren't able to apply simple binary operators to
the fixed-endian types anymore since they are complex... so all
combining fixed-endian constants and values with |, &, etc. and
comparison with ==, !=, <=, etc. must be replaced with a macro which
unpacks the wrapped value and performs the operation. Lots of changes,
lots of work but in the interest of good code quality it's justified.
2016-01-28 08:29:03 +01:00
Erik Larsson 7e85b4ccd4 Replace switch statements for le/be types with equivalent if statements.
Since the le/be-types are now typedef'd to aggregate types, we can't use
those in switch statements.
2016-01-28 08:29:02 +01:00
Erik Larsson 1fdd4fbb71 Replace all le64 "not" negations with le64_not(...). 2016-01-28 08:29:01 +01:00
Erik Larsson 597adff2bb Replace all le32 "not" negations with le32_not(...). 2016-01-28 08:29:00 +01:00
Erik Larsson 85588b8e92 Replace all le16 "not" negations with le16_not(...). 2016-01-28 08:28:59 +01:00
Erik Larsson 46dfbe17ec Replace all le64 "xor" calculations with le64_xor(...). 2016-01-28 08:28:58 +01:00
Erik Larsson 14190d81b3 Replace all le32 "xor" calculations with le32_xor(...). 2016-01-28 08:28:57 +01:00
Erik Larsson 1118a56eea Replace all le16 "xor" calculations with le16_xor(...). 2016-01-28 08:28:56 +01:00
Erik Larsson cc414d9e8b Replace all le64 "or" calculations with le64_or(...). 2016-01-28 08:28:55 +01:00
Erik Larsson 1500a77676 Replace all le32 "or" calculations with le32_or(...). 2016-01-28 08:28:54 +01:00
Erik Larsson b61e7ff449 Replace all le16 "or" calculations with le16_or(...). 2016-01-28 08:28:53 +01:00
Erik Larsson 66d7b85573 Replace all le64 "and" calculations with le64_and(...). 2016-01-28 08:28:52 +01:00
Erik Larsson 7b3700ed5e Replace all le32 "and" calculations with le32_and(...). 2016-01-28 08:28:51 +01:00
Erik Larsson 2b4c3a618c Replace all le16 "and" calculations with le16_and(...). 2016-01-28 08:28:50 +01:00
Erik Larsson e970b57c74 Replace all le32 zero "and" test conditions with le32_andz(...). 2016-01-28 08:28:49 +01:00
Erik Larsson 9f5ad52e5f Replace all le32 non-zero "and" test conditions with !le32_andz(...). 2016-01-28 08:28:48 +01:00
Erik Larsson 1b7bfaa133 Replace all le16 zero "and" test conditions with le16_andz(...). 2016-01-28 08:28:47 +01:00
Erik Larsson 35c72761c7 Replace all le16 non-zero "and" test conditions with !le16_andz(...). 2016-01-28 08:28:46 +01:00
Erik Larsson 01c493f16c Replace all be16 zero test conditions with "be16_cmpz(...)". 2016-01-28 08:28:45 +01:00
Erik Larsson 5097bb9ea3 Replace all sle64 zero test conditions with "sle64_cmpz(...)". 2016-01-28 08:28:44 +01:00
Erik Larsson 97ccd587d6 Replace all sle64 non-zero test conditions with "!sle64_cmpz(...)". 2016-01-28 08:28:43 +01:00
Erik Larsson 65eea3fe0a Replace all le64 zero test conditions with "le64_cmpz(...)". 2016-01-28 08:28:42 +01:00
Erik Larsson 17a2c5f58e Replace all le64 non-zero test conditions with "!le64_cmpz(...)". 2016-01-28 08:28:41 +01:00
Erik Larsson ed87a4dffa Replace all le32 zero test conditions with "le32_cmpz(...)". 2016-01-28 08:28:40 +01:00
Erik Larsson 18990412fa Replace all le32 non-zero test conditions with "!le32_cmpz(...)". 2016-01-28 08:28:39 +01:00
Erik Larsson e366bef954 Replace all le16 zero test conditions with "le16_cmpz(...)". 2016-01-28 08:28:38 +01:00
Erik Larsson 90697bb5ab Replace all le16 non-zero test conditions with "!le16_cmpz(...)". 2016-01-28 08:28:37 +01:00
Erik Larsson c29924872f Replace all be32 usage of the '==' operation with "be32_eq(...)". 2016-01-28 08:28:36 +01:00
Erik Larsson e616a84f21 Replace all be16 usage of the '==' operation with "be16_eq(...)". 2016-01-28 08:28:35 +01:00
Erik Larsson 0657987a0b Replace all sle64 usage of the '!=' operation with "!sle64_eq(...)". 2016-01-28 08:28:34 +01:00
Erik Larsson 7b85755080 Replace all sle64 usage of the '==' operation with "sle64_eq(...)". 2016-01-28 08:28:33 +01:00
Erik Larsson e1bd02ed74 Replace all sle16 usage of the '!=' operation with "!sle16_eq(...)". 2016-01-28 08:28:32 +01:00
Erik Larsson 94589cde03 Replace all sle16 usage of the '==' operation with "sle16_eq(...)". 2016-01-28 08:28:31 +01:00
Erik Larsson d61f8615d9 Replace all le64 usage of the '!=' operation with "!le64_eq(...)". 2016-01-28 08:28:30 +01:00
Erik Larsson 7a88d7821e Replace all le64 usage of the '==' operation with "le64_eq(...)". 2016-01-28 08:28:28 +01:00
Erik Larsson 0876896169 Replace all le32 usage of the '!=' operation with "!le32_eq(...)". 2016-01-28 08:28:27 +01:00
Erik Larsson 011a9e9e5e Replace all le32 usage of the '==' operation with "le32_eq(...)". 2016-01-28 08:28:26 +01:00
Erik Larsson 59a05b5c34 Replace all le16 usage of the '!=' operation with "!le16_eq(...)". 2016-01-28 08:28:25 +01:00
Erik Larsson 347bdf21ec Replace all le16 usage of the '==' operation with "le16_eq(...)". 2016-01-28 08:28:23 +01:00
Erik Larsson 48cb23265b Fix code to use const_cpu_to_X/const_X_to_cpu macros for constants.
This enables the compiler to optimize this code in cases where compiler
support for endianness swapping is not present.
2015-12-21 23:21:00 +01:00
50 changed files with 2384 additions and 1779 deletions

View File

@ -47,35 +47,35 @@
/* flags which are set to mean exec, write or read */
#define FILE_READ (FILE_READ_DATA)
#define FILE_WRITE (FILE_WRITE_DATA | FILE_APPEND_DATA \
| READ_CONTROL | FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA)
#define FILE_WRITE le32_or(FILE_WRITE_DATA, le32_or(FILE_APPEND_DATA, \
le32_or(READ_CONTROL, le32_or(FILE_WRITE_ATTRIBUTES, FILE_WRITE_EA))))
#define FILE_EXEC (FILE_EXECUTE)
#define DIR_READ FILE_LIST_DIRECTORY
#define DIR_WRITE (FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY | FILE_DELETE_CHILD \
| READ_CONTROL | FILE_WRITE_ATTRIBUTES | FILE_WRITE_EA)
#define DIR_WRITE le32_or(FILE_ADD_FILE, le32_or(FILE_ADD_SUBDIRECTORY, le32_or(FILE_DELETE_CHILD, \
le32_or(READ_CONTROL, le32_or(FILE_WRITE_ATTRIBUTES, FILE_WRITE_EA)))))
#define DIR_EXEC (FILE_TRAVERSE)
/* flags tested for meaning exec, write or read */
/* tests for write allow for interpretation of a sticky bit */
#define FILE_GREAD (FILE_READ_DATA | GENERIC_READ)
#define FILE_GWRITE (FILE_WRITE_DATA | FILE_APPEND_DATA | GENERIC_WRITE)
#define FILE_GEXEC (FILE_EXECUTE | GENERIC_EXECUTE)
#define DIR_GREAD (FILE_LIST_DIRECTORY | GENERIC_READ)
#define DIR_GWRITE (FILE_ADD_FILE | FILE_ADD_SUBDIRECTORY | GENERIC_WRITE)
#define DIR_GEXEC (FILE_TRAVERSE | GENERIC_EXECUTE)
#define FILE_GREAD le32_or(FILE_READ_DATA, GENERIC_READ)
#define FILE_GWRITE le32_or(FILE_WRITE_DATA, le32_or(FILE_APPEND_DATA, GENERIC_WRITE))
#define FILE_GEXEC le32_or(FILE_EXECUTE, GENERIC_EXECUTE)
#define DIR_GREAD le32_or(FILE_LIST_DIRECTORY, GENERIC_READ)
#define DIR_GWRITE le32_or(FILE_ADD_FILE, le32_or(FILE_ADD_SUBDIRECTORY, GENERIC_WRITE))
#define DIR_GEXEC le32_or(FILE_TRAVERSE, GENERIC_EXECUTE)
/* standard owner (and administrator) rights */
#define OWNER_RIGHTS (DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER \
| SYNCHRONIZE \
| FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES \
| FILE_READ_EA | FILE_WRITE_EA)
#define OWNER_RIGHTS le32_or(DELETE, le32_or(READ_CONTROL, le32_or(WRITE_DAC, le32_or(WRITE_OWNER, \
le32_or(SYNCHRONIZE, \
le32_or(FILE_READ_ATTRIBUTES, le32_or(FILE_WRITE_ATTRIBUTES, \
le32_or(FILE_READ_EA, FILE_WRITE_EA))))))))
/* standard world rights */
#define WORLD_RIGHTS (READ_CONTROL | FILE_READ_ATTRIBUTES | FILE_READ_EA \
| SYNCHRONIZE)
#define WORLD_RIGHTS le32_or(READ_CONTROL, le32_or(FILE_READ_ATTRIBUTES, le32_or(FILE_READ_EA, \
SYNCHRONIZE)))
/* inheritance flags for files and directories */

View File

@ -52,6 +52,8 @@
#include <sys/param.h>
#endif
#include "types.h"
#ifndef __BYTE_ORDER
# if defined(_BYTE_ORDER)
# define __BYTE_ORDER _BYTE_ORDER
@ -188,6 +190,8 @@
#endif
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
/* Unsigned from LE to CPU conversion. */
#define le16_to_cpu(x) (u16)__le16_to_cpu((u16)(x))
@ -302,4 +306,325 @@
#define const_cpu_to_sbe32(x) ((sbe32) __constant_cpu_to_be32((u32) x))
#define const_cpu_to_sbe64(x) ((sbe64) __constant_cpu_to_be64((u64) x))
#define le16_eq(a, b) ((a) == (b))
#define le32_eq(a, b) ((a) == (b))
#define le64_eq(a, b) ((a) == (b))
#define sle16_eq(a, b) ((a) == (b))
#define sle64_eq(a, b) ((a) == (b))
#define be16_eq(a, b) ((a) == (b))
#define be32_eq(a, b) ((a) == (b))
#define le16_cmpz(a) (!(a))
#define le32_cmpz(a) (!(a))
#define le64_cmpz(a) (!(a))
#define sle64_cmpz(a) (!(a))
#define be16_cmpz(a) (!(a))
#define le16_andz(a, b) (!((a) & (b)))
#define le32_andz(a, b) (!((a) & (b)))
#define le16_and(a, b) ((a) & (b))
#define le32_and(a, b) ((a) & (b))
#define le64_and(a, b) ((a) & (b))
#define le16_or(a, b) ((a) | (b))
#define le32_or(a, b) ((a) | (b))
#define le64_or(a, b) ((a) | (b))
#define le16_xor(a, b) ((a) ^ (b))
#define le32_xor(a, b) ((a) ^ (b))
#define le64_xor(a, b) ((a) ^ (b))
#define le16_not(a) (~(a))
#define le32_not(a) (~(a))
#define le64_not(a) (~(a))
#else
/* Unsigned from LE to CPU conversion. */
static inline u16 le16_to_cpu(le16 x) { return (u16) __le16_to_cpu(x.value); }
static inline u32 le32_to_cpu(le32 x) { return (u32) __le32_to_cpu(x.value); }
static inline u64 le64_to_cpu(le64 x) { return (u64) __le64_to_cpu(x.value); }
static inline u16 le16_to_cpup(const le16 *x) {
return (u16) __le16_to_cpu(x->value);
}
static inline u32 le32_to_cpup(const le32 *x) {
return (u32) __le32_to_cpu(x->value);
}
static inline u64 le64_to_cpup(const le64 *x) {
return (u64) __le64_to_cpu(x->value);
}
/* Signed from LE to CPU conversion. */
static inline s16 sle16_to_cpu(sle16 x) { return (s16) __le16_to_cpu(x.value); }
static inline s32 sle32_to_cpu(sle32 x) { return (s32) __le32_to_cpu(x.value); }
static inline s64 sle64_to_cpu(sle64 x) { return (s64) __le64_to_cpu(x.value); }
static inline s16 sle16_to_cpup(const sle16 *x) {
return (s16) __le16_to_cpu(x->value);
}
static inline s32 sle32_to_cpup(const sle32 *x) {
return (s32) __le32_to_cpu(x->value);
}
static inline s64 sle64_to_cpup(const sle64 *x) {
return (s64) __le64_to_cpu(x->value);
}
/* Unsigned from CPU to LE conversion. */
static inline le16 cpu_to_le16(u16 x) {
le16 leval; leval.value = __cpu_to_le16(x); return leval;
}
static inline le32 cpu_to_le32(u32 x) {
le32 leval; leval.value = __cpu_to_le32(x); return leval;
}
static inline le64 cpu_to_le64(u64 x) {
le64 leval; leval.value = __cpu_to_le64(x); return leval;
}
static inline le16 cpu_to_le16p(const u16 *x) {
le16 leval; leval.value = __cpu_to_le16(*x); return leval;
}
static inline le32 cpu_to_le32p(const u32 *x) {
le32 leval; leval.value = __cpu_to_le32(*x); return leval;
}
static inline le64 cpu_to_le64p(const u64 *x) {
le64 leval; leval.value = __cpu_to_le64(*x); return leval;
}
/* Signed from CPU to LE conversion. */
static inline sle16 cpu_to_sle16(s16 x) {
sle16 leval; leval.value = __cpu_to_le16(x); return leval;
}
static inline sle32 cpu_to_sle32(s32 x) {
sle32 leval; leval.value = __cpu_to_le32(x); return leval;
}
static inline sle64 cpu_to_sle64(s64 x) {
sle64 leval; leval.value = __cpu_to_le64(x); return leval;
}
static inline sle16 cpu_to_sle16p(const s16 *x) {
sle16 leval; leval.value = __cpu_to_le16(*x); return leval;
}
static inline sle32 cpu_to_sle32p(const s32 *x) {
sle32 leval; leval.value = __cpu_to_le32(*x); return leval;
}
static inline sle64 cpu_to_sle64p(const s64 *x) {
sle64 leval; leval.value = __cpu_to_le64(*x); return leval;
}
/* Unsigned from BE to CPU conversion. */
static inline u16 be16_to_cpu(be16 x) { return (u16) __be16_to_cpu(x.value); }
static inline u32 be32_to_cpu(be32 x) { return (u32) __be32_to_cpu(x.value); }
static inline u64 be64_to_cpu(be64 x) { return (u64) __be64_to_cpu(x.value); }
static inline u16 be16_to_cpup(const be16 *x) {
return (u16) __be16_to_cpu(x->value);
}
static inline u32 be32_to_cpup(const be32 *x) {
return (u32) __be32_to_cpu(x->value);
}
static inline u64 be64_to_cpup(const be64 *x) {
return (u64) __be64_to_cpu(x->value);
}
/* Signed from BE to CPU conversion. */
static inline s16 sbe16_to_cpu(sbe16 x) { return (s16) __be16_to_cpu(x.value); }
static inline s32 sbe32_to_cpu(sbe32 x) { return (s32) __be32_to_cpu(x.value); }
static inline s64 sbe64_to_cpu(sbe64 x) { return (s64) __be64_to_cpu(x.value); }
static inline s16 sbe16_to_cpup(const sbe16 *x) {
return (s16) __be16_to_cpu(x->value);
}
static inline s32 sbe32_to_cpup(const sbe32 *x) {
return (s32) __be32_to_cpu(x->value);
}
static inline s64 sbe64_to_cpup(const sbe64 *x) {
return (s64) __be64_to_cpu(x->value);
}
/* Unsigned from CPU to BE conversion. */
static inline be16 cpu_to_be16(u16 x) {
be16 beval; beval.value = __cpu_to_be16(x); return beval;
}
static inline be32 cpu_to_be32(u32 x) {
be32 beval; beval.value = __cpu_to_be32(x); return beval;
}
static inline be64 cpu_to_be64(u64 x) {
be64 beval; beval.value = __cpu_to_be64(x); return beval;
}
static inline be16 cpu_to_be16p(const u16 *x) {
be16 beval; beval.value = __cpu_to_be16(*x); return beval;
}
static inline be32 cpu_to_be32p(const u32 *x) {
be32 beval; beval.value = __cpu_to_be32(*x); return beval;
}
static inline be64 cpu_to_be64p(const u64 *x) {
be64 beval; beval.value = __cpu_to_be64(*x); return beval;
}
/* Signed from CPU to BE conversion. */
static inline sbe16 cpu_to_sbe16(s16 x) {
sbe16 beval; beval.value = __cpu_to_be16(x); return beval;
}
static inline sbe32 cpu_to_sbe32(s32 x) {
sbe32 beval; beval.value = __cpu_to_be32(x); return beval;
}
static inline sbe64 cpu_to_sbe64(s64 x) {
sbe64 beval; beval.value = __cpu_to_be64(x); return beval;
}
static inline sbe16 cpu_to_sbe16p(const s16 *x) {
sbe16 beval; beval.value = __cpu_to_be16(*x); return beval;
}
static inline sbe32 cpu_to_sbe32p(const s32 *x) {
sbe32 beval; beval.value = __cpu_to_be32(*x); return beval;
}
static inline sbe64 cpu_to_sbe64p(const s64 *x) {
sbe64 beval; beval.value = __cpu_to_be64(*x); return beval;
}
/* Constant endianness conversion defines. */
#define const_le16_to_cpu(x) ((u16) __constant_le16_to_cpu((u16)(x.value)))
#define const_le32_to_cpu(x) ((u32) __constant_le32_to_cpu((u32)(x.value)))
#define const_le64_to_cpu(x) ((u64) __constant_le64_to_cpu((u64)(x.value)))
#define const_cpu_to_le16(x) ((le16)(u16) __constant_cpu_to_le16((u16)(x)))
#define const_cpu_to_le32(x) ((le32) __constant_cpu_to_le32((u32)(x)))
#define const_cpu_to_le64(x) ((le64) __constant_cpu_to_le64((u64)(x)))
#define const_sle16_to_cpu(x) ((s16) __constant_le16_to_cpu((u16)(x.value)))
#define const_sle32_to_cpu(x) ((s32) __constant_le32_to_cpu((u32)(x.value)))
#define const_sle64_to_cpu(x) ((s64) __constant_le64_to_cpu((u64)(x.value)))
#define const_cpu_to_sle16(x) ((sle16)(u16) __constant_cpu_to_le16((u16)(x)))
#define const_cpu_to_sle32(x) ((sle32) __constant_cpu_to_le32((u32)(x)))
#define const_cpu_to_sle64(x) ((sle64) __constant_cpu_to_le64((u64)(x)))
#define const_be16_to_cpu(x) ((u16) __constant_be16_to_cpu((u16)(x.value)))
#define const_be32_to_cpu(x) ((u32) __constant_be32_to_cpu((u32)(x.value)))
#define const_be64_to_cpu(x) ((s64) __constant_be64_to_cpu((u64)(x.value)))
#define const_cpu_to_be16(x) ((be16)(u16) __constant_cpu_to_be16((u16)(x)))
#define const_cpu_to_be32(x) ((be32) __constant_cpu_to_be32((u32)(x)))
#define const_cpu_to_be64(x) ((be64) __constant_cpu_to_be64((u64)(x)))
#define const_sbe16_to_cpu(x) ((s16) __constant_be16_to_cpu((u16)(x.value)))
#define const_sbe32_to_cpu(x) ((s32) __constant_be32_to_cpu((u32)(x.value)))
#define const_sbe64_to_cpu(x) ((s64) __constant_be64_to_cpu((u64)(x.value)))
#define const_cpu_to_sbe16(x) ((sbe16)(u16) __constant_cpu_to_be16((u16)(x)))
#define const_cpu_to_sbe32(x) ((sbe32) __constant_cpu_to_be32((u32)(x)))
#define const_cpu_to_sbe64(x) ((sbe64) __constant_cpu_to_be64((u64)(x)))
static inline int le16_eq(le16 a, le16 b) { return (a.value == b.value); }
static inline int le32_eq(le32 a, le32 b) { return (a.value == b.value); }
static inline int le64_eq(le64 a, le64 b) { return (a.value == b.value); }
static inline int sle16_eq(sle16 a, sle16 b) { return (a.value == b.value); }
static inline int sle64_eq(sle64 a, sle64 b) { return (a.value == b.value); }
static inline int be16_eq(be16 a, be16 b) { return (a.value == b.value); }
static inline int be32_eq(be32 a, be32 b) { return (a.value == b.value); }
static inline int le16_cmpz(le16 a) { return !a.value; }
static inline int le32_cmpz(le32 a) { return !a.value; }
static inline int le64_cmpz(le64 a) { return !a.value; }
static inline int sle64_cmpz(sle64 a) { return !a.value; }
static inline int be16_cmpz(be16 a) { return !a.value; }
static inline int le16_andz(le16 a, le16 b) { return !(a.value & b.value); }
static inline int le32_andz(le32 a, le32 b) { return !(a.value & b.value); }
static inline le16 le16_and(le16 a, le16 b)
{
return (le16) ((u16) (a.value & b.value));
}
static inline le32 le32_and(le32 a, le32 b)
{
return (le32) (a.value & b.value);
}
static inline le64 le64_and(le64 a, le64 b)
{
return (le64) (a.value & b.value);
}
static inline le16 le16_or(le16 a, le16 b)
{
return (le16) ((u16) (a.value | b.value));
}
static inline le32 le32_or(le32 a, le32 b)
{
return (le32) (a.value | b.value);
}
static inline le64 le64_or(le64 a, le64 b)
{
return (le64) (a.value | b.value);
}
static inline le16 le16_xor(le16 a, le16 b)
{
return (le16) ((u16) (a.value ^ b.value));
}
static inline le32 le32_xor(le32 a, le32 b)
{
return (le32) (a.value ^ b.value);
}
static inline le64 le64_xor(le64 a, le64 b)
{
return (le64) (a.value ^ b.value);
}
static inline le16 le16_not(le16 a) { return (le16) ((u16) (~a.value)); }
static inline le32 le32_not(le32 a) { return (le32) (~a.value); }
static inline le64 le64_not(le64 a) { return (le64) (~a.value); }
#endif /* !ENABLE_STRICT_ENDIANNESS_CHECKING ... */
#endif /* defined _NTFS_ENDIANS_H */

View File

@ -100,7 +100,13 @@ typedef struct {
* Magic identifiers present at the beginning of all ntfs record containing
* records (like mft records for example).
*/
#if ENABLE_STRICT_ENDIANNESS_CHECKING
typedef le32 NTFS_RECORD_TYPES;
static const le32
#else
typedef enum {
#endif
/* Found in $MFT/$DATA. */
magic_FILE = const_cpu_to_le32(0x454c4946), /* Mft entry. */
magic_INDX = const_cpu_to_le32(0x58444e49), /* Index buffer. */
@ -125,14 +131,18 @@ typedef enum {
magic_empty = const_cpu_to_le32(0xffffffff),/* Record is empty and has
to be initialized before
it can be used. */
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
} NTFS_RECORD_TYPES;
#else
__NTFS_RECORD_TYPES_end;
#endif
/*
* Generic magic comparison macros. Finally found a use for the ## preprocessor
* operator! (-8
*/
#define ntfs_is_magic(x, m) ( (u32)(x) == (u32)magic_##m )
#define ntfs_is_magicp(p, m) ( *(u32*)(p) == (u32)magic_##m )
#define ntfs_is_magic(x, m) ( le32_eq(x, magic_##m) )
#define ntfs_is_magicp(p, m) ( le32_eq(*p, magic_##m) )
/*
* Specialised magic comparison macros for the NTFS_RECORD_TYPES defined above.
@ -260,14 +270,24 @@ typedef enum {
* index, that means an INDEX_ROOT and an INDEX_ALLOCATION with a name other
* than "$I30". It is unknown if it is limited to metadata files only.
*/
#if ENABLE_STRICT_ENDIANNESS_CHECKING
typedef le16 MFT_RECORD_FLAGS;
static const MFT_RECORD_FLAGS
#else
typedef enum {
#endif
MFT_RECORD_IN_USE = const_cpu_to_le16(0x0001),
MFT_RECORD_IS_DIRECTORY = const_cpu_to_le16(0x0002),
MFT_RECORD_IS_4 = const_cpu_to_le16(0x0004),
MFT_RECORD_IS_VIEW_INDEX = const_cpu_to_le16(0x0008),
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
MFT_REC_SPACE_FILLER = 0xffff, /* Just to make flags
16-bit. */
} __attribute__((__packed__)) MFT_RECORD_FLAGS;
#else
__MFT_RECORD_FLAGS_end;
#endif
/*
* mft references (aka file references or file record segment references) are
@ -495,7 +515,13 @@ typedef struct {
* enum exchanging AT_ for the dollar sign ($). If that isn't a revealing
* choice of symbol... (-;
*/
#if ENABLE_STRICT_ENDIANNESS_CHECKING
typedef le32 ATTR_TYPES;
static const ATTR_TYPES
#else
typedef enum {
#endif
AT_UNUSED = const_cpu_to_le32( 0),
AT_STANDARD_INFORMATION = const_cpu_to_le32( 0x10),
AT_ATTRIBUTE_LIST = const_cpu_to_le32( 0x20),
@ -515,7 +541,11 @@ typedef enum {
AT_LOGGED_UTILITY_STREAM = const_cpu_to_le32( 0x100),
AT_FIRST_USER_DEFINED_ATTRIBUTE = const_cpu_to_le32( 0x1000),
AT_END = const_cpu_to_le32(0xffffffff),
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
} ATTR_TYPES;
#else
__ATTR_TYPES_end;
#endif
/**
* enum COLLATION_RULES - The collation rules for sorting views/indexes/etc
@ -553,7 +583,13 @@ typedef enum {
* the 2nd object_id. If the first le32 values of both object_ids were
* equal then the second le32 values would be compared, etc.
*/
#if ENABLE_STRICT_ENDIANNESS_CHECKING
typedef le32 COLLATION_RULES;
static const COLLATION_RULES
#else
typedef enum {
#endif
COLLATION_BINARY = const_cpu_to_le32(0),
COLLATION_FILE_NAME = const_cpu_to_le32(1),
COLLATION_UNICODE_STRING = const_cpu_to_le32(2),
@ -561,7 +597,11 @@ typedef enum {
COLLATION_NTOFS_SID = const_cpu_to_le32(17),
COLLATION_NTOFS_SECURITY_HASH = const_cpu_to_le32(18),
COLLATION_NTOFS_ULONGS = const_cpu_to_le32(19),
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
} COLLATION_RULES;
#else
__COLLATION_RULES_end;
#endif
/**
* enum ATTR_DEF_FLAGS -
@ -573,7 +613,13 @@ typedef enum {
* name attribute has this flag set and this is the only attribute indexed in
* NT4.
*/
#if ENABLE_STRICT_ENDIANNESS_CHECKING
typedef le32 ATTR_DEF_FLAGS;
static const ATTR_DEF_FLAGS
#else
typedef enum {
#endif
ATTR_DEF_INDEXABLE = const_cpu_to_le32(0x02), /* Attribute can be
indexed. */
ATTR_DEF_MULTIPLE = const_cpu_to_le32(0x04), /* Attribute type
@ -598,7 +644,11 @@ typedef enum {
non-resident. Without this, only log
modifications if the attribute is
resident. */
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
} ATTR_DEF_FLAGS;
#else
__ATTR_DEF_FLAGS_end;
#endif
/**
* struct ATTR_DEF -
@ -628,14 +678,24 @@ typedef struct {
/**
* enum ATTR_FLAGS - Attribute flags (16-bit).
*/
#if ENABLE_STRICT_ENDIANNESS_CHECKING
typedef le16 ATTR_FLAGS;
static const ATTR_FLAGS
#else
typedef enum {
#endif
ATTR_IS_COMPRESSED = const_cpu_to_le16(0x0001),
ATTR_COMPRESSION_MASK = const_cpu_to_le16(0x00ff), /* Compression
method mask. Also, first
illegal value. */
ATTR_IS_ENCRYPTED = const_cpu_to_le16(0x4000),
ATTR_IS_SPARSE = const_cpu_to_le16(0x8000),
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
} __attribute__((__packed__)) ATTR_FLAGS;
#else
__ATTR_FLAGS_end;
#endif
/*
* Attribute compression.
@ -825,7 +885,13 @@ typedef ATTR_RECORD ATTR_REC;
/**
* enum FILE_ATTR_FLAGS - File attribute flags (32-bit).
*/
#if ENABLE_STRICT_ENDIANNESS_CHECKING
typedef le32 FILE_ATTR_FLAGS;
static const FILE_ATTR_FLAGS
#else
typedef enum {
#endif
/*
* These flags are only present in the STANDARD_INFORMATION attribute
* (in the field file_attributes).
@ -888,7 +954,11 @@ typedef enum {
* $FILE_NAME attributes.
*/
FILE_ATTR_VIEW_INDEX_PRESENT = const_cpu_to_le32(0x20000000),
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
} __attribute__((__packed__)) FILE_ATTR_FLAGS;
#else
__FILE_ATTR_FLAGS_end;
#endif
/*
* NOTE on times in NTFS: All times are in MS standard time format, i.e. they
@ -1505,7 +1575,13 @@ typedef struct {
*
* Defines the access rights.
*/
#if ENABLE_STRICT_ENDIANNESS_CHECKING
typedef le32 ACCESS_MASK;
static const ACCESS_MASK
#else
typedef enum {
#endif
/*
* The specific rights (bits 0 to 15). Depend on the type of the
* object being secured by the ACE.
@ -1633,7 +1709,11 @@ typedef enum {
* above for the descriptions of the rights granted.
*/
GENERIC_READ = const_cpu_to_le32(0x80000000),
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
} ACCESS_MASK;
#else
__ACCESS_MASK_end;
#endif
/**
* struct GENERIC_MAPPING -
@ -1673,10 +1753,20 @@ typedef struct {
/**
* enum OBJECT_ACE_FLAGS - The object ACE flags (32-bit).
*/
#if ENABLE_STRICT_ENDIANNESS_CHECKING
typedef le32 OBJECT_ACE_FLAGS;
static const OBJECT_ACE_FLAGS
#else
typedef enum {
#endif
ACE_OBJECT_TYPE_PRESENT = const_cpu_to_le32(1),
ACE_INHERITED_OBJECT_TYPE_PRESENT = const_cpu_to_le32(2),
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
} OBJECT_ACE_FLAGS;
#else
__OBJECT_ACE_FLAGS_end;
#endif
/**
* struct ACCESS_ALLOWED_OBJECT_ACE -
@ -1781,7 +1871,13 @@ typedef enum {
* and all pointer fields are expressed as offsets from the
* beginning of the security descriptor.
*/
#if ENABLE_STRICT_ENDIANNESS_CHECKING
typedef le16 SECURITY_DESCRIPTOR_CONTROL;
static const SECURITY_DESCRIPTOR_CONTROL
#else
typedef enum {
#endif
SE_OWNER_DEFAULTED = const_cpu_to_le16(0x0001),
SE_GROUP_DEFAULTED = const_cpu_to_le16(0x0002),
SE_DACL_PRESENT = const_cpu_to_le16(0x0004),
@ -1796,7 +1892,11 @@ typedef enum {
SE_SACL_PROTECTED = const_cpu_to_le16(0x2000),
SE_RM_CONTROL_VALID = const_cpu_to_le16(0x4000),
SE_SELF_RELATIVE = const_cpu_to_le16(0x8000),
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
} __attribute__((__packed__)) SECURITY_DESCRIPTOR_CONTROL;
#else
__SECURITY_DESCRIPTOR_CONTROL_end;
#endif
/**
* struct SECURITY_DESCRIPTOR_RELATIVE -
@ -2010,7 +2110,13 @@ typedef struct {
/**
* enum VOLUME_FLAGS - Possible flags for the volume (16-bit).
*/
#if ENABLE_STRICT_ENDIANNESS_CHECKING
typedef le16 VOLUME_FLAGS;
static const VOLUME_FLAGS
#else
typedef enum {
#endif
VOLUME_IS_DIRTY = const_cpu_to_le16(0x0001),
VOLUME_RESIZE_LOG_FILE = const_cpu_to_le16(0x0002),
VOLUME_UPGRADE_ON_MOUNT = const_cpu_to_le16(0x0004),
@ -2020,7 +2126,11 @@ typedef enum {
VOLUME_CHKDSK_UNDERWAY = const_cpu_to_le16(0x4000),
VOLUME_MODIFIED_BY_CHKDSK = const_cpu_to_le16(0x8000),
VOLUME_FLAGS_MASK = const_cpu_to_le16(0xc03f),
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
} __attribute__((__packed__)) VOLUME_FLAGS;
#else
__VOLUME_FLAGS_end;
#endif
/**
* struct VOLUME_INFORMATION - Attribute: Volume information (0x70).
@ -2194,7 +2304,13 @@ typedef struct {
/**
* enum QUOTA_FLAGS - Quota flags (32-bit).
*/
#if ENABLE_STRICT_ENDIANNESS_CHECKING
typedef le32 QUOTA_FLAGS;
static const QUOTA_FLAGS
#else
typedef enum {
#endif
/* The user quota flags. Names explain meaning. */
QUOTA_FLAG_DEFAULT_LIMITS = const_cpu_to_le32(0x00000001),
QUOTA_FLAG_LIMIT_REACHED = const_cpu_to_le32(0x00000002),
@ -2213,7 +2329,11 @@ typedef enum {
QUOTA_FLAG_OUT_OF_DATE = const_cpu_to_le32(0x00000200),
QUOTA_FLAG_CORRUPT = const_cpu_to_le32(0x00000400),
QUOTA_FLAG_PENDING_DELETES = const_cpu_to_le32(0x00000800),
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
} QUOTA_FLAGS;
#else
__QUOTA_FLAGS_end;
#endif
/**
* struct QUOTA_CONTROL_ENTRY -
@ -2270,16 +2390,32 @@ typedef struct {
/**
* enum PREDEFINED_OWNER_IDS - Predefined owner_id values (32-bit).
*/
#if ENABLE_STRICT_ENDIANNESS_CHECKING
typedef le32 PREDEFINED_OWNER_IDS;
static const PREDEFINED_OWNER_IDS
#else
typedef enum {
#endif
QUOTA_INVALID_ID = const_cpu_to_le32(0x00000000),
QUOTA_DEFAULTS_ID = const_cpu_to_le32(0x00000001),
QUOTA_FIRST_USER_ID = const_cpu_to_le32(0x00000100),
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
} PREDEFINED_OWNER_IDS;
#else
__PREDEFINED_OWNER_IDS_end;
#endif
/**
* enum INDEX_ENTRY_FLAGS - Index entry flags (16-bit).
*/
#if ENABLE_STRICT_ENDIANNESS_CHECKING
typedef le16 INDEX_ENTRY_FLAGS;
static const INDEX_ENTRY_FLAGS
#else
typedef enum {
#endif
INDEX_ENTRY_NODE = const_cpu_to_le16(1), /* This entry contains a
sub-node, i.e. a reference to an index
block in form of a virtual cluster
@ -2288,8 +2424,12 @@ typedef enum {
entry in an index block. The index
entry does not represent a file but it
can point to a sub-node. */
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
INDEX_ENTRY_SPACE_FILLER = 0xffff, /* Just to force 16-bit width. */
} __attribute__((__packed__)) INDEX_ENTRY_FLAGS;
#else
__INDEX_ENTRY_FLAGS_end;
#endif
/**
* struct INDEX_ENTRY_HEADER - This the index entry header (see below).
@ -2420,7 +2560,13 @@ typedef struct {
* Some flags may be used in bits 12 to 15 to further describe the
* reparse point.
*/
#if ENABLE_STRICT_ENDIANNESS_CHECKING
typedef le32 PREDEFINED_REPARSE_TAGS;
static const PREDEFINED_REPARSE_TAGS
#else
typedef enum {
#endif
IO_REPARSE_TAG_DIRECTORY = const_cpu_to_le32(0x10000000),
IO_REPARSE_TAG_IS_ALIAS = const_cpu_to_le32(0x20000000),
IO_REPARSE_TAG_IS_HIGH_LATENCY = const_cpu_to_le32(0x40000000),
@ -2455,7 +2601,11 @@ typedef enum {
IO_REPARSE_TAG_VALID_VALUES = const_cpu_to_le32(0xf000ffff),
IO_REPARSE_PLUGIN_SELECT = const_cpu_to_le32(0xffff0fff),
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
} PREDEFINED_REPARSE_TAGS;
#else
__PREDEFINED_REPARSE_TAGS_end;
#endif
/**
* struct REPARSE_POINT - Attribute: Reparse point (0xc0).
@ -2681,14 +2831,24 @@ typedef struct {
typedef EFS_DF_CERTIFICATE_THUMBPRINT_HEADER EFS_DF_CERT_THUMBPRINT_HEADER;
#if ENABLE_STRICT_ENDIANNESS_CHECKING
typedef le64 INTX_FILE_TYPES;
static const INTX_FILE_TYPES
#else
typedef enum {
#endif
INTX_SYMBOLIC_LINK =
const_cpu_to_le64(0x014B4E4C78746E49ULL), /* "IntxLNK\1" */
INTX_CHARACTER_DEVICE =
const_cpu_to_le64(0x0052484378746E49ULL), /* "IntxCHR\0" */
INTX_BLOCK_DEVICE =
const_cpu_to_le64(0x004B4C4278746E49ULL), /* "IntxBLK\0" */
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
} INTX_FILE_TYPES;
#else
__INTX_FILE_TYPES_end;
#endif
typedef struct {
INTX_FILE_TYPES magic; /* Intx file magic. */

View File

@ -110,10 +110,18 @@ typedef struct {
* These are the so far known RESTART_AREA_* flags (16-bit) which contain
* information about the log file in which they are present.
*/
#if ENABLE_STRICT_ENDIANNESS_CHECKING
static const le16
#else
enum {
#endif
RESTART_VOLUME_IS_CLEAN = const_cpu_to_le16(0x0002),
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
RESTART_SPACE_FILLER = 0xffff, /* gcc: Force enum bit width to 16. */
} __attribute__((__packed__));
#else
__RESTART_AREA_FLAGS_end;
#endif
typedef le16 RESTART_AREA_FLAGS;
@ -335,15 +343,25 @@ typedef struct {
*
* (Or is it log record pages?)
*/
#if ENABLE_STRICT_ENDIANNESS_CHECKING
typedef le16 LOG_RECORD_FLAGS;
static const LOG_RECORD_FLAGS
#else
typedef enum {
#endif
LOG_RECORD_MULTI_PAGE = const_cpu_to_le16(0x0001), /* ??? */
/* The flags below were introduced in Windows 10 */
LOG_RECORD_DELETING = const_cpu_to_le16(0x0002),
LOG_RECORD_ADDING = const_cpu_to_le16(0x0004),
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
LOG_RECORD_SIZE_PLACE_HOLDER = 0xffff,
/* This has nothing to do with the log record. It is only so
gcc knows to make the flags 16-bit. */
} __attribute__((__packed__)) LOG_RECORD_FLAGS;
#else
__LOG_RECORD_FLAGS_end;
#endif
/**
* struct LOG_CLIENT_ID - The log client id structure identifying a log client.
@ -357,12 +375,22 @@ typedef struct {
* LOG_RECORD_TYPE : types of log records
*/
#if ENABLE_STRICT_ENDIANNESS_CHECKING
typedef le32 LOG_RECORD_TYPE;
static const LOG_RECORD_TYPE
#else
enum {
#endif
LOG_STANDARD = const_cpu_to_le32(1),
LOG_CHECKPOINT = const_cpu_to_le32(2),
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
LOG_RECORD_TYPE_PLACE_HOLDER = 0xffffffffU
} ;
typedef le32 LOG_RECORD_TYPE;
#else
__LOG_RECORD_TYPE_end;
#endif
/*
* ATTRIBUTE_FLAGS : flags describing the kind of NTFS record
@ -370,12 +398,22 @@ typedef le32 LOG_RECORD_TYPE;
* These flags were introduced in Vista, only two flags are known?
*/
#if ENABLE_STRICT_ENDIANNESS_CHECKING
typedef le16 ATTRIBUTE_FLAGS;
static const ATTRIBUTE_FLAGS
#else
enum {
#endif
ACTS_ON_MFT = const_cpu_to_le16(2),
ACTS_ON_INDX = const_cpu_to_le16(8),
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
ATTRIBUTE_FLAGS_PLACE_HOLDER = 0xffff,
} ;
typedef le16 ATTRIBUTE_FLAGS;
#else
__ATTRIBUTE_FLAGS_end;
#endif
#define LOG_RECORD_HEAD_SZ 0x30 /* size of header of struct LOG_RECORD */

View File

@ -27,6 +27,10 @@
#include "config.h"
#endif
#if !defined(ENABLE_STRICT_ENDIANNESS_CHECKING)
#define ENABLE_STRICT_ENDIANNESS_CHECKING 1
#endif /* !defined(ENABLE_STRICT_ENDIANNESS_CHECKING) */
#if HAVE_STDINT_H || !HAVE_CONFIG_H
#include <stdint.h>
#endif
@ -44,6 +48,7 @@ typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
typedef u16 le16;
typedef u32 le32;
typedef u64 le64;
@ -63,6 +68,71 @@ typedef u64 sle64;
typedef u16 sbe16;
typedef u32 sbe32;
typedef u64 sbe64;
#else
typedef union {
u8 data[2];
u16 value;
} le16;
typedef union {
u8 data[4];
u32 value;
} le32;
typedef union {
u8 data[8];
u64 value;
} le64;
typedef union {
u8 data[2];
u16 value;
} be16;
typedef union {
u8 data[4];
u32 value;
} be32;
typedef union {
u8 data[8];
u64 value;
} be64;
/*
* Declare s{l,b}e{16,32,64} to be unsigned because we do not want sign
* extension on BE architectures.
*/
typedef union {
u8 data[2];
u16 value;
} sle16;
typedef union {
u8 data[4];
u32 value;
} sle32;
typedef union {
u8 data[8];
u64 value;
} sle64;
typedef union {
u8 data[2];
u16 value;
} sbe16;
typedef union {
u8 data[4];
u32 value;
} sbe32;
typedef union {
u8 data[8];
u64 value;
} sbe64;
#endif /* !ENABLE_STRICT_ENDIANNESS_CHECKING ... */
typedef le16 ntfschar; /* 2-byte Unicode character type. */
#define UCHAR_T_SIZE_BITS 1

View File

@ -189,29 +189,29 @@ static int is_world_sid(const SID * usid)
return (
/* check whether S-1-1-0 : world */
((usid->sub_authority_count == 1)
&& (usid->identifier_authority.high_part == const_cpu_to_be16(0))
&& (usid->identifier_authority.low_part == const_cpu_to_be32(1))
&& (usid->sub_authority[0] == const_cpu_to_le32(0)))
&& be16_eq(usid->identifier_authority.high_part, const_cpu_to_be16(0))
&& be32_eq(usid->identifier_authority.low_part, const_cpu_to_be32(1))
&& le32_eq(usid->sub_authority[0], const_cpu_to_le32(0)))
/* check whether S-1-5-32-545 : local user */
|| ((usid->sub_authority_count == 2)
&& (usid->identifier_authority.high_part == const_cpu_to_be16(0))
&& (usid->identifier_authority.low_part == const_cpu_to_be32(5))
&& (usid->sub_authority[0] == const_cpu_to_le32(32))
&& (usid->sub_authority[1] == const_cpu_to_le32(545)))
&& be16_eq(usid->identifier_authority.high_part, const_cpu_to_be16(0))
&& be32_eq(usid->identifier_authority.low_part, const_cpu_to_be32(5))
&& le32_eq(usid->sub_authority[0], const_cpu_to_le32(32))
&& le32_eq(usid->sub_authority[1], const_cpu_to_le32(545)))
/* check whether S-1-5-11 : authenticated user */
|| ((usid->sub_authority_count == 1)
&& (usid->identifier_authority.high_part == const_cpu_to_be16(0))
&& (usid->identifier_authority.low_part == const_cpu_to_be32(5))
&& (usid->sub_authority[0] == const_cpu_to_le32(11)))
&& be16_eq(usid->identifier_authority.high_part, const_cpu_to_be16(0))
&& be32_eq(usid->identifier_authority.low_part, const_cpu_to_be32(5))
&& le32_eq(usid->sub_authority[0], const_cpu_to_le32(11)))
#if !POSIXACLS
/* check whether S-1-5-4 : interactive user */
|| ((usid->sub_authority_count == 1)
&& (usid->identifier_authority.high_part == const_cpu_to_be16(0))
&& (usid->identifier_authority.low_part == const_cpu_to_be32(5))
&& (usid->sub_authority[0] == const_cpu_to_le32(4)))
&& be16_eq(usid->identifier_authority.high_part, const_cpu_to_be16(0))
&& be32_eq(usid->identifier_authority.low_part, const_cpu_to_be32(5))
&& le32_eq(usid->sub_authority[0], const_cpu_to_le32(4)))
#endif /* !POSIXACLS */
);
}
@ -225,9 +225,9 @@ static int is_world_sid(const SID * usid)
BOOL ntfs_is_user_sid(const SID *usid)
{
return ((usid->sub_authority_count == 5)
&& (usid->identifier_authority.high_part == const_cpu_to_be16(0))
&& (usid->identifier_authority.low_part == const_cpu_to_be32(5))
&& (usid->sub_authority[0] == const_cpu_to_le32(21)));
&& be16_eq(usid->identifier_authority.high_part, const_cpu_to_be16(0))
&& be32_eq(usid->identifier_authority.low_part, const_cpu_to_be32(5))
&& le32_eq(usid->sub_authority[0], const_cpu_to_le32(21)));
}
/*
@ -243,8 +243,8 @@ static BOOL ntfs_known_group_sid(const SID *usid)
{
/* count == 1 excludes S-1-5-5-X-Y (logon) */
return ((usid->sub_authority_count == 1)
&& (usid->identifier_authority.high_part == const_cpu_to_be16(0))
&& (usid->identifier_authority.low_part == const_cpu_to_be32(5))
&& be16_eq(usid->identifier_authority.high_part, const_cpu_to_be16(0))
&& be32_eq(usid->identifier_authority.low_part, const_cpu_to_be32(5))
&& (le32_to_cpu(usid->sub_authority[0]) >= 1)
&& (le32_to_cpu(usid->sub_authority[0]) <= 6));
}
@ -649,10 +649,10 @@ BOOL ntfs_valid_descr(const char *securattr, unsigned int attrsz)
&& (!offsacl
|| ((offsacl >= sizeof(SECURITY_DESCRIPTOR_RELATIVE))
&& (offsacl+sizeof(ACL) <= attrsz)))
&& !(phead->owner & const_cpu_to_le32(3))
&& !(phead->group & const_cpu_to_le32(3))
&& !(phead->dacl & const_cpu_to_le32(3))
&& !(phead->sacl & const_cpu_to_le32(3))
&& le32_andz(phead->owner, const_cpu_to_le32(3))
&& le32_andz(phead->group, const_cpu_to_le32(3))
&& le32_andz(phead->dacl, const_cpu_to_le32(3))
&& le32_andz(phead->sacl, const_cpu_to_le32(3))
&& (ntfs_attr_size(securattr) <= attrsz)
&& ntfs_valid_sid((const SID*)&securattr[offowner])
&& ntfs_valid_sid((const SID*)&securattr[offgroup])
@ -662,12 +662,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))))) {
/*
@ -757,61 +757,61 @@ int ntfs_inherit_acl(const ACL *oldacl, ACL *newacl,
&& acceptable
&& (!fordir
|| (poldace->flags & NO_PROPAGATE_INHERIT_ACE)
|| (poldace->mask & (GENERIC_ALL | GENERIC_READ
| GENERIC_WRITE | GENERIC_EXECUTE)))
|| !le32_andz(poldace->mask, le32_or(GENERIC_ALL, le32_or(GENERIC_READ,
le32_or(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) {
pnewace->mask &= ~GENERIC_ALL;
if (!le32_andz(pnewace->mask, GENERIC_ALL)) {
pnewace->mask = le32_and(pnewace->mask, le32_not(GENERIC_ALL));
if (fordir)
pnewace->mask |= OWNER_RIGHTS
| DIR_READ
| DIR_WRITE
| DIR_EXEC;
pnewace->mask = le32_or(pnewace->mask, le32_or(OWNER_RIGHTS,
le32_or(DIR_READ,
le32_or(DIR_WRITE,
DIR_EXEC))));
else
/*
* The last flag is not defined for a file,
* however Windows sets it, so do the same
*/
pnewace->mask |= OWNER_RIGHTS
| FILE_READ
| FILE_WRITE
| FILE_EXEC
| const_cpu_to_le32(0x40);
pnewace->mask = le32_or(pnewace->mask, le32_or(OWNER_RIGHTS,
le32_or(FILE_READ,
le32_or(FILE_WRITE,
le32_or(FILE_EXEC,
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
| DIR_EXEC;
pnewace->mask = le32_or(pnewace->mask, le32_or(OWNER_RIGHTS,
le32_or(DIR_READ,
DIR_EXEC)));
else
pnewace->mask |= OWNER_RIGHTS
| FILE_READ
| FILE_EXEC;
pnewace->mask &= ~(GENERIC_READ
| GENERIC_EXECUTE
| WRITE_DAC
| WRITE_OWNER
| DELETE | FILE_WRITE_EA
| FILE_WRITE_ATTRIBUTES);
pnewace->mask = le32_or(pnewace->mask, le32_or(OWNER_RIGHTS,
le32_or(FILE_READ,
FILE_EXEC)));
pnewace->mask = le32_and(pnewace->mask, le32_not(le32_or(GENERIC_READ,
le32_or(GENERIC_EXECUTE,
le32_or(WRITE_DAC,
le32_or(WRITE_OWNER,
le32_or(DELETE, le32_or(FILE_WRITE_EA,
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;
pnewace->mask = le32_or(pnewace->mask, le32_or(OWNER_RIGHTS,
DIR_WRITE));
else
pnewace->mask |= OWNER_RIGHTS
| FILE_WRITE;
pnewace->mask &= ~(GENERIC_WRITE
| WRITE_DAC
| WRITE_OWNER
| FILE_DELETE_CHILD);
pnewace->mask = le32_or(pnewace->mask, le32_or(OWNER_RIGHTS,
FILE_WRITE));
pnewace->mask = le32_and(pnewace->mask, le32_not(le32_or(GENERIC_WRITE,
le32_or(WRITE_DAC,
le32_or(WRITE_OWNER,
FILE_DELETE_CHILD)))));
}
/* remove inheritance flags */
pnewace->flags &= ~(OBJECT_INHERIT_ACE
@ -825,16 +825,16 @@ int ntfs_inherit_acl(const ACL *oldacl, ACL *newacl,
&& ntfs_same_sid(&poldace->sid, authsid)) {
if (pauthace) {
pauthace->flags |= pnewace->flags;
pauthace->mask |= pnewace->mask;
pauthace->mask = le32_or(pauthace->mask, pnewace->mask);
} else {
pauthace = pnewace;
if (inherited)
if (!le16_cmpz(inherited))
pnewace->flags |= INHERITED_ACE;
dst += acesz;
newcnt++;
}
} else {
if (inherited)
if (!le16_cmpz(inherited))
pnewace->flags |= INHERITED_ACE;
dst += acesz;
newcnt++;
@ -844,7 +844,7 @@ int ntfs_inherit_acl(const ACL *oldacl, ACL *newacl,
* Inheritance for access, specific to
* creator-owner (and creator-group)
*/
if ((fordir || !inherited
if ((fordir || le16_cmpz(inherited)
|| (poldace->flags
& (CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE)))
&& acceptable) {
@ -863,12 +863,12 @@ int ntfs_inherit_acl(const ACL *oldacl, ACL *newacl,
pnewace->flags &= ~(OBJECT_INHERIT_ACE
| CONTAINER_INHERIT_ACE
| INHERIT_ONLY_ACE);
if (inherited)
if (!le16_cmpz(inherited))
pnewace->flags |= INHERITED_ACE;
if ((pnewace->type == ACCESS_ALLOWED_ACE_TYPE)
&& pownerace
&& !(pnewace->flags & ~pownerace->flags)) {
pownerace->mask |= pnewace->mask;
pownerace->mask = le32_or(pownerace->mask, pnewace->mask);
} else {
dst += usidsz + 8;
newcnt++;
@ -881,7 +881,7 @@ int ntfs_inherit_acl(const ACL *oldacl, ACL *newacl,
pnewace->flags &= ~(OBJECT_INHERIT_ACE
| CONTAINER_INHERIT_ACE
| INHERIT_ONLY_ACE);
if (inherited)
if (!le16_cmpz(inherited))
pnewace->flags |= INHERITED_ACE;
dst += gsidsz + 8;
newcnt++;
@ -909,13 +909,13 @@ 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, le32_or(GENERIC_ALL, le32_or(GENERIC_READ,
le32_or(GENERIC_WRITE, GENERIC_EXECUTE)))))
pnewace->flags |= INHERIT_ONLY_ACE;
else
pnewace->flags &= ~INHERIT_ONLY_ACE;
}
if (inherited)
if (!le16_cmpz(inherited))
pnewace->flags |= INHERITED_ACE;
/*
* Prepare grouping similar ACE for authenticated users
@ -2480,19 +2480,19 @@ static int buildacls(char *secattr, int offs, mode_t mode, int isdir,
if (isdir) {
gflags = DIR_INHERITANCE;
if (mode & S_IXUSR)
grants |= DIR_EXEC;
grants = le32_or(grants, DIR_EXEC);
if (mode & S_IWUSR)
grants |= DIR_WRITE;
grants = le32_or(grants, DIR_WRITE);
if (mode & S_IRUSR)
grants |= DIR_READ;
grants = le32_or(grants, DIR_READ);
} else {
gflags = FILE_INHERITANCE;
if (mode & S_IXUSR)
grants |= FILE_EXEC;
grants = le32_or(grants, FILE_EXEC);
if (mode & S_IWUSR)
grants |= FILE_WRITE;
grants = le32_or(grants, FILE_WRITE);
if (mode & S_IRUSR)
grants |= FILE_READ;
grants = le32_or(grants, FILE_READ);
}
/* a possible ACE to deny owner what he/she would */
@ -2506,41 +2506,41 @@ static int buildacls(char *secattr, int offs, mode_t mode, int isdir,
if (isdir) {
pdace->flags = DIR_INHERITANCE;
if (mode & (S_IXGRP | S_IXOTH))
denials |= DIR_EXEC;
denials = le32_or(denials, DIR_EXEC);
if (mode & (S_IWGRP | S_IWOTH))
denials |= DIR_WRITE;
denials = le32_or(denials, DIR_WRITE);
if (mode & (S_IRGRP | S_IROTH))
denials |= DIR_READ;
denials = le32_or(denials, DIR_READ);
} else {
pdace->flags = FILE_INHERITANCE;
if (mode & (S_IXGRP | S_IXOTH))
denials |= FILE_EXEC;
denials = le32_or(denials, FILE_EXEC);
if (mode & (S_IWGRP | S_IWOTH))
denials |= FILE_WRITE;
denials = le32_or(denials, FILE_WRITE);
if (mode & (S_IRGRP | S_IROTH))
denials |= FILE_READ;
denials = le32_or(denials, FILE_READ);
}
} else {
if (isdir) {
pdace->flags = DIR_INHERITANCE;
if ((mode & S_IXOTH) && !(mode & S_IXGRP))
denials |= DIR_EXEC;
denials = le32_or(denials, DIR_EXEC);
if ((mode & S_IWOTH) && !(mode & S_IWGRP))
denials |= DIR_WRITE;
denials = le32_or(denials, DIR_WRITE);
if ((mode & S_IROTH) && !(mode & S_IRGRP))
denials |= DIR_READ;
denials = le32_or(denials, DIR_READ);
} else {
pdace->flags = FILE_INHERITANCE;
if ((mode & S_IXOTH) && !(mode & S_IXGRP))
denials |= FILE_EXEC;
denials = le32_or(denials, FILE_EXEC);
if ((mode & S_IWOTH) && !(mode & S_IWGRP))
denials |= FILE_WRITE;
denials = le32_or(denials, FILE_WRITE);
if ((mode & S_IROTH) && !(mode & S_IRGRP))
denials |= FILE_READ;
denials = le32_or(denials, FILE_READ);
}
}
denials &= ~grants;
if (denials) {
denials = le32_and(denials, le32_not(grants));
if (!le32_cmpz(denials)) {
pdace->type = ACCESS_DENIED_ACE_TYPE;
pdace->size = cpu_to_le16(usidsz + 8);
pdace->mask = denials;
@ -2587,19 +2587,19 @@ static int buildacls(char *secattr, int offs, mode_t mode, int isdir,
if (isdir) {
gflags = DIR_INHERITANCE;
if (mode & S_IXGRP)
grants |= DIR_EXEC;
grants = le32_or(grants, DIR_EXEC);
if (mode & S_IWGRP)
grants |= DIR_WRITE;
grants = le32_or(grants, DIR_WRITE);
if (mode & S_IRGRP)
grants |= DIR_READ;
grants = le32_or(grants, DIR_READ);
} else {
gflags = FILE_INHERITANCE;
if (mode & S_IXGRP)
grants |= FILE_EXEC;
grants = le32_or(grants, FILE_EXEC);
if (mode & S_IWGRP)
grants |= FILE_WRITE;
grants = le32_or(grants, FILE_WRITE);
if (mode & S_IRGRP)
grants |= FILE_READ;
grants = le32_or(grants, FILE_READ);
}
/* a possible ACE to deny group what it would get from world */
@ -2611,22 +2611,22 @@ static int buildacls(char *secattr, int offs, mode_t mode, int isdir,
if (isdir) {
pdace->flags = DIR_INHERITANCE;
if (mode & S_IXOTH)
denials |= DIR_EXEC;
denials = le32_or(denials, DIR_EXEC);
if (mode & S_IWOTH)
denials |= DIR_WRITE;
denials = le32_or(denials, DIR_WRITE);
if (mode & S_IROTH)
denials |= DIR_READ;
denials = le32_or(denials, DIR_READ);
} else {
pdace->flags = FILE_INHERITANCE;
if (mode & S_IXOTH)
denials |= FILE_EXEC;
denials = le32_or(denials, FILE_EXEC);
if (mode & S_IWOTH)
denials |= FILE_WRITE;
denials = le32_or(denials, FILE_WRITE);
if (mode & S_IROTH)
denials |= FILE_READ;
denials = le32_or(denials, FILE_READ);
}
denials &= ~(grants | OWNER_RIGHTS);
if (denials) {
denials = le32_and(denials, le32_not(le32_or(grants, OWNER_RIGHTS)));
if (!le32_cmpz(denials)) {
pdace->type = ACCESS_DENIED_ACE_TYPE;
pdace->size = cpu_to_le16(gsidsz + 8);
pdace->mask = denials;
@ -2660,19 +2660,19 @@ static int buildacls(char *secattr, int offs, mode_t mode, int isdir,
if (isdir) {
pgace->flags = DIR_INHERITANCE;
if (mode & S_IXOTH)
grants |= DIR_EXEC;
grants = le32_or(grants, DIR_EXEC);
if (mode & S_IWOTH)
grants |= DIR_WRITE;
grants = le32_or(grants, DIR_WRITE);
if (mode & S_IROTH)
grants |= DIR_READ;
grants = le32_or(grants, DIR_READ);
} else {
pgace->flags = FILE_INHERITANCE;
if (mode & S_IXOTH)
grants |= FILE_EXEC;
grants = le32_or(grants, FILE_EXEC);
if (mode & S_IWOTH)
grants |= FILE_WRITE;
grants = le32_or(grants, FILE_WRITE);
if (mode & S_IROTH)
grants |= FILE_READ;
grants = le32_or(grants, FILE_READ);
}
pgace->size = cpu_to_le16(wsidsz + 8);
pgace->mask = grants;
@ -2690,7 +2690,7 @@ static int buildacls(char *secattr, int offs, mode_t mode, int isdir,
else
pgace->flags = FILE_INHERITANCE;
pgace->size = cpu_to_le16(asidsz + 8);
grants = OWNER_RIGHTS | FILE_READ | FILE_WRITE | FILE_EXEC;
grants = le32_or(OWNER_RIGHTS, le32_or(FILE_READ, le32_or(FILE_WRITE, FILE_EXEC)));
pgace->mask = grants;
memcpy((char*)&pgace->sid, adminsid, asidsz);
pos += asidsz + 8;
@ -2706,7 +2706,7 @@ static int buildacls(char *secattr, int offs, mode_t mode, int isdir,
else
pgace->flags = FILE_INHERITANCE;
pgace->size = cpu_to_le16(ssidsz + 8);
grants = OWNER_RIGHTS | FILE_READ | FILE_WRITE | FILE_EXEC;
grants = le32_or(OWNER_RIGHTS, le32_or(FILE_READ, le32_or(FILE_WRITE, FILE_EXEC)));
pgace->mask = grants;
memcpy((char*)&pgace->sid, systemsid, ssidsz);
pos += ssidsz + 8;
@ -2723,11 +2723,11 @@ static int buildacls(char *secattr, int offs, mode_t mode, int isdir,
pgace->size = cpu_to_le16(nsidsz + 8);
grants = const_cpu_to_le32(0);
if (mode & S_ISUID)
grants |= FILE_APPEND_DATA;
grants = le32_or(grants, FILE_APPEND_DATA);
if (mode & S_ISGID)
grants |= FILE_WRITE_DATA;
grants = le32_or(grants, FILE_WRITE_DATA);
if (mode & S_ISVTX)
grants |= FILE_READ_DATA;
grants = le32_or(grants, FILE_READ_DATA);
pgace->mask = grants;
memcpy((char*)&pgace->sid, nullsid, nsidsz);
pos += nsidsz + 8;
@ -2890,8 +2890,8 @@ char *ntfs_build_descr(mode_t mode,
* The flag SE_DACL_PROTECTED prevents the ACL
* to be changed in an inheritance after creation
*/
pnhead->control = SE_DACL_PRESENT | SE_DACL_PROTECTED
| SE_SELF_RELATIVE;
pnhead->control = le16_or(SE_DACL_PRESENT, le16_or(SE_DACL_PROTECTED,
SE_SELF_RELATIVE));
/*
* Windows prefers ACL first, do the same to
* get the same hash value and avoid duplication
@ -2942,84 +2942,84 @@ 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)
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;
}
}
/* build group permission */
if (group) {
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;
}
}
/* build world permission */
if (world) {
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 (special) {
if (special & FILE_APPEND_DATA)
if (!le32_cmpz(special)) {
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);
@ -3225,27 +3225,27 @@ static int build_std_permissions(const char *securattr,
|| ntfs_same_sid(ownersid, &pace->sid)) {
noown = FALSE;
if (pace->type == ACCESS_ALLOWED_ACE_TYPE)
allowown |= pace->mask;
allowown = le32_or(allowown, pace->mask);
else if (pace->type == ACCESS_DENIED_ACE_TYPE)
denyown |= pace->mask;
denyown = le32_or(denyown, pace->mask);
} else
if (ntfs_same_sid(gsid, &pace->sid)
&& !(pace->mask & WRITE_OWNER)) {
&& le32_andz(pace->mask, WRITE_OWNER)) {
if (pace->type == ACCESS_ALLOWED_ACE_TYPE)
allowgrp |= pace->mask;
allowgrp = le32_or(allowgrp, pace->mask);
else if (pace->type == ACCESS_DENIED_ACE_TYPE)
denygrp |= pace->mask;
denygrp = le32_or(denygrp, pace->mask);
} else
if (is_world_sid((const SID*)&pace->sid)) {
if (pace->type == ACCESS_ALLOWED_ACE_TYPE)
allowall |= pace->mask;
allowall = le32_or(allowall, pace->mask);
else
if (pace->type == ACCESS_DENIED_ACE_TYPE)
denyall |= pace->mask;
denyall = le32_or(denyall, pace->mask);
} else
if ((ntfs_same_sid((const SID*)&pace->sid,nullsid))
&& (pace->type == ACCESS_ALLOWED_ACE_TYPE))
special |= pace->mask;
special = le32_or(special, pace->mask);
}
offace += le16_to_cpu(pace->size);
}
@ -3256,18 +3256,18 @@ static int build_std_permissions(const char *securattr,
* merges the admin ACEs
*/
if (noown)
allowown = (FILE_READ_DATA | FILE_WRITE_DATA | FILE_EXECUTE);
allowown = le32_or(FILE_READ_DATA, le32_or(FILE_WRITE_DATA, FILE_EXECUTE));
/*
* Add to owner rights granted to group or world
* unless denied personaly, and add to group rights
* granted to world unless denied specifically
*/
allowown |= (allowgrp | allowall);
allowgrp |= allowall;
allowown = le32_or(allowown, le32_or(allowgrp, allowall));
allowgrp = le32_or(allowgrp, allowall);
return (merge_permissions(isdir,
allowown & ~(denyown | denyall),
allowgrp & ~(denygrp | denyall),
allowall & ~denyall,
le32_and(allowown, le32_not(le32_or(denyown, denyall))),
le32_and(allowgrp, le32_not(le32_or(denygrp, denyall))),
le32_and(allowall, le32_not(denyall)),
special));
}
@ -3313,29 +3313,29 @@ 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;
allowown = le32_or(allowown, pace->mask);
ownpresent = TRUE;
}
} else
if (ntfs_same_sid(usid, &pace->sid)
&& (!(pace->mask & WRITE_OWNER))) {
&& le32_andz(pace->mask, WRITE_OWNER)) {
if (pace->type == ACCESS_ALLOWED_ACE_TYPE) {
allowgrp |= pace->mask;
allowgrp = le32_or(allowgrp, pace->mask);
grppresent = TRUE;
}
} else
if (is_world_sid((const SID*)&pace->sid)) {
if (pace->type == ACCESS_ALLOWED_ACE_TYPE)
allowall |= pace->mask;
allowall = le32_or(allowall, pace->mask);
else
if (pace->type == ACCESS_DENIED_ACE_TYPE)
denyall |= pace->mask;
denyall = le32_or(denyall, pace->mask);
} else
if ((ntfs_same_sid((const SID*)&pace->sid,nullsid))
&& (pace->type == ACCESS_ALLOWED_ACE_TYPE))
special |= pace->mask;
special = le32_or(special, pace->mask);
}
offace += le16_to_cpu(pace->size);
}
@ -3344,9 +3344,9 @@ static int build_owngrp_permissions(const char *securattr,
if (!grppresent)
allowgrp = allowall;
return (merge_permissions(isdir,
allowown & ~(denyown | denyall),
allowgrp & ~(denygrp | denyall),
allowall & ~denyall,
le32_and(allowown, le32_not(le32_or(denyown, denyall))),
le32_and(allowgrp, le32_not(le32_or(denygrp, denyall))),
le32_and(allowall, le32_not(denyall)),
special));
}
@ -3501,48 +3501,48 @@ static int build_ownadmin_permissions(const char *securattr,
for (nace = 0; nace < acecnt; nace++) {
pace = (const ACCESS_ALLOWED_ACE*)&securattr[offace];
if (!(pace->flags & INHERIT_ONLY_ACE)
&& !(~pace->mask & (ROOT_OWNER_UNMARK | ROOT_GROUP_UNMARK))) {
&& le32_andz(le32_not(pace->mask), le32_or(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;
allowown = le32_or(allowown, pace->mask);
isforeign &= ~1;
} else
if (pace->type == ACCESS_DENIED_ACE_TYPE)
denyown |= pace->mask;
denyown = le32_or(denyown, pace->mask);
} else
if (ntfs_same_sid(gsid, &pace->sid)
&& (!(pace->mask & WRITE_OWNER))) {
&& (le32_andz(pace->mask, WRITE_OWNER))) {
if (pace->type == ACCESS_ALLOWED_ACE_TYPE) {
allowgrp |= pace->mask;
allowgrp = le32_or(allowgrp, pace->mask);
isforeign &= ~2;
} else
if (pace->type == ACCESS_DENIED_ACE_TYPE)
denygrp |= pace->mask;
denygrp = le32_or(denygrp, pace->mask);
} else if (is_world_sid((const SID*)&pace->sid)) {
if (pace->type == ACCESS_ALLOWED_ACE_TYPE)
allowall |= pace->mask;
allowall = le32_or(allowall, pace->mask);
else
if (pace->type == ACCESS_DENIED_ACE_TYPE)
denyall |= pace->mask;
denyall = le32_or(denyall, pace->mask);
}
firstapply = FALSE;
} else
if (!(pace->flags & INHERIT_ONLY_ACE))
if ((ntfs_same_sid((const SID*)&pace->sid,nullsid))
&& (pace->type == ACCESS_ALLOWED_ACE_TYPE))
special |= pace->mask;
special = le32_or(special, pace->mask);
offace += le16_to_cpu(pace->size);
}
if (isforeign) {
allowown |= (allowgrp | allowall);
allowgrp |= allowall;
allowown = le32_or(allowown, le32_or(allowgrp, allowall));
allowgrp = le32_or(allowgrp, allowall);
}
return (merge_permissions(isdir,
allowown & ~(denyown | denyall),
allowgrp & ~(denygrp | denyall),
allowall & ~denyall,
le32_and(allowown, le32_not(le32_or(denyown, denyall))),
le32_and(allowgrp, le32_not(le32_or(denygrp, denyall))),
le32_and(allowall, le32_not(denyall)),
special));
}
@ -3583,7 +3583,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;

File diff suppressed because it is too large Load Diff

View File

@ -155,7 +155,7 @@ int ntfs_attrlist_entry_add(ntfs_inode *ni, ATTR_RECORD *attr)
le16_to_cpu(attr->value_offset)), (attr->non_resident) ?
0 : le32_to_cpu(attr->value_length), ctx)) {
/* Found some extent, check it to be before new extent. */
if (ctx->al_entry->lowest_vcn == attr->lowest_vcn) {
if (sle64_eq(ctx->al_entry->lowest_vcn, attr->lowest_vcn)) {
err = EEXIST;
ntfs_log_trace("Such attribute already present in the "
"attribute list.\n");

View File

@ -67,7 +67,7 @@ BOOL ntfs_boot_sector_is_ntfs(NTFS_BOOT_SECTOR *b)
ntfs_log_debug("Beginning bootsector check.\n");
ntfs_log_debug("Checking OEMid, NTFS signature.\n");
if (b->oem_id != const_cpu_to_le64(0x202020205346544eULL)) { /* "NTFS " */
if (!le64_eq(b->oem_id, const_cpu_to_le64(0x202020205346544eULL))) { /* "NTFS " */
ntfs_log_error("NTFS signature is missing.\n");
goto not_ntfs;
}
@ -157,12 +157,12 @@ BOOL ntfs_boot_sector_is_ntfs(NTFS_BOOT_SECTOR *b)
/* MFT and MFTMirr may not overlap the boot sector or be the same */
if (((s64)sle64_to_cpu(b->mft_lcn) <= 0)
|| ((s64)sle64_to_cpu(b->mftmirr_lcn) <= 0)
|| (b->mft_lcn == b->mftmirr_lcn)) {
|| sle64_eq(b->mft_lcn, b->mftmirr_lcn)) {
ntfs_log_error("Invalid location of MFT or MFTMirr.\n");
goto not_ntfs;
}
if (b->end_of_sector_marker != const_cpu_to_le16(0xaa55))
if (!le16_eq(b->end_of_sector_marker, const_cpu_to_le16(0xaa55)))
ntfs_log_debug("Warning: Bootsector has invalid end of sector "
"marker.\n");

View File

@ -246,26 +246,26 @@ COLLATE ntfs_get_collate_function(COLLATION_RULES cr)
{
COLLATE collate;
switch (cr) {
case COLLATION_BINARY :
/* switch (cr) { */
if (le32_eq(cr, COLLATION_BINARY)) {
collate = ntfs_collate_binary;
break;
case COLLATION_FILE_NAME :
}
else if (le32_eq(cr, COLLATION_FILE_NAME)) {
collate = ntfs_collate_file_name;
break;
case COLLATION_NTOFS_SECURITY_HASH :
}
else if (le32_eq(cr, COLLATION_NTOFS_SECURITY_HASH)) {
collate = ntfs_collate_ntofs_security_hash;
break;
case COLLATION_NTOFS_ULONG :
}
else if (le32_eq(cr, COLLATION_NTOFS_ULONG)) {
collate = ntfs_collate_ntofs_ulong;
break;
case COLLATION_NTOFS_ULONGS :
}
else if (le32_eq(cr, COLLATION_NTOFS_ULONGS)) {
collate = ntfs_collate_ntofs_ulongs;
break;
default :
}
else {
errno = EOPNOTSUPP;
collate = (COLLATE)NULL;
break;
/* break; */
}
return (collate);
}

View File

@ -724,10 +724,10 @@ s64 ntfs_compressed_attr_pread(ntfs_attr *na, s64 pos, s64 count, void *b)
(unsigned long long)na->ni->mft_no, le32_to_cpu(na->type),
(long long)pos, (long long)count);
data_flags = na->data_flags;
compression = na->ni->flags & FILE_ATTR_COMPRESSED;
compression = le32_and(na->ni->flags, FILE_ATTR_COMPRESSED);
if (!na || !na->ni || !na->ni->vol || !b
|| ((data_flags & ATTR_COMPRESSION_MASK)
!= ATTR_IS_COMPRESSED)
|| !le16_eq(le16_and(data_flags, ATTR_COMPRESSION_MASK),
ATTR_IS_COMPRESSED)
|| pos < 0 || count < 0) {
errno = EINVAL;
return -1;
@ -846,7 +846,7 @@ do_next_cb:
to_read = min(count, cb_size - ofs);
ofs += vcn << vol->cluster_size_bits;
NAttrClearCompressed(na);
na->data_flags &= ~ATTR_COMPRESSION_MASK;
na->data_flags = le16_and(na->data_flags, le16_not(ATTR_COMPRESSION_MASK));
tdata_size = na->data_size;
tinitialized_size = na->initialized_size;
na->data_size = na->initialized_size = na->allocated_size;
@ -864,7 +864,7 @@ do_next_cb:
err = errno;
na->data_size = tdata_size;
na->initialized_size = tinitialized_size;
na->ni->flags |= compression;
na->ni->flags = le32_or(na->ni->flags, compression);
na->data_flags = data_flags;
free(cb);
free(dest);
@ -881,7 +881,7 @@ do_next_cb:
} while (to_read > 0);
na->data_size = tdata_size;
na->initialized_size = tinitialized_size;
na->ni->flags |= compression;
na->ni->flags = le32_or(na->ni->flags, compression);
na->data_flags = data_flags;
ofs = 0;
} else {
@ -904,7 +904,7 @@ do_next_cb:
*/
to_read = cb_size;
NAttrClearCompressed(na);
na->data_flags &= ~ATTR_COMPRESSION_MASK;
na->data_flags = le16_and(na->data_flags, le16_not(ATTR_COMPRESSION_MASK));
tdata_size = na->data_size;
tinitialized_size = na->initialized_size;
na->data_size = na->initialized_size = na->allocated_size;
@ -924,7 +924,7 @@ do_next_cb:
err = errno;
na->data_size = tdata_size;
na->initialized_size = tinitialized_size;
na->ni->flags |= compression;
na->ni->flags = le32_or(na->ni->flags, compression);
na->data_flags = data_flags;
free(cb);
free(dest);
@ -938,7 +938,7 @@ do_next_cb:
} while (to_read > 0);
na->data_size = tdata_size;
na->initialized_size = tinitialized_size;
na->ni->flags |= compression;
na->ni->flags = le32_or(na->ni->flags, compression);
na->data_flags = data_flags;
/* Just a precaution. */
if (cb_pos + 2 <= cb_end)

View File

@ -317,7 +317,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;
/* The file name must not overflow from the entry */
@ -359,7 +359,7 @@ u64 ntfs_inode_lookup_by_name(ntfs_inode *dir_ni,
* ENOENT, unless we have got the mft reference of a matching name
* cached in mref in which case return mref.
*/
if (!(ie->ie_flags & INDEX_ENTRY_NODE)) {
if (le16_andz(ie->ie_flags, INDEX_ENTRY_NODE)) {
ntfs_attr_put_search_ctx(ctx);
if (mref)
return mref;
@ -438,7 +438,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;
/* The file name must not overflow from the entry */
@ -475,7 +475,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",
@ -876,23 +876,23 @@ u32 ntfs_interix_types(ntfs_inode *ni)
* Unrecognized patterns (eg HID + SYST for metadata)
* are plain files or directories
*/
if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)
if (!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY))
dt_type = NTFS_DT_DIR;
else
dt_type = NTFS_DT_REG;
if (na->data_size <= 1) {
if (!(ni->flags & FILE_ATTR_HIDDEN))
if (le32_andz(ni->flags, FILE_ATTR_HIDDEN))
dt_type = (na->data_size ?
NTFS_DT_SOCK : NTFS_DT_FIFO);
} else {
if ((na->data_size >= (s64)sizeof(magic))
&& (ntfs_attr_pread(na, 0, sizeof(magic), &magic)
== sizeof(magic))) {
if (magic == INTX_SYMBOLIC_LINK)
if (le64_eq(magic, INTX_SYMBOLIC_LINK))
dt_type = NTFS_DT_LNK;
else if (magic == INTX_BLOCK_DEVICE)
else if (le64_eq(magic, INTX_BLOCK_DEVICE))
dt_type = NTFS_DT_BLK;
else if (magic == INTX_CHARACTER_DEVICE)
else if (le64_eq(magic, INTX_CHARACTER_DEVICE))
dt_type = NTFS_DT_CHR;
}
}
@ -919,16 +919,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))
dt_type = (ntfs_possible_symlink(ni)
? NTFS_DT_LNK : NTFS_DT_REPARSE);
else
if ((attributes & FILE_ATTR_SYSTEM)
&& !(attributes & FILE_ATTR_I30_INDEX_PRESENT))
if (!le32_andz(attributes, FILE_ATTR_SYSTEM)
&& le32_andz(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 ? */
@ -981,20 +981,20 @@ 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,
le32_or(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;
/* return metadata files and hidden files if requested */
if ((!metadata && (NVolShowHidFiles(dir_ni->vol)
|| !(fn->file_attributes & FILE_ATTR_HIDDEN)))
|| le32_andz(fn->file_attributes, FILE_ATTR_HIDDEN)))
|| (NVolShowSysFiles(dir_ni->vol) && (NVolShowHidFiles(dir_ni->vol)
|| metadata))) {
if (NVolCaseSensitive(dir_ni->vol)) {
@ -1120,7 +1120,7 @@ int ntfs_readdir(ntfs_inode *dir_ni, s64 *pos,
return -1;
}
if (!(dir_ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)) {
if (le16_andz(dir_ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)) {
errno = ENOTDIR;
return -1;
}
@ -1236,7 +1236,7 @@ int ntfs_readdir(ntfs_inode *dir_ni, s64 *pos,
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))
@ -1378,7 +1378,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))
@ -1499,7 +1499,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);
@ -1512,7 +1512,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 = const_cpu_to_le32(0);
ni->security_id = si->security_id = securid;
@ -1535,23 +1535,23 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid,
break;
}
}
ni->flags |= FILE_ATTR_ARCHIVE;
ni->flags = le32_or(ni->flags, FILE_ATTR_ARCHIVE);
if (NVolHideDotFiles(dir_ni->vol)
&& (name_len > 1)
&& (name[0] == const_cpu_to_le16('.'))
&& (name[1] != const_cpu_to_le16('.')))
ni->flags |= FILE_ATTR_HIDDEN;
&& (le16_eq(name[0], const_cpu_to_le16('.')))
&& (!le16_eq(name[1], const_cpu_to_le16('.'))))
ni->flags = le32_or(ni->flags, FILE_ATTR_HIDDEN);
/*
* Set compression flag according to parent directory
* 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)
&& (S_ISREG(type) || S_ISDIR(type)))
ni->flags |= FILE_ATTR_COMPRESSED;
ni->flags = le32_or(ni->flags, FILE_ATTR_COMPRESSED);
/* Add STANDARD_INFORMATION to inode. */
if (ntfs_attr_add(ni, AT_STANDARD_INFORMATION, AT_UNNAMED, 0,
(u8*)si, si_len)) {
@ -1561,7 +1561,7 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid,
goto err_out;
}
if (!securid) {
if (le32_cmpz(securid)) {
if (ntfs_sd_add_everyone(ni)) {
err = errno;
goto err_out;
@ -1702,14 +1702,14 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid,
if (special_files == NTFS_FILES_INTERIX)
fn->file_attributes = FILE_ATTR_SYSTEM;
} else
fn->file_attributes |= ni->flags & FILE_ATTR_COMPRESSED;
fn->file_attributes |= FILE_ATTR_ARCHIVE;
fn->file_attributes |= ni->flags & FILE_ATTR_HIDDEN;
fn->file_attributes = le32_or(fn->file_attributes, le32_and(ni->flags, FILE_ATTR_COMPRESSED));
fn->file_attributes = le32_or(fn->file_attributes, FILE_ATTR_ARCHIVE);
fn->file_attributes = le32_or(fn->file_attributes, le32_and(ni->flags, FILE_ATTR_HIDDEN));
fn->creation_time = ni->creation_time;
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_sle64(0);
else {
fn->data_size = cpu_to_sle64(ni->data_size);
@ -1733,7 +1733,7 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, le32 securid,
/* Set hard links count and directory flag. */
ni->mrec->link_count = const_cpu_to_le16(1);
if (S_ISDIR(type))
ni->mrec->flags |= MFT_RECORD_IS_DIRECTORY;
ni->mrec->flags = le16_or(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY);
/* Add reparse data */
if (special_files == NTFS_FILES_WSL) {
switch (type) {
@ -1843,7 +1843,7 @@ int ntfs_check_empty_dir(ntfs_inode *ni)
ntfs_attr *na;
int ret = 0;
if (!(ni->mrec->flags & MFT_RECORD_IS_DIRECTORY))
if (le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY))
return 0;
na = ntfs_attr_open(ni, AT_INDEX_ROOT, NTFS_INDEX_I30, 4);
@ -2025,7 +2025,7 @@ search:
* (Windows also does so), however delete the name if it were
* in an extent, to avoid leaving an attribute list.
*/
if ((ni->mrec->link_count == const_cpu_to_le16(1)) && !actx->base_ntfs_ino) {
if (le16_eq(ni->mrec->link_count, const_cpu_to_le16(1)) && !actx->base_ntfs_ino) {
/* make sure to not loop to another search */
looking_for_dos_name = FALSE;
} else {
@ -2081,7 +2081,7 @@ search:
ntfs_log_error("Could not delete inode cache entry for %s\n",
pathname);
#endif
if (ni->mrec->link_count) {
if (!le16_cmpz(ni->mrec->link_count)) {
ntfs_inode_update_times(ni, NTFS_UPDATE_CTIME);
goto ok;
}
@ -2215,11 +2215,11 @@ static int ntfs_link_i(ntfs_inode *ni, ntfs_inode *dir_ni, const ntfschar *name,
if (NVolHideDotFiles(dir_ni->vol)) {
/* Set hidden flag according to the latest name */
if ((name_len > 1)
&& (name[0] == const_cpu_to_le16('.'))
&& (name[1] != const_cpu_to_le16('.')))
ni->flags |= FILE_ATTR_HIDDEN;
&& (le16_eq(name[0], const_cpu_to_le16('.')))
&& (!le16_eq(name[1], const_cpu_to_le16('.'))))
ni->flags = le32_or(ni->flags, FILE_ATTR_HIDDEN);
else
ni->flags &= ~FILE_ATTR_HIDDEN;
ni->flags = le32_and(ni->flags, le32_not(FILE_ATTR_HIDDEN));
}
/* Create FILE_NAME attribute. */
@ -2234,8 +2234,8 @@ 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) {
fn->file_attributes |= FILE_ATTR_I30_INDEX_PRESENT;
if (!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)) {
fn->file_attributes = le32_or(fn->file_attributes, FILE_ATTR_I30_INDEX_PRESENT);
fn->data_size = fn->allocated_size = const_cpu_to_sle64(0);
} else {
fn->allocated_size = cpu_to_sle64(ni->allocated_size);
@ -2878,7 +2878,7 @@ int ntfs_dir_link_cnt(ntfs_inode *ni)
}
if (ni->nr_extents == -1)
ni = ni->base_ni;
if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) {
if (!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)) {
/*
* Directory : scan the directory and count
* subdirectories whose name is not DOS-only.

View File

@ -448,8 +448,8 @@ int ntfs_ea_check_wsldev(ntfs_inode *ni, dev_t *rdevp)
next = le32_to_cpu(p_ea->next_entry_offset);
found = ((next > (int)(sizeof(lxdev) + sizeof(device)))
&& (p_ea->name_length == (sizeof(lxdev) - 1))
&& (p_ea->value_length
== const_cpu_to_le16(sizeof(device)))
&& le16_eq(p_ea->value_length,
const_cpu_to_le16(sizeof(device)))
&& !memcmp(p_ea->name, lxdev, sizeof(lxdev)));
if (!found)
offset += next;

View File

@ -74,7 +74,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);
@ -159,7 +159,7 @@ static int fixup_loop(ntfs_inode *ni)
ntfs_log_error("can't open DATA Attribute\n");
res = -1;
}
if (na && !(ctx->attr->flags & ATTR_IS_ENCRYPTED)) {
if (na && le16_andz(ctx->attr->flags, ATTR_IS_ENCRYPTED)) {
if (!NAttrNonResident(na)
&& ntfs_attr_make_non_resident(na, ctx)) {
/*
@ -217,8 +217,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, le32_or(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;
@ -285,14 +285,14 @@ int ntfs_set_efs_info(ntfs_inode *ni, const char *value, size_t size,
}
if (!res) {
/* Don't handle AT_DATA Attribute(s) if inode is a directory */
if (!(ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)) {
if (le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)) {
/* iterate over AT_DATA attributes */
/* set encrypted flag, truncate attribute to match padding bytes */
if (fixup_loop(ni))
return -1;
}
ni->flags |= FILE_ATTR_ENCRYPTED;
ni->flags = le32_or(ni->flags, FILE_ATTR_ENCRYPTED);
NInoSetDirty(ni);
NInoFileNameSetDirty(ni);
}
@ -418,7 +418,7 @@ int ntfs_efs_fixup_attribute(ntfs_attr_search_ctx *ctx, ntfs_attr *na)
ctx->attr->data_size = cpu_to_sle64(newsize);
if (sle64_to_cpu(ctx->attr->initialized_size) > newsize)
ctx->attr->initialized_size = ctx->attr->data_size;
ctx->attr->flags |= ATTR_IS_ENCRYPTED;
ctx->attr->flags = le16_or(ctx->attr->flags, ATTR_IS_ENCRYPTED);
if (close_ctx)
ntfs_attr_put_search_ctx(ctx);

View File

@ -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 || !ie->length;
return !le16_andz(ie->ie_flags, INDEX_ENTRY_END) || le16_cmpz(ie->length);
}
/**
@ -376,13 +376,13 @@ 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);
if (dup) {
memcpy(dup, ie, size);
dup->ie_flags &= ~INDEX_ENTRY_NODE;
dup->ie_flags = le16_and(dup->ie_flags, le16_not(INDEX_ENTRY_NODE));
dup->length = cpu_to_le16(size);
}
return dup;
@ -528,7 +528,7 @@ int ntfs_index_entry_inconsistent(const INDEX_ENTRY *ie,
int ret;
ret = 0;
if (ie->key_length
if (!le16_cmpz(ie->key_length)
&& ((le16_to_cpu(ie->key_length) + offsetof(INDEX_ENTRY, key))
> le16_to_cpu(ie->length))) {
ntfs_log_error("Overflow from index entry in inode %lld\n",
@ -536,7 +536,7 @@ int ntfs_index_entry_inconsistent(const INDEX_ENTRY *ie,
ret = -1;
} else
if (collation_rule == COLLATION_FILE_NAME) {
if (le32_eq(collation_rule, COLLATION_FILE_NAME)) {
if ((offsetof(INDEX_ENTRY, key.file_name.file_name)
+ ie->key.file_name.file_name_length
* sizeof(ntfschar))
@ -547,7 +547,7 @@ int ntfs_index_entry_inconsistent(const INDEX_ENTRY *ie,
ret = -1;
}
} else {
if (ie->data_length
if (!le16_cmpz(ie->data_length)
&& ((le16_to_cpu(ie->data_offset)
+ le16_to_cpu(ie->data_length))
> le16_to_cpu(ie->length))) {
@ -649,7 +649,7 @@ static int ntfs_ie_lookup(const void *key, const int key_len,
* presence of a child node and if not present return with errno ENOENT,
* otherwise we will keep searching in another index block.
*/
if (!(ie->ie_flags & INDEX_ENTRY_NODE)) {
if (le16_andz(ie->ie_flags, INDEX_ENTRY_NODE)) {
ntfs_log_debug("Index entry wasn't found.\n");
*ie_out = ie;
errno = ENOENT;
@ -1180,7 +1180,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));
@ -1262,7 +1262,7 @@ retry :
ntfs_ir_nill(ir);
ie = ntfs_ie_get_first(&ir->index);
ie->ie_flags |= INDEX_ENTRY_NODE;
ie->ie_flags = le16_or(ie->ie_flags, INDEX_ENTRY_NODE);
ie->length = const_cpu_to_le16(sizeof(INDEX_ENTRY_HEADER) + sizeof(VCN));
ir->index.ih_flags = LARGE_INDEX;
@ -1385,7 +1385,7 @@ static int ntfs_ie_add_vcn(INDEX_ENTRY **ie)
if (!p)
return STATUS_ERROR;
p->ie_flags |= INDEX_ENTRY_NODE;
p->ie_flags = le16_or(p->ie_flags, INDEX_ENTRY_NODE);
*ie = p;
return STATUS_OK;
@ -1404,7 +1404,7 @@ static int ntfs_ih_insert(INDEX_HEADER *ih, INDEX_ENTRY *orig_ie, VCN new_vcn,
if (!ie)
return STATUS_ERROR;
if (!(ie->ie_flags & INDEX_ENTRY_NODE))
if (le16_andz(ie->ie_flags, INDEX_ENTRY_NODE))
if (ntfs_ie_add_vcn(&ie))
goto out;
@ -1446,7 +1446,7 @@ static int ntfs_ir_insert_median(ntfs_index_context *icx, INDEX_ENTRY *median,
new_size = le32_to_cpu(icx->ir->index.index_length) +
le16_to_cpu(median->length);
if (!(median->ie_flags & INDEX_ENTRY_NODE))
if (le16_andz(median->ie_flags, INDEX_ENTRY_NODE))
new_size += sizeof(VCN);
ret = ntfs_ir_make_space(icx, new_size);
@ -1670,7 +1670,7 @@ static int ntfs_ih_takeout(ntfs_index_context *icx, INDEX_HEADER *ih,
ntfs_log_trace("Entering\n");
full = ih->index_length == ih->allocated_size;
full = le32_eq(ih->index_length, ih->allocated_size);
ie_roam = ntfs_ie_dup_novcn(ie);
if (!ie_roam)
return STATUS_ERROR;
@ -1712,7 +1712,7 @@ static void ntfs_ir_leafify(ntfs_index_context *icx, INDEX_HEADER *ih)
ntfs_log_trace("Entering\n");
ie = ntfs_ie_get_first(ih);
ie->ie_flags &= ~INDEX_ENTRY_NODE;
ie->ie_flags = le16_and(ie->ie_flags, le16_not(INDEX_ENTRY_NODE));
ie->length = cpu_to_le16(le16_to_cpu(ie->length) - sizeof(VCN));
ih->index_length = cpu_to_le32(le32_to_cpu(ih->index_length) - sizeof(VCN));
@ -1931,7 +1931,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);
@ -2064,7 +2064,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);
}
@ -2115,7 +2115,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);
@ -2159,7 +2159,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 {
/*
@ -2173,20 +2173,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);
}

View File

@ -173,7 +173,7 @@ static ntfs_inode *ntfs_inode_real_open(ntfs_volume *vol, const MFT_REF mref)
goto out;
if (ntfs_file_record_read(vol, mref, &ni->mrec, NULL))
goto err_out;
if (!(ni->mrec->flags & MFT_RECORD_IN_USE)) {
if (le16_andz(ni->mrec->flags, MFT_RECORD_IN_USE)) {
errno = ENOENT;
goto err_out;
}
@ -184,7 +184,7 @@ static ntfs_inode *ntfs_inode_real_open(ntfs_volume *vol, const MFT_REF mref)
/* Receive some basic information about inode. */
if (ntfs_attr_lookup(AT_STANDARD_INFORMATION, AT_UNNAMED,
0, CASE_SENSITIVE, 0, NULL, 0, ctx)) {
if (!ni->mrec->base_mft_record)
if (le64_cmpz(ni->mrec->base_mft_record))
ntfs_log_perror("No STANDARD_INFORMATION in base record"
" %lld", (long long)MREF(mref));
goto put_err_out;
@ -263,8 +263,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,
le16_or(ATTR_IS_COMPRESSED, ATTR_IS_SPARSE)))
ni->allocated_size = sle64_to_cpu(
ctx->attr->compressed_size);
else
@ -516,7 +516,7 @@ int ntfs_inode_close(ntfs_inode *ni)
if (ni->vol && ni->vol->nidata_cache
&& ((ni->mft_no == FILE_root)
|| ((ni->mft_no >= FILE_first_user)
&& !(ni->mrec->flags & MFT_RECORD_IS_4)))) {
&& le16_andz(ni->mrec->flags, MFT_RECORD_IS_4)))) {
/* If we have dirty metadata, write it out. */
dirty = NInoDirty(ni) || NInoAttrListDirty(ni);
if (dirty) {
@ -811,7 +811,7 @@ static int ntfs_inode_sync_file_name(ntfs_inode *ni, ntfs_inode *dir_ni)
}
/* Collect the reparse tag, if any */
reparse_tag = const_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 +
@ -874,9 +874,9 @@ static int ntfs_inode_sync_file_name(ntfs_inode *ni, ntfs_inode *dir_ni)
/* Update flags and file size. */
fnx = (FILE_NAME_ATTR *)ictx->data;
fnx->file_attributes =
(fnx->file_attributes & ~FILE_ATTR_VALID_FLAGS) |
(ni->flags & FILE_ATTR_VALID_FLAGS);
if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)
le32_or(le32_and(fnx->file_attributes, le32_not(FILE_ATTR_VALID_FLAGS)),
le32_and(ni->flags, FILE_ATTR_VALID_FLAGS));
if (!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY))
fnx->data_size = fnx->allocated_size
= const_cpu_to_sle64(0);
else {
@ -960,7 +960,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;
@ -970,7 +970,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) {
@ -984,7 +984,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;
@ -1142,7 +1142,7 @@ int ntfs_inode_add_attrlist(ntfs_inode *ni)
int ale_size;
if (ctx->attr->type == AT_ATTRIBUTE_LIST) {
if (le32_eq(ctx->attr->type, AT_ATTRIBUTE_LIST)) {
err = EIO;
ntfs_log_perror("Attribute list already present");
goto put_err_out;
@ -1336,10 +1336,10 @@ retry:
}
if (ntfs_inode_base(ctx->ntfs_ino)->mft_no == FILE_MFT &&
ctx->attr->type == AT_DATA)
le32_eq(ctx->attr->type, AT_DATA))
goto retry;
if (ctx->attr->type == AT_INDEX_ROOT)
if (le32_eq(ctx->attr->type, AT_INDEX_ROOT))
goto retry;
record_size = le32_to_cpu(ctx->attr->length);
@ -1432,7 +1432,7 @@ int ntfs_inode_badclus_bad(u64 mft_no, ATTR_RECORD *attr)
if (mft_no != FILE_BadClus)
return 0;
if (attr->type != AT_DATA)
if (!le32_eq(attr->type, AT_DATA))
return 0;
if ((ustr = ntfs_str2ucs("$Bad", &len)) == NULL) {

View File

@ -90,10 +90,10 @@ static BOOL ntfs_check_restart_page_header(RESTART_PAGE_HEADER *rp, s64 pos)
* Windows 8, and we will refuse to mount.
* Nevertheless, do all the relevant checks before rejecting.
*/
if (((rp->major_ver != const_cpu_to_sle16(1))
|| (rp->minor_ver != const_cpu_to_sle16(1)))
&& ((rp->major_ver != const_cpu_to_sle16(2))
|| (rp->minor_ver != const_cpu_to_sle16(0)))) {
if ((!sle16_eq(rp->major_ver, const_cpu_to_sle16(1))
|| !sle16_eq(rp->minor_ver, const_cpu_to_sle16(1)))
&& (!sle16_eq(rp->major_ver, const_cpu_to_sle16(2))
|| !sle16_eq(rp->minor_ver, const_cpu_to_sle16(0)))) {
ntfs_log_error("$LogFile version %i.%i is not "
"supported.\n (This driver supports version "
"1.1 and 2.0 only.)\n",
@ -224,10 +224,10 @@ static BOOL ntfs_check_restart_area(RESTART_PAGE_HEADER *rp)
* LOGFILE_NO_CLIENT or less than ra->log_clients or they are
* overflowing the client array.
*/
if ((ra->client_free_list != LOGFILE_NO_CLIENT &&
if ((!le16_eq(ra->client_free_list, LOGFILE_NO_CLIENT) &&
le16_to_cpu(ra->client_free_list) >=
le16_to_cpu(ra->log_clients)) ||
(ra->client_in_use_list != LOGFILE_NO_CLIENT &&
(!le16_eq(ra->client_in_use_list, LOGFILE_NO_CLIENT) &&
le16_to_cpu(ra->client_in_use_list) >=
le16_to_cpu(ra->log_clients))) {
ntfs_log_error("$LogFile restart area specifies "
@ -312,7 +312,7 @@ check_list:
cr = ca + idx;
/* The first log client record must not have a prev_client. */
if (idx_is_first) {
if (cr->prev_client != LOGFILE_NO_CLIENT)
if (!le16_eq(cr->prev_client, LOGFILE_NO_CLIENT))
goto err_out;
idx_is_first = FALSE;
}
@ -429,7 +429,7 @@ static int ntfs_check_and_load_restart_page(ntfs_attr *log_na,
*/
err = 0;
if (ntfs_is_rstr_record(rp->magic) &&
ra->client_in_use_list != LOGFILE_NO_CLIENT) {
!le16_eq(ra->client_in_use_list, LOGFILE_NO_CLIENT)) {
if (!ntfs_check_log_client_array(trp)) {
err = EINVAL;
goto err_out;
@ -681,8 +681,8 @@ BOOL ntfs_is_logfile_clean(ntfs_attr *log_na, RESTART_PAGE_HEADER *rp)
* have the RESTART_VOLUME_IS_CLEAN bit set in the restart area flags,
* we assume there was an unclean shutdown.
*/
if (ra->client_in_use_list != LOGFILE_NO_CLIENT &&
!(ra->flags & RESTART_VOLUME_IS_CLEAN)) {
if (!le16_eq(ra->client_in_use_list, LOGFILE_NO_CLIENT) &&
le16_andz(ra->flags, RESTART_VOLUME_IS_CLEAN)) {
ntfs_log_error("The disk contains an unclean file system (%d, "
"%d).\n", le16_to_cpu(ra->client_in_use_list),
le16_to_cpu(ra->flags));

View File

@ -282,7 +282,7 @@ int ntfs_mft_record_check(const ntfs_volume *vol, const MFT_REF mref,
a = (ATTR_RECORD*)((char*)m + offset);
previous_type = AT_STANDARD_INFORMATION;
while ((space >= (s32)offsetof(ATTR_RECORD, resident_end))
&& (a->type != AT_END)
&& !le32_eq(a->type, AT_END)
&& (le32_to_cpu(a->type) >= le32_to_cpu(previous_type))) {
if ((le32_to_cpu(a->length) <= (u32)space)
&& !(le32_to_cpu(a->length) & 7)) {
@ -300,7 +300,7 @@ int ntfs_mft_record_check(const ntfs_volume *vol, const MFT_REF mref,
}
}
/* We are supposed to reach an AT_END */
if ((space < 4) || (a->type != AT_END)) {
if ((space < 4) || !le32_eq(a->type, AT_END)) {
ntfs_log_error("Bad end of MFT record %llu\n",
(unsigned long long)MREF(mref));
goto err_out;
@ -828,7 +828,7 @@ static int ntfs_mft_bitmap_extend_allocation_i(ntfs_volume *vol)
* We now have extended the mft bitmap allocated_size by one cluster.
* Reflect this in the ntfs_attr structure and the attribute record.
*/
if (a->lowest_vcn) {
if (!sle64_cmpz(a->lowest_vcn)) {
/*
* We are not in the first attribute extent, switch to it, but
* first ensure the changes will make it to disk later.
@ -1180,7 +1180,7 @@ static int ntfs_mft_data_extend_allocation(ntfs_volume *vol)
* @rl is the last (non-terminator) runlist element of mft data
* attribute.
*/
if (a->lowest_vcn) {
if (!sle64_cmpz(a->lowest_vcn)) {
/*
* We are not in the first attribute extent, switch to it, but
* first ensure the changes will make it to disk later.
@ -1463,8 +1463,8 @@ ntfs_inode *ntfs_mft_rec_alloc(ntfs_volume *vol, BOOL mft_data)
* extents of MFT, so we need a special check.
* If already used, apply standard procedure.
*/
if (!ext_ni->mrec->base_mft_record
&& !ext_ni->mrec->link_count)
if (le64_cmpz(ext_ni->mrec->base_mft_record)
&& le16_cmpz(ext_ni->mrec->link_count))
forced_mft_data = TRUE;
ntfs_inode_close(ext_ni);
/* Double-check, in case it is used for MFT */
@ -1522,7 +1522,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);
@ -1536,13 +1536,13 @@ found_free_rec:
free(m);
goto undo_mftbmp_alloc;
}
if (seq_no)
if (!le16_cmpz(seq_no))
m->sequence_number = seq_no;
seq_no = usn;
if (seq_no && seq_no != const_cpu_to_le16(0xffff))
if (!le16_cmpz(seq_no) && !le16_eq(seq_no, const_cpu_to_le16(0xffff)))
*(le16*)((u8*)m + le16_to_cpu(m->usa_ofs)) = usn;
/* Set the mft record itself in use. */
m->flags |= MFT_RECORD_IN_USE;
m->flags = le16_or(m->flags, MFT_RECORD_IN_USE);
/* Now need to open an ntfs inode for the mft record. */
ni = ntfs_inode_allocate(vol);
if (!ni) {
@ -1839,7 +1839,7 @@ found_free_rec:
NVolClearNoFixupWarn(vol);
/* 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);
@ -1861,13 +1861,13 @@ found_free_rec:
free(m);
goto undo_mftbmp_alloc;
}
if (seq_no)
if (!le16_cmpz(seq_no))
m->sequence_number = seq_no;
seq_no = usn;
if (seq_no && seq_no != const_cpu_to_le16(0xffff))
if (!le16_cmpz(seq_no) && !le16_eq(seq_no, const_cpu_to_le16(0xffff)))
*(le16*)((u8*)m + le16_to_cpu(m->usa_ofs)) = usn;
/* Set the mft record itself in use. */
m->flags |= MFT_RECORD_IN_USE;
m->flags = le16_or(m->flags, MFT_RECORD_IN_USE);
/* Now need to open an ntfs inode for the mft record. */
ni = ntfs_inode_allocate(vol);
if (!ni) {
@ -1971,7 +1971,7 @@ int ntfs_mft_record_free(ntfs_volume *vol, ntfs_inode *ni)
mft_no = ni->mft_no;
/* Mark the mft record as not in use. */
ni->mrec->flags &= ~MFT_RECORD_IN_USE;
ni->mrec->flags = le16_and(ni->mrec->flags, le16_not(MFT_RECORD_IN_USE));
/* Increment the sequence number, skipping zero, if it is not zero. */
old_seq_no = ni->mrec->sequence_number;
@ -2014,7 +2014,7 @@ bitmap_rollback:
ntfs_log_debug("Eeek! Rollback failed in ntfs_mft_record_free(). "
"Leaving inconsistent metadata!\n");
sync_rollback:
ni->mrec->flags |= MFT_RECORD_IN_USE;
ni->mrec->flags = le16_or(ni->mrec->flags, MFT_RECORD_IN_USE);
ni->mrec->sequence_number = old_seq_no;
ntfs_inode_mark_dirty(ni);
errno = err;

View File

@ -174,7 +174,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
@ -244,7 +244,7 @@ static char *search_absolute(ntfs_volume *vol, ntfschar *path,
do {
len = 0;
while (((start + len) < count)
&& (path[start + len] != const_cpu_to_le16('\\')))
&& !le16_eq(path[start + len], const_cpu_to_le16('\\')))
len++;
inum = ntfs_fix_file_name(ni, &path[start], len);
ntfs_inode_close(ni);
@ -257,12 +257,12 @@ static char *search_absolute(ntfs_volume *vol, ntfschar *path,
path[start++] = const_cpu_to_le16('/');
}
} while (ni
&& (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)
&& !(ni->flags & FILE_ATTR_REPARSE_POINT)
&& !le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)
&& le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)
&& (start < count));
if (ni
&& ((ni->mrec->flags & MFT_RECORD_IS_DIRECTORY ? isdir : !isdir)
|| (ni->flags & FILE_ATTR_REPARSE_POINT)))
&& ((!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY) ? isdir : !isdir)
|| (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT))))
if (ntfs_ucstombs(path, count, &target, 0) < 0) {
if (target) {
free(target);
@ -316,15 +316,15 @@ static char *search_relative(ntfs_inode *ni, ntfschar *path, int count)
*/
while (curni && ok && !morelinks && (pos < (count - 1)) && --max) {
if ((count >= (pos + 2))
&& (path[pos] == const_cpu_to_le16('.'))
&& (path[pos+1] == const_cpu_to_le16('\\'))) {
&& le16_eq(path[pos], const_cpu_to_le16('.'))
&& le16_eq(path[pos+1], const_cpu_to_le16('\\'))) {
path[pos+1] = const_cpu_to_le16('/');
pos += 2;
} else {
if ((count >= (pos + 3))
&& (path[pos] == const_cpu_to_le16('.'))
&&(path[pos+1] == const_cpu_to_le16('.'))
&& (path[pos+2] == const_cpu_to_le16('\\'))) {
&& le16_eq(path[pos], const_cpu_to_le16('.'))
&& le16_eq(path[pos+1], const_cpu_to_le16('.'))
&& le16_eq(path[pos+2], const_cpu_to_le16('\\'))) {
path[pos+2] = const_cpu_to_le16('/');
pos += 3;
newni = ntfs_dir_parent_inode(curni);
@ -336,7 +336,7 @@ static char *search_relative(ntfs_inode *ni, ntfschar *path, int count)
} else {
lth = 0;
while (((pos + lth) < count)
&& (path[pos + lth] != const_cpu_to_le16('\\')))
&& !le16_eq(path[pos + lth], const_cpu_to_le16('\\')))
lth++;
if (lth > 0)
inum = ntfs_fix_file_name(curni,&path[pos],lth);
@ -352,7 +352,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('/');
@ -363,8 +363,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(le16_xor(ni->mrec->flags, curni->mrec->flags),
MFT_RECORD_IS_DIRECTORY))
ok = FALSE;
if (ntfs_inode_close(curni))
ok = FALSE;
@ -436,18 +436,18 @@ int ntfs_reparse_check_wsl(ntfs_inode *ni, const REPARSE_POINT *reparse)
int res;
res = -EOPNOTSUPP;
switch (reparse->reparse_tag) {
case IO_REPARSE_TAG_AF_UNIX :
case IO_REPARSE_TAG_LX_FIFO :
case IO_REPARSE_TAG_LX_CHR :
case IO_REPARSE_TAG_LX_BLK :
if (!reparse->reparse_data_length
&& (ni->flags & FILE_ATTRIBUTE_RECALL_ON_OPEN))
/* switch (reparse->reparse_tag) { */
if (le32_eq(reparse->reparse_tag, IO_REPARSE_TAG_AF_UNIX) ||
le32_eq(reparse->reparse_tag, IO_REPARSE_TAG_LX_FIFO) ||
le32_eq(reparse->reparse_tag, IO_REPARSE_TAG_LX_CHR) ||
le32_eq(reparse->reparse_tag, IO_REPARSE_TAG_LX_BLK)) {
if (le16_cmpz(reparse->reparse_data_length)
&& !le32_andz(ni->flags, FILE_ATTRIBUTE_RECALL_ON_OPEN))
res = 0;
break;
default :
break;
}
else {
}
/* } */
if (res)
errno = EOPNOTSUPP;
return (res);
@ -477,14 +477,14 @@ static BOOL valid_reparse_data(ntfs_inode *ni,
ok = ni && reparse_attr
&& (size >= sizeof(REPARSE_POINT))
&& (reparse_attr->reparse_tag != IO_REPARSE_TAG_RESERVED_ZERO)
&& !le32_eq(reparse_attr->reparse_tag, IO_REPARSE_TAG_RESERVED_ZERO)
&& (((size_t)le16_to_cpu(reparse_attr->reparse_data_length)
+ sizeof(REPARSE_POINT)
+ ((reparse_attr->reparse_tag &
+ (!le32_andz(reparse_attr->reparse_tag,
IO_REPARSE_TAG_IS_MICROSOFT) ? 0 : sizeof(GUID))) == size);
if (ok) {
switch (reparse_attr->reparse_tag) {
case IO_REPARSE_TAG_MOUNT_POINT :
do {
if (le32_eq(reparse_attr->reparse_tag, IO_REPARSE_TAG_MOUNT_POINT)) {
if (size < sizeof(REPARSE_POINT) +
sizeof(struct MOUNT_POINT_REPARSE_DATA)) {
ok = FALSE;
@ -495,13 +495,13 @@ static BOOL valid_reparse_data(ntfs_inode *ni,
offs = le16_to_cpu(mount_point_data->subst_name_offset);
lth = le16_to_cpu(mount_point_data->subst_name_length);
/* consistency checks */
if (!(ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)
if (le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)
|| ((size_t)((sizeof(REPARSE_POINT)
+ sizeof(struct MOUNT_POINT_REPARSE_DATA)
+ offs + lth)) > size))
ok = FALSE;
break;
case IO_REPARSE_TAG_SYMLINK :
} else if (le32_eq(reparse_attr->reparse_tag, IO_REPARSE_TAG_SYMLINK)) {
if (size < sizeof(REPARSE_POINT) +
sizeof(struct SYMLINK_REPARSE_DATA)) {
ok = FALSE;
@ -516,25 +516,26 @@ static BOOL valid_reparse_data(ntfs_inode *ni,
+ offs + lth)) > size)
ok = FALSE;
break;
case IO_REPARSE_TAG_LX_SYMLINK :
} else if (le32_eq(reparse_attr->reparse_tag, IO_REPARSE_TAG_LX_SYMLINK)) {
wsl_reparse_data = (const struct WSL_LINK_REPARSE_DATA*)
reparse_attr->reparse_data;
if ((le16_to_cpu(reparse_attr->reparse_data_length)
<= sizeof(wsl_reparse_data->type))
|| (wsl_reparse_data->type != const_cpu_to_le32(2)))
|| (!le32_eq(wsl_reparse_data->type, const_cpu_to_le32(2))))
ok = FALSE;
break;
case IO_REPARSE_TAG_AF_UNIX :
case IO_REPARSE_TAG_LX_FIFO :
case IO_REPARSE_TAG_LX_CHR :
case IO_REPARSE_TAG_LX_BLK :
if (reparse_attr->reparse_data_length
|| !(ni->flags & FILE_ATTRIBUTE_RECALL_ON_OPEN))
} else if (le32_eq(reparse_attr->reparse_tag, IO_REPARSE_TAG_AF_UNIX) ||
le32_eq(reparse_attr->reparse_tag, IO_REPARSE_TAG_LX_FIFO) ||
le32_eq(reparse_attr->reparse_tag, IO_REPARSE_TAG_LX_CHR) ||
le32_eq(reparse_attr->reparse_tag, IO_REPARSE_TAG_LX_BLK)) {
if (!le16_cmpz(reparse_attr->reparse_data_length)
|| le32_andz(ni->flags, FILE_ATTRIBUTE_RECALL_ON_OPEN))
ok = FALSE;
break;
default :
break;
}
else {
break;
} } while(0);
}
if (!ok)
errno = EINVAL;
@ -573,9 +574,9 @@ static char *ntfs_get_fulllink(ntfs_volume *vol, ntfschar *junction,
*/
if ((count >= 7)
&& !memcmp(junction,dir_junction_head,8)
&& junction[4]
&& (junction[5] == const_cpu_to_le16(':'))
&& (junction[6] == const_cpu_to_le16('\\')))
&& !le16_cmpz(junction[4])
&& le16_eq(junction[5], const_cpu_to_le16(':'))
&& le16_eq(junction[6], const_cpu_to_le16('\\')))
kind = DIR_JUNCTION;
else
/*
@ -584,7 +585,7 @@ static char *ntfs_get_fulllink(ntfs_volume *vol, ntfschar *junction,
*/
if ((count >= 12)
&& !memcmp(junction,vol_junction_head,22)
&& (junction[count-1] == const_cpu_to_le16('\\')))
&& le16_eq(junction[count-1], const_cpu_to_le16('\\')))
kind = VOL_JUNCTION;
else
kind = NO_JUNCTION;
@ -595,7 +596,7 @@ static char *ntfs_get_fulllink(ntfs_volume *vol, ntfschar *junction,
*/
if ((kind == DIR_JUNCTION)
&& (count >= 7)
&& junction[7]
&& !le16_cmpz(junction[7])
&& !ntfs_drive_letter(vol, junction[4])) {
target = search_absolute(vol,&junction[7],count - 7, isdir);
if (target) {
@ -676,16 +677,16 @@ char *ntfs_get_abslink(ntfs_volume *vol, ntfschar *junction, int count,
* where \ is an individual char and x a non-null char
*/
if ((count >= 3)
&& junction[0]
&& (junction[1] == const_cpu_to_le16(':'))
&& (junction[2] == const_cpu_to_le16('\\')))
&& !le16_cmpz(junction[0])
&& le16_eq(junction[1], const_cpu_to_le16(':'))
&& le16_eq(junction[2], const_cpu_to_le16('\\')))
kind = FULL_PATH;
else
/*
* For an absolute path we want an initial \
*/
if ((count >= 0)
&& (junction[0] == const_cpu_to_le16('\\')))
&& le16_eq(junction[0], const_cpu_to_le16('\\')))
kind = ABS_PATH;
else
kind = REJECTED_PATH;
@ -697,7 +698,7 @@ char *ntfs_get_abslink(ntfs_volume *vol, ntfschar *junction, int count,
*/
if (((kind == FULL_PATH)
&& (count >= 3)
&& junction[3]
&& !le16_cmpz(junction[3])
&& !ntfs_drive_letter(vol, junction[0]))
|| (kind == ABS_PATH)) {
if (kind == ABS_PATH)
@ -800,15 +801,15 @@ char *ntfs_make_symlink(ntfs_inode *ni, const char *mnt_point)
target = (char*)NULL;
bad = TRUE;
isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)
!= const_cpu_to_le16(0);
isdir = !le16_eq(le16_and(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY),
const_cpu_to_le16(0));
vol = ni->vol;
reparse_attr = (REPARSE_POINT*)ntfs_attr_readall(ni,
AT_REPARSE_POINT,(ntfschar*)NULL, 0, &attr_size);
if (reparse_attr && attr_size
&& valid_reparse_data(ni, reparse_attr, attr_size)) {
switch (reparse_attr->reparse_tag) {
case IO_REPARSE_TAG_MOUNT_POINT :
/* switch (reparse_attr->reparse_tag) { */
if (le32_eq(reparse_attr->reparse_tag, IO_REPARSE_TAG_MOUNT_POINT)) {
mount_point_data = (struct MOUNT_POINT_REPARSE_DATA*)
reparse_attr->reparse_data;
offs = le16_to_cpu(mount_point_data->subst_name_offset);
@ -819,8 +820,8 @@ char *ntfs_make_symlink(ntfs_inode *ni, const char *mnt_point)
lth/2, mnt_point, isdir);
if (target)
bad = FALSE;
break;
case IO_REPARSE_TAG_SYMLINK :
}
else if (le32_eq(reparse_attr->reparse_tag, IO_REPARSE_TAG_SYMLINK)) {
symlink_data = (struct SYMLINK_REPARSE_DATA*)
reparse_attr->reparse_data;
offs = le16_to_cpu(symlink_data->subst_name_offset);
@ -830,14 +831,14 @@ char *ntfs_make_symlink(ntfs_inode *ni, const char *mnt_point)
* Predetermine the kind of target,
* the called function has to make a full check
*/
if (*p++ == const_cpu_to_le16('\\')) {
if ((*p == const_cpu_to_le16('?'))
|| (*p == const_cpu_to_le16('\\')))
if (le16_eq(*p++, const_cpu_to_le16('\\'))) {
if ((le16_eq(*p, const_cpu_to_le16('?')))
|| (le16_eq(*p, const_cpu_to_le16('\\'))))
kind = FULL_TARGET;
else
kind = ABS_TARGET;
} else
if (*p == const_cpu_to_le16(':'))
if (le16_eq(*p, const_cpu_to_le16(':')))
kind = ABS_TARGET;
else
kind = REL_TARGET;
@ -845,8 +846,8 @@ char *ntfs_make_symlink(ntfs_inode *ni, const char *mnt_point)
/* reparse data consistency has been checked */
switch (kind) {
case FULL_TARGET :
if (!(symlink_data->flags
& const_cpu_to_le32(1))) {
if (le32_andz(symlink_data->flags,
const_cpu_to_le32(1))) {
target = ntfs_get_fulllink(vol,
p, lth/2,
mnt_point, isdir);
@ -855,8 +856,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);
@ -865,8 +866,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)
@ -874,11 +875,11 @@ char *ntfs_make_symlink(ntfs_inode *ni, const char *mnt_point)
}
break;
}
break;
case IO_REPARSE_TAG_LX_SYMLINK :
}
else if (le32_eq(reparse_attr->reparse_tag, IO_REPARSE_TAG_LX_SYMLINK)) {
wsl_link_data = (struct WSL_LINK_REPARSE_DATA*)
reparse_attr->reparse_data;
if (wsl_link_data->type == const_cpu_to_le32(2)) {
if (le32_eq(wsl_link_data->type, const_cpu_to_le32(2))) {
lth = le16_to_cpu(
reparse_attr->reparse_data_length)
- sizeof(wsl_link_data->type);
@ -890,7 +891,6 @@ char *ntfs_make_symlink(ntfs_inode *ni, const char *mnt_point)
bad = FALSE;
}
}
break;
}
free(reparse_attr);
}
@ -917,12 +917,12 @@ BOOL ntfs_possible_symlink(ntfs_inode *ni)
reparse_attr = (REPARSE_POINT*)ntfs_attr_readall(ni,
AT_REPARSE_POINT,(ntfschar*)NULL, 0, &attr_size);
if (reparse_attr && attr_size) {
switch (reparse_attr->reparse_tag) {
case IO_REPARSE_TAG_MOUNT_POINT :
case IO_REPARSE_TAG_SYMLINK :
case IO_REPARSE_TAG_LX_SYMLINK :
/* switch (reparse_attr->reparse_tag) { */
if (le32_eq(reparse_attr->reparse_tag, IO_REPARSE_TAG_MOUNT_POINT) ||
le32_eq(reparse_attr->reparse_tag, IO_REPARSE_TAG_SYMLINK) ||
le32_eq(reparse_attr->reparse_tag, IO_REPARSE_TAG_LX_SYMLINK)) {
possible = TRUE;
default : ;
} else {
}
free(reparse_attr);
}
@ -1161,7 +1161,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) {
@ -1219,8 +1219,8 @@ int ntfs_set_ntfs_reparse_data(ntfs_inode *ni,
AT_UNNAMED,0,&dummy,
(s64)0);
if (!res) {
ni->flags |=
FILE_ATTR_REPARSE_POINT;
ni->flags = le32_or(ni->flags,
FILE_ATTR_REPARSE_POINT);
NInoFileNameSetDirty(ni);
}
NInoSetDirty(ni);
@ -1290,8 +1290,8 @@ int ntfs_remove_ntfs_reparse_data(ntfs_inode *ni)
/* now remove attribute */
res = ntfs_attr_rm(na);
if (!res) {
ni->flags &=
~FILE_ATTR_REPARSE_POINT;
ni->flags = le32_and(ni->flags,
le32_not(FILE_ATTR_REPARSE_POINT));
NInoFileNameSetDirty(ni);
} else {
/*

View File

@ -948,7 +948,7 @@ mpa_err:
* the runlist with LCN_NOENT. Otherwise, we must terminate the runlist
* with LCN_RL_NOT_MAPPED and let the caller look for more extents.
*/
if (!attr->lowest_vcn) {
if (sle64_cmpz(attr->lowest_vcn)) {
VCN num_clusters;
num_clusters = ((sle64_to_cpu(attr->allocated_size) +

View File

@ -74,13 +74,13 @@
#define FIRST_SECURITY_ID 0x100 /* Lowest security id */
/* Mask for attributes which can be forced */
#define FILE_ATTR_SETTABLE ( FILE_ATTR_READONLY \
| FILE_ATTR_HIDDEN \
| FILE_ATTR_SYSTEM \
| FILE_ATTR_ARCHIVE \
| FILE_ATTR_TEMPORARY \
| FILE_ATTR_OFFLINE \
| FILE_ATTR_NOT_CONTENT_INDEXED )
#define FILE_ATTR_SETTABLE le32_or(FILE_ATTR_READONLY, \
le32_or(FILE_ATTR_HIDDEN, \
le32_or(FILE_ATTR_SYSTEM, \
le32_or(FILE_ATTR_ARCHIVE, \
le32_or(FILE_ATTR_TEMPORARY, \
le32_or(FILE_ATTR_OFFLINE, \
FILE_ATTR_NOT_CONTENT_INDEXED))))))
struct SII { /* this is an image of an $SII index entry */
le16 offs;
@ -241,7 +241,7 @@ int ntfs_sid_to_mbs_size(const SID *sid)
* maximum is 2^32-1 = 4294967295 = 10 characters. If it needs to be
* in hexadecimal, then maximum is 0x665544332211 = 14 characters.
*/
if (!sid->identifier_authority.high_part)
if (be16_cmpz(sid->identifier_authority.high_part))
size += 10;
else
size += 14;
@ -324,7 +324,7 @@ char *ntfs_sid_to_mbs(const SID *sid, char *sid_str, size_t sid_str_size)
/* Add the identifier authority. */
for (u = i = 0, j = 40; i < 6; i++, j -= 8)
u += (u64)sid->identifier_authority.value[i] << j;
if (!sid->identifier_authority.high_part)
if (be16_cmpz(sid->identifier_authority.high_part))
i = snprintf(s, cnt, "%lu", (unsigned long)u);
else
i = snprintf(s, cnt, "0x%llx", (unsigned long long)u);
@ -707,7 +707,7 @@ static le32 entersecurityattr(ntfs_volume *vol,
size = le32_to_cpu(psii->datasize);
}
entry = next;
if (!entry && !keyid && !retries) {
if (!entry && le32_cmpz(keyid) && !retries) {
/* search failed, retry from smallest key */
ntfs_index_ctx_reinit(xsii);
found = !ntfs_index_lookup((char*)&keyid,
@ -722,7 +722,7 @@ static le32 entersecurityattr(ntfs_volume *vol,
psii = (struct SII*)entry;
}
if (psii
&& !(psii->flags & INDEX_ENTRY_END)) {
&& le16_andz(psii->flags, INDEX_ENTRY_END)) {
/* save first key and */
/* available position */
keyid = psii->keysecurid;
@ -737,7 +737,7 @@ static le32 entersecurityattr(ntfs_volume *vol,
}
}
}
if (!keyid) {
if (le32_cmpz(keyid)) {
/*
* could not find any entry, before creating the first
* entry, make a double check by making sure size of $SII
@ -753,7 +753,7 @@ static le32 entersecurityattr(ntfs_volume *vol,
}
ntfs_attr_close(na);
}
if (!securid) {
if (le32_cmpz(securid)) {
ntfs_log_error("Error creating a security_id\n");
errno = EIO;
}
@ -769,7 +769,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)
@ -870,7 +870,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;
@ -881,7 +881,7 @@ static le32 setsecurityattr(ntfs_volume *vol,
else size = 0;
/* if hash is not the same, the key is not present */
if (psdh && (size > 0)
&& (psdh->keyhash == hash)) {
&& (le32_eq(psdh->keyhash, hash))) {
/* if hash is the same */
/* check the whole record */
realign.parts.dataoffsh = psdh->dataoffsh;
@ -1009,7 +1009,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) {
@ -1085,7 +1085,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) {
@ -1592,7 +1592,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
@ -1682,7 +1682,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;
@ -1744,7 +1744,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);
@ -1765,7 +1765,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;
@ -1879,7 +1879,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);
@ -2322,8 +2322,8 @@ static int ntfs_get_perm(struct SECURITY_CONTEXT *scx,
gid = cached->gid;
} else {
perm = 0; /* default to no permission */
isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)
!= const_cpu_to_le16(0);
isdir = !le16_eq(le16_and(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY),
const_cpu_to_le16(0));
securattr = getsecurityattr(scx->vol, ni);
if (securattr) {
phead = (const SECURITY_DESCRIPTOR_RELATIVE*)
@ -2467,8 +2467,8 @@ int ntfs_get_owner_mode(struct SECURITY_CONTEXT *scx,
stbuf->st_mode = (stbuf->st_mode & ~07777) + perm;
} else {
perm = -1; /* default to error */
isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)
!= const_cpu_to_le16(0);
isdir = !le16_eq(le16_and(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY),
const_cpu_to_le16(0));
securattr = getsecurityattr(scx->vol, ni);
if (securattr) {
phead =
@ -2838,7 +2838,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,
@ -2889,7 +2889,7 @@ int ntfs_set_owner_mode(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
/* check whether target securid is known in cache */
isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) != const_cpu_to_le16(0);
isdir = !le16_eq(le16_and(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY), const_cpu_to_le16(0));
wanted.uid = uid;
wanted.gid = gid;
wanted.dmode = mode & 07777;
@ -2916,9 +2916,9 @@ int ntfs_set_owner_mode(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
/* adjust Windows read-only flag */
if (!isdir) {
if (mode & S_IWUSR)
ni->flags &= ~FILE_ATTR_READONLY;
ni->flags = le32_and(ni->flags, le32_not(FILE_ATTR_READONLY));
else
ni->flags |= FILE_ATTR_READONLY;
ni->flags = le32_or(ni->flags, FILE_ATTR_READONLY);
NInoFileNameSetDirty(ni);
}
}
@ -2954,9 +2954,9 @@ int ntfs_set_owner_mode(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
/* adjust Windows read-only flag */
if (!isdir) {
if (mode & S_IWUSR)
ni->flags &= ~FILE_ATTR_READONLY;
ni->flags = le32_and(ni->flags, le32_not(FILE_ATTR_READONLY));
else
ni->flags |= FILE_ATTR_READONLY;
ni->flags = le32_or(ni->flags, FILE_ATTR_READONLY);
NInoFileNameSetDirty(ni);
}
/* update cache, for subsequent use */
@ -2968,7 +2968,7 @@ int ntfs_set_owner_mode(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
}
#if CACHE_LEGACY_SIZE
/* also invalidate legacy cache */
if (isdir && !ni->security_id) {
if (isdir && le32_cmpz(ni->security_id)) {
struct CACHED_PERMISSIONS_LEGACY legacy;
legacy.mft_no = ni->mft_no;
@ -3218,8 +3218,8 @@ 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)
&& !ni->security_id) {
if (!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)
&& le32_cmpz(ni->security_id)) {
struct CACHED_PERMISSIONS_LEGACY legacy;
legacy.mft_no = ni->mft_no;
@ -3381,7 +3381,7 @@ int ntfs_sd_add_everyone(ntfs_inode *ni)
return -1;
sd->revision = SECURITY_DESCRIPTOR_REVISION;
sd->control = SE_DACL_PRESENT | SE_SELF_RELATIVE;
sd->control = le16_or(SE_DACL_PRESENT, SE_SELF_RELATIVE);
sid = (SID*)((u8*)sd + sizeof(SECURITY_DESCRIPTOR_ATTR));
sid->revision = SID_REVISION;
@ -3453,7 +3453,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);
@ -3663,8 +3663,8 @@ int ntfs_set_owner(struct SECURITY_CONTEXT *scx, ntfs_inode *ni,
mode = 0;
oldattr = getsecurityattr(scx->vol, ni);
if (oldattr) {
isdir = (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)
!= const_cpu_to_le16(0);
isdir = !le16_eq(le16_and(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY),
const_cpu_to_le16(0));
phead = (const SECURITY_DESCRIPTOR_RELATIVE*)
oldattr;
gsid = (const SID*)
@ -3951,43 +3951,43 @@ static le32 build_inherited_id(struct SECURITY_CONTEXT *scx,
pnhead = (SECURITY_DESCRIPTOR_RELATIVE*)newattr;
pnhead->revision = SECURITY_DESCRIPTOR_REVISION;
pnhead->alignment = 0;
pnhead->control = (pphead->control
& (SE_DACL_AUTO_INHERITED | SE_SACL_AUTO_INHERITED))
| SE_SELF_RELATIVE;
pnhead->control = le16_or(le16_and(pphead->control,
le16_or(SE_DACL_AUTO_INHERITED, SE_SACL_AUTO_INHERITED)),
SE_SELF_RELATIVE);
pos = sizeof(SECURITY_DESCRIPTOR_RELATIVE);
/*
* locate and inherit DACL
* 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];
aclsz = ntfs_inherit_acl(ppacl, pnacl, usid, gsid,
fordir, pphead->control
& SE_DACL_AUTO_INHERITED);
fordir, le16_and(pphead->control,
SE_DACL_AUTO_INHERITED));
if (aclsz) {
pnhead->dacl = cpu_to_le32(pos);
pos += aclsz;
pnhead->control |= SE_DACL_PRESENT;
pnhead->control = le16_or(pnhead->control, SE_DACL_PRESENT);
}
}
/*
* 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];
aclsz = ntfs_inherit_acl(ppacl, pnacl, usid, gsid,
fordir, pphead->control
& SE_SACL_AUTO_INHERITED);
fordir, le16_and(pphead->control,
SE_SACL_AUTO_INHERITED));
if (aclsz) {
pnhead->sacl = cpu_to_le32(pos);
pos += aclsz;
pnhead->control |= SE_SACL_PRESENT;
pnhead->control = le16_or(pnhead->control, SE_DACL_PRESENT);
}
}
/*
@ -4040,7 +4040,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))
@ -4051,7 +4051,7 @@ le32 ntfs_inherited_id(struct SECURITY_CONTEXT *scx,
* Not cached or not available in cache, compute it all
* Note : if parent directory has no id, it is not cacheable
*/
if (!securid) {
if (le32_cmpz(securid)) {
parentattr = getsecurityattr(scx->vol, dir_ni);
if (parentattr) {
securid = build_inherited_id(scx,
@ -4061,7 +4061,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)
@ -4392,7 +4392,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);
@ -4431,15 +4431,15 @@ 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
*/
settable |= FILE_ATTR_COMPRESSED;
if ((ni->flags ^ cpu_to_le32(attrib))
& FILE_ATTR_COMPRESSED) {
if (ni->flags & FILE_ATTR_COMPRESSED)
settable = le32_or(settable, FILE_ATTR_COMPRESSED);
if (!le32_andz(le32_xor(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;
@ -4451,8 +4451,8 @@ int ntfs_set_ntfs_attrib(ntfs_inode *ni,
}
}
if (!res) {
ni->flags = (ni->flags & ~settable)
| (cpu_to_le32(attrib) & settable);
ni->flags = le32_or(le32_and(ni->flags, le32_not(settable)),
le32_and(cpu_to_le32(attrib), settable));
NInoFileNameSetDirty(ni);
NInoSetDirty(ni);
}
@ -4585,7 +4585,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);
@ -4617,7 +4617,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];
@ -4638,21 +4638,21 @@ static BOOL feedsecurityattr(const char *attr, u32 selection,
ok = FALSE;
} else {
if (selection & OWNER_SECURITY_INFORMATION)
control |= phead->control & SE_OWNER_DEFAULTED;
control = le16_or(control, le16_and(phead->control, SE_OWNER_DEFAULTED));
if (selection & GROUP_SECURITY_INFORMATION)
control |= phead->control & SE_GROUP_DEFAULTED;
control = le16_or(control, le16_and(phead->control, SE_GROUP_DEFAULTED));
if (selection & DACL_SECURITY_INFORMATION)
control |= phead->control
& (SE_DACL_PRESENT
| SE_DACL_DEFAULTED
| SE_DACL_AUTO_INHERITED
| SE_DACL_PROTECTED);
control = le16_or(control, le16_and(phead->control,
le16_or(SE_DACL_PRESENT,
le16_or(SE_DACL_DEFAULTED,
le16_or(SE_DACL_AUTO_INHERITED,
SE_DACL_PROTECTED)))));
if (selection & SACL_SECURITY_INFORMATION)
control |= phead->control
& (SE_SACL_PRESENT
| SE_SACL_DEFAULTED
| SE_SACL_AUTO_INHERITED
| SE_SACL_PROTECTED);
control = le16_or(control, le16_and(phead->control,
le16_or(SE_SACL_PRESENT,
le16_or(SE_SACL_DEFAULTED,
le16_or(SE_SACL_AUTO_INHERITED,
SE_SACL_PROTECTED)))));
/*
* copy header and feed new flags, even if no detailed data
*/
@ -4744,8 +4744,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];
@ -4760,24 +4760,24 @@ static BOOL mergesecurityattr(ntfs_volume *vol, const char *oldattr,
} else
targhead->dacl = const_cpu_to_le32(0);
if (selection & DACL_SECURITY_INFORMATION) {
control |= newhead->control
& (SE_DACL_PRESENT
| SE_DACL_DEFAULTED
| SE_DACL_PROTECTED);
if (newhead->control & SE_DACL_AUTO_INHERIT_REQ)
control |= SE_DACL_AUTO_INHERITED;
control = le16_or(control, le16_and(newhead->control,
le16_or(SE_DACL_PRESENT,
le16_or(SE_DACL_DEFAULTED,
SE_DACL_PROTECTED))));
if (!le16_andz(newhead->control, SE_DACL_AUTO_INHERIT_REQ))
control = le16_or(control, SE_DACL_AUTO_INHERITED);
} else
control |= oldhead->control
& (SE_DACL_PRESENT
| SE_DACL_DEFAULTED
| SE_DACL_AUTO_INHERITED
| SE_DACL_PROTECTED);
control = le16_or(control, le16_and(oldhead->control,
le16_or(SE_DACL_PRESENT,
le16_or(SE_DACL_DEFAULTED,
le16_or(SE_DACL_AUTO_INHERITED,
SE_DACL_PROTECTED)))));
/*
* 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];
@ -4792,24 +4792,24 @@ static BOOL mergesecurityattr(ntfs_volume *vol, const char *oldattr,
} else
targhead->sacl = const_cpu_to_le32(0);
if (selection & SACL_SECURITY_INFORMATION) {
control |= newhead->control
& (SE_SACL_PRESENT
| SE_SACL_DEFAULTED
| SE_SACL_PROTECTED);
if (newhead->control & SE_SACL_AUTO_INHERIT_REQ)
control |= SE_SACL_AUTO_INHERITED;
control = le16_or(control, le16_and(newhead->control,
le16_or(SE_SACL_PRESENT,
le16_or(SE_SACL_DEFAULTED,
SE_SACL_PROTECTED))));
if (!le16_andz(newhead->control, SE_SACL_AUTO_INHERIT_REQ))
control = le16_or(control, SE_SACL_AUTO_INHERITED);
} else
control |= oldhead->control
& (SE_SACL_PRESENT
| SE_SACL_DEFAULTED
| SE_SACL_AUTO_INHERITED
| SE_SACL_PROTECTED);
control = le16_or(control, le16_and(oldhead->control,
le16_or(SE_SACL_PRESENT,
le16_or(SE_SACL_DEFAULTED,
le16_or(SE_SACL_AUTO_INHERITED,
SE_SACL_PROTECTED)))));
/*
* 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];
@ -4824,25 +4824,25 @@ static BOOL mergesecurityattr(ntfs_volume *vol, const char *oldattr,
} else
targhead->owner = const_cpu_to_le32(0);
if (selection & OWNER_SECURITY_INFORMATION)
control |= newhead->control & SE_OWNER_DEFAULTED;
control = le16_or(control, le16_and(newhead->control, SE_OWNER_DEFAULTED));
else
control |= oldhead->control & SE_OWNER_DEFAULTED;
control = le16_or(control, le16_and(oldhead->control, SE_OWNER_DEFAULTED));
/*
* 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];
control |= newhead->control
& SE_GROUP_DEFAULTED;
control = le16_or(control, le16_and(newhead->control,
SE_GROUP_DEFAULTED));
} else {
offgroup = le32_to_cpu(oldhead->group);
pgroup = (const SID*)&oldattr[offgroup];
control |= oldhead->control
& SE_GROUP_DEFAULTED;
control = le16_or(control, le16_and(oldhead->control,
SE_GROUP_DEFAULTED));
}
size = ntfs_sid_size(pgroup);
memcpy(&target[pos], pgroup, size);
@ -4851,9 +4851,9 @@ static BOOL mergesecurityattr(ntfs_volume *vol, const char *oldattr,
} else
targhead->group = const_cpu_to_le32(0);
if (selection & GROUP_SECURITY_INFORMATION)
control |= newhead->control & SE_GROUP_DEFAULTED;
control = le16_or(control, le16_and(newhead->control, SE_GROUP_DEFAULTED));
else
control |= oldhead->control & SE_GROUP_DEFAULTED;
control = le16_or(control, le16_and(oldhead->control, SE_GROUP_DEFAULTED));
targhead->revision = SECURITY_DESCRIPTOR_REVISION;
targhead->alignment = 0;
targhead->control = control;
@ -4901,7 +4901,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
@ -4953,13 +4953,13 @@ int ntfs_set_file_security(struct SECURITY_API *scapi,
attrsz = ntfs_attr_size(attr);
/* if selected, owner and group must be present or defaulted */
missing = ((selection & OWNER_SECURITY_INFORMATION)
&& !phead->owner
&& !(phead->control & SE_OWNER_DEFAULTED))
&& le32_cmpz(phead->owner)
&& le16_andz(phead->control, SE_OWNER_DEFAULTED))
|| ((selection & GROUP_SECURITY_INFORMATION)
&& !phead->group
&& !(phead->control & SE_GROUP_DEFAULTED));
&& le32_cmpz(phead->group)
&& le16_andz(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);
@ -5014,7 +5014,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);
@ -5061,15 +5061,15 @@ 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
*/
settable |= FILE_ATTR_COMPRESSED;
if ((ni->flags ^ cpu_to_le32(attrib))
& FILE_ATTR_COMPRESSED) {
if (ni->flags & FILE_ATTR_COMPRESSED)
settable = le32_or(settable, FILE_ATTR_COMPRESSED);
if (!le32_andz(le32_xor(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;
@ -5081,8 +5081,8 @@ BOOL ntfs_set_file_attributes(struct SECURITY_API *scapi,
}
}
if (!res) {
ni->flags = (ni->flags & ~settable)
| (cpu_to_le32(attrib) & settable);
ni->flags = le32_or(le32_and(ni->flags, le32_not(settable)),
le32_and(cpu_to_le32(attrib), settable));
NInoSetDirty(ni);
NInoFileNameSetDirty(ni);
}
@ -5106,7 +5106,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);

View File

@ -180,7 +180,7 @@ int ntfs_names_full_collate(const ntfschar *name1, const u32 name1_len,
cnt = min(name1_len, name2_len);
if (cnt > 0) {
if (ic == CASE_SENSITIVE) {
while (--cnt && (*name1 == *name2)) {
while (--cnt && le16_eq(*name1, *name2)) {
name1++;
name2++;
}
@ -475,7 +475,7 @@ static int utf16_to_utf8_size(const ntfschar *ins, const int ins_len, int outs_l
BOOL surrog;
surrog = FALSE;
for (i = 0; i < ins_len && ins[i] && count <= outs_len; i++) {
for (i = 0; i < ins_len && !le16_cmpz(ins[i]) && count <= outs_len; i++) {
unsigned short c = le16_to_cpu(ins[i]);
if (surrog) {
if ((c >= 0xdc00) && (c < 0xe000)) {
@ -586,7 +586,7 @@ static int ntfs_utf16_to_utf8(const ntfschar *ins, const int ins_len,
t = *outs;
for (i = 0; i < ins_len && ins[i]; i++) {
for (i = 0; i < ins_len && !le16_cmpz(ins[i]); i++) {
unsigned short c = le16_to_cpu(ins[i]);
/* size not double-checked */
if (halfpair) {
@ -1498,8 +1498,8 @@ BOOL ntfs_forbidden_chars(const ntfschar *name, int len, BOOL strict)
| (1L << ('?' - 0x20));
forbidden = (len == 0) ||
(strict && (name[len-1] == const_cpu_to_le16(' ') ||
name[len-1] == const_cpu_to_le16('.')));
(strict && (le16_eq(name[len-1], const_cpu_to_le16(' ')) ||
le16_eq(name[len-1], const_cpu_to_le16('.'))));
for (i=0; i<len; i++) {
ch = le16_to_cpu(name[i]);
if ((ch < 0x20)
@ -1559,7 +1559,7 @@ BOOL ntfs_forbidden_names(ntfs_volume *vol, const ntfschar *name, int len,
/* do a full check, depending on the third char */
switch (le16_to_cpu(name[2]) & ~0x20) {
case 'N' :
if (((len == 3) || (name[3] == dot))
if (((len == 3) || le16_eq(name[3], dot))
&& (!ntfs_ucsncasecmp(name, con, 3,
vol->upcase, vol->upcase_len)
|| !ntfs_ucsncasecmp(name, prn, 3,
@ -1567,13 +1567,13 @@ BOOL ntfs_forbidden_names(ntfs_volume *vol, const ntfschar *name, int len,
forbidden = TRUE;
break;
case 'X' :
if (((len == 3) || (name[3] == dot))
if (((len == 3) || le16_eq(name[3], dot))
&& !ntfs_ucsncasecmp(name, aux, 3,
vol->upcase, vol->upcase_len))
forbidden = TRUE;
break;
case 'L' :
if (((len == 3) || (name[3] == dot))
if (((len == 3) || le16_eq(name[3], dot))
&& !ntfs_ucsncasecmp(name, nul, 3,
vol->upcase, vol->upcase_len))
forbidden = TRUE;
@ -1582,7 +1582,7 @@ BOOL ntfs_forbidden_names(ntfs_volume *vol, const ntfschar *name, int len,
if ((len > 3)
&& (le16_to_cpu(name[3]) >= '1')
&& (le16_to_cpu(name[3]) <= '9')
&& ((len == 4) || (name[4] == dot))
&& ((len == 4) || le16_eq(name[4], dot))
&& !ntfs_ucsncasecmp(name, com, 3,
vol->upcase, vol->upcase_len))
forbidden = TRUE;
@ -1591,7 +1591,7 @@ BOOL ntfs_forbidden_names(ntfs_volume *vol, const ntfschar *name, int len,
if ((len > 3)
&& (le16_to_cpu(name[3]) >= '1')
&& (le16_to_cpu(name[3]) <= '9')
&& ((len == 4) || (name[4] == dot))
&& ((len == 4) || le16_eq(name[4], dot))
&& !ntfs_ucsncasecmp(name, lpt, 3,
vol->upcase, vol->upcase_len))
forbidden = TRUE;
@ -1629,7 +1629,7 @@ BOOL ntfs_collapsible_chars(ntfs_volume *vol,
if ((cs != ch)
&& ((ch >= vol->upcase_len)
|| (cs >= vol->upcase_len)
|| (vol->upcase[cs] != vol->upcase[ch])))
|| !le16_eq(vol->upcase[cs], vol->upcase[ch])))
collapsible = FALSE;
}
return (collapsible);

View File

@ -350,8 +350,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;
@ -711,8 +711,8 @@ static int ntfs_volume_check_logfile(ntfs_volume *vol)
* after such an event.
*/
if (rp
&& (rp->major_ver == const_cpu_to_le16(2))
&& (rp->minor_ver == const_cpu_to_le16(0))) {
&& sle16_eq(rp->major_ver, const_cpu_to_sle16(2))
&& sle16_eq(rp->minor_ver, const_cpu_to_sle16(0))) {
ntfs_log_error("Metadata kept in Windows cache, refused to mount.\n");
err = EPERM;
}
@ -1010,7 +1010,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_record(mrec->magic)) {
ntfs_log_error("$MFT error: Incomplete multi "
"sector transfer detected in "
@ -1024,7 +1024,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_record(mrec2->magic)) {
ntfs_log_error("$MFTMirr error: Incomplete "
"multi sector transfer "
@ -1778,7 +1778,7 @@ int ntfs_volume_write_flags(ntfs_volume *vol, const le16 flags)
goto err_out;
}
/* Set the volume flags. */
vol->flags = c->flags = flags & VOLUME_FLAGS_MASK;
vol->flags = c->flags = le16_and(flags, VOLUME_FLAGS_MASK);
/* Write them to disk. */
ntfs_inode_mark_dirty(vol->vol_ni);
if (ntfs_inode_sync(vol->vol_ni))

View File

@ -1234,18 +1234,18 @@ static int mkntfs_attr_find(const ATTR_TYPES type, const ntfschar *name,
le32_to_cpu(ctx->mrec->bytes_allocated))
break;
ctx->attr = a;
if (((type != AT_UNUSED) && (le32_to_cpu(a->type) >
if ((!le32_eq(type, AT_UNUSED) && (le32_to_cpu(a->type) >
le32_to_cpu(type))) ||
(a->type == AT_END)) {
le32_eq(a->type, AT_END)) {
errno = ENOENT;
return -1;
}
if (!a->length)
if (le32_cmpz(a->length))
break;
/* If this is an enumeration return this attribute. */
if (type == AT_UNUSED)
if (le32_eq(type, AT_UNUSED))
return 0;
if (a->type != type)
if (!le32_eq(a->type, type))
continue;
/*
* If @name is AT_UNNAMED we want an unnamed attribute.
@ -1410,7 +1410,7 @@ static int mkntfs_attr_lookup(const ATTR_TYPES type, const ntfschar *name,
base_ni = ctx->base_ntfs_ino;
else
base_ni = ctx->ntfs_ino;
if (!base_ni || !NInoAttrList(base_ni) || type == AT_ATTRIBUTE_LIST)
if (!base_ni || !NInoAttrList(base_ni) || le32_eq(type, AT_ATTRIBUTE_LIST))
return mkntfs_attr_find(type, name, name_len, ic, val, val_len,
ctx);
errno = EOPNOTSUPP;
@ -1471,19 +1471,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, le16_or(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) */
@ -1562,12 +1562,12 @@ 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, le16_and(ATTR_COMPRESSION_MASK, le16_not(ATTR_IS_COMPRESSED)))) {
ntfs_log_error("Unknown compression format. Reverting "
"to standard compression.\n");
a->flags &= ~ATTR_COMPRESSION_MASK;
a->flags |= ATTR_IS_COMPRESSED;
a->flags = le16_and(a->flags, le16_not(ATTR_COMPRESSION_MASK));
a->flags = le16_or(a->flags, ATTR_IS_COMPRESSED);
}
a->compression_unit = 4;
inited_size = val_len;
@ -1578,9 +1578,9 @@ static int insert_positioned_attr_in_mft_record(MFT_RECORD *m,
err = -EOPNOTSUPP;
} else {
a->compression_unit = 0;
if ((type == AT_DATA)
&& (m->mft_record_number
== const_cpu_to_le32(FILE_LogFile)))
if (le32_eq(type, AT_DATA)
&& le32_eq(m->mft_record_number,
const_cpu_to_le32(FILE_LogFile)))
bw = ntfs_rlwrite(g_vol->dev, rl, val, val_len,
&inited_size, WRITE_LOGFILE);
else
@ -1662,14 +1662,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, le16_or(ATTR_IS_ENCRYPTED, ATTR_IS_SPARSE))) {
ntfs_log_error("Encrypted/sparse attributes not supported.\n");
err = -EOPNOTSUPP;
goto err_out;
@ -1685,7 +1685,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) */
@ -1759,12 +1759,12 @@ 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, le16_and(ATTR_COMPRESSION_MASK, le16_not(ATTR_IS_COMPRESSED)))) {
ntfs_log_error("Unknown compression format. Reverting "
"to standard compression.\n");
a->flags &= ~ATTR_COMPRESSION_MASK;
a->flags |= ATTR_IS_COMPRESSED;
a->flags = le16_and(a->flags, le16_not(ATTR_COMPRESSION_MASK));
a->flags = le16_or(a->flags, ATTR_IS_COMPRESSED);
}
a->compression_unit = 4;
/* FIXME: Set the compressed size. */
@ -1885,7 +1885,7 @@ static int insert_resident_attr_in_mft_record(MFT_RECORD *m,
a->length = cpu_to_le32(asize);
a->non_resident = 0;
a->name_length = name_len;
if (type == AT_OBJECT_ID)
if (le32_eq(type, AT_OBJECT_ID))
a->name_offset = const_cpu_to_le16(0);
else
a->name_offset = const_cpu_to_le16(24);
@ -1931,7 +1931,7 @@ static int add_attr_std_info(MFT_RECORD *m, const FILE_ATTR_FLAGS flags,
si.version_number = const_cpu_to_le32(0);
si.class_id = const_cpu_to_le32(0);
si.security_id = security_id;
if (si.security_id != const_cpu_to_le32(0))
if (!le32_eq(si.security_id, const_cpu_to_le32(0)))
sd_size = 72;
/* FIXME: $Quota support... */
si.owner_id = const_cpu_to_le32(0);
@ -2249,7 +2249,7 @@ static int add_attr_vol_info(MFT_RECORD *m, const VOLUME_FLAGS flags,
memset(&vi, 0, sizeof(vi));
vi.major_ver = major_ver;
vi.minor_ver = minor_ver;
vi.flags = flags & VOLUME_FLAGS_MASK;
vi.flags = le16_and(flags, VOLUME_FLAGS_MASK);
err = insert_resident_attr_in_mft_record(m, AT_VOLUME_INFORMATION, NULL,
0, CASE_SENSITIVE, const_cpu_to_le16(0),
0, (u8*)&vi, sizeof(vi));
@ -2277,10 +2277,10 @@ static int add_attr_index_root(MFT_RECORD *m, const char *name,
r = ntfs_malloc(val_len);
if (!r)
return -errno;
r->type = (indexed_attr_type == AT_FILE_NAME)
r->type = le32_eq(indexed_attr_type, AT_FILE_NAME)
? AT_FILE_NAME : const_cpu_to_le32(0);
if (indexed_attr_type == AT_FILE_NAME &&
collation_rule != COLLATION_FILE_NAME) {
if (le32_eq(indexed_attr_type, AT_FILE_NAME) &&
!le32_eq(collation_rule, COLLATION_FILE_NAME)) {
free(r);
ntfs_log_error("add_attr_index_root: indexed attribute is $FILE_NAME "
"but collation rule is not COLLATION_FILE_NAME.\n");
@ -2460,7 +2460,7 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name,
goto err_out;
}
a = ctx->attr;
if (a->non_resident || a->flags) {
if (a->non_resident || !le16_cmpz(a->flags)) {
err = -EINVAL;
goto err_out;
}
@ -2507,7 +2507,7 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name,
ia_val->index.allocated_size = cpu_to_le32(index_block_size -
(sizeof(INDEX_ALLOCATION) - sizeof(INDEX_HEADER)));
/* Find the last entry in the index root and save it in re. */
while ((char*)re < re_end && !(re->ie_flags & INDEX_ENTRY_END)) {
while ((char*)re < re_end && le16_andz(re->ie_flags, INDEX_ENTRY_END)) {
/* Next entry in index root. */
re = (INDEX_ENTRY*)((char*)re + le16_to_cpu(re->length));
}
@ -2525,7 +2525,7 @@ static int upgrade_to_large_index(MFT_RECORD *m, const char *name,
}
/* Now fixup empty index root with pointer to index allocation VCN 0. */
r->index.ih_flags = LARGE_INDEX;
re->ie_flags |= INDEX_ENTRY_NODE;
re->ie_flags = le16_or(re->ie_flags, INDEX_ENTRY_NODE);
if (le16_to_cpu(re->length) < sizeof(INDEX_ENTRY_HEADER) + sizeof(VCN))
re->length = cpu_to_le16(le16_to_cpu(re->length) + sizeof(VCN));
r->index.index_length = cpu_to_le32(le32_to_cpu(r->index.entries_offset)
@ -2631,7 +2631,7 @@ static int ntfs_index_keys_compare(u8 *key1, u8 *key2, int key1_length,
u32 u1, u2;
int i;
if (collation_rule == COLLATION_NTOFS_ULONG) {
if (le32_eq(collation_rule, COLLATION_NTOFS_ULONG)) {
/* i.e. $SII or $QUOTA-$Q */
u1 = le32_to_cpup((const le32*)key1);
u2 = le32_to_cpup((const le32*)key2);
@ -2642,7 +2642,7 @@ static int ntfs_index_keys_compare(u8 *key1, u8 *key2, int key1_length,
/* u1 == u2 */
return 0;
}
if (collation_rule == COLLATION_NTOFS_ULONGS) {
if (le32_eq(collation_rule, COLLATION_NTOFS_ULONGS)) {
/* i.e $OBJID-$O */
i = 0;
while (i < min(key1_length, key2_length)) {
@ -2661,7 +2661,7 @@ static int ntfs_index_keys_compare(u8 *key1, u8 *key2, int key1_length,
return 1;
return 0;
}
if (collation_rule == COLLATION_NTOFS_SECURITY_HASH) {
if (le32_eq(collation_rule, COLLATION_NTOFS_SECURITY_HASH)) {
/* i.e. $SDH */
u1 = le32_to_cpu(((SDH_INDEX_KEY*)key1)->hash);
u2 = le32_to_cpu(((SDH_INDEX_KEY*)key2)->hash);
@ -2678,7 +2678,7 @@ static int ntfs_index_keys_compare(u8 *key1, u8 *key2, int key1_length,
return 1;
return 0;
}
if (collation_rule == COLLATION_NTOFS_SID) {
if (le32_eq(collation_rule, COLLATION_NTOFS_SID)) {
/* i.e. $QUOTA-O */
i = memcmp(key1, key2, min(key1_length, key2_length));
if (!i) {
@ -2741,9 +2741,9 @@ static int insert_index_entry_in_res_dir_index(INDEX_ENTRY *idx, u32 idx_size,
* Loop until we exceed valid memory (corruption case) or until we
* reach the last entry.
*/
if (type == AT_FILE_NAME) {
if (le32_eq(type, AT_FILE_NAME)) {
while (((u8*)idx_entry < (u8*)idx_end) &&
!(idx_entry->ie_flags & INDEX_ENTRY_END)) {
le16_andz(idx_entry->ie_flags, INDEX_ENTRY_END)) {
/*
i = ntfs_file_values_compare(&idx->key.file_name,
&idx_entry->key.file_name, 1,
@ -2786,9 +2786,9 @@ do_next:
idx_entry = (INDEX_ENTRY*)((u8*)idx_entry +
le16_to_cpu(idx_entry->length));
}
} else if (type == AT_UNUSED) { /* case view */
} else if (le32_eq(type, AT_UNUSED)) { /* case view */
while (((u8*)idx_entry < (u8*)idx_end) &&
!(idx_entry->ie_flags & INDEX_ENTRY_END)) {
le16_andz(idx_entry->ie_flags, INDEX_ENTRY_END)) {
i = ntfs_index_keys_compare((u8*)idx + 0x10,
(u8*)idx_entry + 0x10,
le16_to_cpu(idx->key_length),
@ -2850,7 +2850,7 @@ static int initialize_secure(char *sds, u32 sds_size, MFT_RECORD *m)
err = 0;
while ((char*)sds_header < (char*)sds + sds_size) {
if (!sds_header->length)
if (le32_cmpz(sds_header->length))
break;
/* SDH index entry */
idx_entry_sdh->data_offset = const_cpu_to_le16(0x18);
@ -3037,7 +3037,7 @@ static int insert_file_link_in_dir_index(INDEX_BLOCK *idx, leMFT_REF file_ref,
* Loop until we exceed valid memory (corruption case) or until we
* reach the last entry.
*/
while ((char*)ie < index_end && !(ie->ie_flags & INDEX_ENTRY_END)) {
while ((char*)ie < index_end && le16_andz(ie->ie_flags, INDEX_ENTRY_END)) {
#if 0
#ifdef DEBUG
ntfs_log_debug("file_name_attr1->file_name_length = %i\n",
@ -3115,7 +3115,7 @@ static int insert_file_link_in_dir_index(INDEX_BLOCK *idx, leMFT_REF file_ref,
do_next:
#ifdef DEBUG
/* Next entry. */
if (!ie->length) {
if (le16_cmpz(ie->length)) {
ntfs_log_debug("BUG: ie->length is zero, breaking out "
"of loop.\n");
break;
@ -4297,7 +4297,7 @@ static BOOL create_file_volume(MFT_RECORD *m, leMFT_REF root_ref,
m = (MFT_RECORD*)(g_buf + 3 * g_vol->mft_record_size);
err = create_hardlink(g_index_block, root_ref, m,
MK_LE_MREF(FILE_Volume, FILE_Volume), 0LL, 0LL,
FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM, 0, 0,
le32_or(FILE_ATTR_HIDDEN, FILE_ATTR_SYSTEM), 0, 0,
"$Volume", FILE_NAME_WIN32_AND_DOS);
if (!err) {
init_system_file_sd(FILE_Volume, &sd, &i);
@ -4310,7 +4310,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");
@ -4447,16 +4447,16 @@ static BOOL mkntfs_create_root_structures(void)
m = (MFT_RECORD*)(g_buf + i * g_vol->mft_record_size);
if (i < 16 || i > 23) {
m->mft_record_number = cpu_to_le32(i);
m->flags |= MFT_RECORD_IN_USE;
m->flags = le16_or(m->flags, MFT_RECORD_IN_USE);
ntfs_bit_set(g_mft_bitmap, 0LL + i, 1);
}
file_attrs = FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM;
file_attrs = le32_or(FILE_ATTR_HIDDEN, FILE_ATTR_SYSTEM);
if (i == FILE_root) {
file_attrs |= FILE_ATTR_ARCHIVE;
file_attrs = le32_or(file_attrs, FILE_ATTR_ARCHIVE);
if (opts.disable_indexing)
file_attrs |= FILE_ATTR_NOT_CONTENT_INDEXED;
file_attrs = le32_or(file_attrs, FILE_ATTR_NOT_CONTENT_INDEXED);
if (opts.enable_compression)
file_attrs |= FILE_ATTR_COMPRESSED;
file_attrs = le32_or(file_attrs, FILE_ATTR_COMPRESSED);
}
/* setting specific security_id flag and */
/* file permissions for ntfs 3.x */
@ -4465,15 +4465,15 @@ static BOOL mkntfs_create_root_structures(void)
add_attr_std_info(m, file_attrs,
const_cpu_to_le32(0x0100));
} else if (i == 9) {
file_attrs |= FILE_ATTR_VIEW_INDEX_PRESENT;
file_attrs = le32_or(file_attrs, FILE_ATTR_VIEW_INDEX_PRESENT);
add_attr_std_info(m, file_attrs,
const_cpu_to_le32(0x0101));
} else if (i == 11) {
add_attr_std_info(m, file_attrs,
const_cpu_to_le32(0x0101));
} else if (i == 24 || i == 25 || i == 26) {
file_attrs |= FILE_ATTR_ARCHIVE;
file_attrs |= FILE_ATTR_VIEW_INDEX_PRESENT;
file_attrs = le32_or(file_attrs, FILE_ATTR_ARCHIVE);
file_attrs = le32_or(file_attrs, FILE_ATTR_VIEW_INDEX_PRESENT);
add_attr_std_info(m, file_attrs,
const_cpu_to_le32(0x0101));
} else {
@ -4486,11 +4486,11 @@ static BOOL mkntfs_create_root_structures(void)
extend_ref = MK_LE_MREF(11,11);
ntfs_log_verbose("Creating root directory (mft record 5)\n");
m = (MFT_RECORD*)(g_buf + 5 * g_vol->mft_record_size);
m->flags |= MFT_RECORD_IS_DIRECTORY;
m->flags = le16_or(m->flags, MFT_RECORD_IS_DIRECTORY);
m->link_count = cpu_to_le16(le16_to_cpu(m->link_count) + 1);
err = add_attr_file_name(m, root_ref, 0LL, 0LL,
FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM |
FILE_ATTR_I30_INDEX_PRESENT, 0, 0, ".",
le32_or(FILE_ATTR_HIDDEN, le32_or(FILE_ATTR_SYSTEM,
FILE_ATTR_I30_INDEX_PRESENT)), 0, 0, ".",
FILE_NAME_WIN32_AND_DOS);
if (!err) {
init_root_sd(&sd, &i);
@ -4544,8 +4544,8 @@ static BOOL mkntfs_create_root_structures(void)
MK_LE_MREF(FILE_MFT, 1),
((g_mft_size - 1)
| (g_vol->cluster_size - 1)) + 1,
g_mft_size, FILE_ATTR_HIDDEN |
FILE_ATTR_SYSTEM, 0, 0, "$MFT",
g_mft_size, le32_or(FILE_ATTR_HIDDEN,
FILE_ATTR_SYSTEM), 0, 0, "$MFT",
FILE_NAME_WIN32_AND_DOS);
/* mft_bitmap is not modified in mkntfs; no need to sync it later. */
if (!err)
@ -4566,7 +4566,7 @@ static BOOL mkntfs_create_root_structures(void)
MK_LE_MREF(FILE_MFTMirr, FILE_MFTMirr),
g_rl_mftmirr[0].length * g_vol->cluster_size,
g_rl_mftmirr[0].length * g_vol->cluster_size,
FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM, 0, 0,
le32_or(FILE_ATTR_HIDDEN, FILE_ATTR_SYSTEM), 0, 0,
"$MFTMirr", FILE_NAME_WIN32_AND_DOS);
if (err < 0) {
ntfs_log_error("Couldn't create $MFTMirr: %s\n",
@ -4582,7 +4582,7 @@ static BOOL mkntfs_create_root_structures(void)
err = create_hardlink(g_index_block, root_ref, m,
MK_LE_MREF(FILE_LogFile, FILE_LogFile),
g_logfile_size, g_logfile_size,
FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM, 0, 0,
le32_or(FILE_ATTR_HIDDEN, FILE_ATTR_SYSTEM), 0, 0,
"$LogFile", FILE_NAME_WIN32_AND_DOS);
if (err < 0) {
ntfs_log_error("Couldn't create $LogFile: %s\n",
@ -4598,7 +4598,7 @@ static BOOL mkntfs_create_root_structures(void)
MK_LE_MREF(FILE_AttrDef, FILE_AttrDef),
(g_vol->attrdef_len + g_vol->cluster_size - 1) &
~(g_vol->cluster_size - 1), g_vol->attrdef_len,
FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM, 0, 0,
le32_or(FILE_ATTR_HIDDEN, FILE_ATTR_SYSTEM), 0, 0,
"$AttrDef", FILE_NAME_WIN32_AND_DOS);
if (!err) {
init_system_file_sd(FILE_AttrDef, &sd, &i);
@ -4626,7 +4626,7 @@ static BOOL mkntfs_create_root_structures(void)
(g_lcn_bitmap_byte_size + g_vol->cluster_size -
1) & ~(g_vol->cluster_size - 1),
g_lcn_bitmap_byte_size,
FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM, 0, 0,
le32_or(FILE_ATTR_HIDDEN, FILE_ATTR_SYSTEM), 0, 0,
"$Bitmap", FILE_NAME_WIN32_AND_DOS);
if (err < 0) {
ntfs_log_error("Couldn't create $Bitmap: %s\n", strerror(-err));
@ -4720,7 +4720,7 @@ static BOOL mkntfs_create_root_structures(void)
MK_LE_MREF(FILE_Boot, FILE_Boot),
(8192 + g_vol->cluster_size - 1) &
~(g_vol->cluster_size - 1), 8192,
FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM, 0, 0,
le32_or(FILE_ATTR_HIDDEN, FILE_ATTR_SYSTEM), 0, 0,
"$Boot", FILE_NAME_WIN32_AND_DOS);
if (!err) {
init_system_file_sd(FILE_Boot, &sd, &i);
@ -4737,7 +4737,7 @@ static BOOL mkntfs_create_root_structures(void)
* odd and we failed to set the device block size to the sector
* size, hence we schedule chkdsk to create it.
*/
volume_flags |= VOLUME_IS_DIRTY;
volume_flags = le16_or(volume_flags, VOLUME_IS_DIRTY);
}
free(bs);
/*
@ -4770,7 +4770,7 @@ static BOOL mkntfs_create_root_structures(void)
if (!err) {
err = create_hardlink(g_index_block, root_ref, m,
MK_LE_MREF(FILE_BadClus, FILE_BadClus),
0LL, 0LL, FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM,
0LL, 0LL, le32_or(FILE_ATTR_HIDDEN, FILE_ATTR_SYSTEM),
0, 0, "$BadClus", FILE_NAME_WIN32_AND_DOS);
}
if (err < 0) {
@ -4781,12 +4781,12 @@ static BOOL mkntfs_create_root_structures(void)
/* create $Secure (NTFS 3.0+) */
ntfs_log_verbose("Creating $Secure (mft record 9)\n");
m = (MFT_RECORD*)(g_buf + 9 * g_vol->mft_record_size);
m->flags |= MFT_RECORD_IS_VIEW_INDEX;
m->flags = le16_or(m->flags, MFT_RECORD_IS_VIEW_INDEX);
if (!err)
err = create_hardlink(g_index_block, root_ref, m,
MK_LE_MREF(9, 9), 0LL, 0LL,
FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM |
FILE_ATTR_VIEW_INDEX_PRESENT, 0, 0,
le32_or(FILE_ATTR_HIDDEN, le32_or(FILE_ATTR_SYSTEM,
FILE_ATTR_VIEW_INDEX_PRESENT)), 0, 0,
"$Secure", FILE_NAME_WIN32_AND_DOS);
buf_sds = NULL;
buf_sds_first_size = 0;
@ -4841,7 +4841,7 @@ static BOOL mkntfs_create_root_structures(void)
g_vol->cluster_size - 1) &
~(g_vol->cluster_size - 1),
g_vol->upcase_len << 1,
FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM, 0, 0,
le32_or(FILE_ATTR_HIDDEN, FILE_ATTR_SYSTEM), 0, 0,
"$UpCase", FILE_NAME_WIN32_AND_DOS);
if (err < 0) {
ntfs_log_error("Couldn't create $UpCase: %s\n", strerror(-err));
@ -4853,12 +4853,12 @@ static BOOL mkntfs_create_root_structures(void)
* volume as corrupt. (ERSO)
*/
m = (MFT_RECORD*)(g_buf + 11 * g_vol->mft_record_size);
m->flags |= MFT_RECORD_IS_DIRECTORY;
m->flags = le16_or(m->flags, MFT_RECORD_IS_DIRECTORY);
if (!err)
err = create_hardlink(g_index_block, root_ref, m,
MK_LE_MREF(11, 11), 0LL, 0LL,
FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM |
FILE_ATTR_I30_INDEX_PRESENT, 0, 0,
le32_or(FILE_ATTR_HIDDEN, le32_or(FILE_ATTR_SYSTEM,
FILE_ATTR_I30_INDEX_PRESENT)), 0, 0,
"$Extend", FILE_NAME_WIN32_AND_DOS);
/* FIXME: This should be IGNORE_CASE */
if (!err)
@ -4888,12 +4888,12 @@ static BOOL mkntfs_create_root_structures(void)
}
/* create systemfiles for ntfs volumes (3.1) */
/* starting with file 24 (ignoring file 16-23) */
extend_flags = FILE_ATTR_HIDDEN | FILE_ATTR_SYSTEM |
FILE_ATTR_ARCHIVE | FILE_ATTR_VIEW_INDEX_PRESENT;
extend_flags = le32_or(FILE_ATTR_HIDDEN, le32_or(FILE_ATTR_SYSTEM,
le32_or(FILE_ATTR_ARCHIVE, FILE_ATTR_VIEW_INDEX_PRESENT)));
ntfs_log_verbose("Creating $Quota (mft record 24)\n");
m = (MFT_RECORD*)(g_buf + 24 * g_vol->mft_record_size);
m->flags |= MFT_RECORD_IS_4;
m->flags |= MFT_RECORD_IS_VIEW_INDEX;
m->flags = le16_or(m->flags, MFT_RECORD_IS_4);
m->flags = le16_or(m->flags, MFT_RECORD_IS_VIEW_INDEX);
if (!err)
err = create_hardlink_res((MFT_RECORD*)(g_buf +
11 * g_vol->mft_record_size), extend_ref, m,
@ -4915,8 +4915,8 @@ static BOOL mkntfs_create_root_structures(void)
}
ntfs_log_verbose("Creating $ObjId (mft record 25)\n");
m = (MFT_RECORD*)(g_buf + 25 * g_vol->mft_record_size);
m->flags |= MFT_RECORD_IS_4;
m->flags |= MFT_RECORD_IS_VIEW_INDEX;
m->flags = le16_or(m->flags, MFT_RECORD_IS_4);
m->flags = le16_or(m->flags, MFT_RECORD_IS_VIEW_INDEX);
if (!err)
err = create_hardlink_res((MFT_RECORD*)(g_buf +
11 * g_vol->mft_record_size), extend_ref,
@ -4939,8 +4939,8 @@ static BOOL mkntfs_create_root_structures(void)
}
ntfs_log_verbose("Creating $Reparse (mft record 26)\n");
m = (MFT_RECORD*)(g_buf + 26 * g_vol->mft_record_size);
m->flags |= MFT_RECORD_IS_4;
m->flags |= MFT_RECORD_IS_VIEW_INDEX;
m->flags = le16_or(m->flags, MFT_RECORD_IS_4);
m->flags = le16_or(m->flags, MFT_RECORD_IS_VIEW_INDEX);
if (!err)
err = create_hardlink_res((MFT_RECORD*)(g_buf +
11 * g_vol->mft_record_size),

View File

@ -201,7 +201,7 @@ static int parse_options(int argc, char **argv)
}
break;
case 'a':
if (opts.attr != const_cpu_to_le32(-1)) {
if (!le32_eq(opts.attr, const_cpu_to_le32(-1))) {
ntfs_log_error("You must specify exactly one "
"attribute.\n");
} else if (parse_attribute(optarg, &attr) > 0) {
@ -353,9 +353,9 @@ static int cat(ntfs_volume *vol, ntfs_inode *inode, ATTR_TYPES type,
return 1;
}
if ((inode->mft_no < 2) && (attr->type == AT_DATA))
if ((inode->mft_no < 2) && le32_eq(attr->type, AT_DATA))
block_size = vol->mft_record_size;
else if (attr->type == AT_INDEX_ALLOCATION)
else if (le32_eq(attr->type, AT_INDEX_ALLOCATION))
block_size = index_get_size(inode);
else
block_size = 0;
@ -446,7 +446,7 @@ int main(int argc, char *argv[])
}
attr = AT_DATA;
if (opts.attr != const_cpu_to_le32(-1))
if (!le32_eq(opts.attr, const_cpu_to_le32(-1)))
attr = opts.attr;
result = cat(vol, inode, attr, opts.attr_name, opts.attr_name_len);

View File

@ -209,7 +209,7 @@ static BOOL verify_boot_sector(struct ntfs_device *dev, ntfs_volume *rawvol)
(buf[2]!=0x90)) {
check_failed("Boot sector: Bad jump.\n");
}
if (ntfs_boot->oem_id != magicNTFS) {
if (!le64_eq(ntfs_boot->oem_id, magicNTFS)) {
check_failed("Boot sector: Bad NTFS magic.\n");
}
bytes_per_sector = le16_to_cpu(ntfs_boot->bpb.bytes_per_sector);
@ -281,7 +281,7 @@ static runlist *load_runlist(ntfs_volume *rawvol, s64 offset_to_file_record, ATT
//printf("Attr type: 0x%x.\n", attr_rec->type);
// Check attribute record. (Only what is in the buffer)
if (attr_rec->type==AT_END) {
if (le32_eq(attr_rec->type, AT_END)) {
check_failed("Attribute 0x%x not found in file record at offset %lld (0x%llx).\n", (int)le32_to_cpu(attr_rec->type),
(long long)offset_to_file_record,
(long long)offset_to_file_record);
@ -307,7 +307,7 @@ static runlist *load_runlist(ntfs_volume *rawvol, s64 offset_to_file_record, ATT
}
// todo: what ATTRIBUTE_LIST (0x20)?
if (attr_rec->type==attr_type) {
if (le32_eq(attr_rec->type, attr_type)) {
// Eurika!
// ntfs_mapping_pairs_decompress only use two values from vol. Just fake it.
@ -449,7 +449,7 @@ static ATTR_REC *check_attr_record(ATTR_REC *attr_rec, MFT_RECORD *mft_rec,
// If this is the first attribute:
// todo: instance number must be smaller than next_instance.
if ((u8*)attr_rec == ((u8*)mft_rec) + attrs_offset) {
if (!mft_rec->base_mft_record)
if (le64_cmpz(mft_rec->base_mft_record))
assert_u32_equal(attr_type, 0x10,
"First attribute type");
// The following not always holds.
@ -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, le16_not(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));
@ -629,7 +629,7 @@ static BOOL check_file_record(u8 *buffer, u16 buflen)
while ((u8*)attr_rec<=buffer+buflen-4) {
// Check attribute record. (Only what is in the buffer)
if (attr_rec->type==AT_END) {
if (le32_eq(attr_rec->type, AT_END)) {
// Done.
return 0;
}
@ -791,12 +791,12 @@ static int reset_dirty(ntfs_volume *vol)
{
le16 flags;
if (!(vol->flags | VOLUME_IS_DIRTY))
if (le16_cmpz(le16_or(vol->flags, VOLUME_IS_DIRTY)))
return 0;
ntfs_log_verbose("Resetting dirty flag.\n");
flags = vol->flags & ~VOLUME_IS_DIRTY;
flags = le16_and(vol->flags, le16_not(VOLUME_IS_DIRTY));
if (ntfs_volume_write_flags(vol, flags)) {
ntfs_log_error("Error setting volume flags.\n");
@ -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);

View File

@ -637,13 +637,13 @@ static s64 is_critical_metadata(ntfs_walk_clusters_ctx *image, runlist *rl)
if (inode <= LAST_METADATA_INODE) {
/* Don't save bad sectors (both $Bad and unnamed are ignored */
if (inode == FILE_BadClus && image->ctx->attr->type == AT_DATA)
if (inode == FILE_BadClus && le32_eq(image->ctx->attr->type, AT_DATA))
return 0;
if ((inode != FILE_LogFile) || opt.full_logfile)
return rl->length;
if (image->ctx->attr->type == AT_DATA) {
if (le32_eq(image->ctx->attr->type, AT_DATA)) {
/* Save at least the first 16 KiB of FILE_LogFile */
s64 s = (s64)16384 - rl->vcn * vol->cluster_size;
@ -657,7 +657,7 @@ static s64 is_critical_metadata(ntfs_walk_clusters_ctx *image, runlist *rl)
}
}
if (image->ctx->attr->type != AT_DATA)
if (!le32_eq(image->ctx->attr->type, AT_DATA))
return rl->length;
return 0;
@ -831,8 +831,8 @@ static void copy_cluster(int rescue, u64 rescue_lcn, u64 lcn)
else {
mask = const_cpu_to_le64(~0x0ffffffffULL);
bs->volume_serial_number
= (volume_serial_number & mask)
| (bs->volume_serial_number & ~mask);
= le64_or(le64_and(volume_serial_number, mask),
le64_and(bs->volume_serial_number, le64_not(mask)));
}
/* Show the new full serial after merging */
if (!lcn)
@ -1102,7 +1102,7 @@ static void wipe_index_entry_timestams(INDEX_ENTRY *e)
sle64 timestamp = timespec2ntfs(zero_time);
/* FIXME: can fall into infinite loop if corrupted */
while (!(e->ie_flags & INDEX_ENTRY_END)) {
while (le16_andz(e->ie_flags, INDEX_ENTRY_END)) {
e->key.file_name.creation_time = timestamp;
e->key.file_name.last_data_change_time = timestamp;
@ -1133,7 +1133,7 @@ static void wipe_index_allocation_timestamps(ntfs_inode *ni, ATTR_RECORD *attr)
return;
}
if (indexr->type != AT_FILE_NAME)
if (!le32_eq(indexr->type, AT_FILE_NAME))
goto out_indexr;
name = (ntfschar *)((u8 *)attr + le16_to_cpu(attr->name_offset));
@ -1218,9 +1218,9 @@ static void wipe_index_root_timestamps(ATTR_RECORD *attr, sle64 timestamp)
entry = (INDEX_ENTRY *)((u8 *)iroot +
le32_to_cpu(iroot->index.entries_offset) + 0x10);
while (!(entry->ie_flags & INDEX_ENTRY_END)) {
while (le16_andz(entry->ie_flags, INDEX_ENTRY_END)) {
if (iroot->type == AT_FILE_NAME) {
if (le32_eq(iroot->type, AT_FILE_NAME)) {
entry->key.file_name.creation_time = timestamp;
entry->key.file_name.last_access_time = timestamp;
@ -1274,13 +1274,13 @@ static void wipe_timestamps(ntfs_walk_clusters_ctx *image)
ATTR_RECORD *a = image->ctx->attr;
sle64 timestamp = timespec2ntfs(zero_time);
if (a->type == AT_FILE_NAME)
if (le32_eq(a->type, AT_FILE_NAME))
WIPE_TIMESTAMPS(FILE_NAME_ATTR, a, timestamp);
else if (a->type == AT_STANDARD_INFORMATION)
else if (le32_eq(a->type, AT_STANDARD_INFORMATION))
WIPE_TIMESTAMPS(STANDARD_INFORMATION, a, timestamp);
else if (a->type == AT_INDEX_ROOT)
else if (le32_eq(a->type, AT_INDEX_ROOT))
wipe_index_root_timestamps(a, timestamp);
}
@ -1297,7 +1297,7 @@ static void wipe_resident_data(ntfs_walk_clusters_ctx *image)
if (image->ni->mft_no <= LAST_METADATA_INODE)
return;
if (a->type != AT_DATA)
if (!le32_eq(a->type, AT_DATA))
return;
for (i = 0; i < le32_to_cpu(a->value_length); i++) {
@ -1401,7 +1401,7 @@ static void wipe_mft(char *mrec, u32 mrecsz, u64 mft_no)
image.ni = &ni;
ntfs_mst_post_read_fixup_warn((NTFS_RECORD*)mrec,mrecsz,FALSE);
wipe_unused_mft_data(&ni);
if (!(((MFT_RECORD*)mrec)->flags & MFT_RECORD_IN_USE)) {
if (le16_andz(((MFT_RECORD*)mrec)->flags, MFT_RECORD_IN_USE)) {
wipe_unused_mft(&ni);
} else {
/* ctx with no ntfs_inode prevents from searching external attrs */
@ -1410,7 +1410,7 @@ static void wipe_mft(char *mrec, u32 mrecsz, u64 mft_no)
while (!ntfs_attr_lookup(AT_UNUSED, NULL, 0, CASE_SENSITIVE, 0,
NULL, 0, ctx)) {
if (ctx->attr->type == AT_END)
if (le32_eq(ctx->attr->type, AT_END))
break;
image.ctx = ctx;
@ -1447,7 +1447,7 @@ static void wipe_indx(char *mrec, u32 mrecsz)
* The index bitmap is not checked, obsoleted records are
* wiped if they pass the safety checks
*/
if ((indexa->magic == magic_INDX)
if (le32_eq(indexa->magic, magic_INDX)
&& (le32_to_cpu(indexa->index.entries_offset) >= sizeof(INDEX_HEADER))
&& (le32_to_cpu(indexa->index.allocated_size) <= mrecsz)) {
entry = (INDEX_ENTRY *)((u8 *)mrec + le32_to_cpu(
@ -1704,7 +1704,7 @@ static void walk_runs(struct ntfs_walk_cluster *walk)
if (wipe
&& !opt.preserve_timestamps
&& walk->image->ctx->attr->type == AT_INDEX_ALLOCATION)
&& le32_eq(walk->image->ctx->attr->type, AT_INDEX_ALLOCATION))
wipe_index_allocation_timestamps(walk->image->ni, a);
if (!(rl = ntfs_mapping_pairs_decompress(vol, a, NULL)))
@ -1713,8 +1713,8 @@ static void walk_runs(struct ntfs_walk_cluster *walk)
/* special wipings for MFT records and directory indexes */
mft_data = ((walk->image->ni->mft_no == FILE_MFT)
|| (walk->image->ni->mft_no == FILE_MFTMirr))
&& (a->type == AT_DATA);
index_i30 = (walk->image->ctx->attr->type == AT_INDEX_ALLOCATION)
&& le32_eq(a->type, AT_DATA);
index_i30 = le32_eq(walk->image->ctx->attr->type, AT_INDEX_ALLOCATION)
&& (a->name_length == 4)
&& !memcmp((char*)a + le16_to_cpu(a->name_offset),
NTFS_INDEX_I30,8);
@ -1761,14 +1761,14 @@ static void walk_runs(struct ntfs_walk_cluster *walk)
*/
if (!wipe && opt.metadata_image) {
if ((walk->image->ni->mft_no == FILE_LogFile)
&& (walk->image->ctx->attr->type == AT_DATA)) {
&& le32_eq(walk->image->ctx->attr->type, AT_DATA)) {
/* 16 KiB of FILE_LogFile */
walk->image->inuse
+= is_critical_metadata(walk->image,rl);
} else {
if ((walk->image->ni->mft_no
<= LAST_METADATA_INODE)
|| (walk->image->ctx->attr->type != AT_DATA))
|| !le32_eq(walk->image->ctx->attr->type, AT_DATA))
walk->image->inuse += lcn_length;
}
}
@ -1780,7 +1780,7 @@ static void walk_runs(struct ntfs_walk_cluster *walk)
* because its logical blocks may be larger than
* a cluster and split over two extents.
*/
if (mft_data && !a->lowest_vcn) {
if (mft_data && sle64_cmpz(a->lowest_vcn)) {
na = ntfs_attr_open(walk->image->ni,
AT_DATA, NULL, 0);
if (na) {
@ -1796,7 +1796,7 @@ static void walk_runs(struct ntfs_walk_cluster *walk)
perr_exit("Failed to open data of inode %lld",
(long long)walk->image->ni->mft_no);
}
if (index_i30 && !a->lowest_vcn) {
if (index_i30 && sle64_cmpz(a->lowest_vcn)) {
na = ntfs_attr_open(walk->image->ni,
AT_INDEX_ALLOCATION, NTFS_INDEX_I30, 4);
if (na) {
@ -1816,7 +1816,7 @@ static void walk_runs(struct ntfs_walk_cluster *walk)
if (opt.metadata
&& (opt.metadata_image || !wipe)
&& (walk->image->ni->mft_no == FILE_LogFile)
&& (walk->image->ctx->attr->type == AT_DATA))
&& le32_eq(walk->image->ctx->attr->type, AT_DATA))
clone_logfile_parts(walk->image, rl);
free(rl);
@ -1831,7 +1831,7 @@ static void walk_attributes(struct ntfs_walk_cluster *walk)
perr_exit("ntfs_get_attr_search_ctx");
while (!ntfs_attrs_walk(ctx)) {
if (ctx->attr->type == AT_END)
if (le32_eq(ctx->attr->type, AT_END))
break;
walk->image->ctx = ctx;
@ -1996,7 +1996,7 @@ static int walk_clusters(ntfs_volume *volume, struct ntfs_walk_cluster *walk)
continue;
}
deleted_inode = !(ni->mrec->flags & MFT_RECORD_IN_USE);
deleted_inode = le16_andz(ni->mrec->flags, MFT_RECORD_IN_USE);
if (deleted_inode && !opt.metadata_image) {
@ -2026,7 +2026,7 @@ static int walk_clusters(ntfs_volume *volume, struct ntfs_walk_cluster *walk)
if (wipe)
nr_used_mft_records++;
if (ni->mrec->base_mft_record)
if (!le64_cmpz(ni->mrec->base_mft_record))
goto out;
walk->image->ni = ni;
@ -2211,7 +2211,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);

View File

@ -363,7 +363,7 @@ static int inode_open(ntfs_volume *vol, MFT_REF mref, ntfs_inode **ni)
return NTFSCMP_INODE_OPEN_ERROR;
}
if ((*ni)->mrec->base_mft_record) {
if (!le64_cmpz((*ni)->mrec->base_mft_record)) {
if (inode_close(*ni) != 0)
return NTFSCMP_INODE_CLOSE_ERROR;
@ -423,7 +423,7 @@ static char *get_attr_name(u64 mft_no,
char *name = NULL;
int name_len;
if (atype == AT_END)
if (le32_eq(atype, AT_END))
return NULL;
name_len = ntfs_ucstombs(uname, uname_len, &name, 0);
@ -707,7 +707,7 @@ static void cmp_attribute(ntfs_attr_search_ctx *ctx1,
goto close_attribs;
}
if (na1->type == AT_INDEX_ALLOCATION)
if (le32_eq(na1->type, AT_INDEX_ALLOCATION))
cmp_index_allocation(na1, na2);
else
cmp_attribute_data(na1, na2);
@ -764,13 +764,13 @@ static int new_attribute(ntfs_attr_search_ctx *ctx,
ATTR_TYPES prev_atype,
char *prev_name)
{
if (!prev_atype && !prev_name)
if (le32_cmpz(prev_atype) && !prev_name)
return 1;
if (!ctx->attr->non_resident)
return 1;
if (prev_atype != ctx->attr->type)
if (!le32_eq(prev_atype, ctx->attr->type))
return 1;
if (new_name(ctx, prev_name))

View File

@ -199,7 +199,7 @@ static int parse_options(int argc, char **argv)
}
break;
case 'a':
if (opts.attribute != AT_DATA) {
if (!le32_eq(opts.attribute, AT_DATA)) {
ntfs_log_error("You can specify only one "
"attribute.\n");
err++;
@ -293,7 +293,7 @@ static int parse_options(int argc, char **argv)
err++;
}
if (opts.timestamp
&& (opts.attr_name || (opts.attribute != AT_DATA))) {
&& (opts.attr_name || !le32_eq(opts.attribute, AT_DATA))) {
ntfs_log_error("Setting --timestamp is only possible"
" with unname data attribute.\n");
err++;
@ -626,15 +626,15 @@ static int set_sizes(struct ALLOC_CONTEXT *alctx, ntfs_attr_search_ctx *ctx)
attr->data_size = cpu_to_sle64(na->data_size);
attr->initialized_size = cpu_to_sle64(na->initialized_size);
attr->allocated_size = cpu_to_sle64(na->allocated_size);
if (na->data_flags & ATTR_IS_SPARSE)
if (!le16_andz(na->data_flags, ATTR_IS_SPARSE))
attr->compressed_size = cpu_to_sle64(na->compressed_size);
/* Copy the unnamed data attribute sizes to inode */
if ((opts.attribute == AT_DATA) && !na->name_len) {
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;
ni->flags = le32_or(ni->flags, FILE_ATTR_SPARSE_FILE);
} else
ni->allocated_size = na->allocated_size;
}
@ -883,7 +883,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 */
@ -962,7 +962,7 @@ int main(int argc, char *argv[])
dir_ni = ntfs_inode_open(vol, FILE_root);
}
if (dir_ni) {
if (!(dir_ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)) {
if (le16_andz(dir_ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)) {
/* Remove the last '/' for estetic reasons. */
dirname_last_whack[0] = 0;
ntfs_log_error("The file '%s' already exists "
@ -993,7 +993,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;
@ -1143,7 +1143,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");

View File

@ -96,13 +96,23 @@ typedef enum {
* this registry key. It would be interesting to check out encryption on one
* of the "crippled" crypto Windows versions...
*/
#if ENABLE_STRICT_ENDIANNESS_CHECKING
typedef le32 NTFS_CRYPTO_ALGORITHMS;
static const le32
#else
typedef enum {
#endif
CALG_DES = const_cpu_to_le32(0x6601),
/* If not one of the below three, fall back to standard Des. */
CALG_3DES = const_cpu_to_le32(0x6603),
CALG_DESX = const_cpu_to_le32(0x6604),
CALG_AES_256 = const_cpu_to_le32(0x6610),
#if !ENABLE_STRICT_ENDIANNESS_CHECKING
} NTFS_CRYPTO_ALGORITHMS;
#else
__NTFS_CRYPTO_ALGORITHMS_end;
#endif
typedef struct {
u64 in_whitening, out_whitening;
@ -1073,27 +1083,27 @@ static ntfs_fek *ntfs_fek_import_from_raw(u8 *fek_buf, unsigned fek_size)
fek->des_gcry_cipher_hd_ptr = NULL;
*(gcry_cipher_hd_t***)(fek->key_data + ((key_size + 7) & ~7)) =
&fek->des_gcry_cipher_hd_ptr;
switch (fek->alg_id) {
case CALG_DESX:
/* switch (fek->alg_id) { */
if (le32_eq(fek->alg_id, CALG_DESX)) {
wanted_key_size = 16;
gcry_algo = GCRY_CIPHER_DES;
gcry_mode = GCRY_CIPHER_MODE_ECB;
break;
case CALG_3DES:
}
else if (le32_eq(fek->alg_id, CALG_3DES)) {
wanted_key_size = 24;
gcry_algo = GCRY_CIPHER_3DES;
gcry_mode = GCRY_CIPHER_MODE_CBC;
break;
case CALG_AES_256:
}
else if (le32_eq(fek->alg_id, CALG_AES_256)) {
wanted_key_size = 32;
gcry_algo = GCRY_CIPHER_AES256;
gcry_mode = GCRY_CIPHER_MODE_CBC;
break;
default:
}
else {
wanted_key_size = 8;
gcry_algo = GCRY_CIPHER_DES;
gcry_mode = GCRY_CIPHER_MODE_CBC;
if (fek->alg_id == CALG_DES)
if (le32_eq(fek->alg_id, CALG_DES))
ntfs_log_error("DES is not supported at present\n");
else
ntfs_log_error("Unknown crypto algorithm 0x%x\n",
@ -1122,7 +1132,7 @@ static ntfs_fek *ntfs_fek_import_from_raw(u8 *fek_buf, unsigned fek_size)
err = EINVAL;
goto out;
}
if (fek->alg_id == CALG_DESX) {
if (le32_eq(fek->alg_id, CALG_DESX)) {
err = ntfs_desx_key_expand(fek->key_data, (u32*)ctx->des_key,
&ctx->out_whitening, &ctx->in_whitening);
if (err == GPG_ERR_NO_ERROR)
@ -1180,7 +1190,7 @@ static ntfs_fek *ntfs_df_array_fek_get(EFS_DF_ARRAY_HEADER *df_array,
(u8*)df_header + le32_to_cpu(df_header->df_length))) {
df_cred = (EFS_DF_CREDENTIAL_HEADER*)((u8*)df_header +
le32_to_cpu(df_header->cred_header_offset));
if (df_cred->type != NTFS_CRED_TYPE_CERT_THUMBPRINT) {
if (!le32_eq(df_cred->type, NTFS_CRED_TYPE_CERT_THUMBPRINT)) {
ntfs_log_debug("Credential type is not certificate "
"thumbprint, skipping DF entry.\n");
continue;
@ -1248,14 +1258,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
@ -1289,7 +1299,7 @@ static int ntfs_fek_decrypt_sector(ntfs_fek *fek, u8 *data, const u64 offset)
* that gcry_cipher_setiv() wants an iv of length 8 bytes but we give
* it a length of 16 for AES256 so it does not like it.
*/
if (fek->alg_id == CALG_DESX) {
if (le32_eq(fek->alg_id, CALG_DESX)) {
int k;
fek->desx_ctx.prev_blk = 0;
@ -1303,12 +1313,12 @@ static int ntfs_fek_decrypt_sector(ntfs_fek *fek, u8 *data, const u64 offset)
return -1;
}
/* Apply the IV. */
if (fek->alg_id == CALG_AES_256) {
((le64*)data)[0] ^= cpu_to_le64(0x5816657be9161312ULL + offset);
((le64*)data)[1] ^= cpu_to_le64(0x1989adbe44918961ULL + offset);
if (le32_eq(fek->alg_id, CALG_AES_256)) {
((le64*)data)[0] = le64_xor(((le64*)data)[0], cpu_to_le64(0x5816657be9161312ULL + offset));
((le64*)data)[1] = le64_xor(((le64*)data)[1], cpu_to_le64(0x1989adbe44918961ULL + offset));
} else {
/* All other algos (Des, 3Des, DesX) use the same IV. */
((le64*)data)[0] ^= cpu_to_le64(0x169119629891ad13ULL + offset);
((le64*)data)[0] = le64_xor(((le64*)data)[0], cpu_to_le64(0x169119629891ad13ULL + offset));
}
return 512;
}
@ -1333,14 +1343,14 @@ static int ntfs_fek_encrypt_sector(ntfs_fek *fek, u8 *data, const u64 offset)
* it a length of 16 for AES256 so it does not like it.
*/
/* Apply the IV. */
if (fek->alg_id == CALG_AES_256) {
((le64*)data)[0] ^= cpu_to_le64(0x5816657be9161312ULL + offset);
((le64*)data)[1] ^= cpu_to_le64(0x1989adbe44918961ULL + offset);
if (le32_eq(fek->alg_id, CALG_AES_256)) {
((le64*)data)[0] = le64_xor(((le64*)data)[0], cpu_to_le64(0x5816657be9161312ULL + offset));
((le64*)data)[1] = le64_xor(((le64*)data)[1], cpu_to_le64(0x1989adbe44918961ULL + offset));
} else {
/* All other algos (Des, 3Des, DesX) use the same IV. */
((le64*)data)[0] ^= cpu_to_le64(0x169119629891ad13ULL + offset);
((le64*)data)[0] = le64_xor(((le64*)data)[0], cpu_to_le64(0x169119629891ad13ULL + offset));
}
if (fek->alg_id == CALG_DESX) {
if (le32_eq(fek->alg_id, CALG_DESX)) {
int k;
fek->desx_ctx.prev_blk = 0;
@ -1452,7 +1462,7 @@ static int ntfs_feed_encrypt(ntfs_inode *inode, ntfs_fek *fek)
}
total = 0;
if (!(attr->data_flags & ATTR_IS_ENCRYPTED)) {
if (le16_andz(attr->data_flags, ATTR_IS_ENCRYPTED)) {
ntfs_log_error("The data stream was not encrypted\n");
goto rejected;
}

View File

@ -511,8 +511,8 @@ rstr_pass_loc:
* The $LogFile versions specified in each of the two restart
* page headers must match.
*/
if (rstr1->major_ver != rstr->major_ver ||
rstr1->minor_ver != rstr->minor_ver)
if (!sle16_eq(rstr1->major_ver, rstr->major_ver) ||
!sle16_eq(rstr1->minor_ver, rstr->minor_ver))
log_err_exit(buf, "Second restart area specifies "
"different $LogFile version to first "
"restart area. Cannot handle this "
@ -558,16 +558,16 @@ static void dump_log_record(LOG_RECORD *lr)
ntfs_log_info("transaction_id = 0x%x\n",
(unsigned int)le32_to_cpu(lr->transaction_id));
ntfs_log_info("flags = 0x%x:", le16_to_cpu(lr->log_record_flags));
if (!lr->log_record_flags)
if (le16_cmpz(lr->log_record_flags))
ntfs_log_info(" NONE\n");
else {
int _b = 0;
if (lr->log_record_flags & LOG_RECORD_MULTI_PAGE) {
if (!le16_andz(lr->log_record_flags, LOG_RECORD_MULTI_PAGE)) {
ntfs_log_info(" LOG_RECORD_MULTI_PAGE");
_b = 1;
}
if (lr->log_record_flags & ~LOG_RECORD_MULTI_PAGE) {
if (!le16_andz(lr->log_record_flags, le16_not(LOG_RECORD_MULTI_PAGE))) {
if (_b)
ntfs_log_info(" |");
ntfs_log_info(" Unknown flags");

View File

@ -550,10 +550,10 @@ 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;
na->data_flags = le16_and(na->data_flags, le16_not(ATTR_IS_SPARSE));
if (na->compressed_size > na->allocated_size) {
ntfs_log_error("File size error : "
"apparent %lld, "
@ -714,17 +714,17 @@ static int ntfs_full_allocation(ntfs_attr *na, ntfs_attr_search_ctx *ctx,
= cpu_to_sle64(na->initialized_size);
attr->allocated_size
= cpu_to_sle64(na->allocated_size);
if (na->data_flags & ATTR_IS_SPARSE)
if (!le16_andz(na->data_flags, ATTR_IS_SPARSE))
attr->compressed_size
= cpu_to_sle64(na->compressed_size);
/* Copy the unnamed data attribute sizes to inode */
if ((attr_type == AT_DATA) && !attr_name_len) {
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;
ni->flags = le32_or(ni->flags, FILE_ATTR_SPARSE_FILE);
} else
ni->allocated_size
= na->allocated_size;
@ -759,7 +759,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";
}
@ -859,7 +859,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))

View File

@ -236,7 +236,7 @@ static int OLD_ntfs_volume_set_flags(ntfs_volume *vol, const le16 flags)
return -1;
}
/* Sanity check */
if (!(m->flags & MFT_RECORD_IN_USE)) {
if (le16_andz(m->flags, MFT_RECORD_IN_USE)) {
ntfs_log_error("$Volume has been deleted. Cannot handle this "
"yet. Run chkdsk to fix this.\n");
errno = EIO;
@ -298,14 +298,14 @@ 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... ");
/*
* Set chkdsk flag, i.e. mark the partition dirty so chkdsk will run
* and fix it for us.
*/
flags = vol->flags | VOLUME_IS_DIRTY;
flags = le16_or(vol->flags, VOLUME_IS_DIRTY);
if (!opt.no_action && OLD_ntfs_volume_set_flags(vol, flags)) {
ntfs_log_info(FAILED);
ntfs_log_error("Error setting volume flags.\n");
@ -355,7 +355,7 @@ static int clear_sparse(ntfs_attr *na, const char *name)
if (ctx) {
if (!ntfs_attr_lookup(na->type, na->name, na->name_len,
CASE_SENSITIVE, 0, NULL, 0, ctx)) {
na->data_flags &= ~ATTR_IS_SPARSE;
na->data_flags = le16_and(na->data_flags, le16_not(ATTR_IS_SPARSE));
ctx->attr->data_size = cpu_to_sle64(na->data_size);
ctx->attr->initialized_size
= cpu_to_sle64(na->initialized_size);
@ -427,7 +427,7 @@ static int clear_badclus(ntfs_volume *vol)
* formatting, so do the same.
*/
if (ok) {
ni->flags &= ~FILE_ATTR_SPARSE_FILE;
ni->flags = le32_and(ni->flags, le32_not(FILE_ATTR_SPARSE_FILE));
ok = !clear_sparse(na, "$BadClus::$Bad");
}
ntfs_attr_close(na);
@ -528,7 +528,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 "
@ -546,7 +546,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 "
@ -561,7 +561,7 @@ static int fix_mftmirr(ntfs_volume *vol)
goto error_exit;
}
/* $MFT is corrupt but $MFTMirr is ok, use $MFTMirr. */
if (!(mrec->flags & MFT_RECORD_IN_USE) &&
if (le16_andz(mrec->flags, MFT_RECORD_IN_USE) &&
!ntfs_is_mft_record(mrec->magic))
use_mirr = TRUE;
}
@ -787,16 +787,16 @@ static ATTR_RECORD *find_unnamed_attr(MFT_RECORD *mrec, ATTR_TYPES type)
space = le32_to_cpu(mrec->bytes_in_use) - offset;
a = (ATTR_RECORD*)((char*)mrec + offset);
while ((space >= (s32)offsetof(ATTR_RECORD, resident_end))
&& (a->type != AT_END)
&& !le32_eq(a->type, AT_END)
&& (le32_to_cpu(a->length) <= (u32)space)
&& !(le32_to_cpu(a->length) & 7)
&& ((a->type != type) || a->name_length)) {
&& (!le32_eq(a->type, type) || a->name_length)) {
offset += le32_to_cpu(a->length);
space -= le32_to_cpu(a->length);
a = (ATTR_RECORD*)((char*)mrec + offset);
}
if ((offset >= le32_to_cpu(mrec->bytes_in_use))
|| (a->type != type)
|| !le32_eq(a->type, type)
|| a->name_length)
a = (ATTR_RECORD*)NULL;
return (a);
@ -912,18 +912,18 @@ static BOOL attrlist_selfloc_condition(struct MFT_SELF_LOCATED *selfloc)
>> vol->cluster_size_bits;
levcn = cpu_to_sle64(vcn);
while ((length > 0)
&& al->length
&& ((al->type != AT_DATA)
|| ((leVCN)al->lowest_vcn != levcn))) {
&& !le16_cmpz(al->length)
&& (!le32_eq(al->type, AT_DATA)
|| !sle64_eq(al->lowest_vcn, levcn))) {
length -= le16_to_cpu(al->length);
al = (ATTR_LIST_ENTRY*)
((char*)al + le16_to_cpu(al->length));
}
if ((length > 0)
&& al->length
&& (al->type == AT_DATA)
&& !le16_cmpz(al->length)
&& le32_eq(al->type, AT_DATA)
&& !al->name_length
&& ((leVCN)al->lowest_vcn == levcn)
&& sle64_eq(al->lowest_vcn, levcn)
&& (MREF_LE(al->mft_reference) >= SELFLOC_LIMIT)) {
selfloc->mft_ref1
= le64_to_cpu(al->mft_reference);
@ -974,7 +974,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)sle64_to_cpu(a->lowest_vcn) == lowest_vcn)
&& (le64_to_cpu(mft1->base_mft_record)
== selfloc->mft_ref0)
@ -1027,8 +1027,8 @@ static BOOL spare_record_selfloc_condition(struct MFT_SELF_LOCATED *selfloc)
&& !ntfs_mst_post_read_fixup((NTFS_RECORD*)mft2,
vol->mft_record_size)
&& !ntfs_mft_record_check(vol, inum, mft2)) {
if (!mft2->base_mft_record
&& (mft2->flags & MFT_RECORD_IN_USE)
if (le64_cmpz(mft2->base_mft_record)
&& !le16_andz(mft2->flags, MFT_RECORD_IN_USE)
&& !find_unnamed_attr(mft2,AT_ATTRIBUTE_LIST)
&& !find_unnamed_attr(mft2,AT_FILE_NAME)) {
ok = TRUE;
@ -1670,9 +1670,9 @@ int main(int argc, char **argv)
* mounting was successful.
*/
if (opt.clear_dirty)
vol->flags &= ~VOLUME_IS_DIRTY;
vol->flags = le16_and(vol->flags, le16_not(VOLUME_IS_DIRTY));
else
vol->flags |= VOLUME_IS_DIRTY;
vol->flags = le16_or(vol->flags, VOLUME_IS_DIRTY);
if (!opt.no_action && ntfs_volume_write_flags(vol, vol->flags)) {
ntfs_log_error("Error: Failed to set volume dirty flag (%d "
"(%s))!\n", errno, strerror(errno));

View File

@ -413,51 +413,51 @@ static const char *reparse_type_name(le32 tag)
const char *name;
le32 seltag;
seltag = tag & IO_REPARSE_PLUGIN_SELECT;
switch (seltag) {
case IO_REPARSE_TAG_MOUNT_POINT :
seltag = le32_and(tag, IO_REPARSE_PLUGIN_SELECT);
do {
if (le32_eq(seltag, IO_REPARSE_TAG_MOUNT_POINT)) {
name = " (mount point)";
break;
case IO_REPARSE_TAG_SYMLINK :
} else if (le32_eq(seltag, IO_REPARSE_TAG_SYMLINK)) {
name = " (symlink)";
break;
case IO_REPARSE_TAG_WOF :
} else if (le32_eq(seltag, IO_REPARSE_TAG_WOF)) {
name = " (Wof compressed)";
break;
case IO_REPARSE_TAG_DEDUP :
} else if (le32_eq(seltag, IO_REPARSE_TAG_DEDUP)) {
name = " (deduplicated)";
break;
case IO_REPARSE_TAG_WCI :
} else if (le32_eq(seltag, IO_REPARSE_TAG_WCI)) {
name = " (Windows container)";
break;
case IO_REPARSE_TAG_CLOUD :
} else if (le32_eq(seltag, IO_REPARSE_TAG_CLOUD)) {
name = " (Cloud)";
break;
case IO_REPARSE_TAG_NFS :
} else if (le32_eq(seltag, IO_REPARSE_TAG_NFS)) {
name = " (NFS symlink)";
break;
case IO_REPARSE_TAG_LX_SYMLINK :
} else if (le32_eq(seltag, IO_REPARSE_TAG_LX_SYMLINK)) {
name = " (Linux symlink)";
break;
case IO_REPARSE_TAG_LX_FIFO :
} else if (le32_eq(seltag, IO_REPARSE_TAG_LX_FIFO)) {
name = " (Linux fifo)";
break;
case IO_REPARSE_TAG_LX_CHR :
} else if (le32_eq(seltag, IO_REPARSE_TAG_LX_CHR)) {
name = " (Linux character device)";
break;
case IO_REPARSE_TAG_LX_BLK :
} else if (le32_eq(seltag, IO_REPARSE_TAG_LX_BLK)) {
name = " (Linux block device)";
break;
case IO_REPARSE_TAG_AF_UNIX :
} else if (le32_eq(seltag, IO_REPARSE_TAG_AF_UNIX)) {
name = " (Unix socket)";
break;
case IO_REPARSE_TAG_APPEXECLINK :
} else if (le32_eq(seltag, IO_REPARSE_TAG_APPEXECLINK)) {
name = " (Exec link)";
break;
default :
} else {
name = "";
break;
}
} } while(0);
return (name);
}
@ -473,9 +473,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)le16_to_cpu(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);
@ -566,79 +566,79 @@ 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;
flags = le32_and(flags, le32_not(FILE_ATTR_READONLY));
}
if (flags & FILE_ATTR_HIDDEN) {
if (!le32_andz(flags, FILE_ATTR_HIDDEN)) {
printf(" HIDDEN");
flags &= ~FILE_ATTR_HIDDEN;
flags = le32_and(flags, le32_not(FILE_ATTR_HIDDEN));
}
if (flags & FILE_ATTR_SYSTEM) {
if (!le32_andz(flags, FILE_ATTR_SYSTEM)) {
printf(" SYSTEM");
flags &= ~FILE_ATTR_SYSTEM;
flags = le32_and(flags, le32_not(FILE_ATTR_SYSTEM));
}
if (flags & FILE_ATTR_DIRECTORY) {
if (!le32_andz(flags, FILE_ATTR_DIRECTORY)) {
printf(" DIRECTORY");
flags &= ~FILE_ATTR_DIRECTORY;
flags = le32_and(flags, le32_not(FILE_ATTR_DIRECTORY));
}
if (flags & FILE_ATTR_ARCHIVE) {
if (!le32_andz(flags, FILE_ATTR_ARCHIVE)) {
printf(" ARCHIVE");
flags &= ~FILE_ATTR_ARCHIVE;
flags = le32_and(flags, le32_not(FILE_ATTR_ARCHIVE));
}
if (flags & FILE_ATTR_DEVICE) {
if (!le32_andz(flags, FILE_ATTR_DEVICE)) {
printf(" DEVICE");
flags &= ~FILE_ATTR_DEVICE;
flags = le32_and(flags, le32_not(FILE_ATTR_DEVICE));
}
if (flags & FILE_ATTR_NORMAL) {
if (!le32_andz(flags, FILE_ATTR_NORMAL)) {
printf(" NORMAL");
flags &= ~FILE_ATTR_NORMAL;
flags = le32_and(flags, le32_not(FILE_ATTR_NORMAL));
}
if (flags & FILE_ATTR_TEMPORARY) {
if (!le32_andz(flags, FILE_ATTR_TEMPORARY)) {
printf(" TEMPORARY");
flags &= ~FILE_ATTR_TEMPORARY;
flags = le32_and(flags, le32_not(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;
flags = le32_and(flags, le32_not(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;
flags = le32_and(flags, le32_not(FILE_ATTR_REPARSE_POINT));
}
if (flags & FILE_ATTR_COMPRESSED) {
if (!le32_andz(flags, FILE_ATTR_COMPRESSED)) {
printf(" COMPRESSED");
flags &= ~FILE_ATTR_COMPRESSED;
flags = le32_and(flags, le32_not(FILE_ATTR_COMPRESSED));
}
if (flags & FILE_ATTR_OFFLINE) {
if (!le32_andz(flags, FILE_ATTR_OFFLINE)) {
printf(" OFFLINE");
flags &= ~FILE_ATTR_OFFLINE;
flags = le32_and(flags, le32_not(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;
flags = le32_and(flags, le32_not(FILE_ATTR_NOT_CONTENT_INDEXED));
}
if (flags & FILE_ATTR_ENCRYPTED) {
if (!le32_andz(flags, FILE_ATTR_ENCRYPTED)) {
printf(" ENCRYPTED");
flags &= ~FILE_ATTR_ENCRYPTED;
flags = le32_and(flags, le32_not(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 (type == AT_FILE_NAME) {
if (flags & FILE_ATTR_I30_INDEX_PRESENT) {
if (le32_eq(type, AT_FILE_NAME)) {
if (!le32_andz(flags, FILE_ATTR_I30_INDEX_PRESENT)) {
printf(" I30_INDEX");
flags &= ~FILE_ATTR_I30_INDEX_PRESENT;
flags = le32_and(flags, le32_not(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;
flags = le32_and(flags, le32_not(FILE_ATTR_VIEW_INDEX_PRESENT));
}
if (flags & FILE_ATTRIBUTE_RECALL_ON_OPEN) {
if (!le32_andz(flags, FILE_ATTRIBUTE_RECALL_ON_OPEN)) {
printf(" RECALL_ON_OPEN");
flags &= ~FILE_ATTRIBUTE_RECALL_ON_OPEN;
flags = le32_and(flags, le32_not(FILE_ATTRIBUTE_RECALL_ON_OPEN));
}
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));
@ -870,18 +870,18 @@ 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 &&
file_name_attr->reparse_point_tag) {
if (!le32_andz(file_name_attr->file_attributes, FILE_ATTR_REPARSE_POINT) &&
!le32_cmpz(file_name_attr->reparse_point_tag)) {
tag = file_name_attr->reparse_point_tag;
printf("%sReparse point tag:\t 0x%08lx%s\n", indent,
(long)le32_to_cpu(tag),
reparse_type_name(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)
le16_to_cpu(file_name_attr->packed_ea_size));
if (file_name_attr->reserved)
if (!le16_cmpz(file_name_attr->reserved))
printf("%sReserved:\t\t %d (0x%x)\n", indent,
(unsigned)
le16_to_cpu(file_name_attr->reserved),
@ -1043,7 +1043,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(le16_not(sec_desc->control), SE_SELF_RELATIVE)) {
SECURITY_DESCRIPTOR *sd = (SECURITY_DESCRIPTOR *)sec_desc;
printf("%s\tOwner SID pointer:\t %p\n", indent, sd->owner);
@ -1054,7 +1054,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);
@ -1062,7 +1062,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);
@ -1071,8 +1071,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");
@ -1084,8 +1084,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");
@ -1191,31 +1191,31 @@ 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, le16_not(VOLUME_FLAGS_MASK)))
printf("\t\t\t\t Unknown Flags: 0x%04x\n",
le16_to_cpu(vol_information->flags &
(~VOLUME_FLAGS_MASK)));
le16_to_cpu(le16_and(vol_information->flags,
le16_not(VOLUME_FLAGS_MASK))));
}
static ntfschar NTFS_DATA_SDS[5] = { const_cpu_to_le16('$'),
@ -1277,7 +1277,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) +
@ -1291,25 +1291,25 @@ static void ntfs_dump_sds(ATTR_RECORD *attr, ntfs_inode *ni)
static const char *get_attribute_type_name(le32 type)
{
switch (type) {
case AT_UNUSED: return "$UNUSED";
case AT_STANDARD_INFORMATION: return "$STANDARD_INFORMATION";
case AT_ATTRIBUTE_LIST: return "$ATTRIBUTE_LIST";
case AT_FILE_NAME: return "$FILE_NAME";
case AT_OBJECT_ID: return "$OBJECT_ID";
case AT_SECURITY_DESCRIPTOR: return "$SECURITY_DESCRIPTOR";
case AT_VOLUME_NAME: return "$VOLUME_NAME";
case AT_VOLUME_INFORMATION: return "$VOLUME_INFORMATION";
case AT_DATA: return "$DATA";
case AT_INDEX_ROOT: return "$INDEX_ROOT";
case AT_INDEX_ALLOCATION: return "$INDEX_ALLOCATION";
case AT_BITMAP: return "$BITMAP";
case AT_REPARSE_POINT: return "$REPARSE_POINT";
case AT_EA_INFORMATION: return "$EA_INFORMATION";
case AT_EA: return "$EA";
case AT_PROPERTY_SET: return "$PROPERTY_SET";
case AT_LOGGED_UTILITY_STREAM: return "$LOGGED_UTILITY_STREAM";
case AT_END: return "$END";
/* switch(type) */ {
if (le32_eq(type, AT_UNUSED)) return "$UNUSED";
else if (le32_eq(type, AT_STANDARD_INFORMATION)) return "$STANDARD_INFORMATION";
else if (le32_eq(type, AT_ATTRIBUTE_LIST)) return "$ATTRIBUTE_LIST";
else if (le32_eq(type, AT_FILE_NAME)) return "$FILE_NAME";
else if (le32_eq(type, AT_OBJECT_ID)) return "$OBJECT_ID";
else if (le32_eq(type, AT_SECURITY_DESCRIPTOR)) return "$SECURITY_DESCRIPTOR";
else if (le32_eq(type, AT_VOLUME_NAME)) return "$VOLUME_NAME";
else if (le32_eq(type, AT_VOLUME_INFORMATION)) return "$VOLUME_INFORMATION";
else if (le32_eq(type, AT_DATA)) return "$DATA";
else if (le32_eq(type, AT_INDEX_ROOT)) return "$INDEX_ROOT";
else if (le32_eq(type, AT_INDEX_ALLOCATION)) return "$INDEX_ALLOCATION";
else if (le32_eq(type, AT_BITMAP)) return "$BITMAP";
else if (le32_eq(type, AT_REPARSE_POINT)) return "$REPARSE_POINT";
else if (le32_eq(type, AT_EA_INFORMATION)) return "$EA_INFORMATION";
else if (le32_eq(type, AT_EA)) return "$EA";
else if (le32_eq(type, AT_PROPERTY_SET)) return "$PROPERTY_SET";
else if (le32_eq(type, AT_LOGGED_UTILITY_STREAM)) return "$LOGGED_UTILITY_STREAM";
else if (le32_eq(type, AT_END)) return "$END";
}
return "$UNKNOWN";
@ -1406,7 +1406,7 @@ static void ntfs_dump_attribute_header(ntfs_attr_search_ctx *ctx,
(unsigned)a->compression_unit);
/* TODO: dump the 5 reserved bytes here in verbose mode */
if (!a->lowest_vcn) {
if (sle64_cmpz(a->lowest_vcn)) {
printf("\tData size:\t\t %llu (0x%llx)\n",
(long long)sle64_to_cpu(a->data_size),
(unsigned long long)sle64_to_cpu(a->data_size));
@ -1418,8 +1418,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),
@ -1677,7 +1677,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));
@ -1693,11 +1693,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) {
@ -1725,7 +1725,7 @@ static int ntfs_dump_index_entries(INDEX_ENTRY *entry, INDEX_ATTR_TYPE type)
ntfs_dump_index_data(entry, type);
break;
}
if (!entry->length) {
if (le16_cmpz(entry->length)) {
ntfs_log_verbose("\tWARNING: Corrupt index entry, "
"skipping the remainder of this index "
"block.\n");
@ -1752,8 +1752,8 @@ 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 (index_root->type == AT_FILE_NAME)
if (!le32_cmpz(index_root->type)) {
if (le32_eq(index_root->type, AT_FILE_NAME))
return INDEX_ATTR_DIRECTORY_I30;
else
/* weird, this should be illegal */
@ -2166,7 +2166,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));
@ -2291,25 +2291,25 @@ static void ntfs_dump_inode_general_info(ntfs_inode *inode)
(unsigned)le16_to_cpu(mrec->attrs_offset));
printf("MFT Record Flags:\t ");
if (inode_flags) {
if (MFT_RECORD_IN_USE & inode_flags) {
if (!le16_cmpz(inode_flags)) {
if (!le16_andz(MFT_RECORD_IN_USE, inode_flags)) {
printf("IN_USE ");
inode_flags &= ~MFT_RECORD_IN_USE;
inode_flags = le16_and(inode_flags, le16_not(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;
inode_flags = le16_and(inode_flags, le16_not(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;
inode_flags = le16_and(inode_flags, le16_not(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;
inode_flags = le16_and(inode_flags, le16_not(MFT_RECORD_IS_VIEW_INDEX));
}
if (inode_flags)
if (!le16_cmpz(inode_flags))
printf("UNKNOWN: 0x%04x", (unsigned)le16_to_cpu(
inode_flags));
} else {
@ -2324,7 +2324,7 @@ static void ntfs_dump_inode_general_info(ntfs_inode *inode)
(unsigned)le32_to_cpu(mrec->bytes_allocated),
(unsigned)le32_to_cpu(mrec->bytes_allocated));
if (mrec->base_mft_record) {
if (!le64_cmpz(mrec->base_mft_record)) {
printf("Base MFT Record:\t %llu (0x%llx)\n",
(unsigned long long)
MREF_LE(mrec->base_mft_record),
@ -2357,7 +2357,7 @@ static void ntfs_dump_file_attributes(ntfs_inode *inode)
ctx = ntfs_attr_get_search_ctx(inode, NULL);
while (!ntfs_attr_lookup(AT_UNUSED, NULL, 0, CASE_SENSITIVE,
0, NULL, 0, ctx)) {
if (ctx->attr->type == AT_END || ctx->attr->type == AT_UNUSED) {
if (le32_eq(ctx->attr->type, AT_END) || le32_eq(ctx->attr->type, AT_UNUSED)) {
printf("Weird: %s attribute type was found, please "
"report this.\n",
get_attribute_type_name(
@ -2367,57 +2367,57 @@ static void ntfs_dump_file_attributes(ntfs_inode *inode)
ntfs_dump_attribute_header(ctx, inode->vol, &runcount);
switch (ctx->attr->type) {
case AT_STANDARD_INFORMATION:
if (le32_eq(ctx->attr->type, AT_STANDARD_INFORMATION)) {
ntfs_dump_attr_standard_information(ctx->attr);
break;
case AT_ATTRIBUTE_LIST:
}
else if (le32_eq(ctx->attr->type, AT_ATTRIBUTE_LIST)) {
ntfs_dump_attr_list(ctx->attr, inode->vol);
break;
case AT_FILE_NAME:
}
else if (le32_eq(ctx->attr->type, AT_FILE_NAME)) {
ntfs_dump_attr_file_name(ctx->attr);
break;
case AT_OBJECT_ID:
}
else if (le32_eq(ctx->attr->type, AT_OBJECT_ID)) {
ntfs_dump_attr_object_id(ctx->attr, inode->vol);
break;
case AT_SECURITY_DESCRIPTOR:
}
else if (le32_eq(ctx->attr->type, AT_SECURITY_DESCRIPTOR)) {
ntfs_dump_attr_security_descriptor(ctx->attr,
inode->vol);
break;
case AT_VOLUME_NAME:
}
else if (le32_eq(ctx->attr->type, AT_VOLUME_NAME)) {
ntfs_dump_attr_volume_name(ctx->attr);
break;
case AT_VOLUME_INFORMATION:
}
else if (le32_eq(ctx->attr->type, AT_VOLUME_INFORMATION)) {
ntfs_dump_attr_volume_information(ctx->attr);
break;
case AT_DATA:
}
else if (le32_eq(ctx->attr->type, AT_DATA)) {
ntfs_dump_attr_data(ctx->attr, inode);
break;
case AT_INDEX_ROOT:
}
else if (le32_eq(ctx->attr->type, AT_INDEX_ROOT)) {
ntfs_dump_attr_index_root(ctx->attr, inode);
break;
case AT_INDEX_ALLOCATION:
}
else if (le32_eq(ctx->attr->type, AT_INDEX_ALLOCATION)) {
ntfs_dump_attr_index_allocation(ctx->attr, inode);
break;
case AT_BITMAP:
}
else if (le32_eq(ctx->attr->type, AT_BITMAP)) {
ntfs_dump_attr_bitmap(ctx->attr);
break;
case AT_REPARSE_POINT:
}
else if (le32_eq(ctx->attr->type, AT_REPARSE_POINT)) {
ntfs_dump_attr_reparse_point(ctx->attr, inode);
break;
case AT_EA_INFORMATION:
}
else if (le32_eq(ctx->attr->type, AT_EA_INFORMATION)) {
ntfs_dump_attr_ea_information(ctx->attr);
break;
case AT_EA:
}
else if (le32_eq(ctx->attr->type, AT_EA)) {
ntfs_dump_attr_ea(ctx->attr, inode->vol);
break;
case AT_PROPERTY_SET:
}
else if (le32_eq(ctx->attr->type, AT_PROPERTY_SET)) {
ntfs_dump_attr_property_set(ctx->attr);
break;
case AT_LOGGED_UTILITY_STREAM:
}
else if (le32_eq(ctx->attr->type, AT_LOGGED_UTILITY_STREAM)) {
ntfs_dump_attr_logged_utility_stream(ctx->attr, inode);
break;
default:
}
else {
ntfs_dump_attr_unknown(ctx->attr);
}
}

View File

@ -258,8 +258,8 @@ static int change_serial(ntfs_volume *vol, u64 sector, le64 serial_number,
else {
mask = const_cpu_to_le64(~0x0ffffffffULL);
bs->volume_serial_number
= (serial_number & mask)
| (bs->volume_serial_number & ~mask);
= le64_or(le64_and(serial_number, mask),
le64_and(bs->volume_serial_number, le64_not(mask)));
}
if (opts.noaction
|| (ntfs_pwrite(vol->dev,

View File

@ -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

View File

@ -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);
@ -256,7 +256,7 @@ static void dump_mft_record(MFT_RECORD *m)
a = (ATTR_RECORD*)((char*)m + le16_to_cpu(m->attrs_offset));
ntfs_log_info("-- Beginning dump of attributes within mft record. --\n");
while ((char*)a < (char*)m + le32_to_cpu(m->bytes_in_use)) {
if (a->type == AT_END)
if (le32_eq(a->type, AT_END))
break;
a = (ATTR_RECORD*)((char*)a + le32_to_cpu(a->length));
};

View File

@ -904,8 +904,8 @@ int main(int argc, char *argv[])
* This means that the dirty flag is possibly not set, but
* should be set. So we explicitly set it with a call to
* ntfs_volume_write_flags. */
if(!(vol->flags & VOLUME_IS_DIRTY) && ntfs_volume_write_flags(
vol, vol->flags | VOLUME_IS_DIRTY)) {
if(le16_andz(vol->flags, VOLUME_IS_DIRTY) && ntfs_volume_write_flags(
vol, le16_or(vol->flags, VOLUME_IS_DIRTY))) {
ntfs_log_error("Error: Failed to set volume dirty "
"flag (%d (%s))!\n", errno, strerror(errno));
}

View File

@ -480,7 +480,7 @@ void showname(const char *prefix, const char *name, int cnt)
printf("%s",prefix);
n = (const le16*)name;
for (i=0; (i<cnt) && n[i]; i++) {
for (i=0; (i<cnt) && !le16_cmpz(n[i]); i++) {
c = le16_to_cpu(n[i]);
if (c < 0x20)
printf(".");
@ -695,62 +695,62 @@ const char *mftattrname(ATTR_TYPES attr)
static char badattr[24];
const char *p;
switch (attr) {
case AT_STANDARD_INFORMATION :
/* switch (attr) { */
if (le32_eq(attr, AT_STANDARD_INFORMATION)) {
p = "Standard-Information";
break;
case AT_ATTRIBUTE_LIST :
}
else if (le32_eq(attr, AT_ATTRIBUTE_LIST)) {
p = "Attribute-List";
break;
case AT_FILE_NAME :
}
else if (le32_eq(attr, AT_FILE_NAME)) {
p = "Name";
break;
case AT_OBJECT_ID :
}
else if (le32_eq(attr, AT_OBJECT_ID)) {
p = "Volume-Version";
break;
case AT_SECURITY_DESCRIPTOR :
}
else if (le32_eq(attr, AT_SECURITY_DESCRIPTOR)) {
p = "Security-Descriptor";
break;
case AT_VOLUME_NAME :
}
else if (le32_eq(attr, AT_VOLUME_NAME)) {
p = "Volume-Name";
break;
case AT_VOLUME_INFORMATION :
}
else if (le32_eq(attr, AT_VOLUME_INFORMATION)) {
p = "Volume-Information";
break;
case AT_DATA :
}
else if (le32_eq(attr, AT_DATA)) {
p = "Data";
break;
case AT_INDEX_ROOT :
}
else if (le32_eq(attr, AT_INDEX_ROOT)) {
p = "Index-Root";
break;
case AT_INDEX_ALLOCATION :
}
else if (le32_eq(attr, AT_INDEX_ALLOCATION)) {
p = "Index-Allocation";
break;
case AT_BITMAP :
}
else if (le32_eq(attr, AT_BITMAP)) {
p = "Bitmap";
break;
case AT_REPARSE_POINT :
}
else if (le32_eq(attr, AT_REPARSE_POINT)) {
p = "Reparse-Point";
break;
case AT_EA_INFORMATION :
}
else if (le32_eq(attr, AT_EA_INFORMATION)) {
p = "EA-Information";
break;
case AT_EA :
}
else if (le32_eq(attr, AT_EA)) {
p = "EA";
break;
case AT_PROPERTY_SET :
}
else if (le32_eq(attr, AT_PROPERTY_SET)) {
p = "Property-Set";
break;
case AT_LOGGED_UTILITY_STREAM :
}
else if (le32_eq(attr, AT_LOGGED_UTILITY_STREAM)) {
p = "Logged-Utility-Stream";
break;
case AT_END :
}
else if (le32_eq(attr, AT_END)) {
p = "End";
break;
default :
sprintf(badattr,"*0x%x-Unknown*",attr);
}
else {
sprintf(badattr, "*0x%x-Unknown*", le32_to_cpu(attr));
p = badattr;
break;
/* break; */
}
return (p);
}
@ -758,7 +758,7 @@ const char *mftattrname(ATTR_TYPES attr)
static void showattribute(const char *prefix, const struct ATTR *pa)
{
if (pa) {
if (pa->type) {
if (!le32_cmpz(pa->type)) {
printf("%sattr 0x%x : inode %lld type %s",
prefix, pa->key, (long long)pa->inode,
mftattrname(pa->type));
@ -815,7 +815,7 @@ u32 get_undo_offset(const LOG_RECORD *logr)
{
u32 offset;
if (logr->lcns_to_follow)
if (!le16_cmpz(logr->lcns_to_follow))
offset = 0x30 + le16_to_cpu(logr->undo_offset);
else
offset = 0x28 + le16_to_cpu(logr->undo_offset);
@ -826,7 +826,7 @@ u32 get_redo_offset(const LOG_RECORD *logr)
{
u32 offset;
if (logr->lcns_to_follow)
if (!le16_cmpz(logr->lcns_to_follow))
offset = 0x30 + le16_to_cpu(logr->redo_offset);
else
offset = 0x28 + le16_to_cpu(logr->redo_offset);
@ -849,8 +849,8 @@ static BOOL likelyop(const LOG_RECORD *logr)
{
BOOL likely;
switch (logr->record_type) {
case LOG_STANDARD : /* standard record */
do {
if (le32_eq(logr->record_type, LOG_STANDARD)) { /* standard record */
/* Operations in range 0..LastAction-1, can be both null */
likely = ((unsigned int)le16_to_cpu(logr->redo_operation)
< LastAction)
@ -860,7 +860,7 @@ static BOOL likelyop(const LOG_RECORD *logr)
&& !(le16_to_cpu(logr->redo_offset) & 7)
&& !(le16_to_cpu(logr->undo_offset) & 7)
/* transaction id must not be null */
&& logr->transaction_id
&& !le32_cmpz(logr->transaction_id)
/* client data length aligned to 8 bytes */
&& !(le32_to_cpu(logr->client_data_length) & 7)
/* client data length less than 64K (131K ?) */
@ -872,10 +872,10 @@ static BOOL likelyop(const LOG_RECORD *logr)
&& (!le16_to_cpu(logr->undo_length)
|| ((unsigned int)le16_to_cpu(logr->undo_offset) >= 0x28));
/* undo data and redo data should be contiguous when both present */
if (likely && logr->redo_length && logr->undo_length) {
if (likely && !le16_cmpz(logr->redo_length) && !le16_cmpz(logr->undo_length)) {
/* undo and redo data may be the same when both present and same size */
if (logr->undo_offset == logr->redo_offset) {
if (logr->redo_length != logr->undo_length)
if (le16_eq(logr->undo_offset, logr->redo_offset)) {
if (!le16_eq(logr->redo_length, logr->undo_length))
likely = FALSE;
} else {
if (le16_to_cpu(logr->redo_offset)
@ -897,27 +897,27 @@ static BOOL likelyop(const LOG_RECORD *logr)
}
}
break;
case LOG_CHECKPOINT : /* check-point */
} else if (le32_eq(logr->record_type, LOG_CHECKPOINT)) { /* check-point */
/*
* undo and redo operations are null
* or CompensationlogRecord with no data
*/
likely = (!logr->redo_operation
|| ((logr->redo_operation == const_cpu_to_le16(1))
&& !logr->redo_length))
&& (!logr->undo_operation
|| ((logr->undo_operation == const_cpu_to_le16(1))
&& !logr->undo_length))
likely = (le16_cmpz(logr->redo_operation)
|| (le16_eq(logr->redo_operation, const_cpu_to_le16(1))
&& le16_cmpz(logr->redo_length)))
&& (le16_cmpz(logr->undo_operation)
|| (le16_eq(logr->undo_operation, const_cpu_to_le16(1))
&& le16_cmpz(logr->undo_length)))
/* transaction id must be null */
&& !logr->transaction_id
&& le32_cmpz(logr->transaction_id)
/* client_data_length is 0x68 or 0x70 (Vista and subsequent) */
&& ((le32_to_cpu(logr->client_data_length) == 0x68)
|| (le32_to_cpu(logr->client_data_length) == 0x70));
break;
default :
} else {
likely = FALSE;
break;
}
} } while(0);
return (likely);
}
@ -996,7 +996,7 @@ static u16 firstrecord(int skipped, const struct BUFFER *buf,
/* Minimal size is apparently 48 : offset of redo_operation */
if (k && ((blocksz - k) >= LOG_RECORD_HEAD_SZ)) {
logr = (const LOG_RECORD*)&prevdata[k];
if (!logr->client_data_length) {
if (le32_cmpz(logr->client_data_length)) {
/*
* Sometimes the end of record is free space.
* This apparently means reaching the end of
@ -1145,9 +1145,9 @@ static const struct BUFFER *findprevious(CONTEXT *ctx, const struct BUFFER *buf)
prevbuf = read_buffer(ctx, prevblk);
if (prevbuf) {
rph = &prevbuf->block.record;
prevmiddle = !(rph->flags
& const_cpu_to_le32(1))
|| !rph->next_record_offset;
prevmiddle = le32_andz(rph->flags,
const_cpu_to_le32(1))
|| le16_cmpz(rph->next_record_offset);
if (prevmiddle) {
savebuf = prevbuf;
skipped++;
@ -1221,7 +1221,7 @@ static int refresh_attributes(const struct ACTION_RECORD *firstaction)
case OpenNonResidentAttribute :
extra = get_extra_offset(logr)
- get_redo_offset(logr);
if (logr->undo_length) {
if (!le16_cmpz(logr->undo_length)) {
len = le32_to_cpu(logr->client_data_length)
+ LOG_RECORD_HEAD_SZ
- get_extra_offset(logr);
@ -1376,7 +1376,7 @@ static void fixup(CONTEXT *ctx, const LOG_RECORD *logr, const char *buf,
printf(" attrib 0x%lx (%s) at offset 0x%x\n",
(long)le32_to_cpu(mftattr),
mftattrname(mftattr), (int)base);
if (mftattr == AT_FILE_NAME) {
if (le32_eq(mftattr, AT_FILE_NAME)) {
showname(" name ",&buf[base + 90],
buf[base + 88] & 255);
inode = feedle64(buf, base + 24);
@ -1455,7 +1455,7 @@ static void fixup(CONTEXT *ctx, const LOG_RECORD *logr, const char *buf,
firstpos = 0x30 + (((mftrecsz/512 + 1)*2 - 1 ) | 7) + 1;
if (pa
&& !pa->inode
&& (pa->type == const_cpu_to_le32(0x80))
&& le32_eq(pa->type, const_cpu_to_le32(0x80))
&& !(offs & 3)
&& (le16_to_cpu(logr->record_offset) == firstpos)) {
printf(" set standard information, attr 0x%x\n",attr);
@ -1598,8 +1598,8 @@ static void fixup(CONTEXT *ctx, const LOG_RECORD *logr, const char *buf,
inode = feedle64(buf,16);
printf(" parent dir inode %lld\n",
(long long)MREF(le64_to_cpu(inode)));
if (feedle32(buf,72)
& const_cpu_to_le32(0x10000000))
if (!le32_andz(feedle32(buf,72),
const_cpu_to_le32(0x10000000)))
showname(" file (dir) ",
&buf[base + 82],
buf[base + 80] & 255);
@ -1648,7 +1648,7 @@ static void fixup(CONTEXT *ctx, const LOG_RECORD *logr, const char *buf,
showattribute(" ",pa);
if (pa
&& !pa->inode
&& (pa->type == const_cpu_to_le32(0x80))
&& le32_eq(pa->type, const_cpu_to_le32(0x80))
&& !(offs & 3)) {
if (base >= -24)
showdate(" created ",feedle64(buf,
@ -1679,7 +1679,7 @@ static void fixup(CONTEXT *ctx, const LOG_RECORD *logr, const char *buf,
}
} else {
/* Usually caused by attr not yet defined */
if (pa && pa->type)
if (pa && !le32_cmpz(pa->type))
printf("** Unexpected index parameters\n");
}
break;
@ -1735,7 +1735,7 @@ static void fixup(CONTEXT *ctx, const LOG_RECORD *logr, const char *buf,
extra = get_extra_offset(logr)
- (redo ? get_redo_offset(logr)
: get_undo_offset(logr));
if (logr->undo_length) {
if (!le16_cmpz(logr->undo_length)) {
len = le32_to_cpu(logr->client_data_length)
+ LOG_RECORD_HEAD_SZ
- get_extra_offset(logr);
@ -1761,7 +1761,7 @@ static void fixup(CONTEXT *ctx, const LOG_RECORD *logr, const char *buf,
printf(" inode %lld\n",
(long long)pa->inode);
}
if (logr->undo_length)
if (!le16_cmpz(logr->undo_length))
showname(" extra : attr name ", &buf[extra], len/2);
if (!redo && length) {
printf(" * undo attr not shown\n");
@ -1870,9 +1870,9 @@ static void detaillogr(CONTEXT *ctx, const LOG_RECORD *logr)
unsigned int listsize;
BOOL onmft;
switch (logr->record_type) {
case LOG_STANDARD :
onmft = logr->cluster_index
do {
if (le32_eq(logr->record_type, LOG_STANDARD)) {
onmft = !le16_cmpz(logr->cluster_index)
|| acts_on_mft(le16_to_cpu(logr->redo_operation))
|| acts_on_mft(le16_to_cpu(logr->undo_operation));
printf("redo_operation %04x %s\n",
@ -1949,7 +1949,7 @@ static void detaillogr(CONTEXT *ctx, const LOG_RECORD *logr)
* 4) extra : unknown data (end of undo to data_length)
*/
end = le32_to_cpu(logr->client_data_length) + LOG_RECORD_HEAD_SZ;
if (logr->redo_length && logr->undo_length)
if (!le16_cmpz(logr->redo_length) && !le16_cmpz(logr->undo_length))
{
/* both undo and redo are present */
if (le16_to_cpu(logr->undo_offset) <=
@ -1957,7 +1957,7 @@ static void detaillogr(CONTEXT *ctx, const LOG_RECORD *logr)
{
undo = sizeof(LOG_RECORD) - 8
+ 8*le16_to_cpu(logr->lcns_to_follow);
if (logr->redo_offset == logr->undo_offset)
if (le16_eq(logr->redo_offset, logr->undo_offset))
redo = undo;
else
redo = undo + ((le16_to_cpu(logr->undo_length) - 1) | 7) + 1;
@ -1972,7 +1972,7 @@ static void detaillogr(CONTEXT *ctx, const LOG_RECORD *logr)
}
}
else
if (logr->redo_length)
if (!le16_cmpz(logr->redo_length))
{
/* redo and not undo */
redo = undo = sizeof(LOG_RECORD) - 8
@ -1992,11 +1992,11 @@ static void detaillogr(CONTEXT *ctx, const LOG_RECORD *logr)
undo,(int)(((le16_to_cpu(logr->undo_length) - 1) | 7) + 1),
extra,(int)(end > extra ? end - extra : 0));
if (logr->redo_length && (get_redo_offset(logr) != redo))
if (!le16_cmpz(logr->redo_length) && (get_redo_offset(logr) != redo))
printf("** Unexpected redo offset 0x%x %u (%u)\n",
get_redo_offset(logr),(int)redo,
(int)le16_to_cpu(logr->lcns_to_follow));
if (logr->undo_length && (get_undo_offset(logr) != undo))
if (!le16_cmpz(logr->undo_length) && (get_undo_offset(logr) != undo))
printf("** Unexpected undo offset 0x%x %u (%u)\n",
get_undo_offset(logr),(int)undo,
(int)le16_to_cpu(logr->lcns_to_follow));
@ -2008,9 +2008,9 @@ static void detaillogr(CONTEXT *ctx, const LOG_RECORD *logr)
if (extra <= end)
{
/* show redo data */
if (logr->redo_length)
if (!le16_cmpz(logr->redo_length))
{
if (logr->lcns_to_follow)
if (!le16_cmpz(logr->lcns_to_follow))
{
off = le16_to_cpu(logr->record_offset)
+ le16_to_cpu(logr->attribute_offset);
@ -2037,9 +2037,9 @@ static void detaillogr(CONTEXT *ctx, const LOG_RECORD *logr)
}
/* show undo data */
if (logr->undo_length)
if (!le16_cmpz(logr->undo_length))
{
if (logr->lcns_to_follow)
if (!le16_cmpz(logr->lcns_to_follow))
{
off = le16_to_cpu(logr->record_offset)
+ le16_to_cpu(logr->attribute_offset);
@ -2083,15 +2083,15 @@ static void detaillogr(CONTEXT *ctx, const LOG_RECORD *logr)
else
{
/* sometimes the designated data overflows */
if (logr->redo_length
if (!le16_cmpz(logr->redo_length)
&& ((u32)(redo + le16_to_cpu(logr->redo_length)) > end))
printf("* redo data overflows from record\n");
if (logr->undo_length
if (!le16_cmpz(logr->undo_length)
&& ((u32)(undo + le16_to_cpu(logr->undo_length)) > end))
printf("* undo data overflows from record\n");
}
break;
case LOG_CHECKPOINT :
} else if (le32_eq(logr->record_type, LOG_CHECKPOINT)) {
printf("---> checkpoint record\n");
printf("redo_operation %04x %s\n",
(int)le16_to_cpu(logr->redo_operation),
@ -2120,7 +2120,7 @@ static void detaillogr(CONTEXT *ctx, const LOG_RECORD *logr)
printf("unknown-%u %016llx\n",i,
(long long)le64_to_cpu(logr->unknown_list[i]));
break;
default :
} else {
printf("** Unknown action type\n");
if (le32_to_cpu(logr->client_data_length) < blocksz) {
printf("client_data for record type %ld\n",
@ -2130,7 +2130,7 @@ static void detaillogr(CONTEXT *ctx, const LOG_RECORD *logr)
} else
printf("** Bad client data\n");
break;
}
} } while(0);
}
BOOL within_lcn_range(const LOG_RECORD *logr)
@ -2140,17 +2140,17 @@ BOOL within_lcn_range(const LOG_RECORD *logr)
BOOL within;
within = FALSE;
switch (logr->record_type) {
case LOG_STANDARD :
do {
if (le32_eq(logr->record_type, LOG_STANDARD)) {
for (i=0; i<le16_to_cpu(logr->lcns_to_follow); i++) {
lcn = MREF(sle64_to_cpu(logr->lcn_list[i]));
if ((lcn >= firstlcn) && (lcn <= lastlcn))
within = TRUE;
}
break;
default :
} else {
break;
}
} } while(0);
return (within);
}
@ -2189,7 +2189,7 @@ static void showlogr(CONTEXT *ctx, int k, const LOG_RECORD *logr)
if (optt) {
const char *state;
if (logr->record_type == LOG_CHECKPOINT)
if (le32_eq(logr->record_type, LOG_CHECKPOINT))
state = "--checkpoint--";
else
state = commitment(sle64_to_cpu(logr->this_lsn));
@ -2198,9 +2198,9 @@ static void showlogr(CONTEXT *ctx, int k, const LOG_RECORD *logr)
state,
(long)(sle64_to_cpu(logr->this_lsn) - synced_lsn),
actionname(le16_to_cpu(logr->redo_operation)));
if (logr->client_previous_lsn || logr->client_undo_next_lsn) {
if (logr->client_previous_lsn
== logr->client_undo_next_lsn) {
if (!sle64_cmpz(logr->client_previous_lsn) || !sle64_cmpz(logr->client_undo_next_lsn)) {
if (sle64_eq(logr->client_previous_lsn,
logr->client_undo_next_lsn)) {
printf(" "
" previous and undo %016llx\n",
(long long)sle64_to_cpu(
@ -2211,7 +2211,7 @@ static void showlogr(CONTEXT *ctx, int k, const LOG_RECORD *logr)
(long long)sle64_to_cpu(
logr->client_previous_lsn));
if (logr->client_undo_next_lsn)
if (!sle64_cmpz(logr->client_undo_next_lsn))
printf(" undo %016llx\n",
(long long)sle64_to_cpu(
logr->client_undo_next_lsn));
@ -2241,10 +2241,10 @@ static void mark_transactions(struct ACTION_RECORD *lastaction)
id = const_cpu_to_le32(0);
for (action=lastaction; action; action=action->prev) {
logr = &action->record;
if ((logr->redo_operation
== const_cpu_to_le16(ForgetTransaction))
if (le16_eq(logr->redo_operation,
const_cpu_to_le16(ForgetTransaction))
&& !(action->flags & ACTION_TO_REDO)
&& !id) {
&& le32_cmpz(id)) {
id = logr->transaction_id;
action->flags |= ACTION_TO_REDO;
if (optv)
@ -2253,11 +2253,11 @@ static void mark_transactions(struct ACTION_RECORD *lastaction)
}
committed = ((s64)(sle64_to_cpu(logr->this_lsn)
- committed_lsn)) <= 0;
if (!logr->transaction_id
if (le32_cmpz(logr->transaction_id)
&& committed)
action->flags |= ACTION_TO_REDO;
if (id
&& (logr->transaction_id == id)
if (!le32_cmpz(id)
&& le32_eq(logr->transaction_id, id)
&& committed) {
action->flags |= ACTION_TO_REDO;
more = TRUE;
@ -2272,7 +2272,7 @@ static void mark_transactions(struct ACTION_RECORD *lastaction)
if (optv) {
for (action=lastaction; action; action=action->prev) {
logr = &action->record;
if (logr->transaction_id
if (!le32_cmpz(logr->transaction_id)
&& !(action->flags & ACTION_TO_REDO))
printf("** Action %d was aborted\n",
(int)action->num);
@ -2313,7 +2313,7 @@ static TRISTATE enqueue_action(CONTEXT *ctx, const LOG_RECORD *logr,
err = 0;
state = T_OK;
if ((optp || optu)
&& (logr->record_type == LOG_CHECKPOINT)) {
&& le32_eq(logr->record_type, LOG_CHECKPOINT)) {
/* if chkp process queue, and increment count */
playedactions++;
if (playedactions <= playcount) {
@ -2620,7 +2620,7 @@ static u16 forward_rcrd(CONTEXT *ctx, u32 blk, u16 pos,
BOOL stop;
rph = &buf->block.record;
if (rph && (rph->magic == magic_RCRD)) {
if (rph && le32_eq(rph->magic, magic_RCRD)) {
data = buf->block.data;
showheadrcrd(blk, rph);
k = buf->headsz;
@ -2677,7 +2677,7 @@ static u16 forward_rcrd(CONTEXT *ctx, u32 blk, u16 pos,
k + size);
}
showlogr(ctx, k, logr);
if (!logr->client_data_length) {
if (le32_cmpz(logr->client_data_length)) {
printf("** Bad"
" client_data_length\n");
stop = TRUE;
@ -2714,8 +2714,8 @@ static void showrest(const RESTART_PAGE_HEADER *rest)
const char *data;
data = (const char*)rest;
if ((rest->magic == magic_RSTR)
|| (rest->magic == magic_CHKD)) {
if (le32_eq(rest->magic, magic_RSTR)
|| le32_eq(rest->magic, magic_CHKD)) {
if (optv) {
printf("magic %08lx\n",
(long)le32_to_cpu(rest->magic));
@ -2843,7 +2843,7 @@ static BOOL dorest(CONTEXT *ctx, unsigned long blk,
offs += le16_to_cpu(restart.client_array_offset);
memcpy(&client, &data[offs],
sizeof(LOG_CLIENT_RECORD));
dirty = !(resa->flags & RESTART_VOLUME_IS_CLEAN);
dirty = le16_andz(resa->flags, RESTART_VOLUME_IS_CLEAN);
if (optv || optt)
printf("* Using initial restart page,"
" syncing from 0x%llx, %s\n",
@ -2870,7 +2870,7 @@ static BOOL dorest(CONTEXT *ctx, unsigned long blk,
}
showrest(rph);
/* Information from an older restart block if requested */
dirty = !(restart.flags & RESTART_VOLUME_IS_CLEAN);
dirty = le16_andz(restart.flags, RESTART_VOLUME_IS_CLEAN);
diff = sle64_to_cpu(rcli->client_restart_lsn) - committed_lsn;
if (ctx->vol) {
change = (opts > 1) && (diff < 0);
@ -2889,7 +2889,7 @@ static BOOL dorest(CONTEXT *ctx, unsigned long blk,
offs += le16_to_cpu(restart.client_array_offset);
memcpy(&client, &data[offs],
sizeof(LOG_CLIENT_RECORD));
dirty = !(resa->flags & RESTART_VOLUME_IS_CLEAN);
dirty = le16_andz(resa->flags, RESTART_VOLUME_IS_CLEAN);
if (optv || optt)
printf("* Using %s restart page,"
" syncing from 0x%llx, %s\n",
@ -2956,21 +2956,21 @@ static const struct BUFFER *read_restart(CONTEXT *ctx)
NTFS_RECORD_TYPES magic;
magic = buf->block.restart.magic;
switch (magic) {
case magic_RSTR :
break;
case magic_CHKD :
/* switch (magic) { */
if (le32_eq(magic, magic_RSTR)) {
}
else if (le32_eq(magic, magic_CHKD)) {
printf("** The log file has been obsoleted by chkdsk\n");
bad = TRUE;
break;
case magic_empty :
}
else if (le32_eq(magic, magic_empty)) {
printf("** The log file has been wiped out\n");
bad = TRUE;
break;
default :
}
else {
printf("** Invalid restart block\n");
bad = TRUE;
break;
/* break; */
}
if (!bad && !ctx->vol)
dorest(ctx, 0, &buf->block.restart, TRUE);
@ -3013,7 +3013,7 @@ static int reset_logfile(CONTEXT *ctx __attribute__((unused)))
if (buffer) {
memset(buffer, 0, blocksz);
restart.client_in_use_list = LOGFILE_NO_CLIENT;
restart.flags |= RESTART_VOLUME_IS_CLEAN;
restart.flags = le16_or(restart.flags, RESTART_VOLUME_IS_CLEAN);
client.oldest_lsn = cpu_to_sle64(restart_lsn);
/* Set $LogFile version to 1.1 so that volume can be mounted */
log_header.major_ver = const_cpu_to_sle16(1);
@ -3062,7 +3062,7 @@ static const struct BUFFER *best_start(const struct BUFFER *buf,
else
best = buf;
}
if (best && (best->block.record.magic != magic_RCRD))
if (best && !le32_eq(best->block.record.magic, magic_RCRD))
best = (const struct BUFFER*)NULL;
return (best);
}
@ -3244,8 +3244,8 @@ static BOOL getvolumedata(CONTEXT *ctx, char *boot)
}
// TODO get rest ?, meaningful ?
if (ok && rest) {
if (rest->client_in_use_list
|| !(rest->flags & const_cpu_to_le16(2)))
if (!le16_cmpz(rest->client_in_use_list)
|| le16_andz(rest->flags, const_cpu_to_le16(2)))
printf("Volume was not unmounted safely\n");
else
printf("Volume was unmounted safely\n");
@ -3453,8 +3453,8 @@ static TRISTATE backward_rcrd(CONTEXT *ctx, u32 blk, int skipped,
if (prevbuf)
prevrph = &prevbuf->block.record;
data = buf->block.data;
if (rph && (rph->magic == magic_RCRD)
&& (!prevrph || (prevrph->magic == magic_RCRD))) {
if (rph && le32_eq(rph->magic, magic_RCRD)
&& (!prevrph || le32_eq(prevrph->magic, magic_RCRD))) {
if (optv) {
if (optv >= 2)
hexdump(data,blocksz);
@ -3521,7 +3521,7 @@ static TRISTATE backward_rcrd(CONTEXT *ctx, u32 blk, int skipped,
if (((u32)(k + size) <= blocksz)
&& ((u32)(k + size) <= endoff)) {
poslist[cnt++] = k;
if (!logr->client_data_length)
if (le32_cmpz(logr->client_data_length))
stop = TRUE;
k += size;
if ((u32)(k
@ -3561,14 +3561,14 @@ static TRISTATE backward_rcrd(CONTEXT *ctx, u32 blk, int skipped,
if ((optv | optt)
&& (!nextbuf && (j == (cnt - 1)))) {
printf("* This is the latest record\n");
if (logr->this_lsn == restart.current_lsn)
if (sle64_eq(logr->this_lsn, restart.current_lsn))
printf(" its lsn matches the global"
" restart lsn\n");
if (logr->this_lsn == client.client_restart_lsn)
if (sle64_eq(logr->this_lsn, client.client_restart_lsn))
printf(" its lsn matches the client"
" restart lsn\n");
if (logr->client_data_length
== restart.last_lsn_data_length)
if (le32_eq(logr->client_data_length,
restart.last_lsn_data_length))
printf(" its length matches the"
" last record length\n");
}
@ -3623,18 +3623,18 @@ static int walkback(CONTEXT *ctx, const struct BUFFER *buf, u32 blk,
- (log_major < 2 ? BASEBLKS
: BASEBLKS2);
magic = prevbuf->block.record.magic;
switch (magic) {
case magic_RCRD :
break;
case magic_CHKD :
/* switch (magic) { */
if (le32_eq(magic, magic_RCRD)) {
}
else if (le32_eq(magic, magic_CHKD)) {
printf("** Unexpected block type CHKD\n");
break;
case magic_RSTR :
}
else if (le32_eq(magic, magic_RSTR)) {
printf("** Unexpected block type RSTR\n");
break;
default :
}
else {
printf("** Invalid block %d\n",(int)prevblk);
break;
/* break; */
}
if (optv) {
if (skipped)
@ -3888,24 +3888,24 @@ static int walk(CONTEXT *ctx)
record = (const NTFS_RECORD*)&nextbuf->block.data;
blkheadsz = nextbuf->headsz;
magic = record->magic;
switch (magic) {
case magic_CHKD :
case magic_RSTR :
case magic_RCRD :
break;
default :
/* switch (magic) { */
if (le32_eq(magic, magic_CHKD) ||
le32_eq(magic, magic_RSTR) ||
le32_eq(magic, magic_RCRD)) {
}
else {
printf("** Invalid block\n");
err = 1;
break;
/* break; */
}
magic = buf->block.record.magic;
switch (magic) {
case magic_CHKD :
case magic_RSTR :
/* switch (magic) { */
if (le32_eq(magic, magic_CHKD) ||
le32_eq(magic, magic_RSTR)) {
dirty = dorest(ctx, blk, &buf->block.restart,
FALSE);
break;
case magic_RCRD :
}
else if (le32_eq(magic, magic_RCRD)) {
if (blk < BASEBLKS)
pos = buf->headsz;
pos = dorcrd(ctx, blk, pos, buf, nextbuf);
@ -3924,13 +3924,13 @@ static int walk(CONTEXT *ctx)
if (nextblk != (blk + 1)) {
nextbuf = read_buffer(ctx,nextblk);
}
break;
default :
if (!~magic) {
}
else {
if (le32_cmpz(le32_not(magic))) {
if (optv)
printf(" empty block\n");
}
break;
/* break; */
}
} else {
fprintf(stderr,"* Could not read block %d\n",nextblk);
@ -4063,21 +4063,21 @@ static int walk(CONTEXT *ctx)
if (prevbuf) {
prevblk = prevbuf->num;
magic = prevbuf->block.record.magic;
switch (magic) {
case magic_RCRD :
break;
case magic_CHKD :
/* switch (magic) { */
if (le32_eq(magic, magic_RCRD)) {
}
else if (le32_eq(magic, magic_CHKD)) {
printf("** Unexpected block type CHKD\n");
err = 1;
break;
case magic_RSTR :
}
else if (le32_eq(magic, magic_RSTR)) {
err = 1;
printf("** Unexpected block type RSTR\n");
break;
default :
}
else {
err = 1;
printf("** Invalid block\n");
break;
/* break; */
}
} else
prevblk = BASEBLKS;

View File

@ -728,7 +728,7 @@ static void collect_resize_constraints(ntfs_resize_t *resize, runlist *rl)
if (inode == FILE_Bitmap) {
llcn = &resize->last_lcn;
if (atype == AT_DATA && NInoAttrList(resize->ni))
if (le32_eq(atype, AT_DATA) && NInoAttrList(resize->ni))
err_exit("Highly fragmented $Bitmap isn't supported yet.");
supported = 1;
@ -739,11 +739,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;
@ -752,7 +752,7 @@ static void collect_resize_constraints(ntfs_resize_t *resize, runlist *rl)
supported = 1;
/* Fragmented $MFTMirr DATA attribute isn't supported yet */
if (atype == AT_DATA)
if (le32_eq(atype, AT_DATA))
if (rl[1].length != 0 || rl->vcn)
supported = 0;
} else {
@ -786,7 +786,7 @@ static void collect_relocation_info(ntfs_resize_t *resize, runlist *rl)
if (lcn + lcn_length <= new_vol_size)
return;
if (inode == FILE_Bitmap && resize->ctx->attr->type == AT_DATA)
if (inode == FILE_Bitmap && le32_eq(resize->ctx->attr->type, AT_DATA))
return;
start = lcn;
@ -915,7 +915,7 @@ static int walk_attributes(ntfs_volume *vol, ntfsck_t *fsck)
return -1;
while (!ntfs_attrs_walk(fsck->ctx)) {
if (fsck->ctx->attr->type == AT_END)
if (le32_eq(fsck->ctx->attr->type, AT_END))
break;
build_lcn_usage_bitmap(vol, fsck);
}
@ -1087,7 +1087,7 @@ static int build_allocation_bitmap(ntfs_volume *vol, ntfsck_t *fsck)
return -1;
}
if (ni->mrec->base_mft_record)
if (!le64_cmpz(ni->mrec->base_mft_record))
goto close_inode;
fsck->ni = ni;
@ -1132,7 +1132,7 @@ static void resize_constraints_by_attributes(ntfs_resize_t *resize)
exit(1);
while (!ntfs_attrs_walk(resize->ctx)) {
if (resize->ctx->attr->type == AT_END)
if (le32_eq(resize->ctx->attr->type, AT_END))
break;
build_resize_constraints(resize);
}
@ -1161,7 +1161,7 @@ static void set_resize_constraints(ntfs_resize_t *resize)
(long long)inode);
}
if (ni->mrec->base_mft_record)
if (!le64_cmpz(ni->mrec->base_mft_record))
goto close_inode;
resize->ni = ni;
@ -1339,7 +1339,7 @@ static void expand_attribute_runlist(ntfs_volume *vol, struct DELAYED *delayed)
ni = ntfs_inode_open(vol,mref);
if (ni) {
if (mref == FILE_MFT)
na = (type == AT_DATA ? vol->mft_na : vol->mftbmp_na);
na = (le32_eq(type, AT_DATA) ? vol->mft_na : vol->mftbmp_na);
else
na = ntfs_attr_open(ni, type,
delayed->attr_name, delayed->name_len);
@ -1496,7 +1496,7 @@ static void delayed_updates(ntfs_resize_t *resize)
if (opt.ro_flag
&& resize->delayed_runlists
&& (resize->delayed_runlists->mref == FILE_MFT)
&& (resize->delayed_runlists->type == AT_DATA)) {
&& le32_eq(resize->delayed_runlists->type, AT_DATA)) {
/* Update the MFT data runlist later */
delayed_mft_data = resize->delayed_runlists;
resize->delayed_runlists = resize->delayed_runlists->next;
@ -1506,9 +1506,9 @@ static void delayed_updates(ntfs_resize_t *resize)
delayed = resize->delayed_runlists;
expand_attribute_runlist(resize->vol, delayed);
if (delayed->mref == FILE_MFT) {
if (delayed->type == AT_BITMAP)
if (le32_eq(delayed->type, AT_BITMAP))
record_mft_in_bitmap(resize);
if (delayed->type == AT_DATA)
if (le32_eq(delayed->type, AT_DATA))
resize->mirr_from = MIRR_MFT;
}
resize->delayed_runlists = resize->delayed_runlists->next;
@ -1563,7 +1563,7 @@ static void replace_later(ntfs_resize_t *resize, runlist *rl, runlist *head_rl)
delayed = (struct DELAYED*)ntfs_malloc(sizeof(struct DELAYED));
if (delayed && (attr_name || !name_len)) {
lemref = resize->ctx->mrec->base_mft_record;
if (lemref)
if (!le64_cmpz(lemref))
mref = le64_to_cpu(lemref);
else
mref = resize->mref;
@ -1928,7 +1928,7 @@ static void copy_clusters(ntfs_resize_t *resize, s64 dest, s64 src, s64 len)
static void relocate_clusters(ntfs_resize_t *r, runlist *dest_rl, s64 src_lcn)
{
/* collect_shrink_constraints() ensured $MFTMir DATA is one run */
if (r->mref == FILE_MFTMirr && r->ctx->attr->type == AT_DATA) {
if (r->mref == FILE_MFTMirr && le32_eq(r->ctx->attr->type, AT_DATA)) {
if (!r->mftmir_old) {
r->mftmir_rl.lcn = dest_rl->lcn;
r->mftmir_rl.length = dest_rl->length;
@ -2026,7 +2026,7 @@ static void relocate_run(ntfs_resize_t *resize, runlist **rl, int run)
hint = (resize->mref == FILE_MFTMirr) ? 1 : 0;
if ((resize->mref == FILE_MFT)
&& (resize->ctx->attr->type == AT_DATA)
&& le32_eq(resize->ctx->attr->type, AT_DATA)
&& !run
&& resize->new_mft_start) {
relocate_rl = resize->new_mft_start;
@ -2054,7 +2054,7 @@ static void relocate_run(ntfs_resize_t *resize, runlist **rl, int run)
/* Do not free the relocated MFT start */
if ((resize->mref != FILE_MFT)
|| (resize->ctx->attr->type != AT_DATA)
|| !le32_eq(resize->ctx->attr->type, AT_DATA)
|| run
|| !resize->new_mft_start)
free(relocate_rl);
@ -2110,7 +2110,7 @@ static int is_mftdata(ntfs_resize_t *resize)
* the other files.
*/
if (resize->ctx->attr->type != AT_DATA)
if (!le32_eq(resize->ctx->attr->type, AT_DATA))
return 0;
if (resize->mref == 0)
@ -2167,12 +2167,12 @@ static void relocate_attributes(ntfs_resize_t *resize, int do_mftdata)
exit(1);
lemref = resize->mrec->base_mft_record;
if (lemref)
if (!le64_cmpz(lemref))
base_mref = MREF(le64_to_cpu(lemref));
else
base_mref = resize->mref;
while (!ntfs_attrs_walk(resize->ctx)) {
if (resize->ctx->attr->type == AT_END)
if (le32_eq(resize->ctx->attr->type, AT_END))
break;
if (handle_mftdata(resize, do_mftdata) == 0)
@ -2185,12 +2185,12 @@ static void relocate_attributes(ntfs_resize_t *resize, int do_mftdata)
continue;
if (resize->mref == FILE_Bitmap &&
resize->ctx->attr->type == AT_DATA)
le32_eq(resize->ctx->attr->type, AT_DATA))
continue;
/* Do not relocate bad clusters */
if ((base_mref == FILE_BadClus)
&& (resize->ctx->attr->type == AT_DATA))
&& (le32_eq(resize->ctx->attr->type, AT_DATA)))
continue;
relocate_attribute(resize);
@ -2211,7 +2211,7 @@ static void relocate_inode(ntfs_resize_t *resize, MFT_REF mref, int do_mftdata)
perr_exit("ntfs_file_record_record");
}
if (!(resize->mrec->flags & MFT_RECORD_IN_USE))
if (le16_andz(resize->mrec->flags, MFT_RECORD_IN_USE))
return;
resize->mref = mref;
@ -2290,8 +2290,8 @@ static void relocate_inodes(ntfs_resize_t *resize)
err_exit("Could not read the base record of MFT\n");
}
while (!ntfs_attrs_walk(resize->ctx)
&& (resize->ctx->attr->type != AT_DATA)) { }
if (resize->ctx->attr->type == AT_DATA) {
&& !le32_eq(resize->ctx->attr->type, AT_DATA)) { }
if (le32_eq(resize->ctx->attr->type, AT_DATA)) {
sle64 high_le;
high_le = resize->ctx->attr->highest_vcn;
@ -2441,8 +2441,9 @@ static void truncate_badclust_bad_attr(ntfs_resize_t *resize)
exit(1);
}
/* Clear the sparse flags, even if there are bad clusters */
na->ni->flags &= ~FILE_ATTR_SPARSE_FILE;
na->data_flags &= ~ATTR_IS_SPARSE;
na->ni->flags =
le32_and(na->ni->flags, le32_not(FILE_ATTR_SPARSE_FILE));
na->data_flags = le16_and(na->data_flags, le16_not(ATTR_IS_SPARSE));
ctx = resize->ctx;
ctx->attr->data_size = cpu_to_sle64(na->data_size);
ctx->attr->initialized_size = cpu_to_sle64(na->initialized_size);
@ -2943,7 +2944,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");
@ -2984,7 +2985,7 @@ static void prepare_volume_fixup(ntfs_volume *vol)
{
printf("Schedule chkdsk for NTFS consistency check at Windows boot "
"time ...\n");
vol->flags |= VOLUME_IS_DIRTY;
vol->flags = le16_or(vol->flags, VOLUME_IS_DIRTY);
if (ntfs_volume_write_flags(vol, vol->flags))
perr_exit("Failed to set the volume dirty");
@ -3128,8 +3129,8 @@ static ATTR_RECORD *find_attr(MFT_RECORD *mrec, ATTR_TYPES type,
offset = le16_to_cpu(mrec->attrs_offset);
a = (ATTR_RECORD*)((char*)mrec + offset);
attrname = (ntfschar*)((char*)a + le16_to_cpu(a->name_offset));
while ((a->type != AT_END)
&& ((a->type != type)
while (!le32_eq(a->type, AT_END)
&& (!le32_eq(a->type, type)
|| (a->name_length != namelen)
|| (namelen && memcmp(attrname,name,2*namelen)))
&& (offset < le32_to_cpu(mrec->bytes_in_use))) {
@ -3139,7 +3140,7 @@ static ATTR_RECORD *find_attr(MFT_RECORD *mrec, ATTR_TYPES type,
attrname = (ntfschar*)((char*)a
+ le16_to_cpu(a->name_offset));
}
if ((a->type != type)
if (!le32_eq(a->type, type)
|| (a->name_length != namelen)
|| (namelen && memcmp(attrname,name,2*namelen)))
a = (ATTR_RECORD*)NULL;
@ -3170,12 +3171,12 @@ 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 && (a->type == type) && !a->name_length;
found = a && le32_eq(a->type, type) && !a->name_length;
}
/* not finding the attribute list is not an error */
if (!found && (type != AT_ATTRIBUTE_LIST)) {
if (!found && !le32_eq(type, AT_ATTRIBUTE_LIST)) {
err_printf("Could not find attribute 0x%lx in inode %lld\n",
(long)le32_to_cpu(type), (long long)inum);
a = (ATTR_RECORD*)NULL;
@ -3205,7 +3206,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) {
@ -3408,7 +3409,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;
@ -3788,7 +3789,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;
@ -4036,7 +4037,7 @@ static int rebase_runlists(expand_t *expand, s64 inum)
mrec = expand->mrec;
offset = le16_to_cpu(mrec->attrs_offset);
a = (ATTR_RECORD*)((char*)mrec + offset);
while (!res && (a->type != AT_END)
while (!res && !le32_eq(a->type, AT_END)
&& (offset < le32_to_cpu(mrec->bytes_in_use))) {
if (a->non_resident) {
rl = ntfs_mapping_pairs_decompress(expand->vol, a,
@ -4121,7 +4122,7 @@ static runlist_element *rebase_runlists_meta(expand_t *expand, s64 inum)
allocated_size = lth << vol->cluster_size_bits;
offset = le16_to_cpu(mrec->attrs_offset);
a = (ATTR_RECORD*)((char*)mrec + offset);
while (!res && (a->type != AT_END)
while (!res && !le32_eq(a->type, AT_END)
&& (offset < le32_to_cpu(mrec->bytes_in_use))) {
if (a->non_resident) {
keeprl = FALSE;
@ -4132,12 +4133,12 @@ static runlist_element *rebase_runlists_meta(expand_t *expand, s64 inum)
for (prl=rl; prl->length; prl++)
if (prl->lcn >= 0) {
prl->lcn += expand->cluster_increment;
if ((a->type != AT_DATA)
if (!le32_eq(a->type, AT_DATA)
&& set_bitmap(expand,prl))
res = -1;
}
/* relocated unnamed data (not $BadClus) */
if ((a->type == AT_DATA)
if (le32_eq(a->type, AT_DATA)
&& !a->name_length
&& (inum != FILE_BadClus)) {
old_rl = rl;
@ -4158,7 +4159,7 @@ static runlist_element *rebase_runlists_meta(expand_t *expand, s64 inum)
a->highest_vcn = cpu_to_sle64(lth - 1);
}
/* expand the named data for $BadClus */
if ((a->type == AT_DATA)
if (le32_eq(a->type, AT_DATA)
&& a->name_length
&& (inum == FILE_BadClus)) {
old_rl = rl;
@ -4221,7 +4222,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 :
@ -4295,7 +4296,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",

View File

@ -366,15 +366,15 @@ typedef enum { CMD_AUDIT, CMD_BACKUP, CMD_HEX, CMD_HELP, CMD_SET,
/* standard owner (and administrator) rights */
#define OWNER_RIGHTS (DELETE | READ_CONTROL | WRITE_DAC | WRITE_OWNER \
| SYNCHRONIZE \
| FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES \
| FILE_READ_EA | FILE_WRITE_EA)
#define OWNER_RIGHTS le32_or(DELETE, le32_or(READ_CONTROL, le32_or(WRITE_DAC, le32_or(WRITE_OWNER, \
le32_or(SYNCHRONIZE, \
le32_or(FILE_READ_ATTRIBUTES, le32_or(FILE_WRITE_ATTRIBUTES, \
le32_or(FILE_READ_EA, FILE_WRITE_EA))))))))
/* standard world rights */
#define WORLD_RIGHTS (READ_CONTROL | FILE_READ_ATTRIBUTES | FILE_READ_EA \
| SYNCHRONIZE)
#define WORLD_RIGHTS le32_or(READ_CONTROL, le32_or(FILE_READ_ATTRIBUTES, le32_or(FILE_READ_EA, \
SYNCHRONIZE)))
/* inheritance flags for files and directories */
@ -812,7 +812,7 @@ static unsigned int utf8size(const ntfschar *utf16, int length)
surrog = FALSE;
fail = FALSE;
for (i = 0; i < length && utf16[i] && !fail; i++) {
for (i = 0; i < length && !le16_cmpz(utf16[i]) && !fail; i++) {
unsigned short c = le16_to_cpu(utf16[i]);
if (surrog) {
if ((c >= 0xdc00) && (c < 0xe000)) {
@ -1391,7 +1391,7 @@ static void showace(const char *attr, int off, int isdir, int level)
printf(" grant");
if (attr[off] == 1)
printf(" deny");
if (rights & le32_to_cpu(FILE_GREAD | FILE_GWRITE | FILE_GEXEC)) {
if (rights & le32_to_cpu(le32_or(FILE_GREAD, le32_or(FILE_GWRITE, FILE_GEXEC)))) {
printf(" ");
if (rights & le32_to_cpu(FILE_GREAD))
printf("r");
@ -2399,8 +2399,8 @@ static BOOL restore(FILE *fd)
if (fullname[0]) {
phead = (SECURITY_DESCRIPTOR_RELATIVE*)attr;
/* set the request for auto-inheritance */
if (phead->control & SE_DACL_AUTO_INHERITED)
phead->control |= SE_DACL_AUTO_INHERIT_REQ;
if (!le16_andz(phead->control, SE_DACL_AUTO_INHERITED))
phead->control = le16_or(phead->control, SE_DACL_AUTO_INHERIT_REQ);
if (!applyattr(fullname,attr,withattr,
attrib,key))
errors++;
@ -2670,8 +2670,8 @@ static char *build_dummy_descr(BOOL isdir __attribute__((unused)),
* The flag SE_DACL_PROTECTED prevents the ACL
* to be changed in an inheritance after creation
*/
pnhead->control = SE_DACL_PRESENT | SE_DACL_PROTECTED
| SE_SELF_RELATIVE;
pnhead->control = le16_or(SE_DACL_PRESENT, le16_or(SE_DACL_PROTECTED,
SE_SELF_RELATIVE));
/*
* Windows prefers ACL first, do the same to
* get the same hash value and avoid duplication
@ -3025,11 +3025,11 @@ static void check_samples(void)
(const SID*)owner3, (const SID*)group3,
4,
(int)TRUE, (const SID*)owner3, 0,
le32_to_cpu(FILE_READ_DATA | OWNER_RIGHTS),
le32_to_cpu(le32_or(FILE_READ_DATA, OWNER_RIGHTS)),
(int)TRUE, (const SID*)group3, 0,
le32_to_cpu(FILE_WRITE_DATA),
(int)TRUE, (const SID*)group2, 0,
le32_to_cpu(FILE_WRITE_DATA | FILE_READ_DATA),
le32_to_cpu(le32_or(FILE_WRITE_DATA, FILE_READ_DATA)),
(int)TRUE, (const SID*)worldsid, 0,
le32_to_cpu(FILE_EXECUTE));
expect = 0731;
@ -3706,9 +3706,9 @@ static unsigned int getfull(char *attr, const char *fullname)
memcpy(&attr[attrsz],&part[20],partsz-20);
set4l(&attr[16],(partsz > 20 ? attrsz : 0));
set2l(&attr[2],get2l(attr,2) | (get2l(part,2)
& const_le16_to_cpu(SE_DACL_PROTECTED
| SE_DACL_AUTO_INHERITED
| SE_DACL_PRESENT)));
& const_le16_to_cpu(le16_or(SE_DACL_PROTECTED,
le16_or(SE_DACL_AUTO_INHERITED,
SE_DACL_PRESENT)))));
attrsz += partsz - 20;
} else
overflow = TRUE;
@ -4695,9 +4695,9 @@ static int callback(void *ctx, const ntfschar *ntfsname,
&& (type != 2) /* 2 : dos name (8+3) */
&& (size > 0) /* chars convertible to utf8 */
&& ((length > 2)
|| (ntfsname[0] != const_cpu_to_le16('.'))
|| !le16_eq(ntfsname[0], const_cpu_to_le16('.'))
|| ((length > 1)
&& (ntfsname[1] != const_cpu_to_le16('.'))))) {
&& !le16_eq(ntfsname[1], const_cpu_to_le16('.'))))) {
linkage = (struct LINK*)malloc(sizeof(struct LINK)
+ strlen(dircontext->dir)
+ size + 2);

View File

@ -317,28 +317,28 @@ static void dump_resident_attr_val(ATTR_TYPES type, char *val, u32 val_len)
VOLUME_FLAGS flags;
u32 u;
switch (type) {
case AT_STANDARD_INFORMATION:
/* switch (type) { */
if (le32_eq(type, AT_STANDARD_INFORMATION)) {
// TODO
printf("%s\n", todo);
return;
case AT_ATTRIBUTE_LIST:
} else if (le32_eq(type, AT_ATTRIBUTE_LIST)) {
// TODO
printf("%s\n", todo);
return;
case AT_FILE_NAME:
} else if (le32_eq(type, AT_FILE_NAME)) {
// TODO
printf("%s\n", todo);
return;
case AT_OBJECT_ID:
} else if (le32_eq(type, AT_OBJECT_ID)) {
// TODO
printf("%s\n", todo);
return;
case AT_SECURITY_DESCRIPTOR:
} else if (le32_eq(type, AT_SECURITY_DESCRIPTOR)) {
// TODO
printf("%s\n", todo);
return;
case AT_VOLUME_NAME:
} else if (le32_eq(type, AT_VOLUME_NAME)) {
printf("Volume name length = %u\n", (unsigned int)val_len);
if (val_len) {
buf = calloc(1, val_len);
@ -353,58 +353,58 @@ static void dump_resident_attr_val(ATTR_TYPES type, char *val, u32 val_len)
free(buf);
}
return;
case AT_VOLUME_INFORMATION:
} else if (le32_eq(type, AT_VOLUME_INFORMATION)) {
#define VOL_INF(x) ((VOLUME_INFORMATION *)(x))
printf("NTFS version %i.%i\n", VOL_INF(val)->major_ver,
VOL_INF(val)->minor_ver);
flags = VOL_INF(val)->flags;
#undef VOL_INF
printf("Volume flags = 0x%x: ", le16_to_cpu(flags));
if (!flags) {
if (le16_cmpz(flags)) {
printf("NONE\n");
return;
}
j = 0;
if (flags & VOLUME_MODIFIED_BY_CHKDSK) {
if (!le16_andz(flags, VOLUME_MODIFIED_BY_CHKDSK)) {
j = 1;
printf("VOLUME_MODIFIED_BY_CHKDSK");
}
if (flags & VOLUME_REPAIR_OBJECT_ID) {
if (!le16_andz(flags, VOLUME_REPAIR_OBJECT_ID)) {
if (j)
printf(" | ");
else
j = 0;
printf("VOLUME_REPAIR_OBJECT_ID");
}
if (flags & VOLUME_DELETE_USN_UNDERWAY) {
if (!le16_andz(flags, VOLUME_DELETE_USN_UNDERWAY)) {
if (j)
printf(" | ");
else
j = 0;
printf("VOLUME_DELETE_USN_UNDERWAY");
}
if (flags & VOLUME_MOUNTED_ON_NT4) {
if (!le16_andz(flags, VOLUME_MOUNTED_ON_NT4)) {
if (j)
printf(" | ");
else
j = 0;
printf("VOLUME_MOUNTED_ON_NT4");
}
if (flags & VOLUME_UPGRADE_ON_MOUNT) {
if (!le16_andz(flags, VOLUME_UPGRADE_ON_MOUNT)) {
if (j)
printf(" | ");
else
j = 0;
printf("VOLUME_UPGRADE_ON_MOUNT");
}
if (flags & VOLUME_RESIZE_LOG_FILE) {
if (!le16_andz(flags, VOLUME_RESIZE_LOG_FILE)) {
if (j)
printf(" | ");
else
j = 0;
printf("VOLUME_RESIZE_LOG_FILE");
}
if (flags & VOLUME_IS_DIRTY) {
if (!le16_andz(flags, VOLUME_IS_DIRTY)) {
if (j)
printf(" | ");
else
@ -413,37 +413,37 @@ static void dump_resident_attr_val(ATTR_TYPES type, char *val, u32 val_len)
}
printf("\n");
return;
case AT_DATA:
} else if (le32_eq(type, AT_DATA)) {
printf(skip, "DATA");
return;
case AT_INDEX_ROOT:
} else if (le32_eq(type, AT_INDEX_ROOT)) {
// TODO
printf("%s\n", todo);
return;
case AT_INDEX_ALLOCATION:
} else if (le32_eq(type, AT_INDEX_ALLOCATION)) {
// TODO
printf("%s\n", todo);
return;
case AT_BITMAP:
} else if (le32_eq(type, AT_BITMAP)) {
printf(skip, "BITMAP");
return;
case AT_REPARSE_POINT:
} else if (le32_eq(type, AT_REPARSE_POINT)) {
// TODO
printf("%s\n", todo);
return;
case AT_EA_INFORMATION:
} else if (le32_eq(type, AT_EA_INFORMATION)) {
// TODO
printf("%s\n", don_t_know);
return;
case AT_EA:
} else if (le32_eq(type, AT_EA)) {
// TODO
printf("%s\n", don_t_know);
return;
case AT_LOGGED_UTILITY_STREAM:
} else if (le32_eq(type, AT_LOGGED_UTILITY_STREAM)) {
// TODO
printf("%s\n", don_t_know);
return;
default:
} else {
u = le32_to_cpu(type);
printf("Cannot display unknown %s defined attribute type 0x%x"
".\n", u >=
@ -515,7 +515,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);
@ -536,7 +536,7 @@ static void dump_attr_record(MFT_RECORD *m, ATTR_RECORD *a)
printf("-- Beginning dump of attribute record at offset 0x%x. --\n",
(unsigned)((u8*)a - (u8*)m));
if (a->type == AT_END) {
if (le32_eq(a->type, AT_END)) {
printf("Attribute type = 0x%x ($END)\n",
(unsigned int)le32_to_cpu(AT_END));
u = le32_to_cpu(a->length);
@ -544,10 +544,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]);
@ -582,16 +582,16 @@ static void dump_attr_record(MFT_RECORD *m, ATTR_RECORD *a)
printf("Name = %s\n", s);
}
printf("Attribute flags = 0x%x: ", le16_to_cpu(flags));
if (!flags)
if (le16_cmpz(flags))
printf("NONE");
else {
int first = TRUE;
if (flags & ATTR_COMPRESSION_MASK) {
if (flags & ATTR_IS_COMPRESSED) {
if (!le16_andz(flags, ATTR_COMPRESSION_MASK)) {
if (!le16_andz(flags, ATTR_IS_COMPRESSED)) {
printf("ATTR_IS_COMPRESSED");
first = FALSE;
}
if ((flags & ATTR_COMPRESSION_MASK) & ~ATTR_IS_COMPRESSED) {
if (!le16_andz(le16_and(flags, ATTR_COMPRESSION_MASK), le16_not(ATTR_IS_COMPRESSED))) {
if (!first)
printf(" | ");
else
@ -599,14 +599,14 @@ static void dump_attr_record(MFT_RECORD *m, ATTR_RECORD *a)
printf("ATTR_UNKNOWN_COMPRESSION");
}
}
if (flags & ATTR_IS_ENCRYPTED) {
if (!le16_andz(flags, ATTR_IS_ENCRYPTED)) {
if (!first)
printf(" | ");
else
first = FALSE;
printf("ATTR_IS_ENCRYPTED");
}
if (flags & ATTR_IS_SPARSE) {
if (!le16_andz(flags, ATTR_IS_SPARSE)) {
if (!first)
printf(" | ");
else
@ -647,11 +647,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);
@ -667,9 +667,9 @@ static void dump_mft_record(MFT_RECORD *m)
a = (ATTR_RECORD*)((char*)m + le16_to_cpu(m->attrs_offset));
printf("-- Beginning dump of attributes within mft record. --\n");
while ((char*)a < (char*)m + le32_to_cpu(m->bytes_in_use)) {
if (a->type == attr_type)
if (le32_eq(a->type, attr_type))
dump_attr_record(m, a);
if (a->type == AT_END)
if (le32_eq(a->type, AT_END))
break;
a = (ATTR_RECORD*)((char*)a + le32_to_cpu(a->length));
};

View File

@ -960,7 +960,7 @@ static FILE_NAME_ATTR* verify_parent(struct filename* name, MFT_RECORD* rec)
if (!name || !rec)
return NULL;
if (!(rec->flags & MFT_RECORD_IS_DIRECTORY)) {
if (le16_andz(rec->flags, MFT_RECORD_IS_DIRECTORY)) {
return NULL;
}
@ -1283,8 +1283,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 +
@ -1583,21 +1583,21 @@ 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 |
FILE_ATTR_COMPRESSED | FILE_ATTR_ENCRYPTED))) {
if (le32_andz(f->flags, le32_or(FILE_ATTR_SYSTEM, le32_or(FILE_ATTR_DIRECTORY,
le32_or(FILE_ATTR_SPARSE_FILE, le32_or(FILE_ATTR_REPARSE_POINT,
le32_or(FILE_ATTR_COMPRESSED, FILE_ATTR_ENCRYPTED))))))) {
ntfs_log_quiet("%s", NONE);
}
@ -2008,7 +2008,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);

View File

@ -779,7 +779,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;
@ -839,7 +839,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);
@ -899,7 +899,7 @@ static s64 wipe_tails(ntfs_volume *vol, int byte, enum action act)
continue;
}
if (ni->mrec->base_mft_record) {
if (!le64_cmpz(ni->mrec->base_mft_record)) {
ntfs_log_verbose("Not base mft record. Skipping\n");
goto close_inode;
}
@ -914,7 +914,7 @@ static s64 wipe_tails(ntfs_volume *vol, int byte, enum action act)
NULL, 0, ctx)) {
a = ctx->attr;
if (!ctx->al_entry || !ctx->al_entry->lowest_vcn) {
if (!ctx->al_entry || sle64_cmpz(ctx->al_entry->lowest_vcn)) {
name = (ntfschar*)((u8*)a
+ le16_to_cpu(a->name_offset));
attr_wiped = wipe_attr_tail(ni, name,
@ -1271,7 +1271,7 @@ static s64 wipe_directory(ntfs_volume *vol, int byte, enum action act)
continue;
}
if (ni->mrec->base_mft_record) {
if (!le64_cmpz(ni->mrec->base_mft_record)) {
if (opts.verbose > 2)
ntfs_log_verbose("Not base mft record. Skipping\n");
else
@ -2174,7 +2174,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) {

View File

@ -188,30 +188,30 @@ static BOOL valid_type(ATTR_TYPES type)
{
BOOL ok;
switch (type) {
case AT_STANDARD_INFORMATION :
case AT_ATTRIBUTE_LIST :
case AT_FILE_NAME :
case AT_OBJECT_ID :
case AT_SECURITY_DESCRIPTOR :
case AT_VOLUME_NAME :
case AT_VOLUME_INFORMATION :
case AT_DATA :
case AT_INDEX_ROOT :
case AT_INDEX_ALLOCATION :
case AT_BITMAP :
case AT_REPARSE_POINT :
case AT_EA_INFORMATION :
case AT_EA :
case AT_PROPERTY_SET :
case AT_LOGGED_UTILITY_STREAM :
case AT_FIRST_USER_DEFINED_ATTRIBUTE :
case AT_END :
if (le32_eq(type, AT_STANDARD_INFORMATION) ||
le32_eq(type, AT_ATTRIBUTE_LIST) ||
le32_eq(type, AT_FILE_NAME) ||
le32_eq(type, AT_OBJECT_ID) ||
le32_eq(type, AT_SECURITY_DESCRIPTOR) ||
le32_eq(type, AT_VOLUME_NAME) ||
le32_eq(type, AT_VOLUME_INFORMATION) ||
le32_eq(type, AT_DATA) ||
le32_eq(type, AT_INDEX_ROOT) ||
le32_eq(type, AT_INDEX_ALLOCATION) ||
le32_eq(type, AT_BITMAP) ||
le32_eq(type, AT_REPARSE_POINT) ||
le32_eq(type, AT_EA_INFORMATION) ||
le32_eq(type, AT_EA) ||
le32_eq(type, AT_PROPERTY_SET) ||
le32_eq(type, AT_LOGGED_UTILITY_STREAM) ||
le32_eq(type, AT_FIRST_USER_DEFINED_ATTRIBUTE) ||
le32_eq(type, AT_END))
{
ok = TRUE;
break;
default :
}
else {
ok = FALSE;
break;
/* break; */
}
return (ok);
}
@ -276,7 +276,7 @@ static int sanity_indx_list(const char *buffer, u32 k, u32 end)
err = 1;
}
}
done = (feedle16(buffer,k+12) & INDEX_ENTRY_END) || !lth;
done = !le16_andz(feedle16(buffer,k+12), INDEX_ENTRY_END) || !lth;
if (lth & 7) {
if (optv <= 1) /* Do not repeat the warning */
printf("** Invalid index record length %d\n",
@ -321,7 +321,7 @@ static int sanity_mft(const char *buffer)
attr = (const ATTR_RECORD*)&buffer[k];
prevtype = 0;
while ((k < mftrecsz)
&& (attr->type != AT_END)
&& !le32_eq(attr->type, AT_END)
&& valid_type(attr->type)) {
type = le32_to_cpu(attr->type);
if (type < prevtype) {
@ -345,7 +345,7 @@ static int sanity_mft(const char *buffer)
instances |= (u64)1 << instance;
}
if (optv > 1) {
if ((attr->type == AT_FILE_NAME)
if (le32_eq(attr->type, AT_FILE_NAME)
&& buffer[k + 88]) {
printf("attr %08lx offs 0x%x nres %d",
(long)type, (int)k,
@ -357,7 +357,7 @@ static int sanity_mft(const char *buffer)
(long)type, (int)k,
(int)attr->non_resident);
}
if ((attr->type == AT_INDEX_ROOT)
if (le32_eq(attr->type, AT_INDEX_ROOT)
&& sanity_indx_list(buffer,
k + le16_to_cpu(attr->value_offset) + 32,
k + le32_to_cpu(attr->length))) {
@ -367,10 +367,10 @@ static int sanity_mft(const char *buffer)
attr = (const ATTR_RECORD*)&buffer[k];
prevtype = type;
}
if ((optv > 1) && (attr->type == AT_END))
if ((optv > 1) && le32_eq(attr->type, AT_END))
printf("attr %08lx offs 0x%x\n",
(long)le32_to_cpu(attr->type), (int)k);
if ((attr->type != AT_END)
if (!le32_eq(attr->type, AT_END)
|| (le32_to_cpu(record->bytes_in_use) != (k + 8))
|| (le32_to_cpu(record->bytes_allocated) < (k + 8))) {
printf("** Bad MFT record length %ld"
@ -773,7 +773,7 @@ static void adjust_instance(const ATTR_RECORD *attr, MFT_RECORD *entry, int incr
if (increment > 0) {
/* Allocating a new instance ? */
if (attr->instance == entry->next_attr_instance) {
if (le16_eq(attr->instance, entry->next_attr_instance)) {
instance = (le16_to_cpu(entry->next_attr_instance)
+ 1) & 0xffff;
entry->next_attr_instance = cpu_to_le16(instance);
@ -783,7 +783,7 @@ static void adjust_instance(const ATTR_RECORD *attr, MFT_RECORD *entry, int incr
/* Freeing the latest instance ? */
instance = (le16_to_cpu(entry->next_attr_instance)
- 1) & 0xffff;
if (attr->instance == cpu_to_le16(instance))
if (le16_eq(attr->instance, cpu_to_le16(instance)))
entry->next_attr_instance = attr->instance;
}
}
@ -846,7 +846,7 @@ static BOOL index_match_undo(const char *first, const char *second, int length)
dump(second,length);
}
len = (first[80] & 255)*2 + 2;
match = (feedle64(first, 16) == feedle64(second, 16))
match = le64_eq(feedle64(first, 16), feedle64(second, 16))
&& !memcmp(first + 80, second + 80, len);
if (match && optv)
printf("However parent dir and name do match\n");
@ -869,7 +869,7 @@ static int change_resident(ntfs_volume *vol, const struct ACTION_RECORD *action,
int changed;
err = 1;
if (action->record.undo_length != action->record.redo_length)
if (!le16_eq(action->record.undo_length, action->record.redo_length))
printf("** Error size change in change_resident\n");
if (optv > 1) {
lcn = sle64_to_cpu(action->record.lcn_list[0]);
@ -923,7 +923,7 @@ static int change_resident_expect(ntfs_volume *vol, const struct ACTION_RECORD *
BOOL found;
err = 1;
if (action->record.undo_length != action->record.redo_length)
if (!le16_eq(action->record.undo_length, action->record.redo_length))
printf("** Error size change in change_resident\n");
if (optv > 1) {
lcn = sle64_to_cpu(action->record.lcn_list[0]);
@ -939,7 +939,7 @@ static int change_resident_expect(ntfs_volume *vol, const struct ACTION_RECORD *
printf("-> full record :\n");
dump((char*)attr, le32_to_cpu(attr->length));
}
if ((attr->type == type)
if (le32_eq(attr->type, type)
&& !(length & 7)
&& ((target + length) <= mftrecsz)) {
found = !memcmp(buffer + target, expected, length);
@ -1223,15 +1223,15 @@ static int insert_resident(ntfs_volume *vol, const struct ACTION_RECORD *action,
newused = le32_to_cpu(entry->bytes_in_use)
+ length;
entry->bytes_in_use = cpu_to_le32(newused);
if (action->record.redo_operation
== const_cpu_to_le16(CreateAttribute)) {
if (le16_eq(action->record.redo_operation,
const_cpu_to_le16(CreateAttribute))) {
/*
* For a real create, may have to adjust
* the next attribute instance
*/
adjust_instance(newattr, entry, 1);
}
if (newattr->type == AT_FILE_NAME) {
if (le32_eq(newattr->type, AT_FILE_NAME)) {
links = le16_to_cpu(entry->link_count) + 1;
entry->link_count = cpu_to_le16(links);
}
@ -1286,7 +1286,7 @@ static int remove_resident(ntfs_volume *vol, const struct ACTION_RECORD *action,
&& ((target + length) <= mftrecsz)) {
/* This has to be an idempotent action */
/* For AT_DATA the value is not always present */
if (attr->type == AT_DATA)
if (le32_eq(attr->type, AT_DATA))
found = !memcmp(buffer + target, data,
le16_to_cpu(attr->value_offset));
else
@ -1307,12 +1307,12 @@ static int remove_resident(ntfs_volume *vol, const struct ACTION_RECORD *action,
}
err = 0;
if (found) {
if (attr->type == AT_FILE_NAME) {
if (le32_eq(attr->type, AT_FILE_NAME)) {
links = le16_to_cpu(entry->link_count) - 1;
entry->link_count = cpu_to_le16(links);
}
if (action->record.redo_operation
== const_cpu_to_le16(CreateAttribute)) {
if (le16_eq(action->record.redo_operation,
const_cpu_to_le16(CreateAttribute))) {
adjust_instance(attr, entry, -1);
}
/* Remove the entry */
@ -1503,7 +1503,7 @@ static int update_index(ntfs_volume *vol, const struct ACTION_RECORD *action,
printf("-> existing index :\n");
dump(&buffer[target], length);
}
if ((indx->magic == magic_INDX)
if (le32_eq(indx->magic, magic_INDX)
&& !(length & 7)
&& ((target + length) <= xsize)) {
/* This has to be an idempotent action */
@ -1547,7 +1547,7 @@ static int delete_names(char *buffer)
do {
attr = (ATTR_RECORD*)&buffer[pos];
length = le32_to_cpu(attr->length);
if (attr->type == AT_FILE_NAME) {
if (le32_eq(attr->type, AT_FILE_NAME)) {
if (optv)
showname("Controversial deletion of ",
&buffer[pos+90], buffer[pos+88] & 255);
@ -1634,7 +1634,7 @@ static int insert_index_allocation(ntfs_volume *vol, char *buffer, u32 offs)
length = le32_to_cpu(attr->length);
addedlength = length - 8 /* index allocation */
+ length - 48; /* bitmap */
if ((attr->type == AT_INDEX_ROOT)
if (le32_eq(attr->type, AT_INDEX_ROOT)
&& ((pos + length) == offs)
&& ((used + addedlength) < mftrecsz)) {
/* Make space for the attribute */
@ -1722,9 +1722,9 @@ static BOOL check_full_mft(const struct ACTION_RECORD *action, BOOL redoing)
length = le16_to_cpu(action->record.undo_length);
}
/* The length in use must be fed */
ok = !action->record.record_offset
&& !action->record.attribute_offset
&& (record->magic == magic_FILE)
ok = le16_cmpz(action->record.record_offset)
&& le16_cmpz(action->record.attribute_offset)
&& le32_eq(record->magic, magic_FILE)
&& (length <= mftrecsz)
&& (length >= (offsetof(MFT_RECORD, bytes_in_use)
+ sizeof(record->bytes_in_use)));
@ -1732,14 +1732,14 @@ static BOOL check_full_mft(const struct ACTION_RECORD *action, BOOL redoing)
k = le16_to_cpu(record->attrs_offset);
attr = (const ATTR_RECORD*)((const char*)record + k);
while (((k + sizeof(attr->type)) <= length)
&& (attr->type != AT_END)
&& !le32_eq(attr->type, AT_END)
&& valid_type(attr->type)) {
k += le32_to_cpu(attr->length);
attr = (const ATTR_RECORD*)((const char*)record + k);
}
/* AT_END must be present */
ok = ((k + sizeof(attr->type)) <= length)
&& (attr->type == AT_END);
&& le32_eq(attr->type, AT_END);
}
return (ok);
}
@ -1765,9 +1765,9 @@ static BOOL check_full_index(const struct ACTION_RECORD *action, BOOL redoing)
length = le16_to_cpu(action->record.undo_length);
}
/* the index length must be fed, so must be the full index block */
return (!action->record.record_offset
&& !action->record.attribute_offset
&& (indx->magic == magic_INDX)
return (le16_cmpz(action->record.record_offset)
&& le16_cmpz(action->record.attribute_offset)
&& le32_eq(indx->magic, magic_INDX)
&& (length >= (offsetof(INDEX_BLOCK, index.index_length) + 4))
&& (length >= (le32_to_cpu(indx->index.index_length) + 24)));
}
@ -1890,7 +1890,7 @@ static int redo_add_index(ntfs_volume *vol, const struct ACTION_RECORD *action,
printf("-> existing record :\n");
dump(&buffer[target], length);
}
if ((indx->magic == magic_INDX)
if (le32_eq(indx->magic, magic_INDX)
&& !(length & 7)
&& ((target + length) <= xsize)) {
/* This has to be an idempotent action */
@ -1956,7 +1956,7 @@ static int redo_add_root_index(ntfs_volume *vol,
printf("existing index :\n");
dump(buffer + target,length);
}
if ((attr->type == AT_INDEX_ROOT)
if (le32_eq(attr->type, AT_INDEX_ROOT)
&& !(length & 7)
&& ((target + length) <= mftrecsz)) {
/* This has to be an idempotent action */
@ -2033,9 +2033,9 @@ static int redo_create_file(ntfs_volume *vol,
if ((target + length) <= mftrecsz) {
changed = memcmp(buffer + target, data, length);
err = 0;
if (changed || !(record->flags & MFT_RECORD_IN_USE)) {
if (changed || le16_andz(record->flags, MFT_RECORD_IN_USE)) {
memcpy(buffer + target, data, length);
record->flags |= MFT_RECORD_IN_USE;
record->flags = le16_or(record->flags, MFT_RECORD_IN_USE);
if (optv > 1) {
printf("-> new record :\n");
dump(buffer,mftrecsz);
@ -2070,7 +2070,7 @@ static int redo_create_attribute(ntfs_volume *vol,
target = le16_to_cpu(action->record.record_offset)
+ le16_to_cpu(action->record.attribute_offset);
// Could also be AT_DATA or AT_INDEX_ALLOCATION
if (!action->record.undo_length)
if (le16_cmpz(action->record.undo_length))
err = insert_resident(vol, action, buffer, data,
target, length);
return (err);
@ -2092,7 +2092,7 @@ static int redo_delete_attribute(ntfs_volume *vol,
length = le16_to_cpu(action->record.undo_length);
target = le16_to_cpu(action->record.record_offset)
+ le16_to_cpu(action->record.attribute_offset);
if (!action->record.redo_length)
if (le16_cmpz(action->record.redo_length))
err = remove_resident(vol, action, buffer, data,
target, length);
return (err);
@ -2131,11 +2131,11 @@ static int redo_delete_file(ntfs_volume *vol,
if ((target + length) <= mftrecsz) {
/* write a void mft entry (needed ?) */
changed = (length && memcmp(buffer + target, data, length))
|| (record->flags & MFT_RECORD_IN_USE);
|| !le16_andz(record->flags, MFT_RECORD_IN_USE);
err = 0;
if (changed) {
memcpy(buffer + target, data, length);
record->flags &= ~MFT_RECORD_IN_USE;
record->flags = le16_and(record->flags, le16_not(MFT_RECORD_IN_USE));
if (optv > 1) {
printf("-> new record :\n");
dump(buffer,mftrecsz);
@ -2184,7 +2184,7 @@ static int redo_delete_index(ntfs_volume *vol,
printf("-> existing record :\n");
dump(&buffer[target], length);
}
if ((indx->magic == magic_INDX)
if (le32_eq(indx->magic, magic_INDX)
&& !(length & 7)
&& ((target + length) <= xsize)) {
/* This has to be an idempotent action */
@ -2248,7 +2248,7 @@ static int redo_delete_root_index(ntfs_volume *vol,
printf("existing index :\n");
dump(buffer + target,length);
}
if ((attr->type == AT_INDEX_ROOT)
if (le32_eq(attr->type, AT_INDEX_ROOT)
&& !(length & 7)
&& ((target + length) <= mftrecsz)) {
/* This has to be an idempotent action */
@ -2297,8 +2297,8 @@ static int redo_force_bits(ntfs_volume *vol,
+ get_redo_offset(&action->record));
firstbit = le32_to_cpu(data->firstbit);
count = le32_to_cpu(data->count);
if (action->record.redo_operation
== const_cpu_to_le16(SetBitsInNonResidentBitMap))
if (le16_eq(action->record.redo_operation,
const_cpu_to_le16(SetBitsInNonResidentBitMap)))
wanted = 1;
else
wanted = 0;
@ -2342,7 +2342,7 @@ static int redo_open_attribute(ntfs_volume *vol __attribute__((unused)),
+ get_redo_offset(&action->record);
length = le16_to_cpu(action->record.redo_length);
extra = get_extra_offset(&action->record);
if (action->record.undo_length) {
if (!le16_cmpz(action->record.undo_length)) {
name = ((const char*)&action->record) + extra;
namelen = le32_to_cpu(action->record.client_data_length)
+ LOG_RECORD_HEAD_SZ - extra;
@ -2371,13 +2371,13 @@ static int redo_open_attribute(ntfs_volume *vol __attribute__((unused)),
/* Badly aligned */
memcpy(&inode, &attr_old->inode, 8);
err = (MREF(le64_to_cpu(inode)) != pa->inode)
|| (attr_old->type != pa->type);
|| !le32_eq(attr_old->type, pa->type);
break;
case sizeof(ATTR_NEW) :
attr_new = (const ATTR_NEW*)data;
err = (MREF(le64_to_cpu(attr_new->inode))
!= pa->inode)
|| (attr_new->type != pa->type);
|| !le32_eq(attr_new->type, pa->type);
break;
default : err = 1;
}
@ -2868,14 +2868,14 @@ static int redo_write_index(ntfs_volume *vol,
}
xsize = vol->indx_record_size;
indx = (INDEX_BLOCK*)buffer;
if (action->record.record_offset) {
if (!le16_cmpz(action->record.record_offset)) {
printf("** Non-null record_offset in redo_write_index()\n");
}
if (optv > 1) {
printf("-> existing index :\n");
dump(&buffer[target], length);
}
if ((indx->magic == magic_INDX)
if (le32_eq(indx->magic, magic_INDX)
&& !(length & 7)
&& ((target + length) <= xsize)) {
/* This has to be an idempotent action */
@ -2962,7 +2962,7 @@ static int undo_add_index(ntfs_volume *vol,
printf("-> existing record :\n");
dump(&buffer[target], length);
}
if ((indx->magic == magic_INDX)
if (le32_eq(indx->magic, magic_INDX)
&& !(length & 7)
&& ((target + length) <= xsize)) {
/* This has to be an idempotent action */
@ -3027,7 +3027,7 @@ static int undo_add_root_index(ntfs_volume *vol,
printf("existing index :\n");
dump(buffer + target,length);
}
if ((attr->type == AT_INDEX_ROOT)
if (le32_eq(attr->type, AT_INDEX_ROOT)
&& !(length & 7)
&& ((target + length) <= mftrecsz)) {
/* This has to be an idempotent action */
@ -3070,7 +3070,7 @@ static int undo_create_attribute(ntfs_volume *vol,
length = le16_to_cpu(action->record.redo_length);
target = le16_to_cpu(action->record.record_offset)
+ le16_to_cpu(action->record.attribute_offset);
if (!action->record.undo_length)
if (le16_cmpz(action->record.undo_length))
err = remove_resident(vol, action, buffer, data,
target, length);
return (err);
@ -3092,7 +3092,7 @@ static int undo_delete_attribute(ntfs_volume *vol,
length = le16_to_cpu(action->record.undo_length);
target = le16_to_cpu(action->record.record_offset)
+ le16_to_cpu(action->record.attribute_offset);
if (!action->record.redo_length)
if (le16_cmpz(action->record.redo_length))
err = insert_resident(vol, action, buffer, data,
target, length);
return (err);
@ -3132,7 +3132,7 @@ static int undo_delete_index(ntfs_volume *vol,
printf("-> existing record :\n");
dump(&buffer[target], length);
}
if ((indx->magic == magic_INDX)
if (le32_eq(indx->magic, magic_INDX)
&& !(length & 7)
&& ((target + length) <= xsize)
&& !sanity_indx(vol,buffer)) {
@ -3197,7 +3197,7 @@ static int undo_delete_root_index(ntfs_volume *vol,
+ le16_to_cpu(action->record.record_offset));
index = (INDEX_ROOT*)(((char*)attr)
+ le16_to_cpu(attr->value_offset));
if (attr->type != AT_INDEX_ROOT) {
if (!le32_eq(attr->type, AT_INDEX_ROOT)) {
printf("** Unexpected attr type 0x%lx\n",
(long)le32_to_cpu(attr->type));
printf("existing mft\n");
@ -3209,7 +3209,7 @@ static int undo_delete_root_index(ntfs_volume *vol,
printf("existing index :\n");
dump(buffer + target,length);
}
if ((attr->type == AT_INDEX_ROOT)
if (le32_eq(attr->type, AT_INDEX_ROOT)
&& !(length & 7)
&& ((target + length) <= mftrecsz)) {
/* This has to be an idempotent action */
@ -3272,9 +3272,9 @@ static int undo_create_file(ntfs_volume *vol,
if ((target + length) <= mftrecsz) {
changed = memcmp(buffer + target, data, length);
err = 0;
if (changed || (record->flags & MFT_RECORD_IN_USE)) {
if (changed || !le16_andz(record->flags, MFT_RECORD_IN_USE)) {
memcpy(buffer + target, data, length);
record->flags &= ~MFT_RECORD_IN_USE;
record->flags = le16_and(record->flags, le16_not(MFT_RECORD_IN_USE));
if (optv > 1) {
printf("-> new record :\n");
dump(buffer,mftrecsz);
@ -3322,7 +3322,7 @@ static int undo_delete_file(ntfs_volume *vol,
record = (MFT_RECORD*)buffer;
if ((target + length) <= mftrecsz) {
changed = memcmp(buffer + target, data, length)
|| !(record->flags & MFT_RECORD_IN_USE);
|| le16_andz(record->flags, MFT_RECORD_IN_USE);
err = 0;
if (changed) {
memcpy(buffer + target, data, length);
@ -3338,10 +3338,10 @@ static int undo_delete_file(ntfs_volume *vol,
* the record now appears to not be in use and there are
* links.
*/
if (record->link_count
&& !(record->flags & MFT_RECORD_IN_USE))
if (!le16_cmpz(record->link_count)
&& le16_andz(record->flags, MFT_RECORD_IN_USE))
err = delete_names(buffer);
record->flags |= MFT_RECORD_IN_USE;
record->flags = le16_or(record->flags, MFT_RECORD_IN_USE);
if (optv > 1) {
printf("-> new record :\n");
dump(buffer,mftrecsz);
@ -3378,8 +3378,8 @@ static int undo_force_bits(ntfs_volume *vol,
+ get_redo_offset(&action->record));
firstbit = le32_to_cpu(data->firstbit);
count = le32_to_cpu(data->count);
if (action->record.redo_operation
== const_cpu_to_le16(SetBitsInNonResidentBitMap))
if (le16_eq(action->record.redo_operation,
const_cpu_to_le16(SetBitsInNonResidentBitMap)))
wanted = 0;
else
wanted = 1;
@ -3423,7 +3423,7 @@ static int undo_open_attribute(ntfs_volume *vol __attribute__((unused)),
+ get_redo_offset(&action->record);
length = le16_to_cpu(action->record.redo_length);
extra = get_extra_offset(&action->record);
if (action->record.undo_length) {
if (!le16_cmpz(action->record.undo_length)) {
name = ((const char*)&action->record) + extra;
namelen = le32_to_cpu(action->record.client_data_length)
+ LOG_RECORD_HEAD_SZ - extra;
@ -3448,12 +3448,12 @@ static int undo_open_attribute(ntfs_volume *vol __attribute__((unused)),
/* Badly aligned */
memcpy(&inode, &attr_old->inode, 8);
err = (MREF(le64_to_cpu(inode)) != pa->inode)
|| (attr_old->type != pa->type);
|| !le32_eq(attr_old->type, pa->type);
break;
case sizeof(ATTR_NEW) :
attr_new = (const ATTR_NEW*)data;
err = (MREF(le64_to_cpu(attr_new->inode))!= pa->inode)
|| (attr_new->type != pa->type);
|| !le32_eq(attr_new->type, pa->type);
break;
default : err = 1;
}
@ -3493,14 +3493,14 @@ static int undo_sizes(ntfs_volume *vol,
+ le16_to_cpu(action->record.attribute_offset)
+ offsetof(ATTR_RECORD, allocated_size);
entry = (MFT_RECORD*)buffer;
if (!(entry->flags & MFT_RECORD_IS_DIRECTORY))
if (le16_andz(entry->flags, MFT_RECORD_IS_DIRECTORY))
err = change_resident(vol, action, buffer,
data, target, length);
else {
/* On a directory, may have to build an index allocation */
offs = le16_to_cpu(action->record.record_offset);
attr = (ATTR_RECORD*)(buffer + offs);
if (attr->type != AT_INDEX_ALLOCATION) {
if (!le32_eq(attr->type, AT_INDEX_ALLOCATION)) {
err = insert_index_allocation(vol, buffer, offs);
if (!err)
err = change_resident(vol, action, buffer,
@ -4022,12 +4022,13 @@ static enum ACTION_KIND get_action_kind(const struct ACTION_RECORD *action)
* Unfortunately, only on some cases we can determine
* the action was defined by Win10 (or subsequent).
*/
if (action->record.log_record_flags
& (LOG_RECORD_DELETING | LOG_RECORD_ADDING)) {
if (action->record.attribute_flags & ACTS_ON_INDX)
if (!le16_andz(action->record.log_record_flags,
le16_or(LOG_RECORD_DELETING, LOG_RECORD_ADDING))) {
if (!le16_andz(action->record.attribute_flags, ACTS_ON_INDX))
kind = ON_INDX;
else
if (action->record.attribute_flags & ACTS_ON_MFT)
if (!le16_andz(action->record.attribute_flags,
ACTS_ON_MFT))
kind = ON_MFT;
else
kind = ON_RAW;
@ -4038,7 +4039,7 @@ static enum ACTION_KIND get_action_kind(const struct ACTION_RECORD *action)
*/
pa = getattrentry(le16_to_cpu(
action->record.target_attribute),0);
if (!pa || !pa->type) {
if (!pa || le32_cmpz(pa->type)) {
/*
* Even when the attribute has not been recorded,
* we can sometimes tell the record does not apply
@ -4050,8 +4051,8 @@ static enum ACTION_KIND get_action_kind(const struct ACTION_RECORD *action)
*/
data = (const char*)&action->record
+ get_redo_offset(&action->record);
if (action->record.record_offset
|| (!action->record.attribute_offset
if (!le16_cmpz(action->record.record_offset)
|| (le16_cmpz(action->record.attribute_offset)
&& (le16_to_cpu(action->record.redo_length)
>= 4)
&& memcmp(data,"FILE",4)
@ -4065,7 +4066,7 @@ static enum ACTION_KIND get_action_kind(const struct ACTION_RECORD *action)
kind = ON_NONE;
}
} else {
if (pa->type == AT_INDEX_ALLOCATION)
if (le32_eq(pa->type, AT_INDEX_ALLOCATION))
kind = ON_INDX;
else
kind = ON_RAW;
@ -4104,113 +4105,113 @@ static int distribute_redos(ntfs_volume *vol,
uop = le16_to_cpu(action->record.undo_operation);
switch (rop) {
case AddIndexEntryAllocation :
if (action->record.undo_operation
== const_cpu_to_le16(DeleteIndexEntryAllocation))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(DeleteIndexEntryAllocation)))
err = redo_add_index(vol, action, buffer);
break;
case AddIndexEntryRoot :
if (action->record.undo_operation
== const_cpu_to_le16(DeleteIndexEntryRoot))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(DeleteIndexEntryRoot)))
err = redo_add_root_index(vol, action, buffer);
break;
case ClearBitsInNonResidentBitMap :
if ((action->record.undo_operation
== const_cpu_to_le16(SetBitsInNonResidentBitMap))
|| (action->record.undo_operation
== const_cpu_to_le16(CompensationlogRecord)))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(SetBitsInNonResidentBitMap))
|| le16_eq(action->record.undo_operation,
const_cpu_to_le16(CompensationlogRecord)))
err = redo_force_bits(vol, action, buffer);
break;
case CompensationlogRecord :
if (action->record.undo_operation
== const_cpu_to_le16(Noop))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(Noop)))
err = redo_compensate(vol, action, buffer);
break;
case CreateAttribute :
if ((action->record.undo_operation
== const_cpu_to_le16(DeleteAttribute))
|| (action->record.undo_operation
== const_cpu_to_le16(CompensationlogRecord)))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(DeleteAttribute))
|| le16_eq(action->record.undo_operation,
const_cpu_to_le16(CompensationlogRecord)))
err = redo_create_attribute(vol, action, buffer);
break;
case DeallocateFileRecordSegment :
if ((action->record.undo_operation
== const_cpu_to_le16(InitializeFileRecordSegment))
|| (action->record.undo_operation
== const_cpu_to_le16(CompensationlogRecord)))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(InitializeFileRecordSegment))
|| le16_eq(action->record.undo_operation,
const_cpu_to_le16(CompensationlogRecord)))
err = redo_delete_file(vol, action, buffer);
break;
case DeleteAttribute :
if ((action->record.undo_operation
== const_cpu_to_le16(CreateAttribute))
|| (action->record.undo_operation
== const_cpu_to_le16(CompensationlogRecord)))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(CreateAttribute))
|| le16_eq(action->record.undo_operation,
const_cpu_to_le16(CompensationlogRecord)))
err = redo_delete_attribute(vol, action, buffer);
break;
case DeleteIndexEntryAllocation :
if ((action->record.undo_operation
== const_cpu_to_le16(AddIndexEntryAllocation))
|| (action->record.undo_operation
== const_cpu_to_le16(CompensationlogRecord)))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(AddIndexEntryAllocation))
|| le16_eq(action->record.undo_operation,
const_cpu_to_le16(CompensationlogRecord)))
err = redo_delete_index(vol, action, buffer);
break;
case DeleteIndexEntryRoot :
if ((action->record.undo_operation
== const_cpu_to_le16(AddIndexEntryRoot))
|| (action->record.undo_operation
== const_cpu_to_le16(CompensationlogRecord)))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(AddIndexEntryRoot))
|| le16_eq(action->record.undo_operation,
const_cpu_to_le16(CompensationlogRecord)))
err = redo_delete_root_index(vol, action, buffer);
break;
case InitializeFileRecordSegment :
if (action->record.undo_operation
== const_cpu_to_le16(Noop))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(Noop)))
err = redo_create_file(vol, action, buffer);
break;
case OpenNonResidentAttribute :
if (action->record.undo_operation
== const_cpu_to_le16(Noop))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(Noop)))
err = redo_open_attribute(vol, action);
break;
case SetBitsInNonResidentBitMap :
if (action->record.undo_operation
== const_cpu_to_le16(ClearBitsInNonResidentBitMap))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(ClearBitsInNonResidentBitMap)))
err = redo_force_bits(vol, action, buffer);
break;
case SetIndexEntryVcnAllocation :
if ((action->record.undo_operation
== const_cpu_to_le16(SetIndexEntryVcnAllocation))
|| (action->record.undo_operation
== const_cpu_to_le16(CompensationlogRecord)))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(SetIndexEntryVcnAllocation))
|| le16_eq(action->record.undo_operation,
const_cpu_to_le16(CompensationlogRecord)))
err = redo_update_vcn(vol, action, buffer);
break;
case SetIndexEntryVcnRoot :
if (action->record.undo_operation
== const_cpu_to_le16(SetIndexEntryVcnRoot))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(SetIndexEntryVcnRoot)))
err = redo_update_root_vcn(vol, action, buffer);
break;
case SetNewAttributeSizes :
if ((action->record.undo_operation
== const_cpu_to_le16(SetNewAttributeSizes))
|| (action->record.undo_operation
== const_cpu_to_le16(CompensationlogRecord)))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(SetNewAttributeSizes))
|| le16_eq(action->record.undo_operation,
const_cpu_to_le16(CompensationlogRecord)))
err = redo_sizes(vol, action, buffer);
break;
case UpdateFileNameAllocation :
if ((action->record.undo_operation
== const_cpu_to_le16(UpdateFileNameAllocation))
|| (action->record.undo_operation
== const_cpu_to_le16(CompensationlogRecord)))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(UpdateFileNameAllocation))
|| le16_eq(action->record.undo_operation,
const_cpu_to_le16(CompensationlogRecord)))
err = redo_update_index(vol, action, buffer);
break;
case UpdateFileNameRoot :
if ((action->record.undo_operation
== const_cpu_to_le16(UpdateFileNameRoot))
|| (action->record.undo_operation
== const_cpu_to_le16(CompensationlogRecord)))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(UpdateFileNameRoot))
|| le16_eq(action->record.undo_operation,
const_cpu_to_le16(CompensationlogRecord)))
err = redo_update_root_index(vol, action, buffer);
break;
case UpdateMappingPairs :
if (action->record.undo_operation
== const_cpu_to_le16(UpdateMappingPairs))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(UpdateMappingPairs)))
err = redo_update_mapping(vol, action, buffer);
break;
case UpdateNonResidentValue :
@ -4227,27 +4228,27 @@ static int distribute_redos(ntfs_volume *vol,
}
break;
case UpdateResidentValue :
if ((action->record.undo_operation
== const_cpu_to_le16(UpdateResidentValue))
|| (action->record.undo_operation
== const_cpu_to_le16(CompensationlogRecord)))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(UpdateResidentValue))
|| le16_eq(action->record.undo_operation,
const_cpu_to_le16(CompensationlogRecord)))
err = redo_update_resident(vol, action, buffer);
break;
case Win10Action37 :
if (action->record.undo_operation
== const_cpu_to_le16(Noop))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(Noop)))
err = redo_action37(vol, action, buffer);
break;
case WriteEndofFileRecordSegment :
if (action->record.undo_operation
== const_cpu_to_le16(WriteEndofFileRecordSegment))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(WriteEndofFileRecordSegment)))
err = redo_write_end(vol, action, buffer);
break;
case WriteEndOfIndexBuffer :
if ((action->record.undo_operation
== const_cpu_to_le16(WriteEndOfIndexBuffer))
|| (action->record.undo_operation
== const_cpu_to_le16(CompensationlogRecord)))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(WriteEndOfIndexBuffer))
|| le16_eq(action->record.undo_operation,
const_cpu_to_le16(CompensationlogRecord)))
err = redo_write_index(vol, action, buffer);
break;
case AttributeNamesDump :
@ -4388,7 +4389,7 @@ printf("** %s (action %d) not acting on MFT\n",actionname(rop),(int)action->num)
buffer = read_protected(vol, &action->record,
mftrecsz, warn);
entry = (MFT_RECORD*)buffer;
if (entry && (entry->magic == magic_FILE)) {
if (entry && le32_eq(entry->magic, magic_FILE)) {
data_lsn = sle64_to_cpu(entry->lsn);
/*
* Beware of records not updated
@ -4430,7 +4431,7 @@ printf("** %s (action %d) not acting on INDX\n",actionname(rop),(int)action->num
buffer = read_protected(vol, &action->record,
xsize, warn);
indx = (INDEX_BLOCK*)buffer;
if (indx && (indx->magic == magic_INDX)) {
if (indx && le32_eq(indx->magic, magic_INDX)) {
data_lsn = sle64_to_cpu(indx->lsn);
/*
* Beware of records not updated
@ -4460,8 +4461,8 @@ printf("** %s (action %d) not acting on INDX\n",actionname(rop),(int)action->num
}
break;
case ON_RAW :
if (action->record.attribute_flags
& (ACTS_ON_INDX | ACTS_ON_MFT)) {
if (!le16_andz(action->record.attribute_flags,
le16_or(ACTS_ON_INDX, ACTS_ON_MFT))) {
printf("** Error : action %s on MFT"
" or INDX\n",
actionname(rop));
@ -4528,88 +4529,88 @@ static int distribute_undos(ntfs_volume *vol, const struct ACTION_RECORD *action
uop = le16_to_cpu(action->record.undo_operation);
switch (rop) {
case AddIndexEntryAllocation :
if (action->record.undo_operation
== const_cpu_to_le16(DeleteIndexEntryAllocation))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(DeleteIndexEntryAllocation)))
err = undo_add_index(vol, action, buffer);
break;
case AddIndexEntryRoot :
if (action->record.undo_operation
== const_cpu_to_le16(DeleteIndexEntryRoot))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(DeleteIndexEntryRoot)))
err = undo_add_root_index(vol, action, buffer);
break;
case ClearBitsInNonResidentBitMap :
if (action->record.undo_operation
== const_cpu_to_le16(SetBitsInNonResidentBitMap))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(SetBitsInNonResidentBitMap)))
err = undo_force_bits(vol, action, buffer);
break;
case CreateAttribute :
if (action->record.undo_operation
== const_cpu_to_le16(DeleteAttribute))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(DeleteAttribute)))
err = undo_create_attribute(vol, action, buffer);
break;
case DeallocateFileRecordSegment :
if (action->record.undo_operation
== const_cpu_to_le16(InitializeFileRecordSegment))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(InitializeFileRecordSegment)))
err = undo_delete_file(vol, action, buffer);
break;
case DeleteAttribute :
if (action->record.undo_operation
== const_cpu_to_le16(CreateAttribute))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(CreateAttribute)))
err = undo_delete_attribute(vol, action, buffer);
break;
case DeleteIndexEntryAllocation :
if (action->record.undo_operation
== const_cpu_to_le16(AddIndexEntryAllocation))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(AddIndexEntryAllocation)))
err = undo_delete_index(vol, action, buffer);
break;
case DeleteIndexEntryRoot :
if (action->record.undo_operation
== const_cpu_to_le16(AddIndexEntryRoot))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(AddIndexEntryRoot)))
err = undo_delete_root_index(vol, action, buffer);
break;
case InitializeFileRecordSegment :
if (action->record.undo_operation
== const_cpu_to_le16(Noop))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(Noop)))
err = undo_create_file(vol, action, buffer);
break;
case OpenNonResidentAttribute :
if (action->record.undo_operation
== const_cpu_to_le16(Noop))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(Noop)))
err = undo_open_attribute(vol, action);
break;
case SetBitsInNonResidentBitMap :
if (action->record.undo_operation
== const_cpu_to_le16(ClearBitsInNonResidentBitMap))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(ClearBitsInNonResidentBitMap)))
err = undo_force_bits(vol, action, buffer);
break;
case SetIndexEntryVcnAllocation :
if (action->record.undo_operation
== const_cpu_to_le16(SetIndexEntryVcnAllocation))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(SetIndexEntryVcnAllocation)))
err = undo_update_vcn(vol, action, buffer);
break;
case SetIndexEntryVcnRoot :
if (action->record.undo_operation
== const_cpu_to_le16(SetIndexEntryVcnRoot))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(SetIndexEntryVcnRoot)))
err = undo_update_root_vcn(vol, action, buffer);
break;
case SetNewAttributeSizes :
if (action->record.undo_operation
== const_cpu_to_le16(SetNewAttributeSizes))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(SetNewAttributeSizes)))
err = undo_sizes(vol, action, buffer);
break;
case UpdateFileNameAllocation :
if (action->record.undo_operation
== const_cpu_to_le16(UpdateFileNameAllocation))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(UpdateFileNameAllocation)))
err = undo_update_index(vol, action, buffer);
break;
case UpdateFileNameRoot :
if (action->record.undo_operation
== const_cpu_to_le16(UpdateFileNameRoot))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(UpdateFileNameRoot)))
err = undo_update_root_index(vol, action, buffer);
break;
case UpdateMappingPairs :
if (action->record.undo_operation
== const_cpu_to_le16(UpdateMappingPairs))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(UpdateMappingPairs)))
err = undo_update_mapping(vol, action, buffer);
break;
case UpdateNonResidentValue :
@ -4626,23 +4627,23 @@ static int distribute_undos(ntfs_volume *vol, const struct ACTION_RECORD *action
}
break;
case UpdateResidentValue :
if (action->record.undo_operation
== const_cpu_to_le16(UpdateResidentValue))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(UpdateResidentValue)))
err = undo_update_resident(vol, action, buffer);
break;
case Win10Action37 :
if (action->record.undo_operation
== const_cpu_to_le16(Noop))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(Noop)))
err = undo_action37(vol, action, buffer);
break;
case WriteEndofFileRecordSegment :
if (action->record.undo_operation
== const_cpu_to_le16(WriteEndofFileRecordSegment))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(WriteEndofFileRecordSegment)))
err = undo_write_end(vol, action, buffer);
break;
case WriteEndOfIndexBuffer :
if (action->record.undo_operation
== const_cpu_to_le16(WriteEndOfIndexBuffer))
if (le16_eq(action->record.undo_operation,
const_cpu_to_le16(WriteEndOfIndexBuffer)))
err = undo_write_index(vol, action, buffer);
break;
case AttributeNamesDump :
@ -4767,7 +4768,7 @@ printf("** %s (action %d) not acting on MFT\n",actionname(rop),(int)action->num)
buffer = read_protected(vol, &action->record, mftrecsz, TRUE);
entry = (MFT_RECORD*)buffer;
if (entry) {
if (entry->magic == magic_FILE) {
if (le32_eq(entry->magic, magic_FILE)) {
executed = !older_record(entry,
&action->record);
if (!executed
@ -4807,7 +4808,7 @@ printf("** %s (action %d) not acting on INDX\n",actionname(rop),(int)action->num
buffer = read_protected(vol, &action->record, xsize, TRUE);
indx = (INDEX_BLOCK*)buffer;
if (indx) {
if (indx->magic == magic_INDX) {
if (le32_eq(indx->magic, magic_INDX)) {
executed = !older_record(indx,
&action->record);
if (!executed
@ -4850,8 +4851,8 @@ printf("index lsn 0x%llx is %s than action %d lsn 0x%llx\n",
}
break;
case ON_RAW :
if (action->record.attribute_flags
& (ACTS_ON_INDX | ACTS_ON_MFT)) {
if (!le16_andz(action->record.attribute_flags,
le16_or(ACTS_ON_INDX, ACTS_ON_MFT))) {
printf("** Error : action %s on MFT or INDX\n",
actionname(rop));
err = 1;

View File

@ -37,7 +37,7 @@ void init_system_file_sd(int sys_file_no, u8 **sd_val, int *sd_val_len)
sd = (SECURITY_DESCRIPTOR_RELATIVE*)&sd_array;
sd->revision = 1;
sd->alignment = 0;
sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT;
sd->control = le16_or(SE_SELF_RELATIVE, SE_DACL_PRESENT);
*sd_val_len = 0x64;
sd->owner = const_cpu_to_le32(0x48);
sd->group = const_cpu_to_le32(0x54);
@ -64,14 +64,14 @@ void init_system_file_sd(int sys_file_no, u8 **sd_val, int *sd_val_len)
switch (sys_file_no) {
case FILE_AttrDef:
case FILE_Boot:
aa_ace->mask = SYNCHRONIZE | STANDARD_RIGHTS_READ |
FILE_READ_ATTRIBUTES | FILE_READ_EA | FILE_READ_DATA;
aa_ace->mask = le32_or(SYNCHRONIZE, le32_or(STANDARD_RIGHTS_READ,
le32_or(FILE_READ_ATTRIBUTES, le32_or(FILE_READ_EA, FILE_READ_DATA))));
break;
default:
aa_ace->mask = SYNCHRONIZE | STANDARD_RIGHTS_WRITE |
FILE_WRITE_ATTRIBUTES | FILE_READ_ATTRIBUTES |
FILE_WRITE_EA | FILE_READ_EA | FILE_APPEND_DATA |
FILE_WRITE_DATA | FILE_READ_DATA;
aa_ace->mask = le32_or(SYNCHRONIZE, le32_or(STANDARD_RIGHTS_WRITE,
le32_or(FILE_WRITE_ATTRIBUTES, le32_or(FILE_READ_ATTRIBUTES,
le32_or(FILE_WRITE_EA, le32_or(FILE_READ_EA, le32_or(FILE_APPEND_DATA,
le32_or(FILE_WRITE_DATA, FILE_READ_DATA))))))));
break;
}
aa_ace->sid.revision = 1;
@ -100,16 +100,16 @@ void init_system_file_sd(int sys_file_no, u8 **sd_val, int *sd_val_len)
switch (sys_file_no) {
case FILE_AttrDef:
case FILE_Boot:
aa_ace->mask = SYNCHRONIZE | STANDARD_RIGHTS_READ |
FILE_READ_ATTRIBUTES | FILE_READ_EA |
FILE_READ_DATA;
aa_ace->mask = le32_or(SYNCHRONIZE, le32_or(STANDARD_RIGHTS_READ,
le32_or(FILE_READ_ATTRIBUTES, le32_or(FILE_READ_EA,
FILE_READ_DATA))));
break;
default:
aa_ace->mask = SYNCHRONIZE | STANDARD_RIGHTS_READ |
FILE_WRITE_ATTRIBUTES |
FILE_READ_ATTRIBUTES | FILE_WRITE_EA |
FILE_READ_EA | FILE_APPEND_DATA |
FILE_WRITE_DATA | FILE_READ_DATA;
aa_ace->mask = le32_or(SYNCHRONIZE, le32_or(STANDARD_RIGHTS_READ,
le32_or(FILE_WRITE_ATTRIBUTES,
le32_or(FILE_READ_ATTRIBUTES, le32_or(FILE_WRITE_EA,
le32_or(FILE_READ_EA, le32_or(FILE_APPEND_DATA,
le32_or(FILE_WRITE_DATA, FILE_READ_DATA))))))));
break;
}
aa_ace->sid.revision = 1;
@ -184,7 +184,7 @@ void init_root_sd(u8 **sd_val, int *sd_val_len)
sd = (SECURITY_DESCRIPTOR_RELATIVE*)sd_array;
sd->revision = SECURITY_DESCRIPTOR_REVISION;
sd->alignment = 0;
sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT;
sd->control = le16_or(SE_SELF_RELATIVE, SE_DACL_PRESENT);
sd->owner = const_cpu_to_le32(0x1014);
sd->group = const_cpu_to_le32(0x1020);
sd->sacl = const_cpu_to_le32(0);
@ -203,11 +203,11 @@ void init_root_sd(u8 **sd_val, int *sd_val_len)
ace->type = ACCESS_ALLOWED_ACE_TYPE;
ace->flags = 0;
ace->size = const_cpu_to_le16(0x18);
ace->mask = STANDARD_RIGHTS_ALL | FILE_WRITE_ATTRIBUTES |
FILE_LIST_DIRECTORY | FILE_WRITE_DATA |
FILE_ADD_SUBDIRECTORY | FILE_READ_EA | FILE_WRITE_EA |
FILE_TRAVERSE | FILE_DELETE_CHILD |
FILE_READ_ATTRIBUTES;
ace->mask = le32_or(STANDARD_RIGHTS_ALL, le32_or(FILE_WRITE_ATTRIBUTES,
le32_or(FILE_LIST_DIRECTORY, le32_or(FILE_WRITE_DATA,
le32_or(FILE_ADD_SUBDIRECTORY, le32_or(FILE_READ_EA, le32_or(FILE_WRITE_EA,
le32_or(FILE_TRAVERSE, le32_or(FILE_DELETE_CHILD,
FILE_READ_ATTRIBUTES)))))))));
ace->sid.revision = SID_REVISION;
ace->sid.sub_authority_count = 0x02;
/* SECURITY_NT_SID_AUTHORITY (S-1-5) */
@ -248,11 +248,11 @@ void init_root_sd(u8 **sd_val, int *sd_val_len)
ace->type = ACCESS_ALLOWED_ACE_TYPE;
ace->flags = 0;
ace->size = const_cpu_to_le16(0x14);
ace->mask = STANDARD_RIGHTS_ALL | FILE_WRITE_ATTRIBUTES |
FILE_LIST_DIRECTORY | FILE_WRITE_DATA |
FILE_ADD_SUBDIRECTORY | FILE_READ_EA | FILE_WRITE_EA |
FILE_TRAVERSE | FILE_DELETE_CHILD |
FILE_READ_ATTRIBUTES;
ace->mask = le32_or(STANDARD_RIGHTS_ALL, le32_or(FILE_WRITE_ATTRIBUTES,
le32_or(FILE_LIST_DIRECTORY, le32_or(FILE_WRITE_DATA,
le32_or(FILE_ADD_SUBDIRECTORY, le32_or(FILE_READ_EA, le32_or(FILE_WRITE_EA,
le32_or(FILE_TRAVERSE, le32_or(FILE_DELETE_CHILD,
FILE_READ_ATTRIBUTES)))))))));
ace->sid.revision = SID_REVISION;
ace->sid.sub_authority_count = 0x01;
/* SECURITY_NT_SID_AUTHORITY (S-1-5) */
@ -289,11 +289,11 @@ void init_root_sd(u8 **sd_val, int *sd_val_len)
ace->type = ACCESS_ALLOWED_ACE_TYPE;
ace->flags = 0;
ace->size = const_cpu_to_le16(0x14);
ace->mask = SYNCHRONIZE | READ_CONTROL | DELETE |
FILE_WRITE_ATTRIBUTES | FILE_READ_ATTRIBUTES |
FILE_TRAVERSE | FILE_WRITE_EA | FILE_READ_EA |
FILE_ADD_SUBDIRECTORY | FILE_ADD_FILE |
FILE_LIST_DIRECTORY;
ace->mask = le32_or(SYNCHRONIZE, le32_or(READ_CONTROL, le32_or(DELETE,
le32_or(FILE_WRITE_ATTRIBUTES, le32_or(FILE_READ_ATTRIBUTES,
le32_or(FILE_TRAVERSE, le32_or(FILE_WRITE_EA, le32_or(FILE_READ_EA,
le32_or(FILE_ADD_SUBDIRECTORY, le32_or(FILE_ADD_FILE,
FILE_LIST_DIRECTORY))))))))));
ace->sid.revision = SID_REVISION;
ace->sid.sub_authority_count = 0x01;
/* SECURITY_NT_SID_AUTHORITY (S-1-5) */
@ -312,7 +312,7 @@ void init_root_sd(u8 **sd_val, int *sd_val_len)
ace->flags = OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE |
INHERIT_ONLY_ACE;
ace->size = const_cpu_to_le16(0x14);
ace->mask = GENERIC_READ | GENERIC_WRITE | GENERIC_EXECUTE | DELETE;
ace->mask = le32_or(GENERIC_READ, le32_or(GENERIC_WRITE, le32_or(GENERIC_EXECUTE, DELETE)));
ace->sid.revision = SID_REVISION;
ace->sid.sub_authority_count = 0x01;
/* SECURITY_NT_SID_AUTHORITY (S-1-5) */
@ -330,8 +330,8 @@ void init_root_sd(u8 **sd_val, int *sd_val_len)
ace->type = ACCESS_ALLOWED_ACE_TYPE;
ace->flags = 0;
ace->size = const_cpu_to_le16(0x18);
ace->mask = SYNCHRONIZE | READ_CONTROL | FILE_READ_ATTRIBUTES |
FILE_TRAVERSE | FILE_READ_EA | FILE_LIST_DIRECTORY;
ace->mask = le32_or(SYNCHRONIZE, le32_or(READ_CONTROL, le32_or(FILE_READ_ATTRIBUTES,
le32_or(FILE_TRAVERSE, le32_or(FILE_READ_EA, FILE_LIST_DIRECTORY)))));
ace->sid.revision = SID_REVISION;
ace->sid.sub_authority_count = 0x02;
/* SECURITY_NT_SID_AUTHORITY (S-1-5) */
@ -352,7 +352,7 @@ void init_root_sd(u8 **sd_val, int *sd_val_len)
ace->flags = OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE |
INHERIT_ONLY_ACE;
ace->size = const_cpu_to_le16(0x18);
ace->mask = GENERIC_READ | GENERIC_EXECUTE;
ace->mask = le32_or(GENERIC_READ, GENERIC_EXECUTE);
ace->sid.revision = SID_REVISION;
ace->sid.sub_authority_count = 0x02;
/* SECURITY_NT_SID_AUTHORITY (S-1-5) */
@ -424,7 +424,7 @@ void init_secure_sds(char *sd_val)
sizeof(SECURITY_DESCRIPTOR_HEADER));
sd->revision = 0x01;
sd->alignment = 0x00;
sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT;
sd->control = le16_or(SE_SELF_RELATIVE, SE_DACL_PRESENT);
sd->owner = const_cpu_to_le32(0x48);
sd->group = const_cpu_to_le32(0x58);
sd->sacl = const_cpu_to_le32(0x00);
@ -520,7 +520,7 @@ void init_secure_sds(char *sd_val)
sizeof(SECURITY_DESCRIPTOR_HEADER));
sd->revision = 0x01;
sd->alignment = 0x00;
sd->control = SE_SELF_RELATIVE | SE_DACL_PRESENT;
sd->control = le16_or(SE_SELF_RELATIVE, SE_DACL_PRESENT);
sd->owner = const_cpu_to_le32(0x48);
sd->group = const_cpu_to_le32(0x58);
sd->sacl = const_cpu_to_le32(0x00);

View File

@ -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);
@ -875,7 +875,7 @@ int utils_is_metadata(ntfs_inode *inode)
return 1;
file = inode->mrec;
if (file && (file->base_mft_record != 0)) {
if (file && !le64_cmpz(file->base_mft_record)) {
num = MREF_LE(file->base_mft_record);
if (__metadata(vol, num) == 1)
return 1;
@ -1041,7 +1041,7 @@ int mft_next_record(struct mft_search_ctx *ctx)
mrec = (MFT_RECORD*)NULL;
r = ntfs_file_record_read(ctx->vol,
(MFT_REF) ctx->mft_num, &mrec, NULL);
if (r || !mrec || !mrec->base_mft_record)
if (r || !mrec || le64_cmpz(mrec->base_mft_record))
ntfs_log_error(
"Error reading inode %lld.\n",
(long long)ctx->mft_num);

View File

@ -166,7 +166,7 @@
? 1 : ntfs_allowed_access(scx, ni, type))
#endif
#define set_archive(ni) (ni)->flags |= FILE_ATTR_ARCHIVE
#define set_archive(ni) (ni)->flags = le32_or((ni)->flags, FILE_ATTR_ARCHIVE)
#define INODE(ino) ((ino) == 1 ? (MFT_REF)FILE_root : (MFT_REF)(ino))
/*
@ -686,28 +686,28 @@ static int wsl_getstat(ntfs_inode *ni, const REPARSE_POINT *reparse,
res = ntfs_reparse_check_wsl(ni, reparse);
if (!res) {
switch (reparse->reparse_tag) {
case IO_REPARSE_TAG_AF_UNIX :
/* switch (reparse->reparse_tag) { */
if (le32_eq(reparse->reparse_tag, IO_REPARSE_TAG_AF_UNIX)) {
stbuf->st_mode = S_IFSOCK;
break;
case IO_REPARSE_TAG_LX_FIFO :
}
else if (le32_eq(reparse->reparse_tag, IO_REPARSE_TAG_LX_FIFO)) {
stbuf->st_mode = S_IFIFO;
break;
case IO_REPARSE_TAG_LX_CHR :
}
else if (le32_eq(reparse->reparse_tag, IO_REPARSE_TAG_LX_CHR)) {
stbuf->st_mode = S_IFCHR;
res = ntfs_ea_check_wsldev(ni, &rdev);
stbuf->st_rdev = rdev;
break;
case IO_REPARSE_TAG_LX_BLK :
}
else if (le32_eq(reparse->reparse_tag, IO_REPARSE_TAG_LX_BLK)) {
stbuf->st_mode = S_IFBLK;
res = ntfs_ea_check_wsldev(ni, &rdev);
stbuf->st_rdev = rdev;
break;
default :
}
else {
stbuf->st_size = ntfs_bad_reparse_lth;
stbuf->st_mode = S_IFLNK;
break;
}
/* } */
}
/*
* If the reparse point is not a valid wsl special file
@ -755,11 +755,11 @@ static int ntfs_fuse_getstat(struct SECURITY_CONTEXT *scx,
withusermapping = (scx->mapping[MAPUSERS] != (struct MAPPING*)NULL);
stbuf->st_nlink = le16_to_cpu(ni->mrec->link_count);
if (ctx->posix_nlink
&& !(ni->flags & FILE_ATTR_REPARSE_POINT))
&& le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT))
stbuf->st_nlink = ntfs_dir_link_cnt(ni);
if ((ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)
|| (ni->flags & FILE_ATTR_REPARSE_POINT)) {
if (ni->flags & FILE_ATTR_REPARSE_POINT) {
if (!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)
|| !le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) {
if (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) {
#ifndef DISABLE_PLUGINS
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
@ -831,7 +831,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 */
@ -840,14 +840,14 @@ static int ntfs_fuse_getstat(struct SECURITY_CONTEXT *scx,
* See more on the ntfs-3g-devel list.
*/
stbuf->st_blocks = (ni->allocated_size + 511) >> 9;
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;
goto nodata;
}
/* Check whether it's Interix FIFO or socket. */
if (!(ni->flags & FILE_ATTR_HIDDEN)) {
if (le32_andz(ni->flags, FILE_ATTR_HIDDEN)) {
/* FIFO. */
if (na->data_size == 0)
stbuf->st_mode = S_IFIFO;
@ -879,7 +879,7 @@ static int ntfs_fuse_getstat(struct SECURITY_CONTEXT *scx,
ntfs_attr_close(na);
goto exit;
}
if (intx_file->magic == INTX_BLOCK_DEVICE &&
if (le64_eq(intx_file->magic, INTX_BLOCK_DEVICE) &&
na->data_size == (s64)offsetof(
INTX_FILE, device_end)) {
stbuf->st_mode = S_IFBLK;
@ -888,7 +888,7 @@ static int ntfs_fuse_getstat(struct SECURITY_CONTEXT *scx,
le64_to_cpu(
intx_file->minor));
}
if (intx_file->magic == INTX_CHARACTER_DEVICE &&
if (le64_eq(intx_file->magic, INTX_CHARACTER_DEVICE) &&
na->data_size == (s64)offsetof(
INTX_FILE, device_end)) {
stbuf->st_mode = S_IFCHR;
@ -897,7 +897,7 @@ static int ntfs_fuse_getstat(struct SECURITY_CONTEXT *scx,
le64_to_cpu(
intx_file->minor));
}
if (intx_file->magic == INTX_SYMBOLIC_LINK) {
if (le64_eq(intx_file->magic, INTX_SYMBOLIC_LINK)) {
char *target = NULL;
int len;
@ -1131,7 +1131,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)) {
REPARSE_POINT *reparse;
le32 tag;
int lth;
@ -1171,7 +1171,7 @@ static void ntfs_fuse_readlink(fuse_req_t req, fuse_ino_t ino)
goto exit;
}
/* Sanity checks. */
if (!(ni->flags & FILE_ATTR_SYSTEM)) {
if (le32_andz(ni->flags, FILE_ATTR_SYSTEM)) {
res = -EINVAL;
goto exit;
}
@ -1200,7 +1200,7 @@ static void ntfs_fuse_readlink(fuse_req_t req, fuse_ino_t ino)
goto exit;
}
/* Sanity check. */
if (intx_file->magic != INTX_SYMBOLIC_LINK) {
if (!le64_eq(intx_file->magic, INTX_SYMBOLIC_LINK)) {
res = -EINVAL;
goto exit;
}
@ -1277,7 +1277,7 @@ static int ntfs_fuse_filler(ntfs_fuse_fill_context_t *fill_ctx,
#ifndef DISABLE_PLUGINS
/* get emulated type from plugin if available */
ni = ntfs_inode_open(ctx->vol, mref);
if (ni && (ni->flags & FILE_ATTR_REPARSE_POINT)) {
if (ni && !le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) {
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
int res;
@ -1395,7 +1395,7 @@ static void ntfs_fuse_opendir(fuse_req_t req, fuse_ino_t ino,
if (!ntfs_allowed_access(&security,ni,accesstype))
res = -EACCES;
}
if (ni->flags & FILE_ATTR_REPARSE_POINT) {
if (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) {
#ifndef DISABLE_PLUGINS
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
@ -1463,7 +1463,7 @@ static void ntfs_fuse_releasedir(fuse_req_t req,
ni = ntfs_inode_open(ctx->vol, INODE(ino));
if (ni) {
if (ni->flags & FILE_ATTR_REPARSE_POINT) {
if (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) {
memcpy(&ufi, fi, sizeof(ufi));
ufi.fh = fill->fh;
res = CALL_REPARSE_PLUGIN(ni, release,
@ -1524,8 +1524,8 @@ static void ntfs_fuse_readdir(fuse_req_t req, fuse_ino_t ino, size_t size,
if (!ni)
err = -errno;
else {
if (ni->flags
& FILE_ATTR_REPARSE_POINT) {
if (!le32_andz(ni->flags,
FILE_ATTR_REPARSE_POINT)) {
#ifndef DISABLE_PLUGINS
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
@ -1613,7 +1613,7 @@ static void ntfs_fuse_open(fuse_req_t req, fuse_ino_t ino,
ni = ntfs_inode_open(ctx->vol, INODE(ino));
if (ni) {
if (!(ni->flags & FILE_ATTR_REPARSE_POINT)) {
if (le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) {
na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0);
if (!na) {
res = -errno;
@ -1635,7 +1635,7 @@ static void ntfs_fuse_open(fuse_req_t req, fuse_ino_t ino,
res = -EACCES;
}
#endif
if (ni->flags & FILE_ATTR_REPARSE_POINT) {
if (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) {
#ifndef DISABLE_PLUGINS
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
@ -1653,13 +1653,13 @@ 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 */
if (ctx->efs_raw
&& !(na->data_flags & ATTR_IS_ENCRYPTED)
&& (ni->flags & FILE_ATTR_ENCRYPTED))
&& le16_andz(na->data_flags, ATTR_IS_ENCRYPTED)
&& !le32_andz(ni->flags, FILE_ATTR_ENCRYPTED))
state |= CLOSE_ENCRYPTED;
#endif /* HAVE_SETXATTR */
/* mark a future need to update the mtime */
@ -1724,7 +1724,7 @@ static void ntfs_fuse_read(fuse_req_t req, fuse_ino_t ino, size_t size,
res = -errno;
goto exit;
}
if (ni->flags & FILE_ATTR_REPARSE_POINT) {
if (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) {
#ifndef DISABLE_PLUGINS
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
@ -1750,7 +1750,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;
}
@ -1805,7 +1805,7 @@ static void ntfs_fuse_write(fuse_req_t req, fuse_ino_t ino, const char *buf,
res = -errno;
goto exit;
}
if (ni->flags & FILE_ATTR_REPARSE_POINT) {
if (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) {
#ifndef DISABLE_PLUGINS
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
@ -2002,7 +2002,7 @@ static int ntfs_fuse_trunc(struct SECURITY_CONTEXT *scx, fuse_ino_t ino,
errno = EPERM;
goto exit;
}
if (!(ni->flags & FILE_ATTR_REPARSE_POINT)) {
if (le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) {
na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0);
if (!na)
goto exit;
@ -2019,7 +2019,7 @@ static int ntfs_fuse_trunc(struct SECURITY_CONTEXT *scx, fuse_ino_t ino,
goto exit;
}
#endif
if (ni->flags & FILE_ATTR_REPARSE_POINT) {
if (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) {
#ifndef DISABLE_PLUGINS
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
@ -2039,7 +2039,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)
@ -2413,7 +2413,7 @@ static int ntfs_fuse_create(fuse_req_t req, fuse_ino_t parent, const char *name,
perm & ~security.umask, S_ISDIR(type));
#endif
/* Create object specified in @type. */
if (dir_ni->flags & FILE_ATTR_REPARSE_POINT) {
if (!le32_andz(dir_ni->flags, FILE_ATTR_REPARSE_POINT)) {
#ifndef DISABLE_PLUGINS
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
@ -2465,13 +2465,13 @@ static int ntfs_fuse_create(fuse_req_t req, fuse_ino_t parent, const char *name,
*/
if (ctx->security.mapping[MAPUSERS]) {
#if POSIXACLS
if (!securid
if (le32_cmpz(securid)
&& ntfs_set_inherited_posix(&security, ni,
security.uid, gid,
dir_ni, perm) < 0)
set_fuse_error(&res);
#else
if (!securid
if (le32_cmpz(securid)
&& ntfs_set_owner_mode(&security, ni,
security.uid, gid,
perm & ~security.umask) < 0)
@ -2480,14 +2480,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)
@ -2597,7 +2597,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;
@ -2627,7 +2627,7 @@ static int ntfs_fuse_newlink(fuse_req_t req __attribute__((unused)),
ntfs_fuse_fill_security_context(req, &security);
#endif
{
if (dir_ni->flags & FILE_ATTR_REPARSE_POINT) {
if (!le32_andz(dir_ni->flags, FILE_ATTR_REPARSE_POINT)) {
#ifndef DISABLE_PLUGINS
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
@ -2741,10 +2741,10 @@ 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 */
isdir = ni->mrec->flags & MFT_RECORD_IS_DIRECTORY;
isdir = !le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY);
#ifndef DISABLE_PLUGINS
/* get emulated type from plugin if available */
if (ni->flags & FILE_ATTR_REPARSE_POINT) {
if (!le32_andz((ni->flags, FILE_ATTR_REPARSE_POINT) {
struct stat st;
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
@ -2854,7 +2854,7 @@ static int ntfs_fuse_rm(fuse_req_t req, fuse_ino_t parent, const char *name,
goto exit;
}
}
if (dir_ni->flags & FILE_ATTR_REPARSE_POINT) {
if (!le32_andz(dir_ni->flags, FILE_ATTR_REPARSE_POINT)) {
#ifndef DISABLE_PLUGINS
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
@ -3091,7 +3091,7 @@ static void ntfs_fuse_release(fuse_req_t req, fuse_ino_t ino,
res = -errno;
goto exit;
}
if (ni->flags & FILE_ATTR_REPARSE_POINT) {
if (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) {
#ifndef DISABLE_PLUGINS
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
@ -3265,7 +3265,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, le16_or(ATTR_COMPRESSION_MASK, ATTR_IS_ENCRYPTED))
|| !NAttrNonResident(na)) {
ret = -EINVAL;
goto close_attr;
@ -3671,7 +3671,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;
rsize -= position;
@ -3908,7 +3908,7 @@ static void ntfs_fuse_setxattr(fuse_req_t req, fuse_ino_t ino, const char *name,
res = -errno;
goto exit;
}
if (!(ni->flags & FILE_ATTR_ARCHIVE)) {
if (le32_andz(ni->flags, FILE_ATTR_ARCHIVE)) {
set_archive(ni);
NInoFileNameSetDirty(ni);
}
@ -3943,14 +3943,14 @@ 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;
}
}
if (!res) {
ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME);
if (!(ni->flags & FILE_ATTR_ARCHIVE)) {
if (le32_andz(ni->flags, FILE_ATTR_ARCHIVE)) {
set_archive(ni);
NInoFileNameSetDirty(ni);
}
@ -4149,7 +4149,7 @@ static void ntfs_fuse_removexattr(fuse_req_t req, fuse_ino_t ino, const char *na
}
if (!res) {
ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME);
if (!(ni->flags & FILE_ATTR_ARCHIVE)) {
if (le32_andz(ni->flags, FILE_ATTR_ARCHIVE)) {
set_archive(ni);
NInoFileNameSetDirty(ni);
}

View File

@ -136,7 +136,7 @@
? 1 : ntfs_allowed_access(scx, ni, type))
#endif
#define set_archive(ni) (ni)->flags |= FILE_ATTR_ARCHIVE
#define set_archive(ni) (ni)->flags = le32_or((ni)->flags, FILE_ATTR_ARCHIVE)
/*
* Call a function from a reparse plugin (variable arguments)
@ -744,28 +744,28 @@ static int wsl_getattr(ntfs_inode *ni, const REPARSE_POINT *reparse,
res = ntfs_reparse_check_wsl(ni, reparse);
if (!res) {
switch (reparse->reparse_tag) {
case IO_REPARSE_TAG_AF_UNIX :
/* switch (reparse->reparse_tag) { */
if (le32_eq(reparse->reparse_tag, IO_REPARSE_TAG_AF_UNIX)) {
stbuf->st_mode = S_IFSOCK;
break;
case IO_REPARSE_TAG_LX_FIFO :
}
else if (le32_eq(reparse->reparse_tag, IO_REPARSE_TAG_LX_FIFO)) {
stbuf->st_mode = S_IFIFO;
break;
case IO_REPARSE_TAG_LX_CHR :
}
else if (le32_eq(reparse->reparse_tag, IO_REPARSE_TAG_LX_CHR)) {
stbuf->st_mode = S_IFCHR;
res = ntfs_ea_check_wsldev(ni, &rdev);
stbuf->st_rdev = rdev;
break;
case IO_REPARSE_TAG_LX_BLK :
}
else if (le32_eq(reparse->reparse_tag, IO_REPARSE_TAG_LX_BLK)) {
stbuf->st_mode = S_IFBLK;
res = ntfs_ea_check_wsldev(ni, &rdev);
stbuf->st_rdev = rdev;
break;
default :
}
else {
stbuf->st_size = ntfs_bad_reparse_lth;
stbuf->st_mode = S_IFLNK;
break;
}
/* } */
}
/*
* If the reparse point is not a valid wsl special file
@ -837,13 +837,13 @@ static int ntfs_fuse_getattr(const char *org_path, struct stat *stbuf)
#endif
stbuf->st_nlink = le16_to_cpu(ni->mrec->link_count);
if (ctx->posix_nlink
&& !(ni->flags & FILE_ATTR_REPARSE_POINT))
&& le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT))
stbuf->st_nlink = ntfs_dir_link_cnt(ni);
if (((ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)
|| (ni->flags & FILE_ATTR_REPARSE_POINT))
if ((!le16_andz(ni->mrec->flags, MFT_RECORD_IS_DIRECTORY)
|| !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)) {
#ifndef DISABLE_PLUGINS
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
@ -914,7 +914,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 */
@ -923,7 +923,7 @@ static int ntfs_fuse_getattr(const char *org_path, struct stat *stbuf)
* See more on the ntfs-3g-devel list.
*/
stbuf->st_blocks = (ni->allocated_size + 511) >> 9;
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) {
@ -938,7 +938,7 @@ static int ntfs_fuse_getattr(const char *org_path, struct stat *stbuf)
stbuf->st_blocks = na->allocated_size >> 9;
}
/* Check whether it's Interix FIFO or socket. */
if (!(ni->flags & FILE_ATTR_HIDDEN) &&
if (le32_andz(ni->flags, FILE_ATTR_HIDDEN) &&
!stream_name_len) {
/* FIFO. */
if (na->data_size == 0)
@ -951,7 +951,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 */
@ -980,7 +980,7 @@ static int ntfs_fuse_getattr(const char *org_path, struct stat *stbuf)
ntfs_attr_close(na);
goto exit;
}
if (intx_file->magic == INTX_BLOCK_DEVICE &&
if (le64_eq(intx_file->magic, INTX_BLOCK_DEVICE) &&
na->data_size == offsetof(
INTX_FILE, device_end)) {
stbuf->st_mode = S_IFBLK;
@ -989,7 +989,7 @@ static int ntfs_fuse_getattr(const char *org_path, struct stat *stbuf)
le64_to_cpu(
intx_file->minor));
}
if (intx_file->magic == INTX_CHARACTER_DEVICE &&
if (le64_eq(intx_file->magic, INTX_CHARACTER_DEVICE) &&
na->data_size == offsetof(
INTX_FILE, device_end)) {
stbuf->st_mode = S_IFCHR;
@ -998,7 +998,7 @@ static int ntfs_fuse_getattr(const char *org_path, struct stat *stbuf)
le64_to_cpu(
intx_file->minor));
}
if (intx_file->magic == INTX_SYMBOLIC_LINK) {
if (le64_eq(intx_file->magic, INTX_SYMBOLIC_LINK)) {
char *target = NULL;
int len;
@ -1157,7 +1157,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)) {
#ifndef DISABLE_PLUGINS
char *gotlink;
const plugin_operations_t *ops;
@ -1201,7 +1201,7 @@ static int ntfs_fuse_readlink(const char *org_path, char *buf, size_t buf_size)
goto exit;
}
/* Sanity checks. */
if (!(ni->flags & FILE_ATTR_SYSTEM)) {
if (le32_andz(ni->flags, FILE_ATTR_SYSTEM)) {
res = -EINVAL;
goto exit;
}
@ -1230,7 +1230,7 @@ static int ntfs_fuse_readlink(const char *org_path, char *buf, size_t buf_size)
goto exit;
}
/* Sanity check. */
if (intx_file->magic != INTX_SYMBOLIC_LINK) {
if (!le64_eq(intx_file->magic, INTX_SYMBOLIC_LINK)) {
res = -EINVAL;
goto exit;
}
@ -1308,7 +1308,7 @@ static int ntfs_fuse_filler(ntfs_fuse_fill_context_t *fill_ctx,
#ifndef DISABLE_PLUGINS
/* get emulated type from plugin if available */
ni = ntfs_inode_open(ctx->vol, mref);
if (ni && (ni->flags & FILE_ATTR_REPARSE_POINT)) {
if (ni && !le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) {
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
int res;
@ -1439,7 +1439,7 @@ static int ntfs_fuse_readdir(const char *path, void *buf,
if (!ni)
return -errno;
if (ni->flags & FILE_ATTR_REPARSE_POINT) {
if (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) {
#ifndef DISABLE_PLUGINS
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
@ -1483,7 +1483,7 @@ static int ntfs_fuse_open(const char *org_path,
return stream_name_len;
ni = ntfs_pathname_to_inode(ctx->vol, NULL, path);
if (ni) {
if (!(ni->flags & FILE_ATTR_REPARSE_POINT)) {
if (le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) {
na = ntfs_attr_open(ni, AT_DATA, stream_name, stream_name_len);
if (!na) {
res = -errno;
@ -1510,7 +1510,7 @@ static int ntfs_fuse_open(const char *org_path,
res = -EACCES;
}
#endif
if (ni->flags & FILE_ATTR_REPARSE_POINT) {
if (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) {
#ifndef DISABLE_PLUGINS
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
@ -1525,13 +1525,13 @@ 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 */
if (ctx->efs_raw
&& !(na->data_flags & ATTR_IS_ENCRYPTED)
&& (ni->flags & FILE_ATTR_ENCRYPTED))
&& le16_andz(na->data_flags, ATTR_IS_ENCRYPTED)
&& !le32_andz(ni->flags, FILE_ATTR_ENCRYPTED))
fi->fh |= CLOSE_ENCRYPTED;
#endif /* HAVE_SETXATTR */
/* mark a future need to update the mtime */
@ -1575,7 +1575,7 @@ static int ntfs_fuse_read(const char *org_path, char *buf, size_t size,
res = -errno;
goto exit;
}
if (ni->flags & FILE_ATTR_REPARSE_POINT) {
if (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) {
#ifndef DISABLE_PLUGINS
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
@ -1603,7 +1603,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;
}
@ -1663,7 +1663,7 @@ static int ntfs_fuse_write(const char *org_path, const char *buf, size_t size,
res = -errno;
goto exit;
}
if (ni->flags & FILE_ATTR_REPARSE_POINT) {
if (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) {
#ifndef DISABLE_PLUGINS
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
@ -1749,7 +1749,7 @@ static int ntfs_fuse_release(const char *org_path,
res = -errno;
goto exit;
}
if (ni->flags & FILE_ATTR_REPARSE_POINT) {
if (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) {
#ifndef DISABLE_PLUGINS
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
@ -1831,7 +1831,7 @@ static int ntfs_fuse_trunc(const char *org_path, off_t size,
goto exit;
}
if (ni->flags & FILE_ATTR_REPARSE_POINT) {
if (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) {
#ifndef DISABLE_PLUGINS
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
@ -1872,7 +1872,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)
@ -2145,7 +2145,7 @@ static int ntfs_fuse_create(const char *org_path, mode_t typemode, dev_t dev,
perm & ~security.umask, S_ISDIR(type));
#endif
/* Create object specified in @type. */
if (dir_ni->flags & FILE_ATTR_REPARSE_POINT) {
if (!le32_andz(dir_ni->flags, FILE_ATTR_REPARSE_POINT)) {
#ifndef DISABLE_PLUGINS
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
@ -2194,13 +2194,13 @@ static int ntfs_fuse_create(const char *org_path, mode_t typemode, dev_t dev,
*/
if (ctx->security.mapping[MAPUSERS]) {
#if POSIXACLS
if (!securid
if (le32_cmpz(securid)
&& ntfs_set_inherited_posix(&security, ni,
security.uid, gid,
dir_ni, perm) < 0)
set_fuse_error(&res);
#else
if (!securid
if (le32_cmpz(securid)
&& ntfs_set_owner_mode(&security, ni,
security.uid, gid,
perm & ~security.umask) < 0)
@ -2209,14 +2209,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 */
@ -2283,12 +2283,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)
@ -2408,7 +2408,7 @@ static int ntfs_fuse_link(const char *old_path, const char *new_path)
else
#endif
{
if (dir_ni->flags & FILE_ATTR_REPARSE_POINT) {
if (!le32_andz(dir_ni->flags, FILE_ATTR_REPARSE_POINT)) {
#ifndef DISABLE_PLUGINS
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
@ -2497,7 +2497,7 @@ static int ntfs_fuse_rm(const char *org_path)
|| ntfs_allowed_dir_access(&security, org_path, dir_ni, ni,
S_IEXEC + S_IWRITE + S_ISVTX)) {
#endif
if (dir_ni->flags & FILE_ATTR_REPARSE_POINT) {
if (!le32_andz(dir_ni->flags, FILE_ATTR_REPARSE_POINT)) {
#ifndef DISABLE_PLUGINS
const plugin_operations_t *ops;
REPARSE_POINT *reparse;
@ -2969,7 +2969,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, le16_or(ATTR_COMPRESSION_MASK, ATTR_IS_ENCRYPTED))
|| !NAttrNonResident(na)) {
ret = -EINVAL;
goto close_attr;
@ -3408,7 +3408,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;
rsize -= position;
@ -3622,7 +3622,7 @@ static int ntfs_fuse_setxattr(const char *path, const char *name,
res = -errno;
goto exit;
}
if (!(ni->flags & FILE_ATTR_ARCHIVE)) {
if (le32_andz(ni->flags, FILE_ATTR_ARCHIVE)) {
set_archive(ni);
NInoFileNameSetDirty(ni);
}
@ -3657,14 +3657,14 @@ 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;
}
}
if (!res) {
ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME);
if (!(ni->flags & FILE_ATTR_ARCHIVE)) {
if (le32_andz(ni->flags, FILE_ATTR_ARCHIVE)) {
set_archive(ni);
NInoFileNameSetDirty(ni);
}
@ -3855,7 +3855,7 @@ static int ntfs_fuse_removexattr(const char *path, const char *name)
}
if (!res) {
ntfs_fuse_update_times(ni, NTFS_UPDATE_CTIME);
if (!(ni->flags & FILE_ATTR_ARCHIVE)) {
if (le32_andz(ni->flags, FILE_ATTR_ARCHIVE)) {
set_archive(ni);
NInoFileNameSetDirty(ni);
}

View File

@ -772,7 +772,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,
@ -832,8 +832,8 @@ const struct plugin_operations *select_reparse_plugin(ntfs_fuse_context_t *ctx,
reparse = ntfs_get_reparse_point(ni);
if (reparse) {
tag = reparse->reparse_tag;
seltag = tag & IO_REPARSE_PLUGIN_SELECT;
for (plugin=ctx->plugins; plugin && (plugin->tag != seltag);
seltag = le32_and(tag, IO_REPARSE_PLUGIN_SELECT);
for (plugin=ctx->plugins; plugin && !le32_eq(plugin->tag, seltag);
plugin = plugin->next) { }
if (plugin) {
ops = plugin->ops;
@ -914,12 +914,12 @@ BOOL user_xattrs_allowed(ntfs_fuse_context_t *ctx __attribute__((unused)),
BOOL res;
/* Quick return for common cases and root */
if (!(ni->flags & (FILE_ATTR_SYSTEM | FILE_ATTR_REPARSE_POINT))
if (le32_andz(ni->flags, le32_or(FILE_ATTR_SYSTEM, FILE_ATTR_REPARSE_POINT))
|| (ni->mft_no == FILE_root))
res = TRUE;
else {
/* Reparse point depends on kind, see plugin */
if (ni->flags & FILE_ATTR_REPARSE_POINT) {
if (!le32_andz(ni->flags, FILE_ATTR_REPARSE_POINT)) {
#ifndef DISABLE_PLUGINS
struct stat stbuf;
REPARSE_POINT *reparse;