Last active
October 13, 2015 23:38
-
-
Save polachok/65a156c931eb287850a4 to your computer and use it in GitHub Desktop.
Read quota directly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import namedtuple | |
import struct | |
Block = namedtuple('Block', 'next_free prev_free entries pad1 pad2') | |
Quota = namedtuple('Quota', 'id ihardlimit isoftlimit curinodes bhardlimit bsoftlimit curspace btime itime') | |
def read_quota(f): | |
return Quota._make(struct.unpack('<IIIIIIQQQ', f.read(48))) | |
def report_block(f, i): | |
f.seek(1024 * i) | |
block = Block._make(struct.unpack('<IIHHI', f.read(16))) | |
for i in xrange(0, block.entries): | |
print read_quota(f) | |
def read_block(f, i): | |
f.seek(1024 * i) | |
return struct.unpack('<' + 'I' * 256, f.read(1024)) | |
def report_tree(f, blk, depth, visited = set()): | |
block = read_block(f, blk) | |
if depth == 3: | |
for i in xrange(0, 256): | |
if block[i] != 0 and block[i] not in visited: | |
report_block(f, block[i]) | |
visited.add(block[i]) | |
else: | |
for i in xrange(0, 256): | |
if block[i] != 0: | |
report_tree(f, block[i], depth + 1, visited) | |
with open('/home/aquota.user', 'rb') as f: | |
report_tree(f, 1, 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment