Skip to content
This repository was archived by the owner on Mar 27, 2020. It is now read-only.

Commit 5d2fb8a

Browse files
committed
Initial commit
1 parent 1c3aa33 commit 5d2fb8a

6 files changed

Lines changed: 154 additions & 2 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.o
2+
*.so

Makefile

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
INSTALL_DIR=/usr/local
2+
3+
libdropbox_ext4.so: dropbox_ext4.o
4+
$(LD) -shared -ldl -o $@ $^ && strip $@
5+
6+
%.o: %.c
7+
$(CC) -fPIC -D_GNU_SOURCE -Wall -Os -o $@ -c $<
8+
9+
clean:
10+
rm -f *.o *.so
11+
12+
install: libdropbox_ext4.so
13+
install $^ $(INSTALL_DIR)/lib/ && \
14+
echo -e "#!/bin/bash\n\nLD_PRELOAD=$(INSTALL_DIR)/lib/$^ exec /usr/bin/dropbox \"\$$@\"" > $(INSTALL_DIR)/bin/dropbox
15+
16+
uninstall:
17+
rm -f $(INSTALL_DIR)/bin/dropbox && \
18+
rm -f $(INSTALL_DIR)/lib/libdropbox_ext4.so

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,20 @@
1-
# dropbox_ext4
2-
Hack to make Dropbox work on non-ext4 filesystems
1+
# Dropbox ext4 Hack
2+
3+
Gets around Dropbox dropping support for non-ext4 filesystems by wrapping the `statfs64` function and overwriting the filesystem type.
4+
5+
## Install the pre-built hack
6+
7+
Just run:
8+
9+
sudo ./fix_dropbox.py
10+
dropbox stop
11+
dropbox start
12+
13+
It will install the hack into `/usr/local/`. You can modify `fix_dropbox.py` to customize that.
14+
15+
## Install from source
16+
17+
Make sure you have GCC installed and run the following:
18+
19+
make
20+
sudo make install

dropbox_ext4.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Wraps statfs64 and changes the filesystem type to EXT4.
3+
*/
4+
5+
#include <stdlib.h>
6+
#include <dlfcn.h>
7+
#include <sys/vfs.h>
8+
#include <linux/magic.h>
9+
10+
int statfs64(const char *path, struct statfs64 *buf) {
11+
static int (*_orig_statfs64)(const char *path, struct statfs64 *buf) = NULL;
12+
13+
if (_orig_statfs64 == NULL) {
14+
_orig_statfs64 = dlsym(RTLD_NEXT, "statfs64");
15+
}
16+
17+
int retval = _orig_statfs64(path, buf);
18+
if (retval == 0) {
19+
buf->f_type = EXT4_SUPER_MAGIC;
20+
}
21+
return retval;
22+
}

encode_lib.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
Encodes the shared library so it can be stored inline in `fix_installer.py`.
5+
"""
6+
7+
import base64
8+
import gzip
9+
import textwrap
10+
11+
12+
INPUT_FILE = 'libdropbox_ext4.so'
13+
14+
15+
def main():
16+
with open(INPUT_FILE, 'rb') as fd:
17+
contents = fd.read()
18+
19+
encoded_contents = base64.b85encode(gzip.compress(contents)).decode()
20+
21+
print("ENCODED_LIB_CONTENTS = (")
22+
for line in textwrap.wrap(encoded_contents, 128):
23+
print(" '%s'" % line)
24+
print(")")
25+
26+
27+
if __name__ == '__main__':
28+
main()

fix_dropbox.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python3
2+
3+
import base64
4+
import gzip
5+
import os
6+
import subprocess
7+
8+
# Install a wrapper script as /usr/local/bin/dropbox.
9+
# It *should* be in $PATH before /usr/bin/dropbox, and therefore take precedence.
10+
INSTALL_PATH = '/usr/local/'
11+
12+
# Replace with ~/.local/ if you like - but make sure it's in the $PATH before /usr/bin/!
13+
# INSTALL_PATH = os.path.expanduser('~/.local/')
14+
15+
# Base85-encoded gzipped libdropbox_ext4.so, generated by `encode_lib.py`,
16+
ENCODED_LIB_CONTENTS = (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?c7d?(P5yT#f$_)lo3KCopF#t<!Tw0^!yNtby-1c'
25+
'0kC){)VgEQINB^NF`QsYAi7kNtPLuol0dn-cOwben00'
26+
)
27+
28+
LIBRARY_PATH = os.path.join(INSTALL_PATH, 'lib', 'libdropbox_ext4.so')
29+
SCRIPT_PATH = os.path.join(INSTALL_PATH, 'bin', 'dropbox')
30+
31+
DROPBOX_WRAPPER_CONTENTS = '''
32+
#!/bin/bash
33+
34+
LD_PRELOAD=%s exec /usr/bin/dropbox "$@"
35+
'''.lstrip() % LIBRARY_PATH
36+
37+
38+
def main():
39+
# Install the library.
40+
os.makedirs(os.path.join(INSTALL_PATH, 'bin'), exist_ok=True)
41+
42+
with open(LIBRARY_PATH, 'wb') as fd:
43+
fd.write(gzip.decompress(base64.b85decode(ENCODED_LIB_CONTENTS)))
44+
os.fchmod(fd.fileno(), 0o755)
45+
46+
# Install the wrapper script.
47+
os.makedirs(os.path.join(INSTALL_PATH, 'lib'), exist_ok=True)
48+
49+
with open(SCRIPT_PATH, 'w') as fd:
50+
fd.write(DROPBOX_WRAPPER_CONTENTS)
51+
os.fchmod(fd.fileno(), 0o755)
52+
53+
print("Installed the library and the wrapper script at:\n %s\n %s" % (LIBRARY_PATH, SCRIPT_PATH))
54+
print("(To uninstall, simply delete them.)")
55+
56+
# Check that the correct 'dropbox' is in the $PATH.
57+
result = subprocess.check_output(['which', 'dropbox']).decode().rstrip()
58+
if result != SCRIPT_PATH:
59+
print()
60+
print("You will need to fix your $PATH! Currently, %r takes precedence." % result)
61+
62+
63+
if __name__ == '__main__':
64+
main()

0 commit comments

Comments
 (0)