diff options
author | Gabor Juhos <juhosg@openwrt.org> | 2013-09-21 17:55:44 +0000 |
---|---|---|
committer | Gabor Juhos <juhosg@openwrt.org> | 2013-09-21 17:55:44 +0000 |
commit | d89bea92b31b4e157a0fa438e75370f089f73427 (patch) | |
tree | f36cc78f4f16c0d477f124d102d614d4f8f120d6 /target/linux/generic/files/drivers | |
parent | 3b71cd94bc9517bc25267dccb393b07d4b54564e (diff) | |
download | mtk-20170518-d89bea92b31b4e157a0fa438e75370f089f73427.zip mtk-20170518-d89bea92b31b4e157a0fa438e75370f089f73427.tar.gz mtk-20170518-d89bea92b31b4e157a0fa438e75370f089f73427.tar.bz2 |
kernel/3.10: move squashfs check from rootfs split code into a separate file
Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
SVN-Revision: 38109
Diffstat (limited to 'target/linux/generic/files/drivers')
-rw-r--r-- | target/linux/generic/files/drivers/mtd/mtdsplit.c | 66 | ||||
-rw-r--r-- | target/linux/generic/files/drivers/mtd/mtdsplit.h | 31 |
2 files changed, 97 insertions, 0 deletions
diff --git a/target/linux/generic/files/drivers/mtd/mtdsplit.c b/target/linux/generic/files/drivers/mtd/mtdsplit.c new file mode 100644 index 0000000..0ba35fe --- /dev/null +++ b/target/linux/generic/files/drivers/mtd/mtdsplit.c @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2009-2013 Felix Fietkau <nbd@openwrt.org> + * Copyright (C) 2009-2013 Gabor Juhos <juhosg@openwrt.org> + * Copyright (C) 2012 Jonas Gorski <jogo@openwrt.org> + * Copyright (C) 2013 Hauke Mehrtens <hauke@hauke-m.de> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + * + */ + +#define pr_fmt(fmt) "mtdsplit: " fmt + +#include <linux/export.h> +#include <linux/init.h> +#include <linux/kernel.h> +#include <linux/magic.h> +#include <linux/mtd/mtd.h> +#include <linux/mtd/partitions.h> +#include <linux/byteorder/generic.h> + +#include "mtdsplit.h" + +struct squashfs_super_block { + __le32 s_magic; + __le32 pad0[9]; + __le64 bytes_used; +}; + +int mtd_get_squashfs_len(struct mtd_info *master, + size_t offset, + size_t *squashfs_len) +{ + struct squashfs_super_block sb; + size_t retlen; + int err; + + err = mtd_read(master, offset, sizeof(sb), &retlen, (void *)&sb); + if (err || (retlen != sizeof(sb))) { + pr_alert("error occured while reading from \"%s\"\n", + master->name); + return -EIO; + } + + if (le32_to_cpu(sb.s_magic) != SQUASHFS_MAGIC) { + pr_alert("no squashfs found in \"%s\"\n", master->name); + return -EINVAL; + } + + retlen = le64_to_cpu(sb.bytes_used); + if (retlen <= 0) { + pr_alert("squashfs is empty in \"%s\"\n", master->name); + return -ENODEV; + } + + if (offset + retlen > master->size) { + pr_alert("squashfs has invalid size in \"%s\"\n", + master->name); + return -EINVAL; + } + + *squashfs_len = retlen; + return 0; +} +EXPORT_SYMBOL_GPL(mtd_get_squashfs_len); diff --git a/target/linux/generic/files/drivers/mtd/mtdsplit.h b/target/linux/generic/files/drivers/mtd/mtdsplit.h new file mode 100644 index 0000000..8ba6c8b --- /dev/null +++ b/target/linux/generic/files/drivers/mtd/mtdsplit.h @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2009-2013 Felix Fietkau <nbd@openwrt.org> + * Copyright (C) 2009-2013 Gabor Juhos <juhosg@openwrt.org> + * Copyright (C) 2012 Jonas Gorski <jogo@openwrt.org> + * Copyright (C) 2013 Hauke Mehrtens <hauke@hauke-m.de> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published + * by the Free Software Foundation. + * + */ + +#ifndef _MTDSPLIT_H +#define _MTDSPLIT_H + +#define ROOTFS_SPLIT_NAME "rootfs_data" + +#ifdef CONFIG_MTD_SPLIT +int mtd_get_squashfs_len(struct mtd_info *master, + size_t offset, + size_t *squashfs_len); +#else +static inline int mtd_get_squashfs_len(struct mtd_info *master, + size_t offset, + size_t *squashfs_len) +{ + return -ENODEV; +} +#endif + +#endif /* _MTDSPLIT_H */ |