root/fs/devices.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. register_chrdev
  2. register_blkdev
  3. blkdev_open
  4. chrdev_open

   1 /*
   2  *  linux/fs/devices.c
   3  *
   4  * (C) 1993 Matthias Urlichs -- collected common code and tables.
   5  * 
   6  *  Copyright (C) 1991, 1992  Linus Torvalds
   7  */
   8 
   9 #include <linux/fs.h>
  10 #include <linux/string.h>
  11 #include <linux/sched.h>
  12 #include <linux/ext_fs.h>
  13 #include <linux/tty.h>
  14 #include <linux/stat.h>
  15 #include <linux/fcntl.h>
  16 #include <linux/errno.h>
  17 
  18 struct file_operations * chrdev_fops[MAX_CHRDEV] = {
  19         NULL,
  20 };
  21 
  22 struct file_operations * blkdev_fops[MAX_BLKDEV] = {
  23         NULL,
  24 };
  25 
  26 int register_chrdev(unsigned int major, const char * name, struct file_operations *fops)
     /* [previous][next][first][last][top][bottom][index][help] */
  27 {
  28         if (major >= MAX_CHRDEV)
  29                 return -EINVAL;
  30         if (chrdev_fops[major])
  31                 return -EBUSY;
  32         chrdev_fops[major] = fops;
  33         return 0;
  34 }
  35 
  36 int register_blkdev(unsigned int major, const char * name, struct file_operations *fops)
     /* [previous][next][first][last][top][bottom][index][help] */
  37 {
  38         if (major >= MAX_BLKDEV)
  39                 return -EINVAL;
  40         if (blkdev_fops[major])
  41                 return -EBUSY;
  42         blkdev_fops[major] = fops;
  43         return 0;
  44 }
  45 
  46 /*
  47  * Called every time a block special file is opened
  48  */
  49 int blkdev_open(struct inode * inode, struct file * filp)
     /* [previous][next][first][last][top][bottom][index][help] */
  50 {
  51         int i;
  52 
  53         i = MAJOR(inode->i_rdev);
  54         if (i >= MAX_BLKDEV || !blkdev_fops[i])
  55                 return -ENODEV;
  56         filp->f_op = blkdev_fops[i];
  57         if (filp->f_op->open)
  58                 return filp->f_op->open(inode,filp);
  59         return 0;
  60 }       
  61 
  62 /*
  63  * Dummy default file-operations: the only thing this does
  64  * is contain the open that then fills in the correct operations
  65  * depending on the special file...
  66  */
  67 struct file_operations def_blk_fops = {
  68         NULL,           /* lseek */
  69         NULL,           /* read */
  70         NULL,           /* write */
  71         NULL,           /* readdir */
  72         NULL,           /* select */
  73         NULL,           /* ioctl */
  74         NULL,           /* mmap */
  75         blkdev_open,    /* open */
  76         NULL,           /* release */
  77 };
  78 
  79 struct inode_operations blkdev_inode_operations = {
  80         &def_blk_fops,          /* default file operations */
  81         NULL,                   /* create */
  82         NULL,                   /* lookup */
  83         NULL,                   /* link */
  84         NULL,                   /* unlink */
  85         NULL,                   /* symlink */
  86         NULL,                   /* mkdir */
  87         NULL,                   /* rmdir */
  88         NULL,                   /* mknod */
  89         NULL,                   /* rename */
  90         NULL,                   /* readlink */
  91         NULL,                   /* follow_link */
  92         NULL,                   /* bmap */
  93         NULL,                   /* truncate */
  94         NULL                    /* permission */
  95 };
  96 
  97 /*
  98  * Called every time a character special file is opened
  99  */
 100 int chrdev_open(struct inode * inode, struct file * filp)
     /* [previous][next][first][last][top][bottom][index][help] */
 101 {
 102         int i;
 103 
 104         i = MAJOR(inode->i_rdev);
 105         if (i >= MAX_CHRDEV || !chrdev_fops[i])
 106                 return -ENODEV;
 107         filp->f_op = chrdev_fops[i];
 108         if (filp->f_op->open)
 109                 return filp->f_op->open(inode,filp);
 110         return 0;
 111 }
 112 
 113 /*
 114  * Dummy default file-operations: the only thing this does
 115  * is contain the open that then fills in the correct operations
 116  * depending on the special file...
 117  */
 118 struct file_operations def_chr_fops = {
 119         NULL,           /* lseek */
 120         NULL,           /* read */
 121         NULL,           /* write */
 122         NULL,           /* readdir */
 123         NULL,           /* select */
 124         NULL,           /* ioctl */
 125         NULL,           /* mmap */
 126         chrdev_open,    /* open */
 127         NULL,           /* release */
 128 };
 129 
 130 struct inode_operations chrdev_inode_operations = {
 131         &def_chr_fops,          /* default file operations */
 132         NULL,                   /* create */
 133         NULL,                   /* lookup */
 134         NULL,                   /* link */
 135         NULL,                   /* unlink */
 136         NULL,                   /* symlink */
 137         NULL,                   /* mkdir */
 138         NULL,                   /* rmdir */
 139         NULL,                   /* mknod */
 140         NULL,                   /* rename */
 141         NULL,                   /* readlink */
 142         NULL,                   /* follow_link */
 143         NULL,                   /* bmap */
 144         NULL,                   /* truncate */
 145         NULL                    /* permission */
 146 };

/* [previous][next][first][last][top][bottom][index][help] */