138465Smsmith/*- 238465Smsmith * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> 338465Smsmith * All rights reserved. 438465Smsmith * 538465Smsmith * Redistribution and use in source and binary forms, with or without 638465Smsmith * modification, are permitted provided that the following conditions 738465Smsmith * are met: 838465Smsmith * 1. Redistributions of source code must retain the above copyright 938465Smsmith * notice, this list of conditions and the following disclaimer. 1038465Smsmith * 2. Redistributions in binary form must reproduce the above copyright 1138465Smsmith * notice, this list of conditions and the following disclaimer in the 1238465Smsmith * documentation and/or other materials provided with the distribution. 1338465Smsmith * 1438465Smsmith * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1538465Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1638465Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1738465Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1838465Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1938465Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2038465Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2138465Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2238465Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2338465Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2438465Smsmith * SUCH DAMAGE. 2538465Smsmith */ 2638465Smsmith 27119483Sobrien#include <sys/cdefs.h> 28119483Sobrien__FBSDID("$FreeBSD$"); 2938465Smsmith 3038465Smsmith#include <stand.h> 3138465Smsmith#include <string.h> 3238465Smsmith 3338465Smsmith#include "bootstrap.h" 3438465Smsmith 3538465Smsmithint 3639673Sdfrdevopen(struct open_file *f, const char *fname, const char **file) 3738465Smsmith{ 38182731Sraj struct devdesc *dev; 39182731Sraj int result; 4038465Smsmith 41182731Sraj result = archsw.arch_getdev((void **)&dev, fname, file); 42182731Sraj if (result) 43182731Sraj return (result); 44163891Smarcel 45182731Sraj /* point to device-specific data so that device open can use it */ 46182731Sraj f->f_devdata = dev; 47182731Sraj result = dev->d_dev->dv_open(f, dev); 48182731Sraj if (result != 0) { 49182731Sraj f->f_devdata = NULL; 50182731Sraj free(dev); 51182731Sraj return (result); 52182731Sraj } 53163891Smarcel 54182731Sraj /* reference the devsw entry from the open_file structure */ 55182731Sraj f->f_dev = dev->d_dev; 56182731Sraj return (0); 5738465Smsmith} 5838465Smsmith 5938465Smsmithint 6038465Smsmithdevclose(struct open_file *f) 6138465Smsmith{ 62182731Sraj 63182731Sraj if (f->f_devdata != NULL) { 64182731Sraj free(f->f_devdata); 65182731Sraj } 66182731Sraj return (0); 6738465Smsmith} 68