/* Create a new external memory list. */ static int em_list_create(em_list_t *self) { mapped_file_t *mf; em_list_index_hdr_t index_hdr; em_list_values_hdr_t values_hdr; size_t size; char *filename; const char *dirname = self->dirname; /* Compute initial external memory list index size. */ size = EM_LIST_E2S(0); /* Create directory to hold external memory list files. */ if(mk_dir(dirname) != 0) goto _err1; /* Create "index.bin" and write file header. */ filename = path_combine(dirname, "index.bin"); if((mf = mapped_file_create(filename, size)) == NULL) goto _err2; index_hdr.magic = MAGIC; index_hdr.used = 0; index_hdr.capacity = 0; mapped_file_write(mf, &index_hdr, sizeof(em_list_index_hdr_t)); self->index = mf; /* Create "values.bin" and write file header. */ filename = path_combine(dirname, "values.bin"); if((mf = mapped_file_create(filename, size)) == NULL) goto _err3; values_hdr.magic = MAGIC; mapped_file_write(mf, &values_hdr, sizeof(em_list_values_hdr_t)); self->values = mf; return 0; _err3: mapped_file_unlink(self->index); mapped_file_close(self->index); _err2: rm_dir(dirname); _err1: PyErr_SetString(PyExc_RuntimeError, "Cannot open EMList"); return -1; }
static void InitRemoteKVMPath() { char modulePath[MAX_PATH] = {0}; /*if(!app_os_get_module_path(modulePath)) return; sprintf(VNCServerPath, "%s/%s/%s", modulePath, DEF_VNC_FOLDER_NAME, DEF_VNC_SERVER_EXE_NAME);*/ char vncPath[MAX_PATH] = {0}; if(strlen(g_PluginInfo.WorkDir)<=0) return; strcpy(modulePath, g_PluginInfo.WorkDir); path_combine(vncPath, modulePath, DEF_VNC_FOLDER_NAME); path_combine(VNCServerPath, vncPath, DEF_VNC_SERVER_EXE_NAME); path_combine(ConfigFilePath, modulePath, DEF_CONFIG_FILE_NAME); }
const char* vs_filter_links(const char* name) { int i = prj_find_package(name); if (i >= 0) { const char* lang = prj_get_language_for(i); const char* kind = prj_get_config_for(i)->kind; if (matches(kind, "cxxtestgen")) return NULL; // note that "run" matches against the /current/ project, not the link // dependency we've been run for else if (prj_is_kind("run")) { return path_translate(prj_get_target_for(i), "windows"); } else if (matches(lang, "c") || matches(lang, "c++")) { strcpy(g_buffer, prj_get_libdir_for(i)); return path_combine(g_buffer, prj_get_targetname_for(i)); } else return NULL; } else { return name; } }
/* ************************************************************************************** * Function Name: Handler_Initialize * Description: Init any objects or variables of this handler * Input : PLUGIN_INFO *pluginfo * Output: None * Return: handler_success : Success Init Handler * handler_fail : Fail Init Handler * ***************************************************************************************/ int HANDLER_API Handler_Initialize( HANDLER_INFO *pluginfo ) { HANDLER_INFO_EX* tmpinfo = NULL; if(pluginfo == NULL) { return handler_fail; } tmpinfo = (HANDLER_INFO_EX*)pluginfo; if(g_bEnableLog) { g_loghandle = tmpinfo->loghandle; } // 1. Topic of this handler snprintf( tmpinfo->Name, sizeof(tmpinfo->Name), "%s", strPluginName ); tmpinfo->RequestID = iRequestID; tmpinfo->ActionID = iActionID; printf(" >Name: %s\n", strPluginName); // 2. Copy agent info memcpy(&g_PluginInfo, tmpinfo, sizeof(HANDLER_INFO_EX)); g_PluginInfo.agentInfo = tmpinfo->agentInfo; { char mdPath[MAX_PATH] = {0}; app_os_get_module_path(mdPath); path_combine(agentConfigFilePath, mdPath, DEF_CONFIG_FILE_NAME); if(g_bEnableLog) { g_loghandle = tmpinfo->loghandle; } } // 3. Callback function -> Send JSON Data by this callback function g_sendcbf = g_PluginInfo.sendcbf = tmpinfo->sendcbf; g_sendcustcbf = g_PluginInfo.sendcustcbf = tmpinfo->sendcustcbf; g_subscribecustcbf = g_PluginInfo.subscribecustcbf = tmpinfo->subscribecustcbf; g_sendreportcbf = g_PluginInfo.sendreportcbf = tmpinfo->sendreportcbf; g_sendcapabilitycbf =g_PluginInfo.sendcapabilitycbf = tmpinfo->sendcapabilitycbf; g_connectservercbf = g_PluginInfo.connectservercbf = tmpinfo->connectservercbf; g_disconnectcbf = g_PluginInfo.disconnectcbf = tmpinfo->disconnectcbf; LoadServerList(g_PluginInfo.WorkDir, &g_ServerList); if(g_ServerList.serverCount==0) { g_ServerList.server = malloc(sizeof(struct SERVER_INFO)); memset(g_ServerList.server, 0, sizeof(struct SERVER_INFO)); g_ServerList.serverCount = 1; strncpy(g_ServerList.server->sServerIP, tmpinfo->ServerIP, strlen(tmpinfo->ServerIP)+1); g_ServerList.server->iServerPort = tmpinfo->ServerPort; strncpy(g_ServerList.server->sServerAuth, tmpinfo->serverAuth, strlen(tmpinfo->serverAuth)+1); g_ServerList.server->eTLSType = tmpinfo->TLSType; strncpy(g_ServerList.server->sPSK, tmpinfo->PSK, strlen(tmpinfo->PSK)+1); } return handler_success; }
/* Open existing external memory list. */ static int em_list_open_existing(em_list_t *self) { mapped_file_t *mf; em_list_index_hdr_t *index_hdr; em_list_values_hdr_t *values_hdr; size_t pos; char *filename; const char *dirname = self->dirname; /* Open and verify "index.bin". */ filename = path_combine(dirname, "index.bin"); if((mf = mapped_file_open(filename)) == NULL) goto _err1; self->index = mf; index_hdr = mf->address; if(index_hdr->magic != MAGIC) goto _err2; /* Open and verify "values.bin". */ filename = path_combine(dirname, "values.bin"); if((mf = mapped_file_open(filename)) == NULL) goto _err2; self->values = mf; values_hdr = mf->address; pos = mapped_file_get_eof(mf); if(values_hdr->magic != MAGIC || mapped_file_seek(mf, pos, SEEK_SET) != 0) goto _err3; return 0; _err3: mapped_file_close(self->values); _err2: mapped_file_close(self->index); _err1: PyErr_SetString(PyExc_RuntimeError, "Cannot open EMList"); return -1; }
static void InitRemoteKVMPath() { char modulePath[MAX_PATH] = {0}; char vncPath[MAX_PATH] = {0}; if(strlen(g_PluginInfo.WorkDir)<=0) return; strcpy(modulePath, g_PluginInfo.WorkDir); path_combine(vncPath, modulePath, DEF_VNC_FOLDER_NAME); path_combine(VNCIniFilePath, vncPath, DEF_VNC_INI_FILE_NAME); path_combine(VNCServerPath, vncPath, DEF_VNC_SERVER_EXE_NAME); path_combine(VNCChangePwdExePath, vncPath, DEF_VNC_CHANGE_PWD_EXE_NAME); path_combine(ConfigFilePath, modulePath, DEF_CONFIG_FILE_NAME); /*sprintf(VNCIniFilePath, "%s\\%s\\%s", modulePath, DEF_VNC_FOLDER_NAME, DEF_VNC_INI_FILE_NAME); sprintf(VNCServerPath, "%s\\%s\\%s", modulePath, DEF_VNC_FOLDER_NAME, DEF_VNC_SERVER_EXE_NAME); sprintf(VNCChangePwdExePath, "%s\\%s\\%s", modulePath, DEF_VNC_FOLDER_NAME, DEF_VNC_CHANGE_PWD_EXE_NAME);*/ }
bool LoadServerList(char *workDir, struct SERVER_LIST* pServerList) { FILE *fp = NULL; char filepath[MAX_PATH] = {0}; char* buffer = NULL; long lSize = 0; long result = 0; cJSON* pServerListNode = NULL; if(!pServerList) return false; path_combine(filepath, workDir, DEF_SERVER_IP_LIST_FILE);//g_PluginInfo.WorkDir, if(fp=fopen(filepath,"r")) { // obtain file size: fseek (fp , 0 , SEEK_END); lSize = ftell (fp); rewind (fp); // allocate memory to contain the whole file: buffer = (char*) malloc (sizeof(char)*lSize); if (!buffer) { fclose(fp); return false; } // copy the file into the buffer: result = fread (buffer,1,lSize,fp); if (result != lSize) { free(buffer); fclose(fp); return false; } pServerListNode = cJSON_Parse(buffer); if(pServerListNode) { ParseServerList(pServerListNode, pServerList); cJSON_Delete(pServerListNode); } free(buffer); fclose(fp); } return true; }
// 評価関数ファイルを読み込む // benchコマンドなどでOptionsを保存して復元するのでこのときEvalDirが変更されたことになって、 // 評価関数の再読込の必要があるというフラグを立てるため、この関数は2度呼び出されることがある。 void load_eval() { NNUE::Initialize(); #if defined(EVAL_LEARN) if (!Options["SkipLoadingEval"]) #endif { const std::string dir_name = Options["EvalDir"]; const std::string file_name = path_combine(dir_name, NNUE::kFileName); std::ifstream stream(file_name, std::ios::binary); const bool result = NNUE::ReadParameters(stream); ASSERT(result); } }
bool dl_IsExistSAManagerLib(char* path) { bool bRet = false; void * hSAMANAGERDLL = NULL; char file[MAX_PATH] = {0}; path_combine(file, path, DEF_SAMANAGER_LIB_NAME); hSAMANAGERDLL = app_load_library(file); if(hSAMANAGERDLL != NULL) { bRet = true; app_free_library(hSAMANAGERDLL); hSAMANAGERDLL = NULL; } return bRet; }
bool dl_LoadSAManagerLib(char* path, SAManager_Interface * SAManager) { bool bRet = false; void * hSAMANAGERDLL = NULL; char file[MAX_PATH] = {0}; if(!SAManager) return bRet; path_combine(file, path, DEF_SAMANAGER_LIB_NAME); hSAMANAGERDLL = app_load_library(file); if(hSAMANAGERDLL != NULL) { memset(SAManager, 0, sizeof(SAManager_Interface)); SAManager->Handler = hSAMANAGERDLL; dl_GetSAManagerFunction(SAManager); } bRet = true; return bRet; }
const char* vs_filter_links(const char* name) { int i = prj_find_package(name); if (i >= 0) { const char* lang = prj_get_language_for(i); if (matches(lang, "c") || matches(lang, "c++")) { strcpy(g_buffer, prj_get_libdir_for(i)); return path_combine(g_buffer, prj_get_targetname_for(i)); } else return NULL; } else { return name; } }
static int matchfiles(lua_State* L) { int numArgs, i; const char* pkgPath; /* Get the current package path */ lua_getglobal(L, "package"); lua_pushstring(L, "path"); lua_gettable(L, -2); pkgPath = lua_tostring(L, -1); lua_pop(L, 2); /* If path is same as current, I can ignore it */ if (matches(path_getdir(currentScript), pkgPath)) pkgPath = ""; /* Create a table to hold the results */ lua_newtable(L); /* Read and scan for each mask in turn */ numArgs = lua_gettop(L) - 1; for (i = 1; i <= numArgs; ++i) { const char* mask = luaL_checkstring(L, i); const char* maskWithPath = path_combine(pkgPath, mask); io_mask_open(maskWithPath); while(io_mask_getnext()) { if (io_mask_isfile()) { const char* name = io_mask_getname(); if (strlen(pkgPath) > 0) name += strlen(pkgPath) + 1; lua_pushstring(L, name); lua_rawseti(L, -2, luaL_getn(L, -2) + 1); } } io_mask_close(); } return 1; }
static int em_list_resize(em_list_t *self) { size_t capacity, new_capacity, new_size; char *filename; mapped_file_t *mf; em_list_index_hdr_t *index_hdr, *new_index_hdr; /* Get a reference to the current index file header. */ index_hdr = (em_list_index_hdr_t *)self->index->address; /* Compute new capacity and size in bytes and check for overflows. */ capacity = index_hdr->capacity; if(capacity == 0) new_capacity = 1; else new_capacity = capacity << 1; new_size = EM_LIST_E2S(new_capacity); if(new_capacity < capacity || new_size < new_capacity) { PyErr_SetString(PyExc_RuntimeError, "Integer overflow while resizing EMList"); goto _err1; } msgf("EMList: Resizing"); filename = path_combine(self->dirname, "index.bin.1"); if((mf = mapped_file_create(filename, new_size)) == NULL) goto _err1; /* Copy old entries to the new external memory list. */ memcpy(mf->address, self->index->address, EM_LIST_E2S(capacity)); msgf("EMList: Resize successful"); filename = path_combine(self->dirname, "index.bin.0"); if(mapped_file_rename(self->index, filename) != 0) { PyErr_SetString(PyExc_RuntimeError, "Cannot rename old EMList index file"); goto _err2; } filename = path_combine(self->dirname, "index.bin"); if(mapped_file_rename(mf, filename) != 0) { PyErr_SetString(PyExc_RuntimeError, "Cannot rename new EMList index file"); goto _err2; } /* Populate new index file header. */ new_index_hdr = (em_list_index_hdr_t *)mf->address; new_index_hdr->magic = MAGIC; new_index_hdr->used = index_hdr->used; new_index_hdr->capacity = new_capacity; mapped_file_unlink(self->index); mapped_file_close(self->index); self->index = mf; return 0; _err2: mapped_file_unlink(mf); mapped_file_close(mf); _err1: return -1; }
int main(int argc, char *argv[]) { int c; const char *filename, *fmt; BlockDriver *drv; BlockDriverState *bs; char fmt_name[128], size_buf[128], dsize_buf[128]; uint64_t total_sectors; int64_t allocated_size; char backing_filename[1024]; char backing_filename2[1024]; BlockDriverInfo bdi; bdrv_init(); fmt = NULL; for(;;) { c = getopt(argc, argv, "f:h"); if (c == -1) break; switch(c) { case 'h': // help(); break; case 'f': fmt = optarg; break; } } if (optind >= argc) help(); filename = argv[optind++]; bs = bdrv_new(""); if (!bs) error("Not enough memory"); if (fmt) { drv = bdrv_find_format(fmt); if (!drv) error("Unknown file format '%s'", fmt); } else { drv = NULL; } if (bdrv_open2(bs, filename, 0, drv) < 0) { error("Could not open '%s'", filename); } bdrv_get_format(bs, fmt_name, sizeof(fmt_name)); bdrv_get_geometry(bs, &total_sectors); get_human_readable_size(size_buf, sizeof(size_buf), total_sectors * 512); allocated_size = get_allocated_file_size(filename); if (allocated_size < 0) sprintf(dsize_buf, "unavailable"); else get_human_readable_size(dsize_buf, sizeof(dsize_buf), allocated_size); /* if (bdrv_is_encrypted(bs)) fprintf(stderr, "encrypted: yes\n"); if (bdrv_get_info(bs, &bdi) >= 0) { if (bdi.cluster_size != 0) fprintf(stderr, "cluster_size: %d\n", bdi.cluster_size); } */ bdrv_get_info(bs, &bdi); bdrv_get_backing_filename(bs, backing_filename, sizeof(backing_filename)); if (backing_filename[0] != '\0') { path_combine(backing_filename2, sizeof(backing_filename2), filename, backing_filename); /* fprintf(stderr, "backing file: %s (actual path: %s)\n", backing_filename, backing_filename2); */ } fprintf(stdout, "{'filename' : '%s'," " 'format' : '%s'," " 'image_disk_size' : '%s'," " 'allocated_size' : '%s'," " 'total_sectors' : '%"PRId64"'," " 'backing_file' : '%s',}", filename, fmt_name, size_buf, dsize_buf, total_sectors, backing_filename); dump_snapshots(bs); bdrv_delete(bs); return 0; }
/* Resize external memory dictionary. */ static int em_dict_resize(em_dict_t *self) { em_dict_index_hdr_t *index_hdr, *new_index_hdr; em_dict_index_ent_t ent, new_ent; size_t mask, new_mask, num_ents, new_num_ents, size, new_size, i, j, perturb; mapped_file_t *mf; char *filename; int ret = -1; /* Store current values for later use. */ index_hdr = self->index->address; mask = index_hdr->mask; num_ents = mask + 1; size = self->index->size; /* Compute new values and do some sanity checking. */ new_num_ents = num_ents << 1; new_size = EM_DICT_E2S(new_num_ents); if(new_num_ents < num_ents || new_size < size) goto _err; msgf("EMDict: Resizing"); filename = path_combine(self->dirname, "index.bin.1"); if((mf = mapped_file_create(filename, new_size)) == NULL) goto _err; new_mask = new_num_ents - 1; new_index_hdr = mf->address; new_index_hdr->magic = MAGIC; new_index_hdr->used = 0; new_index_hdr->mask = new_mask; msgf("EMDict: Rehashing"); /* Rehash all dictionary entries in the new index file. */ for(i = 0; i < num_ents; i++) { em_dict_get_entry(self->index, &ent, i); if(!em_dict_entry_is_free(&ent)) { /* Locate empty slot in new index file. */ j = ent.hash & new_mask; em_dict_get_entry(mf, &new_ent, j); perturb = ent.hash; while(em_dict_entry_is_free(&new_ent) == 0) { j = ((j << 2) + j + perturb + 1) & new_mask; perturb >>= PERTURB_SHIFT; em_dict_get_entry(mf, &new_ent, j); } /* Key and value offsets in "keys.bin" and "values.bin" are the same. * We just rehash the index entry in a (possibly) different position * in the new "index.bin". */ em_dict_set_entry(mf, &ent, j); new_index_hdr->used += 1; } }
* We just rehash the index entry in a (possibly) different position * in the new "index.bin". */ em_dict_set_entry(mf, &ent, j); new_index_hdr->used += 1; } } msgf("EMDict: Resize successful"); /* Move the new mapped file over the old one. When the file is closed below, * the kernel will remove it from our filesystem because the link count will * reach 0. This works on Microsoft Windows too, but with a slightly * different technique (see `mapped_file_unlink()' for more information). */ filename = path_combine(self->dirname, "index.bin.0"); if(mapped_file_rename(self->index, filename) != 0) goto _err; filename = path_combine(self->dirname, "index.bin"); if(mapped_file_rename(mf, filename) != 0) goto _err; mapped_file_unlink(self->index); mapped_file_close(self->index); self->index = mf; ret = 0; _err:
File_List file_list(std::string path) { File_List files; auto name_max = pathconf(path.c_str(), _PC_NAME_MAX); if (name_max == -1) name_max = 255; auto len = offsetof(struct dirent, d_name) + name_max + 1; std::vector<uint8_t> entry_buffer(len, '\0'); auto entry = reinterpret_cast<struct dirent*>(entry_buffer.data()); struct dirent* result; std::stack<std::string> directories; directories.push(path); while (!directories.empty()) { path = directories.top(); directories.pop(); auto dir = opendir(path.c_str()); if (dir == nullptr) throw os_error::make_os_error(errno); do { readdir_r(dir, entry, &result); if (result == nullptr) break; // skip 'hidden' files, which includes the pseudo dirs . and .. if (result->d_name[0] == '.') continue; auto new_item = path_get_full_name(path_combine(path, result->d_name)); if (result->d_type == DT_DIR) { // add this directory to our stack directories.push(new_item); } else if (result->d_type == DT_REG) { // add this file to our list of results files.push_back(new_item); } else if (result->d_type == DT_LNK) { // is it a link to a file or a directory? struct stat stat_buf; if (stat(new_item.c_str(), &stat_buf) == -1) throw os_error::make_os_error(errno, new_item); if (S_ISDIR(stat_buf.st_mode)) { directories.push(new_item); } else if (S_ISREG(stat_buf.st_mode)) { files.push_back(new_item); } } } while (true); closedir(dir); } return files; }
static int vmdk_parse_extents(const char *desc, BlockDriverState *bs, const char *desc_file_path) { int ret; char access[11]; char type[11]; char fname[512]; const char *p = desc; int64_t sectors = 0; int64_t flat_offset; char extent_path[PATH_MAX]; BlockDriverState *extent_file; while (*p) { /* parse extent line: * RW [size in sectors] FLAT "file-name.vmdk" OFFSET * or * RW [size in sectors] SPARSE "file-name.vmdk" */ flat_offset = -1; ret = sscanf(p, "%10s %" SCNd64 " %10s %511s %" SCNd64, access, §ors, type, fname, &flat_offset); if (ret < 4 || strcmp(access, "RW")) { goto next_line; } else if (!strcmp(type, "FLAT")) { if (ret != 5 || flat_offset < 0) { return -EINVAL; } } else if (ret != 4) { return -EINVAL; } /* trim the quotation marks around */ if (fname[0] == '"') { memmove(fname, fname + 1, strlen(fname)); if (strlen(fname) <= 1 || fname[strlen(fname) - 1] != '"') { return -EINVAL; } fname[strlen(fname) - 1] = '\0'; } if (sectors <= 0 || (strcmp(type, "FLAT") && strcmp(type, "SPARSE")) || (strcmp(access, "RW"))) { goto next_line; } path_combine(extent_path, sizeof(extent_path), desc_file_path, fname); ret = bdrv_file_open(&extent_file, extent_path, bs->open_flags); if (ret) { return ret; } /* save to extents array */ if (!strcmp(type, "FLAT")) { /* FLAT extent */ VmdkExtent *extent; extent = vmdk_add_extent(bs, extent_file, true, sectors, 0, 0, 0, 0, sectors); extent->flat_start_offset = flat_offset << 9; } else if (!strcmp(type, "SPARSE")) { /* SPARSE extent */ ret = vmdk_open_sparse(bs, extent_file, bs->open_flags); if (ret) { bdrv_delete(extent_file); return ret; } } else { fprintf(stderr, "VMDK: Not supported extent type \"%s\""".\n", type); return -ENOTSUP; } next_line: /* move to next line */ while (*p && *p != '\n') { p++; } p++; } return 0; }