Re: Python linuxfs Modules
Lawrence D’Oliveiro <[email protected]> Tue, 17 Mar 2026 21:26:00 -0000 (UTC)
| Newsgroups | comp.lang.python |
|---|---|
| Organization | A noiseless patient Spider |
| Message-ID | <[email protected]> |
On Tue, 17 Mar 2026 14:30:42 +0300, Oguz Kaan Ocal wrote:
> Regarding the linuxacl and linuxmount modules: how do you handle
> compatibility across different kernel versions? Since some of these
> APIs (like Landlock or newer mount features) are relatively recent,
> does the library provide graceful fallbacks or just raise
> NotImplementedError?
Landlock in particular has been through about 7 versions so far, with
signs of an eighth on the way. I deal with that by attach API version
info to the relevant enums.
For example, if you look at my Python version of the “sandboxer”
sample program in the Landlock documentation, I get the API version
from the current kernel with
LL_VERSION = linuxpriv.get_landlock_version()
then I can collect sets of available access attributes with constructs
like:
* All read/write operations on both files and directories:
access_file_dir_rw = set \
(
acc for acc in ACCESS_FS
if acc.min_version <= LL_VERSION
)
* Read-only operations on files:
access_file_ro = set \
(
acc for acc in ACCESS_FS
if acc.min_version <= LL_VERSION and acc.file_op and not acc.write_op
)
etc.
As for libacl, I’m not aware of any API version changes -- not in the
man pages I’ve been reading so far. Similarly the mount API -- both go
so far back that I don’t think any kernels that don’t implement them
are still in any kind of support. Correct me if I’m wrong. ;)
> Using sets of enums instead of bitmasks is definitely 'The Pythonic
> Way'. It makes the code much more self-documenting.
More than that, I can attach extra attributes that can be used to ease
programming, as in the examples above.