kernel module to write data to a file

2006-11-07 Thread Robotis Konstantinos

Hello,

I am trying to create a module for kernel 2.4.27 that writes data to a
file when it
receives a packet from the network interface card. In the code below
the pkt_handler function is called each time a packet is received. A
while after the insmod, the CPU reaches 100% and the pc freezes.

Is there something wrong with the code or is there an alternate way to
write data to a file? Actually I think this is the right way but the
problem is that the opening and writing are happening too often.

Don't tell me to use the proc filesystem, it is not appropriate in my case.

Thanks in advance.

(I've commented out the semaphore operations because they don't seem to
work as they are currently used)

/* Packet handler. It is called by the kernel when a new packet has
been received.  */
int pkt_handler (struct sk_buff *skb, struct net_device *dv, struct
packet_type *pt)
{
static int calls = 0;
kfree_skb (skb);

printk (KERN_ALERT "packet %d received\n", calls);
if (calls++ > 10) {
  open_f_and_write ("/tmp/tmp.log");
  calls = 0;
}

return 0;
}


int open_f_and_write (const char *file_name)
{
struct file *file = NULL;
mm_segment_t fs;
char *tmp;
struct inode *inode;

tmp = getname (file_name);

file = filp_open (tmp, O_CREAT | O_WRONLY | O_APPEND, S_IRWXU);
if (IS_ERR (file)) {
  int errno = PTR_ERR (file);
  printk (KERN_DEBUG "error %i\n", errno);
  return 2;
}
if (!file->f_op->write) {
  fput (file);
  return 3;
}

fs = get_fs ();
set_fs (KERNEL_DS);
//inode = file->f_dentry->d_inode;
//down (&inode->i_sem);

{
  char *buffer = "write something\n";
  int p = file->f_op->write (file, buffer, m_strlen (buffer),
&file->f_pos);
  printk (KERN_ALERT "write returned %d\n", p);
}
//up(&inode->i_sem);
set_fs (fs);
putname (tmp);
filp_close (file, NULL);

return 0;
}


--
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]




PCMCIA problem

2006-10-26 Thread Robotis Konstantinos
I have Debian Sarge with kernel 2.6.8-2 and I want to install a wireless
pcmcia card. The kernel is configured with every module related to
PCMCIA as far as I am concerned and the pcmcia-cs package is also
installed. The problem is that when the the /etc/init.d/pcmcia script
starts I always get following:
 

euklides:/usr/src# /etc/init.d/pcmcia start

Starting PCMCIA services: using yenta_socket instead of i82365

cardmgr[6759]: no sockets found!

done.
 

Any suggestions?
 

I haven't provided you with the details of the wireless card because
that's irrelevant (for the time being) since the pcmcia device is not
recognized.