YouTube Icon

Interview Questions.

Top 15 Linux Device Drivers Interview Questions - Jul 24, 2022

fluid

Top 15 Linux Device Drivers Interview Questions

Q1. Can We Have Same Major Number For More Than One Device File ?

Yes . We are able to have .

Q2. What Is Minor Number And It's Usage ?

The minor variety is used most effective by means of the driving force itself to differentiate which tool it's running on, just in case the driving force handles more than one device.

(or)

one driving force can manipulate a couple of device .Minor can be used to distinguish the only device from other gadgets   .

Q3. What Is Mknod And It's Usage ?

Mknod is a command  which used create the device document (or) node in Linux file gadget.

In unix or linux we will represent the whole lot as a file .

Syntax: mknod Name  b   Major  Minor

Name : call of the device document

 c  : kind of device (ex; char or block device)

Major  : Major variety of the device file

Minor  : Minor range of the device report

ex : $  mknod /dev/rama  c  12  5

MKDEV(int essential, int minor);

Q4. What Is Major Number And It's Usage ?

It's an  integer variety  specifically used to offer the affiliation among the device driver and tool report . This variety is utilized by kernel .

                (or)

The predominant variety tells you which driving force handles which device record. 

Q5. What Is Range Of Major And Minor Numbers?

0-255

Q6. How Can I Use My Own Major And Minor Number For A Device File ?

If you have the predominant and minor numbers and want to show them right into a dev_t, use:

register_chrdev_region works well if you realize beforehand of time exactly which tool numbers you need. Often, however, you will no longer recognize which main numbers your device will use; there is a consistent attempt in the Linux kernel improvement community to transport over to the use of dynamically-allocated device numbers.

Q7. Where Can We Write Allocation And Freeing Of Device Number's Code ?

Allocation : init characteristic of a module

liberating : cleanup characteristic of a module

Q8. How Can We Allocate Device Number Statically ?

Register_chrdev_region() feature will statically allocate tool numbers. Which is declared in <linux/fs.H>

int register_chrdev_region(dev_t first, unsigned int be counted, char *name);

Return values : In case of fulfillment "0" will go back , In case of failure  "-1 or poor value " will go back 

Here

first is the beginning tool number of the variety you would like to allocate. The minor number portion of first is regularly @

rely is the entire range of contiguous device numbers you're soliciting for.

Name is the call of the tool that have to be related to this quantity range. It'll seem in /proc/gadgets and sysfs.

Q9. In How Many Ways We Can Allocate Device Number ?

In 2 approaches we are able to allocate tool numbers

statically

dynamically

Q10. How Can We Free Device Numbers ?

Void unregister_chrdev_region(dev_t first, unsigned int be counted);

Q11. How To Retrieve Major And Minor Number From Dev_t Type ?

To obtain the main or minor number  of a dev_t, use:

MAJOR(dev_t dev); // to obtain foremost variety

MINOR(dev_t dev);  // to gain minor quantity

int foremost=MAJOR(dev_t dev);

int minor =MINOR(dev_t dev);

Q12. How Can We Allocate Device Number Dynamically ?

Alloc_chrdev_region()will dynamically  allocate device numbers.

Int alloc_chrdev_region(dev_t *dev, unsigned int firstminor, 

                        unsigned int rely, char *call);

Here

dev is an output-handiest parameter as a way to, on successful final touch, maintain the primary variety to your allotted range. 

Firstminor should be the requested first minor variety to apply; it's also 0

count number is the entire variety of contiguous tool numbers you're requesting.

Name is the call of the device that ought to be related to this quantity range. It'll seem in /proc/devices and sysfs.

Q13. How To See Statically Assigned Major Numbers ?

Some fundamental device numbers are statically assigned to the maximum not unusual gadgets. A list of these devices may be determined in Documentation/gadgets.Txt inside the kernel supply tree.

Q14. What Is The Disadvantage Of Dynamic Device Number Assignment ?

The drawback of dynamic assignment is which you can't create the device nodes in advance, because the essential wide variety assigned on your module will range.

Q15. What Is Use Of Dev_t Type ?

This is used to maintain tool numbers—each the foremost and minor components.




CFG