33 #include <linux/list.h>
34 #include <linux/slab.h>
35 #include <linux/sched.h>
37 #include <linux/module.h>
43 #define err_msg(fmt, ...) \
44 pr_err("gluebi (pid %d): %s: " fmt "\n", \
45 current->pid, __func__, ##__VA_ARGS__)
84 if (gluebi->ubi_num == ubi_num && gluebi->vol_id == vol_id)
130 if (IS_ERR(gluebi->
desc)) {
133 return PTR_ERR(gluebi->
desc);
147 static void gluebi_put_device(
struct mtd_info *mtd)
171 static int gluebi_read(
struct mtd_info *mtd, loff_t
from,
size_t len,
172 size_t *retlen,
unsigned char *
buf)
174 int err = 0, lnum,
offs, total_read;
178 lnum = div_u64_rem(from, mtd->
erasesize, &offs);
183 if (to_read > total_read)
184 to_read = total_read;
186 err = ubi_read(gluebi->
desc, lnum, buf, offs, to_read);
192 total_read -= to_read;
196 *retlen = len - total_read;
211 static int gluebi_write(
struct mtd_info *mtd, loff_t to,
size_t len,
212 size_t *retlen,
const u_char *buf)
214 int err = 0, lnum,
offs, total_written;
218 lnum = div_u64_rem(to, mtd->
erasesize, &offs);
224 while (total_written) {
227 if (to_write > total_written)
228 to_write = total_written;
236 total_written -= to_write;
240 *retlen = len - total_written;
257 if (mtd_mod_by_ws(instr->
addr, mtd) || mtd_mod_by_ws(instr->
len, mtd))
260 lnum = mtd_div_by_eb(instr->
addr, mtd);
261 count = mtd_div_by_eb(instr->
len, mtd);
264 for (i = 0; i < count - 1; i++) {
324 mtd->
_read = gluebi_read;
325 mtd->
_write = gluebi_write;
326 mtd->
_erase = gluebi_erase;
344 err_msg(
"gluebi MTD device %d form UBI device %d volume %d already exists",
349 err_msg(
"cannot add MTD device");
378 err_msg(
"got remove notification for unknown UBI device %d volume %d",
381 }
else if (gluebi->
refcnt)
392 err_msg(
"cannot remove fake MTD device %d, UBI device %d, volume %d, error %d",
423 err_msg(
"got update notification for unknown UBI device %d volume %d",
450 err_msg(
"got update notification for unknown UBI device %d volume %d",
472 gluebi_create(&nt->
di, &nt->
vi);
475 gluebi_remove(&nt->
vi);
478 gluebi_resized(&nt->
vi);
481 gluebi_updated(&nt->
vi);
490 .notifier_call = gluebi_notify,
493 static int __init ubi_gluebi_init(
void)
498 static void __exit ubi_gluebi_exit(
void)
508 err_msg(
"error %d while removing gluebi MTD device %d, UBI device %d, volume %d - ignoring",