* Boston, MA 021110-1307, USA.
*/
-#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
u64 bgused = 0;
u64 saved_extent = 0;
u64 saved_len = 0;
- u64 saved_flags = 0;
int saved_color = 0;
u64 last_end = 0;
u64 areas = 0;
gdImagePtr im = NULL;
int black = 0;
- int white = 0;
int width = 800;
snprintf(name, sizeof(name), "%s/index.html", dir);
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)
im = gdImageCreate(width,
(sh->offset / 4096 + 799) / width);
- white = gdImageColorAllocate(im, 255, 255, 255);
black = gdImageColorAllocate(im, 0, 0, 0);
- for (j = 0; j < 10; ++j)
+ for (j = 0; j < ARRAY_SIZE(colors); ++j)
colors[j] = black;
init_colors(im, colors);
saved_len = 0;
}
if (im && sh->type == BTRFS_EXTENT_ITEM_KEY) {
- u64 e_flags;
int c;
struct btrfs_extent_item *item;
item = (struct btrfs_extent_item *)
(args.buf + off);
- e_flags = btrfs_stack_extent_flags(item);
if (use_color)
c = colors[get_color(item, sh->len)];
if (sh->objectid == bgend) {
saved_extent = sh->objectid;
saved_len = sh->offset;
- saved_flags = e_flags;
saved_color = c;
goto skip;
}
fprintf(html, "</p>");
}
fprintf(html, "</body></html>\n");
-
+
+out_close:
+ fclose(html);
+
return ret;
}
}
}
- if (optind < argc) {
- path = argv[optind++];
- } else {
+ set_argv0(argv);
+ argc = argc - optind;
+ if (check_argc_min(argc, 1)) {
usage();
exit(1);
}
- 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);
- }
if (flags == 0)
flags = BTRFS_BLOCK_GROUP_DATA | BTRFS_BLOCK_GROUP_METADATA;