Re: skeleton char driver

Tigran Aivazian (tigran@sco.COM)
Mon, 4 Oct 1999 16:04:30 +0100 (BST)


Hi,

Try these (should work on 2.3.latest though I haven't tested them - just
typed in from memory :) (I couldn't compile because my workstation runs
2.2.12 but the code below is for 2.3.x).

Note the use of major 42 - it is intentional, read
Documentation/devices.txt to understand why.

Regards,
------
Tigran A. Aivazian | http://www.sco.com
Escalations Research Group | tel: +44-(0)1923-813796
Santa Cruz Operation Ltd | http://www.ocston.org/~tigran

#
# Simple Makefile for Skeleton Char Driver
#

INCLUDEDIR = /usr/include
CC = gcc

CFLAGS = -D__KERNEL__ -I$(INCLUDEDIR) -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer -pipe -fno-strength-reduce -m486 -malign-loops=2 -malign-jumps=2 -malign-functions=2 -DCPU=586 -DMODULE

VER = $(shell awk -F\" '/REL/ {print $$2}' $(INCLUDEDIR)/linux/version.h)

OBJS = skel.o

all: $(OBJS)

install:
install -d /lib/modules/$(VER)/char
install -c skel.o /lib/modules/$(VER)/char

clean:
rm -f *.o *~ core *.bak

/*
* Skeleton Char Driver.
*/

#include <linux/module.h>
#include <linux/fs.h>
#include <linux/poll.h>
#include <linux/init.h>
#include <asm/uaccess.h>

#define SKEL_VERSION "0.01"
#define SKEL_MAJOR 42

static long long skel_llseek(struct file *file, loff_t offset, int origin)
{
return -ESPIPE;
}

static ssize_t skel_read(struct file *file, char *buf, size_t count, loff_t *ppos)
{
return -EIO;
}

static int skel_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
return -EINVAL;
}

static int skel_open(struct inode *inode, struct file *file)
{
return 0;
}

static int skel_release(struct inode *inode, struct file *file)
{
return 0;
}

static unsigned int skel_poll(struct file *file, poll_table *wait)
{
return -EIO;
}

static struct file_operations skel_fops = {
llseek: skel_llseek,
read: skel_read,
write: NULL,
readdir: NULL,
poll: skel_poll,
ioctl: skel_ioctl,
mmap: NULL,
open: skel_open,
flush: NULL,
release: skel_release,
fsync: NULL,
fasync: NULL,
check_media_change: NULL,
revalidate: NULL,
lock: NULL
};

static int __init skel_init(void)
{
printk(KERN_INFO "Skeleton Char Driver v%s\n", SKEL_VERSION);
if (register_chrdev(SKEL_MAJOR, "skel", &skel_fops)) {
printk("skel: unable to get major %d\n", SKEL_MAJOR);
return -EBUSY;
}
return 0;
}

static void __exit skel_exit(void)
{
unregister_chrdev(SKEL_MAJOR, "skel");
}

module_init(skel_init);
module_exit(skel_exit);

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/