From: Colin Cross Date: Wed, 7 Apr 2010 19:05:32 +0000 (-0700) Subject: fs: partitions: Add support for named partitions X-Git-Tag: firefly_0821_release~9833^2~5^2~132 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=4cc08cf96b436a6e38a0b0259241d9636a957dc5;p=firefly-linux-kernel-4.4.55.git fs: partitions: Add support for named partitions Adds a new file in /sys/block// called partition_name that contains the name of the partition, if specified by the partition handler. Change-Id: I6648ed95eabefd1d00edbfdfd99eeb971d15f4b3 Signed-off-by: Colin Cross --- diff --git a/fs/partitions/check.c b/fs/partitions/check.c index 77e420c0d2c0..dba7af33ea3a 100644 --- a/fs/partitions/check.c +++ b/fs/partitions/check.c @@ -286,6 +286,13 @@ ssize_t part_inflight_show(struct device *dev, return sprintf(buf, "%8u %8u\n", p->in_flight[0], p->in_flight[1]); } +ssize_t part_partition_name_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct hd_struct *p = dev_to_part(dev); + return sprintf(buf, "%s\n", p->partition_name); +} + #ifdef CONFIG_FAIL_MAKE_REQUEST ssize_t part_fail_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -317,6 +324,8 @@ static DEVICE_ATTR(discard_alignment, S_IRUGO, part_discard_alignment_show, NULL); static DEVICE_ATTR(stat, S_IRUGO, part_stat_show, NULL); static DEVICE_ATTR(inflight, S_IRUGO, part_inflight_show, NULL); +static DEVICE_ATTR(partition_name, S_IRUGO, part_partition_name_show, NULL); + #ifdef CONFIG_FAIL_MAKE_REQUEST static struct device_attribute dev_attr_fail = __ATTR(make-it-fail, S_IRUGO|S_IWUSR, part_fail_show, part_fail_store); @@ -330,6 +339,7 @@ static struct attribute *part_attrs[] = { &dev_attr_discard_alignment.attr, &dev_attr_stat.attr, &dev_attr_inflight.attr, + &dev_attr_partition_name.attr, #ifdef CONFIG_FAIL_MAKE_REQUEST &dev_attr_fail.attr, #endif @@ -409,6 +419,11 @@ static ssize_t whole_disk_show(struct device *dev, static DEVICE_ATTR(whole_disk, S_IRUSR | S_IRGRP | S_IROTH, whole_disk_show, NULL); +static void name_partition(struct hd_struct *p, const char *name) +{ + strlcpy(p->partition_name, name, GENHD_PART_NAME_SIZE); +} + struct hd_struct *add_partition(struct gendisk *disk, int partno, sector_t start, sector_t len, int flags) { @@ -691,6 +706,7 @@ rescan: disk->disk_name, p, -PTR_ERR(part)); continue; } + name_partition(part, state->parts[p].name); #ifdef CONFIG_BLK_DEV_MD if (state->parts[p].flags & ADDPART_FLAG_RAID) md_autodetect_dev(part_to_dev(part)->devt); diff --git a/fs/partitions/check.h b/fs/partitions/check.h index 8e4e103ba216..5ef9da15197b 100644 --- a/fs/partitions/check.h +++ b/fs/partitions/check.h @@ -1,6 +1,8 @@ #include #include +#define PART_NAME_SIZE 128 + /* * add_gd_partition adds a partitions details to the devices partition * description. @@ -12,6 +14,7 @@ struct parsed_partitions { sector_t from; sector_t size; int flags; + char name[PART_NAME_SIZE]; } parts[DISK_MAX_PARTS]; int next; int limit; @@ -30,7 +33,8 @@ static inline void *read_part_sector(struct parsed_partitions *state, } static inline void -put_partition(struct parsed_partitions *p, int n, sector_t from, sector_t size) +put_named_partition(struct parsed_partitions *p, int n, sector_t from, + sector_t size, const char *name, size_t name_size) { if (n < p->limit) { char tmp[1 + BDEVNAME_SIZE + 10 + 1]; @@ -39,8 +43,22 @@ put_partition(struct parsed_partitions *p, int n, sector_t from, sector_t size) p->parts[n].size = size; snprintf(tmp, sizeof(tmp), " %s%d", p->name, n); strlcat(p->pp_buf, tmp, PAGE_SIZE); + if (name) { + if (name_size > PART_NAME_SIZE - 1) + name_size = PART_NAME_SIZE - 1; + memcpy(p->parts[n].name, name, name_size); + p->parts[n].name[name_size] = 0; + snprintf(tmp, sizeof(tmp), " (%s)", p->parts[n].name); + strlcat(p->pp_buf, tmp, PAGE_SIZE); + } } } +static inline void +put_partition(struct parsed_partitions *p, int n, sector_t from, sector_t size) +{ + put_named_partition(p, n, from, size, NULL, 0); +} + extern int warn_no_part; diff --git a/include/linux/genhd.h b/include/linux/genhd.h index 5f2f4c4d8fb0..27bc65f3cef0 100644 --- a/include/linux/genhd.h +++ b/include/linux/genhd.h @@ -21,6 +21,8 @@ #define disk_to_dev(disk) (&(disk)->part0.__dev) #define part_to_dev(part) (&((part)->__dev)) +#define GENHD_PART_NAME_SIZE 128 + extern struct device_type part_type; extern struct kobject *block_depr; extern struct class block_class; @@ -106,6 +108,7 @@ struct hd_struct { struct disk_stats dkstats; #endif struct rcu_head rcu_head; + char partition_name[GENHD_PART_NAME_SIZE]; }; #define GENHD_FL_REMOVABLE 1