Re: Char Driver Munmap

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

 




Jan Hudec wrote:
On Thu, Dec 14, 2006 at 04:25:14PM -0800, Manisha Maheshwari wrote:
I am writing a Char device driver.

I need to implement the munmap file operation for this driver.
Some how i couldn't find any infomation abt it in Linux device Driver book.
There is no such file_operation as munmap as of linux 2.6.18. Isn't that
the reason you can't find any info on it?

Can anybody provide the driver_munmap() code.


One way i know is -
In User space file   -  call munmap(mmaped_address, size);
Then switch to driver using   -  ioctl()  and
In driver code, the memory allocated can be freed.
I dont think  any specific driver_munmap() needed here as there is no file operation available.
If any other method , plz let us know.

Yes you are correct there is no file operation available for driver_munmap().

I wanted  to do some state change when munmap is called for driver.

I found a way to do it :

In vm_area_struct stucture there is a field vm_ops  which point to table of operation assciated with given memory.
This structure is intialized during driver_mmap().
 
Operation table describe open(),close etc method.
These method can be used to track map count and when map count drops to 0, driver_munmap() code can be called.

Here is code for implementing driver_munmap().

-----

static int count = 0;
void driver_munmap()
{
  // i did state change here
}
void driver_vma_open(struct vm_area_struct *vma)
{
count++;

}

void driver_vma_close(struct vm_area_struct *vma)
{
count--;

if ( count == 0)
{
// then it memory area is removed form address space of all process.
// here you can call your driver_munmap().
driver_munmap();

}
}
------

For more explanation : Refer page 258  "Linux Kernel Development" by Robert love.

Correct me if I am wrong??

Thanks,
Manisha



Thanks in advance,
Manisha
--------------------------------------------------------------------------------
- Jan Hudec `Bulb' <bulb@xxxxxx>


--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/





[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