Patch from Andries.Brouwer@cwi.nl Below some random patch, not to be applied, so that people can play with a 32-bit dev_t. Nothing here is hewn in stone. By some coincidence the division below is 16+16, but a simple edit turns that into 12+20 or 32+32. Elsewhere there are no (well, there still are a few, but they will be eliminated), there are no assumptions on the sizes involved. A major and a minor are unsigned ints of unknown size. Of course not all filesystems can handle all sizes. [I still see a B_FREE here - had removed that earlier, but perhaps the patch was not applied. There is another occurrence in video/pm3fb.h that can be removed, and one in video/pm3fb.c that should become NODEV. Will find this patch again.] 25-akpm/include/asm-i386/posix_types.h | 2 25-akpm/include/linux/kdev_t.h | 69 ++++++++++++++++++++++++++------- fs/libfs.c | 0 3 files changed, 56 insertions(+), 15 deletions(-) diff -puN fs/libfs.c~dev_t-32-bit fs/libfs.c diff -puN include/asm-i386/posix_types.h~dev_t-32-bit include/asm-i386/posix_types.h --- 25/include/asm-i386/posix_types.h~dev_t-32-bit Mon Mar 31 13:49:18 2003 +++ 25-akpm/include/asm-i386/posix_types.h Mon Mar 31 13:49:18 2003 @@ -7,7 +7,7 @@ * assume GCC is being used. */ -typedef unsigned short __kernel_dev_t; +typedef unsigned long __kernel_dev_t; typedef unsigned long __kernel_ino_t; typedef unsigned short __kernel_mode_t; typedef unsigned short __kernel_nlink_t; diff -puN include/linux/kdev_t.h~dev_t-32-bit include/linux/kdev_t.h --- 25/include/linux/kdev_t.h~dev_t-32-bit Mon Mar 31 13:49:18 2003 +++ 25-akpm/include/linux/kdev_t.h Mon Mar 31 13:49:18 2003 @@ -70,13 +70,13 @@ aeb - 950811 * static arrays, and they are sized for a 8-bit index. */ typedef struct { - unsigned short value; + unsigned int value; } kdev_t; -#define KDEV_MINOR_BITS 8 -#define KDEV_MAJOR_BITS 8 +#define KDEV_MINOR_BITS 16 +#define KDEV_MAJOR_BITS 16 -#define __mkdev(major,minor) (((major) << KDEV_MINOR_BITS) + (minor)) +#define __mkdev(major, minor) (((major) << KDEV_MINOR_BITS) + (minor)) #define mk_kdev(major, minor) ((kdev_t) { __mkdev(major,minor) } ) @@ -99,7 +99,6 @@ static inline kdev_t val_to_kdev(unsigne #define HASHDEV(dev) (kdev_val(dev)) #define NODEV (mk_kdev(0,0)) -#define B_FREE (mk_kdev(0xff,0xff)) static inline int kdev_same(kdev_t dev1, kdev_t dev2) { @@ -108,17 +107,55 @@ static inline int kdev_same(kdev_t dev1, #define kdev_none(d1) (!kdev_val(d1)) -/* Mask off the high bits for now.. */ -#define minor(dev) ((dev).value & 0xff) -#define major(dev) (((dev).value >> KDEV_MINOR_BITS) & 0xff) +#define minor(dev) ((dev).value & 0xffff) +#define major(dev) (((dev).value >> KDEV_MINOR_BITS) & 0xffff) /* These are for user-level "dev_t" */ +/* Since glibc uses 8+8 in , we'll get + incompatibilities with a simple scheme like 12+20. + Use 8+8 for 16-bit values, some other division, say 16+16, + for 32-bit values. */ #define MINORBITS 8 #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)) +#include /* dev_t */ +#if 1 +/* macro versions */ + +#define MAJOR(dev) ((unsigned int)(((dev) & 0xffff0000) ? ((dev) >> 16) & 0xffff : ((dev) >> 8) & 0xff)) +#define MINOR(dev) ((unsigned int)(((dev) & 0xffff0000) ? ((dev) & 0xffff) : ((dev) & 0xff))) +#define MKDEV(ma,mi) ((dev_t)((((ma) & ~0xff) == 0 && ((mi) & ~0xff) == 0) ? (((ma) << 8) | (mi)) : (((ma) << 16) | (mi)))) + +#else +/* inline function versions */ + +static inline unsigned int +MAJOR(dev_t dev) { + unsigned int ma; + + ma = ((dev >> 16) & 0xffff); + if (ma == 0) + ma = ((dev >> 8) & 0xff); + return ma; +} + +static inline unsigned int +MINOR(dev_t dev) { + unsigned int mi; + + mi = (dev & 0xffff); + if (mi == dev) + mi = (dev & 0xff); + return mi; +} + +static inline dev_t +MKDEV(unsigned int ma, unsigned int mi) { + if ((ma & ~0xff) == 0 && (mi & ~0xff) == 0) + return ((ma << 8) | mi); + return ((ma << 16) | mi); +} +#endif /* * Conversion functions @@ -126,12 +163,16 @@ static inline int kdev_same(kdev_t dev1, static inline int kdev_t_to_nr(kdev_t dev) { - return MKDEV(major(dev), minor(dev)); + unsigned int ma = major(dev); + unsigned int mi = minor(dev); + return MKDEV(ma, mi); } -static inline kdev_t to_kdev_t(int dev) +static inline kdev_t to_kdev_t(dev_t dev) { - return mk_kdev(MAJOR(dev),MINOR(dev)); + unsigned int ma = MAJOR(dev); + unsigned int mi = MINOR(dev); + return mk_kdev(ma, mi); } #else /* __KERNEL__ */ _