[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
 

modulprogrammering



For sjov skyld ville jeg lave et lille fortune modul til kernen( man kan
vel ikke leve uden ).
Jeg for problemer når jeg laver min struct file_operations. Folk på
nettet siger, at det skulle
løse problemet at sætte NULL, som det sidste argument, da den selv
skulle kunne "fylde"
de resterende elementer ud. Jeg prøver at compile på en 2.2-14 kerne.

Koden ser indtil videre sådan her ud:

//inkluder header filer
#include <linux/kernel.h>
#include <linux/module.h>
//vi arbejder i filsystemet
#include <linux/fs.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();
ssize_t fortune_read( struct file *f,char *buf, ssize_t count, loff_t
*ppos );

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

//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");
}

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.
 memcpy_tofs( buf, message, count );

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


Jeg får den følgende fejl:

fortune.c:26: warning: `struct file' declared inside parameter list
fortune.c:26: warning: its scope is only this definition or declaration,

fortune.c:26: warning: which is probably not what you want.
fortune.c:29: variable `fortune_fops' has initializer but incomplete
type
fortune.c:30: warning: excess elements in struct initializer after
`fortune_fops'
fortune.c:31: warning: excess elements in struct initializer after
`fortune_fops'
fortune.c:32: warning: excess elements in struct initializer after
`fortune_fops'
fortune.c:54: warning: `struct file' declared inside parameter list
fortune.c:55: conflicting types for `fortune_read'
fortune.c:26: previous declaration of `fortune_read'
fortune.c: In function `fortune_read':
fortune.c:69: dereferencing pointer to incomplete type

Jeg håber nogle kan hjælpe mig

Med venlig hilsen

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] *