->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)
{
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,
};
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,
}
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);
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();
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();
{
.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,
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);
char *flags;
unsigned int unit;
extern devfs_handle_t ide_devfs_handle;
+ char *names;
if (!ch->present)
return;
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;
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;
return;
+err_kmalloc_gd_names:
+ kfree(names);
err_kmalloc_gd_flags:
kfree(de_arr);
err_kmalloc_gd_de_arr:
/* 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;
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,
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))
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;
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++)
}
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);
+ 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)
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;
}
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)) {
"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;
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);
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];
struct NFTLrecord *nftl;
unsigned long temp;
int firstfree = -1;
+ struct gendisk *gd;
+ char *name;
DEBUG(MTD_DEBUG_LEVEL1,"NFTL_setup\n");
}
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;
}
if (NFTL_mount(nftl) < 0) {
printk(KERN_WARNING "Could not mount NFTL device\n");
kfree(nftl);
+ kfree(gd);
+ kfree(name);
return;
}
/* 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)
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);
}
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,
release: nftl_release,
ioctl: nftl_ioctl
};
-#endif
-
-
/****************************************************************************
*
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);
{
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);
devfs_handle_t de;
struct device *dev;
char flags;
+ char name[5];
} *p;
struct gendisk *gd;
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;
#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"
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) {
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;
}
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);