Date: Tue, 24 Aug 2010 10:03:09 +0200 From: Ed Schouten <ed@80386.nl> To: Marcel Moolenaar <xcllnt@mac.com> Cc: "freebsd-arch@FreeBSD.org" <freebsd-arch@FreeBSD.org> Subject: Re: RFC: enhancing the root mount logic Message-ID: <20100824080309.GK64651@hoeg.nl> In-Reply-To: <20100824080128.GJ64651@hoeg.nl> References: <AFBE2FCA-30A6-4E1D-A964-AC4DC4C843EB@juniper.net> <20100823.171201.107001114053031707.imp@bsdimp.com> <8C76250B-E272-4807-BD0D-9F50D0BC5E10@mac.com> <20100824002350.042A45B3B@mail.bitblocks.com> <4CB9F7C8-39E8-4C3B-A3F8-A5A9EC178E7D@mac.com> <20100824080128.GJ64651@hoeg.nl>
next in thread | previous in thread | raw e-mail | index | archive | help
--RVlUGXxwBj5SDcM9 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable * Ed Schouten <ed@80386.nl> wrote: > See the attachment. It seems like Mailman ate the attachment. %%% /*- * Copyright (c) 2010 Ed Schouten <ed@FreeBSD.org> * 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 PURPO= SE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTI= AL * 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, STRI= CT * 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/param.h> #include <sys/linker.h> #include <sys/mount.h> #include <sys/uio.h> #include <errno.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> static void die(const char *msg) { int fd, serrno; serrno =3D errno; fd =3D open("/dev/console", O_RDWR); if (fd !=3D -1 && fd !=3D STDERR_FILENO) dup2(fd, STDERR_FILENO); errno =3D serrno; perror(msg); sleep(10); exit(1); } static void domount(const char * const list[], unsigned int elems) { struct iovec iov[elems]; unsigned int i; for (i =3D 0; i < elems; i++) { iov[i].iov_base =3D (char *)list[i]; iov[i].iov_len =3D strlen(list[i]) + 1; } if (nmount(iov, elems, 0) !=3D 0) die(list[1]); } static char const * const cdfs[] =3D { "fstype", "cd9660", "from", "/dev/iso9660/freebsd", "fspath", "/ro" }; static char const * const tmpfs[] =3D { "fstype", "tmpfs", "fspath", "/rw" }; static char const * const unionfs[] =3D { "fstype", "unionfs", "from", "/ro", "fspath", "/rw", "below", "", "whiteout", "whenneeded" }; static char const * const devfs[] =3D { "fstype", "devfs", "fspath", "/rw/dev" }; int main(int argc, char *argv[]) { /* Prevent foot shooting. */ if (getpid() !=3D 1) return (1); /* Perform mounts. */ domount(cdfs, sizeof cdfs / sizeof(char *)); domount(tmpfs, sizeof tmpfs / sizeof(char *)); domount(unionfs, sizeof unionfs / sizeof(char *)); domount(devfs, sizeof devfs / sizeof(char *)); /* chroot() into system and continue boot process. */ if (chroot("/rw") !=3D 0) die("chroot"); chdir("/"); /* Execute the real /sbin/init. */ execv(argv[0], argv); die("execv"); return (1); } %%% --=20 Ed Schouten <ed@80386.nl> WWW: http://80386.nl/ --RVlUGXxwBj5SDcM9 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (FreeBSD) iEYEARECAAYFAkxzfL0ACgkQ52SDGA2eCwVX4gCfXGwT+BrR2p/fcSDwzlgtDk4r LREAn1cIzCh1vFzUWnlRdCLCc48wwe8e =vd94 -----END PGP SIGNATURE----- --RVlUGXxwBj5SDcM9--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20100824080309.GK64651>