Home | History | Annotate | Line # | Download | only in fsck_ffs
wapbl.c revision 1.1.2.4
      1 /*	$NetBSD: wapbl.c,v 1.1.2.4 2008/06/12 08:39:21 martin Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2005,2008 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Wasabi Systems, Inc.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /* This file contains fsck support for wapbl
     33  */
     34 
     35 #include <sys/cdefs.h>
     36 __KERNEL_RCSID(0, "$NetBSD: wapbl.c,v 1.1.2.4 2008/06/12 08:39:21 martin Exp $");
     37 
     38 #include <sys/time.h>
     39 #include <sys/types.h>
     40 #include <sys/uio.h>
     41 
     42 #include <assert.h>
     43 #include <errno.h>
     44 #include <inttypes.h>
     45 #include <stdio.h>
     46 #include <stdbool.h>
     47 #include <stdlib.h>
     48 #include <string.h>
     49 #include <unistd.h>
     50 
     51 #include <ufs/ufs/dinode.h>
     52 #include <ufs/ufs/dir.h>
     53 #include <ufs/ufs/ufs_bswap.h>
     54 #include <ufs/ffs/fs.h>
     55 #include <ufs/ffs/ffs_extern.h>
     56 
     57 #include <sys/wapbl.h>
     58 
     59 #include "fsck.h"
     60 #include "fsutil.h"
     61 #include "extern.h"
     62 #include "exitvalues.h"
     63 
     64 int
     65 wapbl_write(void *data, size_t len, struct vnode *devvp, daddr_t pbn)
     66 {
     67 
     68 	WAPBL_PRINTF(WAPBL_PRINT_IO,
     69 		("wapbl_write: %zd bytes at block %"PRId64" on fd 0x%x\n",
     70 		len, pbn, fswritefd));
     71 	bwrite(fswritefd, data, pbn, len);
     72 	return 0;
     73 }
     74 
     75 int
     76 wapbl_read(void *data, size_t len, struct vnode *devvp, daddr_t pbn)
     77 {
     78 
     79 	WAPBL_PRINTF(WAPBL_PRINT_IO,
     80 		("wapbl_read: %zd bytes at block %"PRId64" on fd 0x%x\n",
     81 		len, pbn, fsreadfd));
     82 	bread(fsreadfd, data, pbn, len);
     83 	return 0;
     84 }
     85 
     86 struct wapbl_replay *wapbl_replay;
     87 
     88 void
     89 replay_wapbl(void)
     90 {
     91 	int error;
     92 
     93 	if (debug)
     94 		wapbl_debug_print = WAPBL_PRINT_ERROR | WAPBL_PRINT_REPLAY;
     95 	if (debug > 1)
     96 		wapbl_debug_print |= WAPBL_PRINT_IO;
     97 	error = wapbl_replay_start(&wapbl_replay,
     98 			0,
     99 			fsbtodb(sblock, sblock->fs_size),
    100 					/* journal is after file system */
    101 			0 /* XXX */,
    102 			dev_bsize);
    103 	if (error) {
    104 		pfatal("UNABLE TO READ JOURNAL FOR REPLAY");
    105 		if (reply("CONTINUE") == 0) {
    106 			exit(FSCK_EXIT_CHECK_FAILED);
    107 		}
    108 		return;
    109 	}
    110 	if (!nflag) {
    111 		error = wapbl_replay_write(wapbl_replay, 0);
    112 		if (error) {
    113 			pfatal("UNABLE TO REPLAY JOURNAL BLOCKS");
    114 			if (reply("CONTINUE") == 0) {
    115 				exit(FSCK_EXIT_CHECK_FAILED);
    116 			}
    117 		} else {
    118 			wapbl_replay_stop(wapbl_replay);
    119 		}
    120 	}
    121 	{
    122 		int i;
    123 		for (i = 0; i < wapbl_replay->wr_inodescnt; i++) {
    124 			WAPBL_PRINTF(WAPBL_PRINT_REPLAY,("wapbl_replay: "
    125 			    "not cleaning inode %"PRIu32" mode %"PRIo32"\n",
    126 			    wapbl_replay->wr_inodes[i].wr_inumber,
    127 			    wapbl_replay->wr_inodes[i].wr_imode));
    128 		}
    129 	}
    130 }
    131 
    132 void
    133 cleanup_wapbl(void)
    134 {
    135 
    136 	if (wapbl_replay) {
    137 		if (wapbl_replay_isopen(wapbl_replay))
    138 			wapbl_replay_stop(wapbl_replay);
    139 		wapbl_replay_free(wapbl_replay);
    140 		wapbl_replay = 0;
    141 	}
    142 }
    143 
    144 int
    145 read_wapbl(char *buf, long size, daddr_t blk)
    146 {
    147 
    148 	if (!wapbl_replay || !wapbl_replay_isopen(wapbl_replay))
    149 		return 0;
    150 	return wapbl_replay_read(wapbl_replay, buf, blk, size);
    151 }
    152