3
votes

I'm planning to write a new device driver on Linux kernel.The device I intend to write will be a device that will pipe the data coming into it to another computer that will be also having the same device.

So in short the device will be readable/writable and should communicate through network.I know it sounds like a socket but the idea would be to implement a interface in shell so that if you type

    root@host$ echo "Hi" >> mydevice 

will transfer the word Hi to the system on the other side of network (and may be configure it to store on file).

This is a leisure time project I intend to do and it sounds much like sockets and other already existing implementations.Well the questions regarding the design for device implementations are:

  1. Should I use a block or a character device? The advantage I see for a block device is that if I am a initiating a complete file transfer through the device (which I in tend to support later), then it would be fast.
  2. How do I write the data on the network? I'm familiar with sockets and stuff, but using sockets from with in the Kernel has performance issues (I read it somewhere, after all sockets was designed to be used in userspace).Will using netfilter or other stuffs work ?Maybe crafting the packet directly would help :-)? Any innovations are welcome
  3. How do I configure the driver, like how do I let it know that it should connect to a specific host in user space programs we usually do this by config files , but to change the connection settings of a driver how do you manage it? (sysfs ?? Frankly I never worked with sysfs or proc/)
  4. Now as the design specifies all the transfer of files is in kernel space . When I transfer huge chunks of data through kernel space, will it slow down the system? The design shouldn't overload the system , doing it in a pre-empitble kernel will help, but are there other characteristics I should be aware of to make the design as efficient as possible (I'm doing it on the latest Linux kernel)?
  5. I don't want to leave a huge memory imprint so is there any way I can reduce it while transferring of data , may be caching data on disk ?
  6. I will have to design a user space programme to co ordinate the driver won't I? I cannot let the driver alone do the whole task, that would be tedious.
1
After going through a lot of code and documentation , i couldnt think of anything better than the Network Filesystem implementation in Linux . Practically every one of my requirement is fullfilled by this (except may be the kernel space part, Not sure how nfs works with this regard) . So now I've concluded to build a char driver in Linux which'll do almost all the task stated above . So question 1 down .Malice

1 Answers

0
votes

Have a look at the tun/tap driver in the Linux kernel, I think it will fulfill your needs.