fix mknod
PATCH 1/1 fix mknod
Hi,
I was playing with user-mode Linux and found that mknod creates devices node in hostfs with wrong major/minor numbers. The patch below fixes it for me.
Johannes
---mknod() is broken on UML because userspace has differernt dev_t size and encoding than kernel.
fs/hostfs/hostfs.h +11 -1
@@ -76,7 +76,17 @@ extern int make_symlink(const char *fromextern int unlink_file (const char *file);extern int do_mkdir (const char *file,int mode);extern int do_rmdir (const char *file); -extern int do_mknod (const char *file,int mode,int dev); + +/* gnu_dev_makedev from glibc's sys/sysmacros.h */ +static inline unsigned long long makedev (unsigned int major,unsigned int minor) +{ +return ((minor &0xff ) | ((major &0xfff ) <<8 ) + | (((unsigned long long int ) (minor & ~0xff )) <<12 ) + | (((unsigned long long int ) (major & ~0xfff )) <<32 )); + +} + +extern int do_mknod (const char *file,int mode,unsigned long long dev);extern int link_file (const char *from,const char *to);extern int do_readlink (char *file,char *buf,int size);extern int rename_file (char *from,char *to);
fs/hostfs/hostfs_kern.c +4 -1
@@ -740,6 +740,7 @@ int hostfs_mknod(struct inode *dir, strustruct inode *inode;char *name;int err = -ENOMEM ; +unsigned long long udev; inode =iget (dir->i_sb,0 );if (inode ==NULL )
@@ -755,7 +756,9 @@ int hostfs_mknod(struct inode *dir, stru goto out_put;init_special_inode (inode, mode, dev); - err =do_mknod (name, mode, dev); +/* userspace has different dev_t encoding than kernel... */ + udev =makedev (MAJOR (dev),MINOR (dev)); + err =do_mknod (name, mode, udev);if (err) goto out_free;
fs/hostfs/hostfs_user.c +1 -1
@@ -295,7 +295,7 @@ int do_rmdir(const char *file)return (0 ); } -int do_mknod (const char *file,int mode,int dev) +int do_mknod (const char *file,int mode,unsigned long long dev) {int err;
Quoted 7 lines · Johannes Stezenbach
Hi,
I was playing with user-mode Linux and found that mknod creates devices node in hostfs with wrong major/minor numbers. The patch below fixes it for me.
Johannes
Hmpf. Still having this bug on hostfs is quite bad. Thanks for reporting.
It should be hostfs_user.c to take major and minor and to combine them correctly - it can use libc's macros.
Quoted 73 lines
Signed-off-by Johannes Stezenbach <[email protected]>diff -rup
linux-2.6.19.orig/fs/hostfs/hostfs.hlinux-2.6.19/fs/hostfs/hostfs.h---linux-2.6.19.orig/fs/hostfs/hostfs.h2006-11-29 22:57:37.000000000 +0100
+++linux-2.6.19/fs/hostfs/hostfs.h2007-01-22 20:53:23.000000000 +0100 @@
-76,7 +76,17 @@ extern int make_symlink(const char *from
extern intunlink_file(const char *file); extern intdo_mkdir(const char *file, int mode); extern intdo_rmdir(const char *file);fs/hostfs/hostfs.h +3
-1-extern int do_mknod (const char *file,int mode,int dev); + +/* gnu_dev_makedev from glibc's sys/sysmacros.h */ +static inline unsigned long long makedev(unsigned int major, unsigned intminor) +{
fs/hostfs/hostfs.h +7
-0+return ((minor &0xff ) | ((major &0xfff ) <<8 ) + | (((unsigned long long int ) (minor & ~0xff )) <<12 ) + | (((unsigned long long int ) (major & ~0xfff )) <<32 )); + +} + +extern int do_mknod (const char *file,int mode,unsigned long long dev);extern int link_file (const char *from,const char *to);extern int do_readlink (char *file,char *buf,int size);extern int rename_file (char *from,char *to);diff -rup
linux-2.6.19.orig/fs/hostfs/hostfs_kern.clinux-2.6.19/fs/hostfs/hostfs_kern.c---linux-2.6.19.orig/fs/hostfs/hostfs_kern.c2006-11-29 22:57:37.000000000
+0100 +++linux-2.6.19/fs/hostfs/hostfs_kern.c2007-01-22
20:57:58.000000000 +0100 @@ -740,6 +740,7 @@ int hostfs_mknod(struct inode *dir, strufs/hostfs/hostfs_kern.c +4
-1struct inode *inode;char *name;int err = -ENOMEM ; +unsigned long long udev; inode =iget (dir->i_sb,0 );if (inode ==NULL )@@ -755,7 +756,9 @@ int hostfs_mknod(struct inode *dir, stru goto out_put;init_special_inode (inode, mode, dev); - err =do_mknod (name, mode, dev); +/* userspace has different dev_t encoding than kernel... */ + udev =makedev (MAJOR (dev),MINOR (dev)); + err =do_mknod (name, mode, udev);if (err) goto out_free;diff -rup
linux-2.6.19.orig/fs/hostfs/hostfs_user.clinux-2.6.19/fs/hostfs/hostfs_user.c---linux-2.6.19.orig/fs/hostfs/hostfs_user.c2006-11-29 22:57:37.000000000
+0100 +++linux-2.6.19/fs/hostfs/hostfs_user.c2007-01-22
20:54:37.000000000 +0100 @@ -295,7 +295,7 @@ intdo_rmdir(const char *file)fs/hostfs/hostfs_user.c +1
-2return (0 ); } -int do_mknod (const char *file,int mode,int dev) +int do_mknod (const char *file,int mode,unsigned long long dev) {int err; -------------------------------------------------------------------------Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
Signature · 5 lines
Inform me of my mistakes, so I can add them to my list! Paolo Giarrusso, aka Blaisorblade http://www.user-mode-linux.org/~blaisorblade Chiacchiera con i tuoi amici in tempo reale! http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com
Quoted 10 lines · Blaisorblade
Quoted 4 lines · Johannes Stezenbach
I was playing with user-mode Linux and found that mknod creates devices node in hostfs with wrong major/minor numbers. The patch below fixes it for me.
Hmpf. Still having this bug on hostfs is quite bad. Thanks for reporting.
It should be
hostfs_user.cto take major and minor and to combine them correctly - it can use libc's macros.
Right, below is a better patch.
Thanks,
Johannes
---
Fix UML hostfs mknod(): userspace has differernt dev_t size and encoding than kernel, so extract major/minor and reencode using glibc makedev() macro.
fs/hostfs/hostfs.h +1 -1
@@ -76,7 +76,7 @@ extern int make_symlink(const char *fromextern int unlink_file (const char *file);extern int do_mkdir (const char *file,int mode);extern int do_rmdir (const char *file); -extern int do_mknod (const char *file,int mode,int dev); +extern int do_mknod (const char *file,int mode,unsigned int major,unsigned int minor);extern int link_file (const char *from,const char *to);extern int do_readlink (char *file,char *buf,int size);extern int rename_file (char *from,char *to);
fs/hostfs/hostfs_kern.c +1 -1
@@ -755,7 +755,7 @@ int hostfs_mknod(struct inode *dir, stru goto out_put;init_special_inode (inode, mode, dev); - err =do_mknod (name, mode, dev); + err =do_mknod (name, mode,MAJOR (dev),MINOR (dev));if (err) goto out_free;
fs/hostfs/hostfs_user.c +2 -2
@@ -295,11 +295,11 @@ int do_rmdir(const char *file)return (0 ); } -int do_mknod (const char *file,int mode,int dev) +int do_mknod (const char *file,int mode,unsigned int major,unsigned int minor) {int err; - err =mknod (file, mode, dev); + err =mknod (file, mode,makedev (major, minor));if (err)return (-errno);return (0 ); }
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
Blaisorblade
Acked-byQuoted 7 lines · Johannes Stezenbach
Quoted 6 lines · Blaisorblade
Quoted 3 lines · Johannes Stezenbach
I was playing with user-mode Linux and found that mknod creates devices node in hostfs with wrong major/minor numbers. The patch below fixes it for me.
Hmpf. Still having this bug on hostfs is quite bad. Thanks for reporting.
I've now seen - we never fixed this one, we fixed the analogous problem on 'ls' output and friends (in init_inode, which is used in many places).
Quoted 4 lines
Quoted 2 lines
It should be
hostfs_user.cto take major and minor and to combine them correctly - it can use libc's macros.Right, below is a better patch.
Exactly what I meant, thanks!
I'd say:
This can go to 2.6.20, and possibly even to -stable (after either me or Jeff tests it once).
Quoted 55 lines
---
Fix UML hostfsmknod(): userspace has differerntdev_tsize and encoding than kernel, so extract major/minor and reencode using glibcmakedev()macro.Signed-off-by Johannes Stezenbach <[email protected]>diff -rup
linux-2.6.19.orig/fs/hostfs/hostfs.hlinux-2.6.19/fs/hostfs/hostfs.h---linux-2.6.19.orig/fs/hostfs/hostfs.h2006-11-29 22:57:37.000000000 +0100
+++linux-2.6.19/fs/hostfs/hostfs.h2007-01-23 14:11:03.000000000 +0100 @@
-76,7 +76,7 @@ extern int make_symlink(const char *from
extern intunlink_file(const char *file); extern intdo_mkdir(const char *file, int mode); extern intdo_rmdir(const char *file);(quoted diff) +1
-1-extern int do_mknod(const char *file, int mode, int dev); +extern int do_mknod(const char *file, int mode, unsigned int major,unsigned int minor);
extern int link_file(const char *from, const char
*to);
extern intdo_readlink(char *file, char *buf, int size); extern intrename_file(char *from, char *to);
diff -ruplinux-2.6.19.orig/fs/hostfs/hostfs_kern.clinux-2.6.19/fs/hostfs/hostfs_kern.c---linux-2.6.19.orig/fs/hostfs/hostfs_kern.c2006-11-29 22:57:37.000000000
+0100 +++linux-2.6.19/fs/hostfs/hostfs_kern.c2007-01-23
14:11:20.000000000 +0100 @@ -755,7 +755,7 @@ int hostfs_mknod(struct inode *dir, strufs/hostfs/hostfs_kern.c +1
-1goto out_put;init_special_inode (inode, mode, dev); - err =do_mknod (name, mode, dev); + err =do_mknod (name, mode,MAJOR (dev),MINOR (dev));if (err) goto out_free;diff -rup
linux-2.6.19.orig/fs/hostfs/hostfs_user.clinux-2.6.19/fs/hostfs/hostfs_user.c---linux-2.6.19.orig/fs/hostfs/hostfs_user.c2006-11-29 22:57:37.000000000
+0100 +++linux-2.6.19/fs/hostfs/hostfs_user.c2007-01-23
14:11:39.000000000 +0100 @@ -295,11 +295,11 @@ intdo_rmdir(const char *file)fs/hostfs/hostfs_user.c +1
-1return (0 ); } -int do_mknod (const char *file,int mode,int dev) +int do_mknod(const char *file, int mode, unsigned int major, unsigned intminor) {
fs/hostfs/hostfs_user.c +1
-1int err; - err =mknod (file, mode, dev); + err =mknod (file, mode,makedev (major, minor));if (err)return (-errno);return (0 ); }
Signature · 5 lines
Inform me of my mistakes, so I can add them to my list! Paolo Giarrusso, aka Blaisorblade http://www.user-mode-linux.org/~blaisorblade Chiacchiera con i tuoi amici in tempo reale! http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com
Quoted 15 lines · On Tue, 23 Jan 2007 23:33:29 +0100 Blaisorblade <[email protected]> wrote:
Quoted 7 lines · Johannes Stezenbach
Quoted 6 lines · Blaisorblade
Quoted 3 lines · Johannes Stezenbach
I was playing with user-mode Linux and found that mknod creates devices node in hostfs with wrong major/minor numbers. The patch below fixes it for me.
Hmpf. Still having this bug on hostfs is quite bad. Thanks for reporting.
I've now seen - we never fixed this one, we fixed the analogous problem on 'ls' output and friends (in
init_inode, which is used in many places).Quoted 3 lines
Quoted 2 lines
It should be
hostfs_user.cto take major and minor and to combine them correctly - it can use libc's macros.
Quoted 7 lines
Quoted 1 line
Right, below is a better patch.
Exactly what I meant, thanks!
I'd say:This can go to 2.6.20, and possibly even to -stable (after either me or Jeff tests it once).
So.. did you test it?
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel
Quoted 21 lines · Andrew Morton
On Tue, 23 Jan 2007 23:33:29 +0100
Quoted 18 lines · Blaisorblade
Quoted 8 lines · Johannes Stezenbach
Quoted 7 lines · Blaisorblade
Quoted 3 lines · Johannes Stezenbach
I was playing with user-mode Linux and found that mknod creates devices node in hostfs with wrong major/minor numbers. The patch below fixes it for me.
Hmpf. Still having this bug on hostfs is quite bad. Thanks for reporting.
I've now seen - we never fixed this one, we fixed the analogous problem on 'ls' output and friends (in
init_inode, which is used in many places).Quoted 4 lines
Quoted 2 lines
It should be
hostfs_user.cto take major and minor and to combine them correctly - it can use libc's macros.Right, below is a better patch.
Quoted 7 lines
Quoted 5 lines
Exactly what I meant, thanks!
I'd say:This can go to 2.6.20, and possibly even to -stable (after either me or Jeff tests it once).
So.. did you test it?
Just tested, I could reproduce the bug and verify the fix works, on 2.6.18; and for me it's enough to merge it, considering that little changes happened on hostfs, and because it's well understood with static review that this fix is needed.
It should also be merged in 2.6.16-stable.
Signature · 5 lines
Inform me of my mistakes, so I can add them to my list! Paolo Giarrusso, aka Blaisorblade http://www.user-mode-linux.org/~blaisorblade Chiacchiera con i tuoi amici in tempo reale! http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com