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

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

?? schar.c

?? linux程序設計(第三版)隨書附帶示例
?? 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 = {	read:		schar_read,	write:		schar_write,	poll:		schar_poll,	ioctl:		schar_ioctl,	mmap:		schar_mmap,	open:		schar_open,	release:	schar_release,};/* 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");/* This keeps us from having the "taint" flag *//* Besides, the GPL is a good thing */MODULE_LICENSE("GPL");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_pgoff != 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);		}#if 0/* 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;	}}#endifstatic 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;	struct page *page;		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;	page = virt_to_page(schar_buffer);	/* reserve the page and fill it with garbage */	mem_map_reserve(page);	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/sys/dev entry */	schar_root_header = register_sysctl_table(schar_root_dir, 0);#if 0	schar_root_dir->child->de->fill_inode = &schar_fill_inode;#endif /*WKP... If this does nothing useful, don't try to update it. */		/* 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){	struct page *page;	/* 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 */	page = virt_to_page(schar_buffer);	mem_map_unreserve(page);	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一区二区三区免费野_久草精品视频
亚洲一区二区三区影院| 欧美在线观看18| 日韩视频在线你懂得| 亚洲成人免费看| 91麻豆视频网站| 国产精品久久久久9999吃药| 精品一区二区三区视频 | 成人一区二区三区在线观看| 成人免费视频视频| 亚洲国产精品精华液ab| 大美女一区二区三区| 国产欧美日韩综合| 99久久婷婷国产综合精品电影 | 99精品久久只有精品| 国产精品成人午夜| 色欧美乱欧美15图片| 亚洲美女免费在线| 欧美日韩国产首页在线观看| 日韩电影免费一区| 日韩美女一区二区三区| 久久66热re国产| 精品欧美黑人一区二区三区| 丝袜国产日韩另类美女| 欧美人狂配大交3d怪物一区| 午夜精品久久久久久| 福利一区二区在线| 风间由美一区二区三区在线观看| 99久久精品国产一区二区三区| 中文字幕字幕中文在线中不卡视频| a美女胸又www黄视频久久| 亚洲婷婷综合久久一本伊一区| 色婷婷激情一区二区三区| 一区二区三区日韩欧美| 日韩视频免费直播| 国产精品一区二区在线播放| 精品国产免费久久| 色哟哟日韩精品| 毛片av中文字幕一区二区| 国产欧美日韩中文久久| 欧美色图激情小说| 国产馆精品极品| 亚洲国产婷婷综合在线精品| 91精品国产一区二区| 成人少妇影院yyyy| 五月婷婷久久丁香| 久久久一区二区三区捆绑**| 91老师片黄在线观看| 日本成人在线不卡视频| 中文字幕乱码久久午夜不卡| 在线成人小视频| 丁香婷婷深情五月亚洲| 亚洲免费资源在线播放| 精品福利av导航| 91精品福利视频| 精品一区二区三区蜜桃| 中文字幕高清一区| 日韩一二三区视频| 色综合天天综合色综合av | 国产精品一区二区你懂的| 偷拍一区二区三区四区| 亚洲精品v日韩精品| 中文字幕国产一区二区| 久久精品夜色噜噜亚洲aⅴ| 日韩无一区二区| 91麻豆精品国产91久久久久| 欧美性三三影院| 欧美在线一区二区| 色视频一区二区| 日韩制服丝袜先锋影音| 亚洲国产日韩在线一区模特| 一区二区视频在线| 亚洲品质自拍视频| 亚洲四区在线观看| 亚洲男人天堂av| 亚洲男人的天堂网| 一区二区三区精密机械公司| 亚洲欧美偷拍另类a∨色屁股| 中文字幕va一区二区三区| 中文无字幕一区二区三区| 国产精品污www在线观看| 国产欧美精品区一区二区三区 | 99久久婷婷国产综合精品| 成人爽a毛片一区二区免费| 粉嫩av亚洲一区二区图片| 成人手机电影网| 一本久道久久综合中文字幕 | 国产精品国产馆在线真实露脸| 中文字幕精品综合| 亚洲品质自拍视频| 亚洲电影中文字幕在线观看| 香蕉成人伊视频在线观看| 日韩成人一级大片| 精品一区二区免费| 成人黄色小视频在线观看| 91色在线porny| 欧美亚洲综合色| 91精品在线观看入口| 精品国产百合女同互慰| 国产精品色在线观看| 亚洲色图.com| 日韩精品免费专区| 国产一区二区导航在线播放| av在线这里只有精品| 欧美中文字幕不卡| 日韩欧美资源站| 国产精品色在线| 亚洲.国产.中文慕字在线| 久久国产精品一区二区| 波多野结衣中文字幕一区二区三区| 在线观看亚洲精品视频| 欧美成人欧美edvon| 国产精品久久久久久久久晋中| 亚洲一区二区成人在线观看| 久久精品99国产精品| 成人黄色av网站在线| 欧美性高清videossexo| 欧美精品一区二区在线播放| 亚洲美女淫视频| 国产在线国偷精品产拍免费yy| 91丨九色丨国产丨porny| 日韩精品一区国产麻豆| 亚洲男帅同性gay1069| 国内久久婷婷综合| 欧美三级欧美一级| 亚洲一区二区偷拍精品| 激情欧美一区二区三区在线观看| 99免费精品视频| 欧美成人一区二区三区片免费| 国产精品理论片在线观看| 日一区二区三区| 91女厕偷拍女厕偷拍高清| 亚洲精品在线观| 日韩精品一级二级 | 中文字幕av一区二区三区免费看| 午夜视频在线观看一区二区三区| 国产精品69毛片高清亚洲| 欧美三级在线播放| 国产午夜精品一区二区三区四区| 天天综合网 天天综合色| 91丨九色porny丨蝌蚪| www久久精品| 午夜久久久影院| 色天使色偷偷av一区二区| 中文字幕乱码亚洲精品一区| 伦理电影国产精品| 精品视频一区二区三区免费| 亚洲欧洲成人精品av97| 国产成人高清视频| 久久网这里都是精品| 麻豆91小视频| 欧美一区午夜视频在线观看| 亚洲主播在线观看| 91年精品国产| 亚洲精品视频免费看| 92精品国产成人观看免费| 国产精品久久久久9999吃药| 国产suv精品一区二区883| 2欧美一区二区三区在线观看视频 337p粉嫩大胆噜噜噜噜噜91av | 欧美剧在线免费观看网站 | 91片黄在线观看| 中文字幕一区不卡| 99久久精品一区二区| 亚洲国产电影在线观看| 粉嫩绯色av一区二区在线观看| 久久久99久久| 国产成人午夜电影网| 中文字幕第一区| 不卡电影一区二区三区| 亚洲欧美日韩中文播放| 日本福利一区二区| 亚洲制服丝袜在线| 欧美精选午夜久久久乱码6080| 日本视频在线一区| 日韩一区二区三区免费观看| 蓝色福利精品导航| 国产视频一区二区三区在线观看| 国产精品正在播放| 亚洲天堂精品视频| 欧美午夜宅男影院| 日韩和欧美一区二区三区| 日韩欧美在线影院| 国产乱人伦精品一区二区在线观看| 久久天天做天天爱综合色| 成人av午夜电影| 亚洲乱码日产精品bd| 欧美日韩黄色一区二区| 美女一区二区在线观看| 久久精品网站免费观看| 99精品桃花视频在线观看| 亚洲妇熟xx妇色黄| 精品三级在线观看| 成人黄色免费短视频| 亚洲一区二区三区不卡国产欧美| 91精品国产品国语在线不卡| 国产一区二区三区四| 亚洲欧美综合网| 欧美一区二区成人| 丁香天五香天堂综合| 99久久精品国产网站| 91视视频在线观看入口直接观看www|