FileBase::FileBase(int data_fd, int meta_fd, const key_type& key_, const id_type& id_, bool check) : m_lock() , m_refcount(1) , m_header() , m_id(id_) , m_data_fd(data_fd) , m_meta_fd(meta_fd) , m_dirty(false) , m_check(check) , m_stream() , m_removed(false) { auto data_stream = std::make_shared<POSIXFileStream>(data_fd); auto meta_stream = std::make_shared<POSIXFileStream>(meta_fd); key_type data_key, meta_key; byte generated_keys[KEY_LENGTH * 3]; hkdf(key_.data(), key_.size(), nullptr, 0, id_.data(), id_.size(), generated_keys, sizeof(generated_keys)); memcpy(data_key.data(), generated_keys, KEY_LENGTH); memcpy(meta_key.data(), generated_keys + KEY_LENGTH, KEY_LENGTH); memcpy(m_key.data(), generated_keys + 2 * KEY_LENGTH, KEY_LENGTH); auto crypt = make_cryptstream_aes_gcm( std::move(data_stream), std::move(meta_stream), data_key, meta_key, id_, check); m_stream = crypt.first; m_header = crypt.second; read_header(); }
/*********************************************************************** * The converter functions **********************************************************************/ convert::function_type convert::get_converter( const id_type &id, const priority_type prio ){ if (not get_table().has_key(id)) throw uhd::key_error( "Cannot find a conversion routine for " + id.to_pp_string()); //find a matching priority priority_type best_prio = -1; for(priority_type prio_i: get_table()[id].keys()){ if (prio_i == prio) { //----------------------------------------------------------------// UHD_LOGGER_DEBUG("CONVERT") << "get_converter: For converter ID: " << id.to_pp_string() << " Using prio: " << prio; ; //----------------------------------------------------------------// return get_table()[id][prio]; } best_prio = std::max(best_prio, prio_i); } //wanted a specific prio, didnt find if (prio != -1) throw uhd::key_error( "Cannot find a conversion routine [with prio] for " + id.to_pp_string()); //----------------------------------------------------------------// UHD_LOGGER_DEBUG("CONVERT") << "get_converter: For converter ID: " << id.to_pp_string() << " Using prio: " << best_prio; //----------------------------------------------------------------// //otherwise, return best prio return get_table()[id][best_prio]; }
bool SimpleDirectory::get_entry(const std::string& name, id_type& id, int& type) { auto it = m_table.find(name); if (it == m_table.end()) return false; memcpy(id.data(), it->second.first.data(), id.size()); type = it->second.second; return true; }
void split( id_type const& from , id_type const& target , boost::uint16_t old_credit ) { cout << "[" << find_here() << "/" << target << "]: " << old_credit << ", " << get_credit(target) << ", " << get_management_type_name(target.get_management_type()) << "\n" << flush; // If we have more credits than the sender, then we're done. if (old_credit < get_credit(target)) return; id_type const here = find_here(); if (get_locality_id_from_id(from) == get_locality_id_from_id(here)) throw std::logic_error("infinite recursion detected, split was " "invoked locally"); // Recursively call split on the sender locality. async<split_action>(from, here, target, get_credit(target)).get(); cout << " after split: " << get_credit(target) << "\n" << flush; }
void SlotModel::putToFront( const id_type<LayerModel>& layerId) { if(!layerId.val()) return; if(layerId != m_frontLayerModelId) { m_frontLayerModelId = layerId; emit layerModelPutToFront(layerId); } }
void AbstractConstraintViewModel::showRack(const id_type<RackModel>& rackId) { if(rackId.val().is_initialized()) { m_shownRack = rackId; emit rackShown(m_shownRack); } else { hideRack(); } }
/*********************************************************************** * The registry functions **********************************************************************/ void shd::convert::register_converter( const id_type &id, const function_type &fcn, const priority_type prio ){ //get a reference to the function table fcn_table_type &table = get_table(); //register the function if higher priority if (not table.has_key(id) or table[id].prio < prio){ table[id].fcn = fcn; table[id].prio = prio; } //----------------------------------------------------------------// SHD_LOGV(always) << "register_converter: " << id.to_pp_string() << std::endl << " prio: " << prio << std::endl << std::endl ; //----------------------------------------------------------------// }
/////////////////////////////////////////////////////////////////////////////// // Helper functions. inline boost::uint32_t get_credit(id_type const& id) { return get_credit_from_gid(id.get_gid()); }
#include <errno.h> #include <vector> #include <algorithm> #include <set> #include <fcntl.h> #include <unistd.h> TEST_CASE("File table") { using namespace securefs; char dir_template[] = "/tmp/securefs_file_table.XXXXXXX"; mkdtemp(dir_template); key_type master_key; id_type null_id, file_id; memset(master_key.data(), 0xFF, master_key.size()); memset(null_id.data(), 0, null_id.size()); memset(file_id.data(), 0xEE, file_id.size()); const char* xattr_name = "com.apple.FinderInfo..."; const securefs::PODArray<char, 32> xattr_value(0x11); { int tmp_fd = ::open(dir_template, O_RDONLY); REQUIRE(tmp_fd >= 0); FileTable table(tmp_fd, master_key, 0); auto dir = dynamic_cast<Directory*>(table.create_as(null_id, FileBase::DIRECTORY)); dir->add_entry(".", null_id, FileBase::DIRECTORY); dir->add_entry("..", null_id, FileBase::DIRECTORY); dir->add_entry("hello", file_id, FileBase::REGULAR_FILE); try
bool operator == (unsigned long lhs, id_type rhs) { return lhs == rhs.get_id(); }
/////////////////////////////////////////////////////////////////////////////// // helper functions inline boost::int64_t get_credit(id_type const& id) { return hpx::naming::detail::get_credit_from_gid(id.get_gid()); }
/// Checks if item with id exists inline bool exists(const id_type& _id) const { return map_type::count(_id) != 0 && _id.valid(); }
std::size_t hash_value(const id_type<model>& id) { Q_ASSERT(bool(id)); return *id.val(); }
/*********************************************************************** * The converter functions **********************************************************************/ convert::function_type convert::get_converter(const id_type &id){ if (get_table().has_key(id)) return get_table()[id].fcn; throw shd::key_error("Cannot find a conversion routine for " + id.to_pp_string()); }