what is the problem with this incomplete module ?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



the code below is incomplete.. but the scala is in that way.

#define MODULE
#include <linux/module.h>
#include <linux/ioport.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/proc_fs.h>
#include <linux/sem.h>
#include <linux/config.h>
#include <linux/types.h>
#include <linux/fcntl.h>
#include <linux/irq.h>

typedef struct Dev {
  void **data; 
  struct semaphore sem;
  struct Dev *next;
  int quantum;
  int qset;
  unsigned long size;
  unsigned int access_key;
 } Dev; 



loff_t skull_seek(struct file *, loff_t, int);
ssize_t skull_read(struct file *, char *, size_t, loff_t *);
ssize_t skull_write(struct file *, const char *, size_t, loff_t *);
int skull_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
int skull_open(struct inode *, struct file *);
int skull_release(struct inode *, struct file *);

struct file_operations f_ops = {
   llseek:	skull_seek,
   read:	skull_read,
   write:	skull_write,
   ioctl:	skull_ioctl,
   open:	skull_open,
   release:	skull_release,
};  

unsigned long skull_major = 254;
int result;


init_module(void)
{ 
  result = register_chrdev(skull_major, "skull", &f_ops);
  if(skull_major == 0) skull_major = result;
  if(result < 0) return result;   
  printk("Ok\n");  
  return 0; 
}

cleanup_module(void)
{
 unregister_chrdev(skull_major, "skull"); 
 printk("stmodule is removed\n");
}


loff_t skull_seek(struct file * filp, loff_t lale, int inte)
{
return 0;
}

ssize_t skull_read(struct file * filp, char *ch, size_t boyut, loff_t *bil)
{
return 0;
}

ssize_t skull_write(struct file * fp, const char *ch, size_t byt, loff_t *bil)
{
 return 0;

}

int skull_ioctl(struct inode * inodi, struct file * filp, unsigned
int uint, unsigned long unlong )
{
  return 0;
}


int skull_open(struct inode * inode, struct file * filp)
{
  int i;
  loff_t *bil;   
  Dev *dev;
  const char *buf;
  printk("Major Number =>%d\n",inode->i_rdev >> 8);    
  printk("Minor Number =>%d\n",inode->i_rdev & 0xff);  
  
  filp->f_op = &f_ops;

  sema_init(&dev->sem, 1); 

  dev = (Dev *)filp->private_data; 
  
/* the problem is below */

  if((filp->f_flags & O_ACCMODE) == O_WRONLY) {
    down_interruptible(&dev->sem);
    up(&dev->sem);   
       
  }   
   MOD_INC_USE_COUNT;  
   return 0;

}

int skull_release(struct inode * inode, struct file * filp)
{
  MOD_DEC_USE_COUNT;  
  return 0;
}


i compile this code with gcc -c -D__MODULE__ -D__KERNEL__ scull.c
there in no problem when reading the device with the major number assigned to this 
module. like this cat /dev/scull0
however, when trying to write to the device such as using 
cat > /dev/scull0
then, kernel fails and halts. there is an opps..

according to you.. what is the problem?

and how can i overcome the GPL warnings when i install the module.. i dont wanna see the warnings. how should i make changes in the code not to let the warning outcome..

sincerely






---------------------------------------
This message was sent by Postaci Webmail. See www.trlinux.com for details.

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux