Skip to content

Instantly share code, notes, and snippets.

@yellowcrescent
Last active Mar 8, 2020
Embed
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 <elixir.free-electrons.com/linux/latest/source/include/uapi/linux/fs.h>
FS_IOC_GETFLAGS = 0x80086601
FS_IMMUTABLE_FL = 0x010
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