亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? schar.c

?? linux字符設備驅動程序schar 內附makefile
?? C
字號:
/* *	Example of simple character device driver (schar) */#include <linux/module.h>#if defined(CONFIG_SMP)#define __SMP__#endif#if defined(CONFIG_MODVERSIONS)#define MODVERSIONS#include <linux/modversions.h>#endif#include <linux/kernel.h>#include <linux/sched.h>#include <linux/timer.h>	/* for timers */#include <linux/fs.h>		/* file modes and device registration */#include <linux/poll.h>		/* for poll */#include <linux/wrapper.h>	/* mem_map_reserve,mem_map_unreserve */#include <linux/proc_fs.h>#include <linux/sysctl.h>#include <linux/init.h>#include <asm/io.h>#include "schar.h"/* forward declarations for _fops */static ssize_t schar_read(struct file *file, char *buf, size_t count, loff_t *offset);static ssize_t schar_write(struct file *file, const char *buf, size_t count, loff_t *offset);static unsigned int schar_poll(struct file *file, poll_table *wait);static int schar_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg);static int schar_mmap(struct file *file, struct vm_area_struct *vma);static int schar_open(struct inode *inode, struct file *file);static int schar_release(struct inode *inode, struct file *file);static struct file_operations schar_fops = {	NULL,		/* llseek */	schar_read,	schar_write,	NULL,		/* readdir */	schar_poll,	schar_ioctl,	schar_mmap,	schar_open,	NULL,		/* flush */	schar_release,	NULL,		/* fsync */	NULL,		/* fasync */	NULL		/* lock */};/* data */static long schar_pool, schar_data_read, schar_data_written;static char *schar_buffer;/* schar wait queues. kernel newer than 2.3.0 uses a different syntax   for declaring wait queues so check for that. */#if LINUX_VERSION_CODE > 0x20300DECLARE_WAIT_QUEUE_HEAD(schar_wq);DECLARE_WAIT_QUEUE_HEAD(schar_poll_read);#elsestatic struct wait_queue *schar_wq = NULL;static struct wait_queue *schar_poll_read = NULL;#endif/* timer */static struct timer_list schar_timer;static long timer_fires;/* settable parameters */static char *schar_name = NULL;static char schar_debug = 1;static unsigned schar_inc = SCHAR_INC;static unsigned long schar_timer_delay = SCHAR_TIMER_DELAY;static unsigned long schar_pool_min = SCHAR_POOL_MIN;/* sysctl entries */static char schar_proc_string[SCHAR_MAX_SYSCTL];static struct ctl_table_header *schar_root_header = NULL;static int schar_read_proc(ctl_table *ctl, int write, struct file *file,			   void *buffer, size_t *lenp);static ctl_table schar_sysctl_table[] = {	{ DEV_SCHAR_ENTRY,	/* binary id */	  "0",			/* name */	  &schar_proc_string,	/* data */	  SCHAR_MAX_SYSCTL,	/* max size of output */	  0644,			/* mode */	  0,			/* child - none */	  &schar_read_proc },	/* set up text */	{ 0 }};static ctl_table schar_dir[] = {	{ DEV_SCHAR,		/* /proc/dev/schar */	  "schar",		/* name */	  NULL,	  0,	  0555,	  schar_sysctl_table },	/* the child */	{ 0 }};static ctl_table schar_root_dir[] = {	{ CTL_DEV,		/* /proc/dev */	  "dev",		/* name */	  NULL,	  0,	  0555,	  schar_dir },		/* the child */	{ 0 }};/* module parameters and descriptions */MODULE_PARM(schar_name, "s");MODULE_PARM_DESC(schar_name, "Name of device");MODULE_PARM(schar_debug, "1b");MODULE_PARM_DESC(schar_debug, "Enable debugging messages");MODULE_PARM(schar_inc, "1i");MODULE_PARM_DESC(schar_inc, "Byte increase in pool per timer fire");MODULE_PARM(schar_timer_delay, "1l");MODULE_PARM_DESC(schar_timer_delay, "Timer ticks between timer fire");MODULE_PARM(schar_pool_min, "1l");MODULE_PARM_DESC(schar_pool_min, "Timer fill pool minimum in bytes");MODULE_DESCRIPTION("schar, Sample character driver");MODULE_AUTHOR("Jens Axboe");static void schar_timer_handler(unsigned long data){	timer_fires++;	/* setup timer again */	if (schar_pool < schar_pool_min) {		schar_pool += SCHAR_INC;		schar_timer.expires = jiffies + schar_timer_delay;		schar_timer.function = &schar_timer_handler;		add_timer(&schar_timer);		MSG("setting timer up again, %ld data now\n", schar_pool);	}	/* if the module is in use, we most likely has a reader waiting for	   data. wake up any processes that are waiting for data. */	if (MOD_IN_USE && schar_pool > 0) {		wake_up_interruptible(&schar_wq);		wake_up_interruptible(&schar_poll_read);	}		return;}static int schar_mmap(struct file *file, struct vm_area_struct *vma){	unsigned long size;	/* mmap flags - could be read and write, also */	MSG("mmap: %s\n", vma->vm_flags & VM_WRITE ? "write" : "read");		/* we will not accept an offset into the page */	if(vma->vm_offset != 0) {		MSG("mmap: offset must be 0\n");		return -EINVAL;	}			/* schar_buffer is only one page */	size = vma->vm_end - vma->vm_start;	if (size != PAGE_SIZE) {		MSG("mmap: wanted %lu, but PAGE_SIZE is %lu\n", size, PAGE_SIZE);		return -EINVAL;	}		/* remap user buffer */	if (remap_page_range(vma->vm_start, virt_to_phys(schar_buffer), size,			     vma->vm_page_prot))		return -EAGAIN;			return 0;}static int schar_ioctl(struct inode *inode, struct file *file,		       unsigned int cmd, unsigned long arg){	/* make sure that the command is really one of schar's */	if (_IOC_TYPE(cmd) != SCHAR_IOCTL_BASE)		return -ENOTTY;			switch (cmd) {		case SCHAR_TOGGLE_DEBUG: {			schar_debug = !schar_debug;			return 0;		}		case SCHAR_GET_POOL: {			if (put_user(schar_pool, (unsigned long *)arg))				return -EFAULT;			break;		}		case SCHAR_GET_TIMER_FIRES: {			if (put_user(timer_fires, (unsigned long *)arg))				return -EFAULT;			break;		}						case SCHAR_GET_READ: {			if (put_user(schar_data_read, (unsigned long *)arg))				return -EFAULT;			break;		}		case SCHAR_GET_WRITTEN: {			if (put_user(schar_data_read, (unsigned long *)arg))				return -EFAULT;			break;		}		case SCHAR_EX_TIMER_DELAY: {			unsigned long tmp = schar_timer_delay;			if (!capable(CAP_SYS_ADMIN))				return -EACCES;			if (get_user(schar_timer_delay, (unsigned long *)arg))				return -EFAULT;			if (put_user(tmp, (unsigned long *)arg))				return -EFAULT;			break;		}		case SCHAR_EX_POOL_MIN: {			unsigned long tmp = schar_pool_min;			if (get_user(schar_pool_min, (unsigned long *)arg))				return -EFAULT;			if (put_user(tmp, (unsigned long *)arg))				return -EFAULT;			break;		}		case SCHAR_EX_TIMER_INC: {			unsigned tmp = schar_inc;			if (get_user(schar_inc, (unsigned *)arg))				return -EFAULT;			if (put_user(tmp, (unsigned*)arg))				return -EFAULT;			break;		}				default: {			MSG("ioctl: no such command\n");			return -ENOTTY;		}	}	/* to keep gcc happy */	return 0;}static int schar_read_proc(ctl_table *ctl, int write, struct file *file,			   void *buffer, size_t *lenp){	int len = 0;		MSG("proc: %s\n", write ? "write" : "read");	/* someone is writing data to us */	if (write) {		char *tmp = (char *) get_free_page(GFP_KERNEL);		MSG("proc: someone wrote %u bytes\n", (unsigned)*lenp);		if (tmp) {			if (!copy_from_user(tmp, buffer, *lenp))				MSG("proc: %s", tmp);			free_page((unsigned long)tmp);			file->f_pos += *lenp;		}		return 0;	}		len += sprintf(schar_proc_string, "schar\n\n");	len += sprintf(schar_proc_string+len, "schar_pool\t\t\t%ld\n",						schar_pool);	len += sprintf(schar_proc_string+len, "data read\t\t\t%ld\n",						schar_data_read);	len += sprintf(schar_proc_string+len, "data written\t\t\t%ld\n",						schar_data_written);	len += sprintf(schar_proc_string+len, "timer fired\t\t\t%ld times\n",						timer_fires);	len += sprintf(schar_proc_string+len, "\nchangable parameters:\n\n");	len += sprintf(schar_proc_string+len, "debugging %sabled\n",						schar_debug ? "en" : "dis");	len += sprintf(schar_proc_string+len, "bytes increase for timer\t%u\n",						schar_inc);	len += sprintf(schar_proc_string+len, "timer delay\t\t\t%lu\n",						schar_timer_delay);	len += sprintf(schar_proc_string+len, "pool byte minimum\t\t%lu\n",						schar_pool_min);		*lenp = len;	return proc_dostring(ctl, write, file, buffer, lenp);		}/* increment and decrement usage count when someone is accessing   /proc/sys/dev/schar */static void schar_fill_inode(struct inode *inode, int fill){	if (fill) {		MOD_INC_USE_COUNT;	} else {		MOD_DEC_USE_COUNT;	}}static ssize_t schar_read(struct file *file, char *buf, size_t count,			  loff_t *offset){	/* if less data than requested is here, put reading process to sleep */	while (count > schar_pool) {		/* if the device is opened non blocking satisfy what we		   can of the request and don't put the process to sleep. */		if (file->f_flags & O_NONBLOCK) {			if (schar_pool > 0) {				file->f_pos += schar_pool;				schar_data_read += file->f_pos;				if(copy_to_user(buf, schar_buffer, schar_pool))					return -EFAULT;				count = schar_pool;				schar_pool = 0;				return count;			} else {				return -EAGAIN;			}		}					MSG("putting process with pid %u to sleep\n", current->pid);		/* go to sleep, but wake up on signals */		interruptible_sleep_on(&schar_wq);		if (signal_pending(current)) {			MSG("pid %u got signal\n", (unsigned)current->pid);			/* tell vfs about the signal */			return -EINTR;		}	}	/* copy the data the our buffer */	if (copy_to_user(buf, schar_buffer, count))		return -EFAULT;	schar_pool -= count;	schar_data_read += count;	MSG("want to read %u bytes, %ld bytes in queue\n", (unsigned)count,							    schar_pool);		/* return data written */	file->f_pos += count;	return count;}static ssize_t schar_write(struct file *file, const char *buf, size_t count,			   loff_t *offset){	schar_pool += count;	schar_data_written += count;	/* if we were really writing - modify the file position to	    reflect the amount of data written */	file->f_pos += count;	if (copy_from_user(schar_buffer, buf, count))		return -EFAULT;		/* wake up reading processes, if any */	if (schar_pool > 0) {		wake_up_interruptible(&schar_wq);		wake_up_interruptible(&schar_poll_read);	}		MSG("trying to write %u bytes, %ld bytes in queue now\n",					(unsigned)count, schar_pool);	/* return data written */	return count;}static unsigned int schar_poll(struct file *file, poll_table * wait){	unsigned int mask = 0;	poll_wait(file, &schar_poll_read, wait);		/* if the pool contains data, a read will succeed */	if (schar_pool > 0)		mask |= POLLIN | POLLRDNORM;			/* a write always succeeds */	mask |= POLLOUT | POLLWRNORM;		return mask;}static int schar_open(struct inode *inode, struct file *file){	/* increment usage count */	MOD_INC_USE_COUNT;		if (file->f_mode & FMODE_READ) {		MSG("opened for reading\n");		/* we have a reader, set up the timer if it isn't set */		if (!timer_pending(&schar_timer)) {			schar_timer.function = &schar_timer_handler;			mod_timer(&schar_timer, SCHAR_TIMER_DELAY);		}	} else if (file->f_mode & FMODE_WRITE) {		MSG("opened for writing \n");	}	MSG("major: %d minor: %d\n", MAJOR(inode->i_rdev), MINOR(inode->i_rdev));	return 0;}static int schar_release(struct inode *inode, struct file *file){	MOD_DEC_USE_COUNT;	MSG("schar_release\n");	return 0;}int init_module(void){	int res;		if (schar_name == NULL)		schar_name = "schar";			/* get a free page */	schar_buffer = (char *) __get_free_page(GFP_KERNEL);	if (schar_buffer == NULL)		return -ENOMEM;	/* reserve the page and fill it with garbage */	mem_map_reserve(MAP_NR(schar_buffer));	memset(schar_buffer, 0x59, PAGE_SIZE);		/* register device with kernel */	res = register_chrdev(SCHAR_MAJOR, schar_name, &schar_fops);	if (res) {		MSG("can't register device with kernel\n");		return res;	}		/* register proc entry */	schar_root_header = register_sysctl_table(schar_root_dir, 0);	schar_root_dir->child->de->fill_inode = &schar_fill_inode;		/* init statistics vars */	timer_fires = schar_pool = schar_data_read = schar_data_written = 0;		/* initialize timer */	init_timer(&schar_timer);		/* all done */		MSG("module loaded\n");	return 0;}void cleanup_module(void){	/* unregister device and proc entry */	unregister_chrdev(SCHAR_MAJOR, "schar");	if (schar_root_header)		unregister_sysctl_table(schar_root_header);		/* unreserve page and free it */	mem_map_unreserve(MAP_NR(schar_buffer));	free_page((unsigned long) schar_buffer);	if (timer_pending(&schar_timer))		del_timer(&schar_timer);		MSG("unloaded\n");	return;}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美美女喷水视频| 亚洲一区自拍偷拍| 精品美女一区二区| 欧美一级黄色片| 欧美福利视频导航| 5858s免费视频成人| 欧美老女人第四色| 在线播放一区二区三区| 欧美疯狂做受xxxx富婆| 欧美一区二区三区视频在线观看| 欧美揉bbbbb揉bbbbb| 欧美美女喷水视频| 欧美刺激午夜性久久久久久久| 欧美一二三区精品| 久久人人爽爽爽人久久久| 久久综合九色综合97婷婷女人 | 成人一区在线观看| av高清久久久| 欧美在线高清视频| 91精品国产91热久久久做人人 | 日韩av电影免费观看高清完整版| 日韩黄色在线观看| 精品一区二区三区日韩| 国产91对白在线观看九色| 99视频一区二区| 欧美色男人天堂| 精品成人一区二区三区四区| 久久精品夜夜夜夜久久| 最新国产成人在线观看| 亚洲国产成人av好男人在线观看| 三级一区在线视频先锋| 国内精品伊人久久久久av一坑| 成人免费高清视频| 在线免费不卡电影| 日韩美女主播在线视频一区二区三区| 亚洲成人中文在线| 国产女人18毛片水真多成人如厕| 国产喷白浆一区二区三区| 亚洲婷婷综合色高清在线| 亚洲国产日韩a在线播放性色| 五月天中文字幕一区二区| 九九热在线视频观看这里只有精品| 国产成都精品91一区二区三| 色综合色综合色综合 | 亚洲精品乱码久久久久久黑人 | 日韩高清在线观看| 国产99一区视频免费| 91久久精品日日躁夜夜躁欧美| 欧美一区二区三区在| 欧美激情一二三区| 日韩中文字幕av电影| 国产老肥熟一区二区三区| 91无套直看片红桃| 日韩欧美国产三级电影视频| 国产精品国产三级国产| 日韩国产精品91| caoporm超碰国产精品| 欧美日韩在线播放三区| 国产欧美日韩精品在线| 香蕉久久夜色精品国产使用方法| 国产二区国产一区在线观看| 777久久久精品| 亚洲欧美偷拍三级| 国产夫妻精品视频| 日韩午夜精品电影| 亚洲影视在线播放| 粉嫩aⅴ一区二区三区四区| 欧美一二三区在线| 亚洲午夜久久久久久久久久久| 国产成人欧美日韩在线电影| 欧美日韩精品欧美日韩精品一综合| 中文字幕一区av| 国产麻豆一精品一av一免费| 欧美精品日韩一本| 一区二区三区中文字幕| 成人av在线电影| 久久久久久久久久美女| 日本网站在线观看一区二区三区| 色婷婷亚洲一区二区三区| 欧美极品aⅴ影院| 九九**精品视频免费播放| 欧美日韩综合在线免费观看| 一区二区三区在线视频播放| eeuss影院一区二区三区| 日本一区二区三区在线观看| 美国三级日本三级久久99| 欧美精品vⅰdeose4hd| 亚洲精品久久7777| 91丨国产丨九色丨pron| 国产精品欧美久久久久一区二区 | 日韩欧美一区二区三区在线| 亚洲午夜一区二区三区| 在线免费一区三区| 一片黄亚洲嫩模| 91麻豆产精品久久久久久| 国产精品的网站| 不卡视频在线观看| 国产精品久久久久婷婷二区次| 国产精品羞羞答答xxdd| 久久婷婷色综合| 国产成人免费视频精品含羞草妖精| 欧美成人三级在线| 韩日精品视频一区| 久久女同性恋中文字幕| 国产一区二区三区精品视频| 精品福利av导航| 激情欧美一区二区| 久久精品一区四区| 国产成人激情av| 国产精品传媒入口麻豆| 色综合久久久久综合体| 亚洲免费资源在线播放| 欧美三区在线观看| 奇米888四色在线精品| 精品人伦一区二区色婷婷| 国内不卡的二区三区中文字幕| xf在线a精品一区二区视频网站| 国产成人精品一区二| 国产精品理伦片| 色婷婷久久久亚洲一区二区三区| 亚洲成人动漫一区| 欧美va亚洲va| 成人精品视频网站| 亚洲欧美电影一区二区| 欧美日韩一区不卡| 久久99蜜桃精品| 国产日本欧洲亚洲| 色丁香久综合在线久综合在线观看| 亚洲午夜久久久久久久久电影网| 3d成人h动漫网站入口| 国产成人在线色| 亚洲精品欧美激情| 日韩欧美一区在线| 成人动漫在线一区| 亚洲尤物视频在线| 日韩精品一区二区三区在线观看| 国产精品一区在线观看乱码 | 国产成人一区在线| 亚洲女爱视频在线| 日韩视频一区二区三区在线播放| 成人免费视频视频| 亚洲成av人影院| 国产日韩三级在线| 欧美性淫爽ww久久久久无| 九九久久精品视频| 亚洲黄色性网站| 精品理论电影在线| 色婷婷av一区二区三区软件| 久久精品国产99久久6| 亚洲青青青在线视频| 日韩写真欧美这视频| 91丨九色丨黑人外教| 麻豆国产欧美一区二区三区| 亚洲欧美综合色| 日韩欧美成人一区| 色婷婷激情久久| 国产精品一区二区91| 亚洲成av人片在线| 中文一区二区完整视频在线观看| 欧美日韩国产123区| 国产成人在线视频网站| 日韩电影在线观看一区| 中文字幕一区二| 久久综合久久综合九色| 欧美剧情片在线观看| 99精品一区二区| 九色综合国产一区二区三区| 亚洲午夜成aⅴ人片| 国产精品久久久久aaaa樱花| 日韩欧美一二三四区| 欧美色倩网站大全免费| 99re8在线精品视频免费播放| 精油按摩中文字幕久久| 午夜久久电影网| 亚洲免费视频中文字幕| 欧美高清在线一区| 久久久亚洲综合| 91精品国产丝袜白色高跟鞋| 欧美在线你懂的| 91麻豆蜜桃一区二区三区| 成人午夜大片免费观看| 久久99精品一区二区三区三区| 亚洲福利电影网| 亚洲激情图片小说视频| 国产精品的网站| 国产精品久久久久四虎| 久久精品视频网| 精品久久久网站| 欧美一级片在线| 欧美肥胖老妇做爰| 在线观看不卡一区| 在线观看一区二区视频| 色呦呦一区二区三区| 99re热这里只有精品免费视频| 国产成人免费视频网站| 高潮精品一区videoshd| 国产一区 二区| 国产成人在线色| 福利电影一区二区| 国产69精品久久99不卡|