1*8ac5aef8SEnji Cooper#!/usr/bin/env python 2*8ac5aef8SEnji Cooperimport sys 3*8ac5aef8SEnji Cooperimport re 4*8ac5aef8SEnji Cooper 5*8ac5aef8SEnji Cooper_values = { # 2-tuple => name 6*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000000100) : 'TTYHOOK', 7*8ac5aef8SEnji Cooper (0x0000000000000040, 0x0000000000000000) : 'CREATE', 8*8ac5aef8SEnji Cooper (0x0000000200000000, 0x0000000000000000) : 'GETSOCKNAME', 9*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000100000) : 'KQUEUE_CHANGE', 10*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000004000) : 'EXTATTR_LIST', 11*8ac5aef8SEnji Cooper (0x0000000000000080, 0x0000000000000000) : 'FEXECVE', 12*8ac5aef8SEnji Cooper (0x0000001000000000, 0x0000000000000000) : 'PEELOFF', 13*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000800000) : 'NOTIFY', 14*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000001000) : 'EXTATTR_DELETE', 15*8ac5aef8SEnji Cooper (0x0000000040000000, 0x0000000000000000) : 'BIND', 16*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000002000) : 'EXTATTR_GET', 17*8ac5aef8SEnji Cooper (0x0000000000008000, 0x0000000000000000) : 'FCNTL', 18*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000400000) : 'EPOLL_CTL', 19*8ac5aef8SEnji Cooper (0x0000000000000004, 0x0000000000000000) : 'SEEK_TELL', 20*8ac5aef8SEnji Cooper (0x000000000000000c, 0x0000000000000000) : 'SEEK', 21*8ac5aef8SEnji Cooper (0x0000004000000000, 0x0000000000000000) : 'SHUTDOWN', 22*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000000080) : 'IOCTL', 23*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000000020) : 'EVENT', 24*8ac5aef8SEnji Cooper (0x0000000400000000, 0x0000000000000000) : 'GETSOCKOPT', 25*8ac5aef8SEnji Cooper (0x0000000080000000, 0x0000000000000000) : 'CONNECT', 26*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000200000) : 'FSIGNAL', 27*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000008000) : 'EXTATTR_SET', 28*8ac5aef8SEnji Cooper (0x0000000000100000, 0x0000000000000000) : 'FSTATFS', 29*8ac5aef8SEnji Cooper (0x0000000000040000, 0x0000000000000000) : 'FSCK', 30*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000000800) : 'PDKILL_FREEBSD', 31*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000000004) : 'SEM_GETVALUE', 32*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000080000) : 'ACL_SET', 33*8ac5aef8SEnji Cooper (0x0000000000200000, 0x0000000000000000) : 'FUTIMES', 34*8ac5aef8SEnji Cooper (0x0000000000000200, 0x0000000000000000) : 'FTRUNCATE', 35*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000000001) : 'MAC_GET', 36*8ac5aef8SEnji Cooper (0x0000000000020000, 0x0000000000000000) : 'FPATHCONF', 37*8ac5aef8SEnji Cooper (0x0000002000000000, 0x0000000000000000) : 'SETSOCKOPT', 38*8ac5aef8SEnji Cooper (0x0000000000002000, 0x0000000000000000) : 'FCHMOD', 39*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000002000000) : 'PERFMON', 40*8ac5aef8SEnji Cooper (0x0000000000004000, 0x0000000000000000) : 'FCHOWN', 41*8ac5aef8SEnji Cooper (0x0000000000000400, 0x0000000000000000) : 'LOOKUP', 42*8ac5aef8SEnji Cooper (0x0000000000400400, 0x0000000000000000) : 'LINKAT_TARGET', 43*8ac5aef8SEnji Cooper (0x0000000000800400, 0x0000000000000000) : 'MKDIRAT', 44*8ac5aef8SEnji Cooper (0x0000000001000400, 0x0000000000000000) : 'MKFIFOAT', 45*8ac5aef8SEnji Cooper (0x0000000002000400, 0x0000000000000000) : 'MKNODAT', 46*8ac5aef8SEnji Cooper (0x0000000004000400, 0x0000000000000000) : 'RENAMEAT_SOURCE', 47*8ac5aef8SEnji Cooper (0x0000000008000400, 0x0000000000000000) : 'SYMLINKAT', 48*8ac5aef8SEnji Cooper (0x0000000010000400, 0x0000000000000000) : 'UNLINKAT', 49*8ac5aef8SEnji Cooper (0x0000008000000400, 0x0000000000000000) : 'BINDAT', 50*8ac5aef8SEnji Cooper (0x0000010000000400, 0x0000000000000000) : 'CONNECTAT', 51*8ac5aef8SEnji Cooper (0x0000020000000400, 0x0000000000000000) : 'LINKAT_SOURCE', 52*8ac5aef8SEnji Cooper (0x0000040000000400, 0x0000000000000000) : 'RENAMEAT_TARGET', 53*8ac5aef8SEnji Cooper (0x0000000000000010, 0x0000000000000000) : 'MMAP', 54*8ac5aef8SEnji Cooper (0x000000000000003c, 0x0000000000000000) : 'MMAP_X', 55*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000001000000) : 'SETNS', 56*8ac5aef8SEnji Cooper (0x0000000000080000, 0x0000000000000000) : 'FSTAT', 57*8ac5aef8SEnji Cooper (0x0000000000000001, 0x0000000000000000) : 'READ', 58*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000000008) : 'SEM_POST', 59*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000020000) : 'ACL_DELETE', 60*8ac5aef8SEnji Cooper (0x0000000000001000, 0x0000000000000000) : 'FCHFLAGS', 61*8ac5aef8SEnji Cooper (0x0000000800000000, 0x0000000000000000) : 'LISTEN', 62*8ac5aef8SEnji Cooper (0x0000000100000000, 0x0000000000000000) : 'GETPEERNAME', 63*8ac5aef8SEnji Cooper (0x0000000000000100, 0x0000000000000000) : 'FSYNC', 64*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000004000000) : 'BPF', 65*8ac5aef8SEnji Cooper (0x0000000020000000, 0x0000000000000000) : 'ACCEPT', 66*8ac5aef8SEnji Cooper (0x0000000000000800, 0x0000000000000000) : 'FCHDIR', 67*8ac5aef8SEnji Cooper (0x0000000000000002, 0x0000000000000000) : 'WRITE', 68*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000000010) : 'SEM_WAIT', 69*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000000040) : 'KQUEUE_EVENT', 70*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000000400) : 'PDWAIT', 71*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000040000) : 'ACL_GET', 72*8ac5aef8SEnji Cooper (0x0000000000010000, 0x0000000000000000) : 'FLOCK', 73*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000010000) : 'ACL_CHECK', 74*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000000002) : 'MAC_SET', 75*8ac5aef8SEnji Cooper (0x0000000000000000, 0x0000000000000200) : 'PDGETPID_FREEBSD', 76*8ac5aef8SEnji Cooper} 77*8ac5aef8SEnji Cooper 78*8ac5aef8SEnji Cooper 79*8ac5aef8SEnji Cooperdef _map_fdinfo(line): 80*8ac5aef8SEnji Cooper RIGHTS_RE = re.compile(r'(?P<prefix>.*)rights:(?P<ws>\s+)0x(?P<v0>[0-9a-fA-F]+)\s+0x(?P<v1>[0-9a-fA-F]+)$') 81*8ac5aef8SEnji Cooper m = RIGHTS_RE.match(line) 82*8ac5aef8SEnji Cooper if m: 83*8ac5aef8SEnji Cooper val0 = long(m.group('v0'), 16) 84*8ac5aef8SEnji Cooper val0 = (val0 & ~(0x0200000000000000L)) 85*8ac5aef8SEnji Cooper val1 = long(m.group('v1'), 16) 86*8ac5aef8SEnji Cooper val1 = (val1 & ~(0x0400000000000000L)) 87*8ac5aef8SEnji Cooper rights = [] 88*8ac5aef8SEnji Cooper for (right, name) in _values.items(): 89*8ac5aef8SEnji Cooper if ((right[0] == 0 or (val0 & right[0])) and 90*8ac5aef8SEnji Cooper (right[1] == 0 or (val1 & right[1]))): 91*8ac5aef8SEnji Cooper rights.append(name) 92*8ac5aef8SEnji Cooper return "%srights:%s%s" % (m.group('prefix'), m.group('ws'), '|'.join(rights)) 93*8ac5aef8SEnji Cooper else: 94*8ac5aef8SEnji Cooper return line.rstrip() 95*8ac5aef8SEnji Cooper 96*8ac5aef8SEnji Cooperif __name__ == "__main__": 97*8ac5aef8SEnji Cooper infile = open(sys.argv[1], 'r') if len(sys.argv) > 1 else sys.stdin 98*8ac5aef8SEnji Cooper for line in infile.readlines(): 99*8ac5aef8SEnji Cooper print _map_fdinfo(line) 100