Update the sample 'echo' character device driver for 5.x:
- Use an dynamic major number rather than a static one. - Use 'struct cdev *' rather than 'dev_t'. - Add d_version field to echo_devsw. - Use malloc()/free() rather than the macros. Submitted by: Karl Andersson karland at home dot se (2,3)
This commit is contained in:
parent
631dc54dfb
commit
53bd474e4d
Notes:
svn2git
2020-12-08 03:00:23 +00:00
svn path=/head/; revision=22728
1 changed files with 10 additions and 11 deletions
|
@ -364,7 +364,6 @@ DEV_MODULE(echo,echo_loader,NULL);</programlisting>
|
|||
#include <sys/malloc.h>
|
||||
|
||||
#define BUFFERSIZE 256
|
||||
#define CDEV_MAJOR 33
|
||||
|
||||
|
||||
/* Function prototypes */
|
||||
|
@ -375,12 +374,12 @@ static d_write_t echo_write;
|
|||
|
||||
/* Character device entry points */
|
||||
static struct cdevsw echo_cdevsw = {
|
||||
.d_version = D_VERSION,
|
||||
.d_open = echo_open,
|
||||
.d_close = echo_close,
|
||||
.d_maj = CDEV_MAJOR,
|
||||
.d_name = "echo",
|
||||
.d_read = echo_read,
|
||||
.d_write = echo_write
|
||||
.d_write = echo_write,
|
||||
.d_name = "echo",
|
||||
};
|
||||
|
||||
typedef struct s_echo {
|
||||
|
@ -389,7 +388,7 @@ typedef struct s_echo {
|
|||
} t_echo;
|
||||
|
||||
/* vars */
|
||||
static dev_t echo_dev;
|
||||
static struct cdev *echo_dev;
|
||||
static int count;
|
||||
static t_echo *echomsg;
|
||||
|
||||
|
@ -415,12 +414,12 @@ echo_loader(struct module *m, int what, void *arg)
|
|||
0600,
|
||||
"echo");
|
||||
/* kmalloc memory for use by this driver */
|
||||
MALLOC(echomsg, t_echo *, sizeof(t_echo), M_ECHOBUF, M_WAITOK);
|
||||
echomsg = malloc(sizeof(t_echo), M_ECHOBUF, M_WAITOK);
|
||||
printf("Echo device loaded.\n");
|
||||
break;
|
||||
case MOD_UNLOAD:
|
||||
destroy_dev(echo_dev);
|
||||
FREE(echomsg,M_ECHOBUF);
|
||||
free(echomsg, M_ECHOBUF);
|
||||
printf("Echo device unloaded.\n");
|
||||
break;
|
||||
default:
|
||||
|
@ -431,7 +430,7 @@ echo_loader(struct module *m, int what, void *arg)
|
|||
}
|
||||
|
||||
static int
|
||||
echo_open(dev_t dev, int oflags, int devtype, struct thread *p)
|
||||
echo_open(struct cdev *dev, int oflags, int devtype, struct thread *p)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
|
@ -440,7 +439,7 @@ echo_open(dev_t dev, int oflags, int devtype, struct thread *p)
|
|||
}
|
||||
|
||||
static int
|
||||
echo_close(dev_t dev, int fflag, int devtype, struct thread *p)
|
||||
echo_close(struct cdev *dev, int fflag, int devtype, struct thread *p)
|
||||
{
|
||||
uprintf("Closing device \"echo.\"\n");
|
||||
return(0);
|
||||
|
@ -453,7 +452,7 @@ echo_close(dev_t dev, int fflag, int devtype, struct thread *p)
|
|||
*/
|
||||
|
||||
static int
|
||||
echo_read(dev_t dev, struct uio *uio, int ioflag)
|
||||
echo_read(struct cdev *dev, struct uio *uio, int ioflag)
|
||||
{
|
||||
int err = 0;
|
||||
int amt;
|
||||
|
@ -476,7 +475,7 @@ echo_read(dev_t dev, struct uio *uio, int ioflag)
|
|||
*/
|
||||
|
||||
static int
|
||||
echo_write(dev_t dev, struct uio *uio, int ioflag)
|
||||
echo_write(struct cdev *dev, struct uio *uio, int ioflag)
|
||||
{
|
||||
int err = 0;
|
||||
|
||||
|
|
Loading…
Reference in a new issue