2002-04-09 05:47:30 +04:00
|
|
|
/* $NetBSD: ex_preserve.c,v 1.8 2002/04/09 01:47:33 thorpej Exp $ */
|
1998-01-09 11:03:16 +03:00
|
|
|
|
1994-01-24 08:52:58 +03:00
|
|
|
/*-
|
1994-03-28 08:28:20 +04:00
|
|
|
* Copyright (c) 1993, 1994
|
1994-01-24 08:52:58 +03:00
|
|
|
* The Regents of the University of California. All rights reserved.
|
1996-05-20 07:47:00 +04:00
|
|
|
* Copyright (c) 1993, 1994, 1995, 1996
|
|
|
|
* Keith Bostic. All rights reserved.
|
1994-01-24 08:52:58 +03:00
|
|
|
*
|
1996-05-20 07:47:00 +04:00
|
|
|
* See the LICENSE file for redistribution information.
|
1994-01-24 08:52:58 +03:00
|
|
|
*/
|
|
|
|
|
1996-05-20 07:47:00 +04:00
|
|
|
#include "config.h"
|
|
|
|
|
2002-04-09 05:47:30 +04:00
|
|
|
#include <sys/cdefs.h>
|
1994-01-24 08:52:58 +03:00
|
|
|
#ifndef lint
|
2002-04-09 05:47:30 +04:00
|
|
|
#if 0
|
1996-05-20 07:47:00 +04:00
|
|
|
static const char sccsid[] = "@(#)ex_preserve.c 10.12 (Berkeley) 4/27/96";
|
2002-04-09 05:47:30 +04:00
|
|
|
#else
|
|
|
|
__RCSID("$NetBSD");
|
|
|
|
#endif
|
1994-01-24 08:52:58 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
1994-03-28 08:28:20 +04:00
|
|
|
#include <sys/queue.h>
|
1994-01-24 08:52:58 +03:00
|
|
|
|
1994-03-28 08:28:20 +04:00
|
|
|
#include <bitstring.h>
|
1994-01-24 08:52:58 +03:00
|
|
|
#include <errno.h>
|
1994-03-28 08:28:20 +04:00
|
|
|
#include <limits.h>
|
|
|
|
#include <stdio.h>
|
1994-01-24 08:52:58 +03:00
|
|
|
#include <string.h>
|
|
|
|
|
1996-05-20 07:47:00 +04:00
|
|
|
#include "../common/common.h"
|
1994-01-24 08:52:58 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ex_preserve -- :pre[serve]
|
|
|
|
* Push the file to recovery.
|
1996-05-20 07:47:00 +04:00
|
|
|
*
|
|
|
|
* PUBLIC: int ex_preserve __P((SCR *, EXCMD *));
|
1994-01-24 08:52:58 +03:00
|
|
|
*/
|
|
|
|
int
|
1996-05-20 07:47:00 +04:00
|
|
|
ex_preserve(sp, cmdp)
|
1994-01-24 08:52:58 +03:00
|
|
|
SCR *sp;
|
1996-05-20 07:47:00 +04:00
|
|
|
EXCMD *cmdp;
|
1994-01-24 08:52:58 +03:00
|
|
|
{
|
|
|
|
recno_t lno;
|
|
|
|
|
1996-05-20 07:47:00 +04:00
|
|
|
NEEDFILE(sp, cmdp);
|
|
|
|
|
|
|
|
if (!F_ISSET(sp->ep, F_RCV_ON)) {
|
|
|
|
msgq(sp, M_ERR, "142|Preservation of this file not possible");
|
1994-01-24 08:52:58 +03:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If recovery not initialized, do so. */
|
1996-05-20 07:47:00 +04:00
|
|
|
if (F_ISSET(sp->ep, F_FIRSTMODIFY) && rcv_init(sp))
|
1994-01-24 08:52:58 +03:00
|
|
|
return (1);
|
|
|
|
|
|
|
|
/* Force the file to be read in, in case it hasn't yet. */
|
1996-05-20 07:47:00 +04:00
|
|
|
if (db_last(sp, &lno))
|
1994-01-24 08:52:58 +03:00
|
|
|
return (1);
|
|
|
|
|
|
|
|
/* Sync to disk. */
|
1996-05-20 07:47:00 +04:00
|
|
|
if (rcv_sync(sp, RCV_SNAPSHOT))
|
1994-01-24 08:52:58 +03:00
|
|
|
return (1);
|
|
|
|
|
1996-05-20 07:47:00 +04:00
|
|
|
msgq(sp, M_INFO, "143|File preserved");
|
1994-08-17 20:35:35 +04:00
|
|
|
return (0);
|
|
|
|
}
|
1994-01-24 08:52:58 +03:00
|
|
|
|
1994-08-17 20:35:35 +04:00
|
|
|
/*
|
|
|
|
* ex_recover -- :rec[over][!] file
|
1996-05-20 07:47:00 +04:00
|
|
|
* Recover the file.
|
1994-08-17 20:35:35 +04:00
|
|
|
*
|
1996-05-20 07:47:00 +04:00
|
|
|
* PUBLIC: int ex_recover __P((SCR *, EXCMD *));
|
1994-08-17 20:35:35 +04:00
|
|
|
*/
|
|
|
|
int
|
1996-05-20 07:47:00 +04:00
|
|
|
ex_recover(sp, cmdp)
|
1994-08-17 20:35:35 +04:00
|
|
|
SCR *sp;
|
1996-05-20 07:47:00 +04:00
|
|
|
EXCMD *cmdp;
|
1994-08-17 20:35:35 +04:00
|
|
|
{
|
|
|
|
ARGS *ap;
|
|
|
|
FREF *frp;
|
|
|
|
|
|
|
|
ap = cmdp->argv[0];
|
|
|
|
|
|
|
|
/* Set the alternate file name. */
|
|
|
|
set_alt_name(sp, ap->bp);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for modifications. Autowrite did not historically
|
|
|
|
* affect :recover.
|
|
|
|
*/
|
1996-05-20 07:47:00 +04:00
|
|
|
if (file_m2(sp, FL_ISSET(cmdp->iflags, E_C_FORCE)))
|
1994-08-17 20:35:35 +04:00
|
|
|
return (1);
|
|
|
|
|
|
|
|
/* Get a file structure for the file. */
|
|
|
|
if ((frp = file_add(sp, ap->bp)) == NULL)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
/* Set the recover bit. */
|
|
|
|
F_SET(frp, FR_RECOVER);
|
|
|
|
|
|
|
|
/* Switch files. */
|
1996-05-20 07:47:00 +04:00
|
|
|
if (file_init(sp, frp, NULL, FS_SETALT |
|
|
|
|
(FL_ISSET(cmdp->iflags, E_C_FORCE) ? FS_FORCE : 0)))
|
1994-08-17 20:35:35 +04:00
|
|
|
return (1);
|
1996-05-20 07:47:00 +04:00
|
|
|
|
|
|
|
F_SET(sp, SC_FSWITCH);
|
1994-01-24 08:52:58 +03:00
|
|
|
return (0);
|
|
|
|
}
|