summaryrefslogtreecommitdiff
path: root/usr/src/boot/common/md.c
diff options
context:
space:
mode:
authorRichard Lowe <richlowe@richlowe.net>2022-02-22 18:00:48 -0600
committerRichard Lowe <richlowe@richlowe.net>2022-02-22 18:00:48 -0600
commit3971085411b91c5d82e278443ab68fca1946cb21 (patch)
tree8e6d01d8aea1c3d8179a47b929ff5bfa8b42f752 /usr/src/boot/common/md.c
parent1df45418ec3688847e142a9a2213965459ff39c7 (diff)
parentca783257c986cddcc674ae22916a6766b98a2d36 (diff)
downloadillumos-joyent-3971085411b91c5d82e278443ab68fca1946cb21.tar.gz
Merge branch 'master' of https://github.com/illumos/illumos-gate into man/big-reorg
# Conflicts: # usr/src/cmd/fmthard/fmthard.c # usr/src/cmd/zoneadmd/zcons.c # usr/src/man/man2/chmod.2 # usr/src/man/man2/close.2 # usr/src/man/man2/open.2 # usr/src/man/man3c/grantpt.3c # usr/src/man/man3c/posix_openpt.3c # usr/src/man/man3c/ptsname.3c # usr/src/man/man3c/unlockpt.3c # usr/src/man/man3utempter/utempter_add_record.3utempter # usr/src/man/man4/Makefile # usr/src/man/man4d/ptm.4d # usr/src/man/man4d/pts.4d # usr/src/man/man4d/pty.4d # usr/src/man/man4d/zcons.4d # usr/src/man/man4m/pckt.4m # usr/src/man/man4m/ptem.4m # usr/src/man/man4p/vxlan.7p # usr/src/man/man5/Makefile # usr/src/man/man5/bhyve_config.5 # usr/src/man/man7d/Makefile # usr/src/man/man7p/Makefile # usr/src/man/man8/bhyve.8 # usr/src/man/man8/dladm.8 # usr/src/man/man8/flowadm.8 # usr/src/man/man8/fmthard.8 # usr/src/man/man8/in.rlogind.8 # usr/src/man/man8/in.telnetd.8 # usr/src/man/man8/nvmeadm.8 # usr/src/man/man8/pppd.8 # usr/src/pkg/manifests/SUNWcs.man4d.inc # usr/src/uts/common/io/zcons.c
Diffstat (limited to 'usr/src/boot/common/md.c')
-rw-r--r--usr/src/boot/common/md.c156
1 files changed, 156 insertions, 0 deletions
diff --git a/usr/src/boot/common/md.c b/usr/src/boot/common/md.c
new file mode 100644
index 0000000000..175833d748
--- /dev/null
+++ b/usr/src/boot/common/md.c
@@ -0,0 +1,156 @@
+/*-
+ * Copyright (c) 2009 Marcel Moolenaar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <stand.h>
+#include <sys/param.h>
+#include <sys/endian.h>
+#include <sys/queue.h>
+#include <machine/stdarg.h>
+
+#include "bootstrap.h"
+
+#define MD_BLOCK_SIZE 512
+
+#ifndef MD_IMAGE_SIZE
+#error Must be compiled with MD_IMAGE_SIZE defined
+#endif
+#if (MD_IMAGE_SIZE == 0 || MD_IMAGE_SIZE % MD_BLOCK_SIZE)
+#error Image size must be a multiple of 512.
+#endif
+
+/*
+ * Preloaded image gets put here.
+ * Applications that patch the object with the image can determine
+ * the size looking at the start and end markers (strings),
+ * so we want them contiguous.
+ */
+static struct {
+ u_char start[MD_IMAGE_SIZE];
+ u_char end[128];
+} md_image = {
+ .start = "MFS Filesystem goes here",
+ .end = "MFS Filesystem had better STOP here",
+};
+
+/* devsw I/F */
+static int md_init(void);
+static int md_strategy(void *, int, daddr_t, size_t, char *, size_t *);
+static int md_open(struct open_file *, ...);
+static int md_close(struct open_file *);
+static int md_print(int);
+
+struct devsw md_dev = {
+ "md",
+ DEVT_DISK,
+ md_init,
+ md_strategy,
+ md_open,
+ md_close,
+ noioctl,
+ md_print
+};
+
+static int
+md_init(void)
+{
+
+ return (0);
+}
+
+static int
+md_strategy(void *devdata, int rw, daddr_t blk, size_t size, char *buf,
+ size_t *rsize)
+{
+ struct devdesc *dev = (struct devdesc *)devdata;
+ size_t ofs;
+
+ if (dev->d_unit != 0)
+ return (ENXIO);
+
+ if (blk < 0 || blk >= (MD_IMAGE_SIZE / MD_BLOCK_SIZE))
+ return (EIO);
+
+ if (size % MD_BLOCK_SIZE)
+ return (EIO);
+
+ ofs = blk * MD_BLOCK_SIZE;
+ if ((ofs + size) > MD_IMAGE_SIZE)
+ size = MD_IMAGE_SIZE - ofs;
+
+ if (rsize != 0)
+ *rsize = size;
+
+ switch (rw & F_MASK) {
+ case F_READ:
+ bcopy(md_image.start + ofs, buf, size);
+ return (0);
+ case F_WRITE:
+ bcopy(buf, md_image.start + ofs, size);
+ return (0);
+ }
+
+ return (ENODEV);
+}
+
+static int
+md_open(struct open_file *f, ...)
+{
+ va_list ap;
+ struct devdesc *dev;
+
+ va_start(ap, f);
+ dev = va_arg(ap, struct devdesc *);
+ va_end(ap);
+
+ if (dev->d_unit != 0)
+ return (ENXIO);
+
+ return (0);
+}
+
+static int
+md_close(struct open_file *f)
+{
+ struct devdesc *dev;
+
+ dev = (struct devdesc *)(f->f_devdata);
+ return ((dev->d_unit != 0) ? ENXIO : 0);
+}
+
+static int
+md_print(int verbose)
+{
+
+ printf("%s devices:", md_dev.dv_name);
+ if (pager_output("\n") != 0)
+ return (1);
+
+ printf("MD (%u bytes)", MD_IMAGE_SIZE);
+ return (pager_output("\n"));
+}