Skip to content

Instantly share code, notes, and snippets.

Last active Mar 8, 2020
What would you like to do?
get filesystem attribs (like immutable) with python
import fcntl
from array import array
# FS constants - see /uapi/linux/fs.h in kernel source
# or <>
FS_IOC_GETFLAGS = 0x80086601
with open(FILENAME) as f:
arg = array('L', [0])
fcntl.ioctl(f.fileno(), FS_IOC_GETFLAGS, arg, True)
# other flags are defined in the fs.h kernel source
a_immutable = bool(arg[0] & 0x010)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment