易截截图软件、单文件、免安装、纯绿色、仅160KB

linux 0.11 内核学习 char_dev.c


/*
 *  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++);


相关文档:

Linux各发行版本 优缺点 简介


 
Linux各发行版本 优缺点 简介
来源: ChinaUnix博客  日期: 2008.01.21 13:43 (共有25条评论) 我要评论
 
Linux最早由Linus Benedict Torvalds在1991年开始编写。在这之前,Richard
Stallman创建了Free Software
Foundation(FSF)组织以及GNU项目,并不断的编写创建GNU程序(此类程序的许可方式均为 ......

linux命令的全称~~~·

转载自:http://www.91linux.com/html/article/go/20090205/15634.html
bin = BINaries (binary)
/dev = devices
/etc = ETCetera
etcetera附加的人, 附加物, 以及其它, 等等
/lib = LIBrary
/proc = PROCesses
/sbin
= Superuser BINaries
/tmp = TeMPorary
/usr = Unix Shared
Resources
/var = ......

linux非阻塞socket教程

        本文并非解释什么是非阻塞socket,也不是介绍socket API的用法, 取而代替的是让你感受实际工作中的代码编写。虽然很简陋,但你可以通过man手册与其它资源非富你的代码。请注意本教程所说的主题,如果细说,内容可以达到一本书内容,你会发现本教程很有用。
本教程内容如下: ......

linux条件变量例程

#include
#include
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
void *thread1(void *);
void *thread2(void *);
int i=1;
main(void)
{
pthread_t t_a;
pthread_t t_b;
pthread_create(&t_a,NULL,thread1,(void *)NULL) ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号