Skip to content

Instantly share code, notes, and snippets.

@kennethso168
Last active June 6, 2026 14:56
Show Gist options
  • Select an option

  • Save kennethso168/eed0be7824cb1438b946cc4f7679068d to your computer and use it in GitHub Desktop.

Select an option

Save kennethso168/eed0be7824cb1438b946cc4f7679068d to your computer and use it in GitHub Desktop.
Solution for overriding filesystem types in latest KDE dolphin (which uses libmount instead of statfs)
# example .desktop file that opens Dolphin with the environment variable set
# basically, this is just the stock Dolphin .desktop file modified
# Created using KDE's built-in menu editor, which puts this file
# into ~/.local/share/applications/
[Desktop Entry]
Categories=Qt;KDE;System;FileTools;FileManager;
Comment=Manage your files
Exec=env LD_PRELOAD=/home/USERNAME/.local/lib/override_proc.so dolphin %u
GenericName=File Manager
Icon=org.kde.dolphin
InitialPreference=10
Keywords=files;file management;file browsing;samba;network shares;Explorer;Finder;
MimeType=inode/directory;
Name=Dolphin
NoDisplay=false
Path=
PrefersNonDefaultGPU=false
StartupNotify=true
StartupWMClass=dolphin
Terminal=false
TerminalOptions=
Type=Application
X-DBUS-ServiceName=org.kde.dolphin
X-DocPath=dolphin/index.html
X-KDE-Shortcuts=Meta+E
X-KDE-SubstituteUID=false
X-KDE-Username=
/*
Patches libmount's mnt_table_parse_mtab function to use a custom file /tmp/mountinfo instead of /proc/self/mountinfo
Another python script monitors /proc/self/mountinfo, overrides fs types and output to /tmp/mountinfo
Temporary fix for KDE Dolphin bug #452924.
More info: https://bugs.kde.org/show_bug.cgi?id=452924
Prerequisite:
libmount-devel on Fedora (sudo dnf install libmount-devel)
Compile with:
gcc -Wall -fPIC -shared -o override_proc.so override_proc.c -ldl -lmount
Run Dolphin like so:
LD_PRELOAD=./override_proc.so dolphin
With the example .desktop file, put the .so file into /home/USERNAME/.local/lib
Disclaimer: I'm not a C or kernel developer, therefore this file is created with assistance from Gemini
This file is provided as is and I'm not responsible for any damages to your system!
*/
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <dlfcn.h>
#include <libmount/libmount.h>
// Define the function pointer type for mnt_table_parse_mtab
typedef int (*orig_mnt_table_parse_mtab_f)(struct libmnt_table *, const char *);
int mnt_table_parse_mtab(struct libmnt_table *tb, const char *filename) {
orig_mnt_table_parse_mtab_f orig_func;
orig_func = (orig_mnt_table_parse_mtab_f)dlsym(RTLD_NEXT, "mnt_table_parse_mtab");
char *error = dlerror();
if (error != NULL) {
fprintf(stderr, "Error binding mnt_table_parse_mtab: %s\n", error);
return -1; // libmount functions generally return negative numbers on error
}
// Default to the original filename passed by the application
const char *target_file = filename;
printf("[Wrapper] Intercepted mnt_table_parse_mtab. Original filename: %s\n",
filename ? filename : "(NULL/Default system file)");
// Custom Logic: Override the filename if it matches a specific condition,
// or blanket override it if filename is NULL (libmount uses defaults if NULL)
if (filename == NULL || strcmp(filename, "/proc/self/mountinfo") == 0) {
target_file = "/tmp/mountinfo";
printf("[Wrapper] Redirecting mtab parsing to: %s\n", target_file);
}
// Call the original function with the modified target_file
int result = orig_func(tb, target_file);
// printf("[Wrapper] mnt_table_parse_mtab returned status: %d\n", result);
return result;
}
# Put this file in ~/.config/systemd/user/
# Enable and start with systemctl --user enable --now poll-mount.service
# Check unit status with systemctl --user status poll-mount.service
[Unit]
Description=Polls changes, edit and export /proc/self/mountinfo to /tmp/mountinfo
[Service]
ExecStart=%h/.local/bin/poll_mount.py
[Install]
WantedBy=default.target
#!/usr/bin/env -S python3 -u
"""
A python script that continuously polls for changes for /proc/self/mountinfo
and if there are changes, replaces each mount entry in that file
that matches one of the defined TARGET_FILESYSTEMS and TARGET_MOUNTPOINTS
to change the filesystem type to ext4 and output it to /tmp/mountinfo
In the SystemD user service unit example, put this python file in ~/.local/bin,
and make the file executable
"""
import select
import time
import os
TARGET_FILESYSTEMS = ("cifs", "autofs",) # change as appropriate
TARGET_MOUNTPOINTS = ("/srv/share",) # change as appropriate
INPUT_FILE = "/proc/self/mountinfo"
OUTPUT_FILE = "/tmp/mountinfo"
def replace_file(f):
# Reset file pointer to read new changes
f.seek(0)
lines = f.readlines()
new_lines = []
for l in lines:
fields = l.split(" ")
if fields[4] in TARGET_MOUNTPOINTS and fields[8] in TARGET_FILESYSTEMS:
print(f"Replacing fstype of {fields[4]} ({fields[8]}) to ext4")
fields[8] = 'ext4'
new_lines.append(" ".join(fields))
with open(OUTPUT_FILE, "w") as o:
o.write("".join(new_lines))
with open(INPUT_FILE, "r") as f:
replace_file(f)
# Setup the polling object
poller = select.poll()
# Register the file descriptor for priority data events
poller.register(f.fileno(), select.POLLPRI)
print("Watching for mount changes...")
while True:
events = poller.poll()
for fd, event in events:
if event & select.POLLPRI:
print(f"[{time.strftime('%X')}] Change detected in mounts!")
replace_file(f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment