kernel: mtdsplit: modify rootfs helpers to provide partition type
authorRafał Miłecki <zajec5@gmail.com>
Mon, 1 Feb 2016 12:41:41 +0000 (12:41 +0000)
committerRafał Miłecki <zajec5@gmail.com>
Mon, 1 Feb 2016 12:41:41 +0000 (12:41 +0000)
Our mtdsplit parsers may want to create partition with name choice based
on partition file system (e.g. SquashFS vs. JFFS2). This patch allows
passing extra argument pointing to variable that will be set properly.

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
SVN-Revision: 48598

target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit.c
target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit.h
target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_brnimage.c
target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_eva.c
target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_fit.c
target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_lzma.c
target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_seama.c
target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_tplink.c
target/linux/generic/files/drivers/mtd/mtdsplit/mtdsplit_uimage.c

index 162739f..4f6b46e 100644 (file)
@@ -70,7 +70,8 @@ static ssize_t mtd_next_eb(struct mtd_info *mtd, size_t offset)
        return mtd_rounddown_to_eb(offset, mtd) + mtd->erasesize;
 }
 
-int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset)
+int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset,
+                          enum mtdsplit_part_type *type)
 {
        u32 magic;
        size_t retlen;
@@ -84,25 +85,32 @@ int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset)
        if (retlen != sizeof(magic))
                return -EIO;
 
-       if (le32_to_cpu(magic) != SQUASHFS_MAGIC &&
-           magic != 0x19852003)
-               return -EINVAL;
+       if (le32_to_cpu(magic) == SQUASHFS_MAGIC) {
+               if (type)
+                       *type = MTDSPLIT_PART_TYPE_SQUASHFS;
+               return 0;
+       } else if (magic == 0x19852003) {
+               if (type)
+                       *type = MTDSPLIT_PART_TYPE_JFFS2;
+               return 0;
+       }
 
-       return 0;
+       return -EINVAL;
 }
 EXPORT_SYMBOL_GPL(mtd_check_rootfs_magic);
 
 int mtd_find_rootfs_from(struct mtd_info *mtd,
                         size_t from,
                         size_t limit,
-                        size_t *ret_offset)
+                        size_t *ret_offset,
+                        enum mtdsplit_part_type *type)
 {
        size_t offset;
        int err;
 
        for (offset = from; offset < limit;
             offset = mtd_next_eb(mtd, offset)) {
-               err = mtd_check_rootfs_magic(mtd, offset);
+               err = mtd_check_rootfs_magic(mtd, offset, type);
                if (err)
                        continue;
 
index 7ee88b0..b757758 100644 (file)
 
 #define ROOTFS_SPLIT_NAME      "rootfs_data"
 
+enum mtdsplit_part_type {
+       MTDSPLIT_PART_TYPE_UNK = 0,
+       MTDSPLIT_PART_TYPE_SQUASHFS,
+       MTDSPLIT_PART_TYPE_JFFS2,
+};
+
 #ifdef CONFIG_MTD_SPLIT
 int mtd_get_squashfs_len(struct mtd_info *master,
                         size_t offset,
                         size_t *squashfs_len);
 
-int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset);
+int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset,
+                          enum mtdsplit_part_type *type);
 
 int mtd_find_rootfs_from(struct mtd_info *mtd,
                         size_t from,
                         size_t limit,
-                        size_t *ret_offset);
+                        size_t *ret_offset,
+                        enum mtdsplit_part_type *type);
 
 #else
 static inline int mtd_get_squashfs_len(struct mtd_info *master,
@@ -38,7 +46,8 @@ static inline int mtd_get_squashfs_len(struct mtd_info *master,
        return -ENODEV;
 }
 
-static inline int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset)
+static inline int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset,
+                                        enum mtdsplit_part_type *type)
 {
        return -EINVAL;
 }
@@ -46,7 +55,8 @@ static inline int mtd_check_rootfs_magic(struct mtd_info *mtd, size_t offset)
 static inline int mtd_find_rootfs_from(struct mtd_info *mtd,
                                       size_t from,
                                       size_t limit,
-                                      size_t *ret_offset)
+                                      size_t *ret_offset,
+                                      enum mtdsplit_part_type *type)
 {
        return -ENODEV;
 }
index 7ddd69b..c088772 100644 (file)
@@ -38,7 +38,7 @@ static int mtdsplit_parse_brnimage(struct mtd_info *master,
 
        for (rootfs_offset = 0; rootfs_offset < master->size;
             rootfs_offset += BRNIMAGE_ALIGN_BYTES) {
-               ret = mtd_check_rootfs_magic(master, rootfs_offset);
+               ret = mtd_check_rootfs_magic(master, rootfs_offset, NULL);
                if (!ret)
                        break;
        }
index d262e60..3edc104 100644 (file)
@@ -59,7 +59,7 @@ static int mtdsplit_parse_eva(struct mtd_info *master,
        if (rootfs_offset >= master->size)
                return -EINVAL;
 
-       err = mtd_check_rootfs_magic(master, rootfs_offset);
+       err = mtd_check_rootfs_magic(master, rootfs_offset, NULL);
        if (err)
                return err;
 
index d1087f6..5795406 100644 (file)
@@ -93,8 +93,8 @@ mtdsplit_fit_parse(struct mtd_info *mtd, struct mtd_partition **pparts,
        }
 
        /* Search for the rootfs partition after the FIT image */
-       ret = mtd_find_rootfs_from(mtd, fit_offset + fit_size,
-                                  mtd->size, &rootfs_offset);
+       ret = mtd_find_rootfs_from(mtd, fit_offset + fit_size, mtd->size,
+                                  &rootfs_offset, NULL);
        if (ret) {
                pr_info("no rootfs found after FIT image in \"%s\"\n",
                        mtd->name);
index 64dc7cb..f3d8c04 100644 (file)
@@ -58,8 +58,8 @@ static int mtdsplit_parse_lzma(struct mtd_info *master,
        if (t)
                return -EINVAL;
 
-       err = mtd_find_rootfs_from(master, master->erasesize,
-                                  master->size, &rootfs_offset);
+       err = mtd_find_rootfs_from(master, master->erasesize, master->size,
+                                  &rootfs_offset, NULL);
        if (err)
                return err;
 
index 4ff361c..228b899 100644 (file)
@@ -56,7 +56,7 @@ static int mtdsplit_parse_seama(struct mtd_info *master,
                return -EINVAL;
 
        /* Check for the rootfs right after Seama entity with a kernel. */
-       err = mtd_check_rootfs_magic(master, kernel_ent_size);
+       err = mtd_check_rootfs_magic(master, kernel_ent_size, NULL);
        if (!err) {
                rootfs_offset = kernel_ent_size;
        } else {
@@ -67,7 +67,7 @@ static int mtdsplit_parse_seama(struct mtd_info *master,
                 * Start the search from an arbitrary offset.
                 */
                err = mtd_find_rootfs_from(master, SEAMA_MIN_ROOTFS_OFFS,
-                                          master->size, &rootfs_offset);
+                                          master->size, &rootfs_offset, NULL);
                if (err)
                        return err;
        }
index 00c2d39..c65e60a 100644 (file)
@@ -122,7 +122,7 @@ static int mtdsplit_parse_tplink(struct mtd_info *master,
                return -EINVAL;
 
        /* Find the rootfs after the kernel. */
-       err = mtd_check_rootfs_magic(master, kernel_size);
+       err = mtd_check_rootfs_magic(master, kernel_size, NULL);
        if (!err) {
                rootfs_offset = kernel_size;
        } else {
@@ -131,7 +131,7 @@ static int mtdsplit_parse_tplink(struct mtd_info *master,
                 * Start the search from an arbitrary offset.
                 */
                err = mtd_find_rootfs_from(master, TPLINK_MIN_ROOTFS_OFFS,
-                                          master->size, &rootfs_offset);
+                                          master->size, &rootfs_offset, NULL);
                if (err)
                        return err;
        }
index b815869..c30ee6a 100644 (file)
@@ -147,10 +147,8 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master,
                rf_part = 1;
 
                /* find the roots after the uImage */
-               ret = mtd_find_rootfs_from(master,
-                                          uimage_offset + uimage_size,
-                                          master->size,
-                                          &rootfs_offset);
+               ret = mtd_find_rootfs_from(master, uimage_offset + uimage_size,
+                                          master->size, &rootfs_offset, NULL);
                if (ret) {
                        pr_debug("no rootfs after uImage in \"%s\"\n",
                                 master->name);
@@ -164,7 +162,7 @@ static int __mtdsplit_parse_uimage(struct mtd_info *master,
                uimage_part = 1;
 
                /* check rootfs presence at offset 0 */
-               ret = mtd_check_rootfs_magic(master, 0);
+               ret = mtd_check_rootfs_magic(master, 0, NULL);
                if (ret) {
                        pr_debug("no rootfs before uImage in \"%s\"\n",
                                 master->name);