2 * Copyright (c) 2014 Juniper Networks, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/errno.h>
42 static struct mkimg_alias vtoc8_aliases[] = {
43 { ALIAS_FREEBSD_NANDFS, ALIAS_INT2TYPE(VTOC_TAG_FREEBSD_NANDFS) },
44 { ALIAS_FREEBSD_SWAP, ALIAS_INT2TYPE(VTOC_TAG_FREEBSD_SWAP) },
45 { ALIAS_FREEBSD_UFS, ALIAS_INT2TYPE(VTOC_TAG_FREEBSD_UFS) },
46 { ALIAS_FREEBSD_VINUM, ALIAS_INT2TYPE(VTOC_TAG_FREEBSD_VINUM) },
47 { ALIAS_FREEBSD_ZFS, ALIAS_INT2TYPE(VTOC_TAG_FREEBSD_NANDFS) },
52 vtoc8_metadata(u_int where, lba_t blk)
55 blk += (where == SCHEME_META_IMG_START) ? 1 : 0;
56 return (round_cylinder(blk));
60 vtoc8_write(lba_t imgsz, void *bootcode __unused)
68 imgsz = (lba_t)ncyls * nheads * nsecs;
70 memset(&vtoc8, 0, sizeof(vtoc8));
71 sprintf(vtoc8.ascii, "FreeBSD%lldM",
72 (long long)(imgsz * secsz / 1048576));
73 be32enc(&vtoc8.version, VTOC_VERSION);
74 be16enc(&vtoc8.nparts, VTOC8_NPARTS);
75 be32enc(&vtoc8.sanity, VTOC_SANITY);
76 be16enc(&vtoc8.rpm, 3600);
77 be16enc(&vtoc8.physcyls, ncyls);
78 be16enc(&vtoc8.ncyls, ncyls);
79 be16enc(&vtoc8.altcyls, 0);
80 be16enc(&vtoc8.nheads, nheads);
81 be16enc(&vtoc8.nsecs, nsecs);
82 be16enc(&vtoc8.magic, VTOC_MAGIC);
84 be32enc(&vtoc8.map[VTOC_RAW_PART].nblks, imgsz);
85 TAILQ_FOREACH(part, &partlist, link) {
86 n = part->index + ((part->index >= VTOC_RAW_PART) ? 1 : 0);
87 be16enc(&vtoc8.part[n].tag, ALIAS_TYPE2INT(part->type));
88 be32enc(&vtoc8.map[n].cyl, part->block / (nsecs * nheads));
89 be32enc(&vtoc8.map[n].nblks, part->size);
92 /* Calculate checksum. */
95 for (ofs = 0; ofs < sizeof(vtoc8) - 2; ofs += 2)
96 sum ^= be16dec(p + ofs);
97 be16enc(&vtoc8.cksum, sum);
99 error = image_write(0, &vtoc8, 1);
103 static struct mkimg_scheme vtoc8_scheme = {
105 .description = "SMI VTOC8 disk labels",
106 .aliases = vtoc8_aliases,
107 .metadata = vtoc8_metadata,
108 .write = vtoc8_write,
109 .nparts = VTOC8_NPARTS - 1,
113 SCHEME_DEFINE(vtoc8_scheme);