Subject: Ideas about the cdevsw/bdevsw structs.
To: None <>
From: Anders Magnusson <>
List: tech-kern
Date: 05/16/1999 03:42:14
I have been thinking a little about our current bdevsw/cdevsw design.
It is... ancient, to be nice :-) I would like to have a change of
the way this is handled.

	All devices are registered when they are attached. The attach
	(or similar) function calls a register function with a syntax

		int devsw_register(struct device *,
		    struct bdevsw *, struct cdevsw *);

	The devsw ptr's can be NULL if it isn't applicable (like for
	tty devices no block device). The device struct is used for
	registering the device name in a (future) devfs, and is NULL
	otherwise. The chrtoblk table is maintained from this function.

	Returns zero on success, and some errno otherwise (E2BIG, EEXIST, ...).

	Similar, a function:

		int devsw_unregister(struct bdevsw *, struct cdevsw *);

	is called to detach a device.

	The devsw* functions can be in kern_subr if noone has a better
	idea. They are rather small.

	The bdevsw/cdevsw structs get another field that contains the
	major number for it. The structs with the function calls are
	kept in each driver and not necessarily visible outside that file.

	All major numbers are kept in an include file; machine/conf.h
	for example. They are syntactically:

	#define	CDEV_CN_MAJOR	0
	#define CDEV_MM_MAJOR	1
	#define	BDEV_SD_MAJOR	42

	etc, to allow use from MI code. 

	config(8) is changed to include and use this defines in swapnetbsd.c
	instead of getting the majors out of the "files" file. No need to
	duplicate info :-)

Comments about this? If noone screams loudly or has a better idea I would
like to check this in in a couple of days.

-- Ragge