fsmounter: formatting code using astyle

Origin commit data
------------------
Commit: 5648bbe1cd
Author: vanhofen <vanhofen@gmx.de>
Date: 2021-05-15 (Sat, 15 May 2021)

Origin message was:
------------------
- fsmounter: formatting code using astyle
This commit is contained in:
vanhofen
2021-05-15 21:59:40 +02:00
parent 126e4e6a67
commit c022e3d25f
2 changed files with 104 additions and 105 deletions

View File

@@ -54,12 +54,12 @@ pthread_cond_t g_cond;
pthread_t g_mnt; pthread_t g_mnt;
int g_mntstatus; int g_mntstatus;
void *mount_thread(void* cmd) void *mount_thread(void *cmd)
{ {
int ret; int ret;
ret=system((const char *) cmd); ret = system((const char *) cmd);
pthread_mutex_lock(&g_mut); pthread_mutex_lock(&g_mut);
g_mntstatus=ret; g_mntstatus = ret;
pthread_cond_broadcast(&g_cond); pthread_cond_broadcast(&g_cond);
pthread_mutex_unlock(&g_mut); pthread_mutex_unlock(&g_mut);
pthread_exit(NULL); pthread_exit(NULL);
@@ -69,7 +69,7 @@ CFSMounter::CFSMounter()
{ {
} }
bool in_proc_filesystems(const char * const fsname) bool in_proc_filesystems(const char *const fsname)
{ {
std::string s; std::string s;
std::string t; std::string t;
@@ -123,7 +123,7 @@ bool remove_modules(const CFSMounter::FSType fstype)
CFSMounter::FS_Support CFSMounter::fsSupported(const CFSMounter::FSType fstype, const bool keep_modules) CFSMounter::FS_Support CFSMounter::fsSupported(const CFSMounter::FSType fstype, const bool keep_modules)
{ {
const char * fsname = NULL; const char *fsname = NULL;
if (fstype == CFSMounter::NFS) if (fstype == CFSMounter::NFS)
fsname = "nfs"; fsname = "nfs";
@@ -167,12 +167,13 @@ bool CFSMounter::isMounted(const std::string &local_dir)
#else #else
char mount_point[4096]; char mount_point[4096];
#endif #endif
if (realpath(local_dir.c_str(), mount_point) == NULL) { if (realpath(local_dir.c_str(), mount_point) == NULL)
printf("[CFSMounter] could not resolve dir: %s: %s\n",local_dir.c_str(), strerror(errno)); {
printf("[CFSMounter] could not resolve dir: %s: %s\n", local_dir.c_str(), strerror(errno));
return false; return false;
} }
in.open("/proc/mounts", std::ifstream::in); in.open("/proc/mounts", std::ifstream::in);
while(in.good()) while (in.good())
{ {
MountInfo mi; MountInfo mi;
in >> mi.device >> mi.mountPoint >> mi.type; in >> mi.device >> mi.mountPoint >> mi.type;
@@ -181,7 +182,7 @@ bool CFSMounter::isMounted(const std::string &local_dir)
if (mi.type == "tmpfs") if (mi.type == "tmpfs")
continue; continue;
if (strcmp(mi.mountPoint.c_str(),mount_point) == 0) if (strcmp(mi.mountPoint.c_str(), mount_point) == 0)
{ {
return true; return true;
} }
@@ -197,7 +198,7 @@ CFSMounter::MountRes CFSMounter::mount(const std::string &ip, const std::string
std::string cmd; std::string cmd;
pthread_mutex_init(&g_mut, NULL); pthread_mutex_init(&g_mut, NULL);
pthread_cond_init(&g_cond, NULL); pthread_cond_init(&g_cond, NULL);
g_mntstatus=-1; g_mntstatus = -1;
FS_Support sup = fsSupported(fstype, true); /* keep modules if necessary */ FS_Support sup = fsSupported(fstype, true); /* keep modules if necessary */
@@ -218,32 +219,32 @@ CFSMounter::MountRes CFSMounter::mount(const std::string &ip, const std::string
return MRES_FS_ALREADY_MOUNTED; return MRES_FS_ALREADY_MOUNTED;
} }
if(options1.empty()) if (options1.empty())
{ {
options1 = options2; options1 = options2;
options2 = ""; options2 = "";
} }
if(options1.empty() && options2.empty()) if (options1.empty() && options2.empty())
{ {
if(fstype == NFS) if (fstype == NFS)
{ {
options1 = "soft"; //NI options1 = "soft"; //NI
options2 = "nolock"; //NI options2 = "nolock"; //NI
} }
else if(fstype == CIFS) else if (fstype == CIFS)
{ {
options1 = "ro"; options1 = "ro";
options2 = ""; options2 = "";
} }
else if(fstype == LUFS) else if (fstype == LUFS)
{ {
options1 = ""; options1 = "";
options2 = ""; options2 = "";
} }
} }
if(fstype == NFS) if (fstype == NFS)
{ {
cmd = "mount -t nfs "; cmd = "mount -t nfs ";
cmd += ip; cmd += ip;
@@ -254,7 +255,7 @@ CFSMounter::MountRes CFSMounter::mount(const std::string &ip, const std::string
cmd += " -o "; cmd += " -o ";
cmd += options1; cmd += options1;
} }
else if(fstype == CIFS) else if (fstype == CIFS)
{ {
cmd = "mount -t cifs //"; cmd = "mount -t cifs //";
cmd += ip; cmd += ip;
@@ -289,7 +290,7 @@ CFSMounter::MountRes CFSMounter::mount(const std::string &ip, const std::string
cmd += options1; cmd += options1;
} }
if (options2[0] !='\0') if (options2[0] != '\0')
{ {
cmd += ','; cmd += ',';
cmd += options2; cmd += options2;
@@ -305,12 +306,13 @@ CFSMounter::MountRes CFSMounter::mount(const std::string &ip, const std::string
timeout.tv_nsec = 0; timeout.tv_nsec = 0;
retcode = pthread_cond_timedwait(&g_cond, &g_mut, &timeout); retcode = pthread_cond_timedwait(&g_cond, &g_mut, &timeout);
if (retcode == ETIMEDOUT) if (retcode == ETIMEDOUT)
{ // timeout occurred {
// timeout occurred
pthread_cancel(g_mnt); pthread_cancel(g_mnt);
} }
pthread_mutex_unlock(&g_mut); pthread_mutex_unlock(&g_mut);
pthread_join(g_mnt, NULL); pthread_join(g_mnt, NULL);
if ( g_mntstatus != 0 ) if (g_mntstatus != 0)
{ {
printf("[CFSMounter] FS mount error: \"%s\"\n", cmd.c_str()); printf("[CFSMounter] FS mount error: \"%s\"\n", cmd.c_str());
return (retcode == ETIMEDOUT) ? MRES_TIMEOUT : MRES_UNKNOWN; return (retcode == ETIMEDOUT) ? MRES_TIMEOUT : MRES_UNKNOWN;
@@ -322,9 +324,9 @@ CFSMounter::MountRes CFSMounter::mount(const std::string &ip, const std::string
bool CFSMounter::automount() bool CFSMounter::automount()
{ {
bool res = true; bool res = true;
for(int i = 0; i < NETWORK_NFS_NR_OF_ENTRIES; i++) for (int i = 0; i < NETWORK_NFS_NR_OF_ENTRIES; i++)
{ {
if(g_settings.network_nfs[i].automount) if (g_settings.network_nfs[i].automount)
{ {
res = (MRES_OK == mount(g_settings.network_nfs[i].ip, g_settings.network_nfs[i].dir, g_settings.network_nfs[i].local_dir, res = (MRES_OK == mount(g_settings.network_nfs[i].ip, g_settings.network_nfs[i].dir, g_settings.network_nfs[i].local_dir,
(FSType) g_settings.network_nfs[i].type, g_settings.network_nfs[i].username, (FSType) g_settings.network_nfs[i].type, g_settings.network_nfs[i].username,
@@ -335,7 +337,7 @@ bool CFSMounter::automount()
return res; return res;
} }
CFSMounter::UMountRes CFSMounter::umount(const char * const dir) CFSMounter::UMountRes CFSMounter::umount(const char *const dir)
{ {
UMountRes res = UMRES_OK; UMountRes res = UMRES_OK;
if (dir != NULL) if (dir != NULL)
@@ -349,16 +351,16 @@ CFSMounter::UMountRes CFSMounter::umount(const char * const dir)
{ {
MountInfo mi; MountInfo mi;
std::ifstream in("/proc/mounts", std::ifstream::in); std::ifstream in("/proc/mounts", std::ifstream::in);
while(in.good()) while (in.good())
{ {
in >> mi.device >> mi.mountPoint >> mi.type; in >> mi.device >> mi.mountPoint >> mi.type;
in.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
if(strcmp(mi.type.c_str(),"nfs")==0 && strcmp(mi.mountPoint.c_str(),"/")==0) if (strcmp(mi.type.c_str(), "nfs") == 0 && strcmp(mi.mountPoint.c_str(), "/") == 0)
{ {
if (umount2(mi.mountPoint.c_str(),MNT_FORCE) != 0) if (umount2(mi.mountPoint.c_str(), MNT_FORCE) != 0)
{ {
printf("[CFSMounter] Error umounting %s\n",mi.device.c_str()); printf("[CFSMounter] Error umounting %s\n", mi.device.c_str());
res = UMRES_ERR; res = UMRES_ERR;
} }
} }
@@ -369,22 +371,20 @@ CFSMounter::UMountRes CFSMounter::umount(const char * const dir)
return res; return res;
} }
void CFSMounter::getMountedFS(MountInfos& info) void CFSMounter::getMountedFS(MountInfos &info)
{ {
std::ifstream in("/proc/mounts", std::ifstream::in); std::ifstream in("/proc/mounts", std::ifstream::in);
while(in.good()) while (in.good())
{ {
MountInfo mi; MountInfo mi;
in >> mi.device >> mi.mountPoint >> mi.type; in >> mi.device >> mi.mountPoint >> mi.type;
in.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); in.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
if (mi.type == "nfs" || if (mi.type == "nfs" || mi.type == "cifs" || mi.type == "lufs")
mi.type == "cifs" ||
mi.type == "lufs")
{ {
info.push_back(mi); info.push_back(mi);
printf("[CFSMounter] mounted fs: dev: %s, mp: %s, type: %s\n", printf("[CFSMounter] mounted fs: dev: %s, mp: %s, type: %s\n",
mi.device.c_str(),mi.mountPoint.c_str(),mi.type.c_str()); mi.device.c_str(), mi.mountPoint.c_str(), mi.type.c_str());
} }
} }
} }

View File

@@ -39,7 +39,6 @@
class CFSMounter class CFSMounter
{ {
// protected
public: public:
enum FS_Support enum FS_Support
@@ -84,11 +83,11 @@ class CFSMounter
typedef std::vector<CFSMounter::MountInfo> MountInfos; typedef std::vector<CFSMounter::MountInfo> MountInfos;
private: private:
/* /*
FS_Support m_nfs_sup; FS_Support m_nfs_sup;
FS_Support m_cifs_sup; FS_Support m_cifs_sup;
FS_Support m_lufs_sup; FS_Support m_lufs_sup;
*/ */
public: public:
CFSMounter(); CFSMounter();
static bool isMounted(const std::string &local_dir); static bool isMounted(const std::string &local_dir);
@@ -96,12 +95,12 @@ class CFSMounter
const FSType fstype, const std::string &username, const std::string &password, const FSType fstype, const std::string &username, const std::string &password,
std::string options1, std::string options2); std::string options1, std::string options2);
static bool automount(); static bool automount();
static CFSMounter::UMountRes umount(const char * const dir = NULL); static CFSMounter::UMountRes umount(const char *const dir = NULL);
static void getMountedFS(MountInfos& fs); static void getMountedFS(MountInfos &fs);
static FS_Support fsSupported(const FSType fs, const bool keep_modules = false); static FS_Support fsSupported(const FSType fs, const bool keep_modules = false);
}; };
bool in_proc_filesystems(const char * const fsname); bool in_proc_filesystems(const char *const fsname);
bool insert_modules(const CFSMounter::FSType fstype); bool insert_modules(const CFSMounter::FSType fstype);
bool remove_modules(const CFSMounter::FSType fstype); bool remove_modules(const CFSMounter::FSType fstype);