]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
UBI: set correct gluebi device size
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Sat, 5 May 2007 13:33:13 +0000 (16:33 +0300)
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>
Wed, 18 Jul 2007 13:52:51 +0000 (16:52 +0300)
In case of static volumes, make emulated MTD device size to
be equivalent to data size, rather then volume size.

Reported-by: John Smith <john@arrows.demon.co.uk>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
drivers/mtd/ubi/cdev.c
drivers/mtd/ubi/gluebi.c
drivers/mtd/ubi/scan.c
drivers/mtd/ubi/ubi.h

index 6612eb79bf17b2fd7529ed9a4aba00e6a6060637..959044a2ddbffa0abfa7114a4b1b3b79a7ac7988 100644 (file)
@@ -397,6 +397,7 @@ static ssize_t vol_cdev_write(struct file *file, const char __user *buf,
                        vol->corrupted = 1;
                }
                vol->checked = 1;
+               ubi_gluebi_updated(vol);
                revoke_exclusive(desc, UBI_READWRITE);
        }
 
index fc9478d605ff134255e91f5834a3c6ba17eab122..41ff74c60e1483d7a25d70f5df7832d77c603cb8 100644 (file)
@@ -282,7 +282,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 +289,15 @@ 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, which is zero at this moment and will be changed after volume
+        * update.
+        */
+       if (vol->vol_type == UBI_DYNAMIC_VOLUME)
+               mtd->size = vol->usable_leb_size * vol->reserved_pebs;
+
        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;
+}
index 30d536ee10fcbb3009ac7cf43f7bf94192e14c13..197cd650356b474f1daf812966c1e697b30ee24c 100644 (file)
@@ -55,7 +55,7 @@ static int paranoid_check_si(const struct ubi_device *ubi,
 static struct ubi_ec_hdr *ech;
 static struct ubi_vid_hdr *vidh;
 
-/*
+/**
  * add_to_list - add physical eraseblock to a list.
  * @si: scanning information
  * @pnum: physical eraseblock number to add
index feb647f108f013a2b5c1753751688aae26a3e643..c26edea968182c6109a1de94fcbc6690eed75310 100644 (file)
@@ -374,9 +374,11 @@ void ubi_calculate_reserved(struct ubi_device *ubi);
 #ifdef CONFIG_MTD_UBI_GLUEBI
 int ubi_create_gluebi(struct ubi_device *ubi, struct ubi_volume *vol);
 int ubi_destroy_gluebi(struct ubi_volume *vol);
+void ubi_gluebi_updated(struct ubi_volume *vol);
 #else
 #define ubi_create_gluebi(ubi, vol) 0
 #define ubi_destroy_gluebi(vol) 0
+#define ubi_gluebi_updated(vol)
 #endif
 
 /* eba.c */