From patchwork Mon May 16 17:44:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Vrabel X-Patchwork-Id: 9104841 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7BDD2BF29F for ; Mon, 16 May 2016 17:46:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8FAF4201CD for ; Mon, 16 May 2016 17:46:23 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AB56A201B4 for ; Mon, 16 May 2016 17:46:22 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b2MZ1-0004z9-9O; Mon, 16 May 2016 17:44:19 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b2MZ0-0004yq-EG for xen-devel@lists.xenproject.org; Mon, 16 May 2016 17:44:18 +0000 Received: from [85.158.139.211] by server-7.bemta-5.messagelabs.com id E9/3A-26575-1F60A375; Mon, 16 May 2016 17:44:17 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjkeJIrShJLcpLzFFi42JxWrrBXvcjm1W 4wYvJIhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bRr7sYCzYKVWyf9I61gXEyfxcjJ4eEgL/E mzeHmUBsNgEdicdLZrB3MXJwiAioSNzeawASZhaokrhy6TMriC0s4C5x6NECFpASFgFViZsnX UHCvEDhDQtOsUJMlJM4f/wnM0gJp4CHxO4/PCBhIaCS64d3sEDYKhIf165ihWgVlDg58wkLxC YJiYMvXjBDjOGWuH16KvMERr5ZSMpmISlbwMi0ilGjOLWoLLVI19BQL6koMz2jJDcxM0fX0MB ULze1uDgxPTUnMalYLzk/dxMjMJwYgGAH48p250OMkhxMSqK8D5mswoX4kvJTKjMSizPii0pz UosPMcpwcChJ8C5iBcoJFqWmp1akZeYAAxsmLcHBoyTC2w2S5i0uSMwtzkyHSJ1iVJQS51UDS QiAJDJK8+DaYNF0iVFWSpiXEegQIZ6C1KLczBJU+VeM4hyMSsK8sSBTeDLzSuCmvwJazAS0eI KZBcjikkSElFQD4xKbw7sU95kGzFwwecPm0AVn9SU57XWsLy6tftx62CdJQpz/zVTtX8E/r6/ t7jx/OOvzwd8P9if+3Hr326bPKx9ppSzZravZyLP1mouEsLZoEKc/096P937v8mQTv/zPdAXX TjYj0Vfhh12v3ohVdFvaPU11X+HRZ4fTv1Ys0Xg1bfX2S80uki+UWIozEg21mIuKEwFNps0So QIAAA== X-Env-Sender: prvs=937e80a62=david.vrabel@citrix.com X-Msg-Ref: server-9.tower-206.messagelabs.com!1463420652!39966791!3 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 8.34; banners=-,-,- X-VirusChecked: Checked Received: (qmail 48300 invoked from network); 16 May 2016 17:44:17 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-9.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 16 May 2016 17:44:17 -0000 X-IronPort-AV: E=Sophos;i="5.26,627,1459814400"; d="scan'208";a="361318603" From: David Vrabel To: Date: Mon, 16 May 2016 18:44:05 +0100 Message-ID: <1463420646-29530-2-git-send-email-david.vrabel@citrix.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1463420646-29530-1-git-send-email-david.vrabel@citrix.com> References: <1463420646-29530-1-git-send-email-david.vrabel@citrix.com> MIME-Version: 1.0 X-DLP: MIA2 Cc: Juergen Gross , Boris Ostrovsky , David Vrabel Subject: [Xen-devel] [PATCHv1 1/2] libfs: allow simple_fill_super() to add symlinks X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.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 --- fs/libfs.c | 23 ++++++++++++++++++++--- include/linux/fs.h | 2 +- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index f3fa82c..894e182 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -500,6 +500,8 @@ int simple_fill_super(struct super_block *s, unsigned long magic, if (!root) return -ENOMEM; for (i = 0; !files->name || files->name[0]; i++, files++) { + char *link = NULL; + if (!files->name) continue; @@ -509,17 +511,32 @@ int simple_fill_super(struct super_block *s, unsigned long magic, "with an index of 1!\n", __func__, s->s_type->name); + if (files->mode & S_IFLNK) { + link = kstrdup(files->link, GFP_KERNEL); + if (!link) + goto out; + } + dentry = d_alloc_name(root, files->name); - if (!dentry) + if (!dentry) { + kfree(link); goto out; + } inode = new_inode(s); if (!inode) { dput(dentry); + kfree(link); goto out; } - inode->i_mode = S_IFREG | files->mode; + inode->i_mode = files->mode; + if (files->mode & S_IFLNK) { + inode->i_op = &simple_symlink_inode_operations; + inode->i_link = link; + } else { + inode->i_fop = files->ops; + inode->i_mode |= S_IFREG; + } 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 70e61b5..8a09998 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2897,7 +2897,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);