Re: can i see a driver's registered *minor* number(s)?

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

 



On 11-04-08 13:34, Robert P. J. Day wrote:

Historically, no way. The driver just gets everything for its
registered major and has to switch on minor itself. That is, no such
thing as "allocated" minors as far as the system is concerned.

just to be pedantic here, when you say there are no such things as
"allocated" minors, i'm assuming that what you mean is that it's
always up to a loaded module to choose what minors it wants to try to
allocate and register, right?  or, put another way, there are no such
things as *pre*-allocated minors.  am i parsing that the right way?

No, really no such thing as allocated minors. You don't register them with anything historically. I've attached a very minimal char driver using The Olden Ways and you see that it itself checks in its open method -- doesn't register a minor anyhere and gets called for every minor; only the major is significant to the system.

Rene.
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>

#define FOO_MAJOR 240
#define FOO_MINOR 0

static const char * const foo_name = "foo";

static int foo_open(struct inode *inode, struct file *filp)
{
	if (iminor(inode) != FOO_MINOR)
		return -ENXIO;
	
	printk(KERN_INFO "%s: foo_open\n", foo_name);
	return 0;
}

static int foo_release(struct inode *inode, struct file *filp)
{
	printk(KERN_INFO "%s: foo_release\n", foo_name);
	return 0;
}

static struct file_operations foo_fops = {
	.open		= foo_open,
	.release	= foo_release,
	.owner		= THIS_MODULE
};

static int foo_init(void)
{
	return register_chrdev(FOO_MAJOR, foo_name, &foo_fops) < 0 ? -ENODEV : 0;
}

static void foo_exit(void)
{
	unregister_chrdev(FOO_MAJOR, foo_name);
}

module_init(foo_init);
module_exit(foo_exit);

MODULE_LICENSE("GPL");

[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