diff options
author | Colin Cross <ccross@android.com> | 2010-04-07 12:05:32 -0700 |
---|---|---|
committer | Colin Cross <ccross@android.com> | 2010-09-29 17:49:47 -0700 |
commit | 4cc08cf96b436a6e38a0b0259241d9636a957dc5 (patch) | |
tree | a4c0af5d04bf3faa911d532e714386085da61351 /fs/partitions | |
parent | ba583532869283e80e4ffe8f271b7626be5c381c (diff) |
fs: partitions: Add support for named partitions
Adds a new file in /sys/block/<block>/<partition> called partition_name
that contains the name of the partition, if specified by the partition
handler.
Change-Id: I6648ed95eabefd1d00edbfdfd99eeb971d15f4b3
Signed-off-by: Colin Cross <ccross@android.com>
Diffstat (limited to 'fs/partitions')
-rw-r--r-- | fs/partitions/check.c | 16 | ||||
-rw-r--r-- | fs/partitions/check.h | 20 |
2 files changed, 35 insertions, 1 deletions
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 <linux/pagemap.h> #include <linux/blkdev.h> +#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; |