erofs-utils: don't create hardlinked directories

Fix an issue which behaves the same as the following
mkisofs BZ due to bindmount:
https://bugzilla.redhat.com/show_bug.cgi?id=1749860

Link: https://lore.kernel.org/r/20201204172042.24180-1-hsiangkao@aol.com
Fixes: a17497f0844a ("erofs-utils: introduce inode operations")
Reviewed-by: Li Guifu <bluce.lee@aliyun.com>
Signed-off-by: Gao Xiang <hsiangkao@aol.com>
diff --git a/lib/inode.c b/lib/inode.c
index 388d21d..1cf813d 100644
--- a/lib/inode.c
+++ b/lib/inode.c
@@ -823,9 +823,16 @@
 	if (ret)
 		return ERR_PTR(-errno);
 
-	inode = erofs_iget(st.st_ino);
-	if (inode)
-		return inode;
+	/*
+	 * lookup in hash table first, if it already exists we have a
+	 * hard-link, just return it. Also don't lookup for directories
+	 * since hard-link directory isn't allowed.
+	 */
+	if (!S_ISDIR(st.st_mode)) {
+		inode = erofs_iget(st.st_ino);
+		if (inode)
+			return inode;
+	}
 
 	/* cannot find in the inode cache */
 	inode = erofs_new_inode();