易截截图软件、单文件、免安装、纯绿色、仅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条件变量例程

#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) ......

Linux 内核配置

Linux内核配置办法:
1. make config
这种办法会遍历所有配置项,要求用户逐个选择Y/N/M
2. make menuconfig
这个办法是基于ncurse库编制的图形界面工具。常用
3. make xconfig
用于基于X11的图形工具
4. make gconfig
用于基于gtk+图形工具
5. make defconfig
创建一个默认的配置,生成当前的.config
6. make x ......

linux 0.11 内核学习 truncate.c


/*
 * 该文件主要实现的是truncate函数,该函数是释放指定i 
 * 节点在设备上占用的所有逻辑块,包括直接块、一次间
 * 接块和二次间接块
 */
/*
 *  linux/fs/truncate.c
 *
 *  (C) 1991  Linus Torvalds
 */
#include <linux/sched.h>
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号