diff options
author | Christoph Hellwig <hch@lst.de> | 2020-03-24 08:25:12 +0100 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2020-03-24 07:57:07 -0600 |
commit | 5cbd28e3cef14b43b2a8271d36b75fc61c13bb8a (patch) | |
tree | 3c2243343e2631c9129f3f663c450de6f92b00ca /block/genhd.c | |
parent | ea3edd4dc23027083fbb4a73b65114d08fe73a76 (diff) |
block: move disk_name and related helpers out of partition-generic.c
Thes functions aren't really related to partition support, so move them
to a more suitable place.
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/genhd.c')
-rw-r--r-- | block/genhd.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/block/genhd.c b/block/genhd.c index c5d20a48b4de..2484348d1850 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -69,6 +69,27 @@ void set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size, EXPORT_SYMBOL_GPL(set_capacity_revalidate_and_notify); +/* + * Format the device name of the indicated disk into the supplied buffer and + * return a pointer to that same buffer for convenience. + */ +char *disk_name(struct gendisk *hd, int partno, char *buf) +{ + if (!partno) + snprintf(buf, BDEVNAME_SIZE, "%s", hd->disk_name); + else if (isdigit(hd->disk_name[strlen(hd->disk_name)-1])) + snprintf(buf, BDEVNAME_SIZE, "%sp%d", hd->disk_name, partno); + else + snprintf(buf, BDEVNAME_SIZE, "%s%d", hd->disk_name, partno); + + return buf; +} + +const char *bdevname(struct block_device *bdev, char *buf) +{ + return disk_name(bdev->bd_disk, bdev->bd_part->partno, buf); +} +EXPORT_SYMBOL(bdevname); void part_inc_in_flight(struct request_queue *q, struct hd_struct *part, int rw) { |