int ret;
DIR *dirstream = NULL;
- optind = 1;
while (1) {
int c = getopt(argc, argv, "v");
if (c < 0)
struct btrfs_ioctl_logical_ino_args loi;
struct btrfs_data_container *inodes;
u64 size = 4096;
- char full_path[4096];
+ char full_path[PATH_MAX];
char *path_ptr;
DIR *dirstream = NULL;
- optind = 1;
while (1) {
int c = getopt(argc, argv, "Pvs:");
if (c < 0)
ret = snprintf(full_path, bytes_left, "%s/", argv[optind+1]);
path_ptr = full_path + ret;
bytes_left -= ret + 1;
- BUG_ON(bytes_left < 0);
+ if (bytes_left < 0) {
+ error("path buffer too small: %d bytes", bytes_left);
+ goto out;
+ }
for (i = 0; i < inodes->elem_cnt; i += 3) {
u64 inum = inodes->val[i];
path_ptr[-1] = '/';
ret = snprintf(path_ptr, bytes_left, "%s",
name);
- BUG_ON(ret >= bytes_left);
free(name);
+ if (ret >= bytes_left) {
+ error("path buffer too small: %d bytes",
+ bytes_left - ret);
+ goto out;
+ }
path_fd = btrfs_open_dir(full_path, &dirs, 1);
if (path_fd < 0) {
ret = -ENOENT;
goto out;
}
- ret = lookup_ino_rootid(fd, &rootid);
+ ret = lookup_path_rootid(fd, &rootid);
if (ret) {
- error("rootid failed with ret=%d", ret);
+ error("failed to lookup root id: %s", strerror(-ret));
goto out;
}