From owner-svn-src-stable-10@FreeBSD.ORG Wed Oct 8 22:13:20 2014 Return-Path: Delivered-To: svn-src-stable-10@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 9611DB77; Wed, 8 Oct 2014 22:13:20 +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 8199C6CC; Wed, 8 Oct 2014 22:13:20 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s98MDK6A046125; Wed, 8 Oct 2014 22:13:20 GMT (envelope-from marcel@FreeBSD.org) Received: (from marcel@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s98MDJrY046117; Wed, 8 Oct 2014 22:13:19 GMT (envelope-from marcel@FreeBSD.org) Message-Id: <201410082213.s98MDJrY046117@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: marcel set sender to marcel@FreeBSD.org using -f From: Marcel Moolenaar Date: Wed, 8 Oct 2014 22:13:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r272776 - stable/10/usr.bin/mkimg X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Oct 2014 22:13:20 -0000 Author: marcel Date: Wed Oct 8 22:13:18 2014 New Revision: 272776 URL: https://svnweb.freebsd.org/changeset/base/272776 Log: MFC r272485: Fill cyclinder, head and sector fields for the EBR, MBR and PC98 schemes. Requested by: gjb Modified: stable/10/usr.bin/mkimg/Makefile stable/10/usr.bin/mkimg/ebr.c stable/10/usr.bin/mkimg/mbr.c stable/10/usr.bin/mkimg/mkimg.c stable/10/usr.bin/mkimg/mkimg.h stable/10/usr.bin/mkimg/pc98.c Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.bin/mkimg/Makefile ============================================================================== --- stable/10/usr.bin/mkimg/Makefile Wed Oct 8 22:09:36 2014 (r272775) +++ stable/10/usr.bin/mkimg/Makefile Wed Oct 8 22:13:18 2014 (r272776) @@ -4,7 +4,9 @@ PROG= mkimg SRCS= format.c image.c mkimg.c scheme.c MAN= mkimg.1 -MKIMG_VERSION=20141001 +MKIMG_VERSION=20141003 +mkimg.o: Makefile + CFLAGS+=-DMKIMG_VERSION=${MKIMG_VERSION} CFLAGS+=-DSPARSE_WRITE Modified: stable/10/usr.bin/mkimg/ebr.c ============================================================================== --- stable/10/usr.bin/mkimg/ebr.c Wed Oct 8 22:09:36 2014 (r272775) +++ stable/10/usr.bin/mkimg/ebr.c Wed Oct 8 22:13:18 2014 (r272776) @@ -58,12 +58,14 @@ ebr_metadata(u_int where, lba_t blk) } static void -ebr_chs(u_char *cyl, u_char *hd, u_char *sec, uint32_t lba __unused) +ebr_chs(u_char *cylp, u_char *hdp, u_char *secp, lba_t lba) { + u_int cyl, hd, sec; - *cyl = 0xff; /* XXX */ - *hd = 0xff; /* XXX */ - *sec = 0xff; /* XXX */ + mkimg_chs(lba, 1023, &cyl, &hd, &sec); + *cylp = cyl; + *hdp = hd; + *secp = (sec & 0x3f) | ((cyl >> 2) & 0xc0); } static int @@ -72,7 +74,7 @@ ebr_write(lba_t imgsz __unused, void *bo u_char *ebr; struct dos_partition *dp; struct part *part, *next; - lba_t block; + lba_t block, size; int error; ebr = malloc(secsz); @@ -84,24 +86,26 @@ ebr_write(lba_t imgsz __unused, void *bo error = 0; STAILQ_FOREACH_SAFE(part, &partlist, link, next) { block = part->block - nsecs; + size = round_track(part->size); dp = (void *)(ebr + DOSPARTOFF); ebr_chs(&dp->dp_scyl, &dp->dp_shd, &dp->dp_ssect, nsecs); dp->dp_typ = ALIAS_TYPE2INT(part->type); ebr_chs(&dp->dp_ecyl, &dp->dp_ehd, &dp->dp_esect, - part->block + part->size - 1); + part->block + size - 1); le32enc(&dp->dp_start, nsecs); - le32enc(&dp->dp_size, part->size); + le32enc(&dp->dp_size, size); /* Add link entry */ if (next != NULL) { + size = round_track(next->size); dp++; ebr_chs(&dp->dp_scyl, &dp->dp_shd, &dp->dp_ssect, next->block - nsecs); dp->dp_typ = DOSPTYP_EXT; ebr_chs(&dp->dp_ecyl, &dp->dp_ehd, &dp->dp_esect, - next->block + next->size - 1); + next->block + size - 1); le32enc(&dp->dp_start, next->block - nsecs); - le32enc(&dp->dp_size, next->size + nsecs); + le32enc(&dp->dp_size, size + nsecs); } error = image_write(block, ebr, 1); Modified: stable/10/usr.bin/mkimg/mbr.c ============================================================================== --- stable/10/usr.bin/mkimg/mbr.c Wed Oct 8 22:09:36 2014 (r272775) +++ stable/10/usr.bin/mkimg/mbr.c Wed Oct 8 22:13:18 2014 (r272776) @@ -59,12 +59,14 @@ mbr_metadata(u_int where, lba_t blk) } static void -mbr_chs(u_char *cyl, u_char *hd, u_char *sec, uint32_t lba __unused) +mbr_chs(u_char *cylp, u_char *hdp, u_char *secp, lba_t lba) { + u_int cyl, hd, sec; - *cyl = 0xff; /* XXX */ - *hd = 0xff; /* XXX */ - *sec = 0xff; /* XXX */ + mkimg_chs(lba, 1023, &cyl, &hd, &sec); + *cylp = cyl; + *hdp = hd; + *secp = (sec & 0x3f) | ((cyl >> 2) & 0xc0); } static int @@ -73,6 +75,7 @@ mbr_write(lba_t imgsz __unused, void *bo u_char *mbr; struct dos_partition *dpbase, *dp; struct part *part; + lba_t size; int error; mbr = malloc(secsz); @@ -86,15 +89,16 @@ mbr_write(lba_t imgsz __unused, void *bo le16enc(mbr + DOSMAGICOFFSET, DOSMAGIC); dpbase = (void *)(mbr + DOSPARTOFF); STAILQ_FOREACH(part, &partlist, link) { + size = round_track(part->size); dp = dpbase + part->index; dp->dp_flag = (part->index == 0 && bootcode != NULL) ? 0x80 : 0; mbr_chs(&dp->dp_scyl, &dp->dp_shd, &dp->dp_ssect, part->block); dp->dp_typ = ALIAS_TYPE2INT(part->type); mbr_chs(&dp->dp_ecyl, &dp->dp_ehd, &dp->dp_esect, - part->block + part->size - 1); + part->block + size - 1); le32enc(&dp->dp_start, part->block); - le32enc(&dp->dp_size, part->size); + le32enc(&dp->dp_size, size); } error = image_write(0, mbr, 1); free(mbr); Modified: stable/10/usr.bin/mkimg/mkimg.c ============================================================================== --- stable/10/usr.bin/mkimg/mkimg.c Wed Oct 8 22:09:36 2014 (r272775) +++ stable/10/usr.bin/mkimg/mkimg.c Wed Oct 8 22:13:18 2014 (r272776) @@ -340,6 +340,27 @@ sparse_write(int fd, const void *ptr, si #endif /* SPARSE_WRITE */ void +mkimg_chs(lba_t lba, u_int maxcyl, u_int *cylp, u_int *hdp, u_int *secp) +{ + u_int hd, sec; + + *cylp = *hdp = *secp = ~0U; + if (nsecs == 1 || nheads == 1) + return; + + sec = lba % nsecs + 1; + lba /= nsecs; + hd = lba % nheads; + lba /= nheads; + if (lba > maxcyl) + return; + + *cylp = lba; + *hdp = hd; + *secp = sec; +} + +void mkimg_uuid(struct uuid *uuid) { static uint8_t gen[sizeof(struct uuid)]; Modified: stable/10/usr.bin/mkimg/mkimg.h ============================================================================== --- stable/10/usr.bin/mkimg/mkimg.h Wed Oct 8 22:09:36 2014 (r272775) +++ stable/10/usr.bin/mkimg/mkimg.h Wed Oct 8 22:13:18 2014 (r272776) @@ -87,6 +87,8 @@ round_track(lba_t n) ssize_t sparse_write(int, const void *, size_t); #endif +void mkimg_chs(lba_t, u_int, u_int *, u_int *, u_int *); + struct uuid; void mkimg_uuid(struct uuid *); Modified: stable/10/usr.bin/mkimg/pc98.c ============================================================================== --- stable/10/usr.bin/mkimg/pc98.c Wed Oct 8 22:09:36 2014 (r272775) +++ stable/10/usr.bin/mkimg/pc98.c Wed Oct 8 22:13:18 2014 (r272776) @@ -68,12 +68,14 @@ pc98_metadata(u_int where, lba_t blk) } static void -pc98_chs(u_short *cyl, u_char *hd, u_char *sec, uint32_t lba __unused) +pc98_chs(u_short *cylp, u_char *hdp, u_char *secp, lba_t lba) { + u_int cyl, hd, sec; - *cyl = 0xffff; /* XXX */ - *hd = 0xff; /* XXX */ - *sec = 0xff; /* XXX */ + mkimg_chs(lba, 0xffff, &cyl, &hd, &sec); + le16enc(cylp, cyl); + *hdp = hd; + *secp = sec; } static int @@ -82,6 +84,7 @@ pc98_write(lba_t imgsz __unused, void *b struct part *part; struct pc98_partition *dpbase, *dp; u_char *buf; + lba_t size; int error, ptyp; buf = malloc(PC98_BOOTCODESZ); @@ -95,6 +98,7 @@ pc98_write(lba_t imgsz __unused, void *b le16enc(buf + PC98_MAGICOFS, PC98_MAGIC); dpbase = (void *)(buf + secsz); STAILQ_FOREACH(part, &partlist, link) { + size = round_track(part->size); dp = dpbase + part->index; ptyp = ALIAS_TYPE2INT(part->type); dp->dp_mid = ptyp; @@ -102,7 +106,7 @@ pc98_write(lba_t imgsz __unused, void *b pc98_chs(&dp->dp_scyl, &dp->dp_shd, &dp->dp_ssect, part->block); pc98_chs(&dp->dp_scyl, &dp->dp_shd, &dp->dp_ssect, - part->block + part->size - 1); + part->block + size - 1); if (part->label != NULL) memcpy(dp->dp_name, part->label, strlen(part->label)); }