docs/59587: rewriting examples (part of documentation for FreeBSD 5.x)

Radko Keves rado at studnet.edu.eu.org
Sat Nov 22 16:00:36 UTC 2003


>Number:         59587
>Category:       docs
>Synopsis:       rewriting examples (part of documentation for FreeBSD 5.x)
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-doc
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Sat Nov 22 08:00:32 PST 2003
>Closed-Date:
>Last-Modified:
>Originator:     Radko Keves
>Release:        FreeBSD 5.1-CURRENT i386
>Organization:
UKF-Nitra, Slovakia
>Environment:
System: FreeBSD kripel 5.1-CURRENT FreeBSD 5.1-CURRENT #9: Tue Nov 4 02:27:40 CET 2003 root at kripel:/usr/src/sys/i386/compile/angel i386


	
>Description:
In documentation (/usr/share/examples/kld/cdev) is source code from year 1998 and from this time kernel changed (so kld too).
My patches update this example for new kernels (FreeBSD 5.1 and upper).
Patches are attached
dmesg.boot (of my box too)
>How-To-Repeat:
>Fix:
apply my patches

--- patch-cdevmoc begins here ---
--- module/cdevmod.c	Sat Nov 22 15:49:20 2003
+++ module/cdevmod.c.1	Sat Nov 22 15:46:46 2003
@@ -1,8 +1,9 @@
-/* 08 Nov 1998*/
+/* 22 Nov 2003*/
 /*
  * cdevmod.c - a sample kld module implementing a character device driver.
  *
  * 08 Nov 1998  Rajesh Vaidheeswarran
+ * 22 Nov 2003  Radko Keves
  *
  * Copyright (c) 1998 Rajesh Vaidheeswarran
  * All rights reserved.
@@ -76,22 +77,15 @@
 #include "cdev.h"
 
 #define CDEV_MAJOR 32
-
 static struct cdevsw my_devsw = {
-	/* open */	mydev_open,
-	/* close */	mydev_close,
-	/* read */	mydev_read,
-	/* write */	mydev_write,
-	/* ioctl */	mydev_ioctl,
-	/* poll */	nopoll,
-	/* mmap */	nommap,
-	/* strategy */	nostrategy,
-	/* name */	"cdev",
-	/* maj */	CDEV_MAJOR,
-	/* dump */	nodump,
-	/* psize */	nopsize,
-	/* flags */	D_TTY,
-	/* bmaj */	-1
+	.d_open =	mydev_open,
+	.d_close =	mydev_close,
+	.d_read =	mydev_read,
+	.d_write =	mydev_write,
+	.d_ioctl =	mydev_ioctl,
+	.d_poll =	nopoll,
+	.d_name =	"mydev_",
+	.d_maj =	CDEV_MAJOR,
 };
 
 /* 
@@ -113,36 +107,30 @@
  */
 
 static int
-cdev_load(module_t mod, int cmd, void *arg)
+mydev_modevent(mod,type, data)
+	module_t mod;
+	int type;
+	void *data;
 {
-    int  err = 0;
-
-    switch (cmd) {
-    case MOD_LOAD:
-	
-	/* Do any initialization that you should do with the kernel */
-	
-	/* if we make it to here, print copyright on console*/
-	printf("\nSample Loaded kld character device driver\n");
-	printf("Copyright (c) 1998\n");
-	printf("Rajesh Vaidheeswarran\n");
-	printf("All rights reserved\n");
-	sdev = make_dev(&my_devsw, 0, UID_ROOT, GID_WHEEL, 0600, "cdev");
-	break;		/* Success*/
-
-    case MOD_UNLOAD:
-	printf("Unloaded kld character device driver\n");
-	destroy_dev(sdev);
-	break;		/* Success*/
-
-    default:	/* we only understand load/unload*/
-	err = EINVAL;
-	break;
-    }
-
-    return(err);
+	switch (type) {
+	case MOD_LOAD:
+		printf("\nSample Loaded kld character device driver\n");
+		sdev = make_dev(&my_devsw, 0, UID_ROOT, GID_WHEEL, 0600, "cdev");
+		break;
+	case MOD_UNLOAD:
+		printf("Unloaded kld character device driver\n");
+		destroy_dev(sdev);
+		break;
+	default:
+
+		break;
+	}
+	return (0);
 }
 
-/* Now declare the module to the system */
-
-DEV_MODULE(cdev, cdev_load, NULL);
+static moduledata_t mydev_mod = {
+        "mydev",
+        mydev_modevent,
+        NULL
+};
+DECLARE_MODULE(mydev, mydev_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE + CDEV_MAJOR);
--- patch-cdevmoc ends here ---

--- patch-Makefile begins here ---
--- module/Makefile	Sat Nov 22 15:49:20 2003
+++ module/Makefile.1	Sat Nov 22 15:34:09 2003
@@ -1,16 +1,4 @@
-# Makefile for kld char device driver.
-# $FreeBSD: src/share/examples/kld/cdev/module/Makefile,v 1.5 2001/09/18 12:28:22 ru Exp $
-
 KMOD=	cdev
-SRCS=	cdev.c cdevmod.c
-
-/dev/cdev:
-	mknod ${.TARGET} c 32 0
-
-un/dev/cdev: .PHONY
-	rm -f /dev/cdev
+SRCS=	cdevmod.c cdev.c
 
 .include <bsd.kmod.mk>
-
-load: /dev/cdev
-unload: un/dev/cdev
--- patch-Makefile ends here ---

--- patch-README begins here ---
--- README	Sat Nov 22 15:49:20 2003
+++ README.1	Sat Nov 22 15:48:52 2003
@@ -1,4 +1,5 @@
 # Copyright (c) 1998 Rajesh Vaidheeswarran
+# For FreeBSD 5.x rewrited by Radko Keves 2003
 # All rights reserved.
 #
 # Redistribution and use in source and binary forms, with or without
--- patch-README ends here ---

--- patch-testcdev begins here ---
--- test/testcdev.c	Sat Nov 22 15:49:20 2003
+++ test/testcdev.c.1	Sat Nov 22 15:45:45 2003
@@ -1,11 +1,11 @@
-/* 08 Nov 1998*/
+/* 22 Nov 2003*/
 /*
  * testmisc.c
  *
  * Test program to call the sample loaded kld device driver.
  *
  * 05 Jun 93	Rajesh Vaidheeswarran		Original
- *
+ * 22 Nov 03    Radko Keves			Rewrited for 5.x
  *
  * Copyright (c) 1993 Rajesh Vaidheeswarran.
  * All rights reserved.
@@ -70,7 +70,7 @@
  *
  * $FreeBSD: src/share/examples/kld/cdev/test/testcdev.c,v 1.4 2000/12/09 09:35:39 obrien Exp $
  */
-
+#include <sys/types.h>
 #include <stdio.h>
 #include <fcntl.h>
 #include <paths.h>
--- patch-testcdev ends here ---

--- dmesg.boot begins here ---
Copyright (c) 1992-2003 The FreeBSD Project.
Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
	The Regents of the University of California. All rights reserved.
FreeBSD 5.1-RELEASE #0: Thu Jun  5 02:55:42 GMT 2003
    root at wv1u.btc.adaptec.com:/usr/obj/usr/src/sys/GENERIC
Preloaded elf kernel "/boot/kernel/kernel" at 0xc0689000.
Timecounter "i8254"  frequency 1193182 Hz
Timecounter "TSC"  frequency 133121313 Hz
CPU: Pentium/P54C (133.12-MHz 586-class CPU)
  Origin = "GenuineIntel"  Id = 0x52c  Stepping = 12
  Features=0x1bf<FPU,VME,DE,PSE,TSC,MSR,MCE,CX8>
real memory  = 67108864 (64 MB)
avail memory = 58179584 (55 MB)
Intel Pentium detected, installing workaround for F00F bug
npx0: <math processor> on motherboard
npx0: INT 16 interface
pcibios: BIOS version 2.10
pcib0: <Host to PCI bridge> at pcibus 0 on motherboard
pci0: <PCI bus> on pcib0
isab0: <PCI-ISA bridge> at device 7.0 on pci0
isa0: <ISA bus> on isab0
atapci0: <VIA 82C586B UDMA33 controller> port 0x6000-0x600f at device 7.1 on pci0
ata0: at 0x1f0 irq 14 on atapci0
ata1: at 0x170 irq 15 on atapci0
ed0: <NE2000 PCI Ethernet (RealTek 8029)> port 0x6200-0x621f irq 11 at device 10.0 on pci0
ed0: address 00:e0:7d:85:ff:02, type NE2000 (16 bit) 
pci0: <display, VGA> at device 11.0 (no driver attached)
orm0: <Option ROM> at iomem 0xc0000-0xc7fff on isa0
pmtimer0 on isa0
atkbdc0: <Keyboard controller (i8042)> at port 0x64,0x60 on isa0
atkbd0: <AT Keyboard> flags 0x1 irq 1 on atkbdc0
kbd0 at atkbd0
fdc0: <NEC 765 or clone> at port 0x3f7,0x3f0-0x3f5 irq 6 drq 2 on isa0
fd0: <1440-KB 3.5" drive> on fdc0 drive 0
ppc0: <Parallel port> at port 0x378-0x37f irq 7 on isa0
ppc0: Generic chipset (NIBBLE-only) in COMPATIBLE mode
ppbus0: <Parallel port bus> on ppc0
plip0: <PLIP network interface> on ppbus0
lpt0: <Printer> on ppbus0
lpt0: Interrupt-driven port
ppi0: <Parallel I/O> on ppbus0
sc0: <System console> at flags 0x100 on isa0
sc0: VGA <16 virtual consoles, flags=0x300>
sio0 at port 0x3f8-0x3ff irq 4 flags 0x10 on isa0
sio0: type 16550A
sio1 at port 0x2f8-0x2ff irq 3 on isa0
sio1: type 16550A
vga0: <Generic ISA VGA> at port 0x3c0-0x3df iomem 0xa0000-0xbffff on isa0
ata2: <Generic ESDI/IDE/ATA controller> at port 0x36e,0x168-0x16f irq 10 on isa0
unknown: <PNP0303> can't assign resources (port)
unknown: <PNP0501> can't assign resources (port)
unknown: <PNP0700> can't assign resources (port)
unknown: <PNP0400> can't assign resources (port)
unknown: <PNP0501> can't assign resources (port)
Timecounters tick every 10.000 msec
ad0: 1222MB <WDC AC21200H> [2484/16/63] at ata0-master WDMA2
acd0: CDROM <CD-540E> at ata0-slave PIO4
Mounting root from ufs:/dev/ad0s1a
WARNING: / was not properly dismounted
--- dmesg.boot ends here ---


>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the freebsd-doc mailing list