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

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

?? access.c

?? Linux設備驅動程序第二版
?? C
字號:
/* * access.c -- the files with access control on open * * 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: access.c,v 1.21 2001/07/18 22:28:16 rubini Exp $ */ #ifndef __KERNEL__#  define __KERNEL__#endif#ifndef MODULE#  define MODULE#endif#define __NO_VERSION__#include <linux/module.h> /* get MOD_DEC_USE_COUNT, not the version string */#include <linux/version.h> /* need it for conditionals in scull.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/fcntl.h>#include <linux/tty.h>    /* current->tty */#include "scull.h"        /* local definitions *//* * These devices fall back on the main scull operations. They only * differ in the implementation of open() and close() *//* * The following deals with some of the 2.2 API changes. */#ifdef LINUX_20extern int scull_lseek_20(struct inode *ino, struct file *f, off_t offset,                int whence);extern int scull_read_20(struct inode *ino, struct file *f, char *buf,                int count);extern int scull_write_20(struct inode *ino, struct file *f, const char *buf,                int count);#define scull_llseek scull_lseek_20#define scull_read   scull_read_20#define scull_write  scull_write_20#endif/************************************************************************ * * The first device is the single-open one, *  it has an hw structure and an open count */Scull_Dev scull_s_device;int scull_s_count = 0;spinlock_t scull_s_lock;int scull_s_open(struct inode *inode, struct file *filp){    Scull_Dev *dev = &scull_s_device; /* device information */    int num = NUM(inode->i_rdev);    if (!filp->private_data && num > 0)        return -ENODEV; /* not devfs: allow 1 device only */    spin_lock(&scull_s_lock);    if (scull_s_count) {        spin_unlock(&scull_s_lock);        return -EBUSY; /* already open */    }    scull_s_count++;    spin_unlock(&scull_s_lock);    /* then, everything else is copied from the bare scull device */    if ( (filp->f_flags & O_ACCMODE) == O_WRONLY)        scull_trim(dev);    if (!filp->private_data)        filp->private_data = dev;    MOD_INC_USE_COUNT;    return 0;          /* success */}int scull_s_release(struct inode *inode, struct file *filp){    scull_s_count--; /* release the device */    MOD_DEC_USE_COUNT;    return 0;}#ifdef LINUX_20void scull_s_release_20(struct inode *ino, struct file *f){    scull_s_release(ino, f);}#define scull_s_release scull_s_release_20#define llseek lseek#endif/* * The other operations for the single-open device come from the bare device */struct file_operations scull_sngl_fops = {    llseek:     scull_llseek,    read:       scull_read,    write:      scull_write,    ioctl:      scull_ioctl,    open:       scull_s_open,    release:    scull_s_release,};/************************************************************************ * * Next, the "uid" device. It can be opened multiple times by the * same user, but access is denied to other users if the device is open */Scull_Dev scull_u_device;int scull_u_count = 0;uid_t scull_u_owner = 0;spinlock_t scull_u_lock;int scull_u_open(struct inode *inode, struct file *filp){    Scull_Dev *dev = &scull_u_device; /* device information */    int num = NUM(inode->i_rdev);    if (!filp->private_data && num > 0)        return -ENODEV; /* not devfs: allow 1 device only */    spin_lock(&scull_u_lock);    if (scull_u_count &&         (scull_u_owner != current->uid) &&  /* allow user */        (scull_u_owner != current->euid) && /* allow whoever did su */                    !capable(CAP_DAC_OVERRIDE)) { /* still allow root */            spin_unlock(&scull_u_lock);            return -EBUSY;   /* -EPERM would confuse the user */    }    if (scull_u_count == 0)        scull_u_owner = current->uid; /* grab it */    scull_u_count++;    spin_unlock(&scull_u_lock);    /* then, everything else is copied from the bare scull device */    if ( (filp->f_flags & O_ACCMODE) == O_WRONLY)        scull_trim(dev);    if (!filp->private_data)        filp->private_data = dev;    MOD_INC_USE_COUNT;    return 0;          /* success */}int scull_u_release(struct inode *inode, struct file *filp){    scull_u_count--; /* nothing else */    MOD_DEC_USE_COUNT;    return 0;}#ifdef LINUX_20void scull_u_release_20(struct inode *ino, struct file *f){    scull_u_release(ino, f);}#define scull_u_release scull_u_release_20#endif/* * The other operations for the device come from the bare device */struct file_operations scull_user_fops = {    llseek:     scull_llseek,    read:       scull_read,    write:      scull_write,    ioctl:      scull_ioctl,    open:       scull_u_open,    release:    scull_u_release,};/************************************************************************ * * Next, the device with blocking-open based on uid */Scull_Dev scull_w_device;int scull_w_count = 0;uid_t scull_w_owner = 0;static DECLARE_WAIT_QUEUE_HEAD(scull_w_wait);spinlock_t scull_w_lock;int scull_w_open(struct inode *inode, struct file *filp){    Scull_Dev *dev = &scull_w_device; /* device information */    int num = NUM(inode->i_rdev);    if (!filp->private_data && num > 0)        return -ENODEV; /* not devfs: allow 1 device only */    spin_lock(&scull_w_lock);    while (scull_w_count &&       (scull_w_owner != current->uid) &&  /* allow user */      (scull_w_owner != current->euid) && /* allow whoever did su */      !capable(CAP_DAC_OVERRIDE)) {        spin_unlock(&scull_w_lock);        if (filp->f_flags & O_NONBLOCK) return -EAGAIN;         interruptible_sleep_on(&scull_w_wait);        if (signal_pending(current)) /* a signal arrived */          return -ERESTARTSYS; /* tell the fs layer to handle it */        /* else, loop */        spin_lock(&scull_w_lock);    }    if (scull_w_count == 0)        scull_w_owner = current->uid; /* grab it */    scull_w_count++;    spin_unlock(&scull_w_lock);    /* then, everything else is copied from the bare scull device */    if ( (filp->f_flags & O_ACCMODE) == O_WRONLY)        scull_trim(dev);    if (!filp->private_data)        filp->private_data = dev;    MOD_INC_USE_COUNT;    return 0;          /* success */}int scull_w_release(struct inode *inode, struct file *filp){    scull_w_count--;    if (scull_w_count == 0)        wake_up_interruptible(&scull_w_wait); /* awake other uid's */    MOD_DEC_USE_COUNT;    return 0;}#ifdef LINUX_20void scull_w_release_20(struct inode *ino, struct file *f){    scull_w_release(ino, f);}#define scull_w_release scull_w_release_20#endif/* * The other operations for the device come from the bare device */struct file_operations scull_wusr_fops = {    llseek:     scull_llseek,    read:       scull_read,    write:      scull_write,    ioctl:      scull_ioctl,    open:       scull_w_open,    release:    scull_w_release,};/************************************************************************ * * Finally the `cloned' private device. This is trickier because it * involves list management, and dynamic allocation. */devfs_handle_t scull_priv_handle;    /* only used if devfs is there *//* The clone-specific data structure includes a key field */struct scull_listitem {    Scull_Dev device;    int key;    struct scull_listitem *next;    };/* The list of devices, and a lock to protect it */struct scull_listitem *scull_c_head;spinlock_t scull_c_lock;/* Look for a device or create one if missing */static Scull_Dev *scull_c_lookfor_device(int key){    struct scull_listitem *lptr, *prev = NULL;    for (lptr = scull_c_head; lptr && (lptr->key != key); lptr = lptr->next)        prev=lptr;    if (lptr) return &(lptr->device);    /* not found */    lptr = kmalloc(sizeof(struct scull_listitem), GFP_ATOMIC);    if (!lptr) return NULL;    /* initialize the device */    memset(lptr, 0, sizeof(struct scull_listitem));    lptr->key = key;    scull_trim(&(lptr->device)); /* initialize it */    sema_init(&(lptr->device.sem), 1);    /* place it in the list */    if (prev)  prev->next = lptr;    else       scull_c_head = lptr;    return &(lptr->device);}int scull_c_open(struct inode *inode, struct file *filp){    Scull_Dev *dev;    int key, num = NUM(inode->i_rdev);     if (!filp->private_data && num > 0)        return -ENODEV; /* not devfs: allow 1 device only */    if (!current->tty) {         PDEBUG("Process \"%s\" has no ctl tty\n",current->comm);        return -EINVAL;    }    key = MINOR(current->tty->device);    /* look for a scullc device in the list */    spin_lock(&scull_c_lock);    dev = scull_c_lookfor_device(key);    spin_unlock(&scull_c_lock);    if (!dev) return -ENOMEM;    /* then, everything else is copied from the bare scull device */    if ( (filp->f_flags & O_ACCMODE) == O_WRONLY)        scull_trim(dev);    filp->private_data = dev;    MOD_INC_USE_COUNT;    return 0;          /* success */}int scull_c_release(struct inode *inode, struct file *filp){    /*     * Nothing to do, because the device is persistent.     * A `real' cloned device should be freed on last close     */    MOD_DEC_USE_COUNT;    return 0;}#ifdef LINUX_20void scull_c_release_20(struct inode *ino, struct file *f){    scull_c_release(ino, f);}#define scull_c_release scull_c_release_20#endif/* * The other operations for the device come from the bare device */struct file_operations scull_priv_fops = {    llseek:   scull_llseek,    read:     scull_read,    write:    scull_write,    ioctl:    scull_ioctl,    open:     scull_c_open,    release:  scull_c_release,};/************************************************************************ * * And the init and cleanup functions come last */int scull_access_init(void){    /* assign quantum and quantumset */    scull_s_device.quantum = scull_quantum;    scull_s_device.qset    = scull_qset;    scull_u_device.quantum = scull_quantum;    scull_u_device.qset    = scull_qset;    scull_w_device.quantum = scull_quantum;    scull_w_device.qset    = scull_qset;    /* Initialize spinlocks */    spin_lock_init(&scull_s_lock);    spin_lock_init(&scull_u_lock);    spin_lock_init(&scull_w_lock);    spin_lock_init(&scull_c_lock);    /* and semaphores (used by read and write) */    sema_init(&scull_s_device.sem, 1);    sema_init(&scull_u_device.sem, 1);    sema_init(&scull_w_device.sem, 1);    /* and file operations owners */    SET_MODULE_OWNER(&scull_sngl_fops);    SET_MODULE_OWNER(&scull_user_fops);    SET_MODULE_OWNER(&scull_wusr_fops);    SET_MODULE_OWNER(&scull_priv_fops);#ifdef CONFIG_DEVFS_FS    /* finally, create the devfs entry points */    scull_s_device.handle =        devfs_register(scull_devfs_dir, "single",                       DEVFS_FL_AUTO_DEVNUM,                       0, 0, S_IFCHR | S_IRUGO | S_IWUGO,                       &scull_sngl_fops,                       &scull_s_device);    scull_u_device.handle =        devfs_register(scull_devfs_dir, "user",                       DEVFS_FL_AUTO_DEVNUM,                       0, 0, S_IFCHR | S_IRUGO | S_IWUGO,                       &scull_user_fops,                       &scull_u_device);    scull_w_device.handle =        devfs_register(scull_devfs_dir, "wuser",                       DEVFS_FL_AUTO_DEVNUM,                       0, 0, S_IFCHR | S_IRUGO | S_IWUGO,                       &scull_wusr_fops,                       &scull_w_device);    scull_priv_handle =        devfs_register(scull_devfs_dir, "priv",                       DEVFS_FL_AUTO_DEVNUM,                       0, 0, S_IFCHR | S_IRUGO | S_IWUGO,                       &scull_priv_fops,                       &scull_priv_fops); /* any non-null value */#endif        return 0;}/* * This is called by cleanup_module or on failure. * It is required to never fail, even if nothing was initialized first */void scull_access_cleanup(void){    struct scull_listitem *lptr, *prev;    scull_trim(&scull_s_device); /* disallocate it */    scull_trim(&scull_u_device); /* disallocate it */    scull_trim(&scull_w_device); /* disallocate it */    /* all the cloned devices */    prev=NULL;    for (lptr = scull_c_head; lptr; lptr = lptr->next) {        scull_trim(&(lptr->device));        if (prev) kfree(prev);        prev=lptr;    }    if (prev) kfree(prev);    scull_c_head = NULL; /* overkill: we're unloading anyways */    /* remove devfs entry points */    devfs_unregister(scull_s_device.handle);    devfs_unregister(scull_u_device.handle);    devfs_unregister(scull_w_device.handle);    devfs_unregister(scull_priv_handle);    return;}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
大美女一区二区三区| 美女视频网站久久| 欧美激情一区二区三区四区 | 日本亚洲欧美天堂免费| 亚洲乱码日产精品bd| 亚洲婷婷在线视频| 伊人开心综合网| 亚洲欧美日韩在线| 亚洲一区视频在线| 午夜激情综合网| 奇米影视7777精品一区二区| 美女视频黄免费的久久 | 处破女av一区二区| 不卡的电视剧免费网站有什么| 成人午夜视频网站| 91在线国产观看| 欧美日韩mp4| 26uuu欧美日本| 亚洲免费三区一区二区| 视频精品一区二区| 黑人精品欧美一区二区蜜桃| 国产一区不卡精品| 91同城在线观看| 在线不卡一区二区| 国产欧美日韩另类一区| 一区二区三区日韩精品| 日韩影视精彩在线| 成人午夜视频在线观看| 欧美人成免费网站| 国产日韩欧美精品一区| 亚洲欧洲精品天堂一级| 三级久久三级久久| av中文字幕在线不卡| 欧美日韩亚洲另类| 中文字幕的久久| 日本成人中文字幕| 成人黄色免费短视频| 91精品国产综合久久久蜜臀粉嫩| 欧美极品aⅴ影院| 日韩不卡一区二区三区| 99精品1区2区| 日韩欧美成人激情| 亚洲自拍偷拍九九九| 国产福利一区二区三区视频在线| 91福利国产精品| 国产精品伦一区| 久久狠狠亚洲综合| 精品视频一区二区不卡| 欧美韩日一区二区三区四区| 日韩国产在线观看| 欧洲生活片亚洲生活在线观看| 久久综合久久综合亚洲| 日韩福利电影在线观看| 91麻豆国产福利精品| 久久无码av三级| 美女免费视频一区二区| 欧美三级韩国三级日本一级| 国产精品的网站| 国产成人免费xxxxxxxx| 精品国产麻豆免费人成网站| 五月激情六月综合| 欧美视频中文字幕| 亚洲一区在线免费观看| 99精品久久99久久久久| 亚洲精品乱码久久久久久久久| 国内欧美视频一区二区| 欧美一区二区三区成人| 亚洲国产日韩av| 欧美日韩中字一区| 亚洲午夜三级在线| 欧美亚洲丝袜传媒另类| 亚洲一区二区三区免费视频| 欧美亚洲一区三区| 亚洲自拍偷拍麻豆| 7777女厕盗摄久久久| 午夜精品爽啪视频| 7777精品久久久大香线蕉| 日韩av午夜在线观看| 欧美www视频| 精品一区二区三区久久久| 日韩欧美国产综合| 国模大尺度一区二区三区| 久久综合狠狠综合| 国产91对白在线观看九色| 国产精品美女久久久久aⅴ国产馆 国产精品美女久久久久av爽李琼 国产精品美女久久久久高潮 | 一区二区三区中文在线观看| 99久久99精品久久久久久| 亚洲欧美国产77777| 精品污污网站免费看| 日韩电影在线观看电影| 日韩视频免费观看高清在线视频| 久久国产精品第一页| 久久久99精品免费观看不卡| av电影天堂一区二区在线观看| 亚洲精品一二三区| 5月丁香婷婷综合| 国产一区二区三区在线看麻豆| 久久久精品免费免费| 色综合中文综合网| 亚洲成人高清在线| 日韩视频免费直播| 粉嫩嫩av羞羞动漫久久久| 亚洲日本在线看| 欧美二区在线观看| 国产成人精品免费| 一区二区高清免费观看影视大全| 欧美高清视频一二三区| 国产麻豆精品一区二区| 亚洲精品乱码久久久久久| 欧美放荡的少妇| 成人黄色一级视频| 日韩av网站免费在线| 国产精品美女久久久久久| 欧美精品久久久久久久久老牛影院| 精品亚洲国产成人av制服丝袜| 亚洲欧洲国产日韩| 日韩一级完整毛片| 色88888久久久久久影院按摩| 久久精品久久综合| 一区二区三区免费看视频| 精品国产露脸精彩对白| 欧美艳星brazzers| www.亚洲在线| 激情小说亚洲一区| 午夜精品一区二区三区电影天堂| 国产精品萝li| 久久色.com| 日韩精品中文字幕在线不卡尤物| eeuss鲁片一区二区三区在线观看| 蜜臀av性久久久久蜜臀aⅴ| 一区二区三区久久| 国产精品福利电影一区二区三区四区| 日韩欧美美女一区二区三区| 欧美日韩日日夜夜| 91成人网在线| 91欧美一区二区| 粉嫩av一区二区三区粉嫩| 久久精品国产77777蜜臀| 亚洲电影第三页| 一区二区高清在线| 亚洲精品视频在线观看免费| 中文字幕不卡三区| 欧美激情一区二区三区| 国产欧美精品一区aⅴ影院 | 精品午夜久久福利影院| 午夜精品福利一区二区三区av| 亚洲精品国产一区二区三区四区在线| 中文一区在线播放| 国产精品国产精品国产专区不蜜| 中文子幕无线码一区tr| 国产欧美精品国产国产专区| 精品国产乱子伦一区| 精品国产一二三区| 欧美精品一区二区三区四区 | 亚洲视频中文字幕| 亚洲视频精选在线| 亚洲自拍偷拍麻豆| 日韩黄色免费网站| 老司机免费视频一区二区| 男女激情视频一区| 激情五月婷婷综合| 国产v综合v亚洲欧| 91免费小视频| 欧美日韩黄色一区二区| 91麻豆精品国产91久久久久| 日韩女优毛片在线| 欧美激情综合五月色丁香小说| 欧美国产精品久久| 一区二区三区在线播放| 亚洲不卡在线观看| 激情五月婷婷综合网| 成人少妇影院yyyy| 在线免费观看日本一区| 91精品免费在线观看| 久久人人爽爽爽人久久久| 中文字幕一区二区三区在线播放 | 99精品国产热久久91蜜凸| 91麻豆免费视频| 欧美一区二区三区免费在线看| 日韩欧美一区二区视频| 国产日韩欧美综合在线| 亚洲最色的网站| 久久精品噜噜噜成人88aⅴ| 国产91精品在线观看| 欧美在线观看18| 精品国产电影一区二区| 亚洲欧美偷拍卡通变态| 丝袜亚洲精品中文字幕一区| 国产成人精品免费| 欧美精选一区二区| 国产精品网曝门| 免费成人在线观看视频| 99精品国产一区二区三区不卡| 91麻豆精品久久久久蜜臀| 国产精品免费视频网站| 日本欧美一区二区三区| 91丨九色丨尤物| 国产欧美一区二区精品性色 | 欧美一区二区三区在线电影| 亚洲国产精品成人综合|