btrd
btrd copied to clipboard
Add write API
Add a write API such that if btrd is given an unmounted FS image, btrd can write arbitrary bytes to anywhere in the image.
Code example:
(btrd) filesystem /home/dev/dxu/unmounted_image
(btrd) key = key(0, BTRFS_BLOCK_GROUP_ITEM_KEY, 0, 0)
(btrd) res = search(BTRFS_CHUNK_TREE_FSID, key)
(btrd) # '&' operator resolves physical address of field in image
(btrd) print &res[0].chunk_objectid
0x12345
(btrd) write &res[0].chunk_objectid = 7
(btrd) write &key.min_objectid = -1
Error: Cannot get physical offset of 'key.min_objectid'
(btrd) print &key.min_objectid
Error: Cannot get physical offset of 'key.min_objectid'
(btrd) # Batch changes; LHS and RHS types must match
(btrd) res[0].chunk_objectid = 1234 # only changes in memory variable
(btrd) res[0].flags = 0 # ditto
(btrd) write &res[0] = res[0]
(btrd) # Write to arbitrary physical offset
(btrd) write 0xDEADBEEF = 7 # 64 bit write b/c ints are 64 bits internally
(btrd) write 0xDEADBEEF = res[0] # sizeof(res[0]) sized write