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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? main.c

?? linux設備驅(qū)動第二版例子程序
?? 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一区二区三区免费野_久草精品视频
欧美人狂配大交3d怪物一区| 国产农村妇女精品| 久久这里只精品最新地址| 亚洲欧美另类小说| 美脚の诱脚舐め脚责91| 99视频在线精品| 久久综合999| 日本成人超碰在线观看| 色婷婷国产精品| 久久久三级国产网站| 日本中文字幕不卡| 欧美做爰猛烈大尺度电影无法无天| 久久久久九九视频| 久久电影国产免费久久电影| 欧美色精品在线视频| ...xxx性欧美| 北条麻妃国产九九精品视频| 久久嫩草精品久久久久| 久久精品国产亚洲aⅴ| 欧美日韩亚洲另类| 亚洲午夜激情网页| 97久久精品人人做人人爽50路| 国产亚洲欧美在线| 国产高清不卡一区二区| 日韩视频一区二区三区| 日日夜夜免费精品| 91精品国产入口在线| 亚洲成人精品在线观看| 欧美日韩免费观看一区二区三区| 亚洲精品视频一区| 蜜桃久久久久久久| 2021国产精品久久精品| 久久成人久久爱| 欧美成人官网二区| 国产麻豆成人传媒免费观看| 欧美精品一区二区三区蜜臀| 国产一区久久久| 国产日韩av一区| 成人av在线资源网| 亚洲精品高清在线观看| 欧洲亚洲国产日韩| 亚洲国产裸拍裸体视频在线观看乱了| 欧美最猛黑人xxxxx猛交| 亚洲一区二区成人在线观看| 欧美日本在线看| 久久99国产精品麻豆| www国产精品av| 成人黄色在线视频| 亚洲国产一区二区三区青草影视| 欧美放荡的少妇| 精品一区二区免费| 中文字幕制服丝袜成人av| 色丁香久综合在线久综合在线观看| 一区二区三区毛片| 91麻豆精品国产91久久久使用方法| 婷婷六月综合亚洲| 久久久久国产精品厨房| 99久久精品国产麻豆演员表| 亚洲综合丁香婷婷六月香| 日韩欧美国产一区二区三区| 国产91精品欧美| 五月婷婷综合网| 国产午夜精品久久| 欧美调教femdomvk| 国产乱码一区二区三区| 日韩毛片在线免费观看| 91精品国产综合久久国产大片| 国产电影精品久久禁18| 亚洲午夜精品在线| 久久先锋资源网| 91福利精品第一导航| 国产一区二区网址| 亚洲福利一区二区| 国产亚洲一区二区三区| 欧美日韩黄色影视| 国产成人精品免费看| 婷婷中文字幕一区三区| 国产精品嫩草影院com| 91精品国产福利在线观看| 懂色av噜噜一区二区三区av| 午夜国产精品一区| 亚洲精品欧美在线| 国产欧美日韩精品在线| 精品美女一区二区| 欧美中文字幕一区| 99精品视频一区二区三区| 久久av资源站| 日韩在线a电影| 一区二区三区欧美视频| 国产精品情趣视频| 亚洲精品一区二区三区香蕉| 精品污污网站免费看| 99精品1区2区| 成人免费视频视频| 国产精品99久久久| 狠狠色狠狠色综合系列| 婷婷久久综合九色综合绿巨人| 中文字幕人成不卡一区| 国产亚洲成年网址在线观看| 欧美电影免费观看完整版| 欧美日本不卡视频| 欧美亚洲综合网| 日本道精品一区二区三区| 99视频有精品| www.成人网.com| 国产 日韩 欧美大片| 国产精品一区三区| 国产在线精品一区二区三区不卡| 日韩电影免费在线| 日本一不卡视频| 日本在线观看不卡视频| 美女性感视频久久| 免费观看一级特黄欧美大片| 婷婷丁香激情综合| 丝袜美腿亚洲一区| 日本va欧美va精品| 麻豆国产精品一区二区三区 | 色播五月激情综合网| eeuss鲁一区二区三区| 成人综合婷婷国产精品久久| 国产成人久久精品77777最新版本 国产成人鲁色资源国产91色综 | 一区二区三区在线观看动漫| 亚洲女女做受ⅹxx高潮| 亚洲精品菠萝久久久久久久| 一区二区三区美女| 日韩电影免费一区| 精品写真视频在线观看| 国产经典欧美精品| av在线一区二区| 在线一区二区视频| 欧美一区欧美二区| 久久亚洲精精品中文字幕早川悠里| 国产欧美日韩在线看| 国产精品久久久久影院老司| 亚洲日本一区二区三区| 亚洲国产精品自拍| 免费观看91视频大全| 成人性生交大片免费看在线播放| av一本久道久久综合久久鬼色| 91免费在线看| 日韩一区二区在线免费观看| 久久九九99视频| 亚洲综合色噜噜狠狠| 久久爱另类一区二区小说| av一二三不卡影片| 日韩女优视频免费观看| 亚洲视频狠狠干| 日本在线不卡一区| 不卡的av电影在线观看| 精品视频全国免费看| 久久久青草青青国产亚洲免观| 一区二区在线观看不卡| 极品美女销魂一区二区三区| 91丨九色丨蝌蚪丨老版| 日韩欧美在线影院| 一区二区三区中文字幕在线观看| 美女高潮久久久| 欧美性欧美巨大黑白大战| 欧美精品一区二区久久久| 伊人性伊人情综合网| 国产又黄又大久久| 欧美三级蜜桃2在线观看| 国产视频一区在线观看| 午夜精品福利一区二区蜜股av | 在线播放一区二区三区| 中文在线免费一区三区高中清不卡| 亚洲成a人在线观看| 高清不卡在线观看| 日韩欧美久久久| 亚洲成精国产精品女| av在线播放一区二区三区| 欧美videos中文字幕| 亚洲国产成人av网| www.亚洲激情.com| 久久久久久久久久久久电影| 日韩激情一区二区| 色婷婷香蕉在线一区二区| 精品播放一区二区| 亚洲成人资源在线| 色婷婷亚洲精品| 椎名由奈av一区二区三区| 国产一区在线观看麻豆| 欧美一级免费观看| 五月天激情小说综合| 欧美在线视频全部完| 亚洲男人的天堂av| av在线这里只有精品| 国产精品的网站| 国产精品88av| 国产性天天综合网| 国产福利精品一区| 国产日产精品一区| 国产凹凸在线观看一区二区| 欧美xxxxxxxxx| 国产一区二区三区香蕉| 久久一留热品黄| 久久精品国产**网站演员| 日韩视频免费观看高清完整版在线观看 | 一卡二卡三卡日韩欧美| av一区二区三区四区|