Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Jan 2010 09:49:54 +0000 (UTC)
From:      Jeff Roberson <jeff@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   svn commit: r202688 - in projects/suj/8: . contrib/top lib/libufs lib/libusb sbin/fsck_ffs sbin/fsdb sbin/mount sbin/tunefs share/man/man4 sys/kern sys/sys sys/ufs/ffs sys/ufs/ufs tools/regression/...
Message-ID:  <201001200949.o0K9nsgX076781@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jeff
Date: Wed Jan 20 09:49:53 2010
New Revision: 202688
URL: http://svn.freebsd.org/changeset/base/202688

Log:
   - Merge SUJ from the private head branch to the private 8 branch.

Added:
  projects/suj/8/sbin/fsck_ffs/suj.c
     - copied unchanged from r202685, projects/suj/head/sbin/fsck_ffs/suj.c
Modified:
  projects/suj/8/lib/libufs/Makefile
  projects/suj/8/lib/libufs/cgroup.c
  projects/suj/8/lib/libufs/inode.c
  projects/suj/8/lib/libufs/libufs.h
  projects/suj/8/lib/libufs/sblock.c
  projects/suj/8/lib/libufs/type.c
  projects/suj/8/sbin/fsck_ffs/Makefile
  projects/suj/8/sbin/fsck_ffs/fsck.h
  projects/suj/8/sbin/fsck_ffs/gjournal.c
  projects/suj/8/sbin/fsck_ffs/main.c
  projects/suj/8/sbin/fsck_ffs/pass4.c
  projects/suj/8/sbin/fsck_ffs/pass5.c
  projects/suj/8/sbin/fsdb/fsdbutil.c
  projects/suj/8/sbin/mount/mount.c
  projects/suj/8/sbin/tunefs/tunefs.c
  projects/suj/8/sys/kern/vfs_bio.c
  projects/suj/8/sys/kern/vfs_subr.c
  projects/suj/8/sys/sys/buf.h
  projects/suj/8/sys/sys/mount.h
  projects/suj/8/sys/ufs/ffs/ffs_alloc.c
  projects/suj/8/sys/ufs/ffs/ffs_balloc.c
  projects/suj/8/sys/ufs/ffs/ffs_extern.h
  projects/suj/8/sys/ufs/ffs/ffs_inode.c
  projects/suj/8/sys/ufs/ffs/ffs_snapshot.c
  projects/suj/8/sys/ufs/ffs/ffs_softdep.c
  projects/suj/8/sys/ufs/ffs/ffs_subr.c
  projects/suj/8/sys/ufs/ffs/ffs_vfsops.c
  projects/suj/8/sys/ufs/ffs/ffs_vnops.c
  projects/suj/8/sys/ufs/ffs/fs.h
  projects/suj/8/sys/ufs/ffs/softdep.h
  projects/suj/8/sys/ufs/ufs/dinode.h
  projects/suj/8/sys/ufs/ufs/inode.h
  projects/suj/8/sys/ufs/ufs/ufs_dirhash.c
  projects/suj/8/sys/ufs/ufs/ufs_extern.h
  projects/suj/8/sys/ufs/ufs/ufs_lookup.c
  projects/suj/8/sys/ufs/ufs/ufs_vnops.c
  projects/suj/8/sys/ufs/ufs/ufsmount.h
  projects/suj/8/usr.sbin/makefs/ffs/ffs_bswap.c   (contents, props changed)
Directory Properties:
  projects/suj/8/   (props changed)
  projects/suj/8/ObsoleteFiles.inc   (props changed)
  projects/suj/8/UPDATING   (props changed)
  projects/suj/8/bin/   (props changed)
  projects/suj/8/bin/csh/   (props changed)
  projects/suj/8/bin/pax/   (props changed)
  projects/suj/8/bin/ps/   (props changed)
  projects/suj/8/bin/sh/   (props changed)
  projects/suj/8/cddl/compat/opensolaris/   (props changed)
  projects/suj/8/cddl/contrib/opensolaris/   (props changed)
  projects/suj/8/cddl/contrib/opensolaris/cmd/zdb/   (props changed)
  projects/suj/8/cddl/contrib/opensolaris/cmd/zfs/   (props changed)
  projects/suj/8/cddl/contrib/opensolaris/lib/libzfs/   (props changed)
  projects/suj/8/cddl/lib/libnvpair/   (props changed)
  projects/suj/8/contrib/bind9/   (props changed)
  projects/suj/8/contrib/bsnmp/   (props changed)
  projects/suj/8/contrib/bzip2/   (props changed)
  projects/suj/8/contrib/cpio/   (props changed)
  projects/suj/8/contrib/csup/   (props changed)
  projects/suj/8/contrib/ee/   (props changed)
  projects/suj/8/contrib/expat/   (props changed)
  projects/suj/8/contrib/file/   (props changed)
  projects/suj/8/contrib/gcc/   (props changed)
  projects/suj/8/contrib/gdb/   (props changed)
  projects/suj/8/contrib/gdtoa/   (props changed)
  projects/suj/8/contrib/groff/   (props changed)
  projects/suj/8/contrib/less/   (props changed)
  projects/suj/8/contrib/libpcap/   (props changed)
  projects/suj/8/contrib/ncurses/   (props changed)
  projects/suj/8/contrib/netcat/   (props changed)
  projects/suj/8/contrib/ntp/   (props changed)
  projects/suj/8/contrib/one-true-awk/   (props changed)
  projects/suj/8/contrib/openbsm/   (props changed)
  projects/suj/8/contrib/openpam/   (props changed)
  projects/suj/8/contrib/pf/   (props changed)
  projects/suj/8/contrib/sendmail/   (props changed)
  projects/suj/8/contrib/tcpdump/   (props changed)
  projects/suj/8/contrib/tcsh/   (props changed)
  projects/suj/8/contrib/top/   (props changed)
  projects/suj/8/contrib/top/install-sh   (props changed)
  projects/suj/8/contrib/traceroute/   (props changed)
  projects/suj/8/contrib/wpa/   (props changed)
  projects/suj/8/crypto/heimdal/   (props changed)
  projects/suj/8/crypto/openssh/   (props changed)
  projects/suj/8/crypto/openssl/   (props changed)
  projects/suj/8/etc/   (props changed)
  projects/suj/8/etc/rc.d/   (props changed)
  projects/suj/8/games/factor/   (props changed)
  projects/suj/8/games/fortune/   (props changed)
  projects/suj/8/games/fortune/datfiles/   (props changed)
  projects/suj/8/gnu/usr.bin/groff/   (props changed)
  projects/suj/8/gnu/usr.bin/patch/   (props changed)
  projects/suj/8/include/   (props changed)
  projects/suj/8/kerberos5/lib/libgssapi_krb5/   (props changed)
  projects/suj/8/kerberos5/lib/libgssapi_spnego/   (props changed)
  projects/suj/8/lib/bind/   (props changed)
  projects/suj/8/lib/csu/   (props changed)
  projects/suj/8/lib/libarchive/   (props changed)
  projects/suj/8/lib/libc/   (props changed)
  projects/suj/8/lib/libc/stdtime/   (props changed)
  projects/suj/8/lib/libdevinfo/   (props changed)
  projects/suj/8/lib/libdisk/   (props changed)
  projects/suj/8/lib/libelf/   (props changed)
  projects/suj/8/lib/libexpat/   (props changed)
  projects/suj/8/lib/libfetch/   (props changed)
  projects/suj/8/lib/libjail/   (props changed)
  projects/suj/8/lib/libkvm/   (props changed)
  projects/suj/8/lib/libpmc/   (props changed)
  projects/suj/8/lib/libradius/   (props changed)
  projects/suj/8/lib/libstand/   (props changed)
  projects/suj/8/lib/libtacplus/   (props changed)
  projects/suj/8/lib/libthr/   (props changed)
  projects/suj/8/lib/libusb/   (props changed)
  projects/suj/8/lib/libusb/usb.h   (props changed)
  projects/suj/8/lib/libutil/   (props changed)
  projects/suj/8/libexec/rtld-elf/   (props changed)
  projects/suj/8/release/   (props changed)
  projects/suj/8/release/doc/   (props changed)
  projects/suj/8/release/doc/en_US.ISO8859-1/hardware/   (props changed)
  projects/suj/8/sbin/   (props changed)
  projects/suj/8/sbin/atacontrol/   (props changed)
  projects/suj/8/sbin/bsdlabel/   (props changed)
  projects/suj/8/sbin/camcontrol/   (props changed)
  projects/suj/8/sbin/ddb/   (props changed)
  projects/suj/8/sbin/dhclient/   (props changed)
  projects/suj/8/sbin/fsck/   (props changed)
  projects/suj/8/sbin/geom/   (props changed)
  projects/suj/8/sbin/geom/class/stripe/   (props changed)
  projects/suj/8/sbin/ifconfig/   (props changed)
  projects/suj/8/sbin/ipfw/   (props changed)
  projects/suj/8/sbin/mksnap_ffs/   (props changed)
  projects/suj/8/sbin/mount/   (props changed)
  projects/suj/8/sbin/mount_cd9660/   (props changed)
  projects/suj/8/sbin/mount_msdosfs/   (props changed)
  projects/suj/8/sbin/mount_nfs/   (props changed)
  projects/suj/8/sbin/umount/   (props changed)
  projects/suj/8/secure/usr.bin/bdes/   (props changed)
  projects/suj/8/share/examples/   (props changed)
  projects/suj/8/share/man/man3/   (props changed)
  projects/suj/8/share/man/man4/   (props changed)
  projects/suj/8/share/man/man4/de.4   (props changed)
  projects/suj/8/share/man/man5/   (props changed)
  projects/suj/8/share/man/man7/   (props changed)
  projects/suj/8/share/man/man8/   (props changed)
  projects/suj/8/share/man/man9/   (props changed)
  projects/suj/8/share/misc/   (props changed)
  projects/suj/8/share/timedef/   (props changed)
  projects/suj/8/share/zoneinfo/   (props changed)
  projects/suj/8/sys/   (props changed)
  projects/suj/8/sys/amd64/include/xen/   (props changed)
  projects/suj/8/sys/cddl/contrib/opensolaris/   (props changed)
  projects/suj/8/sys/contrib/dev/acpica/   (props changed)
  projects/suj/8/sys/contrib/pf/   (props changed)
  projects/suj/8/sys/dev/xen/xenpci/   (props changed)
  projects/suj/8/tools/kerneldoc/subsys/   (props changed)
  projects/suj/8/tools/regression/bin/sh/   (props changed)
  projects/suj/8/tools/regression/lib/libc/   (props changed)
  projects/suj/8/tools/regression/lib/msun/test-conj.t   (props changed)
  projects/suj/8/tools/regression/poll/   (props changed)
  projects/suj/8/tools/regression/priv/   (props changed)
  projects/suj/8/tools/regression/usr.bin/pkill/pgrep-_g.t   (props changed)
  projects/suj/8/tools/regression/usr.bin/pkill/pgrep-_s.t   (props changed)
  projects/suj/8/tools/regression/usr.bin/pkill/pkill-_g.t   (props changed)
  projects/suj/8/tools/tools/ath/common/dumpregs.h   (props changed)
  projects/suj/8/tools/tools/ath/common/dumpregs_5210.c   (props changed)
  projects/suj/8/tools/tools/ath/common/dumpregs_5211.c   (props changed)
  projects/suj/8/tools/tools/ath/common/dumpregs_5212.c   (props changed)
  projects/suj/8/tools/tools/ath/common/dumpregs_5416.c   (props changed)
  projects/suj/8/tools/tools/termcap/termcap.pl   (props changed)
  projects/suj/8/tools/tools/vimage/   (props changed)
  projects/suj/8/usr.bin/awk/   (props changed)
  projects/suj/8/usr.bin/calendar/   (props changed)
  projects/suj/8/usr.bin/calendar/calendars/calendar.freebsd   (props changed)
  projects/suj/8/usr.bin/csup/   (props changed)
  projects/suj/8/usr.bin/fetch/   (props changed)
  projects/suj/8/usr.bin/find/   (props changed)
  projects/suj/8/usr.bin/finger/   (props changed)
  projects/suj/8/usr.bin/fstat/   (props changed)
  projects/suj/8/usr.bin/gcore/   (props changed)
  projects/suj/8/usr.bin/gzip/   (props changed)
  projects/suj/8/usr.bin/kdump/   (props changed)
  projects/suj/8/usr.bin/locale/   (props changed)
  projects/suj/8/usr.bin/look/   (props changed)
  projects/suj/8/usr.bin/netstat/   (props changed)
  projects/suj/8/usr.bin/perror/   (props changed)
  projects/suj/8/usr.bin/procstat/   (props changed)
  projects/suj/8/usr.bin/systat/   (props changed)
  projects/suj/8/usr.bin/tftp/   (props changed)
  projects/suj/8/usr.bin/unifdef/   (props changed)
  projects/suj/8/usr.bin/vmstat/   (props changed)
  projects/suj/8/usr.bin/w/   (props changed)
  projects/suj/8/usr.bin/whois/   (props changed)
  projects/suj/8/usr.sbin/   (props changed)
  projects/suj/8/usr.sbin/Makefile   (props changed)
  projects/suj/8/usr.sbin/acpi/   (props changed)
  projects/suj/8/usr.sbin/arp/   (props changed)
  projects/suj/8/usr.sbin/bsnmpd/   (props changed)
  projects/suj/8/usr.sbin/burncd/   (props changed)
  projects/suj/8/usr.sbin/cdcontrol/   (props changed)
  projects/suj/8/usr.sbin/crashinfo/   (props changed)
  projects/suj/8/usr.sbin/cron/   (props changed)
  projects/suj/8/usr.sbin/diskinfo/   (props changed)
  projects/suj/8/usr.sbin/dumpcis/cardinfo.h   (props changed)
  projects/suj/8/usr.sbin/dumpcis/cis.h   (props changed)
  projects/suj/8/usr.sbin/faithd/   (props changed)
  projects/suj/8/usr.sbin/freebsd-update/   (props changed)
  projects/suj/8/usr.sbin/inetd/   (props changed)
  projects/suj/8/usr.sbin/iostat/   (props changed)
  projects/suj/8/usr.sbin/jail/   (props changed)
  projects/suj/8/usr.sbin/jls/   (props changed)
  projects/suj/8/usr.sbin/lpr/   (props changed)
  projects/suj/8/usr.sbin/makefs/ffs/ffs_subr.c   (props changed)
  projects/suj/8/usr.sbin/makefs/ffs/ufs_bswap.h   (props changed)
  projects/suj/8/usr.sbin/makefs/getid.c   (props changed)
  projects/suj/8/usr.sbin/mergemaster/   (props changed)
  projects/suj/8/usr.sbin/mfiutil/mfiutil.8   (props changed)
  projects/suj/8/usr.sbin/ndp/   (props changed)
  projects/suj/8/usr.sbin/ntp/   (props changed)
  projects/suj/8/usr.sbin/powerd/   (props changed)
  projects/suj/8/usr.sbin/ppp/   (props changed)
  projects/suj/8/usr.sbin/pstat/   (props changed)
  projects/suj/8/usr.sbin/rtsold/   (props changed)
  projects/suj/8/usr.sbin/service/   (props changed)
  projects/suj/8/usr.sbin/sysinstall/   (props changed)
  projects/suj/8/usr.sbin/syslogd/   (props changed)
  projects/suj/8/usr.sbin/traceroute/   (props changed)
  projects/suj/8/usr.sbin/traceroute6/   (props changed)
  projects/suj/8/usr.sbin/usbconfig/   (props changed)
  projects/suj/8/usr.sbin/wpa/   (props changed)
  projects/suj/8/usr.sbin/ypserv/   (props changed)
  projects/suj/8/usr.sbin/zic/   (props changed)

Modified: projects/suj/8/lib/libufs/Makefile
==============================================================================
--- projects/suj/8/lib/libufs/Makefile	Wed Jan 20 09:48:46 2010	(r202687)
+++ projects/suj/8/lib/libufs/Makefile	Wed Jan 20 09:49:53 2010	(r202688)
@@ -3,7 +3,7 @@
 LIB=	ufs
 SHLIBDIR?= /lib
 
-SRCS=	block.c cgroup.c inode.c sblock.c type.c
+SRCS=	block.c cgroup.c inode.c sblock.c type.c ffs_subr.c ffs_tables.c
 INCS=	libufs.h
 
 MAN=	bread.3 cgread.3 libufs.3 sbread.3 ufs_disk_close.3
@@ -18,6 +18,9 @@ MLINKS+= ufs_disk_close.3 ufs_disk_write
 
 WARNS?=	2
 
+.PATH:  ${.CURDIR}/../../sys/ufs/ffs
+
+DEBUG_FLAGS = -g
 CFLAGS+= -D_LIBUFS
 .if defined(LIBUFS_DEBUG)
 CFLAGS+= -D_LIBUFS_DEBUGGING

Modified: projects/suj/8/lib/libufs/cgroup.c
==============================================================================
--- projects/suj/8/lib/libufs/cgroup.c	Wed Jan 20 09:48:46 2010	(r202687)
+++ projects/suj/8/lib/libufs/cgroup.c	Wed Jan 20 09:49:53 2010	(r202688)
@@ -40,11 +40,82 @@ __FBSDID("$FreeBSD$");
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
 #include <libufs.h>
 
+ufs2_daddr_t
+cgballoc(struct uufsd *disk)
+{
+	u_int8_t *blksfree;
+	struct cg *cgp;
+	struct fs *fs;
+	long bno;
+
+	fs = &disk->d_fs;
+	cgp = &disk->d_cg;
+	blksfree = cg_blksfree(cgp);
+	for (bno = 0; bno < fs->fs_fpg / fs->fs_frag; bno++)
+		if (ffs_isblock(fs, blksfree, bno))
+			goto gotit;
+	return (0);
+gotit:
+	fs->fs_cs(fs, cgp->cg_cgx).cs_nbfree--;
+	ffs_clrblock(fs, blksfree, (long)bno);
+	ffs_clusteracct(fs, cgp, bno, -1);
+	cgp->cg_cs.cs_nbfree--;
+	fs->fs_cstotal.cs_nbfree--;
+	fs->fs_fmod = 1;
+	return (cgbase(fs, cgp->cg_cgx) + blkstofrags(fs, bno));
+}
+
+ino_t
+cgialloc(struct uufsd *disk)
+{
+	struct ufs2_dinode *dp2;
+	u_int8_t *inosused;
+	struct cg *cgp;
+	struct fs *fs;
+	ino_t ino;
+	int i;
+
+	fs = &disk->d_fs;
+	cgp = &disk->d_cg;
+	inosused = cg_inosused(cgp);
+	for (ino = 0; ino < fs->fs_ipg / NBBY; ino++)
+		if (isclr(inosused, ino))
+			goto gotit;
+	return (0);
+gotit:
+	if (fs->fs_magic == FS_UFS2_MAGIC &&
+	    ino + INOPB(fs) > cgp->cg_initediblk &&
+	    cgp->cg_initediblk < cgp->cg_niblk) {
+		char block[MAXBSIZE];
+		bzero(block, (int)fs->fs_bsize);
+		dp2 = (struct ufs2_dinode *)&block;
+		for (i = 0; i < INOPB(fs); i++) {
+			dp2->di_gen = arc4random() / 2 + 1;
+			dp2++;
+		}
+		if (bwrite(disk, ino_to_fsba(fs,
+		    cgp->cg_cgx * fs->fs_ipg + cgp->cg_initediblk),
+		    block, fs->fs_bsize))
+			return (0);
+		cgp->cg_initediblk += INOPB(fs);
+	}
+
+	setbit(inosused, ino);
+	cgp->cg_irotor = ino;
+	cgp->cg_cs.cs_nifree--;
+	fs->fs_cstotal.cs_nifree--;
+	fs->fs_cs(fs, cgp->cg_cgx).cs_nifree--;
+	fs->fs_fmod = 1;
+
+	return (ino + (cgp->cg_cgx * fs->fs_ipg));
+}
+
 int
 cgread(struct uufsd *disk)
 {
@@ -55,14 +126,12 @@ int
 cgread1(struct uufsd *disk, int c)
 {
 	struct fs *fs;
-	off_t ccg;
 
 	fs = &disk->d_fs;
 
 	if (c >= fs->fs_ncg) {
 		return (0);
 	}
-	ccg = fsbtodb(fs, cgtod(fs, c)) * disk->d_bsize;
 	if (bread(disk, fsbtodb(fs, cgtod(fs, c)), disk->d_cgunion.d_buf,
 	    fs->fs_bsize) == -1) {
 		ERROR(disk, "unable to read cylinder group");
@@ -73,6 +142,12 @@ cgread1(struct uufsd *disk, int c)
 }
 
 int
+cgwrite(struct uufsd *disk)
+{
+	return (cgwrite1(disk, disk->d_lcg));
+}
+
+int
 cgwrite1(struct uufsd *disk, int c)
 {
 	struct fs *fs;

Modified: projects/suj/8/lib/libufs/inode.c
==============================================================================
--- projects/suj/8/lib/libufs/inode.c	Wed Jan 20 09:48:46 2010	(r202687)
+++ projects/suj/8/lib/libufs/inode.c	Wed Jan 20 09:49:53 2010	(r202688)
@@ -93,3 +93,19 @@ gotit:	switch (disk->d_ufs) {
 	ERROR(disk, "unknown UFS filesystem type");
 	return (-1);
 }
+
+int
+putino(struct uufsd *disk)
+{
+	struct fs *fs;
+
+	fs = &disk->d_fs;
+	if (disk->d_inoblock == NULL) {
+		ERROR(disk, "No inode block allocated");
+		return (-1);
+	}
+	if (bwrite(disk, fsbtodb(fs, ino_to_fsba(&disk->d_fs, disk->d_inomin)),
+	    disk->d_inoblock, disk->d_fs.fs_bsize) <= 0)
+		return (-1);
+	return (0);
+}

Modified: projects/suj/8/lib/libufs/libufs.h
==============================================================================
--- projects/suj/8/lib/libufs/libufs.h	Wed Jan 20 09:48:46 2010	(r202687)
+++ projects/suj/8/lib/libufs/libufs.h	Wed Jan 20 09:49:53 2010	(r202688)
@@ -71,6 +71,7 @@ struct uufsd {
 	int d_fd;		/* raw device file descriptor */
 	long d_bsize;		/* device bsize */
 	ufs2_daddr_t d_sblock;	/* superblock location */
+	struct csum *d_sbcsum;	/* Superblock summary info */
 	caddr_t d_inoblock;	/* inode block */
 	ino_t d_inomin;		/* low inode */
 	ino_t d_inomax;		/* high inode */
@@ -109,14 +110,18 @@ int berase(struct uufsd *, ufs2_daddr_t,
 /*
  * cgroup.c
  */
+ufs2_daddr_t cgballoc(struct uufsd *);
+ino_t cgialloc(struct uufsd *);
 int cgread(struct uufsd *);
 int cgread1(struct uufsd *, int);
+int cgwrite(struct uufsd *);
 int cgwrite1(struct uufsd *, int);
 
 /*
  * inode.c
  */
 int getino(struct uufsd *, void **, ino_t, int *);
+int putino(struct uufsd *);
 
 /*
  * sblock.c
@@ -132,6 +137,16 @@ int ufs_disk_fillout(struct uufsd *, con
 int ufs_disk_fillout_blank(struct uufsd *, const char *);
 int ufs_disk_write(struct uufsd *);
 
+/*
+ * ffs_subr.c
+ */
+void	ffs_clrblock(struct fs *, u_char *, ufs1_daddr_t);
+void	ffs_clusteracct(struct fs *, struct cg *, ufs1_daddr_t, int);
+void	ffs_fragacct(struct fs *, int, int32_t [], int);
+int	ffs_isblock(struct fs *, u_char *, ufs1_daddr_t);
+int	ffs_isfreeblock(struct fs *, u_char *, ufs1_daddr_t);
+void	ffs_setblock(struct fs *, u_char *, ufs1_daddr_t);
+
 __END_DECLS
 
 #endif	/* __LIBUFS_H__ */

Modified: projects/suj/8/lib/libufs/sblock.c
==============================================================================
--- projects/suj/8/lib/libufs/sblock.c	Wed Jan 20 09:48:46 2010	(r202687)
+++ projects/suj/8/lib/libufs/sblock.c	Wed Jan 20 09:49:53 2010	(r202688)
@@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$");
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
+#include <stdlib.h>
 #include <unistd.h>
 
 #include <libufs.h>
@@ -49,8 +50,11 @@ static int superblocks[] = SBLOCKSEARCH;
 int
 sbread(struct uufsd *disk)
 {
+	uint8_t block[MAXBSIZE];
 	struct fs *fs;
 	int sb, superblock;
+	int i, size, blks;
+	uint8_t *space;
 
 	ERROR(disk, NULL);
 
@@ -86,6 +90,34 @@ sbread(struct uufsd *disk)
 	}
 	disk->d_bsize = fs->fs_fsize / fsbtodb(fs, 1);
 	disk->d_sblock = superblock / disk->d_bsize;
+	/*
+	 * Read in the superblock summary information.
+	 */
+	size = fs->fs_cssize;
+	blks = howmany(size, fs->fs_fsize);
+	size += fs->fs_ncg * sizeof(int32_t);
+	space = malloc(size);
+	if (space == NULL) {
+		ERROR(disk, "failed to allocate space for summary information");
+		return (-1);
+	}
+	fs->fs_csp = (struct csum *)space;
+	for (i = 0; i < blks; i += fs->fs_frag) {
+		size = fs->fs_bsize;
+		if (i + fs->fs_frag > blks)
+			size = (blks - i) * fs->fs_fsize;
+		if (bread(disk, fsbtodb(fs, fs->fs_csaddr + i), block, size)
+		    == -1) {
+			ERROR(disk, "Failed to read sb summary information");
+			free(fs->fs_csp);
+			return (-1);
+		}
+		bcopy(block, space, size);
+		space += size;
+	}
+	fs->fs_maxcluster = (uint32_t *)space;
+	disk->d_sbcsum = fs->fs_csp;
+
 	return (0);
 }
 
@@ -93,7 +125,8 @@ int
 sbwrite(struct uufsd *disk, int all)
 {
 	struct fs *fs;
-	int i;
+	int i, blks, size;
+	uint8_t *space;
 
 	ERROR(disk, NULL);
 
@@ -107,6 +140,22 @@ sbwrite(struct uufsd *disk, int all)
 		ERROR(disk, "failed to write superblock");
 		return (-1);
 	}
+	/*
+	 * Write superblock summary information.
+	 */
+	blks = howmany(fs->fs_cssize, fs->fs_fsize);
+	space = (uint8_t *)disk->d_sbcsum;
+	for (i = 0; i < blks; i += fs->fs_frag) {
+		size = fs->fs_bsize;
+		if (i + fs->fs_frag > blks)
+			size = (blks - i) * fs->fs_fsize;
+		if (bwrite(disk, fsbtodb(fs, fs->fs_csaddr + i), space, size)
+		    == -1) {
+			ERROR(disk, "Failed to write sb summary information");
+			return (-1);
+		}
+		space += size;
+	}
 	if (all) {
 		for (i = 0; i < fs->fs_ncg; i++)
 			if (bwrite(disk, fsbtodb(fs, cgsblock(fs, i)),

Modified: projects/suj/8/lib/libufs/type.c
==============================================================================
--- projects/suj/8/lib/libufs/type.c	Wed Jan 20 09:48:46 2010	(r202687)
+++ projects/suj/8/lib/libufs/type.c	Wed Jan 20 09:49:53 2010	(r202688)
@@ -66,6 +66,10 @@ ufs_disk_close(struct uufsd *disk)
 		free((char *)(uintptr_t)disk->d_name);
 		disk->d_name = NULL;
 	}
+	if (disk->d_sbcsum != NULL) {
+		free(disk->d_sbcsum);
+		disk->d_sbcsum = NULL;
+	}
 	return (0);
 }
 
@@ -156,6 +160,7 @@ again:	if ((ret = stat(name, &st)) < 0) 
 	disk->d_mine = 0;
 	disk->d_ufs = 0;
 	disk->d_error = NULL;
+	disk->d_sbcsum = NULL;
 
 	if (oname != name) {
 		name = strdup(name);

Modified: projects/suj/8/sbin/fsck_ffs/Makefile
==============================================================================
--- projects/suj/8/sbin/fsck_ffs/Makefile	Wed Jan 20 09:48:46 2010	(r202687)
+++ projects/suj/8/sbin/fsck_ffs/Makefile	Wed Jan 20 09:49:53 2010	(r202688)
@@ -7,8 +7,7 @@ LINKS+=	${BINDIR}/fsck_ffs ${BINDIR}/fsc
 MAN=	fsck_ffs.8
 MLINKS=	fsck_ffs.8 fsck_ufs.8 fsck_ffs.8 fsck_4.2bsd.8
 SRCS=	dir.c ea.c fsutil.c inode.c main.c pass1.c pass1b.c pass2.c pass3.c \
-	pass4.c pass5.c setup.c utilities.c ffs_subr.c ffs_tables.c gjournal.c \
-	getmntopts.c
+	pass4.c pass5.c setup.c suj.c utilities.c gjournal.c getmntopts.c
 DPADD=	${LIBUFS}
 LDADD=	-lufs
 WARNS?=	2

Modified: projects/suj/8/sbin/fsck_ffs/fsck.h
==============================================================================
--- projects/suj/8/sbin/fsck_ffs/fsck.h	Wed Jan 20 09:48:46 2010	(r202687)
+++ projects/suj/8/sbin/fsck_ffs/fsck.h	Wed Jan 20 09:49:53 2010	(r202688)
@@ -347,10 +347,6 @@ void		direrror(ino_t ino, const char *er
 int		dirscan(struct inodesc *);
 int		dofix(struct inodesc *, const char *msg);
 int		eascan(struct inodesc *, struct ufs2_dinode *dp);
-void		ffs_clrblock(struct fs *, u_char *, ufs1_daddr_t);
-void		ffs_fragacct(struct fs *, int, int32_t [], int);
-int		ffs_isblock(struct fs *, u_char *, ufs1_daddr_t);
-void		ffs_setblock(struct fs *, u_char *, ufs1_daddr_t);
 void		fileerror(ino_t cwd, ino_t ino, const char *errmesg);
 int		findino(struct inodesc *);
 int		findname(struct inodesc *);
@@ -392,3 +388,4 @@ void		sblock_init(void);
 void		setinodebuf(ino_t);
 int		setup(char *dev);
 void		gjournal_check(const char *filesys);
+void		suj_check(const char *filesys);

Modified: projects/suj/8/sbin/fsck_ffs/gjournal.c
==============================================================================
--- projects/suj/8/sbin/fsck_ffs/gjournal.c	Wed Jan 20 09:48:46 2010	(r202687)
+++ projects/suj/8/sbin/fsck_ffs/gjournal.c	Wed Jan 20 09:49:53 2010	(r202688)
@@ -96,27 +96,6 @@ struct ufs2_dinode ufs2_zino;
 static void putcgs(void);
 
 /*
- * Write current block of inodes.
- */
-static int
-putino(struct uufsd *disk, ino_t inode)
-{
-	caddr_t inoblock;
-	struct fs *fs;
-	ssize_t ret;
-
-	fs = &disk->d_fs;
-	inoblock = disk->d_inoblock;
-
-	assert(inoblock != NULL);
-	assert(inode >= disk->d_inomin && inode <= disk->d_inomax);
-	ret = bwrite(disk, fsbtodb(fs, ino_to_fsba(fs, inode)), inoblock,
-	    fs->fs_bsize);
-
-	return (ret == -1 ? -1 : 0);
-}
-
-/*
  * Return cylinder group from the cache or load it if it is not in the
  * cache yet.
  * Don't cache more than MAX_CACHED_CGS cylinder groups.
@@ -242,13 +221,11 @@ cancelcgs(void)
 #endif
 
 /*
- * Open the given provider, load statistics.
+ * Open the given provider, load superblock.
  */
 static void
-getdisk(void)
+opendisk(void)
 {
-	int i;
-
 	if (disk != NULL)
 		return;
 	disk = malloc(sizeof(*disk));
@@ -259,24 +236,6 @@ getdisk(void)
 		    disk->d_error);
 	}
 	fs = &disk->d_fs;
-	fs->fs_csp = malloc((size_t)fs->fs_cssize);
-	if (fs->fs_csp == NULL)
-		err(1, "malloc(%zu)", (size_t)fs->fs_cssize);
-	bzero(fs->fs_csp, (size_t)fs->fs_cssize);
-	for (i = 0; i < fs->fs_cssize; i += fs->fs_bsize) {
-		if (bread(disk, fsbtodb(fs, fs->fs_csaddr + numfrags(fs, i)),
-		    (void *)(((char *)fs->fs_csp) + i),
-		    (size_t)(fs->fs_cssize - i < fs->fs_bsize ? fs->fs_cssize - i : fs->fs_bsize)) == -1) {
-			err(1, "bread: %s", disk->d_error);
-		}
-	}
-	if (fs->fs_contigsumsize > 0) {
-		fs->fs_maxcluster = malloc(fs->fs_ncg * sizeof(int32_t));
-		if (fs->fs_maxcluster == NULL)
-			err(1, "malloc(%zu)", fs->fs_ncg * sizeof(int32_t));
-		for (i = 0; i < fs->fs_ncg; i++)
-			fs->fs_maxcluster[i] = fs->fs_contigsumsize;
-	}
 }
 
 /*
@@ -286,11 +245,6 @@ static void
 closedisk(void)
 {
 
-	free(fs->fs_csp);
-	if (fs->fs_contigsumsize > 0) {
-		free(fs->fs_maxcluster);
-		fs->fs_maxcluster = NULL;
-	}
 	fs->fs_clean = 1;
 	if (sbwrite(disk, 0) == -1)
 		err(1, "sbwrite(%s)", devnam);
@@ -301,227 +255,6 @@ closedisk(void)
 	fs = NULL;
 }
 
-/*
- * Write the statistics back, call closedisk().
- */
-static void
-putdisk(void)
-{
-	int i;
-
-	assert(disk != NULL && fs != NULL);
-	for (i = 0; i < fs->fs_cssize; i += fs->fs_bsize) {
-		if (bwrite(disk, fsbtodb(fs, fs->fs_csaddr + numfrags(fs, i)),
-		    (void *)(((char *)fs->fs_csp) + i),
-		    (size_t)(fs->fs_cssize - i < fs->fs_bsize ? fs->fs_cssize - i : fs->fs_bsize)) == -1) {
-			err(1, "bwrite: %s", disk->d_error);
-		}
-	}
-	closedisk();
-}
-
-#if 0
-/*
- * Free memory, close the disk, but don't write anything back.
- */
-static void
-canceldisk(void)
-{
-	int i;
-
-	assert(disk != NULL && fs != NULL);
-	free(fs->fs_csp);
-	if (fs->fs_contigsumsize > 0)
-		free(fs->fs_maxcluster);
-	if (ufs_disk_close(disk) == -1)
-		err(1, "ufs_disk_close(%s)", devnam);
-	free(disk);
-	disk = NULL;
-	fs = NULL;
-}
-#endif
-
-static int
-isblock(unsigned char *cp, ufs1_daddr_t h)
-{
-	unsigned char mask;
-
-	switch ((int)fs->fs_frag) {
-	case 8:
-		return (cp[h] == 0xff);
-	case 4:
-		mask = 0x0f << ((h & 0x1) << 2);
-		return ((cp[h >> 1] & mask) == mask);
-	case 2:
-		mask = 0x03 << ((h & 0x3) << 1);
-		return ((cp[h >> 2] & mask) == mask);
-	case 1:
-		mask = 0x01 << (h & 0x7);
-		return ((cp[h >> 3] & mask) == mask);
-	default:
-		assert(!"isblock: invalid number of fragments");
-	}
-	return (0);
-}
-
-/*
- * put a block into the map
- */
-static void
-setblock(unsigned char *cp, ufs1_daddr_t h)
-{
-
-	switch ((int)fs->fs_frag) {
-	case 8:
-		cp[h] = 0xff;
-		return;
-	case 4:
-		cp[h >> 1] |= (0x0f << ((h & 0x1) << 2));
-		return;
-	case 2:
-		cp[h >> 2] |= (0x03 << ((h & 0x3) << 1));
-		return;
-	case 1:
-		cp[h >> 3] |= (0x01 << (h & 0x7));
-		return;
-	default:
-		assert(!"setblock: invalid number of fragments");
-	}
-}
-
-/*
- * check if a block is free
- */
-static int
-isfreeblock(u_char *cp, ufs1_daddr_t h)
-{
-
-	switch ((int)fs->fs_frag) {
-	case 8:
-		return (cp[h] == 0);
-	case 4:
-		return ((cp[h >> 1] & (0x0f << ((h & 0x1) << 2))) == 0);
-	case 2:
-		return ((cp[h >> 2] & (0x03 << ((h & 0x3) << 1))) == 0);
-	case 1:
-		return ((cp[h >> 3] & (0x01 << (h & 0x7))) == 0);
-	default:
-		assert(!"isfreeblock: invalid number of fragments");
-	}
-	return (0);
-}
-
-/*
- * Update the frsum fields to reflect addition or deletion
- * of some frags.
- */
-void
-fragacct(int fragmap, int32_t fraglist[], int cnt)
-{
-	int inblk;
-	int field, subfield;
-	int siz, pos;
-
-	inblk = (int)(fragtbl[fs->fs_frag][fragmap]) << 1;
-	fragmap <<= 1;
-	for (siz = 1; siz < fs->fs_frag; siz++) {
-		if ((inblk & (1 << (siz + (fs->fs_frag % NBBY)))) == 0)
-			continue;
-		field = around[siz];
-		subfield = inside[siz];
-		for (pos = siz; pos <= fs->fs_frag; pos++) {
-			if ((fragmap & field) == subfield) {
-				fraglist[siz] += cnt;
-				pos += siz;
-				field <<= siz;
-				subfield <<= siz;
-			}
-			field <<= 1;
-			subfield <<= 1;
-		}
-	}
-}
-
-static void
-clusteracct(struct cg *cgp, ufs1_daddr_t blkno)
-{
-	int32_t *sump;
-	int32_t *lp;
-	u_char *freemapp, *mapp;
-	int i, start, end, forw, back, map, bit;
-
-	if (fs->fs_contigsumsize <= 0)
-		return;
-	freemapp = cg_clustersfree(cgp);
-	sump = cg_clustersum(cgp);
-	/*
-	 * Clear the actual block.
-	 */
-	setbit(freemapp, blkno);
-	/*
-	 * Find the size of the cluster going forward.
-	 */
-	start = blkno + 1;
-	end = start + fs->fs_contigsumsize;
-	if (end >= cgp->cg_nclusterblks)
-		end = cgp->cg_nclusterblks;
-	mapp = &freemapp[start / NBBY];
-	map = *mapp++;
-	bit = 1 << (start % NBBY);
-	for (i = start; i < end; i++) {
-		if ((map & bit) == 0)
-			break;
-		if ((i & (NBBY - 1)) != (NBBY - 1)) {
-			bit <<= 1;
-		} else {
-			map = *mapp++;
-			bit = 1;
-		}
-	}
-	forw = i - start;
-	/*
-	 * Find the size of the cluster going backward.
-	 */
-	start = blkno - 1;
-	end = start - fs->fs_contigsumsize;
-	if (end < 0)
-		end = -1;
-	mapp = &freemapp[start / NBBY];
-	map = *mapp--;
-	bit = 1 << (start % NBBY);
-	for (i = start; i > end; i--) {
-		if ((map & bit) == 0)
-			break;
-		if ((i & (NBBY - 1)) != 0) {
-			bit >>= 1;
-		} else {
-			map = *mapp--;
-			bit = 1 << (NBBY - 1);
-		}
-	}
-	back = start - i;
-	/*
-	 * Account for old cluster and the possibly new forward and
-	 * back clusters.
-	 */
-	i = back + forw + 1;
-	if (i > fs->fs_contigsumsize)
-		i = fs->fs_contigsumsize;
-	sump[i]++;
-	if (back > 0)
-		sump[back]--;
-	if (forw > 0)
-		sump[forw]--;
-	/*
-	 * Update cluster summary information.
-	 */
-	lp = &sump[fs->fs_contigsumsize];
-	for (i = fs->fs_contigsumsize; i > 0; i--)
-		if (*lp-- > 0)
-			break;
-	fs->fs_maxcluster[cgp->cg_cgx] = i;
-}
-
 static void
 blkfree(ufs2_daddr_t bno, long size)
 {
@@ -539,10 +272,10 @@ blkfree(ufs2_daddr_t bno, long size)
 	blksfree = cg_blksfree(cgp);
 	if (size == fs->fs_bsize) {
 		fragno = fragstoblks(fs, cgbno);
-		if (!isfreeblock(blksfree, fragno))
+		if (!ffs_isfreeblock(fs, blksfree, fragno))
 			assert(!"blkfree: freeing free block");
-		setblock(blksfree, fragno);
-		clusteracct(cgp, fragno);
+		ffs_setblock(fs, blksfree, fragno);
+		ffs_clusteracct(fs, cgp, fragno, 1);
 		cgp->cg_cs.cs_nbfree++;
 		fs->fs_cstotal.cs_nbfree++;
 		fs->fs_cs(fs, cg).cs_nbfree++;
@@ -552,7 +285,7 @@ blkfree(ufs2_daddr_t bno, long size)
 		 * decrement the counts associated with the old frags
 		 */
 		blk = blkmap(fs, blksfree, bbase);
-		fragacct(blk, cgp->cg_frsum, -1);
+		ffs_fragacct(fs, blk, cgp->cg_frsum, -1);
 		/*
 		 * deallocate the fragment
 		 */
@@ -569,16 +302,16 @@ blkfree(ufs2_daddr_t bno, long size)
 		 * add back in counts associated with the new frags
 		 */
 		blk = blkmap(fs, blksfree, bbase);
-		fragacct(blk, cgp->cg_frsum, 1);
+		ffs_fragacct(fs, blk, cgp->cg_frsum, 1);
 		/*
 		 * if a complete block has been reassembled, account for it
 		 */
 		fragno = fragstoblks(fs, bbase);
-		if (isblock(blksfree, fragno)) {
+		if (ffs_isblock(fs, blksfree, fragno)) {
 			cgp->cg_cs.cs_nffree -= fs->fs_frag;
 			fs->fs_cstotal.cs_nffree -= fs->fs_frag;
 			fs->fs_cs(fs, cg).cs_nffree -= fs->fs_frag;
-			clusteracct(cgp, fragno);
+			ffs_clusteracct(fs, cgp, fragno, 1);
 			cgp->cg_cs.cs_nbfree++;
 			fs->fs_cstotal.cs_nbfree++;
 			fs->fs_cs(fs, cg).cs_nbfree++;
@@ -599,7 +332,7 @@ freeindir(ufs2_daddr_t blk, int level)
 	if (bread(disk, fsbtodb(fs, blk), (void *)&sblks, (size_t)fs->fs_bsize) == -1)
 		err(1, "bread: %s", disk->d_error);
 	blks = (ufs2_daddr_t *)&sblks;
-	for (i = 0; i < howmany(fs->fs_bsize, sizeof(ufs2_daddr_t)); i++) {
+	for (i = 0; i < NINDIR(fs); i++) {
 		if (blks[i] == 0)
 			break;
 		if (level == 0)
@@ -671,7 +404,7 @@ gjournal_check(const char *filesys)
 	int cg, mode;
 
 	devnam = filesys;
-	getdisk();
+	opendisk();
 	/* Are there any unreferenced inodes in this file system? */
 	if (fs->fs_unrefs == 0) {
 		//printf("No unreferenced inodes.\n");
@@ -747,7 +480,7 @@ gjournal_check(const char *filesys)
 			/* Zero-fill the inode. */
 			*dino = ufs2_zino;
 			/* Write the inode back. */
-			if (putino(disk, ino) == -1)
+			if (putino(disk) == -1)
 				err(1, "putino(cg=%d ino=%d)", cg, ino);
 			if (cgp->cg_unrefs == 0) {
 				//printf("No more unreferenced inodes in cg=%d.\n", cg);
@@ -772,5 +505,5 @@ gjournal_check(const char *filesys)
 	/* Write back modified cylinder groups. */
 	putcgs();
 	/* Write back updated statistics and super-block. */
-	putdisk();
+	closedisk();
 }

Modified: projects/suj/8/sbin/fsck_ffs/main.c
==============================================================================
--- projects/suj/8/sbin/fsck_ffs/main.c	Wed Jan 20 09:48:46 2010	(r202687)
+++ projects/suj/8/sbin/fsck_ffs/main.c	Wed Jan 20 09:49:53 2010	(r202688)
@@ -256,7 +256,7 @@ checkfilesys(char *filesys)
 	}
 	if (ckclean && skipclean) {
 		/*
-		 * If file system is gjournaled, check it here.
+		 * If file system is gjournaled or su+j, check it here.
 		 */
 		if ((fsreadfd = open(filesys, O_RDONLY)) < 0 || readsb(0) == 0)
 			exit(3);	/* Cannot read superblock */
@@ -278,6 +278,18 @@ checkfilesys(char *filesys)
 				    "CANNOT RUN FAST FSCK\n");
 			}
 		}
+#if 0
+		if ((sblock.fs_flags & FS_SUJ) != 0) {
+			if (sblock.fs_clean == 1) {
+				pwarn("FILE SYSTEM CLEAN; SKIPPING CHECKS\n");
+				exit(0);
+			}
+			suj_check(filesys);
+			if (chkdoreload(mntp) == 0)
+				exit(0);
+			exit(4);
+		}
+#endif
 	}
 	/*
 	 * If we are to do a background check:
@@ -299,7 +311,7 @@ checkfilesys(char *filesys)
 			pfatal("MOUNTED READ-ONLY, CANNOT RUN IN BACKGROUND\n");
 		} else if ((fsreadfd = open(filesys, O_RDONLY)) >= 0) {
 			if (readsb(0) != 0) {
-				if (sblock.fs_flags & FS_NEEDSFSCK) {
+				if (sblock.fs_flags & (FS_NEEDSFSCK | FS_SUJ)) {
 					bkgrdflag = 0;
 					pfatal("UNEXPECTED INCONSISTENCY, %s\n",
 					    "CANNOT RUN IN BACKGROUND\n");
@@ -478,6 +490,7 @@ checkfilesys(char *filesys)
 	inocleanup();
 	if (fsmodified) {
 		sblock.fs_time = time(NULL);
+		sblock.fs_mtime = time(NULL);
 		sbdirty();
 	}
 	if (cvtlevel && sblk.b_dirty) {

Modified: projects/suj/8/sbin/fsck_ffs/pass4.c
==============================================================================
--- projects/suj/8/sbin/fsck_ffs/pass4.c	Wed Jan 20 09:48:46 2010	(r202687)
+++ projects/suj/8/sbin/fsck_ffs/pass4.c	Wed Jan 20 09:49:53 2010	(r202688)
@@ -72,6 +72,9 @@ pass4(void)
 		for (i = 0; i < inostathead[cg].il_numalloced; i++, inumber++) {
 			if (inumber < ROOTINO)
 				continue;
+			if (sblock.fs_flags & FS_SUJ &&
+			    inumber == sblock.fs_sujournal)
+				continue;
 			idesc.id_number = inumber;
 			switch (inoinfo(inumber)->ino_state) {
 

Modified: projects/suj/8/sbin/fsck_ffs/pass5.c
==============================================================================
--- projects/suj/8/sbin/fsck_ffs/pass5.c	Wed Jan 20 09:48:46 2010	(r202687)
+++ projects/suj/8/sbin/fsck_ffs/pass5.c	Wed Jan 20 09:49:53 2010	(r202688)
@@ -45,6 +45,7 @@ __FBSDID("$FreeBSD$");
 #include <inttypes.h>
 #include <limits.h>
 #include <string.h>
+#include <libufs.h>
 
 #include "fsck.h"
 

Copied: projects/suj/8/sbin/fsck_ffs/suj.c (from r202685, projects/suj/head/sbin/fsck_ffs/suj.c)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ projects/suj/8/sbin/fsck_ffs/suj.c	Wed Jan 20 09:49:53 2010	(r202688, copy of r202685, projects/suj/head/sbin/fsck_ffs/suj.c)
@@ -0,0 +1,2065 @@
+/*-
+ * Copyright (c) 2009 Jeffrey W. Roberson <jeff@FreeBSD.org>
+ * 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS 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 AUTHORS 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/disklabel.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+
+#include <ufs/ufs/ufsmount.h>
+#include <ufs/ufs/dinode.h>
+#include <ufs/ufs/dir.h>
+#include <ufs/ffs/fs.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <libufs.h>
+#include <strings.h>
+#include <err.h>
+#include <assert.h>
+
+#include "fsck.h"
+
+static void	ino_decr(ino_t);
+
+#define	SUJ_HASHSIZE	128
+#define	SUJ_HASHMASK	(SUJ_HASHSIZE - 1)
+#define	SUJ_HASH(x)	((x * 2654435761) & SUJ_HASHMASK)
+
+struct suj_seg {
+	TAILQ_ENTRY(suj_seg) ss_next;
+	struct jsegrec	ss_rec;
+	uint8_t		*ss_blk;
+};
+
+struct suj_rec {
+	TAILQ_ENTRY(suj_rec) sr_next;
+	union jrec	*sr_rec;
+};
+TAILQ_HEAD(srechd, suj_rec);
+
+struct suj_ino {
+	LIST_ENTRY(suj_ino)	si_next;
+	struct srechd		si_recs;
+	struct srechd		si_movs;
+	ino_t			si_ino;
+	int			si_nlinkadj;
+	int			si_skipparent;
+	int			si_linkadj;
+	int			si_hasrecs;
+	int			si_blkadj;
+};
+LIST_HEAD(inohd, suj_ino);
+
+struct suj_blk {
+	LIST_ENTRY(suj_blk)	sb_next;
+	struct srechd		sb_recs;
+	ufs2_daddr_t		sb_blk;
+};
+LIST_HEAD(blkhd, suj_blk);
+
+struct data_blk {
+	LIST_ENTRY(data_blk)	db_next;
+	uint8_t			*db_buf;
+	ufs2_daddr_t		db_blk;
+	int			db_size;
+};
+
+struct ino_blk {
+	LIST_ENTRY(ino_blk)	ib_next;
+	uint8_t			*ib_buf;
+	int			ib_dirty;
+	ufs2_daddr_t		ib_blk;
+};
+LIST_HEAD(iblkhd, ino_blk);
+
+struct suj_cg {
+	LIST_ENTRY(suj_cg)	sc_next;
+	struct blkhd		sc_blkhash[SUJ_HASHSIZE];
+	struct inohd		sc_inohash[SUJ_HASHSIZE];
+	struct iblkhd		sc_iblkhash[SUJ_HASHSIZE];
+	struct ino_blk		*sc_lastiblk;
+	uint8_t			*sc_cgbuf;
+	struct cg		*sc_cgp;
+	int			sc_dirty;
+	int			sc_cgx;
+};
+
+LIST_HEAD(cghd, suj_cg) cghash[SUJ_HASHSIZE];
+LIST_HEAD(dblkhd, data_blk) dbhash[SUJ_HASHSIZE];
+
+TAILQ_HEAD(seghd, suj_seg) allsegs;
+uint64_t oldseq;
+static struct uufsd *disk = NULL;
+static struct fs *fs = NULL;
+
+/*
+ * Summary statistics.
+ */
+uint64_t freefrags;
+uint64_t freeblocks;
+uint64_t freeinos;
+uint64_t freedir;
+uint64_t jbytes;
+uint64_t jrecs;
+
+typedef void (*ino_visitor)(ino_t, ufs_lbn_t, ufs2_daddr_t, int);
+
+static void *
+errmalloc(size_t n)
+{
+	void *a;
+
+	a = malloc(n);
+	if (a == NULL)
+		errx(1, "malloc(%zu)", n);
+	return (a);
+}
+
+/*
+ * Open the given provider, load superblock.
+ */
+static void
+opendisk(const char *devnam)
+{
+	if (disk != NULL)
+		return;
+	disk = malloc(sizeof(*disk));
+	if (disk == NULL)
+		errx(1, "malloc(%zu)", sizeof(*disk));
+	if (ufs_disk_fillout(disk, devnam) == -1) {
+		err(1, "ufs_disk_fillout(%s) failed: %s", devnam,
+		    disk->d_error);
+	}
+	fs = &disk->d_fs;
+	/*
+	 * Setup a few things so reply() can work.
+	 */
+	bcopy(fs, &sblock, sizeof(sblock));
+	fsreadfd = disk->d_fd;
+	fswritefd = disk->d_fd;
+}
+
+/*
+ * Mark file system as clean, write the super-block back, close the disk.
+ */
+static void
+closedisk(const char *devnam)
+{
+	struct csum *cgsum;
+	int i;
+
+	/*
+	 * Recompute the fs summary info from correct cs summaries.
+	 */
+	bzero(&fs->fs_cstotal, sizeof(struct csum_total));
+	for (i = 0; i < fs->fs_ncg; i++) {
+		cgsum = &fs->fs_cs(fs, i);
+		fs->fs_cstotal.cs_nffree += cgsum->cs_nffree;
+		fs->fs_cstotal.cs_nbfree += cgsum->cs_nbfree;
+		fs->fs_cstotal.cs_nifree += cgsum->cs_nifree;
+		fs->fs_cstotal.cs_ndir += cgsum->cs_ndir;
+	}
+	/* XXX Don't set clean for now, we don't trust the journal. */
+	/* fs->fs_clean = 1; */
+	fs->fs_time = time(NULL);
+	fs->fs_mtime = time(NULL);
+	if (sbwrite(disk, 0) == -1)
+		err(1, "sbwrite(%s)", devnam);
+	if (ufs_disk_close(disk) == -1)
+		err(1, "ufs_disk_close(%s)", devnam);

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201001200949.o0K9nsgX076781>