Module Name:    src
Committed By:   dholland
Date:           Tue Jul 28 05:09:35 UTC 2015

Modified Files:
        src/distrib/sets/lists/comp: mi
        src/libexec/lfs_cleanerd: cleaner.h coalesce.c
        src/sbin/dump: dump.h
        src/sbin/fsck_lfs: dir.c inode.c lfs.c main.c pass0.c pass1.c pass4.c
            pass5.c pass6.c segwrite.c setup.c utilities.c
        src/sbin/newfs_lfs: make_lfs.c
        src/sbin/resize_lfs: resize_lfs.c
        src/sbin/scan_ffs: scan_ffs.c
        src/sys/lib/libsa: ufs.c
        src/sys/ufs/lfs: Makefile lfs.h lfs_alloc.c lfs_balloc.c lfs_bio.c
            lfs_debug.c lfs_inode.c lfs_itimes.c lfs_pages.c lfs_rfw.c
            lfs_segment.c lfs_subr.c lfs_syscalls.c lfs_vfsops.c lfs_vnops.c
            ulfs_quota2.c
        src/usr.sbin/dumplfs: dumplfs.c
Added Files:
        src/sys/ufs/lfs: lfs_accessors.h

Log Message:
Add a new lfs header file: lfs_accessors.h.

This contains all the accessor functions and macros out of lfs.h.
Add an include of lfs_accessors.h after all uses of lfs.h... except
for code that wants to define its own struct lfs-alike that the
accessors are supposed to play along with. For these, set STRUCT_LFS
and include lfs_accessors.h after the necessary structure has been
defined, so that lfs_accessors.h can emit functions in terms of it.


To generate a diff of this commit:
cvs rdiff -u -r1.1972 -r1.1973 src/distrib/sets/lists/comp/mi
cvs rdiff -u -r1.7 -r1.8 src/libexec/lfs_cleanerd/cleaner.h
cvs rdiff -u -r1.26 -r1.27 src/libexec/lfs_cleanerd/coalesce.c
cvs rdiff -u -r1.51 -r1.52 src/sbin/dump/dump.h
cvs rdiff -u -r1.34 -r1.35 src/sbin/fsck_lfs/dir.c
cvs rdiff -u -r1.56 -r1.57 src/sbin/fsck_lfs/inode.c
cvs rdiff -u -r1.47 -r1.48 src/sbin/fsck_lfs/lfs.c
cvs rdiff -u -r1.51 -r1.52 src/sbin/fsck_lfs/main.c
cvs rdiff -u -r1.36 -r1.37 src/sbin/fsck_lfs/pass0.c \
    src/sbin/fsck_lfs/pass6.c
cvs rdiff -u -r1.39 -r1.40 src/sbin/fsck_lfs/pass1.c \
    src/sbin/fsck_lfs/utilities.c
cvs rdiff -u -r1.24 -r1.25 src/sbin/fsck_lfs/pass4.c
cvs rdiff -u -r1.31 -r1.32 src/sbin/fsck_lfs/pass5.c
cvs rdiff -u -r1.33 -r1.34 src/sbin/fsck_lfs/segwrite.c
cvs rdiff -u -r1.48 -r1.49 src/sbin/fsck_lfs/setup.c
cvs rdiff -u -r1.33 -r1.34 src/sbin/newfs_lfs/make_lfs.c
cvs rdiff -u -r1.11 -r1.12 src/sbin/resize_lfs/resize_lfs.c
cvs rdiff -u -r1.27 -r1.28 src/sbin/scan_ffs/scan_ffs.c
cvs rdiff -u -r1.67 -r1.68 src/sys/lib/libsa/ufs.c
cvs rdiff -u -r1.2 -r1.3 src/sys/ufs/lfs/Makefile
cvs rdiff -u -r1.165 -r1.166 src/sys/ufs/lfs/lfs.h
cvs rdiff -u -r0 -r1.1 src/sys/ufs/lfs/lfs_accessors.h
cvs rdiff -u -r1.123 -r1.124 src/sys/ufs/lfs/lfs_alloc.c
cvs rdiff -u -r1.83 -r1.84 src/sys/ufs/lfs/lfs_balloc.c \
    src/sys/ufs/lfs/lfs_subr.c
cvs rdiff -u -r1.131 -r1.132 src/sys/ufs/lfs/lfs_bio.c
cvs rdiff -u -r1.45 -r1.46 src/sys/ufs/lfs/lfs_debug.c
cvs rdiff -u -r1.139 -r1.140 src/sys/ufs/lfs/lfs_inode.c
cvs rdiff -u -r1.15 -r1.16 src/sys/ufs/lfs/lfs_itimes.c
cvs rdiff -u -r1.4 -r1.5 src/sys/ufs/lfs/lfs_pages.c
cvs rdiff -u -r1.23 -r1.24 src/sys/ufs/lfs/lfs_rfw.c
cvs rdiff -u -r1.244 -r1.245 src/sys/ufs/lfs/lfs_segment.c
cvs rdiff -u -r1.162 -r1.163 src/sys/ufs/lfs/lfs_syscalls.c
cvs rdiff -u -r1.328 -r1.329 src/sys/ufs/lfs/lfs_vfsops.c
cvs rdiff -u -r1.277 -r1.278 src/sys/ufs/lfs/lfs_vnops.c
cvs rdiff -u -r1.20 -r1.21 src/sys/ufs/lfs/ulfs_quota2.c
cvs rdiff -u -r1.44 -r1.45 src/usr.sbin/dumplfs/dumplfs.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/comp/mi
diff -u src/distrib/sets/lists/comp/mi:1.1972 src/distrib/sets/lists/comp/mi:1.1973
--- src/distrib/sets/lists/comp/mi:1.1972	Sun Jul 26 02:20:30 2015
+++ src/distrib/sets/lists/comp/mi	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-#	$NetBSD: mi,v 1.1972 2015/07/26 02:20:30 kamil Exp $
+#	$NetBSD: mi,v 1.1973 2015/07/28 05:09:34 dholland Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -3394,6 +3394,7 @@
 ./usr/include/ufs/ffs/ffs_extern.h		comp-c-include
 ./usr/include/ufs/ffs/fs.h			comp-c-include
 ./usr/include/ufs/lfs/lfs.h			comp-c-include
+./usr/include/ufs/lfs/lfs_accessors.h		comp-c-include
 ./usr/include/ufs/lfs/lfs_extern.h		comp-c-include
 ./usr/include/ufs/lfs/lfs_inode.h		comp-c-include
 ./usr/include/ufs/mfs/mfs_extern.h		comp-c-include

Index: src/libexec/lfs_cleanerd/cleaner.h
diff -u src/libexec/lfs_cleanerd/cleaner.h:1.7 src/libexec/lfs_cleanerd/cleaner.h:1.8
--- src/libexec/lfs_cleanerd/cleaner.h:1.7	Fri Jul 24 06:59:31 2015
+++ src/libexec/lfs_cleanerd/cleaner.h	Tue Jul 28 05:09:34 2015
@@ -37,6 +37,9 @@ struct clfs {
 	int clfs_onhold;	   /* If cleaning this fs is on hold */
 };
 
+// XXX temporary
+#include <ufs/lfs/lfs_accessors.h>
+
 /* ugh... */
 #define CLFS_DEF_SB_ACCESSOR(type, field) \
 	static __unused inline type				\
@@ -115,6 +118,12 @@ clfs_sb_getfsmnt(struct clfs *fs)
 #define lfs_sb_getfsmnt(fs) clfs_sb_getfsmnt(fs)
 
 /*
+ * This needs to come after the definition of struct clfs. (XXX blah)
+ */
+//#define STRUCT_LFS struct clfs
+//#include <ufs/lfs/lfs_accessors.h>
+
+/*
  * Fraction of the could-be-clean segments required to be clean.
  */
 #define BUSY_LIM 0.5

Index: src/libexec/lfs_cleanerd/coalesce.c
diff -u src/libexec/lfs_cleanerd/coalesce.c:1.26 src/libexec/lfs_cleanerd/coalesce.c:1.27
--- src/libexec/lfs_cleanerd/coalesce.c:1.26	Fri Jul 24 06:59:31 2015
+++ src/libexec/lfs_cleanerd/coalesce.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/*      $NetBSD: coalesce.c,v 1.26 2015/07/24 06:59:31 dholland Exp $  */
+/*      $NetBSD: coalesce.c,v 1.27 2015/07/28 05:09:34 dholland Exp $  */
 
 /*-
  * Copyright (c) 2002, 2005 The NetBSD Foundation, Inc.
@@ -38,6 +38,7 @@
 #include <sys/mman.h>
 
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 
 #include <fcntl.h>
 #include <signal.h>

Index: src/sbin/dump/dump.h
diff -u src/sbin/dump/dump.h:1.51 src/sbin/dump/dump.h:1.52
--- src/sbin/dump/dump.h:1.51	Sat Jun 15 01:27:19 2013
+++ src/sbin/dump/dump.h	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: dump.h,v 1.51 2013/06/15 01:27:19 christos Exp $	*/
+/*	$NetBSD: dump.h,v 1.52 2015/07/28 05:09:34 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1980, 1993
@@ -34,6 +34,7 @@
 #include <machine/bswap.h>
 #ifdef DUMP_LFS
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #endif
 #include <ufs/ufs/dinode.h>
 #include <protocols/dumprestore.h>

Index: src/sbin/fsck_lfs/dir.c
diff -u src/sbin/fsck_lfs/dir.c:1.34 src/sbin/fsck_lfs/dir.c:1.35
--- src/sbin/fsck_lfs/dir.c:1.34	Fri Jul 24 06:56:41 2015
+++ src/sbin/fsck_lfs/dir.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: dir.c,v 1.34 2015/07/24 06:56:41 dholland Exp $	 */
+/* $NetBSD: dir.c,v 1.35 2015/07/28 05:09:34 dholland Exp $	 */
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -36,6 +36,7 @@
 #include <sys/mount.h>
 
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_inode.h>
 
 #include <err.h>

Index: src/sbin/fsck_lfs/inode.c
diff -u src/sbin/fsck_lfs/inode.c:1.56 src/sbin/fsck_lfs/inode.c:1.57
--- src/sbin/fsck_lfs/inode.c:1.56	Fri Jul 24 06:59:32 2015
+++ src/sbin/fsck_lfs/inode.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: inode.c,v 1.56 2015/07/24 06:59:32 dholland Exp $	 */
+/* $NetBSD: inode.c,v 1.57 2015/07/28 05:09:34 dholland Exp $	 */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -66,6 +66,7 @@
 
 #define vnode uvnode
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_inode.h>
 #undef vnode
 

Index: src/sbin/fsck_lfs/lfs.c
diff -u src/sbin/fsck_lfs/lfs.c:1.47 src/sbin/fsck_lfs/lfs.c:1.48
--- src/sbin/fsck_lfs/lfs.c:1.47	Fri Jul 24 06:59:32 2015
+++ src/sbin/fsck_lfs/lfs.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: lfs.c,v 1.47 2015/07/24 06:59:32 dholland Exp $ */
+/* $NetBSD: lfs.c,v 1.48 2015/07/28 05:09:34 dholland Exp $ */
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -72,6 +72,7 @@
 
 #define vnode uvnode
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_inode.h>
 #undef vnode
 

Index: src/sbin/fsck_lfs/main.c
diff -u src/sbin/fsck_lfs/main.c:1.51 src/sbin/fsck_lfs/main.c:1.52
--- src/sbin/fsck_lfs/main.c:1.51	Fri Jul 24 06:59:32 2015
+++ src/sbin/fsck_lfs/main.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.51 2015/07/24 06:59:32 dholland Exp $	 */
+/* $NetBSD: main.c,v 1.52 2015/07/28 05:09:34 dholland Exp $	 */
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -32,7 +32,9 @@
 #include <sys/param.h>
 #include <sys/time.h>
 #include <sys/mount.h>
+
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 
 #include <fstab.h>
 #include <stdbool.h>

Index: src/sbin/fsck_lfs/pass0.c
diff -u src/sbin/fsck_lfs/pass0.c:1.36 src/sbin/fsck_lfs/pass0.c:1.37
--- src/sbin/fsck_lfs/pass0.c:1.36	Fri Jul 24 06:56:41 2015
+++ src/sbin/fsck_lfs/pass0.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: pass0.c,v 1.36 2015/07/24 06:56:41 dholland Exp $	 */
+/* $NetBSD: pass0.c,v 1.37 2015/07/28 05:09:34 dholland Exp $	 */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -65,6 +65,7 @@
 
 #define vnode uvnode
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_inode.h>
 #undef vnode
 
Index: src/sbin/fsck_lfs/pass6.c
diff -u src/sbin/fsck_lfs/pass6.c:1.36 src/sbin/fsck_lfs/pass6.c:1.37
--- src/sbin/fsck_lfs/pass6.c:1.36	Fri Jul 24 06:59:32 2015
+++ src/sbin/fsck_lfs/pass6.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: pass6.c,v 1.36 2015/07/24 06:59:32 dholland Exp $	 */
+/* $NetBSD: pass6.c,v 1.37 2015/07/28 05:09:34 dholland Exp $	 */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -38,6 +38,7 @@
 #define VU_DIROP 0x01000000 /* XXX XXX from sys/vnode.h */
 #define vnode uvnode
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_inode.h>
 #undef vnode
 

Index: src/sbin/fsck_lfs/pass1.c
diff -u src/sbin/fsck_lfs/pass1.c:1.39 src/sbin/fsck_lfs/pass1.c:1.40
--- src/sbin/fsck_lfs/pass1.c:1.39	Fri Jul 24 06:59:32 2015
+++ src/sbin/fsck_lfs/pass1.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: pass1.c,v 1.39 2015/07/24 06:59:32 dholland Exp $	 */
+/* $NetBSD: pass1.c,v 1.40 2015/07/28 05:09:34 dholland Exp $	 */
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -36,6 +36,7 @@
 
 #define vnode uvnode
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_inode.h>
 #undef vnode
 
Index: src/sbin/fsck_lfs/utilities.c
diff -u src/sbin/fsck_lfs/utilities.c:1.39 src/sbin/fsck_lfs/utilities.c:1.40
--- src/sbin/fsck_lfs/utilities.c:1.39	Fri Jul 24 06:59:32 2015
+++ src/sbin/fsck_lfs/utilities.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: utilities.c,v 1.39 2015/07/24 06:59:32 dholland Exp $	 */
+/* $NetBSD: utilities.c,v 1.40 2015/07/28 05:09:34 dholland Exp $	 */
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -36,6 +36,7 @@
 #define buf ubuf
 #define vnode uvnode
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 
 #include <err.h>
 #include <stdio.h>

Index: src/sbin/fsck_lfs/pass4.c
diff -u src/sbin/fsck_lfs/pass4.c:1.24 src/sbin/fsck_lfs/pass4.c:1.25
--- src/sbin/fsck_lfs/pass4.c:1.24	Fri Jul 24 06:56:41 2015
+++ src/sbin/fsck_lfs/pass4.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: pass4.c,v 1.24 2015/07/24 06:56:41 dholland Exp $	 */
+/* $NetBSD: pass4.c,v 1.25 2015/07/28 05:09:34 dholland Exp $	 */
 
 /*
  * Copyright (c) 1980, 1986, 1993
@@ -37,6 +37,7 @@
 #define buf ubuf
 #define panic call_panic
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_inode.h>
 
 #include <err.h>

Index: src/sbin/fsck_lfs/pass5.c
diff -u src/sbin/fsck_lfs/pass5.c:1.31 src/sbin/fsck_lfs/pass5.c:1.32
--- src/sbin/fsck_lfs/pass5.c:1.31	Fri Jul 24 06:59:32 2015
+++ src/sbin/fsck_lfs/pass5.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: pass5.c,v 1.31 2015/07/24 06:59:32 dholland Exp $	 */
+/* $NetBSD: pass5.c,v 1.32 2015/07/28 05:09:34 dholland Exp $	 */
 
 /*-
  * Copyright (c) 2000, 2003 The NetBSD Foundation, Inc.
@@ -37,6 +37,7 @@
 
 #define vnode uvnode
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_inode.h>
 #undef vnode
 

Index: src/sbin/fsck_lfs/segwrite.c
diff -u src/sbin/fsck_lfs/segwrite.c:1.33 src/sbin/fsck_lfs/segwrite.c:1.34
--- src/sbin/fsck_lfs/segwrite.c:1.33	Fri Jul 24 06:59:32 2015
+++ src/sbin/fsck_lfs/segwrite.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: segwrite.c,v 1.33 2015/07/24 06:59:32 dholland Exp $ */
+/* $NetBSD: segwrite.c,v 1.34 2015/07/28 05:09:34 dholland Exp $ */
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -74,6 +74,7 @@
 #define panic call_panic
 
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_inode.h>
 
 #include <assert.h>

Index: src/sbin/fsck_lfs/setup.c
diff -u src/sbin/fsck_lfs/setup.c:1.48 src/sbin/fsck_lfs/setup.c:1.49
--- src/sbin/fsck_lfs/setup.c:1.48	Fri Jul 24 06:59:32 2015
+++ src/sbin/fsck_lfs/setup.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: setup.c,v 1.48 2015/07/24 06:59:32 dholland Exp $ */
+/* $NetBSD: setup.c,v 1.49 2015/07/28 05:09:34 dholland Exp $ */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -73,6 +73,7 @@
 
 #define vnode uvnode
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_inode.h>
 #undef vnode
 

Index: src/sbin/newfs_lfs/make_lfs.c
diff -u src/sbin/newfs_lfs/make_lfs.c:1.33 src/sbin/newfs_lfs/make_lfs.c:1.34
--- src/sbin/newfs_lfs/make_lfs.c:1.33	Fri Jul 24 06:59:32 2015
+++ src/sbin/newfs_lfs/make_lfs.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: make_lfs.c,v 1.33 2015/07/24 06:59:32 dholland Exp $	*/
+/*	$NetBSD: make_lfs.c,v 1.34 2015/07/28 05:09:34 dholland Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
 #if 0
 static char sccsid[] = "@(#)lfs.c	8.5 (Berkeley) 5/24/95";
 #else
-__RCSID("$NetBSD: make_lfs.c,v 1.33 2015/07/24 06:59:32 dholland Exp $");
+__RCSID("$NetBSD: make_lfs.c,v 1.34 2015/07/28 05:09:34 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -81,6 +81,7 @@ __RCSID("$NetBSD: make_lfs.c,v 1.33 2015
 # define buf ubuf
 # define panic call_panic
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_inode.h>
 
 #include <err.h>

Index: src/sbin/resize_lfs/resize_lfs.c
diff -u src/sbin/resize_lfs/resize_lfs.c:1.11 src/sbin/resize_lfs/resize_lfs.c:1.12
--- src/sbin/resize_lfs/resize_lfs.c:1.11	Fri Jul 24 06:59:32 2015
+++ src/sbin/resize_lfs/resize_lfs.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize_lfs.c,v 1.11 2015/07/24 06:59:32 dholland Exp $	*/
+/*	$NetBSD: resize_lfs.c,v 1.12 2015/07/28 05:09:34 dholland Exp $	*/
 /*-
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -40,6 +40,7 @@
 
 #include <ufs/ufs/dinode.h>
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 
 #include <disktab.h>
 #include <err.h>

Index: src/sbin/scan_ffs/scan_ffs.c
diff -u src/sbin/scan_ffs/scan_ffs.c:1.27 src/sbin/scan_ffs/scan_ffs.c:1.28
--- src/sbin/scan_ffs/scan_ffs.c:1.27	Fri Jul 24 06:59:32 2015
+++ src/sbin/scan_ffs/scan_ffs.c	Tue Jul 28 05:09:35 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: scan_ffs.c,v 1.27 2015/07/24 06:59:32 dholland Exp $ */
+/* $NetBSD: scan_ffs.c,v 1.28 2015/07/28 05:09:35 dholland Exp $ */
 
 /*
  * Copyright (c) 2005-2007 Juan Romero Pardines
@@ -33,7 +33,7 @@
  
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: scan_ffs.c,v 1.27 2015/07/24 06:59:32 dholland Exp $");
+__RCSID("$NetBSD: scan_ffs.c,v 1.28 2015/07/28 05:09:35 dholland Exp $");
 #endif /* not lint */
 
 #include <sys/types.h>
@@ -45,6 +45,7 @@ __RCSID("$NetBSD: scan_ffs.c,v 1.27 2015
 #include <sys/mount.h>
 
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_extern.h>
 
 #include <ufs/ufs/dinode.h>

Index: src/sys/lib/libsa/ufs.c
diff -u src/sys/lib/libsa/ufs.c:1.67 src/sys/lib/libsa/ufs.c:1.68
--- src/sys/lib/libsa/ufs.c:1.67	Fri Jul 24 06:56:42 2015
+++ src/sys/lib/libsa/ufs.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs.c,v 1.67 2015/07/24 06:56:42 dholland Exp $	*/
+/*	$NetBSD: ufs.c,v 1.68 2015/07/28 05:09:34 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1993
@@ -70,8 +70,9 @@
 #include <sys/queue.h>
 #include <sys/condvar.h>
 #include <sys/mount.h>			/* XXX for MNAMELEN */
-#define STRUCT_LFS struct salfs
 #include <ufs/lfs/lfs.h>
+#define STRUCT_LFS struct salfs
+#include <ufs/lfs/lfs_accessors.h>
 #else
 #include <ufs/ffs/fs.h>
 #endif

Index: src/sys/ufs/lfs/Makefile
diff -u src/sys/ufs/lfs/Makefile:1.2 src/sys/ufs/lfs/Makefile:1.3
--- src/sys/ufs/lfs/Makefile:1.2	Sat Jun  8 02:04:31 2013
+++ src/sys/ufs/lfs/Makefile	Tue Jul 28 05:09:34 2015
@@ -1,7 +1,7 @@
-#	$NetBSD: Makefile,v 1.2 2013/06/08 02:04:31 dholland Exp $
+#	$NetBSD: Makefile,v 1.3 2015/07/28 05:09:34 dholland Exp $
 
 INCSDIR= /usr/include/ufs/lfs
 
-INCS=	lfs.h lfs_inode.h lfs_extern.h
+INCS=	lfs.h lfs_accessors.h lfs_inode.h lfs_extern.h
 
 .include <bsd.kinc.mk>

Index: src/sys/ufs/lfs/lfs.h
diff -u src/sys/ufs/lfs/lfs.h:1.165 src/sys/ufs/lfs/lfs.h:1.166
--- src/sys/ufs/lfs/lfs.h:1.165	Fri Jul 24 06:59:32 2015
+++ src/sys/ufs/lfs/lfs.h	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs.h,v 1.165 2015/07/24 06:59:32 dholland Exp $	*/
+/*	$NetBSD: lfs.h,v 1.166 2015/07/28 05:09:34 dholland Exp $	*/
 
 /*  from NetBSD: dinode.h,v 1.22 2013/01/22 09:39:18 dholland Exp  */
 /*  from NetBSD: dir.h,v 1.21 2009/07/22 04:49:19 dholland Exp  */
@@ -425,16 +425,6 @@ struct ulfs2_dinode {
 #define	LFS_IFWHT	0160000		/* Whiteout. */
 
 /*
- * Maximum length of a symlink that can be stored within the inode.
- */
-#define ULFS1_MAXSYMLINKLEN	((ULFS_NDADDR + ULFS_NIADDR) * sizeof(int32_t))
-#define ULFS2_MAXSYMLINKLEN	((ULFS_NDADDR + ULFS_NIADDR) * sizeof(int64_t))
-
-#define ULFS_MAXSYMLINKLEN(ip) \
-	((ip)->i_ump->um_fstype == ULFS1) ? \
-	ULFS1_MAXSYMLINKLEN : ULFS2_MAXSYMLINKLEN
-
-/*
  * "struct buf" associated definitions
  */
 
@@ -445,29 +435,6 @@ struct ulfs2_dinode {
 /* Unused logical block number */
 #define LFS_UNUSED_LBN	-1
 
-# define LFS_LOCK_BUF(bp) do {						\
-	if (((bp)->b_flags & B_LOCKED) == 0 && bp->b_iodone == NULL) {	\
-		mutex_enter(&lfs_lock);					\
-		++locked_queue_count;					\
-		locked_queue_bytes += bp->b_bufsize;			\
-		mutex_exit(&lfs_lock);					\
-	}								\
-	(bp)->b_flags |= B_LOCKED;					\
-} while (0)
-
-# define LFS_UNLOCK_BUF(bp) do {					\
-	if (((bp)->b_flags & B_LOCKED) != 0 && bp->b_iodone == NULL) {	\
-		mutex_enter(&lfs_lock);					\
-		--locked_queue_count;					\
-		locked_queue_bytes -= bp->b_bufsize;			\
-		if (locked_queue_count < LFS_WAIT_BUFS &&		\
-		    locked_queue_bytes < LFS_WAIT_BYTES)		\
-			cv_broadcast(&locked_queue_cv);			\
-		mutex_exit(&lfs_lock);					\
-	}								\
-	(bp)->b_flags &= ~B_LOCKED;					\
-} while (0)
-
 /*
  * "struct inode" associated definitions
  */
@@ -475,33 +442,6 @@ struct ulfs2_dinode {
 /* For convenience */
 #define IN_ALLMOD (IN_MODIFIED|IN_ACCESS|IN_CHANGE|IN_UPDATE|IN_MODIFY|IN_ACCESSED|IN_CLEANING)
 
-#define LFS_SET_UINO(ip, flags) do {					\
-	if (((flags) & IN_ACCESSED) && !((ip)->i_flag & IN_ACCESSED))	\
-		lfs_sb_adduinodes((ip)->i_lfs, 1);			\
-	if (((flags) & IN_CLEANING) && !((ip)->i_flag & IN_CLEANING))	\
-		lfs_sb_adduinodes((ip)->i_lfs, 1);			\
-	if (((flags) & IN_MODIFIED) && !((ip)->i_flag & IN_MODIFIED))	\
-		lfs_sb_adduinodes((ip)->i_lfs, 1);			\
-	(ip)->i_flag |= (flags);					\
-} while (0)
-
-#define LFS_CLR_UINO(ip, flags) do {					\
-	if (((flags) & IN_ACCESSED) && ((ip)->i_flag & IN_ACCESSED))	\
-		lfs_sb_subuinodes((ip)->i_lfs, 1);			\
-	if (((flags) & IN_CLEANING) && ((ip)->i_flag & IN_CLEANING))	\
-		lfs_sb_subuinodes((ip)->i_lfs, 1);			\
-	if (((flags) & IN_MODIFIED) && ((ip)->i_flag & IN_MODIFIED))	\
-		lfs_sb_subuinodes((ip)->i_lfs, 1);			\
-	(ip)->i_flag &= ~(flags);					\
-	if (lfs_sb_getuinodes((ip)->i_lfs) < 0) {			\
-		panic("lfs_uinodes < 0");				\
-	}								\
-} while (0)
-
-#define LFS_ITIMES(ip, acc, mod, cre) \
-	while ((ip)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY)) \
-		lfs_itimes(ip, acc, mod, cre)
-
 /*
  * On-disk and in-memory checkpoint segment usage structure.
  */
@@ -531,50 +471,6 @@ struct segusage_v1 {
 	u_int32_t su_flags;		/* 12: segment flags  */
 };
 
-#define	SEGUPB(fs)	(lfs_sb_getsepb(fs))
-#define	SEGTABSIZE_SU(fs)						\
-	((lfs_sb_getnseg(fs) + SEGUPB(fs) - 1) / lfs_sb_getsepb(fs))
-
-#ifdef _KERNEL
-# define SHARE_IFLOCK(F) 						\
-  do {									\
-	rw_enter(&(F)->lfs_iflock, RW_READER);				\
-  } while(0)
-# define UNSHARE_IFLOCK(F)						\
-  do {									\
-	rw_exit(&(F)->lfs_iflock);					\
-  } while(0)
-#else /* ! _KERNEL */
-# define SHARE_IFLOCK(F)
-# define UNSHARE_IFLOCK(F)
-#endif /* ! _KERNEL */
-
-/* Read in the block with a specific segment usage entry from the ifile. */
-#define	LFS_SEGENTRY(SP, F, IN, BP) do {				\
-	int _e;								\
-	SHARE_IFLOCK(F);						\
-	VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS;			\
-	if ((_e = bread((F)->lfs_ivnode,				\
-	    ((IN) / lfs_sb_getsepb(F)) + lfs_sb_getcleansz(F),		\
-	    lfs_sb_getbsize(F), 0, &(BP))) != 0)			\
-		panic("lfs: ifile read: %d", _e);			\
-	if ((F)->lfs_version == 1)					\
-		(SP) = (SEGUSE *)((SEGUSE_V1 *)(BP)->b_data +		\
-			((IN) & (lfs_sb_getsepb(F) - 1)));		\
-	else								\
-		(SP) = (SEGUSE *)(BP)->b_data + ((IN) % lfs_sb_getsepb(F)); \
-	UNSHARE_IFLOCK(F);						\
-} while (0)
-
-#define LFS_WRITESEGENTRY(SP, F, IN, BP) do {				\
-	if ((SP)->su_nbytes == 0)					\
-		(SP)->su_flags |= SEGUSE_EMPTY;				\
-	else								\
-		(SP)->su_flags &= ~SEGUSE_EMPTY;			\
-	(F)->lfs_suflags[(F)->lfs_activesb][(IN)] = (SP)->su_flags;	\
-	LFS_BWRITE_LOG(BP);						\
-} while (0)
-
 /*
  * On-disk file information.  One per file with data blocks in the segment.
  */
@@ -614,27 +510,6 @@ struct ifile_v1 {
 };
 
 /*
- * LFSv1 compatibility code is not allowed to touch if_atime, since it
- * may not be mapped!
- */
-/* Read in the block with a specific inode from the ifile. */
-#define	LFS_IENTRY(IP, F, IN, BP) do {					\
-	int _e;								\
-	SHARE_IFLOCK(F);						\
-	VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS;			\
-	if ((_e = bread((F)->lfs_ivnode,				\
-	(IN) / lfs_sb_getifpb(F) + lfs_sb_getcleansz(F) + lfs_sb_getsegtabsz(F), \
-	lfs_sb_getbsize(F), 0, &(BP))) != 0)				\
-		panic("lfs: ifile ino %d read %d", (int)(IN), _e);	\
-	if ((F)->lfs_version == 1)					\
-		(IP) = (IFILE *)((IFILE_V1 *)(BP)->b_data +		\
-				 (IN) % lfs_sb_getifpb(F));		\
-	else								\
-		(IP) = (IFILE *)(BP)->b_data + (IN) % lfs_sb_getifpb(F); \
-	UNSHARE_IFLOCK(F);						\
-} while (0)
-
-/*
  * Cleaner information structure.  This resides in the ifile and is used
  * to pass information from the kernel to the cleaner.
  */
@@ -649,82 +524,6 @@ typedef struct _cleanerinfo {
 	u_int32_t flags;		/* status word from the kernel */
 } CLEANERINFO;
 
-#define	CLEANSIZE_SU(fs)						\
-	((sizeof(CLEANERINFO) + lfs_sb_getbsize(fs) - 1) >> lfs_sb_getbshift(fs))
-
-/* Read in the block with the cleaner info from the ifile. */
-#define LFS_CLEANERINFO(CP, F, BP) do {					\
-	SHARE_IFLOCK(F);						\
-	VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS;			\
-	if (bread((F)->lfs_ivnode,					\
-	    (daddr_t)0, lfs_sb_getbsize(F), 0, &(BP)))			\
-		panic("lfs: ifile read");				\
-	(CP) = (CLEANERINFO *)(BP)->b_data;				\
-	UNSHARE_IFLOCK(F);						\
-} while (0)
-
-/*
- * Synchronize the Ifile cleaner info with current avail and bfree.
- */
-#define LFS_SYNC_CLEANERINFO(cip, fs, bp, w) do {		 	\
-    mutex_enter(&lfs_lock);						\
-    if ((w) || (cip)->bfree != lfs_sb_getbfree(fs) ||		 	\
-	(cip)->avail != lfs_sb_getavail(fs) - fs->lfs_ravail -	 	\
-	fs->lfs_favail) {	 					\
-	(cip)->bfree = lfs_sb_getbfree(fs);			 	\
-	(cip)->avail = lfs_sb_getavail(fs) - fs->lfs_ravail -		\
-		fs->lfs_favail;					 	\
-	if (((bp)->b_flags & B_GATHERED) == 0) {		 	\
-		fs->lfs_flags |= LFS_IFDIRTY;				\
-	}								\
-	mutex_exit(&lfs_lock);						\
-	(void) LFS_BWRITE_LOG(bp); /* Ifile */			 	\
-    } else {							 	\
-	mutex_exit(&lfs_lock);						\
-	brelse(bp, 0);						 	\
-    }									\
-} while (0)
-
-/*
- * Get the head of the inode free list.
- * Always called with the segment lock held.
- */
-#define LFS_GET_HEADFREE(FS, CIP, BP, FREEP) do {			\
-	if ((FS)->lfs_version > 1) {					\
-		LFS_CLEANERINFO((CIP), (FS), (BP));			\
-		lfs_sb_setfreehd(FS, (CIP)->free_head);			\
-		brelse(BP, 0);						\
-	}								\
-	*(FREEP) = lfs_sb_getfreehd(FS);				\
-} while (0)
-
-#define LFS_PUT_HEADFREE(FS, CIP, BP, VAL) do {				\
-	lfs_sb_setfreehd(FS, VAL);					\
-	if ((FS)->lfs_version > 1) {					\
-		LFS_CLEANERINFO((CIP), (FS), (BP));			\
-		(CIP)->free_head = (VAL);				\
-		LFS_BWRITE_LOG(BP);					\
-		mutex_enter(&lfs_lock);					\
-		(FS)->lfs_flags |= LFS_IFDIRTY;				\
-		mutex_exit(&lfs_lock);					\
-	}								\
-} while (0)
-
-#define LFS_GET_TAILFREE(FS, CIP, BP, FREEP) do {			\
-	LFS_CLEANERINFO((CIP), (FS), (BP));				\
-	*(FREEP) = (CIP)->free_tail;					\
-	brelse(BP, 0);							\
-} while (0)
-
-#define LFS_PUT_TAILFREE(FS, CIP, BP, VAL) do {				\
-	LFS_CLEANERINFO((CIP), (FS), (BP));				\
-	(CIP)->free_tail = (VAL);					\
-	LFS_BWRITE_LOG(BP);						\
-	mutex_enter(&lfs_lock);						\
-	(FS)->lfs_flags |= LFS_IFDIRTY;					\
-	mutex_exit(&lfs_lock);						\
-} while (0)
-
 /*
  * On-disk segment summary information
  */
@@ -767,8 +566,6 @@ struct segsum {
 	/* FINFO's and inode daddr's... */
 };
 
-#define SEGSUM_SIZE(fs) ((fs)->lfs_version == 1 ? sizeof(SEGSUM_V1) : sizeof(SEGSUM))
-
 
 /*
  * On-disk super block.
@@ -970,197 +767,6 @@ struct salfs {
 };
 
 /*
- * Generate accessors for the on-disk superblock fields with cpp.
- *
- * STRUCT_LFS is used by the libsa code to get accessors that work
- * with struct salfs instead of struct lfs.
- */
-
-#ifndef STRUCT_LFS
-#define STRUCT_LFS struct lfs
-#endif
-
-#define LFS_DEF_SB_ACCESSOR(type, field) \
-	static __unused inline type				\
-	lfs_sb_get##field(STRUCT_LFS *fs)			\
-	{							\
-		return fs->lfs_dlfs.dlfs_##field;		\
-	}							\
-	static __unused inline void				\
-	lfs_sb_set##field(STRUCT_LFS *fs, type val)		\
-	{							\
-		fs->lfs_dlfs.dlfs_##field = val;		\
-	}							\
-	static __unused inline void				\
-	lfs_sb_add##field(STRUCT_LFS *fs, type val)		\
-	{							\
-		type *p = &fs->lfs_dlfs.dlfs_##field;		\
-		*p += val;					\
-	}							\
-	static __unused inline void				\
-	lfs_sb_sub##field(STRUCT_LFS *fs, type val)		\
-	{							\
-		type *p = &fs->lfs_dlfs.dlfs_##field;		\
-		*p -= val;					\
-	}
-
-#define lfs_magic lfs_dlfs.dlfs_magic
-#define lfs_version lfs_dlfs.dlfs_version
-LFS_DEF_SB_ACCESSOR(u_int32_t, size);
-LFS_DEF_SB_ACCESSOR(u_int32_t, ssize);
-LFS_DEF_SB_ACCESSOR(u_int32_t, dsize);
-LFS_DEF_SB_ACCESSOR(u_int32_t, bsize);
-LFS_DEF_SB_ACCESSOR(u_int32_t, fsize);
-LFS_DEF_SB_ACCESSOR(u_int32_t, frag);
-LFS_DEF_SB_ACCESSOR(u_int32_t, freehd);
-LFS_DEF_SB_ACCESSOR(int32_t, bfree);
-LFS_DEF_SB_ACCESSOR(u_int32_t, nfiles);
-LFS_DEF_SB_ACCESSOR(int32_t, avail);
-LFS_DEF_SB_ACCESSOR(int32_t, uinodes);
-LFS_DEF_SB_ACCESSOR(int32_t, idaddr);
-LFS_DEF_SB_ACCESSOR(u_int32_t, ifile);
-LFS_DEF_SB_ACCESSOR(int32_t, lastseg);
-LFS_DEF_SB_ACCESSOR(int32_t, nextseg);
-LFS_DEF_SB_ACCESSOR(int32_t, curseg);
-LFS_DEF_SB_ACCESSOR(int32_t, offset);
-LFS_DEF_SB_ACCESSOR(int32_t, lastpseg);
-LFS_DEF_SB_ACCESSOR(u_int32_t, inopf);
-LFS_DEF_SB_ACCESSOR(u_int32_t, minfree);
-LFS_DEF_SB_ACCESSOR(uint64_t, maxfilesize);
-LFS_DEF_SB_ACCESSOR(u_int32_t, fsbpseg);
-LFS_DEF_SB_ACCESSOR(u_int32_t, inopb);
-LFS_DEF_SB_ACCESSOR(u_int32_t, ifpb);
-LFS_DEF_SB_ACCESSOR(u_int32_t, sepb);
-LFS_DEF_SB_ACCESSOR(u_int32_t, nindir);
-LFS_DEF_SB_ACCESSOR(u_int32_t, nseg);
-LFS_DEF_SB_ACCESSOR(u_int32_t, nspf);
-LFS_DEF_SB_ACCESSOR(u_int32_t, cleansz);
-LFS_DEF_SB_ACCESSOR(u_int32_t, segtabsz);
-LFS_DEF_SB_ACCESSOR(u_int32_t, segmask);
-LFS_DEF_SB_ACCESSOR(u_int32_t, segshift);
-LFS_DEF_SB_ACCESSOR(u_int64_t, bmask);
-LFS_DEF_SB_ACCESSOR(u_int32_t, bshift);
-LFS_DEF_SB_ACCESSOR(u_int64_t, ffmask);
-LFS_DEF_SB_ACCESSOR(u_int32_t, ffshift);
-LFS_DEF_SB_ACCESSOR(u_int64_t, fbmask);
-LFS_DEF_SB_ACCESSOR(u_int32_t, fbshift);
-LFS_DEF_SB_ACCESSOR(u_int32_t, blktodb);
-LFS_DEF_SB_ACCESSOR(u_int32_t, fsbtodb);
-LFS_DEF_SB_ACCESSOR(u_int32_t, sushift);
-LFS_DEF_SB_ACCESSOR(int32_t, maxsymlinklen);
-LFS_DEF_SB_ACCESSOR(u_int32_t, cksum);
-LFS_DEF_SB_ACCESSOR(u_int16_t, pflags);
-LFS_DEF_SB_ACCESSOR(u_int32_t, nclean);
-LFS_DEF_SB_ACCESSOR(int32_t, dmeta);
-LFS_DEF_SB_ACCESSOR(u_int32_t, minfreeseg);
-LFS_DEF_SB_ACCESSOR(u_int32_t, sumsize);
-LFS_DEF_SB_ACCESSOR(u_int64_t, serial);
-LFS_DEF_SB_ACCESSOR(u_int32_t, ibsize);
-LFS_DEF_SB_ACCESSOR(int32_t, s0addr);
-LFS_DEF_SB_ACCESSOR(u_int64_t, tstamp);
-LFS_DEF_SB_ACCESSOR(u_int32_t, inodefmt);
-LFS_DEF_SB_ACCESSOR(u_int32_t, interleave);
-LFS_DEF_SB_ACCESSOR(u_int32_t, ident);
-LFS_DEF_SB_ACCESSOR(u_int32_t, resvseg);
-
-/* special-case accessors */
-
-/*
- * the v1 otstamp field lives in what's now dlfs_inopf
- */
-#define lfs_sb_getotstamp(fs) lfs_sb_getinopf(fs)
-#define lfs_sb_setotstamp(fs, val) lfs_sb_setinopf(fs, val)
-
-/*
- * lfs_sboffs is an array
- */
-static __unused inline int32_t
-lfs_sb_getsboff(struct lfs *fs, unsigned n)
-{
-#ifdef KASSERT /* ugh */
-	KASSERT(n < LFS_MAXNUMSB);
-#endif
-	return fs->lfs_dlfs.dlfs_sboffs[n];
-}
-static __unused inline void
-lfs_sb_setsboff(struct lfs *fs, unsigned n, int32_t val)
-{
-#ifdef KASSERT /* ugh */
-	KASSERT(n < LFS_MAXNUMSB);
-#endif
-	fs->lfs_dlfs.dlfs_sboffs[n] = val;
-}
-
-/*
- * lfs_fsmnt is a string
- */
-static __unused inline const char *
-lfs_sb_getfsmnt(struct lfs *fs)
-{
-	return fs->lfs_dlfs.dlfs_fsmnt;
-}
-
-/* LFS_NINDIR is the number of indirects in a file system block. */
-#define	LFS_NINDIR(fs)	(lfs_sb_getnindir(fs))
-
-/* LFS_INOPB is the number of inodes in a secondary storage block. */
-#define	LFS_INOPB(fs)	(lfs_sb_getinopb(fs))
-/* LFS_INOPF is the number of inodes in a fragment. */
-#define LFS_INOPF(fs)	(lfs_sb_getinopf(fs))
-
-#define	lfs_blksize(fs, ip, lbn) \
-	(((lbn) >= ULFS_NDADDR || (ip)->i_ffs1_size >= ((lbn) + 1) << lfs_sb_getbshift(fs)) \
-	    ? lfs_sb_getbsize(fs) \
-	    : (lfs_fragroundup(fs, lfs_blkoff(fs, (ip)->i_ffs1_size))))
-#define	lfs_blkoff(fs, loc)	((int)((loc) & lfs_sb_getbmask(fs)))
-#define lfs_fragoff(fs, loc)    /* calculates (loc % fs->lfs_fsize) */ \
-    ((int)((loc) & lfs_sb_getffmask(fs)))
-
-#if defined(_KERNEL)
-#define	LFS_FSBTODB(fs, b)	((b) << (lfs_sb_getffshift(fs) - DEV_BSHIFT))
-#define	LFS_DBTOFSB(fs, b)	((b) >> (lfs_sb_getffshift(fs) - DEV_BSHIFT))
-#else
-#define	LFS_FSBTODB(fs, b)	((b) << lfs_sb_getfsbtodb(fs))
-#define	LFS_DBTOFSB(fs, b)	((b) >> lfs_sb_getfsbtodb(fs))
-#endif
-
-#define	lfs_lblkno(fs, loc)	((loc) >> lfs_sb_getbshift(fs))
-#define	lfs_lblktosize(fs, blk)	((blk) << lfs_sb_getbshift(fs))
-
-#define lfs_fsbtob(fs, b)	((b) << lfs_sb_getffshift(fs))
-#define lfs_btofsb(fs, b)	((b) >> lfs_sb_getffshift(fs))
-
-#define lfs_numfrags(fs, loc)	/* calculates (loc / fs->lfs_fsize) */	\
-	((loc) >> lfs_sb_getffshift(fs))
-#define lfs_blkroundup(fs, size)/* calculates roundup(size, lfs_sb_getbsize(fs)) */ \
-	((off_t)(((size) + lfs_sb_getbmask(fs)) & (~lfs_sb_getbmask(fs))))
-#define lfs_fragroundup(fs, size)/* calculates roundup(size, fs->lfs_fsize) */ \
-	((off_t)(((size) + lfs_sb_getffmask(fs)) & (~lfs_sb_getffmask(fs))))
-#define lfs_fragstoblks(fs, frags)/* calculates (frags / fs->fs_frag) */ \
-	((frags) >> lfs_sb_getfbshift(fs))
-#define lfs_blkstofrags(fs, blks)/* calculates (blks * fs->fs_frag) */ \
-	((blks) << lfs_sb_getfbshift(fs))
-#define lfs_fragnum(fs, fsb)	/* calculates (fsb % fs->lfs_frag) */	\
-	((fsb) & ((fs)->lfs_frag - 1))
-#define lfs_blknum(fs, fsb)	/* calculates rounddown(fsb, fs->lfs_frag) */ \
-	((fsb) &~ ((fs)->lfs_frag - 1))
-#define lfs_dblksize(fs, dp, lbn) \
-	(((lbn) >= ULFS_NDADDR || (dp)->di_size >= ((lbn) + 1) << lfs_sb_getbshift(fs)) \
-	    ? lfs_sb_getbsize(fs) \
-	    : (lfs_fragroundup(fs, lfs_blkoff(fs, (dp)->di_size))))
-
-#define	lfs_segsize(fs)	((fs)->lfs_version == 1 ?	     		\
-			   lfs_lblktosize((fs), lfs_sb_getssize(fs)) :	\
-			   lfs_sb_getssize(fs))
-#define lfs_segtod(fs, seg) (((fs)->lfs_version == 1     ?	    	\
-			   lfs_sb_getssize(fs) << lfs_sb_getblktodb(fs) : \
-			   lfs_btofsb((fs), lfs_sb_getssize(fs))) * (seg))
-#define	lfs_dtosn(fs, daddr)	/* block address to segment number */	\
-	((uint32_t)(((daddr) - lfs_sb_gets0addr(fs)) / lfs_segtod((fs), 1)))
-#define lfs_sntod(fs, sn)	/* segment number to disk address */	\
-	((daddr_t)(lfs_segtod((fs), (sn)) + lfs_sb_gets0addr(fs)))
-
-/*
  * Structures used by lfs_bmapv and lfs_markv to communicate information
  * about inodes and data blocks.
  */
@@ -1216,60 +822,6 @@ struct segment {
 	int	  ndupino;		/* number of duplicate inodes */
 };
 
-/*
- * Macros for determining free space on the disk, with the variable metadata
- * of segment summaries and inode blocks taken into account.
- */
-/*
- * Estimate number of clean blocks not available for writing because
- * they will contain metadata or overhead.  This is calculated as
- *
- *		E = ((C * M / D) * D + (0) * (T - D)) / T
- * or more simply
- *		E = (C * M) / T
- *
- * where
- * C is the clean space,
- * D is the dirty space,
- * M is the dirty metadata, and
- * T = C + D is the total space on disk.
- *
- * This approximates the old formula of E = C * M / D when D is close to T,
- * but avoids falsely reporting "disk full" when the sample size (D) is small.
- */
-#define LFS_EST_CMETA(F) (int32_t)((					\
-	(lfs_sb_getdmeta(F) * (int64_t)lfs_sb_getnclean(F)) / 		\
-	(lfs_sb_getnseg(F))))
-
-/* Estimate total size of the disk not including metadata */
-#define LFS_EST_NONMETA(F) (lfs_sb_getdsize(F) - lfs_sb_getdmeta(F) - LFS_EST_CMETA(F))
-
-/* Estimate number of blocks actually available for writing */
-#define LFS_EST_BFREE(F) (lfs_sb_getbfree(F) > LFS_EST_CMETA(F) ?	     \
-			  lfs_sb_getbfree(F) - LFS_EST_CMETA(F) : 0)
-
-/* Amount of non-meta space not available to mortal man */
-#define LFS_EST_RSVD(F) (int32_t)((LFS_EST_NONMETA(F) *			     \
-				   (u_int64_t)lfs_sb_getminfree(F)) /	     \
-				  100)
-
-/* Can credential C write BB blocks */
-#define ISSPACE(F, BB, C)						\
-	((((C) == NOCRED || kauth_cred_geteuid(C) == 0) &&		\
-	  LFS_EST_BFREE(F) >= (BB)) ||					\
-	 (kauth_cred_geteuid(C) != 0 && IS_FREESPACE(F, BB)))
-
-/* Can an ordinary user write BB blocks */
-#define IS_FREESPACE(F, BB)						\
-	  (LFS_EST_BFREE(F) >= (BB) + LFS_EST_RSVD(F))
-
-/*
- * The minimum number of blocks to create a new inode.  This is:
- * directory direct block (1) + ULFS_NIADDR indirect blocks + inode block (1) +
- * ifile direct block (1) + ULFS_NIADDR indirect blocks = 3 + 2 * ULFS_NIADDR blocks.
- */
-#define LFS_NRESERVE(F) (lfs_btofsb((F), (2 * ULFS_NIADDR + 3) << lfs_sb_getbshift(F)))
-
 /* Statistics Counters */
 struct lfs_stats {	/* Must match sysctl list in lfs_vfsops.h ! */
 	u_int	segsused;

Index: src/sys/ufs/lfs/lfs_alloc.c
diff -u src/sys/ufs/lfs/lfs_alloc.c:1.123 src/sys/ufs/lfs/lfs_alloc.c:1.124
--- src/sys/ufs/lfs/lfs_alloc.c:1.123	Fri Jul 24 06:59:32 2015
+++ src/sys/ufs/lfs/lfs_alloc.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_alloc.c,v 1.123 2015/07/24 06:59:32 dholland Exp $	*/
+/*	$NetBSD: lfs_alloc.c,v 1.124 2015/07/28 05:09:34 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.123 2015/07/24 06:59:32 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,v 1.124 2015/07/28 05:09:34 dholland Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -86,6 +86,7 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_alloc.c,
 #include <ufs/lfs/ulfs_extern.h>
 
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_extern.h>
 #include <ufs/lfs/lfs_kernel.h>
 

Index: src/sys/ufs/lfs/lfs_balloc.c
diff -u src/sys/ufs/lfs/lfs_balloc.c:1.83 src/sys/ufs/lfs/lfs_balloc.c:1.84
--- src/sys/ufs/lfs/lfs_balloc.c:1.83	Fri Jul 24 06:59:32 2015
+++ src/sys/ufs/lfs/lfs_balloc.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_balloc.c,v 1.83 2015/07/24 06:59:32 dholland Exp $	*/
+/*	$NetBSD: lfs_balloc.c,v 1.84 2015/07/28 05:09:34 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_balloc.c,v 1.83 2015/07/24 06:59:32 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_balloc.c,v 1.84 2015/07/28 05:09:34 dholland Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -85,6 +85,7 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_balloc.c
 #include <ufs/lfs/ulfs_extern.h>
 
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_extern.h>
 #include <ufs/lfs/lfs_kernel.h>
 
Index: src/sys/ufs/lfs/lfs_subr.c
diff -u src/sys/ufs/lfs/lfs_subr.c:1.83 src/sys/ufs/lfs/lfs_subr.c:1.84
--- src/sys/ufs/lfs/lfs_subr.c:1.83	Fri Jul 24 06:59:32 2015
+++ src/sys/ufs/lfs/lfs_subr.c	Tue Jul 28 05:09:35 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_subr.c,v 1.83 2015/07/24 06:59:32 dholland Exp $	*/
+/*	$NetBSD: lfs_subr.c,v 1.84 2015/07/28 05:09:35 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.83 2015/07/24 06:59:32 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.84 2015/07/28 05:09:35 dholland Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -74,6 +74,7 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v
 
 #include <ufs/lfs/ulfs_inode.h>
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_kernel.h>
 #include <ufs/lfs/lfs_extern.h>
 

Index: src/sys/ufs/lfs/lfs_bio.c
diff -u src/sys/ufs/lfs/lfs_bio.c:1.131 src/sys/ufs/lfs/lfs_bio.c:1.132
--- src/sys/ufs/lfs/lfs_bio.c:1.131	Sat Jul 25 10:40:35 2015
+++ src/sys/ufs/lfs/lfs_bio.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_bio.c,v 1.131 2015/07/25 10:40:35 martin Exp $	*/
+/*	$NetBSD: lfs_bio.c,v 1.132 2015/07/28 05:09:34 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2008 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.131 2015/07/25 10:40:35 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.132 2015/07/28 05:09:34 dholland Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -77,6 +77,7 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 
 #include <ufs/lfs/ulfs_extern.h>
 
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_extern.h>
 #include <ufs/lfs/lfs_kernel.h>
 

Index: src/sys/ufs/lfs/lfs_debug.c
diff -u src/sys/ufs/lfs/lfs_debug.c:1.45 src/sys/ufs/lfs/lfs_debug.c:1.46
--- src/sys/ufs/lfs/lfs_debug.c:1.45	Sat Jul 25 13:01:06 2015
+++ src/sys/ufs/lfs/lfs_debug.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_debug.c,v 1.45 2015/07/25 13:01:06 hannken Exp $	*/
+/*	$NetBSD: lfs_debug.c,v 1.46 2015/07/28 05:09:34 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_debug.c,v 1.45 2015/07/25 13:01:06 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_debug.c,v 1.46 2015/07/28 05:09:34 dholland Exp $");
 
 #ifdef DEBUG
 
@@ -75,6 +75,7 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_debug.c,
 
 #include <ufs/lfs/ulfs_inode.h>
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_extern.h>
 
 int lfs_lognum;

Index: src/sys/ufs/lfs/lfs_inode.c
diff -u src/sys/ufs/lfs/lfs_inode.c:1.139 src/sys/ufs/lfs/lfs_inode.c:1.140
--- src/sys/ufs/lfs/lfs_inode.c:1.139	Fri Jul 24 06:59:32 2015
+++ src/sys/ufs/lfs/lfs_inode.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_inode.c,v 1.139 2015/07/24 06:59:32 dholland Exp $	*/
+/*	$NetBSD: lfs_inode.c,v 1.140 2015/07/28 05:09:34 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_inode.c,v 1.139 2015/07/24 06:59:32 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_inode.c,v 1.140 2015/07/28 05:09:34 dholland Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -85,6 +85,7 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_inode.c,
 #include <ufs/lfs/ulfs_extern.h>
 
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_extern.h>
 #include <ufs/lfs/lfs_kernel.h>
 

Index: src/sys/ufs/lfs/lfs_itimes.c
diff -u src/sys/ufs/lfs/lfs_itimes.c:1.15 src/sys/ufs/lfs/lfs_itimes.c:1.16
--- src/sys/ufs/lfs/lfs_itimes.c:1.15	Sat Jun  8 02:16:03 2013
+++ src/sys/ufs/lfs/lfs_itimes.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_itimes.c,v 1.15 2013/06/08 02:16:03 dholland Exp $	*/
+/*	$NetBSD: lfs_itimes.c,v 1.16 2015/07/28 05:09:34 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_itimes.c,v 1.15 2013/06/08 02:16:03 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_itimes.c,v 1.16 2015/07/28 05:09:34 dholland Exp $");
 
 #include <sys/param.h>
 #include <sys/time.h>
@@ -50,6 +50,7 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_itimes.c
 #endif
 
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_inode.h>
 
 void

Index: src/sys/ufs/lfs/lfs_pages.c
diff -u src/sys/ufs/lfs/lfs_pages.c:1.4 src/sys/ufs/lfs/lfs_pages.c:1.5
--- src/sys/ufs/lfs/lfs_pages.c:1.4	Sat Jul 25 10:40:35 2015
+++ src/sys/ufs/lfs/lfs_pages.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_pages.c,v 1.4 2015/07/25 10:40:35 martin Exp $	*/
+/*	$NetBSD: lfs_pages.c,v 1.5 2015/07/28 05:09:34 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_pages.c,v 1.4 2015/07/25 10:40:35 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_pages.c,v 1.5 2015/07/28 05:09:34 dholland Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -99,6 +99,7 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_pages.c,
 #include <uvm/uvm_pager.h>
 
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_kernel.h>
 #include <ufs/lfs/lfs_extern.h>
 

Index: src/sys/ufs/lfs/lfs_rfw.c
diff -u src/sys/ufs/lfs/lfs_rfw.c:1.23 src/sys/ufs/lfs/lfs_rfw.c:1.24
--- src/sys/ufs/lfs/lfs_rfw.c:1.23	Fri Jul 24 06:59:32 2015
+++ src/sys/ufs/lfs/lfs_rfw.c	Tue Jul 28 05:09:34 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_rfw.c,v 1.23 2015/07/24 06:59:32 dholland Exp $	*/
+/*	$NetBSD: lfs_rfw.c,v 1.24 2015/07/28 05:09:34 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_rfw.c,v 1.23 2015/07/24 06:59:32 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_rfw.c,v 1.24 2015/07/28 05:09:34 dholland Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_quota.h"
@@ -73,6 +73,7 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_rfw.c,v 
 #include <uvm/uvm_pdaemon.h>
 
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_kernel.h>
 #include <ufs/lfs/lfs_extern.h>
 

Index: src/sys/ufs/lfs/lfs_segment.c
diff -u src/sys/ufs/lfs/lfs_segment.c:1.244 src/sys/ufs/lfs/lfs_segment.c:1.245
--- src/sys/ufs/lfs/lfs_segment.c:1.244	Sat Jul 25 10:40:35 2015
+++ src/sys/ufs/lfs/lfs_segment.c	Tue Jul 28 05:09:35 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_segment.c,v 1.244 2015/07/25 10:40:35 martin Exp $	*/
+/*	$NetBSD: lfs_segment.c,v 1.245 2015/07/28 05:09:35 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.244 2015/07/25 10:40:35 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.245 2015/07/28 05:09:35 dholland Exp $");
 
 #define _VFS_VNODE_PRIVATE	/* XXX: check for VI_MARKER, this has to go */
 
@@ -102,6 +102,7 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_segment.
 #include <ufs/lfs/ulfs_extern.h>
 
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_kernel.h>
 #include <ufs/lfs/lfs_extern.h>
 

Index: src/sys/ufs/lfs/lfs_syscalls.c
diff -u src/sys/ufs/lfs/lfs_syscalls.c:1.162 src/sys/ufs/lfs/lfs_syscalls.c:1.163
--- src/sys/ufs/lfs/lfs_syscalls.c:1.162	Fri Jul 24 06:59:32 2015
+++ src/sys/ufs/lfs/lfs_syscalls.c	Tue Jul 28 05:09:35 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_syscalls.c,v 1.162 2015/07/24 06:59:32 dholland Exp $	*/
+/*	$NetBSD: lfs_syscalls.c,v 1.163 2015/07/28 05:09:35 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007, 2008
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_syscalls.c,v 1.162 2015/07/24 06:59:32 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_syscalls.c,v 1.163 2015/07/28 05:09:35 dholland Exp $");
 
 #ifndef LFS
 # define LFS		/* for prototypes in syscallargs.h */
@@ -82,6 +82,7 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_syscalls
 #include <ufs/lfs/ulfs_extern.h>
 
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_kernel.h>
 #include <ufs/lfs/lfs_extern.h>
 

Index: src/sys/ufs/lfs/lfs_vfsops.c
diff -u src/sys/ufs/lfs/lfs_vfsops.c:1.328 src/sys/ufs/lfs/lfs_vfsops.c:1.329
--- src/sys/ufs/lfs/lfs_vfsops.c:1.328	Fri Jul 24 06:59:32 2015
+++ src/sys/ufs/lfs/lfs_vfsops.c	Tue Jul 28 05:09:35 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vfsops.c,v 1.328 2015/07/24 06:59:32 dholland Exp $	*/
+/*	$NetBSD: lfs_vfsops.c,v 1.329 2015/07/28 05:09:35 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.328 2015/07/24 06:59:32 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.329 2015/07/28 05:09:35 dholland Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_lfs.h"
@@ -110,6 +110,7 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c
 #include <uvm/uvm_pdaemon.h>
 
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_kernel.h>
 #include <ufs/lfs/lfs_extern.h>
 

Index: src/sys/ufs/lfs/lfs_vnops.c
diff -u src/sys/ufs/lfs/lfs_vnops.c:1.277 src/sys/ufs/lfs/lfs_vnops.c:1.278
--- src/sys/ufs/lfs/lfs_vnops.c:1.277	Sun Jul 26 08:13:23 2015
+++ src/sys/ufs/lfs/lfs_vnops.c	Tue Jul 28 05:09:35 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: lfs_vnops.c,v 1.277 2015/07/26 08:13:23 hannken Exp $	*/
+/*	$NetBSD: lfs_vnops.c,v 1.278 2015/07/28 05:09:35 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@@ -125,7 +125,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.277 2015/07/26 08:13:23 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.278 2015/07/28 05:09:35 dholland Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -164,6 +164,7 @@ __KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,
 #include <uvm/uvm_pager.h>
 
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_kernel.h>
 #include <ufs/lfs/lfs_extern.h>
 

Index: src/sys/ufs/lfs/ulfs_quota2.c
diff -u src/sys/ufs/lfs/ulfs_quota2.c:1.20 src/sys/ufs/lfs/ulfs_quota2.c:1.21
--- src/sys/ufs/lfs/ulfs_quota2.c:1.20	Fri Jul 24 06:59:32 2015
+++ src/sys/ufs/lfs/ulfs_quota2.c	Tue Jul 28 05:09:35 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: ulfs_quota2.c,v 1.20 2015/07/24 06:59:32 dholland Exp $	*/
+/*	$NetBSD: ulfs_quota2.c,v 1.21 2015/07/28 05:09:35 dholland Exp $	*/
 /*  from NetBSD: ufs_quota2.c,v 1.35 2012/09/27 07:47:56 bouyer Exp  */
 /*  from NetBSD: ffs_quota2.c,v 1.4 2011/06/12 03:36:00 rmind Exp  */
 
@@ -29,7 +29,7 @@
   */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ulfs_quota2.c,v 1.20 2015/07/24 06:59:32 dholland Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ulfs_quota2.c,v 1.21 2015/07/28 05:09:35 dholland Exp $");
 
 #include <sys/buf.h>
 #include <sys/param.h>
@@ -46,6 +46,8 @@ __KERNEL_RCSID(0, "$NetBSD: ulfs_quota2.
 #include <sys/quota.h>
 #include <sys/quotactl.h>
 
+#include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 #include <ufs/lfs/lfs_extern.h>
 
 #include <ufs/lfs/ulfs_quota2.h>

Index: src/usr.sbin/dumplfs/dumplfs.c
diff -u src/usr.sbin/dumplfs/dumplfs.c:1.44 src/usr.sbin/dumplfs/dumplfs.c:1.45
--- src/usr.sbin/dumplfs/dumplfs.c:1.44	Fri Jul 24 06:59:32 2015
+++ src/usr.sbin/dumplfs/dumplfs.c	Tue Jul 28 05:09:35 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: dumplfs.c,v 1.44 2015/07/24 06:59:32 dholland Exp $	*/
+/*	$NetBSD: dumplfs.c,v 1.45 2015/07/28 05:09:35 dholland Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -40,7 +40,7 @@ __COPYRIGHT("@(#) Copyright (c) 1991, 19
 #if 0
 static char sccsid[] = "@(#)dumplfs.c	8.5 (Berkeley) 5/24/95";
 #else
-__RCSID("$NetBSD: dumplfs.c,v 1.44 2015/07/24 06:59:32 dholland Exp $");
+__RCSID("$NetBSD: dumplfs.c,v 1.45 2015/07/28 05:09:35 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -50,6 +50,7 @@ __RCSID("$NetBSD: dumplfs.c,v 1.44 2015/
 #include <sys/time.h>
 
 #include <ufs/lfs/lfs.h>
+#include <ufs/lfs/lfs_accessors.h>
 
 #include <err.h>
 #include <errno.h>

Added files:

Index: src/sys/ufs/lfs/lfs_accessors.h
diff -u /dev/null src/sys/ufs/lfs/lfs_accessors.h:1.1
--- /dev/null	Tue Jul 28 05:09:35 2015
+++ src/sys/ufs/lfs/lfs_accessors.h	Tue Jul 28 05:09:34 2015
@@ -0,0 +1,627 @@
+/*	$NetBSD: lfs_accessors.h,v 1.1 2015/07/28 05:09:34 dholland Exp $	*/
+
+/*  from NetBSD: lfs.h,v 1.165 2015/07/24 06:59:32 dholland Exp  */
+/*  from NetBSD: dinode.h,v 1.22 2013/01/22 09:39:18 dholland Exp  */
+/*  from NetBSD: dir.h,v 1.21 2009/07/22 04:49:19 dholland Exp  */
+
+/*-
+ * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Konrad E. Schroder <[email protected]>.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+/*-
+ * Copyright (c) 1991, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	@(#)lfs.h	8.9 (Berkeley) 5/8/95
+ */
+/*
+ * Copyright (c) 2002 Networks Associates Technology, Inc.
+ * All rights reserved.
+ *
+ * This software was developed for the FreeBSD Project by Marshall
+ * Kirk McKusick and Network Associates Laboratories, the Security
+ * Research Division of Network Associates, Inc. under DARPA/SPAWAR
+ * contract N66001-01-C-8035 ("CBOSS"), as part of the DARPA CHATS
+ * research program
+ *
+ * Copyright (c) 1982, 1989, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	@(#)dinode.h	8.9 (Berkeley) 3/29/95
+ */
+/*
+ * Copyright (c) 1982, 1986, 1989, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	@(#)dir.h	8.5 (Berkeley) 4/27/95
+ */
+
+#ifndef _UFS_LFS_LFS_ACCESSORS_H_
+#define _UFS_LFS_LFS_ACCESSORS_H_
+
+/*
+ * Maximum length of a symlink that can be stored within the inode.
+ */
+#define ULFS1_MAXSYMLINKLEN	((ULFS_NDADDR + ULFS_NIADDR) * sizeof(int32_t))
+#define ULFS2_MAXSYMLINKLEN	((ULFS_NDADDR + ULFS_NIADDR) * sizeof(int64_t))
+
+#define ULFS_MAXSYMLINKLEN(ip) \
+	((ip)->i_ump->um_fstype == ULFS1) ? \
+	ULFS1_MAXSYMLINKLEN : ULFS2_MAXSYMLINKLEN
+
+/*
+ * "struct buf" associated definitions
+ */
+
+# define LFS_LOCK_BUF(bp) do {						\
+	if (((bp)->b_flags & B_LOCKED) == 0 && bp->b_iodone == NULL) {	\
+		mutex_enter(&lfs_lock);					\
+		++locked_queue_count;					\
+		locked_queue_bytes += bp->b_bufsize;			\
+		mutex_exit(&lfs_lock);					\
+	}								\
+	(bp)->b_flags |= B_LOCKED;					\
+} while (0)
+
+# define LFS_UNLOCK_BUF(bp) do {					\
+	if (((bp)->b_flags & B_LOCKED) != 0 && bp->b_iodone == NULL) {	\
+		mutex_enter(&lfs_lock);					\
+		--locked_queue_count;					\
+		locked_queue_bytes -= bp->b_bufsize;			\
+		if (locked_queue_count < LFS_WAIT_BUFS &&		\
+		    locked_queue_bytes < LFS_WAIT_BYTES)		\
+			cv_broadcast(&locked_queue_cv);			\
+		mutex_exit(&lfs_lock);					\
+	}								\
+	(bp)->b_flags &= ~B_LOCKED;					\
+} while (0)
+
+/*
+ * "struct inode" associated definitions
+ */
+
+#define LFS_SET_UINO(ip, flags) do {					\
+	if (((flags) & IN_ACCESSED) && !((ip)->i_flag & IN_ACCESSED))	\
+		lfs_sb_adduinodes((ip)->i_lfs, 1);			\
+	if (((flags) & IN_CLEANING) && !((ip)->i_flag & IN_CLEANING))	\
+		lfs_sb_adduinodes((ip)->i_lfs, 1);			\
+	if (((flags) & IN_MODIFIED) && !((ip)->i_flag & IN_MODIFIED))	\
+		lfs_sb_adduinodes((ip)->i_lfs, 1);			\
+	(ip)->i_flag |= (flags);					\
+} while (0)
+
+#define LFS_CLR_UINO(ip, flags) do {					\
+	if (((flags) & IN_ACCESSED) && ((ip)->i_flag & IN_ACCESSED))	\
+		lfs_sb_subuinodes((ip)->i_lfs, 1);			\
+	if (((flags) & IN_CLEANING) && ((ip)->i_flag & IN_CLEANING))	\
+		lfs_sb_subuinodes((ip)->i_lfs, 1);			\
+	if (((flags) & IN_MODIFIED) && ((ip)->i_flag & IN_MODIFIED))	\
+		lfs_sb_subuinodes((ip)->i_lfs, 1);			\
+	(ip)->i_flag &= ~(flags);					\
+	if (lfs_sb_getuinodes((ip)->i_lfs) < 0) {			\
+		panic("lfs_uinodes < 0");				\
+	}								\
+} while (0)
+
+#define LFS_ITIMES(ip, acc, mod, cre) \
+	while ((ip)->i_flag & (IN_ACCESS | IN_CHANGE | IN_UPDATE | IN_MODIFY)) \
+		lfs_itimes(ip, acc, mod, cre)
+
+/*
+ * On-disk and in-memory checkpoint segment usage structure.
+ */
+
+#define	SEGUPB(fs)	(lfs_sb_getsepb(fs))
+#define	SEGTABSIZE_SU(fs)						\
+	((lfs_sb_getnseg(fs) + SEGUPB(fs) - 1) / lfs_sb_getsepb(fs))
+
+#ifdef _KERNEL
+# define SHARE_IFLOCK(F) 						\
+  do {									\
+	rw_enter(&(F)->lfs_iflock, RW_READER);				\
+  } while(0)
+# define UNSHARE_IFLOCK(F)						\
+  do {									\
+	rw_exit(&(F)->lfs_iflock);					\
+  } while(0)
+#else /* ! _KERNEL */
+# define SHARE_IFLOCK(F)
+# define UNSHARE_IFLOCK(F)
+#endif /* ! _KERNEL */
+
+/* Read in the block with a specific segment usage entry from the ifile. */
+#define	LFS_SEGENTRY(SP, F, IN, BP) do {				\
+	int _e;								\
+	SHARE_IFLOCK(F);						\
+	VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS;			\
+	if ((_e = bread((F)->lfs_ivnode,				\
+	    ((IN) / lfs_sb_getsepb(F)) + lfs_sb_getcleansz(F),		\
+	    lfs_sb_getbsize(F), 0, &(BP))) != 0)			\
+		panic("lfs: ifile read: %d", _e);			\
+	if ((F)->lfs_version == 1)					\
+		(SP) = (SEGUSE *)((SEGUSE_V1 *)(BP)->b_data +		\
+			((IN) & (lfs_sb_getsepb(F) - 1)));		\
+	else								\
+		(SP) = (SEGUSE *)(BP)->b_data + ((IN) % lfs_sb_getsepb(F)); \
+	UNSHARE_IFLOCK(F);						\
+} while (0)
+
+#define LFS_WRITESEGENTRY(SP, F, IN, BP) do {				\
+	if ((SP)->su_nbytes == 0)					\
+		(SP)->su_flags |= SEGUSE_EMPTY;				\
+	else								\
+		(SP)->su_flags &= ~SEGUSE_EMPTY;			\
+	(F)->lfs_suflags[(F)->lfs_activesb][(IN)] = (SP)->su_flags;	\
+	LFS_BWRITE_LOG(BP);						\
+} while (0)
+
+/*
+ * Index file inode entries.
+ */
+
+/*
+ * LFSv1 compatibility code is not allowed to touch if_atime, since it
+ * may not be mapped!
+ */
+/* Read in the block with a specific inode from the ifile. */
+#define	LFS_IENTRY(IP, F, IN, BP) do {					\
+	int _e;								\
+	SHARE_IFLOCK(F);						\
+	VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS;			\
+	if ((_e = bread((F)->lfs_ivnode,				\
+	(IN) / lfs_sb_getifpb(F) + lfs_sb_getcleansz(F) + lfs_sb_getsegtabsz(F), \
+	lfs_sb_getbsize(F), 0, &(BP))) != 0)				\
+		panic("lfs: ifile ino %d read %d", (int)(IN), _e);	\
+	if ((F)->lfs_version == 1)					\
+		(IP) = (IFILE *)((IFILE_V1 *)(BP)->b_data +		\
+				 (IN) % lfs_sb_getifpb(F));		\
+	else								\
+		(IP) = (IFILE *)(BP)->b_data + (IN) % lfs_sb_getifpb(F); \
+	UNSHARE_IFLOCK(F);						\
+} while (0)
+
+/*
+ * Cleaner information structure.  This resides in the ifile and is used
+ * to pass information from the kernel to the cleaner.
+ */
+
+#define	CLEANSIZE_SU(fs)						\
+	((sizeof(CLEANERINFO) + lfs_sb_getbsize(fs) - 1) >> lfs_sb_getbshift(fs))
+
+/* Read in the block with the cleaner info from the ifile. */
+#define LFS_CLEANERINFO(CP, F, BP) do {					\
+	SHARE_IFLOCK(F);						\
+	VTOI((F)->lfs_ivnode)->i_flag |= IN_ACCESS;			\
+	if (bread((F)->lfs_ivnode,					\
+	    (daddr_t)0, lfs_sb_getbsize(F), 0, &(BP)))			\
+		panic("lfs: ifile read");				\
+	(CP) = (CLEANERINFO *)(BP)->b_data;				\
+	UNSHARE_IFLOCK(F);						\
+} while (0)
+
+/*
+ * Synchronize the Ifile cleaner info with current avail and bfree.
+ */
+#define LFS_SYNC_CLEANERINFO(cip, fs, bp, w) do {		 	\
+    mutex_enter(&lfs_lock);						\
+    if ((w) || (cip)->bfree != lfs_sb_getbfree(fs) ||		 	\
+	(cip)->avail != lfs_sb_getavail(fs) - fs->lfs_ravail -	 	\
+	fs->lfs_favail) {	 					\
+	(cip)->bfree = lfs_sb_getbfree(fs);			 	\
+	(cip)->avail = lfs_sb_getavail(fs) - fs->lfs_ravail -		\
+		fs->lfs_favail;					 	\
+	if (((bp)->b_flags & B_GATHERED) == 0) {		 	\
+		fs->lfs_flags |= LFS_IFDIRTY;				\
+	}								\
+	mutex_exit(&lfs_lock);						\
+	(void) LFS_BWRITE_LOG(bp); /* Ifile */			 	\
+    } else {							 	\
+	mutex_exit(&lfs_lock);						\
+	brelse(bp, 0);						 	\
+    }									\
+} while (0)
+
+/*
+ * Get the head of the inode free list.
+ * Always called with the segment lock held.
+ */
+#define LFS_GET_HEADFREE(FS, CIP, BP, FREEP) do {			\
+	if ((FS)->lfs_version > 1) {					\
+		LFS_CLEANERINFO((CIP), (FS), (BP));			\
+		lfs_sb_setfreehd(FS, (CIP)->free_head);			\
+		brelse(BP, 0);						\
+	}								\
+	*(FREEP) = lfs_sb_getfreehd(FS);				\
+} while (0)
+
+#define LFS_PUT_HEADFREE(FS, CIP, BP, VAL) do {				\
+	lfs_sb_setfreehd(FS, VAL);					\
+	if ((FS)->lfs_version > 1) {					\
+		LFS_CLEANERINFO((CIP), (FS), (BP));			\
+		(CIP)->free_head = (VAL);				\
+		LFS_BWRITE_LOG(BP);					\
+		mutex_enter(&lfs_lock);					\
+		(FS)->lfs_flags |= LFS_IFDIRTY;				\
+		mutex_exit(&lfs_lock);					\
+	}								\
+} while (0)
+
+#define LFS_GET_TAILFREE(FS, CIP, BP, FREEP) do {			\
+	LFS_CLEANERINFO((CIP), (FS), (BP));				\
+	*(FREEP) = (CIP)->free_tail;					\
+	brelse(BP, 0);							\
+} while (0)
+
+#define LFS_PUT_TAILFREE(FS, CIP, BP, VAL) do {				\
+	LFS_CLEANERINFO((CIP), (FS), (BP));				\
+	(CIP)->free_tail = (VAL);					\
+	LFS_BWRITE_LOG(BP);						\
+	mutex_enter(&lfs_lock);						\
+	(FS)->lfs_flags |= LFS_IFDIRTY;					\
+	mutex_exit(&lfs_lock);						\
+} while (0)
+
+/*
+ * On-disk segment summary information
+ */
+
+#define SEGSUM_SIZE(fs) ((fs)->lfs_version == 1 ? sizeof(SEGSUM_V1) : sizeof(SEGSUM))
+
+/*
+ * Super block.
+ */
+
+/*
+ * Generate accessors for the on-disk superblock fields with cpp.
+ *
+ * STRUCT_LFS is used by the libsa code to get accessors that work
+ * with struct salfs instead of struct lfs.
+ */
+
+#ifndef STRUCT_LFS
+#define STRUCT_LFS struct lfs
+#endif
+
+#define LFS_DEF_SB_ACCESSOR(type, field) \
+	static __unused inline type				\
+	lfs_sb_get##field(STRUCT_LFS *fs)			\
+	{							\
+		return fs->lfs_dlfs.dlfs_##field;		\
+	}							\
+	static __unused inline void				\
+	lfs_sb_set##field(STRUCT_LFS *fs, type val)		\
+	{							\
+		fs->lfs_dlfs.dlfs_##field = val;		\
+	}							\
+	static __unused inline void				\
+	lfs_sb_add##field(STRUCT_LFS *fs, type val)		\
+	{							\
+		type *p = &fs->lfs_dlfs.dlfs_##field;		\
+		*p += val;					\
+	}							\
+	static __unused inline void				\
+	lfs_sb_sub##field(STRUCT_LFS *fs, type val)		\
+	{							\
+		type *p = &fs->lfs_dlfs.dlfs_##field;		\
+		*p -= val;					\
+	}
+
+#define lfs_magic lfs_dlfs.dlfs_magic
+#define lfs_version lfs_dlfs.dlfs_version
+LFS_DEF_SB_ACCESSOR(u_int32_t, size);
+LFS_DEF_SB_ACCESSOR(u_int32_t, ssize);
+LFS_DEF_SB_ACCESSOR(u_int32_t, dsize);
+LFS_DEF_SB_ACCESSOR(u_int32_t, bsize);
+LFS_DEF_SB_ACCESSOR(u_int32_t, fsize);
+LFS_DEF_SB_ACCESSOR(u_int32_t, frag);
+LFS_DEF_SB_ACCESSOR(u_int32_t, freehd);
+LFS_DEF_SB_ACCESSOR(int32_t, bfree);
+LFS_DEF_SB_ACCESSOR(u_int32_t, nfiles);
+LFS_DEF_SB_ACCESSOR(int32_t, avail);
+LFS_DEF_SB_ACCESSOR(int32_t, uinodes);
+LFS_DEF_SB_ACCESSOR(int32_t, idaddr);
+LFS_DEF_SB_ACCESSOR(u_int32_t, ifile);
+LFS_DEF_SB_ACCESSOR(int32_t, lastseg);
+LFS_DEF_SB_ACCESSOR(int32_t, nextseg);
+LFS_DEF_SB_ACCESSOR(int32_t, curseg);
+LFS_DEF_SB_ACCESSOR(int32_t, offset);
+LFS_DEF_SB_ACCESSOR(int32_t, lastpseg);
+LFS_DEF_SB_ACCESSOR(u_int32_t, inopf);
+LFS_DEF_SB_ACCESSOR(u_int32_t, minfree);
+LFS_DEF_SB_ACCESSOR(uint64_t, maxfilesize);
+LFS_DEF_SB_ACCESSOR(u_int32_t, fsbpseg);
+LFS_DEF_SB_ACCESSOR(u_int32_t, inopb);
+LFS_DEF_SB_ACCESSOR(u_int32_t, ifpb);
+LFS_DEF_SB_ACCESSOR(u_int32_t, sepb);
+LFS_DEF_SB_ACCESSOR(u_int32_t, nindir);
+LFS_DEF_SB_ACCESSOR(u_int32_t, nseg);
+LFS_DEF_SB_ACCESSOR(u_int32_t, nspf);
+LFS_DEF_SB_ACCESSOR(u_int32_t, cleansz);
+LFS_DEF_SB_ACCESSOR(u_int32_t, segtabsz);
+LFS_DEF_SB_ACCESSOR(u_int32_t, segmask);
+LFS_DEF_SB_ACCESSOR(u_int32_t, segshift);
+LFS_DEF_SB_ACCESSOR(u_int64_t, bmask);
+LFS_DEF_SB_ACCESSOR(u_int32_t, bshift);
+LFS_DEF_SB_ACCESSOR(u_int64_t, ffmask);
+LFS_DEF_SB_ACCESSOR(u_int32_t, ffshift);
+LFS_DEF_SB_ACCESSOR(u_int64_t, fbmask);
+LFS_DEF_SB_ACCESSOR(u_int32_t, fbshift);
+LFS_DEF_SB_ACCESSOR(u_int32_t, blktodb);
+LFS_DEF_SB_ACCESSOR(u_int32_t, fsbtodb);
+LFS_DEF_SB_ACCESSOR(u_int32_t, sushift);
+LFS_DEF_SB_ACCESSOR(int32_t, maxsymlinklen);
+LFS_DEF_SB_ACCESSOR(u_int32_t, cksum);
+LFS_DEF_SB_ACCESSOR(u_int16_t, pflags);
+LFS_DEF_SB_ACCESSOR(u_int32_t, nclean);
+LFS_DEF_SB_ACCESSOR(int32_t, dmeta);
+LFS_DEF_SB_ACCESSOR(u_int32_t, minfreeseg);
+LFS_DEF_SB_ACCESSOR(u_int32_t, sumsize);
+LFS_DEF_SB_ACCESSOR(u_int64_t, serial);
+LFS_DEF_SB_ACCESSOR(u_int32_t, ibsize);
+LFS_DEF_SB_ACCESSOR(int32_t, s0addr);
+LFS_DEF_SB_ACCESSOR(u_int64_t, tstamp);
+LFS_DEF_SB_ACCESSOR(u_int32_t, inodefmt);
+LFS_DEF_SB_ACCESSOR(u_int32_t, interleave);
+LFS_DEF_SB_ACCESSOR(u_int32_t, ident);
+LFS_DEF_SB_ACCESSOR(u_int32_t, resvseg);
+
+/* special-case accessors */
+
+/*
+ * the v1 otstamp field lives in what's now dlfs_inopf
+ */
+#define lfs_sb_getotstamp(fs) lfs_sb_getinopf(fs)
+#define lfs_sb_setotstamp(fs, val) lfs_sb_setinopf(fs, val)
+
+/*
+ * lfs_sboffs is an array
+ */
+static __unused inline int32_t
+lfs_sb_getsboff(struct lfs *fs, unsigned n)
+{
+#ifdef KASSERT /* ugh */
+	KASSERT(n < LFS_MAXNUMSB);
+#endif
+	return fs->lfs_dlfs.dlfs_sboffs[n];
+}
+static __unused inline void
+lfs_sb_setsboff(struct lfs *fs, unsigned n, int32_t val)
+{
+#ifdef KASSERT /* ugh */
+	KASSERT(n < LFS_MAXNUMSB);
+#endif
+	fs->lfs_dlfs.dlfs_sboffs[n] = val;
+}
+
+/*
+ * lfs_fsmnt is a string
+ */
+static __unused inline const char *
+lfs_sb_getfsmnt(struct lfs *fs)
+{
+	return fs->lfs_dlfs.dlfs_fsmnt;
+}
+
+/* LFS_NINDIR is the number of indirects in a file system block. */
+#define	LFS_NINDIR(fs)	(lfs_sb_getnindir(fs))
+
+/* LFS_INOPB is the number of inodes in a secondary storage block. */
+#define	LFS_INOPB(fs)	(lfs_sb_getinopb(fs))
+/* LFS_INOPF is the number of inodes in a fragment. */
+#define LFS_INOPF(fs)	(lfs_sb_getinopf(fs))
+
+#define	lfs_blksize(fs, ip, lbn) \
+	(((lbn) >= ULFS_NDADDR || (ip)->i_ffs1_size >= ((lbn) + 1) << lfs_sb_getbshift(fs)) \
+	    ? lfs_sb_getbsize(fs) \
+	    : (lfs_fragroundup(fs, lfs_blkoff(fs, (ip)->i_ffs1_size))))
+#define	lfs_blkoff(fs, loc)	((int)((loc) & lfs_sb_getbmask(fs)))
+#define lfs_fragoff(fs, loc)    /* calculates (loc % fs->lfs_fsize) */ \
+    ((int)((loc) & lfs_sb_getffmask(fs)))
+
+#if defined(_KERNEL)
+#define	LFS_FSBTODB(fs, b)	((b) << (lfs_sb_getffshift(fs) - DEV_BSHIFT))
+#define	LFS_DBTOFSB(fs, b)	((b) >> (lfs_sb_getffshift(fs) - DEV_BSHIFT))
+#else
+#define	LFS_FSBTODB(fs, b)	((b) << lfs_sb_getfsbtodb(fs))
+#define	LFS_DBTOFSB(fs, b)	((b) >> lfs_sb_getfsbtodb(fs))
+#endif
+
+#define	lfs_lblkno(fs, loc)	((loc) >> lfs_sb_getbshift(fs))
+#define	lfs_lblktosize(fs, blk)	((blk) << lfs_sb_getbshift(fs))
+
+#define lfs_fsbtob(fs, b)	((b) << lfs_sb_getffshift(fs))
+#define lfs_btofsb(fs, b)	((b) >> lfs_sb_getffshift(fs))
+
+#define lfs_numfrags(fs, loc)	/* calculates (loc / fs->lfs_fsize) */	\
+	((loc) >> lfs_sb_getffshift(fs))
+#define lfs_blkroundup(fs, size)/* calculates roundup(size, lfs_sb_getbsize(fs)) */ \
+	((off_t)(((size) + lfs_sb_getbmask(fs)) & (~lfs_sb_getbmask(fs))))
+#define lfs_fragroundup(fs, size)/* calculates roundup(size, fs->lfs_fsize) */ \
+	((off_t)(((size) + lfs_sb_getffmask(fs)) & (~lfs_sb_getffmask(fs))))
+#define lfs_fragstoblks(fs, frags)/* calculates (frags / fs->fs_frag) */ \
+	((frags) >> lfs_sb_getfbshift(fs))
+#define lfs_blkstofrags(fs, blks)/* calculates (blks * fs->fs_frag) */ \
+	((blks) << lfs_sb_getfbshift(fs))
+#define lfs_fragnum(fs, fsb)	/* calculates (fsb % fs->lfs_frag) */	\
+	((fsb) & ((fs)->lfs_frag - 1))
+#define lfs_blknum(fs, fsb)	/* calculates rounddown(fsb, fs->lfs_frag) */ \
+	((fsb) &~ ((fs)->lfs_frag - 1))
+#define lfs_dblksize(fs, dp, lbn) \
+	(((lbn) >= ULFS_NDADDR || (dp)->di_size >= ((lbn) + 1) << lfs_sb_getbshift(fs)) \
+	    ? lfs_sb_getbsize(fs) \
+	    : (lfs_fragroundup(fs, lfs_blkoff(fs, (dp)->di_size))))
+
+#define	lfs_segsize(fs)	((fs)->lfs_version == 1 ?	     		\
+			   lfs_lblktosize((fs), lfs_sb_getssize(fs)) :	\
+			   lfs_sb_getssize(fs))
+#define lfs_segtod(fs, seg) (((fs)->lfs_version == 1     ?	    	\
+			   lfs_sb_getssize(fs) << lfs_sb_getblktodb(fs) : \
+			   lfs_btofsb((fs), lfs_sb_getssize(fs))) * (seg))
+#define	lfs_dtosn(fs, daddr)	/* block address to segment number */	\
+	((uint32_t)(((daddr) - lfs_sb_gets0addr(fs)) / lfs_segtod((fs), 1)))
+#define lfs_sntod(fs, sn)	/* segment number to disk address */	\
+	((daddr_t)(lfs_segtod((fs), (sn)) + lfs_sb_gets0addr(fs)))
+
+/*
+ * Macros for determining free space on the disk, with the variable metadata
+ * of segment summaries and inode blocks taken into account.
+ */
+/*
+ * Estimate number of clean blocks not available for writing because
+ * they will contain metadata or overhead.  This is calculated as
+ *
+ *		E = ((C * M / D) * D + (0) * (T - D)) / T
+ * or more simply
+ *		E = (C * M) / T
+ *
+ * where
+ * C is the clean space,
+ * D is the dirty space,
+ * M is the dirty metadata, and
+ * T = C + D is the total space on disk.
+ *
+ * This approximates the old formula of E = C * M / D when D is close to T,
+ * but avoids falsely reporting "disk full" when the sample size (D) is small.
+ */
+#define LFS_EST_CMETA(F) (int32_t)((					\
+	(lfs_sb_getdmeta(F) * (int64_t)lfs_sb_getnclean(F)) / 		\
+	(lfs_sb_getnseg(F))))
+
+/* Estimate total size of the disk not including metadata */
+#define LFS_EST_NONMETA(F) (lfs_sb_getdsize(F) - lfs_sb_getdmeta(F) - LFS_EST_CMETA(F))
+
+/* Estimate number of blocks actually available for writing */
+#define LFS_EST_BFREE(F) (lfs_sb_getbfree(F) > LFS_EST_CMETA(F) ?	     \
+			  lfs_sb_getbfree(F) - LFS_EST_CMETA(F) : 0)
+
+/* Amount of non-meta space not available to mortal man */
+#define LFS_EST_RSVD(F) (int32_t)((LFS_EST_NONMETA(F) *			     \
+				   (u_int64_t)lfs_sb_getminfree(F)) /	     \
+				  100)
+
+/* Can credential C write BB blocks */
+#define ISSPACE(F, BB, C)						\
+	((((C) == NOCRED || kauth_cred_geteuid(C) == 0) &&		\
+	  LFS_EST_BFREE(F) >= (BB)) ||					\
+	 (kauth_cred_geteuid(C) != 0 && IS_FREESPACE(F, BB)))
+
+/* Can an ordinary user write BB blocks */
+#define IS_FREESPACE(F, BB)						\
+	  (LFS_EST_BFREE(F) >= (BB) + LFS_EST_RSVD(F))
+
+/*
+ * The minimum number of blocks to create a new inode.  This is:
+ * directory direct block (1) + ULFS_NIADDR indirect blocks + inode block (1) +
+ * ifile direct block (1) + ULFS_NIADDR indirect blocks = 3 + 2 * ULFS_NIADDR blocks.
+ */
+#define LFS_NRESERVE(F) (lfs_btofsb((F), (2 * ULFS_NIADDR + 3) << lfs_sb_getbshift(F)))
+
+
+
+#endif /* _UFS_LFS_LFS_ACCESSORS_H_ */

Reply via email to