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