const std::string &lookup_result_t::path() const { if (!m_path) { std::string p; struct dnet_file_info *info = m_entry.file_info(); if (m_eblob_style_path) { p = m_entry.file_path(); p = p.substr(p.find_last_of("/\\") + 1); std::ostringstream oss; oss << '/' << (port() - m_base_port) << '/' << p << ':' << info->offset << ':' << info->size; m_path.reset(oss.str()); } else { char id[2 * DNET_ID_SIZE + 1]; char hex_dir[2 * DNET_ID_SIZE + 1]; dnet_dump_id_len_raw(m_entry.command()->id.id, DNET_ID_SIZE, id); file_backend_get_dir(m_entry.command()->id.id, m_directory_bit_num, hex_dir); std::ostringstream oss; oss << '/' << boost::lexical_cast<std::string>(port() - m_base_port) << '/' << hex_dir << '/' << id; m_path.reset(oss.str()); } } return *m_path; }
static inline void file_backend_setup_file(struct file_backend_root *r, char *file, unsigned int size, const unsigned char *id) { char dir[2*DNET_ID_SIZE+1]; char id_str[2*DNET_ID_SIZE+1]; file_backend_get_dir(id, r->bit_num, dir); snprintf(file, size, "%s/%s", dir, dnet_dump_id_len_raw(id, DNET_ID_SIZE, id_str)); }
static inline uint64_t file_backend_get_dir_bits(const unsigned char *id, int bit_num) { #if 0 uint64_t res = *(uint64_t *)id; bit_num = 64 - bit_num; res <<= bit_num; res >>= bit_num; return res; #else char sub[DNET_ID_SIZE*2+1]; char *res = file_backend_get_dir(id, bit_num, sub); char hex[DNET_ID_SIZE*2 + 1 + 2]; snprintf(hex, sizeof(hex), "0x%s", res); return strtoull(hex, NULL, 16); #endif }