📄 librcv.c
字号:
{ char *a, type; struct ADREC bllj; while ( cadlj.cm != 0 ) { rcv_LJ_GETREC (&bllj, &cadlj); a = bllj.block; type = *a++; a += size4b; cadlj.npage = t2bunpack (a); a += size2b; cadlj.cm = t2bunpack (a); a += size2b; backactn (bllj.razm, a, type); }}struct ADBL bmtn_feot (i4_t fd, struct ADBL cadlj) /* The motion back to the first EOTLJ */{ char *a, type; i4_t prnftr = 0; struct ADBL ladlj; u2_t blsz; char *pnt, mas[RPAGE]; ladlj = cadlj; while ((blsz = LJ_prev (fd, &cadlj, &pnt, mas)) > 0) { a = pnt; type = *a++; if (type == GRLBLJ) { ladlj = cadlj; prnftr = 1; continue; } if (type == EOTLJ) { getmint (a, blsz - size1b); if (prnftr == 0) rollb_nftr (fd, cadlj, a, blsz - size1b); break; } idtr = t4bunpack (a); backactn (blsz, a + size4b + 2 * size2b, type); ladlj = cadlj; } return (ladlj);}voidbackactn (u2_t blsz, char * a, char type){ u2_t sn, pn, ind, pnr, indr; i2_t n; struct d_r_t *desrel; struct des_tid tid; i4_t rn; struct id_rel idr; if (type == RLBLJ || type == CPRLJ || type == RLBLJ_AS_OP) return; sn = idr.urn.segnum = t2bunpack (a); assert (sn != 0); a += size2b; rn = idr.urn.obnum = t4bunpack (a); a += size4b; idr.pagenum = pnr = t2bunpack (a); a += size2b; idr.index = indr = t2bunpack (a); a += size2b; tid.tpn = t2bunpack (a); a += size2b; tid.tindex = t2bunpack (a); a += size2b; pn = tid.tpn; ind = tid.tindex; if (rn != RDRNUM) { for (desrel = firstrel; desrel != NULL; desrel = desrel->drlist) if (desrel->desrbd.relnum == rn) break; if (desrel == NULL) desrel = cr_rd (&idr); } else desrel = NULL; n = blsz - ljmsize; if (type == DELLJ) { redo_insrtn (sn, desrel, rn, &tid, n, a); } else if (type == INSLJ) { redo_dltn (sn, desrel, rn, &tid, n, a); } else if (type == DLILJ) { /*nead to create an index */ redo_cind (a, n, sn, pnr, indr, &tid); } else { /* The modification */ u2_t corsize; struct des_tid ref_tid; corsize = get_placement (sn, &tid, &ref_tid); n -= corsize; ordmod (sn, rn, &tid, &ref_tid, corsize, a, n); if (rn != RDRNUM) { mproind (desrel, desrel->desrbd.indnum, a + n, a, &tid); } else { i4_t ordrn; ordrn = t4bunpack (a + scscal(a)); idr.urn.obnum = ordrn; desrel = firstrel; for (; desrel->desrbd.relnum != ordrn; desrel = desrel->drlist); if (desrel == NULL) crtfrd (&idr, a); if (type == CRILJ) { /* nead to delete an index */ redo_dind (desrel, a); } else if (type == ADFLJ) { /*nead to delete fields */ struct d_r_bd drbd; a++; drbdunpack (&drbd, a); desrel->desrbd.fieldnum = drbd.fieldnum; } } }}u2_tLJ_prev (i4_t fd, struct ADBL *adj, char **pnt, char *mas){ u2_t N, n, blsz, n1; char *end_of_record; N = adj->npage; n = adj->cm; if (n == RTPAGE && pagenum == 1) return (0); if (pagenum != N) read_page (fd, N, ljpage); n -= RTPAGE; if (n < RTBLK) { /* the endtop-block places in two pages*/ char buff[RTBLK]; n1 = RTBLK - n; bcopy (ljpage + RTPAGE, buff + n1, n); N--; read_page (fd, N, ljpage); end_of_record = ljpage + RPAGE - n1; bcopy (end_of_record, buff, n1); blsz = t2bunpack (buff); n = RPAGE - RTPAGE - n1; } else { /* the top-block places in (N)-page */ end_of_record = ljpage + n + RTPAGE - RTBLK; blsz = t2bunpack (end_of_record); n -= RTBLK; if (n == 0) { N--; read_page (fd, N, ljpage); n = RPAGE - RTPAGE; end_of_record = ljpage + RPAGE; } } if (n < blsz) { /* block-record places in two pages */ n1 = blsz - n; bcopy (ljpage + RTPAGE, mas + n1, n); N--; read_page (fd, N, ljpage); bcopy (ljpage + RPAGE - n1, mas, n1); *pnt = mas; n = RPAGE - RTPAGE - n1; } else { *pnt = end_of_record - blsz; n -= blsz; if (n == 0) { N--; n = RPAGE - RTPAGE; } } if (n < RTBLK) { /* the endtop-block places in two pages */ N--; n1 = RTBLK - n; n = RPAGE - RTPAGE - n1; } else n -= RTBLK; adj->npage = N; adj->cm = n + RTPAGE; return (blsz);}static voidwrite_page(i4_t fd, u2_t N, char *buf){ if (lseek (fd, (i4_t) (RPAGE * (N - 1)), SEEK_SET) < 0) { perror ("LIBRCV: lseek"); exit (1); } if (write (fd, buf, RPAGE) != RPAGE) { perror ("LIBRCV: read"); exit (1); }}static voiddo_cont (void){ register char *a; i4_t NB; NB = t4bunpack (ljpage); *(ljpage + size4b + size2b) = SIGN_CONT; write_page (fdcurlj, pagenum, ljpage); a = ljpage; t4bpack (NB, a); a += size4b; t2bpack (RTPAGE, a); a += size2b; *a = SIGN_NOCONT; pagenum++;}static char *write_topblock(u2_t size, u2_t off, char *a){ if (off + RTBLK > RPAGE) { /* the top-block places in two pages*/ u2_t n, n1; char buff[size2b]; n = RPAGE - off; t2bpack (size, buff); bcopy (buff, a, n); do_cont (); a = ljpage + RTPAGE; n1 = RTBLK - n; bcopy (buff + n, a, n1); a += n1; } else { /* the top-block places in (N)-page */ t2bpack (size, a); a += size2b; } return (a);}voidrcv_wmlj (struct ADBL *cadlj){ u2_t off, razm; register char *p; read_page (fdcurlj, cadlj->npage, ljpage); off = cadlj->cm;; razm = 1; p = write_topblock (razm, off, ljpage + off); if (p + razm > ljpage + RPAGE) { do_cont (); p = ljpage + RTPAGE; } *p++ = (char) GRLBLJ; p = write_topblock (razm, p - ljpage, p); off = p - ljpage; t2bpack (off, ljpage + size4b); *(ljpage + size4b + size2b) = SIGN_NOCONT; write_page (fdcurlj, pagenum, ljpage); ftruncate (fdcurlj, pagenum * RPAGE);}voidrcv_LJ_GETREC (struct ADREC *bllj, struct ADBL *pcadlj){ char *p; struct msg_buf sbuf; sbuf.mtype = GETREC; t2bpack (trnum, sbuf.mtext); bcopy ((char *) pcadlj, sbuf.mtext, adjsize); if (msgsnd (msqidl, (void *) &sbuf, adjsize + size2b, 0) < 0) { perror ("LIBRCV.msgsnd: LJ GETREC"); exit (1); } if (msgrcv (msqidl, (void *) &sbuf, sizeof (struct ADREC), trnum, 0) < 0) { perror ("LIBRCV.msgrcv: Answer from LJ"); exit (1); } p = sbuf.mtext; bllj->razm = t2bunpack (p); p += size2b; bcopy (p, bllj->block, bllj->razm);}intdir_copy (char *dir_from, char *dir_to){ DIR *dp; struct dirent *dir; i4_t num; if ((dp = opendir (dir_from)) == NULL) { fprintf (stderr, "LIBRCV: %s cannot open\n", dir_from); exit (1); } dir = readdir (dp); dir = readdir (dp); for (num = 0; (dir = readdir (dp)) != NULL; num++) { if (dir->d_ino == 0) continue; copy (dir->d_name, dir_from, dir_to); } closedir (dp); return (num);}voidcopy (char *name, char *dir_from, char *dir_to){ i4_t i; pid_t pidcp; char *args[4], mch[4][1024]; i4_t status; for (i = 0; i < 4; i++) args[i] = mch[i]; if ((pidcp = fork ())< 0) { perror ("fork cp"); exit (1); } if (pidcp == 0) { args[0] = CP; sprintf (args[1], "%s/%s", dir_from, name); sprintf (args[2], "%s/%s", dir_to, name); args[3] = NULL; execvp (*args, args); perror ("LIBRCV.copy: CP doesn't exec"); exit (1); } while (waitpid (-1, &status, 0) != pidcp);}intLOGJ_FIX (void){ struct msg_buf sbuf; sbuf.mtype = BEGFIX; if (msgsnd (msqidl, (void *) &sbuf, 0, 0) < 0) { perror ("LIBRCV.msgsnd: LOGJ->FIX"); exit (1); } if (msgrcv (msqidl, (void *) &sbuf, 1, ANSLJ, 0) < 0) { perror ("LIBRCV.msgrcv: BEGFIX LJ"); exit (1); } return ( (i4_t)*sbuf.mtext);}/* Read "N"-page from JRN-basefile into buf */voidread_page(i4_t fd, u2_t N, char *buf){ if (lseek (fd, (i4_t) (RPAGE * (N - 1)), SEEK_SET) < 0) { perror ("LIBRCV: lseek"); exit (1); } if (read (fd, buf, RPAGE) != RPAGE) { perror ("LIBRCV: read"); exit (1); } pagenum = N;}voiddubl_segs (void){ dir_copy (DIR_SEGS, DIR_DUB_SEGS); dir_copy (DIR_SEGS, DIR_REP_SEGS);}voidrcv_ini_lj (){ struct msg_buf sbuf; sbuf.mtype = INILJ; t2bpack (trnum, sbuf.mtext); if (msgsnd (msqidl, (void *) &sbuf, size2b, 0) < 0) { perror ("LIBRCV.msgsnd: LJ INILOGJ"); exit (1); } if (msgrcv (msqidl, (void *) &sbuf, 0, trnum, 0) < 0) { perror ("LIBRCV.msgrcv: Answer from LJ on INILOGJ"); exit (1); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -