Commit 7e06e792 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] clean up major_name

->major_name for per-disk gendisks set to full name - i.e.
IDE gendisks have "hda", "hdb", etc. instead of "hd".
As the result, we kill a lot of crap in check.c::disk_name().
In particular, now we can afford ->minor_shift set to 0
for ide-cd (disk_name() was the only obstacle)
parent 814bd2ba
......@@ -1257,14 +1257,14 @@ static struct gendisk mfm_gendisk[2] = {
{
major: MAJOR_NR,
first_minor: 0,
major_name: "mfm",
major_name: "mfma",
minor_shift: 6,
part: mfm,
},
{
major: MAJOR_NR,
first_minor: 64,
major_name: "mfm",
major_name: "mfmb",
minor_shift: 6,
part: mfm + 64,
};
......
......@@ -327,14 +327,6 @@ static char *pd_errs[17] = { "ERR","INDEX","ECC","DRQ","SEEK","WRERR",
extern struct block_device_operations pd_fops;
static struct gendisk pd_gendisk = {
major: PD_MAJOR,
major_name: PD_NAME,
minor_shift: PD_BITS,
fops: &pd_fops,
nr_real: 1,
};
static struct block_device_operations pd_fops = {
owner: THIS_MODULE,
open: pd_open,
......@@ -706,7 +698,11 @@ static int pd_detect( void )
}
for (unit=0;unit<PD_UNITS;unit++) {
if (PD.present) {
PD.gd = pd_gendisk;
PD.gd.major_name = PD.name;
PD.gd.minor_shift = PD_BITS;
PD.gd.fops = &pd_fops;
PD.gd.nr_real = 1;
PD.gd.major = major;
PD.gd.first_minor = unit << PD_BITS;
PD.gd.part = pd_hd + (unit << PD_BITS);
add_gendisk(&PD.gd);
......@@ -947,8 +943,6 @@ static int __init pd_init(void)
blk_init_queue(q, do_pd_request, &pd_lock);
blk_queue_max_sectors(q, cluster);
pd_gendisk.major = major;
pd_gendisk.major_name = name;
printk("%s: %s version %s, major %d, cluster %d, nice %d\n",
name,name,PD_VERSION,major,cluster,nice);
pd_init_units();
......
......@@ -166,7 +166,7 @@ int __init xd_init (void)
printk("xd: Unable to get major number %d\n",MAJOR_NR);
return -1;
}
devfs_handle = devfs_mk_dir (NULL, xd_gendisk.major_name, NULL);
devfs_handle = devfs_mk_dir (NULL, "xd", NULL);
blk_init_queue(BLK_DEFAULT_QUEUE(MAJOR_NR), do_xd_request, &xd_lock);
add_gendisk(&xd_gendisk);
xd_geninit();
......
......@@ -712,14 +712,14 @@ static struct gendisk hd_gendisk[2] = {
{
.major = MAJOR_NR,
.first_minor = 0,
.major_name = "hd",
.major_name = "hda",
.minor_shift = 6,
.part = hd,
.fops = &hd_fops,
},{
.major = MAJOR_NR,
.first_minor = 64,
.major_name = "hd",
.major_name = "hdb",
.minor_shift = 6,
.part = hd + 64,
.fops = &hd_fops,
......
......@@ -493,6 +493,7 @@ void ide_unregister(struct ata_channel *ch)
int i;
for (i = 0; i < MAX_DRIVES; i++)
del_gendisk(gd + i);
kfree(gd->major_name);
kfree(gd->part);
if (gd->de_arr)
kfree (gd->de_arr);
......
......@@ -1048,6 +1048,7 @@ static void channel_init(struct ata_channel *ch)
char *flags;
unsigned int unit;
extern devfs_handle_t ide_devfs_handle;
char *names;
if (!ch->present)
return;
......@@ -1127,6 +1128,11 @@ static void channel_init(struct ata_channel *ch)
goto err_kmalloc_gd_flags;
memset(flags, 0, sizeof(char) * MAX_DRIVES);
names = kmalloc (4 * MAX_DRIVES, GFP_KERNEL);
if (!names)
goto err_kmalloc_gd_names;
memset(names, 0, 4 * MAX_DRIVES);
for (unit = 0; unit < MAX_DRIVES; ++unit) {
gd[unit].part = part + (unit << PARTN_BITS);
gd[unit].de_arr = de_arr + unit;
......@@ -1134,8 +1140,8 @@ static void channel_init(struct ata_channel *ch)
ch->drives[unit].part = gd[unit].part;
gd[unit].major = ch->major;
gd[unit].first_minor = unit << PARTN_BITS;
/* treated special in genhd.c */
gd[unit].major_name = IDE_MAJOR_NAME;
sprintf(names + 4*unit, "hd%c", 'a'+ch->index*MAX_DRIVES+unit);
gd[unit].major_name = names + 4*unit;
gd[unit].minor_shift = PARTN_BITS;
gd[unit].nr_real = 1;
gd[unit].fops = ide_fops;
......@@ -1161,6 +1167,8 @@ static void channel_init(struct ata_channel *ch)
return;
err_kmalloc_gd_names:
kfree(names);
err_kmalloc_gd_flags:
kfree(de_arr);
err_kmalloc_gd_de_arr:
......
......@@ -125,6 +125,7 @@ MODULE_PARM(shuffle_freq, "i");
/* Each memory region corresponds to a minor device */
typedef struct partition_t {
struct mtd_info *mtd;
struct gndisk *disk;
u_int32_t state;
u_int32_t *VirtualBlockMap;
u_int32_t *VirtualPageMap;
......@@ -176,13 +177,6 @@ static struct mtd_notifier ftl_notifier = {
static struct hd_struct ftl_hd[MINOR_NR(MAX_DEV, 0, 0)];
static struct gendisk ftl_gendisk = {
major: FTL_MAJOR,
major_name: "ftl",
minor_shift: PART_BITS,
part: ftl_hd,
};
/*====================================================================*/
static int ftl_ioctl(struct inode *inode, struct file *file,
......@@ -850,7 +844,7 @@ static int ftl_open(struct inode *inode, struct file *file)
if (partition->state != FTL_FORMATTED)
return -ENXIO;
if (ftl_gendisk.part[minor].nr_sects == 0)
if (partition->disk->part[0].nr_sects == 0)
return -ENXIO;
if (!get_mtd_device(partition->mtd, -1))
......@@ -1181,15 +1175,13 @@ static void do_ftl_request(request_arg_t)
switch (CURRENT->cmd) {
case READ:
ret = ftl_read(part, CURRENT->buffer,
CURRENT->sector+ftl_hd[minor].start_sect,
ret = ftl_read(part, CURRENT->buffer, CURRENT->sector,
CURRENT->current_nr_sectors);
if (ret) printk("ftl_read returned %d\n", ret);
break;
case WRITE:
ret = ftl_write(part, CURRENT->buffer,
CURRENT->sector+ftl_hd[minor].start_sect,
ret = ftl_write(part, CURRENT->buffer, CURRENT->sector,
CURRENT->current_nr_sectors);
if (ret) printk("ftl_write returned %d\n", ret);
break;
......@@ -1241,6 +1233,8 @@ void ftl_freepart(partition_t *part)
static void ftl_notify_add(struct mtd_info *mtd)
{
partition_t *partition;
struct gendisk *disk;
char *name;
int device;
for (device=0; device < MAX_MTD_DEVICES && myparts[device]; device++)
......@@ -1253,30 +1247,48 @@ static void ftl_notify_add(struct mtd_info *mtd)
}
partition = kmalloc(sizeof(partition_t), GFP_KERNEL);
disk = kmalloc(sizeof(struct gendisk), GFP_KERNEL);
name = kmalloc(4, GFP_KERNEL);
if (!partition) {
if (!partition||!disk||!name) {
printk(KERN_WARNING "No memory to scan for FTL on %s\n",
mtd->name);
kfree(partition);
kfree(disk);
kfree(name);
return;
}
memset(partition, 0, sizeof(partition_t));
memset(disk, 0, sizeof(struct gendisk));
sprintf(name, "ftl%c", 'a' + device);
disk->major = FTL_MAJOR;
disk->first_minor = device << 4;
disk->major_name = name;
disk->minor_shift = PART_BITS;
disk->part = ftl_hd + (device << 4);
disk->fops = &ftl_blk_fops;
disk->nr_real = 1;
partition->mtd = mtd;
partition->disk = disk;
if ((scan_header(partition) == 0) && (build_maps(partition) == 0)) {
partition->state = FTL_FORMATTED;
atomic_set(&partition->open, 0);
myparts[device] = partition;
register_disk(&ftl_gendisk, mk_kdev(MAJOR_NR, device << 4),
add_gendisk(disk);
register_disk(disk, mk_kdev(MAJOR_NR, device << 4),
MAX_PART, &ftl_blk_fops,
le32_to_cpu(partition->header.FormattedSize)/SECTOR_SIZE);
#ifdef PCMCIA_DEBUG
printk(KERN_INFO "ftl_cs: opening %d kb FTL partition\n",
le32_to_cpu(partition->header.FormattedSize) >> 10);
#endif
} else
} else {
kfree(partition);
kfree(disk);
kfree(name);
}
}
static void ftl_notify_remove(struct mtd_info *mtd)
......@@ -1300,10 +1312,10 @@ static void ftl_notify_remove(struct mtd_info *mtd)
ftl_freepart(myparts[i]);
myparts[i]->state = 0;
for (j=0; j<16; j++) {
ftl_gendisk.part[j].nr_sects=0;
ftl_gendisk.part[j].start_sect=0;
}
wipe_partitions(mk_kdev(MAJOR_NR, i<<4));
del_gendisk(myparts[i]->disk);
kfree(myparts[i]->disk->name);
kfree(myparts[i]->disk);
kfree(myparts[i]);
myparts[i] = NULL;
}
......@@ -1312,9 +1324,6 @@ static void ftl_notify_remove(struct mtd_info *mtd)
int init_ftl(void)
{
int i;
memset(myparts, 0, sizeof(myparts));
DEBUG(0, "$Id: ftl.c,v 1.39 2001/10/02 15:05:11 dwmw2 Exp $\n");
if (register_blkdev(FTL_MAJOR, "ftl", &ftl_blk_fops)) {
......@@ -1322,15 +1331,7 @@ int init_ftl(void)
"device number!\n");
return -EAGAIN;
}
for (i = 0; i < MAX_DEV*MAX_PART; i++) {
ftl_hd[i].nr_sects = 0;
ftl_hd[i].start_sect = 0;
}
ftl_gendisk.major = FTL_MAJOR;
blk_init_queue(BLK_DEFAULT_QUEUE(FTL_MAJOR), &do_ftl_request);
add_gendisk(&ftl_gendisk);
register_mtd_user(&ftl_notifier);
return 0;
......@@ -1339,12 +1340,9 @@ int init_ftl(void)
static void __exit cleanup_ftl(void)
{
unregister_mtd_user(&ftl_notifier);
unregister_blkdev(FTL_MAJOR, "ftl");
blk_cleanup_queue(BLK_DEFAULT_QUEUE(FTL_MAJOR));
blk_clear(FTL_MAJOR);
del_gendisk(&ftl_gendisk);
}
module_init(init_ftl);
......
......@@ -58,12 +58,6 @@
struct hd_struct part_table[256];
static struct block_device_operations nftl_fops;
static struct gendisk nftl_gendisk = {
major: MAJOR_NR,
major_name: "nftl",
minor_shift: NFTL_PARTN_BITS, /* # of partition bits */
part: part_table, /* hd struct */
};
struct NFTLrecord *NFTLs[MAX_NFTLS];
......@@ -73,6 +67,8 @@ static void NFTL_setup(struct mtd_info *mtd)
struct NFTLrecord *nftl;
unsigned long temp;
int firstfree = -1;
struct gendisk *gd;
char *name;
DEBUG(MTD_DEBUG_LEVEL1,"NFTL_setup\n");
......@@ -91,7 +87,12 @@ static void NFTL_setup(struct mtd_info *mtd)
}
nftl = kmalloc(sizeof(struct NFTLrecord), GFP_KERNEL);
if (!nftl) {
gd = kmalloc(sizeof(struct gendisk), GFP_KERNEL);
name = kmalloc(6, GFP_KERNEL);
if (!nftl || !gd || !name) {
kfree(nftl);
kfree(gd);
kfree(name);
printk(KERN_WARNING "Out of memory for NFTL data structures\n");
return;
}
......@@ -106,6 +107,8 @@ static void NFTL_setup(struct mtd_info *mtd)
if (NFTL_mount(nftl) < 0) {
printk(KERN_WARNING "Could not mount NFTL device\n");
kfree(nftl);
kfree(gd);
kfree(name);
return;
}
......@@ -142,19 +145,18 @@ static void NFTL_setup(struct mtd_info *mtd)
/* Oh no we don't have nftl->nr_sects = nftl->heads * nftl->cylinders * nftl->sectors; */
}
NFTLs[firstfree] = nftl;
/* Finally, set up the block device sizes */
part_table[firstfree * 16].nr_sects = nftl->nr_sects;
nftl_gendisk.nr_real++;
/* partition check ... */
#if LINUX_VERSION_CODE < 0x20328
resetup_one_dev(&nftl_gendisk, firstfree);
#else
register_disk(&nftl_gendisk,
mk_kdev(MAJOR_NR,firstfree<<NFTL_PARTN_BITS),
memset(gd, 0, sizeof(struct gendisk));
sprintf(name, "nftl%c", 'a' + firstfree);
gd->major = MAJOR_NR;
gd->first_minor = firstfree << NFTL_PARTN_BITS;
gd->minor_shift = NFTL_PARTN_BITS;
gd->part = part_table + (firstfree << NFTL_PARTN_BITS);
gd->major_name = name;
gd->nr_real = 1;
nftl->disk = gd;
add_gendisk(gd);
register_disk(gd, mk_kdev(MAJOR_NR,firstfree<<NFTL_PARTN_BITS),
1<<NFTL_PARTN_BITS, &nftl_fops, nftl->nr_sects);
#endif
}
static void NFTL_unsetup(int i)
......@@ -169,8 +171,9 @@ static void NFTL_unsetup(int i)
kfree(nftl->ReplUnitTable);
if (nftl->EUNtable)
kfree(nftl->EUNtable);
nftl_gendisk.nr_real--;
del_gendisk(nftl->disk);
kfree(nftl->disk->major_name);
kfree(nftl->disk);
kfree(nftl);
}
......@@ -964,16 +967,6 @@ static int nftl_release(struct inode *inode, struct file *fp)
return 0;
}
#if LINUX_VERSION_CODE < 0x20326
static struct file_operations nftl_fops = {
read: block_read,
write: block_write,
ioctl: nftl_ioctl,
open: nftl_open,
release: nftl_release,
fsync: block_fsync,
};
#else
static struct block_device_operations nftl_fops =
{
owner: THIS_MODULE,
......@@ -981,9 +974,6 @@ static struct block_device_operations nftl_fops =
release: nftl_release,
ioctl: nftl_ioctl
};
#endif
/****************************************************************************
*
......@@ -1009,10 +999,8 @@ int __init init_nftl(void)
if (register_blkdev(MAJOR_NR, "nftl", &nftl_fops)){
printk("unable to register NFTL block device on major %d\n", MAJOR_NR);
return -EBUSY;
} else {
blk_init_queue(BLK_DEFAULT_QUEUE(MAJOR_NR), &nftl_request, &nftl_lock);
add_gendisk(&nftl_gendisk);
}
blk_init_queue(BLK_DEFAULT_QUEUE(MAJOR_NR), &nftl_request, &nftl_lock);
register_mtd_user(&nftl_notifier);
......@@ -1023,10 +1011,7 @@ static void __exit cleanup_nftl(void)
{
unregister_mtd_user(&nftl_notifier);
unregister_blkdev(MAJOR_NR, "nftl");
blk_cleanup_queue(BLK_DEFAULT_QUEUE(MAJOR_NR));
del_gendisk(&nftl_gendisk);
}
module_init(init_nftl);
......
......@@ -1318,6 +1318,7 @@ static int sd_attach(Scsi_Device * sdp)
devfs_handle_t de;
struct device *dev;
char flags;
char name[5];
} *p;
struct gendisk *gd;
......@@ -1368,10 +1369,14 @@ static int sd_attach(Scsi_Device * sdp)
gd->driverfs_dev_arr[0] = &sdp->sdev_driverfs_dev;
gd->major = SD_MAJOR(dsk_nr>>4);
gd->first_minor = (dsk_nr & 15)<<4;
gd->major_name = "sd";
gd->minor_shift = 4;
gd->part = sd + (dsk_nr << 4);
gd->fops = &sd_fops;
if (dsk_nr > 26)
sprintf(p->name, "sd%c%c", 'a'+dsk_nr/26-1, 'a'+dsk_nr%26);
else
sprintf(p->name, "sd%c", 'a'+dsk_nr%26);
gd->major_name = p->name;
if (sdp->removable)
gd->flags[0] |= GENHD_FL_REMOVABLE;
sd_disks[dsk_nr] = gd;
......
......@@ -16,8 +16,8 @@
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/blk.h>
#include <linux/buffer_head.h> /* for invalidate_bdev() */
#include <linux/kmod.h>
#include <linux/ctype.h>
#include "check.h"
......@@ -104,10 +104,11 @@ EXPORT_SYMBOL(genhd_dasd_ioctl);
char *disk_name (struct gendisk *hd, int minor, char *buf)
{
const char *maj = hd->major_name;
unsigned int unit = (minor >> hd->minor_shift);
unsigned int part = (minor & ((1 << hd->minor_shift) -1 ));
struct hd_struct *p = hd->part + minor - hd->first_minor;
char s[40];
const char *maj;
if ((((minor - hd->first_minor) >> hd->minor_shift) < hd->nr_real) &&
p->de) {
......@@ -124,83 +125,51 @@ char *disk_name (struct gendisk *hd, int minor, char *buf)
return buf;
#endif
/*
* IDE devices use multiple major numbers, but the drives
* are named as: {hda,hdb}, {hdc,hdd}, {hde,hdf}, {hdg,hdh}..
* This requires special handling here.
* Yes, I know, ... in cases is gccism and not a pretty one.
* However, the first variant will eventually consume _all_ cases
* and switch will disappear.
*/
switch (hd->major) {
case IDE9_MAJOR:
unit += 2;
case IDE8_MAJOR:
unit += 2;
case IDE7_MAJOR:
unit += 2;
case IDE6_MAJOR:
unit += 2;
case IDE5_MAJOR:
unit += 2;
case IDE4_MAJOR:
unit += 2;
case IDE3_MAJOR:
unit += 2;
case IDE2_MAJOR:
unit += 2;
case IDE1_MAJOR:
unit += 2;
case IDE0_MAJOR:
maj = "hd";
default:
maj = hd->major_name;
break;
case MD_MAJOR:
sprintf(buf, "%s%d", maj, unit);
return buf;
}
if (hd->major >= SCSI_DISK1_MAJOR && hd->major <= SCSI_DISK7_MAJOR) {
unit = unit + (hd->major - SCSI_DISK1_MAJOR + 1) * 16;
if (unit+'a' > 'z') {
unit -= 26;
sprintf(buf, "sd%c%c", 'a' + unit / 26, 'a' + unit % 26);
if (part)
sprintf(buf + 4, "%d", part);
return buf;
}
}
if (hd->major >= COMPAQ_SMART2_MAJOR && hd->major <= COMPAQ_SMART2_MAJOR+7) {
int ctlr = hd->major - COMPAQ_SMART2_MAJOR;
if (part == 0)
sprintf(buf, "%s/c%dd%d", maj, ctlr, unit);
else
sprintf(buf, "%s/c%dd%dp%d", maj, ctlr, unit, part);
return buf;
}
if (hd->major >= COMPAQ_CISS_MAJOR && hd->major <= COMPAQ_CISS_MAJOR+7) {
int ctlr = hd->major - COMPAQ_CISS_MAJOR;
if (part == 0)
sprintf(buf, "%s/c%dd%d", maj, ctlr, unit);
else
sprintf(buf, "%s/c%dd%dp%d", maj, ctlr, unit, part);
return buf;
}
if (hd->major >= DAC960_MAJOR && hd->major <= DAC960_MAJOR+7) {
int ctlr = hd->major - DAC960_MAJOR;
if (part == 0)
sprintf(buf, "%s/c%dd%d", maj, ctlr, unit);
else
sprintf(buf, "%s/c%dd%dp%d", maj, ctlr, unit, part);
return buf;
}
if (hd->major == ATARAID_MAJOR) {
int disk = minor >> hd->minor_shift;
int part = minor & (( 1 << hd->minor_shift) - 1);
if (part == 0)
sprintf(buf, "%s/d%d", maj, disk);
else
sprintf(buf, "%s/d%dp%d", maj, disk, part);
return buf;
sprintf(s, "%s%d", "md", unit);
maj = s;
break;
case COMPAQ_SMART2_MAJOR ... COMPAQ_SMART2_MAJOR+7:
sprintf(s, "ida/c%dd%d",
hd->major - COMPAQ_SMART2_MAJOR, unit);
maj = s;
break;
case COMPAQ_CISS_MAJOR ... COMPAQ_CISS_MAJOR+7:
sprintf(s, "cciss/c%dd%d",
hd->major - COMPAQ_CISS_MAJOR, unit);
maj = s;
break;
case DAC960_MAJOR ... DAC960_MAJOR+7:
sprintf(s, "rd/c%dd%d",
hd->major - DAC960_MAJOR, unit);
maj = s;
break;
case ATARAID_MAJOR:
sprintf(s, "ataraid/d%d", unit);
maj = s;
break;
case ACSI_MAJOR:
case PS2ESDI_MAJOR:
case XT_DISK_MAJOR:
case I2O_MAJOR:
case DASD_MAJOR:
sprintf(s, "%s%c", hd->major_name, unit + 'a');
maj = s;
}
if (part)
sprintf(buf, "%s%c%d", maj, unit+'a', part);
if (!part)
sprintf(buf, "%s", maj);
else if (isdigit(maj[strlen(maj)-1]))
sprintf(buf, "%sp%d", maj, part);
else
sprintf(buf, "%s%c", maj, unit+'a');
sprintf(buf, "%s%d", maj, part);
return buf;
}
......
......@@ -104,6 +104,7 @@ struct NFTLrecord {
unsigned int nb_blocks; /* number of physical blocks */
unsigned int nb_boot_blocks; /* number of blocks used by the bios */
struct erase_info instr;
struct gendisk *disk;
};
int NFTL_mount(struct NFTLrecord *s);
......
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