From owner-svn-src-user@FreeBSD.ORG Sun Mar 23 04:21:57 2014 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 21CD94A6; Sun, 23 Mar 2014 04:21:57 +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)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id E33A8BDE; Sun, 23 Mar 2014 04:21:56 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s2N4Lu9Y086245; Sun, 23 Mar 2014 04:21:56 GMT (envelope-from marcel@svn.freebsd.org) Received: (from marcel@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s2N4Lupu086244; Sun, 23 Mar 2014 04:21:56 GMT (envelope-from marcel@svn.freebsd.org) Message-Id: <201403230421.s2N4Lupu086244@svn.freebsd.org> From: Marcel Moolenaar Date: Sun, 23 Mar 2014 04:21:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r263656 - user/marcel/mkimg 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.17 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: Sun, 23 Mar 2014 04:21:57 -0000 Author: marcel Date: Sun Mar 23 04:21:56 2014 New Revision: 263656 URL: http://svnweb.freebsd.org/changeset/base/263656 Log: Implement the APM scheme. Modified: user/marcel/mkimg/apm.c Modified: user/marcel/mkimg/apm.c ============================================================================== --- user/marcel/mkimg/apm.c Sun Mar 23 02:29:28 2014 (r263655) +++ user/marcel/mkimg/apm.c Sun Mar 23 04:21:56 2014 (r263656) @@ -29,13 +29,22 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include #include +#include +#include #include "mkimg.h" #include "scheme.h" static struct mkimg_alias apm_aliases[] = { + { ALIAS_FREEBSD, ALIAS_PTR2TYPE(APM_ENT_TYPE_FREEBSD) }, + { ALIAS_FREEBSD_NANDFS, ALIAS_PTR2TYPE(APM_ENT_TYPE_FREEBSD_NANDFS) }, + { ALIAS_FREEBSD_SWAP, ALIAS_PTR2TYPE(APM_ENT_TYPE_FREEBSD_SWAP) }, + { ALIAS_FREEBSD_UFS, ALIAS_PTR2TYPE(APM_ENT_TYPE_FREEBSD_UFS) }, + { ALIAS_FREEBSD_VINUM, ALIAS_PTR2TYPE(APM_ENT_TYPE_FREEBSD_VINUM) }, + { ALIAS_FREEBSD_ZFS, ALIAS_PTR2TYPE(APM_ENT_TYPE_FREEBSD_ZFS) }, { ALIAS_NONE, 0 } }; @@ -44,14 +53,56 @@ apm_metadata(u_int where) { u_int secs; - secs = (where == SCHEME_META_IMG_START) ? nparts + 1 : 0; + secs = (where == SCHEME_META_IMG_START) ? nparts + 2 : 0; return (secs); } static int apm_write(int fd __unused, lba_t imgsz __unused, void *bootcode __unused) { - return (ENOSYS); + u_char *buf; + struct apm_ddr *ddr; + struct apm_ent *ent; + struct part *part; + ssize_t nbytes; + int error; + + buf = calloc(nparts + 2, secsz); + if (buf == NULL) + return (ENOMEM); + ddr = (void *)buf; + be16enc(&ddr->ddr_sig, APM_DDR_SIG); + be16enc(&ddr->ddr_blksize, secsz); + be32enc(&ddr->ddr_blkcount, imgsz); + + /* partition entry for the partition table itself. */ + ent = (void *)(buf + secsz); + be16enc(&ent->ent_sig, APM_ENT_SIG); + be32enc(&ent->ent_pmblkcnt, nparts + 1); + be32enc(&ent->ent_start, 1); + be32enc(&ent->ent_size, nparts + 1); + strcpy(ent->ent_type, APM_ENT_TYPE_SELF); + strcpy(ent->ent_name, "Apple"); + + STAILQ_FOREACH(part, &partlist, link) { + ent = (void *)(buf + (part->index + 2) * secsz); + be16enc(&ent->ent_sig, APM_ENT_SIG); + be32enc(&ent->ent_pmblkcnt, nparts + 1); + be32enc(&ent->ent_start, part->block); + be32enc(&ent->ent_size, part->size); + strcpy(ent->ent_type, ALIAS_TYPE2PTR(part->type)); + if (part->label != NULL) + strcpy(ent->ent_name, part->label); + } + + error = mkimg_seek(fd, 0); + if (error == 0) { + nbytes = (nparts + 2) * secsz; + if (write(fd, buf, nbytes) != nbytes) + error = errno; + } + free(buf); + return (error); } static struct mkimg_scheme apm_scheme = { @@ -60,7 +111,8 @@ static struct mkimg_scheme apm_scheme = .aliases = apm_aliases, .metadata = apm_metadata, .write = apm_write, - .nparts = 4096 + .nparts = 4096, + .labellen = APM_ENT_NAMELEN - 1 }; SCHEME_DEFINE(apm_scheme);