]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/mtd/ubi/gluebi.c
Merge branch 'merge' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc
[linux-2.6-omap-h63xx.git] / drivers / mtd / ubi / gluebi.c
index fc9478d605ff134255e91f5834a3c6ba17eab122..e909b390069a263e63d5d80a9a8bdf239644fb9f 100644 (file)
@@ -129,8 +129,7 @@ static int gluebi_read(struct mtd_info *mtd, loff_t from, size_t len,
                if (to_read > total_read)
                        to_read = total_read;
 
-               err = ubi_eba_read_leb(ubi, vol->vol_id, lnum, buf, offs,
-                                      to_read, 0);
+               err = ubi_eba_read_leb(ubi, vol, lnum, buf, offs, to_read, 0);
                if (err)
                        break;
 
@@ -187,8 +186,8 @@ static int gluebi_write(struct mtd_info *mtd, loff_t to, size_t len,
                if (to_write > total_written)
                        to_write = total_written;
 
-               err = ubi_eba_write_leb(ubi, vol->vol_id, lnum, buf, offs,
-                                       to_write, UBI_UNKNOWN);
+               err = ubi_eba_write_leb(ubi, vol, lnum, buf, offs, to_write,
+                                       UBI_UNKNOWN);
                if (err)
                        break;
 
@@ -237,7 +236,7 @@ static int gluebi_erase(struct mtd_info *mtd, struct erase_info *instr)
                return -EROFS;
 
        for (i = 0; i < count; i++) {
-               err = ubi_eba_unmap_leb(ubi, vol->vol_id, lnum + i);
+               err = ubi_eba_unmap_leb(ubi, vol, lnum + i);
                if (err)
                        goto out_err;
        }
@@ -282,7 +281,6 @@ int ubi_create_gluebi(struct ubi_device *ubi, struct ubi_volume *vol)
                mtd->flags = MTD_WRITEABLE;
        mtd->writesize  = ubi->min_io_size;
        mtd->owner      = THIS_MODULE;
-       mtd->size       = vol->usable_leb_size * vol->reserved_pebs;
        mtd->erasesize  = vol->usable_leb_size;
        mtd->read       = gluebi_read;
        mtd->write      = gluebi_write;
@@ -290,6 +288,16 @@ int ubi_create_gluebi(struct ubi_device *ubi, struct ubi_volume *vol)
        mtd->get_device = gluebi_get_device;
        mtd->put_device = gluebi_put_device;
 
+       /*
+        * In case of dynamic volume, MTD device size is just volume size. In
+        * case of a static volume the size is equivalent to the amount of data
+        * bytes.
+        */
+       if (vol->vol_type == UBI_DYNAMIC_VOLUME)
+               mtd->size = vol->usable_leb_size * vol->reserved_pebs;
+       else
+               mtd->size = vol->used_bytes;
+
        if (add_mtd_device(mtd)) {
                ubi_err("cannot not add MTD device\n");
                kfree(mtd->name);
@@ -321,3 +329,20 @@ int ubi_destroy_gluebi(struct ubi_volume *vol)
        kfree(mtd->name);
        return 0;
 }
+
+/**
+ * ubi_gluebi_updated - UBI volume was updated notifier.
+ * @vol: volume description object
+ *
+ * This function is called every time an UBI volume is updated. This function
+ * does nothing if volume @vol is dynamic, and changes MTD device size if the
+ * volume is static. This is needed because static volumes cannot be read past
+ * data they contain.
+ */
+void ubi_gluebi_updated(struct ubi_volume *vol)
+{
+       struct mtd_info *mtd = &vol->gluebi_mtd;
+
+       if (vol->vol_type == UBI_STATIC_VOLUME)
+               mtd->size = vol->used_bytes;
+}