Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761559AbcJ1PxU (ORCPT ); Fri, 28 Oct 2016 11:53:20 -0400 Received: from smtp.citrix.com ([66.165.176.89]:12110 "EHLO SMTP.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761351AbcJ1Pwu (ORCPT ); Fri, 28 Oct 2016 11:52:50 -0400 X-IronPort-AV: E=Sophos;i="5.31,410,1473120000"; d="scan'208";a="386656935" From: David Vrabel To: Alexander Viro CC: David Vrabel , , , , "Boris Ostrovsky" , Juergen Gross Subject: [PATCHv4 1/3] libfs: allow simple_fill_super() to add symlinks Date: Fri, 28 Oct 2016 16:52:37 +0100 Message-ID: <1477669959-9486-2-git-send-email-david.vrabel@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1477669959-9486-1-git-send-email-david.vrabel@citrix.com> References: <1477669959-9486-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 Content-Type: text/plain X-DLP: MIA1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2541 Lines: 83 simple_fill_super() will add symlinks if an entry has mode & S_IFLNK. The target is provided in the new "link" field. Signed-off-by: David Vrabel --- v4: - Use switch for file type. v2: - simplified. --- fs/libfs.c | 27 ++++++++++++++++++++++++--- include/linux/fs.h | 2 +- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index 48826d4..8eabcb1 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -509,6 +509,7 @@ int simple_fill_super(struct super_block *s, unsigned long magic, struct dentry *root; struct dentry *dentry; int i; + int ret = -ENOMEM; s->s_blocksize = PAGE_SIZE; s->s_blocksize_bits = PAGE_SHIFT; @@ -550,9 +551,29 @@ int simple_fill_super(struct super_block *s, unsigned long magic, dput(dentry); goto out; } - inode->i_mode = S_IFREG | files->mode; + switch (files->mode & S_IFMT) { + case S_IFLNK: + inode->i_mode = files->mode; + inode->i_op = &simple_symlink_inode_operations; + inode->i_link = kstrdup(files->link, GFP_KERNEL); + if (!inode->i_link) { + iput(inode); + dput(dentry); + goto out; + } + break; + case S_IFREG: + case 0: + inode->i_mode = S_IFREG | files->mode; + inode->i_fop = files->ops; + break; + default: + iput(inode); + dput(dentry); + ret = -EINVAL; + goto out; + } inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode); - inode->i_fop = files->ops; inode->i_ino = i; d_add(dentry, inode); } @@ -562,7 +583,7 @@ int simple_fill_super(struct super_block *s, unsigned long magic, d_genocide(root); shrink_dcache_parent(root); dput(root); - return -ENOMEM; + return ret; } EXPORT_SYMBOL(simple_fill_super); diff --git a/include/linux/fs.h b/include/linux/fs.h index 16d2b6e..4b64fbb 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2988,7 +2988,7 @@ extern const struct file_operations simple_dir_operations; extern const struct inode_operations simple_dir_inode_operations; extern void make_empty_dir_inode(struct inode *inode); extern bool is_empty_dir_inode(struct inode *inode); -struct tree_descr { char *name; const struct file_operations *ops; int mode; }; +struct tree_descr { char *name; const struct file_operations *ops; int mode; char *link; }; struct dentry *d_alloc_name(struct dentry *, const char *); extern int simple_fill_super(struct super_block *, unsigned long, struct tree_descr *); extern int simple_pin_fs(struct file_system_type *, struct vfsmount **mount, int *count); -- 2.1.4