lock file structure during undo
[nvi.git] / common / log.c
blob97b1e8c0b9e3df9b6c4d38d1a450ce50b78fdc42
1 /*-
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1992, 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #ifndef lint
13 static const char sccsid[] = "$Id: log.c,v 10.20 2000/08/29 15:52:37 skimo Exp $ (Berkeley) $Date: 2000/08/29 15:52:37 $";
14 #endif /* not lint */
16 #include <sys/types.h>
17 #include <sys/queue.h>
18 #include <sys/stat.h>
20 #include <bitstring.h>
21 #include <errno.h>
22 #include <fcntl.h>
23 #include <limits.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
28 #include "common.h"
31 * The log consists of records, each containing a type byte and a variable
32 * length byte string, as follows:
34 * LOG_CURSOR_INIT MARK
35 * LOG_CURSOR_END MARK
36 * LOG_LINE_APPEND db_recno_t char *
37 * LOG_LINE_DELETE db_recno_t char *
38 * LOG_LINE_INSERT db_recno_t char *
39 * LOG_LINE_RESET_F db_recno_t char *
40 * LOG_LINE_RESET_B db_recno_t char *
41 * LOG_MARK LMARK
43 * We do before image physical logging. This means that the editor layer
44 * MAY NOT modify records in place, even if simply deleting or overwriting
45 * characters. Since the smallest unit of logging is a line, we're using
46 * up lots of space. This may eventually have to be reduced, probably by
47 * doing logical logging, which is a much cooler database phrase.
49 * The implementation of the historic vi 'u' command, using roll-forward and
50 * roll-back, is simple. Each set of changes has a LOG_CURSOR_INIT record,
51 * followed by a number of other records, followed by a LOG_CURSOR_END record.
52 * LOG_LINE_RESET records come in pairs. The first is a LOG_LINE_RESET_B
53 * record, and is the line before the change. The second is LOG_LINE_RESET_F,
54 * and is the line after the change. Roll-back is done by backing up to the
55 * first LOG_CURSOR_INIT record before a change. Roll-forward is done in a
56 * similar fashion.
58 * The 'U' command is implemented by rolling backward to a LOG_CURSOR_END
59 * record for a line different from the current one. It should be noted that
60 * this means that a subsequent 'u' command will make a change based on the
61 * new position of the log's cursor. This is okay, and, in fact, historic vi
62 * behaved that way.
65 static int vi_log_get __P((SCR *sp, db_recno_t *lnop, size_t *size));
66 static int log_cursor1 __P((SCR *, int));
67 static void log_err __P((SCR *, char *, int));
68 #if defined(DEBUG) && 0
69 static void log_trace __P((SCR *, char *, db_recno_t, u_char *));
70 #endif
72 /* Try and restart the log on failure, i.e. if we run out of memory. */
73 #define LOG_ERR { \
74 log_err(sp, __FILE__, __LINE__); \
75 return (1); \
79 * log_init --
80 * Initialize the logging subsystem.
82 * PUBLIC: int log_init __P((SCR *, EXF *));
84 int
85 log_init(sp, ep)
86 SCR *sp;
87 EXF *ep;
90 * !!!
91 * ep MAY NOT BE THE SAME AS sp->ep, DON'T USE THE LATTER.
93 * Initialize the buffer. The logging subsystem has its own
94 * buffers because the global ones are almost by definition
95 * going to be in use when the log runs.
97 sp->wp->l_lp = NULL;
98 sp->wp->l_len = 0;
99 ep->l_cursor.lno = 1; /* XXX Any valid recno. */
100 ep->l_cursor.cno = 0;
101 ep->l_high = ep->l_cur = 1;
103 if (db_create(&ep->log, sp->gp->env, 0) != 0 ||
104 ep->log->open(ep->log, NULL, NULL, DB_RECNO, DB_CREATE | DB_THREAD,
105 S_IRUSR | S_IWUSR) != 0) {
106 msgq(sp, M_SYSERR, "009|Log file");
107 F_SET(ep, F_NOLOG);
108 return (1);
111 ep->l_win = NULL;
112 //LOCK_INIT(sp->wp, ep);
114 return (0);
118 * log_end --
119 * Close the logging subsystem.
121 * PUBLIC: int log_end __P((SCR *, EXF *));
124 log_end(sp, ep)
125 SCR *sp;
126 EXF *ep;
129 * !!!
130 * ep MAY NOT BE THE SAME AS sp->ep, DON'T USE THE LATTER.
132 //LOCK_END(sp->wp, ep);
133 if (ep->log != NULL) {
134 (void)(ep->log->close)(ep->log,DB_NOSYNC);
135 ep->log = NULL;
137 if (sp->wp->l_lp != NULL) {
138 free(sp->wp->l_lp);
139 sp->wp->l_lp = NULL;
141 sp->wp->l_len = 0;
142 ep->l_cursor.lno = 1; /* XXX Any valid recno. */
143 ep->l_cursor.cno = 0;
144 ep->l_high = ep->l_cur = 1;
145 return (0);
149 * log_cursor --
150 * Log the current cursor position, starting an event.
152 * PUBLIC: int log_cursor __P((SCR *));
155 log_cursor(sp)
156 SCR *sp;
158 EXF *ep;
160 ep = sp->ep;
161 if (F_ISSET(ep, F_NOLOG))
162 return (0);
165 * If any changes were made since the last cursor init,
166 * put out the ending cursor record.
168 if (ep->l_cursor.lno == OOBLNO) {
169 if (ep->l_win && ep->l_win != sp->wp)
170 return 0;
171 ep->l_cursor.lno = sp->lno;
172 ep->l_cursor.cno = sp->cno;
173 ep->l_win = NULL;
174 return (log_cursor1(sp, LOG_CURSOR_END));
176 ep->l_cursor.lno = sp->lno;
177 ep->l_cursor.cno = sp->cno;
178 return (0);
182 * log_cursor1 --
183 * Actually push a cursor record out.
185 static int
186 log_cursor1(sp, type)
187 SCR *sp;
188 int type;
190 DBT data, key;
191 EXF *ep;
193 ep = sp->ep;
196 if (type == LOG_CURSOR_INIT &&
197 LOCK_TRY(sp->wp, ep))
198 return 1;
201 BINC_RET(sp, sp->wp->l_lp, sp->wp->l_len, sizeof(u_char) + sizeof(MARK));
202 sp->wp->l_lp[0] = type;
203 memmove(sp->wp->l_lp + sizeof(u_char), &ep->l_cursor, sizeof(MARK));
205 memset(&key, 0, sizeof(key));
206 key.data = &ep->l_cur;
207 key.size = sizeof(db_recno_t);
208 memset(&data, 0, sizeof(data));
209 data.data = sp->wp->l_lp;
210 data.size = sizeof(u_char) + sizeof(MARK);
211 if (ep->log->put(ep->log, NULL, &key, &data, 0) == -1)
212 LOG_ERR;
214 #if defined(DEBUG) && 0
215 vtrace(sp, "%lu: %s: %u/%u\n", ep->l_cur,
216 type == LOG_CURSOR_INIT ? "log_cursor_init" : "log_cursor_end",
217 sp->lno, sp->cno);
218 #endif
219 /* Reset high water mark. */
220 ep->l_high = ++ep->l_cur;
223 if (type == LOG_CURSOR_END)
224 LOCK_UNLOCK(sp->wp, ep);
226 return (0);
230 * log_line --
231 * Log a line change.
233 * PUBLIC: int log_line __P((SCR *, db_recno_t, u_int));
236 log_line(sp, lno, action)
237 SCR *sp;
238 db_recno_t lno;
239 u_int action;
241 DBT data, key;
242 EXF *ep;
243 size_t len;
244 CHAR_T *lp;
245 db_recno_t lcur;
247 ep = sp->ep;
248 if (F_ISSET(ep, F_NOLOG))
249 return (0);
252 * XXX
254 * Kluge for vi. Clear the EXF undo flag so that the
255 * next 'u' command does a roll-back, regardless.
257 F_CLR(ep, F_UNDO);
259 /* Put out one initial cursor record per set of changes. */
260 if (ep->l_cursor.lno != OOBLNO) {
261 if (log_cursor1(sp, LOG_CURSOR_INIT))
262 return (1);
263 ep->l_cursor.lno = OOBLNO;
264 ep->l_win = sp->wp;
265 } /*else if (ep->l_win != sp->wp) {
266 printf("log_line own: %p, this: %p\n", ep->l_win, sp->wp);
267 return 1;
271 * Put out the changes. If it's a LOG_LINE_RESET_B call, it's a
272 * special case, avoid the caches. Also, if it fails and it's
273 * line 1, it just means that the user started with an empty file,
274 * so fake an empty length line.
276 if (action == LOG_LINE_RESET_B) {
277 if (db_get(sp, lno, DBG_NOCACHE, &lp, &len)) {
278 static CHAR_T nul = 0;
279 if (lno != 1) {
280 db_err(sp, lno);
281 return (1);
283 len = 0;
284 lp = &nul;
286 } else
287 if (db_get(sp, lno, DBG_FATAL, &lp, &len))
288 return (1);
289 BINC_RET(sp,
290 sp->wp->l_lp, sp->wp->l_len,
291 len * sizeof(CHAR_T) + sizeof(u_char) + sizeof(db_recno_t));
292 sp->wp->l_lp[0] = action;
293 memmove(sp->wp->l_lp + sizeof(u_char), &lno, sizeof(db_recno_t));
294 MEMMOVEW(sp->wp->l_lp + sizeof(u_char) + sizeof(db_recno_t), lp, len);
296 lcur = ep->l_cur;
297 memset(&key, 0, sizeof(key));
298 key.data = &lcur;
299 key.size = sizeof(db_recno_t);
300 memset(&data, 0, sizeof(data));
301 data.data = sp->wp->l_lp;
302 data.size = len * sizeof(CHAR_T) +
303 sizeof(u_char) + sizeof(db_recno_t);
304 if (ep->log->put(ep->log, NULL, &key, &data, 0) == -1)
305 LOG_ERR;
307 #if defined(DEBUG) && 0
308 switch (action) {
309 case LOG_LINE_APPEND:
310 vtrace(sp, "%u: log_line: append: %lu {%u}\n",
311 ep->l_cur, lno, len);
312 break;
313 case LOG_LINE_DELETE:
314 vtrace(sp, "%lu: log_line: delete: %lu {%u}\n",
315 ep->l_cur, lno, len);
316 break;
317 case LOG_LINE_INSERT:
318 vtrace(sp, "%lu: log_line: insert: %lu {%u}\n",
319 ep->l_cur, lno, len);
320 break;
321 case LOG_LINE_RESET_F:
322 vtrace(sp, "%lu: log_line: reset_f: %lu {%u}\n",
323 ep->l_cur, lno, len);
324 break;
325 case LOG_LINE_RESET_B:
326 vtrace(sp, "%lu: log_line: reset_b: %lu {%u}\n",
327 ep->l_cur, lno, len);
328 break;
330 #endif
331 /* Reset high water mark. */
332 ep->l_high = ++ep->l_cur;
334 return (0);
338 * log_mark --
339 * Log a mark position. For the log to work, we assume that there
340 * aren't any operations that just put out a log record -- this
341 * would mean that undo operations would only reset marks, and not
342 * cause any other change.
344 * PUBLIC: int log_mark __P((SCR *, LMARK *));
347 log_mark(sp, lmp)
348 SCR *sp;
349 LMARK *lmp;
351 DBT data, key;
352 EXF *ep;
354 ep = sp->ep;
355 if (F_ISSET(ep, F_NOLOG))
356 return (0);
358 /* Put out one initial cursor record per set of changes. */
359 if (ep->l_cursor.lno != OOBLNO) {
360 if (log_cursor1(sp, LOG_CURSOR_INIT))
361 return (1);
362 ep->l_cursor.lno = OOBLNO;
363 ep->l_win = sp->wp;
366 BINC_RET(sp, sp->wp->l_lp,
367 sp->wp->l_len, sizeof(u_char) + sizeof(LMARK));
368 sp->wp->l_lp[0] = LOG_MARK;
369 memmove(sp->wp->l_lp + sizeof(u_char), lmp, sizeof(LMARK));
371 memset(&key, 0, sizeof(key));
372 key.data = &ep->l_cur;
373 key.size = sizeof(db_recno_t);
374 memset(&data, 0, sizeof(data));
375 data.data = sp->wp->l_lp;
376 data.size = sizeof(u_char) + sizeof(LMARK);
377 if (ep->log->put(ep->log, NULL, &key, &data, 0) == -1)
378 LOG_ERR;
380 #if defined(DEBUG) && 0
381 vtrace(sp, "%lu: mark %c: %lu/%u\n",
382 ep->l_cur, lmp->name, lmp->lno, lmp->cno);
383 #endif
384 /* Reset high water mark. */
385 ep->l_high = ++ep->l_cur;
386 return (0);
390 * vi_log_get --
391 * Get a line from the log in log buffer.
393 static int
394 vi_log_get(SCR *sp, db_recno_t *lnop, size_t *size)
396 DBT key, data;
397 size_t nlen;
398 EXF *ep;
400 ep = sp->ep;
402 nlen = 1024;
403 retry:
404 BINC_RET(sp, sp->wp->l_lp, sp->wp->l_len, nlen);
406 memset(&key, 0, sizeof(key));
407 key.data = lnop; /* Initialize db request. */
408 key.size = sizeof(db_recno_t);
409 memset(&data, 0, sizeof(data));
410 data.data = sp->wp->l_lp;
411 data.ulen = sp->wp->l_len;
412 data.flags = DB_DBT_USERMEM;
413 switch (ep->log->get(ep->log, NULL, &key, &data, 0)) {
414 case ENOMEM:
415 nlen = data.size;
416 goto retry;
417 case 0:
418 *size = data.size;
419 return 0;
420 default:
421 return 1;
426 * Log_backward --
427 * Roll the log backward one operation.
429 * PUBLIC: int log_backward __P((SCR *, MARK *));
432 log_backward(sp, rp)
433 SCR *sp;
434 MARK *rp;
436 EXF *ep;
437 LMARK lm;
438 MARK m;
439 db_recno_t lno;
440 int didop;
441 u_char *p;
442 size_t size;
444 ep = sp->ep;
445 if (F_ISSET(ep, F_NOLOG)) {
446 msgq(sp, M_ERR,
447 "010|Logging not being performed, undo not possible");
448 return (1);
451 if (ep->l_cur == 1) {
452 msgq(sp, M_BERR, "011|No changes to undo");
453 return (1);
456 if (ep->l_win && ep->l_win != sp->wp) {
457 ex_emsg(sp, NULL, EXM_LOCKED);
458 return 1;
460 ep->l_win = sp->wp;
463 F_SET(ep, F_NOLOG); /* Turn off logging. */
465 for (didop = 0;;) {
466 --ep->l_cur;
467 if (vi_log_get(sp, &ep->l_cur, &size))
468 LOG_ERR;
469 #if defined(DEBUG) && 0
470 log_trace(sp, "log_backward", ep->l_cur, data.data);
471 #endif
472 switch (*(p = (u_char *)sp->wp->l_lp)) {
473 case LOG_CURSOR_INIT:
474 if (didop) {
475 memmove(rp, p + sizeof(u_char), sizeof(MARK));
476 F_CLR(ep, F_NOLOG);
477 ep->l_win = NULL;
478 return (0);
480 break;
481 case LOG_CURSOR_END:
482 break;
483 case LOG_LINE_APPEND:
484 case LOG_LINE_INSERT:
485 didop = 1;
486 memmove(&lno, p + sizeof(u_char), sizeof(db_recno_t));
487 if (db_delete(sp, lno))
488 goto err;
489 ++sp->rptlines[L_DELETED];
490 break;
491 case LOG_LINE_DELETE:
492 didop = 1;
493 memmove(&lno, p + sizeof(u_char), sizeof(db_recno_t));
494 if (db_insert(sp, lno,
495 (CHAR_T *)(p + sizeof(u_char) +
496 sizeof(db_recno_t)),
497 (size - sizeof(u_char) - sizeof(db_recno_t))
498 / sizeof(CHAR_T)))
499 goto err;
500 ++sp->rptlines[L_ADDED];
501 break;
502 case LOG_LINE_RESET_F:
503 break;
504 case LOG_LINE_RESET_B:
505 didop = 1;
506 memmove(&lno, p + sizeof(u_char), sizeof(db_recno_t));
507 if (db_set(sp, lno,
508 (CHAR_T *)(p + sizeof(u_char) +
509 sizeof(db_recno_t)),
510 (size - sizeof(u_char) - sizeof(db_recno_t))
511 / sizeof(CHAR_T)))
512 goto err;
513 if (sp->rptlchange != lno) {
514 sp->rptlchange = lno;
515 ++sp->rptlines[L_CHANGED];
517 break;
518 case LOG_MARK:
519 didop = 1;
520 memmove(&lm, p + sizeof(u_char), sizeof(LMARK));
521 m.lno = lm.lno;
522 m.cno = lm.cno;
523 if (mark_set(sp, lm.name, &m, 0))
524 goto err;
525 break;
526 default:
527 abort();
531 err: F_CLR(ep, F_NOLOG);
532 ep->l_win = NULL;
533 return (1);
537 * Log_setline --
538 * Reset the line to its original appearance.
540 * XXX
541 * There's a bug in this code due to our not logging cursor movements
542 * unless a change was made. If you do a change, move off the line,
543 * then move back on and do a 'U', the line will be restored to the way
544 * it was before the original change.
546 * PUBLIC: int log_setline __P((SCR *));
549 log_setline(sp)
550 SCR *sp;
552 EXF *ep;
553 LMARK lm;
554 MARK m;
555 db_recno_t lno;
556 u_char *p;
557 size_t size;
559 ep = sp->ep;
560 if (F_ISSET(ep, F_NOLOG)) {
561 msgq(sp, M_ERR,
562 "012|Logging not being performed, undo not possible");
563 return (1);
566 if (ep->l_cur == 1)
567 return (1);
569 if (ep->l_win && ep->l_win != sp->wp) {
570 ex_emsg(sp, NULL, EXM_LOCKED);
571 return 1;
573 ep->l_win = sp->wp;
575 F_SET(ep, F_NOLOG); /* Turn off logging. */
577 for (;;) {
578 --ep->l_cur;
579 if (vi_log_get(sp, &ep->l_cur, &size))
580 LOG_ERR;
581 #if defined(DEBUG) && 0
582 log_trace(sp, "log_setline", ep->l_cur, data.data);
583 #endif
584 switch (*(p = (u_char *)sp->wp->l_lp)) {
585 case LOG_CURSOR_INIT:
586 memmove(&m, p + sizeof(u_char), sizeof(MARK));
587 if (m.lno != sp->lno || ep->l_cur == 1) {
588 F_CLR(ep, F_NOLOG);
589 ep->l_win = NULL;
590 return (0);
592 break;
593 case LOG_CURSOR_END:
594 memmove(&m, p + sizeof(u_char), sizeof(MARK));
595 if (m.lno != sp->lno) {
596 ++ep->l_cur;
597 F_CLR(ep, F_NOLOG);
598 ep->l_win = NULL;
599 return (0);
601 break;
602 case LOG_LINE_APPEND:
603 case LOG_LINE_INSERT:
604 case LOG_LINE_DELETE:
605 case LOG_LINE_RESET_F:
606 break;
607 case LOG_LINE_RESET_B:
608 memmove(&lno, p + sizeof(u_char), sizeof(db_recno_t));
609 if (lno == sp->lno &&
610 db_set(sp, lno, (CHAR_T *)(p + sizeof(u_char) +
611 sizeof(db_recno_t)), size - sizeof(u_char) -
612 sizeof(db_recno_t)))
613 goto err;
614 if (sp->rptlchange != lno) {
615 sp->rptlchange = lno;
616 ++sp->rptlines[L_CHANGED];
618 case LOG_MARK:
619 memmove(&lm, p + sizeof(u_char), sizeof(LMARK));
620 m.lno = lm.lno;
621 m.cno = lm.cno;
622 if (mark_set(sp, lm.name, &m, 0))
623 goto err;
624 break;
625 default:
626 abort();
630 err: F_CLR(ep, F_NOLOG);
631 ep->l_win = NULL;
632 return (1);
636 * Log_forward --
637 * Roll the log forward one operation.
639 * PUBLIC: int log_forward __P((SCR *, MARK *));
642 log_forward(sp, rp)
643 SCR *sp;
644 MARK *rp;
646 EXF *ep;
647 LMARK lm;
648 MARK m;
649 db_recno_t lno;
650 int didop;
651 u_char *p;
652 size_t size;
654 ep = sp->ep;
655 if (F_ISSET(ep, F_NOLOG)) {
656 msgq(sp, M_ERR,
657 "013|Logging not being performed, roll-forward not possible");
658 return (1);
661 if (ep->l_cur == ep->l_high) {
662 msgq(sp, M_BERR, "014|No changes to re-do");
663 return (1);
666 if (ep->l_win && ep->l_win != sp->wp) {
667 ex_emsg(sp, NULL, EXM_LOCKED);
668 return 1;
670 ep->l_win = sp->wp;
672 F_SET(ep, F_NOLOG); /* Turn off logging. */
674 for (didop = 0;;) {
675 ++ep->l_cur;
676 if (vi_log_get(sp, &ep->l_cur, &size))
677 LOG_ERR;
678 #if defined(DEBUG) && 0
679 log_trace(sp, "log_forward", ep->l_cur, data.data);
680 #endif
681 switch (*(p = (u_char *)sp->wp->l_lp)) {
682 case LOG_CURSOR_END:
683 if (didop) {
684 ++ep->l_cur;
685 memmove(rp, p + sizeof(u_char), sizeof(MARK));
686 F_CLR(ep, F_NOLOG);
687 ep->l_win = NULL;
688 return (0);
690 break;
691 case LOG_CURSOR_INIT:
692 break;
693 /* XXXX LOG_LINE_APPEND and LOG_LINE_INSERT split
694 for now, because db_insert won't work for adding
695 last line
697 case LOG_LINE_APPEND:
698 didop = 1;
699 memmove(&lno, p + sizeof(u_char), sizeof(db_recno_t));
700 --lno;
701 if (db_append(sp, 1, lno,
702 (CHAR_T *)(p + sizeof(u_char) +
703 sizeof(db_recno_t)),
704 (size - sizeof(u_char) - sizeof(db_recno_t))
705 / sizeof(CHAR_T)))
706 goto err;
707 ++sp->rptlines[L_ADDED];
708 break;
709 case LOG_LINE_INSERT:
710 didop = 1;
711 memmove(&lno, p + sizeof(u_char), sizeof(db_recno_t));
712 if (db_insert(sp, lno,
713 (CHAR_T *)(p + sizeof(u_char) +
714 sizeof(db_recno_t)),
715 (size - sizeof(u_char) - sizeof(db_recno_t))
716 / sizeof(CHAR_T)))
717 goto err;
718 ++sp->rptlines[L_ADDED];
719 break;
720 case LOG_LINE_DELETE:
721 didop = 1;
722 memmove(&lno, p + sizeof(u_char), sizeof(db_recno_t));
723 if (db_delete(sp, lno))
724 goto err;
725 ++sp->rptlines[L_DELETED];
726 break;
727 case LOG_LINE_RESET_B:
728 break;
729 case LOG_LINE_RESET_F:
730 didop = 1;
731 memmove(&lno, p + sizeof(u_char), sizeof(db_recno_t));
732 if (db_set(sp, lno,
733 (CHAR_T *)(p + sizeof(u_char) +
734 sizeof(db_recno_t)),
735 (size - sizeof(u_char) - sizeof(db_recno_t))
736 / sizeof(CHAR_T)))
737 goto err;
738 if (sp->rptlchange != lno) {
739 sp->rptlchange = lno;
740 ++sp->rptlines[L_CHANGED];
742 break;
743 case LOG_MARK:
744 didop = 1;
745 memmove(&lm, p + sizeof(u_char), sizeof(LMARK));
746 m.lno = lm.lno;
747 m.cno = lm.cno;
748 if (mark_set(sp, lm.name, &m, 0))
749 goto err;
750 break;
751 default:
752 abort();
756 err: F_CLR(ep, F_NOLOG);
757 ep->l_win = NULL;
758 return (1);
762 * log_err --
763 * Try and restart the log on failure, i.e. if we run out of memory.
765 static void
766 log_err(sp, file, line)
767 SCR *sp;
768 char *file;
769 int line;
771 EXF *ep;
773 msgq(sp, M_SYSERR, "015|%s/%d: log put error", tail(file), line);
774 ep = sp->ep;
775 (void)ep->log->close(ep->log, DB_NOSYNC);
776 if (!log_init(sp, ep))
777 msgq(sp, M_ERR, "267|Log restarted");
780 #if defined(DEBUG) && 0
781 static void
782 log_trace(sp, msg, rno, p)
783 SCR *sp;
784 char *msg;
785 db_recno_t rno;
786 u_char *p;
788 LMARK lm;
789 MARK m;
790 db_recno_t lno;
792 switch (*p) {
793 case LOG_CURSOR_INIT:
794 memmove(&m, p + sizeof(u_char), sizeof(MARK));
795 vtrace(sp, "%lu: %s: C_INIT: %u/%u\n", rno, msg, m.lno, m.cno);
796 break;
797 case LOG_CURSOR_END:
798 memmove(&m, p + sizeof(u_char), sizeof(MARK));
799 vtrace(sp, "%lu: %s: C_END: %u/%u\n", rno, msg, m.lno, m.cno);
800 break;
801 case LOG_LINE_APPEND:
802 memmove(&lno, p + sizeof(u_char), sizeof(db_recno_t));
803 vtrace(sp, "%lu: %s: APPEND: %lu\n", rno, msg, lno);
804 break;
805 case LOG_LINE_INSERT:
806 memmove(&lno, p + sizeof(u_char), sizeof(db_recno_t));
807 vtrace(sp, "%lu: %s: INSERT: %lu\n", rno, msg, lno);
808 break;
809 case LOG_LINE_DELETE:
810 memmove(&lno, p + sizeof(u_char), sizeof(db_recno_t));
811 vtrace(sp, "%lu: %s: DELETE: %lu\n", rno, msg, lno);
812 break;
813 case LOG_LINE_RESET_F:
814 memmove(&lno, p + sizeof(u_char), sizeof(db_recno_t));
815 vtrace(sp, "%lu: %s: RESET_F: %lu\n", rno, msg, lno);
816 break;
817 case LOG_LINE_RESET_B:
818 memmove(&lno, p + sizeof(u_char), sizeof(db_recno_t));
819 vtrace(sp, "%lu: %s: RESET_B: %lu\n", rno, msg, lno);
820 break;
821 case LOG_MARK:
822 memmove(&lm, p + sizeof(u_char), sizeof(LMARK));
823 vtrace(sp,
824 "%lu: %s: MARK: %u/%u\n", rno, msg, lm.lno, lm.cno);
825 break;
826 default:
827 abort();
830 #endif