adbncfs
0.9.1
|
#include <sstream>
#include <sys/statvfs.h>
#include <execinfo.h>
#include <signal.h>
#include <stdio.h>
#include <pthread.h>
#include "adbncfs.h"
#include "fileInfoCache.h"
#include "spawn.h"
#include "userInfo.h"
#include "mountInfo.h"
Go to the source code of this file.
Macros | |
#define | DBG(line) if (fDebug) cout << "--*-- " << line << endl |
#define | INF(line) cout << "--*-- " << line << endl |
#define | ERR(line) cerr << "--*-- " << line << endl |
Functions | |
static const int | iForwardPort (4444) |
Local and remote adb forward port. More... | |
static bool | fDebug (false) |
Debug mode as set in initAdbncFs() More... | |
static bool | fInReleaseDirCond (false) |
Waited for condition variable. More... | |
static void | sig11Handler (int iSig) |
Segmentation fault handler. More... | |
static Spawn & | initNetCat () |
Spawns a netcat process on the local host with the local forward port. More... | |
static void | destroyNetCat () |
Kills the netcat process spawned in initNetCat(). More... | |
static void | stringReplacer (string &strSource, const string &strFind, const string &strReplace) |
Replace all instances of string strFind with string strReplace in the given string strSource, which is modified in-place. More... | |
static string | makeLocalPath (const string &strPath) |
Converts the given android path to a path on the local host. More... | |
static string | parent (const string &strPath) |
Returns the parent pathname string of the given strPath. More... | |
static vector< string > | tokenize (const string &strData) |
Splits the given data string into tokens. More... | |
static bool | fileExists (const char *pcName) |
Tests whether the file or directory denoted by pcName exists on the local host. More... | |
static deque< string > | execCommandViaNetCat (const string &strCommand) |
Execute the given command string via netcat. More... | |
static deque< string > | execProg (const char *const argv[], const bool fUseStdErr=false, int *const piError=NULL) |
Execute a program. More... | |
static deque< string > | adbncShell (const string &strCommand) |
Execute a shell command on the android device. More... | |
static int | adbncPushPullCmd (const bool fPush, const string &strLocalPath, const string &strRemotePath) |
Execute an adb push or pull command with given paths. More... | |
static int | adbncPull (const string &strRemoteSource, const string &strLocalDestination) |
Copy (using adb pull) a file from the Android device to the local host. More... | |
int | adbncPush (const string &strLocalSource, const string &strRemoteDestination) |
Copy (using adb push) a file from the local host to the Android device. More... | |
static int | doStat (const char *pcPath, vector< string > *pOutputTokens=NULL) |
Execute a stat command on android file or directory denoted by pcPath. More... | |
static const string | androidNetCatStartCommand () |
Return the command line used to start netcat process on android device. More... | |
static int | androidNetcatStarted () |
Test if netcat is started on the android device. More... | |
static void | androidKillNetCat () |
Kills the running netcat process on android device. More... | |
static int | androidStartNetcat () |
Starts a netcat process on the android device. More... | |
static int | isAndroidDeviceConnected () |
Tests if any android device is connected to a local host's usb port. More... | |
static bool | isAndroidPortForwarded (const string &strForwardArg) |
Tests if tcp socket connections from local port to remote port on the android device is in place. More... | |
static int | setAndroidPortForwarding () |
Enable adb port forwarding for our local and remote port. More... | |
static bool | removeAndroidPortForwarding () |
Tries to remove android port forwarding. More... | |
static void | cleanupTempDir (void) |
Recursively deletes the temporary directory created in makeTempDir(). More... | |
static int | makeTempDir (void) |
Create a temporary directory and stores the path in strTempDirPath variable. More... | |
static int | queryUserInfo () |
Query user information (uid, gid, groups) form android device. More... | |
static int | queryMountInfo () |
Query mount information form android device. More... | |
int | initAdbncFs (const int argc, char **const argv) |
Initialize the file system application. More... | |
void * | adbnc_init (struct fuse_conn_info *pConn) |
FUSE callback function to initialize the file system. More... | |
void | adbnc_destroy (void *private_data) |
FUSE callback function, called when the file system exits. More... | |
int | adbnc_statfs (const char *pcPath, struct statvfs *pFst) |
FUSE callback function to retrieve statistics about the file system. More... | |
int | adbnc_getattr (const char *pcPath, struct stat *pStatBuf) |
FUSE callback function to retrieve file attributes. More... | |
int | adbnc_open (const char *pcPath, struct fuse_file_info *pFi) |
FUSE callback to open a file. More... | |
int | adbnc_opendir (const char *pcPath, struct fuse_file_info *pFi) |
FUSE callback to open a directory for reading. More... | |
int | adbnc_readdir (const char *pcPath, void *vpBuf, fuse_fill_dir_t filler, off_t iOffset, struct fuse_file_info *pFi) |
FUSE callback to retrieve directory entries. More... | |
int | adbnc_releasedir (const char *pcPath, struct fuse_file_info *pFi) |
FUSE callback to release given directory. More... | |
int | adbnc_readlink (const char *pcPath, char *pcBuf, size_t iSize) |
FUSE callback function to resolve a link. More... | |
int | adbnc_access (const char *pcPath, int iMask) |
FUSE callback to check whether file pcPath can be accessed. More... | |
int | adbnc_flush (const char *pcPath, struct fuse_file_info *pFi) |
FUSE callback function called on each close so that the file system has a chance to report delayed errors. More... | |
int | adbnc_fsync (const char *pcPath, int iIsdatasync, struct fuse_file_info *pFi) |
int | adbnc_release (const char *pcPath, struct fuse_file_info *pFi) |
FUSE callback called when FUSE is completely done with a file. More... | |
int | adbnc_read (const char *pcPath, char *pcBuf, size_t iSize, off_t iOffset, struct fuse_file_info *pFi) |
FUSE callback to read iSize bytes from the given file into the buffer pcBuf, beginning at iOffset bytes into the file. More... | |
int | adbnc_write (const char *pcPath, const char *pcBuf, size_t iSize, off_t iOffset, struct fuse_file_info *pFi) |
int | adbnc_utimens (const char *pcPath, const struct timespec ts[2]) |
int | adbnc_truncate (const char *pcPath, off_t iSize) |
int | adbnc_mknod (const char *pcPath, mode_t mode, dev_t rdev) |
int | adbnc_mkdir (const char *pcPath, mode_t mode) |
int | adbnc_rename (const char *pcFrom, const char *pcTo) |
int | adbnc_rmdir (const char *pcPath) |
int | adbnc_unlink (const char *pcPath) |
FUSE callback function to remove (delete) the given file, symbolic link, hard link, or special node. More... | |
Variables | |
static const char * | pcDone = "---eoc---" |
static const char * | pcTempDirTemplate = "/tmp/adbncfs-XXXXXX" |
Template used to makeTempDir() More... | |
static const char * | pcSdCardMountEntry = "sdcardfs on /storage/emulated/legacy type sdcardfs (rw,nosuid,nodev,relatime,uid=1023,gid=1023)" |
Big Hack, don't now how to figure out wher sdcard on a phone is mounted. More... | |
static string | strTempDirPath |
Path to the temporary directory used by the instance of this application initialized in makeTempDir(). More... | |
static Spawn * | pNetCat = NULL |
Pointer to the netcat process initialized in initNetCat() More... | |
static FileCache | fileCache |
static FileStatus | fileStatus |
static map< string, deque < string > > | openDirs |
Map to store directory listing retrieved with adbnc_opendir() from android device. More... | |
static UserInfo * | pUserInfo = NULL |
Pointer to user info instance initialized in queryUserInfo() More... | |
static MountInfo * | pMountInfo = NULL |
Pointer to mount info instance initialized in queryMountInfo() More... | |
static pthread_mutex_t | ncCmdMutex |
Mutex to synchronize thread access to execCommandViaNetCat() More... | |
static pthread_mutex_t | openMutex |
Mutex to synchronize thread access to adbnc_open() More... | |
static pthread_mutex_t | inReleaseDirMutex |
Mutex to synchronize thread access to adbnc_opendir() and adbnc_releasedir() More... | |
static pthread_cond_t | inReleaseDirCond |
Condition to block adbnc_opendir() until adbnc_releasedir() is finished. More... | |
#define DBG | ( | line | ) | if (fDebug) cout << "--*-- " << line << endl |
Definition at line 37 of file adbncfs.cpp.
#define ERR | ( | line | ) | cerr << "--*-- " << line << endl |
Definition at line 39 of file adbncfs.cpp.
#define INF | ( | line | ) | cout << "--*-- " << line << endl |
Definition at line 38 of file adbncfs.cpp.
int adbnc_access | ( | const char * | pcPath, |
int | iMask | ||
) |
FUSE callback to check whether file pcPath can be accessed.
No need to follow links, pcPath never points to a link.
pcPath | pathname for that access is tested. |
iMask | specifies the accessibility check(s) to be performed, and is either the value F_OK, or a mask consisting of the bitwise OR of one or more of R_OK, W_OK, and X_OK. F_OK tests for the existence of the file. R_OK, W_OK, and X_OK test whether the file exists and grants read, write, and execute permissions, respectively. |
Definition at line 1474 of file adbncfs.cpp.
void adbnc_destroy | ( | void * | private_data | ) |
FUSE callback function, called when the file system exits.
private_data | comes from the return value of adbnc_init(). |
Definition at line 1003 of file adbncfs.cpp.
int adbnc_flush | ( | const char * | pcPath, |
struct fuse_file_info * | pFi | ||
) |
FUSE callback function called on each close so that the file system has a chance to report delayed errors.
Important: I noticed flush calls for already closed files which causes fsync() to return a EBADF, we'll ignore this error.
pcPath | path to the file to be flushed. |
pFi | pFi-fd the file descriptor of the file to flush. |
Definition at line 1541 of file adbncfs.cpp.
int adbnc_fsync | ( | const char * | pcPath, |
int | iIsdatasync, | ||
struct fuse_file_info * | pFi | ||
) |
Definition at line 1566 of file adbncfs.cpp.
int adbnc_getattr | ( | const char * | pcPath, |
struct stat * | pStatBuf | ||
) |
FUSE callback function to retrieve file attributes.
For the given pathname, the elements of the "stat" structure are filled.
pcPath | |
pStatBuf | is described in detail in the stat(2) manual page. |
Definition at line 1143 of file adbncfs.cpp.
void* adbnc_init | ( | struct fuse_conn_info * | pConn | ) |
FUSE callback function to initialize the file system.
One-time setup of ncCmdMutex, openMutex, inReleaseDirMutex and inReleaseDirCond.
pConn | gives information about what features are supported by FUSE. |
Definition at line 975 of file adbncfs.cpp.
int adbnc_mkdir | ( | const char * | pcPath, |
mode_t | mode | ||
) |
Definition at line 1710 of file adbncfs.cpp.
int adbnc_mknod | ( | const char * | pcPath, |
mode_t | mode, | ||
dev_t | rdev | ||
) |
Definition at line 1687 of file adbncfs.cpp.
int adbnc_open | ( | const char * | pcPath, |
struct fuse_file_info * | pFi | ||
) |
FUSE callback to open a file.
Calls adbncPull() to copy the file from the android device to local host and opens the file on local host. The file handle obtained from local open is set to pFi->fh;
pcPath | path to the filename to open. |
pFi | pFi->fh receives the file handle if file could be opened successfully otherwise it is set to -1. |
Definition at line 1220 of file adbncfs.cpp.
int adbnc_opendir | ( | const char * | pcPath, |
struct fuse_file_info * | pFi | ||
) |
FUSE callback to open a directory for reading.
Stores directory content retrieved from android device in openDirs map for retrieval in adbnc_readdir().
pcPath | pathname of the directory to open. |
pFi | not used here. |
Definition at line 1263 of file adbncfs.cpp.
int adbnc_read | ( | const char * | pcPath, |
char * | pcBuf, | ||
size_t | iSize, | ||
off_t | iOffset, | ||
struct fuse_file_info * | pFi | ||
) |
FUSE callback to read iSize bytes from the given file into the buffer pcBuf, beginning at iOffset bytes into the file.
pcPath | path of the filename to read from. |
pcBuf | receives the read bytes. |
iSize | number of bytes to read. |
iOffset | start reading at this offset. |
pFi | pFi->fh the file handle of the file to read from. as provided by adbnc_open(). |
Definition at line 1619 of file adbncfs.cpp.
int adbnc_readdir | ( | const char * | pcPath, |
void * | vpBuf, | ||
fuse_fill_dir_t | filler, | ||
off_t | iOffset, | ||
struct fuse_file_info * | pFi | ||
) |
FUSE callback to retrieve directory entries.
openDirs, filled by adbnc_opendir(), is supposed to hold the directory listing.
pcPath | pathname of the directory get the listing from. |
vpBuf | buffer where result is returned. |
filler | FUSE provided helper function for putting directory entries into the result buffer. |
iOffset | start reading form this directory entry. |
pFi | not used here. |
Definition at line 1311 of file adbncfs.cpp.
int adbnc_readlink | ( | const char * | pcPath, |
char * | pcBuf, | ||
size_t | iSize | ||
) |
FUSE callback function to resolve a link.
If path is a symbolic link, fills pcBuf with its target, up to iSize.
pcPath | pathname of the link. |
pcBuf | receives the target name of the link. |
iSize | size of pcBuf. |
Definition at line 1400 of file adbncfs.cpp.
int adbnc_release | ( | const char * | pcPath, |
struct fuse_file_info * | pFi | ||
) |
FUSE callback called when FUSE is completely done with a file.
Closes the file handle.
pcPath | path of the filename close. |
pFi | pFi->fh the file handle of the file to close as provided by adbnc_open(). |
Definition at line 1598 of file adbncfs.cpp.
int adbnc_releasedir | ( | const char * | pcPath, |
struct fuse_file_info * | pFi | ||
) |
FUSE callback to release given directory.
Erases the directory listing entry in openDirs.
pcPath | pathname to the directory to release. |
pFi | not used here. |
Definition at line 1366 of file adbncfs.cpp.
int adbnc_rename | ( | const char * | pcFrom, |
const char * | pcTo | ||
) |
Definition at line 1725 of file adbncfs.cpp.
int adbnc_rmdir | ( | const char * | pcPath | ) |
Definition at line 1754 of file adbncfs.cpp.
int adbnc_statfs | ( | const char * | pcPath, |
struct statvfs * | pFst | ||
) |
FUSE callback function to retrieve statistics about the file system.
this is how programs like df determine the free space.
pcPath | statistic is retrieved for the file system containing this path. |
pFst | See statvfs(2) for a description of the structure contents. |
Definition at line 1041 of file adbncfs.cpp.
int adbnc_truncate | ( | const char * | pcPath, |
off_t | iSize | ||
) |
Definition at line 1663 of file adbncfs.cpp.
int adbnc_unlink | ( | const char * | pcPath | ) |
FUSE callback function to remove (delete) the given file, symbolic link, hard link, or special node.
Note that if you support hard links, unlink only deletes the data when the last hard link is removed. See unlink(2) for details.
pcPath | oath to filename to unlink. |
Definition at line 1781 of file adbncfs.cpp.
int adbnc_utimens | ( | const char * | pcPath, |
const struct timespec | ts[2] | ||
) |
Definition at line 1648 of file adbncfs.cpp.
int adbnc_write | ( | const char * | pcPath, |
const char * | pcBuf, | ||
size_t | iSize, | ||
off_t | iOffset, | ||
struct fuse_file_info * | pFi | ||
) |
Definition at line 1637 of file adbncfs.cpp.
|
static |
Copy (using adb pull) a file from the Android device to the local host.
strRemoteSource | Android-side file path to copy. |
strLocalDestination | local host-side destination path for copy. |
Definition at line 512 of file adbncfs.cpp.
int adbncPush | ( | const string & | strLocalSource, |
const string & | strRemoteDestination | ||
) |
Copy (using adb push) a file from the local host to the Android device.
Very similar to adbnc_pull().
Definition at line 528 of file adbncfs.cpp.
|
static |
Execute an adb push or pull command with given paths.
fPush | true for a push command, false for pull. |
strLocalPath | path on local host for push or pull command. |
strRemotePath | path on remote device for push or pull command. |
Definition at line 462 of file adbncfs.cpp.
|
static |
Execute a shell command on the android device.
The given string command is prefixed with "busybox ".
strCommand | the command to execute. |
Definition at line 445 of file adbncfs.cpp.
|
static |
Kills the running netcat process on android device.
Definition at line 636 of file adbncfs.cpp.
|
static |
Return the command line used to start netcat process on android device.
Definition at line 595 of file adbncfs.cpp.
|
static |
Test if netcat is started on the android device.
Definition at line 608 of file adbncfs.cpp.
|
static |
Starts a netcat process on the android device.
Definition at line 661 of file adbncfs.cpp.
|
static |
Recursively deletes the temporary directory created in makeTempDir().
Definition at line 806 of file adbncfs.cpp.
|
static |
Kills the netcat process spawned in initNetCat().
Definition at line 166 of file adbncfs.cpp.
|
static |
Execute a stat command on android file or directory denoted by pcPath.
pcPath | pathname of file or directory on android device. |
pOutputTokens | if not NULL receives the tokenized output of the stat. command. |
Definition at line 542 of file adbncfs.cpp.
|
static |
Execute the given command string via netcat.
strCommand | the string to be executed as a command. |
Definition at line 314 of file adbncfs.cpp.
|
static |
Execute a program.
If program could not be started or if no pipe could be created. an error message is printed to stderr and if piError is not null error number is returned in *piError.
argv | an array of pointers to null-terminated strings that represent the argument list available to the new program. The first argument, by convention, must point to the filename associated with the file being executed. The array of pointers must be terminated by a NULL pointer. |
fUseStdErr | if true stderr is redirected instead of stdout. |
piError | receives, if not NULL,exit code of the program or an errno if an error occurred starting the program. |
Definition at line 362 of file adbncfs.cpp.
|
static |
|
static |
Tests whether the file or directory denoted by pcName exists on the local host.
pcName | the pathname to test for existence. |
Definition at line 301 of file adbncfs.cpp.
|
static |
Waited for condition variable.
|
static |
Local and remote adb forward port.
int initAdbncFs | ( | const int | argc, |
char **const | argv | ||
) |
Initialize the file system application.
Definition at line 906 of file adbncfs.cpp.
|
static |
Spawns a netcat process on the local host with the local forward port.
Writes the used start command to stdout.
Definition at line 140 of file adbncfs.cpp.
|
static |
Tests if any android device is connected to a local host's usb port.
Definition at line 683 of file adbncfs.cpp.
|
static |
Tests if tcp socket connections from local port to remote port on the android device is in place.
strForwardArg | the local and remote port to be used for testing. e.g. "tcp:4444 tcp:4444" |
Definition at line 721 of file adbncfs.cpp.
|
static |
Converts the given android path to a path on the local host.
strPath | the path as used on the android device. |
Definition at line 210 of file adbncfs.cpp.
|
static |
Create a temporary directory and stores the path in strTempDirPath variable.
Definition at line 819 of file adbncfs.cpp.
|
static |
Returns the parent pathname string of the given strPath.
The parent of strPath consists of the pathname's prefix, if any, and each name in the strPath name sequence except for the last.
strPath | the pathname thats parent to retrieve. |
strip last slash if there is one
Definition at line 229 of file adbncfs.cpp.
|
static |
Query mount information form android device.
A "adb shell busybox mount" command is executed and the output is stored in a MontInfo instance for later retrieval. A pointer to the MontInfo object is stored in pMountInfo.
If command failed en error message is written to stdout
Definition at line 870 of file adbncfs.cpp.
|
static |
Query user information (uid, gid, groups) form android device.
A "adb shell busybox id" command is executed and the output is stored in a UserInfo instance for later retrieval. A pointer to the UserInfo object is stored in pUserInfo.
If command failed en error message is written to stdout
Definition at line 845 of file adbncfs.cpp.
|
static |
Tries to remove android port forwarding.
Definition at line 780 of file adbncfs.cpp.
|
static |
Enable adb port forwarding for our local and remote port.
Definition at line 745 of file adbncfs.cpp.
|
static |
Segmentation fault handler.
Is installed in initAdbncFs()
iSig | is supposed to be SIGSEGV. |
Definition at line 119 of file adbncfs.cpp.
|
static |
Replace all instances of string strFind with string strReplace in the given string strSource, which is modified in-place.
The work proceeds down the string and skips over the text introduced by the replacement.
strSource | the string to be modified. |
strFind | the pattern to be replaced. |
strReplace | the replacement for strFind. |
Definition at line 189 of file adbncfs.cpp.
|
static |
Splits the given data string into tokens.
The vector returned by this function contains each substring of the data string that is terminated by
, or blank by the end of the data string.
The substrings in the vector are in the order in which they occur in the data string. If no blank or
, is in the data string then the resulting vector has just one element, namely the data string.
strData | the string to split around blanks and tabs. |
Definition at line 271 of file adbncfs.cpp.
|
static |
Definition at line 77 of file adbncfs.cpp.
|
static |
Definition at line 78 of file adbncfs.cpp.
|
static |
Condition to block adbnc_opendir() until adbnc_releasedir() is finished.
Definition at line 106 of file adbncfs.cpp.
|
static |
Mutex to synchronize thread access to adbnc_opendir() and adbnc_releasedir()
Definition at line 101 of file adbncfs.cpp.
|
static |
Mutex to synchronize thread access to execCommandViaNetCat()
Definition at line 93 of file adbncfs.cpp.
|
static |
Map to store directory listing retrieved with adbnc_opendir() from android device.
Key is the pathname to the directory.
Definition at line 84 of file adbncfs.cpp.
|
static |
Mutex to synchronize thread access to adbnc_open()
Definition at line 96 of file adbncfs.cpp.
|
static |
Definition at line 53 of file adbncfs.cpp.
|
static |
Big Hack, don't now how to figure out wher sdcard on a phone is mounted.
Definition at line 63 of file adbncfs.cpp.
|
static |
Template used to makeTempDir()
Definition at line 56 of file adbncfs.cpp.
|
static |
Pointer to mount info instance initialized in queryMountInfo()
Definition at line 90 of file adbncfs.cpp.
|
static |
Pointer to the netcat process initialized in initNetCat()
Definition at line 75 of file adbncfs.cpp.
|
static |
Pointer to user info instance initialized in queryUserInfo()
Definition at line 87 of file adbncfs.cpp.
|
static |
Path to the temporary directory used by the instance of this application initialized in makeTempDir().
Definition at line 69 of file adbncfs.cpp.