Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Direct MTD block device access |
| 3 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * (C) 2000-2003 Nicolas Pitre <nico@cam.org> |
| 5 | * (C) 1999-2003 David Woodhouse <dwmw2@infradead.org> |
| 6 | */ |
| 7 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/fs.h> |
| 9 | #include <linux/init.h> |
Thomas Gleixner | 15fdc52 | 2005-11-07 00:14:42 +0100 | [diff] [blame] | 10 | #include <linux/kernel.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <linux/slab.h> |
Thomas Gleixner | 15fdc52 | 2005-11-07 00:14:42 +0100 | [diff] [blame] | 14 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/vmalloc.h> |
Thomas Gleixner | 15fdc52 | 2005-11-07 00:14:42 +0100 | [diff] [blame] | 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/mtd/mtd.h> |
| 18 | #include <linux/mtd/blktrans.h> |
Ingo Molnar | 48b1926 | 2006-03-31 02:29:41 -0800 | [diff] [blame] | 19 | #include <linux/mutex.h> |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
| 22 | static struct mtdblk_dev { |
| 23 | struct mtd_info *mtd; |
| 24 | int count; |
Ingo Molnar | 48b1926 | 2006-03-31 02:29:41 -0800 | [diff] [blame] | 25 | struct mutex cache_mutex; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | unsigned char *cache_data; |
| 27 | unsigned long cache_offset; |
| 28 | unsigned int cache_size; |
| 29 | enum { STATE_EMPTY, STATE_CLEAN, STATE_DIRTY } cache_state; |
| 30 | } *mtdblks[MAX_MTD_DEVICES]; |
| 31 | |
| 32 | /* |
| 33 | * Cache stuff... |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 34 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | * Since typical flash erasable sectors are much larger than what Linux's |
| 36 | * buffer cache can handle, we must implement read-modify-write on flash |
| 37 | * sectors for each block write requests. To avoid over-erasing flash sectors |
| 38 | * and to speed things up, we locally cache a whole flash sector while it is |
| 39 | * being written to until a different sector is required. |
| 40 | */ |
| 41 | |
| 42 | static void erase_callback(struct erase_info *done) |
| 43 | { |
| 44 | wait_queue_head_t *wait_q = (wait_queue_head_t *)done->priv; |
| 45 | wake_up(wait_q); |
| 46 | } |
| 47 | |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 48 | static int erase_write (struct mtd_info *mtd, unsigned long pos, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | int len, const char *buf) |
| 50 | { |
| 51 | struct erase_info erase; |
| 52 | DECLARE_WAITQUEUE(wait, current); |
| 53 | wait_queue_head_t wait_q; |
| 54 | size_t retlen; |
| 55 | int ret; |
| 56 | |
| 57 | /* |
| 58 | * First, let's erase the flash block. |
| 59 | */ |
| 60 | |
| 61 | init_waitqueue_head(&wait_q); |
| 62 | erase.mtd = mtd; |
| 63 | erase.callback = erase_callback; |
| 64 | erase.addr = pos; |
| 65 | erase.len = len; |
| 66 | erase.priv = (u_long)&wait_q; |
| 67 | |
| 68 | set_current_state(TASK_INTERRUPTIBLE); |
| 69 | add_wait_queue(&wait_q, &wait); |
| 70 | |
Thomas Gleixner | f4a43cf | 2006-05-28 11:01:53 +0200 | [diff] [blame] | 71 | ret = mtd->erase(mtd, &erase); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | if (ret) { |
| 73 | set_current_state(TASK_RUNNING); |
| 74 | remove_wait_queue(&wait_q, &wait); |
| 75 | printk (KERN_WARNING "mtdblock: erase of region [0x%lx, 0x%x] " |
| 76 | "on \"%s\" failed\n", |
| 77 | pos, len, mtd->name); |
| 78 | return ret; |
| 79 | } |
| 80 | |
| 81 | schedule(); /* Wait for erase to finish. */ |
| 82 | remove_wait_queue(&wait_q, &wait); |
| 83 | |
| 84 | /* |
| 85 | * Next, writhe data to flash. |
| 86 | */ |
| 87 | |
Thomas Gleixner | f4a43cf | 2006-05-28 11:01:53 +0200 | [diff] [blame] | 88 | ret = mtd->write(mtd, pos, len, &retlen, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | if (ret) |
| 90 | return ret; |
| 91 | if (retlen != len) |
| 92 | return -EIO; |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | |
| 97 | static int write_cached_data (struct mtdblk_dev *mtdblk) |
| 98 | { |
| 99 | struct mtd_info *mtd = mtdblk->mtd; |
| 100 | int ret; |
| 101 | |
| 102 | if (mtdblk->cache_state != STATE_DIRTY) |
| 103 | return 0; |
| 104 | |
| 105 | DEBUG(MTD_DEBUG_LEVEL2, "mtdblock: writing cached data for \"%s\" " |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 106 | "at 0x%lx, size 0x%x\n", mtd->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | mtdblk->cache_offset, mtdblk->cache_size); |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 108 | |
| 109 | ret = erase_write (mtd, mtdblk->cache_offset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | mtdblk->cache_size, mtdblk->cache_data); |
| 111 | if (ret) |
| 112 | return ret; |
| 113 | |
| 114 | /* |
| 115 | * Here we could argubly set the cache state to STATE_CLEAN. |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 116 | * However this could lead to inconsistency since we will not |
| 117 | * be notified if this content is altered on the flash by other |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | * means. Let's declare it empty and leave buffering tasks to |
| 119 | * the buffer cache instead. |
| 120 | */ |
| 121 | mtdblk->cache_state = STATE_EMPTY; |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 126 | static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | int len, const char *buf) |
| 128 | { |
| 129 | struct mtd_info *mtd = mtdblk->mtd; |
| 130 | unsigned int sect_size = mtdblk->cache_size; |
| 131 | size_t retlen; |
| 132 | int ret; |
| 133 | |
| 134 | DEBUG(MTD_DEBUG_LEVEL2, "mtdblock: write on \"%s\" at 0x%lx, size 0x%x\n", |
| 135 | mtd->name, pos, len); |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | if (!sect_size) |
Thomas Gleixner | f4a43cf | 2006-05-28 11:01:53 +0200 | [diff] [blame] | 138 | return mtd->write(mtd, pos, len, &retlen, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
| 140 | while (len > 0) { |
| 141 | unsigned long sect_start = (pos/sect_size)*sect_size; |
| 142 | unsigned int offset = pos - sect_start; |
| 143 | unsigned int size = sect_size - offset; |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 144 | if( size > len ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | size = len; |
| 146 | |
| 147 | if (size == sect_size) { |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 148 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | * We are covering a whole sector. Thus there is no |
| 150 | * need to bother with the cache while it may still be |
| 151 | * useful for other partial writes. |
| 152 | */ |
| 153 | ret = erase_write (mtd, pos, size, buf); |
| 154 | if (ret) |
| 155 | return ret; |
| 156 | } else { |
| 157 | /* Partial sector: need to use the cache */ |
| 158 | |
| 159 | if (mtdblk->cache_state == STATE_DIRTY && |
| 160 | mtdblk->cache_offset != sect_start) { |
| 161 | ret = write_cached_data(mtdblk); |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 162 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | return ret; |
| 164 | } |
| 165 | |
| 166 | if (mtdblk->cache_state == STATE_EMPTY || |
| 167 | mtdblk->cache_offset != sect_start) { |
| 168 | /* fill the cache with the current sector */ |
| 169 | mtdblk->cache_state = STATE_EMPTY; |
Thomas Gleixner | f4a43cf | 2006-05-28 11:01:53 +0200 | [diff] [blame] | 170 | ret = mtd->read(mtd, sect_start, sect_size, |
| 171 | &retlen, mtdblk->cache_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | if (ret) |
| 173 | return ret; |
| 174 | if (retlen != sect_size) |
| 175 | return -EIO; |
| 176 | |
| 177 | mtdblk->cache_offset = sect_start; |
| 178 | mtdblk->cache_size = sect_size; |
| 179 | mtdblk->cache_state = STATE_CLEAN; |
| 180 | } |
| 181 | |
| 182 | /* write data to our local cache */ |
| 183 | memcpy (mtdblk->cache_data + offset, buf, size); |
| 184 | mtdblk->cache_state = STATE_DIRTY; |
| 185 | } |
| 186 | |
| 187 | buf += size; |
| 188 | pos += size; |
| 189 | len -= size; |
| 190 | } |
| 191 | |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 196 | static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | int len, char *buf) |
| 198 | { |
| 199 | struct mtd_info *mtd = mtdblk->mtd; |
| 200 | unsigned int sect_size = mtdblk->cache_size; |
| 201 | size_t retlen; |
| 202 | int ret; |
| 203 | |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 204 | DEBUG(MTD_DEBUG_LEVEL2, "mtdblock: read on \"%s\" at 0x%lx, size 0x%x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | mtd->name, pos, len); |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | if (!sect_size) |
Thomas Gleixner | f4a43cf | 2006-05-28 11:01:53 +0200 | [diff] [blame] | 208 | return mtd->read(mtd, pos, len, &retlen, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
| 210 | while (len > 0) { |
| 211 | unsigned long sect_start = (pos/sect_size)*sect_size; |
| 212 | unsigned int offset = pos - sect_start; |
| 213 | unsigned int size = sect_size - offset; |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 214 | if (size > len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | size = len; |
| 216 | |
| 217 | /* |
| 218 | * Check if the requested data is already cached |
| 219 | * Read the requested amount of data from our internal cache if it |
| 220 | * contains what we want, otherwise we read the data directly |
| 221 | * from flash. |
| 222 | */ |
| 223 | if (mtdblk->cache_state != STATE_EMPTY && |
| 224 | mtdblk->cache_offset == sect_start) { |
| 225 | memcpy (buf, mtdblk->cache_data + offset, size); |
| 226 | } else { |
Thomas Gleixner | f4a43cf | 2006-05-28 11:01:53 +0200 | [diff] [blame] | 227 | ret = mtd->read(mtd, pos, size, &retlen, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | if (ret) |
| 229 | return ret; |
| 230 | if (retlen != size) |
| 231 | return -EIO; |
| 232 | } |
| 233 | |
| 234 | buf += size; |
| 235 | pos += size; |
| 236 | len -= size; |
| 237 | } |
| 238 | |
| 239 | return 0; |
| 240 | } |
| 241 | |
| 242 | static int mtdblock_readsect(struct mtd_blktrans_dev *dev, |
| 243 | unsigned long block, char *buf) |
| 244 | { |
| 245 | struct mtdblk_dev *mtdblk = mtdblks[dev->devnum]; |
| 246 | return do_cached_read(mtdblk, block<<9, 512, buf); |
| 247 | } |
| 248 | |
| 249 | static int mtdblock_writesect(struct mtd_blktrans_dev *dev, |
| 250 | unsigned long block, char *buf) |
| 251 | { |
| 252 | struct mtdblk_dev *mtdblk = mtdblks[dev->devnum]; |
| 253 | if (unlikely(!mtdblk->cache_data && mtdblk->cache_size)) { |
| 254 | mtdblk->cache_data = vmalloc(mtdblk->mtd->erasesize); |
| 255 | if (!mtdblk->cache_data) |
| 256 | return -EINTR; |
| 257 | /* -EINTR is not really correct, but it is the best match |
| 258 | * documented in man 2 write for all cases. We could also |
| 259 | * return -EAGAIN sometimes, but why bother? |
| 260 | */ |
| 261 | } |
| 262 | return do_cached_write(mtdblk, block<<9, 512, buf); |
| 263 | } |
| 264 | |
| 265 | static int mtdblock_open(struct mtd_blktrans_dev *mbd) |
| 266 | { |
| 267 | struct mtdblk_dev *mtdblk; |
| 268 | struct mtd_info *mtd = mbd->mtd; |
| 269 | int dev = mbd->devnum; |
| 270 | |
| 271 | DEBUG(MTD_DEBUG_LEVEL1,"mtdblock_open\n"); |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 272 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | if (mtdblks[dev]) { |
| 274 | mtdblks[dev]->count++; |
| 275 | return 0; |
| 276 | } |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | /* OK, it's not open. Create cache info for it */ |
Burman Yan | 95b93a0 | 2006-11-15 21:10:29 +0200 | [diff] [blame] | 279 | mtdblk = kzalloc(sizeof(struct mtdblk_dev), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | if (!mtdblk) |
| 281 | return -ENOMEM; |
| 282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | mtdblk->count = 1; |
| 284 | mtdblk->mtd = mtd; |
| 285 | |
Ingo Molnar | 48b1926 | 2006-03-31 02:29:41 -0800 | [diff] [blame] | 286 | mutex_init(&mtdblk->cache_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | mtdblk->cache_state = STATE_EMPTY; |
Joern Engel | 92cbfdc | 2006-05-30 14:25:24 +0200 | [diff] [blame] | 288 | if ( !(mtdblk->mtd->flags & MTD_NO_ERASE) && mtdblk->mtd->erasesize) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | mtdblk->cache_size = mtdblk->mtd->erasesize; |
| 290 | mtdblk->cache_data = NULL; |
| 291 | } |
| 292 | |
| 293 | mtdblks[dev] = mtdblk; |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 294 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | DEBUG(MTD_DEBUG_LEVEL1, "ok\n"); |
| 296 | |
| 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | static int mtdblock_release(struct mtd_blktrans_dev *mbd) |
| 301 | { |
| 302 | int dev = mbd->devnum; |
| 303 | struct mtdblk_dev *mtdblk = mtdblks[dev]; |
| 304 | |
| 305 | DEBUG(MTD_DEBUG_LEVEL1, "mtdblock_release\n"); |
| 306 | |
Ingo Molnar | 48b1926 | 2006-03-31 02:29:41 -0800 | [diff] [blame] | 307 | mutex_lock(&mtdblk->cache_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | write_cached_data(mtdblk); |
Ingo Molnar | 48b1926 | 2006-03-31 02:29:41 -0800 | [diff] [blame] | 309 | mutex_unlock(&mtdblk->cache_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
| 311 | if (!--mtdblk->count) { |
| 312 | /* It was the last usage. Free the device */ |
| 313 | mtdblks[dev] = NULL; |
| 314 | if (mtdblk->mtd->sync) |
| 315 | mtdblk->mtd->sync(mtdblk->mtd); |
| 316 | vfree(mtdblk->cache_data); |
| 317 | kfree(mtdblk); |
| 318 | } |
| 319 | DEBUG(MTD_DEBUG_LEVEL1, "ok\n"); |
| 320 | |
| 321 | return 0; |
Thomas Gleixner | 97894cd | 2005-11-07 11:15:26 +0000 | [diff] [blame] | 322 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
| 324 | static int mtdblock_flush(struct mtd_blktrans_dev *dev) |
| 325 | { |
| 326 | struct mtdblk_dev *mtdblk = mtdblks[dev->devnum]; |
| 327 | |
Ingo Molnar | 48b1926 | 2006-03-31 02:29:41 -0800 | [diff] [blame] | 328 | mutex_lock(&mtdblk->cache_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | write_cached_data(mtdblk); |
Ingo Molnar | 48b1926 | 2006-03-31 02:29:41 -0800 | [diff] [blame] | 330 | mutex_unlock(&mtdblk->cache_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
| 332 | if (mtdblk->mtd->sync) |
| 333 | mtdblk->mtd->sync(mtdblk->mtd); |
| 334 | return 0; |
| 335 | } |
| 336 | |
| 337 | static void mtdblock_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) |
| 338 | { |
Burman Yan | 95b93a0 | 2006-11-15 21:10:29 +0200 | [diff] [blame] | 339 | struct mtd_blktrans_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
| 341 | if (!dev) |
| 342 | return; |
| 343 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | dev->mtd = mtd; |
| 345 | dev->devnum = mtd->index; |
Richard Purdie | 1918767 | 2006-10-27 09:09:33 +0100 | [diff] [blame] | 346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | dev->size = mtd->size >> 9; |
| 348 | dev->tr = tr; |
| 349 | |
| 350 | if (!(mtd->flags & MTD_WRITEABLE)) |
| 351 | dev->readonly = 1; |
| 352 | |
| 353 | add_mtd_blktrans_dev(dev); |
| 354 | } |
| 355 | |
| 356 | static void mtdblock_remove_dev(struct mtd_blktrans_dev *dev) |
| 357 | { |
| 358 | del_mtd_blktrans_dev(dev); |
| 359 | kfree(dev); |
| 360 | } |
| 361 | |
| 362 | static struct mtd_blktrans_ops mtdblock_tr = { |
| 363 | .name = "mtdblock", |
| 364 | .major = 31, |
| 365 | .part_bits = 0, |
Richard Purdie | 1918767 | 2006-10-27 09:09:33 +0100 | [diff] [blame] | 366 | .blksize = 512, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | .open = mtdblock_open, |
| 368 | .flush = mtdblock_flush, |
| 369 | .release = mtdblock_release, |
| 370 | .readsect = mtdblock_readsect, |
| 371 | .writesect = mtdblock_writesect, |
| 372 | .add_mtd = mtdblock_add_mtd, |
| 373 | .remove_dev = mtdblock_remove_dev, |
| 374 | .owner = THIS_MODULE, |
| 375 | }; |
| 376 | |
| 377 | static int __init init_mtdblock(void) |
| 378 | { |
| 379 | return register_mtd_blktrans(&mtdblock_tr); |
| 380 | } |
| 381 | |
| 382 | static void __exit cleanup_mtdblock(void) |
| 383 | { |
| 384 | deregister_mtd_blktrans(&mtdblock_tr); |
| 385 | } |
| 386 | |
| 387 | module_init(init_mtdblock); |
| 388 | module_exit(cleanup_mtdblock); |
| 389 | |
| 390 | |
| 391 | MODULE_LICENSE("GPL"); |
| 392 | MODULE_AUTHOR("Nicolas Pitre <nico@cam.org> et al."); |
| 393 | MODULE_DESCRIPTION("Caching read/erase/writeback block device emulation access to MTD devices"); |