aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/mem.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/mem.c')
-rw-r--r--drivers/char/mem.c115
1 files changed, 45 insertions, 70 deletions
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index f96d0bef855e..afa8813e737a 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -863,59 +863,58 @@ static const struct file_operations kmsg_fops = {
863 .write = kmsg_write, 863 .write = kmsg_write,
864}; 864};
865 865
866static int memory_open(struct inode * inode, struct file * filp) 866static const struct {
867{ 867 unsigned int minor;
868 int ret = 0; 868 char *name;
869 869 umode_t mode;
870 lock_kernel(); 870 const struct file_operations *fops;
871 switch (iminor(inode)) { 871 struct backing_dev_info *dev_info;
872 case 1: 872} devlist[] = { /* list of minor devices */
873 filp->f_op = &mem_fops; 873 {1, "mem", S_IRUSR | S_IWUSR | S_IRGRP, &mem_fops,
874 filp->f_mapping->backing_dev_info = 874 &directly_mappable_cdev_bdi},
875 &directly_mappable_cdev_bdi;
876 break;
877#ifdef CONFIG_DEVKMEM 875#ifdef CONFIG_DEVKMEM
878 case 2: 876 {2, "kmem", S_IRUSR | S_IWUSR | S_IRGRP, &kmem_fops,
879 filp->f_op = &kmem_fops; 877 &directly_mappable_cdev_bdi},
880 filp->f_mapping->backing_dev_info =
881 &directly_mappable_cdev_bdi;
882 break;
883#endif 878#endif
884 case 3: 879 {3, "null", S_IRUGO | S_IWUGO, &null_fops, NULL},
885 filp->f_op = &null_fops;
886 break;
887#ifdef CONFIG_DEVPORT 880#ifdef CONFIG_DEVPORT
888 case 4: 881 {4, "port", S_IRUSR | S_IWUSR | S_IRGRP, &port_fops, NULL},
889 filp->f_op = &port_fops;
890 break;
891#endif 882#endif
892 case 5: 883 {5, "zero", S_IRUGO | S_IWUGO, &zero_fops, &zero_bdi},
893 filp->f_mapping->backing_dev_info = &zero_bdi; 884 {7, "full", S_IRUGO | S_IWUGO, &full_fops, NULL},
894 filp->f_op = &zero_fops; 885 {8, "random", S_IRUGO | S_IWUSR, &random_fops, NULL},
895 break; 886 {9, "urandom", S_IRUGO | S_IWUSR, &urandom_fops, NULL},
896 case 7: 887 {11,"kmsg", S_IRUGO | S_IWUSR, &kmsg_fops, NULL},
897 filp->f_op = &full_fops;
898 break;
899 case 8:
900 filp->f_op = &random_fops;
901 break;
902 case 9:
903 filp->f_op = &urandom_fops;
904 break;
905 case 11:
906 filp->f_op = &kmsg_fops;
907 break;
908#ifdef CONFIG_CRASH_DUMP 888#ifdef CONFIG_CRASH_DUMP
909 case 12: 889 {12,"oldmem", S_IRUSR | S_IWUSR | S_IRGRP, &oldmem_fops, NULL},
910 filp->f_op = &oldmem_fops;
911 break;
912#endif 890#endif
913 default: 891};
914 unlock_kernel(); 892
915 return -ENXIO; 893static int memory_open(struct inode *inode, struct file *filp)
894{
895 int ret = 0;
896 int i;
897
898 lock_kernel();
899
900 for (i = 0; i < ARRAY_SIZE(devlist); i++) {
901 if (devlist[i].minor == iminor(inode)) {
902 filp->f_op = devlist[i].fops;
903 if (devlist[i].dev_info) {
904 filp->f_mapping->backing_dev_info =
905 devlist[i].dev_info;
906 }
907
908 break;
909 }
916 } 910 }
917 if (filp->f_op && filp->f_op->open) 911
918 ret = filp->f_op->open(inode,filp); 912 if (i == ARRAY_SIZE(devlist))
913 ret = -ENXIO;
914 else
915 if (filp->f_op && filp->f_op->open)
916 ret = filp->f_op->open(inode, filp);
917
919 unlock_kernel(); 918 unlock_kernel();
920 return ret; 919 return ret;
921} 920}
@@ -924,30 +923,6 @@ static const struct file_operations memory_fops = {
924 .open = memory_open, /* just a selector for the real open */ 923 .open = memory_open, /* just a selector for the real open */
925}; 924};
926 925
927static const struct {
928 unsigned int minor;
929 char *name;
930 umode_t mode;
931 const struct file_operations *fops;
932} devlist[] = { /* list of minor devices */
933 {1, "mem", S_IRUSR | S_IWUSR | S_IRGRP, &mem_fops},
934#ifdef CONFIG_DEVKMEM
935 {2, "kmem", S_IRUSR | S_IWUSR | S_IRGRP, &kmem_fops},
936#endif
937 {3, "null", S_IRUGO | S_IWUGO, &null_fops},
938#ifdef CONFIG_DEVPORT
939 {4, "port", S_IRUSR | S_IWUSR | S_IRGRP, &port_fops},
940#endif
941 {5, "zero", S_IRUGO | S_IWUGO, &zero_fops},
942 {7, "full", S_IRUGO | S_IWUGO, &full_fops},
943 {8, "random", S_IRUGO | S_IWUSR, &random_fops},
944 {9, "urandom", S_IRUGO | S_IWUSR, &urandom_fops},
945 {11,"kmsg", S_IRUGO | S_IWUSR, &kmsg_fops},
946#ifdef CONFIG_CRASH_DUMP
947 {12,"oldmem", S_IRUSR | S_IWUSR | S_IRGRP, &oldmem_fops},
948#endif
949};
950
951static struct class *mem_class; 926static struct class *mem_class;
952 927
953static int __init chr_dev_init(void) 928static int __init chr_dev_init(void)