Skip to content

Instantly share code, notes, and snippets.

@droberson
Created April 7, 2020 02:58
Show Gist options
  • Save droberson/562c57377f60cea61f63c76b859d9594 to your computer and use it in GitHub Desktop.
Save droberson/562c57377f60cea61f63c76b859d9594 to your computer and use it in GitHub Desktop.
example to get attributes of files (lsattr) with python.
#!/usr/bin/env python3
import os
import fcntl
from array import array
# https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/fs.h
FS_IOC_GETFLAGS = 0x80086601
f = os.open("/bin/ls", os.O_RDONLY)
arg = array('L', [0])
fcntl.ioctl(f, FS_IOC_GETFLAGS, arg, True)
print(hex(arg[0]))
os.close(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment