Commit 0948aa6d authored by Christoph Hellwig's avatar Christoph Hellwig

[PATCH] improved bdevname

parent 72007d2d
...@@ -99,25 +99,32 @@ char *disk_name(struct gendisk *hd, int part, char *buf) ...@@ -99,25 +99,32 @@ char *disk_name(struct gendisk *hd, int part, char *buf)
#ifdef CONFIG_DEVFS_FS #ifdef CONFIG_DEVFS_FS
if (hd->devfs_name[0] != '\0') { if (hd->devfs_name[0] != '\0') {
if (part) if (part)
sprintf(buf, "%s/part%d", hd->devfs_name, part); snprintf(buf, BDEVNAME_SIZE, "%s/part%d",
hd->devfs_name, part);
else if (hd->minors != 1) else if (hd->minors != 1)
sprintf(buf, "%s/disc", hd->devfs_name); snprintf(buf, BDEVNAME_SIZE, "%s/disc", hd->devfs_name);
else else
sprintf(buf, "%s", hd->devfs_name); snprintf(buf, BDEVNAME_SIZE, "%s", hd->devfs_name);
return buf; return buf;
} }
#endif #endif
if (!part) if (!part)
sprintf(buf, "%s", hd->disk_name); snprintf(buf, BDEVNAME_SIZE, "%s", hd->disk_name);
else if (isdigit(hd->disk_name[strlen(hd->disk_name)-1])) else if (isdigit(hd->disk_name[strlen(hd->disk_name)-1]))
sprintf(buf, "%sp%d", hd->disk_name, part); snprintf(buf, BDEVNAME_SIZE, "%sp%d", hd->disk_name, part);
else else
sprintf(buf, "%s%d", hd->disk_name, part); snprintf(buf, BDEVNAME_SIZE, "%s%d", hd->disk_name, part);
return buf; return buf;
} }
const char *bdevname(struct block_device *bdev, char *buf)
{
int part = MINOR(bdev->bd_dev) - bdev->bd_disk->first_minor;
return disk_name(bdev->bd_disk, part, buf);
}
static struct parsed_partitions * static struct parsed_partitions *
check_partition(struct gendisk *hd, struct block_device *bdev) check_partition(struct gendisk *hd, struct block_device *bdev)
{ {
...@@ -417,7 +424,7 @@ void del_gendisk(struct gendisk *disk) ...@@ -417,7 +424,7 @@ void del_gendisk(struct gendisk *disk)
struct dev_name { struct dev_name {
struct list_head list; struct list_head list;
dev_t dev; dev_t dev;
char namebuf[64]; char namebuf[BDEVNAME_SIZE];
char *name; char *name;
}; };
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
enum { MAX_PART = 256 }; enum { MAX_PART = 256 };
struct parsed_partitions { struct parsed_partitions {
char name[40]; char name[BDEVNAME_SIZE];
struct { struct {
sector_t from; sector_t from;
sector_t size; sector_t size;
......
...@@ -1068,10 +1068,7 @@ extern int chrdev_open(struct inode *, struct file *); ...@@ -1068,10 +1068,7 @@ extern int chrdev_open(struct inode *, struct file *);
/* fs/block_dev.c */ /* fs/block_dev.c */
#define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */ #define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */
extern const char *__bdevname(dev_t, char *buffer); extern const char *__bdevname(dev_t, char *buffer);
extern inline const char *bdevname(struct block_device *bdev, char *buffer) extern const char *bdevname(struct block_device *bdev, char *buffer);
{
return __bdevname(bdev->bd_dev, buffer);
}
extern struct block_device *lookup_bdev(const char *); extern struct block_device *lookup_bdev(const char *);
extern struct block_device *open_bdev_excl(const char *, int, int, void *); extern struct block_device *open_bdev_excl(const char *, int, int, void *);
extern void close_bdev_excl(struct block_device *, int); extern void close_bdev_excl(struct block_device *, int);
......
...@@ -515,6 +515,7 @@ EXPORT_SYMBOL(vsprintf); ...@@ -515,6 +515,7 @@ EXPORT_SYMBOL(vsprintf);
EXPORT_SYMBOL(vsnprintf); EXPORT_SYMBOL(vsnprintf);
EXPORT_SYMBOL(vsscanf); EXPORT_SYMBOL(vsscanf);
EXPORT_SYMBOL(__bdevname); EXPORT_SYMBOL(__bdevname);
EXPORT_SYMBOL(bdevname);
EXPORT_SYMBOL(cdevname); EXPORT_SYMBOL(cdevname);
EXPORT_SYMBOL(simple_strtoull); EXPORT_SYMBOL(simple_strtoull);
EXPORT_SYMBOL(simple_strtoul); EXPORT_SYMBOL(simple_strtoul);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment