devopen.c revision 182731
138889Sjdp/*- 238889Sjdp * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> 338889Sjdp * All rights reserved. 438889Sjdp * 560484Sobrien * Redistribution and use in source and binary forms, with or without 660484Sobrien * modification, are permitted provided that the following conditions 738889Sjdp * are met: 838889Sjdp * 1. Redistributions of source code must retain the above copyright 960484Sobrien * notice, this list of conditions and the following disclaimer. 1038889Sjdp * 2. Redistributions in binary form must reproduce the above copyright 1177298Sobrien * notice, this list of conditions and the following disclaimer in the 1277298Sobrien * documentation and/or other materials provided with the distribution. 1377298Sobrien * 1438889Sjdp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1538889Sjdp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1638889Sjdp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1738889Sjdp * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1838889Sjdp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1977298Sobrien * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2077298Sobrien * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2177298Sobrien * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2238889Sjdp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2338889Sjdp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2438889Sjdp * SUCH DAMAGE. 2560484Sobrien */ 2638889Sjdp 2760484Sobrien#include <sys/cdefs.h> 2860484Sobrien__FBSDID("$FreeBSD: head/sys/boot/common/devopen.c 182731 2008-09-03 17:41:44Z raj $"); 2938889Sjdp 3038889Sjdp#include <stand.h> 3177298Sobrien#include <string.h> 3277298Sobrien 3338889Sjdp#include "bootstrap.h" 3438889Sjdp 3538889Sjdpint 3638889Sjdpdevopen(struct open_file *f, const char *fname, const char **file) 3738889Sjdp{ 3838889Sjdp struct devdesc *dev; 3938889Sjdp int result; 4038889Sjdp 4160484Sobrien result = archsw.arch_getdev((void **)&dev, fname, file); 4260484Sobrien if (result) 4377298Sobrien return (result); 4438889Sjdp 4560484Sobrien /* point to device-specific data so that device open can use it */ 4638889Sjdp f->f_devdata = dev; 4738889Sjdp result = dev->d_dev->dv_open(f, dev); 4838889Sjdp if (result != 0) { 4977298Sobrien f->f_devdata = NULL; 5077298Sobrien free(dev); 5138889Sjdp return (result); 5238889Sjdp } 5360484Sobrien 5460484Sobrien /* reference the devsw entry from the open_file structure */ 5538889Sjdp f->f_dev = dev->d_dev; 5638889Sjdp return (0); 5760484Sobrien} 5860484Sobrien 5960484Sobrienint 6060484Sobriendevclose(struct open_file *f) 6160484Sobrien{ 6238889Sjdp 6338889Sjdp if (f->f_devdata != NULL) { 6438889Sjdp free(f->f_devdata); 6560484Sobrien } 6660484Sobrien return (0); 6738889Sjdp} 6877298Sobrien