diff -uNr linux-2.4.21/drivers/scsi/sd_dynalloc.c linux-2.4.21.fixregdev/drivers/scsi/sd_dynalloc.c --- linux-2.4.21/drivers/scsi/sd_dynalloc.c Sun Jun 29 18:02:35 2003 +++ linux-2.4.21.fixregdev/drivers/scsi/sd_dynalloc.c Sun Jun 29 18:04:03 2003 @@ -28,7 +28,7 @@ * - pass buffer length 252 consistent with alloc length * in sd_init_onedisk() * - Fix deallocation of majors. - * - Fix locking issue with blk_getfops() + * - Use (patched) register_blkdev to get dynamic major */ @@ -120,42 +120,6 @@ gdp->real_devices = (void*) sd_major->disks; } -#ifndef CONFIG_DEVFS_FS -#define FIRST_MAJOR 143 -static int sd_find_major (void) -{ - /* The get_blkfops() has the side-effect of triggering kmod - * on blockdevs. This makes it safe not to accidently - * take the major of sb. else. - * We try to avoid conflicts by allocating - * 8, 65--71, 128--135 ( 16, officially assigned to sd) - * 144--254 (111, not yet assigned) - * 72--127 ( 56, assigned to other devices) - * 136--143 ( 8, assigned to Mylex DAC960) - * 12-- 64 ( 53, assigned to other devices) - * Summary: 16 safe, 127 almost safe (poss. future confl.), - * 244 theoretical maximum, IOW 3904 disks. - */ - int maj = FIRST_MAJOR; - while (++maj < 255) /* 255 is RESERVED */ - if (!get_blkfops(maj)) - return maj; - maj = SCSI_DISK7_MAJOR; /* The search goes on */ - while (++maj < SCSI_DISK10_MAJOR) - if (!get_blkfops(maj)) - return maj; - maj = SCSI_DISK17_MAJOR; - while (++maj < FIRST_MAJOR) - if (!get_blkfops(maj)) - return maj; - maj = 11; - while (++maj < SCSI_DISK1_MAJOR) - if (!get_blkfops(maj)) - return maj; - return SD_NO_MAJOR; -} -#endif - extern request_queue_t *sd_find_queue(kdev_t dev); /* We should already have the lock in write mode when entering */ int sd_alloc_major (void) @@ -178,15 +142,13 @@ else { #ifdef CONFIG_DEVFS_FS major = devfs_alloc_major(DEVFS_SPECIAL_BLK); -#else - SD_UNLOCK_W; - major = sd_find_major (); - SD_LOCK_W; -#endif if (major == SD_NO_MAJOR) { SDD_PRINTK("alloc_major: could not get major\n"); return major; } +#else + major = 0; +#endif } /* Now perform memory allocations */ sd_major = kmalloc (sizeof (*sd_major), GFP_ATOMIC); diff -uNr linux-2.4.21/fs/block_dev.c linux-2.4.21.fixregdev/fs/block_dev.c --- linux-2.4.21/fs/block_dev.c Sun Jun 29 18:02:30 2003 +++ linux-2.4.21.fixregdev/fs/block_dev.c Sun Jun 29 18:04:03 2003 @@ -25,6 +25,32 @@ #include +#define DEV_MAJOR_FREE 0 +#define DEV_MAJOR_STATIC 1 +static const unsigned char block_major_list [] = + { [ 0 ... 3] = DEV_MAJOR_STATIC, + [ 4 ... 6] = DEV_MAJOR_FREE, + [ 7 ... 9] = DEV_MAJOR_STATIC, + [ 10 ... 10] = DEV_MAJOR_FREE, + [ 11 ... 59] = DEV_MAJOR_STATIC, + [ 60 ... 63] = DEV_MAJOR_FREE, + [ 64 ... 93] = DEV_MAJOR_STATIC, + [ 94 ... 94] = DEV_MAJOR_FREE, + [ 95 ... 99] = DEV_MAJOR_STATIC, + [100 ... 100] = DEV_MAJOR_FREE, + [101 ... 117] = DEV_MAJOR_STATIC, + [118 ... 127] = DEV_MAJOR_FREE, + [128 ... 143] = DEV_MAJOR_STATIC, + [144 ... 158] = DEV_MAJOR_FREE, + [159 ... 159] = DEV_MAJOR_STATIC, + [160 ... 198] = DEV_MAJOR_FREE, + [199 ... 199] = DEV_MAJOR_STATIC, + [200 ... 200] = DEV_MAJOR_FREE, + [201 ... 201] = DEV_MAJOR_STATIC, + [202 ... 254] = DEV_MAJOR_FREE, + [255 ... 255] = DEV_MAJOR_STATIC +}; + static unsigned long max_block(kdev_t dev) { unsigned int retval = ~0U; @@ -473,7 +499,7 @@ { if (major == 0) { for (major = MAX_BLKDEV-1; major > 0; major--) { - if (blkdevs[major].bdops == NULL) { + if ((block_major_list[major]==DEV_MAJOR_FREE) && (blkdevs[major].bdops == NULL)) { blkdevs[major].name = name; blkdevs[major].bdops = bdops; return major; diff -uNr linux-2.4.21/fs/devices.c linux-2.4.21.fixregdev/fs/devices.c --- linux-2.4.21/fs/devices.c Sun Sep 23 05:35:43 2001 +++ linux-2.4.21.fixregdev/fs/devices.c Sun Jun 29 18:04:03 2003 @@ -38,6 +38,26 @@ static rwlock_t chrdevs_lock = RW_LOCK_UNLOCKED; static struct device_struct chrdevs[MAX_CHRDEV]; +#define DEV_MAJOR_FREE 0 +#define DEV_MAJOR_STATIC 1 +static const unsigned char char_major_list [] = + { [ 0 ... 7] = DEV_MAJOR_STATIC, + [ 8 ... 8] = DEV_MAJOR_FREE, + [ 9 ... 59] = DEV_MAJOR_STATIC, + [ 60 ... 63] = DEV_MAJOR_FREE, + [ 64 ... 119] = DEV_MAJOR_STATIC, + [120 ... 127] = DEV_MAJOR_FREE, + [128 ... 151] = DEV_MAJOR_STATIC, + [152 ... 153] = DEV_MAJOR_FREE, + [154 ... 211] = DEV_MAJOR_STATIC, + [212 ... 215] = DEV_MAJOR_FREE, + [216 ... 221] = DEV_MAJOR_STATIC, + [222 ... 223] = DEV_MAJOR_FREE, + [224 ... 230] = DEV_MAJOR_STATIC, + [231 ... 254] = DEV_MAJOR_FREE, + [255 ... 255] = DEV_MAJOR_STATIC +}; + extern int get_blkdev_list(char *); int get_device_list(char * page) @@ -100,7 +120,7 @@ if (major == 0) { write_lock(&chrdevs_lock); for (major = MAX_CHRDEV-1; major > 0; major--) { - if (chrdevs[major].fops == NULL) { + if ((char_major_list[major]==DEV_MAJOR_FREE) && (chrdevs[major].fops == NULL)) { chrdevs[major].name = name; chrdevs[major].fops = fops; write_unlock(&chrdevs_lock); diff -uNr linux-2.4.21/kernel/ksyms.c linux-2.4.21.fixregdev/kernel/ksyms.c --- linux-2.4.21/kernel/ksyms.c Sun Jun 29 18:02:52 2003 +++ linux-2.4.21.fixregdev/kernel/ksyms.c Sun Jun 29 18:04:03 2003 @@ -356,7 +356,6 @@ EXPORT_SYMBOL(unregister_chrdev); EXPORT_SYMBOL(register_blkdev); EXPORT_SYMBOL(unregister_blkdev); -EXPORT_SYMBOL(get_blkfops); EXPORT_SYMBOL(tty_register_driver); EXPORT_SYMBOL(tty_unregister_driver); EXPORT_SYMBOL(tty_std_termios);