Skip to contentSkip to conversation

dev_t [2/3]

PATCH In review [email protected] 2 participants 2 messages Mar 18, 2003

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dev_t [2/3]

The actual patch for today is this part. I already quoted most of this on the list earlier this week.

In order not to have to change all drivers, I did

+int register_chrdev(unsigned int major, const char *name,
+ struct file_operations *fops)
+{
+ return register_chrdev_region(major, 0, 256, name, fops);
+}

so that the old register_chrdev registers a single major and 256 minors. Later this can be changed (but see my letter to Al last week).

The only driver that is tricky is the tty driver. Here some major cleanup happened - all tty specific stuff disappeared from char_dev.c, and tty uses the actual register_chrdev_region() call.

There is a race in register_chrdev_region() that I did not worry about: when two dynamic majors 0 are registered simultaneously, one of them will be first and the other one gets -EBUSY. If this is a problem, the code there will have to be uglified a little. I didn't do that because it disappears again in a subsequent patch.

Andries

----------------- 02-chardev-patch ------------------

drivers/char/ip2/ip2.h +4 -15
diff -u --recursive --new-file -X /linux/dontdiff a/drivers/char/ip2/ip2.h b/drivers/char/ip2/ip2.h
@@ -23,21 +23,10 @@
 /* Constants */
 /*************/
 
-/* Device major numbers
- * The first set are the major numbers allocated from the Linux Device Registry.
- * This was expanded from 64 to 128 with version 2.0.26. If this code is built
- * under earlier versions we use majors from the LOCAL/EXPERIMENTAL range.
- */
-#if MAX_CHRDEV > 64
-#	define IP2_TTY_MAJOR      71
-#	define IP2_CALLOUT_MAJOR  72
-#	define IP2_IPL_MAJOR      73
-#else
-#	define IP2_TTY_MAJOR      60
-#	define IP2_CALLOUT_MAJOR  61
-#	define IP2_IPL_MAJOR      62
-#endif
-
+/* Device major numbers - since version 2.0.26. */
+#define IP2_TTY_MAJOR      71
+#define IP2_CALLOUT_MAJOR  72
+#define IP2_IPL_MAJOR      73
 
 /* Board configuration array.
  * This array defines the hardware irq and address for up to IP2_MAX_BOARDS
drivers/char/tty_io.c +2 -1
diff -u --recursive --new-file -X /linux/dontdiff a/drivers/char/tty_io.c b/drivers/char/tty_io.c
@@ -2114,7 +2114,8 @@
 	if (driver->flags & TTY_DRIVER_INSTALLED)
 		return 0;
 
-	error = register_chrdev(driver->major, driver->name, &tty_fops);
+	error = register_chrdev_region(driver->major, driver->minor_start,
+				       driver->num, driver->name, &tty_fops);
 	if (error < 0)
 		return error;
 	else if(driver->major == 0)
fs/char_dev.c +145 -74

280 lines not on this page · raw message

fs/inode.c +1 -1
diff -u --recursive --new-file -X /linux/dontdiff a/fs/inode.c b/fs/inode.c
@@ -145,7 +145,7 @@
 		mapping->assoc_mapping = NULL;
 		mapping->backing_dev_info = &default_backing_dev_info;
 		if (sb->s_bdev)
-			inode->i_data.backing_dev_info = sb->s_bdev->bd_inode->i_mapping->backing_dev_info;
+			mapping->backing_dev_info = sb->s_bdev->bd_inode->i_mapping->backing_dev_info;
 		memset(&inode->u, 0, sizeof(inode->u));
 		inode->i_mapping = mapping;
 	}
include/linux/fs.h +4 -1
diff -u --recursive --new-file -X /linux/dontdiff a/include/linux/fs.h b/include/linux/fs.h
@@ -1053,7 +1053,10 @@
 extern void blk_run_queues(void);
 
 /* fs/char_dev.c */
-extern int register_chrdev(unsigned int, const char *, struct file_operations *);
+extern int register_chrdev_region(unsigned int, unsigned int, int,
+				  const char *, struct file_operations *);
+extern int register_chrdev(unsigned int, const char *,
+			   struct file_operations *);
 extern int unregister_chrdev(unsigned int, const char *);
 extern int chrdev_open(struct inode *, struct file *);
 
#1 lore raw
Quoted 11 lines · On Tue, Mar 18, 2003 at 11:02:21PM +0100, [email protected] wrote:

In order not to have to change all drivers, I did

fs/char_dev.c +5 -0
+int register_chrdev(unsigned int major, const char *name,
+                   struct file_operations *fops)
+{
+       return register_chrdev_region(major, 0, 256, name, fops);
+}

so that the old register_chrdev registers a single major and 256 minors. Later this can be changed (but see my letter to Al last week).

This is nice, thanks. We don't have to touch the char drivers now.

Ah, I wish we could change that function to be:
int register_chrdev_region(major, num_minors, name, fops) if it wasn't for the tty drivers wanting to start their minor at 64.

Hm, wait, why can't we just do it that way and not change the tty core to use the register_chrdev_region() call? It should still all work properly, right? The tty core would ask for 256 minors, and split them off the same way it currently does.

thanks,

greg k-h