From owner-svn-src-user@FreeBSD.ORG Fri Nov 28 21:04:29 2014 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 7349FC7E; Fri, 28 Nov 2014 21:04:29 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 44597259; Fri, 28 Nov 2014 21:04:29 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sASL4TrE027529; Fri, 28 Nov 2014 21:04:29 GMT (envelope-from marcel@FreeBSD.org) Received: (from marcel@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sASL4TEV027528; Fri, 28 Nov 2014 21:04:29 GMT (envelope-from marcel@FreeBSD.org) Message-Id: <201411282104.sASL4TEV027528@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: marcel set sender to marcel@FreeBSD.org using -f From: Marcel Moolenaar Date: Fri, 28 Nov 2014 21:04:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r275215 - user/marcel/libvdsk/libvdsk X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 28 Nov 2014 21:04:29 -0000 Author: marcel Date: Fri Nov 28 21:04:28 2014 New Revision: 275215 URL: https://svnweb.freebsd.org/changeset/base/275215 Log: Make a mutable copy of the libvdsk_formats linker set so that we can white-out the formats we probed as we re-iterate over the set with different probe flags. Modified: user/marcel/libvdsk/libvdsk/vdsk.c Modified: user/marcel/libvdsk/libvdsk/vdsk.c ============================================================================== --- user/marcel/libvdsk/libvdsk/vdsk.c Fri Nov 28 20:48:53 2014 (r275214) +++ user/marcel/libvdsk/libvdsk/vdsk.c Fri Nov 28 21:04:28 2014 (r275215) @@ -58,26 +58,46 @@ vdsk_deref(vdskctx ctx) static struct vdsk_format * vdsk_probe(struct vdsk *vdsk) { - struct vdsk_format *f, *fmt, **f_iter; + struct vdsk_format **fmts; + struct vdsk_format *f, *fmt; + size_t idx, nfmts; int error, probe; + /* + * Create a mutable copy of the linker set. + */ + nfmts = SET_COUNT(libvdsk_formats); + fmts = malloc(nfmts * sizeof(*fmts)); + if (fmts == NULL) + return (NULL); + memcpy(fmts, SET_BEGIN(libvdsk_formats), nfmts * sizeof(*fmts)); + fmt = NULL; probe = VDSKFMT_HAS_HEADER | VDSKFMT_HAS_FOOTER; probe |= (vdsk_is_dev(vdsk)) ? VDSKFMT_DEVICE_OK : 0; probe |= (vdsk->fflags & FWRITE) ? VDSKFMT_CAN_WRITE : 0; while (fmt == NULL && probe >= 0) { - SET_FOREACH(f_iter, libvdsk_formats) { - f = *f_iter; + for (idx = 0; idx < nfmts; idx++) { + f = fmts[idx]; + /* Skip formats we've probed already. */ + if (f == NULL) + continue; + /* Skip formats we shouldn't probe now. */ if ((f->flags & probe) != probe) continue; + /* White-out this format and probe it. */ + fmts[idx] = NULL; error = f->probe(vdsk); if (!error) { + /* We have a match. */ fmt = f; break; } } - probe -= VDSKFMT_HAS_FOOTER; + if (fmt == NULL) + probe -= VDSKFMT_HAS_FOOTER; } + free(fmts); if (fmt == NULL) errno = EFTYPE; return (fmt);