aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Ehrenberg <dehrenberg@chromium.org>2015-04-02 18:15:11 -0400
committerBrian Norris <computersforpeace@gmail.com>2015-04-05 20:44:02 -0400
commita62c24d75529118d10c45350c3b75715d52ff574 (patch)
tree6c18ffa557b84ff94dd6dedce302a556766decf7
parent727dc612c46b8f3858537ea23805b3e897cf127e (diff)
mtd: part: Add sysfs variable for offset of partition
This patch makes a sysfs variable called 'offset' on each partition which contains the offset in bytes from the beginning of the master device that the partition starts. Signed-off-by: Dan Ehrenberg <dehrenberg@chromium.org> Signed-off-by: Brian Norris <computersforpeace@gmail.com>
-rw-r--r--Documentation/ABI/testing/sysfs-class-mtd10
-rw-r--r--drivers/mtd/mtdpart.c29
2 files changed, 39 insertions, 0 deletions
diff --git a/Documentation/ABI/testing/sysfs-class-mtd b/Documentation/ABI/testing/sysfs-class-mtd
index 76ee192f80a0..3b5c3bca9186 100644
--- a/Documentation/ABI/testing/sysfs-class-mtd
+++ b/Documentation/ABI/testing/sysfs-class-mtd
@@ -222,3 +222,13 @@ Description:
222 The number of blocks that are marked as reserved, if any, in 222 The number of blocks that are marked as reserved, if any, in
223 this partition. These are typically used to store the in-flash 223 this partition. These are typically used to store the in-flash
224 bad block table (BBT). 224 bad block table (BBT).
225
226What: /sys/class/mtd/mtdX/offset
227Date: March 2015
228KernelVersion: 4.1
229Contact: linux-mtd@lists.infradead.org
230Description:
231 For a partition, the offset of that partition from the start
232 of the master device in bytes. This attribute is absent on
233 main devices, so it can be used to distinguish between
234 partitions and devices that aren't partitions.
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index a19ec5a4e409..be8034086701 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -554,6 +554,30 @@ out_register:
554 return slave; 554 return slave;
555} 555}
556 556
557static ssize_t mtd_partition_offset_show(struct device *dev,
558 struct device_attribute *attr, char *buf)
559{
560 struct mtd_info *mtd = dev_get_drvdata(dev);
561 struct mtd_part *part = PART(mtd);
562 return snprintf(buf, PAGE_SIZE, "%lld\n", part->offset);
563}
564
565static DEVICE_ATTR(offset, S_IRUGO, mtd_partition_offset_show, NULL);
566
567static const struct attribute *mtd_partition_attrs[] = {
568 &dev_attr_offset.attr,
569 NULL
570};
571
572static int mtd_add_partition_attrs(struct mtd_part *new)
573{
574 int ret = sysfs_create_files(&new->mtd.dev.kobj, mtd_partition_attrs);
575 if (ret)
576 printk(KERN_WARNING
577 "mtd: failed to create partition attrs, err=%d\n", ret);
578 return ret;
579}
580
557int mtd_add_partition(struct mtd_info *master, const char *name, 581int mtd_add_partition(struct mtd_info *master, const char *name,
558 long long offset, long long length) 582 long long offset, long long length)
559{ 583{
@@ -603,6 +627,8 @@ int mtd_add_partition(struct mtd_info *master, const char *name,
603 627
604 add_mtd_device(&new->mtd); 628 add_mtd_device(&new->mtd);
605 629
630 mtd_add_partition_attrs(new);
631
606 return ret; 632 return ret;
607err_inv: 633err_inv:
608 mutex_unlock(&mtd_partitions_mutex); 634 mutex_unlock(&mtd_partitions_mutex);
@@ -620,6 +646,8 @@ int mtd_del_partition(struct mtd_info *master, int partno)
620 list_for_each_entry_safe(slave, next, &mtd_partitions, list) 646 list_for_each_entry_safe(slave, next, &mtd_partitions, list)
621 if ((slave->master == master) && 647 if ((slave->master == master) &&
622 (slave->mtd.index == partno)) { 648 (slave->mtd.index == partno)) {
649 sysfs_remove_files(&slave->mtd.dev.kobj,
650 mtd_partition_attrs);
623 ret = del_mtd_device(&slave->mtd); 651 ret = del_mtd_device(&slave->mtd);
624 if (ret < 0) 652 if (ret < 0)
625 break; 653 break;
@@ -663,6 +691,7 @@ int add_mtd_partitions(struct mtd_info *master,
663 mutex_unlock(&mtd_partitions_mutex); 691 mutex_unlock(&mtd_partitions_mutex);
664 692
665 add_mtd_device(&slave->mtd); 693 add_mtd_device(&slave->mtd);
694 mtd_add_partition_attrs(slave);
666 695
667 cur_offset = slave->offset + slave->mtd.size; 696 cur_offset = slave->offset + slave->mtd.size;
668 } 697 }