projects
/
platform
/
upstream
/
btrfs-progs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
btrfs-progs: fsck-tests: Introduce test case with keyed data backref with the extent...
[platform/upstream/btrfs-progs.git]
/
btrfs-fragments.c
diff --git
a/btrfs-fragments.c
b/btrfs-fragments.c
index
160429a
..
46c78d2
100644
(file)
--- a/
btrfs-fragments.c
+++ b/
btrfs-fragments.c
@@
-14,7
+14,6
@@
* Boston, MA 021110-1307, USA.
*/
* Boston, MA 021110-1307, USA.
*/
-#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@
-219,7
+218,7
@@
list_fragments(int fd, u64 flags, char *dir)
memset(&args, 0, sizeof(args));
memset(&args, 0, sizeof(args));
- sk->tree_id =
2
;
+ sk->tree_id =
BTRFS_EXTENT_TREE_OBJECTID
;
sk->max_type = -1;
sk->min_type = 0;
sk->max_objectid = (u64)-1;
sk->max_type = -1;
sk->min_type = 0;
sk->max_objectid = (u64)-1;
@@
-233,7
+232,7
@@
list_fragments(int fd, u64 flags, char *dir)
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
if (ret < 0) {
fprintf(stderr, "ERROR: can't perform the search\n");
ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
if (ret < 0) {
fprintf(stderr, "ERROR: can't perform the search\n");
-
return ret
;
+
goto out_close
;
}
/* the ioctl returns the number of item it found in nr_items */
if (sk->nr_items == 0)
}
/* the ioctl returns the number of item it found in nr_items */
if (sk->nr_items == 0)
@@
-246,7
+245,8
@@
list_fragments(int fd, u64 flags, char *dir)
sh = (struct btrfs_ioctl_search_header *)(args.buf +
off);
off += sizeof(*sh);
sh = (struct btrfs_ioctl_search_header *)(args.buf +
off);
off += sizeof(*sh);
- if (sh->type == BTRFS_BLOCK_GROUP_ITEM_KEY) {
+ if (btrfs_search_header_type(sh)
+ == BTRFS_BLOCK_GROUP_ITEM_KEY) {
struct btrfs_block_group_item *bg;
if (im) {
struct btrfs_block_group_item *bg;
if (im) {
@@
-263,20
+263,24
@@
list_fragments(int fd, u64 flags, char *dir)
(args.buf + off);
bgflags = btrfs_block_group_flags(bg);
bgused = btrfs_block_group_used(bg);
(args.buf + off);
bgflags = btrfs_block_group_flags(bg);
bgused = btrfs_block_group_used(bg);
-
+
printf("found block group %lld len %lld "
printf("found block group %lld len %lld "
- "flags %lld\n", sh->objectid,
- sh->offset, bgflags);
+ "flags %lld\n",
+ btrfs_search_header_objectid(sh),
+ btrfs_search_header_offset(sh),
+ bgflags);
if (!(bgflags & flags)) {
/* skip this block group */
if (!(bgflags & flags)) {
/* skip this block group */
- sk->min_objectid = sh->objectid +
- sh->offset;
+ sk->min_objectid =
+ btrfs_search_header_objectid(sh) +
+ btrfs_search_header_offset(sh);
sk->min_type = 0;
sk->min_offset = 0;
break;
}
im = gdImageCreate(width,
sk->min_type = 0;
sk->min_offset = 0;
break;
}
im = gdImageCreate(width,
- (sh->offset / 4096 + 799) / width);
+ (btrfs_search_header_offset(sh)
+ / 4096 + 799) / width);
black = gdImageColorAllocate(im, 0, 0, 0);
black = gdImageColorAllocate(im, 0, 0, 0);
@@
-284,8
+288,8
@@
list_fragments(int fd, u64 flags, char *dir)
colors[j] = black;
init_colors(im, colors);
colors[j] = black;
init_colors(im, colors);
- bgstart =
sh->objectid
;
- bglen =
sh->offset
;
+ bgstart =
btrfs_search_header_objectid(sh)
;
+ bglen =
btrfs_search_header_offset(sh)
;
bgend = bgstart + bglen;
snprintf(name, sizeof(name), "bg%d.png", bgnum);
bgend = bgstart + bglen;
snprintf(name, sizeof(name), "bg%d.png", bgnum);
@@
-304,7
+308,8
@@
list_fragments(int fd, u64 flags, char *dir)
areas = 0;
saved_len = 0;
}
areas = 0;
saved_len = 0;
}
- if (im && sh->type == BTRFS_EXTENT_ITEM_KEY) {
+ if (im && btrfs_search_header_type(sh)
+ == BTRFS_EXTENT_ITEM_KEY) {
int c;
struct btrfs_extent_item *item;
int c;
struct btrfs_extent_item *item;
@@
-312,40
+317,48
@@
list_fragments(int fd, u64 flags, char *dir)
(args.buf + off);
if (use_color)
(args.buf + off);
if (use_color)
- c = colors[get_color(item, sh->len)];
+ c = colors[get_color(item,
+ btrfs_search_header_len(sh))];
else
c = black;
else
c = black;
- if (
sh->objectid
> bgend) {
+ if (
btrfs_search_header_objectid(sh)
> bgend) {
printf("WARN: extent %lld is without "
printf("WARN: extent %lld is without "
- "block group\n", sh->objectid);
+ "block group\n",
+ btrfs_search_header_objectid(sh));
goto skip;
}
goto skip;
}
- if (sh->objectid == bgend) {
- saved_extent = sh->objectid;
- saved_len = sh->offset;
+ if (btrfs_search_header_objectid(sh) == bgend) {
+ saved_extent =
+ btrfs_search_header_objectid(sh);
+ saved_len =
+ btrfs_search_header_offset(sh);
saved_color = c;
goto skip;
}
saved_color = c;
goto skip;
}
- px = (sh->objectid - bgstart) / 4096;
- for (j = 0; j < sh->offset / 4096; ++j) {
+ px = (btrfs_search_header_objectid(sh)
+ - bgstart) / 4096;
+ for (j = 0;
+ j < btrfs_search_header_offset(sh) / 4096;
+ ++j) {
int x = (px + j) % width;
int y = (px + j) / width;
gdImageSetPixel(im, x, y, c);
}
int x = (px + j) % width;
int y = (px + j) / width;
gdImageSetPixel(im, x, y, c);
}
- if (
sh->objectid
!= last_end)
+ if (
btrfs_search_header_objectid(sh)
!= last_end)
++areas;
++areas;
- last_end = sh->objectid + sh->offset;
+ last_end = btrfs_search_header_objectid(sh)
+ + btrfs_search_header_offset(sh);
skip:;
}
skip:;
}
- off +=
sh->len
;
+ off +=
btrfs_search_header_len(sh)
;
/*
* record the mins in sk so we can make sure the
* next search doesn't repeat this root
*/
/*
* record the mins in sk so we can make sure the
* next search doesn't repeat this root
*/
- sk->min_objectid =
sh->objectid
;
- sk->min_type =
sh->type
;
- sk->min_offset =
sh->offset
;
+ sk->min_objectid =
btrfs_search_header_objectid(sh)
;
+ sk->min_type =
btrfs_search_header_type(sh)
;
+ sk->min_offset =
btrfs_search_header_offset(sh)
;
}
sk->nr_items = 4096;
}
sk->nr_items = 4096;
@@
-373,12
+386,14
@@
skip:;
fprintf(html, "</p>");
}
fprintf(html, "</body></html>\n");
fprintf(html, "</p>");
}
fprintf(html, "</body></html>\n");
-
+
+out_close:
+ fclose(html);
+
return ret;
}
return ret;
}
-void
-usage(void)
+void fragments_usage(void)
{
printf("usage: btrfs-fragments [options] <path>\n");
printf(" -c use color\n");
{
printf("usage: btrfs-fragments [options] <path>\n");
printf(" -c use color\n");
@@
-421,22
+436,19
@@
int main(int argc, char **argv)
break;
case 'h':
default:
break;
case 'h':
default:
- usage();
+
fragments_
usage();
}
}
}
}
- if (optind < argc) {
- path = argv[optind++];
- } else {
- usage();
- exit(1);
- }
+ set_argv0(argv);
+ if (check_argc_min(argc - optind, 1))
+ fragments_usage();
- fd = open_file_or_dir(path, &dirstream);
- if (fd < 0) {
- fprintf(stderr, "ERROR: can't access '%s'\n", path);
+ path = argv[optind++];
+
+ fd = btrfs_open_dir(path, &dirstream, 1);
+ if (fd < 0)
exit(1);
exit(1);
- }
if (flags == 0)
flags = BTRFS_BLOCK_GROUP_DATA | BTRFS_BLOCK_GROUP_METADATA;
if (flags == 0)
flags = BTRFS_BLOCK_GROUP_DATA | BTRFS_BLOCK_GROUP_METADATA;