EC_BOOL chfsnp_mgr_read(CHFSNP_MGR *chfsnp_mgr, const CSTRING *file_path, CHFSNP_FNODE *chfsnp_fnode) { CHFSNP *chfsnp; uint32_t chfsnp_id; uint32_t node_pos; chfsnp = __chfsnp_mgr_get_np(chfsnp_mgr, (uint32_t)cstring_get_len(file_path), cstring_get_str(file_path), &chfsnp_id); if(NULL_PTR == chfsnp) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_read: no np for path %s\n", (char *)cstring_get_str(file_path)); return (EC_FALSE); } node_pos = chfsnp_search_no_lock(chfsnp, (uint32_t)cstring_get_len(file_path), cstring_get_str(file_path)); if(CHFSNPRB_ERR_POS != node_pos) { CHFSNP_ITEM *chfsnp_item; chfsnp_item = chfsnp_fetch(chfsnp, node_pos); return chfsnp_fnode_import(CHFSNP_ITEM_FNODE(chfsnp_item), chfsnp_fnode); } sys_log(LOGSTDOUT, "[DEBUG] chfsnp_mgr_read: search nothing for path '%s'\n", (char *)cstring_get_str(file_path)); return (EC_FALSE); }
EC_BOOL chfsnp_mgr_write(CHFSNP_MGR *chfsnp_mgr, const CSTRING *file_path, const CHFSNP_FNODE *chfsnp_fnode) { CHFSNP *chfsnp; CHFSNP_ITEM *chfsnp_item; uint32_t chfsnp_id; chfsnp = __chfsnp_mgr_get_np(chfsnp_mgr, (uint32_t)cstring_get_len(file_path), cstring_get_str(file_path), &chfsnp_id); if(NULL_PTR == chfsnp) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_write: no np for path %s\n", (char *)cstring_get_str(file_path)); return (EC_FALSE); } chfsnp_item = chfsnp_set(chfsnp, cstring_get_len(file_path), cstring_get_str(file_path)); if(NULL_PTR == chfsnp_item) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_write: set file %s to np %u failed\n", (char *)cstring_get_str(file_path), chfsnp_id); return (EC_FALSE); } if(EC_FALSE == chfsnp_fnode_import(chfsnp_fnode, CHFSNP_ITEM_FNODE(chfsnp_item))) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_write: import fnode to item failed where path %s\n", (char *)cstring_get_str(file_path)); return (EC_FALSE); } sys_log(LOGSTDOUT, "[DEBUG] chfsnp_mgr_write: import fnode to item successfully where path %s\n", (char *)cstring_get_str(file_path)); chfsnp_item_print(LOGSTDOUT, chfsnp_item); return (EC_TRUE); }
EC_BOOL chfsnp_mgr_delete(CHFSNP_MGR *chfsnp_mgr, const CSTRING *path, CVECTOR *chfsnp_fnode_vec) { CHFSNP *chfsnp; uint32_t chfsnp_id; chfsnp = __chfsnp_mgr_get_np(chfsnp_mgr, (uint32_t)cstring_get_len(path), cstring_get_str(path), &chfsnp_id); if(NULL_PTR == chfsnp) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_delete: no np for path %s\n", (char *)cstring_get_str(path)); return (EC_FALSE); } return chfsnp_delete(chfsnp, (uint32_t)cstring_get_len(path), cstring_get_str(path), chfsnp_fnode_vec); }
void chfsnp_mgr_print_db(LOG *log, const CHFSNP_MGR *chfsnp_mgr) { uint32_t chfsnp_home_dir_num; uint32_t chfsnp_home_dir_pos; uint32_t chfsnp_num; uint32_t chfsnp_id; sys_log(log, "chfsnp mgr db root dir : %s\n", (char *)CHFSNP_MGR_DB_ROOT_DIR_STR(chfsnp_mgr)); sys_log(log, "chfsnp model : %u\n", CHFSNP_MGR_NP_MODEL(chfsnp_mgr)); sys_log(log, "chfsnp 1st hash algo id : %u\n", CHFSNP_MGR_NP_1ST_CHASH_ALGO_ID(chfsnp_mgr)); sys_log(log, "chfsnp 2nd hash algo id : %u\n", CHFSNP_MGR_NP_2ND_CHASH_ALGO_ID(chfsnp_mgr)); sys_log(log, "chfsnp item max num : %u\n", CHFSNP_MGR_NP_ITEM_MAX_NUM(chfsnp_mgr)); sys_log(log, "chfsnp max num : %u\n", CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr)); chfsnp_home_dir_num = (uint32_t)cvector_size(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr)); for(chfsnp_home_dir_pos = 0; chfsnp_home_dir_pos < chfsnp_home_dir_num; chfsnp_home_dir_pos ++) { CSTRING *chfsnp_home_dir_cstr; chfsnp_home_dir_cstr = cvector_get_no_lock(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr), chfsnp_home_dir_pos); if(NULL_PTR == chfsnp_home_dir_cstr || EC_TRUE == cstring_is_empty(chfsnp_home_dir_cstr)) { sys_log(log, "home dir %u #: (null)\n", chfsnp_home_dir_pos); } else { sys_log(log, "home dir %u #: %.*s\n", chfsnp_home_dir_pos, cstring_get_len(chfsnp_home_dir_cstr), (char *)cstring_get_str(chfsnp_home_dir_cstr)); } } chfsnp_num = (uint32_t)cvector_size(CHFSNP_MGR_NP_VEC(chfsnp_mgr)); for(chfsnp_id = 0; chfsnp_id < chfsnp_num; chfsnp_id ++) { CHFSNP *chfsnp; chfsnp = CHFSNP_MGR_NP(chfsnp_mgr, chfsnp_id); if(NULL_PTR == chfsnp) { sys_log(log, "np %u #: (null)\n", chfsnp_id); } else { chfsnp_print(log, chfsnp); } } return; }
static uint32_t __chfsnp_mgr_get_np_id_of_path(const CHFSNP_MGR *chfsnp_mgr, const uint32_t path_len, const uint8_t *path) { uint32_t chfsnp_num; uint32_t chfsnp_id; ASSERT(CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr) == cvector_size(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr))); CHFSNP_MGR_NP_HOME_DIR_VEC_LOCK(chfsnp_mgr, LOC_CHFSNPMGR_0023); chfsnp_num = CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr); for(chfsnp_id = 0; chfsnp_id < chfsnp_num; chfsnp_id ++) { CSTRING *chfsnp_home_dir_cstr; uint32_t chfsnp_home_dir_len; uint8_t *chfsnp_home_dir_str; chfsnp_home_dir_cstr = CHFSNP_MGR_NP_HOME_DIR(chfsnp_mgr, chfsnp_id); if(NULL_PTR == chfsnp_home_dir_cstr || EC_TRUE == cstring_is_empty(chfsnp_home_dir_cstr)) { continue; } chfsnp_home_dir_len = (uint32_t)cstring_get_len(chfsnp_home_dir_cstr); chfsnp_home_dir_str = cstring_get_str(chfsnp_home_dir_cstr); sys_log(LOGSTDOUT, "[DEBUG] __chfsnp_mgr_get_np_id_of_path: %.*s vs %s\n", path_len, (char *)path, (char *)cstring_get_str(chfsnp_home_dir_cstr)); sys_log(LOGSTDOUT, "[DEBUG] __chfsnp_mgr_get_np_id_of_path: path_len %u, chfsnp_home_dir_len %u\n", path_len, chfsnp_home_dir_len); if(path_len < chfsnp_home_dir_len) { continue; } /*now path_len >= chfsnp_home_dir_len*/ if(path_len != chfsnp_home_dir_len && '/' != path[ chfsnp_home_dir_len ]) { continue; } if(0 == BCMP(path, chfsnp_home_dir_str, chfsnp_home_dir_len)) { CHFSNP_MGR_NP_HOME_DIR_VEC_UNLOCK(chfsnp_mgr, LOC_CHFSNPMGR_0024); return (chfsnp_id); } } CHFSNP_MGR_NP_HOME_DIR_VEC_UNLOCK(chfsnp_mgr, LOC_CHFSNPMGR_0025); return (CHFSNP_ERR_ID); }
static size_t __ccurl_write_data( void *buffer, size_t size, size_t nmemb, void *userp) { CSTRING *curl_reply_body; size_t seg_size; curl_reply_body = userp; seg_size = size * nmemb; dbg_log(SEC_0030_CCURL, 9)(LOGSTDNULL, "[DEBUG] __ccurl_write_data enter where curl_reply_body %p\n", curl_reply_body); if(NULL_PTR == curl_reply_body) { dbg_log(SEC_0030_CCURL, 0)(LOGSTDOUT, "error:__ccurl_write_data: curl_reply_body is null\n"); return (0); } dbg_log(SEC_0030_CCURL, 9)(LOGSTDNULL, "[DEBUG] __ccurl_write_data: [1] body %p: str %p, capacity %ld, len %ld\n", curl_reply_body, curl_reply_body->str, curl_reply_body->capacity, curl_reply_body->len); if(EC_TRUE == cstring_is_empty(curl_reply_body)) { cstring_expand_to(curl_reply_body, CCURL_BUFF_INIT_SIZE); } dbg_log(SEC_0030_CCURL, 9)(LOGSTDNULL, "[DEBUG] __ccurl_write_data: [2] body %p: str %p, capacity %ld, len %ld\n", curl_reply_body, curl_reply_body->str, curl_reply_body->capacity, curl_reply_body->len); if(EC_FALSE == cstring_append_chars(curl_reply_body, seg_size, buffer)) { dbg_log(SEC_0030_CCURL, 0)(LOGSTDOUT, "error:__ccurl_write_data: append %d bytes to curl_reply_body %p failed\n", seg_size, curl_reply_body); return (0); } dbg_log(SEC_0030_CCURL, 9)(LOGSTDNULL, "[DEBUG] __ccurl_write_data: [3] body %p: str %p, capacity %ld, len %ld\n", curl_reply_body, curl_reply_body->str, curl_reply_body->capacity, curl_reply_body->len); dbg_log(SEC_0030_CCURL, 9)(LOGSTDNULL, "[DEBUG] __ccurl_write_data leave where curl_reply_body %p len = %ld\n", curl_reply_body, cstring_get_len(curl_reply_body)); /* Return the number of bytes received, indicating to curl that all is okay */ return (seg_size); }
/*bind home_dir and name node, i.e., one name node owns unique home dir*/ EC_BOOL chfsnp_mgr_bind(CHFSNP_MGR *chfsnp_mgr, const CSTRING *path, const UINT32 chfsnp_id) { CSTRING *home_dir; CSTRING *home_dir_old; uint32_t home_dir_pos; ASSERT(cvector_size(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr)) == CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr)); if(CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr) <= chfsnp_id) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_bind: max np num %u but chfsnp id %u overflow\n", CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr), chfsnp_id); return (EC_FALSE); } home_dir_pos = __chfsnp_mgr_get_np_id_of_path(chfsnp_mgr, (uint32_t)cstring_get_len(path), cstring_get_str(path)); if(CHFSNP_ERR_ID != home_dir_pos) { home_dir = cvector_get_no_lock(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr), home_dir_pos); sys_log(LOGSTDOUT, "error:chfsnp_mgr_bind: some dir %s already bound to np %u, thus cannot accept binding %s\n", (char *)cstring_get_str(home_dir), home_dir_pos, (char *)cstring_get_str(path)); return (EC_FALSE); } home_dir = cstring_dup(path); if(NULL_PTR == home_dir) { sys_log(LOGSTDOUT, "error:chfsnp_mgr_bind: dup %s failed\n", (char *)cstring_get_str(path)); return (EC_FALSE); } home_dir_old = (CSTRING *)cvector_set(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr), chfsnp_id, (void *)home_dir); if(NULL_PTR != home_dir_old) { cstring_free(home_dir_old); } return (EC_TRUE); }
EC_BOOL chfsnp_mgr_find(CHFSNP_MGR *chfsnp_mgr, const CSTRING *path) { return chfsnp_mgr_search(chfsnp_mgr, (uint32_t)cstring_get_len(path), cstring_get_str(path), NULL_PTR); }