From 47e61052643ae91847d72e074a706a6ec55411cc Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Tue, 26 Jun 2018 09:02:46 -0400 Subject: [PATCH] debugfs: fix mknod command on some 32-bit platforms due to LFS On some platforms the layout of struct stat changes if _FILE_OFFSET_BITS is set to 64 (which force the use of 64-bit types and 64-bit variants for system calls such as stat, lseek, etc.) This is not true (mercifully) on i386, but it is true for the 32-bit mips platform on Linux. This caused debugfs's mknod command to fail, since it used struct stat to pass the desired st_mode and st_rdev fields for the to-be-created device file or FIFO, and this would be different for create_inode.c and debugfs.c. Linking together different object files together compiled with different values of _FILE_OFFSET_BITS is perilous, but for now, let's fix the specific problem by passing the two fields in the stat structure that we really care about. This fixes two regression tests on the 32-bit MIPS platform: d_special_files and r_move_itable. Signed-off-by: Theodore Ts'o --- debugfs/debugfs.c | 3 ++- misc/create_inode.c | 11 ++++++----- misc/create_inode.h | 3 ++- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/debugfs/debugfs.c b/debugfs/debugfs.c index ecca810..fe859d4 100644 --- a/debugfs/debugfs.c +++ b/debugfs/debugfs.c @@ -1767,7 +1767,8 @@ void do_mknod(int argc, char *argv[]) goto usage; st.st_rdev = makedev(major, minor); - retval = do_mknod_internal(current_fs, cwd, argv[1], &st); + retval = do_mknod_internal(current_fs, cwd, argv[1], + st.st_mode, st.st_rdev); if (retval) com_err(argv[0], retval, 0); } diff --git a/misc/create_inode.c b/misc/create_inode.c index caa3609..6621b0a 100644 --- a/misc/create_inode.c +++ b/misc/create_inode.c @@ -235,7 +235,7 @@ static errcode_t set_inode_xattr(ext2_filsys fs EXT2FS_ATTR((unused)), #ifndef _WIN32 /* Make a special files (block and character devices), fifo's, and sockets */ errcode_t do_mknod_internal(ext2_filsys fs, ext2_ino_t cwd, const char *name, - struct stat *st) + unsigned int st_mode, unsigned int st_rdev) { ext2_ino_t ino; errcode_t retval; @@ -243,7 +243,7 @@ errcode_t do_mknod_internal(ext2_filsys fs, ext2_ino_t cwd, const char *name, unsigned long devmajor, devminor, mode; int filetype; - switch(st->st_mode & S_IFMT) { + switch(st_mode & S_IFMT) { case S_IFCHR: mode = LINUX_S_IFCHR; filetype = EXT2_FT_CHRDEV; @@ -299,8 +299,8 @@ errcode_t do_mknod_internal(ext2_filsys fs, ext2_ino_t cwd, const char *name, fs->now ? fs->now : time(0); if (filetype != S_IFIFO) { - devmajor = major(st->st_rdev); - devminor = minor(st->st_rdev); + devmajor = major(st_rdev); + devminor = minor(st_rdev); if ((devmajor < 256) && (devminor < 256)) { inode.i_block[0] = devmajor * 256 + devminor; @@ -798,7 +798,8 @@ static errcode_t __populate_fs(ext2_filsys fs, ext2_ino_t parent_ino, case S_IFIFO: #ifndef _WIN32 case S_IFSOCK: - retval = do_mknod_internal(fs, parent_ino, name, &st); + retval = do_mknod_internal(fs, parent_ino, name, + st.st_mode, st.st_rdev); if (retval) { com_err(__func__, retval, _("while creating special file " diff --git a/misc/create_inode.h b/misc/create_inode.h index 17309c6..3a37632 100644 --- a/misc/create_inode.h +++ b/misc/create_inode.h @@ -40,7 +40,8 @@ extern errcode_t populate_fs2(ext2_filsys fs, ext2_ino_t parent_ino, const char *source_dir, ext2_ino_t root, struct fs_ops_callbacks *fs_callbacks); extern errcode_t do_mknod_internal(ext2_filsys fs, ext2_ino_t cwd, - const char *name, struct stat *st); + const char *name, unsigned int st_mode, + unsigned int st_rdev); extern errcode_t do_symlink_internal(ext2_filsys fs, ext2_ino_t cwd, const char *name, char *target, ext2_ino_t root); -- 1.8.3.1