Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 12 Feb 2011 13:12:45 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r218603 - head/sbin/tunefs
Message-ID:  <201102121312.p1CDCjhD002584@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Sat Feb 12 13:12:45 2011
New Revision: 218603
URL: http://svn.freebsd.org/changeset/base/218603

Log:
  When creating a directory entry for the journal, always read at least
  the fragment, and write the full block. Reading less might not work
  due to device sector size bigger then size of direntries in the
  last directory fragment.
  
  Reported by:	bz
  In collaboration with:	pho
  Reviewed by:	jeff
  Tested by:	bz, pho

Modified:
  head/sbin/tunefs/tunefs.c

Modified: head/sbin/tunefs/tunefs.c
==============================================================================
--- head/sbin/tunefs/tunefs.c	Sat Feb 12 12:52:12 2011	(r218602)
+++ head/sbin/tunefs/tunefs.c	Sat Feb 12 13:12:45 2011	(r218603)
@@ -688,6 +688,19 @@ journal_findfile(void)
 	return (0);
 }
 
+static void
+dir_clear_block(char *block, off_t off)
+{
+	struct direct *dp;
+
+	for (; off < sblock.fs_bsize; off += DIRBLKSIZ) {
+		dp = (struct direct *)&block[off];
+		dp->d_ino = 0;
+		dp->d_reclen = DIRBLKSIZ;
+		dp->d_type = DT_UNKNOWN;
+	}
+}
+
 /*
  * Insert the journal at inode 'ino' into directory blk 'blk' at the first
  * free offset of 'off'.  DIRBLKSIZ blocks after off are initialized as
@@ -710,13 +723,7 @@ dir_insert(ufs2_daddr_t blk, off_t off, 
 	dp->d_type = DT_REG;
 	dp->d_namlen = strlen(SUJ_FILE);
 	bcopy(SUJ_FILE, &dp->d_name, strlen(SUJ_FILE));
-	off += DIRBLKSIZ;
-	for (; off < sblock.fs_bsize; off += DIRBLKSIZ) {
-		dp = (struct direct *)&block[off];
-		dp->d_ino = 0;
-		dp->d_reclen = DIRBLKSIZ;
-		dp->d_type = DT_UNKNOWN;
-	}
+	dir_clear_block(block, off + DIRBLKSIZ);
 	if (bwrite(&disk, fsbtodb(&sblock, blk), block, sblock.fs_bsize) <= 0) {
 		warn("Failed to write dir block");
 		return (-1);
@@ -733,16 +740,19 @@ dir_extend(ufs2_daddr_t blk, ufs2_daddr_
 {
 	char block[MAXBSIZE];
 
-	if (bread(&disk, fsbtodb(&sblock, blk), block, size) <= 0) {
+	if (bread(&disk, fsbtodb(&sblock, blk), block,
+	    roundup(size, sblock.fs_fsize)) <= 0) {
 		warn("Failed to read dir block");
 		return (-1);
 	}
-	if (bwrite(&disk, fsbtodb(&sblock, nblk), block, size) <= 0) {
+	dir_clear_block(block, size);
+	if (bwrite(&disk, fsbtodb(&sblock, nblk), block, sblock.fs_bsize)
+	    <= 0) {
 		warn("Failed to write dir block");
 		return (-1);
 	}
 
-	return dir_insert(nblk, size, ino);
+	return (dir_insert(nblk, size, ino));
 }
 
 /*



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