Last active
May 23, 2024 02:02
-
-
Save yellowcrescent/e334e03c2531bc2a70bec8f6fe6100b2 to your computer and use it in GitHub Desktop.
get filesystem attribs (like immutable) with python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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