11.3Skiyohara/* $NetBSD: devopen.c,v 1.3 2009/07/20 04:59:03 kiyohara Exp $ */ 21.1Scherry 31.1Scherry/*- 41.1Scherry * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> 51.1Scherry * All rights reserved. 61.1Scherry * 71.1Scherry * Redistribution and use in source and binary forms, with or without 81.1Scherry * modification, are permitted provided that the following conditions 91.1Scherry * are met: 101.1Scherry * 1. Redistributions of source code must retain the above copyright 111.1Scherry * notice, this list of conditions and the following disclaimer. 121.1Scherry * 2. Redistributions in binary form must reproduce the above copyright 131.1Scherry * notice, this list of conditions and the following disclaimer in the 141.1Scherry * documentation and/or other materials provided with the distribution. 151.1Scherry * 161.1Scherry * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 171.1Scherry * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 181.1Scherry * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 191.1Scherry * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 201.1Scherry * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 211.1Scherry * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 221.1Scherry * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 231.1Scherry * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 241.1Scherry * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 251.1Scherry * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 261.1Scherry * SUCH DAMAGE. 271.1Scherry */ 281.1Scherry 291.1Scherry#include <sys/cdefs.h> 301.2Scherry/* __FBSDID("$FreeBSD: src/sys/boot/common/devopen.c,v 1.4 2003/08/25 23:30:41 obrien Exp $"); */ 311.1Scherry 321.1Scherry#include <lib/libsa/stand.h> 331.3Skiyohara#include <lib/libsa/loadfile.h> 341.1Scherry 351.1Scherry#include "bootstrap.h" 361.1Scherry 371.1Scherryint 381.1Scherrydevopen(struct open_file *f, const char *fname, char **file) 391.1Scherry{ 401.1Scherry struct devdesc *dev; 411.1Scherry int result; 421.1Scherry 431.1Scherry if ((result = archsw.arch_getdev((void *)&dev, fname, (const char **) file)) == 0) { /* get the device */ 441.1Scherry /* point to device-specific data so that device open can use it */ 451.1Scherry f->f_devdata = dev; 461.1Scherry if ((result = dev->d_dev->dv_open(f, dev)) == 0) { /* try to open it */ 471.1Scherry /* reference the devsw entry from the open_file structure */ 481.1Scherry f->f_dev = dev->d_dev; 491.1Scherry } else { 501.1Scherry free(dev); /* release the device descriptor */ 511.1Scherry } 521.1Scherry } 531.1Scherry return(result); 541.1Scherry} 551.1Scherry 561.1Scherryint 571.1Scherrydevclose(struct open_file *f) 581.1Scherry{ 591.1Scherry if (f->f_devdata != NULL) { 601.1Scherry free(f->f_devdata); 611.1Scherry } 621.1Scherry return(0); 631.1Scherry} 64