Debian Codegraph @

examples/set_received_uuid.py

raw symbols SCIP
1 #!/usr/bin/python3
2
3 import btrfs
4 import os
5 import sys
6 import uuid
7
8 if len(sys.argv) < 5:
9 print("Usage: {} <received-uuid> <stransid> <stime> <snapshot>".format(sys.argv[0]))
10 print("Example: {} 00000000-1234-5678-90ab-cdef00000000 "
11 "31337 1234.5678 /path/to/snapshot".format(sys.argv[0]))
12 sys.exit(1)
13
14 received_uuid = uuid.UUID(sys.argv[1])
15 stransid = int(sys.argv[2])
16 stime_sec, stime_nsec = [int(x) for x in sys.argv[3].split('.')]
17 stime = btrfs.ctree.TimeSpec.from_values(stime_sec, stime_nsec)
18 subvol_path = sys.argv[4]
19
20 inum = os.stat(subvol_path).st_ino
21 if inum != 256:
22 print("{} is not the start of a subvolume (inum {} != 256)".format(subvol_path, inum))
23 sys.exit(1)
24
25 subvol_fd = os.open(subvol_path, os.O_RDONLY)
26 tree, _ = btrfs.ioctl.ino_lookup(subvol_fd)
27
28
29 def print_subvol_info(root):
30 print(" subvol_id: {}".format(root.key.objectid))
31 print(" received_uuid: {}".format(root.received_uuid))
32 print(" stime: {}".format(root.stime))
33 print(" stransid: {}".format(root.stransid))
34 print(" rtime: {}".format(root.rtime))
35 print(" rtransid: {}".format(root.rtransid))
36 print()
37
38
39 with btrfs.FileSystem(subvol_path) as fs:
40 print("Current subvolume information:")
41 root = list(fs.subvolumes(min_id=tree, max_id=tree))[0]
42 print_subvol_info(root)
43
44 print("Setting received subvolume...")
45 print()
46 rtransid, rtime = btrfs.ioctl.set_received_subvol(subvol_fd, received_uuid, stransid, stime)
47 os.close(subvol_fd)
48
49 print("Resulting subvolume information:")
50 root = list(fs.subvolumes(min_id=tree, max_id=tree))[0]
51 print_subvol_info(root)