1*93b81f4cSkiyohara /* $NetBSD: devopen.c,v 1.3 2009/07/20 04:59:03 kiyohara Exp $ */
2ba7cbe76Scherry
3ba7cbe76Scherry /*-
4ba7cbe76Scherry * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
5ba7cbe76Scherry * All rights reserved.
6ba7cbe76Scherry *
7ba7cbe76Scherry * Redistribution and use in source and binary forms, with or without
8ba7cbe76Scherry * modification, are permitted provided that the following conditions
9ba7cbe76Scherry * are met:
10ba7cbe76Scherry * 1. Redistributions of source code must retain the above copyright
11ba7cbe76Scherry * notice, this list of conditions and the following disclaimer.
12ba7cbe76Scherry * 2. Redistributions in binary form must reproduce the above copyright
13ba7cbe76Scherry * notice, this list of conditions and the following disclaimer in the
14ba7cbe76Scherry * documentation and/or other materials provided with the distribution.
15ba7cbe76Scherry *
16ba7cbe76Scherry * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17ba7cbe76Scherry * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18ba7cbe76Scherry * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19ba7cbe76Scherry * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20ba7cbe76Scherry * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21ba7cbe76Scherry * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22ba7cbe76Scherry * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23ba7cbe76Scherry * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24ba7cbe76Scherry * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25ba7cbe76Scherry * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26ba7cbe76Scherry * SUCH DAMAGE.
27ba7cbe76Scherry */
28ba7cbe76Scherry
29ba7cbe76Scherry #include <sys/cdefs.h>
3040d4f67eScherry /* __FBSDID("$FreeBSD: src/sys/boot/common/devopen.c,v 1.4 2003/08/25 23:30:41 obrien Exp $"); */
31ba7cbe76Scherry
32ba7cbe76Scherry #include <lib/libsa/stand.h>
33*93b81f4cSkiyohara #include <lib/libsa/loadfile.h>
34ba7cbe76Scherry
35ba7cbe76Scherry #include "bootstrap.h"
36ba7cbe76Scherry
37ba7cbe76Scherry int
devopen(struct open_file * f,const char * fname,char ** file)38ba7cbe76Scherry devopen(struct open_file *f, const char *fname, char **file)
39ba7cbe76Scherry {
40ba7cbe76Scherry struct devdesc *dev;
41ba7cbe76Scherry int result;
42ba7cbe76Scherry
43ba7cbe76Scherry if ((result = archsw.arch_getdev((void *)&dev, fname, (const char **) file)) == 0) { /* get the device */
44ba7cbe76Scherry /* point to device-specific data so that device open can use it */
45ba7cbe76Scherry f->f_devdata = dev;
46ba7cbe76Scherry if ((result = dev->d_dev->dv_open(f, dev)) == 0) { /* try to open it */
47ba7cbe76Scherry /* reference the devsw entry from the open_file structure */
48ba7cbe76Scherry f->f_dev = dev->d_dev;
49ba7cbe76Scherry } else {
50ba7cbe76Scherry free(dev); /* release the device descriptor */
51ba7cbe76Scherry }
52ba7cbe76Scherry }
53ba7cbe76Scherry return(result);
54ba7cbe76Scherry }
55ba7cbe76Scherry
56ba7cbe76Scherry int
devclose(struct open_file * f)57ba7cbe76Scherry devclose(struct open_file *f)
58ba7cbe76Scherry {
59ba7cbe76Scherry if (f->f_devdata != NULL) {
60ba7cbe76Scherry free(f->f_devdata);
61ba7cbe76Scherry }
62ba7cbe76Scherry return(0);
63ba7cbe76Scherry }
64