]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/linux/linux-mtx-1-2.4.27/11-mtd-proc-partition-rw.diff
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / linux / linux-mtx-1-2.4.27 / 11-mtd-proc-partition-rw.diff
1 diff -Nurb linux/drivers/mtd/mtdcore.c linux-mtd-rw/drivers/mtd/mtdcore.c
2 --- linux/drivers/mtd/mtdcore.c 2004-11-18 13:16:00.000000000 +0100
3 +++ linux-mtd-rw/drivers/mtd/mtdcore.c  2004-11-18 15:27:13.130036616 +0100
4 @@ -25,6 +25,10 @@
5  
6  #include <linux/mtd/mtd.h>
7  
8 +/* this symbol is exported by the procfs. */
9 +extern struct proc_dir_entry *proc_sys_root;
10 +
11 +
12  /* These are exported solely for the purpose of mtd_blkdevs.c. You 
13     should not use them for _anything_ else */
14  DECLARE_MUTEX(mtd_table_mutex);
15 @@ -336,8 +340,83 @@
16  
17  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
18  static struct proc_dir_entry *proc_mtd;
19 +
20 +static struct proc_dir_entry *proc_sys_mtd;
21 +static struct proc_dir_entry *proc_sys_mtd_partition[MAX_MTD_DEVICES];
22 +static struct proc_dir_entry *proc_sys_mtd_partition_rw[MAX_MTD_DEVICES];
23  #endif
24  
25 +/*===================================0
26 + * mtdproc_read_partition_access
27 + */
28 +static int mtdproc_read_partition_access ( char *page, char **start, off_t off,int count,
29 +                                          int *eof, void *data
30 +                                          )
31 +{
32 +  int partid = (unsigned int)data;
33 +  int len = 0;
34 +
35 +  // NO RETURN FROM HERE UNTIL "up(&mtd_table_mutex)".
36 +  down(&mtd_table_mutex);
37 +
38 +  if (partid < MAX_MTD_DEVICES)
39 +  {
40 +    struct mtd_info *this = mtd_table[partid];
41 +    if (this)
42 +      {
43 +       page[len] = (this->flags & MTD_WRITEABLE) ? '1' : '0';
44 +       len++;
45 +      }
46 +  }
47 +  
48 +  up(&mtd_table_mutex);
49 +
50 +  if (off >= len)
51 +    return 0;
52 +  *start = page + off;
53 +  return ((count < len-off) ? count : len-off);
54 +}
55 +
56 +
57 +static int mtdproc_write_partition_access (struct file *file, const char *buffer,
58 +                                          unsigned long count, void *data)
59 +{
60 +  int partid = (unsigned int)data;
61 +  int len = 0;
62 +
63 +  // NO RETURN FROM HERE UNTIL "up(&mtd_table_mutex)".
64 +  down(&mtd_table_mutex);
65 +
66 +  if (partid < MAX_MTD_DEVICES)
67 +  {
68 +    struct mtd_info *this = mtd_table[partid];
69 +    if (this && count > 0)
70 +      {
71 +       switch (*buffer)
72 +         {
73 +         case '0':
74 +           this->flags &= ~(this->master_flags & MTD_WRITEABLE);
75 +           break;
76 +
77 +         case '1':
78 +           this->flags |= ~(this->master_flags & MTD_WRITEABLE);
79 +           break;
80 +
81 +         default:
82 +           break;
83 +         }
84 +      }
85 +  }
86 +  
87 +  up(&mtd_table_mutex);
88 +
89 +  return count;
90 +}
91 +
92 +
93 +
94 +
95 +
96  static inline int mtd_proc_info (char *buf, int i)
97  {
98         struct mtd_info *this = mtd_table[i];
99 @@ -349,6 +428,7 @@
100                        this->erasesize, this->name);
101  }
102  
103 +
104  static int mtd_read_proc ( char *page, char **start, off_t off,int count
105  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
106                         ,int *eof, void *data_unused
107 @@ -404,12 +484,31 @@
108  /*====================================================================*/
109  /* Init code */
110  
111 +
112  int __init init_mtd(void)
113  {
114  #ifdef CONFIG_PROC_FS
115  #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
116 +       int i;
117 +
118         if ((proc_mtd = create_proc_entry( "mtd", 0, 0 )))
119           proc_mtd->read_proc = mtd_read_proc;
120 +
121 +       proc_sys_mtd = proc_mkdir("mtd", proc_sys_root);
122 +       for (i=0; i<MAX_MTD_DEVICES; i++)
123 +         {
124 +           char partname[10];
125 +           sprintf (partname, "%d", i);
126 +
127 +           proc_sys_mtd_partition[i] = proc_mkdir(partname, proc_sys_mtd);
128 +           proc_sys_mtd_partition_rw[i] = create_proc_entry ("rw", S_IFREG | S_IRUGO, proc_sys_mtd_partition[i]);
129 +           if (proc_sys_mtd_partition_rw[i])
130 +            {
131 +              proc_sys_mtd_partition_rw[i]->read_proc  = mtdproc_read_partition_access;
132 +             proc_sys_mtd_partition_rw[i]->write_proc = mtdproc_write_partition_access;
133 +             proc_sys_mtd_partition_rw[i]->data = (void *)i;
134 +            }
135 +         }
136  #else
137          proc_register_dynamic(&proc_root,&mtd_proc_entry);
138  #endif
139 @@ -425,6 +524,8 @@
140         return 0;
141  }
142  
143 +
144 +
145  static void __exit cleanup_mtd(void)
146  {
147  #ifdef CONFIG_PM
148 diff -Nurb linux/drivers/mtd/mtdpart.c linux-mtd-rw/drivers/mtd/mtdpart.c
149 --- linux/drivers/mtd/mtdpart.c 2004-11-18 13:16:00.000000000 +0100
150 +++ linux-mtd-rw/drivers/mtd/mtdpart.c  2004-11-18 15:27:13.131036464 +0100
151 @@ -341,6 +341,9 @@
152                 /* set up the MTD object for this partition */
153                 slave->mtd.type = master->type;
154                 slave->mtd.flags = master->flags & ~parts[i].mask_flags;
155 +               slave->mtd.master_flags = master->flags;
156 +               slave->mtd.mask_flags = parts[i].mask_flags;
157 +
158                 slave->mtd.size = parts[i].size;
159                 slave->mtd.oobblock = master->oobblock;
160                 slave->mtd.oobsize = master->oobsize;
161 diff -Nurb linux/include/linux/mtd/mtd.h linux-mtd-rw/include/linux/mtd/mtd.h
162 --- linux/include/linux/mtd/mtd.h       2004-11-18 13:16:31.000000000 +0100
163 +++ linux-mtd-rw/include/linux/mtd/mtd.h        2004-11-18 15:27:13.000000000 +0100
164 @@ -232,6 +232,9 @@
165  
166         struct module *owner;
167         int usecount;
168 +
169 +       u_int32_t master_flags;
170 +       u_int32_t mask_flags;
171  };
172  
173