Commit 16a974dc authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] devfs handling for cdroms moved to register_disk()

devfs-related stuff moved from cdrom.c and cdrom drivers to register_disk();
new flag (GENHD_FL_CD) marks gendisks that need such treatment.
parent b39472ce
......@@ -934,7 +934,6 @@ static int __init pcd_init(void)
if (cd->present) {
struct gendisk *disk = &cd->disk;
register_cdrom(&cd->info);
devfs_plain_cdrom(&cd->info, disk->fops);
add_gendisk(disk);
register_disk(disk,
mk_kdev(disk->major,disk->first_minor),
......
......@@ -327,8 +327,6 @@ static void cdrom_count_tracks(struct cdrom_device_info *, tracktype*);
static void cdrom_sysctl_register(void);
#endif /* CONFIG_SYSCTL */
static struct cdrom_device_info *topCdromPtr;
static devfs_handle_t devfs_handle;
static struct unique_numspace cdrom_numspace = UNIQUE_NUMBERSPACE_INITIALISER;
/* This macro makes sure we don't have to check on cdrom_device_ops
* existence in the run-time routines below. Change_capability is a
......@@ -381,26 +379,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
if (check_media_type==1)
cdi->options |= (int) CDO_CHECK_TYPE;
if (!devfs_handle)
devfs_handle = devfs_mk_dir (NULL, "cdroms", NULL);
cdi->number = devfs_alloc_unique_number (&cdrom_numspace);
if (cdi->de) {
int pos;
devfs_handle_t slave;
char rname[64];
pos = devfs_generate_path (cdi->de, rname + 3,
sizeof rname - 3);
if (pos >= 0) {
char vname[16];
sprintf (vname, "cdrom%d", cdi->number);
strncpy (rname + pos, "../", 3);
devfs_mk_symlink (devfs_handle, vname,
DEVFS_FL_DEFAULT,
rname + pos, &slave, NULL);
devfs_auto_unregister (cdi->de, slave);
}
}
cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
cdi->next = topCdromPtr;
topCdromPtr = cdi;
......@@ -432,8 +410,6 @@ int unregister_cdrom(struct cdrom_device_info *unreg)
else
topCdromPtr = cdi->next;
cdi->ops->n_minors--;
devfs_unregister (cdi->de);
devfs_dealloc_unique_number (&cdrom_numspace, cdi->number);
cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
return 0;
}
......@@ -2618,8 +2594,6 @@ static int __init cdrom_init(void)
#ifdef CONFIG_SYSCTL
cdrom_sysctl_register();
#endif
if (!devfs_handle)
devfs_handle = devfs_mk_dir(NULL, "cdroms", NULL);
return 0;
}
......@@ -2629,7 +2603,6 @@ static void __exit cdrom_exit(void)
#ifdef CONFIG_SYSCTL
cdrom_sysctl_unregister();
#endif
devfs_unregister(devfs_handle);
}
module_init(cdrom_init);
......
......@@ -3195,6 +3195,7 @@ static struct gendisk scd_gendisk = {
.minor_shift = 0,
.major_name = "cdu31a"
.fops = &scd_bdops,
.flags = GENHD_FL_CD,
}
/* The different types of disc loading mechanisms supported */
......@@ -3442,7 +3443,6 @@ int __init cdu31a_init(void)
scd_info.mask = deficiency;
if (register_cdrom(&scd_info))
goto errout0;
devfs_plain_cdrom(&scd_info, disk->fops);
add_gendisk(disk);
register_disk(disk,
mk_kdev(disk->major,disk->first_minor),
......
......@@ -1363,6 +1363,7 @@ static struct gendisk cm206_gendisk = {
.minor_shift = 0,
.major_name = "cm206",
.fops = &cm206_bdops,
.flags = GENHD_FL_CD,
};
/* This function probes for the adapter card. It returns the base
......@@ -1481,7 +1482,6 @@ int __init cm206_init(void)
printk(KERN_INFO "Cannot register for cdrom %d!\n", MAJOR_NR);
goto out_cdrom;
}
devfs_plain_cdrom(&cm206_info, disk->fops);
add_gendisk(disk);
register_disk(disk,
mk_kdev(disk->major,disk->first_minor),
......
......@@ -227,6 +227,7 @@ static struct gendisk mcd_gendisk = {
.minor_shift = 0,
.major_name = "mcd",
.fops = &mcd_bdops,
.flags = GENHD_FL_CD;
};
#ifndef MODULE
......@@ -1129,7 +1130,6 @@ int __init mcd_init(void)
printk(KERN_ERR "mcd: Unable to register Mitsumi CD-ROM.\n");
goto out_cdrom;
}
devfs_plain_cdrom(&mcd_info, disk->fops);
add_gendisk(disk);
register_disk(disk,
mk_kdev(disk->major,disk->first_minor),
......
......@@ -1212,6 +1212,7 @@ int __init mcdx_init_drive(int drive)
disk->minor_shift = 0;
disk->major_name = stuffp->info.name;
disk->fops = &mcdx_bdops;
disk->flags = GENHD_FL_CD;
sprintf(msg, " mcdx: Mitsumi CD-ROM installed at 0x%3p, irq %d."
" (Firmware version %c %x)\n",
......@@ -1229,7 +1230,6 @@ int __init mcdx_init_drive(int drive)
blk_cleanup_queue(BLK_DEFAULT_QUEUE(MAJOR_NR));
return 2;
}
devfs_plain_cdrom(&stuffp->info, disk->fops);
add_gendisk(disk);
register_disk(disk,
mk_kdev(disk->major,disk->first_minor),
......
......@@ -5836,11 +5836,9 @@ int __init sbpcd_init(void)
disk->minor_shift = 0;
disk->fops = &sbpcd_bdops;
disk->major_name = sbpcd_infop->name;
sprintf(nbuff, "c0t%d/cd", p->drv_id);
sbpcd_infop->de =
devfs_register (devfs_handle, nbuff, DEVFS_FL_DEFAULT,
MAJOR_NR, j, S_IFBLK | S_IRUGO | S_IWUGO,
&sbpcd_bdops, NULL);
disk->flags = GENHD_FL_CD;
sprintf(nbuff, "c0t%d", p->drv_id);
disk->de = devfs_mk_dir(devfs_handle, nbuff, NULL);
if (register_cdrom(sbpcd_infop))
{
printk(" sbpcd: Unable to register with Uniform CD-ROm driver\n");
......@@ -5879,6 +5877,7 @@ void sbpcd_exit(void)
del_gendisk(&D_S[j].disk);
vfree(D_S[j].sbp_buf);
if (D_S[j].sbp_audsiz>0) vfree(D_S[j].aud_buf);
devfs_unregister(D_S[j].disk.de);
if ((unregister_cdrom(D_S[j].sbpcd_infop) == -EINVAL))
{
msg(DBG_INF, "What's that: can't unregister info %s.\n", major_name);
......
......@@ -2611,12 +2611,6 @@ static int ide_cdrom_register (ide_drive_t *drive, int nslots)
if (!CDROM_CONFIG_FLAGS(drive)->close_tray)
devinfo->mask |= CDC_CLOSE_TRAY;
devinfo->de = devfs_register(drive->de, "cd", DEVFS_FL_DEFAULT,
drive->disk->major,
drive->disk->first_minor,
S_IFBLK | S_IRUGO | S_IWUGO,
ide_fops, NULL);
return register_cdrom(devinfo);
}
......@@ -3127,6 +3121,9 @@ static int ide_cdrom_attach (ide_drive_t *drive)
memset(info, 0, sizeof (struct cdrom_info));
drive->driver_data = info;
DRIVER(drive)->busy++;
g->minor_shift = 0;
g->de = drive->de;
g->flags = GENHD_FL_CD;
if (ide_cdrom_setup(drive)) {
struct cdrom_device_info *devinfo = &info->devinfo;
DRIVER(drive)->busy--;
......@@ -3146,10 +3143,6 @@ static int ide_cdrom_attach (ide_drive_t *drive)
DRIVER(drive)->busy--;
cdrom_read_toc(drive, &sense);
g->minor_shift = 0;
/* probably bogus, but that's the old behaviour */
g->de = NULL;
g->flags = GENHD_FL_DEVFS;
add_gendisk(g);
register_disk(g, mk_kdev(g->major,g->first_minor),
1<<g->minor_shift, ide_fops,
......
......@@ -762,6 +762,7 @@ void sr_finish()
disk->minor_shift = 0;
disk->major_name = cd->cdi.name;
disk->fops = &sr_bdops;
disk->flags = GENHD_FL_CD;
cd->disk = disk;
cd->capacity = 0x1fffff;
cd->device->sector_size = 2048;/* A guess, just in case */
......@@ -805,10 +806,7 @@ void sr_finish()
&dev_attr_type);
device_create_file(&cd->cdi.cdrom_driverfs_dev,
&dev_attr_kdev);
cd->cdi.de = devfs_register(cd->device->de, "cd",
DEVFS_FL_DEFAULT, MAJOR_NR, i,
S_IFBLK | S_IRUGO | S_IWUGO,
&sr_bdops, NULL);
disk->de = cd->device->de;
register_cdrom(&cd->cdi);
add_gendisk(disk);
register_disk(disk, mk_kdev(disk->major, disk->first_minor),
......
......@@ -286,6 +286,8 @@ static void devfs_register_partition(struct gendisk *dev, int part)
#ifdef CONFIG_DEVFS_FS
static struct unique_numspace disc_numspace = UNIQUE_NUMBERSPACE_INITIALISER;
static devfs_handle_t cdroms;
static struct unique_numspace cdrom_numspace = UNIQUE_NUMBERSPACE_INITIALISER;
#endif
static void devfs_create_partitions(struct gendisk *dev)
......@@ -333,6 +335,47 @@ static void devfs_create_partitions(struct gendisk *dev)
#endif
}
static void devfs_create_cdrom(struct gendisk *dev)
{
#ifdef CONFIG_DEVFS_FS
int pos = 0;
devfs_handle_t dir, slave;
unsigned int devfs_flags = DEVFS_FL_DEFAULT;
char dirname[64], symlink[16];
char vname[23];
if (!cdroms)
cdroms = devfs_mk_dir (NULL, "cdroms", NULL);
dev->number = devfs_alloc_unique_number(&cdrom_numspace);
sprintf(vname, "cdroms/cdrom%d", dev->number);
if (dev->de) {
int pos;
devfs_handle_t slave;
char rname[64];
dev->disk_de = devfs_register(dev->de, "cd", DEVFS_FL_DEFAULT,
dev->major, dev->first_minor,
S_IFBLK | S_IRUGO | S_IWUGO,
dev->fops, NULL);
pos = devfs_generate_path(dev->disk_de, rname+3, sizeof(rname)-3);
if (pos >= 0) {
strncpy(rname + pos, "../", 3);
devfs_mk_symlink(devfs_handle, vname,
DEVFS_FL_DEFAULT,
rname + pos, &slave, NULL);
devfs_auto_unregister(dev->de, slave);
}
} else {
dev->disk_de = devfs_register (NULL, vname, DEVFS_FL_DEFAULT,
dev->major, dev->first_minor,
S_IFBLK | S_IRUGO | S_IWUGO,
dev->fops, NULL);
}
#endif
}
static void devfs_remove_partitions(struct gendisk *dev)
{
#ifdef CONFIG_DEVFS_FS
......@@ -343,7 +386,10 @@ static void devfs_remove_partitions(struct gendisk *dev)
}
devfs_unregister(dev->disk_de);
dev->disk_de = NULL;
devfs_dealloc_unique_number(&disc_numspace, dev->number);
if (dev->flags & GENHD_FL_CD)
devfs_dealloc_unique_number(&cdrom_numspace, dev->number);
else
devfs_dealloc_unique_number(&disc_numspace, dev->number);
#endif
}
......@@ -367,6 +413,9 @@ void register_disk(struct gendisk *disk, kdev_t dev, unsigned minors,
set_capacity(disk, size);
if (disk->flags & GENHD_FL_CD)
devfs_create_cdrom(disk);
/* No minors to use for partitions */
if (!disk->minor_shift)
return;
......
......@@ -730,9 +730,7 @@ struct cdrom_device_info {
struct cdrom_device_ops *ops; /* link to device_ops */
struct cdrom_device_info *next; /* next device_info for this major */
void *handle; /* driver-dependent data */
devfs_handle_t de; /* real driver should create this */
struct device cdrom_driverfs_dev; /* driverfs implementation */
int number; /* generic driver updates this */
/* specifications */
kdev_t dev; /* device number */
int mask; /* mask of capability: disables them */
......@@ -787,18 +785,6 @@ extern int cdrom_media_changed(kdev_t);
extern int register_cdrom(struct cdrom_device_info *cdi);
extern int unregister_cdrom(struct cdrom_device_info *cdi);
static inline void devfs_plain_cdrom(struct cdrom_device_info *cdi,
struct block_device_operations *ops)
{
char vname[23];
sprintf (vname, "cdroms/cdrom%d", cdi->number);
cdi->de = devfs_register (NULL, vname, DEVFS_FL_DEFAULT,
major(cdi->dev), minor(cdi->dev),
S_IFBLK | S_IRUGO | S_IWUGO,
ops, NULL);
}
typedef struct {
int data;
int audio;
......
......@@ -68,6 +68,7 @@ struct hd_struct {
#define GENHD_FL_REMOVABLE 1
#define GENHD_FL_DRIVERFS 2
#define GENHD_FL_DEVFS 4
#define GENHD_FL_CD 8
struct gendisk {
int major; /* major number of driver */
......
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