Skip to content

Commit 5cbd28e

Browse files
Christoph Hellwigaxboe
authored andcommitted
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>
1 parent ea3edd4 commit 5cbd28e

3 files changed

Lines changed: 27 additions & 32 deletions

File tree

‎block/bio.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,12 @@ struct bio *bio_clone_fast(struct bio *bio, gfp_t gfp_mask, struct bio_set *bs)
680680
}
681681
EXPORT_SYMBOL(bio_clone_fast);
682682

683+
const char *bio_devname(struct bio *bio, char *buf)
684+
{
685+
return disk_name(bio->bi_disk, bio->bi_partno, buf);
686+
}
687+
EXPORT_SYMBOL(bio_devname);
688+
683689
static inline bool page_is_mergeable(const struct bio_vec *bv,
684690
struct page *page, unsigned int len, unsigned int off,
685691
bool *same_page)

‎block/genhd.c‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,27 @@ void set_capacity_revalidate_and_notify(struct gendisk *disk, sector_t size,
6969

7070
EXPORT_SYMBOL_GPL(set_capacity_revalidate_and_notify);
7171

72+
/*
73+
* Format the device name of the indicated disk into the supplied buffer and
74+
* return a pointer to that same buffer for convenience.
75+
*/
76+
char *disk_name(struct gendisk *hd, int partno, char *buf)
77+
{
78+
if (!partno)
79+
snprintf(buf, BDEVNAME_SIZE, "%s", hd->disk_name);
80+
else if (isdigit(hd->disk_name[strlen(hd->disk_name)-1]))
81+
snprintf(buf, BDEVNAME_SIZE, "%sp%d", hd->disk_name, partno);
82+
else
83+
snprintf(buf, BDEVNAME_SIZE, "%s%d", hd->disk_name, partno);
84+
85+
return buf;
86+
}
87+
88+
const char *bdevname(struct block_device *bdev, char *buf)
89+
{
90+
return disk_name(bdev->bd_disk, bdev->bd_part->partno, buf);
91+
}
92+
EXPORT_SYMBOL(bdevname);
7293

7394
void part_inc_in_flight(struct request_queue *q, struct hd_struct *part, int rw)
7495
{

‎block/partition-generic.c‎

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,6 @@
2525
extern void md_autodetect_dev(dev_t dev);
2626
#endif
2727

28-
/*
29-
* disk_name() is used by partition check code and the genhd driver.
30-
* It formats the devicename of the indicated disk into
31-
* the supplied buffer (of size at least 32), and returns
32-
* a pointer to that same buffer (for convenience).
33-
*/
34-
35-
char *disk_name(struct gendisk *hd, int partno, char *buf)
36-
{
37-
if (!partno)
38-
snprintf(buf, BDEVNAME_SIZE, "%s", hd->disk_name);
39-
else if (isdigit(hd->disk_name[strlen(hd->disk_name)-1]))
40-
snprintf(buf, BDEVNAME_SIZE, "%sp%d", hd->disk_name, partno);
41-
else
42-
snprintf(buf, BDEVNAME_SIZE, "%s%d", hd->disk_name, partno);
43-
44-
return buf;
45-
}
46-
47-
const char *bdevname(struct block_device *bdev, char *buf)
48-
{
49-
return disk_name(bdev->bd_disk, bdev->bd_part->partno, buf);
50-
}
51-
52-
EXPORT_SYMBOL(bdevname);
53-
54-
const char *bio_devname(struct bio *bio, char *buf)
55-
{
56-
return disk_name(bio->bi_disk, bio->bi_partno, buf);
57-
}
58-
EXPORT_SYMBOL(bio_devname);
59-
6028
static ssize_t part_partition_show(struct device *dev,
6129
struct device_attribute *attr, char *buf)
6230
{

0 commit comments

Comments
 (0)