question on cdevsw_add mask/match

Matthew Dillon dillon at apollo.backplane.com
Tue Mar 22 18:26:45 PST 2005


:Matt -
:
:Thanks for the great explanation - this is starting to make sense.
:
:By specifying -1, isn't destroy_all_dev() (kern_conf.c:354) matching 
:against both the major and minor/unit numbers? It looks like 
:dev->si_udev is (major number << 8) | minor number (via makeudev() 
:kern_conf.c:216). match is the minor/unit number which gets compared 
:against all of si_udev because mask is 0xffffffff. Thus the conditional 
:on line 366 will never be equal because the mask includes the major 
:number in the comparison.

    Ah ha!  Yes, you have indeed found a bug.

:The question is how to specify mask/match for drivers wanting 
:/dev/driver%d like devices. If I'm understanding this, two possible 
:approaches would be
:
:1) continue to use the unit number for match but set mask to 0xff
:2) continue to use -1 for the mask but make the match value be a 
:shift/OR or the major and unit numbers
:...
:Chuck Tuffli
:Agilent Technologies

    The device (and thus the major number) are known separately so 
    we do not want to require that they be incorporated in the mask/match
    code.  This means that the destroy_all_dev() function needs to clear
    the bits associated with the major number (it matches the major based on
    matching the devsw already).

    For your own purposes you have a choice of using a mask of -1 or a mask
    of 0xff or a mask of whatever (keeping in mind that the major number eats
    bits 8-15).   Some device drivers use just the upper 16 bits (giving
    65535 units).  Only a very few drivers use all 32-8 = 24 bits of minor
    number.  Block devices that can have disklabels have to use all 24 bits,
    that's pretty much it.

					-Matt
					Matthew Dillon 
					<dillon at xxxxxxxxxxxxx>





More information about the Kernel mailing list