Skip to content

Commit

Permalink
Cygwin, support Windows-style parameter paths (#510)
Browse files Browse the repository at this point in the history
Enable the use of Windows-style paths as parameters.
Now, user can use for example : encfs C:\cipher X:
A new internal option, unmountPoint, then retains the mount point as provided by the user.
  • Loading branch information
Ben RUBSON authored Apr 23, 2018
1 parent 49cfb4c commit 6c1fde2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion encfs/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ bool EncFS_Context::usageAndUnmount(int timeoutCycles) {
if (!openFiles.empty()) {
if (idleCount % timeoutCycles == 0) {
RLOG(WARNING) << "Filesystem inactive, but " << openFiles.size()
<< " files opened: " << this->opts->mountPoint;
<< " files opened: " << this->opts->unmountPoint;
}
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions encfs/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1749,7 +1749,7 @@ void unmountFS(const char *mountPoint) {
pid_t pid;
int status;
if ((pid = fork()) == 0) {
execl("/usr/bin/pkill", "/usr/bin/pkill", "-INT", "-f", string("(^|/)encfs .*/.* ").append(mountPoint).append("?( |$)").c_str(), (char *)0);
execl("/bin/pkill", "/bin/pkill", "-INT", "-if", string("(^|/)encfs .*(/|.:).* ").append(mountPoint).append("( |$)").c_str(), (char *)0);
int eno = errno;
RLOG(ERROR) << "Filesystem unmount failed: " << strerror(eno);
_Exit(127);
Expand All @@ -1775,14 +1775,14 @@ int remountFS(EncFS_Context *ctx) {
bool unmountFS(EncFS_Context *ctx) {
if (ctx->opts->mountOnDemand) {
VLOG(1) << "Detaching filesystem due to inactivity: "
<< ctx->opts->mountPoint;
<< ctx->opts->unmountPoint;

ctx->setRoot(std::shared_ptr<DirNode>());
return false;
}
// Time to unmount!
RLOG(INFO) << "Filesystem inactive, unmounting: " << ctx->opts->mountPoint;
unmountFS(ctx->opts->mountPoint.c_str());
RLOG(INFO) << "Filesystem inactive, unmounting: " << ctx->opts->unmountPoint;
unmountFS(ctx->opts->unmountPoint.c_str());
return true;
}

Expand Down
1 change: 1 addition & 0 deletions encfs/FileUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ enum ConfigMode { Config_Prompt, Config_Standard, Config_Paranoia };
struct EncFS_Opts {
std::string rootDir;
std::string mountPoint; // where to make filesystem visible
std::string unmountPoint;// same as mountPoint, but as given by the user
std::string cygDrive; // Cygwin mount drive
bool createIfNotFound; // create filesystem if not found
bool idleTracking; // turn on idle monitoring of filesystem
Expand Down
28 changes: 21 additions & 7 deletions encfs/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include <pthread.h>
#include <sstream>
#include <string>
#ifdef __CYGWIN__
#include <sys/cygwin.h>
#endif
#include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h>
Expand Down Expand Up @@ -463,7 +466,10 @@ static bool processArgs(int argc, char *argv[],
// for --unmount, we should have exactly 1 argument - the mount point
if (out->opts->unmount) {
if (optind + 1 == argc) {
out->opts->mountPoint = slashTerminate(argv[optind++]);
// unmountPoint is kept as given by the user : in Cygwin, it is used
// by pkill to terminate the correct process. We can't then use a
// Linux-converted Windows-style mountPoint to unmount...
out->opts->unmountPoint = string(argv[optind++]);
return true;
}
// no mount point specified
Expand All @@ -477,7 +483,8 @@ static bool processArgs(int argc, char *argv[],
// both rootDir and mountPoint are assumed to be slash terminated in the
// rest of the code.
out->opts->rootDir = slashTerminate(argv[optind++]);
out->opts->mountPoint = slashTerminate(argv[optind++]);
out->opts->unmountPoint = string(argv[optind++]);
out->opts->mountPoint = slashTerminate(out->opts->unmountPoint.c_str());
} else {
// no mount point specified
cerr << _("Missing one or more arguments, aborting.") << endl;
Expand Down Expand Up @@ -519,6 +526,13 @@ static bool processArgs(int argc, char *argv[],
#endif
}

#ifdef __CYGWIN__
// Windows users may use Windows paths
// https://cygwin.com/cygwin-api/cygwin-functions.html
out->opts->mountPoint = string((char *)cygwin_create_path(CCP_WIN_A_TO_POSIX | CCP_RELATIVE, out->opts->mountPoint.c_str()));
out->opts->rootDir = string((char *)cygwin_create_path(CCP_WIN_A_TO_POSIX | CCP_RELATIVE, out->opts->rootDir.c_str()));
#endif

// sanity check
if (out->isDaemon && (!isAbsolutePath(out->opts->mountPoint.c_str()) ||
!isAbsolutePath(out->opts->rootDir.c_str()))) {
Expand Down Expand Up @@ -574,7 +588,7 @@ static bool processArgs(int argc, char *argv[],
if ((strncmp(out->opts->mountPoint.c_str(), "/cygdrive/", 10) != 0) ||
(out->opts->mountPoint.length() != 12)) {
cerr << _("A drive is prefered for mouting, ")
<< _("so a path like /cygdrive/x should rather be used. ")
<< _("so a path like X: (or /cygdrive/x) should rather be used. ")
<< _("Mounting anyway.") << endl;
}
#else
Expand Down Expand Up @@ -664,8 +678,8 @@ int main(int argc, char *argv[]) {
// Let's unmount if requested
if (encfsArgs->opts->unmount) {
// We use cout here to avoid logging to stderr (and to mess-up tests output)
cout << "Filesystem unmounting: " << encfsArgs->opts->mountPoint << endl;
unmountFS(encfsArgs->opts->mountPoint.c_str());
cout << "Filesystem unmounting: " << encfsArgs->opts->unmountPoint << endl;
unmountFS(encfsArgs->opts->unmountPoint.c_str());
return 0;
}

Expand Down Expand Up @@ -846,7 +860,7 @@ static void *idleMonitor(void *_arg) {

// We will notify when FS will be unmounted, so notify that it has just been
// mounted
RLOG(INFO) << "Filesystem mounted: " << arg->opts->mountPoint;
RLOG(INFO) << "Filesystem mounted: " << arg->opts->unmountPoint;

pthread_mutex_lock(&ctx->wakeupMutex);

Expand All @@ -869,7 +883,7 @@ static void *idleMonitor(void *_arg) {
// If we are here FS has been unmounted, so if the idleMonitor did not unmount itself,
// let's notify (certainly due to a kill signal, a manual unmount...)
if (!unmountres) {
RLOG(INFO) << "Filesystem unmounted: " << arg->opts->mountPoint;
RLOG(INFO) << "Filesystem unmounted: " << arg->opts->unmountPoint;
}

VLOG(1) << "Idle monitoring thread exiting";
Expand Down

0 comments on commit 6c1fde2

Please sign in to comment.