Skip to content

Instantly share code, notes, and snippets.

@sanmai
Last active August 15, 2018 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanmai/0a10af0572dd614acfd680f7b2f6607c to your computer and use it in GitHub Desktop.
Save sanmai/0a10af0572dd614acfd680f7b2f6607c to your computer and use it in GitHub Desktop.
/*
* dropbox_ext4.c
*
* Compile like this:
* gcc -shared -fPIC -ldl -o libdropbox_ext4.so dropbox_ext4.c
*
* Run Dropbox like this:
* LD_PRELOAD=./libdropbox_ext4.so ~/.dropbox-dist/dropboxd
*/
#define _GNU_SOURCE
#include <stdlib.h>
#include <sys/vfs.h>
#include <linux/magic.h>
#include <dlfcn.h>
int (*orig_statfs)(const char *path, struct statfs64 *buf) = NULL;
int statfs64(const char *path, struct statfs64 *buf) {
if (orig_statfs == NULL) {
orig_statfs = dlsym(RTLD_NEXT, "statfs64");
}
int retval = orig_statfs(path, buf);
if (retval == 0) {
buf->f_type = EXT4_SUPER_MAGIC;
}
return retval;
}

Hey guys,

I have a really terrible hack, but it appears to work, so...

Dropbox calls statfs64 to get the filesystem type. Now, if only there was a way to change its return value to "ext4"... oh wait, there is!

Here's code of the new function: dropbox_ext4.c

/*
 * dropbox_ext4.c
 *
 * Compile like this:
 *   gcc -shared -fPIC -ldl -o libdropbox_ext4.so dropbox_ext4.c
 *
 * Run Dropbox like this:
 *   LD_PRELOAD=./libdropbox_ext4.so ~/.dropbox-dist/dropboxd
 */
 
#define _GNU_SOURCE
 
#include <stdlib.h>
#include <sys/vfs.h>
#include <linux/magic.h>
#include <dlfcn.h>
 
int (*orig_statfs)(const char *path, struct statfs64 *buf) = NULL;
 
int statfs64(const char *path, struct statfs64 *buf) {
  if (orig_statfs == NULL) {
    orig_statfs = dlsym(RTLD_NEXT, "statfs64");
  }
  int retval = orig_statfs(path, buf);
  if (retval == 0) {
    buf->f_type = EXT4_SUPER_MAGIC;
  }
  return retval;
}

Here's the compiled shared library, if you trust me enough to use it: libdropbox_ext4.so

If you manually start the Dropbox daemon like this, it will use the fake function:

LD_PRELOAD=libdropbox_ext4.so ~/.dropbox-dist/dropboxd

And, hopefully, it will accept any filesystem you throw at it. Of course, I can't promise that nothing will blow up.

If Dropbox starts up automatically, it won't pick up the hack. I'll let someone else figure out how to make it more permanent.

(via)

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