linux - Get fat32 attributes with python -
how can fat32 attributes (like archived, hidden...) in linux without spawning new process fatattr utility call ? may there python binding or linux/fs functions (fat_ioctl_get_attributes, http://www.cs.fsu.edu/~baker/devices/lxr/http/source/linux/fs/fat/file.c). or maybe can done python-xattr ?
as can see in function name, kernel function fat_ioctl_get_attributes
called userspace via ioctl, , i'm not aware of other binding. therefore, can read attributes calling ioctl
yourself, this:
import array import fcntl import os fat_ioctl_get_attributes = 0x80047210 fatattr_bits = 'rhsvda67' def get_fat_attrs(fn): fd = os.open(fn, os.o_rdonly) try: buf = array.array('l', [0]) try: fcntl.ioctl(fd, fat_ioctl_get_attributes, buf, true) except ioerror ioe: if ioe.errno == 25: # not fat volume return none else: raise return buf[0] finally: os.close(fd) if __name__ == '__main__': import sys fn in sys.argv[1:]: attrv = get_fat_attrs(fn) if attrv none: print(fn + ': not on fat volume') continue s = ''.join((fb if (1 << idx) & attrv else ' ') idx,fb in enumerate(fatattr_bits)) print(fn + ': ' + s)
Comments
Post a Comment