Lines Matching full:mtd

9  * This is a small driver which implements fake MTD devices on top of UBI
11 * MTD-oriented software (including all the legacy software) work on top of
14 * Gluebi emulates MTD devices of "MTD_UBIVOLUME" type. Their minimal I/O unit
15 * size (@mtd->writesize) is equivalent to the UBI minimal I/O unit. The
26 #include <linux/mtd/ubi.h>
27 #include <linux/mtd/mtd.h>
36 * @mtd: emulated MTD device description object
44 struct mtd_info mtd; member
77 * gluebi_get_device - get MTD device reference.
78 * @mtd: the MTD device description object
80 * This function is called every time the MTD device is being opened and
81 * implements the MTD get_device() operation. Returns zero in case of success
84 static int gluebi_get_device(struct mtd_info *mtd) in gluebi_get_device() argument
89 if (mtd->flags & MTD_WRITEABLE) in gluebi_get_device()
92 gluebi = container_of(mtd, struct gluebi_device, mtd); in gluebi_get_device()
96 * The MTD device is already referenced and this is just one in gluebi_get_device()
97 * more reference. MTD allows many users to open the same in gluebi_get_device()
109 * This is the first reference to this UBI volume via the MTD device in gluebi_get_device()
124 * gluebi_put_device - put MTD device reference.
125 * @mtd: the MTD device description object
127 * This function is called every time the MTD device is being put. Returns
130 static void gluebi_put_device(struct mtd_info *mtd) in gluebi_put_device() argument
134 gluebi = container_of(mtd, struct gluebi_device, mtd); in gluebi_put_device()
143 * gluebi_read - read operation of emulated MTD devices.
144 * @mtd: MTD device description object
153 static int gluebi_read(struct mtd_info *mtd, loff_t from, size_t len, in gluebi_read() argument
159 gluebi = container_of(mtd, struct gluebi_device, mtd); in gluebi_read()
160 lnum = div_u64_rem(from, mtd->erasesize, &offs); in gluebi_read()
163 size_t to_read = mtd->erasesize - offs; in gluebi_read()
183 * gluebi_write - write operation of emulated MTD devices.
184 * @mtd: MTD device description object
193 static int gluebi_write(struct mtd_info *mtd, loff_t to, size_t len, in gluebi_write() argument
199 gluebi = container_of(mtd, struct gluebi_device, mtd); in gluebi_write()
200 lnum = div_u64_rem(to, mtd->erasesize, &offs); in gluebi_write()
202 if (len % mtd->writesize || offs % mtd->writesize) in gluebi_write()
207 size_t to_write = mtd->erasesize - offs; in gluebi_write()
227 * gluebi_erase - erase operation of emulated MTD devices.
228 * @mtd: the MTD device description object
234 static int gluebi_erase(struct mtd_info *mtd, struct erase_info *instr) in gluebi_erase() argument
239 if (mtd_mod_by_ws(instr->addr, mtd) || mtd_mod_by_ws(instr->len, mtd)) in gluebi_erase()
242 lnum = mtd_div_by_eb(instr->addr, mtd); in gluebi_erase()
243 count = mtd_div_by_eb(instr->len, mtd); in gluebi_erase()
244 gluebi = container_of(mtd, struct gluebi_device, mtd); in gluebi_erase()
252 * MTD erase operations are synchronous, so we have to make sure the in gluebi_erase()
265 instr->fail_addr = (long long)lnum * mtd->erasesize; in gluebi_erase()
275 * corresponding fake MTD device. Returns zero in case of success and a
282 struct mtd_info *mtd; in gluebi_create() local
288 mtd = &gluebi->mtd; in gluebi_create()
289 mtd->name = kmemdup(vi->name, vi->name_len + 1, GFP_KERNEL); in gluebi_create()
290 if (!mtd->name) { in gluebi_create()
297 mtd->type = MTD_UBIVOLUME; in gluebi_create()
299 mtd->flags = MTD_WRITEABLE; in gluebi_create()
300 mtd->owner = THIS_MODULE; in gluebi_create()
301 mtd->writesize = di->min_io_size; in gluebi_create()
302 mtd->erasesize = vi->usable_leb_size; in gluebi_create()
303 mtd->_read = gluebi_read; in gluebi_create()
304 mtd->_write = gluebi_write; in gluebi_create()
305 mtd->_erase = gluebi_erase; in gluebi_create()
306 mtd->_get_device = gluebi_get_device; in gluebi_create()
307 mtd->_put_device = gluebi_put_device; in gluebi_create()
310 * In case of dynamic a volume, MTD device size is just volume size. In in gluebi_create()
315 mtd->size = (unsigned long long)vi->usable_leb_size * vi->size; in gluebi_create()
317 mtd->size = vi->used_bytes; in gluebi_create()
323 err_msg("gluebi MTD device %d form UBI device %d volume %d already exists", in gluebi_create()
324 g->mtd.index, vi->ubi_num, vi->vol_id); in gluebi_create()
327 if (mtd_device_register(mtd, NULL, 0)) { in gluebi_create()
328 err_msg("cannot add MTD device"); in gluebi_create()
329 kfree(mtd->name); in gluebi_create()
345 * corresponding fake MTD device. Returns zero in case of success and a
351 struct mtd_info *mtd; in gluebi_remove() local
368 mtd = &gluebi->mtd; in gluebi_remove()
369 err = mtd_device_unregister(mtd); in gluebi_remove()
371 err_msg("cannot remove fake MTD device %d, UBI device %d, volume %d, error %d", in gluebi_remove()
372 mtd->index, gluebi->ubi_num, gluebi->vol_id, err); in gluebi_remove()
379 kfree(mtd->name); in gluebi_remove()
389 * if te volume @vol is dynamic, and changes MTD device size if the
408 gluebi->mtd.size = vi->used_bytes; in gluebi_updated()
418 * corresponding fake MTD device size. This function returns zero in case of
433 gluebi->mtd.size = vi->used_bytes; in gluebi_resized()
483 struct mtd_info *mtd = &gluebi->mtd; in ubi_gluebi_exit() local
485 err = mtd_device_unregister(mtd); in ubi_gluebi_exit()
487 err_msg("error %d while removing gluebi MTD device %d, UBI device %d, volume %d - ignoring", in ubi_gluebi_exit()
488 err, mtd->index, gluebi->ubi_num, in ubi_gluebi_exit()
490 kfree(mtd->name); in ubi_gluebi_exit()
498 MODULE_DESCRIPTION("MTD emulation layer over UBI volumes");