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