spion / adbfs-rootless

Mount Android phones on Linux with adb. No root required.
Other
908 stars 73 forks source link

Don't grow unlimited in /tmp #18

Open kaueraal opened 7 years ago

kaueraal commented 7 years ago

Usually /tmp is in a tmpfs, so in ram. adbfs seems to cache data in /tmp without limit, so it fills my 16GiB of ram completly during a backup of my 64GiB internal memory of my phone. adbfs should limit the data in /tmp somehow.

spion commented 7 years ago

AFAIK the right thing here would be to use $TMPDIR instead (likely /var/tmp) which normally doesn't go into RAM...

kaueraal commented 7 years ago

Even when it goes onto a HDD I don't really want to cache 64+ GiB.

spion commented 7 years ago

That might be doable by removing the temporary file on release. Not entirely sure, would need to investigate in more detail.

refola commented 7 years ago

This seems to be the underlying problem behind Issue #8, where the "volume" that's out of room is /tmp and not the device.

I wrote a (very kludgy) script as a workaround that moves the adbfs temp dir somewhere else and points a symlink from the original location to the new one.

#!/bin/bash
## Hardcoded variables that need changing
dir="/where/you/want/it/mounted"
target="/where/you/want/it/cached"

## Unmount and mount
fusermount -u "$dir"
adbfs "$dir"

## Kludge for the adbfs kludge needing to write all accessed data:
cd /tmp || (echo "Cannot cd!" && exit 1)
tmp=(adbfs*)
x="${tmp[0]}" # assumes that there's at least one adbfs dir and that you want the first
source="/tmp/$x"
mv "$source" "$target/"
ln -s "$target/$x" "$source"
hkmaly commented 7 years ago

Would it really be impossible to transfer only part of file instead of whole file at once? Like, using dd installed somewhere on sdcard instead of /bin so no root required?

funnyflowerpot commented 6 years ago

Hi. Since I found adbfs issue #8 kept me from using it efficiently and in a larger scale (e.g. for decentralized file synchronization). Basically, temporary files in /tmp/adbfs-XXXXXX filled my up hard disk until my system became unusable.

I followed the suggestion of @spion above and changed adb_release() to the following snippet. Compiled, executed, worked. Not sure about side effects, but >100 files of >600MB were copied with matching checksums and without obvious errors.

static int adb_release(const char *path, struct fuse_file_info *fi) {
    // just like in the other functions
    string path_string;
    string local_path_string;
    path_string.assign(path);
    local_path_string = tempDirPath;
    string_replacer(path_string,"/","-");
    local_path_string.append(path_string);
    path_string.assign(path);

    // untouched
    int fd = fi->fh;
    filePendingWrite.erase(filePendingWrite.find(fd));
    close(fd);

    // remove local copy
    unlink(local_path_string.c_str());    
    return 0;
}
spion commented 6 years ago

@funnyflowerpot can you submit a pull request? I'll try it out and merge it.

codexp commented 5 years ago

I confirm this issue. This is really pain in the a** on machines with little disk space free. Every time free disk space is almost used, large operations (copying) are failing.