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

📄 rd.c

📁 一款类linux的操作系统源码
💻 C
字号:
/*  *  Roadrunner/pk *    Copyright (C) 1989-2001  Cornfed Systems, Inc. * *  The Roadrunner/pk operating system is free software; you can *  redistribute and/or modify it under the terms of the GNU General *  Public License, version 2, as published by the Free Software *  Foundation. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public *  License along with this program; if not, write to the Free *  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, *  MA 02111-1307 USA * *  More information about the Roadrunner/pk operating system of *  which this file is a part is available on the World-Wide Web *  at: http://www.cornfed.com. * */#include <dev.h>#include <dev/rd.h>#include <errno.h>#include <event.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys.h>#include <sys/intr.h>#include <sys/ioctl.h>#include <sys/mutex.h>#include <sys/proc.h>#include <sys/time.h>#define SECTOR_SIZE	         512#define FD_TRACKS		         80#define FD_HEADS		         2#define FD_SECTORS_PER_TRACK	18/*  * This device driver controls a 3 1/2", 1.44 Mbyte floppy disk that is * assumed to be in BIOS drive A: */#define RD_MODE_READ		0#define RD_MODE_WRITE		1/*  * XXX This is really ugly, but it works (TM).  The memory allocator knows * that the fd driver is using this page (fdbuf = 0x1000 assigned later on * in fd_init()) for its dma buffer and won't ever make use of it. */static struct mutex rdmutex;static u_char * rd_addr;intrd_init(){    mutex_clear(&rdmutex);    return 0;}intrd_ioctl(int cmd, void *args){    switch (cmd) {    case LOCK:	return mutex_lock(&rdmutex);    case UNLOCK:	return mutex_unlock(&rdmutex);    case GET_BUFFER_SIZE:	if (args == NULL)	    return EINVAL;	*((u_long *) args) = SECTOR_SIZE;	return 0;    case SEEK_BLOCK:	{	    seek_t seekargs;	    if (args == NULL)		return EINVAL;	    seekargs = (seek_t) args;	    if (seekargs->whence != SEEK_SET)		return ENOSYS;	    //RD_FIRST 在 config.h 中有定义	    rd_addr =(u_char *)(RD_FIRST + seekargs->offset * SECTOR_SIZE); 	    	}	return 0;    default:    break;    }    return ENOTTY;}static intrd_transfer(u_char mode, char *buf){    if (buf == NULL) return EINVAL;    if (mode == RD_MODE_WRITE){	   bcopy(buf, rd_addr, (size_t) SECTOR_SIZE);	   return 0;	}    if (mode == RD_MODE_READ){		bcopy(rd_addr, buf, (size_t) SECTOR_SIZE);	    return 0;	}    	        return ETIMEDOUT;}intrd_read(buf_t * b){    int result;    if (b == NULL || *b == NULL || bsize(*b) < SECTOR_SIZE)	return EINVAL;    if ((result = rd_transfer(RD_MODE_READ, bstart(*b))) == 0) {	blen(*b) = SECTOR_SIZE;	return 0;    }    blen(*b) = 0;    return result;}intrd_write(buf_t * b){    int result;    if (b == NULL || *b == NULL)	return EINVAL;    result = rd_transfer(RD_MODE_WRITE, bstart(*b));    /* Discard buffer */    brel(*b);    *b = NULL;    return result;}intrd_shut(){    return ENOSYS;}

⌨️ 快捷键说明

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