Created
June 10, 2014 22:09
-
-
Save papamoose/3f0ffdcad5658c964c3a to your computer and use it in GitHub Desktop.
This file contains 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
# /root/xfsprogs-3.1.9ubuntu2/include/xqm.h | |
# (('X'<<8)+(1)) | (('X'<<8)+(3)) | |
# use strace to get above numbers: strace xfs_quota | |
#!/usr/bin/env python | |
# get quota information from XFS | |
import sys | |
from pwd import getpwnam | |
from ctypes import * | |
libc = cdll.LoadLibrary('libc.so.6') | |
# see xfs/xqm.h | |
class fs_disk_quota_t(Structure): | |
_fields_ = [ | |
("d_version", c_char), | |
("d_flags", c_char), | |
("d_fieldmask", c_ushort), | |
("d_id", c_uint32), | |
("d_blk_hardlimit", c_uint64), | |
("d_blk_softlimit", c_uint64), | |
("d_ino_hardlimit", c_uint64), | |
("d_ino_softlimit", c_uint64), | |
("d_bcount", c_uint64), | |
("d_icount", c_uint64), | |
("d_itimer", c_int32), | |
("d_btimer", c_int32), | |
("d_iwarns", c_uint16), | |
("d_bwarns", c_uint16), | |
("d_padding2", c_int32), | |
("d_rtb_hardlimit", c_uint64), | |
("d_rtb_softlimit", c_uint64), | |
("d_rtbcount", c_uint64), | |
("d_rtbtimer", c_int32), | |
("d_rtbwarns", c_uint16), | |
("d_padding3", c_int16), | |
("d_padding4", c_char * 8) | |
] | |
output = fs_disk_quota_t() | |
quota = libc.quotactl | |
quota.argtypes = [c_int, c_char_p, c_int, c_void_p] | |
quota.restype = c_int | |
uid = c_int(getpwnam(sys.argv[1])[2]) | |
cmd = c_int(5767936) # Q_XGETQUOTA|USRQUOTA | |
ptr = pointer(output) | |
if quota(cmd, "/dev/mapper/vg0-storage", uid, ptr) == -1: | |
print "Something went wrong!!" | |
exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment