root/sys/arch/alpha/stand/nboot/devopen.c
/*      $OpenBSD: devopen.c,v 1.1 2023/03/11 20:56:01 miod Exp $        */

/*
 * Copyright (c) 2023 Miodrag Vallat.
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include "libsa.h"

int
devopen(struct open_file *f, const char *fname, char **file)
{
        struct devsw *dp;
        const char *s;

        /*
         * Unfortunately for us, the BOOTDEF_DEV environment variable
         * contents does not match the DKA/DQA/DRA/DVA/MKA/EWA... SRM
         * device names, and we can't convert between them.
         * So we can only boot files from the same device the boot loader
         * was loaded from, and ignore any device specification here.
         */
        s = strchr(fname, ':');
        if (s != NULL)
                *file = (char *)++s;
        else
                *file = (char *)fname;

        dp = &devsw[0];
        f->f_dev = dp;
        return (*dp->dv_open)(f);
}