Date: Fri, 7 May 2010 12:59:10 +0400 From: Dmitry Krivenok <krivenok.dmitry@gmail.com> To: freebsd-hackers@freebsd.org Subject: Moving from FreeBSD7 to FreeBSD8 (cdev, minor, dev2unit) Message-ID: <m2ida48cf211005070159ma464fef5h5baf0107ee6e4e88@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
Hello Hackers,
I'm working on porting some kernel modules written for FreeBSD7 to FreeBSD8.
Some of these modules contain the following code:
struct cdev *dev;
...
int dev_num = minor(dev);
This code doesn't compile on FreeBSD8.
I found that in FreeBSD7 minor() was defined as follows:
515 int
516 minor(struct cdev *x)
517 {
518 if (x == NULL)
519 return NODEV;
520 return(x->si_drv0 & MAXMINOR);
521 }
where MAXMINOR was defined as
236 #define MAXMINOR 0xffff00ffU
But in FreeBSD8 minor() is defined as macro that takes integer as a parameter:
323 #define minor(x) ((int)((x)&0xffff00ff)) /* minor number */
I also found that FreeBSD8 provides dev2unit macro:
276 #define dev2unit(d) ((d)->si_drv0)
It looks like dev2unit is exactly what I need to fix compilation issue.
I changed the code of all modules as follows:
- int dev_num = minor(dev);
+ int dev_num = minor(dev2unit(dev));
and now it compiles and works well.
Is this the proper way of solving the problem?
Thanks in advance!
--
Sincerely yours, Dmitry V. Krivenok
e-mail: krivenok.dmitry@gmail.com
skype: krivenok_dmitry
jabber: krivenok_dmitry@jabber.ru
icq: 242-526-443
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?m2ida48cf211005070159ma464fef5h5baf0107ee6e4e88>
