[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] Multitrådet programmering



Når til de der er interesseret.

Jeg fik lavet lidt læsning, og memcpy_tofs er erstattet med copy_to_user
i 2.2 kernen. For
at benytte den skal man inkludere <asm/uaccess.h>.
Mit nye modul kom til at se sådan her ud.

//inkluder header filer
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/wrapper.h>
//vi arbejder i filsystemet
#include <linux/fs.h>
#include <asm/uaccess.h>
//vi arbejder med kernenn
#ifndef __KERNEL__
#define __KERNEL__
#endif

//vi arbejder med moduler
#ifndef MODULE
#define MODULE
#endif

//håndterer versioner
#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include <linux/modversions.h>
#endif

//erklærer vores funktioner
int init_module();
void cleanup_module();
static ssize_t fortune_read( struct file *f,char *buf, ssize_t
count,loff_t *ppos );
struct file_operations fortune_fops;

//bliver kaldt når modulet bliver loaded
int init_module()
{
 int loaded = register_chrdev( 191, "fortune", &fortune_fops );
 if( loaded < 0 ){
  printk("<1>Could not assign major number for module fortune");
  return -1;
 }
 printk("<1>succesfully registered module fortune");
 return 0;
}

//bliver kaldt når modulet bliver fjernet
void cleanup_module()
{
 unregister_chrdev( 191, "fortune" );
 printk("<1>succesfully removed module fortune");
}

static ssize_t fortune_read( struct file *f,char *buf, ssize_t
count,loff_t *ppos )
{
 char *message ="Hello World";
 //hvis pointeren er længere end "filen" returneres EOF
 if( *ppos > 10 )
  return 0;

 //hvis der skal hæntes mere end der er i "filen" bliver count
 //sat til 10 - f_pos
 if( *ppos + count > 10 )
  count = 10 - *ppos;
 //skriver den del af bufferen der skal skrives.
 copy_to_user( buf, message, count );

 //opdaterer pointeren i "filen"
 f->f_pos += count;
 return count;
}


//definerer vores filoperationer( indtil videre kun read )
struct file_operations fortune_fops = {
 NULL, //lseek
 fortune_read,
 NULL, //write
};

Det skulle virke med egcs, men nu har jeg installeret
2.7.2( IF IT AIN'T BROKEN WHY FIX IT )

Lars Hansen



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *