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

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

?? main.c

?? Linux設備驅動的經典教材, 該電子書是第三版,并附有全部配套代碼.
?? C
字號:
/* -*- C -*- * main.c -- the bare scullv char module * * Copyright (C) 2001 Alessandro Rubini and Jonathan Corbet * Copyright (C) 2001 O'Reilly & Associates * * The source code in this file can be freely used, adapted, * and redistributed in source or binary form, so long as an * acknowledgment appears in derived source files.  The citation * should list that the code comes from the book "Linux Device * Drivers" by Alessandro Rubini and Jonathan Corbet, published * by O'Reilly & Associates.   No warranty is attached; * we cannot take responsibility for errors or fitness for use. * * $Id: _main.c.in,v 1.21 2004/10/14 20:11:39 corbet Exp $ */#include <linux/config.h>#include <linux/module.h>#include <linux/moduleparam.h>#include <linux/init.h>#include <linux/kernel.h>	/* printk() */#include <linux/slab.h>		/* kmalloc() */#include <linux/fs.h>		/* everything... */#include <linux/errno.h>	/* error codes */#include <linux/types.h>	/* size_t */#include <linux/proc_fs.h>#include <linux/fcntl.h>	/* O_ACCMODE */#include <linux/aio.h>#include <asm/uaccess.h>#include <linux/vmalloc.h>#include "scullv.h"		/* local definitions */int scullv_major =   SCULLV_MAJOR;int scullv_devs =    SCULLV_DEVS;	/* number of bare scullv devices */int scullv_qset =    SCULLV_QSET;int scullv_order =   SCULLV_ORDER;module_param(scullv_major, int, 0);module_param(scullv_devs, int, 0);module_param(scullv_qset, int, 0);module_param(scullv_order, int, 0);MODULE_AUTHOR("Alessandro Rubini");MODULE_LICENSE("Dual BSD/GPL");struct scullv_dev *scullv_devices; /* allocated in scullv_init */int scullv_trim(struct scullv_dev *dev);void scullv_cleanup(void);#ifdef SCULLV_USE_PROC /* don't waste space if unused *//* * The proc filesystem: function to read and entry */void scullv_proc_offset(char *buf, char **start, off_t *offset, int *len){	if (*offset == 0)		return;	if (*offset >= *len) {		/* Not there yet */		*offset -= *len;		*len = 0;	} else {		/* We're into the interesting stuff now */		*start = buf + *offset;		*offset = 0;	}}/* FIXME: Do we need this here??  It be ugly  */int scullv_read_procmem(char *buf, char **start, off_t offset,                   int count, int *eof, void *data){	int i, j, order, qset, len = 0;	int limit = count - 80; /* Don't print more than this */	struct scullv_dev *d;	*start = buf;	for(i = 0; i < scullv_devs; i++) {		d = &scullv_devices[i];		if (down_interruptible (&d->sem))			return -ERESTARTSYS;		qset = d->qset;  /* retrieve the features of each device */		order = d->order;		len += sprintf(buf+len,"\nDevice %i: qset %i, order %i, sz %li\n",				i, qset, order, (long)(d->size));		for (; d; d = d->next) { /* scan the list */			len += sprintf(buf+len,"  item at %p, qset at %p\n",d,d->data);			scullv_proc_offset (buf, start, &offset, &len);			if (len > limit)				goto out;			if (d->data && !d->next) /* dump only the last item - save space */				for (j = 0; j < qset; j++) {					if (d->data[j])						len += sprintf(buf+len,"    % 4i:%8p\n",j,d->data[j]);					scullv_proc_offset (buf, start, &offset, &len);					if (len > limit)						goto out;				}		}	  out:		up (&scullv_devices[i].sem);		if (len > limit)			break;	}	*eof = 1;	return len;}#endif /* SCULLV_USE_PROC *//* * Open and close */int scullv_open (struct inode *inode, struct file *filp){	struct scullv_dev *dev; /* device information */	/*  Find the device */	dev = container_of(inode->i_cdev, struct scullv_dev, cdev);    	/* now trim to 0 the length of the device if open was write-only */	if ( (filp->f_flags & O_ACCMODE) == O_WRONLY) {		if (down_interruptible (&dev->sem))			return -ERESTARTSYS;		scullv_trim(dev); /* ignore errors */		up (&dev->sem);	}	/* and use filp->private_data to point to the device data */	filp->private_data = dev;	return 0;          /* success */}int scullv_release (struct inode *inode, struct file *filp){	return 0;}/* * Follow the list  */struct scullv_dev *scullv_follow(struct scullv_dev *dev, int n){	while (n--) {		if (!dev->next) {			dev->next = kmalloc(sizeof(struct scullv_dev), GFP_KERNEL);			memset(dev->next, 0, sizeof(struct scullv_dev));		}		dev = dev->next;		continue;	}	return dev;}/* * Data management: read and write */ssize_t scullv_read (struct file *filp, char __user *buf, size_t count,                loff_t *f_pos){	struct scullv_dev *dev = filp->private_data; /* the first listitem */	struct scullv_dev *dptr;	int quantum = PAGE_SIZE << dev->order;	int qset = dev->qset;	int itemsize = quantum * qset; /* how many bytes in the listitem */	int item, s_pos, q_pos, rest;	ssize_t retval = 0;	if (down_interruptible (&dev->sem))		return -ERESTARTSYS;	if (*f_pos > dev->size) 		goto nothing;	if (*f_pos + count > dev->size)		count = dev->size - *f_pos;	/* find listitem, qset index, and offset in the quantum */	item = ((long) *f_pos) / itemsize;	rest = ((long) *f_pos) % itemsize;	s_pos = rest / quantum; q_pos = rest % quantum;    	/* follow the list up to the right position (defined elsewhere) */	dptr = scullv_follow(dev, item);	if (!dptr->data)		goto nothing; /* don't fill holes */	if (!dptr->data[s_pos])		goto nothing;	if (count > quantum - q_pos)		count = quantum - q_pos; /* read only up to the end of this quantum */	if (copy_to_user (buf, dptr->data[s_pos]+q_pos, count)) {		retval = -EFAULT;		goto nothing;	}	up (&dev->sem);	*f_pos += count;	return count;  nothing:	up (&dev->sem);	return retval;}ssize_t scullv_write (struct file *filp, const char __user *buf, size_t count,                loff_t *f_pos){	struct scullv_dev *dev = filp->private_data;	struct scullv_dev *dptr;	int quantum = PAGE_SIZE << dev->order;	int qset = dev->qset;	int itemsize = quantum * qset;	int item, s_pos, q_pos, rest;	ssize_t retval = -ENOMEM; /* our most likely error */	if (down_interruptible (&dev->sem))		return -ERESTARTSYS;	/* find listitem, qset index and offset in the quantum */	item = ((long) *f_pos) / itemsize;	rest = ((long) *f_pos) % itemsize;	s_pos = rest / quantum; q_pos = rest % quantum;	/* follow the list up to the right position */	dptr = scullv_follow(dev, item);	if (!dptr->data) {		dptr->data = kmalloc(qset * sizeof(void *), GFP_KERNEL);		if (!dptr->data)			goto nomem;		memset(dptr->data, 0, qset * sizeof(char *));	}	/* Allocate a quantum using virtual addresses */	if (!dptr->data[s_pos]) {		dptr->data[s_pos] = (void *)vmalloc(PAGE_SIZE << dptr->order);		if (!dptr->data[s_pos])			goto nomem;		memset(dptr->data[s_pos], 0, PAGE_SIZE << dptr->order);	}	if (count > quantum - q_pos)		count = quantum - q_pos; /* write only up to the end of this quantum */	if (copy_from_user (dptr->data[s_pos]+q_pos, buf, count)) {		retval = -EFAULT;		goto nomem;	}	*f_pos += count;     	/* update the size */	if (dev->size < *f_pos)		dev->size = *f_pos;	up (&dev->sem);	return count;  nomem:	up (&dev->sem);	return retval;}/* * The ioctl() implementation */int scullv_ioctl (struct inode *inode, struct file *filp,                 unsigned int cmd, unsigned long arg){	int err = 0, ret = 0, tmp;	/* don't even decode wrong cmds: better returning  ENOTTY than EFAULT */	if (_IOC_TYPE(cmd) != SCULLV_IOC_MAGIC) return -ENOTTY;	if (_IOC_NR(cmd) > SCULLV_IOC_MAXNR) return -ENOTTY;	/*	 * the type is a bitmask, and VERIFY_WRITE catches R/W	 * transfers. Note that the type is user-oriented, while	 * verify_area is kernel-oriented, so the concept of "read" and	 * "write" is reversed	 */	if (_IOC_DIR(cmd) & _IOC_READ)		err = !access_ok(VERIFY_WRITE, (void __user *)arg, _IOC_SIZE(cmd));	else if (_IOC_DIR(cmd) & _IOC_WRITE)		err =  !access_ok(VERIFY_READ, (void __user *)arg, _IOC_SIZE(cmd));	if (err)		return -EFAULT;	switch(cmd) {	case SCULLV_IOCRESET:		scullv_qset = SCULLV_QSET;		scullv_order = SCULLV_ORDER;		break;	case SCULLV_IOCSORDER: /* Set: arg points to the value */		ret = __get_user(scullv_order, (int __user *) arg);		break;	case SCULLV_IOCTORDER: /* Tell: arg is the value */		scullv_order = arg;		break;	case SCULLV_IOCGORDER: /* Get: arg is pointer to result */		ret = __put_user (scullv_order, (int __user *) arg);		break;	case SCULLV_IOCQORDER: /* Query: return it (it's positive) */		return scullv_order;	case SCULLV_IOCXORDER: /* eXchange: use arg as pointer */		tmp = scullv_order;		ret = __get_user(scullv_order, (int __user *) arg);		if (ret == 0)			ret = __put_user(tmp, (int __user *) arg);		break;	case SCULLV_IOCHORDER: /* sHift: like Tell + Query */		tmp = scullv_order;		scullv_order = arg;		return tmp;	case SCULLV_IOCSQSET:		ret = __get_user(scullv_qset, (int __user *) arg);		break;	case SCULLV_IOCTQSET:		scullv_qset = arg;		break;	case SCULLV_IOCGQSET:		ret = __put_user(scullv_qset, (int __user *)arg);		break;	case SCULLV_IOCQQSET:		return scullv_qset;	case SCULLV_IOCXQSET:		tmp = scullv_qset;		ret = __get_user(scullv_qset, (int __user *)arg);		if (ret == 0)			ret = __put_user(tmp, (int __user *)arg);		break;	case SCULLV_IOCHQSET:		tmp = scullv_qset;		scullv_qset = arg;		return tmp;	default:  /* redundant, as cmd was checked against MAXNR */		return -ENOTTY;	}	return ret;}/* * The "extended" operations */loff_t scullv_llseek (struct file *filp, loff_t off, int whence){	struct scullv_dev *dev = filp->private_data;	long newpos;	switch(whence) {	case 0: /* SEEK_SET */		newpos = off;		break;	case 1: /* SEEK_CUR */		newpos = filp->f_pos + off;		break;	case 2: /* SEEK_END */		newpos = dev->size + off;		break;	default: /* can't happen */		return -EINVAL;	}	if (newpos<0) return -EINVAL;	filp->f_pos = newpos;	return newpos;}/* * A simple asynchronous I/O implementation. */struct async_work {	struct kiocb *iocb;	int result;	struct work_struct work;};/* * "Complete" an asynchronous operation. */static void scullv_do_deferred_op(void *p){	struct async_work *stuff = (struct async_work *) p;	aio_complete(stuff->iocb, stuff->result, 0);	kfree(stuff);}static int scullv_defer_op(int write, struct kiocb *iocb, char __user *buf,		size_t count, loff_t pos){	struct async_work *stuff;	int result;	/* Copy now while we can access the buffer */	if (write)		result = scullv_write(iocb->ki_filp, buf, count, &pos);	else		result = scullv_read(iocb->ki_filp, buf, count, &pos);	/* If this is a synchronous IOCB, we return our status now. */	if (is_sync_kiocb(iocb))		return result;	/* Otherwise defer the completion for a few milliseconds. */	stuff = kmalloc (sizeof (*stuff), GFP_KERNEL);	if (stuff == NULL)		return result; /* No memory, just complete now */	stuff->iocb = iocb;	stuff->result = result;	INIT_WORK(&stuff->work, scullv_do_deferred_op, stuff);	schedule_delayed_work(&stuff->work, HZ/100);	return -EIOCBQUEUED;}static ssize_t scullv_aio_read(struct kiocb *iocb, char __user *buf, size_t count,		loff_t pos){	return scullv_defer_op(0, iocb, buf, count, pos);}static ssize_t scullv_aio_write(struct kiocb *iocb, const char __user *buf,		size_t count, loff_t pos){	return scullv_defer_op(1, iocb, (char __user *) buf, count, pos);} /* * Mmap *is* available, but confined in a different file */extern int scullv_mmap(struct file *filp, struct vm_area_struct *vma);/* * The fops */struct file_operations scullv_fops = {	.owner =     THIS_MODULE,	.llseek =    scullv_llseek,	.read =	     scullv_read,	.write =     scullv_write,	.ioctl =     scullv_ioctl,	.mmap =	     scullv_mmap,	.open =	     scullv_open,	.release =   scullv_release,	.aio_read =  scullv_aio_read,	.aio_write = scullv_aio_write,};int scullv_trim(struct scullv_dev *dev){	struct scullv_dev *next, *dptr;	int qset = dev->qset;   /* "dev" is not-null */	int i;	if (dev->vmas) /* don't trim: there are active mappings */		return -EBUSY;	for (dptr = dev; dptr; dptr = next) { /* all the list items */		if (dptr->data) {			/* Release the quantum-set */			for (i = 0; i < qset; i++)				if (dptr->data[i])					vfree(dptr->data[i]);			kfree(dptr->data);			dptr->data=NULL;		}		next=dptr->next;		if (dptr != dev) kfree(dptr); /* all of them but the first */	}	dev->size = 0;	dev->qset = scullv_qset;	dev->order = scullv_order;	dev->next = NULL;	return 0;}static void scullv_setup_cdev(struct scullv_dev *dev, int index){	int err, devno = MKDEV(scullv_major, index);    	cdev_init(&dev->cdev, &scullv_fops);	dev->cdev.owner = THIS_MODULE;	dev->cdev.ops = &scullv_fops;	err = cdev_add (&dev->cdev, devno, 1);	/* Fail gracefully if need be */	if (err)		printk(KERN_NOTICE "Error %d adding scull%d", err, index);}/* * Finally, the module stuff */int scullv_init(void){	int result, i;	dev_t dev = MKDEV(scullv_major, 0);		/*	 * Register your major, and accept a dynamic number.	 */	if (scullv_major)		result = register_chrdev_region(dev, scullv_devs, "scullv");	else {		result = alloc_chrdev_region(&dev, 0, scullv_devs, "scullv");		scullv_major = MAJOR(dev);	}	if (result < 0)		return result;		/* 	 * allocate the devices -- we can't have them static, as the number	 * can be specified at load time	 */	scullv_devices = kmalloc(scullv_devs*sizeof (struct scullv_dev), GFP_KERNEL);	if (!scullv_devices) {		result = -ENOMEM;		goto fail_malloc;	}	memset(scullv_devices, 0, scullv_devs*sizeof (struct scullv_dev));	for (i = 0; i < scullv_devs; i++) {		scullv_devices[i].order = scullv_order;		scullv_devices[i].qset = scullv_qset;		sema_init (&scullv_devices[i].sem, 1);		scullv_setup_cdev(scullv_devices + i, i);	}#ifdef SCULLV_USE_PROC /* only when available */	create_proc_read_entry("scullvmem", 0, NULL, scullv_read_procmem, NULL);#endif	return 0; /* succeed */  fail_malloc:	unregister_chrdev_region(dev, scullv_devs);	return result;}void scullv_cleanup(void){	int i;#ifdef SCULLV_USE_PROC	remove_proc_entry("scullvmem", NULL);#endif	for (i = 0; i < scullv_devs; i++) {		cdev_del(&scullv_devices[i].cdev);		scullv_trim(scullv_devices + i);	}	kfree(scullv_devices);	unregister_chrdev_region(MKDEV (scullv_major, 0), scullv_devs);}module_init(scullv_init);module_exit(scullv_cleanup);

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久久一区二区三区捆绑**| 久久99深爱久久99精品| 激情亚洲综合在线| 精品视频1区2区3区| 国产精品国产三级国产aⅴ中文 | 国产嫩草影院久久久久| 亚洲风情在线资源站| 国产成人无遮挡在线视频| 欧美日韩国产在线播放网站| 日韩一区在线看| 丁香婷婷综合网| 亚洲精品一区二区三区蜜桃下载 | 精品国产制服丝袜高跟| 视频一区视频二区中文字幕| 日本久久一区二区| 欧美国产成人精品| 国产大陆亚洲精品国产| 欧美电影免费观看高清完整版在线| 亚洲综合区在线| 色94色欧美sute亚洲线路一ni| 国产欧美日韩在线视频| 国产一区二区在线电影| 精品少妇一区二区三区日产乱码| 午夜视频在线观看一区二区三区| 91国偷自产一区二区三区成为亚洲经典| 亚洲国产精品v| 国产成人日日夜夜| 欧美极品xxx| 成人免费毛片片v| 国产精品国产三级国产aⅴ无密码 国产精品国产三级国产aⅴ原创 | 久久午夜国产精品| 精彩视频一区二区三区| 欧美电影免费观看高清完整版 | 91国偷自产一区二区使用方法| 中文字幕中文字幕一区二区| 成人蜜臀av电影| 亚洲少妇屁股交4| 一本一道波多野结衣一区二区 | 欧美日韩国产精品成人| 午夜一区二区三区视频| 337p亚洲精品色噜噜噜| 久久精品国内一区二区三区| 亚洲精品一区二区三区99| 福利一区福利二区| 一区二区三区中文在线| 欧美日韩国产一二三| 老司机午夜精品| 国产午夜亚洲精品理论片色戒| 成人午夜视频在线观看| 亚洲黄一区二区三区| 欧美挠脚心视频网站| 久久se精品一区二区| 欧美激情艳妇裸体舞| 色哟哟一区二区| 日韩二区在线观看| 久久久久国产免费免费| 91免费观看在线| 视频在线观看国产精品| 国产亚洲欧美色| 一本色道久久加勒比精品| 欧美a级理论片| 国产精品日韩成人| 欧美区在线观看| 成人中文字幕合集| 亚洲二区在线观看| 国产欧美精品国产国产专区| 欧美日韩一级二级三级| 国产一区二区导航在线播放| 亚洲精品乱码久久久久久久久 | 尤物视频一区二区| 精品美女一区二区三区| 色网站国产精品| 国产曰批免费观看久久久| 亚洲精品视频在线看| 欧美精品一区二区久久婷婷| 欧美性xxxxx极品少妇| 国产精品12区| 日本在线不卡一区| 亚洲人成精品久久久久| 日韩精品专区在线影院重磅| 色婷婷精品久久二区二区蜜臂av | 日本怡春院一区二区| 亚洲欧美在线视频观看| 2024国产精品| 欧美日韩色综合| 99精品视频在线观看免费| 美女www一区二区| 亚洲影视在线观看| 国产精品国产三级国产| 精品国产乱子伦一区| 欧美精品久久一区| 色综合色综合色综合色综合色综合| 激情图区综合网| 麻豆精品视频在线观看视频| 一区二区三区在线影院| 亚洲天堂免费看| 国产精品不卡在线观看| 久久久精品国产免大香伊| 日韩欧美资源站| 日韩一区二区三区四区| 在线成人小视频| 欧美熟乱第一页| 欧美亚男人的天堂| 91福利区一区二区三区| 91国产免费观看| 色综合色狠狠天天综合色| 95精品视频在线| 91丨porny丨户外露出| 成人免费毛片高清视频| 成人性色生活片| 成人激情文学综合网| 成人视屏免费看| av色综合久久天堂av综合| 成人三级伦理片| 91看片淫黄大片一级| 一本久道中文字幕精品亚洲嫩 | 成人性生交大片免费看中文| 高潮精品一区videoshd| 波多野洁衣一区| 色一区在线观看| 欧美日韩激情一区二区三区| 欧美日韩你懂的| 欧美成人一区二区| 国产欧美日韩综合| 国产精品美女久久久久av爽李琼| 综合色中文字幕| 亚洲成人av一区二区三区| 蜜桃在线一区二区三区| 久88久久88久久久| 国产成人亚洲综合色影视| 成人高清av在线| 欧美色图天堂网| 精品久久久久久久久久久久久久久 | 免费观看30秒视频久久| 国内精品伊人久久久久影院对白| 国产麻豆一精品一av一免费| 成人av网站在线观看| 欧美色视频一区| 久久尤物电影视频在线观看| 国产精品午夜电影| 亚洲成av人片在线观看| 国内国产精品久久| 色偷偷一区二区三区| 日韩欧美一级在线播放| 国产精品国产自产拍高清av王其| 亚洲国产成人av网| 国产在线视频精品一区| 91久久精品午夜一区二区| 日韩欧美国产一区在线观看| 亚洲国产电影在线观看| 香蕉成人啪国产精品视频综合网 | 另类人妖一区二区av| 99精品视频在线观看| 成人免费毛片片v| 日韩一级欧美一级| 亚洲天堂av老司机| 久久精品国产999大香线蕉| 92精品国产成人观看免费| 日韩一区国产二区欧美三区| 亚洲欧美激情一区二区| 国产一区二区中文字幕| 欧美福利电影网| 亚洲色图.com| 国产jizzjizz一区二区| 欧美一区二区视频在线观看| 亚洲日本va在线观看| 国产又黄又大久久| 91麻豆精品国产91久久久久久| 中文字幕一区二区三区四区| 久久99日本精品| 7777精品伊人久久久大香线蕉经典版下载 | 亚洲视频一区在线| 精品一区二区三区视频| 欧美三级一区二区| 综合欧美一区二区三区| 国产麻豆欧美日韩一区| 日韩小视频在线观看专区| 亚洲福利视频三区| 在线亚洲+欧美+日本专区| 国产精品电影一区二区| 国产精品一区二区三区网站| 日韩欧美色电影| 奇米影视一区二区三区小说| 在线欧美日韩精品| 亚洲色图都市小说| 99久久国产综合精品麻豆| 中文一区一区三区高中清不卡| 韩日欧美一区二区三区| 91精品久久久久久蜜臀| 午夜精品福利一区二区三区av| 色婷婷精品大在线视频| 亚洲免费观看高清在线观看| 99久久精品国产网站| **网站欧美大片在线观看| 成人免费视频一区二区| 国产精品成人在线观看| 97精品视频在线观看自产线路二| 国产精品国产自产拍高清av王其| 99久久国产综合精品麻豆| 有坂深雪av一区二区精品|