summaryrefslogtreecommitdiff
path: root/kerncompat.h
diff options
context:
space:
mode:
authorQu Wenruo <quwenruo@cn.fujitsu.com>2015-12-15 10:04:01 +0800
committerDavid Sterba <dsterba@suse.com>2016-01-12 15:01:04 +0100
commit61d6ed4fe7eff80033562380df536351b7ad6e66 (patch)
treebf6361793ec3f8fef17428f27f46ce3b535aabe5 /kerncompat.h
parentf0eae29843a95cb10d9c5f8c03f77e6b74eda656 (diff)
downloadbtrfs-progs-61d6ed4fe7eff80033562380df536351b7ad6e66.tar.gz
btrfs-progs: Enhance chunk validation check
Enhance chunk validation: 1) Num_stripes We already have such check but it's only in super block sys chunk array. Now check all on-disk chunks. 2) Chunk logical It should be aligned to sector size. This behavior should be *DOUBLE CHECKED* for 64K sector size like PPC64 or AArch64. Maybe we can found some hidden bugs. 3) Chunk length Same as chunk logical, should be aligned to sector size. 4) Stripe length It should be power of 2. 5) Chunk type Any bit out of TYPE_MAS | PROFILE_MASK is invalid. With all these much restrict rules, several fuzzed image reported in mail list should no longer cause btrfsck error. Reported-by: Vegard Nossum <vegard.nossum@oracle.com> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'kerncompat.h')
-rw-r--r--kerncompat.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/kerncompat.h b/kerncompat.h
index 7c627ba..0f207b7 100644
--- a/kerncompat.h
+++ b/kerncompat.h
@@ -310,6 +310,14 @@ static inline long IS_ERR(const void *ptr)
#define __bitwise
#endif
+/* Alignment check */
+#define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0)
+
+static inline int is_power_of_2(unsigned long n)
+{
+ return (n != 0 && ((n & (n - 1)) == 0));
+}
+
typedef u16 __bitwise __le16;
typedef u16 __bitwise __be16;
typedef u32 __bitwise __le32;