1 From 2dcf8e92bc39e05b3c799f53fe911c024aee4375 Mon Sep 17 00:00:00 2001
2 From: Robert Yang <liezhi.yang@windriver.com>
3 Date: Fri, 23 Oct 2015 03:21:05 -0700
4 Subject: [PATCH] copy-in: create hardlinks with the correct directory
7 When we're creating hard links via ext2fs_link, the (misnamed?) flags
8 argument specifies the filetype for the directory entry. This is
9 *derived* from i_mode, so provide a translator. Otherwise, fsck will
10 complain about unset file types.
12 Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
13 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
15 Upstream-Status: Backport
17 Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
19 misc/create_inode.c | 33 +++++++++++++++++++++++++++++++--
20 1 file changed, 31 insertions(+), 2 deletions(-)
22 diff --git a/misc/create_inode.c b/misc/create_inode.c
23 index fcec5aa..b8565da 100644
24 --- a/misc/create_inode.c
25 +++ b/misc/create_inode.c
27 /* For saving the hard links */
28 int hdlink_cnt = HDLINK_CNT;
30 +static int ext2_file_type(unsigned int mode)
32 + if (LINUX_S_ISREG(mode))
33 + return EXT2_FT_REG_FILE;
35 + if (LINUX_S_ISDIR(mode))
38 + if (LINUX_S_ISCHR(mode))
39 + return EXT2_FT_CHRDEV;
41 + if (LINUX_S_ISBLK(mode))
42 + return EXT2_FT_BLKDEV;
44 + if (LINUX_S_ISLNK(mode))
45 + return EXT2_FT_SYMLINK;
47 + if (LINUX_S_ISFIFO(mode))
48 + return EXT2_FT_FIFO;
50 + if (LINUX_S_ISSOCK(mode))
51 + return EXT2_FT_SOCK;
57 /* Link an inode number to a directory */
58 static errcode_t add_link(ext2_ino_t parent_ino, ext2_ino_t ino, const char *name)
60 @@ -34,14 +61,16 @@ static errcode_t add_link(ext2_ino_t parent_ino, ext2_ino_t ino, const char *nam
64 - retval = ext2fs_link(current_fs, parent_ino, name, ino, inode.i_flags);
65 + retval = ext2fs_link(current_fs, parent_ino, name, ino,
66 + ext2_file_type(inode.i_mode));
67 if (retval == EXT2_ET_DIR_NO_SPACE) {
68 retval = ext2fs_expand_dir(current_fs, parent_ino);
70 com_err(__func__, retval, "while expanding directory");
73 - retval = ext2fs_link(current_fs, parent_ino, name, ino, inode.i_flags);
74 + retval = ext2fs_link(current_fs, parent_ino, name, ino,
75 + ext2_file_type(inode.i_mode));
78 com_err(__func__, retval, "while linking %s", name);