1 /* $NetBSD: wapbl.c,v 1.3 2008/11/10 20:12:13 joerg Exp $ */
4 * Copyright (c) 2005,2008 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Wasabi Systems, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
32 /* This file contains fsck support for wapbl
34 #define WAPBL_INTERNAL
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: wapbl.c,v 1.3 2008/11/10 20:12:13 joerg Exp $");
52 #include <ufs/ufs/dinode.h>
53 #include <ufs/ufs/dir.h>
54 #include <ufs/ufs/ufs_bswap.h>
55 #include <ufs/ufs/ufs_wapbl.h>
56 #include <ufs/ffs/fs.h>
57 #include <ufs/ffs/ffs_extern.h>
59 #include <sys/wapbl.h>
64 #include "exitvalues.h"
67 wapbl_write(void *data
, size_t len
, struct vnode
*devvp
, daddr_t pbn
)
70 WAPBL_PRINTF(WAPBL_PRINT_IO
,
71 ("wapbl_write: %zd bytes at block %"PRId64
" on fd 0x%x\n",
72 len
, pbn
, fswritefd
));
73 bwrite(fswritefd
, data
, pbn
, len
);
78 wapbl_read(void *data
, size_t len
, struct vnode
*devvp
, daddr_t pbn
)
81 WAPBL_PRINTF(WAPBL_PRINT_IO
,
82 ("wapbl_read: %zd bytes at block %"PRId64
" on fd 0x%x\n",
84 bread(fsreadfd
, data
, pbn
, len
);
88 struct wapbl_replay
*wapbl_replay
;
96 error
= wapbl_replay_write(wapbl_replay
, 0);
98 pfatal("UNABLE TO REPLAY JOURNAL BLOCKS");
99 if (reply("CONTINUE") == 0) {
100 exit(FSCK_EXIT_CHECK_FAILED
);
103 wapbl_replay_stop(wapbl_replay
);
108 for (i
= 0; i
< wapbl_replay
->wr_inodescnt
; i
++) {
109 WAPBL_PRINTF(WAPBL_PRINT_REPLAY
,("wapbl_replay: "
110 "not cleaning inode %"PRIu32
" mode %"PRIo32
"\n",
111 wapbl_replay
->wr_inodes
[i
].wr_inumber
,
112 wapbl_replay
->wr_inodes
[i
].wr_imode
));
122 if (wapbl_replay_isopen(wapbl_replay
))
123 wapbl_replay_stop(wapbl_replay
);
124 wapbl_replay_free(wapbl_replay
);
130 read_wapbl(char *buf
, long size
, daddr_t blk
)
133 if (!wapbl_replay
|| !wapbl_replay_isopen(wapbl_replay
))
135 return wapbl_replay_read(wapbl_replay
, buf
, blk
, size
);
139 is_journal_inode(ino_t ino
)
144 if ((iswap32(DIP(dp
, flags
)) & SF_LOG
) != 0 &&
145 sblock
->fs_journal_version
== UFS_WAPBL_VERSION
&&
146 sblock
->fs_journal_location
== UFS_WAPBL_JOURNALLOC_IN_FILESYSTEM
&&
147 sblock
->fs_journallocs
[UFS_WAPBL_INFS_INO
] == ino
)
156 uint64_t addr
= 0, count
= 0, blksize
= 0;
160 wapbl_debug_print
= WAPBL_PRINT_ERROR
| WAPBL_PRINT_REPLAY
;
162 wapbl_debug_print
|= WAPBL_PRINT_IO
;
164 if (sblock
->fs_flags
& FS_DOWAPBL
) {
165 if (sblock
->fs_journal_version
!= UFS_WAPBL_VERSION
) {
166 pfatal("INVALID JOURNAL VERSION %d",
167 sblock
->fs_journal_version
);
168 if (reply("CONTINUE") == 0) {
169 exit(FSCK_EXIT_CHECK_FAILED
);
171 pwarn("CLEARING EXISTING JOURNAL\n");
172 sblock
->fs_flags
&= ~FS_DOWAPBL
;
174 ret
= FSCK_EXIT_CHECK_FAILED
;
176 switch(sblock
->fs_journal_location
) {
177 case UFS_WAPBL_JOURNALLOC_END_PARTITION
:
179 sblock
->fs_journallocs
[UFS_WAPBL_EPART_ADDR
];
181 sblock
->fs_journallocs
[UFS_WAPBL_EPART_COUNT
];
183 sblock
->fs_journallocs
[UFS_WAPBL_EPART_BLKSZ
];
185 case UFS_WAPBL_JOURNALLOC_IN_FILESYSTEM
:
187 sblock
->fs_journallocs
[UFS_WAPBL_INFS_ADDR
];
189 sblock
->fs_journallocs
[UFS_WAPBL_INFS_COUNT
];
191 sblock
->fs_journallocs
[UFS_WAPBL_INFS_BLKSZ
];
194 pfatal("INVALID JOURNAL LOCATION %d",
195 sblock
->fs_journal_location
);
196 if (reply("CONTINUE") == 0) {
197 exit(FSCK_EXIT_CHECK_FAILED
);
199 pwarn("CLEARING EXISTING JOURNAL\n");
200 sblock
->fs_flags
&= ~FS_DOWAPBL
;
201 sblock
->fs_journal_location
=
202 UFS_WAPBL_JOURNALLOC_NONE
;
204 ret
= FSCK_EXIT_CHECK_FAILED
;
207 if (sblock
->fs_flags
& FS_DOWAPBL
) {
208 error
= wapbl_replay_start(
209 &wapbl_replay
, 0, addr
, count
, blksize
);
212 "UNABLE TO READ JOURNAL FOR REPLAY");
213 if (reply("CONTINUE") == 0) {
214 exit(FSCK_EXIT_CHECK_FAILED
);
216 pwarn("CLEARING EXISTING JOURNAL\n");
217 sblock
->fs_flags
&= ~FS_DOWAPBL
;
219 ret
= FSCK_EXIT_CHECK_FAILED
;
225 * at this time fs_journal_flags can only be 0,
226 * UFS_WAPBL_FLAGS_CREATE_LOG or UFS_WAPBL_FLAGS_CLEAR_LOG.
227 * We can't have both flags at the same time.
229 switch (sblock
->fs_journal_flags
) {
232 case UFS_WAPBL_FLAGS_CREATE_LOG
:
233 case UFS_WAPBL_FLAGS_CLEAR_LOG
:
234 switch(sblock
->fs_journal_location
) {
235 case UFS_WAPBL_JOURNALLOC_END_PARTITION
:
236 case UFS_WAPBL_JOURNALLOC_IN_FILESYSTEM
:
238 case UFS_WAPBL_JOURNALLOC_NONE
:
239 if (sblock
->fs_journal_flags
==
240 UFS_WAPBL_FLAGS_CLEAR_LOG
)
244 pfatal("INVALID JOURNAL LOCATION %d",
245 sblock
->fs_journal_location
);
246 if (reply("CONTINUE") == 0) {
247 exit(FSCK_EXIT_CHECK_FAILED
);
249 pwarn("CLEARING JOURNAL FLAGS\n");
250 sblock
->fs_journal_flags
= 0;
251 sblock
->fs_journal_location
=
252 UFS_WAPBL_JOURNALLOC_NONE
;
254 ret
= FSCK_EXIT_CHECK_FAILED
;
259 pfatal("INVALID JOURNAL FLAGS %d",
260 sblock
->fs_journal_flags
);
261 if (reply("CONTINUE") == 0) {
262 exit(FSCK_EXIT_CHECK_FAILED
);
264 pwarn("CLEARING JOURNAL FLAGS\n");
265 sblock
->fs_journal_flags
= 0;
266 sblock
->fs_journal_location
=
267 UFS_WAPBL_JOURNALLOC_NONE
;
269 ret
= FSCK_EXIT_CHECK_FAILED
;