From e9f1b1c0655a6ca4efb7e9e3aad4b2a05b4c1857 Mon Sep 17 00:00:00 2001 From: zhangkaixiang Date: Wed, 22 Mar 2023 15:25:21 +0800 Subject: [PATCH] fixed f433091 from https://gitee.com/zkx48/kernel_linux_5.10/pulls/730 do not open file when nlink is zero Signed-off-by: zhangkaixiang --- fs/sharefs/file.c | 16 ---------------- fs/sharefs/lookup.c | 7 +++++++ 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/fs/sharefs/file.c b/fs/sharefs/file.c index 07458f47b885..5e62122f98b2 100644 --- a/fs/sharefs/file.c +++ b/fs/sharefs/file.c @@ -11,21 +11,6 @@ #include "sharefs.h" -static int sharefs_readdir(struct file *file, struct dir_context *ctx) -{ - int err; - struct file *lower_file = NULL; - struct dentry *dentry = file->f_path.dentry; - - lower_file = sharefs_lower_file(file); - err = iterate_dir(lower_file, ctx); - file->f_pos = lower_file->f_pos; - if (err >= 0) - fsstack_copy_attr_atime(d_inode(dentry), - file_inode(lower_file)); - return err; -} - static int sharefs_open(struct inode *inode, struct file *file) { int err = 0; @@ -232,7 +217,6 @@ const struct file_operations sharefs_main_fops = { /* trimmed directory options */ const struct file_operations sharefs_dir_fops = { .llseek = sharefs_file_llseek, - .iterate = sharefs_readdir, .open = sharefs_open, .release = sharefs_file_release, .flush = sharefs_flush, diff --git a/fs/sharefs/lookup.c b/fs/sharefs/lookup.c index 47ead11f45f5..fb6da6b11be3 100644 --- a/fs/sharefs/lookup.c +++ b/fs/sharefs/lookup.c @@ -90,6 +90,13 @@ struct inode *sharefs_iget(struct super_block *sb, struct inode *lower_inode) iput(lower_inode); return ERR_PTR(-ENOMEM); } + + if (lower_inode->i_nlink == 0) { + iput(lower_inode); + iput(inode); + return ERR_PTR(-ENOENT); + } + /* if found a cached inode, then just return it (after iput) */ if (!(inode->i_state & I_NEW)) { iput(lower_inode); -- Gitee