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

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

?? main.c

?? linux device driver源碼
?? C
?? 第 1 頁 / 共 2 頁
字號:
/* * main.c -- the bare scull 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. * */#ifndef __KERNEL__#  define __KERNEL__#endif#ifndef MODULE#  define MODULE#endif#include <linux/config.h>#include <linux/module.h>#include <linux/kernel.h>   /* printk() */#include <linux/malloc.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 <asm/system.h>     /* cli(), *_flags */#include "scull.h"          /* local definitions *//* * I don't use static symbols here, because we export no symbols */int scull_major =   SCULL_MAJOR;int scull_nr_devs = SCULL_NR_DEVS;    /* number of bare scull devices */int scull_quantum = SCULL_QUANTUM;int scull_qset =    SCULL_QSET;MODULE_PARM(scull_major,"i");MODULE_PARM(scull_nr_devs,"i");MODULE_PARM(scull_quantum,"i");MODULE_PARM(scull_qset,"i");MODULE_AUTHOR("Alessandro Rubini");Scull_Dev *scull_devices; /* allocated in scull_init_module *//* * Different minors behave differently, so let's use multiple fops */struct file_operations *scull_fop_array[]={    &scull_fops,      /* type 0 */    &scull_priv_fops, /* type 1 */    &scull_pipe_fops, /* type 2 */    &scull_sngl_fops, /* type 3 */    &scull_user_fops, /* type 4 */    &scull_wusr_fops  /* type 5 */};#define SCULL_MAX_TYPE 5int scull_trim(Scull_Dev *dev){    Scull_Dev *next, *dptr;    int qset = dev->qset;   /* "dev" is not-null */    int i;    for (dptr = dev; dptr; dptr = next) { /* all the list items */        if (dptr->data) {            for (i = 0; i < qset; i++)                if (dptr->data[i])                    kfree(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->quantum = scull_quantum;    dev->qset = scull_qset;    dev->next = NULL;    return 0;}#ifdef SCULL_DEBUG /* use proc only if debugging *//* * The proc filesystem: function to read and entry */int scull_read_procmem(char *buf, char **start, off_t offset,                   int count, int *eof, void *data){    int i, j, len = 0;    int limit = count - 80; /* Don't print more than this */    for (i = 0; i < scull_nr_devs && len <= limit; i++) {        Scull_Dev *d = &scull_devices[i];        if (down_interruptible(&d->sem))                return -ERESTARTSYS;        len += sprintf(buf+len,"\nDevice %i: qset %i, q %i, sz %li\n",                       i, d->qset, d->quantum, d->size);        for (; d && len <= limit; d = d->next) { /* scan the list */            len += sprintf(buf+len, "  item at %p, qset at %p\n", d, d->data);            if (d->data && !d->next) /* dump only the last item - save space */                for (j = 0; j < d->qset; j++) {                    if (d->data[j])                        len += sprintf(buf+len,"    % 4i: %8p\n",j,d->data[j]);                }        }        up(&scull_devices[i].sem);    }    *eof = 1;    return len;}#ifdef USE_PROC_REGISTERstatic int scull_get_info(char *buf, char **start, off_t offset,                int len, int unused){    int eof = 0;    return scull_read_procmem (buf, start, offset, len, &eof, NULL);}struct proc_dir_entry scull_proc_entry = {        namelen:    8,        name:       "scullmem",        mode:       S_IFREG | S_IRUGO,        nlink:      1,        get_info:   scull_get_info,};static void scull_create_proc(){    proc_register_dynamic(&proc_root, &scull_proc_entry);}static void scull_remove_proc(){    proc_unregister(&proc_root, scull_proc_entry.low_ino);}#else  /* no USE_PROC_REGISTER - modern world */static void scull_create_proc(){    create_proc_read_entry("scullmem", 0 /* default mode */,                           NULL /* parent dir */, scull_read_procmem,                           NULL /* client data */);}static void scull_remove_proc(){    /* no problem if it was not registered */    remove_proc_entry("scullmem", NULL /* parent dir */);}#endif /* USE_PROC_REGISTER */#endif /* SCULL_DEBUG *//* * Open and close *//* In scull_open, the fop_array is used according to TYPE(dev) */int scull_open(struct inode *inode, struct file *filp){    Scull_Dev *dev; /* device information */    int num = NUM(inode->i_rdev);    int type = TYPE(inode->i_rdev);    /*     * the type and num values are only valid if we are not using devfs.     * However, since we use them to retrieve the device pointer, we     * don't need them with devfs as filp->private_data is already     * initialized     */    /*     * If private data is not valid, we are not using devfs     * so use the type (from minor nr.) to select a new f_op     */    if (!filp->private_data && type) {        if (type > SCULL_MAX_TYPE) return -ENODEV;        filp->f_op = scull_fop_array[type];        return filp->f_op->open(inode, filp); /* dispatch to specific open */    }    /* type 0, check the device number (unless private_data valid) */    dev = (Scull_Dev *)filp->private_data;    if (!dev) {        if (num >= scull_nr_devs) return -ENODEV;        dev = &scull_devices[num];        filp->private_data = dev; /* for other methods */    }    MOD_INC_USE_COUNT;  /* Before we maybe sleep */    /* 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)) {            MOD_DEC_USE_COUNT;            return -ERESTARTSYS;        }        scull_trim(dev); /* ignore errors */        up(&dev->sem);    }    return 0;          /* success */}int scull_release(struct inode *inode, struct file *filp){    MOD_DEC_USE_COUNT;    return 0;}/* * Follow the list  */Scull_Dev *scull_follow(Scull_Dev *dev, int n){    while (n--) {        if (!dev->next) {            dev->next = kmalloc(sizeof(Scull_Dev), GFP_KERNEL);            memset(dev->next, 0, sizeof(Scull_Dev));        }        dev = dev->next;        continue;    }    return dev;}/* * Data management: read and write */ssize_t scull_read(struct file *filp, char *buf, size_t count,                loff_t *f_pos){    Scull_Dev *dev = filp->private_data; /* the first listitem */    Scull_Dev *dptr;    int quantum = dev->quantum;    int qset = dev->qset;    int itemsize = quantum * qset; /* how many bytes in the listitem */    int item, s_pos, q_pos, rest;    ssize_t ret = 0;    if (down_interruptible(&dev->sem))            return -ERESTARTSYS;    if (*f_pos >= dev->size)        goto out;    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 = scull_follow(dev, item);    if (!dptr->data)        goto out; /* don't fill holes */    if (!dptr->data[s_pos])        goto out;    /* read only up to the end of this quantum */    if (count > quantum - q_pos)        count = quantum - q_pos;    if (copy_to_user(buf, dptr->data[s_pos]+q_pos, count)) {        ret = -EFAULT;	goto out;    }    *f_pos += count;    ret = count; out:    up(&dev->sem);    return ret;}ssize_t scull_write(struct file *filp, const char *buf, size_t count,                loff_t *f_pos){    Scull_Dev *dev = filp->private_data;    Scull_Dev *dptr;    int quantum = dev->quantum;    int qset = dev->qset;    int itemsize = quantum * qset;    int item, s_pos, q_pos, rest;    ssize_t ret = -ENOMEM; /* value used in "goto out" statements */    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 = scull_follow(dev, item);    if (!dptr->data) {        dptr->data = kmalloc(qset * sizeof(char *), GFP_KERNEL);        if (!dptr->data)            goto out;        memset(dptr->data, 0, qset * sizeof(char *));    }    if (!dptr->data[s_pos]) {        dptr->data[s_pos] = kmalloc(quantum, GFP_KERNEL);        if (!dptr->data[s_pos])            goto out;    }    /* write only up to the end of this quantum */    if (count > quantum - q_pos)        count = quantum - q_pos;    if (copy_from_user(dptr->data[s_pos]+q_pos, buf, count)) {        ret = -EFAULT;	goto out;    }    *f_pos += count;    ret = count;    /* update the size */    if (dev->size < *f_pos)        dev-> size = *f_pos;  out:    up(&dev->sem);    return ret;}/* * The ioctl() implementation * * This is done twice, once the 2.2 way, followed by the 2.0 way.  One * would not normally do things in this manner, but we wanted to illustrate * both ways... */#ifndef LINUX_20int scull_ioctl(struct inode *inode, struct file *filp,                 unsigned int cmd, unsigned long arg){    int err = 0, tmp;    int ret = 0;        /*     * extract the type and number bitfields, and don't decode     * wrong cmds: return ENOTTY (inappropriate ioctl) before access_ok()     */    if (_IOC_TYPE(cmd) != SCULL_IOC_MAGIC) return -ENOTTY;    if (_IOC_NR(cmd) > SCULL_IOC_MAXNR) return -ENOTTY;    /*     * the direction is a bitmask, and VERIFY_WRITE catches R/W     * transfers. `Type' is user-oriented, while     * access_ok is kernel-oriented, so the concept of "read" and     * "write" is reversed     */    if (_IOC_DIR(cmd) & _IOC_READ)        err = !access_ok(VERIFY_WRITE, (void *)arg, _IOC_SIZE(cmd));    else if (_IOC_DIR(cmd) & _IOC_WRITE)        err =  !access_ok(VERIFY_READ, (void *)arg, _IOC_SIZE(cmd));    if (err) return -EFAULT;    switch(cmd) {#ifdef SCULL_DEBUG      case SCULL_IOCHARDRESET:         /*          * reset the counter to 1, to allow unloading in case          * of problems. Use 1, not 0, because the invoking          * process has the device open.          */         while (MOD_IN_USE)             MOD_DEC_USE_COUNT;         MOD_INC_USE_COUNT;         /* don't break: fall through and reset things */#endif /* SCULL_DEBUG */

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
在线不卡一区二区| 色综合久久综合中文综合网| 欧美va亚洲va| 国产在线精品一区二区夜色| 国产亚洲欧美在线| 国产成人精品网址| 亚洲人成网站影音先锋播放| 欧洲精品在线观看| 日本视频免费一区| 久久精品夜色噜噜亚洲a∨| 国产ts人妖一区二区| 亚洲情趣在线观看| 4438成人网| 国产91在线看| 亚洲国产精品久久人人爱| 日韩视频在线永久播放| 国产精品99久久久久| 亚洲欧美日韩久久| 欧美精品日日鲁夜夜添| 国产精品亚洲第一区在线暖暖韩国| 中文幕一区二区三区久久蜜桃| 91免费精品国自产拍在线不卡| 午夜精品福利在线| 久久久久久久久久久99999| 91丝袜呻吟高潮美腿白嫩在线观看| 亚洲超碰精品一区二区| 久久精品一区四区| 51精品国自产在线| 成人午夜大片免费观看| 视频一区二区三区在线| 中文字幕欧美日韩一区| 3d动漫精品啪啪1区2区免费| 成人免费三级在线| 另类小说欧美激情| 樱花影视一区二区| 久久婷婷色综合| 欧美日韩精品专区| 91丨国产丨九色丨pron| 久久国产欧美日韩精品| 亚洲国产成人av网| 亚洲欧洲国产日本综合| 日韩精品中文字幕一区二区三区| 99久久精品久久久久久清纯| 久久精品国产网站| 亚洲成人免费av| 亚洲三级在线看| 国产婷婷一区二区| 欧美va亚洲va在线观看蝴蝶网| 91黄色免费看| www.亚洲人| 国产成人在线色| 麻豆视频一区二区| 日韩和的一区二区| 亚洲五月六月丁香激情| 亚洲欧美日韩中文播放| 国产日韩欧美精品电影三级在线| 日韩一级二级三级| 91精品黄色片免费大全| 欧洲一区在线电影| 色综合天天视频在线观看 | 久久久亚洲国产美女国产盗摄 | 性做久久久久久免费观看| 国产亚洲综合在线| 欧美大白屁股肥臀xxxxxx| 欧美日韩一区二区三区视频| 99精品桃花视频在线观看| 国产iv一区二区三区| 国产一区二区不卡| 久久不见久久见免费视频7| 秋霞成人午夜伦在线观看| 午夜私人影院久久久久| 亚洲国产精品尤物yw在线观看| 亚洲精品日韩一| 亚洲码国产岛国毛片在线| 亚洲免费观看在线视频| 亚洲免费观看在线观看| 一区二区三区久久| 亚洲制服丝袜一区| 日韩精品一二三区| 日韩avvvv在线播放| 首页国产欧美久久| 久久国产精品99久久久久久老狼| 免费成人结看片| 激情五月激情综合网| 国产一本一道久久香蕉| 国产激情视频一区二区在线观看| 国产精品羞羞答答xxdd| www.欧美色图| 91久久免费观看| 欧美日韩精品一区二区三区 | 国产成人精品网址| 不卡av免费在线观看| 色屁屁一区二区| 欧美肥胖老妇做爰| 久久综合色天天久久综合图片| 欧美白人最猛性xxxxx69交| 国产亚洲综合在线| 亚洲男同性视频| 日韩精品91亚洲二区在线观看 | 国产成人av影院| 成人一道本在线| 在线观看欧美黄色| 精品久久久久久无| 国产精品的网站| 婷婷六月综合网| 国产精品中文字幕日韩精品 | 9191久久久久久久久久久| 欧美不卡一区二区| 国产精品国产精品国产专区不蜜| 亚洲自拍偷拍综合| 国产精品18久久久久久久网站| 99久久婷婷国产精品综合| 91.麻豆视频| 亚洲欧美在线观看| 日产精品久久久久久久性色| 国产成人av一区| 欧美丰满少妇xxxbbb| 国产精品久久久久久久久快鸭| 亚洲国产美女搞黄色| 国产91高潮流白浆在线麻豆 | 久久se精品一区精品二区| 成人一级片在线观看| 欧美一区二区三级| 中文字幕亚洲在| 精品夜夜嗨av一区二区三区| 色综合天天狠狠| 久久久久久综合| 日韩高清不卡一区二区三区| 成人黄色777网| 欧美mv日韩mv亚洲| 亚洲va欧美va天堂v国产综合| 国产精品亚洲第一区在线暖暖韩国 | 国产精品系列在线| 麻豆精品在线播放| 欧美三级日韩三级| 亚洲欧洲在线观看av| 久久66热re国产| 这里只有精品99re| 亚洲综合免费观看高清完整版| 国产成人综合在线| 日韩欧美国产高清| 国产精品18久久久久久vr| 欧美色综合影院| 中文字幕亚洲在| 成熟亚洲日本毛茸茸凸凹| 日韩一区二区免费视频| 亚洲综合自拍偷拍| 91小视频在线| 国产欧美日韩综合精品一区二区| 日本怡春院一区二区| 欧美日韩综合不卡| 一区二区三区四区视频精品免费 | 色哟哟一区二区| 国产精品理伦片| 国产黄色91视频| 精品国产髙清在线看国产毛片 | 欧美激情一区不卡| 国模冰冰炮一区二区| 日韩免费福利电影在线观看| 日韩黄色免费网站| 欧美一级淫片007| 日本成人在线不卡视频| 日韩一级欧美一级| 另类小说综合欧美亚洲| 日韩欧美一区二区在线视频| 日韩国产高清在线| 这里只有精品免费| 麻豆国产欧美日韩综合精品二区| 51午夜精品国产| 精品制服美女久久| 国产色91在线| 成人av午夜电影| 日韩一区在线看| 色屁屁一区二区| 日韩国产一区二| 精品理论电影在线观看| 国产一区二区福利视频| 中文字幕va一区二区三区| 94-欧美-setu| 亚洲不卡在线观看| 日韩欧美专区在线| 国产精品香蕉一区二区三区| 国产精品视频一二| 日本韩国欧美国产| 天天操天天综合网| 日韩精品一区二区三区老鸭窝| 国产精品资源网| 亚洲精品中文在线| 91精品国产综合久久久蜜臀图片| 日本91福利区| 日本一区二区免费在线| 一本色道亚洲精品aⅴ| 日韩精品成人一区二区三区| 久久亚洲精品小早川怜子| 成人app下载| 视频一区视频二区中文字幕| 欧美tk—视频vk| 色综合天天综合网天天看片| 午夜国产精品一区| 久久精品一区二区三区不卡|