/* // // ISAM - build file cluster // */ int tcob_build_vbidx(struct file_desc *f) { int r=0, i=0, ifilehandle, iresult, imode; tcb_fileio_vbidx_handle *h; struct keydesc *wkeydesc; #ifdef DEBUG_FILEISAM_RTS8 fprintf(stderr, "debug : tcob_build_vbidx 010.040 : f->filename=%s, f->flags.file_isvariable=%d;\n", f->filename, f->flags.file_isvariable); #endif h = (tcb_fileio_vbidx_handle *)f->dbp; if (f->flags.file_isvariable == 1) { imode = ISINOUT+ISVARLEN+ISEXCLLOCK; isreclen = f->reclen_min; } else { imode = ISINOUT+ISFIXLEN+ISEXCLLOCK; } wkeydesc = h->skeydesc; /* Define ISAM file - define primary key */ ifilehandle = isbuild(f->filename, f->reclen, wkeydesc, imode); #ifdef DEBUG_FILEISAM_RTS8 fprintf(stderr, "debug : tcob_build_vbidx 010.060 : f->filename=%s, f->reclen=%d, ifilehandle=%d;\n", f->filename, f->reclen, ifilehandle); #endif if (ifilehandle < 0) { r = tcob_eisam2ecob(0); return (r); } /* Define ISAM file - define secondary keys */ for (i=1; i < f->nkeys; i++) { wkeydesc = h->skeydesc + i; iresult = isaddindex(ifilehandle, wkeydesc); if (iresult != 0) { r = tcob_eisam2ecob(0); iresult = isclose(ifilehandle); iserase (f->filename); return (r); } } iresult = isclose(ifilehandle); if (iresult != 0) { r = tcob_eisam2ecob(0); iserase (f->filename); return (r); } h->ifilehandle = ifilehandle; #ifdef DEBUG_FILEISAM_RTS8 fprintf(stderr, "debug : tcob_build_vbidx 010.080 : r=%d;\n", r); #endif RETURN_STATUS(r); }
int idxclose (unit *ftnunit, flag idxerr) { if (isclose (ftnunit->isfd) < SUCCESS) ierr (idxerr, iserrno, "indexed close"); if (ftnunit->ufnm) { if (ftnunit->udisp & DELETE) if (iserase (ftnunit->ufnm) < SUCCESS) ierr (idxerr, iserrno, "indexed close"); free (ftnunit->ufnm); ftnunit->ufnm = NULL; } /* The following fixes bug #231656. The pointers involved are initialized to zero (both when originally allocated in f_init() and when reallocated in map_luno()). So, if non-zero, the buffers must have been allocated, and we should free them. */ if (ftnunit->f77syl) { free(ftnunit->f77syl); ftnunit->f77syl = NULL; } if (ftnunit->f77fio_buf) { free(ftnunit->f77fio_buf); ftnunit->f77fio_buf = NULL; ftnunit->f77fio_size = 0; } if (ftnunit->ukeys) { free(ftnunit->ukeys); ftnunit->ukeys = NULL; } ftnunit->ufd = NULL; ftnunit->uconn = 0; ftnunit->luno = 0; ftnunit->ukeyid = -1; return SUCCESS; }
void kbdinput::readcb () { struct _isigs { int ch; int sig; }; static const _isigs isig[] = { { VINTR, SIGINT }, { VQUIT, SIGQUIT }, { VSUSP, SIGTSTP }, #ifdef VDSUSP { VDSUSP, SIGTSTP }, #endif /* VDSUSP */ { -1, -1 } }; u_char c; size_t n = read (kbdfd, &c, 1); if (n <= 0) { setorig (); if (n == 0) fatal ("keyboard: EOF (with ICANON clear)\n"); else fatal ("keyboard: %m\n"); } dst->update (&c, 1); getclocknoise (dst); if (!lnext && c != _POSIX_VDISABLE) { #ifdef VLNEXT if (c == torig.c_cc[VLNEXT]) { lnext = true; return; } #endif /* VLNEXT */ for (int i = 0; isig[i].sig > 0; i++) if (c == torig.c_cc[isig[i].ch]) { setorig (); tcflush (kbdfd, TCIFLUSH); kill (0, isig[i].sig); gotsig = true; setraw (); getclocknoise (dst); vreprint (); gotsig = false; return; } if (iserase (c)) verase (); else if (iskill (c)) vkill (); else if (isreprint (c)) vreprint (); else goto normal; return; } normal: bool olnext = lnext; lnext = false; gotch (c, olnext); c = 0; }
int main (int iArgc, char **ppcArgv) { int iResult, iLoop, iLoop2, iLoop3, iHandle; unsigned char cRecord [256]; struct keydesc sKeydesc; char cLogfileName [100], cCommand [100]; char cFileName [] = "IsamTest"; memset (&sKeydesc, 0, sizeof (sKeydesc)); sKeydesc.k_flags = COMPRESS; sKeydesc.k_nparts = 1; sKeydesc.k_start = 0; sKeydesc.k_leng = 2; sKeydesc.k_type = CHARTYPE; if (iArgc == 1) { printf ("Usage:\n\t%s create\nOR\n\t%s <#iterations>\n", ppcArgv [0], ppcArgv [0]); exit (1); } if (iArgc > 1 && strcmp (ppcArgv [1], "create") == 0) { iserase (cFileName); iHandle = isbuild (cFileName, 255, &sKeydesc, ISINOUT+ISFIXLEN+ISEXCLLOCK); if (iHandle < 0) { printf ("Error creating database: %d\n", iserrno); exit (-1); } sKeydesc.k_flags |= ISDUPS; sKeydesc.k_start = 3; sKeydesc.k_leng = 4; for (sKeydesc.k_start = 1; sKeydesc.k_start < 2; sKeydesc.k_start++) { if (isaddindex (iHandle, &sKeydesc)) { printf ("Error %d adding index %d\n", iserrno, sKeydesc.k_start); } } isclose (iHandle); sprintf (cLogfileName, "RECOVER"); #ifdef _WIN32 sprintf (cCommand, "del /f /q %s", cLogfileName); #else sprintf (cCommand, "rm -f %s; touch %s", cLogfileName, cLogfileName); #endif system (cCommand); return (0); } sprintf (cLogfileName, "RECOVER"); #ifdef _WIN32 iResult = open("RECOVER", O_CREAT | O_TRUNC | O_RDWR | O_BINARY, 0666); #else iResult = open("RECOVER", O_CREAT | O_TRUNC | O_RDWR, 0666); #endif close(iResult); iResult = islogopen (cLogfileName); if (iResult < 0) { printf ("Error opening log: %d\n", iserrno); exit (-1); } /* srand (time (NULL)); */ srand (9); for (iLoop = 0; iLoop < atoi (ppcArgv [1]); iLoop++) { if (!(iLoop % 100)) { printf ("iLoop=%d\n", iLoop); fflush(stdout); } iVBDlCount = 0; iVBRdCount = 0; iVBUpCount = 0; iVBWrCount = 0; iResult = isbegin (); if (iResult < 0) { printf ("Error begin transaction: %d\n", iserrno); exit (-1); } iHandle = isopen (cFileName, ISINOUT+ISFIXLEN+ISTRANS+ISAUTOLOCK); if (iHandle < 0) { printf ("Error opening database: %d\n", iserrno); exit (-1); } for (iLoop2 = 0; iLoop2 < 100; iLoop2++) { for (iLoop3 = 0; iLoop3 < 256; iLoop3++) { cRecord [iLoop3] = rand () % 256; } iResult =rand () % 4; /* fprintf(stderr, "I %d\n", iResult); */ switch (iResult) { case 0: if ((iResult = iswrite (iHandle, (char *) cRecord)) != 0) { if (iserrno != EDUPL && iserrno != ELOCKED) { printf ("Error writing: %d\n", iserrno); goto err; } } else { iVBWrCount++; } break; case 1: if ((iResult = isread (iHandle, (char *)cRecord, ISEQUAL)) != 0) { if (iserrno == ELOCKED) { ; /* printf ("Locked during deletion\n"); */ } else if (iserrno != ENOREC) { printf ("Error reading: %d\n", iserrno); goto err; } } else { iVBRdCount++; } break; case 2: for (iLoop3 = 0; iLoop3 < 256; iLoop3++) { cRecord [iLoop3] = rand () % 256; } if ((iResult = isrewrite (iHandle, (char *)cRecord)) != 0) { if (iserrno == ELOCKED) { ; /* printf ("Locked during rewrite\n"); */ } else if (iserrno != ENOREC) { printf ("Error rewriting: %d\n", iserrno); goto err; } } else { iVBUpCount++; } break; case 3: if ((iResult = isdelete (iHandle, (char *)cRecord)) != 0) { if (iserrno == ELOCKED) { ; /* printf ("Locked during deletion\n"); */ } else if (iserrno != ENOREC) { printf ("Error deleting: %d\n", iserrno); goto err; } } else iVBDlCount++; break; } } iResult = isflush (iHandle); if (iResult < 0) { printf ("Error flush: %d\n", iserrno); exit (-1); } iResult = isclose (iHandle); if (iResult < 0) { printf ("Error closing database: %d\n", iserrno); exit (-1); } iVBDlTotal += iVBDlCount; iVBRdTotal += iVBRdCount; iVBUpTotal += iVBUpCount; iVBWrTotal += iVBWrCount; switch (rand () % 2) { case 0: iVBDlCommit += iVBDlCount; iVBRdCommit += iVBRdCount; iVBUpCommit += iVBUpCount; iVBWrCommit += iVBWrCount; iResult = iscommit (); if (iResult < 0) { printf ("Error commit: %d\n", iserrno); exit (-1); } break; case 1: iResult = isrollback (); if (iResult < 0) { if (iserrno == EDUPL || iserrno == ENOREC) { printf ("Same BUG (%d) as in C-ISAM!\n", iserrno); } else { printf ("Error rollback: %d\n", iserrno); exit (-1); } } break; } } err: printf (" Total Commited\n"); printf (" -------- --------\n"); printf ("Delete Count: %8d %8d\n", iVBDlTotal, iVBDlCommit); printf ("Read Count: %8d %8d\n", iVBRdTotal, iVBRdCommit); printf ("Update Count: %8d %8d\n", iVBUpTotal, iVBUpCommit); printf ("Write Count: %8d %8d\n", iVBWrTotal, iVBWrCommit); printf (" -------- --------\n"); printf ("OPS OVERALL : %8d %8d\n", (iVBDlTotal + iVBRdTotal + iVBUpTotal + iVBWrTotal), (iVBDlCommit + iVBRdCommit + iVBUpCommit + iVBWrCommit)); printf (" ========\n"); printf ("ROWS ADDED THIS RUN: %8d\n", (iVBWrCommit - iVBDlCommit)); printf (" ========\n"); return (iResult); }
bool_t _Tt_db_partition_global_map_ref ::checkForOldDBTable (const _Tt_string &partition, const _Tt_string &old_file, const _Tt_string &new_file) { static bool_t old_db_diagnostic = FALSE; _Tt_string base_dir = (char *)partition; if (base_dir[base_dir.len()-1] != '/') { base_dir = base_dir.cat("/"); } base_dir = base_dir.cat("TT_DB/"); _Tt_string old_db_file(base_dir); old_db_file = old_db_file.cat(old_file); _Tt_string new_db_file(base_dir); new_db_file = new_db_file.cat(new_file); _Tt_string old_db_index(old_db_file); old_db_index = old_db_index.cat(".ind"); _Tt_string new_db_index(new_db_file); new_db_index = new_db_index.cat(".ind"); struct stat stat_buf; int temp_errno = 0; // If there is no new DB and there is an old DB... if (stat((char *)new_db_index, &stat_buf) && ((temp_errno = errno) == ENOENT) && !stat((char *)old_db_index, &stat_buf)) { if (new_file == TT_DB_ACCESS_TABLE_FILE) { _Tt_isam_file_ptr old_db_table = new _Tt_isam_file(old_db_file, ISFIXLEN+ISINOUT+ISEXCLLOCK); _Tt_isam_file_ptr access_table; int results = old_db_table->getErrorStatus(); if (!results) { _Tt_isam_key_descriptor_ptr access_key = new _Tt_isam_key_descriptor; access_key->addKeyPart(0, TT_DB_KEY_LENGTH, BINTYPE); access_table = new _Tt_isam_file(new_db_file, TT_DB_KEY_LENGTH+3*TT_DB_LONG_SIZE, TT_DB_KEY_LENGTH+3*TT_DB_LONG_SIZE, access_key, ISFIXLEN+ISINOUT+ISEXCLLOCK); results = access_table->getErrorStatus(); if (!results) { results = access_table->writeMagicString(_Tt_string(TT_DB_VERSION)); } } if (!results) { _Tt_isam_record_ptr new_record = access_table->getEmptyRecord(); _Tt_isam_record_ptr record; while (!results) { record = old_db_table->readRecord(ISNEXT); results = old_db_table->getErrorStatus(); if (!results) { memset((char *)new_record->getRecord(), '\0', new_record->getLength()); memcpy((char *)new_record->getRecord(), (char *)record->getRecord(), TT_DB_KEY_LENGTH); short n_user = *(short *) ((char *)record->getRecord()+TT_DB_KEY_LENGTH); long user = (long)ntohs(n_user); u_long nl_user = htonl(user); memcpy((char *)new_record->getRecord()+TT_DB_ACCESS_USER_OFFSET, (char *)&nl_user, TT_DB_LONG_SIZE); short n_group = *(short *) ((char *)record->getRecord()+ TT_DB_KEY_LENGTH+TT_DB_SHORT_SIZE); long group = (long)ntohs(n_group); u_long nl_group = htonl(group); memcpy((char *)new_record->getRecord()+TT_DB_ACCESS_GROUP_OFFSET, (char *)&nl_group, TT_DB_LONG_SIZE); short n_mode = *(short *) ((char *)record->getRecord()+ TT_DB_KEY_LENGTH+2*TT_DB_SHORT_SIZE); long mode = (long)ntohs(n_mode); u_long nl_mode = htonl(mode); memcpy((char *)new_record->getRecord()+TT_DB_ACCESS_MODE_OFFSET, (char *)&nl_mode, TT_DB_LONG_SIZE); results = access_table->writeRecord(new_record); } } if (results == EENDFILE) { results = 0; } } if (!results) { (void)iserase((char *)old_db_file); } if (results) { return TRUE; } } else { if (isrename((char *)old_db_file, (char *)new_db_file)) { return TRUE; } else { _Tt_isam_file_ptr new_db_table = new _Tt_isam_file(new_db_file, ISFIXLEN+ISINOUT+ISEXCLLOCK); int results = new_db_table->getErrorStatus(); if (results) { new_db_table = new _Tt_isam_file(new_db_file, ISVARLEN+ISINOUT+ISEXCLLOCK); results = new_db_table->getErrorStatus(); } if (!results) { (void)new_db_table->writeMagicString(TT_DB_VERSION); } } } } else if (temp_errno && (temp_errno != ENOENT)) { return TRUE; } else if (!stat((char *)old_db_index, &stat_buf)) { if (old_db_diagnostic == FALSE) { _tt_syslog(errstr, LOG_ERR, catgets(_ttcatd, 5, 5, "Any data written using an old (<= 1.0.2) " "rpc.ttdbserverd after using a new (>= 1.1) " "rpc.ttdbserverd will be ignored")); old_db_diagnostic = TRUE; } } return FALSE; }