From owner-svn-src-all@FreeBSD.ORG Sat Feb 12 13:12:46 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 33AEB1065670; Sat, 12 Feb 2011 13:12:46 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 07B028FC08; Sat, 12 Feb 2011 13:12:46 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p1CDCjHW002586; Sat, 12 Feb 2011 13:12:45 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p1CDCjhD002584; Sat, 12 Feb 2011 13:12:45 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201102121312.p1CDCjhD002584@svn.freebsd.org> From: Konstantin Belousov Date: Sat, 12 Feb 2011 13:12:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r218603 - head/sbin/tunefs X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Feb 2011 13:12:46 -0000 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)); } /*