1 --- a/drivers/mtd/ubi/gluebi.c
2 +++ b/drivers/mtd/ubi/gluebi.c
4 #include <linux/mutex.h>
5 #include <linux/mtd/ubi.h>
6 #include <linux/mtd/mtd.h>
7 +#include <linux/export.h>
10 #define err_msg(fmt, ...) \
11 @@ -66,6 +67,16 @@ struct gluebi_device {
12 static LIST_HEAD(gluebi_devices);
13 static DEFINE_MUTEX(devices_mutex);
15 +/* Device attribute handler for gluebi files in '/<sysfs>/class/mtd/mtdX' */
16 +static ssize_t gluebi_attribute_show(struct device *dev,
17 + struct device_attribute *attr, char *buf);
19 +/* Device attributes corresponding to files in '/<sysfs>/class/mtd/mtdX' */
20 +static struct device_attribute attr_vol_gluebi_ubi_num =
21 +__ATTR(gluebi_ubi_num, S_IRUGO, gluebi_attribute_show, NULL);
22 +static struct device_attribute attr_vol_gluebi_vol_id =
23 +__ATTR(gluebi_vol_id, S_IRUGO, gluebi_attribute_show, NULL);
26 * find_gluebi_nolock - find a gluebi device.
27 * @ubi_num: UBI device number
28 @@ -288,6 +299,36 @@ out_err:
32 + * gluebi_attribute_show - "Show" method for gluebi files in sysfs.
34 +static ssize_t gluebi_attribute_show(struct device *dev,
35 + struct device_attribute *attr, char *buf)
38 + struct mtd_info *mtd = container_of(dev, struct mtd_info, dev);
39 + struct gluebi_device *gluebi;
41 + gluebi_get_device(mtd);
42 + gluebi = container_of(mtd, struct gluebi_device, mtd);
44 + /* This really shouldn't happen */
48 + if (attr == &attr_vol_gluebi_ubi_num) {
49 + ret = sprintf(buf, "%u\n", gluebi->ubi_num);
50 + } else if (attr == &attr_vol_gluebi_vol_id) {
51 + ret = sprintf(buf, "%u\n", gluebi->vol_id);
53 + /* This must be a bug */
57 + gluebi_put_device(mtd);
62 * gluebi_create - create a gluebi device for an UBI volume.
63 * @di: UBI device description object
64 * @vi: UBI volume description object
65 @@ -355,6 +396,8 @@ static int gluebi_create(struct ubi_devi
66 mutex_lock(&devices_mutex);
67 list_add_tail(&gluebi->list, &gluebi_devices);
68 mutex_unlock(&devices_mutex);
69 + device_create_file(&mtd->dev, &attr_vol_gluebi_ubi_num);
70 + device_create_file(&mtd->dev, &attr_vol_gluebi_vol_id);
74 @@ -380,8 +423,11 @@ static int gluebi_remove(struct ubi_volu
76 } else if (gluebi->refcnt)
80 + device_remove_file(&gluebi->mtd.dev, &attr_vol_gluebi_ubi_num);
81 + device_remove_file(&gluebi->mtd.dev, &attr_vol_gluebi_vol_id);
82 list_del(&gluebi->list);
84 mutex_unlock(&devices_mutex);