/*----------------------------------------------------------------------------+ | Function : WriteDetailStackToDB | | Description : Push the JNL_DETAIL stack onto the database using whatever method | of insertion has been chosen via the BLK_SWITCH system parameter | | Input : stk_ptr Pointer to detail stack | | Output : None | | Return : SUCCESS or FAILURE +----------------------------------------------------------------------------*/ int WriteDetailStackToDB (JNL_DETAIL_STACK *stk_ptr) { char *name = "WriteDetailStackToDB"; int rtv = SUCCESS; /*----------------------------------------------------------------------------+ | If no records, no work to do! +----------------------------------------------------------------------------*/ if (stk_ptr == NULL || stk_ptr->curr_pos == 0) return rtv; /*----------------------------------------------------------------------------+ | Push detail stack using appropriate method +----------------------------------------------------------------------------*/ switch (stk_ptr->method) { case JNL_BLK_BLK_CPY: tracef (name, "Writing %d JNL_DETAIL rows with Sybase bulk copy.", stk_ptr->curr_pos); if (BulkCopyRowInsertToDB (stk_ptr) == SUCCESS) WriteLogMessage (stk_ptr->ctrl_fd, stk_ptr->proc_id, __FILE__, __LINE__, JNL_BCP_SUCCESS, stk_ptr->curr_pos, NULL, "JNL_DETAIL", NULL, JNL_FORMAT_INT_CHAR); else rtv = FAILURE; break; case JNL_BLK_STK_INS: tracef (name, "Writing %d JNL_DETAIL with stacked inserts", stk_ptr->curr_pos); if (StackRowInsertToDB (stk_ptr) == SUCCESS) WriteLogMessage (stk_ptr->ctrl_fd, stk_ptr->proc_id, __FILE__, __LINE__, JNL_STK_SUCCESS, stk_ptr->curr_pos, NULL, "JNL_DETAIL", NULL, JNL_FORMAT_INT_CHAR); else rtv = FAILURE; break; case JNL_BLK_ARY_INS: tracef (name, "Writing %d JNL_DETAIL rows with Oracle array insert", stk_ptr->curr_pos); if (ArrayRowInsertToDB (stk_ptr) == SUCCESS) WriteLogMessage (stk_ptr->ctrl_fd, stk_ptr->proc_id, __FILE__, __LINE__, JNL_ARY_SUCCESS, stk_ptr->curr_pos, NULL, "JNL_DETAIL", NULL, JNL_FORMAT_INT_CHAR); else rtv = FAILURE; break; case JNL_BLK_SNG_INS: default: tracef (name, "Writing %d JNL_DETAIL rows with single row inserts", stk_ptr->curr_pos); if (SingleRowInsertToDB (stk_ptr) == SUCCESS) WriteLogMessage (stk_ptr->ctrl_fd, stk_ptr->proc_id, __FILE__, __LINE__, JNL_SGL_SUCCESS, stk_ptr->curr_pos, NULL, "JNL_DETAIL", NULL, JNL_FORMAT_INT_CHAR); else rtv = FAILURE; break; } stk_ptr->curr_pos = 0; return rtv; }
/*----------------------------------------------------------------------------+ | Function : StackRowInsertToDB | | Description : Push JNL_DETAIL stack to the database using 'stacked insert'. | Builds the stack into a single SQL statement in the Arbor SQL buffer | before executing the group of insert statements in one go on the DB | server. | | NOTE: Due to the size limitations on the SQL buffer, this method cannot | be used for large BATCH_SIZE values. | | Input : stk_ptr Pointer to detail stack | | Output : None | | Return : SUCCESS / FAILURE +----------------------------------------------------------------------------*/ static int StackRowInsertToDB (JNL_DETAIL_STACK *stk_ptr) { char *name = "StackRowInsertToDB"; int i; if (arb_begin_tran (stk_ptr->dbp, arb_get_process_id()) != SUCCESS) { WriteLogMessage (stk_ptr->ctrl_fd, stk_ptr->proc_id, __FILE__, __LINE__, JNL_DB_TRANS_ERROR, NULL, NULL, "JNL_DETAIL", "jnl_insert_jnl_detail", JNL_FORMAT_CHAR_CHAR); return FAILURE; } /*----------------------------------------------------------------------------+ | Fill execute buffer with rows on the stack - defer execution +----------------------------------------------------------------------------*/ for (i = 0; i < stk_ptr->curr_pos; i++) { if (InsertJNL_DETAIL (stk_ptr->dbp, &stk_ptr->stk_ptr[i], SQL_DEFER_EXECUTE) != SUCCESS) { arb_rollback_tran (stk_ptr->dbp, arb_get_process_id()); WriteLogMessage (stk_ptr->ctrl_fd, stk_ptr->proc_id, __FILE__, __LINE__, JNL_DB_WRITE_ERROR, NULL, NULL, "JNL_DETAIL", "jnl_insert_jnl_detail", JNL_FORMAT_CHAR_CHAR); return FAILURE; } } /*----------------------------------------------------------------------------+ | Call to arb_next_row executes the SQL in the buffer. No rows are returned as | this is an INSERT. +----------------------------------------------------------------------------*/ while (arb_next_row (stk_ptr->dbp) == ARB_MORE_DATA) {} arb_clear_proc_io (&jnl_insert_jnl_detail_proc); if (arb_query_status (stk_ptr->dbp) == FAILURE) { arb_rollback_tran (stk_ptr->dbp, arb_get_process_id()); WriteLogMessage (stk_ptr->ctrl_fd, stk_ptr->proc_id, __FILE__, __LINE__, JNL_DB_WRITE_ERROR, NULL, NULL, "JNL_DETAIL", "jnl_insert_jnl_detail", JNL_FORMAT_CHAR_CHAR); return FAILURE; } if (arb_commit_tran (stk_ptr->dbp) != SUCCESS) { WriteLogMessage (stk_ptr->ctrl_fd, stk_ptr->proc_id, __FILE__, __LINE__, JNL_BCP_SUCCESS, NULL, NULL, "COMMIT", "jnl_insert_jnl_detail", JNL_FORMAT_CHAR_CHAR); return FAILURE; } return SUCCESS; }
/*----------------------------------------------------------------------------+ | Function : NewDetailStack | | Description : Allocate a buffer for storing JNL_DETAIL rows. This is used to | hold rows prior to batch inserting them into the database using | Oracle array inserts or Sybase BCP. | | NOTE: The ctrl_fd is the pipe on which log information will be sent. | If it is left NULL it is assumed that this is being called in | the parent process and log entries can be written directly. | | Input : dbp Database connection which is used for writing DETAIL rows | method Insertion method to use | bsize Batch size to use for stack / DB buffer | ctrl_fd Control pipe handle (NULL if not used) | proc_id Process id for process using these routines | | Output : None | | Return : Pointer to detail stack, NULL if failure +----------------------------------------------------------------------------*/ JNL_DETAIL_STACK * NewDetailStack (Arb_connection *dbp, JNL_BLK_METHOD method, int bsize, FILE *ctrl_fd, JNL_PROCESS_ID proc_id) { char *name = "InitialiseDetailStack"; JNL_DETAIL_STACK *stk_ptr = NULL; /*----------------------------------------------------------------------------+ | Some error checking... +----------------------------------------------------------------------------*/ if (bsize <= 0 || dbp == NULL) { tracef (name, "Invalid batch size (%d) or NULL dbp pointer passed", bsize); return NULL; } if (method <= JNL_BLK_NULL || method >= JNL_BLK_NUM_METHODS) { tracef (name, "Invalid value for JNL BLK_SWITCH parameter (%d)", method); return NULL; } /*----------------------------------------------------------------------------+ | Initialise stack and allocate space for the detail rows +----------------------------------------------------------------------------*/ if ((stk_ptr = malloc (sizeof(JNL_DETAIL_STACK))) == NULL) { WriteLogMessage (ctrl_fd, proc_id, __FILE__, __LINE__, JNL_MEM_ALLOC, sizeof(JNL_DETAIL_STACK), NULL, "JNL_DETAIL_STACK Struct", NULL, JNL_FORMAT_INT_CHAR); return NULL; } stk_ptr->stk_ptr = (JNL_DETAIL *)calloc (bsize, sizeof(JNL_DETAIL)); if (stk_ptr->stk_ptr == NULL) { free (stk_ptr); WriteLogMessage (ctrl_fd, proc_id, __FILE__, __LINE__, JNL_MEM_ALLOC, bsize*sizeof(JNL_DETAIL), NULL, "JNL_DETAIL Stack", NULL, JNL_FORMAT_INT_CHAR); return NULL; } stk_ptr->ctrl_fd = ctrl_fd; stk_ptr->proc_id = proc_id; stk_ptr->batch_size = bsize; stk_ptr->total_jd = 0; /*DENqa71320, initialized to 0*/ stk_ptr->dbp = dbp; stk_ptr->curr_pos = 0; stk_ptr->method = method; return stk_ptr; }
BOOL UninstallApplication(INT Index, BOOL bModify) { WCHAR szModify[] = L"ModifyPath"; WCHAR szUninstall[] = L"UninstallString"; WCHAR szPath[MAX_PATH]; WCHAR szAppName[MAX_STR_LEN]; DWORD dwType, dwSize; INT ItemIndex; LVITEM Item; HKEY hKey; PINSTALLED_INFO ItemInfo; if (!IS_INSTALLED_ENUM(SelectedEnumType)) return FALSE; if (Index == -1) { ItemIndex = (INT) SendMessageW(hListView, LVM_GETNEXTITEM, -1, LVNI_FOCUSED); if (ItemIndex == -1) return FALSE; } else { ItemIndex = Index; } ListView_GetItemText(hListView, ItemIndex, 0, szAppName, sizeof(szAppName) / sizeof(WCHAR)); WriteLogMessage(EVENTLOG_SUCCESS, MSG_SUCCESS_REMOVE, szAppName); ZeroMemory(&Item, sizeof(LVITEM)); Item.mask = LVIF_PARAM; Item.iItem = ItemIndex; if (!ListView_GetItem(hListView, &Item)) return FALSE; ItemInfo = (PINSTALLED_INFO)Item.lParam; hKey = ItemInfo->hSubKey; dwType = REG_SZ; dwSize = MAX_PATH; if (RegQueryValueExW(hKey, bModify ? szModify : szUninstall, NULL, &dwType, (LPBYTE)szPath, &dwSize) != ERROR_SUCCESS) { return FALSE; } return StartProcess(szPath, TRUE); }
/* FunctionName: fnWrite FunctionModifiedTime: 20141019 FunctionPurpose: write memory to buffer */ errorCode CSingleton::fnWrite(void) { MASTER_WAIT ; if(MASTER_IS_READY) { StatusMaster = RAMWrite; if (0 != m_vBufMaster.size()) { if(0 != m_vBufMaster.size()&&err_Success==fnHardProc(&m_vBufMaster[BUFFER_ZERO],COMMON_CMD)) { StatusMaster = Idle; m_bSynLock = READ; m_ucInvalidRetry = 0; m_ucErrorRetry = 0; #if LogComd string Logcontent = "PCI Write {ComdID =" ; Logcontent += TypeConvert <short, string>(m_vBufMaster[BUFFER_ZERO].iCmd); Logcontent += "}" ; Logcontent += "{Data =" ; int itmpi; for(itmpi = 0;itmpi<m_vBufMaster[BUFFER_ZERO].iLength/2;itmpi++) { Logcontent += TypeConvert <short, string>(*((short*)m_vBufMaster[BUFFER_ZERO].pucData + itmpi)); Logcontent += ","; } Logcontent += "}"; LogManage& CurLog=LogManage::GetInit();//获取日志类实例,直到程序结束前手动析构掉 WriteLogMessage(Logcontent ,SMT_WARN,LOG_FDINFO); #endif return err_Success; }else { StatusMaster = Idle; m_ucInvalidRetry++; return err_MS_Memory_Trans_Invalid; } }else { StatusMaster = Idle; return err_PCI_Write_Memory_Invalid; } } else { return err_PCI_Write_Memory_Invalid; } return err_Success; }
BOOL DownloadApplication(INT Index) { if (!IS_AVAILABLE_ENUM(SelectedEnumType)) return FALSE; AppInfo = (PAPPLICATION_INFO) ListViewGetlParam(Index); if (!AppInfo) return FALSE; WriteLogMessage(EVENTLOG_SUCCESS, MSG_SUCCESS_INSTALL, AppInfo->szName); DialogBoxW(hInst, MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG), hMainWnd, DownloadDlgProc); return TRUE; }
// Parses a string of the form "source_planet destination_planet num_ships" // and calls state.ExecuteOrder. If that fails, the player is dropped. bool Game::ExecuteOrder(int playerID, const std::string& order) { std::vector<std::string> tokens = Tokenize(order, " "); if (tokens.size() != 3) return -1; int sourcePlanet = atoi(tokens[0].c_str()); int destinationPlanet = atoi(tokens[1].c_str()); int numShips = atoi(tokens[2].c_str()); if(!state.ExecuteOrder(desc, playerID, sourcePlanet, destinationPlanet, numShips)) { WriteLogMessage("Dropping player " + to_string(playerID) + ". source.Owner() = " + to_string(state.planets[sourcePlanet].owner) + ", playerID = " + to_string(playerID) + ", numShips = " + to_string(numShips) + ", source.NumShips() = " + to_string(state.planets[sourcePlanet].numShips)); std::cerr << "Dropping player " << playerID << " because of invalid order: " << order << std::endl; state.DropPlayer(playerID); return false; } return true; }
/*----------------------------------------------------------------------------+ | Function : SingleRowInsertToDB | | Description : Insert the JNL_DETAIL stack into the database using a single | row at a time insert through a stored procedure. | | Input : stk_ptr Pointer to detail stack | | Output : None | | Return : SUCCESS / FAILURE +----------------------------------------------------------------------------*/ static int SingleRowInsertToDB (JNL_DETAIL_STACK *stk_ptr) { char *name = "SingleRowInsertToDB"; int i; for (i = 0; i < stk_ptr->curr_pos; i++) { InsertJNL_DETAIL (stk_ptr->dbp, &stk_ptr->stk_ptr[i], SQL_EXECUTE_NOW); arb_clear_proc_io (&jnl_insert_jnl_detail_proc); if (arb_query_status (stk_ptr->dbp) != SUCCESS) { tracef (name, "Failed writing row %d to JNL_DETAIL", i); WriteLogMessage (stk_ptr->ctrl_fd, stk_ptr->proc_id, __FILE__, __LINE__, JNL_DB_WRITE_ERROR, NULL, NULL, "JNL_DETAIL", "jnl_insert_jnl_detail", JNL_FORMAT_CHAR_CHAR); return FAILURE; } } return SUCCESS; }
/*----------------------------------------------------------------------------+ | Function : ArrayRowInsertToDB | | Description : Copy JNL_DETAIL stack to database using Oracle array insert. | | Input : stk_ptr Pointer to detail stack | | Output : None | | Return : SUCCESS / FAILURE +----------------------------------------------------------------------------*/ static int ArrayRowInsertToDB (JNL_DETAIL_STACK *stk_ptr) { arb_setup_proc_exec_array (stk_ptr->dbp, &jnl_insert_jnl_detail_proc, sizeof(JNL_DETAIL), stk_ptr->curr_pos, "id_type", &stk_ptr->stk_ptr[0].key.id_type, ARG_NOT_NULL, "id_value", &stk_ptr->stk_ptr[0].key.id_value, ARG_NOT_NULL, "id_type2", &stk_ptr->stk_ptr[0].key.id_type2, ARG_NULL_IF_EMPTY, "id_value2", &stk_ptr->stk_ptr[0].key.id_value2, ARG_NULL_IF_EMPTY, "use_code", &stk_ptr->stk_ptr[0].key.use_code, ARG_NOT_NULL, "account_no", &stk_ptr->stk_ptr[0].account_no, ARG_NOT_NULL, "subscr_no", &stk_ptr->stk_ptr[0].subscr_no, ARG_NOT_NULL, "subscr_no_resets", &stk_ptr->stk_ptr[0].subscr_no_resets, ARG_NOT_NULL, "bill_ref_no", &stk_ptr->stk_ptr[0].bill_ref_no, ARG_NOT_NULL, "bill_ref_resets", &stk_ptr->stk_ptr[0].bill_ref_resets, ARG_NOT_NULL, "jnl_ref_no", &stk_ptr->stk_ptr[0].jnl_ref_no, ARG_NOT_NULL, "jnl_ref_no_serv", &stk_ptr->stk_ptr[0].jnl_ref_no_serv, ARG_NOT_NULL, "element_id", &stk_ptr->stk_ptr[0].key.element_id, ARG_NULL_IF_EMPTY, "tracking_id", &stk_ptr->stk_ptr[0].tracking_id, ARG_NULL_IF_EMPTY, "tracking_id_serv", &stk_ptr->stk_ptr[0].tracking_id_serv, ARG_NULL_IF_EMPTY, "provider_id", &stk_ptr->stk_ptr[0].key.provider_id, ARG_NULL_IF_EMPTY, "account_category", &stk_ptr->stk_ptr[0].key.account_category, ARG_NOT_NULL, "tracking_dt", &stk_ptr->stk_ptr[0].tracking_dt, ARG_NULL_IF_EMPTY, "effective_dt", &stk_ptr->stk_ptr[0].effective_dt, ARG_NULL_IF_EMPTY, "billed_dt", &stk_ptr->stk_ptr[0].billed_dt, ARG_NULL_IF_EMPTY, "accrued_dt", &stk_ptr->stk_ptr[0].accrued_dt, ARG_NULL_IF_EMPTY, "created_dt", &stk_ptr->stk_ptr[0].created_dt, ARG_NOT_NULL, "posted_dt", &stk_ptr->stk_ptr[0].posted_dt, ARG_NULL_IF_EMPTY, "jurisdiction", &stk_ptr->stk_ptr[0].key.jurisdiction, ARG_NULL_IF_EMPTY, "usage_units", &stk_ptr->stk_ptr[0].usage_units, ARG_NULL_IF_EMPTY, "usage_items", &stk_ptr->stk_ptr[0].usage_items, ARG_NULL_IF_EMPTY, "location_code", &stk_ptr->stk_ptr[0].location_code, ARG_NULL_IF_EMPTY, "location_region", &stk_ptr->stk_ptr[0].location_region, ARG_NULL_IF_EMPTY, "adj_category", &stk_ptr->stk_ptr[0].key.adj_category, ARG_NULL_IF_EMPTY, "reference_code", &stk_ptr->stk_ptr[0].reference_code, ARG_NULL_IF_EMPTY, "jnl_code_id", &stk_ptr->stk_ptr[0].key.jnl_code_id, ARG_NULL_IF_EMPTY, "invoice_amount", &stk_ptr->stk_ptr[0].invoice_amount, ARG_NOT_NULL, "reported_amount", &stk_ptr->stk_ptr[0].reported_amount, ARG_NOT_NULL, "invoice_currency_code", &stk_ptr->stk_ptr[0].invoice_currency_code, ARG_NOT_NULL, "currency_code", &stk_ptr->stk_ptr[0].key.currency_code, ARG_NOT_NULL, "fraud_indicator", &stk_ptr->stk_ptr[0].key.fraud_indicator, ARG_NOT_NULL, "mkt_code", &stk_ptr->stk_ptr[0].key.mkt_code, ARG_NOT_NULL, "rev_rcv_cost_ctr", &stk_ptr->stk_ptr[0].rev_rcv_cost_center, ARG_NOT_NULL, "owning_cost_ctr", &stk_ptr->stk_ptr[0].owning_cost_center, ARG_NOT_NULL, "jnl_end_dt", &stk_ptr->stk_ptr[0].jnl_end_dt, ARG_NOT_NULL, "jnl_subcycle_end_dt", &stk_ptr->stk_ptr[0].jnl_subcycle_end_dt, ARG_NULL_IF_EMPTY, "emf_book_id", &stk_ptr->stk_ptr[0].emf_book_id, ARG_NOT_NULL, "jnl_feed_status", &stk_ptr->stk_ptr[0].jnl_feed_status, ARG_NOT_NULL, "tax_type_code", &stk_ptr->stk_ptr[0].key.tax_type_code, ARG_NOT_NULL, "open_item_id", &stk_ptr->stk_ptr[0].key.open_item_id, ARG_NOT_NULL, NO_MORE_ARGS); arb_clear_proc_io (&jnl_insert_jnl_detail_proc); if (arb_query_status (stk_ptr->dbp) != SUCCESS) { WriteLogMessage (stk_ptr->ctrl_fd, stk_ptr->proc_id, __FILE__, __LINE__, JNL_DB_WRITE_ERROR, NULL, NULL, "JNL_DETAIL", "jnl_insert_jnl_detail", JNL_FORMAT_CHAR_CHAR); return FAILURE; } return SUCCESS; }
static int BulkCopyRowInsertToDB (JNL_DETAIL_STACK *stk_ptr) { int col = 0; int row = 0; Arb_bulkdesc s_sDetailDesc; Bulk_param s_sColDesc; JNL_DETAIL data; int *lens; /*----------------------------------------------------------------------------+ | Initialise the bulk structure +----------------------------------------------------------------------------*/ memset (&s_sDetailDesc, 0, sizeof(Arb_bulkdesc)); if (arb_bulk_init (stk_ptr->dbp, &s_sDetailDesc, "JNL_DETAIL", NUM_DETAIL_COLS) != SUCCESS) { WriteLogMessage (stk_ptr->ctrl_fd, stk_ptr->proc_id, __FILE__, __LINE__, JNL_BCP_INIT_ERROR, NULL, NULL, "JNL_DETAIL", NULL, JNL_FORMAT_CHAR); return FAILURE; } /*----------------------------------------------------------------------------+ | Bind the JNL_DETAIL columns to the appropriate address in the array +----------------------------------------------------------------------------*/ for (col = 1; col <= NUM_DETAIL_COLS; col++) { if (GetJnlDetailDesc (&data, col, &s_sColDesc) != SUCCESS || arb_bulk_bind (&s_sDetailDesc, &s_sColDesc, col) != SUCCESS) { WriteLogMessage (stk_ptr->ctrl_fd, stk_ptr->proc_id, __FILE__, __LINE__, JNL_BCP_INIT_ERROR, NULL, NULL, "JNL_DETAIL", NULL, JNL_FORMAT_CHAR); return FAILURE; } } /*----------------------------------------------------------------------------+ | Constant during BCP +----------------------------------------------------------------------------*/ arch_flag = 0; run_success = 0; /*----------------------------------------------------------------------------+ | Loop through entire stack and send each row to the database +----------------------------------------------------------------------------*/ lens = (int *)s_sDetailDesc.collens; for (row = 0; row < stk_ptr->curr_pos; row++) { data = stk_ptr->stk_ptr[row]; /* These columns must be set to NULL if they are empty, because ** they are given ARG_NULL_IF_EMPTY arg flag in single row insert, ** we should keep consistant with it --DENqa25338 ** Note: subscr_no_resets should not be set to NULL if subscr_no ** is not NULL, the same with bill_ref_resets. */ lens[5] = data.account_no == 0 ? 0 : sizeof (data.account_no); lens[6] = data.subscr_no == 0 ? 0 : sizeof (data.subscr_no); lens[7] = data.subscr_no == 0 ? 0 : sizeof (data.subscr_no_resets); lens[8] = data.bill_ref_no == 0 ? 0 : sizeof (data.bill_ref_no); lens[9] = data.bill_ref_no == 0 ? 0 : sizeof (data.bill_ref_resets); lens[13] = data.tracking_id == 0 ? 0 : sizeof (data.tracking_id); lens[14] = data.tracking_id_serv == 0 ? 0 : sizeof (data.tracking_id_serv); lens[17] = Arbdate_is_null (&data.tracking_dt) ? 0 : 8; lens[18] = Arbdate_is_null (&data.effective_dt) ? 0 : 8; lens[19] = Arbdate_is_null (&data.billed_dt) ? 0 : 8; lens[20] = Arbdate_is_null (&data.accrued_dt) ? 0 : 8; lens[22] = Arbdate_is_null (&data.posted_dt) ? 0 : 8; lens[26] = strlen(data.location_code) == 0 ? 0:sizeof(data.location_code); lens[27] = strlen(data.location_region) == 0? 0:sizeof(data.location_region); lens[29] = strlen(data.reference_code) == 0? 0:sizeof(data.reference_code); lens[42] = Arbdate_is_null (&data.jnl_subcycle_end_dt) ? 0 : 8; if (arb_bulk_send (&s_sDetailDesc) != SUCCESS) { WriteLogMessage (stk_ptr->ctrl_fd, stk_ptr->proc_id, __FILE__, __LINE__, JNL_BCP_INIT_ERROR, NULL, NULL, "JNL_DETAIL", NULL, JNL_FORMAT_CHAR); return FAILURE; } } /*----------------------------------------------------------------------------+ | All done so commit the BCP 'batch' and drop the bulk descriptor +----------------------------------------------------------------------------*/ if (arb_bulk_done (&s_sDetailDesc) != SUCCESS) { WriteLogMessage (stk_ptr->ctrl_fd, stk_ptr->proc_id, __FILE__, __LINE__, JNL_BCP_INIT_ERROR, NULL, NULL, "JNL_DETAIL", NULL, JNL_FORMAT_CHAR); return FAILURE; } if (arb_bulk_drop (&s_sDetailDesc) != SUCCESS) { WriteLogMessage (stk_ptr->ctrl_fd, stk_ptr->proc_id, __FILE__, __LINE__, JNL_BCP_INIT_ERROR, NULL, NULL, "JNL_DETAIL", NULL, JNL_FORMAT_CHAR); return FAILURE; } return SUCCESS; }
VOID InitProg(INT iArgc, PSZ rgArgv[]) { APIRET rc; BYTE szTranslate[256]; INT iArg; ULONG ulLVB; USHORT uscbLVB; ULONG ulDataSize; ULONG ulParmSize; BOOL fSetParms = FALSE; ULONG ulParm; memset(szTranslate, 0, sizeof szTranslate); /* Determine if we run in the foreground */ rc = VioGetBuf(&ulLVB, &uscbLVB, (HVIO)0); if (rc) fForeGround = FALSE; else fForeGround = TRUE; if (fForeGround) printf("FAT32 cache helper version %s.\n", FAT32_VERSION); else WriteLogMessage("FAT32 task detached"); rc = DosGetNamedSharedMem((PVOID *)&pOptions, SHAREMEM, PAG_READ|PAG_WRITE); if (!rc) { fActive = TRUE; WriteLogMessage("Shared memory found!"); } else { rc = DosAllocSharedMem((PVOID *)&pOptions, SHAREMEM, sizeof (LWOPTS), PAG_COMMIT|PAG_READ|PAG_WRITE); if (rc) DosExit(EXIT_PROCESS, 1); memset(pOptions, 0, sizeof pOptions); pOptions->bLWPrio = PRTYC_IDLETIME; WriteLogMessage("Shared memory allocated!"); } ulDataSize = sizeof f32Parms; rc = DosFSCtl( (PVOID)&f32Parms, ulDataSize, &ulDataSize, NULL, 0, &ulParmSize, FAT32_GETPARMS, "FAT32", -1, FSCTL_FSDNAME); if (rc) { printf("DosFSCtl, FAT32_GETPARMS failed, rc = %d\n", rc); DosExit(EXIT_PROCESS, 1); } if (strcmp(f32Parms.szVersion, FAT32_VERSION)) { printf("ERROR: FAT32 version (%s) differs from CACHEF32 version (%s)\n", f32Parms.szVersion, FAT32_VERSION); DosExit(EXIT_PROCESS, 1); } for (iArg = 1; iArg < iArgc; iArg++) { strupr(rgArgv[iArg]); if (rgArgv[iArg][0] == '/' || rgArgv[iArg][0] == '-') { switch (rgArgv[iArg][1]) { case '?' : printf("USAGE: CACHEF32 [options]\n"); printf("/Q (Quit)\n"); printf("/N do NOT load lazy write deamon.\n"); printf("/D:diskidle in millisecs.\n"); printf("/B:bufferidle in millisecs.\n"); printf("/M:maxage in millisecs.\n"); printf("/R:d:,n sets read ahead sector count for drive d: to n.\n"); printf("/FS use short file names internally.\n"); printf("/FL use long file names internally.\n"); printf("/L:on|off set lazy writing on or off.\n"); printf("/P:1|2|3|4 Set priority of Lazy writer\n"); DosExit(EXIT_PROCESS, 0); break; case 'P': if (rgArgv[iArg][2] != ':') { printf("Missing : after /P\n"); DosExit(EXIT_PROCESS, 1); } if (rgArgv[iArg][3] < '1' || rgArgv[iArg][3] > '4') { printf("Lazy write priority should be from 1 to 4!\n"); DosExit(EXIT_PROCESS, 1); } pOptions->bLWPrio = rgArgv[iArg][3] - '0'; break; case 'N': fLoadDeamon = FALSE; break; case 'T': printf("The /T option is no longer supported.\n"); printf("Please read the documentation.\n"); break; case 'Q' : if (fActive) { if (pOptions->fTerminate) printf("Terminate request already set!\n"); pOptions->fTerminate = TRUE; printf("Terminating CACHEF32.EXE...\n"); DosExit(EXIT_PROCESS, 0); } printf("/Q is invalid, CACHEF32 is not running!\n"); DosExit(EXIT_PROCESS, 1); break; case 'D': if (rgArgv[iArg][2] != ':') { printf("ERROR: missing : in %s\n", rgArgv[iArg]); DosExit(EXIT_PROCESS, 1); } ulParm = atol(&rgArgv[iArg][3]); if (!ulParm) { printf("ERROR: Invalid value in %s\n", rgArgv[iArg]); DosExit(EXIT_PROCESS, 1); } f32Parms.ulDiskIdle = ulParm / TIME_FACTOR; fSetParms = TRUE; break; case 'B': if (rgArgv[iArg][2] != ':') { printf("ERROR: missing : in %s\n", rgArgv[iArg]); DosExit(EXIT_PROCESS, 1); } ulParm = atol(&rgArgv[iArg][3]); if (!ulParm) { printf("ERROR: Invalid value in %s\n", rgArgv[iArg]); DosExit(EXIT_PROCESS, 1); } f32Parms.ulBufferIdle = ulParm / TIME_FACTOR; fSetParms = TRUE; break; case 'M': if (rgArgv[iArg][2] != ':') { printf("ERROR: missing : in %s\n", rgArgv[iArg]); DosExit(EXIT_PROCESS, 1); } ulParm = atol(&rgArgv[iArg][3]); if (!ulParm) { printf("ERROR: Invalid value in %s\n", rgArgv[iArg]); DosExit(EXIT_PROCESS, 1); } f32Parms.ulMaxAge = ulParm / TIME_FACTOR; fSetParms = TRUE; break; case 'R': if (rgArgv[iArg][2] != ':') { printf("ERROR: missing : in %s\n", rgArgv[iArg]); DosExit(EXIT_PROCESS, 1); } SetRASectors(&rgArgv[iArg][3]); break; case 'F': if (rgArgv[iArg][2] == 'S') f32Parms.fUseShortNames = TRUE; else if (rgArgv[iArg][2] == 'L') f32Parms.fUseShortNames = FALSE; else { printf("ERROR: Unknown option %s\n", rgArgv[iArg]); DosExit(EXIT_PROCESS, 1); } fSetParms = TRUE; break; case 'L': if (!stricmp(&rgArgv[iArg][2], ":ON")) { rc = DosFSCtl(NULL, 0, NULL, NULL, 0, NULL, FAT32_STARTLW, "FAT32", -1, FSCTL_FSDNAME); if (rc) printf("Warning: Lazy writing is already active or cachesize is 0!\n"); } else if (!stricmp(&rgArgv[iArg][2], ":OFF")) { rc = DosFSCtl(NULL, 0, NULL, NULL, 0, NULL, FAT32_STOPLW, "FAT32", -1, FSCTL_FSDNAME); if (rc) printf("Warning: Lazy writing is not active!\n"); } else { printf("ERROR: Unknown option %s\n", rgArgv[iArg]); DosExit(EXIT_PROCESS, 1); } break; default : printf("ERROR: Unknown option %s\n", rgArgv[iArg]); DosExit(EXIT_PROCESS, 1); break; } } } if (LoadTranslateTable()) fSetParms = TRUE; if (fSetParms) { if (f32Parms.ulDiskIdle < f32Parms.ulBufferIdle) { printf("DISKIDLE must be greater than BUFFERIDLE\n"); DosExit(EXIT_PROCESS, 1); } ulParmSize = sizeof f32Parms; rc = DosFSCtl( NULL, 0, &ulDataSize, (PVOID)&f32Parms, ulParmSize, &ulParmSize, FAT32_SETPARMS, "FAT32", -1, FSCTL_FSDNAME); if (rc) { printf("DosFSCtl FAT32_SETPARMS, failed, rc = %d\n", rc); DosExit(EXIT_PROCESS, 1); } } ulDriveMap = GetFAT32Drives(); if (!fActive) { if (!ulDriveMap) { printf("FAT32: No FAT32 partitions found, aborting...\n"); DosExit(EXIT_PROCESS, 1); } } /* Query parms */ if (fActive || !f32Parms.usCacheSize) { if (fActive) { printf("CACHEF32 is already running.\n"); printf("Current priority is %s.\n", rgPriority[pOptions->bLWPrio]); } if (!f32Parms.fLW) printf("LAZY WRITING is NOT active!\n\n"); else { printf("\n"); printf("DISKIDLE : %lu milliseconds.\n", f32Parms.ulDiskIdle * TIME_FACTOR); printf("BUFFERIDLE: %lu milliseconds.\n", f32Parms.ulBufferIdle * TIME_FACTOR); printf("MAXAGE : %lu milliseconds.\n", f32Parms.ulMaxAge * TIME_FACTOR); } printf("\n"); ShowRASectors(); printf("\n"); printf("CACHE has space for %u sectors\n", f32Parms.usCacheSize); printf("CACHE contains %u sectors\n", f32Parms.usCacheUsed); printf("There are %u dirty sectors in cache.\n", f32Parms.usDirtySectors); if (f32Parms.usPendingFlush > 0) printf("%u sectors are in pending flush state.\n", f32Parms.usPendingFlush); printf("The cache hits ratio is %3d%%.\n", f32Parms.ulTotalHits * 100 / f32Parms.ulTotalReads); if (f32Parms.fUseShortNames) { printf("Internally, short names are used.\n"); printf("All files are visible in DOS sessions.\n"); } else { printf("Internally, long names are used.\n"); printf("Files and directories with long names are hidden for DOS.\n"); } printf("FAT32.IFS has currently %u GDT segments allocated.\n", f32Parms.usSegmentsAllocated); } return; }