⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 open.c

📁 MIPS处理器的bootloader,龙芯就是用的修改过的PMON2
💻 C
字号:
/* $Id: open.c,v 1.12 2002/08/19 08:08:08 pefo Exp $ *//* * Copyright (c) 2000-2002 Opsycon AB  (www.opsycon.se) *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by Opsycon AB. * 4. The name of the author may not be used to endorse or promote products *    derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */#include <stdio.h>#include <string.h>#include <file.h>#include <fcntl.h>#include <errno.h>extern SLIST_HEAD(FileSystems, FileSystem) FileSystems;static int __try_open(const char *, int, char *, int, int);intopen(fname, mode)	const char *fname;	int mode;{	char    *dname;	int     lu, i;	for (lu = 0; lu < OPEN_MAX && _file[lu].valid; lu++);	if (lu == OPEN_MAX) {		errno = EMFILE;		return -1;	}		dname = (char *)fname;	if (strncmp (dname, "/dev/", 5) == 0) {		dname += 5;		i = __try_open(fname, mode, dname, lu, 0);		if (i < 0) {			dname = "disk";			i = __try_open(fname, mode, dname, lu, 0);		}		if (i < 0) {			i = __try_open(fname, mode, NULL, lu, FS_FILE);		}	}	else if (strpat(dname, "*ftp://*")) {		i = __try_open(fname, mode, "net", lu, 0);	}	else if (strpat(dname, "file://*")) {		dname += 6;		i = __try_open(dname, mode, NULL, lu, FS_FILE);	}	else {		i = __try_open(fname, mode, dname, lu, 0);	}	return i;}static int__try_open(const char *fname, int mode, char *dname, int lu, int fstype){	FileSystem *fsp;	SLIST_FOREACH(fsp, &FileSystems, i_next) {		if (dname && strbequ(dname, fsp->devname)) {			if(fsp->open && (*fsp->open)(lu, fname, mode, 0) != lu)				return -1;	/* Error? */			break;		}		else if (fstype != FS_NULL && fsp->fstype == fstype) {			if(fsp->open && (*fsp->open)(lu, fname, mode, 0) == lu)				break;		}	}	if (fsp) {		/* Opened */		_file[lu].valid = 1;		_file[lu].posn = 0;		_file[lu].fs = fsp;		return(lu);	}	else {		errno = ENOENT;		return -1;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -