64-bit kdev_t - just for playing
Quoted 3 lines
Quoted 1 line
Maybe I should send another patch tonight, just for playing.
Please, I'd like that.
Below a random version of kdev_t.h.
(The file is smaller than the patch.)
kdev_t is the kernel-internal representation dev_t is the kernel idea of the user space representation (of course glibc uses 64 bits, split up as 8+8 :-)
kdev_t can be equal to dev_t.
The file below completely randomly makes kdev_t
64 bits, split up 32+32, and dev_t 32 bits, split up 12+20.
Andries
------------------------------------------------------------
#ifndef _LINUX_KDEV_T_H
#define _LINUX_KDEV_T_H
#ifdef __KERNEL__
typedef struct {
unsigned long long value;
} kdev_t;#define KDEV_MINOR_BITS 32
#define KDEV_MAJOR_BITS 32
#define KDEV_MINOR_MASK ((1ULL << KDEV_MINOR_BITS) - 1)
#define __mkdev(major, minor) (((unsigned long long)(major) << KDEV_MINOR_BITS) + (minor))
#define mk_kdev(major, minor) ((kdev_t) { __mkdev(major,minor) } )
/*
* The "values" are just _cookies_, usable for
* internal equality comparisons and for things
* like NFS filehandle conversion.
*/
static inline unsigned long long kdev_val(kdev_t dev)
{
return dev.value;
}static inline kdev_t val_to_kdev(unsigned long long val)
{
kdev_t dev;
dev.value = val;
return dev;
}#define HASHDEV(dev) (kdev_val(dev))
#define NODEV (mk_kdev(0,0))
extern const char * kdevname(kdev_t); /* note: returns pointer to static data! */
static inline int kdev_same(kdev_t dev1, kdev_t dev2)
{
return dev1.value == dev2.value;
}#define kdev_none(d1) (!kdev_val(d1))
#define minor(dev) (unsigned int)((dev).value & KDEV_MINOR_MASK)
#define major(dev) (unsigned int)((dev).value >> KDEV_MINOR_BITS)
/* These are for user-level "dev_t" */
#define MINORBITS 8
#define MINORMASK ((1U << MINORBITS) - 1)
#define DEV_MINOR_BITS 20
#define DEV_MAJOR_BITS 12
#define DEV_MINOR_MASK ((1U << DEV_MINOR_BITS) - 1)
#define DEV_MAJOR_MASK ((1U << DEV_MAJOR_BITS) - 1)
#include <linux/types.h> /* dev_t */
#define MAJOR(dev) ((unsigned int)(((dev) & 0xffff0000) ? ((dev) >> DEV_MINOR_BITS) & DEV_MAJOR_MASK : ((dev) >> 8) & 0xff))
#define MINOR(dev) ((unsigned int)(((dev) & 0xffff0000) ? ((dev) & DEV_MINOR_MASK) : ((dev) & 0xff)))
#define MKDEV(ma,mi) ((dev_t)((((ma) & ~0xff) == 0 && ((mi) & ~0xff) == 0) ? (((ma) << 8) | (mi)) : (((ma) << DEV_MINOR_BITS) | (mi))))
/*
* Conversion functions
*/
static inline int kdev_t_to_nr(kdev_t dev)
{
unsigned int ma = major(dev);
unsigned int mi = minor(dev);
return MKDEV(ma, mi);
}static inline kdev_t to_kdev_t(dev_t dev)
{
unsigned int ma = MAJOR(dev);
unsigned int mi = MINOR(dev);
return mk_kdev(ma, mi);
}#else /* __KERNEL__ */
/*
Some programs want their definitions of MAJOR and MINOR and MKDEV from the kernel sources. These must be the externally visible ones. Of course such programs should be updated.
*/
#define MAJOR(dev) ((dev)>>8)
#define MINOR(dev) ((dev) & 0xff)
#define MKDEV(ma,mi) ((ma)<<8 | (mi))
#endif /* __KERNEL__ */
#endif
Hi,
Quoted 8 lines · On Thu, 27 Mar 2003 [email protected] wrote:
kdev_tis the kernel-internal representationdev_tis the kernel idea of the user space representation (of course glibc uses 64 bits, split up as 8+8 :-)
kdev_tcan be equal todev_t.The file below completely randomly makes
kdev_t
64 bits, split up 32+32, anddev_t32 bits, split up 12+20.
It would really help, if you would explain how a larger dev_t will work during 2.6.
Let's take an example, the first user is likely the scsi layer, so how can I manage thousands of disks under 2.6?
How are these disks registered and how will the dev_t number look like? How will the user know about these numbers?
Who creates these device entries (user or daemon)?
How have user space utilities to be changed, which know about dev_t (e.g. ls or fdisk)?
How is backward compatibility done, so that I can still boot a 2.4 kernel?
bye, Roman
Followup to: <[email protected]> By author: [email protected] In newsgroup: linux.dev.kernel
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Maybe I should send another patch tonight, just for playing.
Please, I'd like that.
Below a random version of
kdev_t.h.
(The file is smaller than the patch.)
Quoted 9 lines
kdev_tis the kernel-internal representationdev_tis the kernel idea of the user space representation (of course glibc uses 64 bits, split up as 8+8 :-)
kdev_tcan be equal todev_t.The file below completely randomly makes
kdev_t
64 bits, split up 32+32, anddev_t32 bits, split up 12+20.
I have a few brief questions:
a) Along all of these you have assumed that it's more efficient to have a separate type (kdev_t) for kernel-internal "decoded" device number handling, as opposed to "encoded" device number handling. At some point, however, it ends up being a struct char_dev * or struct block_dev *. How big is this gap and does it really make sense introducing a special type for it?
b) If we do have such a type, would it make more sense to have cdev_t and bdev_t, and have per-type distinction of block- versus charness?
c) If we do have such a type, any reason to have it be a "unsigned long long" (really should be u64), instead of "u32 major; u32 minor;"?
-hpa
Signature · 3 lines
<[email protected]> at work, <[email protected]> in private! "Unix gives you enough rope to shoot yourself in the foot." Architectures needed: ia64 m68k mips64 ppc ppc64 s390 s390x sh v850 x86-64