Skip to content

Commit

Permalink
Merge pull request #288 from trapexit/uint64_t
Browse files Browse the repository at this point in the history
move size calculations to use uint64_t. fixes #287
  • Loading branch information
trapexit authored Jul 11, 2016
2 parents 1e7b84f + 43cbd9c commit a375f33
Show file tree
Hide file tree
Showing 42 changed files with 143 additions and 151 deletions.
2 changes: 1 addition & 1 deletion src/access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static
int
_access(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
const int mask)
{
Expand Down
2 changes: 1 addition & 1 deletion src/chmod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ static
int
_chmod(Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
const mode_t mode)
{
Expand Down
2 changes: 1 addition & 1 deletion src/chown.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static
int
_chown(Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
const uid_t uid,
const gid_t gid)
Expand Down
2 changes: 1 addition & 1 deletion src/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace mergerfs
std::string destmount;
std::vector<std::string> srcmounts;
mutable pthread_rwlock_t srcmountslock;
size_t minfreespace;
uint64_t minfreespace;
bool moveonenospc;

public:
Expand Down
2 changes: 1 addition & 1 deletion src/create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int
_create(Policy::Func::Search searchFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
const mode_t mode,
const int flags,
Expand Down
13 changes: 7 additions & 6 deletions src/fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <fcntl.h>
#include <glob.h>
#include <limits.h>
#include <stdint.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
Expand Down Expand Up @@ -73,8 +74,8 @@ namespace fs
bool
info(const string &path,
bool &readonly,
size_t &spaceavail,
size_t &spaceused)
uint64_t &spaceavail,
uint64_t &spaceused)
{
bool rv;
struct statvfs st;
Expand Down Expand Up @@ -103,7 +104,7 @@ namespace fs

bool
spaceavail(const string &path,
size_t &spaceavail)
uint64_t &spaceavail)
{
bool rv;
struct statvfs st;
Expand All @@ -117,7 +118,7 @@ namespace fs

bool
spaceused(const string &path,
size_t &spaceused)
uint64_t &spaceused)
{
bool rv;
struct statvfs st;
Expand Down Expand Up @@ -231,7 +232,7 @@ namespace fs

int
mfs(const vector<string> &basepaths,
const size_t minfreespace,
const uint64_t minfreespace,
string &path)
{
fsblkcnt_t mfs;
Expand All @@ -241,7 +242,7 @@ namespace fs
mfsbasepath = NULL;
for(size_t i = 0, ei = basepaths.size(); i != ei; i++)
{
size_t spaceavail;
uint64_t spaceavail;
const string &basepath = basepaths[i];

if(!fs::spaceavail(basepath,spaceavail))
Expand Down
13 changes: 7 additions & 6 deletions src/fs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
#ifndef __FS_HPP__
#define __FS_HPP__

#include <stdint.h>

#include <string>
#include <vector>

namespace fs
{
using std::size_t;
using std::string;
using std::vector;

Expand All @@ -35,16 +36,16 @@ namespace fs

bool info(const string &path,
bool &readonly,
size_t &spaceavail,
size_t &spaceused);
uint64_t &spaceavail,
uint64_t &spaceused);

bool readonly(const string &path);

bool spaceavail(const string &path,
size_t &spaceavail);
uint64_t &spaceavail);

bool spaceused(const string &path,
size_t &spaceavail);
uint64_t &spaceavail);

void findallfiles(const vector<string> &srcmounts,
const char *fusepath,
Expand All @@ -63,7 +64,7 @@ namespace fs
int getfl(const int fd);

int mfs(const vector<string> &srcs,
const size_t minfreespace,
const uint64_t minfreespace,
string &path);
};

Expand Down
1 change: 0 additions & 1 deletion src/fs_xattr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace fs
{
namespace xattr
{
using std::size_t;
using std::string;
using std::vector;
using std::map;
Expand Down
2 changes: 1 addition & 1 deletion src/getattr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static
int
_getattr(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
struct stat &buf)
{
Expand Down
2 changes: 1 addition & 1 deletion src/ioctl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static
int
_ioctl_dir_base(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
const int cmd,
void *data)
Expand Down
14 changes: 7 additions & 7 deletions src/link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int
_link_create_path(Policy::Func::Search searchFunc,
Policy::Func::Action actionFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *oldfusepath,
const char *newfusepath)
{
Expand Down Expand Up @@ -117,7 +117,7 @@ int
_clonepath_if_would_create(Policy::Func::Search searchFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const string &oldbasepath,
const char *oldfusepath,
const char *newfusepath)
Expand Down Expand Up @@ -158,7 +158,7 @@ int
_link_preserve_path_core(Policy::Func::Search searchFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const string &oldbasepath,
const char *oldfusepath,
const char *newfusepath,
Expand Down Expand Up @@ -190,7 +190,7 @@ int
_link_preserve_path_loop(Policy::Func::Search searchFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *oldfusepath,
const char *newfusepath,
const vector<const string*> &oldbasepaths)
Expand All @@ -216,9 +216,9 @@ _link_preserve_path(Policy::Func::Search searchFunc,
Policy::Func::Action actionFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const char *oldfusepath,
const char *newfusepath)
const uint64_t minfreespace,
const char *oldfusepath,
const char *newfusepath)
{
int rv;
vector<const string*> oldbasepaths;
Expand Down
2 changes: 1 addition & 1 deletion src/listxattr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ static
int
_listxattr(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
char *list,
const size_t size)
Expand Down
2 changes: 1 addition & 1 deletion src/mkdir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int
_mkdir(Policy::Func::Search searchFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
const mode_t mode)
{
Expand Down
2 changes: 1 addition & 1 deletion src/mknod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ int
_mknod(Policy::Func::Search searchFunc,
Policy::Func::Create createFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
const mode_t mode,
const dev_t dev)
Expand Down
9 changes: 5 additions & 4 deletions src/num.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include <stdint.h>
#include <stdlib.h>

#include <string>

namespace num
{
int
to_size_t(const std::string &str,
size_t &value)
to_uint64_t(const std::string &str,
uint64_t &value)
{
size_t tmp;
char *endptr;
char *endptr;
uint64_t tmp;

tmp = strtoll(str.c_str(),&endptr,10);
switch(*endptr)
Expand Down
4 changes: 3 additions & 1 deletion src/num.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#include <stdint.h>

#include <string>

namespace num
{
int to_size_t(const std::string &str, size_t &value);
int to_uint64_t(const std::string &str, uint64_t &value);
}
2 changes: 1 addition & 1 deletion src/open.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static
int
_open(Policy::Func::Search searchFunc,
const vector<string> &srcmounts,
const size_t minfreespace,
const uint64_t minfreespace,
const char *fusepath,
const int flags,
uint64_t &fh)
Expand Down
4 changes: 2 additions & 2 deletions src/option_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ set_default_options(fuse_args &args)
static
int
parse_and_process_minfreespace(const std::string &value,
size_t &minfreespace)
uint64_t &minfreespace)
{
int rv;

rv = num::to_size_t(value,minfreespace);
rv = num::to_uint64_t(value,minfreespace);
if(rv == -1)
return 1;

Expand Down
35 changes: 17 additions & 18 deletions src/policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,14 @@ namespace mergerfs
struct Func
{
typedef std::string string;
typedef std::size_t size_t;
typedef std::vector<string> strvec;
typedef std::vector<const string*> cstrptrvec;
typedef const string cstring;
typedef const size_t csize_t;
typedef const uint64_t cuint64_t;
typedef const strvec cstrvec;
typedef const Category::Enum::Type CType;

typedef int (*Ptr)(CType,cstrvec &,const char *,csize_t,cstrptrvec &);
typedef int (*Ptr)(CType,cstrvec &,const char *,cuint64_t,cstrptrvec &);

template <CType T>
class Base
Expand All @@ -82,7 +81,7 @@ namespace mergerfs
{}

int
operator()(cstrvec &b,const char *c,csize_t d,cstrptrvec &e)
operator()(cstrvec &b,const char *c,cuint64_t d,cstrptrvec &e)
{
return func(T,b,c,d,e);
}
Expand All @@ -95,18 +94,18 @@ namespace mergerfs
typedef Base<Category::Enum::create> Create;
typedef Base<Category::Enum::search> Search;

static int invalid(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int all(CType,cstrvec&,const char*,csize_t,cstrptrvec&);
static int eplfs(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int eplus(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int epmfs(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int erofs(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int ff(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int lfs(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int lus(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int mfs(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int newest(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int rand(CType,cstrvec&,const char *,csize_t,cstrptrvec&);
static int invalid(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
static int all(CType,cstrvec&,const char*,cuint64_t,cstrptrvec&);
static int eplfs(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
static int eplus(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
static int epmfs(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
static int erofs(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
static int ff(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
static int lfs(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
static int lus(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
static int mfs(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
static int newest(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
static int rand(CType,cstrvec&,const char *,cuint64_t,cstrptrvec&);
};

private:
Expand Down Expand Up @@ -165,8 +164,8 @@ namespace mergerfs
static const Policy &find(const Enum::Type);

public:
static const std::vector<Policy> _policies_;
static const Policy * const policies;
static const std::vector<Policy> _policies_;
static const Policy * const policies;

static const Policy &invalid;
static const Policy &all;
Expand Down
Loading

0 comments on commit a375f33

Please sign in to comment.