Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 464054
Collapse All | Expand All

(-)btrfs-progs-0.19.11.orig/btrfs-list.c (-1 / +82 lines)
Lines 553-558 Link Here
553
	return full;
553
	return full;
554
}
554
}
555
555
556
static int get_default_subvolid(int fd, u64 *default_id)
557
{
558
	struct btrfs_ioctl_search_args args;
559
	struct btrfs_ioctl_search_key *sk = &args.key;
560
	struct btrfs_ioctl_search_header *sh;
561
	u64 found = 0;
562
	int ret;
563
564
	memset(&args, 0, sizeof(args));
565
566
	/*
567
	 * search for a dir item with a name 'default' in the tree of
568
	 * tree roots, it should point us to a default root
569
	 */
570
	sk->tree_id = 1;
571
572
	/* don't worry about ancient format and request only one item */
573
	sk->nr_items = 1;
574
575
	sk->max_objectid = BTRFS_ROOT_TREE_DIR_OBJECTID;
576
	sk->min_objectid = BTRFS_ROOT_TREE_DIR_OBJECTID;
577
	sk->max_type = BTRFS_DIR_ITEM_KEY;
578
	sk->min_type = BTRFS_DIR_ITEM_KEY;
579
	sk->max_offset = (u64)-1;
580
	sk->max_transid = (u64)-1;
581
582
	ret = ioctl(fd, BTRFS_IOC_TREE_SEARCH, &args);
583
	if (ret < 0)
584
		return ret;
585
586
	/* the ioctl returns the number of items it found in nr_items */
587
	if (sk->nr_items == 0)
588
		goto out;
589
590
	sh = (struct btrfs_ioctl_search_header *)args.buf;
591
592
	if (sh->type == BTRFS_DIR_ITEM_KEY) {
593
		struct btrfs_dir_item *di;
594
		int name_len;
595
		char *name;
596
597
		di = (struct btrfs_dir_item *)(sh + 1);
598
		name_len = btrfs_stack_dir_name_len(di);
599
		name = (char *)(di + 1);
600
601
		if (!strncmp("default", name, name_len))
602
			found = btrfs_disk_key_objectid(&di->location);
603
	}
604
605
out:
606
	*default_id = found;
607
	return 0;
608
}
609
556
static int __list_subvol_search(int fd, struct root_lookup *root_lookup)
610
static int __list_subvol_search(int fd, struct root_lookup *root_lookup)
557
{
611
{
558
	int ret;
612
	int ret;
Lines 668-679 Link Here
668
	return 0;
722
	return 0;
669
}
723
}
670
724
671
int list_subvols(int fd, int print_parent)
725
int list_subvols(int fd, int print_parent, int get_default)
672
{
726
{
673
	struct root_lookup root_lookup;
727
	struct root_lookup root_lookup;
674
	struct rb_node *n;
728
	struct rb_node *n;
729
	u64 default_id;
675
	int ret;
730
	int ret;
676
731
732
	if (get_default) {
733
		ret = get_default_subvolid(fd, &default_id);
734
		if (ret) {
735
			fprintf(stderr, "ERROR: can't perform the search - %s\n",
736
				strerror(errno));
737
			return ret;
738
		}
739
		if (default_id == 0) {
740
			fprintf(stderr, "ERROR: 'default' dir item not found\n");
741
			return ret;
742
		}
743
744
		/* no need to resolve roots if FS_TREE is default */
745
		if (default_id == BTRFS_FS_TREE_OBJECTID) {
746
			printf("ID 5 (FS_TREE)\n");
747
			return ret;
748
		}
749
	}
750
677
	ret = __list_subvol_search(fd, &root_lookup);
751
	ret = __list_subvol_search(fd, &root_lookup);
678
	if (ret) {
752
	if (ret) {
679
		fprintf(stderr, "ERROR: can't perform the search - %s\n",
753
		fprintf(stderr, "ERROR: can't perform the search - %s\n",
Lines 700-706 Link Here
700
		u64 level;
774
		u64 level;
701
		u64 parent_id;
775
		u64 parent_id;
702
		char *path;
776
		char *path;
777
703
		entry = rb_entry(n, struct root_info, rb_node);
778
		entry = rb_entry(n, struct root_info, rb_node);
779
780
		if (get_default && entry->root_id != default_id) {
781
			n = rb_prev(n);
782
			continue;
783
		}
784
704
		resolve_root(&root_lookup, entry, &root_id, &parent_id,
785
		resolve_root(&root_lookup, entry, &root_id, &parent_id,
705
				&level, &path);
786
				&level, &path);
706
		if (print_parent) {
787
		if (print_parent) {
(-)btrfs-progs-0.19.11.orig/ctree.h (+2 lines)
Lines 1431-1436 Link Here
1431
BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
1431
BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
1432
BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64);
1432
BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64);
1433
1433
1434
BTRFS_SETGET_STACK_FUNCS(stack_dir_name_len, struct btrfs_dir_item, name_len, 16);
1435
1434
static inline void btrfs_dir_item_key(struct extent_buffer *eb,
1436
static inline void btrfs_dir_item_key(struct extent_buffer *eb,
1435
				      struct btrfs_dir_item *item,
1437
				      struct btrfs_dir_item *item,
1436
				      struct btrfs_disk_key *key)
1438
				      struct btrfs_disk_key *key)

Return to bug 464054