From f06bfcf54d0e91892fcd1379e04aae9cd031fc78 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Wed, 24 Jun 2020 18:03:01 +0200 Subject: fs: btrfs: Crossport open_ctree_fs_info() from btrfs-progs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit open_ctree_fs_info() is the main entry point to open btrfs. This version is a simplfied version of __open_ctree_fd() of btrfs-progs, the main differences are: - Parameters on how to specify a block device Instead of @fd and @path, U-Boot uses blk_desc and disk_partition_t. - Remove open_ctree flags There won't be multiple open ctree modes in U-Boot. Otherwise functions structures are all kept the same. With open_ctree_fs_info() implemented, also introduce the global current_fs_info pointer to show the current opened btrfs. Signed-off-by: Qu Wenruo Reviewed-by: Marek BehĂșn --- fs/btrfs/btrfs.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'fs/btrfs/btrfs.c') diff --git a/fs/btrfs/btrfs.c b/fs/btrfs/btrfs.c index f5266f1b91..2bd2ec9ed9 100644 --- a/fs/btrfs/btrfs.c +++ b/fs/btrfs/btrfs.c @@ -14,6 +14,7 @@ #include "disk-io.h" struct btrfs_info btrfs_info; +struct btrfs_fs_info *current_fs_info; static int readdir_callback(const struct __btrfs_root *root, struct btrfs_dir_item *item) @@ -81,6 +82,9 @@ static int readdir_callback(const struct __btrfs_root *root, int btrfs_probe(struct blk_desc *fs_dev_desc, struct disk_partition *fs_partition) { + struct btrfs_fs_info *fs_info; + int ret = -1; + btrfs_blk_desc = fs_dev_desc; btrfs_part_info = fs_partition; @@ -111,7 +115,12 @@ int btrfs_probe(struct blk_desc *fs_dev_desc, return -1; } - return 0; + fs_info = open_ctree_fs_info(fs_dev_desc, fs_partition); + if (fs_info) { + current_fs_info = fs_info; + ret = 0; + } + return ret; } int btrfs_ls(const char *path) @@ -215,6 +224,10 @@ int btrfs_read(const char *file, void *buf, loff_t offset, loff_t len, void btrfs_close(void) { btrfs_chunk_map_exit(); + if (current_fs_info) { + close_ctree_fs_info(current_fs_info); + current_fs_info = NULL; + } } int btrfs_uuid(char *uuid_str) -- cgit v1.2.3