Browse Source

Merge pull request #791 from trapexit/configcleanup

cleanup: move some config data structures to separate files
pull/792/head
trapexit 4 years ago
committed by GitHub
parent
commit
50d967221e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 136
      src/config.cpp
  2. 38
      src/config.hpp
  3. 62
      src/config_cachefiles.cpp
  4. 32
      src/config_cachefiles.hpp
  5. 50
      src/config_statfs.cpp
  6. 29
      src/config_statfs.hpp
  7. 54
      src/config_statfsignore.cpp
  8. 29
      src/config_statfsignore.hpp
  9. 54
      src/config_xattr.cpp
  10. 31
      src/config_xattr.hpp
  11. 1
      src/fuse_create.cpp
  12. 6
      src/fuse_listxattr.cpp
  13. 1
      src/fuse_open.cpp
  14. 2
      src/fuse_statfs.cpp

136
src/config.cpp

@ -237,142 +237,6 @@ Config::get(const std::string &key_,
return 0;
}
template<>
std::string
Config::StatFS::to_string() const
{
switch(_data)
{
case Config::StatFS::ENUM::BASE:
return "base";
case Config::StatFS::ENUM::FULL:
return "full";
}
return "invalid";
}
template<>
int
Config::StatFS::from_string(const std::string &s_)
{
if(s_ == "base")
_data = Config::StatFS::ENUM::BASE;
ef(s_ == "full")
_data = Config::StatFS::ENUM::FULL;
else
return -EINVAL;
return 0;
}
template<>
std::string
Config::StatFSIgnore::to_string() const
{
switch(_data)
{
case Config::StatFSIgnore::ENUM::NONE:
return "none";
case Config::StatFSIgnore::ENUM::RO:
return "ro";
case Config::StatFSIgnore::ENUM::NC:
return "nc";
}
return "invalid";
}
template<>
int
Config::StatFSIgnore::from_string(const std::string &s_)
{
if(s_ == "none")
_data = Config::StatFSIgnore::ENUM::NONE;
ef(s_ == "ro")
_data = Config::StatFSIgnore::ENUM::RO;
ef(s_ == "nc")
_data = Config::StatFSIgnore::ENUM::NC;
else
return -EINVAL;
return 0;
}
template<>
std::string
Config::CacheFiles::to_string() const
{
switch(_data)
{
case Config::CacheFiles::ENUM::LIBFUSE:
return "libfuse";
case Config::CacheFiles::ENUM::OFF:
return "off";
case Config::CacheFiles::ENUM::PARTIAL:
return "partial";
case Config::CacheFiles::ENUM::FULL:
return "full";
case Config::CacheFiles::ENUM::AUTO_FULL:
return "auto-full";
}
return "invalid";
}
template<>
int
Config::CacheFiles::from_string(const std::string &s_)
{
if(s_ == "libfuse")
_data = Config::CacheFiles::ENUM::LIBFUSE;
ef(s_ == "off")
_data = Config::CacheFiles::ENUM::OFF;
ef(s_ == "partial")
_data = Config::CacheFiles::ENUM::PARTIAL;
ef(s_ == "full")
_data = Config::CacheFiles::ENUM::FULL;
ef(s_ == "auto-full")
_data = Config::CacheFiles::ENUM::AUTO_FULL;
else
return -EINVAL;
return 0;
}
template<>
std::string
Config::XAttr::to_string() const
{
switch(_data)
{
case Config::XAttr::ENUM::PASSTHROUGH:
return "passthrough";
case Config::XAttr::ENUM::NOSYS:
return "nosys";
case Config::XAttr::ENUM::NOATTR:
return "noattr";
}
return "invalid";
}
template<>
int
Config::XAttr::from_string(const std::string &s_)
{
if(s_ == "passthrough")
_data = Config::XAttr::ENUM::PASSTHROUGH;
ef(s_ == "nosys")
_data = Config::XAttr::ENUM::NOSYS;
ef(s_ == "noattr")
_data = Config::XAttr::ENUM::NOATTR;
else
return -EINVAL;
return 0;
}
int
Config::set_raw(const std::string &key_,
const std::string &value_)

38
src/config.hpp

@ -17,10 +17,14 @@
#pragma once
#include "branch.hpp"
#include "config_cachefiles.hpp"
#include "config_inodecalc.hpp"
#include "config_moveonenospc.hpp"
#include "config_nfsopenhack.hpp"
#include "config_readdir.hpp"
#include "config_statfs.hpp"
#include "config_statfsignore.hpp"
#include "config_xattr.hpp"
#include "enum.hpp"
#include "errno.hpp"
#include "func_category.hpp"
@ -45,40 +49,6 @@ typedef std::map<std::string,ToFromString*> Str2TFStrMap;
class Config
{
public:
enum class StatFSEnum
{
BASE,
FULL
};
typedef Enum<StatFSEnum> StatFS;
enum class StatFSIgnoreEnum
{
NONE,
RO,
NC
};
typedef Enum<StatFSIgnoreEnum> StatFSIgnore;
enum class CacheFilesEnum
{
LIBFUSE,
OFF,
PARTIAL,
FULL,
AUTO_FULL
};
typedef Enum<CacheFilesEnum> CacheFiles;
enum class XAttrEnum
{
PASSTHROUGH = 0,
NOSYS = ENOSYS,
NOATTR = ENOATTR
};
typedef Enum<XAttrEnum> XAttr;
public:
Config();

62
src/config_cachefiles.cpp

@ -0,0 +1,62 @@
/*
ISC License
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "config_cachefiles.hpp"
#include "ef.hpp"
#include "errno.hpp"
template<>
std::string
CacheFiles::to_string() const
{
switch(_data)
{
case CacheFiles::ENUM::LIBFUSE:
return "libfuse";
case CacheFiles::ENUM::OFF:
return "off";
case CacheFiles::ENUM::PARTIAL:
return "partial";
case CacheFiles::ENUM::FULL:
return "full";
case CacheFiles::ENUM::AUTO_FULL:
return "auto-full";
}
return "invalid";
}
template<>
int
CacheFiles::from_string(const std::string &s_)
{
if(s_ == "libfuse")
_data = CacheFiles::ENUM::LIBFUSE;
ef(s_ == "off")
_data = CacheFiles::ENUM::OFF;
ef(s_ == "partial")
_data = CacheFiles::ENUM::PARTIAL;
ef(s_ == "full")
_data = CacheFiles::ENUM::FULL;
ef(s_ == "auto-full")
_data = CacheFiles::ENUM::AUTO_FULL;
else
return -EINVAL;
return 0;
}

32
src/config_cachefiles.hpp

@ -0,0 +1,32 @@
/*
ISC License
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
#include "enum.hpp"
enum class CacheFilesEnum
{
LIBFUSE,
OFF,
PARTIAL,
FULL,
AUTO_FULL
};
typedef Enum<CacheFilesEnum> CacheFiles;

50
src/config_statfs.cpp

@ -0,0 +1,50 @@
/*
ISC License
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "config_statfs.hpp"
#include "ef.hpp"
#include "errno.hpp"
template<>
std::string
StatFS::to_string() const
{
switch(_data)
{
case StatFS::ENUM::BASE:
return "base";
case StatFS::ENUM::FULL:
return "full";
}
return "invalid";
}
template<>
int
StatFS::from_string(const std::string &s_)
{
if(s_ == "base")
_data = StatFS::ENUM::BASE;
ef(s_ == "full")
_data = StatFS::ENUM::FULL;
else
return -EINVAL;
return 0;
}

29
src/config_statfs.hpp

@ -0,0 +1,29 @@
/*
ISC License
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
#include "enum.hpp"
enum class StatFSEnum
{
BASE,
FULL
};
typedef Enum<StatFSEnum> StatFS;

54
src/config_statfsignore.cpp

@ -0,0 +1,54 @@
/*
ISC License
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "config_statfsignore.hpp"
#include "ef.hpp"
#include "errno.hpp"
template<>
std::string
StatFSIgnore::to_string() const
{
switch(_data)
{
case StatFSIgnore::ENUM::NONE:
return "none";
case StatFSIgnore::ENUM::RO:
return "ro";
case StatFSIgnore::ENUM::NC:
return "nc";
}
return "invalid";
}
template<>
int
StatFSIgnore::from_string(const std::string &s_)
{
if(s_ == "none")
_data = StatFSIgnore::ENUM::NONE;
ef(s_ == "ro")
_data = StatFSIgnore::ENUM::RO;
ef(s_ == "nc")
_data = StatFSIgnore::ENUM::NC;
else
return -EINVAL;
return 0;
}

29
src/config_statfsignore.hpp

@ -0,0 +1,29 @@
/*
ISC License
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
#include "enum.hpp"
enum class StatFSIgnoreEnum
{
NONE,
RO,
NC
};
typedef Enum<StatFSIgnoreEnum> StatFSIgnore;

54
src/config_xattr.cpp

@ -0,0 +1,54 @@
/*
ISC License
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "config_xattr.hpp"
#include "ef.hpp"
#include "errno.hpp"
template<>
std::string
XAttr::to_string() const
{
switch(_data)
{
case XAttr::ENUM::PASSTHROUGH:
return "passthrough";
case XAttr::ENUM::NOSYS:
return "nosys";
case XAttr::ENUM::NOATTR:
return "noattr";
}
return "invalid";
}
template<>
int
XAttr::from_string(const std::string &s_)
{
if(s_ == "passthrough")
_data = XAttr::ENUM::PASSTHROUGH;
ef(s_ == "nosys")
_data = XAttr::ENUM::NOSYS;
ef(s_ == "noattr")
_data = XAttr::ENUM::NOATTR;
else
return -EINVAL;
return 0;
}

31
src/config_xattr.hpp

@ -0,0 +1,31 @@
/*
ISC License
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#pragma once
#include "enum.hpp"
#include "errno.hpp"
enum class XAttrEnum
{
PASSTHROUGH = 0,
NOSYS = ENOSYS,
NOATTR = ENOATTR
};
typedef Enum<XAttrEnum> XAttr;

1
src/fuse_create.cpp

@ -30,7 +30,6 @@
using std::string;
using std::vector;
typedef Config::CacheFiles CacheFiles;
namespace l
{

6
src/fuse_listxattr.cpp

@ -94,11 +94,11 @@ namespace FUSE
switch(config.xattr)
{
case Config::XAttr::ENUM::PASSTHROUGH:
case XAttr::ENUM::PASSTHROUGH:
break;
case Config::XAttr::ENUM::NOATTR:
case XAttr::ENUM::NOATTR:
return 0;
case Config::XAttr::ENUM::NOSYS:
case XAttr::ENUM::NOSYS:
return -ENOSYS;
}

1
src/fuse_open.cpp

@ -34,7 +34,6 @@
using std::string;
using std::vector;
typedef Config::CacheFiles CacheFiles;
namespace l
{

2
src/fuse_statfs.cpp

@ -33,8 +33,6 @@
using std::string;
using std::map;
using std::vector;
typedef Config::StatFS StatFS;
typedef Config::StatFSIgnore StatFSIgnore;
namespace l
{

Loading…
Cancel
Save