From bryan@barmetta.barmetta.com  Thu Mar 30 21:45:15 2000
Return-Path: <bryan@barmetta.barmetta.com>
Received: from barmetta.barmetta.com (cm-24-142-60-178.cableco-op.ispchannel.com [24.142.60.178])
	by hub.freebsd.org (Postfix) with ESMTP id 6C71C37B83C
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 30 Mar 2000 21:45:08 -0800 (PST)
	(envelope-from bryan@barmetta.barmetta.com)
Received: (from bryan@localhost)
	by barmetta.barmetta.com (8.9.3/8.9.3) id VAA18175;
	Thu, 30 Mar 2000 21:45:01 -0800 (PST)
	(envelope-from bryan)
Message-Id: <200003310545.VAA18175@barmetta.barmetta.com>
Date: Thu, 30 Mar 2000 21:45:01 -0800 (PST)
From: bryan@barmetta.com
Sender: bryan@barmetta.barmetta.com
Reply-To: bryan@barmetta.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: /usr/share/examples/kld/cdev won't compile
X-Send-Pr-Version: 3.2

>Number:         17703
>Category:       misc
>Synopsis:       /usr/share/examples/kld/cdev won't compile
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    dfr
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Mar 30 21:50:00 PST 2000
>Closed-Date:    Mon Oct 2 07:28:20 PDT 2000
>Last-Modified:  Mon Oct 02 07:28:45 PDT 2000
>Originator:     bryan d. o'connor
>Release:        FreeBSD 4.0-STABLE i386
>Organization:
barmetta.com
>Environment:

FreeBSD barmetta.barmetta.com 4.0-STABLE FreeBSD 4.0-STABLE #8: Tue Mar 28 18:11:36 PST 2000     root@barmetta.barmetta.com:/usr/src/sys/compile/BARMETTA  i386

>Description:

/usr/share/examples/kld/cdev is out of date and will no longer
compile under FreeBSD 4.0-STABLE.


>How-To-Repeat:

cd /usr/share/examples/kld/cdev
make

>Fix:

this is my first experience with KLDs, so i used the vn
device as an example.  apologies if that was a poor choice
of example.. i don't know any better yet. ;)

see patch below or at:
  http://www.barmetta.com/freebsd/examples-kld-cdev.patch

diff -rc cdev-old/module/cdevmod.c cdev/module/cdevmod.c
*** cdev-old/module/cdevmod.c	Thu Mar 30 21:19:48 2000
--- cdev/module/cdevmod.c	Thu Mar 30 21:17:15 2000
***************
*** 81,99 ****
  	/* read */	noread,
  	/* write */	nowrite,
  	/* ioctl */	mydev_ioctl,
- 	/* stop */	nostop,
- 	/* reset */	noreset,
- 	/* devtotty */	nodevtotty,
  	/* poll */	nopoll,
  	/* mmap */	nommap,
  	/* strategy */	nostrategy,
  	/* name */	"cdev",
- 	/* parms */	noparms,
  	/* maj */	CDEV_MAJOR,
  	/* dump */	nodump,
  	/* psize */	nopsize,
  	/* flags */	D_TTY,
- 	/* maxio */	0,
  	/* bmaj */	-1
  };
  
--- 81,94 ----
***************
*** 109,115 ****
   */
  
  static int
! cdev_load(module_t mod, int cmd, void *arg)
  {
      int  err = 0;
  
--- 104,110 ----
   */
  
  static int
! cdev_modevent(module_t mod, int cmd, void *arg)
  {
      int  err = 0;
  
***************
*** 117,122 ****
--- 112,119 ----
      case MOD_LOAD:
  	
  	/* Do any initialization that you should do with the kernel */
+ 	cdevsw_add(&my_devsw);
+ 	make_dev(&my_devsw, 0, UID_ROOT, GID_OPERATOR, 0644, "%s", "cdev");
  	
  	/* if we make it to here, print copyright on console*/
  	printf("\nSample Loaded kld character device driver\n");
***************
*** 126,135 ****
  	break;		/* Success*/
  
      case MOD_UNLOAD:
  	printf("Unloaded kld character device driver\n");
  	break;		/* Success*/
  
!     default:	/* we only understand load/unload*/
  	err = EINVAL;
  	break;
      }
--- 123,136 ----
  	break;		/* Success*/
  
      case MOD_UNLOAD:
+ 	/* fall through */
+     case MOD_SHUTDOWN:
+ 	cdevsw_remove(&my_devsw);
+ 
  	printf("Unloaded kld character device driver\n");
  	break;		/* Success*/
  
!     default:
  	err = EINVAL;
  	break;
      }
***************
*** 139,142 ****
  
  /* Now declare the module to the system */
  
! DEV_MODULE(cdev, CDEV_MAJOR, -1, my_devsw, cdev_load, 0);
--- 140,143 ----
  
  /* Now declare the module to the system */
  
! DEV_MODULE(cdev, cdev_modevent, NULL);

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->dfr 
Responsible-Changed-By: sheldonh 
Responsible-Changed-When: Fri Mar 31 01:58:54 PST 2000 
Responsible-Changed-Why:  
Doug's baby. 

From: Bruce Evans <bde@zeta.org.au>
To: bryan@barmetta.com
Cc: FreeBSD-gnats-submit@FreeBSD.ORG
Subject: Re: misc/17703: /usr/share/examples/kld/cdev won't compile
Date: Fri, 31 Mar 2000 20:06:12 +1000 (EST)

 On Thu, 30 Mar 2000 bryan@barmetta.com wrote:
 
 > this is my first experience with KLDs, so i used the vn
 > device as an example.  apologies if that was a poor choice
 > of example.. i don't know any better yet. ;)
 
 It was a poor choice :-).
 
 vn gives many bad examples, in particular its use of an event handler,
 cdevsw_add() and cdevsw_remove().  Event handlers are not necessary 
 for at least most drivers (the newbus framework is more convenient),
 and cdevsw_add() and cdevsw_remove() are deprecated (passing the devsw
 via make_dev() should be sufficient).
 
 The joy driver is a much better example of a simple driver.
 
 Bruce
 
 
State-Changed-From-To: open->closed 
State-Changed-By: sobomax 
State-Changed-When: Mon Oct 2 07:28:20 PDT 2000 
State-Changed-Why:  
Similar fix committed. Anyway thank you for submission! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=17703 
>Unformatted:
