/* * This routine checks whether a floppy has been changed, and * invalidates all buffer-cache-entries in that case. This * is a relatively slow routine, so we have to try to minimize using * it. Thus it is called only upon a 'mount' or 'open'. This * is the best way of combining speed and utility, I think. * People changing diskettes in the middle of an operation deserve * to loose :-) * * NOTE! Although currently this is only for floppies, the idea is * that any additional removable block-device will use this routine, * and that mount/open needn't know that floppies/whatever are * special. */ void check_disk_change(int dev) { int i; struct buffer_head * bh; switch(MAJOR(dev)){ case 2: /* floppy disc */ if (!(bh = getblk(dev,0,1024))) return; i = floppy_change(bh); brelse(bh); break; #if defined(CONFIG_BLK_DEV_SR) && defined(CONFIG_SCSI) case 11: /* CDROM */ i = check_cdrom_media_change(dev, 0); if (i) printk("Flushing buffers and inodes for CDROM\n"); break; #endif default: return; }; if (!i) return; for (i=0 ; i<NR_SUPER ; i++) if (super_block[i].s_dev == dev) put_super(super_block[i].s_dev); invalidate_inodes(dev); invalidate_buffers(dev); }
/* * This routine checks whether a floppy has been changed, and * invalidates all buffer-cache-entries in that case. This * is a relatively slow routine, so we have to try to minimize using * it. Thus it is called only upon a 'mount' or 'open'. This * is the best way of combining speed and utility, I think. * People changing diskettes in the middle of an operation deserve * to loose :-) * * NOTE! Although currently this is only for floppies, the idea is * that any additional removable block-device will use this routine, * and that mount/open needn't know that floppies/whatever are * special. */ void check_disk_change(dev_t dev) { int i; struct buffer_head * bh; switch(MAJOR(dev)){ case FLOPPY_MAJOR: if (!(bh = getblk(dev,0,1024))) return; i = floppy_change(bh); brelse(bh); break; #if defined(CONFIG_BLK_DEV_SD) && defined(CONFIG_SCSI) case SCSI_DISK_MAJOR: i = check_scsidisk_media_change(dev, 0); break; #endif #if defined(CONFIG_BLK_DEV_SR) && defined(CONFIG_SCSI) case SCSI_CDROM_MAJOR: i = check_cdrom_media_change(dev, 0); break; #endif #if defined(CONFIG_CDU31A) case CDU31A_CDROM_MAJOR: i = check_cdu31a_media_change(dev, 0); break; #endif #if defined(CONFIG_MCD) case MITSUMI_CDROM_MAJOR: i = check_mcd_media_change(dev, 0); break; #endif default: return; }; if (!i) return; printk("VFS: Disk change detected on device %d/%d\n", MAJOR(dev), MINOR(dev)); for (i=0 ; i<NR_SUPER ; i++) if (super_blocks[i].s_dev == dev) put_super(super_blocks[i].s_dev); invalidate_inodes(dev); invalidate_buffers(dev); #if defined(CONFIG_BLK_DEV_SD) && defined(CONFIG_SCSI) /* This is trickier for a removable hardisk, because we have to invalidate all of the partitions that lie on the disk. */ if (MAJOR(dev) == SCSI_DISK_MAJOR) revalidate_scsidisk(dev, 0); #endif }