1 /* $OpenBSD: devopen.c,v 1.1 2023/03/11 20:56:01 miod Exp $ */
2
3 /*
4 * Copyright (c) 2023 Miodrag Vallat.
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #include "libsa.h"
20
21 int
devopen(struct open_file * f,const char * fname,char ** file)22 devopen(struct open_file *f, const char *fname, char **file)
23 {
24 struct devsw *dp;
25 const char *s;
26
27 /*
28 * Unfortunately for us, the BOOTDEF_DEV environment variable
29 * contents does not match the DKA/DQA/DRA/DVA/MKA/EWA... SRM
30 * device names, and we can't convert between them.
31 * So we can only boot files from the same device the boot loader
32 * was loaded from, and ignore any device specification here.
33 */
34 s = strchr(fname, ':');
35 if (s != NULL)
36 *file = (char *)++s;
37 else
38 *file = (char *)fname;
39
40 dp = &devsw[0];
41 f->f_dev = dp;
42 return (*dp->dv_open)(f);
43 }
44