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