2009-11-12 19:34:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 Oracle. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public
|
|
|
|
* License v2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public
|
|
|
|
* License along with this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 021110-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2022-09-14 15:06:52 +00:00
|
|
|
#include "kerncompat.h"
|
2009-11-12 19:34:09 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <getopt.h>
|
2022-09-15 11:10:53 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "kernel-lib/sizes.h"
|
2023-08-28 20:12:13 +00:00
|
|
|
#include "kernel-shared/accessors.h"
|
|
|
|
#include "kernel-shared/uapi/btrfs_tree.h"
|
2020-08-18 13:56:04 +00:00
|
|
|
#include "kernel-shared/ctree.h"
|
2022-09-15 11:10:53 +00:00
|
|
|
#include "kernel-shared/extent_io.h"
|
2020-08-18 13:56:04 +00:00
|
|
|
#include "kernel-shared/volumes.h"
|
2020-08-18 13:56:04 +00:00
|
|
|
#include "kernel-shared/disk-io.h"
|
2022-09-15 11:10:53 +00:00
|
|
|
#include "common/internal.h"
|
2023-08-28 20:12:13 +00:00
|
|
|
#include "common/messages.h"
|
2019-06-19 23:46:21 +00:00
|
|
|
#include "common/help.h"
|
2022-09-15 11:10:53 +00:00
|
|
|
#include "common/extent-cache.h"
|
2023-08-23 14:32:41 +00:00
|
|
|
#include "common/extent-tree-utils.h"
|
2022-09-15 21:15:17 +00:00
|
|
|
#include "common/string-utils.h"
|
2023-02-21 23:39:14 +00:00
|
|
|
#include "cmds/commands.h"
|
2009-11-12 19:34:09 +00:00
|
|
|
|
2017-01-24 03:03:05 +00:00
|
|
|
#define BUFFER_SIZE SZ_64K
|
2015-06-17 07:49:03 +00:00
|
|
|
|
2009-11-12 19:34:09 +00:00
|
|
|
/* we write the mirror info to stdout unless they are dumping the data
|
|
|
|
* to stdout
|
|
|
|
* */
|
|
|
|
static FILE *info_file;
|
|
|
|
|
2015-06-17 07:49:01 +00:00
|
|
|
static int map_one_extent(struct btrfs_fs_info *fs_info,
|
2018-06-07 13:23:41 +00:00
|
|
|
u64 *logical_ret, u64 *len_ret, int search_forward)
|
2015-06-17 07:49:01 +00:00
|
|
|
{
|
2021-11-08 19:26:41 +00:00
|
|
|
struct btrfs_root *extent_root;
|
2015-06-17 07:49:01 +00:00
|
|
|
struct btrfs_path *path;
|
|
|
|
struct btrfs_key key;
|
|
|
|
u64 logical;
|
|
|
|
u64 len = 0;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
BUG_ON(!logical_ret);
|
|
|
|
logical = *logical_ret;
|
|
|
|
|
|
|
|
path = btrfs_alloc_path();
|
|
|
|
if (!path)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
key.objectid = logical;
|
|
|
|
key.type = 0;
|
|
|
|
key.offset = 0;
|
|
|
|
|
2021-11-08 19:26:41 +00:00
|
|
|
extent_root = btrfs_extent_root(fs_info, logical);
|
|
|
|
ret = btrfs_search_slot(NULL, extent_root, &key, path, 0, 0);
|
2015-06-17 07:49:01 +00:00
|
|
|
if (ret < 0)
|
|
|
|
goto out;
|
|
|
|
BUG_ON(ret == 0);
|
|
|
|
ret = 0;
|
|
|
|
|
btrfs-progs: map-logical: fix search miss when extent is the first in a leaf
When searching the extent tree for the target extent item, we can miss it
if the extent item is the first item in a leaf and if there is a previous
leaf in the extent tree.
For example, if we call btrfs-map-logical like this:
$ btrfs-map-logical -l 5382144 /dev/sdc
And we have the following extent tree layout:
leaf 5386240 items 26 free space 2505 generation 7 owner EXTENT_TREE
leaf 5386240 flags 0x1(WRITTEN) backref revision 1
(...)
item 25 key (5373952 METADATA_ITEM 0) itemoff 3155 itemsize 33
refs 1 gen 7 flags TREE_BLOCK
tree block skinny level 0
(176 0x5) tree block backref root FS_TREE
leaf 5480448 items 56 free space 276 generation 7 owner EXTENT_TREE
leaf 5480448 flags 0x1(WRITTEN) backref revision 1
(...)
item 0 key (5382144 METADATA_ITEM 0) itemoff 3962 itemsize 33
refs 1 gen 7 flags TREE_BLOCK
tree block skinny level 0
(176 0x7) tree block backref root CSUM_TREE
(...)
Then the following happens:
1) We enter map_one_extent() with search_forward == 0 and
*logical_ret == 5382144;
2) We search for the key (5382144 0 0) which leaves us with a path
pointing to leaf 5386240 at slot 26 - one slot beyond the last item;
3) We then call:
btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0])
Which is not valid since there's no item at that slot, but since the
area of the leaf where an item at that slot should be is zeroed out,
we end up getting a key of (0 0 0);
4) We then enter the "if" statement bellow, since key.type is 0, and call
btrfs_previous_extent_item(), which leaves at slot 25 of leaf 5386240,
point to the extent item of the extent 5373952.
The requested extent, 5382144, is the first item of the next leaf
(5480448), but we totally miss it;
5) We return to the caller, the main() function, with 'cur_logical'
pointing to the metadata extent at 5373952, and not to the requested
one at 5382144.
In the last while loop of main() we have 'cur_logical' == 5373952,
which makes the loop have no iterations and therefore the local
variable 'found' remains with a value of 0, and then the program fails
like this:
$ btrfs-map-logical -l 5382144 /dev/sdc
ERROR: no extent found at range [5382144,5386240)
Fix this by never accessing beyond the last slot of a leaf. If we ever end
up at a slot beyond the last item in a leaf, just call btrfs_next_leaf()
and process the first item in the returned path.
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
2024-09-12 14:05:44 +00:00
|
|
|
if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) {
|
|
|
|
ret = btrfs_next_leaf(extent_root, path);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
}
|
2015-06-17 07:49:01 +00:00
|
|
|
again:
|
|
|
|
btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
|
2018-06-07 13:23:41 +00:00
|
|
|
if ((search_forward && key.objectid < logical) ||
|
|
|
|
(!search_forward && key.objectid > logical) ||
|
2015-06-17 07:49:01 +00:00
|
|
|
(key.type != BTRFS_EXTENT_ITEM_KEY &&
|
|
|
|
key.type != BTRFS_METADATA_ITEM_KEY)) {
|
2018-06-07 13:23:41 +00:00
|
|
|
if (!search_forward)
|
2021-11-08 19:26:41 +00:00
|
|
|
ret = btrfs_previous_extent_item(extent_root,
|
2015-06-17 07:49:01 +00:00
|
|
|
path, 0);
|
|
|
|
else
|
2021-11-08 19:26:41 +00:00
|
|
|
ret = btrfs_next_extent_item(extent_root,
|
2018-06-07 07:20:02 +00:00
|
|
|
path, 0);
|
2015-06-17 07:49:01 +00:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
logical = key.objectid;
|
|
|
|
if (key.type == BTRFS_METADATA_ITEM_KEY)
|
2017-05-18 01:21:05 +00:00
|
|
|
len = fs_info->nodesize;
|
2015-06-17 07:49:01 +00:00
|
|
|
else
|
|
|
|
len = key.offset;
|
|
|
|
|
|
|
|
out:
|
|
|
|
btrfs_free_path(path);
|
|
|
|
if (!ret) {
|
|
|
|
*logical_ret = logical;
|
|
|
|
if (len_ret)
|
|
|
|
*len_ret = len;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-06-17 07:49:02 +00:00
|
|
|
static int __print_mapping_info(struct btrfs_fs_info *fs_info, u64 logical,
|
|
|
|
u64 len, int mirror_num)
|
|
|
|
{
|
|
|
|
struct btrfs_multi_bio *multi = NULL;
|
|
|
|
u64 cur_offset = 0;
|
|
|
|
u64 cur_len;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
while (cur_offset < len) {
|
|
|
|
struct btrfs_device *device;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
cur_len = len - cur_offset;
|
2017-06-13 09:19:17 +00:00
|
|
|
ret = btrfs_map_block(fs_info, READ, logical + cur_offset,
|
|
|
|
&cur_len, &multi, mirror_num, NULL);
|
2015-06-17 07:49:02 +00:00
|
|
|
if (ret) {
|
2018-10-25 12:10:54 +00:00
|
|
|
errno = -ret;
|
2015-06-17 07:49:02 +00:00
|
|
|
fprintf(info_file,
|
2018-10-25 12:10:54 +00:00
|
|
|
"Error: fails to map mirror%d logical %llu: %m\n",
|
|
|
|
mirror_num, logical);
|
2015-06-17 07:49:02 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
for (i = 0; i < multi->num_stripes; i++) {
|
|
|
|
device = multi->stripes[i].dev;
|
|
|
|
fprintf(info_file,
|
2021-06-11 21:07:50 +00:00
|
|
|
"mirror %d logical %llu physical %llu device %s\n",
|
2015-06-17 07:49:02 +00:00
|
|
|
mirror_num, logical + cur_offset,
|
|
|
|
multi->stripes[0].physical,
|
|
|
|
device->name);
|
|
|
|
}
|
2016-09-07 14:22:33 +00:00
|
|
|
free(multi);
|
2015-06-17 07:49:02 +00:00
|
|
|
multi = NULL;
|
|
|
|
cur_offset += cur_len;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Logical and len is the exact value of a extent.
|
|
|
|
* And offset is the offset inside the extent. It's only used for case
|
|
|
|
* where user only want to print part of the extent.
|
|
|
|
*
|
|
|
|
* Caller *MUST* ensure the range [logical,logical+len) are in one extent.
|
|
|
|
* Or we can encounter the following case, causing a -ENOENT error:
|
|
|
|
* |<-----given parameter------>|
|
|
|
|
* |<------ Extent A ----->|
|
|
|
|
*/
|
|
|
|
static int print_mapping_info(struct btrfs_fs_info *fs_info, u64 logical,
|
|
|
|
u64 len)
|
|
|
|
{
|
|
|
|
int num_copies;
|
|
|
|
int mirror_num;
|
|
|
|
int ret = 0;
|
|
|
|
|
2017-06-13 09:19:18 +00:00
|
|
|
num_copies = btrfs_num_copies(fs_info, logical, len);
|
2015-06-17 07:49:02 +00:00
|
|
|
for (mirror_num = 1; mirror_num <= num_copies; mirror_num++) {
|
|
|
|
ret = __print_mapping_info(fs_info, logical, len, mirror_num);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-06-17 07:49:03 +00:00
|
|
|
/* Same requisition as print_mapping_info function */
|
|
|
|
static int write_extent_content(struct btrfs_fs_info *fs_info, int out_fd,
|
|
|
|
u64 logical, u64 length, int mirror)
|
|
|
|
{
|
|
|
|
char buffer[BUFFER_SIZE];
|
|
|
|
u64 cur_offset = 0;
|
|
|
|
u64 cur_len;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
while (cur_offset < length) {
|
|
|
|
cur_len = min_t(u64, length - cur_offset, BUFFER_SIZE);
|
2022-04-05 12:48:27 +00:00
|
|
|
ret = read_data_from_disk(fs_info, buffer,
|
|
|
|
logical + cur_offset, &cur_len,
|
|
|
|
mirror);
|
2015-06-17 07:49:03 +00:00
|
|
|
if (ret < 0) {
|
2018-10-25 12:10:54 +00:00
|
|
|
errno = -ret;
|
2022-09-19 10:17:19 +00:00
|
|
|
error("failed to read extent at [%llu, %llu]: %m",
|
2018-10-25 12:10:54 +00:00
|
|
|
logical, logical + length);
|
2015-06-17 07:49:03 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
ret = write(out_fd, buffer, cur_len);
|
|
|
|
if (ret < 0 || ret != cur_len) {
|
|
|
|
if (ret > 0)
|
|
|
|
ret = -EINTR;
|
2018-10-25 12:10:54 +00:00
|
|
|
errno = -ret;
|
2022-09-19 10:17:19 +00:00
|
|
|
error("output file write failed: %m");
|
2015-06-17 07:49:03 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
cur_offset += cur_len;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-02-21 23:39:14 +00:00
|
|
|
static const char * const map_logical_usage[] = {
|
|
|
|
"btrfs-map-logical [options] device",
|
2023-08-18 16:23:15 +00:00
|
|
|
"Map logical address on a device",
|
2023-02-21 23:39:14 +00:00
|
|
|
"",
|
|
|
|
OPTLINE("-l OFFSET", "logical extent to map"),
|
|
|
|
OPTLINE("-c COPY", "copy of the extent to read (usually 1 or 2)"),
|
|
|
|
OPTLINE("-o FILE", "output file to hold the extent"),
|
|
|
|
OPTLINE("-b BYTES", "number of bytes to read"),
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct cmd_struct map_logical_cmd = {
|
|
|
|
.usagestr = map_logical_usage
|
|
|
|
};
|
2009-11-12 19:34:09 +00:00
|
|
|
|
2016-03-01 15:28:11 +00:00
|
|
|
int main(int argc, char **argv)
|
2009-11-12 19:34:09 +00:00
|
|
|
{
|
|
|
|
struct cache_tree root_cache;
|
|
|
|
struct btrfs_root *root;
|
|
|
|
char *dev;
|
|
|
|
char *output_file = NULL;
|
2014-02-20 01:30:51 +00:00
|
|
|
u64 copy = 0;
|
2015-06-17 07:49:04 +00:00
|
|
|
u64 logical = 0;
|
2009-11-12 19:34:09 +00:00
|
|
|
u64 bytes = 0;
|
2015-06-17 07:49:04 +00:00
|
|
|
u64 cur_logical = 0;
|
|
|
|
u64 cur_len = 0;
|
|
|
|
int out_fd = -1;
|
|
|
|
int found = 0;
|
|
|
|
int ret = 0;
|
2009-11-12 19:34:09 +00:00
|
|
|
|
|
|
|
while(1) {
|
|
|
|
int c;
|
2015-01-19 12:44:49 +00:00
|
|
|
static const struct option long_options[] = {
|
2015-01-19 12:30:06 +00:00
|
|
|
/* { "byte-count", 1, NULL, 'b' }, */
|
2015-04-08 15:39:51 +00:00
|
|
|
{ "logical", required_argument, NULL, 'l' },
|
|
|
|
{ "copy", required_argument, NULL, 'c' },
|
|
|
|
{ "output", required_argument, NULL, 'o' },
|
|
|
|
{ "bytes", required_argument, NULL, 'b' },
|
2015-01-19 12:30:06 +00:00
|
|
|
{ NULL, 0, NULL, 0}
|
|
|
|
};
|
|
|
|
|
2016-03-01 15:28:11 +00:00
|
|
|
c = getopt_long(argc, argv, "l:c:o:b:", long_options, NULL);
|
2009-11-12 19:34:09 +00:00
|
|
|
if (c < 0)
|
|
|
|
break;
|
|
|
|
switch(c) {
|
|
|
|
case 'l':
|
2014-02-20 01:30:51 +00:00
|
|
|
logical = arg_strtou64(optarg);
|
2009-11-12 19:34:09 +00:00
|
|
|
break;
|
|
|
|
case 'c':
|
2014-02-20 01:30:51 +00:00
|
|
|
copy = arg_strtou64(optarg);
|
2009-11-12 19:34:09 +00:00
|
|
|
break;
|
|
|
|
case 'b':
|
2014-02-20 01:30:51 +00:00
|
|
|
bytes = arg_strtou64(optarg);
|
2009-11-12 19:34:09 +00:00
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
output_file = strdup(optarg);
|
|
|
|
break;
|
|
|
|
default:
|
2023-02-21 23:39:14 +00:00
|
|
|
usage(&map_logical_cmd, 1);
|
2009-11-12 19:34:09 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-01 15:28:11 +00:00
|
|
|
set_argv0(argv);
|
2016-03-01 15:29:16 +00:00
|
|
|
if (check_argc_min(argc - optind, 1))
|
2019-03-04 13:49:15 +00:00
|
|
|
return 1;
|
2009-11-12 19:34:09 +00:00
|
|
|
if (logical == 0)
|
2023-02-21 23:39:14 +00:00
|
|
|
usage(&map_logical_cmd, 1);
|
2009-11-12 19:34:09 +00:00
|
|
|
|
2016-03-01 15:28:11 +00:00
|
|
|
dev = argv[optind];
|
2009-11-12 19:34:09 +00:00
|
|
|
|
|
|
|
cache_tree_init(&root_cache);
|
|
|
|
|
|
|
|
root = open_ctree(dev, 0, 0);
|
|
|
|
if (!root) {
|
2022-09-19 10:17:19 +00:00
|
|
|
error("open ctree failed");
|
2015-08-27 15:38:17 +00:00
|
|
|
free(output_file);
|
2009-11-12 19:34:09 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-03-14 11:57:49 +00:00
|
|
|
info_file = stdout;
|
2009-11-12 19:34:09 +00:00
|
|
|
if (output_file) {
|
|
|
|
if (strcmp(output_file, "-") == 0) {
|
|
|
|
out_fd = 1;
|
|
|
|
info_file = stderr;
|
|
|
|
} else {
|
|
|
|
out_fd = open(output_file, O_RDWR | O_CREAT, 0600);
|
|
|
|
if (out_fd < 0)
|
|
|
|
goto close;
|
2013-08-01 05:35:33 +00:00
|
|
|
ret = ftruncate(out_fd, 0);
|
|
|
|
if (ret) {
|
|
|
|
ret = 1;
|
2009-11-12 19:34:09 +00:00
|
|
|
close(out_fd);
|
|
|
|
goto close;
|
|
|
|
}
|
|
|
|
info_file = stdout;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bytes == 0)
|
2017-05-18 01:21:05 +00:00
|
|
|
bytes = root->fs_info->nodesize;
|
2015-06-17 07:49:04 +00:00
|
|
|
cur_logical = logical;
|
|
|
|
cur_len = bytes;
|
|
|
|
|
|
|
|
/* First find the nearest extent */
|
|
|
|
ret = map_one_extent(root->fs_info, &cur_logical, &cur_len, 0);
|
|
|
|
if (ret < 0) {
|
2018-10-25 12:10:54 +00:00
|
|
|
errno = -ret;
|
2022-09-19 10:17:19 +00:00
|
|
|
error("failed to find extent at [%llu,%llu): %m",
|
2018-10-25 12:10:54 +00:00
|
|
|
cur_logical, cur_logical + cur_len);
|
2015-06-17 07:49:04 +00:00
|
|
|
goto out_close_fd;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Normally, search backward should be OK, but for special case like
|
|
|
|
* given logical is quite small where no extents are before it,
|
|
|
|
* we need to search forward.
|
|
|
|
*/
|
|
|
|
if (ret > 0) {
|
|
|
|
ret = map_one_extent(root->fs_info, &cur_logical, &cur_len, 1);
|
|
|
|
if (ret < 0) {
|
2018-10-25 12:10:54 +00:00
|
|
|
errno = -ret;
|
2022-09-19 10:17:19 +00:00
|
|
|
error("Failed to find extent at [%llu,%llu): %m",
|
2018-10-25 12:10:54 +00:00
|
|
|
cur_logical, cur_logical + cur_len);
|
2015-06-17 07:49:04 +00:00
|
|
|
goto out_close_fd;
|
|
|
|
}
|
|
|
|
if (ret > 0) {
|
2022-09-19 10:17:19 +00:00
|
|
|
error("failed to find any extent at [%llu,%llu)",
|
2015-06-17 07:49:04 +00:00
|
|
|
cur_logical, cur_logical + cur_len);
|
|
|
|
goto out_close_fd;
|
|
|
|
}
|
|
|
|
}
|
2009-11-12 19:34:09 +00:00
|
|
|
|
2015-06-17 07:49:04 +00:00
|
|
|
while (cur_logical + cur_len >= logical && cur_logical < logical +
|
|
|
|
bytes) {
|
|
|
|
u64 real_logical;
|
|
|
|
u64 real_len;
|
2009-11-12 19:34:09 +00:00
|
|
|
|
2015-06-17 07:49:04 +00:00
|
|
|
found = 1;
|
|
|
|
ret = map_one_extent(root->fs_info, &cur_logical, &cur_len, 1);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out_close_fd;
|
|
|
|
if (ret > 0)
|
|
|
|
break;
|
2016-07-15 01:40:27 +00:00
|
|
|
/* check again if there is overlap. */
|
|
|
|
if (cur_logical + cur_len < logical ||
|
|
|
|
cur_logical >= logical + bytes)
|
|
|
|
break;
|
|
|
|
|
2015-06-17 07:49:04 +00:00
|
|
|
real_logical = max(logical, cur_logical);
|
|
|
|
real_len = min(logical + bytes, cur_logical + cur_len) -
|
|
|
|
real_logical;
|
|
|
|
|
|
|
|
ret = print_mapping_info(root->fs_info, real_logical, real_len);
|
|
|
|
if (ret < 0)
|
|
|
|
goto out_close_fd;
|
|
|
|
if (output_file && out_fd != -1) {
|
|
|
|
ret = write_extent_content(root->fs_info, out_fd,
|
|
|
|
real_logical, real_len, copy);
|
|
|
|
if (ret < 0)
|
2009-11-12 19:34:09 +00:00
|
|
|
goto out_close_fd;
|
|
|
|
}
|
2015-06-17 07:49:04 +00:00
|
|
|
|
|
|
|
cur_logical += cur_len;
|
2009-11-12 19:34:09 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 07:49:04 +00:00
|
|
|
if (!found) {
|
2022-09-19 10:17:19 +00:00
|
|
|
error("no extent found at range [%llu,%llu)",
|
2015-06-17 07:49:04 +00:00
|
|
|
logical, logical + bytes);
|
|
|
|
}
|
2009-11-12 19:34:09 +00:00
|
|
|
out_close_fd:
|
|
|
|
if (output_file && out_fd != 1)
|
|
|
|
close(out_fd);
|
|
|
|
close:
|
2015-08-27 15:38:17 +00:00
|
|
|
free(output_file);
|
2009-11-12 19:34:09 +00:00
|
|
|
close_ctree(root);
|
2015-06-17 07:49:04 +00:00
|
|
|
if (ret < 0)
|
|
|
|
ret = 1;
|
2015-10-26 10:28:20 +00:00
|
|
|
btrfs_close_all_devices();
|
2009-11-12 19:34:09 +00:00
|
|
|
return ret;
|
|
|
|
}
|