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 162739f472e929378f7a5e72cc441787e8668211..4f6b46e28b93e04e9fbd3f0940008eb28cbcc206 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 7ee88b0bb47b11ceef9e279a13a609955b79ceec..b75775868585526acc68220f879bcdd1e7b3bfed 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 7ddd69b7b70ccc5c35711e06b99671f9013e9734..c0887722d7466915617eac561f185d2e69e12fe3 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 d262e6083ecc0f1d862bd8cddbb60ee97f1b7240..3edc104f4e901ac234356b73146d94ad40da7f8c 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 d1087f62469cb17744185595e1e8432e82a76ad2..57954061cdc7d07a6f1fd998db2ebc05bc09d663 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 64dc7cb31cbcd17501e0f1869ccced93f9ed769a..f3d8c040c21b81e80f211234927e9a5594730f88 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 4ff361c4f25dfec7a8f53b614b1cdda6515c4eec..228b8997ad7e09cd7c8a37638fbceb8750bdd816 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 00c2d39a811eb6adb88d7b2ecca56f4a8cd24819..c65e60a3e2a1a1716f63ae2f09a4ebbb8575cd67 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 b815869a6b1bc77fa42b5a0f87f527d077300c85..c30ee6ad74113d564738b068e83cd6b219c72cb3 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);