Lines Matching refs:mtdblk

136 static int write_cached_data (struct mtdblk_dev *mtdblk)  in write_cached_data()  argument
138 struct mtd_info *mtd = mtdblk->mtd; in write_cached_data()
141 if (mtdblk->cache_state != STATE_DIRTY) in write_cached_data()
146 mtdblk->cache_offset, mtdblk->cache_size); in write_cached_data()
148 ret = erase_write (mtd, mtdblk->cache_offset, in write_cached_data()
149 mtdblk->cache_size, mtdblk->cache_data); in write_cached_data()
160 mtdblk->cache_state = STATE_EMPTY; in write_cached_data()
165 static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos, in do_cached_write() argument
168 struct mtd_info *mtd = mtdblk->mtd; in do_cached_write()
169 unsigned int sect_size = mtdblk->cache_size; in do_cached_write()
198 if (mtdblk->cache_state == STATE_DIRTY && in do_cached_write()
199 mtdblk->cache_offset != sect_start) { in do_cached_write()
200 ret = write_cached_data(mtdblk); in do_cached_write()
205 if (mtdblk->cache_state == STATE_EMPTY || in do_cached_write()
206 mtdblk->cache_offset != sect_start) { in do_cached_write()
208 mtdblk->cache_state = STATE_EMPTY; in do_cached_write()
209 ret = MTD_READ(mtd, sect_start, sect_size, &retlen, mtdblk->cache_data); in do_cached_write()
215 mtdblk->cache_offset = sect_start; in do_cached_write()
216 mtdblk->cache_size = sect_size; in do_cached_write()
217 mtdblk->cache_state = STATE_CLEAN; in do_cached_write()
221 memcpy (mtdblk->cache_data + offset, buf, size); in do_cached_write()
222 mtdblk->cache_state = STATE_DIRTY; in do_cached_write()
234 static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos, in do_cached_read() argument
237 struct mtd_info *mtd = mtdblk->mtd; in do_cached_read()
238 unsigned int sect_size = mtdblk->cache_size; in do_cached_read()
261 if (mtdblk->cache_state != STATE_EMPTY && in do_cached_read()
262 mtdblk->cache_offset == sect_start) { in do_cached_read()
263 memcpy (buf, mtdblk->cache_data + offset, size); in do_cached_read()
284 struct mtdblk_dev *mtdblk; in mtdblock_open() local
325 mtdblk = kmalloc(sizeof(struct mtdblk_dev), GFP_KERNEL); in mtdblock_open()
326 if (!mtdblk) { in mtdblock_open()
331 memset(mtdblk, 0, sizeof(*mtdblk)); in mtdblock_open()
332 mtdblk->count = 1; in mtdblock_open()
333 mtdblk->mtd = mtd; in mtdblock_open()
335 init_MUTEX (&mtdblk->cache_sem); in mtdblock_open()
336 mtdblk->cache_state = STATE_EMPTY; in mtdblock_open()
337 if ((mtdblk->mtd->flags & MTD_CAP_RAM) != MTD_CAP_RAM && in mtdblock_open()
338 mtdblk->mtd->erasesize) { in mtdblock_open()
339 mtdblk->cache_size = mtdblk->mtd->erasesize; in mtdblock_open()
340 mtdblk->cache_data = vmalloc(mtdblk->mtd->erasesize); in mtdblock_open()
341 if (!mtdblk->cache_data) { in mtdblock_open()
342 put_mtd_device(mtdblk->mtd); in mtdblock_open()
343 kfree(mtdblk); in mtdblock_open()
357 put_mtd_device(mtdblk->mtd); in mtdblock_open()
358 vfree(mtdblk->cache_data); in mtdblock_open()
359 kfree(mtdblk); in mtdblock_open()
363 mtdblks[dev] = mtdblk; in mtdblock_open()
364 mtd_sizes[dev] = mtdblk->mtd->size/1024; in mtdblock_open()
365 if (mtdblk->mtd->erasesize) in mtdblock_open()
366 mtd_blksizes[dev] = mtdblk->mtd->erasesize; in mtdblock_open()
369 set_device_ro (inode->i_rdev, !(mtdblk->mtd->flags & MTD_WRITEABLE)); in mtdblock_open()
381 struct mtdblk_dev *mtdblk; in mtdblock_release() local
388 mtdblk = mtdblks[dev]; in mtdblock_release()
390 down(&mtdblk->cache_sem); in mtdblock_release()
391 write_cached_data(mtdblk); in mtdblock_release()
392 up(&mtdblk->cache_sem); in mtdblock_release()
395 if (!--mtdblk->count) { in mtdblock_release()
399 if (mtdblk->mtd->sync) in mtdblock_release()
400 mtdblk->mtd->sync(mtdblk->mtd); in mtdblock_release()
401 put_mtd_device(mtdblk->mtd); in mtdblock_release()
402 vfree(mtdblk->cache_data); in mtdblock_release()
403 kfree(mtdblk); in mtdblock_release()
425 struct mtdblk_dev *mtdblk; in handle_mtdblock_request() local
432 mtdblk = mtdblks[MINOR(req->rq_dev)]; in handle_mtdblock_request()
438 if ((req->sector + req->current_nr_sectors) > (mtdblk->mtd->size >> 9)) in handle_mtdblock_request()
447 down(&mtdblk->cache_sem); in handle_mtdblock_request()
448 err = do_cached_read (mtdblk, req->sector << 9, in handle_mtdblock_request()
451 up(&mtdblk->cache_sem); in handle_mtdblock_request()
458 if ( !(mtdblk->mtd->flags & MTD_WRITEABLE) ) in handle_mtdblock_request()
462 down(&mtdblk->cache_sem); in handle_mtdblock_request()
463 err = do_cached_write (mtdblk, req->sector << 9, in handle_mtdblock_request()
466 up(&mtdblk->cache_sem); in handle_mtdblock_request()
532 struct mtdblk_dev *mtdblk; in mtdblock_ioctl() local
534 mtdblk = mtdblks[MINOR(inode->i_rdev)]; in mtdblock_ioctl()
537 if (!mtdblk) in mtdblock_ioctl()
543 return put_user((mtdblk->mtd->size >> 9), (unsigned long *) arg); in mtdblock_ioctl()
547 return put_user((u64)mtdblk->mtd->size, (u64 *)arg); in mtdblock_ioctl()
557 down(&mtdblk->cache_sem); in mtdblock_ioctl()
558 write_cached_data(mtdblk); in mtdblock_ioctl()
559 up(&mtdblk->cache_sem); in mtdblock_ioctl()
560 if (mtdblk->mtd->sync) in mtdblock_ioctl()
561 mtdblk->mtd->sync(mtdblk->mtd); in mtdblock_ioctl()