From owner-freebsd-hackers@FreeBSD.ORG Fri May 7 08:59:23 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 701401065670 for ; Fri, 7 May 2010 08:59:23 +0000 (UTC) (envelope-from krivenok.dmitry@gmail.com) Received: from mail-ew0-f224.google.com (mail-ew0-f224.google.com [209.85.219.224]) by mx1.freebsd.org (Postfix) with ESMTP id 061838FC1D for ; Fri, 7 May 2010 08:59:22 +0000 (UTC) Received: by ewy24 with SMTP id 24so199600ewy.33 for ; Fri, 07 May 2010 01:59:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=liiAUXldFRhd+CtEAkC/ioKeoacqWusrgQClWTBQJeA=; b=jM6meGzauTpITA47UHQAkSEuZrytswQBBwJ36JYg94QJw2hCBY1b4XJ7jYoY4n4IkG WM0EiqKHjh7QJJM2l1DduzDPkri24vK/ABQgv79JGw+wFeIRcJ89g/awgW8QTbG5Kpir 6XKBUn25z9drRyslt45KSDljLZZ8LaUYaqog8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=ge4PKjmy0oaAXnvwsw/s89zElD159d9a1LcoteorqC2Lu1xUjKCzZhT94t5zzHxYp4 B+AWOItV9Omx+DUrgX3BV1GE9wFv1rmMnRqdDXQjJzmSBQCWJeG0twOD+UgnzQT0BgWb CvC86v+fpX3cWvVy0sILKTKea2llAabBhlHyU= MIME-Version: 1.0 Received: by 10.213.55.209 with SMTP id v17mr4004462ebg.98.1273222750812; Fri, 07 May 2010 01:59:10 -0700 (PDT) Received: by 10.213.35.197 with HTTP; Fri, 7 May 2010 01:59:10 -0700 (PDT) Date: Fri, 7 May 2010 12:59:10 +0400 Message-ID: From: Dmitry Krivenok To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Subject: Moving from FreeBSD7 to FreeBSD8 (cdev, minor, dev2unit) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 May 2010 08:59:23 -0000 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