Re: difference between user space and kernel space dev_t structs?

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

 



=== As a guess and only a guess: ===

POSIX / UNIX SVR4 probably defines minor and major as 8-bits each.

So to be posix compatible, the Linux ABI has to be 8-bits each.

But internal to the kernel, they needed more bits for devices not
exposed to userspace.

As a guess as to what kind of device that is:

SCSI uses the minor device to encode both the drive and the partition.

Something like:

minor = ((drive << 4) | partition);

You can see that only allows a handful of partitions, but the old IDE
driver supported at least 64 partitions (iirc).

So last year a SCSI extended partition setup was created.  In user
space it uses multiple major device numbers.  Hopefully in kernel
space it only uses one!

Greg

On Thu, Jul 8, 2010 at 4:14 PM, Robert P. J. Day <rpjday@xxxxxxxxxxxxxx> wrote:
>
>  over the next little while, i'm going to ask some fairly trivial
> questions that i really should know the answer to but i just don't,
> just because i want to fill in those little gaps.
>
>  for instance, consider the kernel header file
> include/linux/kdev_t.h, which defines a kernel space device file
> major/minor combination thusly:
>
> #define MINORBITS       20
> #define MINORMASK       ((1U << MINORBITS) - 1)
>
> #define MAJOR(dev)      ((unsigned int) ((dev) >> MINORBITS))
> #define MINOR(dev)      ((unsigned int) ((dev) & MINORMASK))
> #define MKDEV(ma,mi)    (((ma) << MINORBITS) | (mi))
> ... etc etc ...
>
>  so it's clear that, these days, a device file is identified by a
> 32-bit value, (major,minor) = (12 bits, 20 bits).
>
>  in addition, later definitions in that file define *old* device
> files as 16-bit, (8,8).
>
>  but at the bottom of that file, you read:
>
> #else /* __KERNEL__ */
>
> /*
> Some programs want their definitions of MAJOR and MINOR and MKDEV
> from the kernel sources. These must be the externally visible ones.
> */
> #define MAJOR(dev)      ((dev)>>8)
> #define MINOR(dev)      ((dev) & 0xff)
> #define MKDEV(ma,mi)    ((ma)<<8 | (mi))
> #endif /* __KERNEL__ */
>
>
>  that means that's what exported to user space in the file
> /usr/include/linux/kdev_t.h is the *old* format.  so what's the value
> of that?  what's the point of having macros in user space that don't
> match the actual structure of a kernel space device file identifier?
>
> rday
>
> --
>
> ========================================================================
> Robert P. J. Day                               Waterloo, Ontario, CANADA
>
>        Top-notch, inexpensive online Linux/OSS/kernel courses
>                        http://crashcourse.ca
>
> Twitter:                                       http://twitter.com/rpjday
> LinkedIn:                               http://ca.linkedin.com/in/rpjday
> ========================================================================
>
> --
> To unsubscribe from this list: send an email with
> "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
> Please read the FAQ at http://kernelnewbies.org/FAQ
>
>



-- 
Greg Freemyer
Head of EDD Tape Extraction and Processing team
Litigation Triage Solutions Specialist
http://www.linkedin.com/in/gregfreemyer
CNN/TruTV Aired Forensic Imaging Demo -
   http://insession.blogs.cnn.com/2010/03/23/how-computer-evidence-gets-retrieved/

The Norcross Group
The Intersection of Evidence & Technology
http://www.norcrossgroup.com

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at 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