From owner-svn-src-all@freebsd.org Wed Feb 7 16:45:40 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 64ED5F13FB3; Wed, 7 Feb 2018 16:45:40 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 167C872000; Wed, 7 Feb 2018 16:45:40 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 0FFD51708; Wed, 7 Feb 2018 16:45:40 +0000 (UTC) (envelope-from manu@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w17GjeoW093423; Wed, 7 Feb 2018 16:45:40 GMT (envelope-from manu@FreeBSD.org) Received: (from manu@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w17Gjd2F093411; Wed, 7 Feb 2018 16:45:39 GMT (envelope-from manu@FreeBSD.org) Message-Id: <201802071645.w17Gjd2F093411@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: manu set sender to manu@FreeBSD.org using -f From: Emmanuel Vadot Date: Wed, 7 Feb 2018 16:45:39 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r328976 - in stable/11/usr.bin/mkimg: . tests X-SVN-Group: stable-11 X-SVN-Commit-Author: manu X-SVN-Commit-Paths: in stable/11/usr.bin/mkimg: . tests X-SVN-Commit-Revision: 328976 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.25 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, 07 Feb 2018 16:45:40 -0000 Author: manu Date: Wed Feb 7 16:45:38 2018 New Revision: 328976 URL: https://svnweb.freebsd.org/changeset/base/328976 Log: Revert r328974, r307387 was not supposed to be part of it. Deleted: stable/11/usr.bin/mkimg/endian.h stable/11/usr.bin/mkimg/uuid.c Modified: stable/11/usr.bin/mkimg/Makefile stable/11/usr.bin/mkimg/apm.c stable/11/usr.bin/mkimg/bsd.c stable/11/usr.bin/mkimg/ebr.c stable/11/usr.bin/mkimg/format.c stable/11/usr.bin/mkimg/format.h stable/11/usr.bin/mkimg/gpt.c stable/11/usr.bin/mkimg/image.c stable/11/usr.bin/mkimg/mbr.c stable/11/usr.bin/mkimg/mkimg.1 stable/11/usr.bin/mkimg/mkimg.c stable/11/usr.bin/mkimg/mkimg.h stable/11/usr.bin/mkimg/pc98.c stable/11/usr.bin/mkimg/qcow.c stable/11/usr.bin/mkimg/raw.c stable/11/usr.bin/mkimg/scheme.c stable/11/usr.bin/mkimg/scheme.h stable/11/usr.bin/mkimg/tests/img-1x1-4096-gpt.qcow.gz.uu stable/11/usr.bin/mkimg/tests/img-1x1-4096-gpt.qcow2.gz.uu stable/11/usr.bin/mkimg/tests/img-1x1-4096-gpt.raw.gz.uu stable/11/usr.bin/mkimg/tests/img-1x1-4096-gpt.vhd.gz.uu stable/11/usr.bin/mkimg/tests/img-1x1-4096-gpt.vhdf.gz.uu stable/11/usr.bin/mkimg/tests/img-1x1-4096-gpt.vmdk.gz.uu stable/11/usr.bin/mkimg/tests/img-1x1-512-gpt.qcow.gz.uu stable/11/usr.bin/mkimg/tests/img-1x1-512-gpt.qcow2.gz.uu stable/11/usr.bin/mkimg/tests/img-1x1-512-gpt.raw.gz.uu stable/11/usr.bin/mkimg/tests/img-1x1-512-gpt.vhd.gz.uu stable/11/usr.bin/mkimg/tests/img-1x1-512-gpt.vhdf.gz.uu stable/11/usr.bin/mkimg/tests/img-1x1-512-gpt.vmdk.gz.uu stable/11/usr.bin/mkimg/tests/img-63x255-4096-gpt.qcow.gz.uu stable/11/usr.bin/mkimg/tests/img-63x255-4096-gpt.qcow2.gz.uu stable/11/usr.bin/mkimg/tests/img-63x255-4096-gpt.raw.gz.uu stable/11/usr.bin/mkimg/tests/img-63x255-4096-gpt.vhd.gz.uu stable/11/usr.bin/mkimg/tests/img-63x255-4096-gpt.vhdf.gz.uu stable/11/usr.bin/mkimg/tests/img-63x255-4096-gpt.vmdk.gz.uu stable/11/usr.bin/mkimg/tests/img-63x255-512-gpt.qcow.gz.uu stable/11/usr.bin/mkimg/tests/img-63x255-512-gpt.qcow2.gz.uu stable/11/usr.bin/mkimg/tests/img-63x255-512-gpt.raw.gz.uu stable/11/usr.bin/mkimg/tests/img-63x255-512-gpt.vhd.gz.uu stable/11/usr.bin/mkimg/tests/img-63x255-512-gpt.vhdf.gz.uu stable/11/usr.bin/mkimg/tests/img-63x255-512-gpt.vmdk.gz.uu stable/11/usr.bin/mkimg/vhd.c stable/11/usr.bin/mkimg/vmdk.c stable/11/usr.bin/mkimg/vtoc8.c Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.bin/mkimg/Makefile ============================================================================== --- stable/11/usr.bin/mkimg/Makefile Wed Feb 7 16:28:26 2018 (r328975) +++ stable/11/usr.bin/mkimg/Makefile Wed Feb 7 16:45:38 2018 (r328976) @@ -3,15 +3,14 @@ .include PROG= mkimg -SRCS= format.c image.c mkimg.c scheme.c uuid.c +SRCS= format.c image.c mkimg.c scheme.c MAN= mkimg.1 -MKIMG_VERSION=20161016 +MKIMG_VERSION=20151211 mkimg.o: Makefile CFLAGS+=-DMKIMG_VERSION=${MKIMG_VERSION} CFLAGS+=-DSPARSE_WRITE -CFLAGS+=-I${SRCTOP}/sys/sys/disk # List of formats to support SRCS+= \ Modified: stable/11/usr.bin/mkimg/apm.c ============================================================================== --- stable/11/usr.bin/mkimg/apm.c Wed Feb 7 16:28:26 2018 (r328975) +++ stable/11/usr.bin/mkimg/apm.c Wed Feb 7 16:45:38 2018 (r328976) @@ -27,19 +27,25 @@ #include __FBSDID("$FreeBSD$"); +#include +#include +#include #include -#include #include #include #include -#include - -#include "endian.h" #include "image.h" #include "mkimg.h" #include "scheme.h" +#ifndef APM_ENT_TYPE_APPLE_BOOT +#define APM_ENT_TYPE_APPLE_BOOT "Apple_Bootstrap" +#endif +#ifndef APM_ENT_TYPE_FREEBSD_NANDFS +#define APM_ENT_TYPE_FREEBSD_NANDFS "FreeBSD-nandfs" +#endif + static struct mkimg_alias apm_aliases[] = { { ALIAS_FREEBSD, ALIAS_PTR2TYPE(APM_ENT_TYPE_FREEBSD) }, { ALIAS_FREEBSD_BOOT, ALIAS_PTR2TYPE(APM_ENT_TYPE_APPLE_BOOT) }, @@ -85,7 +91,7 @@ apm_write(lba_t imgsz, void *bootcode __unused) strncpy(ent->ent_type, APM_ENT_TYPE_SELF, sizeof(ent->ent_type)); strncpy(ent->ent_name, "Apple", sizeof(ent->ent_name)); - TAILQ_FOREACH(part, &partlist, link) { + 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); Modified: stable/11/usr.bin/mkimg/bsd.c ============================================================================== --- stable/11/usr.bin/mkimg/bsd.c Wed Feb 7 16:28:26 2018 (r328975) +++ stable/11/usr.bin/mkimg/bsd.c Wed Feb 7 16:45:38 2018 (r328976) @@ -27,19 +27,22 @@ #include __FBSDID("$FreeBSD$"); +#include +#include +#include #include -#include #include #include #include -#include - -#include "endian.h" #include "image.h" #include "mkimg.h" #include "scheme.h" +#ifndef FS_NANDFS +#define FS_NANDFS 30 +#endif + static struct mkimg_alias bsd_aliases[] = { { ALIAS_FREEBSD_NANDFS, ALIAS_INT2TYPE(FS_NANDFS) }, { ALIAS_FREEBSD_SWAP, ALIAS_INT2TYPE(FS_SWAP) }, @@ -54,7 +57,7 @@ bsd_metadata(u_int where, lba_t blk) { if (where == SCHEME_META_IMG_START) - blk += BSD_BOOTBLOCK_SIZE / secsz; + blk += BBSIZE / secsz; else if (where == SCHEME_META_IMG_END) blk = round_cylinder(blk); else @@ -72,21 +75,21 @@ bsd_write(lba_t imgsz, void *bootcode) int bsdparts, error, n; uint16_t checksum; - buf = malloc(BSD_BOOTBLOCK_SIZE); + buf = malloc(BBSIZE); if (buf == NULL) return (ENOMEM); if (bootcode != NULL) { - memcpy(buf, bootcode, BSD_BOOTBLOCK_SIZE); + memcpy(buf, bootcode, BBSIZE); memset(buf + secsz, 0, sizeof(struct disklabel)); } else - memset(buf, 0, BSD_BOOTBLOCK_SIZE); + memset(buf, 0, BBSIZE); bsdparts = nparts + 1; /* Account for c partition */ - if (bsdparts < BSD_NPARTS_MIN) - bsdparts = BSD_NPARTS_MIN; + if (bsdparts < MAXPARTITIONS) + bsdparts = MAXPARTITIONS; d = (void *)(buf + secsz); - le32enc(&d->d_magic, BSD_MAGIC); + le32enc(&d->d_magic, DISKMAGIC); le32enc(&d->d_secsize, secsz); le32enc(&d->d_nsectors, nsecs); le32enc(&d->d_ntracks, nheads); @@ -94,14 +97,14 @@ bsd_write(lba_t imgsz, void *bootcode) le32enc(&d->d_secpercyl, nsecs * nheads); le32enc(&d->d_secperunit, imgsz); le16enc(&d->d_rpm, 3600); - le32enc(&d->d_magic2, BSD_MAGIC); + le32enc(&d->d_magic2, DISKMAGIC); le16enc(&d->d_npartitions, bsdparts); - le32enc(&d->d_bbsize, BSD_BOOTBLOCK_SIZE); + le32enc(&d->d_bbsize, BBSIZE); - dp = &d->d_partitions[BSD_PART_RAW]; + dp = &d->d_partitions[RAW_PART]; le32enc(&dp->p_size, imgsz); - TAILQ_FOREACH(part, &partlist, link) { - n = part->index + ((part->index >= BSD_PART_RAW) ? 1 : 0); + STAILQ_FOREACH(part, &partlist, link) { + n = part->index + ((part->index >= RAW_PART) ? 1 : 0); dp = &d->d_partitions[n]; le32enc(&dp->p_size, part->size); le32enc(&dp->p_offset, part->block); @@ -117,7 +120,7 @@ bsd_write(lba_t imgsz, void *bootcode) checksum ^= le16dec(p); le16enc(&d->d_checksum, checksum); - error = image_write(0, buf, BSD_BOOTBLOCK_SIZE / secsz); + error = image_write(0, buf, BBSIZE / secsz); free(buf); return (error); } @@ -128,8 +131,8 @@ static struct mkimg_scheme bsd_scheme = { .aliases = bsd_aliases, .metadata = bsd_metadata, .write = bsd_write, - .nparts = BSD_NPARTS_MAX - 1, - .bootcode = BSD_BOOTBLOCK_SIZE, + .nparts = 19, + .bootcode = BBSIZE, .maxsecsz = 512 }; Modified: stable/11/usr.bin/mkimg/ebr.c ============================================================================== --- stable/11/usr.bin/mkimg/ebr.c Wed Feb 7 16:28:26 2018 (r328975) +++ stable/11/usr.bin/mkimg/ebr.c Wed Feb 7 16:45:38 2018 (r328976) @@ -27,21 +27,27 @@ #include __FBSDID("$FreeBSD$"); +#include +#include +#include #include -#include #include #include #include -#include - -#include "endian.h" #include "image.h" #include "mkimg.h" #include "scheme.h" +#ifndef DOSPTYP_FAT16B +#define DOSPTYP_FAT16B 0x06 +#endif +#ifndef DOSPTYP_FAT32 +#define DOSPTYP_FAT32 0x0b +#endif + static struct mkimg_alias ebr_aliases[] = { - { ALIAS_FAT16B, ALIAS_INT2TYPE(DOSPTYP_FAT16) }, + { ALIAS_FAT16B, ALIAS_INT2TYPE(DOSPTYP_FAT16B) }, { ALIAS_FAT32, ALIAS_INT2TYPE(DOSPTYP_FAT32) }, { ALIAS_FREEBSD, ALIAS_INT2TYPE(DOSPTYP_386BSD) }, { ALIAS_NONE, 0 } @@ -82,7 +88,7 @@ ebr_write(lba_t imgsz __unused, void *bootcode __unuse le16enc(ebr + DOSMAGICOFFSET, DOSMAGIC); error = 0; - TAILQ_FOREACH(part, &partlist, link) { + STAILQ_FOREACH_SAFE(part, &partlist, link, next) { block = part->block - nsecs; size = round_track(part->size); dp = (void *)(ebr + DOSPARTOFF); @@ -94,7 +100,6 @@ ebr_write(lba_t imgsz __unused, void *bootcode __unuse le32enc(&dp->dp_size, size); /* Add link entry */ - next = TAILQ_NEXT(part, link); if (next != NULL) { size = round_track(next->size); dp++; Modified: stable/11/usr.bin/mkimg/format.c ============================================================================== --- stable/11/usr.bin/mkimg/format.c Wed Feb 7 16:28:26 2018 (r328975) +++ stable/11/usr.bin/mkimg/format.c Wed Feb 7 16:45:38 2018 (r328976) @@ -27,6 +27,9 @@ #include __FBSDID("$FreeBSD$"); +#include +#include +#include #include #include #include @@ -39,24 +42,8 @@ __FBSDID("$FreeBSD$"); #include "format.h" #include "mkimg.h" -static struct mkimg_format *first; static struct mkimg_format *format; -struct mkimg_format * -format_iterate(struct mkimg_format *f) -{ - - return ((f == NULL) ? first : f->next); -} - -void -format_register(struct mkimg_format *f) -{ - - f->next = first; - first = f; -} - int format_resize(lba_t end) { @@ -69,10 +56,10 @@ format_resize(lba_t end) int format_select(const char *spec) { - struct mkimg_format *f; + struct mkimg_format *f, **iter; - f = NULL; - while ((f = format_iterate(f)) != NULL) { + SET_FOREACH(iter, formats) { + f = *iter; if (strcasecmp(spec, f->name) == 0) { format = f; return (0); Modified: stable/11/usr.bin/mkimg/format.h ============================================================================== --- stable/11/usr.bin/mkimg/format.h Wed Feb 7 16:28:26 2018 (r328975) +++ stable/11/usr.bin/mkimg/format.h Wed Feb 7 16:45:38 2018 (r328976) @@ -29,24 +29,21 @@ #ifndef _MKIMG_FORMAT_H_ #define _MKIMG_FORMAT_H_ +#include + struct mkimg_format { - struct mkimg_format *next; const char *name; const char *description; int (*resize)(lba_t); int (*write)(int); }; -#define FORMAT_DEFINE(nm) \ -static void format_register_##nm(void) __attribute__((constructor)); \ -static void format_register_##nm(void) { format_register(&nm); } +SET_DECLARE(formats, struct mkimg_format); +#define FORMAT_DEFINE(nm) DATA_SET(formats, nm) -struct mkimg_format *format_iterate(struct mkimg_format *); -void format_register(struct mkimg_format *); +int format_resize(lba_t); int format_select(const char *); struct mkimg_format *format_selected(void); - -int format_resize(lba_t); int format_write(int); #endif /* _MKIMG_FORMAT_H_ */ Modified: stable/11/usr.bin/mkimg/gpt.c ============================================================================== --- stable/11/usr.bin/mkimg/gpt.c Wed Feb 7 16:28:26 2018 (r328975) +++ stable/11/usr.bin/mkimg/gpt.c Wed Feb 7 16:45:38 2018 (r328976) @@ -27,32 +27,38 @@ #include __FBSDID("$FreeBSD$"); +#include +#include +#include #include +#include #include #include #include #include #include +#include -#include -#include - -#include "endian.h" #include "image.h" #include "mkimg.h" #include "scheme.h" -static mkimg_uuid_t gpt_uuid_efi = GPT_ENT_TYPE_EFI; -static mkimg_uuid_t gpt_uuid_freebsd = GPT_ENT_TYPE_FREEBSD; -static mkimg_uuid_t gpt_uuid_freebsd_boot = GPT_ENT_TYPE_FREEBSD_BOOT; -static mkimg_uuid_t gpt_uuid_freebsd_nandfs = GPT_ENT_TYPE_FREEBSD_NANDFS; -static mkimg_uuid_t gpt_uuid_freebsd_swap = GPT_ENT_TYPE_FREEBSD_SWAP; -static mkimg_uuid_t gpt_uuid_freebsd_ufs = GPT_ENT_TYPE_FREEBSD_UFS; -static mkimg_uuid_t gpt_uuid_freebsd_vinum = GPT_ENT_TYPE_FREEBSD_VINUM; -static mkimg_uuid_t gpt_uuid_freebsd_zfs = GPT_ENT_TYPE_FREEBSD_ZFS; -static mkimg_uuid_t gpt_uuid_mbr = GPT_ENT_TYPE_MBR; -static mkimg_uuid_t gpt_uuid_ms_basic_data = GPT_ENT_TYPE_MS_BASIC_DATA; +#ifndef GPT_ENT_TYPE_FREEBSD_NANDFS +#define GPT_ENT_TYPE_FREEBSD_NANDFS \ + {0x74ba7dd9,0xa689,0x11e1,0xbd,0x04,{0x00,0xe0,0x81,0x28,0x6a,0xcf}} +#endif +static uuid_t gpt_uuid_efi = GPT_ENT_TYPE_EFI; +static uuid_t gpt_uuid_freebsd = GPT_ENT_TYPE_FREEBSD; +static uuid_t gpt_uuid_freebsd_boot = GPT_ENT_TYPE_FREEBSD_BOOT; +static uuid_t gpt_uuid_freebsd_nandfs = GPT_ENT_TYPE_FREEBSD_NANDFS; +static uuid_t gpt_uuid_freebsd_swap = GPT_ENT_TYPE_FREEBSD_SWAP; +static uuid_t gpt_uuid_freebsd_ufs = GPT_ENT_TYPE_FREEBSD_UFS; +static uuid_t gpt_uuid_freebsd_vinum = GPT_ENT_TYPE_FREEBSD_VINUM; +static uuid_t gpt_uuid_freebsd_zfs = GPT_ENT_TYPE_FREEBSD_ZFS; +static uuid_t gpt_uuid_mbr = GPT_ENT_TYPE_MBR; +static uuid_t gpt_uuid_ms_basic_data = GPT_ENT_TYPE_MS_BASIC_DATA; + static struct mkimg_alias gpt_aliases[] = { { ALIAS_EFI, ALIAS_PTR2TYPE(&gpt_uuid_efi) }, { ALIAS_FREEBSD, ALIAS_PTR2TYPE(&gpt_uuid_freebsd) }, @@ -125,6 +131,21 @@ crc32(const void *buf, size_t sz) return (crc ^ ~0U); } +static void +gpt_uuid_enc(void *buf, const uuid_t *uuid) +{ + uint8_t *p = buf; + int i; + + le32enc(p, uuid->time_low); + le16enc(p + 4, uuid->time_mid); + le16enc(p + 6, uuid->time_hi_and_version); + p[8] = uuid->clock_seq_hi_and_reserved; + p[9] = uuid->clock_seq_low; + for (i = 0; i < _UUID_NODE_LEN; i++) + p[10 + i] = uuid->node[i]; +} + static u_int gpt_tblsz(void) { @@ -152,7 +173,7 @@ gpt_write_pmbr(lba_t blks, void *bootcode) uint32_t secs; int error; - secs = (blks > UINT32_MAX) ? UINT32_MAX : (uint32_t)blks - 1; + secs = (blks > UINT32_MAX) ? UINT32_MAX : (uint32_t)blks; pmbr = malloc(secsz); if (pmbr == NULL) @@ -178,7 +199,7 @@ gpt_write_pmbr(lba_t blks, void *bootcode) static struct gpt_ent * gpt_mktbl(u_int tblsz) { - mkimg_uuid_t uuid; + uuid_t uuid; struct gpt_ent *tbl, *ent; struct part *part; int c, idx; @@ -187,11 +208,11 @@ gpt_mktbl(u_int tblsz) if (tbl == NULL) return (NULL); - TAILQ_FOREACH(part, &partlist, link) { + STAILQ_FOREACH(part, &partlist, link) { ent = tbl + part->index; - mkimg_uuid_enc(&ent->ent_type, ALIAS_TYPE2PTR(part->type)); + gpt_uuid_enc(&ent->ent_type, ALIAS_TYPE2PTR(part->type)); mkimg_uuid(&uuid); - mkimg_uuid_enc(&ent->ent_uuid, &uuid); + gpt_uuid_enc(&ent->ent_uuid, &uuid); le64enc(&ent->ent_lba_start, part->block); le64enc(&ent->ent_lba_end, part->block + part->size - 1); if (part->label != NULL) { @@ -222,7 +243,7 @@ gpt_write_hdr(struct gpt_hdr *hdr, uint64_t self, uint static int gpt_write(lba_t imgsz, void *bootcode) { - mkimg_uuid_t uuid; + uuid_t uuid; struct gpt_ent *tbl; struct gpt_hdr *hdr; uint32_t crc; @@ -259,7 +280,7 @@ gpt_write(lba_t imgsz, void *bootcode) le64enc(&hdr->hdr_lba_start, 2 + tblsz); le64enc(&hdr->hdr_lba_end, imgsz - tblsz - 2); mkimg_uuid(&uuid); - mkimg_uuid_enc(&hdr->hdr_uuid, &uuid); + gpt_uuid_enc(&hdr->hdr_uuid, &uuid); le32enc(&hdr->hdr_entries, nparts); le32enc(&hdr->hdr_entsz, sizeof(struct gpt_ent)); crc = crc32(tbl, nparts * sizeof(struct gpt_ent)); Modified: stable/11/usr.bin/mkimg/image.c ============================================================================== --- stable/11/usr.bin/mkimg/image.c Wed Feb 7 16:28:26 2018 (r328975) +++ stable/11/usr.bin/mkimg/image.c Wed Feb 7 16:45:38 2018 (r328976) @@ -28,7 +28,9 @@ __FBSDID("$FreeBSD$"); #include +#include #include +#include #include #include #include @@ -43,22 +45,8 @@ __FBSDID("$FreeBSD$"); #include "image.h" #include "mkimg.h" -#ifndef MAP_NOCORE -#define MAP_NOCORE 0 -#endif -#ifndef MAP_NOSYNC -#define MAP_NOSYNC 0 -#endif - -#ifndef SEEK_DATA -#define SEEK_DATA -1 -#endif -#ifndef SEEK_HOLE -#define SEEK_HOLE -1 -#endif - struct chunk { - TAILQ_ENTRY(chunk) ch_list; + STAILQ_ENTRY(chunk) ch_list; size_t ch_size; /* Size of chunk in bytes. */ lba_t ch_block; /* Block address in image. */ union { @@ -76,7 +64,7 @@ struct chunk { #define CH_TYPE_MEMORY 2 /* Memory-backed chunk */ }; -static TAILQ_HEAD(chunk_head, chunk) image_chunks; +static STAILQ_HEAD(chunk_head, chunk) image_chunks; static u_int image_nchunks; static char image_swap_file[PATH_MAX]; @@ -137,14 +125,14 @@ image_chunk_find(lba_t blk) struct chunk *ch; ch = (last != NULL && last->ch_block <= blk) - ? last : TAILQ_FIRST(&image_chunks); + ? last : STAILQ_FIRST(&image_chunks); while (ch != NULL) { if (ch->ch_block <= blk && (lba_t)(ch->ch_block + (ch->ch_size / secsz)) > blk) { last = ch; break; } - ch = TAILQ_NEXT(ch, ch_list); + ch = STAILQ_NEXT(ch, ch_list); } return (ch); } @@ -186,7 +174,7 @@ image_chunk_memory(struct chunk *ch, lba_t blk) ch->ch_size = (blk - ch->ch_block) * secsz; new->ch_block = blk; new->ch_size -= ch->ch_size; - TAILQ_INSERT_AFTER(&image_chunks, ch, new, ch_list); + STAILQ_INSERT_AFTER(&image_chunks, ch, new, ch_list); image_nchunks++; ch = new; } @@ -201,7 +189,7 @@ image_chunk_memory(struct chunk *ch, lba_t blk) ch->ch_size = secsz; new->ch_block++; new->ch_size -= secsz; - TAILQ_INSERT_AFTER(&image_chunks, ch, new, ch_list); + STAILQ_INSERT_AFTER(&image_chunks, ch, new, ch_list); image_nchunks++; } @@ -217,7 +205,7 @@ image_chunk_skipto(lba_t to) lba_t from; size_t sz; - ch = TAILQ_LAST(&image_chunks, chunk_head); + ch = STAILQ_LAST(&image_chunks, chunk, ch_list); from = (ch != NULL) ? ch->ch_block + (ch->ch_size / secsz) : 0LL; assert(from <= to); @@ -242,7 +230,7 @@ image_chunk_skipto(lba_t to) ch->ch_block = from; ch->ch_size = sz; ch->ch_type = CH_TYPE_ZEROES; - TAILQ_INSERT_TAIL(&image_chunks, ch, ch_list); + STAILQ_INSERT_TAIL(&image_chunks, ch, ch_list); image_nchunks++; return (0); } @@ -252,7 +240,7 @@ image_chunk_append(lba_t blk, size_t sz, off_t ofs, in { struct chunk *ch; - ch = TAILQ_LAST(&image_chunks, chunk_head); + ch = STAILQ_LAST(&image_chunks, chunk, ch_list); if (ch != NULL && ch->ch_type == CH_TYPE_FILE) { if (fd == ch->ch_u.file.fd && blk == (lba_t)(ch->ch_block + (ch->ch_size / secsz)) && @@ -273,7 +261,7 @@ image_chunk_append(lba_t blk, size_t sz, off_t ofs, in ch->ch_type = CH_TYPE_FILE; ch->ch_u.file.ofs = ofs; ch->ch_u.file.fd = fd; - TAILQ_INSERT_TAIL(&image_chunks, ch, ch_list); + STAILQ_INSERT_TAIL(&image_chunks, ch, ch_list); image_nchunks++; return (0); } @@ -468,7 +456,8 @@ image_copyin_mapped(lba_t blk, int fd, uint64_t *sizep * I don't know what this means or whether it * can happen at all... */ - assert(0); + error = EDOOFUS; + break; } } if (error) @@ -594,13 +583,10 @@ image_copyout_region(int fd, lba_t blk, lba_t size) size *= secsz; - error = 0; - while (!error && size > 0) { + while (size > 0) { ch = image_chunk_find(blk); - if (ch == NULL) { - error = EINVAL; - break; - } + if (ch == NULL) + return (EINVAL); ofs = (blk - ch->ch_block) * secsz; sz = ch->ch_size - ofs; sz = ((lba_t)sz < size) ? sz : (size_t)size; @@ -616,12 +602,12 @@ image_copyout_region(int fd, lba_t blk, lba_t size) error = image_copyout_memory(fd, sz, ch->ch_u.mem.ptr); break; default: - assert(0); + return (EDOOFUS); } size -= sz; blk += sz / secsz; } - return (error); + return (0); } int @@ -696,7 +682,7 @@ image_cleanup(void) { struct chunk *ch; - while ((ch = TAILQ_FIRST(&image_chunks)) != NULL) { + while ((ch = STAILQ_FIRST(&image_chunks)) != NULL) { switch (ch->ch_type) { case CH_TYPE_FILE: /* We may be closing the same file multiple times. */ @@ -709,7 +695,7 @@ image_cleanup(void) default: break; } - TAILQ_REMOVE(&image_chunks, ch, ch_list); + STAILQ_REMOVE_HEAD(&image_chunks, ch_list); free(ch); } if (image_swap_fd != -1) @@ -722,7 +708,7 @@ image_init(void) { const char *tmpdir; - TAILQ_INIT(&image_chunks); + STAILQ_INIT(&image_chunks); image_nchunks = 0; image_swap_size = 0; Modified: stable/11/usr.bin/mkimg/mbr.c ============================================================================== --- stable/11/usr.bin/mkimg/mbr.c Wed Feb 7 16:28:26 2018 (r328975) +++ stable/11/usr.bin/mkimg/mbr.c Wed Feb 7 16:45:38 2018 (r328976) @@ -27,23 +27,35 @@ #include __FBSDID("$FreeBSD$"); +#include +#include +#include #include -#include #include #include #include -#include - -#include "endian.h" #include "image.h" #include "mkimg.h" #include "scheme.h" +#ifndef DOSPTYP_FAT16B +#define DOSPTYP_FAT16B 0x06 +#endif +#ifndef DOSPTYP_FAT32 +#define DOSPTYP_FAT32 0x0b +#endif +#ifndef DOSPTYP_PPCBOOT +#define DOSPTYP_PPCBOOT 0x41 +#endif +#ifndef DOSPTYP_EFI +#define DOSPTYP_EFI 0xef +#endif + static struct mkimg_alias mbr_aliases[] = { { ALIAS_EBR, ALIAS_INT2TYPE(DOSPTYP_EXT) }, { ALIAS_EFI, ALIAS_INT2TYPE(DOSPTYP_EFI) }, - { ALIAS_FAT16B, ALIAS_INT2TYPE(DOSPTYP_FAT16) }, + { ALIAS_FAT16B, ALIAS_INT2TYPE(DOSPTYP_FAT16B) }, { ALIAS_FAT32, ALIAS_INT2TYPE(DOSPTYP_FAT32) }, { ALIAS_FREEBSD, ALIAS_INT2TYPE(DOSPTYP_386BSD) }, { ALIAS_NTFS, ALIAS_INT2TYPE(DOSPTYP_NTFS) }, @@ -89,15 +101,10 @@ mbr_write(lba_t imgsz __unused, void *bootcode) memset(mbr, 0, secsz); le16enc(mbr + DOSMAGICOFFSET, DOSMAGIC); dpbase = (void *)(mbr + DOSPARTOFF); - TAILQ_FOREACH(part, &partlist, link) { + STAILQ_FOREACH(part, &partlist, link) { size = round_track(part->size); dp = dpbase + part->index; - if (active_partition != 0) - dp->dp_flag = - (part->index + 1 == active_partition) ? 0x80 : 0; - else - dp->dp_flag = - (part->index == 0 && bootcode != NULL) ? 0x80 : 0; + 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); Modified: stable/11/usr.bin/mkimg/mkimg.1 ============================================================================== --- stable/11/usr.bin/mkimg/mkimg.1 Wed Feb 7 16:28:26 2018 (r328975) +++ stable/11/usr.bin/mkimg/mkimg.1 Wed Feb 7 16:45:38 2018 (r328976) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd April 26, 2017 +.Dd August 7, 2015 .Dt MKIMG 1 .Os .Sh NAME @@ -37,12 +37,9 @@ .Op Fl S Ar secsz .Op Fl T Ar tracksz .Op Fl b Ar bootcode -.Op Fl c Ar min_capacity -.Op Fl C Ar max_capacity -.Op Fl -capacity Ar capacity +.Op Fl c Ar capacity .Op Fl f Ar format .Op Fl o Ar outfile -.Op Fl a Ar active .Op Fl v .Op Fl y .Op Fl s Ar scheme Op Fl p Ar partition ... @@ -122,23 +119,11 @@ An empty partition table can be written to the disk wh partitioning scheme with the .Fl s option, but without specifying any partitions. -When the size required for all the partitions is larger than the +When the size required to for all the partitions is larger than the given capacity, then the disk image will be larger than the capacity given. .Pp The -.Fl C -option specifies a maximum capacity for the disk image. -If the combined sizes of the given partitions exceed the size given with -.Fl C , -image creation fails. -.Pp -The -.Fl -capacity -option is a shorthand to specify the minimum and maximum capacity at the -same time. -.Pp -The .Fl v option increases the level of output that the .Nm @@ -153,26 +138,6 @@ utility will generate predictable values for Universal (UUIDs) and time stamps so that consecutive runs of the .Nm utility will create images that are identical. -.Pp -The -.Ar active -option marks a partition as active, if the partitioning -scheme supports it. -Currently, only the -.Ar mbr -scheme supports this concept. -By default, -.Nm -will only mark the first partition as active when boot code is -specified. -Use the -.Ar active -option to override the active partition. -The number specified corresponds to the number after the 's' in the -partition's -.Xr geom 8 -name. -No partitions are marked active when the value is 0. .Pp A set of long options exist to query about the .Nm Modified: stable/11/usr.bin/mkimg/mkimg.c ============================================================================== --- stable/11/usr.bin/mkimg/mkimg.c Wed Feb 7 16:28:26 2018 (r328975) +++ stable/11/usr.bin/mkimg/mkimg.c Wed Feb 7 16:45:38 2018 (r328976) @@ -27,15 +27,17 @@ #include __FBSDID("$FreeBSD$"); -#include +#include +#include #include +#include +#include #include #include #include #include #include #include -#include #include #include #include @@ -47,23 +49,20 @@ __FBSDID("$FreeBSD$"); #include "mkimg.h" #include "scheme.h" -#define LONGOPT_FORMATS 0x01000001 -#define LONGOPT_SCHEMES 0x01000002 -#define LONGOPT_VERSION 0x01000003 -#define LONGOPT_CAPACITY 0x01000004 +#define LONGOPT_FORMATS 0x01000001 +#define LONGOPT_SCHEMES 0x01000002 +#define LONGOPT_VERSION 0x01000003 static struct option longopts[] = { { "formats", no_argument, NULL, LONGOPT_FORMATS }, { "schemes", no_argument, NULL, LONGOPT_SCHEMES }, { "version", no_argument, NULL, LONGOPT_VERSION }, - { "capacity", required_argument, NULL, LONGOPT_CAPACITY }, { NULL, 0, NULL, 0 } }; -static uint64_t min_capacity = 0; -static uint64_t max_capacity = 0; +static uint64_t capacity; -struct partlisthead partlist = TAILQ_HEAD_INITIALIZER(partlist); +struct partlisthead partlist = STAILQ_HEAD_INITIALIZER(partlist); u_int nparts = 0; u_int unit_testing; @@ -74,25 +73,24 @@ u_int nheads = 1; u_int nsecs = 1; u_int secsz = 512; u_int blksz = 0; -uint32_t active_partition = 0; static void print_formats(int usage) { - struct mkimg_format *f; + struct mkimg_format *f, **f_iter; const char *sep; if (usage) { fprintf(stderr, " formats:\n"); - f = NULL; - while ((f = format_iterate(f)) != NULL) { + SET_FOREACH(f_iter, formats) { + f = *f_iter; fprintf(stderr, "\t%s\t- %s\n", f->name, f->description); } } else { sep = ""; - f = NULL; - while ((f = format_iterate(f)) != NULL) { + SET_FOREACH(f_iter, formats) { + f = *f_iter; printf("%s%s", sep, f->name); sep = " "; } @@ -103,20 +101,20 @@ print_formats(int usage) static void print_schemes(int usage) { - struct mkimg_scheme *s; + struct mkimg_scheme *s, **s_iter; const char *sep; if (usage) { fprintf(stderr, " schemes:\n"); - s = NULL; - while ((s = scheme_iterate(s)) != NULL) { + SET_FOREACH(s_iter, schemes) { + s = *s_iter; fprintf(stderr, "\t%s\t- %s\n", s->name, s->description); } } else { sep = ""; - s = NULL; - while ((s = scheme_iterate(s)) != NULL) { + SET_FOREACH(s_iter, schemes) { + s = *s_iter; printf("%s%s", sep, s->name); sep = " "; } @@ -150,10 +148,8 @@ usage(const char *why) fprintf(stderr, "\t--schemes\t- list partition schemes\n"); fprintf(stderr, "\t--version\t- show version information\n"); fputc('\n', stderr); - fprintf(stderr, "\t-a \t- mark num'th partion as active\n"); fprintf(stderr, "\t-b \t- file containing boot code\n"); - fprintf(stderr, "\t-c \t- minimum capacity (in bytes) of the disk\n"); - fprintf(stderr, "\t-C \t- maximum capacity (in bytes) of the disk\n"); + fprintf(stderr, "\t-c \t- capacity (in bytes) of the disk\n"); fprintf(stderr, "\t-f \n"); fprintf(stderr, "\t-o \t- file to write image into\n"); fprintf(stderr, "\t-p \n"); @@ -306,7 +302,7 @@ parse_part(const char *spec) } part->index = nparts; - TAILQ_INSERT_TAIL(&partlist, part, link); + STAILQ_INSERT_TAIL(&partlist, part, link); nparts++; return (0); @@ -380,20 +376,31 @@ mkimg_chs(lba_t lba, u_int maxcyl, u_int *cylp, u_int *secp = sec; } +void +mkimg_uuid(struct uuid *uuid) +{ + static uint8_t gen[sizeof(struct uuid)]; + u_int i; + + if (!unit_testing) { + uuidgen(uuid, 1); + return; + } + + for (i = 0; i < sizeof(gen); i++) + gen[i]++; + memcpy(uuid, gen, sizeof(uuid_t)); +} + static int capacity_resize(lba_t end) { - lba_t min_capsz, max_capsz; + lba_t capsz; - min_capsz = (min_capacity + secsz - 1) / secsz; - max_capsz = (max_capacity + secsz - 1) / secsz; - - if (max_capsz != 0 && end > max_capsz) - return (ENOSPC); - if (end >= min_capsz) + capsz = (capacity + secsz - 1) / secsz; + if (end >= capsz) return (0); - - return (image_set_size(min_capsz)); + return (image_set_size(capsz)); } static void @@ -406,14 +413,14 @@ mkimg(void) int error, fd; /* First check partition information */ - TAILQ_FOREACH(part, &partlist, link) { + STAILQ_FOREACH(part, &partlist, link) { error = scheme_check_part(part); if (error) errc(EX_DATAERR, error, "partition %d", part->index+1); } block = scheme_metadata(SCHEME_META_IMG_START, 0); - TAILQ_FOREACH(part, &partlist, link) { + STAILQ_FOREACH(part, &partlist, link) { block = scheme_metadata(SCHEME_META_PART_BEFORE, block); if (verbose) fprintf(stderr, "partition %d: starting block %llu " @@ -480,14 +487,9 @@ main(int argc, char *argv[]) bcfd = -1; outfd = 1; /* Write to stdout by default */ - while ((c = getopt_long(argc, argv, "a:b:c:C:f:o:p:s:vyH:P:S:T:", + while ((c = getopt_long(argc, argv, "b:c:f:o:p:s:vyH:P:S:T:", longopts, NULL)) != -1) { switch (c) { - case 'a': /* ACTIVE PARTITION, if supported */ - error = parse_uint32(&active_partition, 1, 100, optarg); - if (error) - errc(EX_DATAERR, error, "Partition ordinal"); - break; case 'b': /* BOOT CODE */ if (bcfd != -1) usage("multiple bootcode given"); @@ -495,16 +497,11 @@ main(int argc, char *argv[]) if (bcfd == -1) err(EX_UNAVAILABLE, "%s", optarg); break; - case 'c': /* MINIMUM CAPACITY */ - error = parse_uint64(&min_capacity, 1, INT64_MAX, optarg); + case 'c': /* CAPACITY */ + error = parse_uint64(&capacity, 1, OFF_MAX, optarg); if (error) - errc(EX_DATAERR, error, "minimum capacity in bytes"); + errc(EX_DATAERR, error, "capacity in bytes"); break; - case 'C': /* MAXIMUM CAPACITY */ - error = parse_uint64(&max_capacity, 1, INT64_MAX, optarg); - if (error) - errc(EX_DATAERR, error, "maximum capacity in bytes"); - break; case 'f': /* OUTPUT FORMAT */ if (format_selected() != NULL) usage("multiple formats given"); @@ -574,12 +571,6 @@ main(int argc, char *argv[]) print_version(); exit(EX_OK); /*NOTREACHED*/ - case LONGOPT_CAPACITY: - error = parse_uint64(&min_capacity, 1, INT64_MAX, optarg); - if (error) - errc(EX_DATAERR, error, "capacity in bytes"); - max_capacity = min_capacity; - break; default: usage("unknown option"); } @@ -589,10 +580,8 @@ main(int argc, char *argv[]) usage("trailing arguments"); if (scheme_selected() == NULL && nparts > 0) usage("no scheme"); - if (nparts == 0 && min_capacity == 0) + if (nparts == 0 && capacity == 0) usage("no partitions"); - if (max_capacity != 0 && min_capacity > max_capacity) - usage("minimum capacity cannot be larger than the maximum one"); if (secsz > blksz) { *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***