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

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

?? access.c

?? Linux設備驅動程序第二版
?? C
字號:
/*
 * access.c -- the files with access control on open
 *
 * Tested with 1.2 on the x86
 * Tested with 2.0 on the x86, Sparc
 */

 
#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/proc_fs.h>
#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 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;

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 (num > 0) return -ENODEV; /* 1 device only */
    if (scull_s_count) return -EBUSY; /* already open */
    scull_s_count++;

    /* 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 */
}

void scull_s_release (struct inode *inode, struct file *filp)
{
    scull_s_count--; /* release the device */
    MOD_DEC_USE_COUNT;
    return;
}

/*
 * The other operations for the single-open device come from the bare device
 */
struct file_operations scull_sngl_fops = {
    scull_lseek,
    scull_read,
    scull_write,
    NULL,          /* scull_readdir */
    NULL,          /* scull_select */
    scull_ioctl,
    NULL,          /* scull_mmap */
    scull_s_open,
    scull_s_release,
    NULL,          /* scull_fsync */
    NULL,          /* scull_fasync */
                   /* nothing more, fill with NULLs */
};


/************************************************************************
 *
 * 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;

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 (num > 0) return -ENODEV; /* 1 device only */
    if (scull_u_count && 
        (scull_u_owner != current->uid) &&  /* allow user */
        (scull_u_owner != current->euid) && /* allow whoever did su */
        !suser()) /* still allow root */
         return -EBUSY;   /* -EPERM would confuse the user */

    if (scull_u_count == 0)
        scull_u_owner = current->uid; /* grab it */

    scull_u_count++;

    /* 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 */
}

void scull_u_release (struct inode *inode, struct file *filp)
{
    scull_u_count--; /* nothing else */
    MOD_DEC_USE_COUNT;
    return;
}

/*
 * The other operations for the device come from the bare device
 */
struct file_operations scull_user_fops = {
    scull_lseek,
    scull_read,
    scull_write,
    NULL,          /* scull_readdir */
    NULL,          /* scull_select */
    scull_ioctl,
    NULL,          /* scull_mmap */
    scull_u_open,
    scull_u_release,
    NULL,          /* scull_fsync */
    NULL,          /* scull_fasync */
                   /* nothing more, fill with NULLs */
};


/************************************************************************
 *
 * 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;
struct wait_queue *scull_w_wait;

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 (num > 0) return -ENODEV; /* 1 device only */
    while (scull_w_count && 
      (scull_w_owner != current->uid) &&  /* allow user */
      (scull_w_owner != current->euid) && /* allow whoever did su */
      !suser()) {
        if (filp->f_flags & O_NONBLOCK) return -EAGAIN; 
        interruptible_sleep_on(&scull_w_wait);
        if (current->signal & ~current->blocked) /* a signal arrived */
          return -ERESTARTSYS; /* tell the fs layer to handle it */
        /* else, loop */
    }
    if (scull_w_count == 0)
        scull_w_owner = current->uid; /* grab it */
    scull_w_count++;

    /* 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 */
}

void 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;
}

/*
 * The other operations for the device come from the bare device
 */
struct file_operations scull_wusr_fops = {
    scull_lseek,
    scull_read,
    scull_write,
    NULL,          /* scull_readdir */
    NULL,          /* scull_select */
    scull_ioctl,
    NULL,          /* scull_mmap */
    scull_w_open,
    scull_w_release,
    NULL,          /* scull_fsync */
    NULL,          /* scull_fasync */
                   /* nothing more, fill with NULLs */
};

/************************************************************************
 *
 * Finally the `cloned' private device. This is trickier because it
 * involves list management, and dynamic allocation.
 */

struct scull_listitem {
    Scull_Dev device;
    int key;
    struct scull_listitem *next;
};

struct scull_listitem *scull_c_head;

int scull_c_open (struct inode *inode, struct file *filp)
{
    int key;
    int num = NUM(inode->i_rdev);
    struct scull_listitem *lptr, *prev;

    if (num > 0) return -ENODEV; /* 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 device in the linked list; if missing create it */
    prev = NULL;
    for (lptr = scull_c_head; lptr && (lptr->key != key); lptr = lptr->next)
        prev=lptr;
    if (!lptr) { /* not found */
        lptr = kmalloc(sizeof(struct scull_listitem), GFP_KERNEL);
        if (!lptr)
            return -ENOMEM;
        memset(lptr, 0, sizeof(struct scull_listitem));
        lptr->key = key;
        scull_trim(&(lptr->device)); /* initialize it */
        if (prev)
            prev->next = lptr;
        else
            scull_c_head = lptr; /* the first one */
    }

    /* then, everything else is copied from the bare scull device */

    if ( (filp->f_flags & O_ACCMODE) == O_WRONLY)
        scull_trim(&(lptr->device));
    filp->private_data = &(lptr->device);
    MOD_INC_USE_COUNT;
    return 0;          /* success */
}

void 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;
}

/*
 * The other operations for the device come from the bare device
 */
struct file_operations scull_priv_fops = {
    scull_lseek,
    scull_read,
    scull_write,
    NULL,          /* scull_readdir */
    NULL,          /* scull_select */
    scull_ioctl,
    NULL,          /* scull_mmap */
    scull_c_open,
    scull_c_release,
    NULL,          /* scull_fsync */
    NULL,          /* scull_fasync */
                   /* nothing more, fill with NULLs */
};

/************************************************************************
 *
 * 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;

    return 0;
}

void scull_access_cleanup(void) /* called by cleanup_module */
{
    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 */

    return;
}




?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
4438成人网| 亚洲精品国久久99热| 欧美亚洲一区二区三区四区| 高清视频一区二区| 国产一区二区三区免费| 久久精品国产999大香线蕉| 日韩黄色免费电影| 日韩1区2区日韩1区2区| 午夜精品在线看| 五月天婷婷综合| 免费高清在线一区| 久久精品久久99精品久久| 麻豆久久一区二区| 久久99国产精品尤物| 国产麻豆精品一区二区| 国产91丝袜在线播放0| 成人性生交大片| 一本色道久久综合狠狠躁的推荐| 色综合天天综合色综合av| 日本乱码高清不卡字幕| 欧美日韩国产精品成人| 日韩欧美色综合网站| 国产日韩欧美不卡| 亚洲视频在线一区| 亚洲电影在线播放| 免费高清在线一区| 粉嫩高潮美女一区二区三区| 色天天综合久久久久综合片| 欧美美女bb生活片| 久久亚洲精华国产精华液| 国产精品麻豆一区二区| 亚洲国产一区二区视频| 久久av中文字幕片| 不卡视频一二三| 欧美日韩三级一区| 久久久电影一区二区三区| 亚洲欧美激情小说另类| 午夜精品久久久久久久蜜桃app| 免费观看在线综合| 成人黄色一级视频| 欧美高清视频一二三区 | 国产精品成人网| 一区二区三区日韩精品视频| 久久国产乱子精品免费女| 99久久婷婷国产综合精品 | 图片区小说区区亚洲影院| 韩国精品主播一区二区在线观看| 北条麻妃国产九九精品视频| 精品日韩在线一区| 亚洲精品免费一二三区| 国产电影一区二区三区| 欧美丰满高潮xxxx喷水动漫| 中文字幕在线免费不卡| 精品在线视频一区| 色域天天综合网| 久久精品一区二区三区不卡牛牛| 一区二区欧美视频| 成a人片国产精品| 日韩亚洲欧美成人一区| 夜色激情一区二区| 波多野结衣中文字幕一区| 日韩欧美123| 日韩精品一区第一页| 91麻豆免费看片| 国产午夜精品美女毛片视频| 久久国产日韩欧美精品| 4hu四虎永久在线影院成人| 一区二区三区中文在线观看| 波多野结衣中文字幕一区 | 成人黄色免费短视频| 亚洲精品一区二区三区影院| 亚洲亚洲精品在线观看| 色悠悠久久综合| 亚洲日本韩国一区| 91啪亚洲精品| 椎名由奈av一区二区三区| 国产91丝袜在线播放0| 久久久激情视频| 国产一区二区三区四| 久久亚洲精品国产精品紫薇| 国产一区二区三区日韩| 久久综合久久99| 国产原创一区二区三区| 久久婷婷一区二区三区| 狠狠色狠狠色综合系列| 亚洲精品一区二区三区在线观看| 国产一区二区免费看| 久久精品视频一区二区三区| 国产乱对白刺激视频不卡 | 国产a视频精品免费观看| 久久亚洲综合色| 国产成人综合在线| 国产精品理论片| 91美女福利视频| 亚洲一区二区三区在线看| 欧洲精品在线观看| 日韩av一区二区三区| 精品999在线播放| 国产高清亚洲一区| 亚洲色图欧美在线| 欧美日韩亚洲综合一区二区三区| 午夜视频在线观看一区二区三区| 制服丝袜一区二区三区| 国产在线精品免费av| 中文字幕巨乱亚洲| 在线视频你懂得一区| 日本v片在线高清不卡在线观看| 久久在线免费观看| 99精品视频中文字幕| 天天综合日日夜夜精品| 久久影院午夜论| 色综合天天综合色综合av | 欧美电影免费观看高清完整版在| 国产激情一区二区三区四区| 亚洲欧美色图小说| 日韩欧美一区二区不卡| 不卡在线观看av| 免费一级欧美片在线观看| 国产精品拍天天在线| 欧美精品在线一区二区| 国产91精品入口| 日韩福利视频网| 1区2区3区精品视频| 欧美一区二区人人喊爽| youjizz久久| 久久精品国产一区二区三| 亚洲精品少妇30p| 国产无一区二区| 91精品国产色综合久久ai换脸| 99精品视频一区二区三区| 韩国欧美国产一区| 亚洲成人先锋电影| 国产精品久久久久久久久快鸭| 日韩一区二区三区视频在线| 色美美综合视频| 成人做爰69片免费看网站| 国产**成人网毛片九色| 日韩成人伦理电影在线观看| 亚洲女爱视频在线| 日本一区二区免费在线观看视频| 日韩亚洲电影在线| 欧美精品 国产精品| 欧日韩精品视频| 99久久精品免费看国产免费软件| 乱一区二区av| 欧美96一区二区免费视频| 亚洲国产一区二区三区| 亚洲精品免费视频| 亚洲精品一二三区| 亚洲视频一区二区在线| 国产精品久久久久久亚洲毛片| 精品国产一区久久| 精品少妇一区二区三区日产乱码 | 秋霞午夜av一区二区三区| 亚洲色欲色欲www在线观看| 国产精品毛片a∨一区二区三区| 久久久久国产精品免费免费搜索| 2022国产精品视频| 久久综合九色欧美综合狠狠| 精品少妇一区二区三区日产乱码| 日韩视频一区在线观看| 欧美成人高清电影在线| 精品国产乱码久久久久久闺蜜 | 欧美电影免费观看完整版| 欧美一级高清片在线观看| 欧美一区二区三区免费大片| 欧美裸体bbwbbwbbw| 4438x成人网最大色成网站| 欧美一区二区三区在线电影| 日韩精品一区二区三区老鸭窝| 亚洲精品在线一区二区| 国产无一区二区| 亚洲图片激情小说| 亚洲一区二区三区激情| 日韩1区2区3区| 精品一区二区三区免费播放| 国产一区二区精品久久| 成人精品免费看| 色婷婷综合久久| 欧美一区中文字幕| 国产偷国产偷亚洲高清人白洁| 国产精品福利电影一区二区三区四区| 亚洲精品va在线观看| 麻豆一区二区三| youjizz久久| 欧美一区二区三区喷汁尤物| 日本一区二区在线不卡| 亚洲一区二区三区中文字幕在线| 久久精品免费看| 不卡一区在线观看| 在线不卡欧美精品一区二区三区| 精品日本一线二线三线不卡| 中文字幕一区在线观看| 日韩高清一区二区| 丰满少妇在线播放bd日韩电影| 欧美日韩国产片| 国产精品免费视频网站| 青青草视频一区| 91视视频在线直接观看在线看网页在线看 | 中文字幕一区二区三区四区不卡 |