Debian Codegraph @

examples/show_subvolumes.py

raw symbols SCIP
1 #!/usr/bin/python3
2
3 import btrfs
4 import sys
5
6 if len(sys.argv) < 2:
7 print("Usage: {} <mountpoint>".format(sys.argv[0]))
8 sys.exit(1)
9
10
11 def subvolumes_inside(fs, parent_tree):
12 min_key = btrfs.ctree.Key(parent_tree, btrfs.ctree.ROOT_REF_KEY, 0)
13 max_key = btrfs.ctree.Key(parent_tree, btrfs.ctree.ROOT_REF_KEY + 1, 0) - 1
14 for header, data in btrfs.ioctl.search_v2(fs.fd, 1, min_key, max_key):
15 ref = btrfs.ctree.RootRef(header, data)
16 path = (btrfs.ioctl.ino_lookup(fs.fd, ref.parent_tree, ref.dirid).name_bytes +
17 ref.name).decode()
18 yield ref.tree, path
19
20
21 def print_subvolumes_inside(fs, parent_tree, parent_path):
22 for tree, path in subvolumes_inside(fs, parent_tree):
23 sub_path = "{}/{}".format(parent_path, path)
24 print("ID {} parent {} path {}".format(tree, parent_tree, sub_path))
25 print_subvolumes_inside(fs, tree, sub_path)
26
27
28 with btrfs.FileSystem(sys.argv[1]) as fs:
29 print_subvolumes_inside(fs, 5, '')