derheini
07-01-2008, 19:33
Hi,
ich schreibe mir gerade ein Kernelmodul für ein kleines Gerät, welches ich mal im Schulunterricht gebaut habe.
#include <linux/version.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <asm/uaccess.h>
#include <linux/io.h>
#include <linux/proc_fs.h>
#include <linux/device.h>
#define DRIVER_MAJOR 240
#define outport 0x378
#define inport 0x379
static struct proc_dir_entry *proc_dir, *proc_file;
static int driver_open( struct inode *geraete_datei, struct file *instanz );
static int driver_close( struct inode *geraete_datei, struct file *instanz );
static ssize_t driver_read( struct file *instanz, char *user, size_t count, loff_t *offset );
static int proc_read(char *buffer, char **start, off_t offset, int count, int *peof, void *dat);
void get_value(char *byte);
static struct file_operations fops = {
.owner= THIS_MODULE,
.read= driver_read,
.open= driver_open,
.release= driver_close,
};
static int driver_open( struct inode *geraete_datei, struct file *instanz ) {
...
}
static int driver_close( struct inode *geraete_datei, struct file *instanz ) {
...
}
static ssize_t driver_read( struct file *instanz, char *user, size_t count, loff_t *offset ) {
....
}
static int proc_read(char *buf, char **start, off_t offset, int size, int *eof, void *data) {
....
}
void get_value(char *byte) {
....
}
static int __init mod_init(void) {
if( register_chrdev(DRIVER_MAJOR,"andigwan",&fops) )
goto fail_register_chrdev_andigwan;
proc_dir = proc_mkdir( "andigwan", NULL );
if( !proc_dir )
goto fail_proc_mkdir_andigwan;
proc_file = create_proc_read_entry( "digital", S_IRUSR | S_IRGRP | S_IROTH, proc_dir, proc_read, NULL );
if( !proc_file )
goto fail_create_proc_read_entry;
proc_file->read_proc = proc_read;
proc_file->data = NULL;
return 0; // Treiber erfolgreich angemeldet
fail_create_proc_read_entry: printk( "proc_read_entry \"digital\" nicht erstellt" );
remove_proc_entry( "andigwan", NULL );
fail_proc_mkdir_andigwan: printk( "proc_dir \"andigwan\" nicht erstellt" );
unregister_chrdev(DRIVER_MAJOR,"andigwan");
fail_register_chrdev_andigwan: return -EIO; // Anmeldung beim Kernel fehlgeschlagen
}
static void __exit mod_exit(void) {
remove_proc_entry( "digital", proc_dir );
remove_proc_entry( "andigwan", NULL );
unregister_chrdev(DRIVER_MAJOR,"andigwan");
}
module_init( mod_init );
module_exit( mod_exit );
Das habe ich bisher. Jetzt muss ich aber immer mit "mknod c blub 240 0" das device erstellen. Wie veranlasse ich jetzt den kernel/udev dazu das für mich zu tun, kann irgendwie über Google nichts finden.
mfg
ich schreibe mir gerade ein Kernelmodul für ein kleines Gerät, welches ich mal im Schulunterricht gebaut habe.
#include <linux/version.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <asm/uaccess.h>
#include <linux/io.h>
#include <linux/proc_fs.h>
#include <linux/device.h>
#define DRIVER_MAJOR 240
#define outport 0x378
#define inport 0x379
static struct proc_dir_entry *proc_dir, *proc_file;
static int driver_open( struct inode *geraete_datei, struct file *instanz );
static int driver_close( struct inode *geraete_datei, struct file *instanz );
static ssize_t driver_read( struct file *instanz, char *user, size_t count, loff_t *offset );
static int proc_read(char *buffer, char **start, off_t offset, int count, int *peof, void *dat);
void get_value(char *byte);
static struct file_operations fops = {
.owner= THIS_MODULE,
.read= driver_read,
.open= driver_open,
.release= driver_close,
};
static int driver_open( struct inode *geraete_datei, struct file *instanz ) {
...
}
static int driver_close( struct inode *geraete_datei, struct file *instanz ) {
...
}
static ssize_t driver_read( struct file *instanz, char *user, size_t count, loff_t *offset ) {
....
}
static int proc_read(char *buf, char **start, off_t offset, int size, int *eof, void *data) {
....
}
void get_value(char *byte) {
....
}
static int __init mod_init(void) {
if( register_chrdev(DRIVER_MAJOR,"andigwan",&fops) )
goto fail_register_chrdev_andigwan;
proc_dir = proc_mkdir( "andigwan", NULL );
if( !proc_dir )
goto fail_proc_mkdir_andigwan;
proc_file = create_proc_read_entry( "digital", S_IRUSR | S_IRGRP | S_IROTH, proc_dir, proc_read, NULL );
if( !proc_file )
goto fail_create_proc_read_entry;
proc_file->read_proc = proc_read;
proc_file->data = NULL;
return 0; // Treiber erfolgreich angemeldet
fail_create_proc_read_entry: printk( "proc_read_entry \"digital\" nicht erstellt" );
remove_proc_entry( "andigwan", NULL );
fail_proc_mkdir_andigwan: printk( "proc_dir \"andigwan\" nicht erstellt" );
unregister_chrdev(DRIVER_MAJOR,"andigwan");
fail_register_chrdev_andigwan: return -EIO; // Anmeldung beim Kernel fehlgeschlagen
}
static void __exit mod_exit(void) {
remove_proc_entry( "digital", proc_dir );
remove_proc_entry( "andigwan", NULL );
unregister_chrdev(DRIVER_MAJOR,"andigwan");
}
module_init( mod_init );
module_exit( mod_exit );
Das habe ich bisher. Jetzt muss ich aber immer mit "mknod c blub 240 0" das device erstellen. Wie veranlasse ich jetzt den kernel/udev dazu das für mich zu tun, kann irgendwie über Google nichts finden.
mfg