aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ctree.h
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-03-29 15:15:27 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-03-29 15:15:27 -0400
commitf254e52c1ce550fdaa0d31f5e068f0d67c2485d4 (patch)
tree1232b7e16b6f0b1b1b150c5df396452cac5e3853 /fs/btrfs/ctree.h
parent75dfe3960e602e63ea42ac7a2a0520832b189ffa (diff)
Btrfs: verify csums on read
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/ctree.h')
-rw-r--r--fs/btrfs/ctree.h47
1 files changed, 32 insertions, 15 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 6ff87f44c5d8..df1a025a771c 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -21,6 +21,9 @@ struct btrfs_transaction;
21 */ 21 */
22#define BTRFS_NAME_LEN 255 22#define BTRFS_NAME_LEN 255
23 23
24/* 32 bytes in various csum fields */
25#define BTRFS_CSUM_SIZE 32
26
24/* 27/*
25 * the key defines the order in the tree, and so it also defines (optimal) 28 * the key defines the order in the tree, and so it also defines (optimal)
26 * block layout. objectid corresonds to the inode number. The flags 29 * block layout. objectid corresonds to the inode number. The flags
@@ -37,21 +40,21 @@ struct btrfs_transaction;
37 */ 40 */
38struct btrfs_disk_key { 41struct btrfs_disk_key {
39 __le64 objectid; 42 __le64 objectid;
40 __le32 flags;
41 __le64 offset; 43 __le64 offset;
44 __le32 flags;
42} __attribute__ ((__packed__)); 45} __attribute__ ((__packed__));
43 46
44struct btrfs_key { 47struct btrfs_key {
45 u64 objectid; 48 u64 objectid;
46 u32 flags;
47 u64 offset; 49 u64 offset;
50 u32 flags;
48} __attribute__ ((__packed__)); 51} __attribute__ ((__packed__));
49 52
50/* 53/*
51 * every tree block (leaf or node) starts with this header. 54 * every tree block (leaf or node) starts with this header.
52 */ 55 */
53struct btrfs_header { 56struct btrfs_header {
54 __le32 csum[8]; 57 u8 csum[BTRFS_CSUM_SIZE];
55 u8 fsid[16]; /* FS specific uuid */ 58 u8 fsid[16]; /* FS specific uuid */
56 __le64 blocknr; /* which block this node is supposed to live in */ 59 __le64 blocknr; /* which block this node is supposed to live in */
57 __le64 generation; 60 __le64 generation;
@@ -75,7 +78,7 @@ struct buffer_head;
75 * it currently lacks any block count etc etc 78 * it currently lacks any block count etc etc
76 */ 79 */
77struct btrfs_super_block { 80struct btrfs_super_block {
78 __le32 csum[8]; 81 u8 csum[BTRFS_CSUM_SIZE];
79 /* the first 3 fields must match struct btrfs_header */ 82 /* the first 3 fields must match struct btrfs_header */
80 u8 fsid[16]; /* FS specific uuid */ 83 u8 fsid[16]; /* FS specific uuid */
81 __le64 blocknr; /* this block number */ 84 __le64 blocknr; /* this block number */
@@ -147,7 +150,7 @@ struct btrfs_extent_item {
147} __attribute__ ((__packed__)); 150} __attribute__ ((__packed__));
148 151
149struct btrfs_inode_timespec { 152struct btrfs_inode_timespec {
150 __le32 sec; 153 __le64 sec;
151 __le32 nsec; 154 __le32 nsec;
152} __attribute__ ((__packed__)); 155} __attribute__ ((__packed__));
153 156
@@ -214,6 +217,10 @@ struct btrfs_file_extent_item {
214 __le64 num_blocks; 217 __le64 num_blocks;
215} __attribute__ ((__packed__)); 218} __attribute__ ((__packed__));
216 219
220struct btrfs_csum_item {
221 u8 csum[BTRFS_CSUM_SIZE];
222} __attribute__ ((__packed__));
223
217struct btrfs_inode_map_item { 224struct btrfs_inode_map_item {
218 struct btrfs_disk_key key; 225 struct btrfs_disk_key key;
219} __attribute__ ((__packed__)); 226} __attribute__ ((__packed__));
@@ -284,26 +291,31 @@ struct btrfs_root {
284 */ 291 */
285#define BTRFS_EXTENT_DATA_KEY 4 292#define BTRFS_EXTENT_DATA_KEY 4
286/* 293/*
294 * csum items have the checksums for data in the extents
295 */
296#define BTRFS_CSUM_ITEM_KEY 5
297
298/*
287 * root items point to tree roots. There are typically in the root 299 * root items point to tree roots. There are typically in the root
288 * tree used by the super block to find all the other trees 300 * tree used by the super block to find all the other trees
289 */ 301 */
290#define BTRFS_ROOT_ITEM_KEY 5 302#define BTRFS_ROOT_ITEM_KEY 6
291/* 303/*
292 * extent items are in the extent map tree. These record which blocks 304 * extent items are in the extent map tree. These record which blocks
293 * are used, and how many references there are to each block 305 * are used, and how many references there are to each block
294 */ 306 */
295#define BTRFS_EXTENT_ITEM_KEY 6 307#define BTRFS_EXTENT_ITEM_KEY 7
296 308
297/* 309/*
298 * the inode map records which inode numbers are in use and where 310 * the inode map records which inode numbers are in use and where
299 * they actually live on disk 311 * they actually live on disk
300 */ 312 */
301#define BTRFS_INODE_MAP_ITEM_KEY 7 313#define BTRFS_INODE_MAP_ITEM_KEY 8
302/* 314/*
303 * string items are for debugging. They just store a short string of 315 * string items are for debugging. They just store a short string of
304 * data in the FS 316 * data in the FS
305 */ 317 */
306#define BTRFS_STRING_ITEM_KEY 8 318#define BTRFS_STRING_ITEM_KEY 9
307 319
308static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i) 320static inline u64 btrfs_inode_generation(struct btrfs_inode_item *i)
309{ 321{
@@ -407,15 +419,15 @@ static inline void btrfs_set_inode_compat_flags(struct btrfs_inode_item *i,
407 i->compat_flags = cpu_to_le16(val); 419 i->compat_flags = cpu_to_le16(val);
408} 420}
409 421
410static inline u32 btrfs_timespec_sec(struct btrfs_inode_timespec *ts) 422static inline u64 btrfs_timespec_sec(struct btrfs_inode_timespec *ts)
411{ 423{
412 return le32_to_cpu(ts->sec); 424 return le64_to_cpu(ts->sec);
413} 425}
414 426
415static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts, 427static inline void btrfs_set_timespec_sec(struct btrfs_inode_timespec *ts,
416 u32 val) 428 u64 val)
417{ 429{
418 ts->sec = cpu_to_le32(val); 430 ts->sec = cpu_to_le64(val);
419} 431}
420 432
421static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts) 433static inline u32 btrfs_timespec_nsec(struct btrfs_inode_timespec *ts)
@@ -429,8 +441,6 @@ static inline void btrfs_set_timespec_nsec(struct btrfs_inode_timespec *ts,
429 ts->nsec = cpu_to_le32(val); 441 ts->nsec = cpu_to_le32(val);
430} 442}
431 443
432
433
434static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei) 444static inline u64 btrfs_extent_owner(struct btrfs_extent_item *ei)
435{ 445{
436 return le64_to_cpu(ei->owner); 446 return le64_to_cpu(ei->owner);
@@ -905,4 +915,11 @@ int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
905 struct btrfs_root *root, 915 struct btrfs_root *root,
906 struct btrfs_path *path, u64 objectid, 916 struct btrfs_path *path, u64 objectid,
907 u64 blocknr, int mod); 917 u64 blocknr, int mod);
918int btrfs_csum_file_block(struct btrfs_trans_handle *trans,
919 struct btrfs_root *root,
920 u64 objectid, u64 offset,
921 char *data, size_t len);
922int btrfs_csum_verify_file_block(struct btrfs_root *root,
923 u64 objectid, u64 offset,
924 char *data, size_t len);
908#endif 925#endif