From owner-svn-src-all@FreeBSD.ORG Wed Oct 3 10:06:49 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 12E73106564A; Wed, 3 Oct 2012 10:06:49 +0000 (UTC) (envelope-from gber@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id F30F58FC18; Wed, 3 Oct 2012 10:06:48 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q93A6mQq005463; Wed, 3 Oct 2012 10:06:48 GMT (envelope-from gber@svn.freebsd.org) Received: (from gber@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q93A6mZg005461; Wed, 3 Oct 2012 10:06:48 GMT (envelope-from gber@svn.freebsd.org) Message-Id: <201210031006.q93A6mZg005461@svn.freebsd.org> From: Grzegorz Bernacki Date: Wed, 3 Oct 2012 10:06:48 +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: r241157 - head/lib/libstand 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: Wed, 03 Oct 2012 10:06:49 -0000 Author: gber Date: Wed Oct 3 10:06:48 2012 New Revision: 241157 URL: http://svn.freebsd.org/changeset/base/241157 Log: Correct detection of a superblock. Obtained from: Smartcom Bulgaria AD Modified: head/lib/libstand/nandfs.c Modified: head/lib/libstand/nandfs.c ============================================================================== --- head/lib/libstand/nandfs.c Wed Oct 3 05:42:15 2012 (r241156) +++ head/lib/libstand/nandfs.c Wed Oct 3 10:06:48 2012 (r241157) @@ -175,7 +175,7 @@ static int nandfs_find_super_block(struct nandfs *fs, struct open_file *f) { struct nandfs_super_block *sb; - int i, j, n; + int i, j, n, s; int sectors_to_read, error; sb = malloc(fs->nf_sectorsize); @@ -196,23 +196,22 @@ nandfs_find_super_block(struct nandfs *f continue; } n = fs->nf_sectorsize / sizeof(struct nandfs_super_block); + s = 0; if ((i * fs->nf_sectorsize) % fs->nf_fsdata->f_erasesize == 0) { if (fs->nf_sectorsize == sizeof(struct nandfs_fsdata)) continue; else { - sb += (sizeof(struct nandfs_fsdata) / - sizeof(struct nandfs_super_block)); - n -= (sizeof(struct nandfs_fsdata) / + s += (sizeof(struct nandfs_fsdata) / sizeof(struct nandfs_super_block)); } } - for (j = 0; j < n; j++) { + for (j = s; j < n; j++) { if (!nandfs_check_superblock_crc(fs->nf_fsdata, &sb[j])) continue; - NANDFS_DEBUG("magic %x wtime %jd\n", sb->s_magic, - sb->s_wtime); - if (sb[j].s_wtime > fs->nf_sb->s_wtime) + NANDFS_DEBUG("magic %x wtime %jd, lastcp 0x%jx\n", + sb[j].s_magic, sb[j].s_wtime, sb[j].s_last_cno); + if (sb[j].s_last_cno > fs->nf_sb->s_last_cno) memcpy(fs->nf_sb, &sb[j], sizeof(*fs->nf_sb)); } }