diff options
| author | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-04-09 16:08:00 +0100 | 
|---|---|---|
| committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2016-04-09 16:08:00 +0100 | 
| commit | c1242b7cc805eb0ad73b9372544a3f689902ed6d (patch) | |
| tree | 04728fb4f291ec18623ffe6d380102759d99f247 | |
| parent | Add more assertions around times (diff) | |
| download | netfs-c1242b7cc805eb0ad73b9372544a3f689902ed6d.tar.bz2 netfs-c1242b7cc805eb0ad73b9372544a3f689902ed6d.tar.xz netfs-c1242b7cc805eb0ad73b9372544a3f689902ed6d.zip  | |
Tidy up the mess that was type conversion
| -rw-r--r-- | netfs/daemon/daemonFile.cpp | 11 | ||||
| -rw-r--r-- | netfs/daemon/daemonFile.h | 7 | ||||
| -rw-r--r-- | netfs/daemon/daemonVolume.cpp | 12 | ||||
| -rw-r--r-- | netfs/daemon/daemonVolume.h | 2 | ||||
| -rw-r--r-- | netfs/fuse/fuseApp.cpp | 3 | ||||
| -rw-r--r-- | netfs/fuse/fuseApp.h | 2 | ||||
| -rw-r--r-- | netfs/fuse/fuseDirs.cpp | 5 | ||||
| -rw-r--r-- | netfs/fuse/fuseFiles.cpp | 3 | ||||
| -rw-r--r-- | netfs/fuse/fuseMisc.cpp | 3 | ||||
| -rw-r--r-- | netfs/fuse/fuseSystem.cpp | 3 | ||||
| -rw-r--r-- | netfs/ice/Jamfile.jam | 1 | ||||
| -rw-r--r-- | netfs/ice/entryResolver.h | 16 | ||||
| -rw-r--r-- | netfs/ice/typeConvert.cpp | 70 | ||||
| -rw-r--r-- | netfs/ice/typeConvert.h | 37 | ||||
| -rw-r--r-- | netfs/ice/typeConverter.cpp | 90 | ||||
| -rw-r--r-- | netfs/ice/typeConverter.h | 28 | ||||
| -rw-r--r-- | netfs/lib/entCache.h | 2 | 
17 files changed, 156 insertions, 139 deletions
diff --git a/netfs/daemon/daemonFile.cpp b/netfs/daemon/daemonFile.cpp index 48aa025..94aebe6 100644 --- a/netfs/daemon/daemonFile.cpp +++ b/netfs/daemon/daemonFile.cpp @@ -2,15 +2,14 @@  #include <errno.h>  #include <map>  #include <fcntl.h> -#include <typeConvert.h> +#include <typeConverter.h>  #include <sys/stat.h>  #include "daemonFile.h"  #include <entCache.h>  FileServer::FileServer(int f, const EntryResolver<uid_t> & u, const EntryResolver<gid_t> & g) : -	fd(f), -	userLookup(u), -	groupLookup(g) +	TypeConverter(u, g), +	fd(f)  {  } @@ -36,9 +35,7 @@ FileServer::fgetattr(const NetFS::ReqEnv & re, const Ice::Current &)  	if (::fstat(fd, &s) != 0) {  		throw NetFS::SystemError(errno);  	} -	NetFS::Attr a; -	a << StatSource { s, userLookup, groupLookup }; -	return a; +	return convert(s);  }  void diff --git a/netfs/daemon/daemonFile.h b/netfs/daemon/daemonFile.h index 933d687..ca5b7ca 100644 --- a/netfs/daemon/daemonFile.h +++ b/netfs/daemon/daemonFile.h @@ -2,9 +2,9 @@  #define DAEMONFILE_H  #include <file.h> -#include <typeConvert.h> +#include <typeConverter.h> -class FileServer : public NetFS::File { +class FileServer : public NetFS::File, TypeConverter {  	public:  		FileServer(int fd, const EntryResolver<uid_t> &, const EntryResolver<gid_t> &);  		virtual ~FileServer(); @@ -18,9 +18,6 @@ class FileServer : public NetFS::File {  	private:  		const int fd; - -		const EntryResolver<uid_t> & userLookup; -		const EntryResolver<gid_t> & groupLookup;  };  #endif diff --git a/netfs/daemon/daemonVolume.cpp b/netfs/daemon/daemonVolume.cpp index 3ec6865..7603691 100644 --- a/netfs/daemon/daemonVolume.cpp +++ b/netfs/daemon/daemonVolume.cpp @@ -5,7 +5,6 @@  #include <sys/stat.h>  #include <limits.h>  #include <fcntl.h> -#include <typeConvert.h>  #include "daemonVolume.h"  #include "daemonFile.h"  #include "daemonDirectory.h" @@ -21,7 +20,8 @@ extern std::map<Ice::Int, int> files;  VolumeServer::VolumeServer(const boost::filesystem::path & r, const EntCache<User> & u, const EntCache<Group> & g) :  	root(boost::filesystem::canonical(r)),  	userLookup(u), -	groupLookup(g) +	groupLookup(g), +	converter(u, g)  {  } @@ -71,9 +71,7 @@ VolumeServer::getattr(const NetFS::ReqEnv & re, const std::string & path, const  	if (::lstat(p.c_str(), &s) != 0) {  		throw NetFS::SystemError(errno);  	} -	NetFS::Attr a; -	a << StatSource { s, userLookup, groupLookup }; -	return a; +	return converter.convert(s);  }  void @@ -202,9 +200,7 @@ VolumeServer::statfs(const NetFS::ReqEnv & re, const std::string & path, const I  	if (::statvfs(p.c_str(), &s) != 0) {  		throw NetFS::SystemError(errno);  	} -	NetFS::VFS t; -	t << s; -	return t; +	return converter.convert(s);  }  void diff --git a/netfs/daemon/daemonVolume.h b/netfs/daemon/daemonVolume.h index 14e06d3..b5e8b05 100644 --- a/netfs/daemon/daemonVolume.h +++ b/netfs/daemon/daemonVolume.h @@ -5,6 +5,7 @@  #include <boost/thread/shared_mutex.hpp>  #include <boost/filesystem/path.hpp>  #include <entCache.h> +#include <typeConverter.h>  class VolumeServer : public NetFS::Volume {  	public: @@ -47,6 +48,7 @@ class VolumeServer : public NetFS::Volume {  		const EntCache<User> & userLookup;  		const EntCache<Group> & groupLookup; +		TypeConverter converter;  };  #endif diff --git a/netfs/fuse/fuseApp.cpp b/netfs/fuse/fuseApp.cpp index 9b2ba1c..de75c6f 100644 --- a/netfs/fuse/fuseApp.cpp +++ b/netfs/fuse/fuseApp.cpp @@ -16,7 +16,8 @@ NetFS::FuseApp::FuseApp(const Ice::StringSeq & a) :  	args(a),  	sessionOpened(false),  	openDirID(0), -	openFileID(0) +	openFileID(0), +	converter(userLookup, groupLookup)  {  } diff --git a/netfs/fuse/fuseApp.h b/netfs/fuse/fuseApp.h index a210089..ec75d03 100644 --- a/netfs/fuse/fuseApp.h +++ b/netfs/fuse/fuseApp.h @@ -8,6 +8,7 @@  #include <Glacier2/Session.h>  #include <service.h>  #include <entCache.h> +#include <typeConverter.h>  #include "fuseAppBase.h"  #include "fuseConfig.h"  #include "cache.h" @@ -124,6 +125,7 @@ namespace NetFS {  			EntCache<User> userLookup;  			EntCache<Group> groupLookup; +			TypeConverter converter;  			typedef AdHoc::Cache<struct stat, std::string> StatCache;  			StatCache statCache; diff --git a/netfs/fuse/fuseDirs.cpp b/netfs/fuse/fuseDirs.cpp index ab09ca1..00c0ca4 100644 --- a/netfs/fuse/fuseDirs.cpp +++ b/netfs/fuse/fuseDirs.cpp @@ -1,6 +1,5 @@  #include "fuseApp.h"  #include <lockHelpers.h> -#include <typeConvert.h>  #include <entCache.h>  NetFS::FuseApp::OpenDir::OpenDir(DirectoryPrx r, const std::string & p) : @@ -76,9 +75,7 @@ NetFS::FuseApp::readdir(const char * p, void * buf, fuse_fill_dir_t filler, off_  			auto asga = volume->begin_getattr(reqEnv(), epath);  			statCache.addFactory(epath,  						[asga,this]() { -							struct stat s; -							s << AttrSource { volume->end_getattr(asga), userLookup, groupLookup }; -							return s; +							return converter.convert(volume->end_getattr(asga));  						}, time(NULL) + 2);  		}  		return 0; diff --git a/netfs/fuse/fuseFiles.cpp b/netfs/fuse/fuseFiles.cpp index d7b5a6b..fcc58a9 100644 --- a/netfs/fuse/fuseFiles.cpp +++ b/netfs/fuse/fuseFiles.cpp @@ -1,5 +1,4 @@  #include <string.h> -#include <typeConvert.h>  #include "fuseApp.h"  #include "lockHelpers.h"  #include <entCache.h> @@ -134,7 +133,7 @@ NetFS::FuseApp::fgetattr(const char *, struct stat * s, fuse_file_info * fi)  {  	try {  		auto remote = getFileProxy(fi->fh)->remote; -		*s << AttrSource { remote->fgetattr(reqEnv()), userLookup, groupLookup }; +		*s = converter.convert(remote->fgetattr(reqEnv()));  		return 0;  	}  	catch (NetFS::SystemError & e) { diff --git a/netfs/fuse/fuseMisc.cpp b/netfs/fuse/fuseMisc.cpp index 25aa51a..5ece9a1 100644 --- a/netfs/fuse/fuseMisc.cpp +++ b/netfs/fuse/fuseMisc.cpp @@ -1,6 +1,5 @@  #include "fuseApp.h"  #include <string.h> -#include <typeConvert.h>  #include <entCache.h>  int @@ -18,7 +17,7 @@ NetFS::FuseApp::getattr(const char * p, struct stat * s)  			*s = *cacehedStat;  		}  		else { -			*s << AttrSource { volume->getattr(reqEnv(), p), userLookup, groupLookup }; +			*s = converter.convert(volume->getattr(reqEnv(), p));  		}  		return 0;  	} diff --git a/netfs/fuse/fuseSystem.cpp b/netfs/fuse/fuseSystem.cpp index 2440fa8..85432e8 100644 --- a/netfs/fuse/fuseSystem.cpp +++ b/netfs/fuse/fuseSystem.cpp @@ -1,11 +1,10 @@ -#include <typeConvert.h>  #include "fuseApp.h"  int  NetFS::FuseApp::statfs(const char * p, struct statvfs * vfs)  {  	try { -		*vfs << volume->statfs(reqEnv(), p); +		*vfs = converter.convert(volume->statfs(reqEnv(), p));  		return 0;  	}  	catch (NetFS::SystemError & e) { diff --git a/netfs/ice/Jamfile.jam b/netfs/ice/Jamfile.jam index 0a66073..9f6ea43 100644 --- a/netfs/ice/Jamfile.jam +++ b/netfs/ice/Jamfile.jam @@ -10,6 +10,7 @@ lib netfsComms :  	<library>Ice  	<library>IceUtil  	<library>pthread +	<library>..//adhocutil  	: :  	<include>.  	<library>Ice diff --git a/netfs/ice/entryResolver.h b/netfs/ice/entryResolver.h new file mode 100644 index 0000000..1a20ec3 --- /dev/null +++ b/netfs/ice/entryResolver.h @@ -0,0 +1,16 @@ +#ifndef NETFS_ENTRYRESOLVER_H +#define NETFS_ENTRYRESOLVER_H + +#include <string> +#include <stdlib.h> + +template <class entry_t> +class EntryResolver { +	public: +		typedef std::string name_t; +		virtual void getID(const name_t &, id_t *) const = 0; +		virtual void getName(const id_t &, name_t *) const = 0; +}; + +#endif + diff --git a/netfs/ice/typeConvert.cpp b/netfs/ice/typeConvert.cpp deleted file mode 100644 index 91b2cf4..0000000 --- a/netfs/ice/typeConvert.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "typeConvert.h" - -void -operator<<(struct stat & s, const AttrSource & a) -{ -	s.st_dev = a.attr.dev; -	s.st_ino = a.attr.inode; -	s.st_mode = a.attr.mode; -	s.st_nlink = a.attr.links; -	a.user.getID(a.attr.uid, &s.st_uid); -	a.group.getID(a.attr.gid, &s.st_gid); -	s.st_rdev = a.attr.rdev; -	s.st_size = a.attr.size; -	s.st_blksize = a.attr.blockSize; -	s.st_blocks = a.attr.blocks; -	s.st_atime = a.attr.atime; -	s.st_mtime = a.attr.mtime; -	s.st_ctime = a.attr.ctime; -} - -void -operator<<(struct statvfs & vfs, const NetFS::VFS & v) -{ -	vfs.f_bsize = v.blockSize; -	vfs.f_frsize = v.fragmentSize; -	vfs.f_blocks = v.blocks; -	vfs.f_bfree = v.freeBlocks; -	vfs.f_bavail = v.availBlocks; -	vfs.f_files = v.files; -	vfs.f_ffree = v.freeFiles; -	vfs.f_favail = v.availFiles; -	vfs.f_fsid = v.FSID; -	vfs.f_flag = v.flags; -	vfs.f_namemax = v.maxNameLen; -} - -void -operator<<(NetFS::Attr & a, const struct StatSource & s) -{ -	a.dev = s.stat.st_dev; -	a.inode = s.stat.st_ino; -	a.mode = s.stat.st_mode; -	a.links = s.stat.st_nlink; -	s.user.getName(s.stat.st_uid, &a.uid); -	s.group.getName(s.stat.st_gid, &a.gid); -	a.rdev = s.stat.st_rdev; -	a.size = s.stat.st_size; -	a.blockSize = s.stat.st_blksize; -	a.blocks = s.stat.st_blocks; -	a.atime = s.stat.st_atime; -	a.mtime = s.stat.st_mtime; -	a.ctime = s.stat.st_ctime; -} - -void -operator<<(NetFS::VFS & t, const struct statvfs & s) -{ -	t.blockSize = s.f_bsize; -	t.fragmentSize = s.f_frsize; -	t.blocks = s.f_blocks; -	t.freeBlocks = s.f_bfree; -	t.availBlocks = s.f_bavail; -	t.files = s.f_files; -	t.freeFiles = s.f_ffree; -	t.availFiles = s.f_favail; -	t.FSID = s.f_fsid; -	t.flags = s.f_flag; -	t.maxNameLen = s.f_namemax; -} - diff --git a/netfs/ice/typeConvert.h b/netfs/ice/typeConvert.h deleted file mode 100644 index b07b117..0000000 --- a/netfs/ice/typeConvert.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef NETFS_TYPECONVERT_H -#define NETFS_TYPECONVERT_H - -#include <types.h> -#include <sys/stat.h> -#include <sys/statvfs.h> - -template <class entry_t> -class EntryResolver { -	public: -		typedef std::string name_t; -		virtual void getID(const name_t &, id_t *) const = 0; -		virtual void getName(const id_t &, name_t *) const = 0; -}; - -struct AttrSource { -	const NetFS::Attr & attr; -	const EntryResolver<uid_t> & user; -	const EntryResolver<gid_t> & group; -}; - -struct StatSource { -	const struct stat & stat; -	const EntryResolver<uid_t> & user; -	const EntryResolver<gid_t> & group; -}; - -#pragma GCC visibility push(default) -void operator<<(struct stat &, const AttrSource &); -void operator<<(struct statvfs &, const NetFS::VFS &); - -void operator<<(NetFS::Attr &, const struct StatSource &); -void operator<<(NetFS::VFS &, const struct statvfs &); -#pragma GCC visibility pop - -#endif - diff --git a/netfs/ice/typeConverter.cpp b/netfs/ice/typeConverter.cpp new file mode 100644 index 0000000..dc130b1 --- /dev/null +++ b/netfs/ice/typeConverter.cpp @@ -0,0 +1,90 @@ +#include "typeConverter.h" + +TypeConverter::TypeConverter(const EntryResolver<uid_t> & u, const EntryResolver<gid_t> & g) : +	userLookup(u), +	groupLookup(g) +{ +} + +struct stat +TypeConverter::convert(const NetFS::Attr & a) const +{ +	struct stat s; +	s.st_dev = a.dev; +	s.st_ino = a.inode; +	s.st_mode = a.mode; +	s.st_nlink = a.links; +	userLookup.getID(a.uid, &s.st_uid); +	groupLookup.getID(a.gid, &s.st_gid); +	s.st_rdev = a.rdev; +	s.st_size = a.size; +	s.st_blksize = a.blockSize; +	s.st_blocks = a.blocks; +	s.st_atime = a.atime; +	s.st_atim.tv_sec = a.atime; +	s.st_atim.tv_nsec = 0; +	s.st_mtime = a.mtime; +	s.st_mtim.tv_sec = a.mtime; +	s.st_mtim.tv_nsec = 0; +	s.st_ctime = a.ctime; +	s.st_ctim.tv_sec = a.ctime; +	s.st_ctim.tv_nsec = 0; +	return s; +} + +struct statvfs +TypeConverter::convert(const NetFS::VFS & v) const +{ +	struct statvfs vfs; +	vfs.f_bsize = v.blockSize; +	vfs.f_frsize = v.fragmentSize; +	vfs.f_blocks = v.blocks; +	vfs.f_bfree = v.freeBlocks; +	vfs.f_bavail = v.availBlocks; +	vfs.f_files = v.files; +	vfs.f_ffree = v.freeFiles; +	vfs.f_favail = v.availFiles; +	vfs.f_fsid = v.FSID; +	vfs.f_flag = v.flags; +	vfs.f_namemax = v.maxNameLen; +	return vfs; +} + +NetFS::Attr +TypeConverter::convert(const struct stat & s) const +{ +	NetFS::Attr a; +	a.dev = s.st_dev; +	a.inode = s.st_ino; +	a.mode = s.st_mode; +	a.links = s.st_nlink; +	userLookup.getName(s.st_uid, &a.uid); +	groupLookup.getName(s.st_gid, &a.gid); +	a.rdev = s.st_rdev; +	a.size = s.st_size; +	a.blockSize = s.st_blksize; +	a.blocks = s.st_blocks; +	a.atime = s.st_atime; +	a.mtime = s.st_mtime; +	a.ctime = s.st_ctime; +	return a; +} + +NetFS::VFS +TypeConverter::convert(const struct statvfs & s) const +{ +	NetFS::VFS t; +	t.blockSize = s.f_bsize; +	t.fragmentSize = s.f_frsize; +	t.blocks = s.f_blocks; +	t.freeBlocks = s.f_bfree; +	t.availBlocks = s.f_bavail; +	t.files = s.f_files; +	t.freeFiles = s.f_ffree; +	t.availFiles = s.f_favail; +	t.FSID = s.f_fsid; +	t.flags = s.f_flag; +	t.maxNameLen = s.f_namemax; +	return t; +} + diff --git a/netfs/ice/typeConverter.h b/netfs/ice/typeConverter.h new file mode 100644 index 0000000..d4b1617 --- /dev/null +++ b/netfs/ice/typeConverter.h @@ -0,0 +1,28 @@ +#ifndef NETFS_TYPECONVERT_H +#define NETFS_TYPECONVERT_H + +#include <types.h> +#include <sys/stat.h> +#include <sys/statvfs.h> +#include <visibility.h> +#include "entryResolver.h" + +class DLL_PUBLIC TypeConverter { +	public: +		TypeConverter(const EntryResolver<uid_t> &, const EntryResolver<gid_t> &); + +		// Attributes +		struct stat convert(const NetFS::Attr &) const; +		NetFS::Attr convert(const struct stat &) const; + +		// VFS +		struct statvfs convert(const NetFS::VFS &) const; +		NetFS::VFS convert(const struct statvfs &) const; + +	protected: +		const EntryResolver<uid_t> & userLookup; +		const EntryResolver<gid_t> & groupLookup; +}; + +#endif + diff --git a/netfs/lib/entCache.h b/netfs/lib/entCache.h index 40fc0c1..7e82171 100644 --- a/netfs/lib/entCache.h +++ b/netfs/lib/entCache.h @@ -9,7 +9,7 @@  #include <boost/multi_index/member.hpp>  #include <boost/multi_index/ordered_index.hpp>  #include <boost/thread/shared_mutex.hpp> -#include <typeConvert.h> +#include <entryResolver.h>  class User : public IceUtil::Shared {  	public:  | 
