-
Notifications
You must be signed in to change notification settings - Fork 4
/
orphans.btrd
51 lines (40 loc) · 1005 Bytes
/
orphans.btrd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
filesystem "/";
k = key(0, BTRFS_ROOT_ITEM_KEY, 0, 0);
roots = search(BTRFS_ROOT_TREE_OBJECTID, k);
for r in roots {
rkey = keyof(r);
if rkey.type != BTRFS_ROOT_ITEM_KEY {
continue;
}
if rkey.objectid !=5 && (rkey.objectid < BTRFS_FIRST_FREE_OBJECTID || rkey.objectid > BTRFS_LAST_FREE_OBJECTID) {
continue;
}
total = 0;
k = key(BTRFS_ORPHAN_OBJECTID, BTRFS_ORPHAN_ITEM_KEY, 0, 0);
k.max_type = BTRFS_ORPHAN_ITEM_KEY;
orphans = search(rkey.objectid, k);
for o in orphans {
okey = keyof(o);
if okey.type != BTRFS_ORPHAN_ITEM_KEY {
continue;
}
k2 = key(okey.offset, BTRFS_INODE_ITEM_KEY, 0, 0);
k2.max_objectid = okey.offset;
k2.max_type = BTRFS_INODE_ITEM_KEY;
inodes = search(257, k2);
for i in inodes {
ikey = keyof(i);
if ikey.objectid != okey.offset {
break;
}
if (ikey.type != BTRFS_INODE_ITEM_KEY) {
break;
}
total += i.nbytes;
break;
}
}
if total > 0 {
print "root " + str(rkey.objectid) + " bytes " + str(total);
}
}