Moving from FreeBSD7 to FreeBSD8 (cdev, minor, dev2unit)

Ed Schouten ed at 80386.nl
Mon May 10 16:48:27 UTC 2010


* Dmitry Krivenok <krivenok.dmitry at gmail.com> wrote:
> - int dev_num = minor(dev);
> + int dev_num = minor(dev2unit(dev));

Almost there. Just remove all calls to unit2minor() and minor2unit() (if
present) and replace minor() with dev2unit():

	int dev_num = dev2unit(dev);

But even better, don't use device unit numbers at all. The struct cdev
already provides fields like si_drv1 and si_drv2 that can be used to
store per-device data. Some drivers use constructs like these:

	sc = device_get_softc(devclass_get_device(devclass, dev2unit(cdev)));

In those cases the code should just be changed to do something similar
to the following:

	cdev = make_dev(....);
	cdev->si_drv1 = sc;

Greetings,
-- 
 Ed Schouten <ed at 80386.nl>
 WWW: http://80386.nl/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20100510/5763ac85/attachment.pgp


More information about the freebsd-hackers mailing list