Fri Jul 24 06:56:42 2015 UTC ()
Switch to accessor functions for elements of the LFS on-disk
superblock. This will allow switching between 32/64 bit forms on the
fly; it will also allow handling LFS_EI reasonably tidily. (That
currently doesn't work on the superblock.)

It also gets rid of cpp abuse in the form of fake structure member
macros.

Also, instead of doing sleep/wakeup on &lfs_avail and &lfs_nextseg
inside the on-disk superblock, add extra elements to the in-memory
struct lfs for this. (XXX: these should be changed to condvars, but
not right now)

XXX: this migrates a structure needed by the lfs code in libsa (struct
salfs) into lfs.h, where it doesn't belong, but for the time being
this is necessary in order to allow the accessors (and the various
lfs macros and other goop that relies on them) to compile.


(dholland)
diff -r1.5 -r1.6 src/libexec/lfs_cleanerd/cleaner.h
diff -r1.24 -r1.25 src/libexec/lfs_cleanerd/coalesce.c
diff -r1.38 -r1.39 src/libexec/lfs_cleanerd/lfs_cleanerd.c
diff -r1.19 -r1.20 src/sbin/dump_lfs/lfs_inode.c
diff -r1.33 -r1.34 src/sbin/fsck_lfs/dir.c
diff -r1.54 -r1.55 src/sbin/fsck_lfs/inode.c
diff -r1.45 -r1.46 src/sbin/fsck_lfs/lfs.c
diff -r1.49 -r1.50 src/sbin/fsck_lfs/main.c
diff -r1.35 -r1.36 src/sbin/fsck_lfs/pass0.c
diff -r1.37 -r1.38 src/sbin/fsck_lfs/pass1.c
diff -r1.37 -r1.38 src/sbin/fsck_lfs/utilities.c
diff -r1.23 -r1.24 src/sbin/fsck_lfs/pass4.c
diff -r1.29 -r1.30 src/sbin/fsck_lfs/pass5.c
diff -r1.34 -r1.35 src/sbin/fsck_lfs/pass6.c
diff -r1.31 -r1.32 src/sbin/fsck_lfs/segwrite.c
diff -r1.4 -r1.5 src/sbin/fsck_lfs/segwrite.h
diff -r1.46 -r1.47 src/sbin/fsck_lfs/setup.c
diff -r1.31 -r1.32 src/sbin/newfs_lfs/make_lfs.c
diff -r1.9 -r1.10 src/sbin/resize_lfs/resize_lfs.c
diff -r1.25 -r1.26 src/sbin/scan_ffs/scan_ffs.c
diff -r1.10 -r1.11 src/sys/lib/libsa/lfsv1.c
diff -r1.10 -r1.11 src/sys/lib/libsa/lfsv2.c
diff -r1.66 -r1.67 src/sys/lib/libsa/ufs.c
diff -r1.163 -r1.164 src/sys/ufs/lfs/lfs.h
diff -r1.121 -r1.122 src/sys/ufs/lfs/lfs_alloc.c
diff -r1.81 -r1.82 src/sys/ufs/lfs/lfs_balloc.c
diff -r1.81 -r1.82 src/sys/ufs/lfs/lfs_subr.c
diff -r1.128 -r1.129 src/sys/ufs/lfs/lfs_bio.c
diff -r1.137 -r1.138 src/sys/ufs/lfs/lfs_inode.c
diff -r1.1 -r1.2 src/sys/ufs/lfs/lfs_pages.c
diff -r1.21 -r1.22 src/sys/ufs/lfs/lfs_rfw.c
diff -r1.241 -r1.242 src/sys/ufs/lfs/lfs_segment.c
diff -r1.160 -r1.161 src/sys/ufs/lfs/lfs_syscalls.c
diff -r1.326 -r1.327 src/sys/ufs/lfs/lfs_vfsops.c
diff -r1.273 -r1.274 src/sys/ufs/lfs/lfs_vnops.c
diff -r1.12 -r1.13 src/sys/ufs/lfs/ulfs_inode.h
diff -r1.18 -r1.19 src/sys/ufs/lfs/ulfs_quota2.c
diff -r1.17 -r1.18 src/sys/ufs/lfs/ulfs_readwrite.c
diff -r1.42 -r1.43 src/usr.sbin/dumplfs/dumplfs.c

cvs diff -r1.5 -r1.6 src/libexec/lfs_cleanerd/cleaner.h (expand / switch to unified diff)

--- src/libexec/lfs_cleanerd/cleaner.h 2009/03/16 00:08:10 1.5
+++ src/libexec/lfs_cleanerd/cleaner.h 2015/07/24 06:56:41 1.6
@@ -6,47 +6,88 @@ @@ -6,47 +6,88 @@
6 */ 6 */
7struct clfs_seguse { 7struct clfs_seguse {
8 u_int32_t nbytes; 8 u_int32_t nbytes;
9 u_int32_t nsums; 9 u_int32_t nsums;
10 u_int32_t flags; 10 u_int32_t flags;
11 u_int64_t lastmod; 11 u_int64_t lastmod;
12 u_int64_t priority; 12 u_int64_t priority;
13}; 13};
14 14
15/* 15/*
16 * The cleaner's view of the superblock data structure. 16 * The cleaner's view of the superblock data structure.
17 */ 17 */
18struct clfs { 18struct clfs {
19 struct dlfs lfs_dlfs; /* Leverage LFS lfs_* defines here */ 19 struct dlfs lfs_dlfs;
20 20
21 /* Ifile */ 21 /* Ifile */
22 int clfs_ifilefd; /* Ifile file descriptor */ 22 int clfs_ifilefd; /* Ifile file descriptor */
23 struct uvnode *lfs_ivnode; /* Ifile vnode */ 23 struct uvnode *lfs_ivnode; /* Ifile vnode */
24 struct lfs_fhandle clfs_ifilefh; /* Ifile file handle */ 24 struct lfs_fhandle clfs_ifilefh; /* Ifile file handle */
25 25
26 /* Device */ 26 /* Device */
27 int clfs_devfd; /* Device file descriptor */ 27 int clfs_devfd; /* Device file descriptor */
28 struct uvnode *clfs_devvp; /* Device vnode */ 28 struct uvnode *clfs_devvp; /* Device vnode */
29 char *clfs_dev; /* Name of device */ 29 char *clfs_dev; /* Name of device */
30 30
31 /* Cache of segment status */ 31 /* Cache of segment status */
32 struct clfs_seguse *clfs_segtab; /* Abbreviated seguse table */ 32 struct clfs_seguse *clfs_segtab; /* Abbreviated seguse table */
33 struct clfs_seguse **clfs_segtabp; /* pointers to same */ 33 struct clfs_seguse **clfs_segtabp; /* pointers to same */
34 34
35 /* Progress status */ 35 /* Progress status */
36 int clfs_nactive; /* How many segments' blocks we have */ 36 int clfs_nactive; /* How many segments' blocks we have */
37 int clfs_onhold; /* If cleaning this fs is on hold */ 37 int clfs_onhold; /* If cleaning this fs is on hold */
38}; 38};
39 39
 40/* ugh... */
 41#define CLFS_DEF_SB_ACCESSOR(type, field) \
 42 static __unused inline type \
 43 clfs_sb_get##field(struct clfs *fs) \
 44 { \
 45 return fs->lfs_dlfs.dlfs_##field; \
 46 } \
 47 static __unused inline void \
 48 clfs_sb_set##field(struct clfs *fs, type val) \
 49 { \
 50 fs->lfs_dlfs.dlfs_##field = val; \
 51 } \
 52 static __unused inline void \
 53 clfs_sb_add##field(struct clfs *fs, type val) \
 54 { \
 55 fs->lfs_dlfs.dlfs_##field += val; \
 56 }
 57
 58/* more ugh... */
 59CLFS_DEF_SB_ACCESSOR(u_int32_t, ssize);
 60CLFS_DEF_SB_ACCESSOR(u_int32_t, bsize);
 61CLFS_DEF_SB_ACCESSOR(u_int32_t, fsize);
 62CLFS_DEF_SB_ACCESSOR(u_int32_t, frag);
 63CLFS_DEF_SB_ACCESSOR(u_int32_t, ifile);
 64CLFS_DEF_SB_ACCESSOR(u_int32_t, ifpb);
 65CLFS_DEF_SB_ACCESSOR(u_int32_t, sepb);
 66CLFS_DEF_SB_ACCESSOR(u_int32_t, nseg);
 67CLFS_DEF_SB_ACCESSOR(u_int32_t, cleansz);
 68CLFS_DEF_SB_ACCESSOR(u_int32_t, segtabsz);
 69
 70/* still more ugh... */
 71#define lfs_sb_getssize(fs) clfs_sb_getssize(fs)
 72#define lfs_sb_getbsize(fs) clfs_sb_getbsize(fs)
 73#define lfs_sb_getfsize(fs) clfs_sb_getfsize(fs)
 74#define lfs_sb_getfrag(fs) clfs_sb_getfrag(fs)
 75#define lfs_sb_getifpb(fs) clfs_sb_getifpb(fs)
 76#define lfs_sb_getsepb(fs) clfs_sb_getsepb(fs)
 77#define lfs_sb_getnseg(fs) clfs_sb_getnseg(fs)
 78#define lfs_sb_getcleansz(fs) clfs_sb_getcleansz(fs)
 79#define lfs_sb_getsegtabsz(fs) clfs_sb_getsegtabsz(fs)
 80
40/* 81/*
41 * Fraction of the could-be-clean segments required to be clean. 82 * Fraction of the could-be-clean segments required to be clean.
42 */ 83 */
43#define BUSY_LIM 0.5 84#define BUSY_LIM 0.5
44#define IDLE_LIM 0.9 85#define IDLE_LIM 0.9
45 86
46__BEGIN_DECLS 87__BEGIN_DECLS
47 88
48/* lfs_cleanerd.c */ 89/* lfs_cleanerd.c */
49void pwarn(const char *, ...); 90void pwarn(const char *, ...);
50void calc_cb(struct clfs *, int, struct clfs_seguse *); 91void calc_cb(struct clfs *, int, struct clfs_seguse *);
51int clean_fs(struct clfs *, CLEANERINFO *); 92int clean_fs(struct clfs *, CLEANERINFO *);
52void dlog(const char *, ...); 93void dlog(const char *, ...);

cvs diff -r1.24 -r1.25 src/libexec/lfs_cleanerd/coalesce.c (expand / switch to unified diff)

--- src/libexec/lfs_cleanerd/coalesce.c 2015/03/29 19:35:58 1.24
+++ src/libexec/lfs_cleanerd/coalesce.c 2015/07/24 06:56:41 1.25
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: coalesce.c,v 1.24 2015/03/29 19:35:58 chopps Exp $ */ 1/* $NetBSD: coalesce.c,v 1.25 2015/07/24 06:56:41 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2002, 2005 The NetBSD Foundation, Inc. 4 * Copyright (c) 2002, 2005 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant@hhhh.org>. 8 * by Konrad E. Schroder <perseant@hhhh.org>.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -205,30 +205,30 @@ clean_inode(struct clfs *fs, ino_t ino) @@ -205,30 +205,30 @@ clean_inode(struct clfs *fs, ino_t ino)
205 retval = COALESCE_BADBMAPV; 205 retval = COALESCE_BADBMAPV;
206 goto out; 206 goto out;
207 } 207 }
208#if 0 208#if 0
209 for (i = 0; i < nb; i++) { 209 for (i = 0; i < nb; i++) {
210 printf("bi_size = %d, bi_ino = %d, " 210 printf("bi_size = %d, bi_ino = %d, "
211 "bi_lbn = %d, bi_daddr = %d\n", 211 "bi_lbn = %d, bi_daddr = %d\n",
212 bip[i].bi_size, bip[i].bi_inode, bip[i].bi_lbn, 212 bip[i].bi_size, bip[i].bi_inode, bip[i].bi_lbn,
213 bip[i].bi_daddr); 213 bip[i].bi_daddr);
214 } 214 }
215#endif 215#endif
216 noff = toff = 0; 216 noff = toff = 0;
217 for (i = 1; i < nb; i++) { 217 for (i = 1; i < nb; i++) {
218 if (bip[i].bi_daddr != bip[i - 1].bi_daddr + fs->lfs_frag) 218 if (bip[i].bi_daddr != bip[i - 1].bi_daddr + clfs_sb_getfrag(fs))
219 ++noff; 219 ++noff;
220 toff += abs(bip[i].bi_daddr - bip[i - 1].bi_daddr 220 toff += abs(bip[i].bi_daddr - bip[i - 1].bi_daddr
221 - fs->lfs_frag) >> fs->lfs_fbshift; 221 - clfs_sb_getfrag(fs)) >> fs->lfs_fbshift;
222 } 222 }
223 223
224 /* 224 /*
225 * If this file is not discontinuous, there's no point in rewriting it. 225 * If this file is not discontinuous, there's no point in rewriting it.
226 * 226 *
227 * Explicitly allow a certain amount of discontinuity, since large 227 * Explicitly allow a certain amount of discontinuity, since large
228 * files will be broken among segments and medium-sized files 228 * files will be broken among segments and medium-sized files
229 * can have a break or two and it's okay. 229 * can have a break or two and it's okay.
230 */ 230 */
231 if (nb <= 1 || noff == 0 || noff < log2int(nb) || 231 if (nb <= 1 || noff == 0 || noff < log2int(nb) ||
232 lfs_segtod(fs, noff) * 2 < nb) { 232 lfs_segtod(fs, noff) * 2 < nb) {
233 retval = COALESCE_NOTWORTHIT; 233 retval = COALESCE_NOTWORTHIT;
234 goto out; 234 goto out;
@@ -287,27 +287,27 @@ clean_inode(struct clfs *fs, ino_t ino) @@ -287,27 +287,27 @@ clean_inode(struct clfs *fs, ino_t ino)
287 } 287 }
288 if (debug) 288 if (debug)
289 syslog(LOG_DEBUG, "ino %llu markv %d blocks", 289 syslog(LOG_DEBUG, "ino %llu markv %d blocks",
290 (unsigned long long)ino, nb); 290 (unsigned long long)ino, nb);
291 291
292 /* 292 /*
293 * Write in segment-sized chunks. If at any point we'd write more 293 * Write in segment-sized chunks. If at any point we'd write more
294 * than half of the available segments, sleep until that's not 294 * than half of the available segments, sleep until that's not
295 * true any more. 295 * true any more.
296 */ 296 */
297 bps = lfs_segtod(fs, 1); 297 bps = lfs_segtod(fs, 1);
298 for (tbip = bip; tbip < bip + nb; tbip += bps) { 298 for (tbip = bip; tbip < bip + nb; tbip += bps) {
299 do { 299 do {
300 bread(fs->lfs_ivnode, 0, fs->lfs_bsize, 0, &bp); 300 bread(fs->lfs_ivnode, 0, clfs_sb_getbsize(fs), 0, &bp);
301 cip = *(CLEANERINFO *)bp->b_data; 301 cip = *(CLEANERINFO *)bp->b_data;
302 brelse(bp, B_INVAL); 302 brelse(bp, B_INVAL);
303 303
304 if (cip.clean < 4) /* XXX magic number 4 */ 304 if (cip.clean < 4) /* XXX magic number 4 */
305 kops.ko_fcntl(fs->clfs_ifilefd, 305 kops.ko_fcntl(fs->clfs_ifilefd,
306 LFCNSEGWAIT, NULL); 306 LFCNSEGWAIT, NULL);
307 } while(cip.clean < 4); 307 } while(cip.clean < 4);
308 308
309 lim.blkiov = tbip; 309 lim.blkiov = tbip;
310 lim.blkcnt = (tbip + bps < bip + nb ? bps : nb % bps); 310 lim.blkcnt = (tbip + bps < bip + nb ? bps : nb % bps);
311 if (kops.ko_fcntl(fs->clfs_ifilefd, LFCNMARKV, &lim) < 0) { 311 if (kops.ko_fcntl(fs->clfs_ifilefd, LFCNMARKV, &lim) < 0) {
312 retval = COALESCE_BADMARKV; 312 retval = COALESCE_BADMARKV;
313 goto out; 313 goto out;
@@ -329,28 +329,28 @@ out: @@ -329,28 +329,28 @@ out:
329/* 329/*
330 * Try coalescing every inode in the filesystem. 330 * Try coalescing every inode in the filesystem.
331 * Return the number of inodes actually altered. 331 * Return the number of inodes actually altered.
332 */ 332 */
333int clean_all_inodes(struct clfs *fs) 333int clean_all_inodes(struct clfs *fs)
334{ 334{
335 int i, r, maxino; 335 int i, r, maxino;
336 int totals[COALESCE_MAXERROR]; 336 int totals[COALESCE_MAXERROR];
337 struct stat st; 337 struct stat st;
338 338
339 memset(totals, 0, sizeof(totals)); 339 memset(totals, 0, sizeof(totals));
340 340
341 fstat(fs->clfs_ifilefd, &st); 341 fstat(fs->clfs_ifilefd, &st);
342 maxino = fs->lfs_ifpb * (st.st_size >> fs->lfs_bshift) - 342 maxino = lfs_sb_getifpb(fs) * (st.st_size >> fs->lfs_bshift) -
343 fs->lfs_segtabsz - fs->lfs_cleansz; 343 lfs_sb_getsegtabsz(fs) - lfs_sb_getcleansz(fs);
344 344
345 for (i = 0; i < maxino; i++) { 345 for (i = 0; i < maxino; i++) {
346 r = clean_inode(fs, i); 346 r = clean_inode(fs, i);
347 ++totals[r]; 347 ++totals[r];
348 } 348 }
349 349
350 for (i = 0; i < COALESCE_MAXERROR; i++) 350 for (i = 0; i < COALESCE_MAXERROR; i++)
351 if (totals[i]) 351 if (totals[i])
352 syslog(LOG_DEBUG, "%s: %d", coalesce_return[i], 352 syslog(LOG_DEBUG, "%s: %d", coalesce_return[i],
353 totals[i]); 353 totals[i]);
354  354
355 return totals[COALESCE_OK]; 355 return totals[COALESCE_OK];
356} 356}

cvs diff -r1.38 -r1.39 src/libexec/lfs_cleanerd/lfs_cleanerd.c (expand / switch to unified diff)

--- src/libexec/lfs_cleanerd/lfs_cleanerd.c 2015/03/29 19:35:58 1.38
+++ src/libexec/lfs_cleanerd/lfs_cleanerd.c 2015/07/24 06:56:41 1.39
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lfs_cleanerd.c,v 1.38 2015/03/29 19:35:58 chopps Exp $ */ 1/* $NetBSD: lfs_cleanerd.c,v 1.39 2015/07/24 06:56:41 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2005 The NetBSD Foundation, Inc. 4 * Copyright (c) 2005 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant@hhhh.org>. 8 * by Konrad E. Schroder <perseant@hhhh.org>.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -254,28 +254,28 @@ init_fs(struct clfs *fs, char *fsname) @@ -254,28 +254,28 @@ init_fs(struct clfs *fs, char *fsname)
254 memcpy(&(fs->lfs_dlfs), sbuf, sizeof(struct dlfs)); 254 memcpy(&(fs->lfs_dlfs), sbuf, sizeof(struct dlfs));
255 free(sbuf); 255 free(sbuf);
256 256
257 /* If this is not a version 2 filesystem, complain and exit */ 257 /* If this is not a version 2 filesystem, complain and exit */
258 if (fs->lfs_version != 2) { 258 if (fs->lfs_version != 2) {
259 syslog(LOG_ERR, "%s: not a version 2 LFS", fsname); 259 syslog(LOG_ERR, "%s: not a version 2 LFS", fsname);
260 return -1; 260 return -1;
261 } 261 }
262 262
263 /* Assume fsname is the mounted name */ 263 /* Assume fsname is the mounted name */
264 strncpy((char *)fs->lfs_fsmnt, fsname, MNAMELEN); 264 strncpy((char *)fs->lfs_fsmnt, fsname, MNAMELEN);
265 265
266 /* Set up vnodes for Ifile and raw device */ 266 /* Set up vnodes for Ifile and raw device */
267 fs->lfs_ivnode = fd_vget(fs->clfs_ifilefd, fs->lfs_bsize, 0, 0); 267 fs->lfs_ivnode = fd_vget(fs->clfs_ifilefd, clfs_sb_getbsize(fs), 0, 0);
268 fs->clfs_devvp = fd_vget(fs->clfs_devfd, fs->lfs_fsize, fs->lfs_ssize, 268 fs->clfs_devvp = fd_vget(fs->clfs_devfd, clfs_sb_getfsize(fs), clfs_sb_getssize(fs),
269 atatime); 269 atatime);
270 270
271 /* Allocate and clear segtab */ 271 /* Allocate and clear segtab */
272 fs->clfs_segtab = (struct clfs_seguse *)malloc(fs->lfs_nseg * 272 fs->clfs_segtab = (struct clfs_seguse *)malloc(fs->lfs_nseg *
273 sizeof(*fs->clfs_segtab)); 273 sizeof(*fs->clfs_segtab));
274 fs->clfs_segtabp = (struct clfs_seguse **)malloc(fs->lfs_nseg * 274 fs->clfs_segtabp = (struct clfs_seguse **)malloc(fs->lfs_nseg *
275 sizeof(*fs->clfs_segtabp)); 275 sizeof(*fs->clfs_segtabp));
276 if (fs->clfs_segtab == NULL || fs->clfs_segtabp == NULL) { 276 if (fs->clfs_segtab == NULL || fs->clfs_segtabp == NULL) {
277 syslog(LOG_ERR, "%s: couldn't malloc segment table: %m", 277 syslog(LOG_ERR, "%s: couldn't malloc segment table: %m",
278 fs->clfs_dev); 278 fs->clfs_dev);
279 return -1; 279 return -1;
280 } 280 }
281 281
@@ -302,50 +302,51 @@ reload_ifile(struct clfs *fs) @@ -302,50 +302,51 @@ reload_ifile(struct clfs *fs)
302 extern int hashmax; 302 extern int hashmax;
303 303
304 while ((bp = LIST_FIRST(&fs->lfs_ivnode->v_dirtyblkhd)) != NULL) { 304 while ((bp = LIST_FIRST(&fs->lfs_ivnode->v_dirtyblkhd)) != NULL) {
305 bremfree(bp); 305 bremfree(bp);
306 buf_destroy(bp); 306 buf_destroy(bp);
307 } 307 }
308 while ((bp = LIST_FIRST(&fs->lfs_ivnode->v_cleanblkhd)) != NULL) { 308 while ((bp = LIST_FIRST(&fs->lfs_ivnode->v_cleanblkhd)) != NULL) {
309 bremfree(bp); 309 bremfree(bp);
310 buf_destroy(bp); 310 buf_destroy(bp);
311 } 311 }
312 312
313 /* If Ifile is larger than buffer cache, rehash */ 313 /* If Ifile is larger than buffer cache, rehash */
314 fstat(fs->clfs_ifilefd, &st); 314 fstat(fs->clfs_ifilefd, &st);
315 if (st.st_size / fs->lfs_bsize > hashmax) { 315 if (st.st_size / clfs_sb_getbsize(fs) > hashmax) {
316 ohashmax = hashmax; 316 ohashmax = hashmax;
317 bufrehash(st.st_size / fs->lfs_bsize); 317 bufrehash(st.st_size / clfs_sb_getbsize(fs));
318 dlog("%s: resized buffer hash from %d to %d", 318 dlog("%s: resized buffer hash from %d to %d",
319 fs->lfs_fsmnt, ohashmax, hashmax); 319 fs->lfs_fsmnt, ohashmax, hashmax);
320 } 320 }
321} 321}
322 322
323/* 323/*
324 * Get IFILE entry for the given inode, store in ifpp. The buffer 324 * Get IFILE entry for the given inode, store in ifpp. The buffer
325 * which contains that data is returned in bpp, and must be brelse()d 325 * which contains that data is returned in bpp, and must be brelse()d
326 * by the caller. 326 * by the caller.
327 */ 327 */
328void 328void
329lfs_ientry(IFILE **ifpp, struct clfs *fs, ino_t ino, struct ubuf **bpp) 329lfs_ientry(IFILE **ifpp, struct clfs *fs, ino_t ino, struct ubuf **bpp)
330{ 330{
331 int error; 331 int error;
332 332
333 error = bread(fs->lfs_ivnode, ino / fs->lfs_ifpb + fs->lfs_cleansz + 333 error = bread(fs->lfs_ivnode,
334 fs->lfs_segtabsz, fs->lfs_bsize, 0, bpp); 334 ino / lfs_sb_getifpb(fs) + lfs_sb_getcleansz(fs) +
 335 lfs_sb_getsegtabsz(fs), clfs_sb_getbsize(fs), 0, bpp);
335 if (error) 336 if (error)
336 syslog(LOG_ERR, "%s: ientry failed for ino %d", 337 syslog(LOG_ERR, "%s: ientry failed for ino %d",
337 fs->lfs_fsmnt, (int)ino); 338 fs->lfs_fsmnt, (int)ino);
338 *ifpp = (IFILE *)(*bpp)->b_data + ino % fs->lfs_ifpb; 339 *ifpp = (IFILE *)(*bpp)->b_data + ino % lfs_sb_getifpb(fs);
339 return; 340 return;
340} 341}
341 342
342#ifdef TEST_PATTERN 343#ifdef TEST_PATTERN
343/* 344/*
344 * Check ULFS_ROOTINO for file data. The assumption is that we are running 345 * Check ULFS_ROOTINO for file data. The assumption is that we are running
345 * the "twofiles" test with the rest of the filesystem empty. Files 346 * the "twofiles" test with the rest of the filesystem empty. Files
346 * created by "twofiles" match the test pattern, but ULFS_ROOTINO and the 347 * created by "twofiles" match the test pattern, but ULFS_ROOTINO and the
347 * executable itself (assumed to be inode 3) should not match. 348 * executable itself (assumed to be inode 3) should not match.
348 */ 349 */
349static void 350static void
350check_test_pattern(BLOCK_INFO *bip) 351check_test_pattern(BLOCK_INFO *bip)
351{ 352{
@@ -503,27 +504,27 @@ parse_pseg(struct clfs *fs, daddr_t dadd @@ -503,27 +504,27 @@ parse_pseg(struct clfs *fs, daddr_t dadd
503 504
504 /* 505 /*
505 * If this finfo has nblocks==0, it was written wrong. 506 * If this finfo has nblocks==0, it was written wrong.
506 * Kernels with this problem always wrote this zero-sized 507 * Kernels with this problem always wrote this zero-sized
507 * finfo last, so just ignore it. 508 * finfo last, so just ignore it.
508 */ 509 */
509 if (fip->fi_nblocks == 0) { 510 if (fip->fi_nblocks == 0) {
510#ifdef REPAIR_ZERO_FINFO 511#ifdef REPAIR_ZERO_FINFO
511 struct ubuf *nbp; 512 struct ubuf *nbp;
512 SEGSUM *nssp; 513 SEGSUM *nssp;
513 514
514 syslog(LOG_WARNING, "fixing short FINFO at %x (seg %d)", 515 syslog(LOG_WARNING, "fixing short FINFO at %x (seg %d)",
515 odaddr, lfs_dtosn(fs, odaddr)); 516 odaddr, lfs_dtosn(fs, odaddr));
516 bread(fs->clfs_devvp, odaddr, fs->lfs_fsize, 517 bread(fs->clfs_devvp, odaddr, clfs_sb_getfsize(fs),
517 0, &nbp); 518 0, &nbp);
518 nssp = (SEGSUM *)nbp->b_data; 519 nssp = (SEGSUM *)nbp->b_data;
519 --nssp->ss_nfinfo; 520 --nssp->ss_nfinfo;
520 nssp->ss_sumsum = cksum(&nssp->ss_datasum, 521 nssp->ss_sumsum = cksum(&nssp->ss_datasum,
521 fs->lfs_sumsize - sizeof(nssp->ss_sumsum)); 522 fs->lfs_sumsize - sizeof(nssp->ss_sumsum));
522 bwrite(nbp); 523 bwrite(nbp);
523#endif 524#endif
524 syslog(LOG_WARNING, "zero-length FINFO at %x (seg %d)", 525 syslog(LOG_WARNING, "zero-length FINFO at %x (seg %d)",
525 odaddr, lfs_dtosn(fs, odaddr)); 526 odaddr, lfs_dtosn(fs, odaddr));
526 continue; 527 continue;
527 } 528 }
528 529
529 /* 530 /*
@@ -532,53 +533,53 @@ parse_pseg(struct clfs *fs, daddr_t dadd @@ -532,53 +533,53 @@ parse_pseg(struct clfs *fs, daddr_t dadd
532#ifdef REPAIR_ZERO_FINFO 533#ifdef REPAIR_ZERO_FINFO
533 vers = -1; 534 vers = -1;
534#else 535#else
535 lfs_ientry(&ifp, fs, fip->fi_ino, &ifbp); 536 lfs_ientry(&ifp, fs, fip->fi_ino, &ifbp);
536 vers = ifp->if_version; 537 vers = ifp->if_version;
537 brelse(ifbp, 0); 538 brelse(ifbp, 0);
538#endif 539#endif
539 if (vers != fip->fi_version) { 540 if (vers != fip->fi_version) {
540 size_t size; 541 size_t size;
541 542
542 /* Read all the blocks from the data summary */ 543 /* Read all the blocks from the data summary */
543 for (i = 0; i < fip->fi_nblocks; i++) { 544 for (i = 0; i < fip->fi_nblocks; i++) {
544 size = (i == fip->fi_nblocks - 1) ? 545 size = (i == fip->fi_nblocks - 1) ?
545 fip->fi_lastlength : fs->lfs_bsize; 546 fip->fi_lastlength : clfs_sb_getbsize(fs);
546 cp = fd_ptrget(fs->clfs_devvp, daddr); 547 cp = fd_ptrget(fs->clfs_devvp, daddr);
547 ck = lfs_cksum_part(cp, sizeof(u_int32_t), ck); 548 ck = lfs_cksum_part(cp, sizeof(u_int32_t), ck);
548 daddr += lfs_btofsb(fs, size); 549 daddr += lfs_btofsb(fs, size);
549 } 550 }
550 fip = (FINFO *)(fip->fi_blocks + fip->fi_nblocks); 551 fip = (FINFO *)(fip->fi_blocks + fip->fi_nblocks);
551 continue; 552 continue;
552 } 553 }
553 554
554 /* Add all the blocks from the finfos (current or not) */ 555 /* Add all the blocks from the finfos (current or not) */
555 nbip = (BLOCK_INFO *)realloc(bip, (*bic + fip->fi_nblocks) * 556 nbip = (BLOCK_INFO *)realloc(bip, (*bic + fip->fi_nblocks) *
556 sizeof(*bip)); 557 sizeof(*bip));
557 if (nbip) 558 if (nbip)
558 bip = nbip; 559 bip = nbip;
559 else { 560 else {
560 *bipp = bip; 561 *bipp = bip;
561 return 0x0; 562 return 0x0;
562 } 563 }
563 564
564 for (i = 0; i < fip->fi_nblocks; i++) { 565 for (i = 0; i < fip->fi_nblocks; i++) {
565 bip[*bic + i].bi_inode = fip->fi_ino; 566 bip[*bic + i].bi_inode = fip->fi_ino;
566 bip[*bic + i].bi_lbn = fip->fi_blocks[i]; 567 bip[*bic + i].bi_lbn = fip->fi_blocks[i];
567 bip[*bic + i].bi_daddr = daddr; 568 bip[*bic + i].bi_daddr = daddr;
568 bip[*bic + i].bi_segcreate = ssp->ss_create; 569 bip[*bic + i].bi_segcreate = ssp->ss_create;
569 bip[*bic + i].bi_version = fip->fi_version; 570 bip[*bic + i].bi_version = fip->fi_version;
570 bip[*bic + i].bi_size = (i == fip->fi_nblocks - 1) ? 571 bip[*bic + i].bi_size = (i == fip->fi_nblocks - 1) ?
571 fip->fi_lastlength : fs->lfs_bsize; 572 fip->fi_lastlength : clfs_sb_getbsize(fs);
572 cp = fd_ptrget(fs->clfs_devvp, daddr); 573 cp = fd_ptrget(fs->clfs_devvp, daddr);
573 ck = lfs_cksum_part(cp, sizeof(u_int32_t), ck); 574 ck = lfs_cksum_part(cp, sizeof(u_int32_t), ck);
574 bip[*bic + i].bi_bp = cp; 575 bip[*bic + i].bi_bp = cp;
575 daddr += lfs_btofsb(fs, bip[*bic + i].bi_size); 576 daddr += lfs_btofsb(fs, bip[*bic + i].bi_size);
576 577
577#ifdef TEST_PATTERN 578#ifdef TEST_PATTERN
578 check_test_pattern(bip + *bic + i); /* XXXDEBUG */ 579 check_test_pattern(bip + *bic + i); /* XXXDEBUG */
579#endif 580#endif
580 } 581 }
581 *bic += fip->fi_nblocks; 582 *bic += fip->fi_nblocks;
582 fip = (FINFO *)(fip->fi_blocks + fip->fi_nblocks); 583 fip = (FINFO *)(fip->fi_blocks + fip->fi_nblocks);
583 } 584 }
584 585
@@ -607,27 +608,27 @@ log_segment_read(struct clfs *fs, int sn @@ -607,27 +608,27 @@ log_segment_read(struct clfs *fs, int sn
607 * the current directory. We don't need to log the location of 608 * the current directory. We don't need to log the location of
608 * the segment, since that can be inferred from the segments up 609 * the segment, since that can be inferred from the segments up
609 * to this point (ss_nextseg field of the previously written segment). 610 * to this point (ss_nextseg field of the previously written segment).
610 * 611 *
611 * We can use this info later to reconstruct the filesystem at any 612 * We can use this info later to reconstruct the filesystem at any
612 * given point in time for analysis, by replaying the log forward 613 * given point in time for analysis, by replaying the log forward
613 * indexed by the segment serial numbers; but it is not suitable 614 * indexed by the segment serial numbers; but it is not suitable
614 * for everyday use since the copylog will be simply enormous. 615 * for everyday use since the copylog will be simply enormous.
615 */ 616 */
616 cp = fd_ptrget(fs->clfs_devvp, lfs_sntod(fs, sn)); 617 cp = fd_ptrget(fs->clfs_devvp, lfs_sntod(fs, sn));
617 618
618 fp = fopen(copylog_filename, "ab"); 619 fp = fopen(copylog_filename, "ab");
619 if (fp != NULL) { 620 if (fp != NULL) {
620 if (fwrite(cp, (size_t)fs->lfs_ssize, 1, fp) != 1) { 621 if (fwrite(cp, (size_t)clfs_sb_getssize(fs), 1, fp) != 1) {
621 perror("writing segment to copy log"); 622 perror("writing segment to copy log");
622 } 623 }
623 } 624 }
624 fclose(fp); 625 fclose(fp);
625} 626}
626 627
627/* 628/*
628 * Read a segment to populate the BLOCK_INFO structures. 629 * Read a segment to populate the BLOCK_INFO structures.
629 * Return the number of partial segments read and parsed. 630 * Return the number of partial segments read and parsed.
630 */ 631 */
631int 632int
632load_segment(struct clfs *fs, int sn, BLOCK_INFO **bipp, int *bic) 633load_segment(struct clfs *fs, int sn, BLOCK_INFO **bipp, int *bic)
633{ 634{
@@ -643,32 +644,32 @@ load_segment(struct clfs *fs, int sn, BL @@ -643,32 +644,32 @@ load_segment(struct clfs *fs, int sn, BL
643 break; 644 break;
644 } 645 }
645 } 646 }
646 647
647 /* Preload the segment buffer */ 648 /* Preload the segment buffer */
648 if (fd_preload(fs->clfs_devvp, lfs_sntod(fs, sn)) < 0) 649 if (fd_preload(fs->clfs_devvp, lfs_sntod(fs, sn)) < 0)
649 return -1; 650 return -1;
650 651
651 if (copylog_filename) 652 if (copylog_filename)
652 log_segment_read(fs, sn); 653 log_segment_read(fs, sn);
653 654
654 /* Note bytes read for stats */ 655 /* Note bytes read for stats */
655 cleaner_stats.segs_cleaned++; 656 cleaner_stats.segs_cleaned++;
656 cleaner_stats.bytes_read += fs->lfs_ssize; 657 cleaner_stats.bytes_read += clfs_sb_getssize(fs);
657 ++fs->clfs_nactive; 658 ++fs->clfs_nactive;
658 659
659 npseg = 0; 660 npseg = 0;
660 while(lfs_dtosn(fs, daddr) == sn && 661 while(lfs_dtosn(fs, daddr) == sn &&
661 lfs_dtosn(fs, daddr + lfs_btofsb(fs, fs->lfs_bsize)) == sn) { 662 lfs_dtosn(fs, daddr + lfs_btofsb(fs, clfs_sb_getbsize(fs))) == sn) {
662 daddr = parse_pseg(fs, daddr, bipp, bic); 663 daddr = parse_pseg(fs, daddr, bipp, bic);
663 if (daddr == 0x0) { 664 if (daddr == 0x0) {
664 ++cleaner_stats.segs_error; 665 ++cleaner_stats.segs_error;
665 break; 666 break;
666 } 667 }
667 ++npseg; 668 ++npseg;
668 } 669 }
669 670
670 return npseg; 671 return npseg;
671} 672}
672 673
673void 674void
674calc_cb(struct clfs *fs, int sn, struct clfs_seguse *t) 675calc_cb(struct clfs *fs, int sn, struct clfs_seguse *t)
@@ -692,53 +693,53 @@ calc_cb(struct clfs *fs, int sn, struct  @@ -692,53 +693,53 @@ calc_cb(struct clfs *fs, int sn, struct
692 */ 693 */
693 if (t->nbytes == 0) { 694 if (t->nbytes == 0) {
694 t->flags &= ~SEGUSE_ERROR; /* Strip error once empty */ 695 t->flags &= ~SEGUSE_ERROR; /* Strip error once empty */
695 t->priority = 0; 696 t->priority = 0;
696 return; 697 return;
697 } 698 }
698 699
699 if (t->flags & SEGUSE_ERROR) { /* No good if not already empty */ 700 if (t->flags & SEGUSE_ERROR) { /* No good if not already empty */
700 /* No benefit */ 701 /* No benefit */
701 t->priority = 0; 702 t->priority = 0;
702 return; 703 return;
703 } 704 }
704 705
705 if (t->nbytes > fs->lfs_ssize) { 706 if (t->nbytes > clfs_sb_getssize(fs)) {
706 /* Another type of error */ 707 /* Another type of error */
707 syslog(LOG_WARNING, "segment %d: bad seguse count %d", 708 syslog(LOG_WARNING, "segment %d: bad seguse count %d",
708 sn, t->nbytes); 709 sn, t->nbytes);
709 t->flags |= SEGUSE_ERROR; 710 t->flags |= SEGUSE_ERROR;
710 t->priority = 0; 711 t->priority = 0;
711 return; 712 return;
712 } 713 }
713 714
714 /* 715 /*
715 * The non-degenerate case. Use Rosenblum's cost-benefit algorithm. 716 * The non-degenerate case. Use Rosenblum's cost-benefit algorithm.
716 * Calculate the benefit from cleaning this segment (one segment, 717 * Calculate the benefit from cleaning this segment (one segment,
717 * minus fragmentation, dirty blocks and a segment summary block) 718 * minus fragmentation, dirty blocks and a segment summary block)
718 * and weigh that against the cost (bytes read plus bytes written). 719 * and weigh that against the cost (bytes read plus bytes written).
719 * We count the summary headers as "dirty" to avoid cleaning very 720 * We count the summary headers as "dirty" to avoid cleaning very
720 * old and very full segments. 721 * old and very full segments.
721 */ 722 */
722 benefit = (int64_t)fs->lfs_ssize - t->nbytes - 723 benefit = (int64_t)clfs_sb_getssize(fs) - t->nbytes -
723 (t->nsums + 1) * fs->lfs_fsize; 724 (t->nsums + 1) * clfs_sb_getfsize(fs);
724 if (fs->lfs_bsize > fs->lfs_fsize) /* fragmentation */ 725 if (clfs_sb_getbsize(fs) > clfs_sb_getfsize(fs)) /* fragmentation */
725 benefit -= (fs->lfs_bsize / 2); 726 benefit -= (clfs_sb_getbsize(fs) / 2);
726 if (benefit <= 0) { 727 if (benefit <= 0) {
727 t->priority = 0; 728 t->priority = 0;
728 return; 729 return;
729 } 730 }
730 731
731 cost = fs->lfs_ssize + t->nbytes; 732 cost = clfs_sb_getssize(fs) + t->nbytes;
732 t->priority = (256 * benefit * age) / cost; 733 t->priority = (256 * benefit * age) / cost;
733 734
734 return; 735 return;
735} 736}
736 737
737/* 738/*
738 * Comparator for BLOCK_INFO structures. Anything not in one of the segments 739 * Comparator for BLOCK_INFO structures. Anything not in one of the segments
739 * we're looking at sorts higher; after that we sort first by inode number 740 * we're looking at sorts higher; after that we sort first by inode number
740 * and then by block number (unsigned, i.e., negative sorts higher) *but* 741 * and then by block number (unsigned, i.e., negative sorts higher) *but*
741 * sort inodes before data blocks. 742 * sort inodes before data blocks.
742 */ 743 */
743static int 744static int
744bi_comparator(const void *va, const void *vb) 745bi_comparator(const void *va, const void *vb)
@@ -857,27 +858,27 @@ invalidate_segment(struct clfs *fs, int  @@ -857,27 +858,27 @@ invalidate_segment(struct clfs *fs, int
857 858
858 dlog("%s: inval seg %d", fs->lfs_fsmnt, sn); 859 dlog("%s: inval seg %d", fs->lfs_fsmnt, sn);
859 860
860 bip = NULL; 861 bip = NULL;
861 bic = 0; 862 bic = 0;
862 fs->clfs_nactive = 0; 863 fs->clfs_nactive = 0;
863 if (load_segment(fs, sn, &bip, &bic) <= 0) 864 if (load_segment(fs, sn, &bip, &bic) <= 0)
864 return -1; 865 return -1;
865 toss_old_blocks(fs, &bip, &bic, NULL); 866 toss_old_blocks(fs, &bip, &bic, NULL);
866 867
867 /* Record statistics */ 868 /* Record statistics */
868 for (i = nb = 0; i < bic; i++) 869 for (i = nb = 0; i < bic; i++)
869 nb += bip[i].bi_size; 870 nb += bip[i].bi_size;
870 util = ((double)nb) / (fs->clfs_nactive * fs->lfs_ssize); 871 util = ((double)nb) / (fs->clfs_nactive * clfs_sb_getssize(fs));
871 cleaner_stats.util_tot += util; 872 cleaner_stats.util_tot += util;
872 cleaner_stats.util_sos += util * util; 873 cleaner_stats.util_sos += util * util;
873 cleaner_stats.bytes_written += nb; 874 cleaner_stats.bytes_written += nb;
874 875
875 /* 876 /*
876 * Use markv to move the blocks. 877 * Use markv to move the blocks.
877 */ 878 */
878 lim.blkiov = bip; 879 lim.blkiov = bip;
879 lim.blkcnt = bic; 880 lim.blkcnt = bic;
880 if ((r = kops.ko_fcntl(fs->clfs_ifilefd, LFCNMARKV, &lim)) < 0) { 881 if ((r = kops.ko_fcntl(fs->clfs_ifilefd, LFCNMARKV, &lim)) < 0) {
881 syslog(LOG_WARNING, "%s: markv returned %d (%m) " 882 syslog(LOG_WARNING, "%s: markv returned %d (%m) "
882 "for seg %d", fs->lfs_fsmnt, r, sn); 883 "for seg %d", fs->lfs_fsmnt, r, sn);
883 return r; 884 return r;
@@ -954,30 +955,30 @@ check_hidden_cost(struct clfs *fs, BLOCK @@ -954,30 +955,30 @@ check_hidden_cost(struct clfs *fs, BLOCK
954 int i, j, ebic; 955 int i, j, ebic;
955 BLOCK_INFO *ebip; 956 BLOCK_INFO *ebip;
956 int32_t lbn; 957 int32_t lbn;
957 958
958 start = 0; 959 start = 0;
959 ebip = NULL; 960 ebip = NULL;
960 ebic = 0; 961 ebic = 0;
961 for (i = 0; i < bic; i++) { 962 for (i = 0; i < bic; i++) {
962 if (i == 0 || bip[i].bi_inode != bip[start].bi_inode) { 963 if (i == 0 || bip[i].bi_inode != bip[start].bi_inode) {
963 start = i; 964 start = i;
964 /* 965 /*
965 * Look for IFILE blocks, unless this is the Ifile. 966 * Look for IFILE blocks, unless this is the Ifile.
966 */ 967 */
967 if (bip[i].bi_inode != fs->lfs_ifile) { 968 if (bip[i].bi_inode != clfs_sb_getifile(fs)) {
968 lbn = fs->lfs_cleansz + bip[i].bi_inode / 969 lbn = lfs_sb_getcleansz(fs) + bip[i].bi_inode /
969 fs->lfs_ifpb; 970 lfs_sb_getifpb(fs);
970 *ifc += check_or_add(fs->lfs_ifile, lbn, 971 *ifc += check_or_add(clfs_sb_getifile(fs), lbn,
971 bip, bic, &ebip, &ebic); 972 bip, bic, &ebip, &ebic);
972 } 973 }
973 } 974 }
974 if (bip[i].bi_lbn == LFS_UNUSED_LBN) 975 if (bip[i].bi_lbn == LFS_UNUSED_LBN)
975 continue; 976 continue;
976 if (bip[i].bi_lbn < ULFS_NDADDR) 977 if (bip[i].bi_lbn < ULFS_NDADDR)
977 continue; 978 continue;
978 979
979 ulfs_getlbns((struct lfs *)fs, NULL, (daddr_t)bip[i].bi_lbn, in, &num); 980 ulfs_getlbns((struct lfs *)fs, NULL, (daddr_t)bip[i].bi_lbn, in, &num);
980 for (j = 0; j < num; j++) { 981 for (j = 0; j < num; j++) {
981 check_or_add(bip[i].bi_inode, in[j].in_lbn, 982 check_or_add(bip[i].bi_inode, in[j].in_lbn,
982 bip + start, bic - start, &ebip, &ebic); 983 bip + start, bic - start, &ebip, &ebic);
983 } 984 }
@@ -1002,30 +1003,31 @@ clean_fs(struct clfs *fs, CLEANERINFO *c @@ -1002,30 +1003,31 @@ clean_fs(struct clfs *fs, CLEANERINFO *c
1002 BLOCK_INFO *blkiov; 1003 BLOCK_INFO *blkiov;
1003 int blkcnt; 1004 int blkcnt;
1004 } */ lim; 1005 } */ lim;
1005 int mc; 1006 int mc;
1006 BLOCK_INFO *mbip; 1007 BLOCK_INFO *mbip;
1007 int inc; 1008 int inc;
1008 off_t nb; 1009 off_t nb;
1009 off_t goal; 1010 off_t goal;
1010 off_t extra, if_extra; 1011 off_t extra, if_extra;
1011 double util; 1012 double util;
1012 1013
1013 /* Read the segment table into our private structure */ 1014 /* Read the segment table into our private structure */
1014 npos = 0; 1015 npos = 0;
1015 for (i = 0; i < fs->lfs_nseg; i+= fs->lfs_sepb) { 1016 for (i = 0; i < lfs_sb_getnseg(fs); i+= lfs_sb_getsepb(fs)) {
1016 bread(fs->lfs_ivnode, fs->lfs_cleansz + i / fs->lfs_sepb, 1017 bread(fs->lfs_ivnode,
1017 fs->lfs_bsize, 0, &bp); 1018 lfs_sb_getcleansz(fs) + i / lfs_sb_getsepb(fs),
1018 for (j = 0; j < fs->lfs_sepb && i + j < fs->lfs_nseg; j++) { 1019 clfs_sb_getbsize(fs), 0, &bp);
 1020 for (j = 0; j < lfs_sb_getsepb(fs) && i + j < lfs_sb_getnseg(fs); j++) {
1019 sup = ((SEGUSE *)bp->b_data) + j; 1021 sup = ((SEGUSE *)bp->b_data) + j;
1020 fs->clfs_segtab[i + j].nbytes = sup->su_nbytes; 1022 fs->clfs_segtab[i + j].nbytes = sup->su_nbytes;
1021 fs->clfs_segtab[i + j].nsums = sup->su_nsums; 1023 fs->clfs_segtab[i + j].nsums = sup->su_nsums;
1022 fs->clfs_segtab[i + j].lastmod = sup->su_lastmod; 1024 fs->clfs_segtab[i + j].lastmod = sup->su_lastmod;
1023 /* Keep error status but renew other flags */ 1025 /* Keep error status but renew other flags */
1024 fs->clfs_segtab[i + j].flags &= SEGUSE_ERROR; 1026 fs->clfs_segtab[i + j].flags &= SEGUSE_ERROR;
1025 fs->clfs_segtab[i + j].flags |= sup->su_flags; 1027 fs->clfs_segtab[i + j].flags |= sup->su_flags;
1026 1028
1027 /* Compute cost-benefit coefficient */ 1029 /* Compute cost-benefit coefficient */
1028 calc_cb(fs, i + j, fs->clfs_segtab + i + j); 1030 calc_cb(fs, i + j, fs->clfs_segtab + i + j);
1029 if (fs->clfs_segtab[i + j].priority > 0) 1031 if (fs->clfs_segtab[i + j].priority > 0)
1030 ++npos; 1032 ++npos;
1031 } 1033 }
@@ -1038,43 +1040,43 @@ clean_fs(struct clfs *fs, CLEANERINFO *c @@ -1038,43 +1040,43 @@ clean_fs(struct clfs *fs, CLEANERINFO *c
1038 1040
1039 /* If no segment is cleanable, just return */ 1041 /* If no segment is cleanable, just return */
1040 if (fs->clfs_segtabp[0]->priority == 0) { 1042 if (fs->clfs_segtabp[0]->priority == 0) {
1041 dlog("%s: no segment cleanable", fs->lfs_fsmnt); 1043 dlog("%s: no segment cleanable", fs->lfs_fsmnt);
1042 return 0; 1044 return 0;
1043 } 1045 }
1044 1046
1045 /* Load some segments' blocks into bip */ 1047 /* Load some segments' blocks into bip */
1046 bic = 0; 1048 bic = 0;
1047 fs->clfs_nactive = 0; 1049 fs->clfs_nactive = 0;
1048 ngood = 0; 1050 ngood = 0;
1049 if (use_bytes) { 1051 if (use_bytes) {
1050 /* Set attainable goal */ 1052 /* Set attainable goal */
1051 goal = fs->lfs_ssize * atatime; 1053 goal = clfs_sb_getssize(fs) * atatime;
1052 if (goal > (cip->clean - 1) * fs->lfs_ssize / 2) 1054 if (goal > (cip->clean - 1) * clfs_sb_getssize(fs) / 2)
1053 goal = MAX((cip->clean - 1) * fs->lfs_ssize, 1055 goal = MAX((cip->clean - 1) * clfs_sb_getssize(fs),
1054 fs->lfs_ssize) / 2; 1056 clfs_sb_getssize(fs)) / 2;
1055 1057
1056 dlog("%s: cleaning with goal %" PRId64 1058 dlog("%s: cleaning with goal %" PRId64
1057 " bytes (%d segs clean, %d cleanable)", 1059 " bytes (%d segs clean, %d cleanable)",
1058 fs->lfs_fsmnt, goal, cip->clean, npos); 1060 fs->lfs_fsmnt, goal, cip->clean, npos);
1059 syslog(LOG_INFO, "%s: cleaning with goal %" PRId64 1061 syslog(LOG_INFO, "%s: cleaning with goal %" PRId64
1060 " bytes (%d segs clean, %d cleanable)", 1062 " bytes (%d segs clean, %d cleanable)",
1061 fs->lfs_fsmnt, goal, cip->clean, npos); 1063 fs->lfs_fsmnt, goal, cip->clean, npos);
1062 totbytes = 0; 1064 totbytes = 0;
1063 for (i = 0; i < fs->lfs_nseg && totbytes < goal; i++) { 1065 for (i = 0; i < fs->lfs_nseg && totbytes < goal; i++) {
1064 if (fs->clfs_segtabp[i]->priority == 0) 1066 if (fs->clfs_segtabp[i]->priority == 0)
1065 break; 1067 break;
1066 /* Upper bound on number of segments at once */ 1068 /* Upper bound on number of segments at once */
1067 if (ngood * fs->lfs_ssize > 4 * goal) 1069 if (ngood * clfs_sb_getssize(fs) > 4 * goal)
1068 break; 1070 break;
1069 sn = (fs->clfs_segtabp[i] - fs->clfs_segtab); 1071 sn = (fs->clfs_segtabp[i] - fs->clfs_segtab);
1070 dlog("%s: add seg %d prio %" PRIu64 1072 dlog("%s: add seg %d prio %" PRIu64
1071 " containing %ld bytes", 1073 " containing %ld bytes",
1072 fs->lfs_fsmnt, sn, fs->clfs_segtabp[i]->priority, 1074 fs->lfs_fsmnt, sn, fs->clfs_segtabp[i]->priority,
1073 fs->clfs_segtabp[i]->nbytes); 1075 fs->clfs_segtabp[i]->nbytes);
1074 if ((r = load_segment(fs, sn, &bip, &bic)) > 0) { 1076 if ((r = load_segment(fs, sn, &bip, &bic)) > 0) {
1075 ++ngood; 1077 ++ngood;
1076 toss_old_blocks(fs, &bip, &bic, &bytes); 1078 toss_old_blocks(fs, &bip, &bic, &bytes);
1077 totbytes += bytes; 1079 totbytes += bytes;
1078 } else if (r == 0) 1080 } else if (r == 0)
1079 fd_release(fs->clfs_devvp); 1081 fd_release(fs->clfs_devvp);
1080 else 1082 else
@@ -1105,46 +1107,46 @@ clean_fs(struct clfs *fs, CLEANERINFO *c @@ -1105,46 +1107,46 @@ clean_fs(struct clfs *fs, CLEANERINFO *c
1105 } 1107 }
1106 1108
1107 /* If there is nothing to do, try again later. */ 1109 /* If there is nothing to do, try again later. */
1108 if (bic == 0) { 1110 if (bic == 0) {
1109 dlog("%s: no blocks to clean in %d cleanable segments", 1111 dlog("%s: no blocks to clean in %d cleanable segments",
1110 fs->lfs_fsmnt, (int)ngood); 1112 fs->lfs_fsmnt, (int)ngood);
1111 fd_release_all(fs->clfs_devvp); 1113 fd_release_all(fs->clfs_devvp);
1112 return 0; 1114 return 0;
1113 } 1115 }
1114 1116
1115 /* Record statistics */ 1117 /* Record statistics */
1116 for (i = nb = 0; i < bic; i++) 1118 for (i = nb = 0; i < bic; i++)
1117 nb += bip[i].bi_size; 1119 nb += bip[i].bi_size;
1118 util = ((double)nb) / (fs->clfs_nactive * fs->lfs_ssize); 1120 util = ((double)nb) / (fs->clfs_nactive * clfs_sb_getssize(fs));
1119 cleaner_stats.util_tot += util; 1121 cleaner_stats.util_tot += util;
1120 cleaner_stats.util_sos += util * util; 1122 cleaner_stats.util_sos += util * util;
1121 cleaner_stats.bytes_written += nb; 1123 cleaner_stats.bytes_written += nb;
1122 1124
1123 /* 1125 /*
1124 * Check out our blocks to see if there are hidden cleaning costs. 1126 * Check out our blocks to see if there are hidden cleaning costs.
1125 * If there are, we might be cleaning ourselves deeper into a hole 1127 * If there are, we might be cleaning ourselves deeper into a hole
1126 * rather than doing anything useful. 1128 * rather than doing anything useful.
1127 * XXX do something about this. 1129 * XXX do something about this.
1128 */ 1130 */
1129 if_extra = 0; 1131 if_extra = 0;
1130 extra = fs->lfs_bsize * (off_t)check_hidden_cost(fs, bip, bic, &if_extra); 1132 extra = clfs_sb_getbsize(fs) * (off_t)check_hidden_cost(fs, bip, bic, &if_extra);
1131 if_extra *= fs->lfs_bsize; 1133 if_extra *= clfs_sb_getbsize(fs);
1132 1134
1133 /* 1135 /*
1134 * Use markv to move the blocks. 1136 * Use markv to move the blocks.
1135 */ 1137 */
1136 if (do_small)  1138 if (do_small)
1137 inc = MAXPHYS / fs->lfs_bsize - 1; 1139 inc = MAXPHYS / clfs_sb_getbsize(fs) - 1;
1138 else 1140 else
1139 inc = LFS_MARKV_MAXBLKCNT / 2; 1141 inc = LFS_MARKV_MAXBLKCNT / 2;
1140 for (mc = 0, mbip = bip; mc < bic; mc += inc, mbip += inc) { 1142 for (mc = 0, mbip = bip; mc < bic; mc += inc, mbip += inc) {
1141 lim.blkiov = mbip; 1143 lim.blkiov = mbip;
1142 lim.blkcnt = (bic - mc > inc ? inc : bic - mc); 1144 lim.blkcnt = (bic - mc > inc ? inc : bic - mc);
1143#ifdef TEST_PATTERN 1145#ifdef TEST_PATTERN
1144 dlog("checking blocks %d-%d", mc, mc + lim.blkcnt - 1); 1146 dlog("checking blocks %d-%d", mc, mc + lim.blkcnt - 1);
1145 for (i = 0; i < lim.blkcnt; i++) { 1147 for (i = 0; i < lim.blkcnt; i++) {
1146 check_test_pattern(mbip + i); 1148 check_test_pattern(mbip + i);
1147 } 1149 }
1148#endif /* TEST_PATTERN */ 1150#endif /* TEST_PATTERN */
1149 dlog("sending blocks %d-%d", mc, mc + lim.blkcnt - 1); 1151 dlog("sending blocks %d-%d", mc, mc + lim.blkcnt - 1);
1150 if ((r = kops.ko_fcntl(fs->clfs_ifilefd, LFCNMARKV, &lim))<0) { 1152 if ((r = kops.ko_fcntl(fs->clfs_ifilefd, LFCNMARKV, &lim))<0) {
@@ -1166,29 +1168,29 @@ clean_fs(struct clfs *fs, CLEANERINFO *c @@ -1166,29 +1168,29 @@ clean_fs(struct clfs *fs, CLEANERINFO *c
1166 } 1168 }
1167 } 1169 }
1168 1170
1169 /* 1171 /*
1170 * Report progress (or lack thereof) 1172 * Report progress (or lack thereof)
1171 */ 1173 */
1172 syslog(LOG_INFO, "%s: wrote %" PRId64 " dirty + %" 1174 syslog(LOG_INFO, "%s: wrote %" PRId64 " dirty + %"
1173 PRId64 " supporting indirect + %" 1175 PRId64 " supporting indirect + %"
1174 PRId64 " supporting Ifile = %" 1176 PRId64 " supporting Ifile = %"
1175 PRId64 " bytes to clean %d segs (%" PRId64 "%% recovery)", 1177 PRId64 " bytes to clean %d segs (%" PRId64 "%% recovery)",
1176 fs->lfs_fsmnt, (int64_t)nb, (int64_t)(extra - if_extra), 1178 fs->lfs_fsmnt, (int64_t)nb, (int64_t)(extra - if_extra),
1177 (int64_t)if_extra, (int64_t)(nb + extra), ngood, 1179 (int64_t)if_extra, (int64_t)(nb + extra), ngood,
1178 (ngood ? (int64_t)(100 - (100 * (nb + extra)) / 1180 (ngood ? (int64_t)(100 - (100 * (nb + extra)) /
1179 (ngood * fs->lfs_ssize)) : 1181 (ngood * clfs_sb_getssize(fs))) :
1180 (int64_t)0)); 1182 (int64_t)0));
1181 if (nb + extra >= ngood * fs->lfs_ssize) 1183 if (nb + extra >= ngood * clfs_sb_getssize(fs))
1182 syslog(LOG_WARNING, "%s: cleaner not making forward progress", 1184 syslog(LOG_WARNING, "%s: cleaner not making forward progress",
1183 fs->lfs_fsmnt); 1185 fs->lfs_fsmnt);
1184 1186
1185 /* 1187 /*
1186 * Finally call reclaim to prompt cleaning of the segments. 1188 * Finally call reclaim to prompt cleaning of the segments.
1187 */ 1189 */
1188 kops.ko_fcntl(fs->clfs_ifilefd, LFCNRECLAIM, NULL); 1190 kops.ko_fcntl(fs->clfs_ifilefd, LFCNRECLAIM, NULL);
1189 1191
1190 fd_release_all(fs->clfs_devvp); 1192 fd_release_all(fs->clfs_devvp);
1191 return 0; 1193 return 0;
1192} 1194}
1193 1195
1194/* 1196/*
@@ -1204,33 +1206,33 @@ needs_cleaning(struct clfs *fs, CLEANERI @@ -1204,33 +1206,33 @@ needs_cleaning(struct clfs *fs, CLEANERI
1204 daddr_t fsb_per_seg, max_free_segs; 1206 daddr_t fsb_per_seg, max_free_segs;
1205 time_t now; 1207 time_t now;
1206 double loadavg; 1208 double loadavg;
1207 1209
1208 /* If this fs is "on hold", don't clean it. */ 1210 /* If this fs is "on hold", don't clean it. */
1209 if (fs->clfs_onhold) 1211 if (fs->clfs_onhold)
1210 return 0; 1212 return 0;
1211 1213
1212 /* 1214 /*
1213 * Read the cleanerinfo block from the Ifile. We don't want 1215 * Read the cleanerinfo block from the Ifile. We don't want
1214 * the cached information, so invalidate the buffer before 1216 * the cached information, so invalidate the buffer before
1215 * handing it back. 1217 * handing it back.
1216 */ 1218 */
1217 if (bread(fs->lfs_ivnode, 0, fs->lfs_bsize, 0, &bp)) { 1219 if (bread(fs->lfs_ivnode, 0, clfs_sb_getbsize(fs), 0, &bp)) {
1218 syslog(LOG_ERR, "%s: can't read inode", fs->lfs_fsmnt); 1220 syslog(LOG_ERR, "%s: can't read inode", fs->lfs_fsmnt);
1219 return -1; 1221 return -1;
1220 } 1222 }
1221 *cip = *(CLEANERINFO *)bp->b_data; /* Structure copy */ 1223 *cip = *(CLEANERINFO *)bp->b_data; /* Structure copy */
1222 brelse(bp, B_INVAL); 1224 brelse(bp, B_INVAL);
1223 cleaner_stats.bytes_read += fs->lfs_bsize; 1225 cleaner_stats.bytes_read += clfs_sb_getbsize(fs);
1224 1226
1225 /* 1227 /*
1226 * If the number of segments changed under us, reinit. 1228 * If the number of segments changed under us, reinit.
1227 * We don't have to start over from scratch, however, 1229 * We don't have to start over from scratch, however,
1228 * since we don't hold any buffers. 1230 * since we don't hold any buffers.
1229 */ 1231 */
1230 if (fs->lfs_nseg != cip->clean + cip->dirty) { 1232 if (fs->lfs_nseg != cip->clean + cip->dirty) {
1231 if (reinit_fs(fs) < 0) { 1233 if (reinit_fs(fs) < 0) {
1232 /* The normal case for unmount */ 1234 /* The normal case for unmount */
1233 syslog(LOG_NOTICE, "%s: filesystem unmounted", fs->lfs_fsmnt); 1235 syslog(LOG_NOTICE, "%s: filesystem unmounted", fs->lfs_fsmnt);
1234 return -1; 1236 return -1;
1235 } 1237 }
1236 syslog(LOG_NOTICE, "%s: nsegs changed", fs->lfs_fsmnt); 1238 syslog(LOG_NOTICE, "%s: nsegs changed", fs->lfs_fsmnt);

cvs diff -r1.19 -r1.20 src/sbin/dump_lfs/lfs_inode.c (expand / switch to unified diff)

--- src/sbin/dump_lfs/lfs_inode.c 2013/06/19 06:15:54 1.19
+++ src/sbin/dump_lfs/lfs_inode.c 2015/07/24 06:56:41 1.20
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lfs_inode.c,v 1.19 2013/06/19 06:15:54 dholland Exp $ */ 1/* $NetBSD: lfs_inode.c,v 1.20 2015/07/24 06:56:41 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1980, 1991, 1993, 1994 4 * Copyright (c) 1980, 1991, 1993, 1994
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -29,27 +29,27 @@ @@ -29,27 +29,27 @@
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33#ifndef lint 33#ifndef lint
34__COPYRIGHT("@(#) Copyright (c) 1980, 1991, 1993, 1994\ 34__COPYRIGHT("@(#) Copyright (c) 1980, 1991, 1993, 1994\
35 The Regents of the University of California. All rights reserved."); 35 The Regents of the University of California. All rights reserved.");
36#endif /* not lint */ 36#endif /* not lint */
37 37
38#ifndef lint 38#ifndef lint
39#if 0 39#if 0
40static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/1/95"; 40static char sccsid[] = "@(#)main.c 8.6 (Berkeley) 5/1/95";
41#else 41#else
42__RCSID("$NetBSD: lfs_inode.c,v 1.19 2013/06/19 06:15:54 dholland Exp $"); 42__RCSID("$NetBSD: lfs_inode.c,v 1.20 2015/07/24 06:56:41 dholland Exp $");
43#endif 43#endif
44#endif /* not lint */ 44#endif /* not lint */
45 45
46#include <sys/param.h> 46#include <sys/param.h>
47#include <sys/time.h> 47#include <sys/time.h>
48#include <sys/stat.h> 48#include <sys/stat.h>
49#include <sys/mount.h> 49#include <sys/mount.h>
50 50
51#include <ctype.h> 51#include <ctype.h>
52#include <errno.h> 52#include <errno.h>
53#include <fcntl.h> 53#include <fcntl.h>
54#include <fts.h> 54#include <fts.h>
55#include <stdio.h> 55#include <stdio.h>
@@ -106,86 +106,86 @@ fs_read_sblock(char *superblock) @@ -106,86 +106,86 @@ fs_read_sblock(char *superblock)
106 * Read the secondary and take the older of the two 106 * Read the secondary and take the older of the two
107 */ 107 */
108 rawread(lfs_fsbtob(sblock, (off_t)sblock->lfs_sboffs[1]), u.tbuf, 108 rawread(lfs_fsbtob(sblock, (off_t)sblock->lfs_sboffs[1]), u.tbuf,
109 sizeof(u.tbuf)); 109 sizeof(u.tbuf));
110#ifdef notyet 110#ifdef notyet
111 if (ns) 111 if (ns)
112 lfs_sb_swap(u.tbuf, u.tbuf, 0); 112 lfs_sb_swap(u.tbuf, u.tbuf, 0);
113#endif 113#endif
114 if (u.lfss.lfs_magic != LFS_MAGIC) { 114 if (u.lfss.lfs_magic != LFS_MAGIC) {
115 msg("Warning: secondary superblock at 0x%" PRIx64 " bad magic\n", 115 msg("Warning: secondary superblock at 0x%" PRIx64 " bad magic\n",
116 LFS_FSBTODB(sblock, (off_t)sblock->lfs_sboffs[1])); 116 LFS_FSBTODB(sblock, (off_t)sblock->lfs_sboffs[1]));
117 } else { 117 } else {
118 if (sblock->lfs_version > 1) { 118 if (sblock->lfs_version > 1) {
119 if (u.lfss.lfs_serial < sblock->lfs_serial) { 119 if (lfs_sb_getserial(&u.lfss) < lfs_sb_getserial(sblock)) {
120 memcpy(sblock, u.tbuf, sizeof(u.tbuf)); 120 memcpy(sblock, u.tbuf, sizeof(u.tbuf));
121 sboff = lfs_fsbtob(sblock, (off_t)sblock->lfs_sboffs[1]); 121 sboff = lfs_fsbtob(sblock, (off_t)sblock->lfs_sboffs[1]);
122 } 122 }
123 } else { 123 } else {
124 if (u.lfss.lfs_otstamp < sblock->lfs_otstamp) { 124 if (lfs_sb_getotstamp(&u.lfss) < lfs_sb_getotstamp(sblock)) {
125 memcpy(sblock, u.tbuf, sizeof(u.tbuf)); 125 memcpy(sblock, u.tbuf, sizeof(u.tbuf));
126 sboff = lfs_fsbtob(sblock, (off_t)sblock->lfs_sboffs[1]); 126 sboff = lfs_fsbtob(sblock, (off_t)sblock->lfs_sboffs[1]);
127 } 127 }
128 } 128 }
129 } 129 }
130 if (sboff != LFS_SBPAD) { 130 if (sboff != LFS_SBPAD) {
131 msg("Using superblock at alternate location 0x%lx\n", 131 msg("Using superblock at alternate location 0x%lx\n",
132 (unsigned long)(btodb(sboff))); 132 (unsigned long)(btodb(sboff)));
133 } 133 }
134 134
135 return ns; 135 return ns;
136} 136}
137 137
138/* 138/*
139 * Fill in the ufsi struct, as well as the maxino and dev_bsize global 139 * Fill in the ufsi struct, as well as the maxino and dev_bsize global
140 * variables. 140 * variables.
141 */ 141 */
142struct ufsi * 142struct ufsi *
143fs_parametrize(void) 143fs_parametrize(void)
144{ 144{
145 static struct ufsi ufsi; 145 static struct ufsi ufsi;
146 146
147 spcl.c_flags = iswap32(iswap32(spcl.c_flags) | DR_NEWINODEFMT); 147 spcl.c_flags = iswap32(iswap32(spcl.c_flags) | DR_NEWINODEFMT);
148 148
149 ufsi.ufs_dsize = LFS_FSBTODB(sblock,sblock->lfs_size); 149 ufsi.ufs_dsize = LFS_FSBTODB(sblock, lfs_sb_getsize(sblock));
150 if (sblock->lfs_version == 1)  150 if (sblock->lfs_version == 1)
151 ufsi.ufs_dsize = sblock->lfs_size >> sblock->lfs_blktodb; 151 ufsi.ufs_dsize = lfs_sb_getsize(sblock) >> sblock->lfs_blktodb;
152 ufsi.ufs_bsize = sblock->lfs_bsize; 152 ufsi.ufs_bsize = lfs_sb_getbsize(sblock);
153 ufsi.ufs_bshift = sblock->lfs_bshift; 153 ufsi.ufs_bshift = sblock->lfs_bshift;
154 ufsi.ufs_fsize = sblock->lfs_fsize; 154 ufsi.ufs_fsize = lfs_sb_getfsize(sblock);
155 ufsi.ufs_frag = sblock->lfs_frag; 155 ufsi.ufs_frag = lfs_sb_getfrag(sblock);
156 ufsi.ufs_fsatoda = sblock->lfs_fsbtodb; 156 ufsi.ufs_fsatoda = sblock->lfs_fsbtodb;
157 if (sblock->lfs_version == 1) 157 if (sblock->lfs_version == 1)
158 ufsi.ufs_fsatoda = 0; 158 ufsi.ufs_fsatoda = 0;
159 ufsi.ufs_nindir = sblock->lfs_nindir; 159 ufsi.ufs_nindir = sblock->lfs_nindir;
160 ufsi.ufs_inopb = sblock->lfs_inopb; 160 ufsi.ufs_inopb = sblock->lfs_inopb;
161 ufsi.ufs_maxsymlinklen = sblock->lfs_maxsymlinklen; 161 ufsi.ufs_maxsymlinklen = sblock->lfs_maxsymlinklen;
162 ufsi.ufs_bmask = ~(sblock->lfs_bmask); 162 ufsi.ufs_bmask = ~(sblock->lfs_bmask);
163 ufsi.ufs_qbmask = sblock->lfs_bmask; 163 ufsi.ufs_qbmask = sblock->lfs_bmask;
164 ufsi.ufs_fmask = ~(sblock->lfs_ffmask); 164 ufsi.ufs_fmask = ~(sblock->lfs_ffmask);
165 ufsi.ufs_qfmask = sblock->lfs_ffmask; 165 ufsi.ufs_qfmask = sblock->lfs_ffmask;
166 166
167 dev_bsize = sblock->lfs_bsize >> sblock->lfs_blktodb; 167 dev_bsize = lfs_sb_getbsize(sblock) >> sblock->lfs_blktodb;
168 168
169 return &ufsi; 169 return &ufsi;
170} 170}
171 171
172ino_t 172ino_t
173fs_maxino(void) 173fs_maxino(void)
174{ 174{
175 return ((getino(sblock->lfs_ifile)->dp1.di_size 175 return ((getino(lfs_sb_getifile(sblock))->dp1.di_size
176 - (sblock->lfs_cleansz + sblock->lfs_segtabsz) 176 - (lfs_sb_getcleansz(sblock) + lfs_sb_getsegtabsz(sblock))
177 * sblock->lfs_bsize) 177 * lfs_sb_getbsize(sblock))
178 / sblock->lfs_bsize) * sblock->lfs_ifpb - 1; 178 / lfs_sb_getbsize(sblock)) * lfs_sb_getifpb(sblock) - 1;
179} 179}
180 180
181void 181void
182fs_mapinodes(ino_t maxino, u_int64_t *tapesz, int *anydirskipped) 182fs_mapinodes(ino_t maxino, u_int64_t *tapesz, int *anydirskipped)
183{ 183{
184 ino_t ino; 184 ino_t ino;
185 185
186 for (ino = ULFS_ROOTINO; ino < maxino; ino++) 186 for (ino = ULFS_ROOTINO; ino < maxino; ino++)
187 mapfileino(ino, tapesz, anydirskipped); 187 mapfileino(ino, tapesz, anydirskipped);
188} 188}
189 189
190/* 190/*
191 * XXX KS - I know there's a better way to do this. 191 * XXX KS - I know there's a better way to do this.
@@ -230,27 +230,27 @@ lfs_bmap(struct lfs *fs, struct ulfs1_di @@ -230,27 +230,27 @@ lfs_bmap(struct lfs *fs, struct ulfs1_di
230 230
231 /* 231 /*
232 * Find the immediate parent. This is essentially finding the 232 * Find the immediate parent. This is essentially finding the
233 * residue of modulus, and then rounding accordingly. 233 * residue of modulus, and then rounding accordingly.
234 */ 234 */
235 residue = (lbn-ULFS_NDADDR) % LFS_NINDIR(fs); 235 residue = (lbn-ULFS_NDADDR) % LFS_NINDIR(fs);
236 if(residue == 1) { 236 if(residue == 1) {
237 /* Double indirect. Parent is the triple. */ 237 /* Double indirect. Parent is the triple. */
238 up = idinode->di_ib[2]; 238 up = idinode->di_ib[2];
239 off = (lbn-2-BASE_TINDIR)/(LFS_NINDIR(fs)*LFS_NINDIR(fs)); 239 off = (lbn-2-BASE_TINDIR)/(LFS_NINDIR(fs)*LFS_NINDIR(fs));
240 if(up == UNASSIGNED || up == LFS_UNUSED_DADDR) 240 if(up == UNASSIGNED || up == LFS_UNUSED_DADDR)
241 return UNASSIGNED; 241 return UNASSIGNED;
242 /* printf("lbn %d: parent is the triple\n", -lbn); */ 242 /* printf("lbn %d: parent is the triple\n", -lbn); */
243 bread(LFS_FSBTODB(sblock, up), bp, sblock->lfs_bsize); 243 bread(LFS_FSBTODB(sblock, up), bp, lfs_sb_getbsize(sblock));
244 /* XXX ondisk32 */ 244 /* XXX ondisk32 */
245 return (daddr_t)((int32_t *)bp)[off]; 245 return (daddr_t)((int32_t *)bp)[off];
246 } else /* residue == 0 */ { 246 } else /* residue == 0 */ {
247 /* Single indirect. Two cases. */ 247 /* Single indirect. Two cases. */
248 if(lbn < BASE_TINDIR) { 248 if(lbn < BASE_TINDIR) {
249 /* Parent is the double, simple */ 249 /* Parent is the double, simple */
250 up = -(BASE_DINDIR) - 1; 250 up = -(BASE_DINDIR) - 1;
251 off = (lbn-BASE_DINDIR) / D_UNITS; 251 off = (lbn-BASE_DINDIR) / D_UNITS;
252 /* printf("lbn %d: parent is %d/%d\n", -lbn, up,off); */ 252 /* printf("lbn %d: parent is %d/%d\n", -lbn, up,off); */
253 } else { 253 } else {
254 /* Ancestor is the triple, more complex */ 254 /* Ancestor is the triple, more complex */
255 up = ((lbn-BASE_TINDIR) / T_UNITS) 255 up = ((lbn-BASE_TINDIR) / T_UNITS)
256 * T_UNITS + BASE_TINDIR + 1; 256 * T_UNITS + BASE_TINDIR + 1;
@@ -263,94 +263,94 @@ lfs_bmap(struct lfs *fs, struct ulfs1_di @@ -263,94 +263,94 @@ lfs_bmap(struct lfs *fs, struct ulfs1_di
263 /* Direct block. Its parent must be a single indirect. */ 263 /* Direct block. Its parent must be a single indirect. */
264 if (lbn < ULFS_NDADDR) 264 if (lbn < ULFS_NDADDR)
265 return idinode->di_db[lbn]; 265 return idinode->di_db[lbn];
266 else { 266 else {
267 /* Parent is an indirect block. */ 267 /* Parent is an indirect block. */
268 up = -(((lbn-ULFS_NDADDR) / D_UNITS) * D_UNITS + ULFS_NDADDR); 268 up = -(((lbn-ULFS_NDADDR) / D_UNITS) * D_UNITS + ULFS_NDADDR);
269 off = (lbn-ULFS_NDADDR) % D_UNITS; 269 off = (lbn-ULFS_NDADDR) % D_UNITS;
270 /* printf("lbn %d: parent is %d/%d\n", lbn,up,off); */ 270 /* printf("lbn %d: parent is %d/%d\n", lbn,up,off); */
271 } 271 }
272 } 272 }
273 up = lfs_bmap(fs,idinode,up); 273 up = lfs_bmap(fs,idinode,up);
274 if(up == UNASSIGNED || up == LFS_UNUSED_DADDR) 274 if(up == UNASSIGNED || up == LFS_UNUSED_DADDR)
275 return UNASSIGNED; 275 return UNASSIGNED;
276 bread(LFS_FSBTODB(sblock, up), bp, sblock->lfs_bsize); 276 bread(LFS_FSBTODB(sblock, up), bp, lfs_sb_getbsize(sblock));
277 /* XXX ondisk32 */ 277 /* XXX ondisk32 */
278 return (daddr_t)((int32_t *)bp)[off]; 278 return (daddr_t)((int32_t *)bp)[off];
279} 279}
280 280
281static struct ifile * 281static struct ifile *
282lfs_ientry(ino_t ino) 282lfs_ientry(ino_t ino)
283{ 283{
284 static struct ifile ifileblock[MAXIFPB]; 284 static struct ifile ifileblock[MAXIFPB];
285 static daddr_t ifblkno; 285 static daddr_t ifblkno;
286 daddr_t lbn; 286 daddr_t lbn;
287 daddr_t blkno; 287 daddr_t blkno;
288 union dinode *dp; 288 union dinode *dp;
289 struct ulfs1_dinode *ldp; 289 struct ulfs1_dinode *ldp;
290  290
291 lbn = ino/sblock->lfs_ifpb + sblock->lfs_cleansz + sblock->lfs_segtabsz; 291 lbn = ino/lfs_sb_getifpb(sblock) + lfs_sb_getcleansz(sblock) + lfs_sb_getsegtabsz(sblock);
292 dp = getino(sblock->lfs_ifile); 292 dp = getino(lfs_sb_getifile(sblock));
293 /* XXX XXX this is horribly unsafe */ 293 /* XXX XXX this is horribly unsafe */
294 ldp = (struct ulfs1_dinode *)dp; 294 ldp = (struct ulfs1_dinode *)dp;
295 blkno = lfs_bmap(sblock, ldp ,lbn); 295 blkno = lfs_bmap(sblock, ldp ,lbn);
296 if (blkno != ifblkno) 296 if (blkno != ifblkno)
297 bread(LFS_FSBTODB(sblock, blkno), (char *)ifileblock, 297 bread(LFS_FSBTODB(sblock, blkno), (char *)ifileblock,
298 sblock->lfs_bsize); 298 lfs_sb_getbsize(sblock));
299 return ifileblock + (ino % sblock->lfs_ifpb); 299 return ifileblock + (ino % lfs_sb_getifpb(sblock));
300} 300}
301 301
302/* Search a block for a specific dinode. */ 302/* Search a block for a specific dinode. */
303static struct ulfs1_dinode * 303static struct ulfs1_dinode *
304lfs_ifind(struct lfs *fs, ino_t ino, struct ulfs1_dinode *dip) 304lfs_ifind(struct lfs *fs, ino_t ino, struct ulfs1_dinode *dip)
305{ 305{
306 int cnt; 306 int cnt;
307 307
308 for (cnt = 0; cnt < LFS_INOPB(fs); cnt++) 308 for (cnt = 0; cnt < LFS_INOPB(fs); cnt++)
309 if(dip[cnt].di_inumber == ino) 309 if(dip[cnt].di_inumber == ino)
310 return &(dip[cnt]); 310 return &(dip[cnt]);
311 return NULL; 311 return NULL;
312} 312}
313 313
314union dinode * 314union dinode *
315getino(ino_t inum) 315getino(ino_t inum)
316{ 316{
317 static daddr_t inoblkno; 317 static daddr_t inoblkno;
318 daddr_t blkno; 318 daddr_t blkno;
319 static struct ulfs1_dinode inoblock[MAXBSIZE / sizeof (struct ulfs1_dinode)]; 319 static struct ulfs1_dinode inoblock[MAXBSIZE / sizeof (struct ulfs1_dinode)];
320 static union dinode ifile_dinode; /* XXX fill this in */ 320 static union dinode ifile_dinode; /* XXX fill this in */
321 static union dinode empty_dinode; /* Always stays zeroed */ 321 static union dinode empty_dinode; /* Always stays zeroed */
322 struct ulfs1_dinode *dp; 322 struct ulfs1_dinode *dp;
323 323
324 if(inum == sblock->lfs_ifile) { 324 if(inum == lfs_sb_getifile(sblock)) {
325 /* Load the ifile inode if not already */ 325 /* Load the ifile inode if not already */
326 if(ifile_dinode.dlp1.di_inumber == 0) { 326 if(ifile_dinode.dlp1.di_inumber == 0) {
327 blkno = sblock->lfs_idaddr; 327 blkno = lfs_sb_getidaddr(sblock);
328 bread(LFS_FSBTODB(sblock, blkno), (char *)inoblock,  328 bread(LFS_FSBTODB(sblock, blkno), (char *)inoblock,
329 (int)sblock->lfs_bsize); 329 (int)lfs_sb_getbsize(sblock));
330 dp = lfs_ifind(sblock, inum, inoblock); 330 dp = lfs_ifind(sblock, inum, inoblock);
331 ifile_dinode.dlp1 = *dp; /* Structure copy */ 331 ifile_dinode.dlp1 = *dp; /* Structure copy */
332 } 332 }
333 return &ifile_dinode; 333 return &ifile_dinode;
334 } 334 }
335 335
336 curino = inum; 336 curino = inum;
337 blkno = lfs_ientry(inum)->if_daddr; 337 blkno = lfs_ientry(inum)->if_daddr;
338 if(blkno == LFS_UNUSED_DADDR) 338 if(blkno == LFS_UNUSED_DADDR)
339 return &empty_dinode; 339 return &empty_dinode;
340 340
341 if(blkno != inoblkno) { 341 if(blkno != inoblkno) {
342 bread(LFS_FSBTODB(sblock, blkno), (char *)inoblock,  342 bread(LFS_FSBTODB(sblock, blkno), (char *)inoblock,
343 (int)sblock->lfs_bsize); 343 (int)lfs_sb_getbsize(sblock));
344#ifdef notyet 344#ifdef notyet
345 if (needswap) 345 if (needswap)
346 for (i = 0; i < MAXINOPB; i++) 346 for (i = 0; i < MAXINOPB; i++)
347 ffs_dinode_swap(&inoblock[i], &inoblock[i]); 347 ffs_dinode_swap(&inoblock[i], &inoblock[i]);
348#endif 348#endif
349 } 349 }
350 return (void *)lfs_ifind(sblock, inum, inoblock); 350 return (void *)lfs_ifind(sblock, inum, inoblock);
351} 351}
352 352
353/* 353/*
354 * Tell the filesystem not to overwrite any currently dirty segments 354 * Tell the filesystem not to overwrite any currently dirty segments
355 * until we are finished. (It may still write into clean segments, of course, 355 * until we are finished. (It may still write into clean segments, of course,
356 * since we're not using those.) This is only called when dump_lfs is called 356 * since we're not using those.) This is only called when dump_lfs is called

cvs diff -r1.33 -r1.34 src/sbin/fsck_lfs/dir.c (expand / switch to unified diff)

--- src/sbin/fsck_lfs/dir.c 2015/03/29 19:35:58 1.33
+++ src/sbin/fsck_lfs/dir.c 2015/07/24 06:56:41 1.34
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dir.c,v 1.33 2015/03/29 19:35:58 chopps Exp $ */ 1/* $NetBSD: dir.c,v 1.34 2015/07/24 06:56:41 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1986, 1993 4 * Copyright (c) 1980, 1986, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -131,27 +131,27 @@ dirscan(struct inodesc *idesc) @@ -131,27 +131,27 @@ dirscan(struct inodesc *idesc)
131{ 131{
132 struct lfs_direct *dp; 132 struct lfs_direct *dp;
133 struct ubuf *bp; 133 struct ubuf *bp;
134 int dsize, n; 134 int dsize, n;
135 long blksiz; 135 long blksiz;
136 char dbuf[LFS_DIRBLKSIZ]; 136 char dbuf[LFS_DIRBLKSIZ];
137 struct uvnode *vp; 137 struct uvnode *vp;
138 138
139 if (idesc->id_type != DATA) 139 if (idesc->id_type != DATA)
140 errexit("wrong type to dirscan %d", idesc->id_type); 140 errexit("wrong type to dirscan %d", idesc->id_type);
141 if (idesc->id_entryno == 0 && 141 if (idesc->id_entryno == 0 &&
142 (idesc->id_filesize & (LFS_DIRBLKSIZ - 1)) != 0) 142 (idesc->id_filesize & (LFS_DIRBLKSIZ - 1)) != 0)
143 idesc->id_filesize = roundup(idesc->id_filesize, LFS_DIRBLKSIZ); 143 idesc->id_filesize = roundup(idesc->id_filesize, LFS_DIRBLKSIZ);
144 blksiz = idesc->id_numfrags * fs->lfs_fsize; 144 blksiz = idesc->id_numfrags * lfs_sb_getfsize(fs);
145 if (chkrange(idesc->id_blkno, idesc->id_numfrags)) { 145 if (chkrange(idesc->id_blkno, idesc->id_numfrags)) {
146 idesc->id_filesize -= blksiz; 146 idesc->id_filesize -= blksiz;
147 return (SKIP); 147 return (SKIP);
148 } 148 }
149 idesc->id_loc = 0; 149 idesc->id_loc = 0;
150 150
151 vp = vget(fs, idesc->id_number); 151 vp = vget(fs, idesc->id_number);
152 for (dp = fsck_readdir(vp, idesc); dp != NULL; 152 for (dp = fsck_readdir(vp, idesc); dp != NULL;
153 dp = fsck_readdir(vp, idesc)) { 153 dp = fsck_readdir(vp, idesc)) {
154 dsize = dp->d_reclen; 154 dsize = dp->d_reclen;
155 memcpy(dbuf, dp, (size_t) dsize); 155 memcpy(dbuf, dp, (size_t) dsize);
156 idesc->id_dirp = (struct lfs_direct *) dbuf; 156 idesc->id_dirp = (struct lfs_direct *) dbuf;
157 if ((n = (*idesc->id_func) (idesc)) & ALTERED) { 157 if ((n = (*idesc->id_func) (idesc)) & ALTERED) {
@@ -167,27 +167,27 @@ dirscan(struct inodesc *idesc) @@ -167,27 +167,27 @@ dirscan(struct inodesc *idesc)
167 return (idesc->id_filesize > 0 ? KEEPON : STOP); 167 return (idesc->id_filesize > 0 ? KEEPON : STOP);
168} 168}
169 169
170/* 170/*
171 * get next entry in a directory. 171 * get next entry in a directory.
172 */ 172 */
173static struct lfs_direct * 173static struct lfs_direct *
174fsck_readdir(struct uvnode *vp, struct inodesc *idesc) 174fsck_readdir(struct uvnode *vp, struct inodesc *idesc)
175{ 175{
176 struct lfs_direct *dp, *ndp; 176 struct lfs_direct *dp, *ndp;
177 struct ubuf *bp; 177 struct ubuf *bp;
178 long size, blksiz, fix, dploc; 178 long size, blksiz, fix, dploc;
179 179
180 blksiz = idesc->id_numfrags * fs->lfs_fsize; 180 blksiz = idesc->id_numfrags * lfs_sb_getfsize(fs);
181 bread(vp, idesc->id_lblkno, blksiz, 0, &bp); 181 bread(vp, idesc->id_lblkno, blksiz, 0, &bp);
182 if (idesc->id_loc % LFS_DIRBLKSIZ == 0 && idesc->id_filesize > 0 && 182 if (idesc->id_loc % LFS_DIRBLKSIZ == 0 && idesc->id_filesize > 0 &&
183 idesc->id_loc < blksiz) { 183 idesc->id_loc < blksiz) {
184 dp = (struct lfs_direct *) (bp->b_data + idesc->id_loc); 184 dp = (struct lfs_direct *) (bp->b_data + idesc->id_loc);
185 if (dircheck(idesc, dp)) 185 if (dircheck(idesc, dp))
186 goto dpok; 186 goto dpok;
187 brelse(bp, 0); 187 brelse(bp, 0);
188 if (idesc->id_fix == IGNORE) 188 if (idesc->id_fix == IGNORE)
189 return (0); 189 return (0);
190 fix = dofix(idesc, "DIRECTORY CORRUPTED"); 190 fix = dofix(idesc, "DIRECTORY CORRUPTED");
191 bread(vp, idesc->id_lblkno, blksiz, 0, &bp); 191 bread(vp, idesc->id_lblkno, blksiz, 0, &bp);
192 dp = (struct lfs_direct *) (bp->b_data + idesc->id_loc); 192 dp = (struct lfs_direct *) (bp->b_data + idesc->id_loc);
193 dp->d_reclen = LFS_DIRBLKSIZ; 193 dp->d_reclen = LFS_DIRBLKSIZ;
@@ -558,93 +558,93 @@ makeentry(ino_t parent, ino_t ino, const @@ -558,93 +558,93 @@ makeentry(ino_t parent, ino_t ino, const
558 */ 558 */
559static int 559static int
560expanddir(struct uvnode *vp, struct ulfs1_dinode *dp, char *name) 560expanddir(struct uvnode *vp, struct ulfs1_dinode *dp, char *name)
561{ 561{
562 daddr_t lastbn; 562 daddr_t lastbn;
563 struct ubuf *bp; 563 struct ubuf *bp;
564 char *cp, firstblk[LFS_DIRBLKSIZ]; 564 char *cp, firstblk[LFS_DIRBLKSIZ];
565 565
566 lastbn = lfs_lblkno(fs, dp->di_size); 566 lastbn = lfs_lblkno(fs, dp->di_size);
567 if (lastbn >= ULFS_NDADDR - 1 || dp->di_db[lastbn] == 0 || dp->di_size == 0) 567 if (lastbn >= ULFS_NDADDR - 1 || dp->di_db[lastbn] == 0 || dp->di_size == 0)
568 return (0); 568 return (0);
569 dp->di_db[lastbn + 1] = dp->di_db[lastbn]; 569 dp->di_db[lastbn + 1] = dp->di_db[lastbn];
570 dp->di_db[lastbn] = 0; 570 dp->di_db[lastbn] = 0;
571 bp = getblk(vp, lastbn, fs->lfs_bsize); 571 bp = getblk(vp, lastbn, lfs_sb_getbsize(fs));
572 VOP_BWRITE(bp); 572 VOP_BWRITE(bp);
573 dp->di_size += fs->lfs_bsize; 573 dp->di_size += lfs_sb_getbsize(fs);
574 dp->di_blocks += lfs_btofsb(fs, fs->lfs_bsize); 574 dp->di_blocks += lfs_btofsb(fs, lfs_sb_getbsize(fs));
575 bread(vp, dp->di_db[lastbn + 1], 575 bread(vp, dp->di_db[lastbn + 1],
576 (long) lfs_dblksize(fs, dp, lastbn + 1), 0, &bp); 576 (long) lfs_dblksize(fs, dp, lastbn + 1), 0, &bp);
577 if (bp->b_flags & B_ERROR) 577 if (bp->b_flags & B_ERROR)
578 goto bad; 578 goto bad;
579 memcpy(firstblk, bp->b_data, LFS_DIRBLKSIZ); 579 memcpy(firstblk, bp->b_data, LFS_DIRBLKSIZ);
580 bread(vp, lastbn, fs->lfs_bsize, 0, &bp); 580 bread(vp, lastbn, lfs_sb_getbsize(fs), 0, &bp);
581 if (bp->b_flags & B_ERROR) 581 if (bp->b_flags & B_ERROR)
582 goto bad; 582 goto bad;
583 memcpy(bp->b_data, firstblk, LFS_DIRBLKSIZ); 583 memcpy(bp->b_data, firstblk, LFS_DIRBLKSIZ);
584 for (cp = &bp->b_data[LFS_DIRBLKSIZ]; 584 for (cp = &bp->b_data[LFS_DIRBLKSIZ];
585 cp < &bp->b_data[fs->lfs_bsize]; 585 cp < &bp->b_data[lfs_sb_getbsize(fs)];
586 cp += LFS_DIRBLKSIZ) 586 cp += LFS_DIRBLKSIZ)
587 memcpy(cp, &emptydir, sizeof emptydir); 587 memcpy(cp, &emptydir, sizeof emptydir);
588 VOP_BWRITE(bp); 588 VOP_BWRITE(bp);
589 bread(vp, dp->di_db[lastbn + 1], 589 bread(vp, dp->di_db[lastbn + 1],
590 (long) lfs_dblksize(fs, dp, lastbn + 1), 0, &bp); 590 (long) lfs_dblksize(fs, dp, lastbn + 1), 0, &bp);
591 if (bp->b_flags & B_ERROR) 591 if (bp->b_flags & B_ERROR)
592 goto bad; 592 goto bad;
593 memcpy(bp->b_data, &emptydir, sizeof emptydir); 593 memcpy(bp->b_data, &emptydir, sizeof emptydir);
594 pwarn("NO SPACE LEFT IN %s", name); 594 pwarn("NO SPACE LEFT IN %s", name);
595 if (preen) 595 if (preen)
596 printf(" (EXPANDED)\n"); 596 printf(" (EXPANDED)\n");
597 else if (reply("EXPAND") == 0) 597 else if (reply("EXPAND") == 0)
598 goto bad; 598 goto bad;
599 VOP_BWRITE(bp); 599 VOP_BWRITE(bp);
600 inodirty(VTOI(vp)); 600 inodirty(VTOI(vp));
601 return (1); 601 return (1);
602bad: 602bad:
603 dp->di_db[lastbn] = dp->di_db[lastbn + 1]; 603 dp->di_db[lastbn] = dp->di_db[lastbn + 1];
604 dp->di_db[lastbn + 1] = 0; 604 dp->di_db[lastbn + 1] = 0;
605 dp->di_size -= fs->lfs_bsize; 605 dp->di_size -= lfs_sb_getbsize(fs);
606 dp->di_blocks -= lfs_btofsb(fs, fs->lfs_bsize); 606 dp->di_blocks -= lfs_btofsb(fs, lfs_sb_getbsize(fs));
607 return (0); 607 return (0);
608} 608}
609 609
610/* 610/*
611 * allocate a new directory 611 * allocate a new directory
612 */ 612 */
613int 613int
614allocdir(ino_t parent, ino_t request, int mode) 614allocdir(ino_t parent, ino_t request, int mode)
615{ 615{
616 ino_t ino; 616 ino_t ino;
617 char *cp; 617 char *cp;
618 struct ulfs1_dinode *dp; 618 struct ulfs1_dinode *dp;
619 struct ubuf *bp; 619 struct ubuf *bp;
620 struct lfs_dirtemplate *dirp; 620 struct lfs_dirtemplate *dirp;
621 struct uvnode *vp; 621 struct uvnode *vp;
622 622
623 ino = allocino(request, LFS_IFDIR | mode); 623 ino = allocino(request, LFS_IFDIR | mode);
624 dirp = &dirhead; 624 dirp = &dirhead;
625 dirp->dot_ino = ino; 625 dirp->dot_ino = ino;
626 dirp->dotdot_ino = parent; 626 dirp->dotdot_ino = parent;
627 vp = vget(fs, ino); 627 vp = vget(fs, ino);
628 dp = VTOD(vp); 628 dp = VTOD(vp);
629 bread(vp, dp->di_db[0], fs->lfs_fsize, 0, &bp); 629 bread(vp, dp->di_db[0], lfs_sb_getfsize(fs), 0, &bp);
630 if (bp->b_flags & B_ERROR) { 630 if (bp->b_flags & B_ERROR) {
631 brelse(bp, 0); 631 brelse(bp, 0);
632 freeino(ino); 632 freeino(ino);
633 return (0); 633 return (0);
634 } 634 }
635 memcpy(bp->b_data, dirp, sizeof(struct lfs_dirtemplate)); 635 memcpy(bp->b_data, dirp, sizeof(struct lfs_dirtemplate));
636 for (cp = &bp->b_data[LFS_DIRBLKSIZ]; 636 for (cp = &bp->b_data[LFS_DIRBLKSIZ];
637 cp < &bp->b_data[fs->lfs_fsize]; 637 cp < &bp->b_data[lfs_sb_getfsize(fs)];
638 cp += LFS_DIRBLKSIZ) 638 cp += LFS_DIRBLKSIZ)
639 memcpy(cp, &emptydir, sizeof emptydir); 639 memcpy(cp, &emptydir, sizeof emptydir);
640 VOP_BWRITE(bp); 640 VOP_BWRITE(bp);
641 dp->di_nlink = 2; 641 dp->di_nlink = 2;
642 inodirty(VTOI(vp)); 642 inodirty(VTOI(vp));
643 if (ino == ULFS_ROOTINO) { 643 if (ino == ULFS_ROOTINO) {
644 lncntp[ino] = dp->di_nlink; 644 lncntp[ino] = dp->di_nlink;
645 cacheino(dp, ino); 645 cacheino(dp, ino);
646 return (ino); 646 return (ino);
647 } 647 }
648 if (statemap[parent] != DSTATE && statemap[parent] != DFOUND) { 648 if (statemap[parent] != DSTATE && statemap[parent] != DFOUND) {
649 freeino(ino); 649 freeino(ino);
650 return (0); 650 return (0);

cvs diff -r1.54 -r1.55 src/sbin/fsck_lfs/inode.c (expand / switch to unified diff)

--- src/sbin/fsck_lfs/inode.c 2015/06/16 23:18:55 1.54
+++ src/sbin/fsck_lfs/inode.c 2015/07/24 06:56:41 1.55
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: inode.c,v 1.54 2015/06/16 23:18:55 christos Exp $ */ 1/* $NetBSD: inode.c,v 1.55 2015/07/24 06:56:41 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. 4 * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant@hhhh.org>. 8 * by Konrad E. Schroder <perseant@hhhh.org>.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -132,74 +132,74 @@ ckinode(struct ulfs1_dinode *dp, struct  @@ -132,74 +132,74 @@ ckinode(struct ulfs1_dinode *dp, struct
132 struct uvnode *vp, *thisvp; 132 struct uvnode *vp, *thisvp;
133 133
134 if (idesc->id_fix != IGNORE) 134 if (idesc->id_fix != IGNORE)
135 idesc->id_fix = DONTKNOW; 135 idesc->id_fix = DONTKNOW;
136 idesc->id_entryno = 0; 136 idesc->id_entryno = 0;
137 idesc->id_filesize = dp->di_size; 137 idesc->id_filesize = dp->di_size;
138 mode = dp->di_mode & LFS_IFMT; 138 mode = dp->di_mode & LFS_IFMT;
139 if (mode == LFS_IFBLK || mode == LFS_IFCHR || 139 if (mode == LFS_IFBLK || mode == LFS_IFCHR ||
140 (mode == LFS_IFLNK && (dp->di_size < fs->lfs_maxsymlinklen || 140 (mode == LFS_IFLNK && (dp->di_size < fs->lfs_maxsymlinklen ||
141 (fs->lfs_maxsymlinklen == 0 && 141 (fs->lfs_maxsymlinklen == 0 &&
142 dp->di_blocks == 0)))) 142 dp->di_blocks == 0))))
143 return (KEEPON); 143 return (KEEPON);
144 dino = *dp; 144 dino = *dp;
145 ndb = howmany(dino.di_size, fs->lfs_bsize); 145 ndb = howmany(dino.di_size, lfs_sb_getbsize(fs));
146 146
147 thisvp = vget(fs, idesc->id_number); 147 thisvp = vget(fs, idesc->id_number);
148 for (lbn = 0; lbn < ULFS_NDADDR; lbn++) { 148 for (lbn = 0; lbn < ULFS_NDADDR; lbn++) {
149 ap = dino.di_db + lbn; 149 ap = dino.di_db + lbn;
150 if (thisvp) 150 if (thisvp)
151 idesc->id_numfrags = 151 idesc->id_numfrags =
152 lfs_numfrags(fs, VTOI(thisvp)->i_lfs_fragsize[lbn]); 152 lfs_numfrags(fs, VTOI(thisvp)->i_lfs_fragsize[lbn]);
153 else { 153 else {
154 if (--ndb == 0 && (offset = lfs_blkoff(fs, dino.di_size)) != 0) { 154 if (--ndb == 0 && (offset = lfs_blkoff(fs, dino.di_size)) != 0) {
155 idesc->id_numfrags = 155 idesc->id_numfrags =
156 lfs_numfrags(fs, lfs_fragroundup(fs, offset)); 156 lfs_numfrags(fs, lfs_fragroundup(fs, offset));
157 } else 157 } else
158 idesc->id_numfrags = fs->lfs_frag; 158 idesc->id_numfrags = lfs_sb_getfrag(fs);
159 } 159 }
160 if (*ap == 0) { 160 if (*ap == 0) {
161 if (idesc->id_type == DATA && ndb >= 0) { 161 if (idesc->id_type == DATA && ndb >= 0) {
162 /* An empty block in a directory XXX */ 162 /* An empty block in a directory XXX */
163 getpathname(pathbuf, sizeof(pathbuf), 163 getpathname(pathbuf, sizeof(pathbuf),
164 idesc->id_number, idesc->id_number); 164 idesc->id_number, idesc->id_number);
165 pfatal("DIRECTORY %s INO %lld: CONTAINS EMPTY BLOCKS [1]", 165 pfatal("DIRECTORY %s INO %lld: CONTAINS EMPTY BLOCKS [1]",
166 pathbuf, (long long)idesc->id_number); 166 pathbuf, (long long)idesc->id_number);
167 if (reply("ADJUST LENGTH") == 1) { 167 if (reply("ADJUST LENGTH") == 1) {
168 vp = vget(fs, idesc->id_number); 168 vp = vget(fs, idesc->id_number);
169 dp = VTOD(vp); 169 dp = VTOD(vp);
170 dp->di_size = (ap - &dino.di_db[0]) * 170 dp->di_size = (ap - &dino.di_db[0]) *
171 fs->lfs_bsize; 171 lfs_sb_getbsize(fs);
172 printf( 172 printf(
173 "YOU MUST RERUN FSCK AFTERWARDS\n"); 173 "YOU MUST RERUN FSCK AFTERWARDS\n");
174 rerun = 1; 174 rerun = 1;
175 inodirty(VTOI(vp)); 175 inodirty(VTOI(vp));
176 } else 176 } else
177 break; 177 break;
178 } 178 }
179 continue; 179 continue;
180 } 180 }
181 idesc->id_blkno = *ap; 181 idesc->id_blkno = *ap;
182 idesc->id_lblkno = ap - &dino.di_db[0]; 182 idesc->id_lblkno = ap - &dino.di_db[0];
183 if (idesc->id_type == ADDR) { 183 if (idesc->id_type == ADDR) {
184 ret = (*idesc->id_func) (idesc); 184 ret = (*idesc->id_func) (idesc);
185 } else 185 } else
186 ret = dirscan(idesc); 186 ret = dirscan(idesc);
187 if (ret & STOP) 187 if (ret & STOP)
188 return (ret); 188 return (ret);
189 } 189 }
190 idesc->id_numfrags = fs->lfs_frag; 190 idesc->id_numfrags = lfs_sb_getfrag(fs);
191 remsize = dino.di_size - fs->lfs_bsize * ULFS_NDADDR; 191 remsize = dino.di_size - lfs_sb_getbsize(fs) * ULFS_NDADDR;
192 sizepb = fs->lfs_bsize; 192 sizepb = lfs_sb_getbsize(fs);
193 for (ap = &dino.di_ib[0], n = 1; n <= ULFS_NIADDR; ap++, n++) { 193 for (ap = &dino.di_ib[0], n = 1; n <= ULFS_NIADDR; ap++, n++) {
194 if (*ap) { 194 if (*ap) {
195 idesc->id_blkno = *ap; 195 idesc->id_blkno = *ap;
196 ret = iblock(idesc, n, remsize); 196 ret = iblock(idesc, n, remsize);
197 if (ret & STOP) 197 if (ret & STOP)
198 return (ret); 198 return (ret);
199 } else { 199 } else {
200 if (idesc->id_type == DATA && remsize > 0) { 200 if (idesc->id_type == DATA && remsize > 0) {
201 /* An empty block in a directory XXX */ 201 /* An empty block in a directory XXX */
202 getpathname(pathbuf, sizeof(pathbuf), 202 getpathname(pathbuf, sizeof(pathbuf),
203 idesc->id_number, idesc->id_number); 203 idesc->id_number, idesc->id_number);
204 pfatal("DIRECTORY %s INO %lld: CONTAINS EMPTY BLOCKS [2]", 204 pfatal("DIRECTORY %s INO %lld: CONTAINS EMPTY BLOCKS [2]",
205 pathbuf, (long long)idesc->id_number); 205 pathbuf, (long long)idesc->id_number);
@@ -235,30 +235,30 @@ iblock(struct inodesc *idesc, long ileve @@ -235,30 +235,30 @@ iblock(struct inodesc *idesc, long ileve
235 int diddirty = 0; 235 int diddirty = 0;
236 236
237 if (idesc->id_type == ADDR) { 237 if (idesc->id_type == ADDR) {
238 func = idesc->id_func; 238 func = idesc->id_func;
239 n = (*func) (idesc); 239 n = (*func) (idesc);
240 if ((n & KEEPON) == 0) 240 if ((n & KEEPON) == 0)
241 return (n); 241 return (n);
242 } else 242 } else
243 func = dirscan; 243 func = dirscan;
244 if (chkrange(idesc->id_blkno, idesc->id_numfrags)) 244 if (chkrange(idesc->id_blkno, idesc->id_numfrags))
245 return (SKIP); 245 return (SKIP);
246 246
247 devvp = fs->lfs_devvp; 247 devvp = fs->lfs_devvp;
248 bread(devvp, LFS_FSBTODB(fs, idesc->id_blkno), fs->lfs_bsize, 248 bread(devvp, LFS_FSBTODB(fs, idesc->id_blkno), lfs_sb_getbsize(fs),
249 0, &bp); 249 0, &bp);
250 ilevel--; 250 ilevel--;
251 for (sizepb = fs->lfs_bsize, i = 0; i < ilevel; i++) 251 for (sizepb = lfs_sb_getbsize(fs), i = 0; i < ilevel; i++)
252 sizepb *= LFS_NINDIR(fs); 252 sizepb *= LFS_NINDIR(fs);
253 if (isize > sizepb * LFS_NINDIR(fs)) 253 if (isize > sizepb * LFS_NINDIR(fs))
254 nif = LFS_NINDIR(fs); 254 nif = LFS_NINDIR(fs);
255 else 255 else
256 nif = howmany(isize, sizepb); 256 nif = howmany(isize, sizepb);
257 if (idesc->id_func == pass1check && nif < LFS_NINDIR(fs)) { 257 if (idesc->id_func == pass1check && nif < LFS_NINDIR(fs)) {
258 aplim = ((ulfs_daddr_t *) bp->b_data) + LFS_NINDIR(fs); 258 aplim = ((ulfs_daddr_t *) bp->b_data) + LFS_NINDIR(fs);
259 for (ap = ((ulfs_daddr_t *) bp->b_data) + nif; ap < aplim; ap++) { 259 for (ap = ((ulfs_daddr_t *) bp->b_data) + nif; ap < aplim; ap++) {
260 if (*ap == 0) 260 if (*ap == 0)
261 continue; 261 continue;
262 (void)snprintf(buf, sizeof(buf), 262 (void)snprintf(buf, sizeof(buf),
263 "PARTIALLY TRUNCATED INODE I=%llu", 263 "PARTIALLY TRUNCATED INODE I=%llu",
264 (unsigned long long)idesc->id_number); 264 (unsigned long long)idesc->id_number);
@@ -346,27 +346,27 @@ chkrange(daddr_t blk, int cnt) @@ -346,27 +346,27 @@ chkrange(daddr_t blk, int cnt)
346 * Routines to maintain information about directory inodes. 346 * Routines to maintain information about directory inodes.
347 * This is built during the first pass and used during the 347 * This is built during the first pass and used during the
348 * second and third passes. 348 * second and third passes.
349 * 349 *
350 * Enter inodes into the cache. 350 * Enter inodes into the cache.
351 */ 351 */
352void 352void
353cacheino(struct ulfs1_dinode * dp, ino_t inumber) 353cacheino(struct ulfs1_dinode * dp, ino_t inumber)
354{ 354{
355 struct inoinfo *inp; 355 struct inoinfo *inp;
356 struct inoinfo **inpp, **ninpsort; 356 struct inoinfo **inpp, **ninpsort;
357 unsigned int blks; 357 unsigned int blks;
358 358
359 blks = howmany(dp->di_size, fs->lfs_bsize); 359 blks = howmany(dp->di_size, lfs_sb_getbsize(fs));
360 if (blks > ULFS_NDADDR) 360 if (blks > ULFS_NDADDR)
361 blks = ULFS_NDADDR + ULFS_NIADDR; 361 blks = ULFS_NDADDR + ULFS_NIADDR;
362 inp = emalloc(sizeof(*inp) + (blks - 1) * sizeof(ulfs_daddr_t)); 362 inp = emalloc(sizeof(*inp) + (blks - 1) * sizeof(ulfs_daddr_t));
363 inpp = &inphead[inumber % numdirs]; 363 inpp = &inphead[inumber % numdirs];
364 inp->i_nexthash = *inpp; 364 inp->i_nexthash = *inpp;
365 *inpp = inp; 365 *inpp = inp;
366 inp->i_child = inp->i_sibling = inp->i_parentp = 0; 366 inp->i_child = inp->i_sibling = inp->i_parentp = 0;
367 if (inumber == ULFS_ROOTINO) 367 if (inumber == ULFS_ROOTINO)
368 inp->i_parent = ULFS_ROOTINO; 368 inp->i_parent = ULFS_ROOTINO;
369 else 369 else
370 inp->i_parent = (ino_t) 0; 370 inp->i_parent = (ino_t) 0;
371 inp->i_dotdot = (ino_t) 0; 371 inp->i_dotdot = (ino_t) 0;
372 inp->i_number = inumber; 372 inp->i_number = inumber;
@@ -453,28 +453,28 @@ clearinode(ino_t inumber) @@ -453,28 +453,28 @@ clearinode(ino_t inumber)
453 struct ubuf *bp; 453 struct ubuf *bp;
454 IFILE *ifp; 454 IFILE *ifp;
455 daddr_t daddr; 455 daddr_t daddr;
456 456
457 /* Send cleared inode to the free list */ 457 /* Send cleared inode to the free list */
458 458
459 LFS_IENTRY(ifp, fs, inumber, bp); 459 LFS_IENTRY(ifp, fs, inumber, bp);
460 daddr = ifp->if_daddr; 460 daddr = ifp->if_daddr;
461 if (daddr == LFS_UNUSED_DADDR) { 461 if (daddr == LFS_UNUSED_DADDR) {
462 brelse(bp, 0); 462 brelse(bp, 0);
463 return; 463 return;
464 } 464 }
465 ifp->if_daddr = LFS_UNUSED_DADDR; 465 ifp->if_daddr = LFS_UNUSED_DADDR;
466 ifp->if_nextfree = fs->lfs_freehd; 466 ifp->if_nextfree = lfs_sb_getfreehd(fs);
467 fs->lfs_freehd = inumber; 467 lfs_sb_setfreehd(fs, inumber);
468 sbdirty(); 468 sbdirty();
469 VOP_BWRITE(bp); 469 VOP_BWRITE(bp);
470 470
471 /* 471 /*
472 * update segment usage. 472 * update segment usage.
473 */ 473 */
474 if (daddr != LFS_UNUSED_DADDR) { 474 if (daddr != LFS_UNUSED_DADDR) {
475 SEGUSE *sup; 475 SEGUSE *sup;
476 u_int32_t oldsn = lfs_dtosn(fs, daddr); 476 u_int32_t oldsn = lfs_dtosn(fs, daddr);
477 477
478 seg_table[oldsn].su_nbytes -= LFS_DINODE1_SIZE; 478 seg_table[oldsn].su_nbytes -= LFS_DINODE1_SIZE;
479 LFS_SEGENTRY(sup, fs, oldsn, bp); 479 LFS_SEGENTRY(sup, fs, oldsn, bp);
480 sup->su_nbytes -= LFS_DINODE1_SIZE; 480 sup->su_nbytes -= LFS_DINODE1_SIZE;
@@ -598,34 +598,34 @@ allocino(ino_t request, int type) @@ -598,34 +598,34 @@ allocino(ino_t request, int type)
598 statemap[ino] = DSTATE; 598 statemap[ino] = DSTATE;
599 break; 599 break;
600 case LFS_IFREG: 600 case LFS_IFREG:
601 case LFS_IFLNK: 601 case LFS_IFLNK:
602 statemap[ino] = FSTATE; 602 statemap[ino] = FSTATE;
603 break; 603 break;
604 default: 604 default:
605 return (0); 605 return (0);
606 } 606 }
607 vp = lfs_valloc(fs, ino); 607 vp = lfs_valloc(fs, ino);
608 if (vp == NULL) 608 if (vp == NULL)
609 return (0); 609 return (0);
610 dp = (VTOI(vp)->i_din.ffs1_din); 610 dp = (VTOI(vp)->i_din.ffs1_din);
611 bp = getblk(vp, 0, fs->lfs_fsize); 611 bp = getblk(vp, 0, lfs_sb_getfsize(fs));
612 VOP_BWRITE(bp); 612 VOP_BWRITE(bp);
613 dp->di_mode = type; 613 dp->di_mode = type;
614 (void) time(&t); 614 (void) time(&t);
615 dp->di_atime = t; 615 dp->di_atime = t;
616 dp->di_mtime = dp->di_ctime = dp->di_atime; 616 dp->di_mtime = dp->di_ctime = dp->di_atime;
617 dp->di_size = fs->lfs_fsize; 617 dp->di_size = lfs_sb_getfsize(fs);
618 dp->di_blocks = lfs_btofsb(fs, fs->lfs_fsize); 618 dp->di_blocks = lfs_btofsb(fs, lfs_sb_getfsize(fs));
619 n_files++; 619 n_files++;
620 inodirty(VTOI(vp)); 620 inodirty(VTOI(vp));
621 typemap[ino] = LFS_IFTODT(type); 621 typemap[ino] = LFS_IFTODT(type);
622 return (ino); 622 return (ino);
623} 623}
624 624
625/* 625/*
626 * deallocate an inode 626 * deallocate an inode
627 */ 627 */
628void 628void
629freeino(ino_t ino) 629freeino(ino_t ino)
630{ 630{
631 struct inodesc idesc; 631 struct inodesc idesc;

cvs diff -r1.45 -r1.46 src/sbin/fsck_lfs/lfs.c (expand / switch to unified diff)

--- src/sbin/fsck_lfs/lfs.c 2015/05/31 15:44:30 1.45
+++ src/sbin/fsck_lfs/lfs.c 2015/07/24 06:56:41 1.46
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lfs.c,v 1.45 2015/05/31 15:44:30 hannken Exp $ */ 1/* $NetBSD: lfs.c,v 1.46 2015/07/24 06:56:41 dholland Exp $ */
2/*- 2/*-
3 * Copyright (c) 2003 The NetBSD Foundation, Inc. 3 * Copyright (c) 2003 The NetBSD Foundation, Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * This code is derived from software contributed to The NetBSD Foundation 6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Konrad E. Schroder <perseant@hhhh.org>. 7 * by Konrad E. Schroder <perseant@hhhh.org>.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -133,27 +133,27 @@ lfs_vop_strategy(struct ubuf * bp) @@ -133,27 +133,27 @@ lfs_vop_strategy(struct ubuf * bp)
133 bp->b_flags &= ~B_DELWRI; 133 bp->b_flags &= ~B_DELWRI;
134 reassignbuf(bp, bp->b_vp); 134 reassignbuf(bp, bp->b_vp);
135 } 135 }
136 return 0; 136 return 0;
137} 137}
138 138
139int 139int
140lfs_vop_bwrite(struct ubuf * bp) 140lfs_vop_bwrite(struct ubuf * bp)
141{ 141{
142 struct lfs *fs; 142 struct lfs *fs;
143 143
144 fs = bp->b_vp->v_fs; 144 fs = bp->b_vp->v_fs;
145 if (!(bp->b_flags & B_DELWRI)) { 145 if (!(bp->b_flags & B_DELWRI)) {
146 fs->lfs_avail -= lfs_btofsb(fs, bp->b_bcount); 146 lfs_sb_subavail(fs, lfs_btofsb(fs, bp->b_bcount));
147 } 147 }
148 bp->b_flags |= B_DELWRI | B_LOCKED; 148 bp->b_flags |= B_DELWRI | B_LOCKED;
149 reassignbuf(bp, bp->b_vp); 149 reassignbuf(bp, bp->b_vp);
150 brelse(bp, 0); 150 brelse(bp, 0);
151 return 0; 151 return 0;
152} 152}
153 153
154/* 154/*
155 * ulfs_bmaparray does the bmap conversion, and if requested returns the 155 * ulfs_bmaparray does the bmap conversion, and if requested returns the
156 * array of logical blocks which must be traversed to get to a block. 156 * array of logical blocks which must be traversed to get to a block.
157 * Each entry contains the offset into that block that gets you to the 157 * Each entry contains the offset into that block that gets you to the
158 * next block and the disk address of the block (if it is assigned). 158 * next block and the disk address of the block (if it is assigned).
159 */ 159 */
@@ -194,27 +194,27 @@ ulfs_bmaparray(struct lfs * fs, struct u @@ -194,27 +194,27 @@ ulfs_bmaparray(struct lfs * fs, struct u
194 * looking for an indirect block and we've found it. */ 194 * looking for an indirect block and we've found it. */
195 195
196 metalbn = xap->in_lbn; 196 metalbn = xap->in_lbn;
197 if ((daddr == 0 && !incore(vp, metalbn)) || metalbn == bn) 197 if ((daddr == 0 && !incore(vp, metalbn)) || metalbn == bn)
198 break; 198 break;
199 /* 199 /*
200 * If we get here, we've either got the block in the cache 200 * If we get here, we've either got the block in the cache
201 * or we have a disk address for it, go fetch it. 201 * or we have a disk address for it, go fetch it.
202 */ 202 */
203 if (bp) 203 if (bp)
204 brelse(bp, 0); 204 brelse(bp, 0);
205 205
206 xap->in_exists = 1; 206 xap->in_exists = 1;
207 bp = getblk(vp, metalbn, fs->lfs_bsize); 207 bp = getblk(vp, metalbn, lfs_sb_getbsize(fs));
208 208
209 if (!(bp->b_flags & (B_DONE | B_DELWRI))) { 209 if (!(bp->b_flags & (B_DONE | B_DELWRI))) {
210 bp->b_blkno = LFS_FSBTODB(fs, daddr); 210 bp->b_blkno = LFS_FSBTODB(fs, daddr);
211 bp->b_flags |= B_READ; 211 bp->b_flags |= B_READ;
212 VOP_STRATEGY(bp); 212 VOP_STRATEGY(bp);
213 } 213 }
214 daddr = ((ulfs_daddr_t *) bp->b_data)[xap->in_off]; 214 daddr = ((ulfs_daddr_t *) bp->b_data)[xap->in_off];
215 } 215 }
216 if (bp) 216 if (bp)
217 brelse(bp, 0); 217 brelse(bp, 0);
218 218
219 daddr = LFS_FSBTODB(fs, (ulfs_daddr_t) daddr); 219 daddr = LFS_FSBTODB(fs, (ulfs_daddr_t) daddr);
220 *bnp = daddr == 0 ? -1 : daddr; 220 *bnp = daddr == 0 ? -1 : daddr;
@@ -476,38 +476,38 @@ lfs_init(int devfd, daddr_t sblkno, dadd @@ -476,38 +476,38 @@ lfs_init(int devfd, daddr_t sblkno, dadd
476 } else if (debug) { 476 } else if (debug) {
477 printf("No -b flag given, not attempting to verify checkpoint\n"); 477 printf("No -b flag given, not attempting to verify checkpoint\n");
478 } 478 }
479 479
480 dev_bsize = DEV_BSIZE; 480 dev_bsize = DEV_BSIZE;
481 481
482 (void)bread(devvp, sblkno, LFS_SBPAD, 0, &bp); 482 (void)bread(devvp, sblkno, LFS_SBPAD, 0, &bp);
483 fs = ecalloc(1, sizeof(*fs)); 483 fs = ecalloc(1, sizeof(*fs));
484 fs->lfs_dlfs = *((struct dlfs *) bp->b_data); 484 fs->lfs_dlfs = *((struct dlfs *) bp->b_data);
485 fs->lfs_devvp = devvp; 485 fs->lfs_devvp = devvp;
486 bp->b_flags |= B_INVAL; 486 bp->b_flags |= B_INVAL;
487 brelse(bp, 0); 487 brelse(bp, 0);
488 488
489 dev_bsize = fs->lfs_fsize >> fs->lfs_fsbtodb; 489 dev_bsize = lfs_sb_getfsize(fs) >> fs->lfs_fsbtodb;
490  490
491 if (tryalt) { 491 if (tryalt) {
492 (void)bread(devvp, LFS_FSBTODB(fs, fs->lfs_sboffs[1]), 492 (void)bread(devvp, LFS_FSBTODB(fs, fs->lfs_sboffs[1]),
493 LFS_SBPAD, 0, &bp); 493 LFS_SBPAD, 0, &bp);
494 altfs = ecalloc(1, sizeof(*altfs)); 494 altfs = ecalloc(1, sizeof(*altfs));
495 altfs->lfs_dlfs = *((struct dlfs *) bp->b_data); 495 altfs->lfs_dlfs = *((struct dlfs *) bp->b_data);
496 altfs->lfs_devvp = devvp; 496 altfs->lfs_devvp = devvp;
497 bp->b_flags |= B_INVAL; 497 bp->b_flags |= B_INVAL;
498 brelse(bp, 0); 498 brelse(bp, 0);
499  499
500 if (check_sb(fs) || fs->lfs_idaddr <= 0) { 500 if (check_sb(fs) || lfs_sb_getidaddr(fs) <= 0) {
501 if (debug) 501 if (debug)
502 printf("Primary superblock is no good, using first alternate\n"); 502 printf("Primary superblock is no good, using first alternate\n");
503 free(fs); 503 free(fs);
504 fs = altfs; 504 fs = altfs;
505 } else { 505 } else {
506 /* If both superblocks check out, try verification */ 506 /* If both superblocks check out, try verification */
507 if (check_sb(altfs)) { 507 if (check_sb(altfs)) {
508 if (debug) 508 if (debug)
509 printf("First alternate superblock is no good, using primary\n"); 509 printf("First alternate superblock is no good, using primary\n");
510 free(altfs); 510 free(altfs);
511 } else { 511 } else {
512 if (lfs_verify(fs, altfs, devvp, debug) == fs) { 512 if (lfs_verify(fs, altfs, devvp, debug) == fs) {
513 free(altfs); 513 free(altfs);
@@ -517,46 +517,46 @@ lfs_init(int devfd, daddr_t sblkno, dadd @@ -517,46 +517,46 @@ lfs_init(int devfd, daddr_t sblkno, dadd
517 } 517 }
518 } 518 }
519 } 519 }
520 } 520 }
521 if (check_sb(fs)) { 521 if (check_sb(fs)) {
522 free(fs); 522 free(fs);
523 return NULL; 523 return NULL;
524 } 524 }
525 } 525 }
526 526
527 /* Compatibility */ 527 /* Compatibility */
528 if (fs->lfs_version < 2) { 528 if (fs->lfs_version < 2) {
529 fs->lfs_sumsize = LFS_V1_SUMMARY_SIZE; 529 fs->lfs_sumsize = LFS_V1_SUMMARY_SIZE;
530 fs->lfs_ibsize = fs->lfs_bsize; 530 fs->lfs_ibsize = lfs_sb_getbsize(fs);
531 fs->lfs_s0addr = fs->lfs_sboffs[0]; 531 fs->lfs_s0addr = fs->lfs_sboffs[0];
532 fs->lfs_tstamp = fs->lfs_otstamp; 532 lfs_sb_settstamp(fs, lfs_sb_getotstamp(fs));
533 fs->lfs_fsbtodb = 0; 533 fs->lfs_fsbtodb = 0;
534 } 534 }
535 535
536 if (!dummy_read) { 536 if (!dummy_read) {
537 fs->lfs_suflags = emalloc(2 * sizeof(u_int32_t *)); 537 fs->lfs_suflags = emalloc(2 * sizeof(u_int32_t *));
538 fs->lfs_suflags[0] = emalloc(fs->lfs_nseg * sizeof(u_int32_t)); 538 fs->lfs_suflags[0] = emalloc(fs->lfs_nseg * sizeof(u_int32_t));
539 fs->lfs_suflags[1] = emalloc(fs->lfs_nseg * sizeof(u_int32_t)); 539 fs->lfs_suflags[1] = emalloc(fs->lfs_nseg * sizeof(u_int32_t));
540 } 540 }
541 541
542 if (idaddr == 0) 542 if (idaddr == 0)
543 idaddr = fs->lfs_idaddr; 543 idaddr = lfs_sb_getidaddr(fs);
544 else 544 else
545 fs->lfs_idaddr = idaddr; 545 lfs_sb_setidaddr(fs, idaddr);
546 /* NB: If dummy_read!=0, idaddr==0 here so we get a fake inode. */ 546 /* NB: If dummy_read!=0, idaddr==0 here so we get a fake inode. */
547 fs->lfs_ivnode = lfs_raw_vget(fs, 547 fs->lfs_ivnode = lfs_raw_vget(fs,
548 (dummy_read ? LFS_IFILE_INUM : fs->lfs_ifile), devvp->v_fd, 548 (dummy_read ? LFS_IFILE_INUM : lfs_sb_getifile(fs)),
549 idaddr); 549 devvp->v_fd, idaddr);
550 if (fs->lfs_ivnode == NULL) 550 if (fs->lfs_ivnode == NULL)
551 return NULL; 551 return NULL;
552 552
553 register_vget((void *)fs, lfs_vget); 553 register_vget((void *)fs, lfs_vget);
554 554
555 return fs; 555 return fs;
556} 556}
557 557
558/* 558/*
559 * Check partial segment validity between fs->lfs_offset and the given goal. 559 * Check partial segment validity between fs->lfs_offset and the given goal.
560 * 560 *
561 * If goal == 0, just keep on going until the segments stop making sense, 561 * If goal == 0, just keep on going until the segments stop making sense,
562 * and return the address of the last valid partial segment. 562 * and return the address of the last valid partial segment.
@@ -568,29 +568,29 @@ lfs_init(int devfd, daddr_t sblkno, dadd @@ -568,29 +568,29 @@ lfs_init(int devfd, daddr_t sblkno, dadd
568ulfs_daddr_t 568ulfs_daddr_t
569try_verify(struct lfs *osb, struct uvnode *devvp, ulfs_daddr_t goal, int debug) 569try_verify(struct lfs *osb, struct uvnode *devvp, ulfs_daddr_t goal, int debug)
570{ 570{
571 ulfs_daddr_t daddr, odaddr; 571 ulfs_daddr_t daddr, odaddr;
572 SEGSUM *sp; 572 SEGSUM *sp;
573 int i, bc, hitclean; 573 int i, bc, hitclean;
574 struct ubuf *bp; 574 struct ubuf *bp;
575 ulfs_daddr_t nodirop_daddr; 575 ulfs_daddr_t nodirop_daddr;
576 u_int64_t serial; 576 u_int64_t serial;
577 577
578 bc = 0; 578 bc = 0;
579 hitclean = 0; 579 hitclean = 0;
580 odaddr = -1; 580 odaddr = -1;
581 daddr = osb->lfs_offset; 581 daddr = lfs_sb_getoffset(osb);
582 nodirop_daddr = daddr; 582 nodirop_daddr = daddr;
583 serial = osb->lfs_serial; 583 serial = lfs_sb_getserial(osb);
584 while (daddr != goal) { 584 while (daddr != goal) {
585 /* 585 /*
586 * Don't mistakenly read a superblock, if there is one here. 586 * Don't mistakenly read a superblock, if there is one here.
587 */ 587 */
588 if (lfs_sntod(osb, lfs_dtosn(osb, daddr)) == daddr) { 588 if (lfs_sntod(osb, lfs_dtosn(osb, daddr)) == daddr) {
589 if (daddr == osb->lfs_s0addr) 589 if (daddr == osb->lfs_s0addr)
590 daddr += lfs_btofsb(osb, LFS_LABELPAD); 590 daddr += lfs_btofsb(osb, LFS_LABELPAD);
591 for (i = 0; i < LFS_MAXNUMSB; i++) { 591 for (i = 0; i < LFS_MAXNUMSB; i++) {
592 if (osb->lfs_sboffs[i] < daddr) 592 if (osb->lfs_sboffs[i] < daddr)
593 break; 593 break;
594 if (osb->lfs_sboffs[i] == daddr) 594 if (osb->lfs_sboffs[i] == daddr)
595 daddr += lfs_btofsb(osb, LFS_SBPAD); 595 daddr += lfs_btofsb(osb, LFS_SBPAD);
596 } 596 }
@@ -639,27 +639,27 @@ try_verify(struct lfs *osb, struct uvnod @@ -639,27 +639,27 @@ try_verify(struct lfs *osb, struct uvnod
639 bc = check_summary(osb, sp, daddr, debug, devvp, NULL); 639 bc = check_summary(osb, sp, daddr, debug, devvp, NULL);
640 if (bc == 0) { 640 if (bc == 0) {
641 brelse(bp, 0); 641 brelse(bp, 0);
642 break; 642 break;
643 } 643 }
644 if (debug) 644 if (debug)
645 pwarn("summary good: 0x%x/%d\n", (int)daddr, 645 pwarn("summary good: 0x%x/%d\n", (int)daddr,
646 (int)sp->ss_serial); 646 (int)sp->ss_serial);
647 assert (bc > 0); 647 assert (bc > 0);
648 odaddr = daddr; 648 odaddr = daddr;
649 daddr += lfs_btofsb(osb, osb->lfs_sumsize + bc); 649 daddr += lfs_btofsb(osb, osb->lfs_sumsize + bc);
650 if (lfs_dtosn(osb, odaddr) != lfs_dtosn(osb, daddr) || 650 if (lfs_dtosn(osb, odaddr) != lfs_dtosn(osb, daddr) ||
651 lfs_dtosn(osb, daddr) != lfs_dtosn(osb, daddr + 651 lfs_dtosn(osb, daddr) != lfs_dtosn(osb, daddr +
652 lfs_btofsb(osb, osb->lfs_sumsize + osb->lfs_bsize) - 1)) { 652 lfs_btofsb(osb, osb->lfs_sumsize + lfs_sb_getbsize(osb)) - 1)) {
653 daddr = sp->ss_next; 653 daddr = sp->ss_next;
654 } 654 }
655 655
656 /* 656 /*
657 * Check for the beginning and ending of a sequence of 657 * Check for the beginning and ending of a sequence of
658 * dirops. Writes from the cleaner never involve new 658 * dirops. Writes from the cleaner never involve new
659 * information, and are always checkpoints; so don't try 659 * information, and are always checkpoints; so don't try
660 * to roll forward through them. Likewise, psegs written 660 * to roll forward through them. Likewise, psegs written
661 * by a previous roll-forward attempt are not interesting. 661 * by a previous roll-forward attempt are not interesting.
662 */ 662 */
663 if (sp->ss_flags & (SS_CLEAN | SS_RFW)) 663 if (sp->ss_flags & (SS_CLEAN | SS_RFW))
664 hitclean = 1; 664 hitclean = 1;
665 if (hitclean == 0 && (sp->ss_flags & SS_CONT) == 0) 665 if (hitclean == 0 && (sp->ss_flags & SS_CONT) == 0)
@@ -679,67 +679,67 @@ struct lfs * @@ -679,67 +679,67 @@ struct lfs *
679lfs_verify(struct lfs *sb0, struct lfs *sb1, struct uvnode *devvp, int debug) 679lfs_verify(struct lfs *sb0, struct lfs *sb1, struct uvnode *devvp, int debug)
680{ 680{
681 ulfs_daddr_t daddr; 681 ulfs_daddr_t daddr;
682 struct lfs *osb, *nsb; 682 struct lfs *osb, *nsb;
683 683
684 /* 684 /*
685 * Verify the checkpoint of the newer superblock, 685 * Verify the checkpoint of the newer superblock,
686 * if the timestamp/serial number of the two superblocks is 686 * if the timestamp/serial number of the two superblocks is
687 * different. 687 * different.
688 */ 688 */
689 689
690 osb = NULL; 690 osb = NULL;
691 if (debug) 691 if (debug)
692 pwarn("sb0 %lld, sb1 %lld", 692 pwarn("sb0 %ju, sb1 %ju",
693 (long long) sb0->lfs_serial, 693 (uintmax_t) lfs_sb_getserial(sb0),
694 (long long) sb1->lfs_serial); 694 (uintmax_t) lfs_sb_getserial(sb1));
695 695
696 if ((sb0->lfs_version == 1 && 696 if ((sb0->lfs_version == 1 &&
697 sb0->lfs_otstamp != sb1->lfs_otstamp) || 697 lfs_sb_getotstamp(sb0) != lfs_sb_getotstamp(sb1)) ||
698 (sb0->lfs_version > 1 && 698 (sb0->lfs_version > 1 &&
699 sb0->lfs_serial != sb1->lfs_serial)) { 699 lfs_sb_getserial(sb0) != lfs_sb_getserial(sb1))) {
700 if (sb0->lfs_version == 1) { 700 if (sb0->lfs_version == 1) {
701 if (sb0->lfs_otstamp > sb1->lfs_otstamp) { 701 if (lfs_sb_getotstamp(sb0) > lfs_sb_getotstamp(sb1)) {
702 osb = sb1; 702 osb = sb1;
703 nsb = sb0; 703 nsb = sb0;
704 } else { 704 } else {
705 osb = sb0; 705 osb = sb0;
706 nsb = sb1; 706 nsb = sb1;
707 } 707 }
708 } else { 708 } else {
709 if (sb0->lfs_serial > sb1->lfs_serial) { 709 if (lfs_sb_getserial(sb0) > lfs_sb_getserial(sb1)) {
710 osb = sb1; 710 osb = sb1;
711 nsb = sb0; 711 nsb = sb0;
712 } else { 712 } else {
713 osb = sb0; 713 osb = sb0;
714 nsb = sb1; 714 nsb = sb1;
715 } 715 }
716 } 716 }
717 if (debug) { 717 if (debug) {
718 printf("Attempting to verify newer checkpoint..."); 718 printf("Attempting to verify newer checkpoint...");
719 fflush(stdout); 719 fflush(stdout);
720 } 720 }
721 daddr = try_verify(osb, devvp, nsb->lfs_offset, debug); 721 daddr = try_verify(osb, devvp, lfs_sb_getoffset(nsb), debug);
722 722
723 if (debug) 723 if (debug)
724 printf("done.\n"); 724 printf("done.\n");
725 if (daddr == nsb->lfs_offset) { 725 if (daddr == lfs_sb_getoffset(nsb)) {
726 pwarn("** Newer checkpoint verified, recovered %lld seconds of data\n", 726 pwarn("** Newer checkpoint verified; recovered %jd seconds of data\n",
727 (long long) nsb->lfs_tstamp - (long long) osb->lfs_tstamp); 727 (intmax_t)(lfs_sb_gettstamp(nsb) - lfs_sb_gettstamp(osb)));
728 sbdirty(); 728 sbdirty();
729 } else { 729 } else {
730 pwarn("** Newer checkpoint invalid, lost %lld seconds of data\n", (long long) nsb->lfs_tstamp - (long long) osb->lfs_tstamp); 730 pwarn("** Newer checkpoint invalid; lost %jd seconds of data\n", (intmax_t)(lfs_sb_gettstamp(nsb) - lfs_sb_gettstamp(osb)));
731 } 731 }
732 return (daddr == nsb->lfs_offset ? nsb : osb); 732 return (daddr == lfs_sb_getoffset(nsb) ? nsb : osb);
733 } 733 }
734 /* Nothing to check */ 734 /* Nothing to check */
735 return osb; 735 return osb;
736} 736}
737 737
738/* Verify a partial-segment summary; return the number of bytes on disk. */ 738/* Verify a partial-segment summary; return the number of bytes on disk. */
739int 739int
740check_summary(struct lfs *fs, SEGSUM *sp, ulfs_daddr_t pseg_addr, int debug, 740check_summary(struct lfs *fs, SEGSUM *sp, ulfs_daddr_t pseg_addr, int debug,
741 struct uvnode *devvp, void (func(ulfs_daddr_t, FINFO *))) 741 struct uvnode *devvp, void (func(ulfs_daddr_t, FINFO *)))
742{ 742{
743 FINFO *fp; 743 FINFO *fp;
744 int bc; /* Bytes in partial segment */ 744 int bc; /* Bytes in partial segment */
745 int nblocks; 745 int nblocks;
@@ -794,27 +794,27 @@ check_summary(struct lfs *fs, SEGSUM *sp @@ -794,27 +794,27 @@ check_summary(struct lfs *fs, SEGSUM *sp
794 datap[datac++] = ((u_int32_t *) (bp->b_data))[0]; 794 datap[datac++] = ((u_int32_t *) (bp->b_data))[0];
795 brelse(bp, 0); 795 brelse(bp, 0);
796 796
797 ++j; 797 ++j;
798 daddr += lfs_btofsb(fs, fs->lfs_ibsize); 798 daddr += lfs_btofsb(fs, fs->lfs_ibsize);
799 --idp; 799 --idp;
800 } 800 }
801 if (i < sp->ss_nfinfo) { 801 if (i < sp->ss_nfinfo) {
802 if (func) 802 if (func)
803 func(daddr, fp); 803 func(daddr, fp);
804 for (k = 0; k < fp->fi_nblocks; k++) { 804 for (k = 0; k < fp->fi_nblocks; k++) {
805 len = (k == fp->fi_nblocks - 1 ? 805 len = (k == fp->fi_nblocks - 1 ?
806 fp->fi_lastlength 806 fp->fi_lastlength
807 : fs->lfs_bsize); 807 : lfs_sb_getbsize(fs));
808 bread(devvp, LFS_FSBTODB(fs, daddr), len, 808 bread(devvp, LFS_FSBTODB(fs, daddr), len,
809 0, &bp); 809 0, &bp);
810 datap[datac++] = ((u_int32_t *) (bp->b_data))[0]; 810 datap[datac++] = ((u_int32_t *) (bp->b_data))[0];
811 brelse(bp, 0); 811 brelse(bp, 0);
812 daddr += lfs_btofsb(fs, len); 812 daddr += lfs_btofsb(fs, len);
813 } 813 }
814 fp = (FINFO *) (fp->fi_blocks + fp->fi_nblocks); 814 fp = (FINFO *) (fp->fi_blocks + fp->fi_nblocks);
815 } 815 }
816 } 816 }
817 817
818 if (datac != nblocks) { 818 if (datac != nblocks) {
819 pwarn("Partial segment at 0x%llx expected %d blocks counted %d\n", 819 pwarn("Partial segment at 0x%llx expected %d blocks counted %d\n",
820 (long long) pseg_addr, nblocks, datac); 820 (long long) pseg_addr, nblocks, datac);
@@ -866,36 +866,36 @@ lfs_valloc(struct lfs *fs, ino_t ino) @@ -866,36 +866,36 @@ lfs_valloc(struct lfs *fs, ino_t ino)
866 866
867 /* 867 /*
868 * Remove the inode from the free list and write the new start 868 * Remove the inode from the free list and write the new start
869 * of the free list into the superblock. 869 * of the free list into the superblock.
870 */ 870 */
871 LFS_IENTRY(ifp, fs, new_ino, bp); 871 LFS_IENTRY(ifp, fs, new_ino, bp);
872 if (ifp->if_daddr != LFS_UNUSED_DADDR) 872 if (ifp->if_daddr != LFS_UNUSED_DADDR)
873 panic("lfs_valloc: inuse inode %d on the free list", new_ino); 873 panic("lfs_valloc: inuse inode %d on the free list", new_ino);
874 LFS_PUT_HEADFREE(fs, cip, cbp, ifp->if_nextfree); 874 LFS_PUT_HEADFREE(fs, cip, cbp, ifp->if_nextfree);
875 875
876 brelse(bp, 0); 876 brelse(bp, 0);
877 877
878 /* Extend IFILE so that the next lfs_valloc will succeed. */ 878 /* Extend IFILE so that the next lfs_valloc will succeed. */
879 if (fs->lfs_freehd == LFS_UNUSED_INUM) { 879 if (lfs_sb_getfreehd(fs) == LFS_UNUSED_INUM) {
880 if ((error = extend_ifile(fs)) != 0) { 880 if ((error = extend_ifile(fs)) != 0) {
881 LFS_PUT_HEADFREE(fs, cip, cbp, new_ino); 881 LFS_PUT_HEADFREE(fs, cip, cbp, new_ino);
882 return NULL; 882 return NULL;
883 } 883 }
884 } 884 }
885 885
886 /* Set superblock modified bit and increment file count. */ 886 /* Set superblock modified bit and increment file count. */
887 sbdirty(); 887 sbdirty();
888 ++fs->lfs_nfiles; 888 lfs_sb_addnfiles(fs, 1);
889 889
890 return lfs_raw_vget(fs, ino, fs->lfs_devvp->v_fd, 0x0); 890 return lfs_raw_vget(fs, ino, fs->lfs_devvp->v_fd, 0x0);
891} 891}
892 892
893#ifdef IN_FSCK_LFS 893#ifdef IN_FSCK_LFS
894void reset_maxino(ino_t); 894void reset_maxino(ino_t);
895#endif 895#endif
896 896
897/* 897/*
898 * Add a new block to the Ifile, to accommodate future file creations. 898 * Add a new block to the Ifile, to accommodate future file creations.
899 */ 899 */
900int 900int
901extend_ifile(struct lfs *fs) 901extend_ifile(struct lfs *fs)
@@ -903,61 +903,62 @@ extend_ifile(struct lfs *fs) @@ -903,61 +903,62 @@ extend_ifile(struct lfs *fs)
903 struct uvnode *vp; 903 struct uvnode *vp;
904 struct inode *ip; 904 struct inode *ip;
905 IFILE *ifp; 905 IFILE *ifp;
906 IFILE_V1 *ifp_v1; 906 IFILE_V1 *ifp_v1;
907 struct ubuf *bp, *cbp; 907 struct ubuf *bp, *cbp;
908 daddr_t i, blkno, max; 908 daddr_t i, blkno, max;
909 ino_t oldlast; 909 ino_t oldlast;
910 CLEANERINFO *cip; 910 CLEANERINFO *cip;
911 911
912 vp = fs->lfs_ivnode; 912 vp = fs->lfs_ivnode;
913 ip = VTOI(vp); 913 ip = VTOI(vp);
914 blkno = lfs_lblkno(fs, ip->i_ffs1_size); 914 blkno = lfs_lblkno(fs, ip->i_ffs1_size);
915 915
916 lfs_balloc(vp, ip->i_ffs1_size, fs->lfs_bsize, &bp); 916 lfs_balloc(vp, ip->i_ffs1_size, lfs_sb_getbsize(fs), &bp);
917 ip->i_ffs1_size += fs->lfs_bsize; 917 ip->i_ffs1_size += lfs_sb_getbsize(fs);
918 ip->i_flag |= IN_MODIFIED; 918 ip->i_flag |= IN_MODIFIED;
919  919
920 i = (blkno - fs->lfs_segtabsz - fs->lfs_cleansz) * 920 i = (blkno - lfs_sb_getsegtabsz(fs) - lfs_sb_getcleansz(fs)) *
921 fs->lfs_ifpb; 921 lfs_sb_getifpb(fs);
922 LFS_GET_HEADFREE(fs, cip, cbp, &oldlast); 922 LFS_GET_HEADFREE(fs, cip, cbp, &oldlast);
923 LFS_PUT_HEADFREE(fs, cip, cbp, i); 923 LFS_PUT_HEADFREE(fs, cip, cbp, i);
924 max = i + fs->lfs_ifpb; 924 max = i + lfs_sb_getifpb(fs);
925 fs->lfs_bfree -= lfs_btofsb(fs, fs->lfs_bsize); 925 lfs_sb_subbfree(fs, lfs_btofsb(fs, lfs_sb_getbsize(fs)));
926 926
927 if (fs->lfs_version == 1) { 927 if (fs->lfs_version == 1) {
928 for (ifp_v1 = (IFILE_V1 *)bp->b_data; i < max; ++ifp_v1) { 928 for (ifp_v1 = (IFILE_V1 *)bp->b_data; i < max; ++ifp_v1) {
929 ifp_v1->if_version = 1; 929 ifp_v1->if_version = 1;
930 ifp_v1->if_daddr = LFS_UNUSED_DADDR; 930 ifp_v1->if_daddr = LFS_UNUSED_DADDR;
931 ifp_v1->if_nextfree = ++i; 931 ifp_v1->if_nextfree = ++i;
932 } 932 }
933 ifp_v1--; 933 ifp_v1--;
934 ifp_v1->if_nextfree = oldlast; 934 ifp_v1->if_nextfree = oldlast;
935 } else { 935 } else {
936 for (ifp = (IFILE *)bp->b_data; i < max; ++ifp) { 936 for (ifp = (IFILE *)bp->b_data; i < max; ++ifp) {
937 ifp->if_version = 1; 937 ifp->if_version = 1;
938 ifp->if_daddr = LFS_UNUSED_DADDR; 938 ifp->if_daddr = LFS_UNUSED_DADDR;
939 ifp->if_nextfree = ++i; 939 ifp->if_nextfree = ++i;
940 } 940 }
941 ifp--; 941 ifp--;
942 ifp->if_nextfree = oldlast; 942 ifp->if_nextfree = oldlast;
943 } 943 }
944 LFS_PUT_TAILFREE(fs, cip, cbp, max - 1); 944 LFS_PUT_TAILFREE(fs, cip, cbp, max - 1);
945 945
946 LFS_BWRITE_LOG(bp); 946 LFS_BWRITE_LOG(bp);
947 947
948#ifdef IN_FSCK_LFS 948#ifdef IN_FSCK_LFS
949 reset_maxino(((ip->i_ffs1_size >> fs->lfs_bshift) - fs->lfs_segtabsz - 949 reset_maxino(((ip->i_ffs1_size >> fs->lfs_bshift)
950 fs->lfs_cleansz) * fs->lfs_ifpb); 950 - lfs_sb_getsegtabsz(fs)
 951 - lfs_sb_getcleansz(fs)) * lfs_sb_getifpb(fs));
951#endif 952#endif
952 return 0; 953 return 0;
953} 954}
954 955
955/* 956/*
956 * Allocate a block, and to inode and filesystem block accounting for it 957 * Allocate a block, and to inode and filesystem block accounting for it
957 * and for any indirect blocks the may need to be created in order for 958 * and for any indirect blocks the may need to be created in order for
958 * this block to be created. 959 * this block to be created.
959 * 960 *
960 * Blocks which have never been accounted for (i.e., which "do not exist") 961 * Blocks which have never been accounted for (i.e., which "do not exist")
961 * have disk address 0, which is translated by ulfs_bmap to the special value 962 * have disk address 0, which is translated by ulfs_bmap to the special value
962 * UNASSIGNED == -1, as in the historical ULFS. 963 * UNASSIGNED == -1, as in the historical ULFS.
963 * 964 *
@@ -996,58 +997,58 @@ lfs_balloc(struct uvnode *vp, off_t star @@ -996,58 +997,58 @@ lfs_balloc(struct uvnode *vp, off_t star
996 * 997 *
997 * If we are writing a block beyond the end of the file, we need to 998 * If we are writing a block beyond the end of the file, we need to
998 * check if the old last block was a fragment. If it was, we need 999 * check if the old last block was a fragment. If it was, we need
999 * to rewrite it. 1000 * to rewrite it.
1000 */ 1001 */
1001 1002
1002 if (bpp) 1003 if (bpp)
1003 *bpp = NULL; 1004 *bpp = NULL;
1004 1005
1005 /* Check for block beyond end of file and fragment extension needed. */ 1006 /* Check for block beyond end of file and fragment extension needed. */
1006 lastblock = lfs_lblkno(fs, ip->i_ffs1_size); 1007 lastblock = lfs_lblkno(fs, ip->i_ffs1_size);
1007 if (lastblock < ULFS_NDADDR && lastblock < lbn) { 1008 if (lastblock < ULFS_NDADDR && lastblock < lbn) {
1008 osize = lfs_blksize(fs, ip, lastblock); 1009 osize = lfs_blksize(fs, ip, lastblock);
1009 if (osize < fs->lfs_bsize && osize > 0) { 1010 if (osize < lfs_sb_getbsize(fs) && osize > 0) {
1010 if ((error = lfs_fragextend(vp, osize, fs->lfs_bsize, 1011 if ((error = lfs_fragextend(vp, osize, lfs_sb_getbsize(fs),
1011 lastblock, 1012 lastblock,
1012 (bpp ? &bp : NULL)))) 1013 (bpp ? &bp : NULL))))
1013 return (error); 1014 return (error);
1014 ip->i_ffs1_size = (lastblock + 1) * fs->lfs_bsize; 1015 ip->i_ffs1_size = (lastblock + 1) * lfs_sb_getbsize(fs);
1015 ip->i_flag |= IN_CHANGE | IN_UPDATE; 1016 ip->i_flag |= IN_CHANGE | IN_UPDATE;
1016 if (bpp) 1017 if (bpp)
1017 (void) VOP_BWRITE(bp); 1018 (void) VOP_BWRITE(bp);
1018 } 1019 }
1019 } 1020 }
1020 1021
1021 /* 1022 /*
1022 * If the block we are writing is a direct block, it's the last 1023 * If the block we are writing is a direct block, it's the last
1023 * block in the file, and offset + iosize is less than a full 1024 * block in the file, and offset + iosize is less than a full
1024 * block, we can write one or more fragments. There are two cases: 1025 * block, we can write one or more fragments. There are two cases:
1025 * the block is brand new and we should allocate it the correct 1026 * the block is brand new and we should allocate it the correct
1026 * size or it already exists and contains some fragments and 1027 * size or it already exists and contains some fragments and
1027 * may need to extend it. 1028 * may need to extend it.
1028 */ 1029 */
1029 if (lbn < ULFS_NDADDR && lfs_lblkno(fs, ip->i_ffs1_size) <= lbn) { 1030 if (lbn < ULFS_NDADDR && lfs_lblkno(fs, ip->i_ffs1_size) <= lbn) {
1030 osize = lfs_blksize(fs, ip, lbn); 1031 osize = lfs_blksize(fs, ip, lbn);
1031 nsize = lfs_fragroundup(fs, offset + iosize); 1032 nsize = lfs_fragroundup(fs, offset + iosize);
1032 if (lfs_lblktosize(fs, lbn) >= ip->i_ffs1_size) { 1033 if (lfs_lblktosize(fs, lbn) >= ip->i_ffs1_size) {
1033 /* Brand new block or fragment */ 1034 /* Brand new block or fragment */
1034 frags = lfs_numfrags(fs, nsize); 1035 frags = lfs_numfrags(fs, nsize);
1035 if (bpp) { 1036 if (bpp) {
1036 *bpp = bp = getblk(vp, lbn, nsize); 1037 *bpp = bp = getblk(vp, lbn, nsize);
1037 bp->b_blkno = UNWRITTEN; 1038 bp->b_blkno = UNWRITTEN;
1038 } 1039 }
1039 ip->i_lfs_effnblks += frags; 1040 ip->i_lfs_effnblks += frags;
1040 fs->lfs_bfree -= frags; 1041 lfs_sb_subbfree(fs, frags);
1041 ip->i_ffs1_db[lbn] = UNWRITTEN; 1042 ip->i_ffs1_db[lbn] = UNWRITTEN;
1042 } else { 1043 } else {
1043 if (nsize <= osize) { 1044 if (nsize <= osize) {
1044 /* No need to extend */ 1045 /* No need to extend */
1045 if (bpp && (error = bread(vp, lbn, osize, 1046 if (bpp && (error = bread(vp, lbn, osize,
1046 0, &bp))) 1047 0, &bp)))
1047 return error; 1048 return error;
1048 } else { 1049 } else {
1049 /* Extend existing block */ 1050 /* Extend existing block */
1050 if ((error = 1051 if ((error =
1051 lfs_fragextend(vp, osize, nsize, lbn, 1052 lfs_fragextend(vp, osize, nsize, lbn,
1052 (bpp ? &bp : NULL)))) 1053 (bpp ? &bp : NULL))))
1053 return error; 1054 return error;
@@ -1068,42 +1069,42 @@ lfs_balloc(struct uvnode *vp, off_t star @@ -1068,42 +1069,42 @@ lfs_balloc(struct uvnode *vp, off_t star
1068 * Do byte accounting all at once, so we can gracefully fail *before* 1069 * Do byte accounting all at once, so we can gracefully fail *before*
1069 * we start assigning blocks. 1070 * we start assigning blocks.
1070 */ 1071 */
1071 frags = LFS_FSBTODB(fs, 1); /* frags = VFSTOULFS(vp->v_mount)->um_seqinc; */ 1072 frags = LFS_FSBTODB(fs, 1); /* frags = VFSTOULFS(vp->v_mount)->um_seqinc; */
1072 bcount = 0; 1073 bcount = 0;
1073 if (daddr == UNASSIGNED) { 1074 if (daddr == UNASSIGNED) {
1074 bcount = frags; 1075 bcount = frags;
1075 } 1076 }
1076 for (i = 1; i < num; ++i) { 1077 for (i = 1; i < num; ++i) {
1077 if (!indirs[i].in_exists) { 1078 if (!indirs[i].in_exists) {
1078 bcount += frags; 1079 bcount += frags;
1079 } 1080 }
1080 } 1081 }
1081 fs->lfs_bfree -= bcount; 1082 lfs_sb_subbfree(fs, bcount);
1082 ip->i_lfs_effnblks += bcount; 1083 ip->i_lfs_effnblks += bcount;
1083 1084
1084 if (daddr == UNASSIGNED) { 1085 if (daddr == UNASSIGNED) {
1085 if (num > 0 && ip->i_ffs1_ib[indirs[0].in_off] == 0) { 1086 if (num > 0 && ip->i_ffs1_ib[indirs[0].in_off] == 0) {
1086 ip->i_ffs1_ib[indirs[0].in_off] = UNWRITTEN; 1087 ip->i_ffs1_ib[indirs[0].in_off] = UNWRITTEN;
1087 } 1088 }
1088 1089
1089 /* 1090 /*
1090 * Create new indirect blocks if necessary 1091 * Create new indirect blocks if necessary
1091 */ 1092 */
1092 if (num > 1) { 1093 if (num > 1) {
1093 idaddr = ip->i_ffs1_ib[indirs[0].in_off]; 1094 idaddr = ip->i_ffs1_ib[indirs[0].in_off];
1094 for (i = 1; i < num; ++i) { 1095 for (i = 1; i < num; ++i) {
1095 ibp = getblk(vp, indirs[i].in_lbn, 1096 ibp = getblk(vp, indirs[i].in_lbn,
1096 fs->lfs_bsize); 1097 lfs_sb_getbsize(fs));
1097 if (!indirs[i].in_exists) { 1098 if (!indirs[i].in_exists) {
1098 memset(ibp->b_data, 0, ibp->b_bufsize); 1099 memset(ibp->b_data, 0, ibp->b_bufsize);
1099 ibp->b_blkno = UNWRITTEN; 1100 ibp->b_blkno = UNWRITTEN;
1100 } else if (!(ibp->b_flags & (B_DELWRI | B_DONE))) { 1101 } else if (!(ibp->b_flags & (B_DELWRI | B_DONE))) {
1101 ibp->b_blkno = LFS_FSBTODB(fs, idaddr); 1102 ibp->b_blkno = LFS_FSBTODB(fs, idaddr);
1102 ibp->b_flags |= B_READ; 1103 ibp->b_flags |= B_READ;
1103 VOP_STRATEGY(ibp); 1104 VOP_STRATEGY(ibp);
1104 } 1105 }
1105 /* 1106 /*
1106 * This block exists, but the next one may not. 1107 * This block exists, but the next one may not.
1107 * If that is the case mark it UNWRITTEN to 1108 * If that is the case mark it UNWRITTEN to
1108 * keep the accounting straight. 1109 * keep the accounting straight.
1109 */ 1110 */
@@ -1139,39 +1140,39 @@ lfs_balloc(struct uvnode *vp, off_t star @@ -1139,39 +1140,39 @@ lfs_balloc(struct uvnode *vp, off_t star
1139 /* Note the new address */ 1140 /* Note the new address */
1140 bp->b_blkno = UNWRITTEN; 1141 bp->b_blkno = UNWRITTEN;
1141 } 1142 }
1142 1143
1143 switch (num) { 1144 switch (num) {
1144 case 0: 1145 case 0:
1145 ip->i_ffs1_db[lbn] = UNWRITTEN; 1146 ip->i_ffs1_db[lbn] = UNWRITTEN;
1146 break; 1147 break;
1147 case 1: 1148 case 1:
1148 ip->i_ffs1_ib[indirs[0].in_off] = UNWRITTEN; 1149 ip->i_ffs1_ib[indirs[0].in_off] = UNWRITTEN;
1149 break; 1150 break;
1150 default: 1151 default:
1151 idp = &indirs[num - 1]; 1152 idp = &indirs[num - 1];
1152 if (bread(vp, idp->in_lbn, fs->lfs_bsize, 0, &ibp)) 1153 if (bread(vp, idp->in_lbn, lfs_sb_getbsize(fs), 0, &ibp))
1153 panic("lfs_balloc: bread bno %lld", 1154 panic("lfs_balloc: bread bno %lld",
1154 (long long)idp->in_lbn); 1155 (long long)idp->in_lbn);
1155 /* XXX ondisk32 */ 1156 /* XXX ondisk32 */
1156 ((int32_t *)ibp->b_data)[idp->in_off] = UNWRITTEN; 1157 ((int32_t *)ibp->b_data)[idp->in_off] = UNWRITTEN;
1157 VOP_BWRITE(ibp); 1158 VOP_BWRITE(ibp);
1158 } 1159 }
1159 } else if (bpp && !(bp->b_flags & (B_DONE|B_DELWRI))) { 1160 } else if (bpp && !(bp->b_flags & (B_DONE|B_DELWRI))) {
1160 /* 1161 /*
1161 * Not a brand new block, also not in the cache; 1162 * Not a brand new block, also not in the cache;
1162 * read it in from disk. 1163 * read it in from disk.
1163 */ 1164 */
1164 if (iosize == fs->lfs_bsize) 1165 if (iosize == lfs_sb_getbsize(fs))
1165 /* Optimization: I/O is unnecessary. */ 1166 /* Optimization: I/O is unnecessary. */
1166 bp->b_blkno = daddr; 1167 bp->b_blkno = daddr;
1167 else { 1168 else {
1168 /* 1169 /*
1169 * We need to read the block to preserve the 1170 * We need to read the block to preserve the
1170 * existing bytes. 1171 * existing bytes.
1171 */ 1172 */
1172 bp->b_blkno = daddr; 1173 bp->b_blkno = daddr;
1173 bp->b_flags |= B_READ; 1174 bp->b_flags |= B_READ;
1174 VOP_STRATEGY(bp); 1175 VOP_STRATEGY(bp);
1175 return 0; 1176 return 0;
1176 } 1177 }
1177 } 1178 }
@@ -1194,25 +1195,25 @@ lfs_fragextend(struct uvnode *vp, int os @@ -1194,25 +1195,25 @@ lfs_fragextend(struct uvnode *vp, int os
1194 error = 0; 1195 error = 0;
1195 1196
1196 /* 1197 /*
1197 * If we are not asked to actually return the block, all we need 1198 * If we are not asked to actually return the block, all we need
1198 * to do is allocate space for it. UBC will handle dirtying the 1199 * to do is allocate space for it. UBC will handle dirtying the
1199 * appropriate things and making sure it all goes to disk. 1200 * appropriate things and making sure it all goes to disk.
1200 * Don't bother to read in that case. 1201 * Don't bother to read in that case.
1201 */ 1202 */
1202 if (bpp && (error = bread(vp, lbn, osize, 0, bpp))) { 1203 if (bpp && (error = bread(vp, lbn, osize, 0, bpp))) {
1203 brelse(*bpp, 0); 1204 brelse(*bpp, 0);
1204 goto out; 1205 goto out;
1205 } 1206 }
1206 1207
1207 fs->lfs_bfree -= frags; 1208 lfs_sb_subbfree(fs, frags);
1208 ip->i_lfs_effnblks += frags; 1209 ip->i_lfs_effnblks += frags;
1209 ip->i_flag |= IN_CHANGE | IN_UPDATE; 1210 ip->i_flag |= IN_CHANGE | IN_UPDATE;
1210 1211
1211 if (bpp) { 1212 if (bpp) {
1212 (*bpp)->b_data = erealloc((*bpp)->b_data, nsize); 1213 (*bpp)->b_data = erealloc((*bpp)->b_data, nsize);
1213 (void)memset((*bpp)->b_data + osize, 0, nsize - osize); 1214 (void)memset((*bpp)->b_data + osize, 0, nsize - osize);
1214 } 1215 }
1215 1216
1216 out: 1217 out:
1217 return (error); 1218 return (error);
1218} 1219}

cvs diff -r1.49 -r1.50 src/sbin/fsck_lfs/main.c (expand / switch to unified diff)

--- src/sbin/fsck_lfs/main.c 2015/06/16 23:18:55 1.49
+++ src/sbin/fsck_lfs/main.c 2015/07/24 06:56:41 1.50
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: main.c,v 1.49 2015/06/16 23:18:55 christos Exp $ */ 1/* $NetBSD: main.c,v 1.50 2015/07/24 06:56:41 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1986, 1993 4 * Copyright (c) 1980, 1986, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -298,29 +298,29 @@ checkfilesys(const char *filesys, char * @@ -298,29 +298,29 @@ checkfilesys(const char *filesys, char *
298 else { 298 else {
299 pass6(); 299 pass6();
300 } 300 }
301 } 301 }
302 zlnhead = (struct zlncnt *) 0; 302 zlnhead = (struct zlncnt *) 0;
303 orphead = (struct zlncnt *) 0; 303 orphead = (struct zlncnt *) 0;
304 duplist = (struct dups *) 0; 304 duplist = (struct dups *) 0;
305 muldup = (struct dups *) 0; 305 muldup = (struct dups *) 0;
306 inocleanup(); 306 inocleanup();
307 307
308 /* 308 /*
309 * print out summary statistics 309 * print out summary statistics
310 */ 310 */
311 pwarn("%llu files, %lld used, %lld free\n", 311 pwarn("%ju files, %jd used, %jd free\n",
312 (unsigned long long)n_files, (long long) n_blks, 312 (uintmax_t) n_files, (intmax_t) n_blks,
313 (long long) fs->lfs_bfree); 313 (intmax_t) lfs_sb_getbfree(fs));
314 314
315 ckfini(1); 315 ckfini(1);
316 316
317 free(blockmap); 317 free(blockmap);
318 free(statemap); 318 free(statemap);
319 free((char *)lncntp); 319 free((char *)lncntp);
320 if (!fsmodified) { 320 if (!fsmodified) {
321 return FSCK_EXIT_OK; 321 return FSCK_EXIT_OK;
322 } 322 }
323 if (!preen) 323 if (!preen)
324 printf("\n***** FILE SYSTEM WAS MODIFIED *****\n"); 324 printf("\n***** FILE SYSTEM WAS MODIFIED *****\n");
325 if (rerun) 325 if (rerun)
326 printf("\n***** PLEASE RERUN FSCK *****\n"); 326 printf("\n***** PLEASE RERUN FSCK *****\n");

cvs diff -r1.35 -r1.36 src/sbin/fsck_lfs/pass0.c (expand / switch to unified diff)

--- src/sbin/fsck_lfs/pass0.c 2013/06/08 02:16:03 1.35
+++ src/sbin/fsck_lfs/pass0.c 2015/07/24 06:56:41 1.36
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pass0.c,v 1.35 2013/06/08 02:16:03 dholland Exp $ */ 1/* $NetBSD: pass0.c,v 1.36 2015/07/24 06:56:41 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant@hhhh.org>. 8 * by Konrad E. Schroder <perseant@hhhh.org>.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -188,42 +188,42 @@ pass0(void) @@ -188,42 +188,42 @@ pass0(void)
188 /* If freelist was empty, this is the tail */ 188 /* If freelist was empty, this is the tail */
189 if (plastino == 0) 189 if (plastino == 0)
190 plastino = ino; 190 plastino = ino;
191 } else 191 } else
192 brelse(bp, 0); 192 brelse(bp, 0);
193 } 193 }
194 194
195 LFS_CLEANERINFO(cip, fs, cbp); 195 LFS_CLEANERINFO(cip, fs, cbp);
196 if (cip->free_head != freehd) { 196 if (cip->free_head != freehd) {
197 /* They've already given us permission for this change */ 197 /* They've already given us permission for this change */
198 cip->free_head = freehd; 198 cip->free_head = freehd;
199 writeit = 1; 199 writeit = 1;
200 } 200 }
201 if (freehd != fs->lfs_freehd) { 201 if (freehd != lfs_sb_getfreehd(fs)) {
202 pwarn("FREE LIST HEAD IN SUPERBLOCK SHOULD BE %d (WAS %d)\n", 202 pwarn("FREE LIST HEAD IN SUPERBLOCK SHOULD BE %u (WAS %ju)\n",
203 (int)fs->lfs_freehd, (int)freehd); 203 lfs_sb_getfreehd(fs), (uintmax_t)freehd);
204 if (preen || reply("FIX")) { 204 if (preen || reply("FIX")) {
205 fs->lfs_freehd = freehd; 205 lfs_sb_setfreehd(fs, freehd);
206 sbdirty(); 206 sbdirty();
207 } 207 }
208 } 208 }
209 if (cip->free_tail != plastino) { 209 if (cip->free_tail != plastino) {
210 pwarn("FREE LIST TAIL SHOULD BE %llu (WAS %llu)\n", 210 pwarn("FREE LIST TAIL SHOULD BE %llu (WAS %llu)\n",
211 (unsigned long long)plastino, 211 (unsigned long long)plastino,
212 (unsigned long long)cip->free_tail); 212 (unsigned long long)cip->free_tail);
213 if (preen || reply("FIX")) { 213 if (preen || reply("FIX")) {
214 cip->free_tail = plastino; 214 cip->free_tail = plastino;
215 writeit = 1; 215 writeit = 1;
216 } 216 }
217 } 217 }
218 218
219 if (writeit) 219 if (writeit)
220 LFS_SYNC_CLEANERINFO(cip, fs, cbp, writeit); 220 LFS_SYNC_CLEANERINFO(cip, fs, cbp, writeit);
221 else 221 else
222 brelse(cbp, 0); 222 brelse(cbp, 0);
223 223
224 if (fs->lfs_freehd == 0) { 224 if (lfs_sb_getfreehd(fs) == 0) {
225 pwarn("%sree list head is 0x0\n", preen ? "f" : "F"); 225 pwarn("%sree list head is 0x0\n", preen ? "f" : "F");
226 if (preen || reply("FIX")) 226 if (preen || reply("FIX"))
227 extend_ifile(fs); 227 extend_ifile(fs);
228 } 228 }
229} 229}

cvs diff -r1.37 -r1.38 src/sbin/fsck_lfs/pass1.c (expand / switch to unified diff)

--- src/sbin/fsck_lfs/pass1.c 2013/06/18 18:18:58 1.37
+++ src/sbin/fsck_lfs/pass1.c 2015/07/24 06:56:41 1.38
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pass1.c,v 1.37 2013/06/18 18:18:58 christos Exp $ */ 1/* $NetBSD: pass1.c,v 1.38 2015/07/24 06:56:41 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1986, 1993 4 * Copyright (c) 1980, 1986, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -101,28 +101,28 @@ pass1(void) @@ -101,28 +101,28 @@ pass1(void)
101 idesc.id_type = ADDR; 101 idesc.id_type = ADDR;
102 idesc.id_func = pass1check; 102 idesc.id_func = pass1check;
103 idesc.id_lblkno = 0; 103 idesc.id_lblkno = 0;
104 inumber = 0; 104 inumber = 0;
105 n_files = n_blks = 0; 105 n_files = n_blks = 0;
106 106
107 if (debug) 107 if (debug)
108 printf("creating sorted inode address table...\n"); 108 printf("creating sorted inode address table...\n");
109 /* Sort by daddr */ 109 /* Sort by daddr */
110 dins = ecalloc(maxino, sizeof(*dins)); 110 dins = ecalloc(maxino, sizeof(*dins));
111 for (i = 0; i < maxino; i++) { 111 for (i = 0; i < maxino; i++) {
112 dins[i] = emalloc(sizeof(**dins)); 112 dins[i] = emalloc(sizeof(**dins));
113 dins[i]->ino = i; 113 dins[i]->ino = i;
114 if (i == fs->lfs_ifile) 114 if (i == lfs_sb_getifile(fs))
115 dins[i]->daddr = fs->lfs_idaddr; 115 dins[i]->daddr = lfs_sb_getidaddr(fs);
116 else { 116 else {
117 LFS_IENTRY(ifp, fs, i, bp); 117 LFS_IENTRY(ifp, fs, i, bp);
118 dins[i]->daddr = ifp->if_daddr; 118 dins[i]->daddr = ifp->if_daddr;
119 brelse(bp, 0); 119 brelse(bp, 0);
120 } 120 }
121 } 121 }
122 qsort(dins, maxino, sizeof(*dins), i_d_cmp); 122 qsort(dins, maxino, sizeof(*dins), i_d_cmp);
123 123
124 /* find a value for numdirs, fill in din_table */ 124 /* find a value for numdirs, fill in din_table */
125 if (debug) 125 if (debug)
126 printf("counting dirs...\n"); 126 printf("counting dirs...\n");
127 numdirs = 0; 127 numdirs = 0;
128 for (i = 0; i < maxino; i++) { 128 for (i = 0; i < maxino; i++) {
@@ -190,40 +190,40 @@ checkinode(ino_t inumber, struct inodesc @@ -190,40 +190,40 @@ checkinode(ino_t inumber, struct inodesc
190 pfatal("PARTIALLY ALLOCATED INODE I=%llu", 190 pfatal("PARTIALLY ALLOCATED INODE I=%llu",
191 (unsigned long long)inumber); 191 (unsigned long long)inumber);
192 if (reply("CLEAR") == 1) { 192 if (reply("CLEAR") == 1) {
193 vp = vget(fs, inumber); 193 vp = vget(fs, inumber);
194 clearinode(inumber); 194 clearinode(inumber);
195 vnode_destroy(vp); 195 vnode_destroy(vp);
196 } 196 }
197 } 197 }
198 statemap[inumber] = USTATE; 198 statemap[inumber] = USTATE;
199 return; 199 return;
200 } 200 }
201 lastino = inumber; 201 lastino = inumber;
202 if (/* dp->di_size < 0 || */ 202 if (/* dp->di_size < 0 || */
203 dp->di_size + fs->lfs_bsize - 1 < dp->di_size) { 203 dp->di_size + lfs_sb_getbsize(fs) - 1 < dp->di_size) {
204 if (debug) 204 if (debug)
205 printf("bad size %llu:", 205 printf("bad size %llu:",
206 (unsigned long long) dp->di_size); 206 (unsigned long long) dp->di_size);
207 goto unknown; 207 goto unknown;
208 } 208 }
209 if (!preen && mode == LFS_IFMT && reply("HOLD BAD BLOCK") == 1) { 209 if (!preen && mode == LFS_IFMT && reply("HOLD BAD BLOCK") == 1) {
210 vp = vget(fs, inumber); 210 vp = vget(fs, inumber);
211 dp = VTOD(vp); 211 dp = VTOD(vp);
212 dp->di_size = fs->lfs_fsize; 212 dp->di_size = lfs_sb_getfsize(fs);
213 dp->di_mode = LFS_IFREG | 0600; 213 dp->di_mode = LFS_IFREG | 0600;
214 inodirty(VTOI(vp)); 214 inodirty(VTOI(vp));
215 } 215 }
216 ndb = howmany(dp->di_size, fs->lfs_bsize); 216 ndb = howmany(dp->di_size, lfs_sb_getbsize(fs));
217 if (ndb < 0) { 217 if (ndb < 0) {
218 if (debug) 218 if (debug)
219 printf("bad size %llu ndb %d:", 219 printf("bad size %llu ndb %d:",
220 (unsigned long long) dp->di_size, ndb); 220 (unsigned long long) dp->di_size, ndb);
221 goto unknown; 221 goto unknown;
222 } 222 }
223 if (mode == LFS_IFBLK || mode == LFS_IFCHR) 223 if (mode == LFS_IFBLK || mode == LFS_IFCHR)
224 ndb++; 224 ndb++;
225 if (mode == LFS_IFLNK) { 225 if (mode == LFS_IFLNK) {
226 /* 226 /*
227 * Fake ndb value so direct/indirect block checks below 227 * Fake ndb value so direct/indirect block checks below
228 * will detect any garbage after symlink string. 228 * will detect any garbage after symlink string.
229 */ 229 */
@@ -329,27 +329,27 @@ pass1check(struct inodesc *idesc) @@ -329,27 +329,27 @@ pass1check(struct inodesc *idesc)
329 329
330 if ((anyout = chkrange(blkno, idesc->id_numfrags)) != 0) { 330 if ((anyout = chkrange(blkno, idesc->id_numfrags)) != 0) {
331 blkerror(idesc->id_number, "BAD", blkno); 331 blkerror(idesc->id_number, "BAD", blkno);
332 if (badblk++ >= MAXBAD) { 332 if (badblk++ >= MAXBAD) {
333 pwarn("EXCESSIVE BAD BLKS I=%llu", 333 pwarn("EXCESSIVE BAD BLKS I=%llu",
334 (unsigned long long)idesc->id_number); 334 (unsigned long long)idesc->id_number);
335 if (preen) 335 if (preen)
336 printf(" (SKIPPING)\n"); 336 printf(" (SKIPPING)\n");
337 else if (reply("CONTINUE") == 0) 337 else if (reply("CONTINUE") == 0)
338 err(EEXIT, "%s", ""); 338 err(EEXIT, "%s", "");
339 return (STOP); 339 return (STOP);
340 } 340 }
341 } else if (!testbmap(blkno)) { 341 } else if (!testbmap(blkno)) {
342 seg_table[lfs_dtosn(fs, blkno)].su_nbytes += idesc->id_numfrags * fs->lfs_fsize; 342 seg_table[lfs_dtosn(fs, blkno)].su_nbytes += idesc->id_numfrags * lfs_sb_getfsize(fs);
343 } 343 }
344 for (ndblks = idesc->id_numfrags; ndblks > 0; blkno++, ndblks--) { 344 for (ndblks = idesc->id_numfrags; ndblks > 0; blkno++, ndblks--) {
345 if (anyout && chkrange(blkno, 1)) { 345 if (anyout && chkrange(blkno, 1)) {
346 res = SKIP; 346 res = SKIP;
347 } else if (!testbmap(blkno)) { 347 } else if (!testbmap(blkno)) {
348 n_blks++; 348 n_blks++;
349#ifndef VERBOSE_BLOCKMAP 349#ifndef VERBOSE_BLOCKMAP
350 setbmap(blkno); 350 setbmap(blkno);
351#else 351#else
352 setbmap(blkno, idesc->id_number); 352 setbmap(blkno, idesc->id_number);
353#endif 353#endif
354 } else { 354 } else {
355 blkerror(idesc->id_number, "DUP", blkno); 355 blkerror(idesc->id_number, "DUP", blkno);

cvs diff -r1.37 -r1.38 src/sbin/fsck_lfs/utilities.c (expand / switch to unified diff)

--- src/sbin/fsck_lfs/utilities.c 2015/06/16 23:58:30 1.37
+++ src/sbin/fsck_lfs/utilities.c 2015/07/24 06:56:41 1.38
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: utilities.c,v 1.37 2015/06/16 23:58:30 christos Exp $ */ 1/* $NetBSD: utilities.c,v 1.38 2015/07/24 06:56:41 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1986, 1993 4 * Copyright (c) 1980, 1986, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -108,28 +108,28 @@ reply(const char *question) @@ -108,28 +108,28 @@ reply(const char *question)
108 if (feof(stdin)) 108 if (feof(stdin))
109 return (0); 109 return (0);
110 } while (c != 'y' && c != 'Y' && c != 'n' && c != 'N'); 110 } while (c != 'y' && c != 'Y' && c != 'n' && c != 'N');
111 printf("\n"); 111 printf("\n");
112 if (c == 'y' || c == 'Y') 112 if (c == 'y' || c == 'Y')
113 return (1); 113 return (1);
114 return (0); 114 return (0);
115} 115}
116 116
117static void 117static void
118write_superblocks(void) 118write_superblocks(void)
119{ 119{
120 if (debug) 120 if (debug)
121 pwarn("writing superblocks with lfs_idaddr = 0x%x\n", 121 pwarn("writing superblocks with lfs_idaddr = 0x%jx\n",
122 (int)fs->lfs_idaddr); 122 (uintmax_t)lfs_sb_getidaddr(fs));
123 lfs_writesuper(fs, fs->lfs_sboffs[0]); 123 lfs_writesuper(fs, fs->lfs_sboffs[0]);
124 lfs_writesuper(fs, fs->lfs_sboffs[1]); 124 lfs_writesuper(fs, fs->lfs_sboffs[1]);
125 fsmodified = 1; 125 fsmodified = 1;
126} 126}
127 127
128void 128void
129ckfini(int markclean) 129ckfini(int markclean)
130{ 130{
131 if (locked_queue_bytes > 0) { 131 if (locked_queue_bytes > 0) {
132 if (preen || reply("WRITE CHANGES TO DISK") == 1) { 132 if (preen || reply("WRITE CHANGES TO DISK") == 1) {
133 if (preen == 0) 133 if (preen == 0)
134 pwarn("WRITING CHANGES TO DISK\n"); 134 pwarn("WRITING CHANGES TO DISK\n");
135 lfs_segwrite(fs, SEGM_CKP); 135 lfs_segwrite(fs, SEGM_CKP);

cvs diff -r1.23 -r1.24 src/sbin/fsck_lfs/pass4.c (expand / switch to unified diff)

--- src/sbin/fsck_lfs/pass4.c 2015/06/16 23:18:55 1.23
+++ src/sbin/fsck_lfs/pass4.c 2015/07/24 06:56:41 1.24
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pass4.c,v 1.23 2015/06/16 23:18:55 christos Exp $ */ 1/* $NetBSD: pass4.c,v 1.24 2015/07/24 06:56:41 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1986, 1993 4 * Copyright (c) 1980, 1986, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -163,20 +163,20 @@ pass4check(struct inodesc * idesc) @@ -163,20 +163,20 @@ pass4check(struct inodesc * idesc)
163 continue; 163 continue;
164 dlp->dup = duplist->dup; 164 dlp->dup = duplist->dup;
165 dlp = duplist; 165 dlp = duplist;
166 duplist = duplist->next; 166 duplist = duplist->next;
167 free((char *) dlp); 167 free((char *) dlp);
168 break; 168 break;
169 } 169 }
170 if (dlp == 0) { 170 if (dlp == 0) {
171 clrbmap(blkno); 171 clrbmap(blkno);
172 LFS_SEGENTRY(sup, fs, sn, bp); 172 LFS_SEGENTRY(sup, fs, sn, bp);
173 sup->su_nbytes -= lfs_fsbtob(fs, 1); 173 sup->su_nbytes -= lfs_fsbtob(fs, 1);
174 VOP_BWRITE(bp); 174 VOP_BWRITE(bp);
175 seg_table[sn].su_nbytes -= lfs_fsbtob(fs, 1); 175 seg_table[sn].su_nbytes -= lfs_fsbtob(fs, 1);
176 ++fs->lfs_bfree; 176 lfs_sb_addbfree(fs, 1);
177 n_blks--; 177 n_blks--;
178 } 178 }
179 } 179 }
180 } 180 }
181 return (res); 181 return (res);
182} 182}

cvs diff -r1.29 -r1.30 src/sbin/fsck_lfs/pass5.c (expand / switch to unified diff)

--- src/sbin/fsck_lfs/pass5.c 2015/05/31 15:44:30 1.29
+++ src/sbin/fsck_lfs/pass5.c 2015/07/24 06:56:41 1.30
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pass5.c,v 1.29 2015/05/31 15:44:30 hannken Exp $ */ 1/* $NetBSD: pass5.c,v 1.30 2015/07/24 06:56:41 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2000, 2003 The NetBSD Foundation, Inc. 4 * Copyright (c) 2000, 2003 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant@hhhh.org>. 8 * by Konrad E. Schroder <perseant@hhhh.org>.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -121,66 +121,67 @@ pass5(void) @@ -121,66 +121,67 @@ pass5(void)
121 avail -= lfs_btofsb(fs, LFS_SBPAD); 121 avail -= lfs_btofsb(fs, LFS_SBPAD);
122 if (i == 0 && fs->lfs_version > 1 && 122 if (i == 0 && fs->lfs_version > 1 &&
123 fs->lfs_s0addr < lfs_btofsb(fs, LFS_LABELPAD)) 123 fs->lfs_s0addr < lfs_btofsb(fs, LFS_LABELPAD))
124 avail -= lfs_btofsb(fs, LFS_LABELPAD) - 124 avail -= lfs_btofsb(fs, LFS_LABELPAD) -
125 fs->lfs_s0addr; 125 fs->lfs_s0addr;
126 } 126 }
127 if (diddirty) 127 if (diddirty)
128 VOP_BWRITE(bp); 128 VOP_BWRITE(bp);
129 else 129 else
130 brelse(bp, 0); 130 brelse(bp, 0);
131 } 131 }
132 132
133 /* Also may be available bytes in current seg */ 133 /* Also may be available bytes in current seg */
134 i = lfs_dtosn(fs, fs->lfs_offset); 134 i = lfs_dtosn(fs, lfs_sb_getoffset(fs));
135 avail += lfs_sntod(fs, i + 1) - fs->lfs_offset; 135 avail += lfs_sntod(fs, i + 1) - lfs_sb_getoffset(fs);
136 /* But do not count minfreesegs */ 136 /* But do not count minfreesegs */
137 avail -= lfs_segtod(fs, (fs->lfs_minfreeseg - 137 avail -= lfs_segtod(fs, (fs->lfs_minfreeseg -
138 (fs->lfs_minfreeseg / 2))); 138 (fs->lfs_minfreeseg / 2)));
139 /* Note we may have bytes to write yet */ 139 /* Note we may have bytes to write yet */
140 avail -= lfs_btofsb(fs, locked_queue_bytes); 140 avail -= lfs_btofsb(fs, locked_queue_bytes);
141 141
142 if (idaddr) 142 if (idaddr)
143 pwarn("NOTE: when using -i, expect discrepancies in dmeta," 143 pwarn("NOTE: when using -i, expect discrepancies in dmeta,"
144 " avail, nclean, bfree\n"); 144 " avail, nclean, bfree\n");
145 if (dmeta != fs->lfs_dmeta) { 145 if (dmeta != fs->lfs_dmeta) {
146 pwarn("DMETA GIVEN AS %d, SHOULD BE %ld\n", fs->lfs_dmeta, 146 pwarn("DMETA GIVEN AS %d, SHOULD BE %ld\n", fs->lfs_dmeta,
147 dmeta); 147 dmeta);
148 if (preen || reply("FIX")) { 148 if (preen || reply("FIX")) {
149 fs->lfs_dmeta = dmeta; 149 fs->lfs_dmeta = dmeta;
150 sbdirty(); 150 sbdirty();
151 } 151 }
152 } 152 }
153 if (avail != fs->lfs_avail) { 153 if (avail != lfs_sb_getavail(fs)) {
154 pwarn("AVAIL GIVEN AS %d, SHOULD BE %ld\n", fs->lfs_avail, 154 pwarn("AVAIL GIVEN AS %d, SHOULD BE %ld\n",
155 avail); 155 lfs_sb_getavail(fs), avail);
156 if (preen || reply("FIX")) { 156 if (preen || reply("FIX")) {
157 fs->lfs_avail = avail; 157 lfs_sb_setavail(fs, avail);
158 sbdirty(); 158 sbdirty();
159 } 159 }
160 } 160 }
161 if (nclean != fs->lfs_nclean) { 161 if (nclean != fs->lfs_nclean) {
162 pwarn("NCLEAN GIVEN AS %d, SHOULD BE %d\n", fs->lfs_nclean, 162 pwarn("NCLEAN GIVEN AS %d, SHOULD BE %d\n", fs->lfs_nclean,
163 nclean); 163 nclean);
164 if (preen || reply("FIX")) { 164 if (preen || reply("FIX")) {
165 fs->lfs_nclean = nclean; 165 fs->lfs_nclean = nclean;
166 sbdirty(); 166 sbdirty();
167 } 167 }
168 } 168 }
169 169
170 labelskew = 0; 170 labelskew = 0;
171 if (fs->lfs_version > 1 && 171 if (fs->lfs_version > 1 &&
172 fs->lfs_s0addr < lfs_btofsb(fs, LFS_LABELPAD)) 172 fs->lfs_s0addr < lfs_btofsb(fs, LFS_LABELPAD))
173 labelskew = lfs_btofsb(fs, LFS_LABELPAD); 173 labelskew = lfs_btofsb(fs, LFS_LABELPAD);
174 if (fs->lfs_bfree > fs->lfs_dsize - bb - labelskew || 174 if (lfs_sb_getbfree(fs) > lfs_sb_getdsize(fs) - bb - labelskew ||
175 fs->lfs_bfree < fs->lfs_dsize - ubb - labelskew) { 175 lfs_sb_getbfree(fs) < lfs_sb_getdsize(fs) - ubb - labelskew) {
176 pwarn("BFREE GIVEN AS %d, SHOULD BE BETWEEN %ld AND %ld\n", 176 pwarn("BFREE GIVEN AS %jd, SHOULD BE BETWEEN %ld AND %ld\n",
177 fs->lfs_bfree, (fs->lfs_dsize - ubb - labelskew), 177 (intmax_t)lfs_sb_getbfree(fs),
178 fs->lfs_dsize - bb - labelskew); 178 lfs_sb_getdsize(fs) - ubb - labelskew,
 179 lfs_sb_getdsize(fs) - bb - labelskew);
179 if (preen || reply("FIX")) { 180 if (preen || reply("FIX")) {
180 fs->lfs_bfree = 181 lfs_sb_setbfree(fs,
181 ((fs->lfs_dsize - labelskew - ubb) + 182 ((lfs_sb_getdsize(fs) - labelskew - ubb) +
182 fs->lfs_dsize - labelskew - bb) / 2; 183 lfs_sb_getdsize(fs) - labelskew - bb) / 2);
183 sbdirty(); 184 sbdirty();
184 } 185 }
185 } 186 }
186} 187}

cvs diff -r1.34 -r1.35 src/sbin/fsck_lfs/pass6.c (expand / switch to unified diff)

--- src/sbin/fsck_lfs/pass6.c 2015/05/31 15:44:30 1.34
+++ src/sbin/fsck_lfs/pass6.c 2015/07/24 06:56:41 1.35
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pass6.c,v 1.34 2015/05/31 15:44:30 hannken Exp $ */ 1/* $NetBSD: pass6.c,v 1.35 2015/07/24 06:56:41 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc. 4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant@hhhh.org>. 8 * by Konrad E. Schroder <perseant@hhhh.org>.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -110,95 +110,95 @@ rfw_update_single(struct uvnode *vp, dad @@ -110,95 +110,95 @@ rfw_update_single(struct uvnode *vp, dad
110 ofrags = lfs_numfrags(fs, ip->i_lfs_fragsize[lbn]); 110 ofrags = lfs_numfrags(fs, ip->i_lfs_fragsize[lbn]);
111 ip->i_ffs1_blocks += (frags - ofrags); 111 ip->i_ffs1_blocks += (frags - ofrags);
112 } 112 }
113 ip->i_ffs1_db[lbn] = ndaddr; 113 ip->i_ffs1_db[lbn] = ndaddr;
114 break; 114 break;
115 case 1: 115 case 1:
116 ooff = ip->i_ffs1_ib[a[0].in_off]; 116 ooff = ip->i_ffs1_ib[a[0].in_off];
117 if (ooff <= 0) 117 if (ooff <= 0)
118 ip->i_ffs1_blocks += frags; 118 ip->i_ffs1_blocks += frags;
119 ip->i_ffs1_ib[a[0].in_off] = ndaddr; 119 ip->i_ffs1_ib[a[0].in_off] = ndaddr;
120 break; 120 break;
121 default: 121 default:
122 ap = &a[num - 1]; 122 ap = &a[num - 1];
123 if (bread(vp, ap->in_lbn, fs->lfs_bsize, 0, &bp)) 123 if (bread(vp, ap->in_lbn, lfs_sb_getbsize(fs), 0, &bp))
124 errx(1, "lfs_updatemeta: bread bno %" PRId64, 124 errx(1, "lfs_updatemeta: bread bno %" PRId64,
125 ap->in_lbn); 125 ap->in_lbn);
126 126
127 ooff = ((ulfs_daddr_t *) bp->b_data)[ap->in_off]; 127 ooff = ((ulfs_daddr_t *) bp->b_data)[ap->in_off];
128 if (ooff <= 0) 128 if (ooff <= 0)
129 ip->i_ffs1_blocks += frags; 129 ip->i_ffs1_blocks += frags;
130 ((ulfs_daddr_t *) bp->b_data)[ap->in_off] = ndaddr; 130 ((ulfs_daddr_t *) bp->b_data)[ap->in_off] = ndaddr;
131 (void) VOP_BWRITE(bp); 131 (void) VOP_BWRITE(bp);
132 } 132 }
133 133
134 /* 134 /*
135 * Update segment usage information, based on old size 135 * Update segment usage information, based on old size
136 * and location. 136 * and location.
137 */ 137 */
138 if (daddr > 0) { 138 if (daddr > 0) {
139 oldsn = lfs_dtosn(fs, daddr); 139 oldsn = lfs_dtosn(fs, daddr);
140 if (lbn >= 0 && lbn < ULFS_NDADDR) 140 if (lbn >= 0 && lbn < ULFS_NDADDR)
141 osize = ip->i_lfs_fragsize[lbn]; 141 osize = ip->i_lfs_fragsize[lbn];
142 else 142 else
143 osize = fs->lfs_bsize; 143 osize = lfs_sb_getbsize(fs);
144 LFS_SEGENTRY(sup, fs, oldsn, bp); 144 LFS_SEGENTRY(sup, fs, oldsn, bp);
145 seg_table[oldsn].su_nbytes -= osize; 145 seg_table[oldsn].su_nbytes -= osize;
146 sup->su_nbytes -= osize; 146 sup->su_nbytes -= osize;
147 if (!(bp->b_flags & B_GATHERED)) 147 if (!(bp->b_flags & B_GATHERED))
148 fs->lfs_flags |= LFS_IFDIRTY; 148 fs->lfs_flags |= LFS_IFDIRTY;
149 LFS_WRITESEGENTRY(sup, fs, oldsn, bp); 149 LFS_WRITESEGENTRY(sup, fs, oldsn, bp);
150 for (i = 0; i < lfs_btofsb(fs, osize); i++) 150 for (i = 0; i < lfs_btofsb(fs, osize); i++)
151 clrbmap(daddr + i); 151 clrbmap(daddr + i);
152 } 152 }
153 153
154 /* If block is beyond EOF, update size */ 154 /* If block is beyond EOF, update size */
155 if (lbn >= 0 && ip->i_ffs1_size <= (lbn << fs->lfs_bshift)) { 155 if (lbn >= 0 && ip->i_ffs1_size <= (lbn << fs->lfs_bshift)) {
156 ip->i_ffs1_size = (lbn << fs->lfs_bshift) + 1; 156 ip->i_ffs1_size = (lbn << fs->lfs_bshift) + 1;
157 } 157 }
158 158
159 /* If block frag size is too large for old EOF, update size */ 159 /* If block frag size is too large for old EOF, update size */
160 if (lbn < ULFS_NDADDR) { 160 if (lbn < ULFS_NDADDR) {
161 off_t minsize; 161 off_t minsize;
162 162
163 minsize = (lbn << fs->lfs_bshift); 163 minsize = (lbn << fs->lfs_bshift);
164 minsize += (size - fs->lfs_fsize) + 1; 164 minsize += (size - lfs_sb_getfsize(fs)) + 1;
165 if (ip->i_ffs1_size < minsize) 165 if (ip->i_ffs1_size < minsize)
166 ip->i_ffs1_size = minsize; 166 ip->i_ffs1_size = minsize;
167 } 167 }
168 168
169 /* Count for the user */ 169 /* Count for the user */
170 ++nnewblocks; 170 ++nnewblocks;
171 171
172 /* Add block to its new segment */ 172 /* Add block to its new segment */
173 sn = lfs_dtosn(fs, ndaddr); 173 sn = lfs_dtosn(fs, ndaddr);
174 LFS_SEGENTRY(sup, fs, sn, bp); 174 LFS_SEGENTRY(sup, fs, sn, bp);
175 seg_table[sn].su_nbytes += size; 175 seg_table[sn].su_nbytes += size;
176 sup->su_nbytes += size; 176 sup->su_nbytes += size;
177 if (!(bp->b_flags & B_GATHERED)) 177 if (!(bp->b_flags & B_GATHERED))
178 fs->lfs_flags |= LFS_IFDIRTY; 178 fs->lfs_flags |= LFS_IFDIRTY;
179 LFS_WRITESEGENTRY(sup, fs, sn, bp); 179 LFS_WRITESEGENTRY(sup, fs, sn, bp);
180 for (i = 0; i < lfs_btofsb(fs, size); i++) 180 for (i = 0; i < lfs_btofsb(fs, size); i++)
181#ifndef VERBOSE_BLOCKMAP 181#ifndef VERBOSE_BLOCKMAP
182 setbmap(daddr + i); 182 setbmap(daddr + i);
183#else 183#else
184 setbmap(daddr + i, ip->i_number); 184 setbmap(daddr + i, ip->i_number);
185#endif 185#endif
186 186
187 /* Check bfree accounting as well */ 187 /* Check bfree accounting as well */
188 if (daddr <= 0) { 188 if (daddr <= 0) {
189 fs->lfs_bfree -= lfs_btofsb(fs, size); 189 lfs_sb_subbfree(fs, lfs_btofsb(fs, size));
190 } else if (size != osize) { 190 } else if (size != osize) {
191 fs->lfs_bfree -= (frags - ofrags); 191 lfs_sb_subbfree(fs, frags - ofrags);
192 } 192 }
193 193
194 /* 194 /*
195 * Now that this block has a new address, and its old 195 * Now that this block has a new address, and its old
196 * segment no longer owns it, we can forget about its 196 * segment no longer owns it, we can forget about its
197 * old size. 197 * old size.
198 */ 198 */
199 if (lbn >= 0 && lbn < ULFS_NDADDR) 199 if (lbn >= 0 && lbn < ULFS_NDADDR)
200 ip->i_lfs_fragsize[lbn] = size; 200 ip->i_lfs_fragsize[lbn] = size;
201} 201}
202 202
203/* 203/*
204 * Remove the vnode from the cache, including any blocks it 204 * Remove the vnode from the cache, including any blocks it
@@ -254,27 +254,27 @@ remove_ino(struct uvnode *vp, ino_t ino) @@ -254,27 +254,27 @@ remove_ino(struct uvnode *vp, ino_t ino)
254 */ 254 */
255static void 255static void
256pass6harvest(ulfs_daddr_t daddr, FINFO *fip) 256pass6harvest(ulfs_daddr_t daddr, FINFO *fip)
257{ 257{
258 struct uvnode *vp; 258 struct uvnode *vp;
259 int i; 259 int i;
260 size_t size; 260 size_t size;
261 261
262 vp = vget(fs, fip->fi_ino); 262 vp = vget(fs, fip->fi_ino);
263 if (vp && vp != fs->lfs_ivnode && 263 if (vp && vp != fs->lfs_ivnode &&
264 VTOI(vp)->i_ffs1_gen == fip->fi_version) { 264 VTOI(vp)->i_ffs1_gen == fip->fi_version) {
265 for (i = 0; i < fip->fi_nblocks; i++) { 265 for (i = 0; i < fip->fi_nblocks; i++) {
266 size = (i == fip->fi_nblocks - 1 ? 266 size = (i == fip->fi_nblocks - 1 ?
267 fip->fi_lastlength : fs->lfs_bsize); 267 fip->fi_lastlength : lfs_sb_getbsize(fs));
268 if (debug) 268 if (debug)
269 pwarn("ino %lld lbn %lld -> 0x%lx\n", 269 pwarn("ino %lld lbn %lld -> 0x%lx\n",
270 (long long)fip->fi_ino, 270 (long long)fip->fi_ino,
271 (long long)fip->fi_blocks[i], 271 (long long)fip->fi_blocks[i],
272 (long)daddr); 272 (long)daddr);
273 rfw_update_single(vp, fip->fi_blocks[i], daddr, size); 273 rfw_update_single(vp, fip->fi_blocks[i], daddr, size);
274 daddr += lfs_btofsb(fs, size); 274 daddr += lfs_btofsb(fs, size);
275 } 275 }
276 } 276 }
277} 277}
278 278
279/* 279/*
280 * Check validity of blocks on roll-forward inodes. 280 * Check validity of blocks on roll-forward inodes.
@@ -288,28 +288,28 @@ pass6check(struct inodesc * idesc) @@ -288,28 +288,28 @@ pass6check(struct inodesc * idesc)
288 if (idesc->id_blkno == UNWRITTEN) 288 if (idesc->id_blkno == UNWRITTEN)
289 return KEEPON; 289 return KEEPON;
290 290
291 /* Check that the blocks do not lie within clean segments. */ 291 /* Check that the blocks do not lie within clean segments. */
292 anyout = anynew = 0; 292 anyout = anynew = 0;
293 for (i = 0; i < idesc->id_numfrags; i++) { 293 for (i = 0; i < idesc->id_numfrags; i++) {
294 sn = lfs_dtosn(fs, idesc->id_blkno + i); 294 sn = lfs_dtosn(fs, idesc->id_blkno + i);
295 if (sn < 0 || sn >= fs->lfs_nseg || 295 if (sn < 0 || sn >= fs->lfs_nseg ||
296 (seg_table[sn].su_flags & SEGUSE_DIRTY) == 0) { 296 (seg_table[sn].su_flags & SEGUSE_DIRTY) == 0) {
297 anyout = 1; 297 anyout = 1;
298 break; 298 break;
299 } 299 }
300 if (seg_table[sn].su_flags & SEGUSE_ACTIVE) { 300 if (seg_table[sn].su_flags & SEGUSE_ACTIVE) {
301 if (sn != lfs_dtosn(fs, fs->lfs_offset) || 301 if (sn != lfs_dtosn(fs, lfs_sb_getoffset(fs)) ||
302 idesc->id_blkno > fs->lfs_offset) { 302 idesc->id_blkno > lfs_sb_getoffset(fs)) {
303 ++anynew; 303 ++anynew;
304 } 304 }
305 } 305 }
306 if (!anynew) { 306 if (!anynew) {
307 /* Clear so pass1check won't be surprised */ 307 /* Clear so pass1check won't be surprised */
308 clrbmap(idesc->id_blkno + i); 308 clrbmap(idesc->id_blkno + i);
309 seg_table[sn].su_nbytes -= lfs_fsbtob(fs, 1); 309 seg_table[sn].su_nbytes -= lfs_fsbtob(fs, 1);
310 } 310 }
311 } 311 }
312 if (anyout) { 312 if (anyout) {
313 blkerror(idesc->id_number, "BAD", idesc->id_blkno); 313 blkerror(idesc->id_number, "BAD", idesc->id_blkno);
314 if (badblk++ >= MAXBAD) { 314 if (badblk++ >= MAXBAD) {
315 pwarn("EXCESSIVE BAD BLKS I=%llu", 315 pwarn("EXCESSIVE BAD BLKS I=%llu",
@@ -326,41 +326,41 @@ pass6check(struct inodesc * idesc) @@ -326,41 +326,41 @@ pass6check(struct inodesc * idesc)
326} 326}
327 327
328static void 328static void
329account_indir(struct uvnode *vp, struct ulfs1_dinode *dp, daddr_t ilbn, daddr_t daddr, int lvl) 329account_indir(struct uvnode *vp, struct ulfs1_dinode *dp, daddr_t ilbn, daddr_t daddr, int lvl)
330{ 330{
331 struct ubuf *bp; 331 struct ubuf *bp;
332 int32_t *dap, *odap, *buf, *obuf; 332 int32_t *dap, *odap, *buf, *obuf;
333 daddr_t lbn; 333 daddr_t lbn;
334 334
335 if (lvl == 0) 335 if (lvl == 0)
336 lbn = -ilbn; 336 lbn = -ilbn;
337 else 337 else
338 lbn = ilbn + 1; 338 lbn = ilbn + 1;
339 bread(fs->lfs_devvp, LFS_FSBTODB(fs, daddr), fs->lfs_bsize, 0, &bp); 339 bread(fs->lfs_devvp, LFS_FSBTODB(fs, daddr), lfs_sb_getbsize(fs), 0, &bp);
340 buf = emalloc(fs->lfs_bsize); 340 buf = emalloc(lfs_sb_getbsize(fs));
341 memcpy(buf, bp->b_data, fs->lfs_bsize); 341 memcpy(buf, bp->b_data, lfs_sb_getbsize(fs));
342 brelse(bp, 0); 342 brelse(bp, 0);
343 343
344 obuf = emalloc(fs->lfs_bsize); 344 obuf = emalloc(lfs_sb_getbsize(fs));
345 if (vp) { 345 if (vp) {
346 bread(vp, ilbn, fs->lfs_bsize, 0, &bp); 346 bread(vp, ilbn, lfs_sb_getbsize(fs), 0, &bp);
347 memcpy(obuf, bp->b_data, fs->lfs_bsize); 347 memcpy(obuf, bp->b_data, lfs_sb_getbsize(fs));
348 brelse(bp, 0); 348 brelse(bp, 0);
349 } else 349 } else
350 memset(obuf, 0, fs->lfs_bsize); 350 memset(obuf, 0, lfs_sb_getbsize(fs));
351 351
352 for (dap = buf, odap = obuf; 352 for (dap = buf, odap = obuf;
353 dap < (int32_t *)((char *)buf + fs->lfs_bsize); 353 dap < (int32_t *)((char *)buf + lfs_sb_getbsize(fs));
354 ++dap, ++odap) { 354 ++dap, ++odap) {
355 if (*dap > 0 && *dap != *odap) { 355 if (*dap > 0 && *dap != *odap) {
356 rfw_update_single(vp, lbn, *dap, lfs_dblksize(fs, dp, lbn)); 356 rfw_update_single(vp, lbn, *dap, lfs_dblksize(fs, dp, lbn));
357 if (lvl > 0) 357 if (lvl > 0)
358 account_indir(vp, dp, lbn, *dap, lvl - 1); 358 account_indir(vp, dp, lbn, *dap, lvl - 1);
359 } 359 }
360 if (lvl == 0) 360 if (lvl == 0)
361 ++lbn; 361 ++lbn;
362 else if (lvl == 1) 362 else if (lvl == 1)
363 lbn -= LFS_NINDIR(fs); 363 lbn -= LFS_NINDIR(fs);
364 else if (lvl == 2) 364 else if (lvl == 2)
365 lbn -= LFS_NINDIR(fs) * LFS_NINDIR(fs); 365 lbn -= LFS_NINDIR(fs) * LFS_NINDIR(fs);
366 } 366 }
@@ -387,27 +387,27 @@ account_block_changes(struct ulfs1_dinod @@ -387,27 +387,27 @@ account_block_changes(struct ulfs1_dinod
387 for (i = 0; i < ULFS_NDADDR; i++) { 387 for (i = 0; i < ULFS_NDADDR; i++) {
388 odaddr = (ip ? ip->i_ffs1_db[i] : 0x0); 388 odaddr = (ip ? ip->i_ffs1_db[i] : 0x0);
389 if (dp->di_db[i] > 0 && dp->di_db[i] != odaddr) 389 if (dp->di_db[i] > 0 && dp->di_db[i] != odaddr)
390 rfw_update_single(vp, i, dp->di_db[i], 390 rfw_update_single(vp, i, dp->di_db[i],
391 lfs_dblksize(fs, dp, i)); 391 lfs_dblksize(fs, dp, i));
392 } 392 }
393 393
394 /* Check indirect block holdings between existing and new */ 394 /* Check indirect block holdings between existing and new */
395 off = 0; 395 off = 0;
396 for (i = 0; i < ULFS_NIADDR; i++) { 396 for (i = 0; i < ULFS_NIADDR; i++) {
397 odaddr = (ip ? ip->i_ffs1_ib[i] : 0x0); 397 odaddr = (ip ? ip->i_ffs1_ib[i] : 0x0);
398 if (dp->di_ib[i] > 0 && dp->di_ib[i] != odaddr) { 398 if (dp->di_ib[i] > 0 && dp->di_ib[i] != odaddr) {
399 lbn = -(ULFS_NDADDR + off + i); 399 lbn = -(ULFS_NDADDR + off + i);
400 rfw_update_single(vp, i, dp->di_ib[i], fs->lfs_bsize); 400 rfw_update_single(vp, i, dp->di_ib[i], lfs_sb_getbsize(fs));
401 account_indir(vp, dp, lbn, dp->di_ib[i], i); 401 account_indir(vp, dp, lbn, dp->di_ib[i], i);
402 } 402 }
403 if (off == 0) 403 if (off == 0)
404 off = LFS_NINDIR(fs); 404 off = LFS_NINDIR(fs);
405 else 405 else
406 off *= LFS_NINDIR(fs); 406 off *= LFS_NINDIR(fs);
407 } 407 }
408} 408}
409 409
410/* 410/*
411 * Give a previously allocated inode a new address; do segment 411 * Give a previously allocated inode a new address; do segment
412 * accounting if necessary. 412 * accounting if necessary.
413 * 413 *
@@ -556,46 +556,46 @@ pass6(void) @@ -556,46 +556,46 @@ pass6(void)
556 long lastserial; 556 long lastserial;
557 557
558 devvp = fs->lfs_devvp; 558 devvp = fs->lfs_devvp;
559 559
560 /* If we can't roll forward because of created files, don't try */ 560 /* If we can't roll forward because of created files, don't try */
561 if (no_roll_forward) { 561 if (no_roll_forward) {
562 if (debug) 562 if (debug)
563 pwarn("not rolling forward due to possible allocation conflict\n"); 563 pwarn("not rolling forward due to possible allocation conflict\n");
564 return; 564 return;
565 } 565 }
566 566
567 /* Find last valid partial segment */ 567 /* Find last valid partial segment */
568 lastgood = try_verify(fs, devvp, 0, debug); 568 lastgood = try_verify(fs, devvp, 0, debug);
569 if (lastgood == fs->lfs_offset) { 569 if (lastgood == lfs_sb_getoffset(fs)) {
570 if (debug) 570 if (debug)
571 pwarn("not rolling forward, nothing to recover\n"); 571 pwarn("not rolling forward, nothing to recover\n");
572 return; 572 return;
573 } 573 }
574 574
575 if (debug) 575 if (debug)
576 pwarn("could roll forward from 0x%" PRIx32 " to 0x%" PRIx32 "\n", 576 pwarn("could roll forward from 0x%jx to 0x%jx\n",
577 fs->lfs_offset, lastgood); 577 (uintmax_t)lfs_sb_getoffset(fs), (uintmax_t)lastgood);
578 578
579 if (!preen && reply("ROLL FORWARD") == 0) 579 if (!preen && reply("ROLL FORWARD") == 0)
580 return; 580 return;
581 /* 581 /*
582 * Pass 1: find inode blocks. We ignore the Ifile inode but accept 582 * Pass 1: find inode blocks. We ignore the Ifile inode but accept
583 * changes to any other inode. 583 * changes to any other inode.
584 */ 584 */
585 585
586 ibbuf = emalloc(fs->lfs_ibsize); 586 ibbuf = emalloc(fs->lfs_ibsize);
587 nnewfiles = ndelfiles = nmvfiles = nnewblocks = 0; 587 nnewfiles = ndelfiles = nmvfiles = nnewblocks = 0;
588 daddr = fs->lfs_offset; 588 daddr = lfs_sb_getoffset(fs);
589 hassuper = 0; 589 hassuper = 0;
590 lastserial = 0; 590 lastserial = 0;
591 while (daddr != lastgood) { 591 while (daddr != lastgood) {
592 seg_table[lfs_dtosn(fs, daddr)].su_flags |= SEGUSE_DIRTY | SEGUSE_ACTIVE; 592 seg_table[lfs_dtosn(fs, daddr)].su_flags |= SEGUSE_DIRTY | SEGUSE_ACTIVE;
593 LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, daddr), sbp); 593 LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, daddr), sbp);
594 sup->su_flags |= SEGUSE_DIRTY; 594 sup->su_flags |= SEGUSE_DIRTY;
595 VOP_BWRITE(sbp); 595 VOP_BWRITE(sbp);
596 596
597 /* Could be a superblock */ 597 /* Could be a superblock */
598 if (lfs_sntod(fs, lfs_dtosn(fs, daddr)) == daddr) { 598 if (lfs_sntod(fs, lfs_dtosn(fs, daddr)) == daddr) {
599 if (daddr == fs->lfs_s0addr) { 599 if (daddr == fs->lfs_s0addr) {
600 ++hassuper; 600 ++hassuper;
601 daddr += lfs_btofsb(fs, LFS_LABELPAD); 601 daddr += lfs_btofsb(fs, LFS_LABELPAD);
@@ -612,64 +612,64 @@ pass6(void) @@ -612,64 +612,64 @@ pass6(void)
612  612
613 /* Read in summary block */ 613 /* Read in summary block */
614 bread(devvp, LFS_FSBTODB(fs, daddr), fs->lfs_sumsize, 0, &bp); 614 bread(devvp, LFS_FSBTODB(fs, daddr), fs->lfs_sumsize, 0, &bp);
615 sp = (SEGSUM *)bp->b_data; 615 sp = (SEGSUM *)bp->b_data;
616 if (debug) 616 if (debug)
617 pwarn("sum at 0x%x: ninos=%d nfinfo=%d\n", 617 pwarn("sum at 0x%x: ninos=%d nfinfo=%d\n",
618 (unsigned)daddr, (int)sp->ss_ninos, 618 (unsigned)daddr, (int)sp->ss_ninos,
619 (int)sp->ss_nfinfo); 619 (int)sp->ss_nfinfo);
620 620
621 /* We have verified that this is a good summary. */ 621 /* We have verified that this is a good summary. */
622 LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, daddr), sbp); 622 LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, daddr), sbp);
623 ++sup->su_nsums; 623 ++sup->su_nsums;
624 VOP_BWRITE(sbp); 624 VOP_BWRITE(sbp);
625 fs->lfs_bfree -= lfs_btofsb(fs, fs->lfs_sumsize); 625 lfs_sb_subbfree(fs, lfs_btofsb(fs, fs->lfs_sumsize));
626 fs->lfs_dmeta += lfs_btofsb(fs, fs->lfs_sumsize); 626 lfs_sb_adddmeta(fs, lfs_btofsb(fs, fs->lfs_sumsize));
627 sbdirty(); 627 sbdirty();
628 if (lfs_sntod(fs, lfs_dtosn(fs, daddr)) == daddr + 628 if (lfs_sntod(fs, lfs_dtosn(fs, daddr)) == daddr +
629 hassuper * lfs_btofsb(fs, LFS_SBPAD) && 629 hassuper * lfs_btofsb(fs, LFS_SBPAD) &&
630 lfs_dtosn(fs, daddr) != lfs_dtosn(fs, fs->lfs_offset)) { 630 lfs_dtosn(fs, daddr) != lfs_dtosn(fs, lfs_sb_getoffset(fs))) {
631 --fs->lfs_nclean; 631 --fs->lfs_nclean;
632 sbdirty(); 632 sbdirty();
633 } 633 }
634 634
635 /* Find inodes, look at generation number. */ 635 /* Find inodes, look at generation number. */
636 if (sp->ss_ninos) { 636 if (sp->ss_ninos) {
637 LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, daddr), sbp); 637 LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, daddr), sbp);
638 sup->su_ninos += howmany(sp->ss_ninos, LFS_INOPB(fs)); 638 sup->su_ninos += howmany(sp->ss_ninos, LFS_INOPB(fs));
639 VOP_BWRITE(sbp); 639 VOP_BWRITE(sbp);
640 fs->lfs_dmeta += lfs_btofsb(fs, howmany(sp->ss_ninos, 640 fs->lfs_dmeta += lfs_btofsb(fs, howmany(sp->ss_ninos,
641 LFS_INOPB(fs)) * 641 LFS_INOPB(fs)) *
642 fs->lfs_ibsize); 642 fs->lfs_ibsize);
643 } 643 }
644 idaddrp = ((ulfs_daddr_t *)((char *)bp->b_data + fs->lfs_sumsize)); 644 idaddrp = ((ulfs_daddr_t *)((char *)bp->b_data + fs->lfs_sumsize));
645 for (i = 0; i < howmany(sp->ss_ninos, LFS_INOPB(fs)); i++) { 645 for (i = 0; i < howmany(sp->ss_ninos, LFS_INOPB(fs)); i++) {
646 ino_t *inums; 646 ino_t *inums;
647  647
648 inums = ecalloc(LFS_INOPB(fs) + 1, sizeof(*inums)); 648 inums = ecalloc(LFS_INOPB(fs) + 1, sizeof(*inums));
649 ibdaddr = *--idaddrp; 649 ibdaddr = *--idaddrp;
650 fs->lfs_bfree -= lfs_btofsb(fs, fs->lfs_ibsize); 650 lfs_sb_subbfree(fs, lfs_btofsb(fs, fs->lfs_ibsize));
651 sbdirty(); 651 sbdirty();
652 bread(devvp, LFS_FSBTODB(fs, ibdaddr), fs->lfs_ibsize, 652 bread(devvp, LFS_FSBTODB(fs, ibdaddr), fs->lfs_ibsize,
653 0, &ibp); 653 0, &ibp);
654 memcpy(ibbuf, ibp->b_data, fs->lfs_ibsize); 654 memcpy(ibbuf, ibp->b_data, fs->lfs_ibsize);
655 brelse(ibp, 0); 655 brelse(ibp, 0);
656 656
657 j = 0; 657 j = 0;
658 for (dp = (struct ulfs1_dinode *)ibbuf; 658 for (dp = (struct ulfs1_dinode *)ibbuf;
659 dp < (struct ulfs1_dinode *)ibbuf + LFS_INOPB(fs); 659 dp < (struct ulfs1_dinode *)ibbuf + LFS_INOPB(fs);
660 ++dp) { 660 ++dp) {
661 if (dp->di_inumber == 0 || 661 if (dp->di_inumber == 0 ||
662 dp->di_inumber == fs->lfs_ifile) 662 dp->di_inumber == lfs_sb_getifile(fs))
663 continue; 663 continue;
664 /* Basic sanity checks */ 664 /* Basic sanity checks */
665 if (dp->di_nlink < 0  665 if (dp->di_nlink < 0
666#if 0 666#if 0
667 || dp->di_u.inumber < 0 667 || dp->di_u.inumber < 0
668 || dp->di_size < 0 668 || dp->di_size < 0
669#endif 669#endif
670 ) { 670 ) {
671 pwarn("BAD INODE AT 0x%" PRIx32 "\n", 671 pwarn("BAD INODE AT 0x%" PRIx32 "\n",
672 ibdaddr); 672 ibdaddr);
673 brelse(bp, 0); 673 brelse(bp, 0);
674 free(inums); 674 free(inums);
675 goto out; 675 goto out;
@@ -770,61 +770,61 @@ pass6(void) @@ -770,61 +770,61 @@ pass6(void)
770 (int)daddr, (int)sp->ss_serial); 770 (int)daddr, (int)sp->ss_serial);
771 brelse(bp, 0); 771 brelse(bp, 0);
772 break; 772 break;
773 } else { 773 } else {
774 if (debug) 774 if (debug)
775 pwarn("good seg ptr at 0x%x with serial=%d\n", 775 pwarn("good seg ptr at 0x%x with serial=%d\n",
776 (int)daddr, (int)sp->ss_serial); 776 (int)daddr, (int)sp->ss_serial);
777 lastserial = sp->ss_serial; 777 lastserial = sp->ss_serial;
778 } 778 }
779 odaddr = daddr; 779 odaddr = daddr;
780 daddr += lfs_btofsb(fs, fs->lfs_sumsize + bc); 780 daddr += lfs_btofsb(fs, fs->lfs_sumsize + bc);
781 if (lfs_dtosn(fs, odaddr) != lfs_dtosn(fs, daddr) || 781 if (lfs_dtosn(fs, odaddr) != lfs_dtosn(fs, daddr) ||
782 lfs_dtosn(fs, daddr) != lfs_dtosn(fs, daddr + 782 lfs_dtosn(fs, daddr) != lfs_dtosn(fs, daddr +
783 lfs_btofsb(fs, fs->lfs_sumsize + fs->lfs_bsize) - 1)) { 783 lfs_btofsb(fs, fs->lfs_sumsize + lfs_sb_getbsize(fs)) - 1)) {
784 daddr = ((SEGSUM *)bp->b_data)->ss_next; 784 daddr = ((SEGSUM *)bp->b_data)->ss_next;
785 } 785 }
786 brelse(bp, 0); 786 brelse(bp, 0);
787 } 787 }
788 788
789 out: 789 out:
790 free(ibbuf); 790 free(ibbuf);
791 791
792 /* Set serial here, just to be sure (XXX should be right already) */ 792 /* Set serial here, just to be sure (XXX should be right already) */
793 fs->lfs_serial = lastserial + 1; 793 lfs_sb_setserial(fs, lastserial + 1);
794 794
795 /* 795 /*
796 * Check our new vnodes. Any blocks must lie in segments that 796 * Check our new vnodes. Any blocks must lie in segments that
797 * we've seen before (SEGUSE_DIRTY or SEGUSE_RFW); and the rest 797 * we've seen before (SEGUSE_DIRTY or SEGUSE_RFW); and the rest
798 * of the pass 1 checks as well. 798 * of the pass 1 checks as well.
799 */ 799 */
800 memset(&idesc, 0, sizeof(struct inodesc)); 800 memset(&idesc, 0, sizeof(struct inodesc));
801 idesc.id_type = ADDR; 801 idesc.id_type = ADDR;
802 idesc.id_func = pass6check; 802 idesc.id_func = pass6check;
803 idesc.id_lblkno = 0; 803 idesc.id_lblkno = 0;
804 LIST_FOREACH(vp, &vnodelist, v_mntvnodes) { 804 LIST_FOREACH(vp, &vnodelist, v_mntvnodes) {
805 if ((vp->v_uflag & VU_DIROP) == 0) 805 if ((vp->v_uflag & VU_DIROP) == 0)
806 --n_files; /* Don't double count */ 806 --n_files; /* Don't double count */
807 checkinode(VTOI(vp)->i_number, &idesc); 807 checkinode(VTOI(vp)->i_number, &idesc);
808 } 808 }
809 809
810 /* 810 /*
811 * Second pass. Run through FINFO entries looking for blocks 811 * Second pass. Run through FINFO entries looking for blocks
812 * with the same generation number as files we've seen before. 812 * with the same generation number as files we've seen before.
813 * If they have it, pretend like we just wrote them. We don't 813 * If they have it, pretend like we just wrote them. We don't
814 * do the pretend-write, though, if we've already seen them 814 * do the pretend-write, though, if we've already seen them
815 * (the accounting would have been done for us already). 815 * (the accounting would have been done for us already).
816 */ 816 */
817 daddr = fs->lfs_offset; 817 daddr = lfs_sb_getoffset(fs);
818 while (daddr != lastgood) { 818 while (daddr != lastgood) {
819 if (!(seg_table[lfs_dtosn(fs, daddr)].su_flags & SEGUSE_DIRTY)) { 819 if (!(seg_table[lfs_dtosn(fs, daddr)].su_flags & SEGUSE_DIRTY)) {
820 seg_table[lfs_dtosn(fs, daddr)].su_flags |= SEGUSE_DIRTY; 820 seg_table[lfs_dtosn(fs, daddr)].su_flags |= SEGUSE_DIRTY;
821 LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, daddr), sbp); 821 LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, daddr), sbp);
822 sup->su_flags |= SEGUSE_DIRTY; 822 sup->su_flags |= SEGUSE_DIRTY;
823 VOP_BWRITE(sbp); 823 VOP_BWRITE(sbp);
824 } 824 }
825 825
826 /* Could be a superblock */ 826 /* Could be a superblock */
827 if (lfs_sntod(fs, lfs_dtosn(fs, daddr)) == daddr) { 827 if (lfs_sntod(fs, lfs_dtosn(fs, daddr)) == daddr) {
828 if (daddr == fs->lfs_s0addr) 828 if (daddr == fs->lfs_s0addr)
829 daddr += lfs_btofsb(fs, LFS_LABELPAD); 829 daddr += lfs_btofsb(fs, LFS_LABELPAD);
830 for (i = 0; i < LFS_MAXNUMSB; i++) { 830 for (i = 0; i < LFS_MAXNUMSB; i++) {
@@ -838,67 +838,67 @@ pass6(void) @@ -838,67 +838,67 @@ pass6(void)
838  838
839 /* Read in summary block */ 839 /* Read in summary block */
840 bread(devvp, LFS_FSBTODB(fs, daddr), fs->lfs_sumsize, 0, &bp); 840 bread(devvp, LFS_FSBTODB(fs, daddr), fs->lfs_sumsize, 0, &bp);
841 sp = (SEGSUM *)bp->b_data; 841 sp = (SEGSUM *)bp->b_data;
842 bc = check_summary(fs, sp, daddr, debug, devvp, pass6harvest); 842 bc = check_summary(fs, sp, daddr, debug, devvp, pass6harvest);
843 if (bc == 0) { 843 if (bc == 0) {
844 pwarn("unexpected bad seg ptr [2] at 0x%x with serial=%d\n", 844 pwarn("unexpected bad seg ptr [2] at 0x%x with serial=%d\n",
845 (int)daddr, (int)sp->ss_serial); 845 (int)daddr, (int)sp->ss_serial);
846 brelse(bp, 0); 846 brelse(bp, 0);
847 break; 847 break;
848 } 848 }
849 odaddr = daddr; 849 odaddr = daddr;
850 daddr += lfs_btofsb(fs, fs->lfs_sumsize + bc); 850 daddr += lfs_btofsb(fs, fs->lfs_sumsize + bc);
851 fs->lfs_avail -= lfs_btofsb(fs, fs->lfs_sumsize + bc); 851 lfs_sb_subavail(fs, lfs_btofsb(fs, lfs_sb_getsumsize(fs) + bc));
852 if (lfs_dtosn(fs, odaddr) != lfs_dtosn(fs, daddr) || 852 if (lfs_dtosn(fs, odaddr) != lfs_dtosn(fs, daddr) ||
853 lfs_dtosn(fs, daddr) != lfs_dtosn(fs, daddr + 853 lfs_dtosn(fs, daddr) != lfs_dtosn(fs, daddr +
854 lfs_btofsb(fs, fs->lfs_sumsize + fs->lfs_bsize) - 1)) { 854 lfs_btofsb(fs, lfs_sb_getsumsize(fs) + lfs_sb_getbsize(fs)) - 1)) {
855 fs->lfs_avail -= lfs_sntod(fs, lfs_dtosn(fs, daddr) + 1) - daddr; 855 lfs_sb_subavail(fs, lfs_sntod(fs, lfs_dtosn(fs, daddr) + 1) - daddr);
856 daddr = ((SEGSUM *)bp->b_data)->ss_next; 856 daddr = ((SEGSUM *)bp->b_data)->ss_next;
857 } 857 }
858 LFS_CLEANERINFO(cip, fs, cbp); 858 LFS_CLEANERINFO(cip, fs, cbp);
859 LFS_SYNC_CLEANERINFO(cip, fs, cbp, 0); 859 LFS_SYNC_CLEANERINFO(cip, fs, cbp, 0);
860 bp->b_flags |= B_AGE; 860 bp->b_flags |= B_AGE;
861 brelse(bp, 0); 861 brelse(bp, 0);
862 } 862 }
863 863
864 /* Final address could also be a superblock */ 864 /* Final address could also be a superblock */
865 if (lfs_sntod(fs, lfs_dtosn(fs, lastgood)) == lastgood) { 865 if (lfs_sntod(fs, lfs_dtosn(fs, lastgood)) == lastgood) {
866 if (lastgood == fs->lfs_s0addr) 866 if (lastgood == fs->lfs_s0addr)
867 lastgood += lfs_btofsb(fs, LFS_LABELPAD); 867 lastgood += lfs_btofsb(fs, LFS_LABELPAD);
868 for (i = 0; i < LFS_MAXNUMSB; i++) { 868 for (i = 0; i < LFS_MAXNUMSB; i++) {
869 if (lastgood == fs->lfs_sboffs[i]) 869 if (lastgood == fs->lfs_sboffs[i])
870 lastgood += lfs_btofsb(fs, LFS_SBPAD);  870 lastgood += lfs_btofsb(fs, LFS_SBPAD);
871 if (lastgood < fs->lfs_sboffs[i]) 871 if (lastgood < fs->lfs_sboffs[i])
872 break; 872 break;
873 } 873 }
874 } 874 }
875  875
876 /* Update offset to point at correct location */ 876 /* Update offset to point at correct location */
877 fs->lfs_offset = lastgood; 877 lfs_sb_setoffset(fs, lastgood);
878 fs->lfs_curseg = lfs_sntod(fs, lfs_dtosn(fs, lastgood)); 878 lfs_sb_setcurseg(fs, lfs_sntod(fs, lfs_dtosn(fs, lastgood)));
879 for (sn = curseg = lfs_dtosn(fs, fs->lfs_curseg);;) { 879 for (sn = curseg = lfs_dtosn(fs, lfs_sb_getcurseg(fs));;) {
880 sn = (sn + 1) % fs->lfs_nseg; 880 sn = (sn + 1) % fs->lfs_nseg;
881 if (sn == curseg) 881 if (sn == curseg)
882 errx(1, "no clean segments"); 882 errx(1, "no clean segments");
883 LFS_SEGENTRY(sup, fs, sn, bp); 883 LFS_SEGENTRY(sup, fs, sn, bp);
884 if ((sup->su_flags & SEGUSE_DIRTY) == 0) { 884 if ((sup->su_flags & SEGUSE_DIRTY) == 0) {
885 sup->su_flags |= SEGUSE_DIRTY | SEGUSE_ACTIVE; 885 sup->su_flags |= SEGUSE_DIRTY | SEGUSE_ACTIVE;
886 VOP_BWRITE(bp); 886 VOP_BWRITE(bp);
887 break; 887 break;
888 } 888 }
889 brelse(bp, 0); 889 brelse(bp, 0);
890 } 890 }
891 fs->lfs_nextseg = lfs_sntod(fs, sn); 891 lfs_sb_setnextseg(fs, lfs_sntod(fs, sn));
892 892
893 if (preen) { 893 if (preen) {
894 if (ndelfiles) 894 if (ndelfiles)
895 pwarn("roll forward deleted %d file%s\n", ndelfiles, 895 pwarn("roll forward deleted %d file%s\n", ndelfiles,
896 (ndelfiles > 1 ? "s" : "")); 896 (ndelfiles > 1 ? "s" : ""));
897 if (nnewfiles) 897 if (nnewfiles)
898 pwarn("roll forward added %d file%s\n", nnewfiles, 898 pwarn("roll forward added %d file%s\n", nnewfiles,
899 (nnewfiles > 1 ? "s" : "")); 899 (nnewfiles > 1 ? "s" : ""));
900 if (nmvfiles) 900 if (nmvfiles)
901 pwarn("roll forward relocated %d inode%s\n", nmvfiles, 901 pwarn("roll forward relocated %d inode%s\n", nmvfiles,
902 (nmvfiles > 1 ? "s" : "")); 902 (nmvfiles > 1 ? "s" : ""));
903 if (nnewblocks) 903 if (nnewblocks)
904 pwarn("roll forward verified %d data block%s\n", nnewblocks, 904 pwarn("roll forward verified %d data block%s\n", nnewblocks,

cvs diff -r1.31 -r1.32 src/sbin/fsck_lfs/segwrite.c (expand / switch to unified diff)

--- src/sbin/fsck_lfs/segwrite.c 2015/06/17 00:18:35 1.31
+++ src/sbin/fsck_lfs/segwrite.c 2015/07/24 06:56:41 1.32
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: segwrite.c,v 1.31 2015/06/17 00:18:35 christos Exp $ */ 1/* $NetBSD: segwrite.c,v 1.32 2015/07/24 06:56:41 dholland Exp $ */
2/*- 2/*-
3 * Copyright (c) 2003 The NetBSD Foundation, Inc. 3 * Copyright (c) 2003 The NetBSD Foundation, Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * This code is derived from software contributed to The NetBSD Foundation 6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Konrad E. Schroder <perseant@hhhh.org>. 7 * by Konrad E. Schroder <perseant@hhhh.org>.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -154,27 +154,27 @@ lfs_segwrite(struct lfs * fs, int flags) @@ -154,27 +154,27 @@ lfs_segwrite(struct lfs * fs, int flags)
154 int redo; 154 int redo;
155 155
156 lfs_seglock(fs, flags | SEGM_CKP); 156 lfs_seglock(fs, flags | SEGM_CKP);
157 sp = fs->lfs_sp; 157 sp = fs->lfs_sp;
158 158
159 lfs_writevnodes(fs, sp, VN_REG); 159 lfs_writevnodes(fs, sp, VN_REG);
160 lfs_writevnodes(fs, sp, VN_DIROP); 160 lfs_writevnodes(fs, sp, VN_DIROP);
161 ((SEGSUM *) (sp->segsum))->ss_flags &= ~(SS_CONT); 161 ((SEGSUM *) (sp->segsum))->ss_flags &= ~(SS_CONT);
162 162
163 do { 163 do {
164 vp = fs->lfs_ivnode; 164 vp = fs->lfs_ivnode;
165 fs->lfs_flags &= ~LFS_IFDIRTY; 165 fs->lfs_flags &= ~LFS_IFDIRTY;
166 ip = VTOI(vp); 166 ip = VTOI(vp);
167 if (LIST_FIRST(&vp->v_dirtyblkhd) != NULL || fs->lfs_idaddr <= 0) 167 if (LIST_FIRST(&vp->v_dirtyblkhd) != NULL || lfs_sb_getidaddr(fs) <= 0)
168 lfs_writefile(fs, sp, vp); 168 lfs_writefile(fs, sp, vp);
169 169
170 redo = lfs_writeinode(fs, sp, ip); 170 redo = lfs_writeinode(fs, sp, ip);
171 redo += lfs_writeseg(fs, sp); 171 redo += lfs_writeseg(fs, sp);
172 redo += (fs->lfs_flags & LFS_IFDIRTY); 172 redo += (fs->lfs_flags & LFS_IFDIRTY);
173 } while (redo); 173 } while (redo);
174 174
175 lfs_segunlock(fs); 175 lfs_segunlock(fs);
176#if 0 176#if 0
177 printf("wrote %" PRId64 " bytes (%" PRId32 " fsb)\n", 177 printf("wrote %" PRId64 " bytes (%" PRId32 " fsb)\n",
178 written_bytes, (ulfs_daddr_t)lfs_btofsb(fs, written_bytes)); 178 written_bytes, (ulfs_daddr_t)lfs_btofsb(fs, written_bytes));
179 printf("wrote %" PRId64 " bytes data (%" PRId32 " fsb)\n", 179 printf("wrote %" PRId64 " bytes data (%" PRId32 " fsb)\n",
180 written_data, (ulfs_daddr_t)lfs_btofsb(fs, written_data)); 180 written_data, (ulfs_daddr_t)lfs_btofsb(fs, written_data));
@@ -191,27 +191,27 @@ lfs_segwrite(struct lfs * fs, int flags) @@ -191,27 +191,27 @@ lfs_segwrite(struct lfs * fs, int flags)
191/* 191/*
192 * Write the dirty blocks associated with a vnode. 192 * Write the dirty blocks associated with a vnode.
193 */ 193 */
194void 194void
195lfs_writefile(struct lfs * fs, struct segment * sp, struct uvnode * vp) 195lfs_writefile(struct lfs * fs, struct segment * sp, struct uvnode * vp)
196{ 196{
197 struct ubuf *bp; 197 struct ubuf *bp;
198 struct finfo *fip; 198 struct finfo *fip;
199 struct inode *ip; 199 struct inode *ip;
200 IFILE *ifp; 200 IFILE *ifp;
201 201
202 ip = VTOI(vp); 202 ip = VTOI(vp);
203 203
204 if (sp->seg_bytes_left < fs->lfs_bsize || 204 if (sp->seg_bytes_left < lfs_sb_getbsize(fs) ||
205 sp->sum_bytes_left < sizeof(struct finfo)) 205 sp->sum_bytes_left < sizeof(struct finfo))
206 (void) lfs_writeseg(fs, sp); 206 (void) lfs_writeseg(fs, sp);
207 207
208 sp->sum_bytes_left -= FINFOSIZE; 208 sp->sum_bytes_left -= FINFOSIZE;
209 ++((SEGSUM *) (sp->segsum))->ss_nfinfo; 209 ++((SEGSUM *) (sp->segsum))->ss_nfinfo;
210 210
211 if (vp->v_uflag & VU_DIROP) 211 if (vp->v_uflag & VU_DIROP)
212 ((SEGSUM *) (sp->segsum))->ss_flags |= (SS_DIROP | SS_CONT); 212 ((SEGSUM *) (sp->segsum))->ss_flags |= (SS_DIROP | SS_CONT);
213 213
214 fip = sp->fip; 214 fip = sp->fip;
215 fip->fi_nblocks = 0; 215 fip->fi_nblocks = 0;
216 fip->fi_ino = ip->i_number; 216 fip->fi_ino = ip->i_number;
217 LFS_IENTRY(ifp, fs, fip->fi_ino, bp); 217 LFS_IENTRY(ifp, fs, fip->fi_ino, bp);
@@ -247,44 +247,44 @@ lfs_writeinode(struct lfs * fs, struct s @@ -247,44 +247,44 @@ lfs_writeinode(struct lfs * fs, struct s
247 int redo_ifile = 0; 247 int redo_ifile = 0;
248 struct timespec ts; 248 struct timespec ts;
249 int gotblk = 0; 249 int gotblk = 0;
250 250
251 /* Allocate a new inode block if necessary. */ 251 /* Allocate a new inode block if necessary. */
252 if ((ip->i_number != LFS_IFILE_INUM || sp->idp == NULL) && 252 if ((ip->i_number != LFS_IFILE_INUM || sp->idp == NULL) &&
253 sp->ibp == NULL) { 253 sp->ibp == NULL) {
254 /* Allocate a new segment if necessary. */ 254 /* Allocate a new segment if necessary. */
255 if (sp->seg_bytes_left < fs->lfs_ibsize || 255 if (sp->seg_bytes_left < fs->lfs_ibsize ||
256 sp->sum_bytes_left < sizeof(ulfs_daddr_t)) 256 sp->sum_bytes_left < sizeof(ulfs_daddr_t))
257 (void) lfs_writeseg(fs, sp); 257 (void) lfs_writeseg(fs, sp);
258 258
259 /* Get next inode block. */ 259 /* Get next inode block. */
260 daddr = fs->lfs_offset; 260 daddr = lfs_sb_getoffset(fs);
261 fs->lfs_offset += lfs_btofsb(fs, fs->lfs_ibsize); 261 lfs_sb_addoffset(fs, lfs_btofsb(fs, lfs_sb_getibsize(fs)));
262 sp->ibp = *sp->cbpp++ = 262 sp->ibp = *sp->cbpp++ =
263 getblk(fs->lfs_devvp, LFS_FSBTODB(fs, daddr), 263 getblk(fs->lfs_devvp, LFS_FSBTODB(fs, daddr),
264 fs->lfs_ibsize); 264 fs->lfs_ibsize);
265 sp->ibp->b_flags |= B_GATHERED; 265 sp->ibp->b_flags |= B_GATHERED;
266 gotblk++; 266 gotblk++;
267 267
268 /* Zero out inode numbers */ 268 /* Zero out inode numbers */
269 for (i = 0; i < LFS_INOPB(fs); ++i) 269 for (i = 0; i < LFS_INOPB(fs); ++i)
270 ((struct ulfs1_dinode *) sp->ibp->b_data)[i].di_inumber = 0; 270 ((struct ulfs1_dinode *) sp->ibp->b_data)[i].di_inumber = 0;
271 271
272 ++sp->start_bpp; 272 ++sp->start_bpp;
273 fs->lfs_avail -= lfs_btofsb(fs, fs->lfs_ibsize); 273 lfs_sb_subavail(fs, lfs_btofsb(fs, lfs_sb_getibsize(fs)));
274 /* Set remaining space counters. */ 274 /* Set remaining space counters. */
275 sp->seg_bytes_left -= fs->lfs_ibsize; 275 sp->seg_bytes_left -= lfs_sb_getibsize(fs);
276 sp->sum_bytes_left -= sizeof(ulfs_daddr_t); 276 sp->sum_bytes_left -= sizeof(ulfs_daddr_t);
277 ndx = fs->lfs_sumsize / sizeof(ulfs_daddr_t) - 277 ndx = lfs_sb_getsumsize(fs) / sizeof(ulfs_daddr_t) -
278 sp->ninodes / LFS_INOPB(fs) - 1; 278 sp->ninodes / LFS_INOPB(fs) - 1;
279 ((ulfs_daddr_t *) (sp->segsum))[ndx] = daddr; 279 ((ulfs_daddr_t *) (sp->segsum))[ndx] = daddr;
280 } 280 }
281 /* Update the inode times and copy the inode onto the inode page. */ 281 /* Update the inode times and copy the inode onto the inode page. */
282 ts.tv_nsec = 0; 282 ts.tv_nsec = 0;
283 ts.tv_sec = write_time; 283 ts.tv_sec = write_time;
284 /* XXX kludge --- don't redirty the ifile just to put times on it */ 284 /* XXX kludge --- don't redirty the ifile just to put times on it */
285 if (ip->i_number != LFS_IFILE_INUM) 285 if (ip->i_number != LFS_IFILE_INUM)
286 LFS_ITIMES(ip, &ts, &ts, &ts); 286 LFS_ITIMES(ip, &ts, &ts, &ts);
287 287
288 /* 288 /*
289 * If this is the Ifile, and we've already written the Ifile in this 289 * If this is the Ifile, and we've already written the Ifile in this
290 * partial segment, just overwrite it (it's not on disk yet) and 290 * partial segment, just overwrite it (it's not on disk yet) and
@@ -316,28 +316,28 @@ lfs_writeinode(struct lfs * fs, struct s @@ -316,28 +316,28 @@ lfs_writeinode(struct lfs * fs, struct s
316 /* Increment inode count in segment summary block. */ 316 /* Increment inode count in segment summary block. */
317 ++((SEGSUM *) (sp->segsum))->ss_ninos; 317 ++((SEGSUM *) (sp->segsum))->ss_ninos;
318 318
319 /* If this page is full, set flag to allocate a new page. */ 319 /* If this page is full, set flag to allocate a new page. */
320 if (++sp->ninodes % LFS_INOPB(fs) == 0) 320 if (++sp->ninodes % LFS_INOPB(fs) == 0)
321 sp->ibp = NULL; 321 sp->ibp = NULL;
322 322
323 /* 323 /*
324 * If updating the ifile, update the super-block. Update the disk 324 * If updating the ifile, update the super-block. Update the disk
325 * address and access times for this inode in the ifile. 325 * address and access times for this inode in the ifile.
326 */ 326 */
327 ino = ip->i_number; 327 ino = ip->i_number;
328 if (ino == LFS_IFILE_INUM) { 328 if (ino == LFS_IFILE_INUM) {
329 daddr = fs->lfs_idaddr; 329 daddr = lfs_sb_getidaddr(fs);
330 fs->lfs_idaddr = LFS_DBTOFSB(fs, bp->b_blkno); 330 lfs_sb_setidaddr(fs, LFS_DBTOFSB(fs, bp->b_blkno));
331 sbdirty(); 331 sbdirty();
332 } else { 332 } else {
333 LFS_IENTRY(ifp, fs, ino, ibp); 333 LFS_IENTRY(ifp, fs, ino, ibp);
334 daddr = ifp->if_daddr; 334 daddr = ifp->if_daddr;
335 ifp->if_daddr = LFS_DBTOFSB(fs, bp->b_blkno) + fsb; 335 ifp->if_daddr = LFS_DBTOFSB(fs, bp->b_blkno) + fsb;
336 (void)LFS_BWRITE_LOG(ibp); /* Ifile */ 336 (void)LFS_BWRITE_LOG(ibp); /* Ifile */
337 } 337 }
338 338
339 /* 339 /*
340 * Account the inode: it no longer belongs to its former segment, 340 * Account the inode: it no longer belongs to its former segment,
341 * though it will not belong to the new segment until that segment 341 * though it will not belong to the new segment until that segment
342 * is actually written. 342 * is actually written.
343 */ 343 */
@@ -356,27 +356,27 @@ lfs_writeinode(struct lfs * fs, struct s @@ -356,27 +356,27 @@ lfs_writeinode(struct lfs * fs, struct s
356 356
357int 357int
358lfs_gatherblock(struct segment * sp, struct ubuf * bp) 358lfs_gatherblock(struct segment * sp, struct ubuf * bp)
359{ 359{
360 struct lfs *fs; 360 struct lfs *fs;
361 int version; 361 int version;
362 int j, blksinblk; 362 int j, blksinblk;
363 363
364 /* 364 /*
365 * If full, finish this segment. We may be doing I/O, so 365 * If full, finish this segment. We may be doing I/O, so
366 * release and reacquire the splbio(). 366 * release and reacquire the splbio().
367 */ 367 */
368 fs = sp->fs; 368 fs = sp->fs;
369 blksinblk = howmany(bp->b_bcount, fs->lfs_bsize); 369 blksinblk = howmany(bp->b_bcount, lfs_sb_getbsize(fs));
370 if (sp->sum_bytes_left < sizeof(ulfs_daddr_t) * blksinblk || 370 if (sp->sum_bytes_left < sizeof(ulfs_daddr_t) * blksinblk ||
371 sp->seg_bytes_left < bp->b_bcount) { 371 sp->seg_bytes_left < bp->b_bcount) {
372 lfs_updatemeta(sp); 372 lfs_updatemeta(sp);
373 373
374 version = sp->fip->fi_version; 374 version = sp->fip->fi_version;
375 (void) lfs_writeseg(fs, sp); 375 (void) lfs_writeseg(fs, sp);
376 376
377 sp->fip->fi_version = version; 377 sp->fip->fi_version = version;
378 sp->fip->fi_ino = VTOI(sp->vp)->i_number; 378 sp->fip->fi_ino = VTOI(sp->vp)->i_number;
379 /* Add the current file to the segment summary. */ 379 /* Add the current file to the segment summary. */
380 ++((SEGSUM *) (sp->segsum))->ss_nfinfo; 380 ++((SEGSUM *) (sp->segsum))->ss_nfinfo;
381 sp->sum_bytes_left -= FINFOSIZE; 381 sp->sum_bytes_left -= FINFOSIZE;
382 382
@@ -463,47 +463,47 @@ lfs_update_single(struct lfs * fs, struc @@ -463,47 +463,47 @@ lfs_update_single(struct lfs * fs, struc
463 ofrags = lfs_btofsb(fs, ip->i_lfs_fragsize[lbn]); 463 ofrags = lfs_btofsb(fs, ip->i_lfs_fragsize[lbn]);
464 ip->i_ffs1_blocks += (frags - ofrags); 464 ip->i_ffs1_blocks += (frags - ofrags);
465 } 465 }
466 ip->i_ffs1_db[lbn] = ndaddr; 466 ip->i_ffs1_db[lbn] = ndaddr;
467 break; 467 break;
468 case 1: 468 case 1:
469 ooff = ip->i_ffs1_ib[a[0].in_off]; 469 ooff = ip->i_ffs1_ib[a[0].in_off];
470 if (ooff == UNWRITTEN) 470 if (ooff == UNWRITTEN)
471 ip->i_ffs1_blocks += frags; 471 ip->i_ffs1_blocks += frags;
472 ip->i_ffs1_ib[a[0].in_off] = ndaddr; 472 ip->i_ffs1_ib[a[0].in_off] = ndaddr;
473 break; 473 break;
474 default: 474 default:
475 ap = &a[num - 1]; 475 ap = &a[num - 1];
476 if (bread(vp, ap->in_lbn, fs->lfs_bsize, 0, &bp)) 476 if (bread(vp, ap->in_lbn, lfs_sb_getbsize(fs), 0, &bp))
477 errx(EXIT_FAILURE, "%s: bread bno %" PRId64, __func__, 477 errx(EXIT_FAILURE, "%s: bread bno %" PRId64, __func__,
478 ap->in_lbn); 478 ap->in_lbn);
479 479
480 ooff = ((ulfs_daddr_t *) bp->b_data)[ap->in_off]; 480 ooff = ((ulfs_daddr_t *) bp->b_data)[ap->in_off];
481 if (ooff == UNWRITTEN) 481 if (ooff == UNWRITTEN)
482 ip->i_ffs1_blocks += frags; 482 ip->i_ffs1_blocks += frags;
483 ((ulfs_daddr_t *) bp->b_data)[ap->in_off] = ndaddr; 483 ((ulfs_daddr_t *) bp->b_data)[ap->in_off] = ndaddr;
484 (void) VOP_BWRITE(bp); 484 (void) VOP_BWRITE(bp);
485 } 485 }
486 486
487 /* 487 /*
488 * Update segment usage information, based on old size 488 * Update segment usage information, based on old size
489 * and location. 489 * and location.
490 */ 490 */
491 if (daddr > 0) { 491 if (daddr > 0) {
492 u_int32_t oldsn = lfs_dtosn(fs, daddr); 492 u_int32_t oldsn = lfs_dtosn(fs, daddr);
493 if (lbn >= 0 && lbn < ULFS_NDADDR) 493 if (lbn >= 0 && lbn < ULFS_NDADDR)
494 osize = ip->i_lfs_fragsize[lbn]; 494 osize = ip->i_lfs_fragsize[lbn];
495 else 495 else
496 osize = fs->lfs_bsize; 496 osize = lfs_sb_getbsize(fs);
497 LFS_SEGENTRY(sup, fs, oldsn, bp); 497 LFS_SEGENTRY(sup, fs, oldsn, bp);
498 sup->su_nbytes -= osize; 498 sup->su_nbytes -= osize;
499 if (!(bp->b_flags & B_GATHERED)) 499 if (!(bp->b_flags & B_GATHERED))
500 fs->lfs_flags |= LFS_IFDIRTY; 500 fs->lfs_flags |= LFS_IFDIRTY;
501 LFS_WRITESEGENTRY(sup, fs, oldsn, bp); 501 LFS_WRITESEGENTRY(sup, fs, oldsn, bp);
502 } 502 }
503 /* 503 /*
504 * Now that this block has a new address, and its old 504 * Now that this block has a new address, and its old
505 * segment no longer owns it, we can forget about its 505 * segment no longer owns it, we can forget about its
506 * old size. 506 * old size.
507 */ 507 */
508 if (lbn >= 0 && lbn < ULFS_NDADDR) 508 if (lbn >= 0 && lbn < ULFS_NDADDR)
509 ip->i_lfs_fragsize[lbn] = size; 509 ip->i_lfs_fragsize[lbn] = size;
@@ -531,206 +531,206 @@ lfs_updatemeta(struct segment * sp) @@ -531,206 +531,206 @@ lfs_updatemeta(struct segment * sp)
531 return; 531 return;
532 532
533 /* 533 /*
534 * This count may be high due to oversize blocks from lfs_gop_write. 534 * This count may be high due to oversize blocks from lfs_gop_write.
535 * Correct for this. (XXX we should be able to keep track of these.) 535 * Correct for this. (XXX we should be able to keep track of these.)
536 */ 536 */
537 fs = sp->fs; 537 fs = sp->fs;
538 for (i = 0; i < nblocks; i++) { 538 for (i = 0; i < nblocks; i++) {
539 if (sp->start_bpp[i] == NULL) { 539 if (sp->start_bpp[i] == NULL) {
540 printf("nblocks = %d, not %d\n", i, nblocks); 540 printf("nblocks = %d, not %d\n", i, nblocks);
541 nblocks = i; 541 nblocks = i;
542 break; 542 break;
543 } 543 }
544 num = howmany(sp->start_bpp[i]->b_bcount, fs->lfs_bsize); 544 num = howmany(sp->start_bpp[i]->b_bcount, lfs_sb_getbsize(fs));
545 nblocks -= num - 1; 545 nblocks -= num - 1;
546 } 546 }
547 547
548 /* 548 /*
549 * Sort the blocks. 549 * Sort the blocks.
550 */ 550 */
551 lfs_shellsort(sp->start_bpp, sp->start_lbp, nblocks, fs->lfs_bsize); 551 lfs_shellsort(sp->start_bpp, sp->start_lbp, nblocks, lfs_sb_getbsize(fs));
552 552
553 /* 553 /*
554 * Record the length of the last block in case it's a fragment. 554 * Record the length of the last block in case it's a fragment.
555 * If there are indirect blocks present, they sort last. An 555 * If there are indirect blocks present, they sort last. An
556 * indirect block will be lfs_bsize and its presence indicates 556 * indirect block will be lfs_bsize and its presence indicates
557 * that you cannot have fragments. 557 * that you cannot have fragments.
558 */ 558 */
559 sp->fip->fi_lastlength = ((sp->start_bpp[nblocks - 1]->b_bcount - 1) & 559 sp->fip->fi_lastlength = ((sp->start_bpp[nblocks - 1]->b_bcount - 1) &
560 fs->lfs_bmask) + 1; 560 fs->lfs_bmask) + 1;
561 561
562 /* 562 /*
563 * Assign disk addresses, and update references to the logical 563 * Assign disk addresses, and update references to the logical
564 * block and the segment usage information. 564 * block and the segment usage information.
565 */ 565 */
566 for (i = nblocks; i--; ++sp->start_bpp) { 566 for (i = nblocks; i--; ++sp->start_bpp) {
567 sbp = *sp->start_bpp; 567 sbp = *sp->start_bpp;
568 lbn = *sp->start_lbp; 568 lbn = *sp->start_lbp;
569 569
570 sbp->b_blkno = LFS_FSBTODB(fs, fs->lfs_offset); 570 sbp->b_blkno = LFS_FSBTODB(fs, lfs_sb_getoffset(fs));
571 571
572 /* 572 /*
573 * If we write a frag in the wrong place, the cleaner won't 573 * If we write a frag in the wrong place, the cleaner won't
574 * be able to correctly identify its size later, and the 574 * be able to correctly identify its size later, and the
575 * segment will be uncleanable. (Even worse, it will assume 575 * segment will be uncleanable. (Even worse, it will assume
576 * that the indirect block that actually ends the list 576 * that the indirect block that actually ends the list
577 * is of a smaller size!) 577 * is of a smaller size!)
578 */ 578 */
579 if ((sbp->b_bcount & fs->lfs_bmask) && i != 0) 579 if ((sbp->b_bcount & fs->lfs_bmask) && i != 0)
580 errx(EXIT_FAILURE, "%s: fragment is not last block", __func__); 580 errx(EXIT_FAILURE, "%s: fragment is not last block", __func__);
581 581
582 /* 582 /*
583 * For each subblock in this possibly oversized block, 583 * For each subblock in this possibly oversized block,
584 * update its address on disk. 584 * update its address on disk.
585 */ 585 */
586 for (bytesleft = sbp->b_bcount; bytesleft > 0; 586 for (bytesleft = sbp->b_bcount; bytesleft > 0;
587 bytesleft -= fs->lfs_bsize) { 587 bytesleft -= lfs_sb_getbsize(fs)) {
588 size = MIN(bytesleft, fs->lfs_bsize); 588 size = MIN(bytesleft, lfs_sb_getbsize(fs));
589 frags = lfs_numfrags(fs, size); 589 frags = lfs_numfrags(fs, size);
590 lbn = *sp->start_lbp++; 590 lbn = *sp->start_lbp++;
591 lfs_update_single(fs, sp, lbn, fs->lfs_offset, size); 591 lfs_update_single(fs, sp, lbn, lfs_sb_getoffset(fs), size);
592 fs->lfs_offset += frags; 592 lfs_sb_addoffset(fs, frags);
593 } 593 }
594 594
595 } 595 }
596} 596}
597 597
598/* 598/*
599 * Start a new segment. 599 * Start a new segment.
600 */ 600 */
601int 601int
602lfs_initseg(struct lfs * fs) 602lfs_initseg(struct lfs * fs)
603{ 603{
604 struct segment *sp; 604 struct segment *sp;
605 SEGUSE *sup; 605 SEGUSE *sup;
606 SEGSUM *ssp; 606 SEGSUM *ssp;
607 struct ubuf *bp, *sbp; 607 struct ubuf *bp, *sbp;
608 int repeat; 608 int repeat;
609 609
610 sp = fs->lfs_sp; 610 sp = fs->lfs_sp;
611 611
612 repeat = 0; 612 repeat = 0;
613 613
614 /* Advance to the next segment. */ 614 /* Advance to the next segment. */
615 if (!LFS_PARTIAL_FITS(fs)) { 615 if (!LFS_PARTIAL_FITS(fs)) {
616 /* lfs_avail eats the remaining space */ 616 /* lfs_avail eats the remaining space */
617 fs->lfs_avail -= fs->lfs_fsbpseg - (fs->lfs_offset - 617 lfs_sb_subavail(fs, lfs_sb_getfsbpseg(fs) - (lfs_sb_getoffset(fs) -
618 fs->lfs_curseg); 618 lfs_sb_getcurseg(fs)));
619 lfs_newseg(fs); 619 lfs_newseg(fs);
620 repeat = 1; 620 repeat = 1;
621 fs->lfs_offset = fs->lfs_curseg; 621 lfs_sb_setoffset(fs, lfs_sb_getcurseg(fs));
622 622
623 sp->seg_number = lfs_dtosn(fs, fs->lfs_curseg); 623 sp->seg_number = lfs_dtosn(fs, lfs_sb_getcurseg(fs));
624 sp->seg_bytes_left = lfs_fsbtob(fs, fs->lfs_fsbpseg); 624 sp->seg_bytes_left = lfs_fsbtob(fs, lfs_sb_getfsbpseg(fs));
625 625
626 /* 626 /*
627 * If the segment contains a superblock, update the offset 627 * If the segment contains a superblock, update the offset
628 * and summary address to skip over it. 628 * and summary address to skip over it.
629 */ 629 */
630 LFS_SEGENTRY(sup, fs, sp->seg_number, bp); 630 LFS_SEGENTRY(sup, fs, sp->seg_number, bp);
631 if (sup->su_flags & SEGUSE_SUPERBLOCK) { 631 if (sup->su_flags & SEGUSE_SUPERBLOCK) {
632 fs->lfs_offset += lfs_btofsb(fs, LFS_SBPAD); 632 lfs_sb_addoffset(fs, lfs_btofsb(fs, LFS_SBPAD));
633 sp->seg_bytes_left -= LFS_SBPAD; 633 sp->seg_bytes_left -= LFS_SBPAD;
634 } 634 }
635 brelse(bp, 0); 635 brelse(bp, 0);
636 /* Segment zero could also contain the labelpad */ 636 /* Segment zero could also contain the labelpad */
637 if (fs->lfs_version > 1 && sp->seg_number == 0 && 637 if (fs->lfs_version > 1 && sp->seg_number == 0 &&
638 fs->lfs_s0addr < lfs_btofsb(fs, LFS_LABELPAD)) { 638 fs->lfs_s0addr < lfs_btofsb(fs, LFS_LABELPAD)) {
639 fs->lfs_offset += lfs_btofsb(fs, LFS_LABELPAD) - fs->lfs_s0addr; 639 lfs_sb_addoffset(fs, lfs_btofsb(fs, LFS_LABELPAD) - fs->lfs_s0addr);
640 sp->seg_bytes_left -= LFS_LABELPAD - lfs_fsbtob(fs, fs->lfs_s0addr); 640 sp->seg_bytes_left -= LFS_LABELPAD - lfs_fsbtob(fs, fs->lfs_s0addr);
641 } 641 }
642 } else { 642 } else {
643 sp->seg_number = lfs_dtosn(fs, fs->lfs_curseg); 643 sp->seg_number = lfs_dtosn(fs, lfs_sb_getcurseg(fs));
644 sp->seg_bytes_left = lfs_fsbtob(fs, fs->lfs_fsbpseg - 644 sp->seg_bytes_left = lfs_fsbtob(fs, lfs_sb_getfsbpseg(fs) -
645 (fs->lfs_offset - fs->lfs_curseg)); 645 (lfs_sb_getoffset(fs) - lfs_sb_getcurseg(fs)));
646 } 646 }
647 fs->lfs_lastpseg = fs->lfs_offset; 647 lfs_sb_setlastpseg(fs, lfs_sb_getoffset(fs));
648 648
649 sp->fs = fs; 649 sp->fs = fs;
650 sp->ibp = NULL; 650 sp->ibp = NULL;
651 sp->idp = NULL; 651 sp->idp = NULL;
652 sp->ninodes = 0; 652 sp->ninodes = 0;
653 sp->ndupino = 0; 653 sp->ndupino = 0;
654 654
655 /* Get a new buffer for SEGSUM and enter it into the buffer list. */ 655 /* Get a new buffer for SEGSUM and enter it into the buffer list. */
656 sp->cbpp = sp->bpp; 656 sp->cbpp = sp->bpp;
657 sbp = *sp->cbpp = getblk(fs->lfs_devvp, 657 sbp = *sp->cbpp = getblk(fs->lfs_devvp,
658 LFS_FSBTODB(fs, fs->lfs_offset), fs->lfs_sumsize); 658 LFS_FSBTODB(fs, lfs_sb_getoffset(fs)), lfs_sb_getsumsize(fs));
659 sp->segsum = sbp->b_data; 659 sp->segsum = sbp->b_data;
660 memset(sp->segsum, 0, fs->lfs_sumsize); 660 memset(sp->segsum, 0, lfs_sb_getsumsize(fs));
661 sp->start_bpp = ++sp->cbpp; 661 sp->start_bpp = ++sp->cbpp;
662 fs->lfs_offset += lfs_btofsb(fs, fs->lfs_sumsize); 662 lfs_sb_addoffset(fs, lfs_btofsb(fs, lfs_sb_getsumsize(fs)));
663 663
664 /* Set point to SEGSUM, initialize it. */ 664 /* Set point to SEGSUM, initialize it. */
665 ssp = sp->segsum; 665 ssp = sp->segsum;
666 ssp->ss_next = fs->lfs_nextseg; 666 ssp->ss_next = lfs_sb_getnextseg(fs);
667 ssp->ss_nfinfo = ssp->ss_ninos = 0; 667 ssp->ss_nfinfo = ssp->ss_ninos = 0;
668 ssp->ss_magic = SS_MAGIC; 668 ssp->ss_magic = SS_MAGIC;
669 669
670 /* Set pointer to first FINFO, initialize it. */ 670 /* Set pointer to first FINFO, initialize it. */
671 sp->fip = (struct finfo *) ((caddr_t) sp->segsum + SEGSUM_SIZE(fs)); 671 sp->fip = (struct finfo *) ((caddr_t) sp->segsum + SEGSUM_SIZE(fs));
672 sp->fip->fi_nblocks = 0; 672 sp->fip->fi_nblocks = 0;
673 sp->start_lbp = &sp->fip->fi_blocks[0]; 673 sp->start_lbp = &sp->fip->fi_blocks[0];
674 sp->fip->fi_lastlength = 0; 674 sp->fip->fi_lastlength = 0;
675 675
676 sp->seg_bytes_left -= fs->lfs_sumsize; 676 sp->seg_bytes_left -= lfs_sb_getsumsize(fs);
677 sp->sum_bytes_left = fs->lfs_sumsize - SEGSUM_SIZE(fs); 677 sp->sum_bytes_left = lfs_sb_getsumsize(fs) - SEGSUM_SIZE(fs);
678 678
679 LFS_LOCK_BUF(sbp); 679 LFS_LOCK_BUF(sbp);
680 brelse(sbp, 0); 680 brelse(sbp, 0);
681 return repeat; 681 return repeat;
682} 682}
683 683
684/* 684/*
685 * Return the next segment to write. 685 * Return the next segment to write.
686 */ 686 */
687void 687void
688lfs_newseg(struct lfs * fs) 688lfs_newseg(struct lfs * fs)
689{ 689{
690 CLEANERINFO *cip; 690 CLEANERINFO *cip;
691 SEGUSE *sup; 691 SEGUSE *sup;
692 struct ubuf *bp; 692 struct ubuf *bp;
693 int curseg, isdirty, sn; 693 int curseg, isdirty, sn;
694 694
695 LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, fs->lfs_nextseg), bp); 695 LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, lfs_sb_getnextseg(fs)), bp);
696 sup->su_flags |= SEGUSE_DIRTY | SEGUSE_ACTIVE; 696 sup->su_flags |= SEGUSE_DIRTY | SEGUSE_ACTIVE;
697 sup->su_nbytes = 0; 697 sup->su_nbytes = 0;
698 sup->su_nsums = 0; 698 sup->su_nsums = 0;
699 sup->su_ninos = 0; 699 sup->su_ninos = 0;
700 LFS_WRITESEGENTRY(sup, fs, lfs_dtosn(fs, fs->lfs_nextseg), bp); 700 LFS_WRITESEGENTRY(sup, fs, lfs_dtosn(fs, lfs_sb_getnextseg(fs)), bp);
701 701
702 LFS_CLEANERINFO(cip, fs, bp); 702 LFS_CLEANERINFO(cip, fs, bp);
703 --cip->clean; 703 --cip->clean;
704 ++cip->dirty; 704 ++cip->dirty;
705 fs->lfs_nclean = cip->clean; 705 fs->lfs_nclean = cip->clean;
706 LFS_SYNC_CLEANERINFO(cip, fs, bp, 1); 706 LFS_SYNC_CLEANERINFO(cip, fs, bp, 1);
707 707
708 fs->lfs_lastseg = fs->lfs_curseg; 708 lfs_sb_setlastseg(fs, lfs_sb_getcurseg(fs));
709 fs->lfs_curseg = fs->lfs_nextseg; 709 lfs_sb_setcurseg(fs, lfs_sb_getnextseg(fs));
710 for (sn = curseg = lfs_dtosn(fs, fs->lfs_curseg) + fs->lfs_interleave;;) { 710 for (sn = curseg = lfs_dtosn(fs, lfs_sb_getcurseg(fs)) + lfs_sb_getinterleave(fs);;) {
711 sn = (sn + 1) % fs->lfs_nseg; 711 sn = (sn + 1) % fs->lfs_nseg;
712 if (sn == curseg) 712 if (sn == curseg)
713 errx(EXIT_FAILURE, "%s: no clean segments", __func__); 713 errx(EXIT_FAILURE, "%s: no clean segments", __func__);
714 LFS_SEGENTRY(sup, fs, sn, bp); 714 LFS_SEGENTRY(sup, fs, sn, bp);
715 isdirty = sup->su_flags & SEGUSE_DIRTY; 715 isdirty = sup->su_flags & SEGUSE_DIRTY;
716 brelse(bp, 0); 716 brelse(bp, 0);
717 717
718 if (!isdirty) 718 if (!isdirty)
719 break; 719 break;
720 } 720 }
721 721
722 ++fs->lfs_nactive; 722 ++fs->lfs_nactive;
723 fs->lfs_nextseg = lfs_sntod(fs, sn); 723 lfs_sb_setnextseg(fs, lfs_sntod(fs, sn));
724} 724}
725 725
726 726
727int 727int
728lfs_writeseg(struct lfs * fs, struct segment * sp) 728lfs_writeseg(struct lfs * fs, struct segment * sp)
729{ 729{
730 struct ubuf **bpp, *bp; 730 struct ubuf **bpp, *bp;
731 SEGUSE *sup; 731 SEGUSE *sup;
732 SEGSUM *ssp; 732 SEGSUM *ssp;
733 char *datap, *dp; 733 char *datap, *dp;
734 int i; 734 int i;
735 int do_again, nblocks, byteoffset; 735 int do_again, nblocks, byteoffset;
736 size_t el_size; 736 size_t el_size;
@@ -766,72 +766,73 @@ lfs_writeseg(struct lfs * fs, struct seg @@ -766,72 +766,73 @@ lfs_writeseg(struct lfs * fs, struct seg
766 766
767 ssp = (SEGSUM *) sp->segsum; 767 ssp = (SEGSUM *) sp->segsum;
768 ssp->ss_flags |= SS_RFW; 768 ssp->ss_flags |= SS_RFW;
769 769
770 ninos = (ssp->ss_ninos + LFS_INOPB(fs) - 1) / LFS_INOPB(fs); 770 ninos = (ssp->ss_ninos + LFS_INOPB(fs) - 1) / LFS_INOPB(fs);
771 sup->su_nbytes += ssp->ss_ninos * LFS_DINODE1_SIZE; 771 sup->su_nbytes += ssp->ss_ninos * LFS_DINODE1_SIZE;
772 772
773 if (fs->lfs_version == 1) 773 if (fs->lfs_version == 1)
774 sup->su_olastmod = write_time; 774 sup->su_olastmod = write_time;
775 else 775 else
776 sup->su_lastmod = write_time; 776 sup->su_lastmod = write_time;
777 sup->su_ninos += ninos; 777 sup->su_ninos += ninos;
778 ++sup->su_nsums; 778 ++sup->su_nsums;
779 fs->lfs_dmeta += (lfs_btofsb(fs, fs->lfs_sumsize) + lfs_btofsb(fs, ninos * 779 fs->lfs_dmeta += (lfs_btofsb(fs, lfs_sb_getsumsize(fs)) + lfs_btofsb(fs, ninos *
780 fs->lfs_ibsize)); 780 fs->lfs_ibsize));
781 fs->lfs_avail -= lfs_btofsb(fs, fs->lfs_sumsize); 781 lfs_sb_subavail(fs, lfs_btofsb(fs, lfs_sb_getsumsize(fs)));
782 782
783 do_again = !(bp->b_flags & B_GATHERED); 783 do_again = !(bp->b_flags & B_GATHERED);
784 LFS_WRITESEGENTRY(sup, fs, sp->seg_number, bp); /* Ifile */ 784 LFS_WRITESEGENTRY(sup, fs, sp->seg_number, bp); /* Ifile */
785 785
786 /* 786 /*
787 * Compute checksum across data and then across summary; the first 787 * Compute checksum across data and then across summary; the first
788 * block (the summary block) is skipped. Set the create time here 788 * block (the summary block) is skipped. Set the create time here
789 * so that it's guaranteed to be later than the inode mod times. 789 * so that it's guaranteed to be later than the inode mod times.
790 */ 790 */
791 if (fs->lfs_version == 1) 791 if (fs->lfs_version == 1)
792 el_size = sizeof(u_long); 792 el_size = sizeof(u_long);
793 else 793 else
794 el_size = sizeof(u_int32_t); 794 el_size = sizeof(u_int32_t);
795 datap = dp = emalloc(nblocks * el_size); 795 datap = dp = emalloc(nblocks * el_size);
796 for (bpp = sp->bpp, i = nblocks - 1; i--;) { 796 for (bpp = sp->bpp, i = nblocks - 1; i--;) {
797 ++bpp; 797 ++bpp;
798 /* Loop through gop_write cluster blocks */ 798 /* Loop through gop_write cluster blocks */
799 for (byteoffset = 0; byteoffset < (*bpp)->b_bcount; 799 for (byteoffset = 0; byteoffset < (*bpp)->b_bcount;
800 byteoffset += fs->lfs_bsize) { 800 byteoffset += lfs_sb_getbsize(fs)) {
801 memcpy(dp, (*bpp)->b_data + byteoffset, el_size); 801 memcpy(dp, (*bpp)->b_data + byteoffset, el_size);
802 dp += el_size; 802 dp += el_size;
803 } 803 }
804 bremfree(*bpp); 804 bremfree(*bpp);
805 (*bpp)->b_flags |= B_BUSY; 805 (*bpp)->b_flags |= B_BUSY;
806 } 806 }
807 if (fs->lfs_version == 1) 807 if (fs->lfs_version == 1)
808 ssp->ss_ocreate = write_time; 808 ssp->ss_ocreate = write_time;
809 else { 809 else {
810 ssp->ss_create = write_time; 810 ssp->ss_create = write_time;
811 ssp->ss_serial = ++fs->lfs_serial; 811 lfs_sb_addserial(fs, 1);
 812 ssp->ss_serial = lfs_sb_getserial(fs);
812 ssp->ss_ident = fs->lfs_ident; 813 ssp->ss_ident = fs->lfs_ident;
813 } 814 }
814 /* Set the summary block busy too */ 815 /* Set the summary block busy too */
815 bremfree(*(sp->bpp)); 816 bremfree(*(sp->bpp));
816 (*(sp->bpp))->b_flags |= B_BUSY; 817 (*(sp->bpp))->b_flags |= B_BUSY;
817 818
818 ssp->ss_datasum = cksum(datap, (nblocks - 1) * el_size); 819 ssp->ss_datasum = cksum(datap, (nblocks - 1) * el_size);
819 ssp->ss_sumsum = 820 ssp->ss_sumsum =
820 cksum(&ssp->ss_datasum, fs->lfs_sumsize - sizeof(ssp->ss_sumsum)); 821 cksum(&ssp->ss_datasum, lfs_sb_getsumsize(fs) - sizeof(ssp->ss_sumsum));
821 free(datap); 822 free(datap);
822 datap = dp = NULL; 823 datap = dp = NULL;
823 fs->lfs_bfree -= (lfs_btofsb(fs, ninos * fs->lfs_ibsize) + 824 lfs_sb_subbfree(fs, (lfs_btofsb(fs, ninos * lfs_sb_getibsize(fs)) +
824 lfs_btofsb(fs, fs->lfs_sumsize)); 825 lfs_btofsb(fs, lfs_sb_getsumsize(fs))));
825 826
826 if (devvp == NULL) 827 if (devvp == NULL)
827 errx(EXIT_FAILURE, "devvp is NULL"); 828 errx(EXIT_FAILURE, "devvp is NULL");
828 for (bpp = sp->bpp, i = nblocks; i; bpp++, i--) { 829 for (bpp = sp->bpp, i = nblocks; i; bpp++, i--) {
829 bp = *bpp; 830 bp = *bpp;
830#if 0 831#if 0
831 printf("i = %d, bp = %p, flags %lx, bn = %" PRIx64 "\n", 832 printf("i = %d, bp = %p, flags %lx, bn = %" PRIx64 "\n",
832 nblocks - i, bp, bp->b_flags, bp->b_blkno); 833 nblocks - i, bp, bp->b_flags, bp->b_blkno);
833 printf(" vp = %p\n", bp->b_vp); 834 printf(" vp = %p\n", bp->b_vp);
834 if (bp->b_vp != fs->lfs_devvp) 835 if (bp->b_vp != fs->lfs_devvp)
835 printf(" ino = %d lbn = %" PRId64 "\n", 836 printf(" ino = %d lbn = %" PRId64 "\n",
836 VTOI(bp->b_vp)->i_number, bp->b_lblkno); 837 VTOI(bp->b_vp)->i_number, bp->b_lblkno);
837#endif 838#endif
@@ -883,63 +884,64 @@ lfs_shellsort(struct ubuf ** bp_array, u @@ -883,63 +884,64 @@ lfs_shellsort(struct ubuf ** bp_array, u
883 } 884 }
884 } 885 }
885} 886}
886 887
887 888
888/* 889/*
889 * lfs_seglock -- 890 * lfs_seglock --
890 * Single thread the segment writer. 891 * Single thread the segment writer.
891 */ 892 */
892int 893int
893lfs_seglock(struct lfs * fs, unsigned long flags) 894lfs_seglock(struct lfs * fs, unsigned long flags)
894{ 895{
895 struct segment *sp; 896 struct segment *sp;
 897 size_t allocsize;
896 898
897 if (fs->lfs_seglock) { 899 if (fs->lfs_seglock) {
898 ++fs->lfs_seglock; 900 ++fs->lfs_seglock;
899 fs->lfs_sp->seg_flags |= flags; 901 fs->lfs_sp->seg_flags |= flags;
900 return 0; 902 return 0;
901 } 903 }
902 fs->lfs_seglock = 1; 904 fs->lfs_seglock = 1;
903 905
904 sp = fs->lfs_sp = emalloc(sizeof(*sp)); 906 sp = fs->lfs_sp = emalloc(sizeof(*sp));
905 sp->bpp = emalloc(fs->lfs_ssize * sizeof(struct ubuf *)); 907 allocsize = lfs_sb_getssize(fs) * sizeof(struct ubuf *);
 908 sp->bpp = emalloc(allocsize);
906 if (!sp->bpp) 909 if (!sp->bpp)
907 err(!preen, "Could not allocate %zu bytes", 910 err(!preen, "Could not allocate %zu bytes", allocsize);
908 (size_t)(fs->lfs_ssize * sizeof(struct ubuf *))); 
909 sp->seg_flags = flags; 911 sp->seg_flags = flags;
910 sp->vp = NULL; 912 sp->vp = NULL;
911 sp->seg_iocount = 0; 913 sp->seg_iocount = 0;
912 (void) lfs_initseg(fs); 914 (void) lfs_initseg(fs);
913 915
914 return 0; 916 return 0;
915} 917}
916 918
917/* 919/*
918 * lfs_segunlock -- 920 * lfs_segunlock --
919 * Single thread the segment writer. 921 * Single thread the segment writer.
920 */ 922 */
921void 923void
922lfs_segunlock(struct lfs * fs) 924lfs_segunlock(struct lfs * fs)
923{ 925{
924 struct segment *sp; 926 struct segment *sp;
925 struct ubuf *bp; 927 struct ubuf *bp;
926 928
927 sp = fs->lfs_sp; 929 sp = fs->lfs_sp;
928 930
929 if (fs->lfs_seglock == 1) { 931 if (fs->lfs_seglock == 1) {
930 if (sp->bpp != sp->cbpp) { 932 if (sp->bpp != sp->cbpp) {
931 /* Free allocated segment summary */ 933 /* Free allocated segment summary */
932 fs->lfs_offset -= lfs_btofsb(fs, fs->lfs_sumsize); 934 lfs_sb_suboffset(fs, lfs_btofsb(fs, lfs_sb_getsumsize(fs)));
933 bp = *sp->bpp; 935 bp = *sp->bpp;
934 bremfree(bp); 936 bremfree(bp);
935 bp->b_flags |= B_DONE | B_INVAL; 937 bp->b_flags |= B_DONE | B_INVAL;
936 bp->b_flags &= ~B_DELWRI; 938 bp->b_flags &= ~B_DELWRI;
937 reassignbuf(bp, bp->b_vp); 939 reassignbuf(bp, bp->b_vp);
938 bp->b_flags |= B_BUSY; /* XXX */ 940 bp->b_flags |= B_BUSY; /* XXX */
939 brelse(bp, 0); 941 brelse(bp, 0);
940 } else 942 } else
941 printf("unlock to 0 with no summary"); 943 printf("unlock to 0 with no summary");
942 944
943 free(sp->bpp); 945 free(sp->bpp);
944 sp->bpp = NULL; 946 sp->bpp = NULL;
945 free(sp); 947 free(sp);
@@ -987,26 +989,26 @@ lfs_writevnodes(struct lfs *fs, struct s @@ -987,26 +989,26 @@ lfs_writevnodes(struct lfs *fs, struct s
987 inodes_written++; 989 inodes_written++;
988 } 990 }
989 } 991 }
990 return inodes_written; 992 return inodes_written;
991} 993}
992 994
993void 995void
994lfs_writesuper(struct lfs *fs, ulfs_daddr_t daddr) 996lfs_writesuper(struct lfs *fs, ulfs_daddr_t daddr)
995{ 997{
996 struct ubuf *bp; 998 struct ubuf *bp;
997 999
998 /* Set timestamp of this version of the superblock */ 1000 /* Set timestamp of this version of the superblock */
999 if (fs->lfs_version == 1) 1001 if (fs->lfs_version == 1)
1000 fs->lfs_otstamp = write_time; 1002 lfs_sb_setotstamp(fs, write_time);
1001 fs->lfs_tstamp = write_time; 1003 lfs_sb_settstamp(fs, write_time);
1002 1004
1003 /* Checksum the superblock and copy it into a buffer. */ 1005 /* Checksum the superblock and copy it into a buffer. */
1004 fs->lfs_cksum = lfs_sb_cksum(&(fs->lfs_dlfs)); 1006 fs->lfs_cksum = lfs_sb_cksum(&(fs->lfs_dlfs));
1005 assert(daddr > 0); 1007 assert(daddr > 0);
1006 bp = getblk(fs->lfs_devvp, LFS_FSBTODB(fs, daddr), LFS_SBPAD); 1008 bp = getblk(fs->lfs_devvp, LFS_FSBTODB(fs, daddr), LFS_SBPAD);
1007 memset(bp->b_data + sizeof(struct dlfs), 0, 1009 memset(bp->b_data + sizeof(struct dlfs), 0,
1008 LFS_SBPAD - sizeof(struct dlfs)); 1010 LFS_SBPAD - sizeof(struct dlfs));
1009 *(struct dlfs *) bp->b_data = fs->lfs_dlfs; 1011 *(struct dlfs *) bp->b_data = fs->lfs_dlfs;
1010 1012
1011 bwrite(bp); 1013 bwrite(bp);
1012} 1014}

cvs diff -r1.4 -r1.5 src/sbin/fsck_lfs/segwrite.h (expand / switch to unified diff)

--- src/sbin/fsck_lfs/segwrite.h 2013/06/06 00:52:50 1.4
+++ src/sbin/fsck_lfs/segwrite.h 2015/07/24 06:56:41 1.5
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: segwrite.h,v 1.4 2013/06/06 00:52:50 dholland Exp $ */ 1/* $NetBSD: segwrite.h,v 1.5 2015/07/24 06:56:41 dholland Exp $ */
2/*- 2/*-
3 * Copyright (c) 2003 The NetBSD Foundation, Inc. 3 * Copyright (c) 2003 The NetBSD Foundation, Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * This code is derived from software contributed to The NetBSD Foundation 6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Konrad E. Schroder <perseant@hhhh.org>. 7 * by Konrad E. Schroder <perseant@hhhh.org>.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -22,28 +22,28 @@ @@ -22,28 +22,28 @@
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE. 28 * POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30/* 30/*
31 * Determine if it's OK to start a partial in this segment, or if we need 31 * Determine if it's OK to start a partial in this segment, or if we need
32 * to go on to a new segment. 32 * to go on to a new segment.
33 */ 33 */
34#define LFS_PARTIAL_FITS(fs) \ 34#define LFS_PARTIAL_FITS(fs) \
35 ((fs)->lfs_fsbpseg - ((fs)->lfs_offset - (fs)->lfs_curseg) > \ 35 (lfs_sb_getfsbpseg(fs) - (lfs_sb_getoffset(fs) - lfs_sb_getcurseg(fs)) > \
36 (fs)->lfs_frag) 36 lfs_sb_getfrag(fs))
37 37
38/* op values to lfs_writevnodes */ 38/* op values to lfs_writevnodes */
39#define VN_REG 0 39#define VN_REG 0
40#define VN_DIROP 1 40#define VN_DIROP 1
41 41
42int lfs_segwrite(struct lfs *, int); 42int lfs_segwrite(struct lfs *, int);
43void lfs_writefile(struct lfs *, struct segment *, struct uvnode *); 43void lfs_writefile(struct lfs *, struct segment *, struct uvnode *);
44int lfs_writeinode(struct lfs *, struct segment *, struct inode *); 44int lfs_writeinode(struct lfs *, struct segment *, struct inode *);
45int lfs_gatherblock(struct segment *, struct ubuf *); 45int lfs_gatherblock(struct segment *, struct ubuf *);
46int lfs_gather(struct lfs *, struct segment *, struct uvnode *, 46int lfs_gather(struct lfs *, struct segment *, struct uvnode *,
47 int (*match) (struct lfs *, struct ubuf *)); 47 int (*match) (struct lfs *, struct ubuf *));
48void lfs_update_single(struct lfs *, struct segment *, daddr_t, int32_t, int); 48void lfs_update_single(struct lfs *, struct segment *, daddr_t, int32_t, int);
49void lfs_updatemeta(struct segment *); 49void lfs_updatemeta(struct segment *);

cvs diff -r1.46 -r1.47 src/sbin/fsck_lfs/setup.c (expand / switch to unified diff)

--- src/sbin/fsck_lfs/setup.c 2015/05/31 15:44:30 1.46
+++ src/sbin/fsck_lfs/setup.c 2015/07/24 06:56:41 1.47
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: setup.c,v 1.46 2015/05/31 15:44:30 hannken Exp $ */ 1/* $NetBSD: setup.c,v 1.47 2015/07/24 06:56:41 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc. 4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant@hhhh.org>. 8 * by Konrad E. Schroder <perseant@hhhh.org>.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -206,27 +206,27 @@ setup(const char *dev) @@ -206,27 +206,27 @@ setup(const char *dev)
206 206
207 /* Initialize time in case we have to write */ 207 /* Initialize time in case we have to write */
208 time(&write_time); 208 time(&write_time);
209 209
210 bufinit(0); /* XXX we could make a better guess */ 210 bufinit(0); /* XXX we could make a better guess */
211 fs = lfs_init(fsreadfd, bflag, idaddr, 0, debug); 211 fs = lfs_init(fsreadfd, bflag, idaddr, 0, debug);
212 if (fs == NULL) { 212 if (fs == NULL) {
213 if (preen) 213 if (preen)
214 printf("%s: ", cdevname()); 214 printf("%s: ", cdevname());
215 errexit("BAD SUPER BLOCK OR IFILE INODE NOT FOUND"); 215 errexit("BAD SUPER BLOCK OR IFILE INODE NOT FOUND");
216 } 216 }
217 217
218 /* Resize buffer cache now that we have a superblock to guess from. */  218 /* Resize buffer cache now that we have a superblock to guess from. */
219 bufrehash((fs->lfs_segtabsz + maxino / fs->lfs_ifpb) << 4); 219 bufrehash((lfs_sb_getsegtabsz(fs) + maxino / lfs_sb_getifpb(fs)) << 4);
220 220
221 if (fs->lfs_pflags & LFS_PF_CLEAN) { 221 if (fs->lfs_pflags & LFS_PF_CLEAN) {
222 if (doskipclean) { 222 if (doskipclean) {
223 if (!quiet) 223 if (!quiet)
224 pwarn("%sile system is clean; not checking\n", 224 pwarn("%sile system is clean; not checking\n",
225 preen ? "f" : "** F"); 225 preen ? "f" : "** F");
226 return (-1); 226 return (-1);
227 } 227 }
228 if (!preen) 228 if (!preen)
229 pwarn("** File system is already clean\n"); 229 pwarn("** File system is already clean\n");
230 } 230 }
231 231
232 if (idaddr) { 232 if (idaddr) {
@@ -239,136 +239,137 @@ setup(const char *dev) @@ -239,136 +239,137 @@ setup(const char *dev)
239 pwarn("adjusting offset, serial for -i 0x%lx\n", 239 pwarn("adjusting offset, serial for -i 0x%lx\n",
240 (unsigned long)idaddr); 240 (unsigned long)idaddr);
241 tdaddr = lfs_sntod(fs, lfs_dtosn(fs, idaddr)); 241 tdaddr = lfs_sntod(fs, lfs_dtosn(fs, idaddr));
242 if (lfs_sntod(fs, lfs_dtosn(fs, tdaddr)) == tdaddr) { 242 if (lfs_sntod(fs, lfs_dtosn(fs, tdaddr)) == tdaddr) {
243 if (tdaddr == fs->lfs_s0addr) 243 if (tdaddr == fs->lfs_s0addr)
244 tdaddr += lfs_btofsb(fs, LFS_LABELPAD); 244 tdaddr += lfs_btofsb(fs, LFS_LABELPAD);
245 for (i = 0; i < LFS_MAXNUMSB; i++) { 245 for (i = 0; i < LFS_MAXNUMSB; i++) {
246 if (fs->lfs_sboffs[i] == tdaddr) 246 if (fs->lfs_sboffs[i] == tdaddr)
247 tdaddr += lfs_btofsb(fs, LFS_SBPAD); 247 tdaddr += lfs_btofsb(fs, LFS_SBPAD);
248 if (fs->lfs_sboffs[i] > tdaddr) 248 if (fs->lfs_sboffs[i] > tdaddr)
249 break; 249 break;
250 } 250 }
251 } 251 }
252 fs->lfs_offset = tdaddr; 252 lfs_sb_setoffset(fs, tdaddr);
253 if (debug) 253 if (debug)
254 pwarn("begin with offset/serial 0x%x/%d\n", 254 pwarn("begin with offset/serial 0x%jx/%jd\n",
255 (int)fs->lfs_offset, (int)fs->lfs_serial); 255 (uintmax_t)lfs_sb_getoffset(fs),
 256 (intmax_t)lfs_sb_getserial(fs));
256 while (tdaddr < idaddr) { 257 while (tdaddr < idaddr) {
257 bread(fs->lfs_devvp, LFS_FSBTODB(fs, tdaddr), 258 bread(fs->lfs_devvp, LFS_FSBTODB(fs, tdaddr),
258 fs->lfs_sumsize, 259 fs->lfs_sumsize,
259 0, &bp); 260 0, &bp);
260 sp = (SEGSUM *)bp->b_data; 261 sp = (SEGSUM *)bp->b_data;
261 if (sp->ss_sumsum != cksum(&sp->ss_datasum, 262 if (sp->ss_sumsum != cksum(&sp->ss_datasum,
262 fs->lfs_sumsize - 263 fs->lfs_sumsize -
263 sizeof(sp->ss_sumsum))) { 264 sizeof(sp->ss_sumsum))) {
264 brelse(bp, 0); 265 brelse(bp, 0);
265 if (debug) 266 if (debug)
266 printf("bad cksum at %x\n", 267 printf("bad cksum at %x\n",
267 (unsigned)tdaddr); 268 (unsigned)tdaddr);
268 break; 269 break;
269 } 270 }
270 fp = (FINFO *)(sp + 1); 271 fp = (FINFO *)(sp + 1);
271 bc = howmany(sp->ss_ninos, LFS_INOPB(fs)) << 272 bc = howmany(sp->ss_ninos, LFS_INOPB(fs)) <<
272 (fs->lfs_version > 1 ? fs->lfs_ffshift : 273 (fs->lfs_version > 1 ? fs->lfs_ffshift :
273 fs->lfs_bshift); 274 fs->lfs_bshift);
274 for (i = 0; i < sp->ss_nfinfo; i++) { 275 for (i = 0; i < sp->ss_nfinfo; i++) {
275 bc += fp->fi_lastlength + ((fp->fi_nblocks - 1) 276 bc += fp->fi_lastlength + ((fp->fi_nblocks - 1)
276 << fs->lfs_bshift); 277 << fs->lfs_bshift);
277 fp = (FINFO *)(fp->fi_blocks + fp->fi_nblocks); 278 fp = (FINFO *)(fp->fi_blocks + fp->fi_nblocks);
278 } 279 }
279 280
280 tdaddr += lfs_btofsb(fs, bc) + 1; 281 tdaddr += lfs_btofsb(fs, bc) + 1;
281 fs->lfs_offset = tdaddr; 282 lfs_sb_setoffset(fs, tdaddr);
282 fs->lfs_serial = sp->ss_serial + 1; 283 lfs_sb_setserial(fs, sp->ss_serial + 1);
283 brelse(bp, 0); 284 brelse(bp, 0);
284 } 285 }
285 286
286 /* 287 /*
287 * Set curseg, nextseg appropriately -- inlined from 288 * Set curseg, nextseg appropriately -- inlined from
288 * lfs_newseg() 289 * lfs_newseg()
289 */ 290 */
290 curseg = lfs_dtosn(fs, fs->lfs_offset); 291 curseg = lfs_dtosn(fs, lfs_sb_getoffset(fs));
291 fs->lfs_curseg = lfs_sntod(fs, curseg); 292 lfs_sb_setcurseg(fs, lfs_sntod(fs, curseg));
292 for (sn = curseg + fs->lfs_interleave;;) {  293 for (sn = curseg + fs->lfs_interleave;;) {
293 sn = (sn + 1) % fs->lfs_nseg; 294 sn = (sn + 1) % fs->lfs_nseg;
294 if (sn == curseg) 295 if (sn == curseg)
295 errx(1, "init: no clean segments"); 296 errx(1, "init: no clean segments");
296 LFS_SEGENTRY(sup, fs, sn, bp); 297 LFS_SEGENTRY(sup, fs, sn, bp);
297 isdirty = sup->su_flags & SEGUSE_DIRTY; 298 isdirty = sup->su_flags & SEGUSE_DIRTY;
298 brelse(bp, 0); 299 brelse(bp, 0);
299 300
300 if (!isdirty) 301 if (!isdirty)
301 break; 302 break;
302 } 303 }
303 304
304 /* Skip superblock if necessary */ 305 /* Skip superblock if necessary */
305 for (i = 0; i < LFS_MAXNUMSB; i++) 306 for (i = 0; i < LFS_MAXNUMSB; i++)
306 if (fs->lfs_offset == fs->lfs_sboffs[i]) 307 if (lfs_sb_getoffset(fs) == fs->lfs_sboffs[i])
307 fs->lfs_offset += lfs_btofsb(fs, LFS_SBPAD); 308 lfs_sb_addoffset(fs, lfs_btofsb(fs, LFS_SBPAD));
308 309
309 ++fs->lfs_nactive; 310 ++fs->lfs_nactive;
310 fs->lfs_nextseg = lfs_sntod(fs, sn); 311 lfs_sb_setnextseg(fs, lfs_sntod(fs, sn));
311 if (debug) { 312 if (debug) {
312 pwarn("offset = 0x%" PRIx32 ", serial = %" PRId64 "\n", 313 pwarn("offset = 0x%" PRIx32 ", serial = %" PRIu64 "\n",
313 fs->lfs_offset, fs->lfs_serial); 314 lfs_sb_getoffset(fs), lfs_sb_getserial(fs));
314 pwarn("curseg = %" PRIx32 ", nextseg = %" PRIx32 "\n", 315 pwarn("curseg = %" PRIx32 ", nextseg = %" PRIx32 "\n",
315 fs->lfs_curseg, fs->lfs_nextseg); 316 lfs_sb_getcurseg(fs), lfs_sb_getnextseg(fs));
316 } 317 }
317 318
318 if (!nflag && !skipclean) { 319 if (!nflag && !skipclean) {
319 fs->lfs_idaddr = idaddr; 320 lfs_sb_setidaddr(fs, idaddr);
320 fsmodified = 1; 321 fsmodified = 1;
321 sbdirty(); 322 sbdirty();
322 } 323 }
323 } 324 }
324 325
325 if (debug) { 326 if (debug) {
326 pwarn("idaddr = 0x%lx\n", idaddr ? (unsigned long)idaddr : 327 pwarn("idaddr = 0x%jx\n", idaddr ? (uintmax_t)idaddr :
327 (unsigned long)fs->lfs_idaddr); 328 (uintmax_t)lfs_sb_getidaddr(fs));
328 pwarn("dev_bsize = %lu\n", dev_bsize); 329 pwarn("dev_bsize = %lu\n", dev_bsize);
329 pwarn("lfs_bsize = %lu\n", (unsigned long) fs->lfs_bsize); 330 pwarn("lfs_bsize = %lu\n", (unsigned long) lfs_sb_getbsize(fs));
330 pwarn("lfs_fsize = %lu\n", (unsigned long) fs->lfs_fsize); 331 pwarn("lfs_fsize = %lu\n", (unsigned long) lfs_sb_getfsize(fs));
331 pwarn("lfs_frag = %lu\n", (unsigned long) fs->lfs_frag); 332 pwarn("lfs_frag = %lu\n", (unsigned long) lfs_sb_getfrag(fs));
332 pwarn("lfs_inopb = %lu\n", (unsigned long) fs->lfs_inopb); 333 pwarn("lfs_inopb = %lu\n", (unsigned long) fs->lfs_inopb);
333 } 334 }
334 if (fs->lfs_version == 1) 335 if (fs->lfs_version == 1)
335 maxfsblock = fs->lfs_size * (fs->lfs_bsize / dev_bsize); 336 maxfsblock = lfs_sb_getsize(fs) * (lfs_sb_getbsize(fs) / dev_bsize);
336 else 337 else
337 maxfsblock = fs->lfs_size; 338 maxfsblock = lfs_sb_getsize(fs);
338 maxfilesize = calcmaxfilesize(fs->lfs_bshift); 339 maxfilesize = calcmaxfilesize(fs->lfs_bshift);
339 if (/* fs->lfs_minfree < 0 || */ fs->lfs_minfree > 99) { 340 if (/* lfs_sb_getminfree(fs) < 0 || */ lfs_sb_getminfree(fs) > 99) {
340 pfatal("IMPOSSIBLE MINFREE=%d IN SUPERBLOCK", 341 pfatal("IMPOSSIBLE MINFREE=%u IN SUPERBLOCK",
341 fs->lfs_minfree); 342 lfs_sb_getminfree(fs));
342 if (reply("SET TO DEFAULT") == 1) { 343 if (reply("SET TO DEFAULT") == 1) {
343 fs->lfs_minfree = 10; 344 lfs_sb_setminfree(fs, 10);
344 sbdirty(); 345 sbdirty();
345 } 346 }
346 } 347 }
347 if (fs->lfs_bmask != fs->lfs_bsize - 1) { 348 if (fs->lfs_bmask != lfs_sb_getbsize(fs) - 1) {
348 pwarn("INCORRECT BMASK=0x%x IN SUPERBLOCK (SHOULD BE 0x%x)", 349 pwarn("INCORRECT BMASK=0x%x IN SUPERBLOCK (SHOULD BE 0x%x)",
349 (unsigned int) fs->lfs_bmask, 350 (unsigned int) fs->lfs_bmask,
350 (unsigned int) fs->lfs_bsize - 1); 351 (unsigned int) lfs_sb_getbsize(fs) - 1);
351 fs->lfs_bmask = fs->lfs_bsize - 1; 352 fs->lfs_bmask = lfs_sb_getbsize(fs) - 1;
352 if (preen) 353 if (preen)
353 printf(" (FIXED)\n"); 354 printf(" (FIXED)\n");
354 if (preen || reply("FIX") == 1) { 355 if (preen || reply("FIX") == 1) {
355 sbdirty(); 356 sbdirty();
356 } 357 }
357 } 358 }
358 if (fs->lfs_ffmask != fs->lfs_fsize - 1) { 359 if (fs->lfs_ffmask != lfs_sb_getfsize(fs) - 1) {
359 pwarn("INCORRECT FFMASK=%" PRId64 " IN SUPERBLOCK", 360 pwarn("INCORRECT FFMASK=%" PRId64 " IN SUPERBLOCK",
360 fs->lfs_ffmask); 361 fs->lfs_ffmask);
361 fs->lfs_ffmask = fs->lfs_fsize - 1; 362 fs->lfs_ffmask = lfs_sb_getfsize(fs) - 1;
362 if (preen) 363 if (preen)
363 printf(" (FIXED)\n"); 364 printf(" (FIXED)\n");
364 if (preen || reply("FIX") == 1) { 365 if (preen || reply("FIX") == 1) {
365 sbdirty(); 366 sbdirty();
366 } 367 }
367 } 368 }
368 if (fs->lfs_fbmask != (1 << fs->lfs_fbshift) - 1) { 369 if (fs->lfs_fbmask != (1 << fs->lfs_fbshift) - 1) {
369 pwarn("INCORRECT FBMASK=%" PRId64 " IN SUPERBLOCK", 370 pwarn("INCORRECT FBMASK=%" PRId64 " IN SUPERBLOCK",
370 fs->lfs_fbmask); 371 fs->lfs_fbmask);
371 fs->lfs_fbmask = (1 << fs->lfs_fbshift) - 1; 372 fs->lfs_fbmask = (1 << fs->lfs_fbshift) - 1;
372 if (preen) 373 if (preen)
373 printf(" (FIXED)\n"); 374 printf(" (FIXED)\n");
374 if (preen || reply("FIX") == 1) { 375 if (preen || reply("FIX") == 1) {
@@ -396,68 +397,68 @@ setup(const char *dev) @@ -396,68 +397,68 @@ setup(const char *dev)
396 if (preen || reply("FIX") == 1) { 397 if (preen || reply("FIX") == 1) {
397 sbdirty(); 398 sbdirty();
398 } 399 }
399 } 400 }
400 401
401 /* 402 /*
402 * Read in the Ifile; we'll be using it a lot. 403 * Read in the Ifile; we'll be using it a lot.
403 * XXX If the Ifile is corrupted we are in bad shape. We need to 404 * XXX If the Ifile is corrupted we are in bad shape. We need to
404 * XXX run through the segment headers of the entire disk to 405 * XXX run through the segment headers of the entire disk to
405 * XXX reconstruct the inode table, then pretend all segments are 406 * XXX reconstruct the inode table, then pretend all segments are
406 * XXX dirty while we do the rest. 407 * XXX dirty while we do the rest.
407 */ 408 */
408 ivp = fs->lfs_ivnode; 409 ivp = fs->lfs_ivnode;
409 maxino = ((VTOI(ivp)->i_ffs1_size - (fs->lfs_cleansz + fs->lfs_segtabsz) 410 maxino = ((VTOI(ivp)->i_ffs1_size - (lfs_sb_getcleansz(fs) + lfs_sb_getsegtabsz(fs))
410 * fs->lfs_bsize) / fs->lfs_bsize) * fs->lfs_ifpb; 411 * lfs_sb_getbsize(fs)) / lfs_sb_getbsize(fs)) * lfs_sb_getifpb(fs);
411 if (debug) 412 if (debug)
412 pwarn("maxino = %llu\n", (unsigned long long)maxino); 413 pwarn("maxino = %llu\n", (unsigned long long)maxino);
413 for (i = 0; i < VTOI(ivp)->i_ffs1_size; i += fs->lfs_bsize) { 414 for (i = 0; i < VTOI(ivp)->i_ffs1_size; i += lfs_sb_getbsize(fs)) {
414 bread(ivp, i >> fs->lfs_bshift, fs->lfs_bsize, 0, &bp); 415 bread(ivp, i >> fs->lfs_bshift, lfs_sb_getbsize(fs), 0, &bp);
415 /* XXX check B_ERROR */ 416 /* XXX check B_ERROR */
416 brelse(bp, 0); 417 brelse(bp, 0);
417 } 418 }
418 419
419 /* 420 /*
420 * allocate and initialize the necessary maps 421 * allocate and initialize the necessary maps
421 */ 422 */
422 din_table = ecalloc(maxino, sizeof(*din_table)); 423 din_table = ecalloc(maxino, sizeof(*din_table));
423 seg_table = ecalloc(fs->lfs_nseg, sizeof(SEGUSE)); 424 seg_table = ecalloc(fs->lfs_nseg, sizeof(SEGUSE));
424 /* Get segment flags */ 425 /* Get segment flags */
425 for (i = 0; i < fs->lfs_nseg; i++) { 426 for (i = 0; i < fs->lfs_nseg; i++) {
426 LFS_SEGENTRY(sup, fs, i, bp); 427 LFS_SEGENTRY(sup, fs, i, bp);
427 seg_table[i].su_flags = sup->su_flags & ~SEGUSE_ACTIVE; 428 seg_table[i].su_flags = sup->su_flags & ~SEGUSE_ACTIVE;
428 if (preen) 429 if (preen)
429 seg_table[i].su_nbytes = sup->su_nbytes; 430 seg_table[i].su_nbytes = sup->su_nbytes;
430 brelse(bp, 0); 431 brelse(bp, 0);
431 } 432 }
432 433
433 /* Initialize Ifile entry */ 434 /* Initialize Ifile entry */
434 din_table[fs->lfs_ifile] = fs->lfs_idaddr; 435 din_table[lfs_sb_getifile(fs)] = lfs_sb_getidaddr(fs);
435 seg_table[lfs_dtosn(fs, fs->lfs_idaddr)].su_nbytes += LFS_DINODE1_SIZE; 436 seg_table[lfs_dtosn(fs, lfs_sb_getidaddr(fs))].su_nbytes += LFS_DINODE1_SIZE;
436 437
437#ifndef VERBOSE_BLOCKMAP 438#ifndef VERBOSE_BLOCKMAP
438 bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(int16_t)); 439 bmapsize = roundup(howmany(maxfsblock, NBBY), sizeof(int16_t));
439 blockmap = ecalloc(bmapsize, sizeof(char)); 440 blockmap = ecalloc(bmapsize, sizeof(char));
440#else 441#else
441 bmapsize = maxfsblock * sizeof(ino_t); 442 bmapsize = maxfsblock * sizeof(ino_t);
442 blockmap = ecalloc(maxfsblock, sizeof(ino_t)); 443 blockmap = ecalloc(maxfsblock, sizeof(ino_t));
443#endif 444#endif
444 statemap = ecalloc(maxino, sizeof(char)); 445 statemap = ecalloc(maxino, sizeof(char));
445 typemap = ecalloc(maxino, sizeof(char)); 446 typemap = ecalloc(maxino, sizeof(char));
446 lncntp = ecalloc(maxino, sizeof(int16_t)); 447 lncntp = ecalloc(maxino, sizeof(int16_t));
447 448
448 if (preen) { 449 if (preen) {
449 n_files = fs->lfs_nfiles; 450 n_files = lfs_sb_getnfiles(fs);
450 n_blks = fs->lfs_dsize - fs->lfs_bfree; 451 n_blks = lfs_sb_getdsize(fs) - lfs_sb_getbfree(fs);
451 numdirs = maxino; 452 numdirs = maxino;
452 inplast = 0;  453 inplast = 0;
453 listmax = numdirs + 10; 454 listmax = numdirs + 10;
454 inpsort = ecalloc(listmax, sizeof(struct inoinfo *)); 455 inpsort = ecalloc(listmax, sizeof(struct inoinfo *));
455 inphead = ecalloc(numdirs, sizeof(struct inoinfo *)); 456 inphead = ecalloc(numdirs, sizeof(struct inoinfo *));
456 } 457 }
457 458
458 return (1); 459 return (1);
459 460
460 ckfini(0); 461 ckfini(0);
461 return (0); 462 return (0);
462} 463}
463 464

cvs diff -r1.31 -r1.32 src/sbin/newfs_lfs/make_lfs.c (expand / switch to unified diff)

--- src/sbin/newfs_lfs/make_lfs.c 2015/05/31 15:44:31 1.31
+++ src/sbin/newfs_lfs/make_lfs.c 2015/07/24 06:56:41 1.32
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: make_lfs.c,v 1.31 2015/05/31 15:44:31 hannken Exp $ */ 1/* $NetBSD: make_lfs.c,v 1.32 2015/07/24 06:56:41 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc. 4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant@hhhh.org>. 8 * by Konrad E. Schroder <perseant@hhhh.org>.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -52,27 +52,27 @@ @@ -52,27 +52,27 @@
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE. 57 * SUCH DAMAGE.
58 */ 58 */
59 59
60#include <sys/cdefs.h> 60#include <sys/cdefs.h>
61#ifndef lint 61#ifndef lint
62#if 0 62#if 0
63static char sccsid[] = "@(#)lfs.c 8.5 (Berkeley) 5/24/95"; 63static char sccsid[] = "@(#)lfs.c 8.5 (Berkeley) 5/24/95";
64#else 64#else
65__RCSID("$NetBSD: make_lfs.c,v 1.31 2015/05/31 15:44:31 hannken Exp $"); 65__RCSID("$NetBSD: make_lfs.c,v 1.32 2015/07/24 06:56:41 dholland Exp $");
66#endif 66#endif
67#endif /* not lint */ 67#endif /* not lint */
68 68
69#include <sys/param.h> 69#include <sys/param.h>
70#include <sys/disk.h> 70#include <sys/disk.h>
71#include <sys/time.h> 71#include <sys/time.h>
72#include <sys/mount.h> 72#include <sys/mount.h>
73#include <sys/stat.h> 73#include <sys/stat.h>
74 74
75/* Override certain things to make <ufs/lfs/lfs.h> work */ 75/* Override certain things to make <ufs/lfs/lfs.h> work */
76# undef simple_lock 76# undef simple_lock
77# define simple_lock(x) 77# define simple_lock(x)
78# undef simple_unlock 78# undef simple_unlock
@@ -214,35 +214,35 @@ maxfilesize(int bshift) @@ -214,35 +214,35 @@ maxfilesize(int bshift)
214 return maxblock << bshift; 214 return maxblock << bshift;
215} 215}
216 216
217/* 217/*
218 * Create the root directory for this file system and the lost+found 218 * Create the root directory for this file system and the lost+found
219 * directory. 219 * directory.
220 */ 220 */
221static void 221static void
222make_dinode(ino_t ino, struct ulfs1_dinode *dip, int nfrags, struct lfs *fs) 222make_dinode(ino_t ino, struct ulfs1_dinode *dip, int nfrags, struct lfs *fs)
223{ 223{
224 int i; 224 int i;
225 int nblocks, bb, base, factor, lvl; 225 int nblocks, bb, base, factor, lvl;
226 226
227 nblocks = howmany(nfrags, fs->lfs_frag); 227 nblocks = howmany(nfrags, lfs_sb_getfrag(fs));
228 if (nblocks >= ULFS_NDADDR) 228 if (nblocks >= ULFS_NDADDR)
229 nfrags = roundup(nfrags, fs->lfs_frag); 229 nfrags = roundup(nfrags, lfs_sb_getfrag(fs));
230 230
231 dip->di_nlink = 1; 231 dip->di_nlink = 1;
232 dip->di_blocks = nfrags; 232 dip->di_blocks = nfrags;
233 233
234 dip->di_size = (nfrags << fs->lfs_ffshift); 234 dip->di_size = (nfrags << fs->lfs_ffshift);
235 dip->di_atime = dip->di_mtime = dip->di_ctime = fs->lfs_tstamp; 235 dip->di_atime = dip->di_mtime = dip->di_ctime = lfs_sb_gettstamp(fs);
236 dip->di_atimensec = dip->di_mtimensec = dip->di_ctimensec = 0; 236 dip->di_atimensec = dip->di_mtimensec = dip->di_ctimensec = 0;
237 dip->di_inumber = ino; 237 dip->di_inumber = ino;
238 dip->di_gen = 1; 238 dip->di_gen = 1;
239 239
240 if (ULFS_NDADDR < nblocks) { 240 if (ULFS_NDADDR < nblocks) {
241 /* Count up how many indirect blocks we need, recursively */ 241 /* Count up how many indirect blocks we need, recursively */
242 /* XXX We are only called with nblocks > 1 for Ifile */ 242 /* XXX We are only called with nblocks > 1 for Ifile */
243 bb = nblocks - ULFS_NDADDR; 243 bb = nblocks - ULFS_NDADDR;
244 while (bb > 0) { 244 while (bb > 0) {
245 bb = howmany(bb, LFS_NINDIR(fs)); 245 bb = howmany(bb, LFS_NINDIR(fs));
246 ifibc += bb; 246 ifibc += bb;
247 --bb; 247 --bb;
248 } 248 }
@@ -311,26 +311,27 @@ make_lfs(int devfd, uint secsize, struct @@ -311,26 +311,27 @@ make_lfs(int devfd, uint secsize, struct
311 int db_per_blk; /* Disk blocks per file block */ 311 int db_per_blk; /* Disk blocks per file block */
312 int i, j; 312 int i, j;
313 int sb_interval; /* number of segs between super blocks */ 313 int sb_interval; /* number of segs between super blocks */
314 int ssize; /* Segment size */ 314 int ssize; /* Segment size */
315 double fssize; 315 double fssize;
316 int warned_segtoobig=0; 316 int warned_segtoobig=0;
317 int label_fsb, sb_fsb; 317 int label_fsb, sb_fsb;
318 int curw, ww; 318 int curw, ww;
319 char tbuf[BUFSIZ]; 319 char tbuf[BUFSIZ];
320 struct ubuf *bp; 320 struct ubuf *bp;
321 struct uvnode *vp, *save_devvp; 321 struct uvnode *vp, *save_devvp;
322 int bb, ubb, dmeta, labelskew; 322 int bb, ubb, dmeta, labelskew;
323 u_int64_t tsepb, tnseg; 323 u_int64_t tsepb, tnseg;
 324 time_t stamp;
324 325
325 /* 326 /*
326 * Initialize buffer cache. Use a ballpark guess of the length of 327 * Initialize buffer cache. Use a ballpark guess of the length of
327 * the segment table for the number of hash chains. 328 * the segment table for the number of hash chains.
328 */ 329 */
329 tnseg = dkw->dkw_size / ((seg_size ? seg_size : DFL_LFSSEG) / secsize); 330 tnseg = dkw->dkw_size / ((seg_size ? seg_size : DFL_LFSSEG) / secsize);
330 tsepb = (block_size ? block_size : DFL_LFSBLOCK) / sizeof(SEGSUM); 331 tsepb = (block_size ? block_size : DFL_LFSBLOCK) / sizeof(SEGSUM);
331 if (tnseg == 0) 332 if (tnseg == 0)
332 fatal("zero size partition"); 333 fatal("zero size partition");
333 bufinit(tnseg / tsepb); 334 bufinit(tnseg / tsepb);
334 335
335 /* Initialize LFS subsystem with blank superblock and ifile. */ 336 /* Initialize LFS subsystem with blank superblock and ifile. */
336 fs = lfs_init(devfd, start, (ulfs_daddr_t)0, 1, 1/* XXX debug*/); 337 fs = lfs_init(devfd, start, (ulfs_daddr_t)0, 1, 1/* XXX debug*/);
@@ -392,97 +393,100 @@ make_lfs(int devfd, uint secsize, struct @@ -392,97 +393,100 @@ make_lfs(int devfd, uint secsize, struct
392 fatal("filesystem offset %ld out of range", (long)start); 393 fatal("filesystem offset %ld out of range", (long)start);
393 if (version == 1) { 394 if (version == 1) {
394 if (start) 395 if (start)
395 warnx("filesystem offset ignored for version 1 filesystem"); 396 warnx("filesystem offset ignored for version 1 filesystem");
396 start = LFS_LABELPAD / secsize; 397 start = LFS_LABELPAD / secsize;
397 } 398 }
398 399
399 tryagain: 400 tryagain:
400 /* Modify parts of superblock overridden by command line arguments */ 401 /* Modify parts of superblock overridden by command line arguments */
401 if (bsize != DFL_LFSBLOCK || fsize != DFL_LFSFRAG) { 402 if (bsize != DFL_LFSBLOCK || fsize != DFL_LFSFRAG) {
402 fs->lfs_bshift = lfs_log2(bsize); 403 fs->lfs_bshift = lfs_log2(bsize);
403 if (1 << fs->lfs_bshift != bsize) 404 if (1 << fs->lfs_bshift != bsize)
404 fatal("%d: block size not a power of 2", bsize); 405 fatal("%d: block size not a power of 2", bsize);
405 fs->lfs_bsize = bsize; 406 lfs_sb_setbsize(fs, bsize);
406 fs->lfs_fsize = fsize; 407 lfs_sb_setfsize(fs, fsize);
407 fs->lfs_bmask = bsize - 1; 408 fs->lfs_bmask = bsize - 1;
408 fs->lfs_ffmask = fsize - 1; 409 fs->lfs_ffmask = fsize - 1;
409 fs->lfs_ffshift = lfs_log2(fsize); 410 fs->lfs_ffshift = lfs_log2(fsize);
410 if (1 << fs->lfs_ffshift != fsize) 411 if (1 << fs->lfs_ffshift != fsize)
411 fatal("%d: frag size not a power of 2", fsize); 412 fatal("%d: frag size not a power of 2", fsize);
412 fs->lfs_frag = lfs_numfrags(fs, bsize); 413 lfs_sb_setfrag(fs, lfs_numfrags(fs, bsize));
413 fs->lfs_fbmask = fs->lfs_frag - 1; 414 fs->lfs_fbmask = lfs_sb_getfrag(fs) - 1;
414 fs->lfs_fbshift = lfs_log2(fs->lfs_frag); 415 fs->lfs_fbshift = lfs_log2(lfs_sb_getfrag(fs));
415 fs->lfs_ifpb = bsize / sizeof(IFILE); 416 lfs_sb_setifpb(fs, bsize / sizeof(IFILE));
416 /* XXX ondisk32 */ 417 /* XXX ondisk32 */
417 fs->lfs_nindir = bsize / sizeof(int32_t); 418 fs->lfs_nindir = bsize / sizeof(int32_t);
418 } 419 }
419 420
420 if (fs->lfs_version == 1) { 421 if (fs->lfs_version == 1) {
421 fs->lfs_sumsize = LFS_V1_SUMMARY_SIZE; 422 fs->lfs_sumsize = LFS_V1_SUMMARY_SIZE;
422 fs->lfs_segshift = lfs_log2(ssize); 423 fs->lfs_segshift = lfs_log2(ssize);
423 if (1 << fs->lfs_segshift != ssize) 424 if (1 << fs->lfs_segshift != ssize)
424 fatal("%d: segment size not power of 2", ssize); 425 fatal("%d: segment size not power of 2", ssize);
425 fs->lfs_segmask = ssize - 1; 426 fs->lfs_segmask = ssize - 1;
426 fs->lfs_ifpb = fs->lfs_bsize / sizeof(IFILE_V1); 427 lfs_sb_setifpb(fs, lfs_sb_getbsize(fs) / sizeof(IFILE_V1));
427 fs->lfs_ibsize = fs->lfs_bsize; 428 lfs_sb_setibsize(fs, lfs_sb_getbsize(fs));
428 fs->lfs_sepb = bsize / sizeof(SEGUSE_V1); 429 lfs_sb_setsepb(fs, bsize / sizeof(SEGUSE_V1));
429 fs->lfs_ssize = ssize >> fs->lfs_bshift; 430 lfs_sb_setssize(fs, ssize >> fs->lfs_bshift);
430 } else { 431 } else {
431 if (ssize % fsize) { 432 if (ssize % fsize) {
432 fprintf(stderr,  433 fprintf(stderr,
433 "Segment size %d is not a multiple of frag size; ", 434 "Segment size %d is not a multiple of frag size; ",
434 ssize); 435 ssize);
435 ssize = roundup(ssize, fsize); 436 ssize = roundup(ssize, fsize);
436 fprintf(stderr, "trying size %d.\n", ssize); 437 fprintf(stderr, "trying size %d.\n", ssize);
437 goto tryagain; 438 goto tryagain;
438 } 439 }
439 fs->lfs_sumsize = fsize; 440 fs->lfs_sumsize = fsize;
440 fs->lfs_segshift = 0; 441 fs->lfs_segshift = 0;
441 fs->lfs_segmask = 0; 442 fs->lfs_segmask = 0;
442 fs->lfs_sepb = bsize / sizeof(SEGUSE); 443 lfs_sb_setsepb(fs, bsize / sizeof(SEGUSE));
443 fs->lfs_ssize = ssize; 444 lfs_sb_setssize(fs, ssize);
444 fs->lfs_ibsize = ibsize; 445 lfs_sb_setibsize(fs, ibsize);
445 } 446 }
446 fs->lfs_inopb = fs->lfs_ibsize / sizeof(struct ulfs1_dinode); 447 fs->lfs_inopb = fs->lfs_ibsize / sizeof(struct ulfs1_dinode);
447 fs->lfs_minfree = minfree; 448 lfs_sb_setminfree(fs, minfree);
448 449
449 if (version > 1) { 450 if (version > 1) {
450 fs->lfs_inopf = secsize/LFS_DINODE1_SIZE; 451 lfs_sb_setinopf(fs, secsize/LFS_DINODE1_SIZE);
451 fs->lfs_interleave = interleave; 452 fs->lfs_interleave = interleave;
452 if (roll_id == 0) 453 if (roll_id == 0)
453 roll_id = arc4random(); 454 roll_id = arc4random();
454 fs->lfs_ident = roll_id; 455 fs->lfs_ident = roll_id;
455 } 456 }
456 457
457 /* 458 /*
458 * Fill in parts of superblock that can be computed from file system 459 * Fill in parts of superblock that can be computed from file system
459 * size, disk geometry and current time. 460 * size, disk geometry and current time.
 461 *
 462 * XXX: this seems to set dlfs_size wrong for version 1... as in,
 463 * sets it and then overwrites it.
460 */ 464 */
461 db_per_blk = bsize/secsize; 465 db_per_blk = bsize/secsize;
462 fs->lfs_blktodb = lfs_log2(db_per_blk); 466 fs->lfs_blktodb = lfs_log2(db_per_blk);
463 fs->lfs_fsbtodb = lfs_log2(fsize / secsize); 467 fs->lfs_fsbtodb = lfs_log2(fsize / secsize);
464 if (version == 1) { 468 if (version == 1) {
465 fs->lfs_sushift = lfs_log2(fs->lfs_sepb); 469 fs->lfs_sushift = lfs_log2(lfs_sb_getsepb(fs));
466 fs->lfs_fsbtodb = 0; 470 fs->lfs_fsbtodb = 0;
467 fs->lfs_size = dkw->dkw_size >> fs->lfs_blktodb; 471 lfs_sb_setsize(fs, dkw->dkw_size >> fs->lfs_blktodb);
468 } 472 }
469 label_fsb = lfs_btofsb(fs, roundup(LFS_LABELPAD, fsize)); 473 label_fsb = lfs_btofsb(fs, roundup(LFS_LABELPAD, fsize));
470 sb_fsb = lfs_btofsb(fs, roundup(LFS_SBPAD, fsize)); 474 sb_fsb = lfs_btofsb(fs, roundup(LFS_SBPAD, fsize));
471 fs->lfs_fsbpseg = LFS_DBTOFSB(fs, ssize / secsize); 475 fs->lfs_fsbpseg = LFS_DBTOFSB(fs, ssize / secsize);
472 fs->lfs_size = dkw->dkw_size >> fs->lfs_fsbtodb; 476 lfs_sb_setsize(fs, dkw->dkw_size >> fs->lfs_fsbtodb);
473 fs->lfs_dsize = LFS_DBTOFSB(fs, dkw->dkw_size) - 477 lfs_sb_setdsize(fs, LFS_DBTOFSB(fs, dkw->dkw_size) -
474 MAX(label_fsb, LFS_DBTOFSB(fs, start)); 478 MAX(label_fsb, LFS_DBTOFSB(fs, start)));
475 fs->lfs_nseg = fs->lfs_dsize / lfs_segtod(fs, 1); 479 fs->lfs_nseg = lfs_sb_getdsize(fs) / lfs_segtod(fs, 1);
476 480
477 fs->lfs_nclean = fs->lfs_nseg - 1; 481 fs->lfs_nclean = fs->lfs_nseg - 1;
478 fs->lfs_maxfilesize = maxfilesize(fs->lfs_bshift); 482 fs->lfs_maxfilesize = maxfilesize(fs->lfs_bshift);
479 483
480 if (minfreeseg == 0) 484 if (minfreeseg == 0)
481 fs->lfs_minfreeseg = fs->lfs_nseg / DFL_MIN_FREE_SEGS; 485 fs->lfs_minfreeseg = fs->lfs_nseg / DFL_MIN_FREE_SEGS;
482 else 486 else
483 fs->lfs_minfreeseg = minfreeseg; 487 fs->lfs_minfreeseg = minfreeseg;
484 if (fs->lfs_minfreeseg < MIN_FREE_SEGS) 488 if (fs->lfs_minfreeseg < MIN_FREE_SEGS)
485 fs->lfs_minfreeseg = MIN_FREE_SEGS; 489 fs->lfs_minfreeseg = MIN_FREE_SEGS;
486 490
487 if (resvseg == 0) 491 if (resvseg == 0)
488 fs->lfs_resvseg = fs->lfs_minfreeseg / 2 + 1; 492 fs->lfs_resvseg = fs->lfs_minfreeseg / 2 + 1;
@@ -501,222 +505,223 @@ make_lfs(int devfd, uint secsize, struct @@ -501,222 +505,223 @@ make_lfs(int devfd, uint secsize, struct
501 if (ssize == (bsize << 16)) { 505 if (ssize == (bsize << 16)) {
502 fprintf(stderr, "(Did you perhaps " 506 fprintf(stderr, "(Did you perhaps "
503 "accidentally leave \"16\" " 507 "accidentally leave \"16\" "
504 "in the disklabel's sgs " 508 "in the disklabel's sgs "
505 "field?)\n"); 509 "field?)\n");
506 } 510 }
507 } 511 }
508 ++warned_segtoobig; 512 ++warned_segtoobig;
509 ssize >>= 1; 513 ssize >>= 1;
510 goto tryagain; 514 goto tryagain;
511 } 515 }
512 fatal("Could not allocate enough segments with segment " 516 fatal("Could not allocate enough segments with segment "
513 "size %d and block size %d;\nplease decrease the " 517 "size %d and block size %d;\nplease decrease the "
514 "segment size.\n", ssize, fs->lfs_bsize); 518 "segment size.\n", ssize, lfs_sb_getbsize(fs));
515 } 519 }
516 if(warned_segtoobig) 520 if(warned_segtoobig)
517 fprintf(stderr,"Using segment size %d, block size %d, frag size %d.\n", ssize, bsize, fsize); 521 fprintf(stderr,"Using segment size %d, block size %d, frag size %d.\n", ssize, bsize, fsize);
518 522
519 /* 523 /*
520 * Now that we've determined what we're going to do, announce it 524 * Now that we've determined what we're going to do, announce it
521 * to the user. 525 * to the user.
522 */ 526 */
523 printf("Creating a version %d LFS", fs->lfs_version); 527 printf("Creating a version %d LFS", fs->lfs_version);
524 if (fs->lfs_version > 1) 528 if (fs->lfs_version > 1)
525 printf(" with roll-forward ident 0x%x", fs->lfs_ident); 529 printf(" with roll-forward ident 0x%x", fs->lfs_ident);
526 printf("\n");  530 printf("\n");
527 fssize = (double)fs->lfs_nseg; 531 fssize = (double)fs->lfs_nseg;
528 fssize *= (double)ssize; 532 fssize *= (double)ssize;
529 fssize /= 1048576.0; 533 fssize /= 1048576.0;
530 printf("%.1fMB in %d segments of size %d\n", fssize, 534 printf("%.1fMB in %d segments of size %d\n", fssize,
531 fs->lfs_nseg, ssize); 535 fs->lfs_nseg, ssize);
532 536
533 /*  537 /*
534 * The number of free blocks is set from the number of segments 538 * The number of free blocks is set from the number of segments
535 * times the segment size - lfs_minfreesegs (that we never write 539 * times the segment size - lfs_minfreesegs (that we never write
536 * because we need to make sure the cleaner can run). Then 540 * because we need to make sure the cleaner can run). Then
537 * we'll subtract off the room for the superblocks ifile entries 541 * we'll subtract off the room for the superblocks ifile entries
538 * and segment usage table, and half a block per segment that can't 542 * and segment usage table, and half a block per segment that can't
539 * be written due to fragmentation. 543 * be written due to fragmentation.
540 */ 544 */
541 fs->lfs_dsize = (fs->lfs_nseg - fs->lfs_minfreeseg) * 545 lfs_sb_setdsize(fs, (fs->lfs_nseg - fs->lfs_minfreeseg) *
542 lfs_segtod(fs, 1); 546 lfs_segtod(fs, 1));
543 fs->lfs_bfree = fs->lfs_dsize; 547 lfs_sb_setbfree(fs, lfs_sb_getdsize(fs));
544 fs->lfs_bfree -= LFS_DBTOFSB(fs, ((fs->lfs_nseg / 2) <<  548 lfs_sb_subbfree(fs, LFS_DBTOFSB(fs, ((lfs_sb_getnseg(fs) / 2) <<
545 fs->lfs_blktodb)); 549 lfs_sb_getblktodb(fs))));
546 550
547 fs->lfs_segtabsz = SEGTABSIZE_SU(fs); 551 lfs_sb_setsegtabsz(fs, SEGTABSIZE_SU(fs));
548 fs->lfs_cleansz = CLEANSIZE_SU(fs); 552 lfs_sb_setcleansz(fs, CLEANSIZE_SU(fs));
549 if ((fs->lfs_tstamp = time(NULL)) == -1) 553 if (time(&stamp) == -1)
550 fatal("time: %s", strerror(errno)); 554 fatal("time: %s", strerror(errno));
 555 lfs_sb_settstamp(fs, stamp);
551 if (version == 1) 556 if (version == 1)
552 fs->lfs_otstamp = fs->lfs_tstamp; 557 lfs_sb_setotstamp(fs, stamp);
553 558
554 if ((sb_interval = fs->lfs_nseg / LFS_MAXNUMSB) < LFS_MIN_SBINTERVAL) 559 if ((sb_interval = fs->lfs_nseg / LFS_MAXNUMSB) < LFS_MIN_SBINTERVAL)
555 sb_interval = LFS_MIN_SBINTERVAL; 560 sb_interval = LFS_MIN_SBINTERVAL;
556 561
557 /* 562 /*
558 * Figure out where the superblocks are going to live. 563 * Figure out where the superblocks are going to live.
559 * 564 *
560 * Make segment 0 start at either zero, or LFS_LABELPAD, or 565 * Make segment 0 start at either zero, or LFS_LABELPAD, or
561 * >= LFS_SBPAD+LFS_LABELPAD, in order to prevent segment 0 566 * >= LFS_SBPAD+LFS_LABELPAD, in order to prevent segment 0
562 * from having half a superblock in it. 567 * from having half a superblock in it.
563 */ 568 */
564 if (LFS_FSBTODB(fs, LFS_DBTOFSB(fs, start)) != start) 569 if (LFS_FSBTODB(fs, LFS_DBTOFSB(fs, start)) != start)
565 fatal("Segment 0 offset is not multiple of frag size\n"); 570 fatal("Segment 0 offset is not multiple of frag size\n");
566 if (start != 0 && dbtob(start) != LFS_LABELPAD && 571 if (start != 0 && dbtob(start) != LFS_LABELPAD &&
567 dbtob(start) < LFS_SBPAD + LFS_LABELPAD) { 572 dbtob(start) < LFS_SBPAD + LFS_LABELPAD) {
568 fatal("Using flags \"-O %" PRId64 "\" would result in the " 573 fatal("Using flags \"-O %" PRId64 "\" would result in the "
569 "first segment containing only\npart of a superblock. " 574 "first segment containing only\npart of a superblock. "
570 "Please choose an offset of 0, %d, or %d or more,\n", 575 "Please choose an offset of 0, %d, or %d or more,\n",
571 start, btodb(LFS_LABELPAD), 576 start, btodb(LFS_LABELPAD),
572 btodb(LFS_LABELPAD + LFS_SBPAD)); 577 btodb(LFS_LABELPAD + LFS_SBPAD));
573 } 578 }
574 fs->lfs_sboffs[0] = label_fsb; 579 fs->lfs_sboffs[0] = label_fsb;
575 if (version == 1) 580 if (version == 1)
576 fs->lfs_s0addr = fs->lfs_sboffs[0]; 581 fs->lfs_s0addr = fs->lfs_sboffs[0];
577 else 582 else
578 fs->lfs_s0addr = LFS_DBTOFSB(fs, start); 583 fs->lfs_s0addr = LFS_DBTOFSB(fs, start);
579 fs->lfs_dsize -= sb_fsb; 584 lfs_sb_setdsize(fs, lfs_sb_getdsize(fs) - sb_fsb);
580 for (i = 1; i < LFS_MAXNUMSB; i++) { 585 for (i = 1; i < LFS_MAXNUMSB; i++) {
581 sb_addr = ((i * sb_interval) * lfs_segtod(fs, 1)) 586 sb_addr = ((i * sb_interval) * lfs_segtod(fs, 1))
582 + fs->lfs_sboffs[0]; 587 + fs->lfs_sboffs[0];
583 /* Segment 0 eats the label, except for version 1 */ 588 /* Segment 0 eats the label, except for version 1 */
584 if (fs->lfs_version > 1 && fs->lfs_s0addr < label_fsb) 589 if (fs->lfs_version > 1 && fs->lfs_s0addr < label_fsb)
585 sb_addr -= label_fsb - start; 590 sb_addr -= label_fsb - start;
586 if (sb_addr + sizeof(struct dlfs) 591 if (sb_addr + sizeof(struct dlfs)
587 >= LFS_DBTOFSB(fs, dkw->dkw_size)) 592 >= LFS_DBTOFSB(fs, dkw->dkw_size))
588 break; 593 break;
589 fs->lfs_sboffs[i] = sb_addr; 594 fs->lfs_sboffs[i] = sb_addr;
590 fs->lfs_dsize -= sb_fsb; 595 lfs_sb_setdsize(fs, lfs_sb_getdsize(fs) - sb_fsb);
591 } 596 }
592 597
593 /* We need >= 2 superblocks */ 598 /* We need >= 2 superblocks */
594 if(fs->lfs_sboffs[1] == 0x0) { 599 if(fs->lfs_sboffs[1] == 0x0) {
595 fatal("Could not assign a disk address for the second " 600 fatal("Could not assign a disk address for the second "
596 "superblock.\nPlease decrease the segment size.\n"); 601 "superblock.\nPlease decrease the segment size.\n");
597 } 602 }
598 603
599 fs->lfs_lastseg = lfs_sntod(fs, fs->lfs_nseg - 2); 604 lfs_sb_setlastseg(fs, lfs_sntod(fs, lfs_sb_getnseg(fs) - 2));
600 fs->lfs_curseg = lfs_sntod(fs, fs->lfs_nseg - 1); 605 lfs_sb_setcurseg(fs, lfs_sntod(fs, lfs_sb_getnseg(fs) - 1));
601 fs->lfs_offset = lfs_sntod(fs, fs->lfs_nseg); 606 lfs_sb_setoffset(fs, lfs_sntod(fs, lfs_sb_getnseg(fs)));
602 fs->lfs_nextseg = lfs_sntod(fs, 0); 607 lfs_sb_setnextseg(fs, lfs_sntod(fs, 0));
603 608
604 /* 609 /*
605 * Initialize the Ifile inode. Do this before we do anything 610 * Initialize the Ifile inode. Do this before we do anything
606 * with the Ifile or segment tables. 611 * with the Ifile or segment tables.
607 */ 612 */
608 dip = VTOI(fs->lfs_ivnode)->i_din.ffs1_din = (struct ulfs1_dinode *) 613 dip = VTOI(fs->lfs_ivnode)->i_din.ffs1_din = (struct ulfs1_dinode *)
609 malloc(sizeof(*dip)); 614 malloc(sizeof(*dip));
610 if (dip == NULL) 615 if (dip == NULL)
611 err(1, NULL); 616 err(1, NULL);
612 memset(dip, 0, sizeof(*dip)); 617 memset(dip, 0, sizeof(*dip));
613 dip->di_mode = LFS_IFREG | 0600; 618 dip->di_mode = LFS_IFREG | 0600;
614 dip->di_flags = SF_IMMUTABLE; 619 dip->di_flags = SF_IMMUTABLE;
615 make_dinode(LFS_IFILE_INUM, dip, 620 make_dinode(LFS_IFILE_INUM, dip,
616 lfs_blkstofrags(fs, fs->lfs_cleansz + fs->lfs_segtabsz + 1), fs); 621 lfs_blkstofrags(fs, lfs_sb_getcleansz(fs) + lfs_sb_getsegtabsz(fs) + 1), fs);
617 dip->di_size = (fs->lfs_cleansz + fs->lfs_segtabsz + 1) << fs->lfs_bshift; 622 dip->di_size = (lfs_sb_getcleansz(fs) + lfs_sb_getsegtabsz(fs) + 1) << fs->lfs_bshift;
618 for (i = 0; i < ULFS_NDADDR && i < (dip->di_size >> fs->lfs_bshift); i++) 623 for (i = 0; i < ULFS_NDADDR && i < (dip->di_size >> fs->lfs_bshift); i++)
619 VTOI(fs->lfs_ivnode)->i_lfs_fragsize[i] = fs->lfs_bsize; 624 VTOI(fs->lfs_ivnode)->i_lfs_fragsize[i] = lfs_sb_getbsize(fs);
620 625
621 /* 626 /*
622 * Set up in-superblock segment usage cache 627 * Set up in-superblock segment usage cache
623 */ 628 */
624 fs->lfs_suflags = (u_int32_t **) malloc(2 * sizeof(u_int32_t *));  629 fs->lfs_suflags = (u_int32_t **) malloc(2 * sizeof(u_int32_t *));
625 if (fs->lfs_suflags == NULL) 630 if (fs->lfs_suflags == NULL)
626 err(1, NULL); 631 err(1, NULL);
627 fs->lfs_suflags[0] = (u_int32_t *) malloc(fs->lfs_nseg * sizeof(u_int32_t)); 632 fs->lfs_suflags[0] = (u_int32_t *) malloc(fs->lfs_nseg * sizeof(u_int32_t));
628 if (fs->lfs_suflags[0] == NULL) 633 if (fs->lfs_suflags[0] == NULL)
629 err(1, NULL); 634 err(1, NULL);
630 fs->lfs_suflags[1] = (u_int32_t *) malloc(fs->lfs_nseg * sizeof(u_int32_t)); 635 fs->lfs_suflags[1] = (u_int32_t *) malloc(fs->lfs_nseg * sizeof(u_int32_t));
631 if (fs->lfs_suflags[1] == NULL) 636 if (fs->lfs_suflags[1] == NULL)
632 err(1, NULL); 637 err(1, NULL);
633 638
634 /* 639 /*
635 * Initialize the cleanerinfo block 640 * Initialize the cleanerinfo block
636 */ 641 */
637 LFS_CLEANERINFO(cip, fs, bp); 642 LFS_CLEANERINFO(cip, fs, bp);
638 cip->clean = fs->lfs_nseg; 643 cip->clean = fs->lfs_nseg;
639 cip->dirty = 0; 644 cip->dirty = 0;
640 if (version > 1) { 645 if (version > 1) {
641 cip->free_head = HIGHEST_USED_INO + 1; 646 cip->free_head = HIGHEST_USED_INO + 1;
642 cip->free_tail = fs->lfs_ifpb - 1; 647 cip->free_tail = lfs_sb_getifpb(fs) - 1;
643 } 648 }
644 LFS_SYNC_CLEANERINFO(cip, fs, bp, 1); 649 LFS_SYNC_CLEANERINFO(cip, fs, bp, 1);
645 650
646 /* 651 /*
647 * Run through segment table and initialize that 652 * Run through segment table and initialize that
648 */ 653 */
649 for (i = j = 0; i < fs->lfs_nseg; i++) { 654 for (i = j = 0; i < fs->lfs_nseg; i++) {
650 LFS_SEGENTRY(segp, fs, i, bp); 655 LFS_SEGENTRY(segp, fs, i, bp);
651 656
652 if (i == 0 && 657 if (i == 0 &&
653 fs->lfs_s0addr < lfs_btofsb(fs, LFS_LABELPAD + LFS_SBPAD)) { 658 fs->lfs_s0addr < lfs_btofsb(fs, LFS_LABELPAD + LFS_SBPAD)) {
654 segp->su_flags = SEGUSE_SUPERBLOCK; 659 segp->su_flags = SEGUSE_SUPERBLOCK;
655 fs->lfs_bfree -= sb_fsb; 660 lfs_sb_subbfree(fs, sb_fsb);
656 ++j; 661 ++j;
657 } 662 }
658 if (i > 0) {  663 if (i > 0) {
659 if ((i % sb_interval) == 0 && j < LFS_MAXNUMSB) { 664 if ((i % sb_interval) == 0 && j < LFS_MAXNUMSB) {
660 segp->su_flags = SEGUSE_SUPERBLOCK; 665 segp->su_flags = SEGUSE_SUPERBLOCK;
661 fs->lfs_bfree -= sb_fsb; 666 lfs_sb_subbfree(fs, sb_fsb);
662 ++j; 667 ++j;
663 } else 668 } else
664 segp->su_flags = 0; 669 segp->su_flags = 0;
665 } 670 }
666 segp->su_lastmod = 0; 671 segp->su_lastmod = 0;
667 segp->su_nbytes = 0; 672 segp->su_nbytes = 0;
668 segp->su_ninos = 0; 673 segp->su_ninos = 0;
669 segp->su_nsums = 0; 674 segp->su_nsums = 0;
670  675
671 LFS_WRITESEGENTRY(segp, fs, i, bp); 676 LFS_WRITESEGENTRY(segp, fs, i, bp);
672 } 677 }
673 678
674 /* Initialize root directory */ 679 /* Initialize root directory */
675 vp = lfs_raw_vget(fs, ULFS_ROOTINO, devfd, 0x0); 680 vp = lfs_raw_vget(fs, ULFS_ROOTINO, devfd, 0x0);
676 dip = VTOI(vp)->i_din.ffs1_din; 681 dip = VTOI(vp)->i_din.ffs1_din;
677 make_dinode(ULFS_ROOTINO, dip, howmany(LFS_DIRBLKSIZ,fs->lfs_fsize), fs); 682 make_dinode(ULFS_ROOTINO, dip, howmany(LFS_DIRBLKSIZ, lfs_sb_getfsize(fs)), fs);
678 dip->di_mode = LFS_IFDIR | UMASK; 683 dip->di_mode = LFS_IFDIR | UMASK;
679 VTOI(vp)->i_lfs_osize = dip->di_size = LFS_DIRBLKSIZ; 684 VTOI(vp)->i_lfs_osize = dip->di_size = LFS_DIRBLKSIZ;
680#ifdef MAKE_LF_DIR 685#ifdef MAKE_LF_DIR
681 VTOI(vp)->i_nlink = dip->di_nlink = 3; 686 VTOI(vp)->i_nlink = dip->di_nlink = 3;
682#else 687#else
683 VTOI(vp)->i_nlink = dip->di_nlink = 2; 688 VTOI(vp)->i_nlink = dip->di_nlink = 2;
684#endif 689#endif
685 VTOI(vp)->i_lfs_effnblks = dip->di_blocks = 690 VTOI(vp)->i_lfs_effnblks = dip->di_blocks =
686 lfs_btofsb(fs, roundup(LFS_DIRBLKSIZ,fs->lfs_fsize)); 691 lfs_btofsb(fs, roundup(LFS_DIRBLKSIZ, lfs_sb_getfsize(fs)));
687 for (i = 0; i < ULFS_NDADDR && i < howmany(LFS_DIRBLKSIZ, fs->lfs_bsize); i++) 692 for (i = 0; i < ULFS_NDADDR && i < howmany(LFS_DIRBLKSIZ, lfs_sb_getbsize(fs)); i++)
688 VTOI(vp)->i_lfs_fragsize[i] = fs->lfs_bsize; 693 VTOI(vp)->i_lfs_fragsize[i] = lfs_sb_getbsize(fs);
689 if (LFS_DIRBLKSIZ < fs->lfs_bsize) 694 if (LFS_DIRBLKSIZ < lfs_sb_getbsize(fs))
690 VTOI(vp)->i_lfs_fragsize[i - 1] = 695 VTOI(vp)->i_lfs_fragsize[i - 1] =
691 roundup(LFS_DIRBLKSIZ,fs->lfs_fsize); 696 roundup(LFS_DIRBLKSIZ, lfs_sb_getfsize(fs));
692 bread(vp, 0, fs->lfs_fsize, 0, &bp); 697 bread(vp, 0, lfs_sb_getfsize(fs), 0, &bp);
693 make_dir(bp->b_data, lfs_root_dir,  698 make_dir(bp->b_data, lfs_root_dir,
694 sizeof(lfs_root_dir) / sizeof(struct lfs_direct)); 699 sizeof(lfs_root_dir) / sizeof(struct lfs_direct));
695 VOP_BWRITE(bp); 700 VOP_BWRITE(bp);
696 701
697#ifdef MAKE_LF_DIR 702#ifdef MAKE_LF_DIR
698 /* Initialize lost+found directory */ 703 /* Initialize lost+found directory */
699 vp = lfs_raw_vget(fs, LOSTFOUNDINO, devfd, 0x0); 704 vp = lfs_raw_vget(fs, LOSTFOUNDINO, devfd, 0x0);
700 dip = VTOI(vp)->i_din.ffs1_din; 705 dip = VTOI(vp)->i_din.ffs1_din;
701 make_dinode(LOSTFOUNDINO, dip, howmany(DIRBLKSIZ,fs->lfs_fsize), fs); 706 make_dinode(LOSTFOUNDINO, dip, howmany(DIRBLKSIZ,fs->lfs_fsize), fs);
702 dip->di_mode = IFDIR | UMASK; 707 dip->di_mode = IFDIR | UMASK;
703 VTOI(vp)->i_lfs_osize = dip->di_size = DIRBLKSIZ; 708 VTOI(vp)->i_lfs_osize = dip->di_size = DIRBLKSIZ;
704 VTOI(vp)->i_nlink = dip->di_nlink = 2; 709 VTOI(vp)->i_nlink = dip->di_nlink = 2;
705 VTOI(vp)->i_lfs_effnblks = dip->di_blocks = 710 VTOI(vp)->i_lfs_effnblks = dip->di_blocks =
706 lfs_btofsb(fs, roundup(DIRBLKSIZ,fs->lfs_fsize)); 711 lfs_btofsb(fs, roundup(DIRBLKSIZ,fs->lfs_fsize));
707 for (i = 0; i < ULFS_NDADDR && i < howmany(DIRBLKSIZ, fs->lfs_bsize); i++) 712 for (i = 0; i < ULFS_NDADDR && i < howmany(DIRBLKSIZ, lfs_sb_getbsize(fs)); i++)
708 VTOI(vp)->i_lfs_fragsize[i] = fs->lfs_bsize; 713 VTOI(vp)->i_lfs_fragsize[i] = lfs_sb_getbsize(fs);
709 if (DIRBLKSIZ < fs->lfs_bsize) 714 if (DIRBLKSIZ < lfs_sb_getbsize(fs))
710 VTOI(vp)->i_lfs_fragsize[i - 1] = 715 VTOI(vp)->i_lfs_fragsize[i - 1] =
711 roundup(DIRBLKSIZ,fs->lfs_fsize); 716 roundup(DIRBLKSIZ,fs->lfs_fsize);
712 bread(vp, 0, fs->lfs_fsize, 0, &bp); 717 bread(vp, 0, fs->lfs_fsize, 0, &bp);
713 make_dir(bp->b_data, lfs_lf_dir,  718 make_dir(bp->b_data, lfs_lf_dir,
714 sizeof(lfs_lf_dir) / sizeof(struct lfs_direct)); 719 sizeof(lfs_lf_dir) / sizeof(struct lfs_direct));
715 VOP_BWRITE(bp); 720 VOP_BWRITE(bp);
716#endif /* MAKE_LF_DIR */ 721#endif /* MAKE_LF_DIR */
717 722
718 /* Set their IFILE entry version numbers to 1 */ 723 /* Set their IFILE entry version numbers to 1 */
719 LFS_IENTRY(ip, fs, 1, bp); 724 LFS_IENTRY(ip, fs, 1, bp);
720 if (version == 1) { 725 if (version == 1) {
721 ip_v1 = (IFILE_V1 *)ip; 726 ip_v1 = (IFILE_V1 *)ip;
722 for (i = LFS_IFILE_INUM; i <= HIGHEST_USED_INO; i++) { 727 for (i = LFS_IFILE_INUM; i <= HIGHEST_USED_INO; i++) {
@@ -726,93 +731,93 @@ make_lfs(int devfd, uint secsize, struct @@ -726,93 +731,93 @@ make_lfs(int devfd, uint secsize, struct
726 ++ip_v1; 731 ++ip_v1;
727 } 732 }
728 } else { 733 } else {
729 for (i = LFS_IFILE_INUM; i <= HIGHEST_USED_INO; i++) { 734 for (i = LFS_IFILE_INUM; i <= HIGHEST_USED_INO; i++) {
730 ip->if_version = 1; 735 ip->if_version = 1;
731 ip->if_daddr = 0x0; 736 ip->if_daddr = 0x0;
732 ip->if_nextfree = 0; 737 ip->if_nextfree = 0;
733 ++ip; 738 ++ip;
734 } 739 }
735 } 740 }
736 /* Link remaining IFILE entries in free list */ 741 /* Link remaining IFILE entries in free list */
737 if (version == 1) { 742 if (version == 1) {
738 for (; 743 for (;
739 i < fs->lfs_ifpb; ++ip_v1) { 744 i < lfs_sb_getifpb(fs); ++ip_v1) {
740 ip_v1->if_version = 1; 745 ip_v1->if_version = 1;
741 ip_v1->if_daddr = LFS_UNUSED_DADDR; 746 ip_v1->if_daddr = LFS_UNUSED_DADDR;
742 ip_v1->if_nextfree = ++i; 747 ip_v1->if_nextfree = ++i;
743 } 748 }
744 --ip_v1; 749 --ip_v1;
745 ip_v1->if_nextfree = LFS_UNUSED_INUM; 750 ip_v1->if_nextfree = LFS_UNUSED_INUM;
746 } else { 751 } else {
747 for (; 752 for (;
748 i < fs->lfs_ifpb; ++ip) { 753 i < lfs_sb_getifpb(fs); ++ip) {
749 ip->if_version = 1; 754 ip->if_version = 1;
750 ip->if_daddr = LFS_UNUSED_DADDR; 755 ip->if_daddr = LFS_UNUSED_DADDR;
751 ip->if_nextfree = ++i; 756 ip->if_nextfree = ++i;
752 } 757 }
753 --ip; 758 --ip;
754 ip->if_nextfree = LFS_UNUSED_INUM; 759 ip->if_nextfree = LFS_UNUSED_INUM;
755 } 760 }
756 VOP_BWRITE(bp); 761 VOP_BWRITE(bp);
757 762
758 /* Write it all to disk. */ 763 /* Write it all to disk. */
759 if (!Nflag) 764 if (!Nflag)
760 lfs_segwrite(fs, SEGM_CKP); 765 lfs_segwrite(fs, SEGM_CKP);
761 766
762 /* 767 /*
763 * Now that we've written everything, look to see what's available 768 * Now that we've written everything, look to see what's available
764 * for writing. 769 * for writing.
765 */ 770 */
766 fs->lfs_avail = 0; 771 lfs_sb_setavail(fs, 0);
767 bb = ubb = dmeta = 0; 772 bb = ubb = dmeta = 0;
768 for (i = 0; i < fs->lfs_nseg; i++) { 773 for (i = 0; i < fs->lfs_nseg; i++) {
769 LFS_SEGENTRY(segp, fs, i, bp); 774 LFS_SEGENTRY(segp, fs, i, bp);
770 if (segp->su_flags & SEGUSE_DIRTY) { 775 if (segp->su_flags & SEGUSE_DIRTY) {
771 bb += lfs_btofsb(fs, segp->su_nbytes + 776 bb += lfs_btofsb(fs, segp->su_nbytes +
772 segp->su_nsums * fs->lfs_sumsize); 777 segp->su_nsums * fs->lfs_sumsize);
773 ubb += lfs_btofsb(fs, segp->su_nbytes + 778 ubb += lfs_btofsb(fs, segp->su_nbytes +
774 segp->su_nsums * fs->lfs_sumsize + 779 segp->su_nsums * fs->lfs_sumsize +
775 segp->su_ninos * fs->lfs_ibsize); 780 segp->su_ninos * fs->lfs_ibsize);
776 dmeta += lfs_btofsb(fs, 781 dmeta += lfs_btofsb(fs,
777 fs->lfs_sumsize * segp->su_nsums); 782 fs->lfs_sumsize * segp->su_nsums);
778 dmeta += lfs_btofsb(fs, 783 dmeta += lfs_btofsb(fs,
779 fs->lfs_ibsize * segp->su_ninos); 784 fs->lfs_ibsize * segp->su_ninos);
780 } else { 785 } else {
781 fs->lfs_avail += lfs_segtod(fs, 1); 786 lfs_sb_addavail(fs, lfs_segtod(fs, 1));
782 if (segp->su_flags & SEGUSE_SUPERBLOCK) 787 if (segp->su_flags & SEGUSE_SUPERBLOCK)
783 fs->lfs_avail -= lfs_btofsb(fs, LFS_SBPAD); 788 lfs_sb_subavail(fs, lfs_btofsb(fs, LFS_SBPAD));
784 if (i == 0 && fs->lfs_version > 1 && 789 if (i == 0 && fs->lfs_version > 1 &&
785 fs->lfs_s0addr < lfs_btofsb(fs, LFS_LABELPAD)) 790 fs->lfs_s0addr < lfs_btofsb(fs, LFS_LABELPAD))
786 fs->lfs_avail -= lfs_btofsb(fs, LFS_LABELPAD) - 791 lfs_sb_subavail(fs, lfs_btofsb(fs, LFS_LABELPAD) -
787 fs->lfs_s0addr; 792 fs->lfs_s0addr);
788 } 793 }
789 brelse(bp, 0); 794 brelse(bp, 0);
790 } 795 }
791 /* Also may be available bytes in current seg */ 796 /* Also may be available bytes in current seg */
792 i = lfs_dtosn(fs, fs->lfs_offset); 797 i = lfs_dtosn(fs, lfs_sb_getoffset(fs));
793 fs->lfs_avail += lfs_sntod(fs, i + 1) - fs->lfs_offset; 798 lfs_sb_addavail(fs, lfs_sntod(fs, i + 1) - lfs_sb_getoffset(fs));
794 /* But do not count minfreesegs */ 799 /* But do not count minfreesegs */
795 fs->lfs_avail -= lfs_segtod(fs, (fs->lfs_minfreeseg - (fs->lfs_minfreeseg / 2))); 800 lfs_sb_subavail(fs, lfs_segtod(fs, (fs->lfs_minfreeseg - (fs->lfs_minfreeseg / 2))));
796 801
797 labelskew = 0; 802 labelskew = 0;
798 if (fs->lfs_version > 1 && fs->lfs_s0addr < lfs_btofsb(fs, LFS_LABELPAD)) 803 if (fs->lfs_version > 1 && fs->lfs_s0addr < lfs_btofsb(fs, LFS_LABELPAD))
799 labelskew = lfs_btofsb(fs, LFS_LABELPAD); 804 labelskew = lfs_btofsb(fs, LFS_LABELPAD);
800 fs->lfs_bfree = fs->lfs_dsize - labelskew - (ubb + bb) / 2; 805 lfs_sb_setbfree(fs, lfs_sb_getdsize(fs) - labelskew - (ubb + bb) / 2);
801 806
802 /* Put that in the Ifile version too, and write it */ 807 /* Put that in the Ifile version too, and write it */
803 LFS_CLEANERINFO(cip, fs, bp); 808 LFS_CLEANERINFO(cip, fs, bp);
804 cip->bfree = fs->lfs_bfree; 809 cip->bfree = lfs_sb_getbfree(fs);
805 cip->avail = fs->lfs_avail; 810 cip->avail = lfs_sb_getavail(fs);
806 LFS_SYNC_CLEANERINFO(cip, fs, bp, 1); 811 LFS_SYNC_CLEANERINFO(cip, fs, bp, 1);
807 if (!Nflag) 812 if (!Nflag)
808 lfs_segwrite(fs, SEGM_CKP); 813 lfs_segwrite(fs, SEGM_CKP);
809 814
810 /* 815 /*
811 * Finally write out superblocks. 816 * Finally write out superblocks.
812 */ 817 */
813 printf("super-block backups (for fsck -b #) at:\n"); 818 printf("super-block backups (for fsck -b #) at:\n");
814 curw = 0; 819 curw = 0;
815 for (i = 0; i < LFS_MAXNUMSB; i++) { 820 for (i = 0; i < LFS_MAXNUMSB; i++) {
816 seg_addr = fs->lfs_sboffs[i]; 821 seg_addr = fs->lfs_sboffs[i];
817 if (seg_addr == 0) 822 if (seg_addr == 0)
818 break; 823 break;
@@ -821,27 +826,27 @@ make_lfs(int devfd, uint secsize, struct @@ -821,27 +826,27 @@ make_lfs(int devfd, uint secsize, struct
821 curw += printf(", "); 826 curw += printf(", ");
822 ww = snprintf(tbuf, sizeof(tbuf), "%lld", 827 ww = snprintf(tbuf, sizeof(tbuf), "%lld",
823 (long long)LFS_FSBTODB(fs, seg_addr)); 828 (long long)LFS_FSBTODB(fs, seg_addr));
824 curw += ww; 829 curw += ww;
825 if (curw >= 78) { 830 if (curw >= 78) {
826 printf("\n%s", tbuf); 831 printf("\n%s", tbuf);
827 curw = ww; 832 curw = ww;
828 } else 833 } else
829 printf("%s", tbuf); 834 printf("%s", tbuf);
830 fflush(stdout); 835 fflush(stdout);
831 836
832 /* Leave the time stamp on the alt sb, zero the rest */ 837 /* Leave the time stamp on the alt sb, zero the rest */
833 if (i == 2) { 838 if (i == 2) {
834 fs->lfs_tstamp = 0; 839 lfs_sb_settstamp(fs, 0);
835 fs->lfs_cksum = lfs_sb_cksum(&(fs->lfs_dlfs)); 840 fs->lfs_cksum = lfs_sb_cksum(&(fs->lfs_dlfs));
836 } 841 }
837 if (!Nflag) 842 if (!Nflag)
838 lfs_writesuper(fs, seg_addr); 843 lfs_writesuper(fs, seg_addr);
839 } 844 }
840 printf(".\n"); 845 printf(".\n");
841 846
842 return 0; 847 return 0;
843} 848}
844 849
845/* 850/*
846 * Compatibility with fsck_lfs, since the "generic" LFS userland code uses it. 851 * Compatibility with fsck_lfs, since the "generic" LFS userland code uses it.
847 */ 852 */

cvs diff -r1.9 -r1.10 src/sbin/resize_lfs/resize_lfs.c (expand / switch to unified diff)

--- src/sbin/resize_lfs/resize_lfs.c 2014/03/23 05:38:14 1.9
+++ src/sbin/resize_lfs/resize_lfs.c 2015/07/24 06:56:41 1.10
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: resize_lfs.c,v 1.9 2014/03/23 05:38:14 dholland Exp $ */ 1/* $NetBSD: resize_lfs.c,v 1.10 2015/07/24 06:56:41 dholland Exp $ */
2/*- 2/*-
3 * Copyright (c) 2005 The NetBSD Foundation, Inc. 3 * Copyright (c) 2005 The NetBSD Foundation, Inc.
4 * All rights reserved. 4 * All rights reserved.
5 * 5 *
6 * This code is derived from software contributed to The NetBSD Foundation 6 * This code is derived from software contributed to The NetBSD Foundation
7 * by Konrad E. Schroder <perseant@hhhh.org>. 7 * by Konrad E. Schroder <perseant@hhhh.org>.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -124,27 +124,27 @@ main(int argc, char **argv) @@ -124,27 +124,27 @@ main(int argc, char **argv)
124 /* Read the superblock, finding alternates if necessary */ 124 /* Read the superblock, finding alternates if necessary */
125 fs = (struct lfs *)malloc(sizeof(*fs)); 125 fs = (struct lfs *)malloc(sizeof(*fs));
126 for (sboff = LFS_LABELPAD;;) { 126 for (sboff = LFS_LABELPAD;;) {
127 pread(devfd, buf, sboff, LFS_SBPAD); 127 pread(devfd, buf, sboff, LFS_SBPAD);
128 memcpy(&fs->lfs_dlfs, buf, sizeof(struct dlfs)); 128 memcpy(&fs->lfs_dlfs, buf, sizeof(struct dlfs));
129 if (sboff == LFS_LABELPAD && lfs_fsbtob(fs, 1) > LFS_LABELPAD) 129 if (sboff == LFS_LABELPAD && lfs_fsbtob(fs, 1) > LFS_LABELPAD)
130 sboff = lfs_fsbtob(fs, (off_t)fs->lfs_sboffs[0]); 130 sboff = lfs_fsbtob(fs, (off_t)fs->lfs_sboffs[0]);
131 else 131 else
132 break; 132 break;
133 } 133 }
134 close(devfd); 134 close(devfd);
135 135
136 /* Calculate new number of segments. */ 136 /* Calculate new number of segments. */
137 newnsegs = (newsize * secsize) / fs->lfs_ssize; 137 newnsegs = (newsize * secsize) / lfs_sb_getssize(fs);
138 if (newnsegs == fs->lfs_nseg) { 138 if (newnsegs == fs->lfs_nseg) {
139 errx(0, "the filesystem is unchanged."); 139 errx(0, "the filesystem is unchanged.");
140 } 140 }
141 141
142 /* 142 /*
143 * If the new filesystem is smaller than the old, we have to 143 * If the new filesystem is smaller than the old, we have to
144 * invalidate the segments that extend beyond the new boundary. 144 * invalidate the segments that extend beyond the new boundary.
145 * Make the cleaner do this for us. 145 * Make the cleaner do this for us.
146 * (XXX make the kernel able to do this instead?) 146 * (XXX make the kernel able to do this instead?)
147 */ 147 */
148 for (i = fs->lfs_nseg - 1; i >= newnsegs; --i) { 148 for (i = fs->lfs_nseg - 1; i >= newnsegs; --i) {
149 char cmd[128]; 149 char cmd[128];
150 150

cvs diff -r1.25 -r1.26 src/sbin/scan_ffs/scan_ffs.c (expand / switch to unified diff)

--- src/sbin/scan_ffs/scan_ffs.c 2013/06/23 22:03:34 1.25
+++ src/sbin/scan_ffs/scan_ffs.c 2015/07/24 06:56:42 1.26
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: scan_ffs.c,v 1.25 2013/06/23 22:03:34 dholland Exp $ */ 1/* $NetBSD: scan_ffs.c,v 1.26 2015/07/24 06:56:42 dholland Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2005-2007 Juan Romero Pardines 4 * Copyright (c) 2005-2007 Juan Romero Pardines
5 * Copyright (c) 1998 Niklas Hallqvist, Tobias Weingartner 5 * Copyright (c) 1998 Niklas Hallqvist, Tobias Weingartner
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -23,27 +23,27 @@ @@ -23,27 +23,27 @@
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29/* 29/*
30 * Currently it can detect FFS and LFS partitions (version 1 or 2) 30 * Currently it can detect FFS and LFS partitions (version 1 or 2)
31 * up to 8192/65536 fragsize/blocksize. 31 * up to 8192/65536 fragsize/blocksize.
32 */ 32 */
33  33
34#include <sys/cdefs.h> 34#include <sys/cdefs.h>
35#ifndef lint 35#ifndef lint
36__RCSID("$NetBSD: scan_ffs.c,v 1.25 2013/06/23 22:03:34 dholland Exp $"); 36__RCSID("$NetBSD: scan_ffs.c,v 1.26 2015/07/24 06:56:42 dholland Exp $");
37#endif /* not lint */ 37#endif /* not lint */
38 38
39#include <sys/types.h> 39#include <sys/types.h>
40#include <sys/param.h> 40#include <sys/param.h>
41#include <sys/disklabel.h> 41#include <sys/disklabel.h>
42#include <sys/dkio.h> 42#include <sys/dkio.h>
43#include <sys/ioctl.h> 43#include <sys/ioctl.h>
44#include <sys/fcntl.h> 44#include <sys/fcntl.h>
45#include <sys/mount.h> 45#include <sys/mount.h>
46 46
47#include <ufs/lfs/lfs.h> 47#include <ufs/lfs/lfs.h>
48#include <ufs/lfs/lfs_extern.h> 48#include <ufs/lfs/lfs_extern.h>
49 49
@@ -239,53 +239,54 @@ ffs_scan(struct sblockinfo *sbi, int n) @@ -239,53 +239,54 @@ ffs_scan(struct sblockinfo *sbi, int n)
239 ffs_printpart(sbi, LABELS, i, n); 239 ffs_printpart(sbi, LABELS, i, n);
240 else 240 else
241 ffs_printpart(sbi, NADA, i, n); 241 ffs_printpart(sbi, NADA, i, n);
242 } 242 }
243 break; 243 break;
244 } 244 }
245} 245}
246 246
247static void 247static void
248lfs_printpart(struct sblockinfo *sbi, int flag, int n) 248lfs_printpart(struct sblockinfo *sbi, int flag, int n)
249{ 249{
250 if (flags & VERBOSE) 250 if (flags & VERBOSE)
251 (void)printf("offset: %" PRIu64 " size %" PRIu32 251 (void)printf("offset: %" PRIu64 " size %" PRIu32
252 " fsid %" PRIx32 "\n", sbi->lfs_off, sbi->lfs->lfs_size, 252 " fsid %" PRIx32 "\n", sbi->lfs_off,
 253 lfs_sb_getsize(sbi->lfs),
253 sbi->lfs->lfs_ident); 254 sbi->lfs->lfs_ident);
254 switch (flag) { 255 switch (flag) {
255 case LABELS: 256 case LABELS:
256 (void)printf("X: %9" PRIu64, 257 (void)printf("X: %9" PRIu64,
257 (uint64_t)(sbi->lfs->lfs_size * 258 (uint64_t)(lfs_sb_getsize(sbi->lfs) *
258 sbi->lfs->lfs_fsize / 512)); 259 lfs_sb_getfsize(sbi->lfs) / 512));
259 (void)printf(" %9" PRIu64, sbi->lfs_off);  260 (void)printf(" %9" PRIu64, sbi->lfs_off);
260 (void)printf(" 4.4LFS %6d %5d %7d # %s [LFSv%d]\n", 261 (void)printf(" 4.4LFS %6d %5d %7d # %s [LFSv%d]\n",
261 sbi->lfs->lfs_fsize, sbi->lfs->lfs_bsize, 262 lfs_sb_getfsize(sbi->lfs), lfs_sb_getbsize(sbi->lfs),
262 sbi->lfs->lfs_nseg, sbi->lfs_path,  263 lfs_sb_getnseg(sbi->lfs), sbi->lfs_path,
263 sbi->lfs->lfs_version); 264 sbi->lfs->lfs_version);
264 break; 265 break;
265 case BLOCKS: 266 case BLOCKS:
266 (void)printf("LFSv%d", sbi->lfs->lfs_version); 267 (void)printf("LFSv%d", sbi->lfs->lfs_version);
267 (void)printf(" sb at %" PRIu64, sbi->lfs_off + btodb(LFS_LABELPAD)); 268 (void)printf(" sb at %" PRIu64, sbi->lfs_off + btodb(LFS_LABELPAD));
268 (void)printf(" fsid %" PRIx32, sbi->lfs->lfs_ident); 269 (void)printf(" fsid %" PRIx32, sbi->lfs->lfs_ident);
269 (void)printf(" size %" PRIu64 ", last mounted on %s\n", 270 (void)printf(" size %" PRIu64 ", last mounted on %s\n",
270 (uint64_t)(sbi->lfs->lfs_size * 271 (uint64_t)(lfs_sb_getsize(sbi->lfs) *
271 sbi->lfs->lfs_fsize / 512), sbi->lfs_path); 272 lfs_sb_getfsize(sbi->lfs) / 512), sbi->lfs_path);
272 break; 273 break;
273 default: 274 default:
274 (void)printf("LFSv%d ", sbi->lfs->lfs_version); 275 (void)printf("LFSv%d ", sbi->lfs->lfs_version);
275 (void)printf("at %" PRIu64, sbi->lfs_off); 276 (void)printf("at %" PRIu64, sbi->lfs_off);
276 (void)printf(" size %" PRIu64 ", last mounted on %s\n", 277 (void)printf(" size %" PRIu64 ", last mounted on %s\n",
277 (uint64_t)(sbi->lfs->lfs_size * 278 (uint64_t)(lfs_sb_getsize(sbi->lfs) *
278 sbi->lfs->lfs_fsize / 512), sbi->lfs_path); 279 lfs_sb_getfsize(sbi->lfs) / 512), sbi->lfs_path);
279 break; 280 break;
280 } 281 }
281} 282}
282 283
283static void 284static void
284lfs_scan(struct sblockinfo *sbi, int n) 285lfs_scan(struct sblockinfo *sbi, int n)
285{ 286{
286 /* Check to see if the sb checksums correctly */ 287 /* Check to see if the sb checksums correctly */
287 if (lfs_sb_cksum(&(sbi->lfs->lfs_dlfs)) != sbi->lfs->lfs_cksum) { 288 if (lfs_sb_cksum(&(sbi->lfs->lfs_dlfs)) != sbi->lfs->lfs_cksum) {
288 if (flags & VERBOSE) 289 if (flags & VERBOSE)
289 printf("LFS bad superblock at %" PRIu64 "\n", 290 printf("LFS bad superblock at %" PRIu64 "\n",
290 BLK_CNT); 291 BLK_CNT);
291 return; 292 return;

cvs diff -r1.10 -r1.11 src/sys/lib/libsa/lfsv1.c (expand / switch to unified diff)

--- src/sys/lib/libsa/lfsv1.c 2015/07/24 06:53:24 1.10
+++ src/sys/lib/libsa/lfsv1.c 2015/07/24 06:56:42 1.11
@@ -1,31 +1,31 @@ @@ -1,31 +1,31 @@
1/* $NetBSD: lfsv1.c,v 1.10 2015/07/24 06:53:24 dholland Exp $ */ 1/* $NetBSD: lfsv1.c,v 1.11 2015/07/24 06:56:42 dholland Exp $ */
2 2
3#define LIBSA_LFS 3#define LIBSA_LFS
4#define REQUIRED_LFS_VERSION 1 4#define REQUIRED_LFS_VERSION 1
5 5
6#define ufs_open lfsv1_open 6#define ufs_open lfsv1_open
7#define ufs_close lfsv1_close 7#define ufs_close lfsv1_close
8#define ufs_read lfsv1_read 8#define ufs_read lfsv1_read
9#define ufs_write lfsv1_write 9#define ufs_write lfsv1_write
10#define ufs_seek lfsv1_seek 10#define ufs_seek lfsv1_seek
11#define ufs_stat lfsv1_stat 11#define ufs_stat lfsv1_stat
12#if defined(LIBSA_ENABLE_LS_OP) 12#if defined(LIBSA_ENABLE_LS_OP)
13#define ufs_ls lfsv1_ls 13#define ufs_ls lfsv1_ls
14#endif 14#endif
15 15
16#define ufs_dinode ulfs1_dinode 16#define ufs_dinode ulfs1_dinode
17 17
18#define fs_bsize dlfs_ibsize 18#define fs_bsize lfs_dlfs.dlfs_ibsize
19#define IFILE_Vx IFILE_V1 19#define IFILE_Vx IFILE_V1
20 20
21#define INOPBx(fs) LFS_INOPB(fs) 21#define INOPBx(fs) LFS_INOPB(fs)
22 22
23#define UFS_NINDIR(fs) ((fs)->dlfs_nindir) 23#define UFS_NINDIR LFS_NINDIR
24#define ufs_blkoff(a, b) lfs_blkoff((a), (b)) 24#define ufs_blkoff(a, b) lfs_blkoff((a), (b))
25#define ufs_lblkno(a, b) lfs_lblkno((a), (b)) 25#define ufs_lblkno(a, b) lfs_lblkno((a), (b))
26#define dblksize(a, b, c) lfs_dblksize((a), (b), (c)) 26#define dblksize(a, b, c) lfs_dblksize((a), (b), (c))
27#define FSBTODB(fs, daddr) (daddr) /* LFSv1 uses sectors for addresses */ 27#define FSBTODB(fs, daddr) (daddr) /* LFSv1 uses sectors for addresses */
28 28
29#define FSMOD "lfs" 29#define FSMOD "lfs"
30 30
31#include "lib/libsa/ufs.c" 31#include "lib/libsa/ufs.c"

cvs diff -r1.10 -r1.11 src/sys/lib/libsa/lfsv2.c (expand / switch to unified diff)

--- src/sys/lib/libsa/lfsv2.c 2015/07/24 06:53:24 1.10
+++ src/sys/lib/libsa/lfsv2.c 2015/07/24 06:56:42 1.11
@@ -1,36 +1,36 @@ @@ -1,36 +1,36 @@
1/* $NetBSD: lfsv2.c,v 1.10 2015/07/24 06:53:24 dholland Exp $ */ 1/* $NetBSD: lfsv2.c,v 1.11 2015/07/24 06:56:42 dholland Exp $ */
2 2
3#define LIBSA_LFS 3#define LIBSA_LFS
4#define REQUIRED_LFS_VERSION 2 4#define REQUIRED_LFS_VERSION 2
5 5
6#define ufs_open lfsv2_open 6#define ufs_open lfsv2_open
7#define ufs_close lfsv2_close 7#define ufs_close lfsv2_close
8#define ufs_read lfsv2_read 8#define ufs_read lfsv2_read
9#define ufs_write lfsv2_write 9#define ufs_write lfsv2_write
10#define ufs_seek lfsv2_seek 10#define ufs_seek lfsv2_seek
11#define ufs_stat lfsv2_stat 11#define ufs_stat lfsv2_stat
12#if defined(LIBSA_ENABLE_LS_OP) 12#if defined(LIBSA_ENABLE_LS_OP)
13#define ufs_ls lfsv2_ls 13#define ufs_ls lfsv2_ls
14#endif 14#endif
15 15
16/* XXX wrong! but for now it won't build with ulfs2_dinode */ 16/* XXX wrong! but for now it won't build with ulfs2_dinode */
17#define ufs_dinode ulfs1_dinode 17#define ufs_dinode ulfs1_dinode
18 18
19#define fs_bsize dlfs_bsize 19#define fs_bsize lfs_dlfs.dlfs_bsize
20#define IFILE_Vx IFILE 20#define IFILE_Vx IFILE
21 21
22#ifdef LFS_IFILE_FRAG_ADDRESSING /* XXX see sys/ufs/lfs/ -- not tested */ 22#ifdef LFS_IFILE_FRAG_ADDRESSING /* XXX see sys/ufs/lfs/ -- not tested */
23#define INOPBx(fs) LFS_INOPF(fs) 23#define INOPBx(fs) LFS_INOPF(fs)
24#else 24#else
25#define INOPBx(fs) LFS_INOPB(fs) 25#define INOPBx(fs) LFS_INOPB(fs)
26#endif 26#endif
27 27
28#define UFS_NINDIR(fs) ((fs)->dlfs_nindir) 28#define UFS_NINDIR LFS_NINDIR
29#define ufs_blkoff(a, b) lfs_blkoff((a), (b)) 29#define ufs_blkoff(a, b) lfs_blkoff((a), (b))
30#define ufs_lblkno(a, b) lfs_lblkno((a), (b)) 30#define ufs_lblkno(a, b) lfs_lblkno((a), (b))
31#define dblksize(a, b, c) lfs_dblksize((a), (b), (c)) 31#define dblksize(a, b, c) lfs_dblksize((a), (b), (c))
32#define FSBTODB(a, b) LFS_FSBTODB((a), (b)) 32#define FSBTODB(a, b) LFS_FSBTODB((a), (b))
33 33
34#define FSMOD "lfs" 34#define FSMOD "lfs"
35 35
36#include "lib/libsa/ufs.c" 36#include "lib/libsa/ufs.c"

cvs diff -r1.66 -r1.67 src/sys/lib/libsa/ufs.c (expand / switch to unified diff)

--- src/sys/lib/libsa/ufs.c 2015/07/24 06:53:24 1.66
+++ src/sys/lib/libsa/ufs.c 2015/07/24 06:56:42 1.67
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ufs.c,v 1.66 2015/07/24 06:53:24 dholland Exp $ */ 1/* $NetBSD: ufs.c,v 1.67 2015/07/24 06:56:42 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1993 4 * Copyright (c) 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to Berkeley by 7 * This code is derived from software contributed to Berkeley by
8 * The Mach Operating System project at Carnegie-Mellon University. 8 * The Mach Operating System project at Carnegie-Mellon University.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -60,26 +60,27 @@ @@ -60,26 +60,27 @@
60 60
61/* 61/*
62 * Stand-alone file reading package for UFS and LFS filesystems. 62 * Stand-alone file reading package for UFS and LFS filesystems.
63 */ 63 */
64 64
65#include <sys/param.h> 65#include <sys/param.h>
66#include <sys/time.h> 66#include <sys/time.h>
67#include <ufs/ufs/dinode.h> 67#include <ufs/ufs/dinode.h>
68#include <ufs/ufs/dir.h> 68#include <ufs/ufs/dir.h>
69#ifdef LIBSA_LFS 69#ifdef LIBSA_LFS
70#include <sys/queue.h> 70#include <sys/queue.h>
71#include <sys/condvar.h> 71#include <sys/condvar.h>
72#include <sys/mount.h> /* XXX for MNAMELEN */ 72#include <sys/mount.h> /* XXX for MNAMELEN */
 73#define STRUCT_LFS struct salfs
73#include <ufs/lfs/lfs.h> 74#include <ufs/lfs/lfs.h>
74#else 75#else
75#include <ufs/ffs/fs.h> 76#include <ufs/ffs/fs.h>
76#endif 77#endif
77#ifdef _STANDALONE 78#ifdef _STANDALONE
78#include <lib/libkern/libkern.h> 79#include <lib/libkern/libkern.h>
79#else 80#else
80#include <string.h> 81#include <string.h>
81#endif 82#endif
82 83
83#include "stand.h" 84#include "stand.h"
84#ifdef LIBSA_LFS 85#ifdef LIBSA_LFS
85#include "lfs.h" 86#include "lfs.h"
@@ -92,54 +93,31 @@ @@ -92,54 +93,31 @@
92#define LIBSA_FFSv1 93#define LIBSA_FFSv1
93#endif 94#endif
94 95
95#if defined(LIBSA_FS_SINGLECOMPONENT) && !defined(LIBSA_NO_FS_SYMLINK) 96#if defined(LIBSA_FS_SINGLECOMPONENT) && !defined(LIBSA_NO_FS_SYMLINK)
96#define LIBSA_NO_FS_SYMLINK 97#define LIBSA_NO_FS_SYMLINK
97#endif 98#endif
98#if defined(COMPAT_UFS) && defined(LIBSA_NO_COMPAT_UFS) 99#if defined(COMPAT_UFS) && defined(LIBSA_NO_COMPAT_UFS)
99#undef COMPAT_UFS 100#undef COMPAT_UFS
100#endif 101#endif
101 102
102#ifdef LIBSA_LFS 103#ifdef LIBSA_LFS
103/* 104/*
104 * In-core LFS superblock - just the on-disk one. 105 * In-core LFS superblock - just the on-disk one.
 106 * XXX: struct salfs is currently in lfs.h
105 */ 107 */
106typedef struct dlfs FS; 108typedef struct salfs FS;
107#define fs_magic dlfs_magic 109#define fs_magic lfs_dlfs.dlfs_magic
108#define fs_maxsymlinklen dlfs_maxsymlinklen 110#define fs_maxsymlinklen lfs_dlfs.dlfs_maxsymlinklen
109 
110/* XXX these will go away in the near future */ 
111#undef lfs_bmask 
112#define lfs_bmask dlfs_bmask 
113#undef lfs_ifile 
114#define lfs_ifile dlfs_ifile 
115#undef lfs_ifpb 
116#define lfs_ifpb dlfs_ifpb 
117#undef lfs_cleansz 
118#define lfs_cleansz dlfs_cleansz 
119#undef lfs_segtabsz 
120#define lfs_segtabsz dlfs_segtabsz 
121#undef lfs_idaddr 
122#define lfs_idaddr dlfs_idaddr 
123#undef lfs_inopb 
124#define lfs_inopb dlfs_inopb 
125#undef lfs_bshift 
126#define lfs_bshift dlfs_bshift 
127#undef lfs_bsize 
128#define lfs_bsize dlfs_bsize 
129#undef lfs_ffmask 
130#define lfs_ffmask dlfs_ffmask 
131#undef lfs_fsbtodb 
132#define lfs_fsbtodb dlfs_fsbtodb 
133 111
134#define FS_MAGIC LFS_MAGIC 112#define FS_MAGIC LFS_MAGIC
135#define SBLOCKSIZE LFS_SBPAD 113#define SBLOCKSIZE LFS_SBPAD
136#define SBLOCKOFFSET LFS_LABELPAD 114#define SBLOCKOFFSET LFS_LABELPAD
137#else 115#else
138/* NB ufs2 doesn't use the common superblock code... */ 116/* NB ufs2 doesn't use the common superblock code... */
139typedef struct fs FS; 117typedef struct fs FS;
140#define FS_MAGIC FS_UFS1_MAGIC 118#define FS_MAGIC FS_UFS1_MAGIC
141#define SBLOCKOFFSET SBLOCK_UFS1 119#define SBLOCKOFFSET SBLOCK_UFS1
142#endif 120#endif
143 121
144#if defined(LIBSA_NO_TWIDDLE) 122#if defined(LIBSA_NO_TWIDDLE)
145#define twiddle() 123#define twiddle()
@@ -217,34 +195,34 @@ static int ffs_find_superblock(struct op @@ -217,34 +195,34 @@ static int ffs_find_superblock(struct op
217/* 195/*
218 * Find an inode's block. Look it up in the ifile. Whee! 196 * Find an inode's block. Look it up in the ifile. Whee!
219 */ 197 */
220static int 198static int
221find_inode_sector(ino32_t inumber, struct open_file *f, daddr_t *isp) 199find_inode_sector(ino32_t inumber, struct open_file *f, daddr_t *isp)
222{ 200{
223 struct file *fp = (struct file *)f->f_fsdata; 201 struct file *fp = (struct file *)f->f_fsdata;
224 FS *fs = fp->f_fs; 202 FS *fs = fp->f_fs;
225 daddr_t ifileent_blkno; 203 daddr_t ifileent_blkno;
226 char *ent_in_buf; 204 char *ent_in_buf;
227 size_t buf_after_ent; 205 size_t buf_after_ent;
228 int rc; 206 int rc;
229 207
230 rc = read_inode(fs->lfs_ifile, f); 208 rc = read_inode(lfs_sb_getifile(fs), f);
231 if (rc) 209 if (rc)
232 return rc; 210 return rc;
233 211
234 ifileent_blkno = 212 ifileent_blkno =
235 (inumber / fs->lfs_ifpb) + fs->lfs_cleansz + fs->lfs_segtabsz; 213 (inumber / lfs_sb_getifpb(fs)) + lfs_sb_getcleansz(fs) + lfs_sb_getsegtabsz(fs);
236 fp->f_seekp = (off_t)ifileent_blkno * fs->fs_bsize + 214 fp->f_seekp = (off_t)ifileent_blkno * lfs_sb_getbsize(fs) +
237 (inumber % fs->lfs_ifpb) * sizeof (IFILE_Vx); 215 (inumber % lfs_sb_getifpb(fs)) * sizeof (IFILE_Vx);
238 rc = buf_read_file(f, &ent_in_buf, &buf_after_ent); 216 rc = buf_read_file(f, &ent_in_buf, &buf_after_ent);
239 if (rc) 217 if (rc)
240 return rc; 218 return rc;
241 /* make sure something's not badly wrong, but don't panic. */ 219 /* make sure something's not badly wrong, but don't panic. */
242 if (buf_after_ent < sizeof (IFILE_Vx)) 220 if (buf_after_ent < sizeof (IFILE_Vx))
243 return EINVAL; 221 return EINVAL;
244 222
245 *isp = FSBTODB(fs, ((IFILE_Vx *)ent_in_buf)->if_daddr); 223 *isp = FSBTODB(fs, ((IFILE_Vx *)ent_in_buf)->if_daddr);
246 if (*isp == LFS_UNUSED_DADDR) /* again, something badly wrong */ 224 if (*isp == LFS_UNUSED_DADDR) /* again, something badly wrong */
247 return EINVAL; 225 return EINVAL;
248 return 0; 226 return 0;
249} 227}
250#endif 228#endif
@@ -257,28 +235,28 @@ read_inode(ino32_t inumber, struct open_ @@ -257,28 +235,28 @@ read_inode(ino32_t inumber, struct open_
257{ 235{
258 struct file *fp = (struct file *)f->f_fsdata; 236 struct file *fp = (struct file *)f->f_fsdata;
259 FS *fs = fp->f_fs; 237 FS *fs = fp->f_fs;
260 char *buf; 238 char *buf;
261 size_t rsize; 239 size_t rsize;
262 int rc; 240 int rc;
263 daddr_t inode_sector = 0; /* XXX: gcc */ 241 daddr_t inode_sector = 0; /* XXX: gcc */
264#ifdef LIBSA_LFS 242#ifdef LIBSA_LFS
265 struct ufs_dinode *dip; 243 struct ufs_dinode *dip;
266 int cnt; 244 int cnt;
267#endif 245#endif
268 246
269#ifdef LIBSA_LFS 247#ifdef LIBSA_LFS
270 if (inumber == fs->lfs_ifile) 248 if (inumber == lfs_sb_getifile(fs))
271 inode_sector = FSBTODB(fs, fs->lfs_idaddr); 249 inode_sector = FSBTODB(fs, lfs_sb_getidaddr(fs));
272 else if ((rc = find_inode_sector(inumber, f, &inode_sector)) != 0) 250 else if ((rc = find_inode_sector(inumber, f, &inode_sector)) != 0)
273 return rc; 251 return rc;
274#else 252#else
275 inode_sector = FSBTODB(fs, ino_to_fsba(fs, inumber)); 253 inode_sector = FSBTODB(fs, ino_to_fsba(fs, inumber));
276#endif 254#endif
277 255
278 /* 256 /*
279 * Read inode and save it. 257 * Read inode and save it.
280 */ 258 */
281 buf = fp->f_buf; 259 buf = fp->f_buf;
282 twiddle(); 260 twiddle();
283 rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ, 261 rc = DEV_STRATEGY(f->f_dev)(f->f_devdata, F_READ,
284 inode_sector, fs->fs_bsize, buf, &rsize); 262 inode_sector, fs->fs_bsize, buf, &rsize);

cvs diff -r1.163 -r1.164 src/sys/ufs/lfs/lfs.h (expand / switch to unified diff)

--- src/sys/ufs/lfs/lfs.h 2015/07/24 06:51:46 1.163
+++ src/sys/ufs/lfs/lfs.h 2015/07/24 06:56:42 1.164
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lfs.h,v 1.163 2015/07/24 06:51:46 dholland Exp $ */ 1/* $NetBSD: lfs.h,v 1.164 2015/07/24 06:56:42 dholland Exp $ */
2 2
3/* from NetBSD: dinode.h,v 1.22 2013/01/22 09:39:18 dholland Exp */ 3/* from NetBSD: dinode.h,v 1.22 2013/01/22 09:39:18 dholland Exp */
4/* from NetBSD: dir.h,v 1.21 2009/07/22 04:49:19 dholland Exp */ 4/* from NetBSD: dir.h,v 1.21 2009/07/22 04:49:19 dholland Exp */
5 5
6/*- 6/*-
7 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc. 7 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
8 * All rights reserved. 8 * All rights reserved.
9 * 9 *
10 * This code is derived from software contributed to The NetBSD Foundation 10 * This code is derived from software contributed to The NetBSD Foundation
11 * by Konrad E. Schroder <perseant@hhhh.org>. 11 * by Konrad E. Schroder <perseant@hhhh.org>.
12 * 12 *
13 * Redistribution and use in source and binary forms, with or without 13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions 14 * modification, are permitted provided that the following conditions
@@ -467,43 +467,43 @@ struct ulfs2_dinode { @@ -467,43 +467,43 @@ struct ulfs2_dinode {
467 } \ 467 } \
468 (bp)->b_flags &= ~B_LOCKED; \ 468 (bp)->b_flags &= ~B_LOCKED; \
469} while (0) 469} while (0)
470 470
471/* 471/*
472 * "struct inode" associated definitions 472 * "struct inode" associated definitions
473 */ 473 */
474 474
475/* For convenience */ 475/* For convenience */
476#define IN_ALLMOD (IN_MODIFIED|IN_ACCESS|IN_CHANGE|IN_UPDATE|IN_MODIFY|IN_ACCESSED|IN_CLEANING) 476#define IN_ALLMOD (IN_MODIFIED|IN_ACCESS|IN_CHANGE|IN_UPDATE|IN_MODIFY|IN_ACCESSED|IN_CLEANING)
477 477
478#define LFS_SET_UINO(ip, flags) do { \ 478#define LFS_SET_UINO(ip, flags) do { \
479 if (((flags) & IN_ACCESSED) && !((ip)->i_flag & IN_ACCESSED)) \ 479 if (((flags) & IN_ACCESSED) && !((ip)->i_flag & IN_ACCESSED)) \
480 ++(ip)->i_lfs->lfs_uinodes; \ 480 lfs_sb_adduinodes((ip)->i_lfs, 1); \
481 if (((flags) & IN_CLEANING) && !((ip)->i_flag & IN_CLEANING)) \ 481 if (((flags) & IN_CLEANING) && !((ip)->i_flag & IN_CLEANING)) \
482 ++(ip)->i_lfs->lfs_uinodes; \ 482 lfs_sb_adduinodes((ip)->i_lfs, 1); \
483 if (((flags) & IN_MODIFIED) && !((ip)->i_flag & IN_MODIFIED)) \ 483 if (((flags) & IN_MODIFIED) && !((ip)->i_flag & IN_MODIFIED)) \
484 ++(ip)->i_lfs->lfs_uinodes; \ 484 lfs_sb_adduinodes((ip)->i_lfs, 1); \
485 (ip)->i_flag |= (flags); \ 485 (ip)->i_flag |= (flags); \
486} while (0) 486} while (0)
487 487
488#define LFS_CLR_UINO(ip, flags) do { \ 488#define LFS_CLR_UINO(ip, flags) do { \
489 if (((flags) & IN_ACCESSED) && ((ip)->i_flag & IN_ACCESSED)) \ 489 if (((flags) & IN_ACCESSED) && ((ip)->i_flag & IN_ACCESSED)) \
490 --(ip)->i_lfs->lfs_uinodes; \ 490 lfs_sb_subuinodes((ip)->i_lfs, 1); \
491 if (((flags) & IN_CLEANING) && ((ip)->i_flag & IN_CLEANING)) \ 491 if (((flags) & IN_CLEANING) && ((ip)->i_flag & IN_CLEANING)) \
492 --(ip)->i_lfs->lfs_uinodes; \ 492 lfs_sb_subuinodes((ip)->i_lfs, 1); \
493 if (((flags) & IN_MODIFIED) && ((ip)->i_flag & IN_MODIFIED)) \ 493 if (((flags) & IN_MODIFIED) && ((ip)->i_flag & IN_MODIFIED)) \
494 --(ip)->i_lfs->lfs_uinodes; \ 494 lfs_sb_subuinodes((ip)->i_lfs, 1); \
495 (ip)->i_flag &= ~(flags); \ 495 (ip)->i_flag &= ~(flags); \
496 if ((ip)->i_lfs->lfs_uinodes < 0) { \ 496 if (lfs_sb_getuinodes((ip)->i_lfs) < 0) { \
497 panic("lfs_uinodes < 0"); \ 497 panic("lfs_uinodes < 0"); \
498 } \ 498 } \
499} while (0) 499} while (0)
500 500
501#define LFS_ITIMES(ip, acc, mod, cre) \ 501#define LFS_ITIMES(ip, acc, mod, cre) \
502 while ((ip)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY)) \ 502 while ((ip)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY)) \
503 lfs_itimes(ip, acc, mod, cre) 503 lfs_itimes(ip, acc, mod, cre)
504 504
505/* 505/*
506 * On-disk and in-memory checkpoint segment usage structure. 506 * On-disk and in-memory checkpoint segment usage structure.
507 */ 507 */
508typedef struct segusage SEGUSE; 508typedef struct segusage SEGUSE;
509struct segusage { 509struct segusage {
@@ -521,58 +521,58 @@ struct segusage { @@ -521,58 +521,58 @@ struct segusage {
521 u_int32_t su_flags; /* 12: segment flags */ 521 u_int32_t su_flags; /* 12: segment flags */
522 u_int64_t su_lastmod; /* 16: last modified timestamp */ 522 u_int64_t su_lastmod; /* 16: last modified timestamp */
523}; 523};
524 524
525typedef struct segusage_v1 SEGUSE_V1; 525typedef struct segusage_v1 SEGUSE_V1;
526struct segusage_v1 { 526struct segusage_v1 {
527 u_int32_t su_nbytes; /* 0: number of live bytes */ 527 u_int32_t su_nbytes; /* 0: number of live bytes */
528 u_int32_t su_lastmod; /* 4: SEGUSE last modified timestamp */ 528 u_int32_t su_lastmod; /* 4: SEGUSE last modified timestamp */
529 u_int16_t su_nsums; /* 8: number of summaries in segment */ 529 u_int16_t su_nsums; /* 8: number of summaries in segment */
530 u_int16_t su_ninos; /* 10: number of inode blocks in seg */ 530 u_int16_t su_ninos; /* 10: number of inode blocks in seg */
531 u_int32_t su_flags; /* 12: segment flags */ 531 u_int32_t su_flags; /* 12: segment flags */
532}; 532};
533 533
534#define SEGUPB(fs) (fs->lfs_sepb) 534#define SEGUPB(fs) (lfs_sb_getsepb(fs))
535#define SEGTABSIZE_SU(fs) \ 535#define SEGTABSIZE_SU(fs) \
536 (((fs)->lfs_nseg + SEGUPB(fs) - 1) / (fs)->lfs_sepb) 536 ((lfs_sb_getnseg(fs) + SEGUPB(fs) - 1) / lfs_sb_getsepb(fs))
537 537
538#ifdef _KERNEL 538#ifdef _KERNEL
539# define SHARE_IFLOCK(F) \ 539# define SHARE_IFLOCK(F) \
540 do { \ 540 do { \
541 rw_enter(&(F)->lfs_iflock, RW_READER); \ 541 rw_enter(&(F)->lfs_iflock, RW_READER); \
542 } while(0) 542 } while(0)
543# define UNSHARE_IFLOCK(F) \ 543# define UNSHARE_IFLOCK(F) \
544 do { \ 544 do { \
545 rw_exit(&(F)->lfs_iflock); \ 545 rw_exit(&(F)->lfs_iflock); \
546 } while(0) 546 } while(0)
547#else /* ! _KERNEL */ 547#else /* ! _KERNEL */
548# define SHARE_IFLOCK(F) 548# define SHARE_IFLOCK(F)
549# define UNSHARE_IFLOCK(F) 549# define UNSHARE_IFLOCK(F)
550#endif /* ! _KERNEL */ 550#endif /* ! _KERNEL */
551 551
552/* Read in the block with a specific segment usage entry from the ifile. */ 552/* Read in the block with a specific segment usage entry from the ifile. */
553#define LFS_SEGENTRY(SP, F, IN, BP) do { \ 553#define LFS_SEGENTRY(SP, F, IN, BP) do { \
554 int _e; \ 554 int _e; \
555 SHARE_IFLOCK(F); \ 555 SHARE_IFLOCK(F); \
556 VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS; \ 556 VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS; \
557 if ((_e = bread((F)->lfs_ivnode, \ 557 if ((_e = bread((F)->lfs_ivnode, \
558 ((IN) / (F)->lfs_sepb) + (F)->lfs_cleansz, \ 558 ((IN) / lfs_sb_getsepb(F)) + lfs_sb_getcleansz(F), \
559 (F)->lfs_bsize, 0, &(BP))) != 0) \ 559 lfs_sb_getbsize(F), 0, &(BP))) != 0) \
560 panic("lfs: ifile read: %d", _e); \ 560 panic("lfs: ifile read: %d", _e); \
561 if ((F)->lfs_version == 1) \ 561 if ((F)->lfs_version == 1) \
562 (SP) = (SEGUSE *)((SEGUSE_V1 *)(BP)->b_data + \ 562 (SP) = (SEGUSE *)((SEGUSE_V1 *)(BP)->b_data + \
563 ((IN) & ((F)->lfs_sepb - 1))); \ 563 ((IN) & (lfs_sb_getsepb(F) - 1))); \
564 else \ 564 else \
565 (SP) = (SEGUSE *)(BP)->b_data + ((IN) % (F)->lfs_sepb); \ 565 (SP) = (SEGUSE *)(BP)->b_data + ((IN) % lfs_sb_getsepb(F)); \
566 UNSHARE_IFLOCK(F); \ 566 UNSHARE_IFLOCK(F); \
567} while (0) 567} while (0)
568 568
569#define LFS_WRITESEGENTRY(SP, F, IN, BP) do { \ 569#define LFS_WRITESEGENTRY(SP, F, IN, BP) do { \
570 if ((SP)->su_nbytes == 0) \ 570 if ((SP)->su_nbytes == 0) \
571 (SP)->su_flags |= SEGUSE_EMPTY; \ 571 (SP)->su_flags |= SEGUSE_EMPTY; \
572 else \ 572 else \
573 (SP)->su_flags &= ~SEGUSE_EMPTY; \ 573 (SP)->su_flags &= ~SEGUSE_EMPTY; \
574 (F)->lfs_suflags[(F)->lfs_activesb][(IN)] = (SP)->su_flags; \ 574 (F)->lfs_suflags[(F)->lfs_activesb][(IN)] = (SP)->su_flags; \
575 LFS_BWRITE_LOG(BP); \ 575 LFS_BWRITE_LOG(BP); \
576} while (0) 576} while (0)
577 577
578/* 578/*
@@ -613,103 +613,103 @@ struct ifile_v1 { @@ -613,103 +613,103 @@ struct ifile_v1 {
613#endif 613#endif
614}; 614};
615 615
616/* 616/*
617 * LFSv1 compatibility code is not allowed to touch if_atime, since it 617 * LFSv1 compatibility code is not allowed to touch if_atime, since it
618 * may not be mapped! 618 * may not be mapped!
619 */ 619 */
620/* Read in the block with a specific inode from the ifile. */ 620/* Read in the block with a specific inode from the ifile. */
621#define LFS_IENTRY(IP, F, IN, BP) do { \ 621#define LFS_IENTRY(IP, F, IN, BP) do { \
622 int _e; \ 622 int _e; \
623 SHARE_IFLOCK(F); \ 623 SHARE_IFLOCK(F); \
624 VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS; \ 624 VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS; \
625 if ((_e = bread((F)->lfs_ivnode, \ 625 if ((_e = bread((F)->lfs_ivnode, \
626 (IN) / (F)->lfs_ifpb + (F)->lfs_cleansz + (F)->lfs_segtabsz, \ 626 (IN) / lfs_sb_getifpb(F) + lfs_sb_getcleansz(F) + lfs_sb_getsegtabsz(F), \
627 (F)->lfs_bsize, 0, &(BP))) != 0) \ 627 lfs_sb_getbsize(F), 0, &(BP))) != 0) \
628 panic("lfs: ifile ino %d read %d", (int)(IN), _e); \ 628 panic("lfs: ifile ino %d read %d", (int)(IN), _e); \
629 if ((F)->lfs_version == 1) \ 629 if ((F)->lfs_version == 1) \
630 (IP) = (IFILE *)((IFILE_V1 *)(BP)->b_data + \ 630 (IP) = (IFILE *)((IFILE_V1 *)(BP)->b_data + \
631 (IN) % (F)->lfs_ifpb); \ 631 (IN) % lfs_sb_getifpb(F)); \
632 else \ 632 else \
633 (IP) = (IFILE *)(BP)->b_data + (IN) % (F)->lfs_ifpb; \ 633 (IP) = (IFILE *)(BP)->b_data + (IN) % lfs_sb_getifpb(F); \
634 UNSHARE_IFLOCK(F); \ 634 UNSHARE_IFLOCK(F); \
635} while (0) 635} while (0)
636 636
637/* 637/*
638 * Cleaner information structure. This resides in the ifile and is used 638 * Cleaner information structure. This resides in the ifile and is used
639 * to pass information from the kernel to the cleaner. 639 * to pass information from the kernel to the cleaner.
640 */ 640 */
641typedef struct _cleanerinfo { 641typedef struct _cleanerinfo {
642 u_int32_t clean; /* number of clean segments */ 642 u_int32_t clean; /* number of clean segments */
643 u_int32_t dirty; /* number of dirty segments */ 643 u_int32_t dirty; /* number of dirty segments */
644 int32_t bfree; /* disk blocks free */ 644 int32_t bfree; /* disk blocks free */
645 int32_t avail; /* disk blocks available */ 645 int32_t avail; /* disk blocks available */
646 u_int32_t free_head; /* head of the inode free list */ 646 u_int32_t free_head; /* head of the inode free list */
647 u_int32_t free_tail; /* tail of the inode free list */ 647 u_int32_t free_tail; /* tail of the inode free list */
648#define LFS_CLEANER_MUST_CLEAN 0x01 648#define LFS_CLEANER_MUST_CLEAN 0x01
649 u_int32_t flags; /* status word from the kernel */ 649 u_int32_t flags; /* status word from the kernel */
650} CLEANERINFO; 650} CLEANERINFO;
651 651
652#define CLEANSIZE_SU(fs) \ 652#define CLEANSIZE_SU(fs) \
653 ((sizeof(CLEANERINFO) + (fs)->lfs_bsize - 1) >> (fs)->lfs_bshift) 653 ((sizeof(CLEANERINFO) + lfs_sb_getbsize(fs) - 1) >> (fs)->lfs_bshift)
654 654
655/* Read in the block with the cleaner info from the ifile. */ 655/* Read in the block with the cleaner info from the ifile. */
656#define LFS_CLEANERINFO(CP, F, BP) do { \ 656#define LFS_CLEANERINFO(CP, F, BP) do { \
657 SHARE_IFLOCK(F); \ 657 SHARE_IFLOCK(F); \
658 VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS; \ 658 VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS; \
659 if (bread((F)->lfs_ivnode, \ 659 if (bread((F)->lfs_ivnode, \
660 (daddr_t)0, (F)->lfs_bsize, 0, &(BP))) \ 660 (daddr_t)0, lfs_sb_getbsize(F), 0, &(BP))) \
661 panic("lfs: ifile read"); \ 661 panic("lfs: ifile read"); \
662 (CP) = (CLEANERINFO *)(BP)->b_data; \ 662 (CP) = (CLEANERINFO *)(BP)->b_data; \
663 UNSHARE_IFLOCK(F); \ 663 UNSHARE_IFLOCK(F); \
664} while (0) 664} while (0)
665 665
666/* 666/*
667 * Synchronize the Ifile cleaner info with current avail and bfree. 667 * Synchronize the Ifile cleaner info with current avail and bfree.
668 */ 668 */
669#define LFS_SYNC_CLEANERINFO(cip, fs, bp, w) do { \ 669#define LFS_SYNC_CLEANERINFO(cip, fs, bp, w) do { \
670 mutex_enter(&lfs_lock); \ 670 mutex_enter(&lfs_lock); \
671 if ((w) || (cip)->bfree != (fs)->lfs_bfree || \ 671 if ((w) || (cip)->bfree != lfs_sb_getbfree(fs) || \
672 (cip)->avail != (fs)->lfs_avail - (fs)->lfs_ravail - \ 672 (cip)->avail != lfs_sb_getavail(fs) - fs->lfs_ravail - \
673 (fs)->lfs_favail) { \ 673 fs->lfs_favail) { \
674 (cip)->bfree = (fs)->lfs_bfree; \ 674 (cip)->bfree = lfs_sb_getbfree(fs); \
675 (cip)->avail = (fs)->lfs_avail - (fs)->lfs_ravail - \ 675 (cip)->avail = lfs_sb_getavail(fs) - fs->lfs_ravail - \
676 (fs)->lfs_favail; \ 676 fs->lfs_favail; \
677 if (((bp)->b_flags & B_GATHERED) == 0) { \ 677 if (((bp)->b_flags & B_GATHERED) == 0) { \
678 (fs)->lfs_flags |= LFS_IFDIRTY; \ 678 fs->lfs_flags |= LFS_IFDIRTY; \
679 } \ 679 } \
680 mutex_exit(&lfs_lock); \ 680 mutex_exit(&lfs_lock); \
681 (void) LFS_BWRITE_LOG(bp); /* Ifile */ \ 681 (void) LFS_BWRITE_LOG(bp); /* Ifile */ \
682 } else { \ 682 } else { \
683 mutex_exit(&lfs_lock); \ 683 mutex_exit(&lfs_lock); \
684 brelse(bp, 0); \ 684 brelse(bp, 0); \
685 } \ 685 } \
686} while (0) 686} while (0)
687 687
688/* 688/*
689 * Get the head of the inode free list. 689 * Get the head of the inode free list.
690 * Always called with the segment lock held. 690 * Always called with the segment lock held.
691 */ 691 */
692#define LFS_GET_HEADFREE(FS, CIP, BP, FREEP) do { \ 692#define LFS_GET_HEADFREE(FS, CIP, BP, FREEP) do { \
693 if ((FS)->lfs_version > 1) { \ 693 if ((FS)->lfs_version > 1) { \
694 LFS_CLEANERINFO((CIP), (FS), (BP)); \ 694 LFS_CLEANERINFO((CIP), (FS), (BP)); \
695 (FS)->lfs_freehd = (CIP)->free_head; \ 695 lfs_sb_setfreehd(FS, (CIP)->free_head); \
696 brelse(BP, 0); \ 696 brelse(BP, 0); \
697 } \ 697 } \
698 *(FREEP) = (FS)->lfs_freehd; \ 698 *(FREEP) = lfs_sb_getfreehd(FS); \
699} while (0) 699} while (0)
700 700
701#define LFS_PUT_HEADFREE(FS, CIP, BP, VAL) do { \ 701#define LFS_PUT_HEADFREE(FS, CIP, BP, VAL) do { \
702 (FS)->lfs_freehd = (VAL); \ 702 lfs_sb_setfreehd(FS, VAL); \
703 if ((FS)->lfs_version > 1) { \ 703 if ((FS)->lfs_version > 1) { \
704 LFS_CLEANERINFO((CIP), (FS), (BP)); \ 704 LFS_CLEANERINFO((CIP), (FS), (BP)); \
705 (CIP)->free_head = (VAL); \ 705 (CIP)->free_head = (VAL); \
706 LFS_BWRITE_LOG(BP); \ 706 LFS_BWRITE_LOG(BP); \
707 mutex_enter(&lfs_lock); \ 707 mutex_enter(&lfs_lock); \
708 (FS)->lfs_flags |= LFS_IFDIRTY; \ 708 (FS)->lfs_flags |= LFS_IFDIRTY; \
709 mutex_exit(&lfs_lock); \ 709 mutex_exit(&lfs_lock); \
710 } \ 710 } \
711} while (0) 711} while (0)
712 712
713#define LFS_GET_TAILFREE(FS, CIP, BP, FREEP) do { \ 713#define LFS_GET_TAILFREE(FS, CIP, BP, FREEP) do { \
714 LFS_CLEANERINFO((CIP), (FS), (BP)); \ 714 LFS_CLEANERINFO((CIP), (FS), (BP)); \
715 *(FREEP) = (CIP)->free_tail; \ 715 *(FREEP) = (CIP)->free_tail; \
@@ -792,27 +792,26 @@ struct dlfs { @@ -792,27 +792,26 @@ struct dlfs {
792 u_int32_t dlfs_freehd; /* 32: start of the free list */ 792 u_int32_t dlfs_freehd; /* 32: start of the free list */
793 int32_t dlfs_bfree; /* 36: number of free disk blocks */ 793 int32_t dlfs_bfree; /* 36: number of free disk blocks */
794 u_int32_t dlfs_nfiles; /* 40: number of allocated inodes */ 794 u_int32_t dlfs_nfiles; /* 40: number of allocated inodes */
795 int32_t dlfs_avail; /* 44: blocks available for writing */ 795 int32_t dlfs_avail; /* 44: blocks available for writing */
796 int32_t dlfs_uinodes; /* 48: inodes in cache not yet on disk */ 796 int32_t dlfs_uinodes; /* 48: inodes in cache not yet on disk */
797 int32_t dlfs_idaddr; /* 52: inode file disk address */ 797 int32_t dlfs_idaddr; /* 52: inode file disk address */
798 u_int32_t dlfs_ifile; /* 56: inode file inode number */ 798 u_int32_t dlfs_ifile; /* 56: inode file inode number */
799 int32_t dlfs_lastseg; /* 60: address of last segment written */ 799 int32_t dlfs_lastseg; /* 60: address of last segment written */
800 int32_t dlfs_nextseg; /* 64: address of next segment to write */ 800 int32_t dlfs_nextseg; /* 64: address of next segment to write */
801 int32_t dlfs_curseg; /* 68: current segment being written */ 801 int32_t dlfs_curseg; /* 68: current segment being written */
802 int32_t dlfs_offset; /* 72: offset in curseg for next partial */ 802 int32_t dlfs_offset; /* 72: offset in curseg for next partial */
803 int32_t dlfs_lastpseg; /* 76: address of last partial written */ 803 int32_t dlfs_lastpseg; /* 76: address of last partial written */
804 u_int32_t dlfs_inopf; /* 80: v1: time stamp; v2: inodes per frag */ 804 u_int32_t dlfs_inopf; /* 80: v1: time stamp; v2: inodes per frag */
805#define dlfs_otstamp dlfs_inopf 
806 805
807/* These are configuration parameters. */ 806/* These are configuration parameters. */
808 u_int32_t dlfs_minfree; /* 84: minimum percentage of free blocks */ 807 u_int32_t dlfs_minfree; /* 84: minimum percentage of free blocks */
809 808
810/* These fields can be computed from the others. */ 809/* These fields can be computed from the others. */
811 u_int64_t dlfs_maxfilesize; /* 88: maximum representable file size */ 810 u_int64_t dlfs_maxfilesize; /* 88: maximum representable file size */
812 u_int32_t dlfs_fsbpseg; /* 96: fsb per segment */ 811 u_int32_t dlfs_fsbpseg; /* 96: fsb per segment */
813 u_int32_t dlfs_inopb; /* 100: inodes per block */ 812 u_int32_t dlfs_inopb; /* 100: inodes per block */
814 u_int32_t dlfs_ifpb; /* 104: IFILE entries per block */ 813 u_int32_t dlfs_ifpb; /* 104: IFILE entries per block */
815 u_int32_t dlfs_sepb; /* 108: SEGUSE entries per block */ 814 u_int32_t dlfs_sepb; /* 108: SEGUSE entries per block */
816 u_int32_t dlfs_nindir; /* 112: indirect pointers per block */ 815 u_int32_t dlfs_nindir; /* 112: indirect pointers per block */
817 u_int32_t dlfs_nseg; /* 116: number of segments */ 816 u_int32_t dlfs_nseg; /* 116: number of segments */
818 u_int32_t dlfs_nspf; /* 120: number of sectors per fragment */ 817 u_int32_t dlfs_nspf; /* 120: number of sectors per fragment */
@@ -865,87 +864,26 @@ typedef u_int32_t lfs_bm_t; @@ -865,87 +864,26 @@ typedef u_int32_t lfs_bm_t;
865 * file truncation. 864 * file truncation.
866 */ 865 */
867struct segdelta { 866struct segdelta {
868 long segnum; 867 long segnum;
869 size_t num; 868 size_t num;
870 LIST_ENTRY(segdelta) list; 869 LIST_ENTRY(segdelta) list;
871}; 870};
872 871
873/* 872/*
874 * In-memory super block. 873 * In-memory super block.
875 */ 874 */
876struct lfs { 875struct lfs {
877 struct dlfs lfs_dlfs; /* on-disk parameters */ 876 struct dlfs lfs_dlfs; /* on-disk parameters */
878#define lfs_magic lfs_dlfs.dlfs_magic 
879#define lfs_version lfs_dlfs.dlfs_version 
880#define lfs_size lfs_dlfs.dlfs_size 
881#define lfs_ssize lfs_dlfs.dlfs_ssize 
882#define lfs_dsize lfs_dlfs.dlfs_dsize 
883#define lfs_bsize lfs_dlfs.dlfs_bsize 
884#define lfs_fsize lfs_dlfs.dlfs_fsize 
885#define lfs_frag lfs_dlfs.dlfs_frag 
886#define lfs_freehd lfs_dlfs.dlfs_freehd 
887#define lfs_bfree lfs_dlfs.dlfs_bfree 
888#define lfs_nfiles lfs_dlfs.dlfs_nfiles 
889#define lfs_avail lfs_dlfs.dlfs_avail 
890#define lfs_uinodes lfs_dlfs.dlfs_uinodes 
891#define lfs_idaddr lfs_dlfs.dlfs_idaddr 
892#define lfs_ifile lfs_dlfs.dlfs_ifile 
893#define lfs_lastseg lfs_dlfs.dlfs_lastseg 
894#define lfs_nextseg lfs_dlfs.dlfs_nextseg 
895#define lfs_curseg lfs_dlfs.dlfs_curseg 
896#define lfs_offset lfs_dlfs.dlfs_offset 
897#define lfs_lastpseg lfs_dlfs.dlfs_lastpseg 
898#define lfs_otstamp lfs_dlfs.dlfs_inopf 
899#define lfs_inopf lfs_dlfs.dlfs_inopf 
900#define lfs_minfree lfs_dlfs.dlfs_minfree 
901#define lfs_maxfilesize lfs_dlfs.dlfs_maxfilesize 
902#define lfs_fsbpseg lfs_dlfs.dlfs_fsbpseg 
903#define lfs_inopb lfs_dlfs.dlfs_inopb 
904#define lfs_ifpb lfs_dlfs.dlfs_ifpb 
905#define lfs_sepb lfs_dlfs.dlfs_sepb 
906#define lfs_nindir lfs_dlfs.dlfs_nindir 
907#define lfs_nseg lfs_dlfs.dlfs_nseg 
908#define lfs_nspf lfs_dlfs.dlfs_nspf 
909#define lfs_cleansz lfs_dlfs.dlfs_cleansz 
910#define lfs_segtabsz lfs_dlfs.dlfs_segtabsz 
911#define lfs_segmask lfs_dlfs.dlfs_segmask 
912#define lfs_segshift lfs_dlfs.dlfs_segshift 
913#define lfs_bmask lfs_dlfs.dlfs_bmask 
914#define lfs_bshift lfs_dlfs.dlfs_bshift 
915#define lfs_ffmask lfs_dlfs.dlfs_ffmask 
916#define lfs_ffshift lfs_dlfs.dlfs_ffshift 
917#define lfs_fbmask lfs_dlfs.dlfs_fbmask 
918#define lfs_fbshift lfs_dlfs.dlfs_fbshift 
919#define lfs_blktodb lfs_dlfs.dlfs_blktodb 
920#define lfs_fsbtodb lfs_dlfs.dlfs_fsbtodb 
921#define lfs_sushift lfs_dlfs.dlfs_sushift 
922#define lfs_maxsymlinklen lfs_dlfs.dlfs_maxsymlinklen 
923#define lfs_sboffs lfs_dlfs.dlfs_sboffs 
924#define lfs_cksum lfs_dlfs.dlfs_cksum 
925#define lfs_pflags lfs_dlfs.dlfs_pflags 
926#define lfs_fsmnt lfs_dlfs.dlfs_fsmnt 
927#define lfs_nclean lfs_dlfs.dlfs_nclean 
928#define lfs_dmeta lfs_dlfs.dlfs_dmeta 
929#define lfs_minfreeseg lfs_dlfs.dlfs_minfreeseg 
930#define lfs_sumsize lfs_dlfs.dlfs_sumsize 
931#define lfs_serial lfs_dlfs.dlfs_serial 
932#define lfs_ibsize lfs_dlfs.dlfs_ibsize 
933#define lfs_s0addr lfs_dlfs.dlfs_start 
934#define lfs_tstamp lfs_dlfs.dlfs_tstamp 
935#define lfs_inodefmt lfs_dlfs.dlfs_inodefmt 
936#define lfs_interleave lfs_dlfs.dlfs_interleave 
937#define lfs_ident lfs_dlfs.dlfs_ident 
938#define lfs_resvseg lfs_dlfs.dlfs_resvseg 
939 877
940/* These fields are set at mount time and are meaningless on disk. */ 878/* These fields are set at mount time and are meaningless on disk. */
941 struct segment *lfs_sp; /* current segment being written */ 879 struct segment *lfs_sp; /* current segment being written */
942 struct vnode *lfs_ivnode; /* vnode for the ifile */ 880 struct vnode *lfs_ivnode; /* vnode for the ifile */
943 u_int32_t lfs_seglock; /* single-thread the segment writer */ 881 u_int32_t lfs_seglock; /* single-thread the segment writer */
944 pid_t lfs_lockpid; /* pid of lock holder */ 882 pid_t lfs_lockpid; /* pid of lock holder */
945 lwpid_t lfs_locklwp; /* lwp of lock holder */ 883 lwpid_t lfs_locklwp; /* lwp of lock holder */
946 u_int32_t lfs_iocount; /* number of ios pending */ 884 u_int32_t lfs_iocount; /* number of ios pending */
947 u_int32_t lfs_writer; /* don't allow any dirops to start */ 885 u_int32_t lfs_writer; /* don't allow any dirops to start */
948 u_int32_t lfs_dirops; /* count of active directory ops */ 886 u_int32_t lfs_dirops; /* count of active directory ops */
949 u_int32_t lfs_dirvcount; /* count of VDIROP nodes in this fs */ 887 u_int32_t lfs_dirvcount; /* count of VDIROP nodes in this fs */
950 u_int32_t lfs_doifile; /* Write ifile blocks on next write */ 888 u_int32_t lfs_doifile; /* Write ifile blocks on next write */
951 u_int32_t lfs_nactive; /* Number of segments since last ckp */ 889 u_int32_t lfs_nactive; /* Number of segments since last ckp */
@@ -1003,84 +941,234 @@ struct lfs { @@ -1003,84 +941,234 @@ struct lfs {
1003 u_long um_nindir; /* indirect ptrs per block */ 941 u_long um_nindir; /* indirect ptrs per block */
1004 u_long um_lognindir; /* log2 of um_nindir */ 942 u_long um_lognindir; /* log2 of um_nindir */
1005 u_long um_bptrtodb; /* indir ptr to disk block */ 943 u_long um_bptrtodb; /* indir ptr to disk block */
1006 u_long um_seqinc; /* inc between seq blocks */ 944 u_long um_seqinc; /* inc between seq blocks */
1007 int um_maxsymlinklen; 945 int um_maxsymlinklen;
1008 int um_dirblksiz; 946 int um_dirblksiz;
1009 u_int64_t um_maxfilesize; 947 u_int64_t um_maxfilesize;
1010 948
1011 /* Stuff used by quota2 code, not currently operable */ 949 /* Stuff used by quota2 code, not currently operable */
1012 unsigned lfs_use_quota2 : 1; 950 unsigned lfs_use_quota2 : 1;
1013 uint32_t lfs_quota_magic; 951 uint32_t lfs_quota_magic;
1014 uint8_t lfs_quota_flags; 952 uint8_t lfs_quota_flags;
1015 uint64_t lfs_quotaino[2]; 953 uint64_t lfs_quotaino[2];
 954
 955 /* Sleep address replacing &lfs_avail inside the on-disk superblock */
 956 /* XXX: should be replaced with a condvar */
 957 int lfs_availsleep;
 958 /* This one replaces &lfs_nextseg... all ditto */
 959 int lfs_nextsegsleep;
1016#endif 960#endif
1017}; 961};
1018 962
 963/*
 964 * Smaller "struct lfs" used by libsa. XXX: this should not need to be
 965 * exposed here, but currently it must be in order for the superblock
 966 * accessors to work. Blah.
 967 */
 968struct salfs {
 969 struct dlfs lfs_dlfs;
 970};
 971
 972/*
 973 * Generate accessors for the on-disk superblock fields with cpp.
 974 *
 975 * STRUCT_LFS is used by the libsa code to get accessors that work
 976 * with struct salfs instead of struct lfs.
 977 */
 978
 979#ifndef STRUCT_LFS
 980#define STRUCT_LFS struct lfs
 981#endif
 982
 983#define LFS_DEF_SB_ACCESSOR(type, field) \
 984 static __unused inline type \
 985 lfs_sb_get##field(STRUCT_LFS *fs) \
 986 { \
 987 return fs->lfs_dlfs.dlfs_##field; \
 988 } \
 989 static __unused inline void \
 990 lfs_sb_set##field(STRUCT_LFS *fs, type val) \
 991 { \
 992 fs->lfs_dlfs.dlfs_##field = val; \
 993 } \
 994 static __unused inline void \
 995 lfs_sb_add##field(STRUCT_LFS *fs, type val) \
 996 { \
 997 type *p = &fs->lfs_dlfs.dlfs_##field; \
 998 *p += val; \
 999 } \
 1000 static __unused inline void \
 1001 lfs_sb_sub##field(STRUCT_LFS *fs, type val) \
 1002 { \
 1003 type *p = &fs->lfs_dlfs.dlfs_##field; \
 1004 *p -= val; \
 1005 }
 1006
 1007#define lfs_magic lfs_dlfs.dlfs_magic
 1008#define lfs_version lfs_dlfs.dlfs_version
 1009LFS_DEF_SB_ACCESSOR(u_int32_t, size);
 1010LFS_DEF_SB_ACCESSOR(u_int32_t, ssize);
 1011LFS_DEF_SB_ACCESSOR(u_int32_t, dsize);
 1012LFS_DEF_SB_ACCESSOR(u_int32_t, bsize);
 1013LFS_DEF_SB_ACCESSOR(u_int32_t, fsize);
 1014LFS_DEF_SB_ACCESSOR(u_int32_t, frag);
 1015LFS_DEF_SB_ACCESSOR(u_int32_t, freehd);
 1016LFS_DEF_SB_ACCESSOR(int32_t, bfree);
 1017LFS_DEF_SB_ACCESSOR(u_int32_t, nfiles);
 1018LFS_DEF_SB_ACCESSOR(int32_t, avail);
 1019LFS_DEF_SB_ACCESSOR(int32_t, uinodes);
 1020LFS_DEF_SB_ACCESSOR(int32_t, idaddr);
 1021LFS_DEF_SB_ACCESSOR(u_int32_t, ifile);
 1022LFS_DEF_SB_ACCESSOR(int32_t, lastseg);
 1023LFS_DEF_SB_ACCESSOR(int32_t, nextseg);
 1024LFS_DEF_SB_ACCESSOR(int32_t, curseg);
 1025LFS_DEF_SB_ACCESSOR(int32_t, offset);
 1026LFS_DEF_SB_ACCESSOR(int32_t, lastpseg);
 1027LFS_DEF_SB_ACCESSOR(u_int32_t, inopf);
 1028LFS_DEF_SB_ACCESSOR(u_int32_t, minfree);
 1029#define lfs_maxfilesize lfs_dlfs.dlfs_maxfilesize
 1030LFS_DEF_SB_ACCESSOR(uint64_t, maxfilesize);
 1031#define lfs_fsbpseg lfs_dlfs.dlfs_fsbpseg
 1032LFS_DEF_SB_ACCESSOR(u_int32_t, fsbpseg);
 1033#define lfs_inopb lfs_dlfs.dlfs_inopb
 1034LFS_DEF_SB_ACCESSOR(u_int32_t, inopb);
 1035LFS_DEF_SB_ACCESSOR(u_int32_t, ifpb);
 1036LFS_DEF_SB_ACCESSOR(u_int32_t, sepb);
 1037#define lfs_nindir lfs_dlfs.dlfs_nindir
 1038LFS_DEF_SB_ACCESSOR(u_int32_t, nindir);
 1039#define lfs_nseg lfs_dlfs.dlfs_nseg
 1040LFS_DEF_SB_ACCESSOR(u_int32_t, nseg);
 1041#define lfs_nspf lfs_dlfs.dlfs_nspf
 1042LFS_DEF_SB_ACCESSOR(u_int32_t, nspf);
 1043LFS_DEF_SB_ACCESSOR(u_int32_t, cleansz);
 1044LFS_DEF_SB_ACCESSOR(u_int32_t, segtabsz);
 1045#define lfs_segmask lfs_dlfs.dlfs_segmask
 1046LFS_DEF_SB_ACCESSOR(u_int32_t, segmask);
 1047#define lfs_segshift lfs_dlfs.dlfs_segshift
 1048LFS_DEF_SB_ACCESSOR(u_int32_t, segshift);
 1049#define lfs_bmask lfs_dlfs.dlfs_bmask
 1050LFS_DEF_SB_ACCESSOR(u_int64_t, bmask);
 1051#define lfs_bshift lfs_dlfs.dlfs_bshift
 1052LFS_DEF_SB_ACCESSOR(u_int32_t, bshift);
 1053#define lfs_ffmask lfs_dlfs.dlfs_ffmask
 1054LFS_DEF_SB_ACCESSOR(u_int64_t, ffmask);
 1055#define lfs_ffshift lfs_dlfs.dlfs_ffshift
 1056LFS_DEF_SB_ACCESSOR(u_int32_t, ffshift);
 1057#define lfs_fbmask lfs_dlfs.dlfs_fbmask
 1058LFS_DEF_SB_ACCESSOR(u_int64_t, fbmask);
 1059#define lfs_fbshift lfs_dlfs.dlfs_fbshift
 1060LFS_DEF_SB_ACCESSOR(u_int32_t, fbshift);
 1061#define lfs_blktodb lfs_dlfs.dlfs_blktodb
 1062LFS_DEF_SB_ACCESSOR(u_int32_t, blktodb);
 1063#define lfs_fsbtodb lfs_dlfs.dlfs_fsbtodb
 1064LFS_DEF_SB_ACCESSOR(u_int32_t, fsbtodb);
 1065#define lfs_sushift lfs_dlfs.dlfs_sushift
 1066LFS_DEF_SB_ACCESSOR(u_int32_t, sushift);
 1067#define lfs_maxsymlinklen lfs_dlfs.dlfs_maxsymlinklen
 1068LFS_DEF_SB_ACCESSOR(int32_t, maxsymlinklen);
 1069#define lfs_sboffs lfs_dlfs.dlfs_sboffs
 1070#define lfs_cksum lfs_dlfs.dlfs_cksum
 1071LFS_DEF_SB_ACCESSOR(u_int32_t, cksum);
 1072#define lfs_pflags lfs_dlfs.dlfs_pflags
 1073LFS_DEF_SB_ACCESSOR(u_int16_t, pflags);
 1074#define lfs_fsmnt lfs_dlfs.dlfs_fsmnt
 1075#define lfs_nclean lfs_dlfs.dlfs_nclean
 1076LFS_DEF_SB_ACCESSOR(u_int32_t, nclean);
 1077#define lfs_dmeta lfs_dlfs.dlfs_dmeta
 1078LFS_DEF_SB_ACCESSOR(int32_t, dmeta);
 1079#define lfs_minfreeseg lfs_dlfs.dlfs_minfreeseg
 1080LFS_DEF_SB_ACCESSOR(u_int32_t, minfreeseg);
 1081#define lfs_sumsize lfs_dlfs.dlfs_sumsize
 1082LFS_DEF_SB_ACCESSOR(u_int32_t, sumsize);
 1083LFS_DEF_SB_ACCESSOR(u_int64_t, serial);
 1084#define lfs_ibsize lfs_dlfs.dlfs_ibsize
 1085LFS_DEF_SB_ACCESSOR(u_int32_t, ibsize);
 1086#define lfs_s0addr lfs_dlfs.dlfs_start
 1087LFS_DEF_SB_ACCESSOR(int32_t, start);
 1088LFS_DEF_SB_ACCESSOR(u_int64_t, tstamp);
 1089#define lfs_inodefmt lfs_dlfs.dlfs_inodefmt
 1090LFS_DEF_SB_ACCESSOR(u_int32_t, inodefmt);
 1091#define lfs_interleave lfs_dlfs.dlfs_interleave
 1092LFS_DEF_SB_ACCESSOR(u_int32_t, interleave);
 1093#define lfs_ident lfs_dlfs.dlfs_ident
 1094LFS_DEF_SB_ACCESSOR(u_int32_t, ident);
 1095#define lfs_resvseg lfs_dlfs.dlfs_resvseg
 1096LFS_DEF_SB_ACCESSOR(u_int32_t, resvseg);
 1097
 1098/* special-case accessors */
 1099
 1100/*
 1101 * the v1 otstamp field lives in what's now dlfs_inopf
 1102 */
 1103#define lfs_sb_getotstamp(fs) lfs_sb_getinopf(fs)
 1104#define lfs_sb_setotstamp(fs, val) lfs_sb_setinopf(fs, val)
 1105
 1106
1019/* LFS_NINDIR is the number of indirects in a file system block. */ 1107/* LFS_NINDIR is the number of indirects in a file system block. */
1020#define LFS_NINDIR(fs) ((fs)->lfs_nindir) 1108#define LFS_NINDIR(fs) ((fs)->lfs_nindir)
1021 1109
1022/* LFS_INOPB is the number of inodes in a secondary storage block. */ 1110/* LFS_INOPB is the number of inodes in a secondary storage block. */
1023#define LFS_INOPB(fs) ((fs)->lfs_inopb) 1111#define LFS_INOPB(fs) ((fs)->lfs_inopb)
1024/* LFS_INOPF is the number of inodes in a fragment. */ 1112/* LFS_INOPF is the number of inodes in a fragment. */
1025#define LFS_INOPF(fs) ((fs)->lfs_inopf) 1113#define LFS_INOPF(fs) ((fs)->lfs_inopf)
1026 1114
1027#define lfs_blksize(fs, ip, lbn) \ 1115#define lfs_blksize(fs, ip, lbn) \
1028 (((lbn) >= ULFS_NDADDR || (ip)->i_ffs1_size >= ((lbn) + 1) << (fs)->lfs_bshift) \ 1116 (((lbn) >= ULFS_NDADDR || (ip)->i_ffs1_size >= ((lbn) + 1) << (fs)->lfs_bshift) \
1029 ? (fs)->lfs_bsize \ 1117 ? lfs_sb_getbsize(fs) \
1030 : (lfs_fragroundup(fs, lfs_blkoff(fs, (ip)->i_ffs1_size)))) 1118 : (lfs_fragroundup(fs, lfs_blkoff(fs, (ip)->i_ffs1_size))))
1031#define lfs_blkoff(fs, loc) ((int)((loc) & (fs)->lfs_bmask)) 1119#define lfs_blkoff(fs, loc) ((int)((loc) & (fs)->lfs_bmask))
1032#define lfs_fragoff(fs, loc) /* calculates (loc % fs->lfs_fsize) */ \ 1120#define lfs_fragoff(fs, loc) /* calculates (loc % fs->lfs_fsize) */ \
1033 ((int)((loc) & (fs)->lfs_ffmask)) 1121 ((int)((loc) & (fs)->lfs_ffmask))
1034 1122
1035#if defined(_KERNEL) 1123#if defined(_KERNEL)
1036#define LFS_FSBTODB(fs, b) ((b) << ((fs)->lfs_ffshift - DEV_BSHIFT)) 1124#define LFS_FSBTODB(fs, b) ((b) << ((fs)->lfs_ffshift - DEV_BSHIFT))
1037#define LFS_DBTOFSB(fs, b) ((b) >> ((fs)->lfs_ffshift - DEV_BSHIFT)) 1125#define LFS_DBTOFSB(fs, b) ((b) >> ((fs)->lfs_ffshift - DEV_BSHIFT))
1038#else 1126#else
1039#define LFS_FSBTODB(fs, b) ((b) << (fs)->lfs_fsbtodb) 1127#define LFS_FSBTODB(fs, b) ((b) << (fs)->lfs_fsbtodb)
1040#define LFS_DBTOFSB(fs, b) ((b) >> (fs)->lfs_fsbtodb) 1128#define LFS_DBTOFSB(fs, b) ((b) >> (fs)->lfs_fsbtodb)
1041#endif 1129#endif
1042 1130
1043#define lfs_lblkno(fs, loc) ((loc) >> (fs)->lfs_bshift) 1131#define lfs_lblkno(fs, loc) ((loc) >> (fs)->lfs_bshift)
1044#define lfs_lblktosize(fs, blk) ((blk) << (fs)->lfs_bshift) 1132#define lfs_lblktosize(fs, blk) ((blk) << (fs)->lfs_bshift)
1045 1133
1046#define lfs_fsbtob(fs, b) ((b) << (fs)->lfs_ffshift) 1134#define lfs_fsbtob(fs, b) ((b) << (fs)->lfs_ffshift)
1047#define lfs_btofsb(fs, b) ((b) >> (fs)->lfs_ffshift) 1135#define lfs_btofsb(fs, b) ((b) >> (fs)->lfs_ffshift)
1048 1136
1049#define lfs_numfrags(fs, loc) /* calculates (loc / fs->lfs_fsize) */ \ 1137#define lfs_numfrags(fs, loc) /* calculates (loc / fs->lfs_fsize) */ \
1050 ((loc) >> (fs)->lfs_ffshift) 1138 ((loc) >> (fs)->lfs_ffshift)
1051#define lfs_blkroundup(fs, size)/* calculates roundup(size, fs->lfs_bsize) */ \ 1139#define lfs_blkroundup(fs, size)/* calculates roundup(size, lfs_sb_getbsize(fs)) */ \
1052 ((off_t)(((size) + (fs)->lfs_bmask) & (~(fs)->lfs_bmask))) 1140 ((off_t)(((size) + (fs)->lfs_bmask) & (~(fs)->lfs_bmask)))
1053#define lfs_fragroundup(fs, size)/* calculates roundup(size, fs->lfs_fsize) */ \ 1141#define lfs_fragroundup(fs, size)/* calculates roundup(size, fs->lfs_fsize) */ \
1054 ((off_t)(((size) + (fs)->lfs_ffmask) & (~(fs)->lfs_ffmask))) 1142 ((off_t)(((size) + (fs)->lfs_ffmask) & (~(fs)->lfs_ffmask)))
1055#define lfs_fragstoblks(fs, frags)/* calculates (frags / fs->fs_frag) */ \ 1143#define lfs_fragstoblks(fs, frags)/* calculates (frags / fs->fs_frag) */ \
1056 ((frags) >> (fs)->lfs_fbshift) 1144 ((frags) >> (fs)->lfs_fbshift)
1057#define lfs_blkstofrags(fs, blks)/* calculates (blks * fs->fs_frag) */ \ 1145#define lfs_blkstofrags(fs, blks)/* calculates (blks * fs->fs_frag) */ \
1058 ((blks) << (fs)->lfs_fbshift) 1146 ((blks) << (fs)->lfs_fbshift)
1059#define lfs_fragnum(fs, fsb) /* calculates (fsb % fs->lfs_frag) */ \ 1147#define lfs_fragnum(fs, fsb) /* calculates (fsb % fs->lfs_frag) */ \
1060 ((fsb) & ((fs)->lfs_frag - 1)) 1148 ((fsb) & ((fs)->lfs_frag - 1))
1061#define lfs_blknum(fs, fsb) /* calculates rounddown(fsb, fs->lfs_frag) */ \ 1149#define lfs_blknum(fs, fsb) /* calculates rounddown(fsb, fs->lfs_frag) */ \
1062 ((fsb) &~ ((fs)->lfs_frag - 1)) 1150 ((fsb) &~ ((fs)->lfs_frag - 1))
1063#define lfs_dblksize(fs, dp, lbn) \ 1151#define lfs_dblksize(fs, dp, lbn) \
1064 (((lbn) >= ULFS_NDADDR || (dp)->di_size >= ((lbn) + 1) << (fs)->lfs_bshift)\ 1152 (((lbn) >= ULFS_NDADDR || (dp)->di_size >= ((lbn) + 1) << (fs)->lfs_bshift)\
1065 ? (fs)->lfs_bsize \ 1153 ? lfs_sb_getbsize(fs) \
1066 : (lfs_fragroundup(fs, lfs_blkoff(fs, (dp)->di_size)))) 1154 : (lfs_fragroundup(fs, lfs_blkoff(fs, (dp)->di_size))))
1067 1155
1068#define lfs_segsize(fs) ((fs)->lfs_version == 1 ? \ 1156#define lfs_segsize(fs) ((fs)->lfs_version == 1 ? \
1069 lfs_lblktosize((fs), (fs)->lfs_ssize) : \ 1157 lfs_lblktosize((fs), lfs_sb_getssize(fs)) : \
1070 (fs)->lfs_ssize) 1158 lfs_sb_getssize(fs))
1071#define lfs_segtod(fs, seg) (((fs)->lfs_version == 1 ? \ 1159#define lfs_segtod(fs, seg) (((fs)->lfs_version == 1 ? \
1072 (fs)->lfs_ssize << (fs)->lfs_blktodb : \ 1160 lfs_sb_getssize(fs) << (fs)->lfs_blktodb : \
1073 lfs_btofsb((fs), (fs)->lfs_ssize)) * (seg)) 1161 lfs_btofsb((fs), lfs_sb_getssize(fs))) * (seg))
1074#define lfs_dtosn(fs, daddr) /* block address to segment number */ \ 1162#define lfs_dtosn(fs, daddr) /* block address to segment number */ \
1075 ((uint32_t)(((daddr) - (fs)->lfs_s0addr) / lfs_segtod((fs), 1))) 1163 ((uint32_t)(((daddr) - (fs)->lfs_s0addr) / lfs_segtod((fs), 1)))
1076#define lfs_sntod(fs, sn) /* segment number to disk address */ \ 1164#define lfs_sntod(fs, sn) /* segment number to disk address */ \
1077 ((daddr_t)(lfs_segtod((fs), (sn)) + (fs)->lfs_s0addr)) 1165 ((daddr_t)(lfs_segtod((fs), (sn)) + (fs)->lfs_s0addr))
1078 1166
1079/* 1167/*
1080 * Structures used by lfs_bmapv and lfs_markv to communicate information 1168 * Structures used by lfs_bmapv and lfs_markv to communicate information
1081 * about inodes and data blocks. 1169 * about inodes and data blocks.
1082 */ 1170 */
1083typedef struct block_info { 1171typedef struct block_info {
1084 u_int32_t bi_inode; /* inode # */ 1172 u_int32_t bi_inode; /* inode # */
1085 int32_t bi_lbn; /* logical block w/in file */ 1173 int32_t bi_lbn; /* logical block w/in file */
1086 int32_t bi_daddr; /* disk address of block */ 1174 int32_t bi_daddr; /* disk address of block */
@@ -1144,57 +1232,57 @@ struct segment { @@ -1144,57 +1232,57 @@ struct segment {
1144 * or more simply 1232 * or more simply
1145 * E = (C * M) / T 1233 * E = (C * M) / T
1146 * 1234 *
1147 * where 1235 * where
1148 * C is the clean space, 1236 * C is the clean space,
1149 * D is the dirty space, 1237 * D is the dirty space,
1150 * M is the dirty metadata, and 1238 * M is the dirty metadata, and
1151 * T = C + D is the total space on disk. 1239 * T = C + D is the total space on disk.
1152 * 1240 *
1153 * This approximates the old formula of E = C * M / D when D is close to T, 1241 * This approximates the old formula of E = C * M / D when D is close to T,
1154 * but avoids falsely reporting "disk full" when the sample size (D) is small. 1242 * but avoids falsely reporting "disk full" when the sample size (D) is small.
1155 */ 1243 */
1156#define LFS_EST_CMETA(F) (int32_t)(( \ 1244#define LFS_EST_CMETA(F) (int32_t)(( \
1157 ((F)->lfs_dmeta * (int64_t)(F)->lfs_nclean) / \ 1245 (lfs_sb_getdmeta(F) * (int64_t)lfs_sb_getnclean(F)) / \
1158 ((F)->lfs_nseg))) 1246 (lfs_sb_getnseg(F))))
1159 1247
1160/* Estimate total size of the disk not including metadata */ 1248/* Estimate total size of the disk not including metadata */
1161#define LFS_EST_NONMETA(F) ((F)->lfs_dsize - (F)->lfs_dmeta - LFS_EST_CMETA(F)) 1249#define LFS_EST_NONMETA(F) (lfs_sb_getdsize(F) - lfs_sb_getdmeta(F) - LFS_EST_CMETA(F))
1162 1250
1163/* Estimate number of blocks actually available for writing */ 1251/* Estimate number of blocks actually available for writing */
1164#define LFS_EST_BFREE(F) ((F)->lfs_bfree > LFS_EST_CMETA(F) ? \ 1252#define LFS_EST_BFREE(F) (lfs_sb_getbfree(F) > LFS_EST_CMETA(F) ? \
1165 (F)->lfs_bfree - LFS_EST_CMETA(F) : 0) 1253 lfs_sb_getbfree(F) - LFS_EST_CMETA(F) : 0)
1166 1254
1167/* Amount of non-meta space not available to mortal man */ 1255/* Amount of non-meta space not available to mortal man */
1168#define LFS_EST_RSVD(F) (int32_t)((LFS_EST_NONMETA(F) * \ 1256#define LFS_EST_RSVD(F) (int32_t)((LFS_EST_NONMETA(F) * \
1169 (u_int64_t)(F)->lfs_minfree) / \ 1257 (u_int64_t)lfs_sb_getminfree(F)) / \
1170 100) 1258 100)
1171 1259
1172/* Can credential C write BB blocks */ 1260/* Can credential C write BB blocks */
1173#define ISSPACE(F, BB, C) \ 1261#define ISSPACE(F, BB, C) \
1174 ((((C) == NOCRED || kauth_cred_geteuid(C) == 0) && \ 1262 ((((C) == NOCRED || kauth_cred_geteuid(C) == 0) && \
1175 LFS_EST_BFREE(F) >= (BB)) || \ 1263 LFS_EST_BFREE(F) >= (BB)) || \
1176 (kauth_cred_geteuid(C) != 0 && IS_FREESPACE(F, BB))) 1264 (kauth_cred_geteuid(C) != 0 && IS_FREESPACE(F, BB)))
1177 1265
1178/* Can an ordinary user write BB blocks */ 1266/* Can an ordinary user write BB blocks */
1179#define IS_FREESPACE(F, BB) \ 1267#define IS_FREESPACE(F, BB) \
1180 (LFS_EST_BFREE(F) >= (BB) + LFS_EST_RSVD(F)) 1268 (LFS_EST_BFREE(F) >= (BB) + LFS_EST_RSVD(F))
1181 1269
1182/* 1270/*
1183 * The minimum number of blocks to create a new inode. This is: 1271 * The minimum number of blocks to create a new inode. This is:
1184 * directory direct block (1) + ULFS_NIADDR indirect blocks + inode block (1) + 1272 * directory direct block (1) + ULFS_NIADDR indirect blocks + inode block (1) +
1185 * ifile direct block (1) + ULFS_NIADDR indirect blocks = 3 + 2 * ULFS_NIADDR blocks. 1273 * ifile direct block (1) + ULFS_NIADDR indirect blocks = 3 + 2 * ULFS_NIADDR blocks.
1186 */ 1274 */
1187#define LFS_NRESERVE(F) (lfs_btofsb((F), (2 * ULFS_NIADDR + 3) << (F)->lfs_bshift)) 1275#define LFS_NRESERVE(F) (lfs_btofsb((F), (2 * ULFS_NIADDR + 3) << lfs_sb_getbshift(F)))
1188 1276
1189/* Statistics Counters */ 1277/* Statistics Counters */
1190struct lfs_stats { /* Must match sysctl list in lfs_vfsops.h ! */ 1278struct lfs_stats { /* Must match sysctl list in lfs_vfsops.h ! */
1191 u_int segsused; 1279 u_int segsused;
1192 u_int psegwrites; 1280 u_int psegwrites;
1193 u_int psyncwrites; 1281 u_int psyncwrites;
1194 u_int pcleanwrites; 1282 u_int pcleanwrites;
1195 u_int blocktot; 1283 u_int blocktot;
1196 u_int cleanblocks; 1284 u_int cleanblocks;
1197 u_int ncheckpoints; 1285 u_int ncheckpoints;
1198 u_int nwrites; 1286 u_int nwrites;
1199 u_int nsync_writes; 1287 u_int nsync_writes;
1200 u_int wait_exceeded; 1288 u_int wait_exceeded;

cvs diff -r1.121 -r1.122 src/sys/ufs/lfs/lfs_alloc.c (expand / switch to unified diff)

--- src/sys/ufs/lfs/lfs_alloc.c 2015/07/16 08:31:45 1.121
+++ src/sys/ufs/lfs/lfs_alloc.c 2015/07/24 06:56:42 1.122
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lfs_alloc.c,v 1.121 2015/07/16 08:31:45 dholland Exp $ */ 1/* $NetBSD: lfs_alloc.c,v 1.122 2015/07/24 06:56:42 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant@hhhh.org>. 8 * by Konrad E. Schroder <perseant@hhhh.org>.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -50,27 +50,27 @@ @@ -50,27 +50,27 @@
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE. 57 * SUCH DAMAGE.
58 * 58 *
59 * @(#)lfs_alloc.c 8.4 (Berkeley) 1/4/94 59 * @(#)lfs_alloc.c 8.4 (Berkeley) 1/4/94
60 */ 60 */
61 61
62#include <sys/cdefs.h> 62#include <sys/cdefs.h>
63__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.121 2015/07/16 08:31:45 dholland Exp $"); 63__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.122 2015/07/24 06:56:42 dholland Exp $");
64 64
65#if defined(_KERNEL_OPT) 65#if defined(_KERNEL_OPT)
66#include "opt_quota.h" 66#include "opt_quota.h"
67#endif 67#endif
68 68
69#include <sys/param.h> 69#include <sys/param.h>
70#include <sys/systm.h> 70#include <sys/systm.h>
71#include <sys/kernel.h> 71#include <sys/kernel.h>
72#include <sys/buf.h> 72#include <sys/buf.h>
73#include <sys/lock.h> 73#include <sys/lock.h>
74#include <sys/vnode.h> 74#include <sys/vnode.h>
75#include <sys/syslog.h> 75#include <sys/syslog.h>
76#include <sys/mount.h> 76#include <sys/mount.h>
@@ -118,57 +118,57 @@ lfs_extend_ifile(struct lfs *fs, kauth_c @@ -118,57 +118,57 @@ lfs_extend_ifile(struct lfs *fs, kauth_c
118 IFILE *ifp; 118 IFILE *ifp;
119 IFILE_V1 *ifp_v1; 119 IFILE_V1 *ifp_v1;
120 struct buf *bp, *cbp; 120 struct buf *bp, *cbp;
121 int error; 121 int error;
122 daddr_t i, blkno, xmax; 122 daddr_t i, blkno, xmax;
123 ino_t oldlast, maxino; 123 ino_t oldlast, maxino;
124 CLEANERINFO *cip; 124 CLEANERINFO *cip;
125 125
126 ASSERT_SEGLOCK(fs); 126 ASSERT_SEGLOCK(fs);
127 127
128 vp = fs->lfs_ivnode; 128 vp = fs->lfs_ivnode;
129 ip = VTOI(vp); 129 ip = VTOI(vp);
130 blkno = lfs_lblkno(fs, ip->i_size); 130 blkno = lfs_lblkno(fs, ip->i_size);
131 if ((error = lfs_balloc(vp, ip->i_size, fs->lfs_bsize, cred, 0, 131 if ((error = lfs_balloc(vp, ip->i_size, lfs_sb_getbsize(fs), cred, 0,
132 &bp)) != 0) { 132 &bp)) != 0) {
133 return (error); 133 return (error);
134 } 134 }
135 ip->i_size += fs->lfs_bsize; 135 ip->i_size += lfs_sb_getbsize(fs);
136 ip->i_ffs1_size = ip->i_size; 136 ip->i_ffs1_size = ip->i_size;
137 uvm_vnp_setsize(vp, ip->i_size); 137 uvm_vnp_setsize(vp, ip->i_size);
138 138
139 maxino = ((ip->i_size >> fs->lfs_bshift) - fs->lfs_cleansz - 139 maxino = ((ip->i_size >> fs->lfs_bshift) - lfs_sb_getcleansz(fs) -
140 fs->lfs_segtabsz) * fs->lfs_ifpb; 140 lfs_sb_getsegtabsz(fs)) * lfs_sb_getifpb(fs);
141 fs->lfs_ino_bitmap = (lfs_bm_t *) 141 fs->lfs_ino_bitmap = (lfs_bm_t *)
142 realloc(fs->lfs_ino_bitmap, ((maxino + BMMASK) >> BMSHIFT) * 142 realloc(fs->lfs_ino_bitmap, ((maxino + BMMASK) >> BMSHIFT) *
143 sizeof(lfs_bm_t), M_SEGMENT, M_WAITOK); 143 sizeof(lfs_bm_t), M_SEGMENT, M_WAITOK);
144 KASSERT(fs->lfs_ino_bitmap != NULL); 144 KASSERT(fs->lfs_ino_bitmap != NULL);
145 145
146 i = (blkno - fs->lfs_segtabsz - fs->lfs_cleansz) * 146 i = (blkno - lfs_sb_getsegtabsz(fs) - lfs_sb_getcleansz(fs)) *
147 fs->lfs_ifpb; 147 lfs_sb_getifpb(fs);
148 148
149 /* 149 /*
150 * We insert the new inodes at the head of the free list. 150 * We insert the new inodes at the head of the free list.
151 * Under normal circumstances, the free list is empty here, 151 * Under normal circumstances, the free list is empty here,
152 * so we are also incidentally placing them at the end (which 152 * so we are also incidentally placing them at the end (which
153 * we must do if we are to keep them in order). 153 * we must do if we are to keep them in order).
154 */ 154 */
155 LFS_GET_HEADFREE(fs, cip, cbp, &oldlast); 155 LFS_GET_HEADFREE(fs, cip, cbp, &oldlast);
156 LFS_PUT_HEADFREE(fs, cip, cbp, i); 156 LFS_PUT_HEADFREE(fs, cip, cbp, i);
157#ifdef DIAGNOSTIC 157#ifdef DIAGNOSTIC
158 if (fs->lfs_freehd == LFS_UNUSED_INUM) 158 if (lfs_sb_getfreehd(fs) == LFS_UNUSED_INUM)
159 panic("inode 0 allocated [2]"); 159 panic("inode 0 allocated [2]");
160#endif /* DIAGNOSTIC */ 160#endif /* DIAGNOSTIC */
161 xmax = i + fs->lfs_ifpb; 161 xmax = i + lfs_sb_getifpb(fs);
162 162
163 if (fs->lfs_version == 1) { 163 if (fs->lfs_version == 1) {
164 for (ifp_v1 = (IFILE_V1 *)bp->b_data; i < xmax; ++ifp_v1) { 164 for (ifp_v1 = (IFILE_V1 *)bp->b_data; i < xmax; ++ifp_v1) {
165 SET_BITMAP_FREE(fs, i); 165 SET_BITMAP_FREE(fs, i);
166 ifp_v1->if_version = 1; 166 ifp_v1->if_version = 1;
167 ifp_v1->if_daddr = LFS_UNUSED_DADDR; 167 ifp_v1->if_daddr = LFS_UNUSED_DADDR;
168 ifp_v1->if_nextfree = ++i; 168 ifp_v1->if_nextfree = ++i;
169 } 169 }
170 ifp_v1--; 170 ifp_v1--;
171 ifp_v1->if_nextfree = oldlast; 171 ifp_v1->if_nextfree = oldlast;
172 } else { 172 } else {
173 for (ifp = (IFILE *)bp->b_data; i < xmax; ++ifp) { 173 for (ifp = (IFILE *)bp->b_data; i < xmax; ++ifp) {
174 SET_BITMAP_FREE(fs, i); 174 SET_BITMAP_FREE(fs, i);
@@ -221,63 +221,63 @@ lfs_valloc(struct vnode *pvp, int mode,  @@ -221,63 +221,63 @@ lfs_valloc(struct vnode *pvp, int mode,
221 CLR_BITMAP_FREE(fs, *ino); 221 CLR_BITMAP_FREE(fs, *ino);
222 LFS_IENTRY(ifp, fs, *ino, bp); 222 LFS_IENTRY(ifp, fs, *ino, bp);
223 if (ifp->if_daddr != LFS_UNUSED_DADDR) 223 if (ifp->if_daddr != LFS_UNUSED_DADDR)
224 panic("lfs_valloc: inuse inode %" PRId64 " on the free list", 224 panic("lfs_valloc: inuse inode %" PRId64 " on the free list",
225 *ino); 225 *ino);
226 LFS_PUT_HEADFREE(fs, cip, cbp, ifp->if_nextfree); 226 LFS_PUT_HEADFREE(fs, cip, cbp, ifp->if_nextfree);
227 DLOG((DLOG_ALLOC, "lfs_valloc: headfree %" PRId64 " -> %u\n", 227 DLOG((DLOG_ALLOC, "lfs_valloc: headfree %" PRId64 " -> %u\n",
228 *ino, ifp->if_nextfree)); 228 *ino, ifp->if_nextfree));
229 229
230 *gen = ifp->if_version; /* version was updated by vfree */ 230 *gen = ifp->if_version; /* version was updated by vfree */
231 brelse(bp, 0); 231 brelse(bp, 0);
232 232
233 /* Extend IFILE so that the next lfs_valloc will succeed. */ 233 /* Extend IFILE so that the next lfs_valloc will succeed. */
234 if (fs->lfs_freehd == LFS_UNUSED_INUM) { 234 if (lfs_sb_getfreehd(fs) == LFS_UNUSED_INUM) {
235 if ((error = lfs_extend_ifile(fs, cred)) != 0) { 235 if ((error = lfs_extend_ifile(fs, cred)) != 0) {
236 LFS_PUT_HEADFREE(fs, cip, cbp, *ino); 236 LFS_PUT_HEADFREE(fs, cip, cbp, *ino);
237 lfs_segunlock(fs); 237 lfs_segunlock(fs);
238 return error; 238 return error;
239 } 239 }
240 } 240 }
241#ifdef DIAGNOSTIC 241#ifdef DIAGNOSTIC
242 if (fs->lfs_freehd == LFS_UNUSED_INUM) 242 if (lfs_sb_getfreehd(fs) == LFS_UNUSED_INUM)
243 panic("inode 0 allocated [3]"); 243 panic("inode 0 allocated [3]");
244#endif /* DIAGNOSTIC */ 244#endif /* DIAGNOSTIC */
245 245
246 /* Set superblock modified bit and increment file count. */ 246 /* Set superblock modified bit and increment file count. */
247 mutex_enter(&lfs_lock); 247 mutex_enter(&lfs_lock);
248 fs->lfs_fmod = 1; 248 fs->lfs_fmod = 1;
249 mutex_exit(&lfs_lock); 249 mutex_exit(&lfs_lock);
250 ++fs->lfs_nfiles; 250 lfs_sb_addnfiles(fs, 1);
251 251
252 lfs_segunlock(fs); 252 lfs_segunlock(fs);
253 253
254 return 0; 254 return 0;
255} 255}
256 256
257/* 257/*
258 * Allocate a new inode with given inode number and version. 258 * Allocate a new inode with given inode number and version.
259 */ 259 */
260int 260int
261lfs_valloc_fixed(struct lfs *fs, ino_t ino, int vers) 261lfs_valloc_fixed(struct lfs *fs, ino_t ino, int vers)
262{ 262{
263 IFILE *ifp; 263 IFILE *ifp;
264 struct buf *bp, *cbp; 264 struct buf *bp, *cbp;
265 ino_t tino, oldnext; 265 ino_t tino, oldnext;
266 CLEANERINFO *cip; 266 CLEANERINFO *cip;
267 267
268 /* If the Ifile is too short to contain this inum, extend it */ 268 /* If the Ifile is too short to contain this inum, extend it */
269 while (VTOI(fs->lfs_ivnode)->i_size <= (ino / 269 while (VTOI(fs->lfs_ivnode)->i_size <= (ino /
270 fs->lfs_ifpb + fs->lfs_cleansz + fs->lfs_segtabsz) 270 lfs_sb_getifpb(fs) + lfs_sb_getcleansz(fs) + lfs_sb_getsegtabsz(fs))
271 << fs->lfs_bshift) { 271 << fs->lfs_bshift) {
272 lfs_extend_ifile(fs, NOCRED); 272 lfs_extend_ifile(fs, NOCRED);
273 } 273 }
274 274
275 LFS_IENTRY(ifp, fs, ino, bp); 275 LFS_IENTRY(ifp, fs, ino, bp);
276 oldnext = ifp->if_nextfree; 276 oldnext = ifp->if_nextfree;
277 ifp->if_version = vers; 277 ifp->if_version = vers;
278 brelse(bp, 0); 278 brelse(bp, 0);
279 279
280 LFS_GET_HEADFREE(fs, cip, cbp, &ino); 280 LFS_GET_HEADFREE(fs, cip, cbp, &ino);
281 if (ino) { 281 if (ino) {
282 LFS_PUT_HEADFREE(fs, cip, cbp, oldnext); 282 LFS_PUT_HEADFREE(fs, cip, cbp, oldnext);
283 } else { 283 } else {
@@ -302,61 +302,61 @@ lfs_valloc_fixed(struct lfs *fs, ino_t i @@ -302,61 +302,61 @@ lfs_valloc_fixed(struct lfs *fs, ino_t i
302} 302}
303 303
304#if 0 304#if 0
305/* 305/*
306 * Find the highest-numbered allocated inode. 306 * Find the highest-numbered allocated inode.
307 * This will be used to shrink the Ifile. 307 * This will be used to shrink the Ifile.
308 */ 308 */
309static inline ino_t 309static inline ino_t
310lfs_last_alloc_ino(struct lfs *fs) 310lfs_last_alloc_ino(struct lfs *fs)
311{ 311{
312 ino_t ino, maxino; 312 ino_t ino, maxino;
313 313
314 maxino = ((fs->lfs_ivnode->v_size >> fs->lfs_bshift) - 314 maxino = ((fs->lfs_ivnode->v_size >> fs->lfs_bshift) -
315 fs->lfs_cleansz - fs->lfs_segtabsz) * fs->lfs_ifpb; 315 lfs_sb_getcleansz(fs) - lfs_sb_getsegtabsz(fs)) * fs->lfs_ifpb;
316 for (ino = maxino - 1; ino > LFS_UNUSED_INUM; --ino) { 316 for (ino = maxino - 1; ino > LFS_UNUSED_INUM; --ino) {
317 if (ISSET_BITMAP_FREE(fs, ino) == 0) 317 if (ISSET_BITMAP_FREE(fs, ino) == 0)
318 break; 318 break;
319 } 319 }
320 return ino; 320 return ino;
321} 321}
322#endif 322#endif
323 323
324/* 324/*
325 * Find the previous (next lowest numbered) free inode, if any. 325 * Find the previous (next lowest numbered) free inode, if any.
326 * If there is none, return LFS_UNUSED_INUM. 326 * If there is none, return LFS_UNUSED_INUM.
327 */ 327 */
328static inline ino_t 328static inline ino_t
329lfs_freelist_prev(struct lfs *fs, ino_t ino) 329lfs_freelist_prev(struct lfs *fs, ino_t ino)
330{ 330{
331 ino_t tino, bound, bb, freehdbb; 331 ino_t tino, bound, bb, freehdbb;
332 332
333 if (fs->lfs_freehd == LFS_UNUSED_INUM) /* No free inodes at all */ 333 if (lfs_sb_getfreehd(fs) == LFS_UNUSED_INUM) /* No free inodes at all */
334 return LFS_UNUSED_INUM; 334 return LFS_UNUSED_INUM;
335 335
336 /* Search our own word first */ 336 /* Search our own word first */
337 bound = ino & ~BMMASK; 337 bound = ino & ~BMMASK;
338 for (tino = ino - 1; tino >= bound && tino > LFS_UNUSED_INUM; tino--) 338 for (tino = ino - 1; tino >= bound && tino > LFS_UNUSED_INUM; tino--)
339 if (ISSET_BITMAP_FREE(fs, tino)) 339 if (ISSET_BITMAP_FREE(fs, tino))
340 return tino; 340 return tino;
341 /* If there are no lower words to search, just return */ 341 /* If there are no lower words to search, just return */
342 if (ino >> BMSHIFT == 0) 342 if (ino >> BMSHIFT == 0)
343 return LFS_UNUSED_INUM; 343 return LFS_UNUSED_INUM;
344 344
345 /* 345 /*
346 * Find a word with a free inode in it. We have to be a bit 346 * Find a word with a free inode in it. We have to be a bit
347 * careful here since ino_t is unsigned. 347 * careful here since ino_t is unsigned.
348 */ 348 */
349 freehdbb = (fs->lfs_freehd >> BMSHIFT); 349 freehdbb = (lfs_sb_getfreehd(fs) >> BMSHIFT);
350 for (bb = (ino >> BMSHIFT) - 1; bb >= freehdbb && bb > 0; --bb) 350 for (bb = (ino >> BMSHIFT) - 1; bb >= freehdbb && bb > 0; --bb)
351 if (fs->lfs_ino_bitmap[bb]) 351 if (fs->lfs_ino_bitmap[bb])
352 break; 352 break;
353 if (fs->lfs_ino_bitmap[bb] == 0) 353 if (fs->lfs_ino_bitmap[bb] == 0)
354 return LFS_UNUSED_INUM; 354 return LFS_UNUSED_INUM;
355 355
356 /* Search the word we found */ 356 /* Search the word we found */
357 for (tino = (bb << BMSHIFT) | BMMASK; tino >= (bb << BMSHIFT) && 357 for (tino = (bb << BMSHIFT) | BMMASK; tino >= (bb << BMSHIFT) &&
358 tino > LFS_UNUSED_INUM; tino--) 358 tino > LFS_UNUSED_INUM; tino--)
359 if (ISSET_BITMAP_FREE(fs, tino)) 359 if (ISSET_BITMAP_FREE(fs, tino))
360 break; 360 break;
361 361
362 if (tino <= LFS_IFILE_INUM) 362 if (tino <= LFS_IFILE_INUM)
@@ -518,61 +518,61 @@ lfs_vfree(struct vnode *vp, ino_t ino, i @@ -518,61 +518,61 @@ lfs_vfree(struct vnode *vp, ino_t ino, i
518 sup->su_nbytes); 518 sup->su_nbytes);
519 panic("lfs_vfree: negative byte count"); 519 panic("lfs_vfree: negative byte count");
520 sup->su_nbytes = sizeof (struct ulfs1_dinode); 520 sup->su_nbytes = sizeof (struct ulfs1_dinode);
521 } 521 }
522#endif 522#endif
523 sup->su_nbytes -= sizeof (struct ulfs1_dinode); 523 sup->su_nbytes -= sizeof (struct ulfs1_dinode);
524 LFS_WRITESEGENTRY(sup, fs, lfs_dtosn(fs, old_iaddr), bp); /* Ifile */ 524 LFS_WRITESEGENTRY(sup, fs, lfs_dtosn(fs, old_iaddr), bp); /* Ifile */
525 } 525 }
526 526
527 /* Set superblock modified bit and decrement file count. */ 527 /* Set superblock modified bit and decrement file count. */
528 mutex_enter(&lfs_lock); 528 mutex_enter(&lfs_lock);
529 fs->lfs_fmod = 1; 529 fs->lfs_fmod = 1;
530 mutex_exit(&lfs_lock); 530 mutex_exit(&lfs_lock);
531 --fs->lfs_nfiles; 531 lfs_sb_subnfiles(fs, 1);
532 532
533 lfs_segunlock(fs); 533 lfs_segunlock(fs);
534 534
535 return (0); 535 return (0);
536} 536}
537 537
538/* 538/*
539 * Sort the freelist and set up the free-inode bitmap. 539 * Sort the freelist and set up the free-inode bitmap.
540 * To be called by lfs_mountfs(). 540 * To be called by lfs_mountfs().
541 */ 541 */
542void 542void
543lfs_order_freelist(struct lfs *fs) 543lfs_order_freelist(struct lfs *fs)
544{ 544{
545 CLEANERINFO *cip; 545 CLEANERINFO *cip;
546 IFILE *ifp = NULL; 546 IFILE *ifp = NULL;
547 struct buf *bp; 547 struct buf *bp;
548 ino_t ino, firstino, lastino, maxino; 548 ino_t ino, firstino, lastino, maxino;
549#ifdef notyet 549#ifdef notyet
550 struct vnode *vp; 550 struct vnode *vp;
551#endif 551#endif
552  552
553 ASSERT_NO_SEGLOCK(fs); 553 ASSERT_NO_SEGLOCK(fs);
554 lfs_seglock(fs, SEGM_PROT); 554 lfs_seglock(fs, SEGM_PROT);
555 555
556 maxino = ((fs->lfs_ivnode->v_size >> fs->lfs_bshift) - 556 maxino = ((fs->lfs_ivnode->v_size >> fs->lfs_bshift) -
557 fs->lfs_cleansz - fs->lfs_segtabsz) * fs->lfs_ifpb; 557 lfs_sb_getcleansz(fs) - lfs_sb_getsegtabsz(fs)) * lfs_sb_getifpb(fs);
558 fs->lfs_ino_bitmap = 558 fs->lfs_ino_bitmap =
559 malloc(((maxino + BMMASK) >> BMSHIFT) * sizeof(lfs_bm_t), 559 malloc(((maxino + BMMASK) >> BMSHIFT) * sizeof(lfs_bm_t),
560 M_SEGMENT, M_WAITOK | M_ZERO); 560 M_SEGMENT, M_WAITOK | M_ZERO);
561 KASSERT(fs->lfs_ino_bitmap != NULL); 561 KASSERT(fs->lfs_ino_bitmap != NULL);
562 562
563 firstino = lastino = LFS_UNUSED_INUM; 563 firstino = lastino = LFS_UNUSED_INUM;
564 for (ino = 0; ino < maxino; ino++) { 564 for (ino = 0; ino < maxino; ino++) {
565 if (ino % fs->lfs_ifpb == 0) 565 if (ino % lfs_sb_getifpb(fs) == 0)
566 LFS_IENTRY(ifp, fs, ino, bp); 566 LFS_IENTRY(ifp, fs, ino, bp);
567 else 567 else
568 ++ifp; 568 ++ifp;
569 569
570 /* Don't put zero or ifile on the free list */ 570 /* Don't put zero or ifile on the free list */
571 if (ino == LFS_UNUSED_INUM || ino == LFS_IFILE_INUM) 571 if (ino == LFS_UNUSED_INUM || ino == LFS_IFILE_INUM)
572 continue; 572 continue;
573 573
574#ifdef notyet 574#ifdef notyet
575 /* Address orphaned files */ 575 /* Address orphaned files */
576 if (ifp->if_nextfree == LFS_ORPHAN_NEXTFREE && 576 if (ifp->if_nextfree == LFS_ORPHAN_NEXTFREE &&
577 VFS_VGET(fs->lfs_ivnode->v_mount, ino, &vp) == 0) { 577 VFS_VGET(fs->lfs_ivnode->v_mount, ino, &vp) == 0) {
578 lfs_truncate(vp, 0, 0, NOCRED); 578 lfs_truncate(vp, 0, 0, NOCRED);
@@ -596,27 +596,27 @@ lfs_order_freelist(struct lfs *fs) @@ -596,27 +596,27 @@ lfs_order_freelist(struct lfs *fs)
596 brelse(bp, 0); 596 brelse(bp, 0);
597 597
598 LFS_IENTRY(ifp, fs, lastino, bp); 598 LFS_IENTRY(ifp, fs, lastino, bp);
599 ifp->if_nextfree = ino; 599 ifp->if_nextfree = ino;
600 LFS_BWRITE_LOG(bp); 600 LFS_BWRITE_LOG(bp);
601  601
602 LFS_IENTRY(ifp, fs, ino, bp); 602 LFS_IENTRY(ifp, fs, ino, bp);
603 } 603 }
604 lastino = ino; 604 lastino = ino;
605 605
606 SET_BITMAP_FREE(fs, ino); 606 SET_BITMAP_FREE(fs, ino);
607 } 607 }
608 608
609 if ((ino + 1) % fs->lfs_ifpb == 0) 609 if ((ino + 1) % lfs_sb_getifpb(fs) == 0)
610 brelse(bp, 0); 610 brelse(bp, 0);
611 } 611 }
612 612
613 LFS_PUT_HEADFREE(fs, cip, bp, firstino); 613 LFS_PUT_HEADFREE(fs, cip, bp, firstino);
614 LFS_PUT_TAILFREE(fs, cip, bp, lastino); 614 LFS_PUT_TAILFREE(fs, cip, bp, lastino);
615 615
616 lfs_segunlock(fs); 616 lfs_segunlock(fs);
617} 617}
618 618
619void 619void
620lfs_orphan(struct lfs *fs, ino_t ino) 620lfs_orphan(struct lfs *fs, ino_t ino)
621{ 621{
622 IFILE *ifp; 622 IFILE *ifp;

cvs diff -r1.81 -r1.82 src/sys/ufs/lfs/lfs_balloc.c (expand / switch to unified diff)

--- src/sys/ufs/lfs/lfs_balloc.c 2015/03/28 19:24:05 1.81
+++ src/sys/ufs/lfs/lfs_balloc.c 2015/07/24 06:56:42 1.82
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lfs_balloc.c,v 1.81 2015/03/28 19:24:05 maxv Exp $ */ 1/* $NetBSD: lfs_balloc.c,v 1.82 2015/07/24 06:56:42 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant@hhhh.org>. 8 * by Konrad E. Schroder <perseant@hhhh.org>.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -50,27 +50,27 @@ @@ -50,27 +50,27 @@
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE. 57 * SUCH DAMAGE.
58 * 58 *
59 * @(#)lfs_balloc.c 8.4 (Berkeley) 5/8/95 59 * @(#)lfs_balloc.c 8.4 (Berkeley) 5/8/95
60 */ 60 */
61 61
62#include <sys/cdefs.h> 62#include <sys/cdefs.h>
63__KERNEL_RCSID(0, "$NetBSD: lfs_balloc.c,v 1.81 2015/03/28 19:24:05 maxv Exp $"); 63__KERNEL_RCSID(0, "$NetBSD: lfs_balloc.c,v 1.82 2015/07/24 06:56:42 dholland Exp $");
64 64
65#if defined(_KERNEL_OPT) 65#if defined(_KERNEL_OPT)
66#include "opt_quota.h" 66#include "opt_quota.h"
67#endif 67#endif
68 68
69#include <sys/param.h> 69#include <sys/param.h>
70#include <sys/systm.h> 70#include <sys/systm.h>
71#include <sys/buf.h> 71#include <sys/buf.h>
72#include <sys/proc.h> 72#include <sys/proc.h>
73#include <sys/vnode.h> 73#include <sys/vnode.h>
74#include <sys/mount.h> 74#include <sys/mount.h>
75#include <sys/resourcevar.h> 75#include <sys/resourcevar.h>
76#include <sys/tree.h> 76#include <sys/tree.h>
@@ -115,27 +115,27 @@ lfs_balloc(struct vnode *vp, off_t start @@ -115,27 +115,27 @@ lfs_balloc(struct vnode *vp, off_t start
115 int offset; 115 int offset;
116 daddr_t daddr, idaddr; 116 daddr_t daddr, idaddr;
117 struct buf *ibp, *bp; 117 struct buf *ibp, *bp;
118 struct inode *ip; 118 struct inode *ip;
119 struct lfs *fs; 119 struct lfs *fs;
120 struct indir indirs[ULFS_NIADDR+2], *idp; 120 struct indir indirs[ULFS_NIADDR+2], *idp;
121 daddr_t lbn, lastblock; 121 daddr_t lbn, lastblock;
122 int bcount; 122 int bcount;
123 int error, frags, i, nsize, osize, num; 123 int error, frags, i, nsize, osize, num;
124 124
125 ip = VTOI(vp); 125 ip = VTOI(vp);
126 fs = ip->i_lfs; 126 fs = ip->i_lfs;
127 offset = lfs_blkoff(fs, startoffset); 127 offset = lfs_blkoff(fs, startoffset);
128 KASSERT(iosize <= fs->lfs_bsize); 128 KASSERT(iosize <= lfs_sb_getbsize(fs));
129 lbn = lfs_lblkno(fs, startoffset); 129 lbn = lfs_lblkno(fs, startoffset);
130 /* (void)lfs_check(vp, lbn, 0); */ 130 /* (void)lfs_check(vp, lbn, 0); */
131 131
132 ASSERT_MAYBE_SEGLOCK(fs); 132 ASSERT_MAYBE_SEGLOCK(fs);
133 133
134 /* 134 /*
135 * Three cases: it's a block beyond the end of file, it's a block in 135 * Three cases: it's a block beyond the end of file, it's a block in
136 * the file that may or may not have been assigned a disk address or 136 * the file that may or may not have been assigned a disk address or
137 * we're writing an entire block. 137 * we're writing an entire block.
138 * 138 *
139 * Note, if the daddr is UNWRITTEN, the block already exists in 139 * Note, if the daddr is UNWRITTEN, the block already exists in
140 * the cache (it was read or written earlier). If so, make sure 140 * the cache (it was read or written earlier). If so, make sure
141 * we don't count it as a new block or zero out its contents. If 141 * we don't count it as a new block or zero out its contents. If
@@ -144,33 +144,33 @@ lfs_balloc(struct vnode *vp, off_t start @@ -144,33 +144,33 @@ lfs_balloc(struct vnode *vp, off_t start
144 * 144 *
145 * If we are writing a block beyond the end of the file, we need to 145 * If we are writing a block beyond the end of the file, we need to
146 * check if the old last block was a fragment. If it was, we need 146 * check if the old last block was a fragment. If it was, we need
147 * to rewrite it. 147 * to rewrite it.
148 */ 148 */
149 149
150 if (bpp) 150 if (bpp)
151 *bpp = NULL; 151 *bpp = NULL;
152 152
153 /* Check for block beyond end of file and fragment extension needed. */ 153 /* Check for block beyond end of file and fragment extension needed. */
154 lastblock = lfs_lblkno(fs, ip->i_size); 154 lastblock = lfs_lblkno(fs, ip->i_size);
155 if (lastblock < ULFS_NDADDR && lastblock < lbn) { 155 if (lastblock < ULFS_NDADDR && lastblock < lbn) {
156 osize = lfs_blksize(fs, ip, lastblock); 156 osize = lfs_blksize(fs, ip, lastblock);
157 if (osize < fs->lfs_bsize && osize > 0) { 157 if (osize < lfs_sb_getbsize(fs) && osize > 0) {
158 if ((error = lfs_fragextend(vp, osize, fs->lfs_bsize, 158 if ((error = lfs_fragextend(vp, osize, lfs_sb_getbsize(fs),
159 lastblock, 159 lastblock,
160 (bpp ? &bp : NULL), cred))) 160 (bpp ? &bp : NULL), cred)))
161 return (error); 161 return (error);
162 ip->i_ffs1_size = ip->i_size = 162 ip->i_ffs1_size = ip->i_size =
163 (lastblock + 1) * fs->lfs_bsize; 163 (lastblock + 1) * lfs_sb_getbsize(fs);
164 uvm_vnp_setsize(vp, ip->i_size); 164 uvm_vnp_setsize(vp, ip->i_size);
165 ip->i_flag |= IN_CHANGE | IN_UPDATE; 165 ip->i_flag |= IN_CHANGE | IN_UPDATE;
166 if (bpp) 166 if (bpp)
167 (void) VOP_BWRITE(bp->b_vp, bp); 167 (void) VOP_BWRITE(bp->b_vp, bp);
168 } 168 }
169 } 169 }
170 170
171 /* 171 /*
172 * If the block we are writing is a direct block, it's the last 172 * If the block we are writing is a direct block, it's the last
173 * block in the file, and offset + iosize is less than a full 173 * block in the file, and offset + iosize is less than a full
174 * block, we can write one or more fragments. There are two cases: 174 * block, we can write one or more fragments. There are two cases:
175 * the block is brand new and we should allocate it the correct 175 * the block is brand new and we should allocate it the correct
176 * size or it already exists and contains some fragments and 176 * size or it already exists and contains some fragments and
@@ -182,27 +182,27 @@ lfs_balloc(struct vnode *vp, off_t start @@ -182,27 +182,27 @@ lfs_balloc(struct vnode *vp, off_t start
182 if (lfs_lblktosize(fs, lbn) >= ip->i_size) { 182 if (lfs_lblktosize(fs, lbn) >= ip->i_size) {
183 /* Brand new block or fragment */ 183 /* Brand new block or fragment */
184 frags = lfs_numfrags(fs, nsize); 184 frags = lfs_numfrags(fs, nsize);
185 if (!ISSPACE(fs, frags, cred)) 185 if (!ISSPACE(fs, frags, cred))
186 return ENOSPC; 186 return ENOSPC;
187 if (bpp) { 187 if (bpp) {
188 *bpp = bp = getblk(vp, lbn, nsize, 0, 0); 188 *bpp = bp = getblk(vp, lbn, nsize, 0, 0);
189 bp->b_blkno = UNWRITTEN; 189 bp->b_blkno = UNWRITTEN;
190 if (flags & B_CLRBUF) 190 if (flags & B_CLRBUF)
191 clrbuf(bp); 191 clrbuf(bp);
192 } 192 }
193 ip->i_lfs_effnblks += frags; 193 ip->i_lfs_effnblks += frags;
194 mutex_enter(&lfs_lock); 194 mutex_enter(&lfs_lock);
195 fs->lfs_bfree -= frags; 195 lfs_sb_setbfree(fs, lfs_sb_getbfree(fs) - frags);
196 mutex_exit(&lfs_lock); 196 mutex_exit(&lfs_lock);
197 ip->i_ffs1_db[lbn] = UNWRITTEN; 197 ip->i_ffs1_db[lbn] = UNWRITTEN;
198 } else { 198 } else {
199 if (nsize <= osize) { 199 if (nsize <= osize) {
200 /* No need to extend */ 200 /* No need to extend */
201 if (bpp && (error = bread(vp, lbn, osize, 201 if (bpp && (error = bread(vp, lbn, osize,
202 0, &bp))) 202 0, &bp)))
203 return error; 203 return error;
204 } else { 204 } else {
205 /* Extend existing block */ 205 /* Extend existing block */
206 if ((error = 206 if ((error =
207 lfs_fragextend(vp, osize, nsize, lbn, 207 lfs_fragextend(vp, osize, nsize, lbn,
208 (bpp ? &bp : NULL), cred))) 208 (bpp ? &bp : NULL), cred)))
@@ -227,46 +227,46 @@ lfs_balloc(struct vnode *vp, off_t start @@ -227,46 +227,46 @@ lfs_balloc(struct vnode *vp, off_t start
227 */ 227 */
228 frags = fs->um_seqinc; 228 frags = fs->um_seqinc;
229 bcount = 0; 229 bcount = 0;
230 if (daddr == UNASSIGNED) { 230 if (daddr == UNASSIGNED) {
231 bcount = frags; 231 bcount = frags;
232 } 232 }
233 for (i = 1; i < num; ++i) { 233 for (i = 1; i < num; ++i) {
234 if (!indirs[i].in_exists) { 234 if (!indirs[i].in_exists) {
235 bcount += frags; 235 bcount += frags;
236 } 236 }
237 } 237 }
238 if (ISSPACE(fs, bcount, cred)) { 238 if (ISSPACE(fs, bcount, cred)) {
239 mutex_enter(&lfs_lock); 239 mutex_enter(&lfs_lock);
240 fs->lfs_bfree -= bcount; 240 lfs_sb_setbfree(fs, lfs_sb_getbfree(fs) - bcount);
241 mutex_exit(&lfs_lock); 241 mutex_exit(&lfs_lock);
242 ip->i_lfs_effnblks += bcount; 242 ip->i_lfs_effnblks += bcount;
243 } else { 243 } else {
244 return ENOSPC; 244 return ENOSPC;
245 } 245 }
246 246
247 if (daddr == UNASSIGNED) { 247 if (daddr == UNASSIGNED) {
248 if (num > 0 && ip->i_ffs1_ib[indirs[0].in_off] == 0) { 248 if (num > 0 && ip->i_ffs1_ib[indirs[0].in_off] == 0) {
249 ip->i_ffs1_ib[indirs[0].in_off] = UNWRITTEN; 249 ip->i_ffs1_ib[indirs[0].in_off] = UNWRITTEN;
250 } 250 }
251 251
252 /* 252 /*
253 * Create new indirect blocks if necessary 253 * Create new indirect blocks if necessary
254 */ 254 */
255 if (num > 1) { 255 if (num > 1) {
256 idaddr = ip->i_ffs1_ib[indirs[0].in_off]; 256 idaddr = ip->i_ffs1_ib[indirs[0].in_off];
257 for (i = 1; i < num; ++i) { 257 for (i = 1; i < num; ++i) {
258 ibp = getblk(vp, indirs[i].in_lbn, 258 ibp = getblk(vp, indirs[i].in_lbn,
259 fs->lfs_bsize, 0,0); 259 lfs_sb_getbsize(fs), 0,0);
260 if (!indirs[i].in_exists) { 260 if (!indirs[i].in_exists) {
261 clrbuf(ibp); 261 clrbuf(ibp);
262 ibp->b_blkno = UNWRITTEN; 262 ibp->b_blkno = UNWRITTEN;
263 } else if (!(ibp->b_oflags & (BO_DELWRI | BO_DONE))) { 263 } else if (!(ibp->b_oflags & (BO_DELWRI | BO_DONE))) {
264 ibp->b_blkno = LFS_FSBTODB(fs, idaddr); 264 ibp->b_blkno = LFS_FSBTODB(fs, idaddr);
265 ibp->b_flags |= B_READ; 265 ibp->b_flags |= B_READ;
266 VOP_STRATEGY(vp, ibp); 266 VOP_STRATEGY(vp, ibp);
267 biowait(ibp); 267 biowait(ibp);
268 } 268 }
269 /* 269 /*
270 * This block exists, but the next one may not. 270 * This block exists, but the next one may not.
271 * If that is the case mark it UNWRITTEN to keep 271 * If that is the case mark it UNWRITTEN to keep
272 * the accounting straight. 272 * the accounting straight.
@@ -319,47 +319,47 @@ lfs_balloc(struct vnode *vp, off_t start @@ -319,47 +319,47 @@ lfs_balloc(struct vnode *vp, off_t start
319 /* Note the new address */ 319 /* Note the new address */
320 bp->b_blkno = UNWRITTEN; 320 bp->b_blkno = UNWRITTEN;
321 } 321 }
322 322
323 switch (num) { 323 switch (num) {
324 case 0: 324 case 0:
325 ip->i_ffs1_db[lbn] = UNWRITTEN; 325 ip->i_ffs1_db[lbn] = UNWRITTEN;
326 break; 326 break;
327 case 1: 327 case 1:
328 ip->i_ffs1_ib[indirs[0].in_off] = UNWRITTEN; 328 ip->i_ffs1_ib[indirs[0].in_off] = UNWRITTEN;
329 break; 329 break;
330 default: 330 default:
331 idp = &indirs[num - 1]; 331 idp = &indirs[num - 1];
332 if (bread(vp, idp->in_lbn, fs->lfs_bsize, 332 if (bread(vp, idp->in_lbn, lfs_sb_getbsize(fs),
333 B_MODIFY, &ibp)) 333 B_MODIFY, &ibp))
334 panic("lfs_balloc: bread bno %lld", 334 panic("lfs_balloc: bread bno %lld",
335 (long long)idp->in_lbn); 335 (long long)idp->in_lbn);
336 /* XXX ondisk32 */ 336 /* XXX ondisk32 */
337 ((int32_t *)ibp->b_data)[idp->in_off] = UNWRITTEN; 337 ((int32_t *)ibp->b_data)[idp->in_off] = UNWRITTEN;
338#ifdef DEBUG 338#ifdef DEBUG
339 if (vp == fs->lfs_ivnode) { 339 if (vp == fs->lfs_ivnode) {
340 LFS_ENTER_LOG("balloc", __FILE__, 340 LFS_ENTER_LOG("balloc", __FILE__,
341 __LINE__, idp->in_lbn, 341 __LINE__, idp->in_lbn,
342 ibp->b_flags, curproc->p_pid); 342 ibp->b_flags, curproc->p_pid);
343 } 343 }
344#endif 344#endif
345 VOP_BWRITE(ibp->b_vp, ibp); 345 VOP_BWRITE(ibp->b_vp, ibp);
346 } 346 }
347 } else if (bpp && !(bp->b_oflags & (BO_DONE|BO_DELWRI))) { 347 } else if (bpp && !(bp->b_oflags & (BO_DONE|BO_DELWRI))) {
348 /* 348 /*
349 * Not a brand new block, also not in the cache; 349 * Not a brand new block, also not in the cache;
350 * read it in from disk. 350 * read it in from disk.
351 */ 351 */
352 if (iosize == fs->lfs_bsize) 352 if (iosize == lfs_sb_getbsize(fs))
353 /* Optimization: I/O is unnecessary. */ 353 /* Optimization: I/O is unnecessary. */
354 bp->b_blkno = daddr; 354 bp->b_blkno = daddr;
355 else { 355 else {
356 /* 356 /*
357 * We need to read the block to preserve the 357 * We need to read the block to preserve the
358 * existing bytes. 358 * existing bytes.
359 */ 359 */
360 bp->b_blkno = daddr; 360 bp->b_blkno = daddr;
361 bp->b_flags |= B_READ; 361 bp->b_flags |= B_READ;
362 VOP_STRATEGY(vp, bp); 362 VOP_STRATEGY(vp, bp);
363 return (biowait(bp)); 363 return (biowait(bp));
364 } 364 }
365 } 365 }
@@ -427,31 +427,31 @@ lfs_fragextend(struct vnode *vp, int osi @@ -427,31 +427,31 @@ lfs_fragextend(struct vnode *vp, int osi
427 */ 427 */
428 428
429 if (bpp && ((*bpp)->b_oflags & BO_DELWRI)) { 429 if (bpp && ((*bpp)->b_oflags & BO_DELWRI)) {
430 if (!lfs_fits(fs, frags)) { 430 if (!lfs_fits(fs, frags)) {
431 if (bpp) 431 if (bpp)
432 brelse(*bpp, 0); 432 brelse(*bpp, 0);
433#if defined(LFS_QUOTA) || defined(LFS_QUOTA2) 433#if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
434 lfs_chkdq(ip, -frags, cred, 0); 434 lfs_chkdq(ip, -frags, cred, 0);
435#endif 435#endif
436 rw_exit(&fs->lfs_fraglock); 436 rw_exit(&fs->lfs_fraglock);
437 lfs_availwait(fs, frags); 437 lfs_availwait(fs, frags);
438 goto top; 438 goto top;
439 } 439 }
440 fs->lfs_avail -= frags; 440 lfs_sb_subavail(fs, frags);
441 } 441 }
442 442
443 mutex_enter(&lfs_lock); 443 mutex_enter(&lfs_lock);
444 fs->lfs_bfree -= frags; 444 lfs_sb_setbfree(fs, lfs_sb_getbfree(fs) - frags);
445 mutex_exit(&lfs_lock); 445 mutex_exit(&lfs_lock);
446 ip->i_lfs_effnblks += frags; 446 ip->i_lfs_effnblks += frags;
447 ip->i_flag |= IN_CHANGE | IN_UPDATE; 447 ip->i_flag |= IN_CHANGE | IN_UPDATE;
448 448
449 if (bpp) { 449 if (bpp) {
450 obufsize = (*bpp)->b_bufsize; 450 obufsize = (*bpp)->b_bufsize;
451 allocbuf(*bpp, nsize, 1); 451 allocbuf(*bpp, nsize, 1);
452 452
453 /* Adjust locked-list accounting */ 453 /* Adjust locked-list accounting */
454 if (((*bpp)->b_flags & B_LOCKED) != 0 && 454 if (((*bpp)->b_flags & B_LOCKED) != 0 &&
455 (*bpp)->b_iodone == NULL) { 455 (*bpp)->b_iodone == NULL) {
456 mutex_enter(&lfs_lock); 456 mutex_enter(&lfs_lock);
457 locked_queue_bytes += (*bpp)->b_bufsize - obufsize; 457 locked_queue_bytes += (*bpp)->b_bufsize - obufsize;
@@ -505,46 +505,46 @@ lfs_register_block(struct vnode *vp, dad @@ -505,46 +505,46 @@ lfs_register_block(struct vnode *vp, dad
505 505
506 lbp = (struct lbnentry *)pool_get(&lfs_lbnentry_pool, PR_WAITOK); 506 lbp = (struct lbnentry *)pool_get(&lfs_lbnentry_pool, PR_WAITOK);
507 lbp->lbn = lbn; 507 lbp->lbn = lbn;
508 mutex_enter(&lfs_lock); 508 mutex_enter(&lfs_lock);
509 if (SPLAY_INSERT(lfs_splay, &ip->i_lfs_lbtree, lbp) != NULL) { 509 if (SPLAY_INSERT(lfs_splay, &ip->i_lfs_lbtree, lbp) != NULL) {
510 mutex_exit(&lfs_lock); 510 mutex_exit(&lfs_lock);
511 /* Already there */ 511 /* Already there */
512 pool_put(&lfs_lbnentry_pool, lbp); 512 pool_put(&lfs_lbnentry_pool, lbp);
513 return; 513 return;
514 } 514 }
515 515
516 ++ip->i_lfs_nbtree; 516 ++ip->i_lfs_nbtree;
517 fs->lfs_favail += lfs_btofsb(fs, (1 << fs->lfs_bshift)); 517 fs->lfs_favail += lfs_btofsb(fs, (1 << fs->lfs_bshift));
518 fs->lfs_pages += fs->lfs_bsize >> PAGE_SHIFT; 518 fs->lfs_pages += lfs_sb_getbsize(fs) >> PAGE_SHIFT;
519 ++locked_fakequeue_count; 519 ++locked_fakequeue_count;
520 lfs_subsys_pages += fs->lfs_bsize >> PAGE_SHIFT; 520 lfs_subsys_pages += lfs_sb_getbsize(fs) >> PAGE_SHIFT;
521 mutex_exit(&lfs_lock); 521 mutex_exit(&lfs_lock);
522} 522}
523 523
524static void 524static void
525lfs_do_deregister(struct lfs *fs, struct inode *ip, struct lbnentry *lbp) 525lfs_do_deregister(struct lfs *fs, struct inode *ip, struct lbnentry *lbp)
526{ 526{
527 ASSERT_MAYBE_SEGLOCK(fs); 527 ASSERT_MAYBE_SEGLOCK(fs);
528 528
529 mutex_enter(&lfs_lock); 529 mutex_enter(&lfs_lock);
530 --ip->i_lfs_nbtree; 530 --ip->i_lfs_nbtree;
531 SPLAY_REMOVE(lfs_splay, &ip->i_lfs_lbtree, lbp); 531 SPLAY_REMOVE(lfs_splay, &ip->i_lfs_lbtree, lbp);
532 if (fs->lfs_favail > lfs_btofsb(fs, (1 << fs->lfs_bshift))) 532 if (fs->lfs_favail > lfs_btofsb(fs, (1 << fs->lfs_bshift)))
533 fs->lfs_favail -= lfs_btofsb(fs, (1 << fs->lfs_bshift)); 533 fs->lfs_favail -= lfs_btofsb(fs, (1 << fs->lfs_bshift));
534 fs->lfs_pages -= fs->lfs_bsize >> PAGE_SHIFT; 534 fs->lfs_pages -= lfs_sb_getbsize(fs) >> PAGE_SHIFT;
535 if (locked_fakequeue_count > 0) 535 if (locked_fakequeue_count > 0)
536 --locked_fakequeue_count; 536 --locked_fakequeue_count;
537 lfs_subsys_pages -= fs->lfs_bsize >> PAGE_SHIFT; 537 lfs_subsys_pages -= lfs_sb_getbsize(fs) >> PAGE_SHIFT;
538 mutex_exit(&lfs_lock); 538 mutex_exit(&lfs_lock);
539 539
540 pool_put(&lfs_lbnentry_pool, lbp); 540 pool_put(&lfs_lbnentry_pool, lbp);
541} 541}
542 542
543void 543void
544lfs_deregister_block(struct vnode *vp, daddr_t lbn) 544lfs_deregister_block(struct vnode *vp, daddr_t lbn)
545{ 545{
546 struct lfs *fs; 546 struct lfs *fs;
547 struct inode *ip; 547 struct inode *ip;
548 struct lbnentry *lbp; 548 struct lbnentry *lbp;
549 struct lbnentry tmp; 549 struct lbnentry tmp;
550 550

cvs diff -r1.81 -r1.82 src/sys/ufs/lfs/lfs_subr.c (expand / switch to unified diff)

--- src/sys/ufs/lfs/lfs_subr.c 2015/07/16 08:31:45 1.81
+++ src/sys/ufs/lfs/lfs_subr.c 2015/07/24 06:56:42 1.82
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lfs_subr.c,v 1.81 2015/07/16 08:31:45 dholland Exp $ */ 1/* $NetBSD: lfs_subr.c,v 1.82 2015/07/24 06:56:42 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant@hhhh.org>. 8 * by Konrad E. Schroder <perseant@hhhh.org>.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -50,27 +50,27 @@ @@ -50,27 +50,27 @@
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE. 57 * SUCH DAMAGE.
58 * 58 *
59 * @(#)lfs_subr.c 8.4 (Berkeley) 5/8/95 59 * @(#)lfs_subr.c 8.4 (Berkeley) 5/8/95
60 */ 60 */
61 61
62#include <sys/cdefs.h> 62#include <sys/cdefs.h>
63__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.81 2015/07/16 08:31:45 dholland Exp $"); 63__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.82 2015/07/24 06:56:42 dholland Exp $");
64 64
65#include <sys/param.h> 65#include <sys/param.h>
66#include <sys/systm.h> 66#include <sys/systm.h>
67#include <sys/namei.h> 67#include <sys/namei.h>
68#include <sys/vnode.h> 68#include <sys/vnode.h>
69#include <sys/buf.h> 69#include <sys/buf.h>
70#include <sys/mount.h> 70#include <sys/mount.h>
71#include <sys/malloc.h> 71#include <sys/malloc.h>
72#include <sys/proc.h> 72#include <sys/proc.h>
73#include <sys/kauth.h> 73#include <sys/kauth.h>
74 74
75#include <ufs/lfs/ulfs_inode.h> 75#include <ufs/lfs/ulfs_inode.h>
76#include <ufs/lfs/lfs.h> 76#include <ufs/lfs/lfs.h>
@@ -114,48 +114,48 @@ lfs_setup_resblks(struct lfs *fs) @@ -114,48 +114,48 @@ lfs_setup_resblks(struct lfs *fs)
114 } 114 }
115 for (i = 0; i < LFS_RESHASH_WIDTH; i++) 115 for (i = 0; i < LFS_RESHASH_WIDTH; i++)
116 LIST_INIT(fs->lfs_reshash + i); 116 LIST_INIT(fs->lfs_reshash + i);
117 117
118 /* 118 /*
119 * These types of allocations can be larger than a page, 119 * These types of allocations can be larger than a page,
120 * so we can't use the pool subsystem for them. 120 * so we can't use the pool subsystem for them.
121 */ 121 */
122 for (i = 0, j = 0; j < LFS_N_SUMMARIES; j++, i++) 122 for (i = 0, j = 0; j < LFS_N_SUMMARIES; j++, i++)
123 fs->lfs_resblk[i].size = fs->lfs_sumsize; 123 fs->lfs_resblk[i].size = fs->lfs_sumsize;
124 for (j = 0; j < LFS_N_SBLOCKS; j++, i++) 124 for (j = 0; j < LFS_N_SBLOCKS; j++, i++)
125 fs->lfs_resblk[i].size = LFS_SBPAD; 125 fs->lfs_resblk[i].size = LFS_SBPAD;
126 for (j = 0; j < LFS_N_IBLOCKS; j++, i++) 126 for (j = 0; j < LFS_N_IBLOCKS; j++, i++)
127 fs->lfs_resblk[i].size = fs->lfs_bsize; 127 fs->lfs_resblk[i].size = lfs_sb_getbsize(fs);
128 for (j = 0; j < LFS_N_CLUSTERS; j++, i++) 128 for (j = 0; j < LFS_N_CLUSTERS; j++, i++)
129 fs->lfs_resblk[i].size = MAXPHYS; 129 fs->lfs_resblk[i].size = MAXPHYS;
130 for (j = 0; j < LFS_N_CLEAN; j++, i++) 130 for (j = 0; j < LFS_N_CLEAN; j++, i++)
131 fs->lfs_resblk[i].size = MAXPHYS; 131 fs->lfs_resblk[i].size = MAXPHYS;
132 for (j = 0; j < LFS_N_BLKIOV; j++, i++) 132 for (j = 0; j < LFS_N_BLKIOV; j++, i++)
133 fs->lfs_resblk[i].size = LFS_MARKV_MAXBLKCNT * sizeof(BLOCK_INFO); 133 fs->lfs_resblk[i].size = LFS_MARKV_MAXBLKCNT * sizeof(BLOCK_INFO);
134 134
135 for (i = 0; i < LFS_N_TOTAL; i++) { 135 for (i = 0; i < LFS_N_TOTAL; i++) {
136 fs->lfs_resblk[i].p = malloc(fs->lfs_resblk[i].size, 136 fs->lfs_resblk[i].p = malloc(fs->lfs_resblk[i].size,
137 M_SEGMENT, M_WAITOK); 137 M_SEGMENT, M_WAITOK);
138 } 138 }
139 139
140 /* 140 /*
141 * Initialize pools for small types (XXX is BPP small?) 141 * Initialize pools for small types (XXX is BPP small?)
142 */ 142 */
143 pool_init(&fs->lfs_clpool, sizeof(struct lfs_cluster), 0, 0, 0, 143 pool_init(&fs->lfs_clpool, sizeof(struct lfs_cluster), 0, 0, 0,
144 "lfsclpl", &pool_allocator_nointr, IPL_NONE); 144 "lfsclpl", &pool_allocator_nointr, IPL_NONE);
145 pool_init(&fs->lfs_segpool, sizeof(struct segment), 0, 0, 0, 145 pool_init(&fs->lfs_segpool, sizeof(struct segment), 0, 0, 0,
146 "lfssegpool", &pool_allocator_nointr, IPL_NONE); 146 "lfssegpool", &pool_allocator_nointr, IPL_NONE);
147 maxbpp = ((fs->lfs_sumsize - SEGSUM_SIZE(fs)) / sizeof(int32_t) + 2); 147 maxbpp = ((fs->lfs_sumsize - SEGSUM_SIZE(fs)) / sizeof(int32_t) + 2);
148 maxbpp = MIN(maxbpp, lfs_segsize(fs) / fs->lfs_fsize + 2); 148 maxbpp = MIN(maxbpp, lfs_segsize(fs) / lfs_sb_getfsize(fs) + 2);
149 pool_init(&fs->lfs_bpppool, maxbpp * sizeof(struct buf *), 0, 0, 0, 149 pool_init(&fs->lfs_bpppool, maxbpp * sizeof(struct buf *), 0, 0, 0,
150 "lfsbpppl", &pool_allocator_nointr, IPL_NONE); 150 "lfsbpppl", &pool_allocator_nointr, IPL_NONE);
151} 151}
152 152
153void 153void
154lfs_free_resblks(struct lfs *fs) 154lfs_free_resblks(struct lfs *fs)
155{ 155{
156 int i; 156 int i;
157 157
158 pool_destroy(&fs->lfs_bpppool); 158 pool_destroy(&fs->lfs_bpppool);
159 pool_destroy(&fs->lfs_segpool); 159 pool_destroy(&fs->lfs_segpool);
160 pool_destroy(&fs->lfs_clpool); 160 pool_destroy(&fs->lfs_clpool);
161 161
@@ -326,27 +326,27 @@ lfs_seglock(struct lfs *fs, unsigned lon @@ -326,27 +326,27 @@ lfs_seglock(struct lfs *fs, unsigned lon
326 sp->seg_flags = flags; 326 sp->seg_flags = flags;
327 sp->vp = NULL; 327 sp->vp = NULL;
328 sp->seg_iocount = 0; 328 sp->seg_iocount = 0;
329 (void) lfs_initseg(fs); 329 (void) lfs_initseg(fs);
330 330
331 /* 331 /*
332 * Keep a cumulative count of the outstanding I/O operations. If the 332 * Keep a cumulative count of the outstanding I/O operations. If the
333 * disk drive catches up with us it could go to zero before we finish, 333 * disk drive catches up with us it could go to zero before we finish,
334 * so we artificially increment it by one until we've scheduled all of 334 * so we artificially increment it by one until we've scheduled all of
335 * the writes we intend to do. 335 * the writes we intend to do.
336 */ 336 */
337 mutex_enter(&lfs_lock); 337 mutex_enter(&lfs_lock);
338 ++fs->lfs_iocount; 338 ++fs->lfs_iocount;
339 fs->lfs_startseg = fs->lfs_curseg; 339 fs->lfs_startseg = lfs_sb_getcurseg(fs);
340 mutex_exit(&lfs_lock); 340 mutex_exit(&lfs_lock);
341 return 0; 341 return 0;
342} 342}
343 343
344static void lfs_unmark_dirop(struct lfs *); 344static void lfs_unmark_dirop(struct lfs *);
345 345
346static void 346static void
347lfs_unmark_dirop(struct lfs *fs) 347lfs_unmark_dirop(struct lfs *fs)
348{ 348{
349 struct inode *ip, *nip; 349 struct inode *ip, *nip;
350 struct vnode *vp; 350 struct vnode *vp;
351 int doit; 351 int doit;
352 352
@@ -440,27 +440,27 @@ lfs_segunlock(struct lfs *fs) @@ -440,27 +440,27 @@ lfs_segunlock(struct lfs *fs)
440 mutex_enter(&lfs_lock); 440 mutex_enter(&lfs_lock);
441 KASSERT(LFS_SEGLOCK_HELD(fs)); 441 KASSERT(LFS_SEGLOCK_HELD(fs));
442 if (fs->lfs_seglock == 1) { 442 if (fs->lfs_seglock == 1) {
443 if ((sp->seg_flags & (SEGM_PROT | SEGM_CLEAN)) == 0) 443 if ((sp->seg_flags & (SEGM_PROT | SEGM_CLEAN)) == 0)
444 do_unmark_dirop = 1; 444 do_unmark_dirop = 1;
445 mutex_exit(&lfs_lock); 445 mutex_exit(&lfs_lock);
446 sync = sp->seg_flags & SEGM_SYNC; 446 sync = sp->seg_flags & SEGM_SYNC;
447 ckp = sp->seg_flags & SEGM_CKP; 447 ckp = sp->seg_flags & SEGM_CKP;
448 448
449 /* We should have a segment summary, and nothing else */ 449 /* We should have a segment summary, and nothing else */
450 KASSERT(sp->cbpp == sp->bpp + 1); 450 KASSERT(sp->cbpp == sp->bpp + 1);
451 451
452 /* Free allocated segment summary */ 452 /* Free allocated segment summary */
453 fs->lfs_offset -= lfs_btofsb(fs, fs->lfs_sumsize); 453 lfs_sb_suboffset(fs, lfs_btofsb(fs, lfs_sb_getsumsize(fs)));
454 bp = *sp->bpp; 454 bp = *sp->bpp;
455 lfs_freebuf(fs, bp); 455 lfs_freebuf(fs, bp);
456 456
457 pool_put(&fs->lfs_bpppool, sp->bpp); 457 pool_put(&fs->lfs_bpppool, sp->bpp);
458 sp->bpp = NULL; 458 sp->bpp = NULL;
459 459
460 /* 460 /*
461 * If we're not sync, we're done with sp, get rid of it. 461 * If we're not sync, we're done with sp, get rid of it.
462 * Otherwise, we keep a local copy around but free 462 * Otherwise, we keep a local copy around but free
463 * fs->lfs_sp so another process can use it (we have to 463 * fs->lfs_sp so another process can use it (we have to
464 * wait but they don't have to wait for us). 464 * wait but they don't have to wait for us).
465 */ 465 */
466 if (!sync) 466 if (!sync)
@@ -623,41 +623,41 @@ lfs_segunlock_relock(struct lfs *fs) @@ -623,41 +623,41 @@ lfs_segunlock_relock(struct lfs *fs)
623 LFS_SYNC_CLEANERINFO(cip, fs, bp, 1); 623 LFS_SYNC_CLEANERINFO(cip, fs, bp, 1);
624 624
625 /* Save segment flags for later */ 625 /* Save segment flags for later */
626 seg_flags = fs->lfs_sp->seg_flags; 626 seg_flags = fs->lfs_sp->seg_flags;
627 627
628 fs->lfs_sp->seg_flags |= SEGM_PROT; /* Don't unmark dirop nodes */ 628 fs->lfs_sp->seg_flags |= SEGM_PROT; /* Don't unmark dirop nodes */
629 while(fs->lfs_seglock) 629 while(fs->lfs_seglock)
630 lfs_segunlock(fs); 630 lfs_segunlock(fs);
631 631
632 /* Wait for the cleaner */ 632 /* Wait for the cleaner */
633 lfs_wakeup_cleaner(fs); 633 lfs_wakeup_cleaner(fs);
634 mutex_enter(&lfs_lock); 634 mutex_enter(&lfs_lock);
635 while (LFS_STARVED_FOR_SEGS(fs)) 635 while (LFS_STARVED_FOR_SEGS(fs))
636 mtsleep(&fs->lfs_avail, PRIBIO, "relock", 0, 636 mtsleep(&fs->lfs_availsleep, PRIBIO, "relock", 0,
637 &lfs_lock); 637 &lfs_lock);
638 mutex_exit(&lfs_lock); 638 mutex_exit(&lfs_lock);
639 639
640 /* Put the segment lock back the way it was. */ 640 /* Put the segment lock back the way it was. */
641 while(n--) 641 while(n--)
642 lfs_seglock(fs, seg_flags); 642 lfs_seglock(fs, seg_flags);
643 643
644 /* Cleaner can relax now */ 644 /* Cleaner can relax now */
645 LFS_CLEANERINFO(cip, fs, bp); 645 LFS_CLEANERINFO(cip, fs, bp);
646 cip->flags &= ~LFS_CLEANER_MUST_CLEAN; 646 cip->flags &= ~LFS_CLEANER_MUST_CLEAN;
647 LFS_SYNC_CLEANERINFO(cip, fs, bp, 1); 647 LFS_SYNC_CLEANERINFO(cip, fs, bp, 1);
648 648
649 return; 649 return;
650} 650}
651 651
652/* 652/*
653 * Wake up the cleaner, provided that nowrap is not set. 653 * Wake up the cleaner, provided that nowrap is not set.
654 */ 654 */
655void 655void
656lfs_wakeup_cleaner(struct lfs *fs) 656lfs_wakeup_cleaner(struct lfs *fs)
657{ 657{
658 if (fs->lfs_nowrap > 0) 658 if (fs->lfs_nowrap > 0)
659 return; 659 return;
660 660
661 wakeup(&fs->lfs_nextseg); 661 wakeup(&fs->lfs_nextsegsleep);
662 wakeup(&lfs_allclean_wakeup); 662 wakeup(&lfs_allclean_wakeup);
663} 663}

cvs diff -r1.128 -r1.129 src/sys/ufs/lfs/lfs_bio.c (expand / switch to unified diff)

--- src/sys/ufs/lfs/lfs_bio.c 2013/11/27 17:24:44 1.128
+++ src/sys/ufs/lfs/lfs_bio.c 2015/07/24 06:56:42 1.129
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lfs_bio.c,v 1.128 2013/11/27 17:24:44 christos Exp $ */ 1/* $NetBSD: lfs_bio.c,v 1.129 2015/07/24 06:56:42 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant@hhhh.org>. 8 * by Konrad E. Schroder <perseant@hhhh.org>.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -50,27 +50,27 @@ @@ -50,27 +50,27 @@
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE. 57 * SUCH DAMAGE.
58 * 58 *
59 * @(#)lfs_bio.c 8.10 (Berkeley) 6/10/95 59 * @(#)lfs_bio.c 8.10 (Berkeley) 6/10/95
60 */ 60 */
61 61
62#include <sys/cdefs.h> 62#include <sys/cdefs.h>
63__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.128 2013/11/27 17:24:44 christos Exp $"); 63__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.129 2015/07/24 06:56:42 dholland Exp $");
64 64
65#include <sys/param.h> 65#include <sys/param.h>
66#include <sys/systm.h> 66#include <sys/systm.h>
67#include <sys/proc.h> 67#include <sys/proc.h>
68#include <sys/buf.h> 68#include <sys/buf.h>
69#include <sys/vnode.h> 69#include <sys/vnode.h>
70#include <sys/resourcevar.h> 70#include <sys/resourcevar.h>
71#include <sys/mount.h> 71#include <sys/mount.h>
72#include <sys/kernel.h> 72#include <sys/kernel.h>
73#include <sys/kauth.h> 73#include <sys/kauth.h>
74 74
75#include <ufs/lfs/ulfs_inode.h> 75#include <ufs/lfs/ulfs_inode.h>
76#include <ufs/lfs/ulfsmount.h> 76#include <ufs/lfs/ulfsmount.h>
@@ -235,28 +235,28 @@ lfs_reserveavail(struct lfs *fs, struct  @@ -235,28 +235,28 @@ lfs_reserveavail(struct lfs *fs, struct
235 } 235 }
236 ++slept; 236 ++slept;
237 237
238 /* Wake up the cleaner */ 238 /* Wake up the cleaner */
239 LFS_CLEANERINFO(cip, fs, bp); 239 LFS_CLEANERINFO(cip, fs, bp);
240 LFS_SYNC_CLEANERINFO(cip, fs, bp, 0); 240 LFS_SYNC_CLEANERINFO(cip, fs, bp, 0);
241 lfs_wakeup_cleaner(fs); 241 lfs_wakeup_cleaner(fs);
242 242
243 mutex_enter(&lfs_lock); 243 mutex_enter(&lfs_lock);
244 /* Cleaner might have run while we were reading, check again */ 244 /* Cleaner might have run while we were reading, check again */
245 if (lfs_fits(fs, fsb + fs->lfs_ravail + fs->lfs_favail)) 245 if (lfs_fits(fs, fsb + fs->lfs_ravail + fs->lfs_favail))
246 break; 246 break;
247 247
248 error = mtsleep(&fs->lfs_avail, PCATCH | PUSER, "lfs_reserve", 248 error = mtsleep(&fs->lfs_availsleep, PCATCH | PUSER,
249 0, &lfs_lock); 249 "lfs_reserve", 0, &lfs_lock);
250 if (error) { 250 if (error) {
251 mutex_exit(&lfs_lock); 251 mutex_exit(&lfs_lock);
252 return error; 252 return error;
253 } 253 }
254 } 254 }
255#ifdef DEBUG 255#ifdef DEBUG
256 if (slept) { 256 if (slept) {
257 DLOG((DLOG_AVAIL, "lfs_reserve: woke up\n")); 257 DLOG((DLOG_AVAIL, "lfs_reserve: woke up\n"));
258 } 258 }
259#endif 259#endif
260 fs->lfs_ravail += fsb; 260 fs->lfs_ravail += fsb;
261 mutex_exit(&lfs_lock); 261 mutex_exit(&lfs_lock);
262 262
@@ -345,39 +345,40 @@ lfs_bwrite(void *v) @@ -345,39 +345,40 @@ lfs_bwrite(void *v)
345#endif /* DIAGNOSTIC */ 345#endif /* DIAGNOSTIC */
346 return lfs_bwrite_ext(bp, 0); 346 return lfs_bwrite_ext(bp, 0);
347} 347}
348 348
349/* 349/*
350 * Determine if there is enough room currently available to write fsb 350 * Determine if there is enough room currently available to write fsb
351 * blocks. We need enough blocks for the new blocks, the current 351 * blocks. We need enough blocks for the new blocks, the current
352 * inode blocks (including potentially the ifile inode), a summary block, 352 * inode blocks (including potentially the ifile inode), a summary block,
353 * and the segment usage table, plus an ifile block. 353 * and the segment usage table, plus an ifile block.
354 */ 354 */
355int 355int
356lfs_fits(struct lfs *fs, int fsb) 356lfs_fits(struct lfs *fs, int fsb)
357{ 357{
358 int needed; 358 int64_t needed;
359 359
360 ASSERT_NO_SEGLOCK(fs); 360 ASSERT_NO_SEGLOCK(fs);
361 needed = fsb + lfs_btofsb(fs, fs->lfs_sumsize) + 361 needed = fsb + lfs_btofsb(fs, lfs_sb_getsumsize(fs)) +
362 ((howmany(fs->lfs_uinodes + 1, LFS_INOPB(fs)) + fs->lfs_segtabsz + 362 ((howmany(lfs_sb_getuinodes(fs) + 1, LFS_INOPB(fs)) +
 363 lfs_sb_getsegtabsz(fs) +
363 1) << (fs->lfs_bshift - fs->lfs_ffshift)); 364 1) << (fs->lfs_bshift - fs->lfs_ffshift));
364 365
365 if (needed >= fs->lfs_avail) { 366 if (needed >= lfs_sb_getavail(fs)) {
366#ifdef DEBUG 367#ifdef DEBUG
367 DLOG((DLOG_AVAIL, "lfs_fits: no fit: fsb = %ld, uinodes = %ld, " 368 DLOG((DLOG_AVAIL, "lfs_fits: no fit: fsb = %ld, uinodes = %ld, "
368 "needed = %ld, avail = %ld\n", 369 "needed = %jd, avail = %jd\n",
369 (long)fsb, (long)fs->lfs_uinodes, (long)needed, 370 (long)fsb, (long)fs->lfs_uinodes, (intmax_t)needed,
370 (long)fs->lfs_avail)); 371 (intmax_t)lfs_sb_getavail(fs)));
371#endif 372#endif
372 return 0; 373 return 0;
373 } 374 }
374 return 1; 375 return 1;
375} 376}
376 377
377int 378int
378lfs_availwait(struct lfs *fs, int fsb) 379lfs_availwait(struct lfs *fs, int fsb)
379{ 380{
380 int error; 381 int error;
381 CLEANERINFO *cip; 382 CLEANERINFO *cip;
382 struct buf *cbp; 383 struct buf *cbp;
383 384
@@ -401,27 +402,28 @@ lfs_availwait(struct lfs *fs, int fsb) @@ -401,27 +402,28 @@ lfs_availwait(struct lfs *fs, int fsb)
401 LFS_CLEANERINFO(cip, fs, cbp); 402 LFS_CLEANERINFO(cip, fs, cbp);
402 LFS_SYNC_CLEANERINFO(cip, fs, cbp, 0); 403 LFS_SYNC_CLEANERINFO(cip, fs, cbp, 0);
403 404
404#ifdef DEBUG 405#ifdef DEBUG
405 DLOG((DLOG_AVAIL, "lfs_availwait: out of available space, " 406 DLOG((DLOG_AVAIL, "lfs_availwait: out of available space, "
406 "waiting on cleaner\n")); 407 "waiting on cleaner\n"));
407#endif 408#endif
408 409
409 lfs_wakeup_cleaner(fs); 410 lfs_wakeup_cleaner(fs);
410#ifdef DIAGNOSTIC 411#ifdef DIAGNOSTIC
411 if (LFS_SEGLOCK_HELD(fs)) 412 if (LFS_SEGLOCK_HELD(fs))
412 panic("lfs_availwait: deadlock"); 413 panic("lfs_availwait: deadlock");
413#endif 414#endif
414 error = tsleep(&fs->lfs_avail, PCATCH | PUSER, "cleaner", 0); 415 error = tsleep(&fs->lfs_availsleep, PCATCH | PUSER,
 416 "cleaner", 0);
415 if (error) 417 if (error)
416 return (error); 418 return (error);
417 } 419 }
418 return 0; 420 return 0;
419} 421}
420 422
421int 423int
422lfs_bwrite_ext(struct buf *bp, int flags) 424lfs_bwrite_ext(struct buf *bp, int flags)
423{ 425{
424 struct lfs *fs; 426 struct lfs *fs;
425 struct inode *ip; 427 struct inode *ip;
426 struct vnode *vp; 428 struct vnode *vp;
427 int fsb; 429 int fsb;
@@ -470,27 +472,27 @@ lfs_bwrite_ext(struct buf *bp, int flags @@ -470,27 +472,27 @@ lfs_bwrite_ext(struct buf *bp, int flags
470 * blocks. 472 * blocks.
471 */ 473 */
472 if ((bp->b_flags & B_LOCKED) == 0) { 474 if ((bp->b_flags & B_LOCKED) == 0) {
473 fsb = lfs_numfrags(fs, bp->b_bcount); 475 fsb = lfs_numfrags(fs, bp->b_bcount);
474 476
475 ip = VTOI(vp); 477 ip = VTOI(vp);
476 mutex_enter(&lfs_lock); 478 mutex_enter(&lfs_lock);
477 if (flags & BW_CLEAN) { 479 if (flags & BW_CLEAN) {
478 LFS_SET_UINO(ip, IN_CLEANING); 480 LFS_SET_UINO(ip, IN_CLEANING);
479 } else { 481 } else {
480 LFS_SET_UINO(ip, IN_MODIFIED); 482 LFS_SET_UINO(ip, IN_MODIFIED);
481 } 483 }
482 mutex_exit(&lfs_lock); 484 mutex_exit(&lfs_lock);
483 fs->lfs_avail -= fsb; 485 lfs_sb_subavail(fs, fsb);
484 486
485 mutex_enter(&bufcache_lock); 487 mutex_enter(&bufcache_lock);
486 mutex_enter(vp->v_interlock); 488 mutex_enter(vp->v_interlock);
487 bp->b_oflags = (bp->b_oflags | BO_DELWRI) & ~BO_DONE; 489 bp->b_oflags = (bp->b_oflags | BO_DELWRI) & ~BO_DONE;
488 LFS_LOCK_BUF(bp); 490 LFS_LOCK_BUF(bp);
489 bp->b_flags &= ~B_READ; 491 bp->b_flags &= ~B_READ;
490 bp->b_error = 0; 492 bp->b_error = 0;
491 reassignbuf(bp, bp->b_vp); 493 reassignbuf(bp, bp->b_vp);
492 mutex_exit(vp->v_interlock); 494 mutex_exit(vp->v_interlock);
493 } else { 495 } else {
494 mutex_enter(&bufcache_lock); 496 mutex_enter(&bufcache_lock);
495 } 497 }
496 498
@@ -586,28 +588,28 @@ lfs_flush(struct lfs *fs, int flags, int @@ -586,28 +588,28 @@ lfs_flush(struct lfs *fs, int flags, int
586 } 588 }
587 mutex_exit(&mountlist_lock); 589 mutex_exit(&mountlist_lock);
588 } 590 }
589 LFS_DEBUG_COUNTLOCKED("flush"); 591 LFS_DEBUG_COUNTLOCKED("flush");
590 wakeup(&lfs_subsys_pages); 592 wakeup(&lfs_subsys_pages);
591 593
592 errout: 594 errout:
593 mutex_enter(&lfs_lock); 595 mutex_enter(&lfs_lock);
594 KASSERT(lfs_writing); 596 KASSERT(lfs_writing);
595 lfs_writing = 0; 597 lfs_writing = 0;
596 wakeup(&lfs_writing); 598 wakeup(&lfs_writing);
597} 599}
598 600
599#define INOCOUNT(fs) howmany((fs)->lfs_uinodes, LFS_INOPB(fs)) 601#define INOCOUNT(fs) howmany(lfs_sb_getuinodes(fs), LFS_INOPB(fs))
600#define INOBYTES(fs) ((fs)->lfs_uinodes * sizeof (struct ulfs1_dinode)) 602#define INOBYTES(fs) (lfs_sb_getuinodes(fs) * sizeof (struct ulfs1_dinode))
601 603
602/* 604/*
603 * make sure that we don't have too many locked buffers. 605 * make sure that we don't have too many locked buffers.
604 * flush buffers if needed. 606 * flush buffers if needed.
605 */ 607 */
606int 608int
607lfs_check(struct vnode *vp, daddr_t blkno, int flags) 609lfs_check(struct vnode *vp, daddr_t blkno, int flags)
608{ 610{
609 int error; 611 int error;
610 struct lfs *fs; 612 struct lfs *fs;
611 struct inode *ip; 613 struct inode *ip;
612 extern pid_t lfs_writer_daemon; 614 extern pid_t lfs_writer_daemon;
613 615

cvs diff -r1.137 -r1.138 src/sys/ufs/lfs/lfs_inode.c (expand / switch to unified diff)

--- src/sys/ufs/lfs/lfs_inode.c 2015/07/16 08:31:45 1.137
+++ src/sys/ufs/lfs/lfs_inode.c 2015/07/24 06:56:42 1.138
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lfs_inode.c,v 1.137 2015/07/16 08:31:45 dholland Exp $ */ 1/* $NetBSD: lfs_inode.c,v 1.138 2015/07/24 06:56:42 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant@hhhh.org>. 8 * by Konrad E. Schroder <perseant@hhhh.org>.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -50,27 +50,27 @@ @@ -50,27 +50,27 @@
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE. 57 * SUCH DAMAGE.
58 * 58 *
59 * @(#)lfs_inode.c 8.9 (Berkeley) 5/8/95 59 * @(#)lfs_inode.c 8.9 (Berkeley) 5/8/95
60 */ 60 */
61 61
62#include <sys/cdefs.h> 62#include <sys/cdefs.h>
63__KERNEL_RCSID(0, "$NetBSD: lfs_inode.c,v 1.137 2015/07/16 08:31:45 dholland Exp $"); 63__KERNEL_RCSID(0, "$NetBSD: lfs_inode.c,v 1.138 2015/07/24 06:56:42 dholland Exp $");
64 64
65#if defined(_KERNEL_OPT) 65#if defined(_KERNEL_OPT)
66#include "opt_quota.h" 66#include "opt_quota.h"
67#endif 67#endif
68 68
69#include <sys/param.h> 69#include <sys/param.h>
70#include <sys/systm.h> 70#include <sys/systm.h>
71#include <sys/mount.h> 71#include <sys/mount.h>
72#include <sys/malloc.h> 72#include <sys/malloc.h>
73#include <sys/proc.h> 73#include <sys/proc.h>
74#include <sys/file.h> 74#include <sys/file.h>
75#include <sys/buf.h> 75#include <sys/buf.h>
76#include <sys/vnode.h> 76#include <sys/vnode.h>
@@ -103,31 +103,31 @@ lfs_ifind(struct lfs *fs, ino_t ino, str @@ -103,31 +103,31 @@ lfs_ifind(struct lfs *fs, ino_t ino, str
103 103
104 ASSERT_NO_SEGLOCK(fs); 104 ASSERT_NO_SEGLOCK(fs);
105 /* 105 /*
106 * Read the inode block backwards, since later versions of the 106 * Read the inode block backwards, since later versions of the
107 * inode will supercede earlier ones. Though it is unlikely, it is 107 * inode will supercede earlier ones. Though it is unlikely, it is
108 * possible that the same inode will appear in the same inode block. 108 * possible that the same inode will appear in the same inode block.
109 */ 109 */
110 fin = dip + LFS_INOPB(fs); 110 fin = dip + LFS_INOPB(fs);
111 for (ldip = fin - 1; ldip >= dip; --ldip) 111 for (ldip = fin - 1; ldip >= dip; --ldip)
112 if (ldip->di_inumber == ino) 112 if (ldip->di_inumber == ino)
113 return (ldip); 113 return (ldip);
114 114
115 printf("searched %d entries\n", (int)(fin - dip)); 115 printf("searched %d entries\n", (int)(fin - dip));
116 printf("offset is 0x%x (seg %d)\n", fs->lfs_offset, 116 printf("offset is 0x%jx (seg %d)\n", (uintmax_t)lfs_sb_getoffset(fs),
117 lfs_dtosn(fs, fs->lfs_offset)); 117 lfs_dtosn(fs, lfs_sb_getoffset(fs)));
118 printf("block is 0x%llx (seg %lld)\n", 118 printf("block is 0x%jx (seg %d)\n",
119 (unsigned long long)LFS_DBTOFSB(fs, bp->b_blkno), 119 (uintmax_t)LFS_DBTOFSB(fs, bp->b_blkno),
120 (long long)lfs_dtosn(fs, LFS_DBTOFSB(fs, bp->b_blkno))); 120 lfs_dtosn(fs, LFS_DBTOFSB(fs, bp->b_blkno)));
121 121
122 return NULL; 122 return NULL;
123} 123}
124 124
125int 125int
126lfs_update(struct vnode *vp, const struct timespec *acc, 126lfs_update(struct vnode *vp, const struct timespec *acc,
127 const struct timespec *mod, int updflags) 127 const struct timespec *mod, int updflags)
128{ 128{
129 struct inode *ip; 129 struct inode *ip;
130 struct lfs *fs = VFSTOULFS(vp->v_mount)->um_lfs; 130 struct lfs *fs = VFSTOULFS(vp->v_mount)->um_lfs;
131 int flags; 131 int flags;
132 132
133 ASSERT_NO_SEGLOCK(fs); 133 ASSERT_NO_SEGLOCK(fs);
@@ -291,44 +291,44 @@ lfs_truncate(struct vnode *ovp, off_t le @@ -291,44 +291,44 @@ lfs_truncate(struct vnode *ovp, off_t le
291 } 291 }
292 } 292 }
293 uvm_vnp_setwritesize(ovp, length); 293 uvm_vnp_setwritesize(ovp, length);
294 error = ulfs_balloc_range(ovp, length - 1, 1, cred, 294 error = ulfs_balloc_range(ovp, length - 1, 1, cred,
295 aflags); 295 aflags);
296 if (error) { 296 if (error) {
297 (void) lfs_truncate(ovp, osize, 297 (void) lfs_truncate(ovp, osize,
298 ioflag & IO_SYNC, cred); 298 ioflag & IO_SYNC, cred);
299 return error; 299 return error;
300 } 300 }
301 uvm_vnp_setsize(ovp, length); 301 uvm_vnp_setsize(ovp, length);
302 oip->i_flag |= IN_CHANGE | IN_UPDATE; 302 oip->i_flag |= IN_CHANGE | IN_UPDATE;
303 KASSERT(ovp->v_size == oip->i_size); 303 KASSERT(ovp->v_size == oip->i_size);
304 oip->i_lfs_hiblk = lfs_lblkno(fs, oip->i_size + fs->lfs_bsize - 1) - 1; 304 oip->i_lfs_hiblk = lfs_lblkno(fs, oip->i_size + lfs_sb_getbsize(fs) - 1) - 1;
305 return (lfs_update(ovp, NULL, NULL, 0)); 305 return (lfs_update(ovp, NULL, NULL, 0));
306 } else { 306 } else {
307 error = lfs_reserve(fs, ovp, NULL, 307 error = lfs_reserve(fs, ovp, NULL,
308 lfs_btofsb(fs, (ULFS_NIADDR + 2) << fs->lfs_bshift)); 308 lfs_btofsb(fs, (ULFS_NIADDR + 2) << fs->lfs_bshift));
309 if (error) 309 if (error)
310 return (error); 310 return (error);
311 error = lfs_balloc(ovp, length - 1, 1, cred, 311 error = lfs_balloc(ovp, length - 1, 1, cred,
312 aflags, &bp); 312 aflags, &bp);
313 lfs_reserve(fs, ovp, NULL, 313 lfs_reserve(fs, ovp, NULL,
314 -lfs_btofsb(fs, (ULFS_NIADDR + 2) << fs->lfs_bshift)); 314 -lfs_btofsb(fs, (ULFS_NIADDR + 2) << fs->lfs_bshift));
315 if (error) 315 if (error)
316 return (error); 316 return (error);
317 oip->i_ffs1_size = oip->i_size = length; 317 oip->i_ffs1_size = oip->i_size = length;
318 uvm_vnp_setsize(ovp, length); 318 uvm_vnp_setsize(ovp, length);
319 (void) VOP_BWRITE(bp->b_vp, bp); 319 (void) VOP_BWRITE(bp->b_vp, bp);
320 oip->i_flag |= IN_CHANGE | IN_UPDATE; 320 oip->i_flag |= IN_CHANGE | IN_UPDATE;
321 oip->i_lfs_hiblk = lfs_lblkno(fs, oip->i_size + fs->lfs_bsize - 1) - 1; 321 oip->i_lfs_hiblk = lfs_lblkno(fs, oip->i_size + lfs_sb_getbsize(fs) - 1) - 1;
322 return (lfs_update(ovp, NULL, NULL, 0)); 322 return (lfs_update(ovp, NULL, NULL, 0));
323 } 323 }
324 } 324 }
325 325
326 if ((error = lfs_reserve(fs, ovp, NULL, 326 if ((error = lfs_reserve(fs, ovp, NULL,
327 lfs_btofsb(fs, (2 * ULFS_NIADDR + 3) << fs->lfs_bshift))) != 0) 327 lfs_btofsb(fs, (2 * ULFS_NIADDR + 3) << fs->lfs_bshift))) != 0)
328 return (error); 328 return (error);
329 329
330 /* 330 /*
331 * Shorten the size of the file. If the file is not being 331 * Shorten the size of the file. If the file is not being
332 * truncated to a block boundary, the contents of the 332 * truncated to a block boundary, the contents of the
333 * partial block following the end of the file must be 333 * partial block following the end of the file must be
334 * zero'ed in case it ever becomes accessible again because 334 * zero'ed in case it ever becomes accessible again because
@@ -357,28 +357,30 @@ lfs_truncate(struct vnode *ovp, off_t le @@ -357,28 +357,30 @@ lfs_truncate(struct vnode *ovp, off_t le
357 obufsize = bp->b_bufsize; 357 obufsize = bp->b_bufsize;
358 odb = lfs_btofsb(fs, bp->b_bcount); 358 odb = lfs_btofsb(fs, bp->b_bcount);
359 oip->i_size = oip->i_ffs1_size = length; 359 oip->i_size = oip->i_ffs1_size = length;
360 size = lfs_blksize(fs, oip, lbn); 360 size = lfs_blksize(fs, oip, lbn);
361 if (ovp->v_type != VDIR) 361 if (ovp->v_type != VDIR)
362 memset((char *)bp->b_data + offset, 0, 362 memset((char *)bp->b_data + offset, 0,
363 (u_int)(size - offset)); 363 (u_int)(size - offset));
364 allocbuf(bp, size, 1); 364 allocbuf(bp, size, 1);
365 if ((bp->b_flags & B_LOCKED) != 0 && bp->b_iodone == NULL) { 365 if ((bp->b_flags & B_LOCKED) != 0 && bp->b_iodone == NULL) {
366 mutex_enter(&lfs_lock); 366 mutex_enter(&lfs_lock);
367 locked_queue_bytes -= obufsize - bp->b_bufsize; 367 locked_queue_bytes -= obufsize - bp->b_bufsize;
368 mutex_exit(&lfs_lock); 368 mutex_exit(&lfs_lock);
369 } 369 }
370 if (bp->b_oflags & BO_DELWRI) 370 if (bp->b_oflags & BO_DELWRI) {
371 fs->lfs_avail += odb - lfs_btofsb(fs, size); 371 lfs_sb_addavail(fs, odb - lfs_btofsb(fs, size));
 372 /* XXX shouldn't this wake up on lfs_availsleep? */
 373 }
372 (void) VOP_BWRITE(bp->b_vp, bp); 374 (void) VOP_BWRITE(bp->b_vp, bp);
373 } else { /* vp->v_type == VREG && length < osize && offset != 0 */ 375 } else { /* vp->v_type == VREG && length < osize && offset != 0 */
374 /* 376 /*
375 * When truncating a regular file down to a non-block-aligned 377 * When truncating a regular file down to a non-block-aligned
376 * size, we must zero the part of last block which is past 378 * size, we must zero the part of last block which is past
377 * the new EOF. We must synchronously flush the zeroed pages 379 * the new EOF. We must synchronously flush the zeroed pages
378 * to disk since the new pages will be invalidated as soon 380 * to disk since the new pages will be invalidated as soon
379 * as we inform the VM system of the new, smaller size. 381 * as we inform the VM system of the new, smaller size.
380 * We must do this before acquiring the GLOCK, since fetching 382 * We must do this before acquiring the GLOCK, since fetching
381 * the pages will acquire the GLOCK internally. 383 * the pages will acquire the GLOCK internally.
382 * So there is a window where another thread could see a whole 384 * So there is a window where another thread could see a whole
383 * zeroed page past EOF, but that's life. 385 * zeroed page past EOF, but that's life.
384 */ 386 */
@@ -413,34 +415,34 @@ lfs_truncate(struct vnode *ovp, off_t le @@ -413,34 +415,34 @@ lfs_truncate(struct vnode *ovp, off_t le
413 415
414 genfs_node_wrlock(ovp); 416 genfs_node_wrlock(ovp);
415 417
416 oip->i_size = oip->i_ffs1_size = length; 418 oip->i_size = oip->i_ffs1_size = length;
417 uvm_vnp_setsize(ovp, length); 419 uvm_vnp_setsize(ovp, length);
418 420
419 /* 421 /*
420 * Calculate index into inode's block list of 422 * Calculate index into inode's block list of
421 * last direct and indirect blocks (if any) 423 * last direct and indirect blocks (if any)
422 * which we want to keep. Lastblock is -1 when 424 * which we want to keep. Lastblock is -1 when
423 * the file is truncated to 0. 425 * the file is truncated to 0.
424 */ 426 */
425 /* Avoid sign overflow - XXX assumes that off_t is a quad_t. */ 427 /* Avoid sign overflow - XXX assumes that off_t is a quad_t. */
426 if (length > QUAD_MAX - fs->lfs_bsize) 428 if (length > QUAD_MAX - lfs_sb_getbsize(fs))
427 lastblock = lfs_lblkno(fs, QUAD_MAX - fs->lfs_bsize); 429 lastblock = lfs_lblkno(fs, QUAD_MAX - lfs_sb_getbsize(fs));
428 else 430 else
429 lastblock = lfs_lblkno(fs, length + fs->lfs_bsize - 1) - 1; 431 lastblock = lfs_lblkno(fs, length + lfs_sb_getbsize(fs) - 1) - 1;
430 lastiblock[SINGLE] = lastblock - ULFS_NDADDR; 432 lastiblock[SINGLE] = lastblock - ULFS_NDADDR;
431 lastiblock[DOUBLE] = lastiblock[SINGLE] - LFS_NINDIR(fs); 433 lastiblock[DOUBLE] = lastiblock[SINGLE] - LFS_NINDIR(fs);
432 lastiblock[TRIPLE] = lastiblock[DOUBLE] - LFS_NINDIR(fs) * LFS_NINDIR(fs); 434 lastiblock[TRIPLE] = lastiblock[DOUBLE] - LFS_NINDIR(fs) * LFS_NINDIR(fs);
433 nblocks = lfs_btofsb(fs, fs->lfs_bsize); 435 nblocks = lfs_btofsb(fs, lfs_sb_getbsize(fs));
434 /* 436 /*
435 * Record changed file and block pointers before we start 437 * Record changed file and block pointers before we start
436 * freeing blocks. lastiblock values are also normalized to -1 438 * freeing blocks. lastiblock values are also normalized to -1
437 * for calls to lfs_indirtrunc below. 439 * for calls to lfs_indirtrunc below.
438 */ 440 */
439 memcpy((void *)newblks, (void *)&oip->i_ffs1_db[0], sizeof newblks); 441 memcpy((void *)newblks, (void *)&oip->i_ffs1_db[0], sizeof newblks);
440 for (level = TRIPLE; level >= SINGLE; level--) 442 for (level = TRIPLE; level >= SINGLE; level--)
441 if (lastiblock[level] < 0) { 443 if (lastiblock[level] < 0) {
442 newblks[ULFS_NDADDR+level] = 0; 444 newblks[ULFS_NDADDR+level] = 0;
443 lastiblock[level] = -1; 445 lastiblock[level] = -1;
444 } 446 }
445 for (i = ULFS_NDADDR - 1; i > lastblock; i--) 447 for (i = ULFS_NDADDR - 1; i > lastblock; i--)
446 newblks[i] = 0; 448 newblks[i] = 0;
@@ -462,27 +464,27 @@ lfs_truncate(struct vnode *ovp, off_t le @@ -462,27 +464,27 @@ lfs_truncate(struct vnode *ovp, off_t le
462 error = lfs_indirtrunc(oip, indir_lbn[level], 464 error = lfs_indirtrunc(oip, indir_lbn[level],
463 bn, lastiblock[level], 465 bn, lastiblock[level],
464 level, &count, &rcount, 466 level, &count, &rcount,
465 &lastseg, &bc); 467 &lastseg, &bc);
466 if (error) 468 if (error)
467 allerror = error; 469 allerror = error;
468 real_released += rcount; 470 real_released += rcount;
469 blocksreleased += count; 471 blocksreleased += count;
470 if (lastiblock[level] < 0) { 472 if (lastiblock[level] < 0) {
471 if (oip->i_ffs1_ib[level] > 0) 473 if (oip->i_ffs1_ib[level] > 0)
472 real_released += nblocks; 474 real_released += nblocks;
473 blocksreleased += nblocks; 475 blocksreleased += nblocks;
474 oip->i_ffs1_ib[level] = 0; 476 oip->i_ffs1_ib[level] = 0;
475 lfs_blkfree(fs, oip, bn, fs->lfs_bsize, 477 lfs_blkfree(fs, oip, bn, lfs_sb_getbsize(fs),
476 &lastseg, &bc); 478 &lastseg, &bc);
477 lfs_deregister_block(ovp, bn); 479 lfs_deregister_block(ovp, bn);
478 } 480 }
479 } 481 }
480 if (lastiblock[level] >= 0) 482 if (lastiblock[level] >= 0)
481 goto done; 483 goto done;
482 } 484 }
483 485
484 /* 486 /*
485 * All whole direct blocks or frags. 487 * All whole direct blocks or frags.
486 */ 488 */
487 for (i = ULFS_NDADDR - 1; i > lastblock; i--) { 489 for (i = ULFS_NDADDR - 1; i > lastblock; i--) {
488 long bsize, obsize; 490 long bsize, obsize;
@@ -555,27 +557,27 @@ done: @@ -555,27 +557,27 @@ done:
555 panic("lfs itrunc2"); 557 panic("lfs itrunc2");
556 } 558 }
557 if (length == 0 && 559 if (length == 0 &&
558 (!LIST_EMPTY(&ovp->v_cleanblkhd) || !LIST_EMPTY(&ovp->v_dirtyblkhd))) 560 (!LIST_EMPTY(&ovp->v_cleanblkhd) || !LIST_EMPTY(&ovp->v_dirtyblkhd)))
559 panic("lfs itrunc3"); 561 panic("lfs itrunc3");
560#endif /* DIAGNOSTIC */ 562#endif /* DIAGNOSTIC */
561 /* 563 /*
562 * Put back the real size. 564 * Put back the real size.
563 */ 565 */
564 oip->i_size = oip->i_ffs1_size = length; 566 oip->i_size = oip->i_ffs1_size = length;
565 oip->i_lfs_effnblks -= blocksreleased; 567 oip->i_lfs_effnblks -= blocksreleased;
566 oip->i_ffs1_blocks -= real_released; 568 oip->i_ffs1_blocks -= real_released;
567 mutex_enter(&lfs_lock); 569 mutex_enter(&lfs_lock);
568 fs->lfs_bfree += blocksreleased; 570 lfs_sb_addbfree(fs, blocksreleased);
569 mutex_exit(&lfs_lock); 571 mutex_exit(&lfs_lock);
570#ifdef DIAGNOSTIC 572#ifdef DIAGNOSTIC
571 if (oip->i_size == 0 && 573 if (oip->i_size == 0 &&
572 (oip->i_ffs1_blocks != 0 || oip->i_lfs_effnblks != 0)) { 574 (oip->i_ffs1_blocks != 0 || oip->i_lfs_effnblks != 0)) {
573 printf("lfs_truncate: truncate to 0 but %d blks/%d effblks\n", 575 printf("lfs_truncate: truncate to 0 but %d blks/%d effblks\n",
574 oip->i_ffs1_blocks, oip->i_lfs_effnblks); 576 oip->i_ffs1_blocks, oip->i_lfs_effnblks);
575 panic("lfs_truncate: persistent blocks"); 577 panic("lfs_truncate: persistent blocks");
576 } 578 }
577#endif 579#endif
578 580
579 /* 581 /*
580 * If we truncated to zero, take us off the paging queue. 582 * If we truncated to zero, take us off the paging queue.
581 */ 583 */
@@ -584,27 +586,27 @@ done: @@ -584,27 +586,27 @@ done:
584 oip->i_flags &= ~IN_PAGING; 586 oip->i_flags &= ~IN_PAGING;
585 TAILQ_REMOVE(&fs->lfs_pchainhd, oip, i_lfs_pchain); 587 TAILQ_REMOVE(&fs->lfs_pchainhd, oip, i_lfs_pchain);
586 } 588 }
587 mutex_exit(&lfs_lock); 589 mutex_exit(&lfs_lock);
588 590
589 oip->i_flag |= IN_CHANGE; 591 oip->i_flag |= IN_CHANGE;
590#if defined(LFS_QUOTA) || defined(LFS_QUOTA2) 592#if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
591 (void) lfs_chkdq(oip, -blocksreleased, NOCRED, 0); 593 (void) lfs_chkdq(oip, -blocksreleased, NOCRED, 0);
592#endif 594#endif
593 lfs_reserve(fs, ovp, NULL, 595 lfs_reserve(fs, ovp, NULL,
594 -lfs_btofsb(fs, (2 * ULFS_NIADDR + 3) << fs->lfs_bshift)); 596 -lfs_btofsb(fs, (2 * ULFS_NIADDR + 3) << fs->lfs_bshift));
595 genfs_node_unlock(ovp); 597 genfs_node_unlock(ovp);
596 errout: 598 errout:
597 oip->i_lfs_hiblk = lfs_lblkno(fs, oip->i_size + fs->lfs_bsize - 1) - 1; 599 oip->i_lfs_hiblk = lfs_lblkno(fs, oip->i_size + lfs_sb_getbsize(fs) - 1) - 1;
598 if (ovp != fs->lfs_ivnode) 600 if (ovp != fs->lfs_ivnode)
599 lfs_segunlock(fs); 601 lfs_segunlock(fs);
600 return (allerror ? allerror : error); 602 return (allerror ? allerror : error);
601} 603}
602 604
603/* Update segment and avail usage information when removing a block. */ 605/* Update segment and avail usage information when removing a block. */
604static int 606static int
605lfs_blkfree(struct lfs *fs, struct inode *ip, daddr_t daddr, 607lfs_blkfree(struct lfs *fs, struct inode *ip, daddr_t daddr,
606 size_t bsize, long *lastseg, size_t *num) 608 size_t bsize, long *lastseg, size_t *num)
607{ 609{
608 long seg; 610 long seg;
609 int error = 0; 611 int error = 0;
610 612
@@ -713,60 +715,60 @@ lfs_indirtrunc(struct inode *ip, daddr_t @@ -713,60 +715,60 @@ lfs_indirtrunc(struct inode *ip, daddr_t
713 715
714 ASSERT_SEGLOCK(fs); 716 ASSERT_SEGLOCK(fs);
715 /* 717 /*
716 * Calculate index in current block of last 718 * Calculate index in current block of last
717 * block to be kept. -1 indicates the entire 719 * block to be kept. -1 indicates the entire
718 * block so we need not calculate the index. 720 * block so we need not calculate the index.
719 */ 721 */
720 factor = 1; 722 factor = 1;
721 for (i = SINGLE; i < level; i++) 723 for (i = SINGLE; i < level; i++)
722 factor *= LFS_NINDIR(fs); 724 factor *= LFS_NINDIR(fs);
723 last = lastbn; 725 last = lastbn;
724 if (lastbn > 0) 726 if (lastbn > 0)
725 last /= factor; 727 last /= factor;
726 nblocks = lfs_btofsb(fs, fs->lfs_bsize); 728 nblocks = lfs_btofsb(fs, lfs_sb_getbsize(fs));
727 /* 729 /*
728 * Get buffer of block pointers, zero those entries corresponding 730 * Get buffer of block pointers, zero those entries corresponding
729 * to blocks to be free'd, and update on disk copy first. Since 731 * to blocks to be free'd, and update on disk copy first. Since
730 * double(triple) indirect before single(double) indirect, calls 732 * double(triple) indirect before single(double) indirect, calls
731 * to bmap on these blocks will fail. However, we already have 733 * to bmap on these blocks will fail. However, we already have
732 * the on disk address, so we have to set the b_blkno field 734 * the on disk address, so we have to set the b_blkno field
733 * explicitly instead of letting bread do everything for us. 735 * explicitly instead of letting bread do everything for us.
734 */ 736 */
735 vp = ITOV(ip); 737 vp = ITOV(ip);
736 bp = getblk(vp, lbn, (int)fs->lfs_bsize, 0, 0); 738 bp = getblk(vp, lbn, lfs_sb_getbsize(fs), 0, 0);
737 if (bp->b_oflags & (BO_DONE | BO_DELWRI)) { 739 if (bp->b_oflags & (BO_DONE | BO_DELWRI)) {
738 /* Braces must be here in case trace evaluates to nothing. */ 740 /* Braces must be here in case trace evaluates to nothing. */
739 trace(TR_BREADHIT, pack(vp, fs->lfs_bsize), lbn); 741 trace(TR_BREADHIT, pack(vp, lfs_sb_getbsize(fs)), lbn);
740 } else { 742 } else {
741 trace(TR_BREADMISS, pack(vp, fs->lfs_bsize), lbn); 743 trace(TR_BREADMISS, pack(vp, lfs_sb_getbsize(fs)), lbn);
742 curlwp->l_ru.ru_inblock++; /* pay for read */ 744 curlwp->l_ru.ru_inblock++; /* pay for read */
743 bp->b_flags |= B_READ; 745 bp->b_flags |= B_READ;
744 if (bp->b_bcount > bp->b_bufsize) 746 if (bp->b_bcount > bp->b_bufsize)
745 panic("lfs_indirtrunc: bad buffer size"); 747 panic("lfs_indirtrunc: bad buffer size");
746 bp->b_blkno = LFS_FSBTODB(fs, dbn); 748 bp->b_blkno = LFS_FSBTODB(fs, dbn);
747 VOP_STRATEGY(vp, bp); 749 VOP_STRATEGY(vp, bp);
748 error = biowait(bp); 750 error = biowait(bp);
749 } 751 }
750 if (error) { 752 if (error) {
751 brelse(bp, 0); 753 brelse(bp, 0);
752 *countp = *rcountp = 0; 754 *countp = *rcountp = 0;
753 return (error); 755 return (error);
754 } 756 }
755 757
756 bap = (int32_t *)bp->b_data; /* XXX ondisk32 */ 758 bap = (int32_t *)bp->b_data; /* XXX ondisk32 */
757 if (lastbn >= 0) { 759 if (lastbn >= 0) {
758 copy = lfs_malloc(fs, fs->lfs_bsize, LFS_NB_IBLOCK); 760 copy = lfs_malloc(fs, lfs_sb_getbsize(fs), LFS_NB_IBLOCK);
759 memcpy((void *)copy, (void *)bap, (u_int)fs->lfs_bsize); 761 memcpy((void *)copy, (void *)bap, lfs_sb_getbsize(fs));
760 memset((void *)&bap[last + 1], 0, 762 memset((void *)&bap[last + 1], 0,
761 /* XXX ondisk32 */ 763 /* XXX ondisk32 */
762 (u_int)(LFS_NINDIR(fs) - (last + 1)) * sizeof (int32_t)); 764 (u_int)(LFS_NINDIR(fs) - (last + 1)) * sizeof (int32_t));
763 error = VOP_BWRITE(bp->b_vp, bp); 765 error = VOP_BWRITE(bp->b_vp, bp);
764 if (error) 766 if (error)
765 allerror = error; 767 allerror = error;
766 bap = copy; 768 bap = copy;
767 } 769 }
768 770
769 /* 771 /*
770 * Recursively free totally unused blocks. 772 * Recursively free totally unused blocks.
771 */ 773 */
772 for (i = LFS_NINDIR(fs) - 1, nlbn = lbn + 1 - i * factor; i > last; 774 for (i = LFS_NINDIR(fs) - 1, nlbn = lbn + 1 - i * factor; i > last;
@@ -774,27 +776,27 @@ lfs_indirtrunc(struct inode *ip, daddr_t @@ -774,27 +776,27 @@ lfs_indirtrunc(struct inode *ip, daddr_t
774 nb = bap[i]; 776 nb = bap[i];
775 if (nb == 0) 777 if (nb == 0)
776 continue; 778 continue;
777 if (level > SINGLE) { 779 if (level > SINGLE) {
778 error = lfs_indirtrunc(ip, nlbn, nb, 780 error = lfs_indirtrunc(ip, nlbn, nb,
779 (daddr_t)-1, level - 1, 781 (daddr_t)-1, level - 1,
780 &blkcount, &rblkcount, 782 &blkcount, &rblkcount,
781 lastsegp, bcp); 783 lastsegp, bcp);
782 if (error) 784 if (error)
783 allerror = error; 785 allerror = error;
784 blocksreleased += blkcount; 786 blocksreleased += blkcount;
785 real_released += rblkcount; 787 real_released += rblkcount;
786 } 788 }
787 lfs_blkfree(fs, ip, nb, fs->lfs_bsize, lastsegp, bcp); 789 lfs_blkfree(fs, ip, nb, lfs_sb_getbsize(fs), lastsegp, bcp);
788 if (bap[i] > 0) 790 if (bap[i] > 0)
789 real_released += nblocks; 791 real_released += nblocks;
790 blocksreleased += nblocks; 792 blocksreleased += nblocks;
791 } 793 }
792 794
793 /* 795 /*
794 * Recursively free last partial block. 796 * Recursively free last partial block.
795 */ 797 */
796 if (level > SINGLE && lastbn >= 0) { 798 if (level > SINGLE && lastbn >= 0) {
797 last = lastbn % factor; 799 last = lastbn % factor;
798 nb = bap[i]; 800 nb = bap[i];
799 if (nb != 0) { 801 if (nb != 0) {
800 error = lfs_indirtrunc(ip, nlbn, nb, 802 error = lfs_indirtrunc(ip, nlbn, nb,
@@ -803,28 +805,28 @@ lfs_indirtrunc(struct inode *ip, daddr_t @@ -803,28 +805,28 @@ lfs_indirtrunc(struct inode *ip, daddr_t
803 if (error) 805 if (error)
804 allerror = error; 806 allerror = error;
805 real_released += rblkcount; 807 real_released += rblkcount;
806 blocksreleased += blkcount; 808 blocksreleased += blkcount;
807 } 809 }
808 } 810 }
809 811
810 if (copy != NULL) { 812 if (copy != NULL) {
811 lfs_free(fs, copy, LFS_NB_IBLOCK); 813 lfs_free(fs, copy, LFS_NB_IBLOCK);
812 } else { 814 } else {
813 mutex_enter(&bufcache_lock); 815 mutex_enter(&bufcache_lock);
814 if (bp->b_oflags & BO_DELWRI) { 816 if (bp->b_oflags & BO_DELWRI) {
815 LFS_UNLOCK_BUF(bp); 817 LFS_UNLOCK_BUF(bp);
816 fs->lfs_avail += lfs_btofsb(fs, bp->b_bcount); 818 lfs_sb_addavail(fs, lfs_btofsb(fs, bp->b_bcount));
817 wakeup(&fs->lfs_avail); 819 wakeup(&fs->lfs_availsleep);
818 } 820 }
819 brelsel(bp, BC_INVAL); 821 brelsel(bp, BC_INVAL);
820 mutex_exit(&bufcache_lock); 822 mutex_exit(&bufcache_lock);
821 } 823 }
822 824
823 *countp = blocksreleased; 825 *countp = blocksreleased;
824 *rcountp = real_released; 826 *rcountp = real_released;
825 return (allerror); 827 return (allerror);
826} 828}
827 829
828/* 830/*
829 * Destroy any in core blocks past the truncation length. 831 * Destroy any in core blocks past the truncation length.
830 * Inlined from vtruncbuf, so that lfs_avail could be updated. 832 * Inlined from vtruncbuf, so that lfs_avail could be updated.
@@ -855,47 +857,47 @@ restart:  @@ -855,47 +857,47 @@ restart:
855 nbp = LIST_NEXT(bp, b_vnbufs); 857 nbp = LIST_NEXT(bp, b_vnbufs);
856 if (bp->b_lblkno < lbn) 858 if (bp->b_lblkno < lbn)
857 continue; 859 continue;
858 error = bbusy(bp, catch, slptimeo, NULL); 860 error = bbusy(bp, catch, slptimeo, NULL);
859 if (error == EPASSTHROUGH) 861 if (error == EPASSTHROUGH)
860 goto restart; 862 goto restart;
861 if (error != 0) { 863 if (error != 0) {
862 mutex_exit(&bufcache_lock); 864 mutex_exit(&bufcache_lock);
863 return (error); 865 return (error);
864 } 866 }
865 mutex_enter(bp->b_objlock); 867 mutex_enter(bp->b_objlock);
866 if (bp->b_oflags & BO_DELWRI) { 868 if (bp->b_oflags & BO_DELWRI) {
867 bp->b_oflags &= ~BO_DELWRI; 869 bp->b_oflags &= ~BO_DELWRI;
868 fs->lfs_avail += lfs_btofsb(fs, bp->b_bcount); 870 lfs_sb_addavail(fs, lfs_btofsb(fs, bp->b_bcount));
869 wakeup(&fs->lfs_avail); 871 wakeup(&fs->lfs_availsleep);
870 } 872 }
871 mutex_exit(bp->b_objlock); 873 mutex_exit(bp->b_objlock);
872 LFS_UNLOCK_BUF(bp); 874 LFS_UNLOCK_BUF(bp);
873 brelsel(bp, BC_INVAL | BC_VFLUSH); 875 brelsel(bp, BC_INVAL | BC_VFLUSH);
874 } 876 }
875 877
876 for (bp = LIST_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) { 878 for (bp = LIST_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
877 nbp = LIST_NEXT(bp, b_vnbufs); 879 nbp = LIST_NEXT(bp, b_vnbufs);
878 if (bp->b_lblkno < lbn) 880 if (bp->b_lblkno < lbn)
879 continue; 881 continue;
880 error = bbusy(bp, catch, slptimeo, NULL); 882 error = bbusy(bp, catch, slptimeo, NULL);
881 if (error == EPASSTHROUGH) 883 if (error == EPASSTHROUGH)
882 goto restart; 884 goto restart;
883 if (error != 0) { 885 if (error != 0) {
884 mutex_exit(&bufcache_lock); 886 mutex_exit(&bufcache_lock);
885 return (error); 887 return (error);
886 } 888 }
887 mutex_enter(bp->b_objlock); 889 mutex_enter(bp->b_objlock);
888 if (bp->b_oflags & BO_DELWRI) { 890 if (bp->b_oflags & BO_DELWRI) {
889 bp->b_oflags &= ~BO_DELWRI; 891 bp->b_oflags &= ~BO_DELWRI;
890 fs->lfs_avail += lfs_btofsb(fs, bp->b_bcount); 892 lfs_sb_addavail(fs, lfs_btofsb(fs, bp->b_bcount));
891 wakeup(&fs->lfs_avail); 893 wakeup(&fs->lfs_availsleep);
892 } 894 }
893 mutex_exit(bp->b_objlock); 895 mutex_exit(bp->b_objlock);
894 LFS_UNLOCK_BUF(bp); 896 LFS_UNLOCK_BUF(bp);
895 brelsel(bp, BC_INVAL | BC_VFLUSH); 897 brelsel(bp, BC_INVAL | BC_VFLUSH);
896 } 898 }
897 mutex_exit(&bufcache_lock); 899 mutex_exit(&bufcache_lock);
898 900
899 return (0); 901 return (0);
900} 902}
901 903

cvs diff -r1.1 -r1.2 src/sys/ufs/lfs/lfs_pages.c (expand / switch to unified diff)

--- src/sys/ufs/lfs/lfs_pages.c 2014/05/16 09:34:03 1.1
+++ src/sys/ufs/lfs/lfs_pages.c 2015/07/24 06:56:42 1.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lfs_pages.c,v 1.1 2014/05/16 09:34:03 dholland Exp $ */ 1/* $NetBSD: lfs_pages.c,v 1.2 2015/07/24 06:56:42 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant@hhhh.org>. 8 * by Konrad E. Schroder <perseant@hhhh.org>.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -50,27 +50,27 @@ @@ -50,27 +50,27 @@
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE. 57 * SUCH DAMAGE.
58 * 58 *
59 * @(#)lfs_vnops.c 8.13 (Berkeley) 6/10/95 59 * @(#)lfs_vnops.c 8.13 (Berkeley) 6/10/95
60 */ 60 */
61 61
62#include <sys/cdefs.h> 62#include <sys/cdefs.h>
63__KERNEL_RCSID(0, "$NetBSD: lfs_pages.c,v 1.1 2014/05/16 09:34:03 dholland Exp $"); 63__KERNEL_RCSID(0, "$NetBSD: lfs_pages.c,v 1.2 2015/07/24 06:56:42 dholland Exp $");
64 64
65#ifdef _KERNEL_OPT 65#ifdef _KERNEL_OPT
66#include "opt_compat_netbsd.h" 66#include "opt_compat_netbsd.h"
67#include "opt_uvm_page_trkown.h" 67#include "opt_uvm_page_trkown.h"
68#endif 68#endif
69 69
70#include <sys/param.h> 70#include <sys/param.h>
71#include <sys/systm.h> 71#include <sys/systm.h>
72#include <sys/namei.h> 72#include <sys/namei.h>
73#include <sys/resourcevar.h> 73#include <sys/resourcevar.h>
74#include <sys/kernel.h> 74#include <sys/kernel.h>
75#include <sys/file.h> 75#include <sys/file.h>
76#include <sys/stat.h> 76#include <sys/stat.h>
@@ -241,27 +241,27 @@ check_dirty(struct lfs *fs, struct vnode @@ -241,27 +241,27 @@ check_dirty(struct lfs *fs, struct vnode
241 off_t startoffset, off_t endoffset, off_t blkeof, 241 off_t startoffset, off_t endoffset, off_t blkeof,
242 int flags, int checkfirst, struct vm_page **pgp) 242 int flags, int checkfirst, struct vm_page **pgp)
243{ 243{
244 int by_list; 244 int by_list;
245 struct vm_page *curpg = NULL; /* XXX: gcc */ 245 struct vm_page *curpg = NULL; /* XXX: gcc */
246 struct vm_page *pgs[MAXBSIZE / PAGE_SIZE], *pg; 246 struct vm_page *pgs[MAXBSIZE / PAGE_SIZE], *pg;
247 off_t soff = 0; /* XXX: gcc */ 247 off_t soff = 0; /* XXX: gcc */
248 voff_t off; 248 voff_t off;
249 int i; 249 int i;
250 int nonexistent; 250 int nonexistent;
251 int any_dirty; /* number of dirty pages */ 251 int any_dirty; /* number of dirty pages */
252 int dirty; /* number of dirty pages in a block */ 252 int dirty; /* number of dirty pages in a block */
253 int tdirty; 253 int tdirty;
254 int pages_per_block = fs->lfs_bsize >> PAGE_SHIFT; 254 int pages_per_block = lfs_sb_getbsize(fs) >> PAGE_SHIFT;
255 int pagedaemon = (curlwp == uvm.pagedaemon_lwp); 255 int pagedaemon = (curlwp == uvm.pagedaemon_lwp);
256 256
257 KASSERT(mutex_owned(vp->v_interlock)); 257 KASSERT(mutex_owned(vp->v_interlock));
258 ASSERT_MAYBE_SEGLOCK(fs); 258 ASSERT_MAYBE_SEGLOCK(fs);
259 top: 259 top:
260 by_list = (vp->v_uobj.uo_npages <= 260 by_list = (vp->v_uobj.uo_npages <=
261 ((endoffset - startoffset) >> PAGE_SHIFT) * 261 ((endoffset - startoffset) >> PAGE_SHIFT) *
262 UVM_PAGE_TREE_PENALTY); 262 UVM_PAGE_TREE_PENALTY);
263 any_dirty = 0; 263 any_dirty = 0;
264 264
265 if (by_list) { 265 if (by_list) {
266 curpg = TAILQ_FIRST(&vp->v_uobj.memq); 266 curpg = TAILQ_FIRST(&vp->v_uobj.memq);
267 } else { 267 } else {
@@ -337,27 +337,27 @@ check_dirty(struct lfs *fs, struct vnode @@ -337,27 +337,27 @@ check_dirty(struct lfs *fs, struct vnode
337 } 337 }
338 pg->flags |= PG_BUSY; 338 pg->flags |= PG_BUSY;
339 UVM_PAGE_OWN(pg, "lfs_putpages"); 339 UVM_PAGE_OWN(pg, "lfs_putpages");
340 340
341 pmap_page_protect(pg, VM_PROT_NONE); 341 pmap_page_protect(pg, VM_PROT_NONE);
342 tdirty = (pmap_clear_modify(pg) || 342 tdirty = (pmap_clear_modify(pg) ||
343 (pg->flags & PG_CLEAN) == 0); 343 (pg->flags & PG_CLEAN) == 0);
344 dirty += tdirty; 344 dirty += tdirty;
345 } 345 }
346 if (pages_per_block > 0 && nonexistent >= pages_per_block) { 346 if (pages_per_block > 0 && nonexistent >= pages_per_block) {
347 if (by_list) { 347 if (by_list) {
348 curpg = TAILQ_NEXT(curpg, listq.queue); 348 curpg = TAILQ_NEXT(curpg, listq.queue);
349 } else { 349 } else {
350 soff += fs->lfs_bsize; 350 soff += lfs_sb_getbsize(fs);
351 } 351 }
352 continue; 352 continue;
353 } 353 }
354 354
355 any_dirty += dirty; 355 any_dirty += dirty;
356 KASSERT(nonexistent == 0); 356 KASSERT(nonexistent == 0);
357 KASSERT(mutex_owned(vp->v_interlock)); 357 KASSERT(mutex_owned(vp->v_interlock));
358 358
359 /* 359 /*
360 * If any are dirty make all dirty; unbusy them, 360 * If any are dirty make all dirty; unbusy them,
361 * but if we were asked to clean, wire them so that 361 * but if we were asked to clean, wire them so that
362 * the pagedaemon doesn't bother us about them while 362 * the pagedaemon doesn't bother us about them while
363 * they're on their way to disk. 363 * they're on their way to disk.
@@ -384,27 +384,27 @@ check_dirty(struct lfs *fs, struct vnode @@ -384,27 +384,27 @@ check_dirty(struct lfs *fs, struct vnode
384 } 384 }
385 if (pg->flags & PG_WANTED) 385 if (pg->flags & PG_WANTED)
386 wakeup(pg); 386 wakeup(pg);
387 pg->flags &= ~(PG_WANTED|PG_BUSY); 387 pg->flags &= ~(PG_WANTED|PG_BUSY);
388 UVM_PAGE_OWN(pg, NULL); 388 UVM_PAGE_OWN(pg, NULL);
389 } 389 }
390 390
391 if (checkfirst && any_dirty) 391 if (checkfirst && any_dirty)
392 break; 392 break;
393 393
394 if (by_list) { 394 if (by_list) {
395 curpg = TAILQ_NEXT(curpg, listq.queue); 395 curpg = TAILQ_NEXT(curpg, listq.queue);
396 } else { 396 } else {
397 soff += MAX(PAGE_SIZE, fs->lfs_bsize); 397 soff += MAX(PAGE_SIZE, lfs_sb_getbsize(fs));
398 } 398 }
399 } 399 }
400 400
401 KASSERT(mutex_owned(vp->v_interlock)); 401 KASSERT(mutex_owned(vp->v_interlock));
402 return any_dirty; 402 return any_dirty;
403} 403}
404 404
405/* 405/*
406 * lfs_putpages functions like genfs_putpages except that 406 * lfs_putpages functions like genfs_putpages except that
407 * 407 *
408 * (1) It needs to bounds-check the incoming requests to ensure that 408 * (1) It needs to bounds-check the incoming requests to ensure that
409 * they are block-aligned; if they are not, expand the range and 409 * they are block-aligned; if they are not, expand the range and
410 * do the right thing in case, e.g., the requested range is clean 410 * do the right thing in case, e.g., the requested range is clean
@@ -514,27 +514,27 @@ lfs_putpages(void *v) @@ -514,27 +514,27 @@ lfs_putpages(void *v)
514 514
515 /* 515 /*
516 * Ignore requests to free pages past EOF but in the same block 516 * Ignore requests to free pages past EOF but in the same block
517 * as EOF, unless the vnode is being reclaimed or the request 517 * as EOF, unless the vnode is being reclaimed or the request
518 * is synchronous. (If the request is sync, it comes from 518 * is synchronous. (If the request is sync, it comes from
519 * lfs_truncate.) 519 * lfs_truncate.)
520 * 520 *
521 * To avoid being flooded with this request, make these pages 521 * To avoid being flooded with this request, make these pages
522 * look "active". 522 * look "active".
523 */ 523 */
524 if (!sync && !reclaim && 524 if (!sync && !reclaim &&
525 ap->a_offlo >= ip->i_size && ap->a_offlo < blkeof) { 525 ap->a_offlo >= ip->i_size && ap->a_offlo < blkeof) {
526 origoffset = ap->a_offlo; 526 origoffset = ap->a_offlo;
527 for (off = origoffset; off < blkeof; off += fs->lfs_bsize) { 527 for (off = origoffset; off < blkeof; off += lfs_sb_getbsize(fs)) {
528 pg = uvm_pagelookup(&vp->v_uobj, off); 528 pg = uvm_pagelookup(&vp->v_uobj, off);
529 KASSERT(pg != NULL); 529 KASSERT(pg != NULL);
530 while (pg->flags & PG_BUSY) { 530 while (pg->flags & PG_BUSY) {
531 pg->flags |= PG_WANTED; 531 pg->flags |= PG_WANTED;
532 UVM_UNLOCK_AND_WAIT(pg, vp->v_interlock, 0, 532 UVM_UNLOCK_AND_WAIT(pg, vp->v_interlock, 0,
533 "lfsput2", 0); 533 "lfsput2", 0);
534 mutex_enter(vp->v_interlock); 534 mutex_enter(vp->v_interlock);
535 } 535 }
536 mutex_enter(&uvm_pageqlock); 536 mutex_enter(&uvm_pageqlock);
537 uvm_pageactivate(pg); 537 uvm_pageactivate(pg);
538 mutex_exit(&uvm_pageqlock); 538 mutex_exit(&uvm_pageqlock);
539 } 539 }
540 ap->a_offlo = blkeof; 540 ap->a_offlo = blkeof;
@@ -783,27 +783,27 @@ lfs_putpages(void *v) @@ -783,27 +783,27 @@ lfs_putpages(void *v)
783  783
784 if (error == EDEADLK || error == EAGAIN) { 784 if (error == EDEADLK || error == EAGAIN) {
785 DLOG((DLOG_PAGE, "lfs_putpages: genfs_putpages returned" 785 DLOG((DLOG_PAGE, "lfs_putpages: genfs_putpages returned"
786 " %d ino %d off %x (seg %d)\n", error, 786 " %d ino %d off %x (seg %d)\n", error,
787 ip->i_number, fs->lfs_offset, 787 ip->i_number, fs->lfs_offset,
788 lfs_dtosn(fs, fs->lfs_offset))); 788 lfs_dtosn(fs, fs->lfs_offset)));
789 789
790 if (oreclaim) { 790 if (oreclaim) {
791 mutex_enter(vp->v_interlock); 791 mutex_enter(vp->v_interlock);
792 write_and_wait(fs, vp, busypg, seglocked, "again"); 792 write_and_wait(fs, vp, busypg, seglocked, "again");
793 mutex_exit(vp->v_interlock); 793 mutex_exit(vp->v_interlock);
794 } else { 794 } else {
795 if ((sp->seg_flags & SEGM_SINGLE) && 795 if ((sp->seg_flags & SEGM_SINGLE) &&
796 fs->lfs_curseg != fs->lfs_startseg) 796 lfs_sb_getcurseg(fs) != fs->lfs_startseg)
797 donewriting = 1; 797 donewriting = 1;
798 } 798 }
799 } else if (error) { 799 } else if (error) {
800 DLOG((DLOG_PAGE, "lfs_putpages: genfs_putpages returned" 800 DLOG((DLOG_PAGE, "lfs_putpages: genfs_putpages returned"
801 " %d ino %d off %x (seg %d)\n", error, 801 " %d ino %d off %x (seg %d)\n", error,
802 (int)ip->i_number, fs->lfs_offset, 802 (int)ip->i_number, fs->lfs_offset,
803 lfs_dtosn(fs, fs->lfs_offset))); 803 lfs_dtosn(fs, fs->lfs_offset)));
804 } 804 }
805 /* genfs_do_putpages loses the interlock */ 805 /* genfs_do_putpages loses the interlock */
806#ifdef DEBUG 806#ifdef DEBUG
807 ++debug_n_again; 807 ++debug_n_again;
808#endif 808#endif
809 if (oreclaim && error == EAGAIN) { 809 if (oreclaim && error == EAGAIN) {

cvs diff -r1.21 -r1.22 src/sys/ufs/lfs/lfs_rfw.c (expand / switch to unified diff)

--- src/sys/ufs/lfs/lfs_rfw.c 2015/07/16 08:31:45 1.21
+++ src/sys/ufs/lfs/lfs_rfw.c 2015/07/24 06:56:42 1.22
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lfs_rfw.c,v 1.21 2015/07/16 08:31:45 dholland Exp $ */ 1/* $NetBSD: lfs_rfw.c,v 1.22 2015/07/24 06:56:42 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant@hhhh.org>. 8 * by Konrad E. Schroder <perseant@hhhh.org>.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 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 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 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 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 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 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: lfs_rfw.c,v 1.21 2015/07/16 08:31:45 dholland Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: lfs_rfw.c,v 1.22 2015/07/24 06:56:42 dholland Exp $");
34 34
35#if defined(_KERNEL_OPT) 35#if defined(_KERNEL_OPT)
36#include "opt_quota.h" 36#include "opt_quota.h"
37#endif 37#endif
38 38
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/systm.h> 40#include <sys/systm.h>
41#include <sys/namei.h> 41#include <sys/namei.h>
42#include <sys/proc.h> 42#include <sys/proc.h>
43#include <sys/kernel.h> 43#include <sys/kernel.h>
44#include <sys/vnode.h> 44#include <sys/vnode.h>
45#include <sys/mount.h> 45#include <sys/mount.h>
46#include <sys/kthread.h> 46#include <sys/kthread.h>
@@ -182,43 +182,44 @@ update_meta(struct lfs *fs, ino_t ino, i @@ -182,43 +182,44 @@ update_meta(struct lfs *fs, ino_t ino, i
182 DLOG((DLOG_RF, "update_meta: ino %d: lfs_rf_valloc" 182 DLOG((DLOG_RF, "update_meta: ino %d: lfs_rf_valloc"
183 " returned %d\n", ino, error)); 183 " returned %d\n", ino, error));
184 return error; 184 return error;
185 } 185 }
186 186
187 if ((error = lfs_balloc(vp, (lbn << fs->lfs_bshift), size, 187 if ((error = lfs_balloc(vp, (lbn << fs->lfs_bshift), size,
188 NOCRED, 0, &bp)) != 0) { 188 NOCRED, 0, &bp)) != 0) {
189 vput(vp); 189 vput(vp);
190 return (error); 190 return (error);
191 } 191 }
192 /* No need to write, the block is already on disk */ 192 /* No need to write, the block is already on disk */
193 if (bp->b_oflags & BO_DELWRI) { 193 if (bp->b_oflags & BO_DELWRI) {
194 LFS_UNLOCK_BUF(bp); 194 LFS_UNLOCK_BUF(bp);
195 fs->lfs_avail += lfs_btofsb(fs, bp->b_bcount); 195 lfs_sb_addavail(fs, lfs_btofsb(fs, bp->b_bcount));
 196 /* XXX should this wake up fs->lfs_availsleep? */
196 } 197 }
197 brelse(bp, BC_INVAL); 198 brelse(bp, BC_INVAL);
198 199
199 /* 200 /*
200 * Extend the file, if it is not large enough already. 201 * Extend the file, if it is not large enough already.
201 * XXX this is not exactly right, we don't know how much of the 202 * XXX this is not exactly right, we don't know how much of the
202 * XXX last block is actually used. We hope that an inode will 203 * XXX last block is actually used. We hope that an inode will
203 * XXX appear later to give the correct size. 204 * XXX appear later to give the correct size.
204 */ 205 */
205 ip = VTOI(vp); 206 ip = VTOI(vp);
206 if (ip->i_size <= (lbn << fs->lfs_bshift)) { 207 if (ip->i_size <= (lbn << fs->lfs_bshift)) {
207 u_int64_t newsize; 208 u_int64_t newsize;
208 209
209 if (lbn < ULFS_NDADDR) 210 if (lbn < ULFS_NDADDR)
210 newsize = ip->i_ffs1_size = (lbn << fs->lfs_bshift) + 211 newsize = ip->i_ffs1_size = (lbn << fs->lfs_bshift) +
211 (size - fs->lfs_fsize) + 1; 212 (size - lfs_sb_getfsize(fs)) + 1;
212 else 213 else
213 newsize = ip->i_ffs1_size = (lbn << fs->lfs_bshift) + 1; 214 newsize = ip->i_ffs1_size = (lbn << fs->lfs_bshift) + 1;
214 215
215 if (ip->i_size < newsize) { 216 if (ip->i_size < newsize) {
216 ip->i_size = newsize; 217 ip->i_size = newsize;
217 /* 218 /*
218 * tell vm our new size for the case the inode won't 219 * tell vm our new size for the case the inode won't
219 * appear later. 220 * appear later.
220 */ 221 */
221 uvm_vnp_setsize(vp, newsize); 222 uvm_vnp_setsize(vp, newsize);
222 } 223 }
223 } 224 }
224 225
@@ -377,27 +378,27 @@ check_segsum(struct lfs *fs, daddr_t off @@ -377,27 +378,27 @@ check_segsum(struct lfs *fs, daddr_t off
377 if (flags & CHECK_CKSUM) { 378 if (flags & CHECK_CKSUM) {
378 if (ssp->ss_sumsum != cksum(&ssp->ss_datasum, 379 if (ssp->ss_sumsum != cksum(&ssp->ss_datasum,
379 fs->lfs_sumsize - 380 fs->lfs_sumsize -
380 sizeof(ssp->ss_sumsum))) { 381 sizeof(ssp->ss_sumsum))) {
381 DLOG((DLOG_RF, "Sumsum error at 0x%" PRIx64 "\n", offset)); 382 DLOG((DLOG_RF, "Sumsum error at 0x%" PRIx64 "\n", offset));
382 offset = -1; 383 offset = -1;
383 goto err1; 384 goto err1;
384 } 385 }
385 if (ssp->ss_nfinfo == 0 && ssp->ss_ninos == 0) { 386 if (ssp->ss_nfinfo == 0 && ssp->ss_ninos == 0) {
386 DLOG((DLOG_RF, "Empty pseg at 0x%" PRIx64 "\n", offset)); 387 DLOG((DLOG_RF, "Empty pseg at 0x%" PRIx64 "\n", offset));
387 offset = -1; 388 offset = -1;
388 goto err1; 389 goto err1;
389 } 390 }
390 if (ssp->ss_create < fs->lfs_tstamp) { 391 if (ssp->ss_create < lfs_sb_gettstamp(fs)) {
391 DLOG((DLOG_RF, "Old data at 0x%" PRIx64 "\n", offset)); 392 DLOG((DLOG_RF, "Old data at 0x%" PRIx64 "\n", offset));
392 offset = -1; 393 offset = -1;
393 goto err1; 394 goto err1;
394 } 395 }
395 } 396 }
396 if (fs->lfs_version > 1) { 397 if (fs->lfs_version > 1) {
397 if (ssp->ss_serial != nextserial) { 398 if (ssp->ss_serial != nextserial) {
398 DLOG((DLOG_RF, "Unexpected serial number at 0x%" PRIx64 399 DLOG((DLOG_RF, "Unexpected serial number at 0x%" PRIx64
399 "\n", offset)); 400 "\n", offset));
400 offset = -1; 401 offset = -1;
401 goto err1; 402 goto err1;
402 } 403 }
403 if (ssp->ss_ident != fs->lfs_ident) { 404 if (ssp->ss_ident != fs->lfs_ident) {
@@ -430,49 +431,49 @@ check_segsum(struct lfs *fs, daddr_t off @@ -430,49 +431,49 @@ check_segsum(struct lfs *fs, daddr_t off
430 nblocks += ninos; 431 nblocks += ninos;
431 /* Create the sum array */ 432 /* Create the sum array */
432 datap = dp = malloc(nblocks * sizeof(u_long), 433 datap = dp = malloc(nblocks * sizeof(u_long),
433 M_SEGMENT, M_WAITOK); 434 M_SEGMENT, M_WAITOK);
434 } 435 }
435 436
436 /* Handle individual blocks */ 437 /* Handle individual blocks */
437 fip = (FINFO *)((char*)bp->b_data + SEGSUM_SIZE(fs)); 438 fip = (FINFO *)((char*)bp->b_data + SEGSUM_SIZE(fs));
438 for (i = 0; i < ssp->ss_nfinfo || ninos; ++i) { 439 for (i = 0; i < ssp->ss_nfinfo || ninos; ++i) {
439 /* Inode block? */ 440 /* Inode block? */
440 if (ninos && *iaddr == offset) { 441 if (ninos && *iaddr == offset) {
441 if (flags & CHECK_CKSUM) { 442 if (flags & CHECK_CKSUM) {
442 /* Read in the head and add to the buffer */ 443 /* Read in the head and add to the buffer */
443 error = bread(devvp, LFS_FSBTODB(fs, offset), fs->lfs_bsize, 444 error = bread(devvp, LFS_FSBTODB(fs, offset), lfs_sb_getbsize(fs),
444 0, &dbp); 445 0, &dbp);
445 if (error) { 446 if (error) {
446 offset = -1; 447 offset = -1;
447 goto err2; 448 goto err2;
448 } 449 }
449 (*dp++) = ((u_long *)(dbp->b_data))[0]; 450 (*dp++) = ((u_long *)(dbp->b_data))[0];
450 brelse(dbp, BC_AGE); 451 brelse(dbp, BC_AGE);
451 } 452 }
452 if (flags & CHECK_UPDATE) { 453 if (flags & CHECK_UPDATE) {
453 if ((error = update_inoblk(fs, offset, cred, l)) 454 if ((error = update_inoblk(fs, offset, cred, l))
454 != 0) { 455 != 0) {
455 offset = -1; 456 offset = -1;
456 goto err2; 457 goto err2;
457 } 458 }
458 } 459 }
459 offset += lfs_btofsb(fs, fs->lfs_ibsize); 460 offset += lfs_btofsb(fs, fs->lfs_ibsize);
460 --iaddr; 461 --iaddr;
461 --ninos; 462 --ninos;
462 --i; /* compensate */ 463 --i; /* compensate */
463 continue; 464 continue;
464 } 465 }
465 size = fs->lfs_bsize; 466 size = lfs_sb_getbsize(fs);
466 for (j = 0; j < fip->fi_nblocks; ++j) { 467 for (j = 0; j < fip->fi_nblocks; ++j) {
467 if (j == fip->fi_nblocks - 1) 468 if (j == fip->fi_nblocks - 1)
468 size = fip->fi_lastlength; 469 size = fip->fi_lastlength;
469 if (flags & CHECK_CKSUM) { 470 if (flags & CHECK_CKSUM) {
470 error = bread(devvp, LFS_FSBTODB(fs, offset), size, 471 error = bread(devvp, LFS_FSBTODB(fs, offset), size,
471 0, &dbp); 472 0, &dbp);
472 if (error) { 473 if (error) {
473 offset = -1; 474 offset = -1;
474 goto err2; 475 goto err2;
475 } 476 }
476 (*dp++) = ((u_long *)(dbp->b_data))[0]; 477 (*dp++) = ((u_long *)(dbp->b_data))[0];
477 brelse(dbp, BC_AGE); 478 brelse(dbp, BC_AGE);
478 } 479 }
@@ -492,57 +493,57 @@ check_segsum(struct lfs *fs, daddr_t off @@ -492,57 +493,57 @@ check_segsum(struct lfs *fs, daddr_t off
492 /* Checksum the array, compare */ 493 /* Checksum the array, compare */
493 if ((flags & CHECK_CKSUM) && 494 if ((flags & CHECK_CKSUM) &&
494 ssp->ss_datasum != cksum(datap, nblocks * sizeof(u_long))) 495 ssp->ss_datasum != cksum(datap, nblocks * sizeof(u_long)))
495 { 496 {
496 DLOG((DLOG_RF, "Datasum error at 0x%" PRIx64 497 DLOG((DLOG_RF, "Datasum error at 0x%" PRIx64
497 " (wanted %x got %x)\n", 498 " (wanted %x got %x)\n",
498 offset, ssp->ss_datasum, cksum(datap, nblocks * 499 offset, ssp->ss_datasum, cksum(datap, nblocks *
499 sizeof(u_long)))); 500 sizeof(u_long))));
500 offset = -1; 501 offset = -1;
501 goto err2; 502 goto err2;
502 } 503 }
503 504
504 /* If we're at the end of the segment, move to the next */ 505 /* If we're at the end of the segment, move to the next */
505 if (lfs_dtosn(fs, offset + lfs_btofsb(fs, fs->lfs_sumsize + fs->lfs_bsize)) != 506 if (lfs_dtosn(fs, offset + lfs_btofsb(fs, fs->lfs_sumsize + lfs_sb_getbsize(fs))) !=
506 lfs_dtosn(fs, offset)) { 507 lfs_dtosn(fs, offset)) {
507 if (lfs_dtosn(fs, offset) == lfs_dtosn(fs, ssp->ss_next)) { 508 if (lfs_dtosn(fs, offset) == lfs_dtosn(fs, ssp->ss_next)) {
508 offset = -1; 509 offset = -1;
509 goto err2; 510 goto err2;
510 } 511 }
511 offset = ssp->ss_next; 512 offset = ssp->ss_next;
512 DLOG((DLOG_RF, "LFS roll forward: moving to offset 0x%" PRIx64 513 DLOG((DLOG_RF, "LFS roll forward: moving to offset 0x%" PRIx64
513 " -> segment %d\n", offset, lfs_dtosn(fs,offset))); 514 " -> segment %d\n", offset, lfs_dtosn(fs,offset)));
514 } 515 }
515 516
516 if (flags & CHECK_UPDATE) { 517 if (flags & CHECK_UPDATE) {
517 fs->lfs_avail -= (offset - oldoffset); 518 lfs_sb_subavail(fs, offset - oldoffset);
518 /* Don't clog the buffer queue */ 519 /* Don't clog the buffer queue */
519 mutex_enter(&lfs_lock); 520 mutex_enter(&lfs_lock);
520 if (locked_queue_count > LFS_MAX_BUFS || 521 if (locked_queue_count > LFS_MAX_BUFS ||
521 locked_queue_bytes > LFS_MAX_BYTES) { 522 locked_queue_bytes > LFS_MAX_BYTES) {
522 lfs_flush(fs, SEGM_CKP, 0); 523 lfs_flush(fs, SEGM_CKP, 0);
523 } 524 }
524 mutex_exit(&lfs_lock); 525 mutex_exit(&lfs_lock);
525 } 526 }
526 527
527 err2: 528 err2:
528 if (flags & CHECK_CKSUM) 529 if (flags & CHECK_CKSUM)
529 free(datap, M_SEGMENT); 530 free(datap, M_SEGMENT);
530 err1: 531 err1:
531 brelse(bp, BC_AGE); 532 brelse(bp, BC_AGE);
532 533
533 /* XXX should we update the serial number even for bad psegs? */ 534 /* XXX should we update the serial number even for bad psegs? */
534 if ((flags & CHECK_UPDATE) && offset > 0 && fs->lfs_version > 1) 535 if ((flags & CHECK_UPDATE) && offset > 0 && fs->lfs_version > 1)
535 fs->lfs_serial = nextserial; 536 lfs_sb_setserial(fs, nextserial);
536 return offset; 537 return offset;
537} 538}
538 539
539void 540void
540lfs_roll_forward(struct lfs *fs, struct mount *mp, struct lwp *l) 541lfs_roll_forward(struct lfs *fs, struct mount *mp, struct lwp *l)
541{ 542{
542 int flags, dirty; 543 int flags, dirty;
543 daddr_t offset, oldoffset, lastgoodpseg; 544 daddr_t offset, oldoffset, lastgoodpseg;
544 int sn, curseg, do_rollforward; 545 int sn, curseg, do_rollforward;
545 struct proc *p; 546 struct proc *p;
546 kauth_cred_t cred; 547 kauth_cred_t cred;
547 SEGUSE *sup; 548 SEGUSE *sup;
548 struct buf *bp; 549 struct buf *bp;
@@ -560,36 +561,36 @@ lfs_roll_forward(struct lfs *fs, struct  @@ -560,36 +561,36 @@ lfs_roll_forward(struct lfs *fs, struct
560 * v2 filesystems don't have this problem because they use a 561 * v2 filesystems don't have this problem because they use a
561 * monotonically increasing serial number instead of a timestamp. 562 * monotonically increasing serial number instead of a timestamp.
562 */ 563 */
563 do_rollforward = (!(fs->lfs_pflags & LFS_PF_CLEAN) && 564 do_rollforward = (!(fs->lfs_pflags & LFS_PF_CLEAN) &&
564 lfs_do_rfw && fs->lfs_version > 1 && p != NULL); 565 lfs_do_rfw && fs->lfs_version > 1 && p != NULL);
565 if (do_rollforward) { 566 if (do_rollforward) {
566 u_int64_t nextserial; 567 u_int64_t nextserial;
567 /* 568 /*
568 * Phase I: Find the address of the last good partial 569 * Phase I: Find the address of the last good partial
569 * segment that was written after the checkpoint. Mark 570 * segment that was written after the checkpoint. Mark
570 * the segments in question dirty, so they won't be 571 * the segments in question dirty, so they won't be
571 * reallocated. 572 * reallocated.
572 */ 573 */
573 lastgoodpseg = oldoffset = offset = fs->lfs_offset; 574 lastgoodpseg = oldoffset = offset = lfs_sb_getoffset(fs);
574 flags = 0x0; 575 flags = 0x0;
575 DLOG((DLOG_RF, "LFS roll forward phase 1: start at offset 0x%" 576 DLOG((DLOG_RF, "LFS roll forward phase 1: start at offset 0x%"
576 PRIx64 "\n", offset)); 577 PRIx64 "\n", offset));
577 LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, offset), bp); 578 LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, offset), bp);
578 if (!(sup->su_flags & SEGUSE_DIRTY)) 579 if (!(sup->su_flags & SEGUSE_DIRTY))
579 --fs->lfs_nclean; 580 --fs->lfs_nclean;
580 sup->su_flags |= SEGUSE_DIRTY; 581 sup->su_flags |= SEGUSE_DIRTY;
581 LFS_WRITESEGENTRY(sup, fs, lfs_dtosn(fs, offset), bp); 582 LFS_WRITESEGENTRY(sup, fs, lfs_dtosn(fs, offset), bp);
582 nextserial = fs->lfs_serial + 1; 583 nextserial = lfs_sb_getserial(fs) + 1;
583 while ((offset = check_segsum(fs, offset, nextserial, 584 while ((offset = check_segsum(fs, offset, nextserial,
584 cred, CHECK_CKSUM, &flags, l)) > 0) { 585 cred, CHECK_CKSUM, &flags, l)) > 0) {
585 nextserial++; 586 nextserial++;
586 if (lfs_sntod(fs, oldoffset) != lfs_sntod(fs, offset)) { 587 if (lfs_sntod(fs, oldoffset) != lfs_sntod(fs, offset)) {
587 LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, oldoffset), 588 LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, oldoffset),
588 bp); 589 bp);
589 if (!(sup->su_flags & SEGUSE_DIRTY)) 590 if (!(sup->su_flags & SEGUSE_DIRTY))
590 --fs->lfs_nclean; 591 --fs->lfs_nclean;
591 sup->su_flags |= SEGUSE_DIRTY; 592 sup->su_flags |= SEGUSE_DIRTY;
592 LFS_WRITESEGENTRY(sup, fs, lfs_dtosn(fs, oldoffset), 593 LFS_WRITESEGENTRY(sup, fs, lfs_dtosn(fs, oldoffset),
593 bp); 594 bp);
594 } 595 }
595 596
@@ -603,53 +604,53 @@ lfs_roll_forward(struct lfs *fs, struct  @@ -603,53 +604,53 @@ lfs_roll_forward(struct lfs *fs, struct
603 "at 0x%" PRIx64 "\n", oldoffset)); 604 "at 0x%" PRIx64 "\n", oldoffset));
604 } 605 }
605 } 606 }
606 if (!(flags & SS_CONT)) 607 if (!(flags & SS_CONT))
607 lastgoodpseg = offset; 608 lastgoodpseg = offset;
608 oldoffset = offset; 609 oldoffset = offset;
609 } 610 }
610 if (flags & SS_CONT) { 611 if (flags & SS_CONT) {
611 DLOG((DLOG_RF, "LFS roll forward: warning: incomplete " 612 DLOG((DLOG_RF, "LFS roll forward: warning: incomplete "
612 "dirops discarded\n")); 613 "dirops discarded\n"));
613 } 614 }
614 DLOG((DLOG_RF, "LFS roll forward phase 1: completed: " 615 DLOG((DLOG_RF, "LFS roll forward phase 1: completed: "
615 "lastgoodpseg=0x%" PRIx64 "\n", lastgoodpseg)); 616 "lastgoodpseg=0x%" PRIx64 "\n", lastgoodpseg));
616 oldoffset = fs->lfs_offset; 617 oldoffset = lfs_sb_getoffset(fs);
617 if (fs->lfs_offset != lastgoodpseg) { 618 if (lfs_sb_getoffset(fs) != lastgoodpseg) {
618 /* Don't overwrite what we're trying to preserve */ 619 /* Don't overwrite what we're trying to preserve */
619 offset = fs->lfs_offset; 620 offset = lfs_sb_getoffset(fs);
620 fs->lfs_offset = lastgoodpseg; 621 lfs_sb_setoffset(fs, lastgoodpseg);
621 fs->lfs_curseg = lfs_sntod(fs, lfs_dtosn(fs, fs->lfs_offset)); 622 lfs_sb_setcurseg(fs, lfs_sntod(fs, lfs_dtosn(fs, lfs_sb_getoffset(fs))));
622 for (sn = curseg = lfs_dtosn(fs, fs->lfs_curseg);;) { 623 for (sn = curseg = lfs_dtosn(fs, lfs_sb_getcurseg(fs));;) {
623 sn = (sn + 1) % fs->lfs_nseg; 624 sn = (sn + 1) % fs->lfs_nseg;
624 if (sn == curseg) 625 if (sn == curseg)
625 panic("lfs_mountfs: no clean segments"); 626 panic("lfs_mountfs: no clean segments");
626 LFS_SEGENTRY(sup, fs, sn, bp); 627 LFS_SEGENTRY(sup, fs, sn, bp);
627 dirty = (sup->su_flags & SEGUSE_DIRTY); 628 dirty = (sup->su_flags & SEGUSE_DIRTY);
628 brelse(bp, 0); 629 brelse(bp, 0);
629 if (!dirty) 630 if (!dirty)
630 break; 631 break;
631 } 632 }
632 fs->lfs_nextseg = lfs_sntod(fs, sn); 633 lfs_sb_setnextseg(fs, lfs_sntod(fs, sn));
633 634
634 /* 635 /*
635 * Phase II: Roll forward from the first superblock. 636 * Phase II: Roll forward from the first superblock.
636 */ 637 */
637 while (offset != lastgoodpseg) { 638 while (offset != lastgoodpseg) {
638 DLOG((DLOG_RF, "LFS roll forward phase 2: 0x%" 639 DLOG((DLOG_RF, "LFS roll forward phase 2: 0x%"
639 PRIx64 "\n", offset)); 640 PRIx64 "\n", offset));
640 offset = check_segsum(fs, offset, 641 offset = check_segsum(fs, offset,
641 fs->lfs_serial + 1, cred, CHECK_UPDATE, 642 lfs_sb_getserial(fs) + 1, cred, CHECK_UPDATE,
642 NULL, l); 643 NULL, l);
643 } 644 }
644 645
645 /* 646 /*
646 * Finish: flush our changes to disk. 647 * Finish: flush our changes to disk.
647 */ 648 */
648 lfs_segwrite(mp, SEGM_CKP | SEGM_SYNC); 649 lfs_segwrite(mp, SEGM_CKP | SEGM_SYNC);
649 DLOG((DLOG_RF, "lfs_mountfs: roll forward ", 650 DLOG((DLOG_RF, "lfs_mountfs: roll forward ",
650 "recovered %lld blocks\n", 651 "recovered %jd blocks\n",
651 (long long)(lastgoodpseg - oldoffset))); 652 (intmax_t)(lastgoodpseg - oldoffset)));
652 } 653 }
653 DLOG((DLOG_RF, "LFS roll forward complete\n")); 654 DLOG((DLOG_RF, "LFS roll forward complete\n"));
654 } 655 }
655} 656}

cvs diff -r1.241 -r1.242 src/sys/ufs/lfs/lfs_segment.c (expand / switch to unified diff)

--- src/sys/ufs/lfs/lfs_segment.c 2015/06/07 13:39:48 1.241
+++ src/sys/ufs/lfs/lfs_segment.c 2015/07/24 06:56:42 1.242
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lfs_segment.c,v 1.241 2015/06/07 13:39:48 hannken Exp $ */ 1/* $NetBSD: lfs_segment.c,v 1.242 2015/07/24 06:56:42 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant@hhhh.org>. 8 * by Konrad E. Schroder <perseant@hhhh.org>.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -50,27 +50,27 @@ @@ -50,27 +50,27 @@
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57 * SUCH DAMAGE. 57 * SUCH DAMAGE.
58 * 58 *
59 * @(#)lfs_segment.c 8.10 (Berkeley) 6/10/95 59 * @(#)lfs_segment.c 8.10 (Berkeley) 6/10/95
60 */ 60 */
61 61
62#include <sys/cdefs.h> 62#include <sys/cdefs.h>
63__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.241 2015/06/07 13:39:48 hannken Exp $"); 63__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.242 2015/07/24 06:56:42 dholland Exp $");
64 64
65#define _VFS_VNODE_PRIVATE /* XXX: check for VI_MARKER, this has to go */ 65#define _VFS_VNODE_PRIVATE /* XXX: check for VI_MARKER, this has to go */
66 66
67#ifdef DEBUG 67#ifdef DEBUG
68# define vndebug(vp, str) do { \ 68# define vndebug(vp, str) do { \
69 if (VTOI(vp)->i_flag & IN_CLEANING) \ 69 if (VTOI(vp)->i_flag & IN_CLEANING) \
70 DLOG((DLOG_WVNODE, "not writing ino %d because %s (op %d)\n", \ 70 DLOG((DLOG_WVNODE, "not writing ino %d because %s (op %d)\n", \
71 VTOI(vp)->i_number, (str), op)); \ 71 VTOI(vp)->i_number, (str), op)); \
72} while(0) 72} while(0)
73#else 73#else
74# define vndebug(vp, str) 74# define vndebug(vp, str)
75#endif 75#endif
76#define ivndebug(vp, str) \ 76#define ivndebug(vp, str) \
@@ -111,28 +111,29 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_segment. @@ -111,28 +111,29 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_segment.
111MALLOC_JUSTDEFINE(M_SEGMENT, "LFS segment", "Segment for LFS"); 111MALLOC_JUSTDEFINE(M_SEGMENT, "LFS segment", "Segment for LFS");
112 112
113static void lfs_generic_callback(struct buf *, void (*)(struct buf *)); 113static void lfs_generic_callback(struct buf *, void (*)(struct buf *));
114static void lfs_free_aiodone(struct buf *); 114static void lfs_free_aiodone(struct buf *);
115static void lfs_super_aiodone(struct buf *); 115static void lfs_super_aiodone(struct buf *);
116static void lfs_cluster_aiodone(struct buf *); 116static void lfs_cluster_aiodone(struct buf *);
117static void lfs_cluster_callback(struct buf *); 117static void lfs_cluster_callback(struct buf *);
118 118
119/* 119/*
120 * Determine if it's OK to start a partial in this segment, or if we need 120 * Determine if it's OK to start a partial in this segment, or if we need
121 * to go on to a new segment. 121 * to go on to a new segment.
122 */ 122 */
123#define LFS_PARTIAL_FITS(fs) \ 123#define LFS_PARTIAL_FITS(fs) \
124 ((fs)->lfs_fsbpseg - ((fs)->lfs_offset - (fs)->lfs_curseg) > \ 124 (lfs_sb_getfsbpseg(fs) - \
125 (fs)->lfs_frag) 125 (lfs_sb_getoffset(fs) - lfs_sb_getcurseg(fs)) > \
 126 lfs_sb_getfrag(fs))
126 127
127/* 128/*
128 * Figure out whether we should do a checkpoint write or go ahead with 129 * Figure out whether we should do a checkpoint write or go ahead with
129 * an ordinary write. 130 * an ordinary write.
130 */ 131 */
131#define LFS_SHOULD_CHECKPOINT(fs, flags) \ 132#define LFS_SHOULD_CHECKPOINT(fs, flags) \
132 ((flags & SEGM_CLEAN) == 0 && \ 133 ((flags & SEGM_CLEAN) == 0 && \
133 ((fs->lfs_nactive > LFS_MAX_ACTIVE || \ 134 ((fs->lfs_nactive > LFS_MAX_ACTIVE || \
134 (flags & SEGM_CKP) || \ 135 (flags & SEGM_CKP) || \
135 fs->lfs_nclean < LFS_MAX_ACTIVE))) 136 fs->lfs_nclean < LFS_MAX_ACTIVE)))
136 137
137int lfs_match_fake(struct lfs *, struct buf *); 138int lfs_match_fake(struct lfs *, struct buf *);
138void lfs_newseg(struct lfs *); 139void lfs_newseg(struct lfs *);
@@ -232,48 +233,49 @@ lfs_vflush(struct vnode *vp) @@ -232,48 +233,49 @@ lfs_vflush(struct vnode *vp)
232 if (bp->b_lblkno > 0 && vp->v_type == VREG && 233 if (bp->b_lblkno > 0 && vp->v_type == VREG &&
233 vp != fs->lfs_ivnode) { 234 vp != fs->lfs_ivnode) {
234 struct vm_page *pg; 235 struct vm_page *pg;
235 voff_t off; 236 voff_t off;
236 237
237 for (off = lfs_lblktosize(fs, bp->b_lblkno); 238 for (off = lfs_lblktosize(fs, bp->b_lblkno);
238 off < lfs_lblktosize(fs, bp->b_lblkno + 1); 239 off < lfs_lblktosize(fs, bp->b_lblkno + 1);
239 off += PAGE_SIZE) { 240 off += PAGE_SIZE) {
240 pg = uvm_pagelookup(&vp->v_uobj, off); 241 pg = uvm_pagelookup(&vp->v_uobj, off);
241 if (pg == NULL) 242 if (pg == NULL)
242 continue; 243 continue;
243 if ((pg->flags & PG_CLEAN) == 0 || 244 if ((pg->flags & PG_CLEAN) == 0 ||
244 pmap_is_modified(pg)) { 245 pmap_is_modified(pg)) {
245 fs->lfs_avail += lfs_btofsb(fs, 246 lfs_sb_addavail(fs,
246 bp->b_bcount); 247 lfs_btofsb(fs,
247 wakeup(&fs->lfs_avail); 248 bp->b_bcount));
 249 wakeup(&fs->lfs_availsleep);
248 mutex_exit(vp->v_interlock); 250 mutex_exit(vp->v_interlock);
249 lfs_freebuf(fs, bp); 251 lfs_freebuf(fs, bp);
250 mutex_enter(vp->v_interlock); 252 mutex_enter(vp->v_interlock);
251 bp = NULL; 253 bp = NULL;
252 break; 254 break;
253 } 255 }
254 } 256 }
255 } 257 }
256 for (tbp = LIST_FIRST(&vp->v_dirtyblkhd); tbp; 258 for (tbp = LIST_FIRST(&vp->v_dirtyblkhd); tbp;
257 tbp = tnbp) 259 tbp = tnbp)
258 { 260 {
259 tnbp = LIST_NEXT(tbp, b_vnbufs); 261 tnbp = LIST_NEXT(tbp, b_vnbufs);
260 if (tbp->b_vp == bp->b_vp 262 if (tbp->b_vp == bp->b_vp
261 && tbp->b_lblkno == bp->b_lblkno 263 && tbp->b_lblkno == bp->b_lblkno
262 && tbp != bp) 264 && tbp != bp)
263 { 265 {
264 fs->lfs_avail += lfs_btofsb(fs, 266 lfs_sb_addavail(fs, lfs_btofsb(fs,
265 bp->b_bcount); 267 bp->b_bcount));
266 wakeup(&fs->lfs_avail); 268 wakeup(&fs->lfs_availsleep);
267 mutex_exit(vp->v_interlock); 269 mutex_exit(vp->v_interlock);
268 lfs_freebuf(fs, bp); 270 lfs_freebuf(fs, bp);
269 mutex_enter(vp->v_interlock); 271 mutex_enter(vp->v_interlock);
270 bp = NULL; 272 bp = NULL;
271 break; 273 break;
272 } 274 }
273 } 275 }
274 } 276 }
275 } else { 277 } else {
276 mutex_enter(vp->v_interlock); 278 mutex_enter(vp->v_interlock);
277 } 279 }
278 280
279 /* If the node is being written, wait until that is done */ 281 /* If the node is being written, wait until that is done */
@@ -298,28 +300,28 @@ lfs_vflush(struct vnode *vp) @@ -298,28 +300,28 @@ lfs_vflush(struct vnode *vp)
298 mutex_enter(vp->v_interlock); 300 mutex_enter(vp->v_interlock);
299 while (vp->v_numoutput > 0) { 301 while (vp->v_numoutput > 0) {
300 cv_wait(&vp->v_cv, vp->v_interlock); 302 cv_wait(&vp->v_cv, vp->v_interlock);
301 } 303 }
302 KASSERT(vp->v_numoutput == 0); 304 KASSERT(vp->v_numoutput == 0);
303 mutex_exit(vp->v_interlock); 305 mutex_exit(vp->v_interlock);
304  306
305 mutex_enter(&bufcache_lock); 307 mutex_enter(&bufcache_lock);
306 for (bp = LIST_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) { 308 for (bp = LIST_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
307 nbp = LIST_NEXT(bp, b_vnbufs); 309 nbp = LIST_NEXT(bp, b_vnbufs);
308 310
309 KASSERT((bp->b_flags & B_GATHERED) == 0); 311 KASSERT((bp->b_flags & B_GATHERED) == 0);
310 if (bp->b_oflags & BO_DELWRI) { /* XXX always true? */ 312 if (bp->b_oflags & BO_DELWRI) { /* XXX always true? */
311 fs->lfs_avail += lfs_btofsb(fs, bp->b_bcount); 313 lfs_sb_addavail(fs, lfs_btofsb(fs, bp->b_bcount));
312 wakeup(&fs->lfs_avail); 314 wakeup(&fs->lfs_availsleep);
313 } 315 }
314 /* Copied from lfs_writeseg */ 316 /* Copied from lfs_writeseg */
315 if (bp->b_iodone != NULL) { 317 if (bp->b_iodone != NULL) {
316 mutex_exit(&bufcache_lock); 318 mutex_exit(&bufcache_lock);
317 biodone(bp); 319 biodone(bp);
318 mutex_enter(&bufcache_lock); 320 mutex_enter(&bufcache_lock);
319 } else { 321 } else {
320 bremfree(bp); 322 bremfree(bp);
321 LFS_UNLOCK_BUF(bp); 323 LFS_UNLOCK_BUF(bp);
322 mutex_enter(vp->v_interlock); 324 mutex_enter(vp->v_interlock);
323 bp->b_flags &= ~(B_READ | B_GATHERED); 325 bp->b_flags &= ~(B_READ | B_GATHERED);
324 bp->b_oflags = (bp->b_oflags & ~BO_DELWRI) | BO_DONE; 326 bp->b_oflags = (bp->b_oflags & ~BO_DELWRI) | BO_DONE;
325 bp->b_error = 0; 327 bp->b_error = 0;
@@ -493,28 +495,28 @@ lfs_writevnodes(struct lfs *fs, struct m @@ -493,28 +495,28 @@ lfs_writevnodes(struct lfs *fs, struct m
493 */ 495 */
494 if (vp->v_mount != mp) { 496 if (vp->v_mount != mp) {
495 DLOG((DLOG_VNODE, "lfs_writevnodes: starting over\n")); 497 DLOG((DLOG_VNODE, "lfs_writevnodes: starting over\n"));
496 /* 498 /*
497 * After this, pages might be busy 499 * After this, pages might be busy
498 * due to our own previous putpages. 500 * due to our own previous putpages.
499 * Start actual segment write here to avoid deadlock. 501 * Start actual segment write here to avoid deadlock.
500 * If we were just writing one segment and we've done 502 * If we were just writing one segment and we've done
501 * that, break out. 503 * that, break out.
502 */ 504 */
503 mutex_exit(&mntvnode_lock); 505 mutex_exit(&mntvnode_lock);
504 if (lfs_writeseg(fs, sp) && 506 if (lfs_writeseg(fs, sp) &&
505 (sp->seg_flags & SEGM_SINGLE) && 507 (sp->seg_flags & SEGM_SINGLE) &&
506 fs->lfs_curseg != fs->lfs_startseg) { 508 lfs_sb_getcurseg(fs) != fs->lfs_startseg) {
507 DLOG((DLOG_VNODE, "lfs_writevnodes: breaking out of segment write at daddr 0x%x\n", fs->lfs_offset)); 509 DLOG((DLOG_VNODE, "lfs_writevnodes: breaking out of segment write at daddr 0x%jx\n", (uintmax_t)lfs_sb_getoffset(fs)));
508 break; 510 break;
509 } 511 }
510 goto loop; 512 goto loop;
511 } 513 }
512 514
513 mutex_enter(vp->v_interlock); 515 mutex_enter(vp->v_interlock);
514 if (vp->v_type == VNON || (vp->v_iflag & VI_MARKER) || 516 if (vp->v_type == VNON || (vp->v_iflag & VI_MARKER) ||
515 vdead_check(vp, VDEAD_NOWAIT) != 0) { 517 vdead_check(vp, VDEAD_NOWAIT) != 0) {
516 mutex_exit(vp->v_interlock); 518 mutex_exit(vp->v_interlock);
517 continue; 519 continue;
518 } 520 }
519 521
520 ip = VTOI(vp); 522 ip = VTOI(vp);
@@ -650,28 +652,28 @@ lfs_segwrite(struct mount *mp, int flags @@ -650,28 +652,28 @@ lfs_segwrite(struct mount *mp, int flags
650 * in which case we have to flush *all* buffers off of this vnode. 652 * in which case we have to flush *all* buffers off of this vnode.
651 * We don't care about other nodes, but write any non-dirop nodes 653 * We don't care about other nodes, but write any non-dirop nodes
652 * anyway in anticipation of another getnewvnode(). 654 * anyway in anticipation of another getnewvnode().
653 * 655 *
654 * If we're cleaning we only write cleaning and ifile blocks, and 656 * If we're cleaning we only write cleaning and ifile blocks, and
655 * no dirops, since otherwise we'd risk corruption in a crash. 657 * no dirops, since otherwise we'd risk corruption in a crash.
656 */ 658 */
657 if (sp->seg_flags & SEGM_CLEAN) 659 if (sp->seg_flags & SEGM_CLEAN)
658 lfs_writevnodes(fs, mp, sp, VN_CLEAN); 660 lfs_writevnodes(fs, mp, sp, VN_CLEAN);
659 else if (!(sp->seg_flags & SEGM_FORCE_CKP)) { 661 else if (!(sp->seg_flags & SEGM_FORCE_CKP)) {
660 do { 662 do {
661 um_error = lfs_writevnodes(fs, mp, sp, VN_REG); 663 um_error = lfs_writevnodes(fs, mp, sp, VN_REG);
662 if ((sp->seg_flags & SEGM_SINGLE) && 664 if ((sp->seg_flags & SEGM_SINGLE) &&
663 fs->lfs_curseg != fs->lfs_startseg) { 665 lfs_sb_getcurseg(fs) != fs->lfs_startseg) {
664 DLOG((DLOG_SEG, "lfs_segwrite: breaking out of segment write at daddr 0x%x\n", fs->lfs_offset)); 666 DLOG((DLOG_SEG, "lfs_segwrite: breaking out of segment write at daddr 0x%jx\n", (uintmax_t)lfs_sb_getoffset(fs)));
665 break; 667 break;
666 } 668 }
667 669
668 if (do_ckp || fs->lfs_dirops == 0) { 670 if (do_ckp || fs->lfs_dirops == 0) {
669 if (!writer_set) { 671 if (!writer_set) {
670 lfs_writer_enter(fs, "lfs writer"); 672 lfs_writer_enter(fs, "lfs writer");
671 writer_set = 1; 673 writer_set = 1;
672 } 674 }
673 error = lfs_writevnodes(fs, mp, sp, VN_DIROP); 675 error = lfs_writevnodes(fs, mp, sp, VN_DIROP);
674 if (um_error == 0) 676 if (um_error == 0)
675 um_error = error; 677 um_error = error;
676 /* In case writevnodes errored out */ 678 /* In case writevnodes errored out */
677 lfs_flush_dirops(fs); 679 lfs_flush_dirops(fs);
@@ -682,56 +684,56 @@ lfs_segwrite(struct mount *mp, int flags @@ -682,56 +684,56 @@ lfs_segwrite(struct mount *mp, int flags
682 lfs_segunlock_relock(fs); 684 lfs_segunlock_relock(fs);
683 sp = fs->lfs_sp; 685 sp = fs->lfs_sp;
684 } 686 }
685 } while (do_ckp && um_error != 0); 687 } while (do_ckp && um_error != 0);
686 } 688 }
687 689
688 /* 690 /*
689 * If we are doing a checkpoint, mark everything since the 691 * If we are doing a checkpoint, mark everything since the
690 * last checkpoint as no longer ACTIVE. 692 * last checkpoint as no longer ACTIVE.
691 */ 693 */
692 if (do_ckp || fs->lfs_doifile) { 694 if (do_ckp || fs->lfs_doifile) {
693 segleft = fs->lfs_nseg; 695 segleft = fs->lfs_nseg;
694 curseg = 0; 696 curseg = 0;
695 for (n = 0; n < fs->lfs_segtabsz; n++) { 697 for (n = 0; n < lfs_sb_getsegtabsz(fs); n++) {
696 dirty = 0; 698 dirty = 0;
697 if (bread(fs->lfs_ivnode, fs->lfs_cleansz + n, 699 if (bread(fs->lfs_ivnode, lfs_sb_getcleansz(fs) + n,
698 fs->lfs_bsize, B_MODIFY, &bp)) 700 lfs_sb_getbsize(fs), B_MODIFY, &bp))
699 panic("lfs_segwrite: ifile read"); 701 panic("lfs_segwrite: ifile read");
700 segusep = (SEGUSE *)bp->b_data; 702 segusep = (SEGUSE *)bp->b_data;
701 maxseg = min(segleft, fs->lfs_sepb); 703 maxseg = min(segleft, lfs_sb_getsepb(fs));
702 for (i = 0; i < maxseg; i++) { 704 for (i = 0; i < maxseg; i++) {
703 sn = curseg + i; 705 sn = curseg + i;
704 if (sn != lfs_dtosn(fs, fs->lfs_curseg) && 706 if (sn != lfs_dtosn(fs, lfs_sb_getcurseg(fs)) &&
705 segusep->su_flags & SEGUSE_ACTIVE) { 707 segusep->su_flags & SEGUSE_ACTIVE) {
706 segusep->su_flags &= ~SEGUSE_ACTIVE; 708 segusep->su_flags &= ~SEGUSE_ACTIVE;
707 --fs->lfs_nactive; 709 --fs->lfs_nactive;
708 ++dirty; 710 ++dirty;
709 } 711 }
710 fs->lfs_suflags[fs->lfs_activesb][sn] = 712 fs->lfs_suflags[fs->lfs_activesb][sn] =
711 segusep->su_flags; 713 segusep->su_flags;
712 if (fs->lfs_version > 1) 714 if (fs->lfs_version > 1)
713 ++segusep; 715 ++segusep;
714 else 716 else
715 segusep = (SEGUSE *) 717 segusep = (SEGUSE *)
716 ((SEGUSE_V1 *)segusep + 1); 718 ((SEGUSE_V1 *)segusep + 1);
717 } 719 }
718 720
719 if (dirty) 721 if (dirty)
720 error = LFS_BWRITE_LOG(bp); /* Ifile */ 722 error = LFS_BWRITE_LOG(bp); /* Ifile */
721 else 723 else
722 brelse(bp, 0); 724 brelse(bp, 0);
723 segleft -= fs->lfs_sepb; 725 segleft -= lfs_sb_getsepb(fs);
724 curseg += fs->lfs_sepb; 726 curseg += lfs_sb_getsepb(fs);
725 } 727 }
726 } 728 }
727 729
728 KASSERT(LFS_SEGLOCK_HELD(fs)); 730 KASSERT(LFS_SEGLOCK_HELD(fs));
729 731
730 did_ckp = 0; 732 did_ckp = 0;
731 if (do_ckp || fs->lfs_doifile) { 733 if (do_ckp || fs->lfs_doifile) {
732 vp = fs->lfs_ivnode; 734 vp = fs->lfs_ivnode;
733#ifdef DEBUG 735#ifdef DEBUG
734 int loopcount = 0; 736 int loopcount = 0;
735#endif 737#endif
736 do { 738 do {
737#ifdef DEBUG 739#ifdef DEBUG
@@ -780,28 +782,28 @@ lfs_segwrite(struct mount *mp, int flags @@ -780,28 +782,28 @@ lfs_segwrite(struct mount *mp, int flags
780 * dirty blocks even after a checkpoint, due to changes to 782 * dirty blocks even after a checkpoint, due to changes to
781 * inodes' atime. If we're checkpointing, it's "impossible" 783 * inodes' atime. If we're checkpointing, it's "impossible"
782 * for other parts of the Ifile to be dirty after the loop 784 * for other parts of the Ifile to be dirty after the loop
783 * above, since we hold the segment lock. 785 * above, since we hold the segment lock.
784 */ 786 */
785 mutex_enter(vp->v_interlock); 787 mutex_enter(vp->v_interlock);
786 if (LIST_EMPTY(&vp->v_dirtyblkhd)) { 788 if (LIST_EMPTY(&vp->v_dirtyblkhd)) {
787 LFS_CLR_UINO(ip, IN_ALLMOD); 789 LFS_CLR_UINO(ip, IN_ALLMOD);
788 } 790 }
789#ifdef DIAGNOSTIC 791#ifdef DIAGNOSTIC
790 else if (do_ckp) { 792 else if (do_ckp) {
791 int do_panic = 0; 793 int do_panic = 0;
792 LIST_FOREACH(bp, &vp->v_dirtyblkhd, b_vnbufs) { 794 LIST_FOREACH(bp, &vp->v_dirtyblkhd, b_vnbufs) {
793 if (bp->b_lblkno < fs->lfs_cleansz + 795 if (bp->b_lblkno < lfs_sb_getcleansz(fs) +
794 fs->lfs_segtabsz && 796 lfs_sb_getsegtabsz(fs) &&
795 !(bp->b_flags & B_GATHERED)) { 797 !(bp->b_flags & B_GATHERED)) {
796 printf("ifile lbn %ld still dirty (flags %lx)\n", 798 printf("ifile lbn %ld still dirty (flags %lx)\n",
797 (long)bp->b_lblkno, 799 (long)bp->b_lblkno,
798 (long)bp->b_flags); 800 (long)bp->b_flags);
799 ++do_panic; 801 ++do_panic;
800 } 802 }
801 } 803 }
802 if (do_panic) 804 if (do_panic)
803 panic("dirty blocks"); 805 panic("dirty blocks");
804 } 806 }
805#endif 807#endif
806 mutex_exit(vp->v_interlock); 808 mutex_exit(vp->v_interlock);
807 } else { 809 } else {
@@ -896,27 +898,27 @@ lfs_writefile(struct lfs *fs, struct seg @@ -896,27 +898,27 @@ lfs_writefile(struct lfs *fs, struct seg
896 * checkpointing. 898 * checkpointing.
897 * 899 *
898 * BUT if we are cleaning, we might have indirect blocks that refer to 900 * BUT if we are cleaning, we might have indirect blocks that refer to
899 * new blocks not being written yet, in addition to fragments being 901 * new blocks not being written yet, in addition to fragments being
900 * moved out of a cleaned segment. If that is the case, don't 902 * moved out of a cleaned segment. If that is the case, don't
901 * write the indirect blocks, or the finfo will have a small block 903 * write the indirect blocks, or the finfo will have a small block
902 * in the middle of it! 904 * in the middle of it!
903 * XXX in this case isn't the inode size wrong too? 905 * XXX in this case isn't the inode size wrong too?
904 */ 906 */
905 frag = 0; 907 frag = 0;
906 if (sp->seg_flags & SEGM_CLEAN) { 908 if (sp->seg_flags & SEGM_CLEAN) {
907 for (i = 0; i < ULFS_NDADDR; i++) 909 for (i = 0; i < ULFS_NDADDR; i++)
908 if (ip->i_lfs_fragsize[i] > 0 && 910 if (ip->i_lfs_fragsize[i] > 0 &&
909 ip->i_lfs_fragsize[i] < fs->lfs_bsize) 911 ip->i_lfs_fragsize[i] < lfs_sb_getbsize(fs))
910 ++frag; 912 ++frag;
911 } 913 }
912#ifdef DIAGNOSTIC 914#ifdef DIAGNOSTIC
913 if (frag > 1) 915 if (frag > 1)
914 panic("lfs_writefile: more than one fragment!"); 916 panic("lfs_writefile: more than one fragment!");
915#endif 917#endif
916 if (IS_FLUSHING(fs, vp) || 918 if (IS_FLUSHING(fs, vp) ||
917 (frag == 0 && (lfs_writeindir || (sp->seg_flags & SEGM_CKP)))) { 919 (frag == 0 && (lfs_writeindir || (sp->seg_flags & SEGM_CKP)))) {
918 lfs_gather(fs, sp, vp, lfs_match_indir); 920 lfs_gather(fs, sp, vp, lfs_match_indir);
919 lfs_gather(fs, sp, vp, lfs_match_dindir); 921 lfs_gather(fs, sp, vp, lfs_match_dindir);
920 lfs_gather(fs, sp, vp, lfs_match_tindir); 922 lfs_gather(fs, sp, vp, lfs_match_tindir);
921 } 923 }
922 lfs_release_finfo(fs); 924 lfs_release_finfo(fs);
@@ -936,63 +938,63 @@ lfs_update_iaddr(struct lfs *fs, struct  @@ -936,63 +938,63 @@ lfs_update_iaddr(struct lfs *fs, struct
936 SEGUSE *sup; 938 SEGUSE *sup;
937 ino_t ino; 939 ino_t ino;
938 int redo_ifile; 940 int redo_ifile;
939 u_int32_t sn; 941 u_int32_t sn;
940 942
941 redo_ifile = 0; 943 redo_ifile = 0;
942 944
943 /* 945 /*
944 * If updating the ifile, update the super-block. Update the disk 946 * If updating the ifile, update the super-block. Update the disk
945 * address and access times for this inode in the ifile. 947 * address and access times for this inode in the ifile.
946 */ 948 */
947 ino = ip->i_number; 949 ino = ip->i_number;
948 if (ino == LFS_IFILE_INUM) { 950 if (ino == LFS_IFILE_INUM) {
949 daddr = fs->lfs_idaddr; 951 daddr = lfs_sb_getidaddr(fs);
950 fs->lfs_idaddr = LFS_DBTOFSB(fs, ndaddr); 952 lfs_sb_setidaddr(fs, LFS_DBTOFSB(fs, ndaddr));
951 } else { 953 } else {
952 LFS_IENTRY(ifp, fs, ino, bp); 954 LFS_IENTRY(ifp, fs, ino, bp);
953 daddr = ifp->if_daddr; 955 daddr = ifp->if_daddr;
954 ifp->if_daddr = LFS_DBTOFSB(fs, ndaddr); 956 ifp->if_daddr = LFS_DBTOFSB(fs, ndaddr);
955 (void)LFS_BWRITE_LOG(bp); /* Ifile */ 957 (void)LFS_BWRITE_LOG(bp); /* Ifile */
956 } 958 }
957 959
958 /* 960 /*
959 * If this is the Ifile and lfs_offset is set to the first block 961 * If this is the Ifile and lfs_offset is set to the first block
960 * in the segment, dirty the new segment's accounting block 962 * in the segment, dirty the new segment's accounting block
961 * (XXX should already be dirty?) and tell the caller to do it again. 963 * (XXX should already be dirty?) and tell the caller to do it again.
962 */ 964 */
963 if (ip->i_number == LFS_IFILE_INUM) { 965 if (ip->i_number == LFS_IFILE_INUM) {
964 sn = lfs_dtosn(fs, fs->lfs_offset); 966 sn = lfs_dtosn(fs, lfs_sb_getoffset(fs));
965 if (lfs_sntod(fs, sn) + lfs_btofsb(fs, fs->lfs_sumsize) == 967 if (lfs_sntod(fs, sn) + lfs_btofsb(fs, fs->lfs_sumsize) ==
966 fs->lfs_offset) { 968 lfs_sb_getoffset(fs)) {
967 LFS_SEGENTRY(sup, fs, sn, bp); 969 LFS_SEGENTRY(sup, fs, sn, bp);
968 KASSERT(bp->b_oflags & BO_DELWRI); 970 KASSERT(bp->b_oflags & BO_DELWRI);
969 LFS_WRITESEGENTRY(sup, fs, sn, bp); 971 LFS_WRITESEGENTRY(sup, fs, sn, bp);
970 /* fs->lfs_flags |= LFS_IFDIRTY; */ 972 /* fs->lfs_flags |= LFS_IFDIRTY; */
971 redo_ifile |= 1; 973 redo_ifile |= 1;
972 } 974 }
973 } 975 }
974 976
975 /* 977 /*
976 * The inode's last address should not be in the current partial 978 * The inode's last address should not be in the current partial
977 * segment, except under exceptional circumstances (lfs_writevnodes 979 * segment, except under exceptional circumstances (lfs_writevnodes
978 * had to start over, and in the meantime more blocks were written 980 * had to start over, and in the meantime more blocks were written
979 * to a vnode). Both inodes will be accounted to this segment 981 * to a vnode). Both inodes will be accounted to this segment
980 * in lfs_writeseg so we need to subtract the earlier version 982 * in lfs_writeseg so we need to subtract the earlier version
981 * here anyway. The segment count can temporarily dip below 983 * here anyway. The segment count can temporarily dip below
982 * zero here; keep track of how many duplicates we have in 984 * zero here; keep track of how many duplicates we have in
983 * "dupino" so we don't panic below. 985 * "dupino" so we don't panic below.
984 */ 986 */
985 if (daddr >= fs->lfs_lastpseg && daddr <= fs->lfs_offset) { 987 if (daddr >= lfs_sb_getlastpseg(fs) && daddr <= lfs_sb_getoffset(fs)) {
986 ++sp->ndupino; 988 ++sp->ndupino;
987 DLOG((DLOG_SEG, "lfs_writeinode: last inode addr in current pseg " 989 DLOG((DLOG_SEG, "lfs_writeinode: last inode addr in current pseg "
988 "(ino %d daddr 0x%llx) ndupino=%d\n", ino, 990 "(ino %d daddr 0x%llx) ndupino=%d\n", ino,
989 (long long)daddr, sp->ndupino)); 991 (long long)daddr, sp->ndupino));
990 } 992 }
991 /* 993 /*
992 * Account the inode: it no longer belongs to its former segment, 994 * Account the inode: it no longer belongs to its former segment,
993 * though it will not belong to the new segment until that segment 995 * though it will not belong to the new segment until that segment
994 * is actually written. 996 * is actually written.
995 */ 997 */
996 if (daddr != LFS_UNUSED_DADDR) { 998 if (daddr != LFS_UNUSED_DADDR) {
997 u_int32_t oldsn = lfs_dtosn(fs, daddr); 999 u_int32_t oldsn = lfs_dtosn(fs, daddr);
998#ifdef DIAGNOSTIC 1000#ifdef DIAGNOSTIC
@@ -1018,27 +1020,27 @@ lfs_update_iaddr(struct lfs *fs, struct  @@ -1018,27 +1020,27 @@ lfs_update_iaddr(struct lfs *fs, struct
1018 sup->su_nbytes = sizeof (struct ulfs1_dinode); 1020 sup->su_nbytes = sizeof (struct ulfs1_dinode);
1019 } 1021 }
1020#endif 1022#endif
1021 DLOG((DLOG_SU, "seg %d -= %d for ino %d inode\n", 1023 DLOG((DLOG_SU, "seg %d -= %d for ino %d inode\n",
1022 lfs_dtosn(fs, daddr), sizeof (struct ulfs1_dinode), ino)); 1024 lfs_dtosn(fs, daddr), sizeof (struct ulfs1_dinode), ino));
1023 sup->su_nbytes -= sizeof (struct ulfs1_dinode); 1025 sup->su_nbytes -= sizeof (struct ulfs1_dinode);
1024 redo_ifile |= 1026 redo_ifile |=
1025 (ino == LFS_IFILE_INUM && !(bp->b_flags & B_GATHERED)); 1027 (ino == LFS_IFILE_INUM && !(bp->b_flags & B_GATHERED));
1026 if (redo_ifile) { 1028 if (redo_ifile) {
1027 mutex_enter(&lfs_lock); 1029 mutex_enter(&lfs_lock);
1028 fs->lfs_flags |= LFS_IFDIRTY; 1030 fs->lfs_flags |= LFS_IFDIRTY;
1029 mutex_exit(&lfs_lock); 1031 mutex_exit(&lfs_lock);
1030 /* Don't double-account */ 1032 /* Don't double-account */
1031 fs->lfs_idaddr = 0x0; 1033 lfs_sb_setidaddr(fs, 0x0);
1032 } 1034 }
1033 LFS_WRITESEGENTRY(sup, fs, oldsn, bp); /* Ifile */ 1035 LFS_WRITESEGENTRY(sup, fs, oldsn, bp); /* Ifile */
1034 } 1036 }
1035 1037
1036 return redo_ifile; 1038 return redo_ifile;
1037} 1039}
1038 1040
1039int 1041int
1040lfs_writeinode(struct lfs *fs, struct segment *sp, struct inode *ip) 1042lfs_writeinode(struct lfs *fs, struct segment *sp, struct inode *ip)
1041{ 1043{
1042 struct buf *bp; 1044 struct buf *bp;
1043 struct ulfs1_dinode *cdp; 1045 struct ulfs1_dinode *cdp;
1044 struct vnode *vp = ITOV(ip); 1046 struct vnode *vp = ITOV(ip);
@@ -1096,40 +1098,40 @@ lfs_writeinode(struct lfs *fs, struct se @@ -1096,40 +1098,40 @@ lfs_writeinode(struct lfs *fs, struct se
1096 log(LOG_NOTICE, "lfs_writeinode: looping count=%d\n", count); 1098 log(LOG_NOTICE, "lfs_writeinode: looping count=%d\n", count);
1097 lfs_writefile(fs, sp, fs->lfs_ivnode); 1099 lfs_writefile(fs, sp, fs->lfs_ivnode);
1098 } 1100 }
1099 1101
1100 /* Allocate a new inode block if necessary. */ 1102 /* Allocate a new inode block if necessary. */
1101 if ((ip->i_number != LFS_IFILE_INUM || sp->idp == NULL) && 1103 if ((ip->i_number != LFS_IFILE_INUM || sp->idp == NULL) &&
1102 sp->ibp == NULL) { 1104 sp->ibp == NULL) {
1103 /* Allocate a new segment if necessary. */ 1105 /* Allocate a new segment if necessary. */
1104 if (sp->seg_bytes_left < fs->lfs_ibsize || 1106 if (sp->seg_bytes_left < fs->lfs_ibsize ||
1105 sp->sum_bytes_left < sizeof(int32_t)) 1107 sp->sum_bytes_left < sizeof(int32_t))
1106 (void) lfs_writeseg(fs, sp); 1108 (void) lfs_writeseg(fs, sp);
1107 1109
1108 /* Get next inode block. */ 1110 /* Get next inode block. */
1109 daddr = fs->lfs_offset; 1111 daddr = lfs_sb_getoffset(fs);
1110 fs->lfs_offset += lfs_btofsb(fs, fs->lfs_ibsize); 1112 lfs_sb_addoffset(fs, lfs_btofsb(fs, lfs_sb_getibsize(fs)));
1111 sp->ibp = *sp->cbpp++ = 1113 sp->ibp = *sp->cbpp++ =
1112 getblk(VTOI(fs->lfs_ivnode)->i_devvp, 1114 getblk(VTOI(fs->lfs_ivnode)->i_devvp,
1113 LFS_FSBTODB(fs, daddr), fs->lfs_ibsize, 0, 0); 1115 LFS_FSBTODB(fs, daddr), fs->lfs_ibsize, 0, 0);
1114 gotblk++; 1116 gotblk++;
1115 1117
1116 /* Zero out inode numbers */ 1118 /* Zero out inode numbers */
1117 for (i = 0; i < LFS_INOPB(fs); ++i) 1119 for (i = 0; i < LFS_INOPB(fs); ++i)
1118 ((struct ulfs1_dinode *)sp->ibp->b_data)[i].di_inumber = 1120 ((struct ulfs1_dinode *)sp->ibp->b_data)[i].di_inumber =
1119 0; 1121 0;
1120 1122
1121 ++sp->start_bpp; 1123 ++sp->start_bpp;
1122 fs->lfs_avail -= lfs_btofsb(fs, fs->lfs_ibsize); 1124 lfs_sb_subavail(fs, lfs_btofsb(fs, lfs_sb_getibsize(fs)));
1123 /* Set remaining space counters. */ 1125 /* Set remaining space counters. */
1124 sp->seg_bytes_left -= fs->lfs_ibsize; 1126 sp->seg_bytes_left -= fs->lfs_ibsize;
1125 sp->sum_bytes_left -= sizeof(int32_t); 1127 sp->sum_bytes_left -= sizeof(int32_t);
1126 ndx = fs->lfs_sumsize / sizeof(int32_t) - 1128 ndx = fs->lfs_sumsize / sizeof(int32_t) -
1127 sp->ninodes / LFS_INOPB(fs) - 1; 1129 sp->ninodes / LFS_INOPB(fs) - 1;
1128 ((int32_t *)(sp->segsum))[ndx] = daddr; 1130 ((int32_t *)(sp->segsum))[ndx] = daddr;
1129 } 1131 }
1130 1132
1131 /* Check VU_DIROP in case there is a new file with no data blocks */ 1133 /* Check VU_DIROP in case there is a new file with no data blocks */
1132 if (vp->v_uflag & VU_DIROP) 1134 if (vp->v_uflag & VU_DIROP)
1133 ((SEGSUM *)(sp->segsum))->ss_flags |= (SS_DIROP|SS_CONT); 1135 ((SEGSUM *)(sp->segsum))->ss_flags |= (SS_DIROP|SS_CONT);
1134 1136
1135 /* Update the inode times and copy the inode onto the inode page. */ 1137 /* Update the inode times and copy the inode onto the inode page. */
@@ -1202,43 +1204,43 @@ lfs_writeinode(struct lfs *fs, struct se @@ -1202,43 +1204,43 @@ lfs_writeinode(struct lfs *fs, struct se
1202 * XXX Ifile is written. See also in lfs_writeseg. 1204 * XXX Ifile is written. See also in lfs_writeseg.
1203 */ 1205 */
1204 1206
1205 /* Check file size based on highest allocated block */ 1207 /* Check file size based on highest allocated block */
1206 if (((ip->i_ffs1_mode & LFS_IFMT) == LFS_IFREG || 1208 if (((ip->i_ffs1_mode & LFS_IFMT) == LFS_IFREG ||
1207 (ip->i_ffs1_mode & LFS_IFMT) == LFS_IFDIR) && 1209 (ip->i_ffs1_mode & LFS_IFMT) == LFS_IFDIR) &&
1208 ip->i_size > ((ip->i_lfs_hiblk + 1) << fs->lfs_bshift)) { 1210 ip->i_size > ((ip->i_lfs_hiblk + 1) << fs->lfs_bshift)) {
1209 cdp->di_size = (ip->i_lfs_hiblk + 1) << fs->lfs_bshift; 1211 cdp->di_size = (ip->i_lfs_hiblk + 1) << fs->lfs_bshift;
1210 DLOG((DLOG_SEG, "lfs_writeinode: ino %d size %" PRId64 " -> %" 1212 DLOG((DLOG_SEG, "lfs_writeinode: ino %d size %" PRId64 " -> %"
1211 PRId64 "\n", (int)ip->i_number, ip->i_size, cdp->di_size)); 1213 PRId64 "\n", (int)ip->i_number, ip->i_size, cdp->di_size));
1212 } 1214 }
1213 if (ip->i_lfs_effnblks != ip->i_ffs1_blocks) { 1215 if (ip->i_lfs_effnblks != ip->i_ffs1_blocks) {
1214 DLOG((DLOG_SEG, "lfs_writeinode: cleansing ino %d eff %d != nblk %d)" 1216 DLOG((DLOG_SEG, "lfs_writeinode: cleansing ino %d eff %d != nblk %d)"
1215 " at %x\n", ip->i_number, ip->i_lfs_effnblks, 1217 " at %jx\n", ip->i_number, ip->i_lfs_effnblks,
1216 ip->i_ffs1_blocks, fs->lfs_offset)); 1218 ip->i_ffs1_blocks, (uintmax_t)lfs_sb_getoffset(fs)));
1217 for (daddrp = cdp->di_db; daddrp < cdp->di_ib + ULFS_NIADDR; 1219 for (daddrp = cdp->di_db; daddrp < cdp->di_ib + ULFS_NIADDR;
1218 daddrp++) { 1220 daddrp++) {
1219 if (*daddrp == UNWRITTEN) { 1221 if (*daddrp == UNWRITTEN) {
1220 DLOG((DLOG_SEG, "lfs_writeinode: wiping UNWRITTEN\n")); 1222 DLOG((DLOG_SEG, "lfs_writeinode: wiping UNWRITTEN\n"));
1221 *daddrp = 0; 1223 *daddrp = 0;
1222 } 1224 }
1223 } 1225 }
1224 } 1226 }
1225 1227
1226#ifdef DIAGNOSTIC 1228#ifdef DIAGNOSTIC
1227 /* 1229 /*
1228 * Check dinode held blocks against dinode size. 1230 * Check dinode held blocks against dinode size.
1229 * This should be identical to the check in lfs_vget(). 1231 * This should be identical to the check in lfs_vget().
1230 */ 1232 */
1231 for (i = (cdp->di_size + fs->lfs_bsize - 1) >> fs->lfs_bshift; 1233 for (i = (cdp->di_size + lfs_sb_getbsize(fs) - 1) >> fs->lfs_bshift;
1232 i < ULFS_NDADDR; i++) { 1234 i < ULFS_NDADDR; i++) {
1233 KASSERT(i >= 0); 1235 KASSERT(i >= 0);
1234 if ((cdp->di_mode & LFS_IFMT) == LFS_IFLNK) 1236 if ((cdp->di_mode & LFS_IFMT) == LFS_IFLNK)
1235 continue; 1237 continue;
1236 if (((cdp->di_mode & LFS_IFMT) == LFS_IFBLK || 1238 if (((cdp->di_mode & LFS_IFMT) == LFS_IFBLK ||
1237 (cdp->di_mode & LFS_IFMT) == LFS_IFCHR) && i == 0) 1239 (cdp->di_mode & LFS_IFMT) == LFS_IFCHR) && i == 0)
1238 continue; 1240 continue;
1239 if (cdp->di_db[i] != 0) { 1241 if (cdp->di_db[i] != 0) {
1240# ifdef DEBUG 1242# ifdef DEBUG
1241 lfs_dump_dinode(cdp); 1243 lfs_dump_dinode(cdp);
1242# endif 1244# endif
1243 panic("writing inconsistent inode"); 1245 panic("writing inconsistent inode");
1244 } 1246 }
@@ -1298,27 +1300,27 @@ lfs_gatherblock(struct segment *sp, stru @@ -1298,27 +1300,27 @@ lfs_gatherblock(struct segment *sp, stru
1298 int vers; 1300 int vers;
1299 int j, blksinblk; 1301 int j, blksinblk;
1300 1302
1301 ASSERT_SEGLOCK(sp->fs); 1303 ASSERT_SEGLOCK(sp->fs);
1302 /* 1304 /*
1303 * If full, finish this segment. We may be doing I/O, so 1305 * If full, finish this segment. We may be doing I/O, so
1304 * release and reacquire the splbio(). 1306 * release and reacquire the splbio().
1305 */ 1307 */
1306#ifdef DIAGNOSTIC 1308#ifdef DIAGNOSTIC
1307 if (sp->vp == NULL) 1309 if (sp->vp == NULL)
1308 panic ("lfs_gatherblock: Null vp in segment"); 1310 panic ("lfs_gatherblock: Null vp in segment");
1309#endif 1311#endif
1310 fs = sp->fs; 1312 fs = sp->fs;
1311 blksinblk = howmany(bp->b_bcount, fs->lfs_bsize); 1313 blksinblk = howmany(bp->b_bcount, lfs_sb_getbsize(fs));
1312 if (sp->sum_bytes_left < sizeof(int32_t) * blksinblk || 1314 if (sp->sum_bytes_left < sizeof(int32_t) * blksinblk ||
1313 sp->seg_bytes_left < bp->b_bcount) { 1315 sp->seg_bytes_left < bp->b_bcount) {
1314 if (mptr) 1316 if (mptr)
1315 mutex_exit(mptr); 1317 mutex_exit(mptr);
1316 lfs_updatemeta(sp); 1318 lfs_updatemeta(sp);
1317 1319
1318 vers = sp->fip->fi_version; 1320 vers = sp->fip->fi_version;
1319 (void) lfs_writeseg(fs, sp); 1321 (void) lfs_writeseg(fs, sp);
1320 1322
1321 /* Add the current file to the segment summary. */ 1323 /* Add the current file to the segment summary. */
1322 lfs_acquire_finfo(fs, VTOI(sp->vp)->i_number, vers); 1324 lfs_acquire_finfo(fs, VTOI(sp->vp)->i_number, vers);
1323 1325
1324 if (mptr) 1326 if (mptr)
@@ -1381,29 +1383,29 @@ loop: @@ -1381,29 +1383,29 @@ loop:
1381 nbp = BACK_BUF(bp); 1383 nbp = BACK_BUF(bp);
1382#else /* LFS_NO_BACKBUF_HACK */ 1384#else /* LFS_NO_BACKBUF_HACK */
1383loop: 1385loop:
1384 for (bp = LIST_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) { 1386 for (bp = LIST_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
1385 nbp = LIST_NEXT(bp, b_vnbufs); 1387 nbp = LIST_NEXT(bp, b_vnbufs);
1386#endif /* LFS_NO_BACKBUF_HACK */ 1388#endif /* LFS_NO_BACKBUF_HACK */
1387 if ((bp->b_cflags & BC_BUSY) != 0 || 1389 if ((bp->b_cflags & BC_BUSY) != 0 ||
1388 (bp->b_flags & B_GATHERED) != 0 || !match(fs, bp)) { 1390 (bp->b_flags & B_GATHERED) != 0 || !match(fs, bp)) {
1389#ifdef DEBUG 1391#ifdef DEBUG
1390 if (vp == fs->lfs_ivnode && 1392 if (vp == fs->lfs_ivnode &&
1391 (bp->b_cflags & BC_BUSY) != 0 && 1393 (bp->b_cflags & BC_BUSY) != 0 &&
1392 (bp->b_flags & B_GATHERED) == 0) 1394 (bp->b_flags & B_GATHERED) == 0)
1393 log(LOG_NOTICE, "lfs_gather: ifile lbn %" 1395 log(LOG_NOTICE, "lfs_gather: ifile lbn %"
1394 PRId64 " busy (%x) at 0x%x", 1396 PRId64 " busy (%x) at 0x%jx",
1395 bp->b_lblkno, bp->b_flags, 1397 bp->b_lblkno, bp->b_flags,
1396 (unsigned)fs->lfs_offset); 1398 (uintmax_t)lfs_sb_getoffset(fs));
1397#endif 1399#endif
1398 continue; 1400 continue;
1399 } 1401 }
1400#ifdef DIAGNOSTIC 1402#ifdef DIAGNOSTIC
1401# ifdef LFS_USE_B_INVAL 1403# ifdef LFS_USE_B_INVAL
1402 if ((bp->b_flags & BC_INVAL) != 0 && bp->b_iodone == NULL) { 1404 if ((bp->b_flags & BC_INVAL) != 0 && bp->b_iodone == NULL) {
1403 DLOG((DLOG_SEG, "lfs_gather: lbn %" PRId64 1405 DLOG((DLOG_SEG, "lfs_gather: lbn %" PRId64
1404 " is BC_INVAL\n", bp->b_lblkno)); 1406 " is BC_INVAL\n", bp->b_lblkno));
1405 VOP_PRINT(bp->b_vp); 1407 VOP_PRINT(bp->b_vp);
1406 } 1408 }
1407# endif /* LFS_USE_B_INVAL */ 1409# endif /* LFS_USE_B_INVAL */
1408 if (!(bp->b_oflags & BO_DELWRI)) 1410 if (!(bp->b_oflags & BO_DELWRI))
1409 panic("lfs_gather: bp not BO_DELWRI"); 1411 panic("lfs_gather: bp not BO_DELWRI");
@@ -1487,27 +1489,27 @@ lfs_update_single(struct lfs *fs, struct @@ -1487,27 +1489,27 @@ lfs_update_single(struct lfs *fs, struct
1487 ip->i_ffs1_blocks += (bb - obb); 1489 ip->i_ffs1_blocks += (bb - obb);
1488 } 1490 }
1489 ip->i_ffs1_db[lbn] = ndaddr; 1491 ip->i_ffs1_db[lbn] = ndaddr;
1490 break; 1492 break;
1491 case 1: 1493 case 1:
1492 ooff = ip->i_ffs1_ib[a[0].in_off]; 1494 ooff = ip->i_ffs1_ib[a[0].in_off];
1493 DEBUG_OOFF(1); 1495 DEBUG_OOFF(1);
1494 if (ooff == UNWRITTEN) 1496 if (ooff == UNWRITTEN)
1495 ip->i_ffs1_blocks += bb; 1497 ip->i_ffs1_blocks += bb;
1496 ip->i_ffs1_ib[a[0].in_off] = ndaddr; 1498 ip->i_ffs1_ib[a[0].in_off] = ndaddr;
1497 break; 1499 break;
1498 default: 1500 default:
1499 ap = &a[num - 1]; 1501 ap = &a[num - 1];
1500 if (bread(vp, ap->in_lbn, fs->lfs_bsize, 1502 if (bread(vp, ap->in_lbn, lfs_sb_getbsize(fs),
1501 B_MODIFY, &bp)) 1503 B_MODIFY, &bp))
1502 panic("lfs_updatemeta: bread bno %" PRId64, 1504 panic("lfs_updatemeta: bread bno %" PRId64,
1503 ap->in_lbn); 1505 ap->in_lbn);
1504 1506
1505 /* XXX ondisk32 */ 1507 /* XXX ondisk32 */
1506 ooff = ((int32_t *)bp->b_data)[ap->in_off]; 1508 ooff = ((int32_t *)bp->b_data)[ap->in_off];
1507 DEBUG_OOFF(num); 1509 DEBUG_OOFF(num);
1508 if (ooff == UNWRITTEN) 1510 if (ooff == UNWRITTEN)
1509 ip->i_ffs1_blocks += bb; 1511 ip->i_ffs1_blocks += bb;
1510 /* XXX ondisk32 */ 1512 /* XXX ondisk32 */
1511 ((int32_t *)bp->b_data)[ap->in_off] = ndaddr; 1513 ((int32_t *)bp->b_data)[ap->in_off] = ndaddr;
1512 (void) VOP_BWRITE(bp->b_vp, bp); 1514 (void) VOP_BWRITE(bp->b_vp, bp);
1513 } 1515 }
@@ -1533,27 +1535,27 @@ lfs_update_single(struct lfs *fs, struct @@ -1533,27 +1535,27 @@ lfs_update_single(struct lfs *fs, struct
1533#ifdef DIAGNOSTIC 1535#ifdef DIAGNOSTIC
1534 int ndupino; 1536 int ndupino;
1535 1537
1536 if (sp && sp->seg_number == oldsn) { 1538 if (sp && sp->seg_number == oldsn) {
1537 ndupino = sp->ndupino; 1539 ndupino = sp->ndupino;
1538 } else { 1540 } else {
1539 ndupino = 0; 1541 ndupino = 0;
1540 } 1542 }
1541#endif 1543#endif
1542 KASSERT(oldsn < fs->lfs_nseg); 1544 KASSERT(oldsn < fs->lfs_nseg);
1543 if (lbn >= 0 && lbn < ULFS_NDADDR) 1545 if (lbn >= 0 && lbn < ULFS_NDADDR)
1544 osize = ip->i_lfs_fragsize[lbn]; 1546 osize = ip->i_lfs_fragsize[lbn];
1545 else 1547 else
1546 osize = fs->lfs_bsize; 1548 osize = lfs_sb_getbsize(fs);
1547 LFS_SEGENTRY(sup, fs, oldsn, bp); 1549 LFS_SEGENTRY(sup, fs, oldsn, bp);
1548#ifdef DIAGNOSTIC 1550#ifdef DIAGNOSTIC
1549 if (sup->su_nbytes + sizeof (struct ulfs1_dinode) * ndupino 1551 if (sup->su_nbytes + sizeof (struct ulfs1_dinode) * ndupino
1550 < osize) { 1552 < osize) {
1551 printf("lfs_updatemeta: negative bytes " 1553 printf("lfs_updatemeta: negative bytes "
1552 "(segment %" PRIu32 " short by %" PRId64 1554 "(segment %" PRIu32 " short by %" PRId64
1553 ")\n", lfs_dtosn(fs, daddr), 1555 ")\n", lfs_dtosn(fs, daddr),
1554 (int64_t)osize - 1556 (int64_t)osize -
1555 (sizeof (struct ulfs1_dinode) * ndupino + 1557 (sizeof (struct ulfs1_dinode) * ndupino +
1556 sup->su_nbytes)); 1558 sup->su_nbytes));
1557 printf("lfs_updatemeta: ino %llu, lbn %" PRId64 1559 printf("lfs_updatemeta: ino %llu, lbn %" PRId64
1558 ", addr = 0x%" PRIx64 "\n", 1560 ", addr = 0x%" PRIx64 "\n",
1559 (unsigned long long)ip->i_number, lbn, daddr); 1561 (unsigned long long)ip->i_number, lbn, daddr);
@@ -1608,236 +1610,236 @@ lfs_updatemeta(struct segment *sp) @@ -1608,236 +1610,236 @@ lfs_updatemeta(struct segment *sp)
1608 return; 1610 return;
1609 1611
1610 /* 1612 /*
1611 * This count may be high due to oversize blocks from lfs_gop_write. 1613 * This count may be high due to oversize blocks from lfs_gop_write.
1612 * Correct for this. (XXX we should be able to keep track of these.) 1614 * Correct for this. (XXX we should be able to keep track of these.)
1613 */ 1615 */
1614 fs = sp->fs; 1616 fs = sp->fs;
1615 for (i = 0; i < nblocks; i++) { 1617 for (i = 0; i < nblocks; i++) {
1616 if (sp->start_bpp[i] == NULL) { 1618 if (sp->start_bpp[i] == NULL) {
1617 DLOG((DLOG_SEG, "lfs_updatemeta: nblocks = %d, not %d\n", i, nblocks)); 1619 DLOG((DLOG_SEG, "lfs_updatemeta: nblocks = %d, not %d\n", i, nblocks));
1618 nblocks = i; 1620 nblocks = i;
1619 break; 1621 break;
1620 } 1622 }
1621 num = howmany(sp->start_bpp[i]->b_bcount, fs->lfs_bsize); 1623 num = howmany(sp->start_bpp[i]->b_bcount, lfs_sb_getbsize(fs));
1622 KASSERT(sp->start_bpp[i]->b_lblkno >= 0 || num == 1); 1624 KASSERT(sp->start_bpp[i]->b_lblkno >= 0 || num == 1);
1623 nblocks -= num - 1; 1625 nblocks -= num - 1;
1624 } 1626 }
1625 1627
1626 KASSERT(vp->v_type == VREG || 1628 KASSERT(vp->v_type == VREG ||
1627 nblocks == &sp->fip->fi_blocks[sp->fip->fi_nblocks] - sp->start_lbp); 1629 nblocks == &sp->fip->fi_blocks[sp->fip->fi_nblocks] - sp->start_lbp);
1628 KASSERT(nblocks == sp->cbpp - sp->start_bpp); 1630 KASSERT(nblocks == sp->cbpp - sp->start_bpp);
1629 1631
1630 /* 1632 /*
1631 * Sort the blocks. 1633 * Sort the blocks.
1632 * 1634 *
1633 * We have to sort even if the blocks come from the 1635 * We have to sort even if the blocks come from the
1634 * cleaner, because there might be other pending blocks on the 1636 * cleaner, because there might be other pending blocks on the
1635 * same inode...and if we don't sort, and there are fragments 1637 * same inode...and if we don't sort, and there are fragments
1636 * present, blocks may be written in the wrong place. 1638 * present, blocks may be written in the wrong place.
1637 */ 1639 */
1638 lfs_shellsort(sp->start_bpp, sp->start_lbp, nblocks, fs->lfs_bsize); 1640 lfs_shellsort(sp->start_bpp, sp->start_lbp, nblocks, lfs_sb_getbsize(fs));
1639 1641
1640 /* 1642 /*
1641 * Record the length of the last block in case it's a fragment. 1643 * Record the length of the last block in case it's a fragment.
1642 * If there are indirect blocks present, they sort last. An 1644 * If there are indirect blocks present, they sort last. An
1643 * indirect block will be lfs_bsize and its presence indicates 1645 * indirect block will be lfs_bsize and its presence indicates
1644 * that you cannot have fragments. 1646 * that you cannot have fragments.
1645 * 1647 *
1646 * XXX This last is a lie. A cleaned fragment can coexist with 1648 * XXX This last is a lie. A cleaned fragment can coexist with
1647 * XXX a later indirect block. This will continue to be 1649 * XXX a later indirect block. This will continue to be
1648 * XXX true until lfs_markv is fixed to do everything with 1650 * XXX true until lfs_markv is fixed to do everything with
1649 * XXX fake blocks (including fake inodes and fake indirect blocks). 1651 * XXX fake blocks (including fake inodes and fake indirect blocks).
1650 */ 1652 */
1651 sp->fip->fi_lastlength = ((sp->start_bpp[nblocks - 1]->b_bcount - 1) & 1653 sp->fip->fi_lastlength = ((sp->start_bpp[nblocks - 1]->b_bcount - 1) &
1652 fs->lfs_bmask) + 1; 1654 fs->lfs_bmask) + 1;
1653 1655
1654 /* 1656 /*
1655 * Assign disk addresses, and update references to the logical 1657 * Assign disk addresses, and update references to the logical
1656 * block and the segment usage information. 1658 * block and the segment usage information.
1657 */ 1659 */
1658 for (i = nblocks; i--; ++sp->start_bpp) { 1660 for (i = nblocks; i--; ++sp->start_bpp) {
1659 sbp = *sp->start_bpp; 1661 sbp = *sp->start_bpp;
1660 lbn = *sp->start_lbp; 1662 lbn = *sp->start_lbp;
1661 KASSERT(sbp->b_lblkno == lbn); 1663 KASSERT(sbp->b_lblkno == lbn);
1662 1664
1663 sbp->b_blkno = LFS_FSBTODB(fs, fs->lfs_offset); 1665 sbp->b_blkno = LFS_FSBTODB(fs, lfs_sb_getoffset(fs));
1664 1666
1665 /* 1667 /*
1666 * If we write a frag in the wrong place, the cleaner won't 1668 * If we write a frag in the wrong place, the cleaner won't
1667 * be able to correctly identify its size later, and the 1669 * be able to correctly identify its size later, and the
1668 * segment will be uncleanable. (Even worse, it will assume 1670 * segment will be uncleanable. (Even worse, it will assume
1669 * that the indirect block that actually ends the list 1671 * that the indirect block that actually ends the list
1670 * is of a smaller size!) 1672 * is of a smaller size!)
1671 */ 1673 */
1672 if ((sbp->b_bcount & fs->lfs_bmask) && i != 0) 1674 if ((sbp->b_bcount & fs->lfs_bmask) && i != 0)
1673 panic("lfs_updatemeta: fragment is not last block"); 1675 panic("lfs_updatemeta: fragment is not last block");
1674 1676
1675 /* 1677 /*
1676 * For each subblock in this possibly oversized block, 1678 * For each subblock in this possibly oversized block,
1677 * update its address on disk. 1679 * update its address on disk.
1678 */ 1680 */
1679 KASSERT(lbn >= 0 || sbp->b_bcount == fs->lfs_bsize); 1681 KASSERT(lbn >= 0 || sbp->b_bcount == lfs_sb_getbsize(fs));
1680 KASSERT(vp == sbp->b_vp); 1682 KASSERT(vp == sbp->b_vp);
1681 for (bytesleft = sbp->b_bcount; bytesleft > 0; 1683 for (bytesleft = sbp->b_bcount; bytesleft > 0;
1682 bytesleft -= fs->lfs_bsize) { 1684 bytesleft -= lfs_sb_getbsize(fs)) {
1683 size = MIN(bytesleft, fs->lfs_bsize); 1685 size = MIN(bytesleft, lfs_sb_getbsize(fs));
1684 bb = lfs_numfrags(fs, size); 1686 bb = lfs_numfrags(fs, size);
1685 lbn = *sp->start_lbp++; 1687 lbn = *sp->start_lbp++;
1686 lfs_update_single(fs, sp, sp->vp, lbn, fs->lfs_offset, 1688 lfs_update_single(fs, sp, sp->vp, lbn, lfs_sb_getoffset(fs),
1687 size); 1689 size);
1688 fs->lfs_offset += bb; 1690 lfs_sb_addoffset(fs, bb);
1689 } 1691 }
1690 1692
1691 } 1693 }
1692 1694
1693 /* This inode has been modified */ 1695 /* This inode has been modified */
1694 LFS_SET_UINO(VTOI(vp), IN_MODIFIED); 1696 LFS_SET_UINO(VTOI(vp), IN_MODIFIED);
1695} 1697}
1696 1698
1697/* 1699/*
1698 * Move lfs_offset to a segment earlier than sn. 1700 * Move lfs_offset to a segment earlier than sn.
1699 */ 1701 */
1700int 1702int
1701lfs_rewind(struct lfs *fs, int newsn) 1703lfs_rewind(struct lfs *fs, int newsn)
1702{ 1704{
1703 int sn, osn, isdirty; 1705 int sn, osn, isdirty;
1704 struct buf *bp; 1706 struct buf *bp;
1705 SEGUSE *sup; 1707 SEGUSE *sup;
1706 1708
1707 ASSERT_SEGLOCK(fs); 1709 ASSERT_SEGLOCK(fs);
1708 1710
1709 osn = lfs_dtosn(fs, fs->lfs_offset); 1711 osn = lfs_dtosn(fs, lfs_sb_getoffset(fs));
1710 if (osn < newsn) 1712 if (osn < newsn)
1711 return 0; 1713 return 0;
1712 1714
1713 /* lfs_avail eats the remaining space in this segment */ 1715 /* lfs_avail eats the remaining space in this segment */
1714 fs->lfs_avail -= fs->lfs_fsbpseg - (fs->lfs_offset - fs->lfs_curseg); 1716 lfs_sb_subavail(fs, fs->lfs_fsbpseg - (lfs_sb_getoffset(fs) - lfs_sb_getcurseg(fs)));
1715 1717
1716 /* Find a low-numbered segment */ 1718 /* Find a low-numbered segment */
1717 for (sn = 0; sn < fs->lfs_nseg; ++sn) { 1719 for (sn = 0; sn < fs->lfs_nseg; ++sn) {
1718 LFS_SEGENTRY(sup, fs, sn, bp); 1720 LFS_SEGENTRY(sup, fs, sn, bp);
1719 isdirty = sup->su_flags & SEGUSE_DIRTY; 1721 isdirty = sup->su_flags & SEGUSE_DIRTY;
1720 brelse(bp, 0); 1722 brelse(bp, 0);
1721 1723
1722 if (!isdirty) 1724 if (!isdirty)
1723 break; 1725 break;
1724 } 1726 }
1725 if (sn == fs->lfs_nseg) 1727 if (sn == fs->lfs_nseg)
1726 panic("lfs_rewind: no clean segments"); 1728 panic("lfs_rewind: no clean segments");
1727 if (newsn >= 0 && sn >= newsn) 1729 if (newsn >= 0 && sn >= newsn)
1728 return ENOENT; 1730 return ENOENT;
1729 fs->lfs_nextseg = sn; 1731 lfs_sb_setnextseg(fs, sn);
1730 lfs_newseg(fs); 1732 lfs_newseg(fs);
1731 fs->lfs_offset = fs->lfs_curseg; 1733 lfs_sb_setoffset(fs, lfs_sb_getcurseg(fs));
1732 1734
1733 return 0; 1735 return 0;
1734} 1736}
1735 1737
1736/* 1738/*
1737 * Start a new partial segment. 1739 * Start a new partial segment.
1738 * 1740 *
1739 * Return 1 when we entered to a new segment. 1741 * Return 1 when we entered to a new segment.
1740 * Otherwise, return 0. 1742 * Otherwise, return 0.
1741 */ 1743 */
1742int 1744int
1743lfs_initseg(struct lfs *fs) 1745lfs_initseg(struct lfs *fs)
1744{ 1746{
1745 struct segment *sp = fs->lfs_sp; 1747 struct segment *sp = fs->lfs_sp;
1746 SEGSUM *ssp; 1748 SEGSUM *ssp;
1747 struct buf *sbp; /* buffer for SEGSUM */ 1749 struct buf *sbp; /* buffer for SEGSUM */
1748 int repeat = 0; /* return value */ 1750 int repeat = 0; /* return value */
1749 1751
1750 ASSERT_SEGLOCK(fs); 1752 ASSERT_SEGLOCK(fs);
1751 /* Advance to the next segment. */ 1753 /* Advance to the next segment. */
1752 if (!LFS_PARTIAL_FITS(fs)) { 1754 if (!LFS_PARTIAL_FITS(fs)) {
1753 SEGUSE *sup; 1755 SEGUSE *sup;
1754 struct buf *bp; 1756 struct buf *bp;
1755 1757
1756 /* lfs_avail eats the remaining space */ 1758 /* lfs_avail eats the remaining space */
1757 fs->lfs_avail -= fs->lfs_fsbpseg - (fs->lfs_offset - 1759 lfs_sb_subavail(fs, fs->lfs_fsbpseg - (lfs_sb_getoffset(fs) -
1758 fs->lfs_curseg); 1760 lfs_sb_getcurseg(fs)));
1759 /* Wake up any cleaning procs waiting on this file system. */ 1761 /* Wake up any cleaning procs waiting on this file system. */
1760 lfs_wakeup_cleaner(fs); 1762 lfs_wakeup_cleaner(fs);
1761 lfs_newseg(fs); 1763 lfs_newseg(fs);
1762 repeat = 1; 1764 repeat = 1;
1763 fs->lfs_offset = fs->lfs_curseg; 1765 lfs_sb_setoffset(fs, lfs_sb_getcurseg(fs));
1764 1766
1765 sp->seg_number = lfs_dtosn(fs, fs->lfs_curseg); 1767 sp->seg_number = lfs_dtosn(fs, lfs_sb_getcurseg(fs));
1766 sp->seg_bytes_left = lfs_fsbtob(fs, fs->lfs_fsbpseg); 1768 sp->seg_bytes_left = lfs_fsbtob(fs, fs->lfs_fsbpseg);
1767 1769
1768 /* 1770 /*
1769 * If the segment contains a superblock, update the offset 1771 * If the segment contains a superblock, update the offset
1770 * and summary address to skip over it. 1772 * and summary address to skip over it.
1771 */ 1773 */
1772 LFS_SEGENTRY(sup, fs, sp->seg_number, bp); 1774 LFS_SEGENTRY(sup, fs, sp->seg_number, bp);
1773 if (sup->su_flags & SEGUSE_SUPERBLOCK) { 1775 if (sup->su_flags & SEGUSE_SUPERBLOCK) {
1774 fs->lfs_offset += lfs_btofsb(fs, LFS_SBPAD); 1776 lfs_sb_addoffset(fs, lfs_btofsb(fs, LFS_SBPAD));
1775 sp->seg_bytes_left -= LFS_SBPAD; 1777 sp->seg_bytes_left -= LFS_SBPAD;
1776 } 1778 }
1777 brelse(bp, 0); 1779 brelse(bp, 0);
1778 /* Segment zero could also contain the labelpad */ 1780 /* Segment zero could also contain the labelpad */
1779 if (fs->lfs_version > 1 && sp->seg_number == 0 && 1781 if (fs->lfs_version > 1 && sp->seg_number == 0 &&
1780 fs->lfs_s0addr < lfs_btofsb(fs, LFS_LABELPAD)) { 1782 fs->lfs_s0addr < lfs_btofsb(fs, LFS_LABELPAD)) {
1781 fs->lfs_offset += 1783 lfs_sb_addoffset(fs,
1782 lfs_btofsb(fs, LFS_LABELPAD) - fs->lfs_s0addr; 1784 lfs_btofsb(fs, LFS_LABELPAD) - fs->lfs_s0addr);
1783 sp->seg_bytes_left -= 1785 sp->seg_bytes_left -=
1784 LFS_LABELPAD - lfs_fsbtob(fs, fs->lfs_s0addr); 1786 LFS_LABELPAD - lfs_fsbtob(fs, fs->lfs_s0addr);
1785 } 1787 }
1786 } else { 1788 } else {
1787 sp->seg_number = lfs_dtosn(fs, fs->lfs_curseg); 1789 sp->seg_number = lfs_dtosn(fs, lfs_sb_getcurseg(fs));
1788 sp->seg_bytes_left = lfs_fsbtob(fs, fs->lfs_fsbpseg - 1790 sp->seg_bytes_left = lfs_fsbtob(fs, fs->lfs_fsbpseg -
1789 (fs->lfs_offset - fs->lfs_curseg)); 1791 (lfs_sb_getoffset(fs) - lfs_sb_getcurseg(fs)));
1790 } 1792 }
1791 fs->lfs_lastpseg = fs->lfs_offset; 1793 lfs_sb_setlastpseg(fs, lfs_sb_getoffset(fs));
1792 1794
1793 /* Record first address of this partial segment */ 1795 /* Record first address of this partial segment */
1794 if (sp->seg_flags & SEGM_CLEAN) { 1796 if (sp->seg_flags & SEGM_CLEAN) {
1795 fs->lfs_cleanint[fs->lfs_cleanind] = fs->lfs_offset; 1797 fs->lfs_cleanint[fs->lfs_cleanind] = lfs_sb_getoffset(fs);
1796 if (++fs->lfs_cleanind >= LFS_MAX_CLEANIND) { 1798 if (++fs->lfs_cleanind >= LFS_MAX_CLEANIND) {
1797 /* "1" is the artificial inc in lfs_seglock */ 1799 /* "1" is the artificial inc in lfs_seglock */
1798 mutex_enter(&lfs_lock); 1800 mutex_enter(&lfs_lock);
1799 while (fs->lfs_iocount > 1) { 1801 while (fs->lfs_iocount > 1) {
1800 mtsleep(&fs->lfs_iocount, PRIBIO + 1, 1802 mtsleep(&fs->lfs_iocount, PRIBIO + 1,
1801 "lfs_initseg", 0, &lfs_lock); 1803 "lfs_initseg", 0, &lfs_lock);
1802 } 1804 }
1803 mutex_exit(&lfs_lock); 1805 mutex_exit(&lfs_lock);
1804 fs->lfs_cleanind = 0; 1806 fs->lfs_cleanind = 0;
1805 } 1807 }
1806 } 1808 }
1807 1809
1808 sp->fs = fs; 1810 sp->fs = fs;
1809 sp->ibp = NULL; 1811 sp->ibp = NULL;
1810 sp->idp = NULL; 1812 sp->idp = NULL;
1811 sp->ninodes = 0; 1813 sp->ninodes = 0;
1812 sp->ndupino = 0; 1814 sp->ndupino = 0;
1813 1815
1814 sp->cbpp = sp->bpp; 1816 sp->cbpp = sp->bpp;
1815 1817
1816 /* Get a new buffer for SEGSUM */ 1818 /* Get a new buffer for SEGSUM */
1817 sbp = lfs_newbuf(fs, VTOI(fs->lfs_ivnode)->i_devvp, 1819 sbp = lfs_newbuf(fs, VTOI(fs->lfs_ivnode)->i_devvp,
1818 LFS_FSBTODB(fs, fs->lfs_offset), fs->lfs_sumsize, LFS_NB_SUMMARY); 1820 LFS_FSBTODB(fs, lfs_sb_getoffset(fs)), fs->lfs_sumsize, LFS_NB_SUMMARY);
1819 1821
1820 /* ... and enter it into the buffer list. */ 1822 /* ... and enter it into the buffer list. */
1821 *sp->cbpp = sbp; 1823 *sp->cbpp = sbp;
1822 sp->cbpp++; 1824 sp->cbpp++;
1823 fs->lfs_offset += lfs_btofsb(fs, fs->lfs_sumsize); 1825 lfs_sb_addoffset(fs, lfs_btofsb(fs, lfs_sb_getsumsize(fs)));
1824 1826
1825 sp->start_bpp = sp->cbpp; 1827 sp->start_bpp = sp->cbpp;
1826 1828
1827 /* Set point to SEGSUM, initialize it. */ 1829 /* Set point to SEGSUM, initialize it. */
1828 ssp = sp->segsum = sbp->b_data; 1830 ssp = sp->segsum = sbp->b_data;
1829 memset(ssp, 0, fs->lfs_sumsize); 1831 memset(ssp, 0, fs->lfs_sumsize);
1830 ssp->ss_next = fs->lfs_nextseg; 1832 ssp->ss_next = lfs_sb_getnextseg(fs);
1831 ssp->ss_nfinfo = ssp->ss_ninos = 0; 1833 ssp->ss_nfinfo = ssp->ss_ninos = 0;
1832 ssp->ss_magic = SS_MAGIC; 1834 ssp->ss_magic = SS_MAGIC;
1833 1835
1834 /* Set pointer to first FINFO, initialize it. */ 1836 /* Set pointer to first FINFO, initialize it. */
1835 sp->fip = (struct finfo *)((char *)sp->segsum + SEGSUM_SIZE(fs)); 1837 sp->fip = (struct finfo *)((char *)sp->segsum + SEGSUM_SIZE(fs));
1836 sp->fip->fi_nblocks = 0; 1838 sp->fip->fi_nblocks = 0;
1837 sp->start_lbp = &sp->fip->fi_blocks[0]; 1839 sp->start_lbp = &sp->fip->fi_blocks[0];
1838 sp->fip->fi_lastlength = 0; 1840 sp->fip->fi_lastlength = 0;
1839 1841
1840 sp->seg_bytes_left -= fs->lfs_sumsize; 1842 sp->seg_bytes_left -= fs->lfs_sumsize;
1841 sp->sum_bytes_left = fs->lfs_sumsize - SEGSUM_SIZE(fs); 1843 sp->sum_bytes_left = fs->lfs_sumsize - SEGSUM_SIZE(fs);
1842 1844
1843 return (repeat); 1845 return (repeat);
@@ -1868,86 +1870,86 @@ lfs_unset_inval_all(struct lfs *fs) @@ -1868,86 +1870,86 @@ lfs_unset_inval_all(struct lfs *fs)
1868 */ 1870 */
1869void 1871void
1870lfs_newseg(struct lfs *fs) 1872lfs_newseg(struct lfs *fs)
1871{ 1873{
1872 CLEANERINFO *cip; 1874 CLEANERINFO *cip;
1873 SEGUSE *sup; 1875 SEGUSE *sup;
1874 struct buf *bp; 1876 struct buf *bp;
1875 int curseg, isdirty, sn, skip_inval; 1877 int curseg, isdirty, sn, skip_inval;
1876 1878
1877 ASSERT_SEGLOCK(fs); 1879 ASSERT_SEGLOCK(fs);
1878 1880
1879 /* Honor LFCNWRAPSTOP */ 1881 /* Honor LFCNWRAPSTOP */
1880 mutex_enter(&lfs_lock); 1882 mutex_enter(&lfs_lock);
1881 while (fs->lfs_nextseg < fs->lfs_curseg && fs->lfs_nowrap) { 1883 while (lfs_sb_getnextseg(fs) < lfs_sb_getcurseg(fs) && fs->lfs_nowrap) {
1882 if (fs->lfs_wrappass) { 1884 if (fs->lfs_wrappass) {
1883 log(LOG_NOTICE, "%s: wrappass=%d\n", 1885 log(LOG_NOTICE, "%s: wrappass=%d\n",
1884 fs->lfs_fsmnt, fs->lfs_wrappass); 1886 fs->lfs_fsmnt, fs->lfs_wrappass);
1885 fs->lfs_wrappass = 0; 1887 fs->lfs_wrappass = 0;
1886 break; 1888 break;
1887 } 1889 }
1888 fs->lfs_wrapstatus = LFS_WRAP_WAITING; 1890 fs->lfs_wrapstatus = LFS_WRAP_WAITING;
1889 wakeup(&fs->lfs_nowrap); 1891 wakeup(&fs->lfs_nowrap);
1890 log(LOG_NOTICE, "%s: waiting at log wrap\n", fs->lfs_fsmnt); 1892 log(LOG_NOTICE, "%s: waiting at log wrap\n", fs->lfs_fsmnt);
1891 mtsleep(&fs->lfs_wrappass, PVFS, "newseg", 10 * hz, 1893 mtsleep(&fs->lfs_wrappass, PVFS, "newseg", 10 * hz,
1892 &lfs_lock); 1894 &lfs_lock);
1893 } 1895 }
1894 fs->lfs_wrapstatus = LFS_WRAP_GOING; 1896 fs->lfs_wrapstatus = LFS_WRAP_GOING;
1895 mutex_exit(&lfs_lock); 1897 mutex_exit(&lfs_lock);
1896 1898
1897 LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, fs->lfs_nextseg), bp); 1899 LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, lfs_sb_getnextseg(fs)), bp);
1898 DLOG((DLOG_SU, "lfs_newseg: seg %d := 0 in newseg\n", 1900 DLOG((DLOG_SU, "lfs_newseg: seg %d := 0 in newseg\n",
1899 lfs_dtosn(fs, fs->lfs_nextseg))); 1901 lfs_dtosn(fs, lfs_sb_getnextseg(fs))));
1900 sup->su_flags |= SEGUSE_DIRTY | SEGUSE_ACTIVE; 1902 sup->su_flags |= SEGUSE_DIRTY | SEGUSE_ACTIVE;
1901 sup->su_nbytes = 0; 1903 sup->su_nbytes = 0;
1902 sup->su_nsums = 0; 1904 sup->su_nsums = 0;
1903 sup->su_ninos = 0; 1905 sup->su_ninos = 0;
1904 LFS_WRITESEGENTRY(sup, fs, lfs_dtosn(fs, fs->lfs_nextseg), bp); 1906 LFS_WRITESEGENTRY(sup, fs, lfs_dtosn(fs, lfs_sb_getnextseg(fs)), bp);
1905 1907
1906 LFS_CLEANERINFO(cip, fs, bp); 1908 LFS_CLEANERINFO(cip, fs, bp);
1907 --cip->clean; 1909 --cip->clean;
1908 ++cip->dirty; 1910 ++cip->dirty;
1909 fs->lfs_nclean = cip->clean; 1911 fs->lfs_nclean = cip->clean;
1910 LFS_SYNC_CLEANERINFO(cip, fs, bp, 1); 1912 LFS_SYNC_CLEANERINFO(cip, fs, bp, 1);
1911 1913
1912 fs->lfs_lastseg = fs->lfs_curseg; 1914 lfs_sb_setlastseg(fs, lfs_sb_getcurseg(fs));
1913 fs->lfs_curseg = fs->lfs_nextseg; 1915 lfs_sb_setcurseg(fs, lfs_sb_getnextseg(fs));
1914 skip_inval = 1; 1916 skip_inval = 1;
1915 for (sn = curseg = lfs_dtosn(fs, fs->lfs_curseg) + fs->lfs_interleave;;) { 1917 for (sn = curseg = lfs_dtosn(fs, lfs_sb_getcurseg(fs)) + fs->lfs_interleave;;) {
1916 sn = (sn + 1) % fs->lfs_nseg; 1918 sn = (sn + 1) % fs->lfs_nseg;
1917 1919
1918 if (sn == curseg) { 1920 if (sn == curseg) {
1919 if (skip_inval) 1921 if (skip_inval)
1920 skip_inval = 0; 1922 skip_inval = 0;
1921 else 1923 else
1922 panic("lfs_nextseg: no clean segments"); 1924 panic("lfs_nextseg: no clean segments");
1923 } 1925 }
1924 LFS_SEGENTRY(sup, fs, sn, bp); 1926 LFS_SEGENTRY(sup, fs, sn, bp);
1925 isdirty = sup->su_flags & (SEGUSE_DIRTY | (skip_inval ? SEGUSE_INVAL : 0)); 1927 isdirty = sup->su_flags & (SEGUSE_DIRTY | (skip_inval ? SEGUSE_INVAL : 0));
1926 /* Check SEGUSE_EMPTY as we go along */ 1928 /* Check SEGUSE_EMPTY as we go along */
1927 if (isdirty && sup->su_nbytes == 0 && 1929 if (isdirty && sup->su_nbytes == 0 &&
1928 !(sup->su_flags & SEGUSE_EMPTY)) 1930 !(sup->su_flags & SEGUSE_EMPTY))
1929 LFS_WRITESEGENTRY(sup, fs, sn, bp); 1931 LFS_WRITESEGENTRY(sup, fs, sn, bp);
1930 else 1932 else
1931 brelse(bp, 0); 1933 brelse(bp, 0);
1932 1934
1933 if (!isdirty) 1935 if (!isdirty)
1934 break; 1936 break;
1935 } 1937 }
1936 if (skip_inval == 0) 1938 if (skip_inval == 0)
1937 lfs_unset_inval_all(fs); 1939 lfs_unset_inval_all(fs);
1938 1940
1939 ++fs->lfs_nactive; 1941 ++fs->lfs_nactive;
1940 fs->lfs_nextseg = lfs_sntod(fs, sn); 1942 lfs_sb_setnextseg(fs, lfs_sntod(fs, sn));
1941 if (lfs_dostats) { 1943 if (lfs_dostats) {
1942 ++lfs_stats.segsused; 1944 ++lfs_stats.segsused;
1943 } 1945 }
1944} 1946}
1945 1947
1946static struct buf * 1948static struct buf *
1947lfs_newclusterbuf(struct lfs *fs, struct vnode *vp, daddr_t addr, 1949lfs_newclusterbuf(struct lfs *fs, struct vnode *vp, daddr_t addr,
1948 int n) 1950 int n)
1949{ 1951{
1950 struct lfs_cluster *cl; 1952 struct lfs_cluster *cl;
1951 struct buf **bpp, *bp; 1953 struct buf **bpp, *bp;
1952 1954
1953 ASSERT_SEGLOCK(fs); 1955 ASSERT_SEGLOCK(fs);
@@ -2053,27 +2055,27 @@ lfs_writeseg(struct lfs *fs, struct segm @@ -2053,27 +2055,27 @@ lfs_writeseg(struct lfs *fs, struct segm
2053 2055
2054 ninos = (ssp->ss_ninos + LFS_INOPB(fs) - 1) / LFS_INOPB(fs); 2056 ninos = (ssp->ss_ninos + LFS_INOPB(fs) - 1) / LFS_INOPB(fs);
2055 DLOG((DLOG_SU, "seg %d += %d for %d inodes\n", 2057 DLOG((DLOG_SU, "seg %d += %d for %d inodes\n",
2056 sp->seg_number, ssp->ss_ninos * sizeof (struct ulfs1_dinode), 2058 sp->seg_number, ssp->ss_ninos * sizeof (struct ulfs1_dinode),
2057 ssp->ss_ninos)); 2059 ssp->ss_ninos));
2058 sup->su_nbytes += ssp->ss_ninos * sizeof (struct ulfs1_dinode); 2060 sup->su_nbytes += ssp->ss_ninos * sizeof (struct ulfs1_dinode);
2059 /* sup->su_nbytes += fs->lfs_sumsize; */ 2061 /* sup->su_nbytes += fs->lfs_sumsize; */
2060 if (fs->lfs_version == 1) 2062 if (fs->lfs_version == 1)
2061 sup->su_olastmod = time_second; 2063 sup->su_olastmod = time_second;
2062 else 2064 else
2063 sup->su_lastmod = time_second; 2065 sup->su_lastmod = time_second;
2064 sup->su_ninos += ninos; 2066 sup->su_ninos += ninos;
2065 ++sup->su_nsums; 2067 ++sup->su_nsums;
2066 fs->lfs_avail -= lfs_btofsb(fs, fs->lfs_sumsize); 2068 lfs_sb_subavail(fs, lfs_btofsb(fs, lfs_sb_getsumsize(fs)));
2067 2069
2068 do_again = !(bp->b_flags & B_GATHERED); 2070 do_again = !(bp->b_flags & B_GATHERED);
2069 LFS_WRITESEGENTRY(sup, fs, sp->seg_number, bp); /* Ifile */ 2071 LFS_WRITESEGENTRY(sup, fs, sp->seg_number, bp); /* Ifile */
2070 2072
2071 /* 2073 /*
2072 * Mark blocks B_BUSY, to prevent then from being changed between 2074 * Mark blocks B_BUSY, to prevent then from being changed between
2073 * the checksum computation and the actual write. 2075 * the checksum computation and the actual write.
2074 * 2076 *
2075 * If we are cleaning, check indirect blocks for UNWRITTEN, and if 2077 * If we are cleaning, check indirect blocks for UNWRITTEN, and if
2076 * there are any, replace them with copies that have UNASSIGNED 2078 * there are any, replace them with copies that have UNASSIGNED
2077 * instead. 2079 * instead.
2078 */ 2080 */
2079 mutex_enter(&bufcache_lock); 2081 mutex_enter(&bufcache_lock);
@@ -2140,28 +2142,28 @@ lfs_writeseg(struct lfs *fs, struct segm @@ -2140,28 +2142,28 @@ lfs_writeseg(struct lfs *fs, struct segm
2140 DLOG((DLOG_SEG, "lfs_writeseg: " 2142 DLOG((DLOG_SEG, "lfs_writeseg: "
2141 "indir bp should not be B_CALL\n")); 2143 "indir bp should not be B_CALL\n"));
2142 biodone(bp); 2144 biodone(bp);
2143 bp = NULL; 2145 bp = NULL;
2144 } else { 2146 } else {
2145 /* Still on free list, leave it there */ 2147 /* Still on free list, leave it there */
2146 unbusybp = bp; 2148 unbusybp = bp;
2147 /* 2149 /*
2148 * We have to re-decrement lfs_avail 2150 * We have to re-decrement lfs_avail
2149 * since this block is going to come 2151 * since this block is going to come
2150 * back around to us in the next 2152 * back around to us in the next
2151 * segment. 2153 * segment.
2152 */ 2154 */
2153 fs->lfs_avail -= 2155 lfs_sb_subavail(fs,
2154 lfs_btofsb(fs, bp->b_bcount); 2156 lfs_btofsb(fs, bp->b_bcount));
2155 } 2157 }
2156 } else { 2158 } else {
2157 lfs_freebuf(fs, newbp); 2159 lfs_freebuf(fs, newbp);
2158 } 2160 }
2159 } 2161 }
2160 mutex_enter(&bufcache_lock); 2162 mutex_enter(&bufcache_lock);
2161 if (unbusybp != NULL) { 2163 if (unbusybp != NULL) {
2162 unbusybp->b_cflags &= ~BC_BUSY; 2164 unbusybp->b_cflags &= ~BC_BUSY;
2163 if (unbusybp->b_cflags & BC_WANTED) 2165 if (unbusybp->b_cflags & BC_WANTED)
2164 cv_broadcast(&bp->b_busy); 2166 cv_broadcast(&bp->b_busy);
2165 } 2167 }
2166 } 2168 }
2167 mutex_exit(&bufcache_lock); 2169 mutex_exit(&bufcache_lock);
@@ -2170,61 +2172,62 @@ lfs_writeseg(struct lfs *fs, struct segm @@ -2170,61 +2172,62 @@ lfs_writeseg(struct lfs *fs, struct segm
2170 * Compute checksum across data and then across summary; the first 2172 * Compute checksum across data and then across summary; the first
2171 * block (the summary block) is skipped. Set the create time here 2173 * block (the summary block) is skipped. Set the create time here
2172 * so that it's guaranteed to be later than the inode mod times. 2174 * so that it's guaranteed to be later than the inode mod times.
2173 */ 2175 */
2174 sum = 0; 2176 sum = 0;
2175 if (fs->lfs_version == 1) 2177 if (fs->lfs_version == 1)
2176 el_size = sizeof(u_long); 2178 el_size = sizeof(u_long);
2177 else 2179 else
2178 el_size = sizeof(u_int32_t); 2180 el_size = sizeof(u_int32_t);
2179 for (bpp = sp->bpp, i = nblocks - 1; i--; ) { 2181 for (bpp = sp->bpp, i = nblocks - 1; i--; ) {
2180 ++bpp; 2182 ++bpp;
2181 /* Loop through gop_write cluster blocks */ 2183 /* Loop through gop_write cluster blocks */
2182 for (byteoffset = 0; byteoffset < (*bpp)->b_bcount; 2184 for (byteoffset = 0; byteoffset < (*bpp)->b_bcount;
2183 byteoffset += fs->lfs_bsize) { 2185 byteoffset += lfs_sb_getbsize(fs)) {
2184#ifdef LFS_USE_B_INVAL 2186#ifdef LFS_USE_B_INVAL
2185 if (((*bpp)->b_cflags & BC_INVAL) != 0 && 2187 if (((*bpp)->b_cflags & BC_INVAL) != 0 &&
2186 (*bpp)->b_iodone != NULL) { 2188 (*bpp)->b_iodone != NULL) {
2187 if (copyin((void *)(*bpp)->b_saveaddr + 2189 if (copyin((void *)(*bpp)->b_saveaddr +
2188 byteoffset, dp, el_size)) { 2190 byteoffset, dp, el_size)) {
2189 panic("lfs_writeseg: copyin failed [1]:" 2191 panic("lfs_writeseg: copyin failed [1]:"
2190 " ino %d blk %" PRId64, 2192 " ino %d blk %" PRId64,
2191 VTOI((*bpp)->b_vp)->i_number, 2193 VTOI((*bpp)->b_vp)->i_number,
2192 (*bpp)->b_lblkno); 2194 (*bpp)->b_lblkno);
2193 } 2195 }
2194 } else 2196 } else
2195#endif /* LFS_USE_B_INVAL */ 2197#endif /* LFS_USE_B_INVAL */
2196 { 2198 {
2197 sum = lfs_cksum_part((char *) 2199 sum = lfs_cksum_part((char *)
2198 (*bpp)->b_data + byteoffset, el_size, sum); 2200 (*bpp)->b_data + byteoffset, el_size, sum);
2199 } 2201 }
2200 } 2202 }
2201 } 2203 }
2202 if (fs->lfs_version == 1) 2204 if (fs->lfs_version == 1)
2203 ssp->ss_ocreate = time_second; 2205 ssp->ss_ocreate = time_second;
2204 else { 2206 else {
2205 ssp->ss_create = time_second; 2207 ssp->ss_create = time_second;
2206 ssp->ss_serial = ++fs->lfs_serial; 2208 lfs_sb_addserial(fs, 1);
 2209 ssp->ss_serial = lfs_sb_getserial(fs);
2207 ssp->ss_ident = fs->lfs_ident; 2210 ssp->ss_ident = fs->lfs_ident;
2208 } 2211 }
2209 ssp->ss_datasum = lfs_cksum_fold(sum); 2212 ssp->ss_datasum = lfs_cksum_fold(sum);
2210 ssp->ss_sumsum = cksum(&ssp->ss_datasum, 2213 ssp->ss_sumsum = cksum(&ssp->ss_datasum,
2211 fs->lfs_sumsize - sizeof(ssp->ss_sumsum)); 2214 fs->lfs_sumsize - sizeof(ssp->ss_sumsum));
2212 2215
2213 mutex_enter(&lfs_lock); 2216 mutex_enter(&lfs_lock);
2214 fs->lfs_bfree -= (lfs_btofsb(fs, ninos * fs->lfs_ibsize) + 2217 lfs_sb_subbfree(fs, (lfs_btofsb(fs, ninos * fs->lfs_ibsize) +
2215 lfs_btofsb(fs, fs->lfs_sumsize)); 2218 lfs_btofsb(fs, fs->lfs_sumsize)));
2216 fs->lfs_dmeta += (lfs_btofsb(fs, ninos * fs->lfs_ibsize) + 2219 lfs_sb_adddmeta(fs, (lfs_btofsb(fs, ninos * fs->lfs_ibsize) +
2217 lfs_btofsb(fs, fs->lfs_sumsize)); 2220 lfs_btofsb(fs, fs->lfs_sumsize)));
2218 mutex_exit(&lfs_lock); 2221 mutex_exit(&lfs_lock);
2219 2222
2220 /* 2223 /*
2221 * When we simply write the blocks we lose a rotation for every block 2224 * When we simply write the blocks we lose a rotation for every block
2222 * written. To avoid this problem, we cluster the buffers into a 2225 * written. To avoid this problem, we cluster the buffers into a
2223 * chunk and write the chunk. MAXPHYS is the largest size I/O 2226 * chunk and write the chunk. MAXPHYS is the largest size I/O
2224 * devices can handle, use that for the size of the chunks. 2227 * devices can handle, use that for the size of the chunks.
2225 * 2228 *
2226 * Blocks that are already clusters (from GOP_WRITE), however, we 2229 * Blocks that are already clusters (from GOP_WRITE), however, we
2227 * don't bother to copy into other clusters. 2230 * don't bother to copy into other clusters.
2228 */ 2231 */
2229 2232
2230#define CHUNKSIZE MAXPHYS 2233#define CHUNKSIZE MAXPHYS
@@ -2254,27 +2257,27 @@ lfs_writeseg(struct lfs *fs, struct segm @@ -2254,27 +2257,27 @@ lfs_writeseg(struct lfs *fs, struct segm
2254 */ 2257 */
2255 mutex_enter(&lfs_lock); 2258 mutex_enter(&lfs_lock);
2256 ++fs->lfs_iocount; 2259 ++fs->lfs_iocount;
2257 mutex_exit(&lfs_lock); 2260 mutex_exit(&lfs_lock);
2258 while (i && cbp->b_bcount < CHUNKSIZE) { 2261 while (i && cbp->b_bcount < CHUNKSIZE) {
2259 bp = *bpp; 2262 bp = *bpp;
2260 2263
2261 if (bp->b_bcount > (CHUNKSIZE - cbp->b_bcount)) 2264 if (bp->b_bcount > (CHUNKSIZE - cbp->b_bcount))
2262 break; 2265 break;
2263 if (cbp->b_bcount > 0 && !(cl->flags & LFS_CL_MALLOC)) 2266 if (cbp->b_bcount > 0 && !(cl->flags & LFS_CL_MALLOC))
2264 break; 2267 break;
2265 2268
2266 /* Clusters from GOP_WRITE are expedited */ 2269 /* Clusters from GOP_WRITE are expedited */
2267 if (bp->b_bcount > fs->lfs_bsize) { 2270 if (bp->b_bcount > lfs_sb_getbsize(fs)) {
2268 if (cbp->b_bcount > 0) 2271 if (cbp->b_bcount > 0)
2269 /* Put in its own buffer */ 2272 /* Put in its own buffer */
2270 break; 2273 break;
2271 else { 2274 else {
2272 cbp->b_data = bp->b_data; 2275 cbp->b_data = bp->b_data;
2273 } 2276 }
2274 } else if (cbp->b_bcount == 0) { 2277 } else if (cbp->b_bcount == 0) {
2275 p = cbp->b_data = lfs_malloc(fs, CHUNKSIZE, 2278 p = cbp->b_data = lfs_malloc(fs, CHUNKSIZE,
2276 LFS_NB_CLUSTER); 2279 LFS_NB_CLUSTER);
2277 cl->flags |= LFS_CL_MALLOC; 2280 cl->flags |= LFS_CL_MALLOC;
2278 } 2281 }
2279#ifdef DIAGNOSTIC 2282#ifdef DIAGNOSTIC
2280 if (lfs_dtosn(fs, LFS_DBTOFSB(fs, bp->b_blkno + 2283 if (lfs_dtosn(fs, LFS_DBTOFSB(fs, bp->b_blkno +
@@ -2370,28 +2373,28 @@ lfs_writesuper(struct lfs *fs, daddr_t d @@ -2370,28 +2373,28 @@ lfs_writesuper(struct lfs *fs, daddr_t d
2370 */ 2373 */
2371 mutex_enter(&lfs_lock); 2374 mutex_enter(&lfs_lock);
2372 s = splbio(); 2375 s = splbio();
2373 while (fs->lfs_sbactive) { 2376 while (fs->lfs_sbactive) {
2374 mtsleep(&fs->lfs_sbactive, PRIBIO+1, "lfs sb", 0, 2377 mtsleep(&fs->lfs_sbactive, PRIBIO+1, "lfs sb", 0,
2375 &lfs_lock); 2378 &lfs_lock);
2376 } 2379 }
2377 fs->lfs_sbactive = daddr; 2380 fs->lfs_sbactive = daddr;
2378 splx(s); 2381 splx(s);
2379 mutex_exit(&lfs_lock); 2382 mutex_exit(&lfs_lock);
2380 2383
2381 /* Set timestamp of this version of the superblock */ 2384 /* Set timestamp of this version of the superblock */
2382 if (fs->lfs_version == 1) 2385 if (fs->lfs_version == 1)
2383 fs->lfs_otstamp = time_second; 2386 lfs_sb_setotstamp(fs, time_second);
2384 fs->lfs_tstamp = time_second; 2387 lfs_sb_settstamp(fs, time_second);
2385 2388
2386 /* Checksum the superblock and copy it into a buffer. */ 2389 /* Checksum the superblock and copy it into a buffer. */
2387 fs->lfs_cksum = lfs_sb_cksum(&(fs->lfs_dlfs)); 2390 fs->lfs_cksum = lfs_sb_cksum(&(fs->lfs_dlfs));
2388 bp = lfs_newbuf(fs, devvp, 2391 bp = lfs_newbuf(fs, devvp,
2389 LFS_FSBTODB(fs, daddr), LFS_SBPAD, LFS_NB_SBLOCK); 2392 LFS_FSBTODB(fs, daddr), LFS_SBPAD, LFS_NB_SBLOCK);
2390 memset((char *)bp->b_data + sizeof(struct dlfs), 0, 2393 memset((char *)bp->b_data + sizeof(struct dlfs), 0,
2391 LFS_SBPAD - sizeof(struct dlfs)); 2394 LFS_SBPAD - sizeof(struct dlfs));
2392 *(struct dlfs *)bp->b_data = fs->lfs_dlfs; 2395 *(struct dlfs *)bp->b_data = fs->lfs_dlfs;
2393 2396
2394 bp->b_cflags |= BC_BUSY; 2397 bp->b_cflags |= BC_BUSY;
2395 bp->b_flags = (bp->b_flags & ~B_READ) | B_ASYNC; 2398 bp->b_flags = (bp->b_flags & ~B_READ) | B_ASYNC;
2396 bp->b_oflags &= ~(BO_DONE | BO_DELWRI); 2399 bp->b_oflags &= ~(BO_DONE | BO_DELWRI);
2397 bp->b_error = 0; 2400 bp->b_error = 0;
@@ -2749,27 +2752,27 @@ lfs_shellsort(struct buf **bp_array, int @@ -2749,27 +2752,27 @@ lfs_shellsort(struct buf **bp_array, int
2749} 2752}
2750 2753
2751/* 2754/*
2752 * Set up an FINFO entry for a new file. The fip pointer is assumed to  2755 * Set up an FINFO entry for a new file. The fip pointer is assumed to
2753 * point at uninitialized space. 2756 * point at uninitialized space.
2754 */ 2757 */
2755void 2758void
2756lfs_acquire_finfo(struct lfs *fs, ino_t ino, int vers) 2759lfs_acquire_finfo(struct lfs *fs, ino_t ino, int vers)
2757{ 2760{
2758 struct segment *sp = fs->lfs_sp; 2761 struct segment *sp = fs->lfs_sp;
2759 2762
2760 KASSERT(vers > 0); 2763 KASSERT(vers > 0);
2761 2764
2762 if (sp->seg_bytes_left < fs->lfs_bsize || 2765 if (sp->seg_bytes_left < lfs_sb_getbsize(fs) ||
2763 sp->sum_bytes_left < sizeof(struct finfo)) 2766 sp->sum_bytes_left < sizeof(struct finfo))
2764 (void) lfs_writeseg(fs, fs->lfs_sp); 2767 (void) lfs_writeseg(fs, fs->lfs_sp);
2765  2768
2766 sp->sum_bytes_left -= FINFOSIZE; 2769 sp->sum_bytes_left -= FINFOSIZE;
2767 ++((SEGSUM *)(sp->segsum))->ss_nfinfo; 2770 ++((SEGSUM *)(sp->segsum))->ss_nfinfo;
2768 sp->fip->fi_nblocks = 0; 2771 sp->fip->fi_nblocks = 0;
2769 sp->fip->fi_ino = ino; 2772 sp->fip->fi_ino = ino;
2770 sp->fip->fi_version = vers; 2773 sp->fip->fi_version = vers;
2771} 2774}
2772 2775
2773/* 2776/*
2774 * Release the FINFO entry, either clearing out an unused entry or 2777 * Release the FINFO entry, either clearing out an unused entry or
2775 * advancing us to the next available entry. 2778 * advancing us to the next available entry.

cvs diff -r1.160 -r1.161 src/sys/ufs/lfs/lfs_syscalls.c (expand / switch to unified diff)

--- src/sys/ufs/lfs/lfs_syscalls.c 2015/05/31 15:48:03 1.160
+++ src/sys/ufs/lfs/lfs_syscalls.c 2015/07/24 06:56:42 1.161
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lfs_syscalls.c,v 1.160 2015/05/31 15:48:03 hannken Exp $ */ 1/* $NetBSD: lfs_syscalls.c,v 1.161 2015/07/24 06:56:42 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007, 2008 4 * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007, 2008
5 * The NetBSD Foundation, Inc. 5 * The NetBSD Foundation, Inc.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * This code is derived from software contributed to The NetBSD Foundation 8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Konrad E. Schroder <perseant@hhhh.org>. 9 * by Konrad E. Schroder <perseant@hhhh.org>.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -51,27 +51,27 @@ @@ -51,27 +51,27 @@
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE. 58 * SUCH DAMAGE.
59 * 59 *
60 * @(#)lfs_syscalls.c 8.10 (Berkeley) 5/14/95 60 * @(#)lfs_syscalls.c 8.10 (Berkeley) 5/14/95
61 */ 61 */
62 62
63#include <sys/cdefs.h> 63#include <sys/cdefs.h>
64__KERNEL_RCSID(0, "$NetBSD: lfs_syscalls.c,v 1.160 2015/05/31 15:48:03 hannken Exp $"); 64__KERNEL_RCSID(0, "$NetBSD: lfs_syscalls.c,v 1.161 2015/07/24 06:56:42 dholland Exp $");
65 65
66#ifndef LFS 66#ifndef LFS
67# define LFS /* for prototypes in syscallargs.h */ 67# define LFS /* for prototypes in syscallargs.h */
68#endif 68#endif
69 69
70#include <sys/param.h> 70#include <sys/param.h>
71#include <sys/systm.h> 71#include <sys/systm.h>
72#include <sys/proc.h> 72#include <sys/proc.h>
73#include <sys/buf.h> 73#include <sys/buf.h>
74#include <sys/mount.h> 74#include <sys/mount.h>
75#include <sys/vnode.h> 75#include <sys/vnode.h>
76#include <sys/kernel.h> 76#include <sys/kernel.h>
77#include <sys/kauth.h> 77#include <sys/kauth.h>
@@ -242,27 +242,27 @@ lfs_markv(struct proc *p, fsid_t *fsidp, @@ -242,27 +242,27 @@ lfs_markv(struct proc *p, fsid_t *fsidp,
242 /* number of blocks/inodes that we have already bwrite'ed */ 242 /* number of blocks/inodes that we have already bwrite'ed */
243 int nblkwritten, ninowritten; 243 int nblkwritten, ninowritten;
244 244
245 if ((mntp = vfs_getvfs(fsidp)) == NULL) 245 if ((mntp = vfs_getvfs(fsidp)) == NULL)
246 return (ENOENT); 246 return (ENOENT);
247 247
248 ump = VFSTOULFS(mntp); 248 ump = VFSTOULFS(mntp);
249 fs = ump->um_lfs; 249 fs = ump->um_lfs;
250 250
251 if (fs->lfs_ronly) 251 if (fs->lfs_ronly)
252 return EROFS; 252 return EROFS;
253 253
254 maxino = (lfs_fragstoblks(fs, VTOI(fs->lfs_ivnode)->i_ffs1_blocks) - 254 maxino = (lfs_fragstoblks(fs, VTOI(fs->lfs_ivnode)->i_ffs1_blocks) -
255 fs->lfs_cleansz - fs->lfs_segtabsz) * fs->lfs_ifpb; 255 lfs_sb_getcleansz(fs) - lfs_sb_getsegtabsz(fs)) * lfs_sb_getifpb(fs);
256 256
257 cnt = blkcnt; 257 cnt = blkcnt;
258 258
259 if ((error = vfs_busy(mntp, NULL)) != 0) 259 if ((error = vfs_busy(mntp, NULL)) != 0)
260 return (error); 260 return (error);
261 261
262 /* 262 /*
263 * This seglock is just to prevent the fact that we might have to sleep 263 * This seglock is just to prevent the fact that we might have to sleep
264 * from allowing the possibility that our blocks might become 264 * from allowing the possibility that our blocks might become
265 * invalid. 265 * invalid.
266 * 266 *
267 * It is also important to note here that unless we specify SEGM_CKP, 267 * It is also important to note here that unless we specify SEGM_CKP,
268 * any Ifile blocks that we might be asked to clean will never get 268 * any Ifile blocks that we might be asked to clean will never get
@@ -380,27 +380,27 @@ lfs_markv(struct proc *p, fsid_t *fsidp, @@ -380,27 +380,27 @@ lfs_markv(struct proc *p, fsid_t *fsidp,
380 } 380 }
381 do_again++; 381 do_again++;
382 continue; 382 continue;
383 } 383 }
384 384
385 /* 385 /*
386 * Check block sizes. The blocks being cleaned come from 386 * Check block sizes. The blocks being cleaned come from
387 * disk, so they should have the same size as their on-disk 387 * disk, so they should have the same size as their on-disk
388 * counterparts. 388 * counterparts.
389 */ 389 */
390 if (blkp->bi_lbn >= 0) 390 if (blkp->bi_lbn >= 0)
391 obsize = lfs_blksize(fs, ip, blkp->bi_lbn); 391 obsize = lfs_blksize(fs, ip, blkp->bi_lbn);
392 else 392 else
393 obsize = fs->lfs_bsize; 393 obsize = lfs_sb_getbsize(fs);
394 /* Check for fragment size change */ 394 /* Check for fragment size change */
395 if (blkp->bi_lbn >= 0 && blkp->bi_lbn < ULFS_NDADDR) { 395 if (blkp->bi_lbn >= 0 && blkp->bi_lbn < ULFS_NDADDR) {
396 obsize = ip->i_lfs_fragsize[blkp->bi_lbn]; 396 obsize = ip->i_lfs_fragsize[blkp->bi_lbn];
397 } 397 }
398 if (obsize != blkp->bi_size) { 398 if (obsize != blkp->bi_size) {
399 DLOG((DLOG_CLEAN, "lfs_markv: ino %d lbn %lld wrong" 399 DLOG((DLOG_CLEAN, "lfs_markv: ino %d lbn %lld wrong"
400 " size (%ld != %d), try again\n", 400 " size (%ld != %d), try again\n",
401 blkp->bi_inode, (long long)blkp->bi_lbn, 401 blkp->bi_inode, (long long)blkp->bi_lbn,
402 (long) obsize, blkp->bi_size)); 402 (long) obsize, blkp->bi_size));
403 do_again++; 403 do_again++;
404 continue; 404 continue;
405 } 405 }
406 406
@@ -410,27 +410,27 @@ lfs_markv(struct proc *p, fsid_t *fsidp, @@ -410,27 +410,27 @@ lfs_markv(struct proc *p, fsid_t *fsidp,
410 * in the buffer cache so that it can be updated in the 410 * in the buffer cache so that it can be updated in the
411 * finish_meta section. If it's not, we need to 411 * finish_meta section. If it's not, we need to
412 * allocate a fake buffer so that writeseg can perform 412 * allocate a fake buffer so that writeseg can perform
413 * the copyin and write the buffer. 413 * the copyin and write the buffer.
414 */ 414 */
415 if (ip->i_number != LFS_IFILE_INUM && blkp->bi_lbn >= 0) { 415 if (ip->i_number != LFS_IFILE_INUM && blkp->bi_lbn >= 0) {
416 /* Data Block */ 416 /* Data Block */
417 bp = lfs_fakebuf(fs, vp, blkp->bi_lbn, 417 bp = lfs_fakebuf(fs, vp, blkp->bi_lbn,
418 blkp->bi_size, blkp->bi_bp); 418 blkp->bi_size, blkp->bi_bp);
419 /* Pretend we used bread() to get it */ 419 /* Pretend we used bread() to get it */
420 bp->b_blkno = LFS_FSBTODB(fs, blkp->bi_daddr); 420 bp->b_blkno = LFS_FSBTODB(fs, blkp->bi_daddr);
421 } else { 421 } else {
422 /* Indirect block or ifile */ 422 /* Indirect block or ifile */
423 if (blkp->bi_size != fs->lfs_bsize && 423 if (blkp->bi_size != lfs_sb_getbsize(fs) &&
424 ip->i_number != LFS_IFILE_INUM) 424 ip->i_number != LFS_IFILE_INUM)
425 panic("lfs_markv: partial indirect block?" 425 panic("lfs_markv: partial indirect block?"
426 " size=%d\n", blkp->bi_size); 426 " size=%d\n", blkp->bi_size);
427 bp = getblk(vp, blkp->bi_lbn, blkp->bi_size, 0, 0); 427 bp = getblk(vp, blkp->bi_lbn, blkp->bi_size, 0, 0);
428 if (!(bp->b_oflags & (BO_DONE|BO_DELWRI))) { 428 if (!(bp->b_oflags & (BO_DONE|BO_DELWRI))) {
429 /* 429 /*
430 * The block in question was not found 430 * The block in question was not found
431 * in the cache; i.e., the block that 431 * in the cache; i.e., the block that
432 * getblk() returned is empty. So, we 432 * getblk() returned is empty. So, we
433 * can (and should) copy in the 433 * can (and should) copy in the
434 * contents, because we've already 434 * contents, because we've already
435 * determined that this was the right 435 * determined that this was the right
436 * version of this block on disk. 436 * version of this block on disk.
@@ -692,27 +692,27 @@ lfs_bmapv(struct proc *p, fsid_t *fsidp, @@ -692,27 +692,27 @@ lfs_bmapv(struct proc *p, fsid_t *fsidp,
692 * Finish the old file, if there was one. 692 * Finish the old file, if there was one.
693 */ 693 */
694 if (vp != NULL) { 694 if (vp != NULL) {
695 vput(vp); 695 vput(vp);
696 vp = NULL; 696 vp = NULL;
697 numrefed--; 697 numrefed--;
698 } 698 }
699 699
700 /* 700 /*
701 * Start a new file 701 * Start a new file
702 */ 702 */
703 lastino = blkp->bi_inode; 703 lastino = blkp->bi_inode;
704 if (blkp->bi_inode == LFS_IFILE_INUM) 704 if (blkp->bi_inode == LFS_IFILE_INUM)
705 v_daddr = fs->lfs_idaddr; 705 v_daddr = lfs_sb_getidaddr(fs);
706 else { 706 else {
707 LFS_IENTRY(ifp, fs, blkp->bi_inode, bp); 707 LFS_IENTRY(ifp, fs, blkp->bi_inode, bp);
708 v_daddr = ifp->if_daddr; 708 v_daddr = ifp->if_daddr;
709 brelse(bp, 0); 709 brelse(bp, 0);
710 } 710 }
711 if (v_daddr == LFS_UNUSED_DADDR) { 711 if (v_daddr == LFS_UNUSED_DADDR) {
712 blkp->bi_daddr = LFS_UNUSED_DADDR; 712 blkp->bi_daddr = LFS_UNUSED_DADDR;
713 continue; 713 continue;
714 } 714 }
715 error = lfs_fastvget(mntp, blkp->bi_inode, NULL, 715 error = lfs_fastvget(mntp, blkp->bi_inode, NULL,
716 LK_SHARED, &vp); 716 LK_SHARED, &vp);
717 if (error) { 717 if (error) {
718 DLOG((DLOG_CLEAN, "lfs_bmapv: lfs_fastvget ino" 718 DLOG((DLOG_CLEAN, "lfs_bmapv: lfs_fastvget ino"
@@ -753,27 +753,27 @@ lfs_bmapv(struct proc *p, fsid_t *fsidp, @@ -753,27 +753,27 @@ lfs_bmapv(struct proc *p, fsid_t *fsidp,
753 /* XXX ondisk32 */ 753 /* XXX ondisk32 */
754 error = VOP_BMAP(vp, blkp->bi_lbn, NULL, 754 error = VOP_BMAP(vp, blkp->bi_lbn, NULL,
755 &bi_daddr, NULL); 755 &bi_daddr, NULL);
756 if (error) 756 if (error)
757 { 757 {
758 blkp->bi_daddr = LFS_UNUSED_DADDR; 758 blkp->bi_daddr = LFS_UNUSED_DADDR;
759 continue; 759 continue;
760 } 760 }
761 blkp->bi_daddr = LFS_DBTOFSB(fs, bi_daddr); 761 blkp->bi_daddr = LFS_DBTOFSB(fs, bi_daddr);
762 /* Fill in the block size, too */ 762 /* Fill in the block size, too */
763 if (blkp->bi_lbn >= 0) 763 if (blkp->bi_lbn >= 0)
764 blkp->bi_size = lfs_blksize(fs, ip, blkp->bi_lbn); 764 blkp->bi_size = lfs_blksize(fs, ip, blkp->bi_lbn);
765 else 765 else
766 blkp->bi_size = fs->lfs_bsize; 766 blkp->bi_size = lfs_sb_getbsize(fs);
767 } 767 }
768 } 768 }
769 769
770 /* 770 /*
771 * Finish the old file, if there was one. 771 * Finish the old file, if there was one.
772 */ 772 */
773 if (vp != NULL) { 773 if (vp != NULL) {
774 vput(vp); 774 vput(vp);
775 vp = NULL; 775 vp = NULL;
776 numrefed--; 776 numrefed--;
777 } 777 }
778 778
779#ifdef DIAGNOSTIC 779#ifdef DIAGNOSTIC
@@ -834,102 +834,102 @@ sys_lfs_segclean(struct lwp *l, const st @@ -834,102 +834,102 @@ sys_lfs_segclean(struct lwp *l, const st
834 834
835/* 835/*
836 * Actually mark the segment clean. 836 * Actually mark the segment clean.
837 * Must be called with the segment lock held. 837 * Must be called with the segment lock held.
838 */ 838 */
839int 839int
840lfs_do_segclean(struct lfs *fs, unsigned long segnum) 840lfs_do_segclean(struct lfs *fs, unsigned long segnum)
841{ 841{
842 extern int lfs_dostats; 842 extern int lfs_dostats;
843 struct buf *bp; 843 struct buf *bp;
844 CLEANERINFO *cip; 844 CLEANERINFO *cip;
845 SEGUSE *sup; 845 SEGUSE *sup;
846 846
847 if (lfs_dtosn(fs, fs->lfs_curseg) == segnum) { 847 if (lfs_dtosn(fs, lfs_sb_getcurseg(fs)) == segnum) {
848 return (EBUSY); 848 return (EBUSY);
849 } 849 }
850 850
851 LFS_SEGENTRY(sup, fs, segnum, bp); 851 LFS_SEGENTRY(sup, fs, segnum, bp);
852 if (sup->su_nbytes) { 852 if (sup->su_nbytes) {
853 DLOG((DLOG_CLEAN, "lfs_segclean: not cleaning segment %lu:" 853 DLOG((DLOG_CLEAN, "lfs_segclean: not cleaning segment %lu:"
854 " %d live bytes\n", segnum, sup->su_nbytes)); 854 " %d live bytes\n", segnum, sup->su_nbytes));
855 brelse(bp, 0); 855 brelse(bp, 0);
856 return (EBUSY); 856 return (EBUSY);
857 } 857 }
858 if (sup->su_flags & SEGUSE_ACTIVE) { 858 if (sup->su_flags & SEGUSE_ACTIVE) {
859 DLOG((DLOG_CLEAN, "lfs_segclean: not cleaning segment %lu:" 859 DLOG((DLOG_CLEAN, "lfs_segclean: not cleaning segment %lu:"
860 " segment is active\n", segnum)); 860 " segment is active\n", segnum));
861 brelse(bp, 0); 861 brelse(bp, 0);
862 return (EBUSY); 862 return (EBUSY);
863 } 863 }
864 if (!(sup->su_flags & SEGUSE_DIRTY)) { 864 if (!(sup->su_flags & SEGUSE_DIRTY)) {
865 DLOG((DLOG_CLEAN, "lfs_segclean: not cleaning segment %lu:" 865 DLOG((DLOG_CLEAN, "lfs_segclean: not cleaning segment %lu:"
866 " segment is already clean\n", segnum)); 866 " segment is already clean\n", segnum));
867 brelse(bp, 0); 867 brelse(bp, 0);
868 return (EALREADY); 868 return (EALREADY);
869 } 869 }
870 870
871 fs->lfs_avail += lfs_segtod(fs, 1); 871 lfs_sb_addavail(fs, lfs_segtod(fs, 1));
872 if (sup->su_flags & SEGUSE_SUPERBLOCK) 872 if (sup->su_flags & SEGUSE_SUPERBLOCK)
873 fs->lfs_avail -= lfs_btofsb(fs, LFS_SBPAD); 873 lfs_sb_subavail(fs, lfs_btofsb(fs, LFS_SBPAD));
874 if (fs->lfs_version > 1 && segnum == 0 && 874 if (fs->lfs_version > 1 && segnum == 0 &&
875 fs->lfs_s0addr < lfs_btofsb(fs, LFS_LABELPAD)) 875 fs->lfs_s0addr < lfs_btofsb(fs, LFS_LABELPAD))
876 fs->lfs_avail -= lfs_btofsb(fs, LFS_LABELPAD) - fs->lfs_s0addr; 876 lfs_sb_subavail(fs, lfs_btofsb(fs, LFS_LABELPAD) - fs->lfs_s0addr);
877 mutex_enter(&lfs_lock); 877 mutex_enter(&lfs_lock);
878 fs->lfs_bfree += sup->su_nsums * lfs_btofsb(fs, fs->lfs_sumsize) + 878 lfs_sb_addbfree(fs, sup->su_nsums * lfs_btofsb(fs, fs->lfs_sumsize) +
879 lfs_btofsb(fs, sup->su_ninos * fs->lfs_ibsize); 879 lfs_btofsb(fs, sup->su_ninos * lfs_sb_getibsize(fs)));
880 fs->lfs_dmeta -= sup->su_nsums * lfs_btofsb(fs, fs->lfs_sumsize) + 880 lfs_sb_subdmeta(fs, sup->su_nsums * lfs_btofsb(fs, fs->lfs_sumsize) +
881 lfs_btofsb(fs, sup->su_ninos * fs->lfs_ibsize); 881 lfs_btofsb(fs, sup->su_ninos * lfs_sb_getibsize(fs)));
882 if (fs->lfs_dmeta < 0) 882 if (lfs_sb_getdmeta(fs) < 0)
883 fs->lfs_dmeta = 0; 883 lfs_sb_setdmeta(fs, 0);
884 mutex_exit(&lfs_lock); 884 mutex_exit(&lfs_lock);
885 sup->su_flags &= ~SEGUSE_DIRTY; 885 sup->su_flags &= ~SEGUSE_DIRTY;
886 LFS_WRITESEGENTRY(sup, fs, segnum, bp); 886 LFS_WRITESEGENTRY(sup, fs, segnum, bp);
887 887
888 LFS_CLEANERINFO(cip, fs, bp); 888 LFS_CLEANERINFO(cip, fs, bp);
889 ++cip->clean; 889 ++cip->clean;
890 --cip->dirty; 890 --cip->dirty;
891 fs->lfs_nclean = cip->clean; 891 fs->lfs_nclean = cip->clean;
892 cip->bfree = fs->lfs_bfree; 
893 mutex_enter(&lfs_lock); 892 mutex_enter(&lfs_lock);
894 cip->avail = fs->lfs_avail - fs->lfs_ravail - fs->lfs_favail; 893 cip->bfree = lfs_sb_getbfree(fs);
895 wakeup(&fs->lfs_avail); 894 cip->avail = lfs_sb_getavail(fs) - fs->lfs_ravail - fs->lfs_favail;
 895 wakeup(&fs->lfs_availsleep);
896 mutex_exit(&lfs_lock); 896 mutex_exit(&lfs_lock);
897 (void) LFS_BWRITE_LOG(bp); 897 (void) LFS_BWRITE_LOG(bp);
898 898
899 if (lfs_dostats) 899 if (lfs_dostats)
900 ++lfs_stats.segs_reclaimed; 900 ++lfs_stats.segs_reclaimed;
901 901
902 return (0); 902 return (0);
903} 903}
904 904
905/* 905/*
906 * This will block until a segment in file system fsid is written. A timeout 906 * This will block until a segment in file system fsid is written. A timeout
907 * in milliseconds may be specified which will awake the cleaner automatically. 907 * in milliseconds may be specified which will awake the cleaner automatically.
908 * An fsid of -1 means any file system, and a timeout of 0 means forever. 908 * An fsid of -1 means any file system, and a timeout of 0 means forever.
909 */ 909 */
910int 910int
911lfs_segwait(fsid_t *fsidp, struct timeval *tv) 911lfs_segwait(fsid_t *fsidp, struct timeval *tv)
912{ 912{
913 struct mount *mntp; 913 struct mount *mntp;
914 void *addr; 914 void *addr;
915 u_long timeout; 915 u_long timeout;
916 int error; 916 int error;
917 917
918 KERNEL_LOCK(1, NULL); 918 KERNEL_LOCK(1, NULL);
919 if (fsidp == NULL || (mntp = vfs_getvfs(fsidp)) == NULL) 919 if (fsidp == NULL || (mntp = vfs_getvfs(fsidp)) == NULL)
920 addr = &lfs_allclean_wakeup; 920 addr = &lfs_allclean_wakeup;
921 else 921 else
922 addr = &VFSTOULFS(mntp)->um_lfs->lfs_nextseg; 922 addr = &VFSTOULFS(mntp)->um_lfs->lfs_nextsegsleep;
923 /* 923 /*
924 * XXX THIS COULD SLEEP FOREVER IF TIMEOUT IS {0,0}! 924 * XXX THIS COULD SLEEP FOREVER IF TIMEOUT IS {0,0}!
925 * XXX IS THAT WHAT IS INTENDED? 925 * XXX IS THAT WHAT IS INTENDED?
926 */ 926 */
927 timeout = tvtohz(tv); 927 timeout = tvtohz(tv);
928 error = tsleep(addr, PCATCH | PVFS, "segment", timeout); 928 error = tsleep(addr, PCATCH | PVFS, "segment", timeout);
929 KERNEL_UNLOCK_ONE(NULL); 929 KERNEL_UNLOCK_ONE(NULL);
930 return (error == ERESTART ? EINTR : 0); 930 return (error == ERESTART ? EINTR : 0);
931} 931}
932 932
933/* 933/*
934 * sys_lfs_segwait: 934 * sys_lfs_segwait:
935 * 935 *

cvs diff -r1.326 -r1.327 src/sys/ufs/lfs/lfs_vfsops.c (expand / switch to unified diff)

--- src/sys/ufs/lfs/lfs_vfsops.c 2015/07/16 08:31:45 1.326
+++ src/sys/ufs/lfs/lfs_vfsops.c 2015/07/24 06:56:42 1.327
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lfs_vfsops.c,v 1.326 2015/07/16 08:31:45 dholland Exp $ */ 1/* $NetBSD: lfs_vfsops.c,v 1.327 2015/07/24 06:56:42 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007 4 * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007
5 * The NetBSD Foundation, Inc. 5 * The NetBSD Foundation, Inc.
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * This code is derived from software contributed to The NetBSD Foundation 8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Konrad E. Schroder <perseant@hhhh.org>. 9 * by Konrad E. Schroder <perseant@hhhh.org>.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -51,27 +51,27 @@ @@ -51,27 +51,27 @@
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE. 58 * SUCH DAMAGE.
59 * 59 *
60 * @(#)lfs_vfsops.c 8.20 (Berkeley) 6/10/95 60 * @(#)lfs_vfsops.c 8.20 (Berkeley) 6/10/95
61 */ 61 */
62 62
63#include <sys/cdefs.h> 63#include <sys/cdefs.h>
64__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.326 2015/07/16 08:31:45 dholland Exp $"); 64__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.327 2015/07/24 06:56:42 dholland Exp $");
65 65
66#if defined(_KERNEL_OPT) 66#if defined(_KERNEL_OPT)
67#include "opt_lfs.h" 67#include "opt_lfs.h"
68#include "opt_quota.h" 68#include "opt_quota.h"
69#endif 69#endif
70 70
71#include <sys/param.h> 71#include <sys/param.h>
72#include <sys/systm.h> 72#include <sys/systm.h>
73#include <sys/namei.h> 73#include <sys/namei.h>
74#include <sys/proc.h> 74#include <sys/proc.h>
75#include <sys/kernel.h> 75#include <sys/kernel.h>
76#include <sys/vnode.h> 76#include <sys/vnode.h>
77#include <sys/mount.h> 77#include <sys/mount.h>
@@ -452,29 +452,29 @@ lfs_writerd(void *arg) @@ -452,29 +452,29 @@ lfs_writerd(void *arg)
452 if (vfs_busy(mp, &nmp)) { 452 if (vfs_busy(mp, &nmp)) {
453 ++skipc; 453 ++skipc;
454 continue; 454 continue;
455 } 455 }
456 KASSERT(!mutex_owned(&lfs_lock)); 456 KASSERT(!mutex_owned(&lfs_lock));
457 if (strncmp(mp->mnt_stat.f_fstypename, MOUNT_LFS, 457 if (strncmp(mp->mnt_stat.f_fstypename, MOUNT_LFS,
458 sizeof(mp->mnt_stat.f_fstypename)) == 0) { 458 sizeof(mp->mnt_stat.f_fstypename)) == 0) {
459 ++lfsc; 459 ++lfsc;
460 fs = VFSTOULFS(mp)->um_lfs; 460 fs = VFSTOULFS(mp)->um_lfs;
461 int32_t ooffset = 0; 461 int32_t ooffset = 0;
462 fsflags = SEGM_SINGLE; 462 fsflags = SEGM_SINGLE;
463 463
464 mutex_enter(&lfs_lock); 464 mutex_enter(&lfs_lock);
465 ooffset = fs->lfs_offset; 465 ooffset = lfs_sb_getoffset(fs);
466 466
467 if (fs->lfs_nextseg < fs->lfs_curseg && fs->lfs_nowrap) { 467 if (lfs_sb_getnextseg(fs) < lfs_sb_getcurseg(fs) && fs->lfs_nowrap) {
468 /* Don't try to write if we're suspended */ 468 /* Don't try to write if we're suspended */
469 mutex_exit(&lfs_lock); 469 mutex_exit(&lfs_lock);
470 vfs_unbusy(mp, false, &nmp); 470 vfs_unbusy(mp, false, &nmp);
471 continue; 471 continue;
472 } 472 }
473 if (LFS_STARVED_FOR_SEGS(fs)) { 473 if (LFS_STARVED_FOR_SEGS(fs)) {
474 mutex_exit(&lfs_lock); 474 mutex_exit(&lfs_lock);
475 475
476 DLOG((DLOG_FLUSH, "lfs_writerd: need cleaning before writing possible\n")); 476 DLOG((DLOG_FLUSH, "lfs_writerd: need cleaning before writing possible\n"));
477 lfs_wakeup_cleaner(fs); 477 lfs_wakeup_cleaner(fs);
478 vfs_unbusy(mp, false, &nmp); 478 vfs_unbusy(mp, false, &nmp);
479 continue; 479 continue;
480 } 480 }
@@ -487,27 +487,27 @@ lfs_writerd(void *arg) @@ -487,27 +487,27 @@ lfs_writerd(void *arg)
487 DLOG((DLOG_FLUSH, "lfs_writerd: checkpoint\n")); 487 DLOG((DLOG_FLUSH, "lfs_writerd: checkpoint\n"));
488 lfs_flush_fs(fs, fsflags); 488 lfs_flush_fs(fs, fsflags);
489 } else if (fs->lfs_pdflush) { 489 } else if (fs->lfs_pdflush) {
490 DLOG((DLOG_FLUSH, "lfs_writerd: pdflush set\n")); 490 DLOG((DLOG_FLUSH, "lfs_writerd: pdflush set\n"));
491 lfs_flush_fs(fs, fsflags); 491 lfs_flush_fs(fs, fsflags);
492 } else if (!TAILQ_EMPTY(&fs->lfs_pchainhd)) { 492 } else if (!TAILQ_EMPTY(&fs->lfs_pchainhd)) {
493 DLOG((DLOG_FLUSH, "lfs_writerd: pchain non-empty\n")); 493 DLOG((DLOG_FLUSH, "lfs_writerd: pchain non-empty\n"));
494 mutex_exit(&lfs_lock); 494 mutex_exit(&lfs_lock);
495 lfs_writer_enter(fs, "wrdirop"); 495 lfs_writer_enter(fs, "wrdirop");
496 lfs_flush_pchain(fs); 496 lfs_flush_pchain(fs);
497 lfs_writer_leave(fs); 497 lfs_writer_leave(fs);
498 mutex_enter(&lfs_lock); 498 mutex_enter(&lfs_lock);
499 } 499 }
500 if (fs->lfs_offset != ooffset) 500 if (lfs_sb_getoffset(fs) != ooffset)
501 ++wrote_something; 501 ++wrote_something;
502 mutex_exit(&lfs_lock); 502 mutex_exit(&lfs_lock);
503 } 503 }
504 KASSERT(!mutex_owned(&lfs_lock)); 504 KASSERT(!mutex_owned(&lfs_lock));
505 vfs_unbusy(mp, false, &nmp); 505 vfs_unbusy(mp, false, &nmp);
506 } 506 }
507 if (lfsc + skipc == 0) { 507 if (lfsc + skipc == 0) {
508 mutex_enter(&lfs_lock); 508 mutex_enter(&lfs_lock);
509 lfs_writer_daemon = 0; 509 lfs_writer_daemon = 0;
510 lfs_writer_lid = 0; 510 lfs_writer_lid = 0;
511 mutex_exit(&lfs_lock); 511 mutex_exit(&lfs_lock);
512 mutex_exit(&mountlist_lock); 512 mutex_exit(&mountlist_lock);
513 break; 513 break;
@@ -599,27 +599,27 @@ lfs_mountroot(void) @@ -599,27 +599,27 @@ lfs_mountroot(void)
599 } 599 }
600 if ((error = lfs_mountfs(rootvp, mp, l))) { 600 if ((error = lfs_mountfs(rootvp, mp, l))) {
601 vfs_unbusy(mp, false, NULL); 601 vfs_unbusy(mp, false, NULL);
602 vfs_destroy(mp); 602 vfs_destroy(mp);
603 return (error); 603 return (error);
604 } 604 }
605 mountlist_append(mp); 605 mountlist_append(mp);
606 ump = VFSTOULFS(mp); 606 ump = VFSTOULFS(mp);
607 fs = ump->um_lfs; 607 fs = ump->um_lfs;
608 memset(fs->lfs_fsmnt, 0, sizeof(fs->lfs_fsmnt)); 608 memset(fs->lfs_fsmnt, 0, sizeof(fs->lfs_fsmnt));
609 (void)copystr(mp->mnt_stat.f_mntonname, fs->lfs_fsmnt, MNAMELEN - 1, 0); 609 (void)copystr(mp->mnt_stat.f_mntonname, fs->lfs_fsmnt, MNAMELEN - 1, 0);
610 (void)lfs_statvfs(mp, &mp->mnt_stat); 610 (void)lfs_statvfs(mp, &mp->mnt_stat);
611 vfs_unbusy(mp, false, NULL); 611 vfs_unbusy(mp, false, NULL);
612 setrootfstime((time_t)(VFSTOULFS(mp)->um_lfs->lfs_tstamp)); 612 setrootfstime((time_t)lfs_sb_gettstamp(VFSTOULFS(mp)->um_lfs));
613 return (0); 613 return (0);
614} 614}
615 615
616/* 616/*
617 * VFS Operations. 617 * VFS Operations.
618 * 618 *
619 * mount system call 619 * mount system call
620 */ 620 */
621int 621int
622lfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len) 622lfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
623{ 623{
624 struct lwp *l = curlwp; 624 struct lwp *l = curlwp;
625 struct vnode *devvp; 625 struct vnode *devvp;
@@ -943,30 +943,30 @@ lfs_mountfs(struct vnode *devvp, struct  @@ -943,30 +943,30 @@ lfs_mountfs(struct vnode *devvp, struct
943 DLOG((DLOG_MOUNT, "lfs_mountfs: invalid alt superblock" 943 DLOG((DLOG_MOUNT, "lfs_mountfs: invalid alt superblock"
944 " daddr=0x%x\n", dfs->dlfs_sboffs[1])); 944 " daddr=0x%x\n", dfs->dlfs_sboffs[1]));
945 error = EINVAL; 945 error = EINVAL;
946 goto out; 946 goto out;
947 } 947 }
948 948
949 /* Allocate the mount structure, copy the superblock into it. */ 949 /* Allocate the mount structure, copy the superblock into it. */
950 fs = kmem_zalloc(sizeof(struct lfs), KM_SLEEP); 950 fs = kmem_zalloc(sizeof(struct lfs), KM_SLEEP);
951 memcpy(&fs->lfs_dlfs, tdfs, sizeof(struct dlfs)); 951 memcpy(&fs->lfs_dlfs, tdfs, sizeof(struct dlfs));
952 952
953 /* Compatibility */ 953 /* Compatibility */
954 if (fs->lfs_version < 2) { 954 if (fs->lfs_version < 2) {
955 fs->lfs_sumsize = LFS_V1_SUMMARY_SIZE; 955 fs->lfs_sumsize = LFS_V1_SUMMARY_SIZE;
956 fs->lfs_ibsize = fs->lfs_bsize; 956 lfs_sb_setibsize(fs, lfs_sb_getbsize(fs));
957 fs->lfs_s0addr = fs->lfs_sboffs[0]; 957 fs->lfs_s0addr = fs->lfs_sboffs[0];
958 fs->lfs_tstamp = fs->lfs_otstamp; 958 lfs_sb_settstamp(fs, lfs_sb_getotstamp(fs));
959 fs->lfs_fsbtodb = 0; 959 lfs_sb_setfsbtodb(fs, 0);
960 } 960 }
961 if (fs->lfs_resvseg == 0) 961 if (fs->lfs_resvseg == 0)
962 fs->lfs_resvseg = MIN(fs->lfs_minfreeseg - 1, \ 962 fs->lfs_resvseg = MIN(fs->lfs_minfreeseg - 1, \
963 MAX(MIN_RESV_SEGS, fs->lfs_minfreeseg / 2 + 1)); 963 MAX(MIN_RESV_SEGS, fs->lfs_minfreeseg / 2 + 1));
964 964
965 /* 965 /*
966 * If we aren't going to be able to write meaningfully to this 966 * If we aren't going to be able to write meaningfully to this
967 * filesystem, and were not mounted readonly, bomb out now. 967 * filesystem, and were not mounted readonly, bomb out now.
968 */ 968 */
969 if (lfs_fsbtob(fs, LFS_NRESERVE(fs)) > LFS_MAX_BYTES && !ronly) { 969 if (lfs_fsbtob(fs, LFS_NRESERVE(fs)) > LFS_MAX_BYTES && !ronly) {
970 DLOG((DLOG_MOUNT, "lfs_mount: to mount this filesystem read/write," 970 DLOG((DLOG_MOUNT, "lfs_mount: to mount this filesystem read/write,"
971 " we need BUFPAGES >= %lld\n", 971 " we need BUFPAGES >= %lld\n",
972 (long long)((bufmem_hiwater / bufmem_lowater) * 972 (long long)((bufmem_hiwater / bufmem_lowater) *
@@ -993,75 +993,75 @@ lfs_mountfs(struct vnode *devvp, struct  @@ -993,75 +993,75 @@ lfs_mountfs(struct vnode *devvp, struct
993 } else { 993 } else {
994 brelse(bp, 0); 994 brelse(bp, 0);
995 brelse(abp, 0); 995 brelse(abp, 0);
996 } 996 }
997 bp = NULL; 997 bp = NULL;
998 abp = NULL; 998 abp = NULL;
999 999
1000 1000
1001 /* Set up the I/O information */ 1001 /* Set up the I/O information */
1002 fs->lfs_devbsize = DEV_BSIZE; 1002 fs->lfs_devbsize = DEV_BSIZE;
1003 fs->lfs_iocount = 0; 1003 fs->lfs_iocount = 0;
1004 fs->lfs_diropwait = 0; 1004 fs->lfs_diropwait = 0;
1005 fs->lfs_activesb = 0; 1005 fs->lfs_activesb = 0;
1006 fs->lfs_uinodes = 0; 1006 lfs_sb_setuinodes(fs, 0);
1007 fs->lfs_ravail = 0; 1007 fs->lfs_ravail = 0;
1008 fs->lfs_favail = 0; 1008 fs->lfs_favail = 0;
1009 fs->lfs_sbactive = 0; 1009 fs->lfs_sbactive = 0;
1010 1010
1011 /* Set up the ifile and lock aflags */ 1011 /* Set up the ifile and lock aflags */
1012 fs->lfs_doifile = 0; 1012 fs->lfs_doifile = 0;
1013 fs->lfs_writer = 0; 1013 fs->lfs_writer = 0;
1014 fs->lfs_dirops = 0; 1014 fs->lfs_dirops = 0;
1015 fs->lfs_nadirop = 0; 1015 fs->lfs_nadirop = 0;
1016 fs->lfs_seglock = 0; 1016 fs->lfs_seglock = 0;
1017 fs->lfs_pdflush = 0; 1017 fs->lfs_pdflush = 0;
1018 fs->lfs_sleepers = 0; 1018 fs->lfs_sleepers = 0;
1019 fs->lfs_pages = 0; 1019 fs->lfs_pages = 0;
1020 rw_init(&fs->lfs_fraglock); 1020 rw_init(&fs->lfs_fraglock);
1021 rw_init(&fs->lfs_iflock); 1021 rw_init(&fs->lfs_iflock);
1022 cv_init(&fs->lfs_stopcv, "lfsstop"); 1022 cv_init(&fs->lfs_stopcv, "lfsstop");
1023 1023
1024 /* Set the file system readonly/modify bits. */ 1024 /* Set the file system readonly/modify bits. */
1025 fs->lfs_ronly = ronly; 1025 fs->lfs_ronly = ronly;
1026 if (ronly == 0) 1026 if (ronly == 0)
1027 fs->lfs_fmod = 1; 1027 fs->lfs_fmod = 1;
1028 1028
1029 /* ulfs-level information */ 1029 /* ulfs-level information */
1030 fs->um_flags = 0; 1030 fs->um_flags = 0;
1031 fs->um_bptrtodb = fs->lfs_ffshift - DEV_BSHIFT; 1031 fs->um_bptrtodb = fs->lfs_ffshift - DEV_BSHIFT;
1032 fs->um_seqinc = fs->lfs_frag; 1032 fs->um_seqinc = lfs_sb_getfrag(fs);
1033 fs->um_nindir = fs->lfs_nindir; 1033 fs->um_nindir = fs->lfs_nindir;
1034 fs->um_lognindir = ffs(fs->lfs_nindir) - 1; 1034 fs->um_lognindir = ffs(fs->lfs_nindir) - 1;
1035 fs->um_maxsymlinklen = fs->lfs_maxsymlinklen; 1035 fs->um_maxsymlinklen = fs->lfs_maxsymlinklen;
1036 fs->um_dirblksiz = LFS_DIRBLKSIZ; 1036 fs->um_dirblksiz = LFS_DIRBLKSIZ;
1037 fs->um_maxfilesize = fs->lfs_maxfilesize; 1037 fs->um_maxfilesize = fs->lfs_maxfilesize;
1038 1038
1039 /* quota stuff */ 1039 /* quota stuff */
1040 /* XXX: these need to come from the on-disk superblock to be used */ 1040 /* XXX: these need to come from the on-disk superblock to be used */
1041 fs->lfs_use_quota2 = 0; 1041 fs->lfs_use_quota2 = 0;
1042 fs->lfs_quota_magic = 0; 1042 fs->lfs_quota_magic = 0;
1043 fs->lfs_quota_flags = 0; 1043 fs->lfs_quota_flags = 0;
1044 fs->lfs_quotaino[0] = 0; 1044 fs->lfs_quotaino[0] = 0;
1045 fs->lfs_quotaino[1] = 0; 1045 fs->lfs_quotaino[1] = 0;
1046 1046
1047 /* Initialize the mount structure. */ 1047 /* Initialize the mount structure. */
1048 dev = devvp->v_rdev; 1048 dev = devvp->v_rdev;
1049 mp->mnt_data = ump; 1049 mp->mnt_data = ump;
1050 mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)dev; 1050 mp->mnt_stat.f_fsidx.__fsid_val[0] = (long)dev;
1051 mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_LFS); 1051 mp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_LFS);
1052 mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0]; 1052 mp->mnt_stat.f_fsid = mp->mnt_stat.f_fsidx.__fsid_val[0];
1053 mp->mnt_stat.f_namemax = LFS_MAXNAMLEN; 1053 mp->mnt_stat.f_namemax = LFS_MAXNAMLEN;
1054 mp->mnt_stat.f_iosize = fs->lfs_bsize; 1054 mp->mnt_stat.f_iosize = lfs_sb_getbsize(fs);
1055 mp->mnt_flag |= MNT_LOCAL; 1055 mp->mnt_flag |= MNT_LOCAL;
1056 mp->mnt_fs_bshift = fs->lfs_bshift; 1056 mp->mnt_fs_bshift = fs->lfs_bshift;
1057 if (fs->um_maxsymlinklen > 0) 1057 if (fs->um_maxsymlinklen > 0)
1058 mp->mnt_iflag |= IMNT_DTYPE; 1058 mp->mnt_iflag |= IMNT_DTYPE;
1059 1059
1060 ump->um_mountp = mp; 1060 ump->um_mountp = mp;
1061 ump->um_dev = dev; 1061 ump->um_dev = dev;
1062 ump->um_devvp = devvp; 1062 ump->um_devvp = devvp;
1063 for (i = 0; i < ULFS_MAXQUOTAS; i++) 1063 for (i = 0; i < ULFS_MAXQUOTAS; i++)
1064 ump->um_quotas[i] = NULLVP; 1064 ump->um_quotas[i] = NULLVP;
1065 spec_node_setmountedfs(devvp, mp); 1065 spec_node_setmountedfs(devvp, mp);
1066 1066
1067 /* Set up reserved memory for pageout */ 1067 /* Set up reserved memory for pageout */
@@ -1187,40 +1187,40 @@ lfs_mountfs(struct vnode *devvp, struct  @@ -1187,40 +1187,40 @@ lfs_mountfs(struct vnode *devvp, struct
1187 lfs_writesuper(fs, fs->lfs_sboffs[0]); 1187 lfs_writesuper(fs, fs->lfs_sboffs[0]);
1188 lfs_writesuper(fs, fs->lfs_sboffs[1]); 1188 lfs_writesuper(fs, fs->lfs_sboffs[1]);
1189 } 1189 }
1190 1190
1191 /* Allow vget now that roll-forward is complete */ 1191 /* Allow vget now that roll-forward is complete */
1192 fs->lfs_flags &= ~(LFS_NOTYET); 1192 fs->lfs_flags &= ~(LFS_NOTYET);
1193 wakeup(&fs->lfs_flags); 1193 wakeup(&fs->lfs_flags);
1194 1194
1195 /* 1195 /*
1196 * Initialize the ifile cleaner info with information from 1196 * Initialize the ifile cleaner info with information from
1197 * the superblock. 1197 * the superblock.
1198 */ 1198 */
1199 LFS_CLEANERINFO(cip, fs, bp); 1199 LFS_CLEANERINFO(cip, fs, bp);
1200 cip->clean = fs->lfs_nclean; 1200 cip->clean = lfs_sb_getnclean(fs);
1201 cip->dirty = fs->lfs_nseg - fs->lfs_nclean; 1201 cip->dirty = lfs_sb_getnseg(fs) - lfs_sb_getnclean(fs);
1202 cip->avail = fs->lfs_avail; 1202 cip->avail = lfs_sb_getavail(fs);
1203 cip->bfree = fs->lfs_bfree; 1203 cip->bfree = lfs_sb_getbfree(fs);
1204 (void) LFS_BWRITE_LOG(bp); /* Ifile */ 1204 (void) LFS_BWRITE_LOG(bp); /* Ifile */
1205 1205
1206 /* 1206 /*
1207 * Mark the current segment as ACTIVE, since we're going to 1207 * Mark the current segment as ACTIVE, since we're going to
1208 * be writing to it. 1208 * be writing to it.
1209 */ 1209 */
1210 LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, fs->lfs_offset), bp); 1210 LFS_SEGENTRY(sup, fs, lfs_dtosn(fs, lfs_sb_getoffset(fs)), bp);
1211 sup->su_flags |= SEGUSE_DIRTY | SEGUSE_ACTIVE; 1211 sup->su_flags |= SEGUSE_DIRTY | SEGUSE_ACTIVE;
1212 fs->lfs_nactive++; 1212 fs->lfs_nactive++;
1213 LFS_WRITESEGENTRY(sup, fs, lfs_dtosn(fs, fs->lfs_offset), bp); /* Ifile */ 1213 LFS_WRITESEGENTRY(sup, fs, lfs_dtosn(fs, lfs_sb_getoffset(fs)), bp); /* Ifile */
1214 1214
1215 /* Now that roll-forward is done, unlock the Ifile */ 1215 /* Now that roll-forward is done, unlock the Ifile */
1216 vput(vp); 1216 vput(vp);
1217 1217
1218 /* Start the pagedaemon-anticipating daemon */ 1218 /* Start the pagedaemon-anticipating daemon */
1219 mutex_enter(&lfs_lock); 1219 mutex_enter(&lfs_lock);
1220 if (lfs_writer_daemon == 0 && lfs_writer_lid == 0 && 1220 if (lfs_writer_daemon == 0 && lfs_writer_lid == 0 &&
1221 kthread_create(PRI_BIO, 0, NULL, 1221 kthread_create(PRI_BIO, 0, NULL,
1222 lfs_writerd, NULL, NULL, "lfs_writer") != 0) 1222 lfs_writerd, NULL, NULL, "lfs_writer") != 0)
1223 panic("fork lfs_writer"); 1223 panic("fork lfs_writer");
1224 mutex_exit(&lfs_lock); 1224 mutex_exit(&lfs_lock);
1225 1225
1226 printf("WARNING: the log-structured file system is experimental\n" 1226 printf("WARNING: the log-structured file system is experimental\n"
@@ -1353,47 +1353,47 @@ lfs_unmount(struct mount *mp, int mntfla @@ -1353,47 +1353,47 @@ lfs_unmount(struct mount *mp, int mntfla
1353 * really that important if we get it wrong. 1353 * really that important if we get it wrong.
1354 */ 1354 */
1355int 1355int
1356lfs_statvfs(struct mount *mp, struct statvfs *sbp) 1356lfs_statvfs(struct mount *mp, struct statvfs *sbp)
1357{ 1357{
1358 struct lfs *fs; 1358 struct lfs *fs;
1359 struct ulfsmount *ump; 1359 struct ulfsmount *ump;
1360 1360
1361 ump = VFSTOULFS(mp); 1361 ump = VFSTOULFS(mp);
1362 fs = ump->um_lfs; 1362 fs = ump->um_lfs;
1363 if (fs->lfs_magic != LFS_MAGIC) 1363 if (fs->lfs_magic != LFS_MAGIC)
1364 panic("lfs_statvfs: magic"); 1364 panic("lfs_statvfs: magic");
1365 1365
1366 sbp->f_bsize = fs->lfs_bsize; 1366 sbp->f_bsize = lfs_sb_getbsize(fs);
1367 sbp->f_frsize = fs->lfs_fsize; 1367 sbp->f_frsize = lfs_sb_getfsize(fs);
1368 sbp->f_iosize = fs->lfs_bsize; 1368 sbp->f_iosize = lfs_sb_getbsize(fs);
1369 sbp->f_blocks = LFS_EST_NONMETA(fs) - VTOI(fs->lfs_ivnode)->i_lfs_effnblks; 1369 sbp->f_blocks = LFS_EST_NONMETA(fs) - VTOI(fs->lfs_ivnode)->i_lfs_effnblks;
1370 1370
1371 sbp->f_bfree = LFS_EST_BFREE(fs); 1371 sbp->f_bfree = LFS_EST_BFREE(fs);
1372 KASSERT(sbp->f_bfree <= fs->lfs_dsize); 1372 KASSERT(sbp->f_bfree <= lfs_sb_getdsize(fs));
1373#if 0 1373#if 0
1374 if (sbp->f_bfree < 0) 1374 if (sbp->f_bfree < 0)
1375 sbp->f_bfree = 0; 1375 sbp->f_bfree = 0;
1376#endif 1376#endif
1377 1377
1378 sbp->f_bresvd = LFS_EST_RSVD(fs); 1378 sbp->f_bresvd = LFS_EST_RSVD(fs);
1379 if (sbp->f_bfree > sbp->f_bresvd) 1379 if (sbp->f_bfree > sbp->f_bresvd)
1380 sbp->f_bavail = sbp->f_bfree - sbp->f_bresvd; 1380 sbp->f_bavail = sbp->f_bfree - sbp->f_bresvd;
1381 else 1381 else
1382 sbp->f_bavail = 0; 1382 sbp->f_bavail = 0;
1383 1383
1384 sbp->f_files = fs->lfs_bfree / lfs_btofsb(fs, fs->lfs_ibsize) 1384 sbp->f_files = lfs_sb_getbfree(fs) / lfs_btofsb(fs, lfs_sb_getibsize(fs))
1385 * LFS_INOPB(fs); 1385 * LFS_INOPB(fs);
1386 sbp->f_ffree = sbp->f_files - fs->lfs_nfiles; 1386 sbp->f_ffree = sbp->f_files - lfs_sb_getnfiles(fs);
1387 sbp->f_favail = sbp->f_ffree; 1387 sbp->f_favail = sbp->f_ffree;
1388 sbp->f_fresvd = 0; 1388 sbp->f_fresvd = 0;
1389 copy_statvfs_info(sbp, mp); 1389 copy_statvfs_info(sbp, mp);
1390 return (0); 1390 return (0);
1391} 1391}
1392 1392
1393/* 1393/*
1394 * Go through the disk queues to initiate sandbagged IO; 1394 * Go through the disk queues to initiate sandbagged IO;
1395 * go through the inodes to write those that have been modified; 1395 * go through the inodes to write those that have been modified;
1396 * initiate the writing of the super block if it has been modified. 1396 * initiate the writing of the super block if it has been modified.
1397 * 1397 *
1398 * Note: we are always called with the filesystem marked `MPBUSY'. 1398 * Note: we are always called with the filesystem marked `MPBUSY'.
1399 */ 1399 */
@@ -1405,36 +1405,37 @@ lfs_sync(struct mount *mp, int waitfor,  @@ -1405,36 +1405,37 @@ lfs_sync(struct mount *mp, int waitfor,
1405 1405
1406 fs = VFSTOULFS(mp)->um_lfs; 1406 fs = VFSTOULFS(mp)->um_lfs;
1407 if (fs->lfs_ronly) 1407 if (fs->lfs_ronly)
1408 return 0; 1408 return 0;
1409 1409
1410 /* Snapshots should not hose the syncer */ 1410 /* Snapshots should not hose the syncer */
1411 /* 1411 /*
1412 * XXX Sync can block here anyway, since we don't have a very 1412 * XXX Sync can block here anyway, since we don't have a very
1413 * XXX good idea of how much data is pending. If it's more 1413 * XXX good idea of how much data is pending. If it's more
1414 * XXX than a segment and lfs_nextseg is close to the end of 1414 * XXX than a segment and lfs_nextseg is close to the end of
1415 * XXX the log, we'll likely block. 1415 * XXX the log, we'll likely block.
1416 */ 1416 */
1417 mutex_enter(&lfs_lock); 1417 mutex_enter(&lfs_lock);
1418 if (fs->lfs_nowrap && fs->lfs_nextseg < fs->lfs_curseg) { 1418 if (fs->lfs_nowrap && lfs_sb_getnextseg(fs) < lfs_sb_getcurseg(fs)) {
1419 mutex_exit(&lfs_lock); 1419 mutex_exit(&lfs_lock);
1420 return 0; 1420 return 0;
1421 } 1421 }
1422 mutex_exit(&lfs_lock); 1422 mutex_exit(&lfs_lock);
1423 1423
1424 lfs_writer_enter(fs, "lfs_dirops"); 1424 lfs_writer_enter(fs, "lfs_dirops");
1425 1425
1426 /* All syncs must be checkpoints until roll-forward is implemented. */ 1426 /* All syncs must be checkpoints until roll-forward is implemented. */
1427 DLOG((DLOG_FLUSH, "lfs_sync at 0x%x\n", fs->lfs_offset)); 1427 DLOG((DLOG_FLUSH, "lfs_sync at 0x%jx\n",
 1428 (uintmax_t)lfs_sb_getoffset(fs)));
1428 error = lfs_segwrite(mp, SEGM_CKP | (waitfor ? SEGM_SYNC : 0)); 1429 error = lfs_segwrite(mp, SEGM_CKP | (waitfor ? SEGM_SYNC : 0));
1429 lfs_writer_leave(fs); 1430 lfs_writer_leave(fs);
1430#ifdef LFS_QUOTA 1431#ifdef LFS_QUOTA
1431 lfs_qsync(mp); 1432 lfs_qsync(mp);
1432#endif 1433#endif
1433 return (error); 1434 return (error);
1434} 1435}
1435 1436
1436/* 1437/*
1437 * Look up an LFS dinode number to find its incore vnode. If not already 1438 * Look up an LFS dinode number to find its incore vnode. If not already
1438 * in core, read it in from the specified device. Return the inode locked. 1439 * in core, read it in from the specified device. Return the inode locked.
1439 * Detection and handling of mount points must be done by the calling routine. 1440 * Detection and handling of mount points must be done by the calling routine.
1440 */ 1441 */
@@ -1533,27 +1534,27 @@ lfs_loadvnode(struct mount *mp, struct v @@ -1533,27 +1534,27 @@ lfs_loadvnode(struct mount *mp, struct v
1533 1534
1534 /* 1535 /*
1535 * If the filesystem is not completely mounted yet, suspend 1536 * If the filesystem is not completely mounted yet, suspend
1536 * any access requests (wait for roll-forward to complete). 1537 * any access requests (wait for roll-forward to complete).
1537 */ 1538 */
1538 mutex_enter(&lfs_lock); 1539 mutex_enter(&lfs_lock);
1539 while ((fs->lfs_flags & LFS_NOTYET) && curproc->p_pid != fs->lfs_rfpid) 1540 while ((fs->lfs_flags & LFS_NOTYET) && curproc->p_pid != fs->lfs_rfpid)
1540 mtsleep(&fs->lfs_flags, PRIBIO+1, "lfs_notyet", 0, 1541 mtsleep(&fs->lfs_flags, PRIBIO+1, "lfs_notyet", 0,
1541 &lfs_lock); 1542 &lfs_lock);
1542 mutex_exit(&lfs_lock); 1543 mutex_exit(&lfs_lock);
1543 1544
1544 /* Translate the inode number to a disk address. */ 1545 /* Translate the inode number to a disk address. */
1545 if (ino == LFS_IFILE_INUM) 1546 if (ino == LFS_IFILE_INUM)
1546 daddr = fs->lfs_idaddr; 1547 daddr = lfs_sb_getidaddr(fs);
1547 else { 1548 else {
1548 /* XXX bounds-check this too */ 1549 /* XXX bounds-check this too */
1549 LFS_IENTRY(ifp, fs, ino, bp); 1550 LFS_IENTRY(ifp, fs, ino, bp);
1550 daddr = ifp->if_daddr; 1551 daddr = ifp->if_daddr;
1551 if (fs->lfs_version > 1) { 1552 if (fs->lfs_version > 1) {
1552 ts.tv_sec = ifp->if_atime_sec; 1553 ts.tv_sec = ifp->if_atime_sec;
1553 ts.tv_nsec = ifp->if_atime_nsec; 1554 ts.tv_nsec = ifp->if_atime_nsec;
1554 } 1555 }
1555 1556
1556 brelse(bp, 0); 1557 brelse(bp, 0);
1557 if (daddr == LFS_UNUSED_DADDR) 1558 if (daddr == LFS_UNUSED_DADDR)
1558 return (ENOENT); 1559 return (ENOENT);
1559 } 1560 }
@@ -1570,27 +1571,27 @@ lfs_loadvnode(struct mount *mp, struct v @@ -1570,27 +1571,27 @@ lfs_loadvnode(struct mount *mp, struct v
1570 sizeof(struct ulfs1_dinode)); 1571 sizeof(struct ulfs1_dinode));
1571 if (error) { 1572 if (error) {
1572 lfs_deinit_vnode(ump, vp); 1573 lfs_deinit_vnode(ump, vp);
1573 return error; 1574 return error;
1574 } 1575 }
1575 KASSERT(ip->i_number == ino); 1576 KASSERT(ip->i_number == ino);
1576 goto out; 1577 goto out;
1577 } 1578 }
1578 1579
1579 /* Read in the disk contents for the inode, copy into the inode. */ 1580 /* Read in the disk contents for the inode, copy into the inode. */
1580 retries = 0; 1581 retries = 0;
1581again: 1582again:
1582 error = bread(ump->um_devvp, LFS_FSBTODB(fs, daddr), 1583 error = bread(ump->um_devvp, LFS_FSBTODB(fs, daddr),
1583 (fs->lfs_version == 1 ? fs->lfs_bsize : fs->lfs_ibsize), 1584 (fs->lfs_version == 1 ? lfs_sb_getbsize(fs) : fs->lfs_ibsize),
1584 0, &bp); 1585 0, &bp);
1585 if (error) { 1586 if (error) {
1586 lfs_deinit_vnode(ump, vp); 1587 lfs_deinit_vnode(ump, vp);
1587 return error; 1588 return error;
1588 } 1589 }
1589 1590
1590 dip = lfs_ifind(fs, ino, bp); 1591 dip = lfs_ifind(fs, ino, bp);
1591 if (dip == NULL) { 1592 if (dip == NULL) {
1592 /* Assume write has not completed yet; try again */ 1593 /* Assume write has not completed yet; try again */
1593 brelse(bp, BC_INVAL); 1594 brelse(bp, BC_INVAL);
1594 ++retries; 1595 ++retries;
1595 if (retries <= LFS_IFIND_RETRIES) { 1596 if (retries <= LFS_IFIND_RETRIES) {
1596 mutex_enter(&lfs_lock); 1597 mutex_enter(&lfs_lock);
@@ -1761,27 +1762,27 @@ lfs_fhtovp(struct mount *mp, struct fid  @@ -1761,27 +1762,27 @@ lfs_fhtovp(struct mount *mp, struct fid
1761 if (fhp->fid_len != sizeof(struct lfid)) 1762 if (fhp->fid_len != sizeof(struct lfid))
1762 return EINVAL; 1763 return EINVAL;
1763 1764
1764 memcpy(&lfh, fhp, sizeof(lfh)); 1765 memcpy(&lfh, fhp, sizeof(lfh));
1765 if (lfh.lfid_ino < LFS_IFILE_INUM) 1766 if (lfh.lfid_ino < LFS_IFILE_INUM)
1766 return ESTALE; 1767 return ESTALE;
1767 1768
1768 fs = VFSTOULFS(mp)->um_lfs; 1769 fs = VFSTOULFS(mp)->um_lfs;
1769 if (lfh.lfid_ident != fs->lfs_ident) 1770 if (lfh.lfid_ident != fs->lfs_ident)
1770 return ESTALE; 1771 return ESTALE;
1771 1772
1772 if (lfh.lfid_ino > 1773 if (lfh.lfid_ino >
1773 ((VTOI(fs->lfs_ivnode)->i_ffs1_size >> fs->lfs_bshift) - 1774 ((VTOI(fs->lfs_ivnode)->i_ffs1_size >> fs->lfs_bshift) -
1774 fs->lfs_cleansz - fs->lfs_segtabsz) * fs->lfs_ifpb) 1775 lfs_sb_getcleansz(fs) - lfs_sb_getsegtabsz(fs)) * lfs_sb_getifpb(fs))
1775 return ESTALE; 1776 return ESTALE;
1776 1777
1777 return (ulfs_fhtovp(mp, &lfh.lfid_ufid, vpp)); 1778 return (ulfs_fhtovp(mp, &lfh.lfid_ufid, vpp));
1778} 1779}
1779 1780
1780/* 1781/*
1781 * Vnode pointer to File handle 1782 * Vnode pointer to File handle
1782 */ 1783 */
1783/* ARGSUSED */ 1784/* ARGSUSED */
1784int 1785int
1785lfs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size) 1786lfs_vptofh(struct vnode *vp, struct fid *fhp, size_t *fh_size)
1786{ 1787{
1787 struct inode *ip; 1788 struct inode *ip;
@@ -1977,29 +1978,29 @@ lfs_gop_write(struct vnode *vp, struct v @@ -1977,29 +1978,29 @@ lfs_gop_write(struct vnode *vp, struct v
1977 panic("lfs_gop_write: non-integer blocks"); 1978 panic("lfs_gop_write: non-integer blocks");
1978 } 1979 }
1979 1980
1980 /* 1981 /*
1981 * We could deadlock here on pager_map with UVMPAGER_MAPIN_WAITOK. 1982 * We could deadlock here on pager_map with UVMPAGER_MAPIN_WAITOK.
1982 * If we would, write what we have and try again. If we don't 1983 * If we would, write what we have and try again. If we don't
1983 * have anything to write, we'll have to sleep. 1984 * have anything to write, we'll have to sleep.
1984 */ 1985 */
1985 if ((kva = uvm_pagermapin(pgs, npages, UVMPAGER_MAPIN_WRITE | 1986 if ((kva = uvm_pagermapin(pgs, npages, UVMPAGER_MAPIN_WRITE |
1986 (((SEGSUM *)(sp->segsum))->ss_nfinfo < 1 ? 1987 (((SEGSUM *)(sp->segsum))->ss_nfinfo < 1 ?
1987 UVMPAGER_MAPIN_WAITOK : 0))) == 0x0) { 1988 UVMPAGER_MAPIN_WAITOK : 0))) == 0x0) {
1988 DLOG((DLOG_PAGE, "lfs_gop_write: forcing write\n")); 1989 DLOG((DLOG_PAGE, "lfs_gop_write: forcing write\n"));
1989#if 0 1990#if 0
1990 " with nfinfo=%d at offset 0x%x\n", 1991 " with nfinfo=%d at offset 0x%jx\n",
1991 (int)((SEGSUM *)(sp->segsum))->ss_nfinfo, 1992 (int)((SEGSUM *)(sp->segsum))->ss_nfinfo,
1992 (unsigned)fs->lfs_offset)); 1993 (uintmax_t)lfs_sb_getoffset(fs)));
1993#endif 1994#endif
1994 lfs_updatemeta(sp); 1995 lfs_updatemeta(sp);
1995 lfs_release_finfo(fs); 1996 lfs_release_finfo(fs);
1996 (void) lfs_writeseg(fs, sp); 1997 (void) lfs_writeseg(fs, sp);
1997 1998
1998 lfs_acquire_finfo(fs, ip->i_number, ip->i_gen); 1999 lfs_acquire_finfo(fs, ip->i_number, ip->i_gen);
1999 2000
2000 /* 2001 /*
2001 * Having given up all of the pager_map we were holding, 2002 * Having given up all of the pager_map we were holding,
2002 * we can now wait for aiodoned to reclaim it for us 2003 * we can now wait for aiodoned to reclaim it for us
2003 * without fear of deadlock. 2004 * without fear of deadlock.
2004 */ 2005 */
2005 kva = uvm_pagermapin(pgs, npages, UVMPAGER_MAPIN_WRITE | 2006 kva = uvm_pagermapin(pgs, npages, UVMPAGER_MAPIN_WRITE |
@@ -2106,27 +2107,27 @@ lfs_gop_write(struct vnode *vp, struct v @@ -2106,27 +2107,27 @@ lfs_gop_write(struct vnode *vp, struct v
2106 if (skipbytes) { 2107 if (skipbytes) {
2107 UVMHIST_LOG(ubchist, "skipbytes %d", skipbytes, 0,0,0); 2108 UVMHIST_LOG(ubchist, "skipbytes %d", skipbytes, 0,0,0);
2108 } 2109 }
2109 UVMHIST_LOG(ubchist, "returning 0", 0,0,0,0); 2110 UVMHIST_LOG(ubchist, "returning 0", 0,0,0,0);
2110 2111
2111 if (!async) { 2112 if (!async) {
2112 /* Start a segment write. */ 2113 /* Start a segment write. */
2113 UVMHIST_LOG(ubchist, "flushing", 0,0,0,0); 2114 UVMHIST_LOG(ubchist, "flushing", 0,0,0,0);
2114 mutex_enter(&lfs_lock); 2115 mutex_enter(&lfs_lock);
2115 lfs_flush(fs, 0, 1); 2116 lfs_flush(fs, 0, 1);
2116 mutex_exit(&lfs_lock); 2117 mutex_exit(&lfs_lock);
2117 } 2118 }
2118 2119
2119 if ((sp->seg_flags & SEGM_SINGLE) && fs->lfs_curseg != fs->lfs_startseg) 2120 if ((sp->seg_flags & SEGM_SINGLE) && lfs_sb_getcurseg(fs) != fs->lfs_startseg)
2120 return EAGAIN; 2121 return EAGAIN;
2121 2122
2122 return (0); 2123 return (0);
2123 2124
2124 tryagain: 2125 tryagain:
2125 /* 2126 /*
2126 * We can't write the pages, for whatever reason. 2127 * We can't write the pages, for whatever reason.
2127 * Clean up after ourselves, and make the caller try again. 2128 * Clean up after ourselves, and make the caller try again.
2128 */ 2129 */
2129 mutex_enter(vp->v_interlock); 2130 mutex_enter(vp->v_interlock);
2130 2131
2131 /* Tell why we're here, if we know */ 2132 /* Tell why we're here, if we know */
2132 if (failreason != NULL) { 2133 if (failreason != NULL) {
@@ -2191,27 +2192,27 @@ lfs_vinit(struct mount *mp, struct vnode @@ -2191,27 +2192,27 @@ lfs_vinit(struct mount *mp, struct vnode
2191 ip->i_lfs_effnblks = ip->i_ffs1_blocks; 2192 ip->i_lfs_effnblks = ip->i_ffs1_blocks;
2192 ip->i_lfs_odnlink = ip->i_ffs1_nlink; 2193 ip->i_lfs_odnlink = ip->i_ffs1_nlink;
2193 2194
2194 /* 2195 /*
2195 * Initialize the vnode from the inode, check for aliases. In all 2196 * Initialize the vnode from the inode, check for aliases. In all
2196 * cases re-init ip, the underlying vnode/inode may have changed. 2197 * cases re-init ip, the underlying vnode/inode may have changed.
2197 */ 2198 */
2198 ulfs_vinit(mp, lfs_specop_p, lfs_fifoop_p, &vp); 2199 ulfs_vinit(mp, lfs_specop_p, lfs_fifoop_p, &vp);
2199 ip = VTOI(vp); 2200 ip = VTOI(vp);
2200 2201
2201 memset(ip->i_lfs_fragsize, 0, ULFS_NDADDR * sizeof(*ip->i_lfs_fragsize)); 2202 memset(ip->i_lfs_fragsize, 0, ULFS_NDADDR * sizeof(*ip->i_lfs_fragsize));
2202 if (vp->v_type != VLNK || ip->i_size >= ip->i_lfs->um_maxsymlinklen) { 2203 if (vp->v_type != VLNK || ip->i_size >= ip->i_lfs->um_maxsymlinklen) {
2203#ifdef DEBUG 2204#ifdef DEBUG
2204 for (i = (ip->i_size + fs->lfs_bsize - 1) >> fs->lfs_bshift; 2205 for (i = (ip->i_size + lfs_sb_getbsize(fs) - 1) >> fs->lfs_bshift;
2205 i < ULFS_NDADDR; i++) { 2206 i < ULFS_NDADDR; i++) {
2206 if ((vp->v_type == VBLK || vp->v_type == VCHR) && 2207 if ((vp->v_type == VBLK || vp->v_type == VCHR) &&
2207 i == 0) 2208 i == 0)
2208 continue; 2209 continue;
2209 if (ip->i_ffs1_db[i] != 0) { 2210 if (ip->i_ffs1_db[i] != 0) {
2210 lfs_dump_dinode(ip->i_din.ffs1_din); 2211 lfs_dump_dinode(ip->i_din.ffs1_din);
2211 panic("inconsistent inode (direct)"); 2212 panic("inconsistent inode (direct)");
2212 } 2213 }
2213 } 2214 }
2214 for ( ; i < ULFS_NDADDR + ULFS_NIADDR; i++) { 2215 for ( ; i < ULFS_NDADDR + ULFS_NIADDR; i++) {
2215 if (ip->i_ffs1_ib[i - ULFS_NDADDR] != 0) { 2216 if (ip->i_ffs1_ib[i - ULFS_NDADDR] != 0) {
2216 lfs_dump_dinode(ip->i_din.ffs1_din); 2217 lfs_dump_dinode(ip->i_din.ffs1_din);
2217 panic("inconsistent inode (indirect)"); 2218 panic("inconsistent inode (indirect)");
@@ -2237,27 +2238,27 @@ lfs_vinit(struct mount *mp, struct vnode @@ -2237,27 +2238,27 @@ lfs_vinit(struct mount *mp, struct vnode
2237 /* 2238 /*
2238 * Finish inode initialization now that aliasing has been resolved. 2239 * Finish inode initialization now that aliasing has been resolved.
2239 */ 2240 */
2240 2241
2241 ip->i_devvp = ump->um_devvp; 2242 ip->i_devvp = ump->um_devvp;
2242 vref(ip->i_devvp); 2243 vref(ip->i_devvp);
2243#if defined(LFS_QUOTA) || defined(LFS_QUOTA2) 2244#if defined(LFS_QUOTA) || defined(LFS_QUOTA2)
2244 ulfsquota_init(ip); 2245 ulfsquota_init(ip);
2245#endif 2246#endif
2246 genfs_node_init(vp, &lfs_genfsops); 2247 genfs_node_init(vp, &lfs_genfsops);
2247 uvm_vnp_setsize(vp, ip->i_size); 2248 uvm_vnp_setsize(vp, ip->i_size);
2248 2249
2249 /* Initialize hiblk from file size */ 2250 /* Initialize hiblk from file size */
2250 ip->i_lfs_hiblk = lfs_lblkno(ip->i_lfs, ip->i_size + ip->i_lfs->lfs_bsize - 1) - 1; 2251 ip->i_lfs_hiblk = lfs_lblkno(ip->i_lfs, ip->i_size + lfs_sb_getbsize(ip->i_lfs) - 1) - 1;
2251 2252
2252 *vpp = vp; 2253 *vpp = vp;
2253} 2254}
2254 2255
2255/* 2256/*
2256 * Resize the filesystem to contain the specified number of segments. 2257 * Resize the filesystem to contain the specified number of segments.
2257 */ 2258 */
2258int 2259int
2259lfs_resize_fs(struct lfs *fs, int newnsegs) 2260lfs_resize_fs(struct lfs *fs, int newnsegs)
2260{ 2261{
2261 SEGUSE *sup; 2262 SEGUSE *sup;
2262 struct buf *bp, *obp; 2263 struct buf *bp, *obp;
2263 daddr_t olast, nlast, ilast, noff, start, end; 2264 daddr_t olast, nlast, ilast, noff, start, end;
@@ -2303,91 +2304,91 @@ lfs_resize_fs(struct lfs *fs, int newnse @@ -2303,91 +2304,91 @@ lfs_resize_fs(struct lfs *fs, int newnse
2303 if (!(sup->su_flags & SEGUSE_DIRTY)) { 2304 if (!(sup->su_flags & SEGUSE_DIRTY)) {
2304 ++cgain; 2305 ++cgain;
2305 if (sup->su_flags & SEGUSE_SUPERBLOCK) 2306 if (sup->su_flags & SEGUSE_SUPERBLOCK)
2306 csbbytes += LFS_SBPAD; 2307 csbbytes += LFS_SBPAD;
2307 } 2308 }
2308 brelse(bp, 0); 2309 brelse(bp, 0);
2309 if (badnews) { 2310 if (badnews) {
2310 error = EBUSY; 2311 error = EBUSY;
2311 goto out; 2312 goto out;
2312 } 2313 }
2313 } 2314 }
2314 2315
2315 /* Note old and new segment table endpoints, and old ifile size */ 2316 /* Note old and new segment table endpoints, and old ifile size */
2316 olast = fs->lfs_cleansz + fs->lfs_segtabsz; 2317 olast = lfs_sb_getcleansz(fs) + lfs_sb_getsegtabsz(fs);
2317 nlast = howmany(newnsegs, fs->lfs_sepb) + fs->lfs_cleansz; 2318 nlast = howmany(newnsegs, lfs_sb_getsepb(fs)) + lfs_sb_getcleansz(fs);
2318 ilast = ivp->v_size >> fs->lfs_bshift; 2319 ilast = ivp->v_size >> fs->lfs_bshift;
2319 noff = nlast - olast; 2320 noff = nlast - olast;
2320 2321
2321 /* 2322 /*
2322 * Make sure no one can use the Ifile while we change it around. 2323 * Make sure no one can use the Ifile while we change it around.
2323 * Even after taking the iflock we need to make sure no one still 2324 * Even after taking the iflock we need to make sure no one still
2324 * is holding Ifile buffers, so we get each one, to drain them. 2325 * is holding Ifile buffers, so we get each one, to drain them.
2325 * (XXX this could be done better.) 2326 * (XXX this could be done better.)
2326 */ 2327 */
2327 rw_enter(&fs->lfs_iflock, RW_WRITER); 2328 rw_enter(&fs->lfs_iflock, RW_WRITER);
2328 for (i = 0; i < ilast; i++) { 2329 for (i = 0; i < ilast; i++) {
2329 /* XXX what to do if bread fails? */ 2330 /* XXX what to do if bread fails? */
2330 bread(ivp, i, fs->lfs_bsize, 0, &bp); 2331 bread(ivp, i, lfs_sb_getbsize(fs), 0, &bp);
2331 brelse(bp, 0); 2332 brelse(bp, 0);
2332 } 2333 }
2333 2334
2334 /* Allocate new Ifile blocks */ 2335 /* Allocate new Ifile blocks */
2335 for (i = ilast; i < ilast + noff; i++) { 2336 for (i = ilast; i < ilast + noff; i++) {
2336 if (lfs_balloc(ivp, i * fs->lfs_bsize, fs->lfs_bsize, NOCRED, 0, 2337 if (lfs_balloc(ivp, i * lfs_sb_getbsize(fs), lfs_sb_getbsize(fs), NOCRED, 0,
2337 &bp) != 0) 2338 &bp) != 0)
2338 panic("balloc extending ifile"); 2339 panic("balloc extending ifile");
2339 memset(bp->b_data, 0, fs->lfs_bsize); 2340 memset(bp->b_data, 0, lfs_sb_getbsize(fs));
2340 VOP_BWRITE(bp->b_vp, bp); 2341 VOP_BWRITE(bp->b_vp, bp);
2341 } 2342 }
2342 2343
2343 /* Register new ifile size */ 2344 /* Register new ifile size */
2344 ip->i_size += noff * fs->lfs_bsize;  2345 ip->i_size += noff * lfs_sb_getbsize(fs);
2345 ip->i_ffs1_size = ip->i_size; 2346 ip->i_ffs1_size = ip->i_size;
2346 uvm_vnp_setsize(ivp, ip->i_size); 2347 uvm_vnp_setsize(ivp, ip->i_size);
2347 2348
2348 /* Copy the inode table to its new position */ 2349 /* Copy the inode table to its new position */
2349 if (noff != 0) { 2350 if (noff != 0) {
2350 if (noff < 0) { 2351 if (noff < 0) {
2351 start = nlast; 2352 start = nlast;
2352 end = ilast + noff; 2353 end = ilast + noff;
2353 inc = 1; 2354 inc = 1;
2354 } else { 2355 } else {
2355 start = ilast + noff - 1; 2356 start = ilast + noff - 1;
2356 end = nlast - 1; 2357 end = nlast - 1;
2357 inc = -1; 2358 inc = -1;
2358 } 2359 }
2359 for (i = start; i != end; i += inc) { 2360 for (i = start; i != end; i += inc) {
2360 if (bread(ivp, i, fs->lfs_bsize, 2361 if (bread(ivp, i, lfs_sb_getbsize(fs),
2361 B_MODIFY, &bp) != 0) 2362 B_MODIFY, &bp) != 0)
2362 panic("resize: bread dst blk failed"); 2363 panic("resize: bread dst blk failed");
2363 if (bread(ivp, i - noff, fs->lfs_bsize, 2364 if (bread(ivp, i - noff, lfs_sb_getbsize(fs),
2364 0, &obp)) 2365 0, &obp))
2365 panic("resize: bread src blk failed"); 2366 panic("resize: bread src blk failed");
2366 memcpy(bp->b_data, obp->b_data, fs->lfs_bsize); 2367 memcpy(bp->b_data, obp->b_data, lfs_sb_getbsize(fs));
2367 VOP_BWRITE(bp->b_vp, bp); 2368 VOP_BWRITE(bp->b_vp, bp);
2368 brelse(obp, 0); 2369 brelse(obp, 0);
2369 } 2370 }
2370 } 2371 }
2371 2372
2372 /* If we are expanding, write the new empty SEGUSE entries */ 2373 /* If we are expanding, write the new empty SEGUSE entries */
2373 if (newnsegs > oldnsegs) { 2374 if (newnsegs > oldnsegs) {
2374 for (i = oldnsegs; i < newnsegs; i++) { 2375 for (i = oldnsegs; i < newnsegs; i++) {
2375 if ((error = bread(ivp, i / fs->lfs_sepb + 2376 if ((error = bread(ivp, i / lfs_sb_getsepb(fs) +
2376 fs->lfs_cleansz, fs->lfs_bsize, 2377 lfs_sb_getcleansz(fs), lfs_sb_getbsize(fs),
2377 B_MODIFY, &bp)) != 0) 2378 B_MODIFY, &bp)) != 0)
2378 panic("lfs: ifile read: %d", error); 2379 panic("lfs: ifile read: %d", error);
2379 while ((i + 1) % fs->lfs_sepb && i < newnsegs) { 2380 while ((i + 1) % lfs_sb_getsepb(fs) && i < newnsegs) {
2380 sup = &((SEGUSE *)bp->b_data)[i % fs->lfs_sepb]; 2381 sup = &((SEGUSE *)bp->b_data)[i % lfs_sb_getsepb(fs)];
2381 memset(sup, 0, sizeof(*sup)); 2382 memset(sup, 0, sizeof(*sup));
2382 i++; 2383 i++;
2383 } 2384 }
2384 VOP_BWRITE(bp->b_vp, bp); 2385 VOP_BWRITE(bp->b_vp, bp);
2385 } 2386 }
2386 } 2387 }
2387 2388
2388 /* Zero out unused superblock offsets */ 2389 /* Zero out unused superblock offsets */
2389 for (i = 2; i < LFS_MAXNUMSB; i++) 2390 for (i = 2; i < LFS_MAXNUMSB; i++)
2390 if (lfs_dtosn(fs, fs->lfs_sboffs[i]) >= newnsegs) 2391 if (lfs_dtosn(fs, fs->lfs_sboffs[i]) >= newnsegs)
2391 fs->lfs_sboffs[i] = 0x0; 2392 fs->lfs_sboffs[i] = 0x0;
2392 2393
2393 /* 2394 /*
@@ -2395,56 +2396,56 @@ lfs_resize_fs(struct lfs *fs, int newnse @@ -2395,56 +2396,56 @@ lfs_resize_fs(struct lfs *fs, int newnse
2395 * The computations of these are as follows: 2396 * The computations of these are as follows:
2396 * 2397 *
2397 * size = lfs_segtod(fs, nseg) 2398 * size = lfs_segtod(fs, nseg)
2398 * dsize = lfs_segtod(fs, nseg - minfreeseg) - lfs_btofsb(#super * LFS_SBPAD) 2399 * dsize = lfs_segtod(fs, nseg - minfreeseg) - lfs_btofsb(#super * LFS_SBPAD)
2399 * bfree = dsize - lfs_btofsb(fs, bsize * nseg / 2) - blocks_actually_used 2400 * bfree = dsize - lfs_btofsb(fs, bsize * nseg / 2) - blocks_actually_used
2400 * avail = lfs_segtod(fs, nclean) - lfs_btofsb(#clean_super * LFS_SBPAD) 2401 * avail = lfs_segtod(fs, nclean) - lfs_btofsb(#clean_super * LFS_SBPAD)
2401 * + (lfs_segtod(fs, 1) - (offset - curseg)) 2402 * + (lfs_segtod(fs, 1) - (offset - curseg))
2402 * - lfs_segtod(fs, minfreeseg - (minfreeseg / 2)) 2403 * - lfs_segtod(fs, minfreeseg - (minfreeseg / 2))
2403 * 2404 *
2404 * XXX - we should probably adjust minfreeseg as well. 2405 * XXX - we should probably adjust minfreeseg as well.
2405 */ 2406 */
2406 gain = (newnsegs - oldnsegs); 2407 gain = (newnsegs - oldnsegs);
2407 fs->lfs_nseg = newnsegs; 2408 fs->lfs_nseg = newnsegs;
2408 fs->lfs_segtabsz = nlast - fs->lfs_cleansz; 2409 lfs_sb_setsegtabsz(fs, nlast - lfs_sb_getcleansz(fs));
2409 fs->lfs_size += gain * lfs_btofsb(fs, fs->lfs_ssize); 2410 lfs_sb_addsize(fs, gain * lfs_btofsb(fs, lfs_sb_getssize(fs)));
2410 fs->lfs_dsize += gain * lfs_btofsb(fs, fs->lfs_ssize) - lfs_btofsb(fs, sbbytes); 2411 lfs_sb_adddsize(fs, gain * lfs_btofsb(fs, lfs_sb_getssize(fs)) - lfs_btofsb(fs, sbbytes));
2411 fs->lfs_bfree += gain * lfs_btofsb(fs, fs->lfs_ssize) - lfs_btofsb(fs, sbbytes) 2412 lfs_sb_addbfree(fs, gain * lfs_btofsb(fs, lfs_sb_getssize(fs)) - lfs_btofsb(fs, sbbytes)
2412 - gain * lfs_btofsb(fs, fs->lfs_bsize / 2); 2413 - gain * lfs_btofsb(fs, lfs_sb_getbsize(fs) / 2));
2413 if (gain > 0) { 2414 if (gain > 0) {
2414 fs->lfs_nclean += gain; 2415 fs->lfs_nclean += gain;
2415 fs->lfs_avail += gain * lfs_btofsb(fs, fs->lfs_ssize); 2416 lfs_sb_addavail(fs, gain * lfs_btofsb(fs, lfs_sb_getssize(fs)));
2416 } else { 2417 } else {
2417 fs->lfs_nclean -= cgain; 2418 fs->lfs_nclean -= cgain;
2418 fs->lfs_avail -= cgain * lfs_btofsb(fs, fs->lfs_ssize) - 2419 lfs_sb_subavail(fs, cgain * lfs_btofsb(fs, lfs_sb_getssize(fs)) -
2419 lfs_btofsb(fs, csbbytes); 2420 lfs_btofsb(fs, csbbytes));
2420 } 2421 }
2421 2422
2422 /* Resize segment flag cache */ 2423 /* Resize segment flag cache */
2423 fs->lfs_suflags[0] = realloc(fs->lfs_suflags[0], 2424 fs->lfs_suflags[0] = realloc(fs->lfs_suflags[0],
2424 fs->lfs_nseg * sizeof(u_int32_t), M_SEGMENT, M_WAITOK); 2425 fs->lfs_nseg * sizeof(u_int32_t), M_SEGMENT, M_WAITOK);
2425 fs->lfs_suflags[1] = realloc(fs->lfs_suflags[1], 2426 fs->lfs_suflags[1] = realloc(fs->lfs_suflags[1],
2426 fs->lfs_nseg * sizeof(u_int32_t), M_SEGMENT, M_WAITOK); 2427 fs->lfs_nseg * sizeof(u_int32_t), M_SEGMENT, M_WAITOK);
2427 for (i = oldnsegs; i < newnsegs; i++) 2428 for (i = oldnsegs; i < newnsegs; i++)
2428 fs->lfs_suflags[0][i] = fs->lfs_suflags[1][i] = 0x0; 2429 fs->lfs_suflags[0][i] = fs->lfs_suflags[1][i] = 0x0;
2429 2430
2430 /* Truncate Ifile if necessary */ 2431 /* Truncate Ifile if necessary */
2431 if (noff < 0) 2432 if (noff < 0)
2432 lfs_truncate(ivp, ivp->v_size + (noff << fs->lfs_bshift), 0, 2433 lfs_truncate(ivp, ivp->v_size + (noff << fs->lfs_bshift), 0,
2433 NOCRED); 2434 NOCRED);
2434 2435
2435 /* Update cleaner info so the cleaner can die */ 2436 /* Update cleaner info so the cleaner can die */
2436 /* XXX what to do if bread fails? */ 2437 /* XXX what to do if bread fails? */
2437 bread(ivp, 0, fs->lfs_bsize, B_MODIFY, &bp); 2438 bread(ivp, 0, lfs_sb_getbsize(fs), B_MODIFY, &bp);
2438 ((CLEANERINFO *)bp->b_data)->clean = fs->lfs_nclean; 2439 ((CLEANERINFO *)bp->b_data)->clean = fs->lfs_nclean;
2439 ((CLEANERINFO *)bp->b_data)->dirty = fs->lfs_nseg - fs->lfs_nclean; 2440 ((CLEANERINFO *)bp->b_data)->dirty = fs->lfs_nseg - fs->lfs_nclean;
2440 VOP_BWRITE(bp->b_vp, bp); 2441 VOP_BWRITE(bp->b_vp, bp);
2441 2442
2442 /* Let Ifile accesses proceed */ 2443 /* Let Ifile accesses proceed */
2443 rw_exit(&fs->lfs_iflock); 2444 rw_exit(&fs->lfs_iflock);
2444 2445
2445 out: 2446 out:
2446 lfs_segunlock(fs); 2447 lfs_segunlock(fs);
2447 return error; 2448 return error;
2448} 2449}
2449 2450
2450/* 2451/*

cvs diff -r1.273 -r1.274 src/sys/ufs/lfs/lfs_vnops.c (expand / switch to unified diff)

--- src/sys/ufs/lfs/lfs_vnops.c 2015/06/07 13:39:48 1.273
+++ src/sys/ufs/lfs/lfs_vnops.c 2015/07/24 06:56:42 1.274
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lfs_vnops.c,v 1.273 2015/06/07 13:39:48 hannken Exp $ */ 1/* $NetBSD: lfs_vnops.c,v 1.274 2015/07/24 06:56:42 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Konrad E. Schroder <perseant@hhhh.org>. 8 * by Konrad E. Schroder <perseant@hhhh.org>.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -115,27 +115,27 @@ @@ -115,27 +115,27 @@
115 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 115 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
116 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 116 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
117 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 117 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
118 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 118 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
119 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 119 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
120 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 120 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
121 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 121 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
122 * SUCH DAMAGE. 122 * SUCH DAMAGE.
123 * 123 *
124 * @(#)ufs_vnops.c 8.28 (Berkeley) 7/31/95 124 * @(#)ufs_vnops.c 8.28 (Berkeley) 7/31/95
125 */ 125 */
126 126
127#include <sys/cdefs.h> 127#include <sys/cdefs.h>
128__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.273 2015/06/07 13:39:48 hannken Exp $"); 128__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.274 2015/07/24 06:56:42 dholland Exp $");
129 129
130#ifdef _KERNEL_OPT 130#ifdef _KERNEL_OPT
131#include "opt_compat_netbsd.h" 131#include "opt_compat_netbsd.h"
132#include "opt_uvm_page_trkown.h" 132#include "opt_uvm_page_trkown.h"
133#endif 133#endif
134 134
135#include <sys/param.h> 135#include <sys/param.h>
136#include <sys/systm.h> 136#include <sys/systm.h>
137#include <sys/namei.h> 137#include <sys/namei.h>
138#include <sys/resourcevar.h> 138#include <sys/resourcevar.h>
139#include <sys/kernel.h> 139#include <sys/kernel.h>
140#include <sys/file.h> 140#include <sys/file.h>
141#include <sys/stat.h> 141#include <sys/stat.h>
@@ -410,28 +410,28 @@ lfs_fsync(void *v) @@ -410,28 +410,28 @@ lfs_fsync(void *v)
410 */ 410 */
411 if (ap->a_flags & FSYNC_RECLAIM && ip->i_flags & IN_CLEANING) { 411 if (ap->a_flags & FSYNC_RECLAIM && ip->i_flags & IN_CLEANING) {
412 lfs_vflush(vp); 412 lfs_vflush(vp);
413 } 413 }
414 414
415 wait = (ap->a_flags & FSYNC_WAIT); 415 wait = (ap->a_flags & FSYNC_WAIT);
416 do { 416 do {
417 mutex_enter(vp->v_interlock); 417 mutex_enter(vp->v_interlock);
418 error = VOP_PUTPAGES(vp, trunc_page(ap->a_offlo), 418 error = VOP_PUTPAGES(vp, trunc_page(ap->a_offlo),
419 round_page(ap->a_offhi), 419 round_page(ap->a_offhi),
420 PGO_CLEANIT | (wait ? PGO_SYNCIO : 0)); 420 PGO_CLEANIT | (wait ? PGO_SYNCIO : 0));
421 if (error == EAGAIN) { 421 if (error == EAGAIN) {
422 mutex_enter(&lfs_lock); 422 mutex_enter(&lfs_lock);
423 mtsleep(&fs->lfs_avail, PCATCH | PUSER, "lfs_fsync", 423 mtsleep(&fs->lfs_availsleep, PCATCH | PUSER,
424 hz / 100 + 1, &lfs_lock); 424 "lfs_fsync", hz / 100 + 1, &lfs_lock);
425 mutex_exit(&lfs_lock); 425 mutex_exit(&lfs_lock);
426 } 426 }
427 } while (error == EAGAIN); 427 } while (error == EAGAIN);
428 if (error) 428 if (error)
429 return error; 429 return error;
430 430
431 if ((ap->a_flags & FSYNC_DATAONLY) == 0) 431 if ((ap->a_flags & FSYNC_DATAONLY) == 0)
432 error = lfs_update(vp, NULL, NULL, wait ? UPDATE_WAIT : 0); 432 error = lfs_update(vp, NULL, NULL, wait ? UPDATE_WAIT : 0);
433 433
434 if (error == 0 && ap->a_flags & FSYNC_CACHE) { 434 if (error == 0 && ap->a_flags & FSYNC_CACHE) {
435 int l = 0; 435 int l = 0;
436 error = VOP_IOCTL(ip->i_devvp, DIOCCACHESYNC, &l, FWRITE, 436 error = VOP_IOCTL(ip->i_devvp, DIOCCACHESYNC, &l, FWRITE,
437 curlwp->l_cred); 437 curlwp->l_cred);
@@ -1224,27 +1224,27 @@ lfs_wrapgo(struct lfs *fs, struct inode  @@ -1224,27 +1224,27 @@ lfs_wrapgo(struct lfs *fs, struct inode
1224 cv_signal(&fs->lfs_stopcv); 1224 cv_signal(&fs->lfs_stopcv);
1225 1225
1226 KASSERT(fs->lfs_nowrap > 0); 1226 KASSERT(fs->lfs_nowrap > 0);
1227 if (fs->lfs_nowrap <= 0) { 1227 if (fs->lfs_nowrap <= 0) {
1228 return 0; 1228 return 0;
1229 } 1229 }
1230 1230
1231 if (--fs->lfs_nowrap == 0) { 1231 if (--fs->lfs_nowrap == 0) {
1232 log(LOG_NOTICE, "%s: re-enabled log wrap\n", fs->lfs_fsmnt); 1232 log(LOG_NOTICE, "%s: re-enabled log wrap\n", fs->lfs_fsmnt);
1233 wakeup(&fs->lfs_wrappass); 1233 wakeup(&fs->lfs_wrappass);
1234 lfs_wakeup_cleaner(fs); 1234 lfs_wakeup_cleaner(fs);
1235 } 1235 }
1236 if (waitfor) { 1236 if (waitfor) {
1237 mtsleep(&fs->lfs_nextseg, PCATCH | PUSER, "segment", 1237 mtsleep(&fs->lfs_nextsegsleep, PCATCH | PUSER, "segment",
1238 0, &lfs_lock); 1238 0, &lfs_lock);
1239 } 1239 }
1240 1240
1241 return 0; 1241 return 0;
1242} 1242}
1243 1243
1244/* 1244/*
1245 * Close called. 1245 * Close called.
1246 * 1246 *
1247 * Update the times on the inode. 1247 * Update the times on the inode.
1248 */ 1248 */
1249/* ARGSUSED */ 1249/* ARGSUSED */
1250int 1250int
@@ -1844,27 +1844,27 @@ segwait_common: @@ -1844,27 +1844,27 @@ segwait_common:
1844 mutex_enter(&lfs_lock); 1844 mutex_enter(&lfs_lock);
1845 if (--fs->lfs_sleepers == 0) 1845 if (--fs->lfs_sleepers == 0)
1846 wakeup(&fs->lfs_sleepers); 1846 wakeup(&fs->lfs_sleepers);
1847 mutex_exit(&lfs_lock); 1847 mutex_exit(&lfs_lock);
1848 lfs_free(fs, blkiov, LFS_NB_BLKIOV); 1848 lfs_free(fs, blkiov, LFS_NB_BLKIOV);
1849 return error; 1849 return error;
1850 1850
1851 case LFCNRECLAIM: 1851 case LFCNRECLAIM:
1852 /* 1852 /*
1853 * Flush dirops and write Ifile, allowing empty segments 1853 * Flush dirops and write Ifile, allowing empty segments
1854 * to be immediately reclaimed. 1854 * to be immediately reclaimed.
1855 */ 1855 */
1856 lfs_writer_enter(fs, "pndirop"); 1856 lfs_writer_enter(fs, "pndirop");
1857 off = fs->lfs_offset; 1857 off = lfs_sb_getoffset(fs);
1858 lfs_seglock(fs, SEGM_FORCE_CKP | SEGM_CKP); 1858 lfs_seglock(fs, SEGM_FORCE_CKP | SEGM_CKP);
1859 lfs_flush_dirops(fs); 1859 lfs_flush_dirops(fs);
1860 LFS_CLEANERINFO(cip, fs, bp); 1860 LFS_CLEANERINFO(cip, fs, bp);
1861 oclean = cip->clean; 1861 oclean = cip->clean;
1862 LFS_SYNC_CLEANERINFO(cip, fs, bp, 1); 1862 LFS_SYNC_CLEANERINFO(cip, fs, bp, 1);
1863 lfs_segwrite(ap->a_vp->v_mount, SEGM_FORCE_CKP); 1863 lfs_segwrite(ap->a_vp->v_mount, SEGM_FORCE_CKP);
1864 fs->lfs_sp->seg_flags |= SEGM_PROT; 1864 fs->lfs_sp->seg_flags |= SEGM_PROT;
1865 lfs_segunlock(fs); 1865 lfs_segunlock(fs);
1866 lfs_writer_leave(fs); 1866 lfs_writer_leave(fs);
1867 1867
1868#ifdef DEBUG 1868#ifdef DEBUG
1869 LFS_CLEANERINFO(cip, fs, bp); 1869 LFS_CLEANERINFO(cip, fs, bp);
1870 DLOG((DLOG_CLEAN, "lfs_fcntl: reclaim wrote %" PRId64 1870 DLOG((DLOG_CLEAN, "lfs_fcntl: reclaim wrote %" PRId64

cvs diff -r1.12 -r1.13 src/sys/ufs/lfs/ulfs_inode.h (expand / switch to unified diff)

--- src/sys/ufs/lfs/ulfs_inode.h 2014/05/17 07:08:35 1.12
+++ src/sys/ufs/lfs/ulfs_inode.h 2015/07/24 06:56:42 1.13
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ulfs_inode.h,v 1.12 2014/05/17 07:08:35 dholland Exp $ */ 1/* $NetBSD: ulfs_inode.h,v 1.13 2015/07/24 06:56:42 dholland Exp $ */
2/* from NetBSD: inode.h,v 1.64 2012/11/19 00:36:21 jakllsch Exp */ 2/* from NetBSD: inode.h,v 1.64 2012/11/19 00:36:21 jakllsch Exp */
3 3
4/* 4/*
5 * Copyright (c) 1982, 1989, 1993 5 * Copyright (c) 1982, 1989, 1993
6 * The Regents of the University of California. All rights reserved. 6 * The Regents of the University of California. All rights reserved.
7 * (c) UNIX System Laboratories, Inc. 7 * (c) UNIX System Laboratories, Inc.
8 * All or some portions of this file are derived from material licensed 8 * All or some portions of this file are derived from material licensed
9 * to the University of California by American Telephone and Telegraph 9 * to the University of California by American Telephone and Telegraph
10 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 10 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
11 * the permission of UNIX System Laboratories, Inc. 11 * the permission of UNIX System Laboratories, Inc.
12 * 12 *
13 * Redistribution and use in source and binary forms, with or without 13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions 14 * modification, are permitted provided that the following conditions
@@ -66,30 +66,30 @@ void lfs_unset_dirop(struct lfs *, struc @@ -66,30 +66,30 @@ void lfs_unset_dirop(struct lfs *, struc
66#define PG_DELWRI PG_PAGER1 /* Local def for delayed pageout */ 66#define PG_DELWRI PG_PAGER1 /* Local def for delayed pageout */
67 67
68/* Resource limits */ 68/* Resource limits */
69#define LFS_MAX_RESOURCE(x, u) (((x) >> 2) - 10 * (u)) 69#define LFS_MAX_RESOURCE(x, u) (((x) >> 2) - 10 * (u))
70#define LFS_WAIT_RESOURCE(x, u) (((x) >> 1) - ((x) >> 3) - 10 * (u)) 70#define LFS_WAIT_RESOURCE(x, u) (((x) >> 1) - ((x) >> 3) - 10 * (u))
71#define LFS_INVERSE_MAX_RESOURCE(x, u) (((x) + 10 * (u)) << 2) 71#define LFS_INVERSE_MAX_RESOURCE(x, u) (((x) + 10 * (u)) << 2)
72#define LFS_MAX_BUFS LFS_MAX_RESOURCE(nbuf, 1) 72#define LFS_MAX_BUFS LFS_MAX_RESOURCE(nbuf, 1)
73#define LFS_WAIT_BUFS LFS_WAIT_RESOURCE(nbuf, 1) 73#define LFS_WAIT_BUFS LFS_WAIT_RESOURCE(nbuf, 1)
74#define LFS_INVERSE_MAX_BUFS(n) LFS_INVERSE_MAX_RESOURCE(n, 1) 74#define LFS_INVERSE_MAX_BUFS(n) LFS_INVERSE_MAX_RESOURCE(n, 1)
75#define LFS_MAX_BYTES LFS_MAX_RESOURCE(bufmem_lowater, PAGE_SIZE) 75#define LFS_MAX_BYTES LFS_MAX_RESOURCE(bufmem_lowater, PAGE_SIZE)
76#define LFS_INVERSE_MAX_BYTES(n) LFS_INVERSE_MAX_RESOURCE(n, PAGE_SIZE) 76#define LFS_INVERSE_MAX_BYTES(n) LFS_INVERSE_MAX_RESOURCE(n, PAGE_SIZE)
77#define LFS_WAIT_BYTES LFS_WAIT_RESOURCE(bufmem_lowater, PAGE_SIZE) 77#define LFS_WAIT_BYTES LFS_WAIT_RESOURCE(bufmem_lowater, PAGE_SIZE)
78#define LFS_MAX_DIROP ((desiredvnodes >> 2) + (desiredvnodes >> 3)) 78#define LFS_MAX_DIROP ((desiredvnodes >> 2) + (desiredvnodes >> 3))
79#define SIZEOF_DIROP(fs) (2 * ((fs)->lfs_bsize + LFS_DINODE1_SIZE)) 79#define SIZEOF_DIROP(fs) (2 * (lfs_sb_getbsize(fs) + LFS_DINODE1_SIZE))
80#define LFS_MAX_FSDIROP(fs) \ 80#define LFS_MAX_FSDIROP(fs) \
81 ((fs)->lfs_nclean <= (fs)->lfs_resvseg ? 0 : \ 81 ((fs)->lfs_nclean <= (fs)->lfs_resvseg ? 0 : \
82 (((fs)->lfs_nclean - (fs)->lfs_resvseg) * (fs)->lfs_ssize) / \ 82 (((fs)->lfs_nclean - (fs)->lfs_resvseg) * lfs_sb_getssize(fs)) / \
83 (2 * SIZEOF_DIROP(fs))) 83 (2 * SIZEOF_DIROP(fs)))
84#define LFS_MAX_PAGES lfs_max_pages() 84#define LFS_MAX_PAGES lfs_max_pages()
85#define LFS_WAIT_PAGES lfs_wait_pages() 85#define LFS_WAIT_PAGES lfs_wait_pages()
86#define LFS_BUFWAIT 2 /* How long to wait if over *_WAIT_* */ 86#define LFS_BUFWAIT 2 /* How long to wait if over *_WAIT_* */
87 87
88#ifdef _KERNEL 88#ifdef _KERNEL
89extern u_long bufmem_lowater, bufmem_hiwater; /* XXX */ 89extern u_long bufmem_lowater, bufmem_hiwater; /* XXX */
90 90
91int lfs_wait_pages(void); 91int lfs_wait_pages(void);
92int lfs_max_pages(void); 92int lfs_max_pages(void);
93#endif /* _KERNEL */ 93#endif /* _KERNEL */
94 94
95/* How starved can we be before we start holding back page writes */ 95/* How starved can we be before we start holding back page writes */

cvs diff -r1.18 -r1.19 src/sys/ufs/lfs/ulfs_quota2.c (expand / switch to unified diff)

--- src/sys/ufs/lfs/ulfs_quota2.c 2015/03/28 19:24:05 1.18
+++ src/sys/ufs/lfs/ulfs_quota2.c 2015/07/24 06:56:42 1.19
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ulfs_quota2.c,v 1.18 2015/03/28 19:24:05 maxv Exp $ */ 1/* $NetBSD: ulfs_quota2.c,v 1.19 2015/07/24 06:56:42 dholland Exp $ */
2/* from NetBSD: ufs_quota2.c,v 1.35 2012/09/27 07:47:56 bouyer Exp */ 2/* from NetBSD: ufs_quota2.c,v 1.35 2012/09/27 07:47:56 bouyer Exp */
3/* from NetBSD: ffs_quota2.c,v 1.4 2011/06/12 03:36:00 rmind Exp */ 3/* from NetBSD: ffs_quota2.c,v 1.4 2011/06/12 03:36:00 rmind Exp */
4 4
5/*- 5/*-
6 * Copyright (c) 2010 Manuel Bouyer 6 * Copyright (c) 2010 Manuel Bouyer
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -19,27 +19,27 @@ @@ -19,27 +19,27 @@
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE. 28 * POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31#include <sys/cdefs.h> 31#include <sys/cdefs.h>
32__KERNEL_RCSID(0, "$NetBSD: ulfs_quota2.c,v 1.18 2015/03/28 19:24:05 maxv Exp $"); 32__KERNEL_RCSID(0, "$NetBSD: ulfs_quota2.c,v 1.19 2015/07/24 06:56:42 dholland Exp $");
33 33
34#include <sys/buf.h> 34#include <sys/buf.h>
35#include <sys/param.h> 35#include <sys/param.h>
36#include <sys/kernel.h> 36#include <sys/kernel.h>
37#include <sys/systm.h> 37#include <sys/systm.h>
38#include <sys/namei.h> 38#include <sys/namei.h>
39#include <sys/file.h> 39#include <sys/file.h>
40#include <sys/proc.h> 40#include <sys/proc.h>
41#include <sys/vnode.h> 41#include <sys/vnode.h>
42#include <sys/mount.h> 42#include <sys/mount.h>
43#include <sys/fstrans.h> 43#include <sys/fstrans.h>
44#include <sys/kauth.h> 44#include <sys/kauth.h>
45#include <sys/wapbl.h> 45#include <sys/wapbl.h>
@@ -1552,27 +1552,27 @@ lfs_dq2sync(struct vnode *vp, struct dqu @@ -1552,27 +1552,27 @@ lfs_dq2sync(struct vnode *vp, struct dqu
1552int 1552int
1553lfs_quota2_mount(struct mount *mp) 1553lfs_quota2_mount(struct mount *mp)
1554{ 1554{
1555 struct ulfsmount *ump = VFSTOULFS(mp); 1555 struct ulfsmount *ump = VFSTOULFS(mp);
1556 struct lfs *fs = ump->um_lfs; 1556 struct lfs *fs = ump->um_lfs;
1557 int error = 0; 1557 int error = 0;
1558 struct vnode *vp; 1558 struct vnode *vp;
1559 struct lwp *l = curlwp; 1559 struct lwp *l = curlwp;
1560 1560
1561 if ((fs->lfs_use_quota2) == 0) 1561 if ((fs->lfs_use_quota2) == 0)
1562 return 0; 1562 return 0;
1563 1563
1564 fs->um_flags |= ULFS_QUOTA2; 1564 fs->um_flags |= ULFS_QUOTA2;
1565 ump->umq2_bsize = fs->lfs_bsize; 1565 ump->umq2_bsize = lfs_sb_getbsize(fs);
1566 ump->umq2_bmask = fs->lfs_bmask; 1566 ump->umq2_bmask = fs->lfs_bmask;
1567 if (fs->lfs_quota_magic != Q2_HEAD_MAGIC) { 1567 if (fs->lfs_quota_magic != Q2_HEAD_MAGIC) {
1568 printf("%s: Invalid quota magic number\n", 1568 printf("%s: Invalid quota magic number\n",
1569 mp->mnt_stat.f_mntonname); 1569 mp->mnt_stat.f_mntonname);
1570 return EINVAL; 1570 return EINVAL;
1571 } 1571 }
1572 if ((fs->lfs_quota_flags & FS_Q2_DO_TYPE(ULFS_USRQUOTA)) && 1572 if ((fs->lfs_quota_flags & FS_Q2_DO_TYPE(ULFS_USRQUOTA)) &&
1573 fs->lfs_quotaino[ULFS_USRQUOTA] == 0) { 1573 fs->lfs_quotaino[ULFS_USRQUOTA] == 0) {
1574 printf("%s: no user quota inode\n", 1574 printf("%s: no user quota inode\n",
1575 mp->mnt_stat.f_mntonname);  1575 mp->mnt_stat.f_mntonname);
1576 error = EINVAL; 1576 error = EINVAL;
1577 } 1577 }
1578 if ((fs->lfs_quota_flags & FS_Q2_DO_TYPE(ULFS_GRPQUOTA)) && 1578 if ((fs->lfs_quota_flags & FS_Q2_DO_TYPE(ULFS_GRPQUOTA)) &&

cvs diff -r1.17 -r1.18 src/sys/ufs/lfs/ulfs_readwrite.c (expand / switch to unified diff)

--- src/sys/ufs/lfs/ulfs_readwrite.c 2015/04/12 22:51:23 1.17
+++ src/sys/ufs/lfs/ulfs_readwrite.c 2015/07/24 06:56:42 1.18
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: ulfs_readwrite.c,v 1.17 2015/04/12 22:51:23 riastradh Exp $ */ 1/* $NetBSD: ulfs_readwrite.c,v 1.18 2015/07/24 06:56:42 dholland Exp $ */
2/* from NetBSD: ufs_readwrite.c,v 1.105 2013/01/22 09:39:18 dholland Exp */ 2/* from NetBSD: ufs_readwrite.c,v 1.105 2013/01/22 09:39:18 dholland Exp */
3 3
4/*- 4/*-
5 * Copyright (c) 1993 5 * Copyright (c) 1993
6 * The Regents of the University of California. All rights reserved. 6 * The Regents of the University of California. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -23,48 +23,49 @@ @@ -23,48 +23,49 @@
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE. 30 * SUCH DAMAGE.
31 * 31 *
32 * @(#)ufs_readwrite.c 8.11 (Berkeley) 5/8/95 32 * @(#)ufs_readwrite.c 8.11 (Berkeley) 5/8/95
33 */ 33 */
34 34
35#include <sys/cdefs.h> 35#include <sys/cdefs.h>
36__KERNEL_RCSID(1, "$NetBSD: ulfs_readwrite.c,v 1.17 2015/04/12 22:51:23 riastradh Exp $"); 36__KERNEL_RCSID(1, "$NetBSD: ulfs_readwrite.c,v 1.18 2015/07/24 06:56:42 dholland Exp $");
37 37
38#ifdef LFS_READWRITE 38#ifdef LFS_READWRITE
39#define FS struct lfs 39#define FS struct lfs
40#define I_FS i_lfs 40#define I_FS i_lfs
41#define READ lfs_read 41#define READ lfs_read
42#define READ_S "lfs_read" 42#define READ_S "lfs_read"
43#define WRITE lfs_write 43#define WRITE lfs_write
44#define WRITE_S "lfs_write" 44#define WRITE_S "lfs_write"
45#define BUFRD lfs_bufrd 45#define BUFRD lfs_bufrd
46#define BUFWR lfs_bufwr 46#define BUFWR lfs_bufwr
47#define fs_bsize lfs_bsize 47#define fs_sb_getbsize(fs) lfs_sb_getbsize(fs)
48#define fs_bmask lfs_bmask 48#define fs_bmask lfs_bmask
49#else 49#else
50#define FS struct fs 50#define FS struct fs
51#define I_FS i_fs 51#define I_FS i_fs
52#define READ ffs_read 52#define READ ffs_read
53#define READ_S "ffs_read" 53#define READ_S "ffs_read"
54#define WRITE ffs_write 54#define WRITE ffs_write
55#define WRITE_S "ffs_write" 55#define WRITE_S "ffs_write"
56#define BUFRD ffs_bufrd 56#define BUFRD ffs_bufrd
57#define BUFWR ffs_bufwr 57#define BUFWR ffs_bufwr
 58#define fs_sb_getbsize(fs) (fs)->fs_bsize
58#endif 59#endif
59 60
60static int ulfs_post_read_update(struct vnode *, int, int); 61static int ulfs_post_read_update(struct vnode *, int, int);
61static int ulfs_post_write_update(struct vnode *, struct uio *, int, 62static int ulfs_post_write_update(struct vnode *, struct uio *, int,
62 kauth_cred_t, off_t, int, int, int); 63 kauth_cred_t, off_t, int, int, int);
63 64
64/* 65/*
65 * Vnode op for reading. 66 * Vnode op for reading.
66 */ 67 */
67/* ARGSUSED */ 68/* ARGSUSED */
68int 69int
69READ(void *v) 70READ(void *v)
70{ 71{
@@ -176,27 +177,27 @@ BUFRD(struct vnode *vp, struct uio *uio, @@ -176,27 +177,27 @@ BUFRD(struct vnode *vp, struct uio *uio,
176 fstrans_start(vp->v_mount, FSTRANS_SHARED); 177 fstrans_start(vp->v_mount, FSTRANS_SHARED);
177 178
178 if (uio->uio_offset >= ip->i_size) 179 if (uio->uio_offset >= ip->i_size)
179 goto out; 180 goto out;
180 181
181 for (error = 0, bp = NULL; uio->uio_resid > 0; bp = NULL) { 182 for (error = 0, bp = NULL; uio->uio_resid > 0; bp = NULL) {
182 bytesinfile = ip->i_size - uio->uio_offset; 183 bytesinfile = ip->i_size - uio->uio_offset;
183 if (bytesinfile <= 0) 184 if (bytesinfile <= 0)
184 break; 185 break;
185 lbn = lfs_lblkno(fs, uio->uio_offset); 186 lbn = lfs_lblkno(fs, uio->uio_offset);
186 nextlbn = lbn + 1; 187 nextlbn = lbn + 1;
187 size = lfs_blksize(fs, ip, lbn); 188 size = lfs_blksize(fs, ip, lbn);
188 blkoffset = lfs_blkoff(fs, uio->uio_offset); 189 blkoffset = lfs_blkoff(fs, uio->uio_offset);
189 xfersize = MIN(MIN(fs->fs_bsize - blkoffset, uio->uio_resid), 190 xfersize = MIN(MIN(fs_sb_getbsize(fs) - blkoffset, uio->uio_resid),
190 bytesinfile); 191 bytesinfile);
191 192
192 if (lfs_lblktosize(fs, nextlbn) >= ip->i_size) 193 if (lfs_lblktosize(fs, nextlbn) >= ip->i_size)
193 error = bread(vp, lbn, size, 0, &bp); 194 error = bread(vp, lbn, size, 0, &bp);
194 else { 195 else {
195 int nextsize = lfs_blksize(fs, ip, nextlbn); 196 int nextsize = lfs_blksize(fs, ip, nextlbn);
196 error = breadn(vp, lbn, 197 error = breadn(vp, lbn,
197 size, &nextlbn, &nextsize, 1, 0, &bp); 198 size, &nextlbn, &nextsize, 1, 0, &bp);
198 } 199 }
199 if (error) 200 if (error)
200 break; 201 break;
201 202
202 /* 203 /*
@@ -343,27 +344,27 @@ WRITE(void *v) @@ -343,27 +344,27 @@ WRITE(void *v)
343 } 344 }
344 345
345 while (uio->uio_resid > 0) { 346 while (uio->uio_resid > 0) {
346 int ubc_flags = UBC_WRITE; 347 int ubc_flags = UBC_WRITE;
347 bool overwrite; /* if we're overwrite a whole block */ 348 bool overwrite; /* if we're overwrite a whole block */
348 off_t newoff; 349 off_t newoff;
349 350
350 if (ioflag & IO_DIRECT) { 351 if (ioflag & IO_DIRECT) {
351 genfs_directio(vp, uio, ioflag); 352 genfs_directio(vp, uio, ioflag);
352 } 353 }
353 354
354 oldoff = uio->uio_offset; 355 oldoff = uio->uio_offset;
355 blkoffset = lfs_blkoff(fs, uio->uio_offset); 356 blkoffset = lfs_blkoff(fs, uio->uio_offset);
356 bytelen = MIN(fs->fs_bsize - blkoffset, uio->uio_resid); 357 bytelen = MIN(fs_sb_getbsize(fs) - blkoffset, uio->uio_resid);
357 if (bytelen == 0) { 358 if (bytelen == 0) {
358 break; 359 break;
359 } 360 }
360 361
361 /* 362 /*
362 * if we're filling in a hole, allocate the blocks now and 363 * if we're filling in a hole, allocate the blocks now and
363 * initialize the pages first. if we're extending the file, 364 * initialize the pages first. if we're extending the file,
364 * we can safely allocate blocks without initializing pages 365 * we can safely allocate blocks without initializing pages
365 * since the new blocks will be inaccessible until the write 366 * since the new blocks will be inaccessible until the write
366 * is complete. 367 * is complete.
367 */ 368 */
368 overwrite = uio->uio_offset >= preallocoff && 369 overwrite = uio->uio_offset >= preallocoff &&
369 uio->uio_offset < endallocoff; 370 uio->uio_offset < endallocoff;
@@ -504,28 +505,28 @@ BUFWR(struct vnode *vp, struct uio *uio, @@ -504,28 +505,28 @@ BUFWR(struct vnode *vp, struct uio *uio,
504 505
505 KASSERT(vp->v_type != VREG); 506 KASSERT(vp->v_type != VREG);
506 507
507#ifdef LFS_READWRITE 508#ifdef LFS_READWRITE
508 lfs_availwait(fs, lfs_btofsb(fs, uio->uio_resid)); 509 lfs_availwait(fs, lfs_btofsb(fs, uio->uio_resid));
509 lfs_check(vp, LFS_UNUSED_LBN, 0); 510 lfs_check(vp, LFS_UNUSED_LBN, 0);
510#endif /* !LFS_READWRITE */ 511#endif /* !LFS_READWRITE */
511 512
512 /* XXX Should never have pages cached here. */ 513 /* XXX Should never have pages cached here. */
513 KASSERT(vp->v_uobj.uo_npages == 0); 514 KASSERT(vp->v_uobj.uo_npages == 0);
514 while (uio->uio_resid > 0) { 515 while (uio->uio_resid > 0) {
515 lbn = lfs_lblkno(fs, uio->uio_offset); 516 lbn = lfs_lblkno(fs, uio->uio_offset);
516 blkoffset = lfs_blkoff(fs, uio->uio_offset); 517 blkoffset = lfs_blkoff(fs, uio->uio_offset);
517 xfersize = MIN(fs->fs_bsize - blkoffset, uio->uio_resid); 518 xfersize = MIN(fs_sb_getbsize(fs) - blkoffset, uio->uio_resid);
518 if (fs->fs_bsize > xfersize) 519 if (fs_sb_getbsize(fs) > xfersize)
519 flags |= B_CLRBUF; 520 flags |= B_CLRBUF;
520 else 521 else
521 flags &= ~B_CLRBUF; 522 flags &= ~B_CLRBUF;
522 523
523#ifdef LFS_READWRITE 524#ifdef LFS_READWRITE
524 error = lfs_reserve(fs, vp, NULL, 525 error = lfs_reserve(fs, vp, NULL,
525 lfs_btofsb(fs, (ULFS_NIADDR + 1) << fs->lfs_bshift)); 526 lfs_btofsb(fs, (ULFS_NIADDR + 1) << fs->lfs_bshift));
526 if (error) 527 if (error)
527 break; 528 break;
528 need_unreserve = true; 529 need_unreserve = true;
529#endif 530#endif
530 error = lfs_balloc(vp, uio->uio_offset, xfersize, cred, flags, 531 error = lfs_balloc(vp, uio->uio_offset, xfersize, cred, flags,
531 &bp); 532 &bp);

cvs diff -r1.42 -r1.43 src/usr.sbin/dumplfs/dumplfs.c (expand / switch to unified diff)

--- src/usr.sbin/dumplfs/dumplfs.c 2015/05/31 15:44:31 1.42
+++ src/usr.sbin/dumplfs/dumplfs.c 2015/07/24 06:56:42 1.43
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: dumplfs.c,v 1.42 2015/05/31 15:44:31 hannken Exp $ */ 1/* $NetBSD: dumplfs.c,v 1.43 2015/07/24 06:56:42 dholland Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1991, 1993 4 * Copyright (c) 1991, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -30,27 +30,27 @@ @@ -30,27 +30,27 @@
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33 33
34#ifndef lint 34#ifndef lint
35__COPYRIGHT("@(#) Copyright (c) 1991, 1993\ 35__COPYRIGHT("@(#) Copyright (c) 1991, 1993\
36 The Regents of the University of California. All rights reserved."); 36 The Regents of the University of California. All rights reserved.");
37#endif /* not lint */ 37#endif /* not lint */
38 38
39#ifndef lint 39#ifndef lint
40#if 0 40#if 0
41static char sccsid[] = "@(#)dumplfs.c 8.5 (Berkeley) 5/24/95"; 41static char sccsid[] = "@(#)dumplfs.c 8.5 (Berkeley) 5/24/95";
42#else 42#else
43__RCSID("$NetBSD: dumplfs.c,v 1.42 2015/05/31 15:44:31 hannken Exp $"); 43__RCSID("$NetBSD: dumplfs.c,v 1.43 2015/07/24 06:56:42 dholland Exp $");
44#endif 44#endif
45#endif /* not lint */ 45#endif /* not lint */
46 46
47#include <sys/param.h> 47#include <sys/param.h>
48#include <sys/ucred.h> 48#include <sys/ucred.h>
49#include <sys/mount.h> 49#include <sys/mount.h>
50#include <sys/time.h> 50#include <sys/time.h>
51 51
52#include <ufs/lfs/lfs.h> 52#include <ufs/lfs/lfs.h>
53 53
54#include <err.h> 54#include <err.h>
55#include <errno.h> 55#include <errno.h>
56#include <fcntl.h> 56#include <fcntl.h>
@@ -194,53 +194,53 @@ main(int argc, char **argv) @@ -194,53 +194,53 @@ main(int argc, char **argv)
194 &(lfs_sb1.lfs_dlfs), sizeof(struct dlfs)); 194 &(lfs_sb1.lfs_dlfs), sizeof(struct dlfs));
195  195
196 /* 196 /*
197 * Read the second superblock and figure out which check point is 197 * Read the second superblock and figure out which check point is
198 * most up to date. 198 * most up to date.
199 */ 199 */
200 get(fd, 200 get(fd,
201 fsbtobyte(&lfs_sb1, lfs_sb1.lfs_sboffs[1]), 201 fsbtobyte(&lfs_sb1, lfs_sb1.lfs_sboffs[1]),
202 sbuf, LFS_SBPAD); 202 sbuf, LFS_SBPAD);
203 memcpy(&(lfs_sb2.lfs_dlfs), sbuf, sizeof(struct dlfs)); 203 memcpy(&(lfs_sb2.lfs_dlfs), sbuf, sizeof(struct dlfs));
204  204
205 lfs_master = &lfs_sb1; 205 lfs_master = &lfs_sb1;
206 if (lfs_sb1.lfs_version > 1) { 206 if (lfs_sb1.lfs_version > 1) {
207 if (lfs_sb1.lfs_serial > lfs_sb2.lfs_serial) { 207 if (lfs_sb_getserial(&lfs_sb1) > lfs_sb_getserial(&lfs_sb2)) {
208 lfs_master = &lfs_sb2; 208 lfs_master = &lfs_sb2;
209 sbdaddr = lfs_sb1.lfs_sboffs[1]; 209 sbdaddr = lfs_sb1.lfs_sboffs[1];
210 } else 210 } else
211 sbdaddr = lfs_sb1.lfs_sboffs[0]; 211 sbdaddr = lfs_sb1.lfs_sboffs[0];
212 } else { 212 } else {
213 if (lfs_sb1.lfs_otstamp > lfs_sb2.lfs_otstamp) { 213 if (lfs_sb_getotstamp(&lfs_sb1) > lfs_sb_getotstamp(&lfs_sb2)) {
214 lfs_master = &lfs_sb2; 214 lfs_master = &lfs_sb2;
215 sbdaddr = lfs_sb1.lfs_sboffs[1]; 215 sbdaddr = lfs_sb1.lfs_sboffs[1];
216 } else 216 } else
217 sbdaddr = lfs_sb1.lfs_sboffs[0]; 217 sbdaddr = lfs_sb1.lfs_sboffs[0];
218 } 218 }
219 } else { 219 } else {
220 /* Read the first superblock */ 220 /* Read the first superblock */
221 get(fd, dbtob((off_t)sbdaddr), sbuf, LFS_SBPAD); 221 get(fd, dbtob((off_t)sbdaddr), sbuf, LFS_SBPAD);
222 memcpy(&(lfs_sb1.lfs_dlfs), sbuf, sizeof(struct dlfs)); 222 memcpy(&(lfs_sb1.lfs_dlfs), sbuf, sizeof(struct dlfs));
223 lfs_master = &lfs_sb1; 223 lfs_master = &lfs_sb1;
224 } 224 }
225 225
226 free(sbuf); 226 free(sbuf);
227 227
228 /* Compatibility */ 228 /* Compatibility */
229 if (lfs_master->lfs_version == 1) { 229 if (lfs_master->lfs_version == 1) {
230 lfs_master->lfs_sumsize = LFS_V1_SUMMARY_SIZE; 230 lfs_master->lfs_sumsize = LFS_V1_SUMMARY_SIZE;
231 lfs_master->lfs_ibsize = lfs_master->lfs_bsize; 231 lfs_master->lfs_ibsize = lfs_sb_getbsize(lfs_master);
232 lfs_master->lfs_s0addr = lfs_master->lfs_sboffs[0]; 232 lfs_master->lfs_s0addr = lfs_master->lfs_sboffs[0];
233 lfs_master->lfs_tstamp = lfs_master->lfs_otstamp; 233 lfs_sb_settstamp(lfs_master, lfs_sb_getotstamp(lfs_master));
234 lfs_master->lfs_fsbtodb = 0; 234 lfs_master->lfs_fsbtodb = 0;
235 } 235 }
236 236
237 (void)printf("Master Superblock at 0x%llx:\n", (long long)sbdaddr); 237 (void)printf("Master Superblock at 0x%llx:\n", (long long)sbdaddr);
238 dump_super(lfs_master); 238 dump_super(lfs_master);
239 239
240 dump_ifile(fd, lfs_master, do_ientries, do_segentries, idaddr); 240 dump_ifile(fd, lfs_master, do_ientries, do_segentries, idaddr);
241 241
242 if (seglist != NULL) 242 if (seglist != NULL)
243 for (; seglist != NULL; seglist = seglist->next) { 243 for (; seglist != NULL; seglist = seglist->next) {
244 seg_addr = lfs_sntod(lfs_master, seglist->num); 244 seg_addr = lfs_sntod(lfs_master, seglist->num);
245 dump_segment(fd, seglist->num, seg_addr, lfs_master, 245 dump_segment(fd, seglist->num, seg_addr, lfs_master,
246 do_allsb); 246 do_allsb);
@@ -260,150 +260,150 @@ main(int argc, char **argv) @@ -260,150 +260,150 @@ main(int argc, char **argv)
260 * We are reading all the blocks of an inode and dumping out the ifile table. 260 * We are reading all the blocks of an inode and dumping out the ifile table.
261 * This code could be tighter, but this is a first pass at getting the stuff 261 * This code could be tighter, but this is a first pass at getting the stuff
262 * printed out rather than making this code incredibly efficient. 262 * printed out rather than making this code incredibly efficient.
263 */ 263 */
264static void 264static void
265dump_ifile(int fd, struct lfs *lfsp, int do_ientries, int do_segentries, daddr_t addr) 265dump_ifile(int fd, struct lfs *lfsp, int do_ientries, int do_segentries, daddr_t addr)
266{ 266{
267 char *ipage; 267 char *ipage;
268 struct ulfs1_dinode *dip, *dpage; 268 struct ulfs1_dinode *dip, *dpage;
269 /* XXX ondisk32 */ 269 /* XXX ondisk32 */
270 int32_t *addrp, *dindir, *iaddrp, *indir; 270 int32_t *addrp, *dindir, *iaddrp, *indir;
271 int block_limit, i, inum, j, nblocks, psize; 271 int block_limit, i, inum, j, nblocks, psize;
272 272
273 psize = lfsp->lfs_bsize; 273 psize = lfs_sb_getbsize(lfsp);
274 if (!addr) 274 if (!addr)
275 addr = lfsp->lfs_idaddr; 275 addr = lfs_sb_getidaddr(lfsp);
276 276
277 if (!(dpage = malloc(psize))) 277 if (!(dpage = malloc(psize)))
278 err(1, "malloc"); 278 err(1, "malloc");
279 get(fd, fsbtobyte(lfsp, addr), dpage, psize); 279 get(fd, fsbtobyte(lfsp, addr), dpage, psize);
280 280
281 for (dip = dpage + LFS_INOPB(lfsp) - 1; dip >= dpage; --dip) 281 for (dip = dpage + LFS_INOPB(lfsp) - 1; dip >= dpage; --dip)
282 if (dip->di_inumber == LFS_IFILE_INUM) 282 if (dip->di_inumber == LFS_IFILE_INUM)
283 break; 283 break;
284 284
285 if (dip < dpage) { 285 if (dip < dpage) {
286 warnx("unable to locate ifile inode at disk address 0x%llx", 286 warnx("unable to locate ifile inode at disk address 0x%llx",
287 (long long)addr); 287 (long long)addr);
288 return; 288 return;
289 } 289 }
290 290
291 (void)printf("\nIFILE inode\n"); 291 (void)printf("\nIFILE inode\n");
292 dump_dinode(dip); 292 dump_dinode(dip);
293 293
294 (void)printf("\nIFILE contents\n"); 294 (void)printf("\nIFILE contents\n");
295 nblocks = dip->di_size >> lfsp->lfs_bshift; 295 nblocks = dip->di_size >> lfs_sb_getbshift(lfsp);
296 block_limit = MIN(nblocks, ULFS_NDADDR); 296 block_limit = MIN(nblocks, ULFS_NDADDR);
297 297
298 /* Get the direct block */ 298 /* Get the direct block */
299 if ((ipage = malloc(psize)) == NULL) 299 if ((ipage = malloc(psize)) == NULL)
300 err(1, "malloc"); 300 err(1, "malloc");
301 for (inum = 0, addrp = dip->di_db, i = 0; i < block_limit; 301 for (inum = 0, addrp = dip->di_db, i = 0; i < block_limit;
302 i++, addrp++) { 302 i++, addrp++) {
303 get(fd, fsbtobyte(lfsp, *addrp), ipage, psize); 303 get(fd, fsbtobyte(lfsp, *addrp), ipage, psize);
304 if (i < lfsp->lfs_cleansz) { 304 if (i < lfs_sb_getcleansz(lfsp)) {
305 dump_cleaner_info(lfsp, ipage); 305 dump_cleaner_info(lfsp, ipage);
306 if (do_segentries) 306 if (do_segentries)
307 print_suheader; 307 print_suheader;
308 continue; 308 continue;
309 }  309 }
310 310
311 if (i < (lfsp->lfs_segtabsz + lfsp->lfs_cleansz)) { 311 if (i < (lfs_sb_getsegtabsz(lfsp) + lfs_sb_getcleansz(lfsp))) {
312 if (do_segentries) 312 if (do_segentries)
313 inum = dump_ipage_segusage(lfsp, inum, ipage,  313 inum = dump_ipage_segusage(lfsp, inum, ipage,
314 lfsp->lfs_sepb); 314 lfs_sb_getsepb(lfsp));
315 else 315 else
316 inum = (i < lfsp->lfs_segtabsz + lfsp->lfs_cleansz - 1); 316 inum = (i < lfs_sb_getsegtabsz(lfsp) + lfs_sb_getcleansz(lfsp) - 1);
317 if (!inum) { 317 if (!inum) {
318 if(!do_ientries) 318 if(!do_ientries)
319 goto e0; 319 goto e0;
320 else 320 else
321 print_iheader; 321 print_iheader;
322 } 322 }
323 } else 323 } else
324 inum = dump_ipage_ifile(lfsp, inum, ipage, lfsp->lfs_ifpb); 324 inum = dump_ipage_ifile(lfsp, inum, ipage, lfs_sb_getifpb(lfsp));
325 } 325 }
326 326
327 if (nblocks <= ULFS_NDADDR) 327 if (nblocks <= ULFS_NDADDR)
328 goto e0; 328 goto e0;
329 329
330 /* Dump out blocks off of single indirect block */ 330 /* Dump out blocks off of single indirect block */
331 if (!(indir = malloc(psize))) 331 if (!(indir = malloc(psize)))
332 err(1, "malloc"); 332 err(1, "malloc");
333 get(fd, fsbtobyte(lfsp, dip->di_ib[0]), indir, psize); 333 get(fd, fsbtobyte(lfsp, dip->di_ib[0]), indir, psize);
334 block_limit = MIN(i + lfsp->lfs_nindir, nblocks); 334 block_limit = MIN(i + lfs_sb_getnindir(lfsp), nblocks);
335 for (addrp = indir; i < block_limit; i++, addrp++) { 335 for (addrp = indir; i < block_limit; i++, addrp++) {
336 if (*addrp == LFS_UNUSED_DADDR) 336 if (*addrp == LFS_UNUSED_DADDR)
337 break; 337 break;
338 get(fd, fsbtobyte(lfsp, *addrp), ipage, psize); 338 get(fd, fsbtobyte(lfsp, *addrp), ipage, psize);
339 if (i < lfsp->lfs_cleansz) { 339 if (i < lfs_sb_getcleansz(lfsp)) {
340 dump_cleaner_info(lfsp, ipage); 340 dump_cleaner_info(lfsp, ipage);
341 continue; 341 continue;
342 } 342 }
343 343
344 if (i < lfsp->lfs_segtabsz + lfsp->lfs_cleansz) { 344 if (i < lfs_sb_getsegtabsz(lfsp) + lfs_sb_getcleansz(lfsp)) {
345 if (do_segentries) 345 if (do_segentries)
346 inum = dump_ipage_segusage(lfsp, inum, ipage,  346 inum = dump_ipage_segusage(lfsp, inum, ipage,
347 lfsp->lfs_sepb); 347 lfs_sb_getsepb(lfsp));
348 else 348 else
349 inum = (i < lfsp->lfs_segtabsz + lfsp->lfs_cleansz - 1); 349 inum = (i < lfs_sb_getsegtabsz(lfsp) + lfs_sb_getcleansz(lfsp) - 1);
350 if (!inum) { 350 if (!inum) {
351 if(!do_ientries) 351 if(!do_ientries)
352 goto e1; 352 goto e1;
353 else 353 else
354 print_iheader; 354 print_iheader;
355 } 355 }
356 } else 356 } else
357 inum = dump_ipage_ifile(lfsp, inum, ipage, lfsp->lfs_ifpb); 357 inum = dump_ipage_ifile(lfsp, inum, ipage, lfs_sb_getifpb(lfsp));
358 } 358 }
359 359
360 if (nblocks <= lfsp->lfs_nindir * lfsp->lfs_ifpb) 360 if (nblocks <= lfs_sb_getnindir(lfsp) * lfs_sb_getifpb(lfsp))
361 goto e1; 361 goto e1;
362 362
363 /* Get the double indirect block */ 363 /* Get the double indirect block */
364 if (!(dindir = malloc(psize))) 364 if (!(dindir = malloc(psize)))
365 err(1, "malloc"); 365 err(1, "malloc");
366 get(fd, fsbtobyte(lfsp, dip->di_ib[1]), dindir, psize); 366 get(fd, fsbtobyte(lfsp, dip->di_ib[1]), dindir, psize);
367 for (iaddrp = dindir, j = 0; j < lfsp->lfs_nindir; j++, iaddrp++) { 367 for (iaddrp = dindir, j = 0; j < lfs_sb_getnindir(lfsp); j++, iaddrp++) {
368 if (*iaddrp == LFS_UNUSED_DADDR) 368 if (*iaddrp == LFS_UNUSED_DADDR)
369 break; 369 break;
370 get(fd, fsbtobyte(lfsp, *iaddrp), indir, psize); 370 get(fd, fsbtobyte(lfsp, *iaddrp), indir, psize);
371 block_limit = MIN(i + lfsp->lfs_nindir, nblocks); 371 block_limit = MIN(i + lfs_sb_getnindir(lfsp), nblocks);
372 for (addrp = indir; i < block_limit; i++, addrp++) { 372 for (addrp = indir; i < block_limit; i++, addrp++) {
373 if (*addrp == LFS_UNUSED_DADDR) 373 if (*addrp == LFS_UNUSED_DADDR)
374 break; 374 break;
375 get(fd, fsbtobyte(lfsp, *addrp), ipage, psize); 375 get(fd, fsbtobyte(lfsp, *addrp), ipage, psize);
376 if (i < lfsp->lfs_cleansz) { 376 if (i < lfs_sb_getcleansz(lfsp)) {
377 dump_cleaner_info(lfsp, ipage); 377 dump_cleaner_info(lfsp, ipage);
378 continue; 378 continue;
379 } 379 }
380 380
381 if (i < lfsp->lfs_segtabsz + lfsp->lfs_cleansz) { 381 if (i < lfs_sb_getsegtabsz(lfsp) + lfs_sb_getcleansz(lfsp)) {
382 if (do_segentries) 382 if (do_segentries)
383 inum = dump_ipage_segusage(lfsp, 383 inum = dump_ipage_segusage(lfsp,
384 inum, ipage, lfsp->lfs_sepb); 384 inum, ipage, lfs_sb_getsepb(lfsp));
385 else 385 else
386 inum = (i < lfsp->lfs_segtabsz + 386 inum = (i < lfs_sb_getsegtabsz(lfsp) +
387 lfsp->lfs_cleansz - 1); 387 lfs_sb_getcleansz(lfsp) - 1);
388 if (!inum) { 388 if (!inum) {
389 if(!do_ientries) 389 if(!do_ientries)
390 goto e2; 390 goto e2;
391 else 391 else
392 print_iheader; 392 print_iheader;
393 } 393 }
394 } else 394 } else
395 inum = dump_ipage_ifile(lfsp, inum, 395 inum = dump_ipage_ifile(lfsp, inum,
396 ipage, lfsp->lfs_ifpb); 396 ipage, lfs_sb_getifpb(lfsp));
397 } 397 }
398 } 398 }
399e2: free(dindir); 399e2: free(dindir);
400e1: free(indir); 400e1: free(indir);
401e0: free(dpage); 401e0: free(dpage);
402 free(ipage); 402 free(ipage);
403} 403}
404 404
405static int 405static int
406dump_ipage_ifile(struct lfs *lfsp, int i, char *pp, int tot) 406dump_ipage_ifile(struct lfs *lfsp, int i, char *pp, int tot)
407{ 407{
408 char *ip; 408 char *ip;
409 int cnt, max, entsize; 409 int cnt, max, entsize;
@@ -418,42 +418,42 @@ dump_ipage_ifile(struct lfs *lfsp, int i @@ -418,42 +418,42 @@ dump_ipage_ifile(struct lfs *lfsp, int i
418 print_ientry(cnt, (IFILE *)ip); 418 print_ientry(cnt, (IFILE *)ip);
419 return (max); 419 return (max);
420} 420}
421 421
422static int 422static int
423dump_ipage_segusage(struct lfs *lfsp, int i, char *pp, int tot) 423dump_ipage_segusage(struct lfs *lfsp, int i, char *pp, int tot)
424{ 424{
425 SEGUSE *sp; 425 SEGUSE *sp;
426 int cnt, max; 426 int cnt, max;
427 struct seglist *slp; 427 struct seglist *slp;
428 428
429 max = i + tot; 429 max = i + tot;
430 for (sp = (SEGUSE *)pp, cnt = i; 430 for (sp = (SEGUSE *)pp, cnt = i;
431 cnt < lfsp->lfs_nseg && cnt < max; cnt++) { 431 cnt < lfs_sb_getnseg(lfsp) && cnt < max; cnt++) {
432 if (seglist == NULL) 432 if (seglist == NULL)
433 print_suentry(cnt, sp, lfsp); 433 print_suentry(cnt, sp, lfsp);
434 else { 434 else {
435 for (slp = seglist; slp != NULL; slp = slp->next) 435 for (slp = seglist; slp != NULL; slp = slp->next)
436 if (cnt == slp->num) { 436 if (cnt == slp->num) {
437 print_suentry(cnt, sp, lfsp); 437 print_suentry(cnt, sp, lfsp);
438 break; 438 break;
439 } 439 }
440 } 440 }
441 if (lfsp->lfs_version > 1) 441 if (lfsp->lfs_version > 1)
442 ++sp; 442 ++sp;
443 else 443 else
444 sp = (SEGUSE *)((SEGUSE_V1 *)sp + 1); 444 sp = (SEGUSE *)((SEGUSE_V1 *)sp + 1);
445 } 445 }
446 if (max >= lfsp->lfs_nseg) 446 if (max >= lfs_sb_getnseg(lfsp))
447 return (0); 447 return (0);
448 else 448 else
449 return (max); 449 return (max);
450} 450}
451 451
452static void 452static void
453dump_dinode(struct ulfs1_dinode *dip) 453dump_dinode(struct ulfs1_dinode *dip)
454{ 454{
455 int i; 455 int i;
456 time_t at, mt, ct; 456 time_t at, mt, ct;
457 457
458 at = dip->di_atime; 458 at = dip->di_atime;
459 mt = dip->di_mtime; 459 mt = dip->di_mtime;
@@ -488,27 +488,27 @@ dump_sum(int fd, struct lfs *lfsp, SEGSU @@ -488,27 +488,27 @@ dump_sum(int fd, struct lfs *lfsp, SEGSU
488 int32_t *dp, *idp; 488 int32_t *dp, *idp;
489 int i, j, acc; 489 int i, j, acc;
490 int ck; 490 int ck;
491 int numbytes, numblocks; 491 int numbytes, numblocks;
492 char *datap; 492 char *datap;
493 struct ulfs1_dinode *inop; 493 struct ulfs1_dinode *inop;
494 size_t el_size; 494 size_t el_size;
495 u_int32_t datasum; 495 u_int32_t datasum;
496 time_t t; 496 time_t t;
497 char *buf; 497 char *buf;
498 498
499 if (sp->ss_magic != SS_MAGIC ||  499 if (sp->ss_magic != SS_MAGIC ||
500 sp->ss_sumsum != (ck = cksum(&sp->ss_datasum,  500 sp->ss_sumsum != (ck = cksum(&sp->ss_datasum,
501 lfsp->lfs_sumsize - sizeof(sp->ss_sumsum)))) { 501 lfs_sb_getsumsize(lfsp) - sizeof(sp->ss_sumsum)))) {
502 /* Don't print "corrupt" if we're just too close to the edge */ 502 /* Don't print "corrupt" if we're just too close to the edge */
503 if (lfs_dtosn(lfsp, addr + LFS_FSBTODB(lfsp, 1)) == 503 if (lfs_dtosn(lfsp, addr + LFS_FSBTODB(lfsp, 1)) ==
504 lfs_dtosn(lfsp, addr)) 504 lfs_dtosn(lfsp, addr))
505 (void)printf("dumplfs: %s %d address 0x%llx\n", 505 (void)printf("dumplfs: %s %d address 0x%llx\n",
506 "corrupt summary block; segment", segnum, 506 "corrupt summary block; segment", segnum,
507 (long long)addr); 507 (long long)addr);
508 return -1; 508 return -1;
509 } 509 }
510 if (lfsp->lfs_version > 1 && sp->ss_ident != lfsp->lfs_ident) { 510 if (lfsp->lfs_version > 1 && sp->ss_ident != lfsp->lfs_ident) {
511 (void)printf("dumplfs: %s %d address 0x%llx\n", 511 (void)printf("dumplfs: %s %d address 0x%llx\n",
512 "summary from a former life; segment", segnum, 512 "summary from a former life; segment", segnum,
513 (long long)addr); 513 (long long)addr);
514 return -1; 514 return -1;
@@ -527,36 +527,36 @@ dump_sum(int fd, struct lfs *lfsp, SEGSU @@ -527,36 +527,36 @@ dump_sum(int fd, struct lfs *lfsp, SEGSU
527 "datasum ", sp->ss_datasum ); 527 "datasum ", sp->ss_datasum );
528 if (lfsp->lfs_version == 1) { 528 if (lfsp->lfs_version == 1) {
529 t = sp->ss_ocreate; 529 t = sp->ss_ocreate;
530 (void)printf("\tcreate %s\n", ctime(&t)); 530 (void)printf("\tcreate %s\n", ctime(&t));
531 } else { 531 } else {
532 t = sp->ss_create; 532 t = sp->ss_create;
533 (void)printf("\tcreate %s", ctime(&t)); 533 (void)printf("\tcreate %s", ctime(&t));
534 (void)printf(" roll_id %-8x", sp->ss_ident); 534 (void)printf(" roll_id %-8x", sp->ss_ident);
535 (void)printf(" serial %lld\n", (long long)sp->ss_serial); 535 (void)printf(" serial %lld\n", (long long)sp->ss_serial);
536 } 536 }
537 537
538 /* Dump out inode disk addresses */ 538 /* Dump out inode disk addresses */
539 dp = (int32_t *)sp; 539 dp = (int32_t *)sp;
540 dp += lfsp->lfs_sumsize / sizeof(int32_t); 540 dp += lfs_sb_getsumsize(lfsp) / sizeof(int32_t);
541 inop = malloc(lfsp->lfs_bsize); 541 inop = malloc(lfs_sb_getbsize(lfsp));
542 printf(" Inode addresses:"); 542 printf(" Inode addresses:");
543 numbytes = 0; 543 numbytes = 0;
544 numblocks = 0; 544 numblocks = 0;
545 for (dp--, i = 0; i < sp->ss_ninos; dp--) { 545 for (dp--, i = 0; i < sp->ss_ninos; dp--) {
546 ++numblocks; 546 ++numblocks;
547 numbytes += lfsp->lfs_ibsize; /* add bytes for inode block */ 547 numbytes += lfs_sb_getibsize(lfsp); /* add bytes for inode block */
548 printf("\t0x%x {", *dp); 548 printf("\t0x%x {", *dp);
549 get(fd, fsbtobyte(lfsp, *dp), inop, lfsp->lfs_ibsize); 549 get(fd, fsbtobyte(lfsp, *dp), inop, lfs_sb_getibsize(lfsp));
550 for (j = 0; i < sp->ss_ninos && j < LFS_INOPB(lfsp); j++, i++) { 550 for (j = 0; i < sp->ss_ninos && j < LFS_INOPB(lfsp); j++, i++) {
551 if (j > 0)  551 if (j > 0)
552 (void)printf(", "); 552 (void)printf(", ");
553 (void)printf("%dv%d", inop[j].di_inumber, inop[j].di_gen); 553 (void)printf("%dv%d", inop[j].di_inumber, inop[j].di_gen);
554 } 554 }
555 (void)printf("}"); 555 (void)printf("}");
556 if (((i/LFS_INOPB(lfsp)) % 4) == 3) 556 if (((i/LFS_INOPB(lfsp)) % 4) == 3)
557 (void)printf("\n"); 557 (void)printf("\n");
558 } 558 }
559 free(inop); 559 free(inop);
560 560
561 printf("\n"); 561 printf("\n");
562 562
@@ -567,79 +567,79 @@ dump_sum(int fd, struct lfs *lfsp, SEGSU @@ -567,79 +567,79 @@ dump_sum(int fd, struct lfs *lfsp, SEGSU
567 for (i = 0; i < sp->ss_nfinfo; i++) { 567 for (i = 0; i < sp->ss_nfinfo; i++) {
568 (void)printf(" FINFO for inode: %d version %d nblocks %d lastlength %d\n", 568 (void)printf(" FINFO for inode: %d version %d nblocks %d lastlength %d\n",
569 fp->fi_ino, fp->fi_version, fp->fi_nblocks, 569 fp->fi_ino, fp->fi_version, fp->fi_nblocks,
570 fp->fi_lastlength); 570 fp->fi_lastlength);
571 dp = &(fp->fi_blocks[0]); 571 dp = &(fp->fi_blocks[0]);
572 numblocks += fp->fi_nblocks; 572 numblocks += fp->fi_nblocks;
573 for (j = 0; j < fp->fi_nblocks; j++, dp++) { 573 for (j = 0; j < fp->fi_nblocks; j++, dp++) {
574 (void)printf("\t%d", *dp); 574 (void)printf("\t%d", *dp);
575 if ((j % 8) == 7) 575 if ((j % 8) == 7)
576 (void)printf("\n"); 576 (void)printf("\n");
577 if (j == fp->fi_nblocks - 1) 577 if (j == fp->fi_nblocks - 1)
578 numbytes += fp->fi_lastlength; 578 numbytes += fp->fi_lastlength;
579 else 579 else
580 numbytes += lfsp->lfs_bsize; 580 numbytes += lfs_sb_getbsize(lfsp);
581 } 581 }
582 if ((j % 8) != 0) 582 if ((j % 8) != 0)
583 (void)printf("\n"); 583 (void)printf("\n");
584 fp = (FINFO *)dp; 584 fp = (FINFO *)dp;
585 } 585 }
586 586
587 if (datasum_check == 0) 587 if (datasum_check == 0)
588 return (numbytes); 588 return (numbytes);
589 589
590 /* 590 /*
591 * Now that we know the number of blocks, run back through and 591 * Now that we know the number of blocks, run back through and
592 * compute the data checksum. (A bad data checksum is not enough 592 * compute the data checksum. (A bad data checksum is not enough
593 * to prevent us from continuing, but it odes merit a warning.) 593 * to prevent us from continuing, but it odes merit a warning.)
594 */ 594 */
595 idp = (int32_t *)sp; 595 idp = (int32_t *)sp;
596 idp += lfsp->lfs_sumsize / sizeof(int32_t); 596 idp += lfs_sb_getsumsize(lfsp) / sizeof(int32_t);
597 --idp; 597 --idp;
598 if (lfsp->lfs_version == 1) { 598 if (lfsp->lfs_version == 1) {
599 fp = (FINFO *)((SEGSUM_V1 *)sp + 1); 599 fp = (FINFO *)((SEGSUM_V1 *)sp + 1);
600 el_size = sizeof(unsigned long); 600 el_size = sizeof(unsigned long);
601 } else { 601 } else {
602 fp = (FINFO *)(sp + 1); 602 fp = (FINFO *)(sp + 1);
603 el_size = sizeof(u_int32_t); 603 el_size = sizeof(u_int32_t);
604 } 604 }
605 datap = (char *)malloc(el_size * numblocks); 605 datap = (char *)malloc(el_size * numblocks);
606 memset(datap, 0, el_size * numblocks); 606 memset(datap, 0, el_size * numblocks);
607 acc = 0; 607 acc = 0;
608 addr += lfs_btofsb(lfsp, lfsp->lfs_sumsize); 608 addr += lfs_btofsb(lfsp, lfs_sb_getsumsize(lfsp));
609 buf = malloc(lfsp->lfs_bsize); 609 buf = malloc(lfs_sb_getbsize(lfsp));
610 for (i = 0; i < sp->ss_nfinfo; i++) { 610 for (i = 0; i < sp->ss_nfinfo; i++) {
611 while (addr == *idp) { 611 while (addr == *idp) {
612 get(fd, fsbtobyte(lfsp, addr), buf, lfsp->lfs_ibsize); 612 get(fd, fsbtobyte(lfsp, addr), buf, lfs_sb_getibsize(lfsp));
613 memcpy(datap + acc * el_size, buf, el_size); 613 memcpy(datap + acc * el_size, buf, el_size);
614 addr += lfs_btofsb(lfsp, lfsp->lfs_ibsize); 614 addr += lfs_btofsb(lfsp, lfs_sb_getibsize(lfsp));
615 --idp; 615 --idp;
616 ++acc; 616 ++acc;
617 } 617 }
618 for (j = 0; j < fp->fi_nblocks; j++) { 618 for (j = 0; j < fp->fi_nblocks; j++) {
619 get(fd, fsbtobyte(lfsp, addr), buf, lfsp->lfs_fsize); 619 get(fd, fsbtobyte(lfsp, addr), buf, lfs_sb_getfsize(lfsp));
620 memcpy(datap + acc * el_size, buf, el_size); 620 memcpy(datap + acc * el_size, buf, el_size);
621 if (j == fp->fi_nblocks - 1) 621 if (j == fp->fi_nblocks - 1)
622 addr += lfs_btofsb(lfsp, fp->fi_lastlength); 622 addr += lfs_btofsb(lfsp, fp->fi_lastlength);
623 else 623 else
624 addr += lfs_btofsb(lfsp, lfsp->lfs_bsize); 624 addr += lfs_btofsb(lfsp, lfs_sb_getbsize(lfsp));
625 ++acc; 625 ++acc;
626 } 626 }
627 fp = (FINFO *)&(fp->fi_blocks[fp->fi_nblocks]); 627 fp = (FINFO *)&(fp->fi_blocks[fp->fi_nblocks]);
628 } 628 }
629 while (addr == *idp) { 629 while (addr == *idp) {
630 get(fd, fsbtobyte(lfsp, addr), buf, lfsp->lfs_ibsize); 630 get(fd, fsbtobyte(lfsp, addr), buf, lfs_sb_getibsize(lfsp));
631 memcpy(datap + acc * el_size, buf, el_size); 631 memcpy(datap + acc * el_size, buf, el_size);
632 addr += lfs_btofsb(lfsp, lfsp->lfs_ibsize); 632 addr += lfs_btofsb(lfsp, lfs_sb_getibsize(lfsp));
633 --idp; 633 --idp;
634 ++acc; 634 ++acc;
635 } 635 }
636 free(buf); 636 free(buf);
637 if (acc != numblocks) 637 if (acc != numblocks)
638 printf("** counted %d blocks but should have been %d\n", 638 printf("** counted %d blocks but should have been %d\n",
639 acc, numblocks); 639 acc, numblocks);
640 datasum = cksum(datap, numblocks * el_size); 640 datasum = cksum(datap, numblocks * el_size);
641 if (datasum != sp->ss_datasum) 641 if (datasum != sp->ss_datasum)
642 printf("** computed datasum 0x%lx does not match given datasum 0x%lx\n", (unsigned long)datasum, (unsigned long)sp->ss_datasum); 642 printf("** computed datasum 0x%lx does not match given datasum 0x%lx\n", (unsigned long)datasum, (unsigned long)sp->ss_datasum);
643 free(datap); 643 free(datap);
644 644
645 return (numbytes); 645 return (numbytes);
@@ -648,168 +648,170 @@ dump_sum(int fd, struct lfs *lfsp, SEGSU @@ -648,168 +648,170 @@ dump_sum(int fd, struct lfs *lfsp, SEGSU
648static void 648static void
649dump_segment(int fd, int segnum, daddr_t addr, struct lfs *lfsp, int dump_sb) 649dump_segment(int fd, int segnum, daddr_t addr, struct lfs *lfsp, int dump_sb)
650{ 650{
651 struct lfs lfs_sb, *sbp; 651 struct lfs lfs_sb, *sbp;
652 SEGSUM *sump; 652 SEGSUM *sump;
653 char *sumblock; 653 char *sumblock;
654 int did_one, nbytes, sb; 654 int did_one, nbytes, sb;
655 off_t sum_offset; 655 off_t sum_offset;
656 daddr_t new_addr; 656 daddr_t new_addr;
657 657
658 (void)printf("\nSEGMENT %lld (Disk Address 0x%llx)\n", 658 (void)printf("\nSEGMENT %lld (Disk Address 0x%llx)\n",
659 (long long)lfs_dtosn(lfsp, addr), (long long)addr); 659 (long long)lfs_dtosn(lfsp, addr), (long long)addr);
660 sum_offset = fsbtobyte(lfsp, addr); 660 sum_offset = fsbtobyte(lfsp, addr);
661 sumblock = malloc(lfsp->lfs_sumsize); 661 sumblock = malloc(lfs_sb_getsumsize(lfsp));
662 662
663 if (lfsp->lfs_version > 1 && segnum == 0) { 663 if (lfsp->lfs_version > 1 && segnum == 0) {
664 if (lfs_fsbtob(lfsp, lfsp->lfs_s0addr) < LFS_LABELPAD) { 664 if (lfs_fsbtob(lfsp, lfsp->lfs_s0addr) < LFS_LABELPAD) {
665 /* First segment eats the disklabel */ 665 /* First segment eats the disklabel */
666 sum_offset += lfs_fragroundup(lfsp, LFS_LABELPAD) - 666 sum_offset += lfs_fragroundup(lfsp, LFS_LABELPAD) -
667 lfs_fsbtob(lfsp, lfsp->lfs_s0addr); 667 lfs_fsbtob(lfsp, lfsp->lfs_s0addr);
668 addr += lfs_btofsb(lfsp, lfs_fragroundup(lfsp, LFS_LABELPAD)) - 668 addr += lfs_btofsb(lfsp, lfs_fragroundup(lfsp, LFS_LABELPAD)) -
669 lfsp->lfs_s0addr; 669 lfsp->lfs_s0addr;
670 printf("Disklabel at 0x0\n"); 670 printf("Disklabel at 0x0\n");
671 } 671 }
672 } 672 }
673 673
674 sb = 0; 674 sb = 0;
675 did_one = 0; 675 did_one = 0;
676 do { 676 do {
677 get(fd, sum_offset, sumblock, lfsp->lfs_sumsize); 677 get(fd, sum_offset, sumblock, lfs_sb_getsumsize(lfsp));
678 sump = (SEGSUM *)sumblock; 678 sump = (SEGSUM *)sumblock;
679 if ((lfsp->lfs_version > 1 && 679 if ((lfsp->lfs_version > 1 &&
680 sump->ss_ident != lfsp->lfs_ident) || 680 sump->ss_ident != lfs_sb_getident(lfsp)) ||
681 sump->ss_sumsum != cksum (&sump->ss_datasum,  681 sump->ss_sumsum != cksum (&sump->ss_datasum,
682 lfsp->lfs_sumsize - sizeof(sump->ss_sumsum))) { 682 lfs_sb_getsumsize(lfsp) - sizeof(sump->ss_sumsum))) {
683 sbp = (struct lfs *)sump; 683 sbp = (struct lfs *)sump;
684 if ((sb = (sbp->lfs_magic == LFS_MAGIC))) { 684 if ((sb = (sbp->lfs_magic == LFS_MAGIC))) {
685 printf("Superblock at 0x%x\n", 685 printf("Superblock at 0x%x\n",
686 (unsigned)lfs_btofsb(lfsp, sum_offset)); 686 (unsigned)lfs_btofsb(lfsp, sum_offset));
687 if (dump_sb) { 687 if (dump_sb) {
688 get(fd, sum_offset, &(lfs_sb.lfs_dlfs), 688 get(fd, sum_offset, &(lfs_sb.lfs_dlfs),
689 sizeof(struct dlfs)); 689 sizeof(struct dlfs));
690 dump_super(&lfs_sb); 690 dump_super(&lfs_sb);
691 } 691 }
692 if (lfsp->lfs_version > 1) 692 if (lfsp->lfs_version > 1)
693 sum_offset += lfs_fragroundup(lfsp, LFS_SBPAD); 693 sum_offset += lfs_fragroundup(lfsp, LFS_SBPAD);
694 else 694 else
695 sum_offset += LFS_SBPAD; 695 sum_offset += LFS_SBPAD;
696 } else if (did_one) 696 } else if (did_one)
697 break; 697 break;
698 else { 698 else {
699 printf("Segment at 0x%llx empty or corrupt\n", 699 printf("Segment at 0x%llx empty or corrupt\n",
700 (long long)addr); 700 (long long)addr);
701 break; 701 break;
702 } 702 }
703 } else { 703 } else {
704 nbytes = dump_sum(fd, lfsp, sump, segnum,  704 nbytes = dump_sum(fd, lfsp, sump, segnum,
705 lfs_btofsb(lfsp, sum_offset)); 705 lfs_btofsb(lfsp, sum_offset));
706 if (nbytes >= 0) 706 if (nbytes >= 0)
707 sum_offset += lfsp->lfs_sumsize + nbytes; 707 sum_offset += lfs_sb_getsumsize(lfsp) + nbytes;
708 else 708 else
709 sum_offset = 0; 709 sum_offset = 0;
710 did_one = 1; 710 did_one = 1;
711 } 711 }
712 /* If the segment ends right on a boundary, it still ends */ 712 /* If the segment ends right on a boundary, it still ends */
713 new_addr = lfs_btofsb(lfsp, sum_offset); 713 new_addr = lfs_btofsb(lfsp, sum_offset);
714 /* printf("end daddr = 0x%lx\n", (long)new_addr); */ 714 /* printf("end daddr = 0x%lx\n", (long)new_addr); */
715 if (lfs_dtosn(lfsp, new_addr) != lfs_dtosn(lfsp, addr)) 715 if (lfs_dtosn(lfsp, new_addr) != lfs_dtosn(lfsp, addr))
716 break; 716 break;
717 } while (sum_offset); 717 } while (sum_offset);
718 718
719 free(sumblock); 719 free(sumblock);
720} 720}
721 721
722static void 722static void
723dump_super(struct lfs *lfsp) 723dump_super(struct lfs *lfsp)
724{ 724{
 725 time_t stamp;
725 int i; 726 int i;
726 727
727 (void)printf(" %s0x%-8x %s0x%-8x %s%-10d\n", 728 (void)printf(" %s0x%-8x %s0x%-8x %s%-10d\n",
728 "magic ", lfsp->lfs_magic, 729 "magic ", lfsp->lfs_magic,
729 "version ", lfsp->lfs_version, 730 "version ", lfsp->lfs_version,
730 "size ", lfsp->lfs_size); 731 "size ", lfs_sb_getsize(lfsp));
731 (void)printf(" %s%-10d %s%-10d %s%-10d\n", 732 (void)printf(" %s%-10d %s%-10d %s%-10d\n",
732 "ssize ", lfsp->lfs_ssize, 733 "ssize ", lfs_sb_getssize(lfsp),
733 "dsize ", lfsp->lfs_dsize, 734 "dsize ", lfs_sb_getdsize(lfsp),
734 "bsize ", lfsp->lfs_bsize); 735 "bsize ", lfs_sb_getbsize(lfsp));
735 (void)printf(" %s%-10d %s%-10d %s%-10d\n", 736 (void)printf(" %s%-10d %s%-10d %s%-10d\n",
736 "fsize ", lfsp->lfs_fsize, 737 "fsize ", lfs_sb_getfsize(lfsp),
737 "frag ", lfsp->lfs_frag, 738 "frag ", lfs_sb_getfrag(lfsp),
738 "minfree ", lfsp->lfs_minfree); 739 "minfree ", lfs_sb_getminfree(lfsp));
739 (void)printf(" %s%-10d %s%-10d %s%-10d\n", 740 (void)printf(" %s%-10d %s%-10d %s%-10d\n",
740 "inopb ", lfsp->lfs_inopb, 741 "inopb ", lfs_sb_getinopb(lfsp),
741 "ifpb ", lfsp->lfs_ifpb, 742 "ifpb ", lfs_sb_getifpb(lfsp),
742 "nindir ", lfsp->lfs_nindir); 743 "nindir ", lfs_sb_getnindir(lfsp));
743 (void)printf(" %s%-10d %s%-10d %s%-10d\n", 744 (void)printf(" %s%-10d %s%-10d %s%-10d\n",
744 "nseg ", lfsp->lfs_nseg, 745 "nseg ", lfs_sb_getnseg(lfsp),
745 "sepb ", lfsp->lfs_sepb, 746 "sepb ", lfs_sb_getsepb(lfsp),
746 "cleansz ", lfsp->lfs_cleansz); 747 "cleansz ", lfs_sb_getcleansz(lfsp));
747 (void)printf(" %s%-10d %s0x%-8x %s%-10d\n", 748 (void)printf(" %s%-10d %s0x%-8x %s%-10d\n",
748 "segtabsz ", lfsp->lfs_segtabsz, 749 "segtabsz ", lfs_sb_getsegtabsz(lfsp),
749 "segmask ", lfsp->lfs_segmask, 750 "segmask ", lfs_sb_getsegmask(lfsp),
750 "segshift ", lfsp->lfs_segshift); 751 "segshift ", lfs_sb_getsegshift(lfsp));
751 (void)printf(" %s0x%-8qx %s%-10d %s0x%-8qX\n", 752 (void)printf(" %s0x%-8jx %s%-10d %s0x%-8jX\n",
752 "bmask ", (long long)lfsp->lfs_bmask, 753 "bmask ", (uintmax_t)lfs_sb_getbmask(lfsp),
753 "bshift ", lfsp->lfs_bshift, 754 "bshift ", lfs_sb_getbshift(lfsp),
754 "ffmask ", (long long)lfsp->lfs_ffmask); 755 "ffmask ", (uintmax_t)lfs_sb_getffmask(lfsp));
755 (void)printf(" %s%-10d %s0x%-8qx %s%u\n", 756 (void)printf(" %s%-10d %s0x%-8jx %s%u\n",
756 "ffshift ", lfsp->lfs_ffshift, 757 "ffshift ", lfs_sb_getffshift(lfsp),
757 "fbmask ", (long long)lfsp->lfs_fbmask, 758 "fbmask ", (uintmax_t)lfs_sb_getfbmask(lfsp),
758 "fbshift ", lfsp->lfs_fbshift); 759 "fbshift ", lfs_sb_getfbshift(lfsp));
759  760
760 (void)printf(" %s%-10d %s%-10d %s0x%-8x\n", 761 (void)printf(" %s%-10d %s%-10d %s0x%-8x\n",
761 "sushift ", lfsp->lfs_sushift, 762 "sushift ", lfs_sb_getsushift(lfsp),
762 "fsbtodb ", lfsp->lfs_fsbtodb, 763 "fsbtodb ", lfs_sb_getfsbtodb(lfsp),
763 "cksum ", lfsp->lfs_cksum); 764 "cksum ", lfs_sb_getcksum(lfsp));
764 (void)printf(" %s%-10d %s%-10d %s%-10d\n", 765 (void)printf(" %s%-10d %s%-10d %s%-10d\n",
765 "nclean ", lfsp->lfs_nclean, 766 "nclean ", lfs_sb_getnclean(lfsp),
766 "dmeta ", lfsp->lfs_dmeta, 767 "dmeta ", lfs_sb_getdmeta(lfsp),
767 "minfreeseg ", lfsp->lfs_minfreeseg); 768 "minfreeseg ", lfs_sb_getminfreeseg(lfsp));
768 (void)printf(" %s0x%-8x %s%-9d %s%-10d\n", 769 (void)printf(" %s0x%-8x %s%-9d %s%-10d\n",
769 "roll_id ", lfsp->lfs_ident, 770 "roll_id ", lfs_sb_getident(lfsp),
770 "interleave ", lfsp->lfs_interleave, 771 "interleave ", lfs_sb_getinterleave(lfsp),
771 "sumsize ", lfsp->lfs_sumsize); 772 "sumsize ", lfs_sb_getsumsize(lfsp));
772 (void)printf(" %s%-10d %s0x%-8qx\n", 773 (void)printf(" %s%-10d %s0x%-8jx\n",
773 "seg0addr ", lfsp->lfs_s0addr, 774 "seg0addr ", lfsp->lfs_s0addr,
774 "maxfilesize ", (long long)lfsp->lfs_maxfilesize); 775 "maxfilesize ", (uintmax_t)lfs_sb_getmaxfilesize(lfsp));
775  776
776  777
777 (void)printf(" Superblock disk addresses:\n "); 778 (void)printf(" Superblock disk addresses:\n ");
778 for (i = 0; i < LFS_MAXNUMSB; i++) { 779 for (i = 0; i < LFS_MAXNUMSB; i++) {
779 (void)printf(" 0x%-8x", lfsp->lfs_sboffs[i]); 780 (void)printf(" 0x%-8x", lfsp->lfs_sboffs[i]);
780 if (i == (LFS_MAXNUMSB >> 1)) 781 if (i == (LFS_MAXNUMSB >> 1))
781 (void)printf("\n "); 782 (void)printf("\n ");
782 } 783 }
783 (void)printf("\n"); 784 (void)printf("\n");
784  785
785 (void)printf(" Checkpoint Info\n"); 786 (void)printf(" Checkpoint Info\n");
786 (void)printf(" %s%-10d %s0x%-8x %s%-10d\n", 787 (void)printf(" %s%-10d %s0x%-8x %s%-10d\n",
787 "freehd ", lfsp->lfs_freehd, 788 "freehd ", lfs_sb_getfreehd(lfsp),
788 "idaddr ", lfsp->lfs_idaddr, 789 "idaddr ", lfs_sb_getidaddr(lfsp),
789 "ifile ", lfsp->lfs_ifile); 790 "ifile ", lfs_sb_getifile(lfsp));
790 (void)printf(" %s%-10d %s%-10d %s%-10d\n", 791 (void)printf(" %s%-10d %s%-10d %s%-10d\n",
791 "uinodes ", lfsp->lfs_uinodes, 792 "uinodes ", lfs_sb_getuinodes(lfsp),
792 "bfree ", lfsp->lfs_bfree, 793 "bfree ", lfs_sb_getbfree(lfsp),
793 "avail ", lfsp->lfs_avail); 794 "avail ", lfs_sb_getavail(lfsp));
794 (void)printf(" %s%-10d %s0x%-8x %s0x%-8x\n", 795 (void)printf(" %s%-10d %s0x%-8x %s0x%-8x\n",
795 "nfiles ", lfsp->lfs_nfiles, 796 "nfiles ", lfs_sb_getnfiles(lfsp),
796 "lastseg ", lfsp->lfs_lastseg, 797 "lastseg ", lfs_sb_getlastseg(lfsp),
797 "nextseg ", lfsp->lfs_nextseg); 798 "nextseg ", lfs_sb_getnextseg(lfsp));
798 (void)printf(" %s0x%-8x %s0x%-8x %s%-10lld\n", 799 (void)printf(" %s0x%-8x %s0x%-8x %s%-10ju\n",
799 "curseg ", lfsp->lfs_curseg, 800 "curseg ", lfs_sb_getcurseg(lfsp),
800 "offset ", lfsp->lfs_offset, 801 "offset ", lfs_sb_getoffset(lfsp),
801 "serial ", (long long)lfsp->lfs_serial); 802 "serial ", (uintmax_t)lfs_sb_getserial(lfsp));
802 (void)printf(" tstamp %s", ctime((time_t *)&lfsp->lfs_tstamp)); 803 stamp = lfs_sb_gettstamp(lfsp);
 804 (void)printf(" tstamp %s", ctime(&stamp));
803} 805}
804 806
805static void 807static void
806addseg(char *arg) 808addseg(char *arg)
807{ 809{
808 SEGLIST *p; 810 SEGLIST *p;
809 811
810 if ((p = malloc(sizeof(SEGLIST))) == NULL) 812 if ((p = malloc(sizeof(SEGLIST))) == NULL)
811 err(1, "malloc"); 813 err(1, "malloc");
812 p->next = seglist; 814 p->next = seglist;
813 p->num = atoi(arg); 815 p->num = atoi(arg);
814 seglist = p; 816 seglist = p;
815} 817}