mirror of
https://github.com/vgough/encfs.git
synced 2024-11-21 23:43:26 +01:00
Cygwin, support Windows-style parameter paths (#510)
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.
This commit is contained in:
parent
49cfb4cc8e
commit
6c1fde25fc
@ -116,7 +116,7 @@ bool EncFS_Context::usageAndUnmount(int timeoutCycles) {
|
|||||||
if (!openFiles.empty()) {
|
if (!openFiles.empty()) {
|
||||||
if (idleCount % timeoutCycles == 0) {
|
if (idleCount % timeoutCycles == 0) {
|
||||||
RLOG(WARNING) << "Filesystem inactive, but " << openFiles.size()
|
RLOG(WARNING) << "Filesystem inactive, but " << openFiles.size()
|
||||||
<< " files opened: " << this->opts->mountPoint;
|
<< " files opened: " << this->opts->unmountPoint;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1749,7 +1749,7 @@ void unmountFS(const char *mountPoint) {
|
|||||||
pid_t pid;
|
pid_t pid;
|
||||||
int status;
|
int status;
|
||||||
if ((pid = fork()) == 0) {
|
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;
|
int eno = errno;
|
||||||
RLOG(ERROR) << "Filesystem unmount failed: " << strerror(eno);
|
RLOG(ERROR) << "Filesystem unmount failed: " << strerror(eno);
|
||||||
_Exit(127);
|
_Exit(127);
|
||||||
@ -1775,14 +1775,14 @@ int remountFS(EncFS_Context *ctx) {
|
|||||||
bool unmountFS(EncFS_Context *ctx) {
|
bool unmountFS(EncFS_Context *ctx) {
|
||||||
if (ctx->opts->mountOnDemand) {
|
if (ctx->opts->mountOnDemand) {
|
||||||
VLOG(1) << "Detaching filesystem due to inactivity: "
|
VLOG(1) << "Detaching filesystem due to inactivity: "
|
||||||
<< ctx->opts->mountPoint;
|
<< ctx->opts->unmountPoint;
|
||||||
|
|
||||||
ctx->setRoot(std::shared_ptr<DirNode>());
|
ctx->setRoot(std::shared_ptr<DirNode>());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Time to unmount!
|
// Time to unmount!
|
||||||
RLOG(INFO) << "Filesystem inactive, unmounting: " << ctx->opts->mountPoint;
|
RLOG(INFO) << "Filesystem inactive, unmounting: " << ctx->opts->unmountPoint;
|
||||||
unmountFS(ctx->opts->mountPoint.c_str());
|
unmountFS(ctx->opts->unmountPoint.c_str());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,6 +72,7 @@ enum ConfigMode { Config_Prompt, Config_Standard, Config_Paranoia };
|
|||||||
struct EncFS_Opts {
|
struct EncFS_Opts {
|
||||||
std::string rootDir;
|
std::string rootDir;
|
||||||
std::string mountPoint; // where to make filesystem visible
|
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
|
std::string cygDrive; // Cygwin mount drive
|
||||||
bool createIfNotFound; // create filesystem if not found
|
bool createIfNotFound; // create filesystem if not found
|
||||||
bool idleTracking; // turn on idle monitoring of filesystem
|
bool idleTracking; // turn on idle monitoring of filesystem
|
||||||
|
@ -28,6 +28,9 @@
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#ifdef __CYGWIN__
|
||||||
|
#include <sys/cygwin.h>
|
||||||
|
#endif
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -463,7 +466,10 @@ static bool processArgs(int argc, char *argv[],
|
|||||||
// for --unmount, we should have exactly 1 argument - the mount point
|
// for --unmount, we should have exactly 1 argument - the mount point
|
||||||
if (out->opts->unmount) {
|
if (out->opts->unmount) {
|
||||||
if (optind + 1 == argc) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
// no mount point specified
|
// no mount point specified
|
||||||
@ -477,7 +483,8 @@ static bool processArgs(int argc, char *argv[],
|
|||||||
// both rootDir and mountPoint are assumed to be slash terminated in the
|
// both rootDir and mountPoint are assumed to be slash terminated in the
|
||||||
// rest of the code.
|
// rest of the code.
|
||||||
out->opts->rootDir = slashTerminate(argv[optind++]);
|
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 {
|
} else {
|
||||||
// no mount point specified
|
// no mount point specified
|
||||||
cerr << _("Missing one or more arguments, aborting.") << endl;
|
cerr << _("Missing one or more arguments, aborting.") << endl;
|
||||||
@ -519,6 +526,13 @@ static bool processArgs(int argc, char *argv[],
|
|||||||
#endif
|
#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
|
// sanity check
|
||||||
if (out->isDaemon && (!isAbsolutePath(out->opts->mountPoint.c_str()) ||
|
if (out->isDaemon && (!isAbsolutePath(out->opts->mountPoint.c_str()) ||
|
||||||
!isAbsolutePath(out->opts->rootDir.c_str()))) {
|
!isAbsolutePath(out->opts->rootDir.c_str()))) {
|
||||||
@ -574,7 +588,7 @@ static bool processArgs(int argc, char *argv[],
|
|||||||
if ((strncmp(out->opts->mountPoint.c_str(), "/cygdrive/", 10) != 0) ||
|
if ((strncmp(out->opts->mountPoint.c_str(), "/cygdrive/", 10) != 0) ||
|
||||||
(out->opts->mountPoint.length() != 12)) {
|
(out->opts->mountPoint.length() != 12)) {
|
||||||
cerr << _("A drive is prefered for mouting, ")
|
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;
|
<< _("Mounting anyway.") << endl;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -664,8 +678,8 @@ int main(int argc, char *argv[]) {
|
|||||||
// Let's unmount if requested
|
// Let's unmount if requested
|
||||||
if (encfsArgs->opts->unmount) {
|
if (encfsArgs->opts->unmount) {
|
||||||
// We use cout here to avoid logging to stderr (and to mess-up tests output)
|
// We use cout here to avoid logging to stderr (and to mess-up tests output)
|
||||||
cout << "Filesystem unmounting: " << encfsArgs->opts->mountPoint << endl;
|
cout << "Filesystem unmounting: " << encfsArgs->opts->unmountPoint << endl;
|
||||||
unmountFS(encfsArgs->opts->mountPoint.c_str());
|
unmountFS(encfsArgs->opts->unmountPoint.c_str());
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -846,7 +860,7 @@ static void *idleMonitor(void *_arg) {
|
|||||||
|
|
||||||
// We will notify when FS will be unmounted, so notify that it has just been
|
// We will notify when FS will be unmounted, so notify that it has just been
|
||||||
// mounted
|
// mounted
|
||||||
RLOG(INFO) << "Filesystem mounted: " << arg->opts->mountPoint;
|
RLOG(INFO) << "Filesystem mounted: " << arg->opts->unmountPoint;
|
||||||
|
|
||||||
pthread_mutex_lock(&ctx->wakeupMutex);
|
pthread_mutex_lock(&ctx->wakeupMutex);
|
||||||
|
|
||||||
@ -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,
|
// 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...)
|
// let's notify (certainly due to a kill signal, a manual unmount...)
|
||||||
if (!unmountres) {
|
if (!unmountres) {
|
||||||
RLOG(INFO) << "Filesystem unmounted: " << arg->opts->mountPoint;
|
RLOG(INFO) << "Filesystem unmounted: " << arg->opts->unmountPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
VLOG(1) << "Idle monitoring thread exiting";
|
VLOG(1) << "Idle monitoring thread exiting";
|
||||||
|
Loading…
Reference in New Issue
Block a user