On Fri, Jan 22, 2010 at 11:39 AM, Leelakrishna A
<[email protected]>wrote:

> Hi All,
>
> In Oreilly's LDD 3rd edition it is given that *struct cdev* is the
> kernel's internal structure that represents char devices.
> Also given that before kernel invokes your device's operations, you must
> allocate and register one or more of these structures.
> My doubt is who will create this structure for a char device ( either
> kernel will create it or the driver author has to explicitly create it using
> *cdev_alloc()* )
>

Its a responsibilty of driver to allocate the 'cdev' structure, now driver
can allocate it dynamically using 'cdev_alloc' or driver can have
pre-allocated (may be a global structure).
But in both the case driver has to initialize 'ops' field of the cdev
structure and then register cdev with the kernel using 'cdev_add'.


> If kernel creates it then at what situation it will create it or If driver
> author has to create it , when it has to create?
>

appropriate place for this would be the init function of your driver.

And once it get created how to link the file_operations structure to it?
>
Just initializing ops field and registering the cdev with kernel is enough.


> Thanks in advance,
> LeelaKrishna.
>


>
>
Thanks,
Chetan Nanda

Reply via email to