File: show_block_group_free_space_extents.py

package info (click to toggle)
python-btrfs 11-2
  • links: PTS
  • area: main
  • in suites: buster
  • size: 724 kB
  • sloc: python: 4,445; makefile: 195
file content (20 lines) | stat: -rwxr-xr-x 570 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/python3

import btrfs
import sys

if len(sys.argv) < 3:
    print("Usage: {} <vaddr> <mountpoint>".format(sys.argv[0]))
    sys.exit(1)

vaddr = int(sys.argv[1])
with btrfs.FileSystem(sys.argv[2]) as fs:
    block_group = fs.block_group(vaddr)

    try:
        for extent in fs.free_space_extents(min_vaddr=vaddr,
                                            max_vaddr=vaddr + block_group.length - 1):
            print(extent)
    except FileNotFoundError:
        print("No Free Space Tree? To run this example you need space_cache=v2")
        sys.exit(1)