/*
* linux/fs/char_dev.c
*
* (C) 1991 Linus Torvalds
*/
#include <errno.h>
#include <sys/types.h> // ¶¨ÒåÁË»ù±¾µÄϵͳÊý¾ÝÀàÐÍ
#include <linux/sched.h>
#include <linux/kernel.h> // º¬ÓÐһЩÄں˳£Óú¯ÊýµÄÔÐζ¨Òå
#include <asm/segment.h>
#include <asm/io.h>
/* Öж϶Á */
extern int tty_read(unsigned minor,char * buf,int count);
/* ÖжÏд */
extern int tty_write(unsigned minor,char * buf,int count);
/* ¶¨Òå×Ö·ûÉ豸¶Áдº¯ÊýÖ¸ÕëÀàÐÍ */
typedef (*crw_ptr)(int rw,unsigned minor,char * buf,int count,off_t * pos);
/* ´®¿ÚÖն˶Áд²Ù×÷º¯Êý¡£²ÎÊý £º rw¶ÁдÃüÁminorÖжÏ×ÓÉ豸ºÅ£¬buf»º³åÇø */
/* count¶ÁдµÄ×Ö½ÚÊý£¬pos¶Áд²Ù×÷µ±Ç°Ö¸Õ룬·µ»Øʵ¼Ê¶ÁдµÄ×Ö½ÚÊý */
static int rw_ttyx(int rw,unsigned minor,char * buf,int count,off_t * pos)
{
return ((rw==READ)?tty_read(minor,buf,count):
tty_write(minor,buf,count));
}
/* Öն˶Áд²Ù×÷º¯Êý£¬Ö»ÊÇÔö¼ÓÁ˶Խø³ÌÊÇ·ñÓпØÖÆÖն˵ļì²â */
static int rw_tty(int rw,unsigned minor,char * buf,int count, off_t * pos)
{
// Èô½ø³ÌûÓжÔÓ¦µÄ¿ØÖÆÖնˣ¬Ôò·µ»Ø³ö´íºÅ
if (current->tty<0)
return -EPERM;
return rw_ttyx(rw,current->tty,buf,count,pos);
}
/* ÄÚ´æÊý¾Ý¶Áдº¯Êý£¬»¹Ã»ÊµÏÖ */
static int rw_ram(int rw,char * buf, int count, off_t *pos)
{
return -EIO;
}
/* ÄÚ´æÊý¾Ý¶Áд²Ù×÷º¯Êý¡£Î´ÊµÏÖ */
static int rw_mem(int rw,char * buf, int count, off_t * pos)
{
return -EIO;
}
/* ÄÚºËÊý¾ÝÇø¶Áдº¯Êý¡£Î´ÊµÏÖ */
static int rw_kmem(int rw,char * buf, int count, off_t * pos)
{
return -EIO;
}
/* ¶Ë¿Ú¶Áд²Ù×÷º¯Êý£¬²ÎÊý £º rw¶ÁдÃüÁbuf»º³åÇø£¬count¶Áд×Ö½ÚÊý£¬pos */
/* ¶Ë¿ÚµØÖ·£¬·µ»ØµÄÊÇʵ¼Ê¶ÁдµÄ×Ö½ÚÊý */
static int rw_port(int rw,char * buf, int count, off_t * pos)
{
int i=*pos; // ¶Ë¿ÚµØÖ·
// ¶ÔÓÚËùÒªÇó¶ÁдµÄ×Ö½ÚÊý£¬²¢ÇҶ˿ڵØַСÓÚ64k
while (count-->0 && i<65536)
{
// ÈôÊǶÁÃüÁÔò´Ó¶Ë¿Úi ÖжÁÈ¡Ò»×Ö½ÚÄÚÈݲ¢·Åµ½Óû§»º³åÇøÖÐ
if (rw==READ)
put_fs_byte(inb(i),buf++);
1. LinusºÍBill
ËƺõÔÚÒ»Ò¹Ö®¼ä£¬Õâ¸öÃû×ÖͻȻ±äµÃͬÏó±È¶û¡£¸Ç´ÄÒ»ÑùµÄ¶úÊìÄÜÏê¡£µ«ÊDZȶû¡£¸Ç´Ä£¬ÄÄÅÂÉí¼ÛÓÐÊý²»Ç屶µÄ°ÙÍòÃÀ½ð£¬Ò²ÓÀÔ¶²»»á±ä³ÉLinux Torvalds¡£Õâλ29ËêµÄ·ÒÀ¼ÈË£¬¼òµ¥¶øÇ¿´óµÄLinux²Ù×÷ϵͳµÄ´´ÔìÕߣ¬³¬Ô½Á˸ǴĵÄÉñ»°¡£Ò²Óд«ÎÅ˵¸Ç´ÄÊÇÒ»¸ö׿ԽµÄ³ÌÐòÔ±£¬µ«LinusÊÇ»õÕæ¼ÛʵµÄ¸ßÊ ......