summaryrefslogtreecommitdiff
path: root/target/linux/generic/patches-3.13/555-gluebi-sysfs-support.patch
diff options
context:
space:
mode:
authorblogic <blogic@3c298f89-4303-0410-b956-a3cf2f4a3e73>2014-03-30 09:15:20 +0000
committerblogic <blogic@3c298f89-4303-0410-b956-a3cf2f4a3e73>2014-03-30 09:15:20 +0000
commit28eb3d8241120d32cf059fe08d3f0fc8561e05eb (patch)
tree1d7b912db4d285ac19fd959dd1faf5d0e36983e3 /target/linux/generic/patches-3.13/555-gluebi-sysfs-support.patch
parent8e18623ac9b4f934edb5ffa100ff7d4fd7843421 (diff)
kernel: export gluebi info to sysfs
Export the ubi_num and vol_id into the sysfs record of the gluebi- emulated mtd device. Previously userspace didn't have a way to map gluebi-emulated devices back to their corresponding ubi volumes. git-svn-id: svn://svn.openwrt.org/openwrt/trunk@40306 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'target/linux/generic/patches-3.13/555-gluebi-sysfs-support.patch')
-rw-r--r--target/linux/generic/patches-3.13/555-gluebi-sysfs-support.patch88
1 files changed, 88 insertions, 0 deletions
diff --git a/target/linux/generic/patches-3.13/555-gluebi-sysfs-support.patch b/target/linux/generic/patches-3.13/555-gluebi-sysfs-support.patch
new file mode 100644
index 0000000000..91817ba1e8
--- /dev/null
+++ b/target/linux/generic/patches-3.13/555-gluebi-sysfs-support.patch
@@ -0,0 +1,88 @@
+Index: linux-3.13.2/drivers/mtd/ubi/gluebi.c
+===================================================================
+--- linux-3.13.2.orig/drivers/mtd/ubi/gluebi.c
++++ linux-3.13.2/drivers/mtd/ubi/gluebi.c
+@@ -38,6 +38,7 @@
+ #include <linux/mutex.h>
+ #include <linux/mtd/ubi.h>
+ #include <linux/mtd/mtd.h>
++#include <linux/export.h>
+ #include "ubi-media.h"
+
+ #define err_msg(fmt, ...) \
+@@ -66,6 +67,16 @@ struct gluebi_device {
+ static LIST_HEAD(gluebi_devices);
+ static DEFINE_MUTEX(devices_mutex);
+
++/* Device attribute handler for gluebi files in '/<sysfs>/class/mtd/mtdX' */
++static ssize_t gluebi_attribute_show(struct device *dev,
++ struct device_attribute *attr, char *buf);
++
++/* Device attributes corresponding to files in '/<sysfs>/class/mtd/mtdX' */
++static struct device_attribute attr_vol_gluebi_ubi_num =
++__ATTR(gluebi_ubi_num, S_IRUGO, gluebi_attribute_show, NULL);
++static struct device_attribute attr_vol_gluebi_vol_id =
++__ATTR(gluebi_vol_id, S_IRUGO, gluebi_attribute_show, NULL);
++
+ /**
+ * find_gluebi_nolock - find a gluebi device.
+ * @ubi_num: UBI device number
+@@ -288,6 +299,36 @@ out_err:
+ }
+
+ /**
++ * gluebi_attribute_show - "Show" method for gluebi files in sysfs.
++ */
++static ssize_t gluebi_attribute_show(struct device *dev,
++ struct device_attribute *attr, char *buf)
++{
++ int ret;
++ struct mtd_info *mtd = container_of(dev, struct mtd_info, dev);
++ struct gluebi_device *gluebi;
++
++ gluebi_get_device(mtd);
++ gluebi = container_of(mtd, struct gluebi_device, mtd);
++
++ /* This really shouldn't happen */
++ if (!gluebi)
++ return -ENODEV;
++
++ if (attr == &attr_vol_gluebi_ubi_num) {
++ ret = sprintf(buf, "%u\n", gluebi->ubi_num);
++ } else if (attr == &attr_vol_gluebi_vol_id) {
++ ret = sprintf(buf, "%u\n", gluebi->vol_id);
++ } else {
++ /* This must be a bug */
++ ret = -EINVAL;
++ }
++
++ gluebi_put_device(mtd);
++ return ret;
++}
++
++/**
+ * gluebi_create - create a gluebi device for an UBI volume.
+ * @di: UBI device description object
+ * @vi: UBI volume description object
+@@ -355,6 +396,8 @@ static int gluebi_create(struct ubi_devi
+ mutex_lock(&devices_mutex);
+ list_add_tail(&gluebi->list, &gluebi_devices);
+ mutex_unlock(&devices_mutex);
++ device_create_file(&mtd->dev, &attr_vol_gluebi_ubi_num);
++ device_create_file(&mtd->dev, &attr_vol_gluebi_vol_id);
+ return 0;
+ }
+
+@@ -380,8 +423,11 @@ static int gluebi_remove(struct ubi_volu
+ err = -ENOENT;
+ } else if (gluebi->refcnt)
+ err = -EBUSY;
+- else
++ else {
++ device_remove_file(&gluebi->mtd.dev, &attr_vol_gluebi_ubi_num);
++ device_remove_file(&gluebi->mtd.dev, &attr_vol_gluebi_vol_id);
+ list_del(&gluebi->list);
++ }
+ mutex_unlock(&devices_mutex);
+ if (err)
+ return err;