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