kernel - Fix auto port assignment collision in network code
[dragonfly.git] / contrib / nvi2 / ex / ex_preserve.c
blobbbd30bb9dbe5d961b2d9b390459db5c1ada88446
1 /*-
2 * Copyright (c) 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 * Copyright (c) 1993, 1994, 1995, 1996
5 * Keith Bostic. All rights reserved.
7 * See the LICENSE file for redistribution information.
8 */
10 #include "config.h"
12 #include <sys/types.h>
13 #include <sys/queue.h>
14 #include <sys/time.h>
16 #include <bitstring.h>
17 #include <errno.h>
18 #include <limits.h>
19 #include <stdio.h>
20 #include <string.h>
22 #include "../common/common.h"
25 * ex_preserve -- :pre[serve]
26 * Push the file to recovery.
28 * PUBLIC: int ex_preserve(SCR *, EXCMD *);
30 int
31 ex_preserve(SCR *sp, EXCMD *cmdp)
33 recno_t lno;
35 NEEDFILE(sp, cmdp);
37 if (!F_ISSET(sp->ep, F_RCV_ON)) {
38 msgq(sp, M_ERR, "142|Preservation of this file not possible");
39 return (1);
42 /* If recovery not initialized, do so. */
43 if (F_ISSET(sp->ep, F_FIRSTMODIFY) && rcv_init(sp))
44 return (1);
46 /* Force the file to be read in, in case it hasn't yet. */
47 if (db_last(sp, &lno))
48 return (1);
50 /* Sync to disk. */
51 if (rcv_sync(sp, RCV_SNAPSHOT))
52 return (1);
54 msgq(sp, M_INFO, "143|File preserved");
55 return (0);
59 * ex_recover -- :rec[over][!] file
60 * Recover the file.
62 * PUBLIC: int ex_recover(SCR *, EXCMD *);
64 int
65 ex_recover(SCR *sp, EXCMD *cmdp)
67 ARGS *ap;
68 FREF *frp;
69 char *np;
70 size_t nlen;
72 ap = cmdp->argv[0];
74 /* Set the alternate file name. */
75 INT2CHAR(sp, ap->bp, ap->len+1, np, nlen);
76 set_alt_name(sp, np);
79 * Check for modifications. Autowrite did not historically
80 * affect :recover.
82 if (file_m2(sp, FL_ISSET(cmdp->iflags, E_C_FORCE)))
83 return (1);
85 /* Get a file structure for the file. */
86 INT2CHAR(sp, ap->bp, ap->len+1, np, nlen);
87 if ((frp = file_add(sp, np)) == NULL)
88 return (1);
90 /* Set the recover bit. */
91 F_SET(frp, FR_RECOVER);
93 /* Switch files. */
94 if (file_init(sp, frp, NULL, FS_SETALT |
95 (FL_ISSET(cmdp->iflags, E_C_FORCE) ? FS_FORCE : 0)))
96 return (1);
98 F_SET(sp, SC_FSWITCH);
99 return (0);