Skip to content

Instantly share code, notes, and snippets.

@yellowcrescent
Last active March 8, 2020 22:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yellowcrescent/e334e03c2531bc2a70bec8f6fe6100b2 to your computer and use it in GitHub Desktop.
Save yellowcrescent/e334e03c2531bc2a70bec8f6fe6100b2 to your computer and use it in GitHub Desktop.
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