Tech Note (Errors) Vol 3, Issue 1,1993 (pgs 11-15)
Posted in 1993
I don't know if anyone else tried to run the program "countrow.c" given as an example in the just release Tech Notes from Informix, but it doesn't work. It looks like there were ALOT of typos - You'd think that INFORMIX would proof this stuff before sending it out. I called the Author listed, Amit Mehta, who wasn't even aware that the code was released. :)) He's not happy about it too! Anyway, I got it working and list it below with the output compared to running a check with bcheck: /* countrow.c */ /* from Informix's Tech Notes,vol 3, Issue 1, 1993 (pgs 11-15) */ /* additions made to allow compilation of program. bobb@netcom.com */ #include <fcntl.h> #include <bsd/sys/types.h> extern int errno; long ldlong(); short ldint(); struct dict { char d_magic[2]; char d_dummy1[4]; char d_idxsize[2]; char d_nkeys[2]; char d_cflag[1]; char d_dflag[1]; char d_version[1]; char d_recsize[2]; char d_keysnode[4]; char d_dummy2[6]; char d_freedata[4]; char d_freenode[4]; char d_nextdata[4]; char d_nextnode[4]; char d_transaction[4]; char d_uniqid[4]; char d_audit[4]; char d_lkmethod[2]; char d_altcnt[4]; char d_maxsize[2]; }; main (argc,argv) int argc; char **argv; { struct dict *dictp; int fpidx, fpdat; char idxname[64], datname[64]; char *recp; char *valid; long cntval=0; long cntdel=0; if(argc<2) { printf("Usage: %s filename\\n",argv[0]); exit(1); } strcpy(datname,argv[1]); strcpy(idxname,argv[1]); strcat(datname,".dat"); strcat(idxname,".idx"); if ((fpidx=open(idxname, O_RDONLY)) <0) { printf("error on IDX file: open() [errno == %d]\\n",errno); exit(1); } if ((fpdat=open(datname, O_RDONLY)) <0) { printf("error on DAT file: open() [errno == %d]\\n",errno); exit(1); } dictp = (struct dict *) malloc(sizeof(struct dict)); if(dictp == (struct dict *) 0 ) { printf("error getting DICT: malloc() [errno == %d]\\n",errno); exit(1); } if ((read(fpidx,dictp,sizeof(struct dict))) ==0) { printf("error getting DICT: read() [errno == %d] \\n",errno); exit(1); } recp = (char *) malloc(ldint(dictp->d_recsize) + 1); if(recp == (char *) 0) { printf("error reading record: malloc() [errno == %d]\\n",errno); exit(1); } valid = recp+ldint(dictp->d_recsize); while(read(fpdat,recp,ldint(dictp->d_recsize)+ 1)==(ldint(dictp->d_recsize) +1)) { if (*valid=='\\n') { cntval++; } else { cntdel++; } } printf("record size -> %d\\n",ldint(dictp->d_recsize)); printf("nb of valid records-> %ld\\n",cntval); printf("actual rowid is -> %ld\\n",ldlong(dictp->d_nextdata)); printf("nb of unused record slots-> %ld\\n",cntdel); free(dictp); close(fpidx); close(fpdat); exit(0); } #define BYTESHFT 8 #define BYTEMASK 0xff long ldlong(p) register char *p; { return ((((((((long) p[0] << BYTESHFT) + (p[1] & BYTEMASK)) << BYTESHFT) + (p[2] & BYTEMASK)) << BYTESHFT) + (p[3] & BYTEMASK))); } short ldint(p) register char *p; { return(((short) p[0] << BYTESHFT) + (p[1] & BYTEMASK)); } /* end of countrow.c */ OUTPUT DATA BELOW: (command: bcheck vac_li1363.dat or bcheck vac_li1363.idx) ----------------------------------------------------------------------------- Results of output ----------------------------------------------------------------------------- BCHECK C-ISAM B-tree Checker version 4.00.UE2 Copyright (C) 1981-1989 Informix Software, Inc. Software Serial Number INF#F203964 C-ISAM File: vac_li1363.dat Checking dictionary and file sizes. Index file node size = 1024 Current C-ISAM index file node size = 1024 Checking data file records. Checking indexes and key descriptions. Index 1 = unique key 0 index node(s) used -- 1 index b-tree level(s) used Checking data record and index node free lists. 14 index node(s) used, 5 free -- 690 data record(s) used, 3420 free (command: countrow vac_li1363) ----------------------------------------------------------------------------- Results of output ----------------------------------------------------------------------------- record size -> 69 nb of valid records-> 690 actual rowid is -> 3685 nb of unused record slots-> 3420 -- --------------------------------------------------------------------------- |Bob Beaulieu Internet : bobb@netcom.com | |EZ TRAVEL Internet : eztravel@netcom.com | |4640-B Meridian Telephone: (408) 978-0808 | |San Jose, CA 95124 Facsimile: (408) 978-7024 | |+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++| | Serving all your travel needs from start to finish | | $$$ Best Fares $$$ | | Great Service | | Specializing in International Travel | ---------------------------------------------------------------------------