Larger dev_t
Dear Linus and all,
One of these days we must change dev_t.
There are several aspects to this, but this letter touches only the kernel-*libc interface.
We need a size, and I am strongly in favor of sizeof(dev_t) = 8; this is already true in glibc.
The two main uses of dev_t are in struct stat and as parameter of the mknod system call. There are a few other occurrences, such as ustat() and the use of dev_t as a field in struct loopinfo returned by some ioctl.
- For stat all is fine already since we got stat64.
- For mknod a little work is required.
- The state of affairs with loopinfo is sad today (the fact that kernel and glibc use dev_t of different size causes problems) but all will be well with 64-bit dev_t.
- With ustat the converse is true. Of course it is obsolete, but with 64-bit dev_t we are forced to throw it out - libc5 has xustat just like xstat and xmknod, but glibc hasn't so it is not easy to save it. There are still some programs that use it:
in CD players to test (before eject) whether a CD is mounted; in various programs such as sendmail and uucp to test how much free space we have.
So, glibc will have to return EINVAL (or EOVERFLOW) here for device numbers that actually use more than 16 bits.
The transformation from 64 bits to pair (major,minor) is
if ((major = (dev >> 32)) != 0)
minor = (dev & 0xffffffff);
else if ((major = (dev >> 16)) != 0)
minor = (dev & 0xffff);
else {
major = (dev >> 8);
minor = (dev & 0xff);
}This means that old device numbers remain valid.
The stuff below describes a working interface where 64-bit values are passed to and from the kernel, and to and from the filesystem. That is, it is dev_t stuff. Some other time on kernel-internal matters, that is, kdev_t stuff.
Details of my setup of today (with 64-bit dev_t):
(i) ext2:
diff -r linux-2.4.2/linux/fs/ext2/inode.c linux-2.4.2kdevt/linux/fs/ext2/inode.c 1076,1078c1076,1081
< } else
< init_special_inode(inode, inode->i_mode,
< le32_to_cpu(raw_inode->i_block[0]));
---
Quoted 6 lines
} else {
unsigned int lo = le32_to_cpu(raw_inode->i_block[0]);
unsigned int hi = le32_to_cpu(raw_inode->i_block[1]);
dev_t devno = ((unsigned long long) hi << 32) | lo;
init_special_inode(inode, inode->i_mode, devno);
}1211,1213c1214,1221
< if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
< raw_inode->i_block[0] = cpu_to_le32(kdev_t_to_nr(inode->i_rdev))
;
< else for (block = 0; block < EXT2_N_BLOCKS; block++)
---
Quoted 8 lines
if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
/* we use that EXT2_N_BLOCKS > 1 */
dev_t devno = kdev_t_to_nr(inode->i_rdev);
unsigned int hi = (devno >> 32);
unsigned int lo = (devno & 0xffffffff);
raw_inode->i_block[0] = cpu_to_le32(lo);
raw_inode->i_block[1] = cpu_to_le32(hi);
} else for (block = 0; block < EXT2_N_BLOCKS; block++)Ted, please complain if I am mistaken in thinking that raw_inode->i_block[1] can be used.
There is a minor conversion problem here: there is no guarantee that raw_inode->i_block[1] will be zero in old systems.
(ii) vfs:
diff -r linux-2.4.2/linux/fs/devices.c linux-2.4.2kdevt/linux/fs/devices.c 200c200
< void init_special_inode(struct inode *inode, umode_t mode, int rdev)
---
Quoted 1 line
void
init_special_inode(struct inode *inode, umode_t mode, dev_t rdev)
(iii) mknod:
Then there is the prototype of mknod.
I changed it for all filesystems to
diff -r linux-2.4.2/linux/fs/ext2/namei.c linux-2.4.2kdevt/linux/fs/ext2/namei.c 387c387,388
< static int ext2_mknod (struct inode * dir, struct dentry *dentry, int mode, int rdev)
---
Quoted 2 lines
static int
ext2_mknod(struct inode * dir, struct dentry *dentry, int mode,
dev_trdev)
The system call itself cannot easily be changed to take a larger dev_t, mostly because under old glibc the high order part would be random. So, mknod64, with
diff linux-2.4.2/linux/fs/namei.c linux-2.4.2kdevt/linux/fs/namei.c 1205c1208
< asmlinkage long sys_mknod(const char * filename, int mode, dev_t dev)
---
Quoted 1 line
static long
mknod_common(const char * filename, int mode, dev_t dev)
1245a1249,1259
Quoted 11 lines
}
asmlinkage long sys_mknod64(const char * filename, int mode,
unsigned int ma, unsigned int mi){ return mknod_common(filename, mode, ((dev_t) ma << 32) | mi); }asmlinkage long
sys_mknod(const char * filename, int mode, unsigned short dev){ return mknod_common(filename, mode, dev);
and __NR_mknod64 in unistd.h and .long SYMBOL_NAME(sys_mknod64) in entry.S.
Changes to glibc2:
sysdeps/unix/sysv/linux/xmknod.c Sat Mar 24 13:53:50 2001 renamed from sysdeps/unix/sysv/linux/xmknod.c Fri Jul 7 19:57:38 2000 +17 -1
@@ -29,6 +29,13 @@ extern int __syscall_mknod (const char *__unbounded, unsigned short int, unsigned short int); +extern int __syscall_mknod64 (const char *__unbounded, unsigned short int, + dev_t); + +#ifndef __NR_mknod64 +#define __NR_mknod64 223 +#endif + /* Create a device file named PATH, with permission and special bits MODE and device number DEV (which can be constructed from major and minor device numbers with the `makedev' macro above). */
@@ -36,6 +43,7 @@ __xmknod (int vers, const char *path, mode_t mode, dev_t *dev) { unsigned short int k_dev; + unsigned int ma, mi; if (vers != _MKNOD_VER) {
@@ -43,9 +51,17 @@ return -1; } + if ((*dev >> 16) != 0) + { + /* need mknod64 */ + /* pass the 64-bit arg as two 32-bit integers (le) */ + ma = ((*dev) >> 32); + mi = ((*dev) & 0xffffffff); + return INLINE_SYSCALL (mknod64, 4, CHECK_STRING (path), mode, ma, mi); + } + /* We must convert the value to dev_t type used by the kernel. */ k_dev = ((major (*dev) & 0xff) << 8) | (minor (*dev) & 0xff); - return INLINE_SYSCALL (mknod, 3, CHECK_STRING (path), mode, k_dev); }
I almost submitted this as an actual patch, but it changes vfs prototypes, and probably that is against the rules during a stable series. If something in this style is OK I'll make a patch as soon as 2.5 is started.
Andries
[the above is running on the machine I send this mail from]
Also for 2.5, kdev_t needs to go away, along with all those arrays based on major number, and be replaced with either "struct char_device" or "struct block_device" depending on the device.
I actually went through the kernel in 2.4.0-test days and did this. Most kdev_t usages should really be changed to "struct block_device". The only annoyance in the conversion was ROOT_DEV and similar things that are tied into the boot process. I didn't want to change that and potentially break the boot protocol...
Signature · 3 lines
Jeff Garzik | May you have warm words on a cold evening, Building 1024 | a full moon on a dark night, MandrakeSoft | and a smooth road all the way to your door.
Quoted 9 lines · Jeff Garzik
Also for 2.5,
kdev_tneeds to go away, along with all those arrays based on major number, and be replaced with either "structchar_device" or "structblock_device" depending on the device.I actually went through the kernel in 2.4.0-test days and did this. Most
kdev_tusages should really be changed to "structblock_device". The only annoyance in the conversion wasROOT_DEVand similar things that are tied into the boot process. I didn't want to change that and potentially break the boot protocol...
Jeff, check the namespace patch - it simplifies this area big way. Since it's independent from the namespace code I can pull these parts into separate patch.
Basic idea: _always_ use ramfs (initially empty) for absolute root. "real" root is overmounted atop of it. The thing being, by the time when we deal with initrd, unpacking, mounting real root, etc. we have full-blown fs context. I.e. we can call sys_mknod(), sys_mount(), etc. I've pulled the late stages of boot into init/do_mounts.c and had rewritten them - essentially into sequence of syscalls. The thing became seriosuly simpler (not to mention the fact that it's not scattered anymore).
If anyone is interested in seeing it as a separate patch - tell and I'll do it; it's pretty straightforward.
Al
Quoted 3 lines · On Sat, 24 Mar 2001 [email protected] wrote:
We need a size, and I am strongly in favor of
sizeof(dev_t)= 8; this is already true in glibc.
The fact that glibc is a quivering mass of bloat, and total and utter crap makes you suggest that the Linux kernel should try to be as similar as possible?
Not a very strong argument.
There is no way in HELL I will ever accept a 64-bit dev_t.
I _will_ accept a 32-bit dev_t, with 12 bits for major numbers, and 20 bits for minor numbers.
If people cannot fit their data in that size, they have some serious problems. And for people who think that you should have meaningful minor numbers where the bit patterns get split up some way, I can only say "get a frigging clue". That's what you have filesystem namespaces for. Don't try to make binary name-spaces.
And I don't care one _whit_ about the fact that Ulrich Drepper thinks that it's a good idea to make things too large.
Linus
Quoted 17 lines · Linus Torvalds
Quoted 3 lines · On Sat, 24 Mar 2001 [email protected] wrote:
We need a size, and I am strongly in favor of
sizeof(dev_t)= 8; this is already true in glibc.The fact that glibc is a quivering mass of bloat, and total and utter crap makes you suggest that the Linux kernel should try to be as similar as possible?
Not a very strong argument.
There is no way in HELL I will ever accept a 64-bit
dev_t.I _will_ accept a 32-bit
dev_t, with 12 bits for major numbers, and 20 bits for minor numbers.
Quoted 8 lines
If people cannot fit their data in that size, they have some serious problems. And for people who think that you should have meaningful minor numbers where the bit patterns get split up some way, I can only say "get a frigging clue". That's what you have filesystem namespaces for. Don't try to make binary name-spaces.
And I don't care one _whit_ about the fact that Ulrich Drepper thinks that it's a good idea to make things too large.
Amen. It's entierly sufficent to take a size similiar to the one on systems which don't have the problems linux has in this area. Our daily motto should be: "Maybe we don't know a shit about OS design - but we known very well up to the ground how Solaris works."
Please forgive me If I stressed your sense of humour a bit too much :-)
Quoted 10 lines · Jeff Garzik
Also for 2.5,
kdev_tneeds to go away, along with all those arrays based on major number, and be replaced with either "structchar_device" or "structblock_device" depending on the device.I actually went through the kernel in 2.4.0-test days and did this. Most
kdev_tusages should really be changed to "structblock_device". The only annoyance in the conversion wasROOT_DEVand similar things that are tied into the boot process. I didn't want to change that and potentially break the boot protocol...
Please se the patches I have send roughly a year to the list as well. It's actually NOT easy. In esp the SCSI and IDE-CD usage of minor arrays is
a huge obstacle.
Signature · 4 lines
- phone: +49 214 8656 283 - job: eVision-Ventures AG, LEV .de (MY OPINIONS ARE MY OWN!) - langs: de_DE.ISO8859-1, en_US, pl_PL.ISO8859-2, last ressort: ru_RU.KOI8-R