Home | History | Annotate | Line # | Download | only in pxeboot
devopen.c revision 1.1
      1 /*	$NetBSD: devopen.c,v 1.1 2002/02/16 03:37:40 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright 2001 Wasabi Systems, Inc.
      5  * All rights reserved.
      6  *
      7  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed for the NetBSD Project by
     20  *	Wasabi Systems, Inc.
     21  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  *    or promote products derived from this software without specific prior
     23  *    written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  * POSSIBILITY OF SUCH DAMAGE.
     36  */
     37 
     38 #include <sys/param.h>
     39 #include <stand.h>
     40 
     41 #include <libi386.h>
     42 #ifdef _STANDALONE
     43 #include <lib/libkern/libkern.h>
     44 #include <bootinfo.h>
     45 #else
     46 #include <string.h>
     47 #endif
     48 
     49 #include "pxeboot.h"
     50 
     51 #ifdef _STANDALONE
     52 struct btinfo_bootpath bibp;
     53 #endif
     54 
     55 /*
     56  * Open the "device" named by the combined file system/file name
     57  * given as the fname arg.  Format is:
     58  *
     59  *	nfs:netbsd
     60  *	tftp:netbsd
     61  *	netbsd
     62  *
     63  * If no file system is specified, we default to the first in the
     64  * file system table (which ought to be NFS).
     65  *
     66  * We always open just one device (the PXE netif).
     67  */
     68 int
     69 devopen(struct open_file *f, const char *fname, char **file)
     70 {
     71 	struct devsw *dp;
     72 	char *filename;
     73 	size_t fsnamelen;
     74 	int i;
     75 
     76 	bcopy(pxeboot_fstab[0].fst_ops, file_system, sizeof(struct fs_ops));
     77 
     78 	filename = strchr(fname, ':');
     79 	if (filename != NULL) {
     80 		fsnamelen = (size_t)((const char *)filename - fname);
     81 		for (i = 0; i < npxeboot_fstab; i++) {
     82 			if (strncmp(fname, pxeboot_fstab[i].fst_name,
     83 			    fsnamelen) == 0) {
     84 				bcopy(pxeboot_fstab[i].fst_ops, file_system,
     85 				    sizeof(struct fs_ops));
     86 				break;
     87 			}
     88 		}
     89 		if (i == npxeboot_fstab) {
     90 			printf("Invalid file system type specified in %s\n",
     91 			    fname);
     92 			return (EINVAL);
     93 		}
     94 		filename++;
     95 		if (filename[0] == '\0') {
     96 			printf("No file specified in %s\n", fname);
     97 			return (EINVAL);
     98 		}
     99 	} else
    100 		filename = (char *)fname;
    101 
    102 	*file = filename;
    103 	dp = &devsw[0];
    104 	f->f_dev = dp;
    105 
    106 #ifdef _STANDALONE
    107 	strncpy(bibp.bootpath, filename, sizeof(bibp.bootpath));
    108 	BI_ADD(&bibp, BTINFO_BOOTPATH, sizeof(bibp));
    109 #endif
    110 
    111 	return ((*dp->dv_open)(f, NULL));
    112 }
    113