xref: /linux/fs/btrfs/backref.h (revision ef69f8d2ff09518657c3ecaf2db8408c16549829)
1 /*
2  * Copyright (C) 2011 STRATO.  All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public
6  * License v2 as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public
14  * License along with this program; if not, write to the
15  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16  * Boston, MA 021110-1307, USA.
17  */
18 
19 #ifndef __BTRFS_BACKREF__
20 #define __BTRFS_BACKREF__
21 
22 #include <linux/btrfs.h>
23 #include "ulist.h"
24 #include "extent_io.h"
25 
26 struct inode_fs_paths {
27 	struct btrfs_path		*btrfs_path;
28 	struct btrfs_root		*fs_root;
29 	struct btrfs_data_container	*fspath;
30 };
31 
32 typedef int (iterate_extent_inodes_t)(u64 inum, u64 offset, u64 root,
33 		void *ctx);
34 
35 int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
36 			struct btrfs_path *path, struct btrfs_key *found_key,
37 			u64 *flags);
38 
39 int tree_backref_for_extent(unsigned long *ptr, struct extent_buffer *eb,
40 			    struct btrfs_key *key, struct btrfs_extent_item *ei,
41 			    u32 item_size, u64 *out_root, u8 *out_level);
42 
43 int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
44 				u64 extent_item_objectid,
45 				u64 extent_offset, int search_commit_root,
46 				iterate_extent_inodes_t *iterate, void *ctx,
47 				bool ignore_offset);
48 
49 int iterate_inodes_from_logical(u64 logical, struct btrfs_fs_info *fs_info,
50 				struct btrfs_path *path,
51 				iterate_extent_inodes_t *iterate, void *ctx,
52 				bool ignore_offset);
53 
54 int paths_from_inode(u64 inum, struct inode_fs_paths *ipath);
55 
56 int btrfs_find_all_roots(struct btrfs_trans_handle *trans,
57 			 struct btrfs_fs_info *fs_info, u64 bytenr,
58 			 u64 time_seq, struct ulist **roots, bool ignore_offset);
59 char *btrfs_ref_to_path(struct btrfs_root *fs_root, struct btrfs_path *path,
60 			u32 name_len, unsigned long name_off,
61 			struct extent_buffer *eb_in, u64 parent,
62 			char *dest, u32 size);
63 
64 struct btrfs_data_container *init_data_container(u32 total_bytes);
65 struct inode_fs_paths *init_ipath(s32 total_bytes, struct btrfs_root *fs_root,
66 					struct btrfs_path *path);
67 void free_ipath(struct inode_fs_paths *ipath);
68 
69 int btrfs_find_one_extref(struct btrfs_root *root, u64 inode_objectid,
70 			  u64 start_off, struct btrfs_path *path,
71 			  struct btrfs_inode_extref **ret_extref,
72 			  u64 *found_off);
73 int btrfs_check_shared(struct btrfs_root *root, u64 inum, u64 bytenr);
74 
75 int __init btrfs_prelim_ref_init(void);
76 void btrfs_prelim_ref_exit(void);
77 
78 struct prelim_ref {
79 	struct rb_node rbnode;
80 	u64 root_id;
81 	struct btrfs_key key_for_search;
82 	int level;
83 	int count;
84 	struct extent_inode_elem *inode_list;
85 	u64 parent;
86 	u64 wanted_disk_byte;
87 };
88 
89 #endif
90