On 10/19/06, Rahul Theraja <rahul.theraja@xxxxxxxxx> wrote:
Hello All I have some doubts in working with block drivers. I have a "sbd_device.c" a sample block driver file and a small application that does a read request to this driver. I am working on linux-2.6.9. After insmod'ing the driver i have run my application. My doubt is, though i have given only one read() in appln.c , it does many requests to the driver. I could not understand why the "sbd_request " is called even though i have given only one read call from user space file. In the below user space file, i tried changing the buf size from 1 to 512 but the number of read requests done driver are same. int fd = -1, buf[1], count = 1, ret, i=0; fd = open("/dev/sbd_dev0", O_RDWR); if(fd < 0) printf("Could not open /dev/sbd_device\n"); else { printf("\nOpened device file : \n"); printf("\nSending a Read.... \n"); ret = read(fd, buf, count); printf("\n1. The value ret = %x\n", ret); for(i=0; i<count;i++) printf("buf[%d] = 0x%x\n",i, buf[i]); printf("\n\n"); and the dmesg ouput is:Init module... sbd_dev0:sbd_request Calling sbd_transfer Doing a read from device unknown partition table sbd_request Calling sbd_transfer Doing a read from device Calling sbd_transfer Doing a read from device Calling sbd_transfer Doing a read from device Calling sbd_transfer ... ....Does around 20 times.
Ok, have you tried to read again just after doing first read ? I think that time you must get less number of requests. Most likely performing first read actually making kernel to ask for different drive information like partition-table, size, probably file-system information etc; so you will get multiple requests. By the way data transfer in block device takes place in chunks/blocks.
And also in the driver, in the function sbd_request() how does the driver get the parameters like sector, current_nr_sectors and buffer. From user space we just give the size of data transfer but not the sector etc. sbd_transfer(&sbd_device, req->sector, req->current_nr_sectors, req->buffer, rq_data_dir(req));
The read from user-space is actually doing sys_call "read" in kernel which calls VFS functions and VFS/FS provides sector, nr_sector etc to device.
Anyone please help me in clearing this basic doubts so that i could move furhter fastly.
I think I made some doubts clear. You can ask more if needed, and do read book "Linux Device Driver, 3rd Ed"
Thanks in advance Rahul
-- Fawad Lateef -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/