From owner-svn-src-stable@freebsd.org Tue Jul 28 08:25:50 2015 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A22609AA71C; Tue, 28 Jul 2015 08:25:50 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from repo.freebsd.org (repo.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 78880C8C; Tue, 28 Jul 2015 08:25:50 +0000 (UTC) (envelope-from ae@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.14.9/8.14.9) with ESMTP id t6S8PoVP094588; Tue, 28 Jul 2015 08:25:50 GMT (envelope-from ae@FreeBSD.org) Received: (from ae@localhost) by repo.freebsd.org (8.14.9/8.14.9/Submit) id t6S8PoXj094587; Tue, 28 Jul 2015 08:25:50 GMT (envelope-from ae@FreeBSD.org) Message-Id: <201507280825.t6S8PoXj094587@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ae set sender to ae@FreeBSD.org using -f From: "Andrey V. Elsukov" Date: Tue, 28 Jul 2015 08:25:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r285937 - stable/9/sbin/geom/class/part X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Jul 2015 08:25:50 -0000 Author: ae Date: Tue Jul 28 08:25:49 2015 New Revision: 285937 URL: https://svnweb.freebsd.org/changeset/base/285937 Log: MFC r285735: lseek() allows an offset to be set beyond the end of file. Using it to check that partition has enough space to write bootcode doesn't work. Use the known size of provider instead. PR: 201504 Modified: stable/9/sbin/geom/class/part/geom_part.c Directory Properties: stable/9/sbin/geom/class/part/ (props changed) Modified: stable/9/sbin/geom/class/part/geom_part.c ============================================================================== --- stable/9/sbin/geom/class/part/geom_part.c Tue Jul 28 08:22:50 2015 (r285936) +++ stable/9/sbin/geom/class/part/geom_part.c Tue Jul 28 08:25:49 2015 (r285937) @@ -1095,14 +1095,11 @@ gpart_write_partcode(struct ggeom *gp, i if (pp != NULL) { snprintf(dsf, sizeof(dsf), "/dev/%s", pp->lg_name); + if (pp->lg_mediasize < size) + errx(EXIT_FAILURE, "%s: not enough space", dsf); fd = open(dsf, O_WRONLY); if (fd == -1) err(EXIT_FAILURE, "%s", dsf); - if (lseek(fd, size, SEEK_SET) != size) - errx(EXIT_FAILURE, "%s: not enough space", dsf); - if (lseek(fd, 0, SEEK_SET) != 0) - err(EXIT_FAILURE, "%s", dsf); - /* * When writing to a disk device, the write must be * sector aligned and not write to any partial sectors, @@ -1141,11 +1138,11 @@ gpart_write_partcode_vtoc8(struct ggeom if (pp->lg_sectorsize != sizeof(struct vtoc8)) errx(EXIT_FAILURE, "%s: unexpected sector " "size (%d)\n", dsf, pp->lg_sectorsize); + if (pp->lg_mediasize < VTOC_BOOTSIZE) + continue; fd = open(dsf, O_WRONLY); if (fd == -1) err(EXIT_FAILURE, "%s", dsf); - if (lseek(fd, VTOC_BOOTSIZE, SEEK_SET) != VTOC_BOOTSIZE) - continue; /* * We ignore the first VTOC_BOOTSIZE bytes of boot code in * order to avoid overwriting the label.