From patchwork Tue Jun 28 18:06:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vrabel X-Patchwork-Id: 9203789 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DC93C6075F for ; Tue, 28 Jun 2016 18:12:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D45B728611 for ; Tue, 28 Jun 2016 18:12:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C697A2860F; Tue, 28 Jun 2016 18:12:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 457702860F for ; Tue, 28 Jun 2016 18:12:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751068AbcF1SLv (ORCPT ); Tue, 28 Jun 2016 14:11:51 -0400 Received: from smtp.citrix.com ([66.165.176.89]:11357 "EHLO SMTP.CITRIX.COM" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751879AbcF1SLu (ORCPT ); Tue, 28 Jun 2016 14:11:50 -0400 X-IronPort-AV: E=Sophos;i="5.26,542,1459814400"; d="scan'208";a="363291892" From: David Vrabel To: Alexander Viro CC: David Vrabel , , , , "Boris Ostrovsky" , Juergen Gross Subject: [PATCHv3 1/2] libfs: allow simple_fill_super() to add symlinks Date: Tue, 28 Jun 2016 19:06:06 +0100 Message-ID: <1467137167-28546-2-git-send-email-david.vrabel@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1467137167-28546-1-git-send-email-david.vrabel@citrix.com> References: <1467137167-28546-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 X-DLP: MIA1 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- v2: - simplified. --- fs/libfs.c | 15 +++++++++++++-- include/linux/fs.h | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index cedeacb..bbf2d82 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -512,9 +512,20 @@ int simple_fill_super(struct super_block *s, unsigned long magic, dput(dentry); goto out; } - inode->i_mode = S_IFREG | files->mode; + if (files->mode & 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; + } + } else { + inode->i_mode = S_IFREG | files->mode; + inode->i_fop = files->ops; + } inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; - inode->i_fop = files->ops; inode->i_ino = i; d_add(dentry, inode); } diff --git a/include/linux/fs.h b/include/linux/fs.h index dd28814..20c54a2 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2953,7 +2953,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);