Loading fs/src/adafs_ops/metadata_ops.cpp +0 −37 Original line number Diff line number Diff line Loading @@ -5,9 +5,6 @@ #include "metadata_ops.h" #include "dentry_ops.h" #include <boost/archive/binary_iarchive.hpp> #include <boost/archive/binary_oarchive.hpp> // TODO error handling. Each read_metadata_field should check for boolean, i.e., if I/O failed. bool write_all_metadata(const Metadata& md, const unsigned long hash) { write_metadata_field(md.atime(), hash, md_field_map.at(Md_fields::atime)); Loading @@ -24,24 +21,6 @@ bool write_all_metadata(const Metadata& md, const unsigned long hash) { return true; } // TODO error handling. template<typename T> bool write_metadata_field(const T& field, const unsigned long hash, const string& leaf_name) { auto i_path = bfs::path(ADAFS_DATA->inode_path); i_path /= to_string(hash); bfs::create_directories(i_path); i_path /= leaf_name; // for some reason auto ofs = bfs::ofstream(file); does not work. That is why I use the old style. // std::basic_ofstream does not encounter this problem bfs::ofstream ofs{i_path}; // write to disk in binary form boost::archive::binary_oarchive ba(ofs); ba << field; return true; } // TODO error handling. Each read_metadata_field should check for nullptr, i.e., if I/O failed. bool read_all_metadata(Metadata& md, const unsigned long hash) { md.atime(*read_metadata_field<time_t>(hash, md_field_map.at(Md_fields::atime))); Loading @@ -58,22 +37,6 @@ bool read_all_metadata(Metadata& md, const unsigned long hash) { } template<typename T> unique_ptr<T> read_metadata_field(const unsigned long hash, const string& leaf_name) { auto path = bfs::path(ADAFS_DATA->inode_path); path /= to_string(hash); path /= leaf_name; if (!bfs::exists(path)) return nullptr; bfs::ifstream ifs{path}; //fast error checking //ifs.good() boost::archive::binary_iarchive ba(ifs); auto field = make_unique<T>(); ba >> *field; return field; } int get_metadata(Metadata& md, const string& path) { return get_metadata(md, bfs::path(path)); } Loading fs/src/adafs_ops/metadata_ops.h +33 −2 Original line number Diff line number Diff line Loading @@ -10,6 +10,9 @@ using namespace std; #include <boost/archive/binary_iarchive.hpp> #include <boost/archive/binary_oarchive.hpp> // mapping of enum to string to get the file names for metadata enum class Md_fields { atime, mtime, ctime, uid, gid, mode, inode_no, link_count, size, blocks }; Loading @@ -28,13 +31,41 @@ const std::map<Md_fields, std::string> md_field_map = { bool write_all_metadata(const Metadata& md, const unsigned long hash); // TODO error handling. template<typename T> bool write_metadata_field(const T& field, const unsigned long hash, const string& leaf_name); bool write_metadata_field(const T& field, const unsigned long hash, const string& leaf_name) { auto i_path = bfs::path(ADAFS_DATA->inode_path); i_path /= to_string(hash); bfs::create_directories(i_path); i_path /= leaf_name; // for some reason auto ofs = bfs::ofstream(file); does not work. That is why I use the old style. // std::basic_ofstream does not encounter this problem bfs::ofstream ofs{i_path}; // write to disk in binary form boost::archive::binary_oarchive ba(ofs); ba << field; return true; } bool read_all_metadata(Metadata& md, const unsigned long hash); template<typename T> unique_ptr<T> read_metadata_field(const unsigned long hash, const string& leaf_name); unique_ptr<T> read_metadata_field(const unsigned long hash, const string& leaf_name) { auto path = bfs::path(ADAFS_DATA->inode_path); path /= to_string(hash); path /= leaf_name; if (!bfs::exists(path)) return nullptr; bfs::ifstream ifs{path}; //fast error checking //ifs.good() boost::archive::binary_iarchive ba(ifs); auto field = make_unique<T>(); ba >> *field; return field; } int get_metadata(Metadata& md, const std::string& path); Loading Loading
fs/src/adafs_ops/metadata_ops.cpp +0 −37 Original line number Diff line number Diff line Loading @@ -5,9 +5,6 @@ #include "metadata_ops.h" #include "dentry_ops.h" #include <boost/archive/binary_iarchive.hpp> #include <boost/archive/binary_oarchive.hpp> // TODO error handling. Each read_metadata_field should check for boolean, i.e., if I/O failed. bool write_all_metadata(const Metadata& md, const unsigned long hash) { write_metadata_field(md.atime(), hash, md_field_map.at(Md_fields::atime)); Loading @@ -24,24 +21,6 @@ bool write_all_metadata(const Metadata& md, const unsigned long hash) { return true; } // TODO error handling. template<typename T> bool write_metadata_field(const T& field, const unsigned long hash, const string& leaf_name) { auto i_path = bfs::path(ADAFS_DATA->inode_path); i_path /= to_string(hash); bfs::create_directories(i_path); i_path /= leaf_name; // for some reason auto ofs = bfs::ofstream(file); does not work. That is why I use the old style. // std::basic_ofstream does not encounter this problem bfs::ofstream ofs{i_path}; // write to disk in binary form boost::archive::binary_oarchive ba(ofs); ba << field; return true; } // TODO error handling. Each read_metadata_field should check for nullptr, i.e., if I/O failed. bool read_all_metadata(Metadata& md, const unsigned long hash) { md.atime(*read_metadata_field<time_t>(hash, md_field_map.at(Md_fields::atime))); Loading @@ -58,22 +37,6 @@ bool read_all_metadata(Metadata& md, const unsigned long hash) { } template<typename T> unique_ptr<T> read_metadata_field(const unsigned long hash, const string& leaf_name) { auto path = bfs::path(ADAFS_DATA->inode_path); path /= to_string(hash); path /= leaf_name; if (!bfs::exists(path)) return nullptr; bfs::ifstream ifs{path}; //fast error checking //ifs.good() boost::archive::binary_iarchive ba(ifs); auto field = make_unique<T>(); ba >> *field; return field; } int get_metadata(Metadata& md, const string& path) { return get_metadata(md, bfs::path(path)); } Loading
fs/src/adafs_ops/metadata_ops.h +33 −2 Original line number Diff line number Diff line Loading @@ -10,6 +10,9 @@ using namespace std; #include <boost/archive/binary_iarchive.hpp> #include <boost/archive/binary_oarchive.hpp> // mapping of enum to string to get the file names for metadata enum class Md_fields { atime, mtime, ctime, uid, gid, mode, inode_no, link_count, size, blocks }; Loading @@ -28,13 +31,41 @@ const std::map<Md_fields, std::string> md_field_map = { bool write_all_metadata(const Metadata& md, const unsigned long hash); // TODO error handling. template<typename T> bool write_metadata_field(const T& field, const unsigned long hash, const string& leaf_name); bool write_metadata_field(const T& field, const unsigned long hash, const string& leaf_name) { auto i_path = bfs::path(ADAFS_DATA->inode_path); i_path /= to_string(hash); bfs::create_directories(i_path); i_path /= leaf_name; // for some reason auto ofs = bfs::ofstream(file); does not work. That is why I use the old style. // std::basic_ofstream does not encounter this problem bfs::ofstream ofs{i_path}; // write to disk in binary form boost::archive::binary_oarchive ba(ofs); ba << field; return true; } bool read_all_metadata(Metadata& md, const unsigned long hash); template<typename T> unique_ptr<T> read_metadata_field(const unsigned long hash, const string& leaf_name); unique_ptr<T> read_metadata_field(const unsigned long hash, const string& leaf_name) { auto path = bfs::path(ADAFS_DATA->inode_path); path /= to_string(hash); path /= leaf_name; if (!bfs::exists(path)) return nullptr; bfs::ifstream ifs{path}; //fast error checking //ifs.good() boost::archive::binary_iarchive ba(ifs); auto field = make_unique<T>(); ba >> *field; return field; } int get_metadata(Metadata& md, const std::string& path); Loading