Skip to content

Instantly share code, notes, and snippets.

@DownrightNifty
Created May 17, 2024 22:46
Show Gist options
  • Save DownrightNifty/fbfdf50cac60c6d973ebef10438d7ee5 to your computer and use it in GitHub Desktop.
Save DownrightNifty/fbfdf50cac60c6d973ebef10438d7ee5 to your computer and use it in GitHub Desktop.
/*
Patches statfs() syscall* to make programs think that NFS filesystems are actually ext4.
Temporary fix for KDE Dolphin bug #452924.
More info: https://bugs.kde.org/show_bug.cgi?id=452924#c28
Compile with:
cc -fPIC -shared -ldl -o mask_statfs_nfs_as_ext4.so mask_statfs_nfs_as_ext4.c
Run Dolphin like so:
LD_PRELOAD=./mask_statfs_nfs_as_ext4.so dolphin
*technically just patches the libc wrapper for the syscall but most programs will use that instead
*/
#include <sys/vfs.h>
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <dlfcn.h>
int statfs(const char *path, struct statfs *buf) {
// the original statfs
int (*o_statfs)(const char *, struct statfs *) = dlsym(RTLD_NEXT, "statfs");
int rc = o_statfs(path, buf);
if (rc < 0) { return rc; }
// if the filesystem is NFS, pretend that it's actually ext4
if (buf->f_type == 0x6969) { // NFS magic
buf->f_type = 0xef53; // ext4 magic
}
return rc;
}
@DownrightNifty
Copy link
Author

# example .desktop file that opens Dolphin with the environment variable set

[Desktop Entry]
Categories=Qt;KDE;System;FileTools;FileManager;
Exec=env LD_PRELOAD=/home/USERNAME/mask_statfs_nfs_as_ext4.so dolphin %u
Icon=system-file-manager
MimeType=inode/directory;
Name=Dolphin
StartupWMClass=dolphin
Type=Application

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment