mirror of
https://github.com/vgough/encfs.git
synced 2024-11-21 15:33:16 +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 (idleCount % timeoutCycles == 0) {
|
||||
RLOG(WARNING) << "Filesystem inactive, but " << openFiles.size()
|
||||
<< " files opened: " << this->opts->mountPoint;
|
||||
<< " files opened: " << this->opts->unmountPoint;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -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);
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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>
|
||||
@ -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
|
||||
@ -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;
|
||||
@ -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()))) {
|
||||
@ -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
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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";
|
||||
|
Loading…
Reference in New Issue
Block a user