summaryrefslogtreecommitdiff
path: root/cmds-check.c
diff options
context:
space:
mode:
authorQu Wenruo <quwenruo@cn.fujitsu.com>2014-12-09 16:27:28 +0800
committerDavid Sterba <dsterba@suse.cz>2014-12-10 13:44:53 +0100
commit15bc913158710ce6c5bc9e48d902b36ff89f8d18 (patch)
treee9e27b4f11c9733fe85f57fd90a4444aa0cba282 /cmds-check.c
parent1c4d47c037c78cce4c3d5ad7502387ebfd4370cb (diff)
btrfs-progs: Add helper function find_file_name/type for nlink and inode_item repair.
Add find_file_name() and find_file_type() function for later nlink and inode_item repair. Later nlink repair will use both function and and inode_item repair will use find_file_type(). They are done by searching the backref list, dir_item/index for type search and dir_item/index or inode_ref for name search. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'cmds-check.c')
-rw-r--r--cmds-check.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/cmds-check.c b/cmds-check.c
index 408baaa8..9c0189d9 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -1874,6 +1874,47 @@ static int repair_inode_backrefs(struct btrfs_root *root,
return ret ? ret : repaired;
}
+/*
+ * To determine the file type for nlink/inode_item repair
+ *
+ * Return 0 if file type is found and BTRFS_FT_* is stored into type.
+ * Return -ENOENT if file type is not found.
+ */
+static int find_file_type(struct inode_record *rec, u8 *type)
+{
+ struct inode_backref *backref;
+
+ list_for_each_entry(backref, &rec->backrefs, list) {
+ if (backref->found_dir_index || backref->found_dir_item) {
+ *type = backref->filetype;
+ return 0;
+ }
+ }
+ return -ENOENT;
+}
+
+/*
+ * To determine the file name for nlink repair
+ *
+ * Return 0 if file name is found, set name and namelen.
+ * Return -ENOENT if file name is not found.
+ */
+static int find_file_name(struct inode_record *rec,
+ char *name, int *namelen)
+{
+ struct inode_backref *backref;
+
+ list_for_each_entry(backref, &rec->backrefs, list) {
+ if (backref->found_dir_index || backref->found_dir_item ||
+ backref->found_inode_ref) {
+ memcpy(name, backref->name, backref->namelen);
+ *namelen = backref->namelen;
+ return 0;
+ }
+ }
+ return -ENOENT;
+}
+
static int try_repair_inode(struct btrfs_root *root, struct inode_record *rec)
{
struct btrfs_trans_handle *trans;