From patchwork Fri Apr 24 11:04:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Andreas_Gr=C3=BCnbacher?= X-Patchwork-Id: 6268101 Return-Path: X-Original-To: patchwork-linux-nfs@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 D8923BF4A6 for ; Fri, 24 Apr 2015 11:10:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 43662201E4 for ; Fri, 24 Apr 2015 11:10:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6228E200F3 for ; Fri, 24 Apr 2015 11:10:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965140AbbDXLFm (ORCPT ); Fri, 24 Apr 2015 07:05:42 -0400 Received: from mail-wi0-f180.google.com ([209.85.212.180]:36886 "EHLO mail-wi0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964967AbbDXLFd (ORCPT ); Fri, 24 Apr 2015 07:05:33 -0400 Received: by widdi4 with SMTP id di4so16061932wid.0; Fri, 24 Apr 2015 04:05:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=ZlNURZ2wlKvwuNaITpWGBguUxLc88WqGWhuFtcAto+s=; b=kfDj1M3peYiNPlkzkHhAABQhRryhBFfxqXq2DNKBP4v91MnolWNdz1bSTGXoYvYUXf wqm4Jn1UgzBRVsroDA9QNQm2Uq5EVwL5dDIdoy0ZX7srUVqGvqZm4eIE2ptAuC9JZ/vd dyQOZECdUNeg6BEWgzNmjvxnWAVAqmKx7ddENSIy5YqLrQ2LKX8+J/beadVFfxssMV6t gPPa8kHKvjXt8euy5MCtg9mFHYH+b4RBpgKy6pCu46iaEQe+yH2fs4VKpUmPiMhjozrv QAKMSsKa8FNAWySPQ5JJNPlhiPxhDpwTCC/RmloGBzEHu/arK6tq5QrhjX7IuZg+nIUE kw+A== X-Received: by 10.180.208.7 with SMTP id ma7mr2955279wic.0.1429873532344; Fri, 24 Apr 2015 04:05:32 -0700 (PDT) Received: from nuc.home.com (80-110-112-232.cgn.dynamic.surfer.at. [80.110.112.232]) by mx.google.com with ESMTPSA id ch6sm16410648wjc.3.2015.04.24.04.05.30 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Apr 2015 04:05:31 -0700 (PDT) From: Andreas Gruenbacher X-Google-Original-From: Andreas Gruenbacher To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org Cc: Andreas Gruenbacher Subject: [RFC v3 30/45] richacl: Create richacl from mode values Date: Fri, 24 Apr 2015 13:04:27 +0200 Message-Id: X-Mailer: git-send-email 2.1.0 In-Reply-To: References: In-Reply-To: References: Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, 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 Create a richacl that corresponds to given file mode permission bits. Signed-off-by: Andreas Gruenbacher --- fs/richacl_compat.c | 38 ++++++++++++++++++++++++++++++++++++++ include/linux/richacl.h | 1 + 2 files changed, 39 insertions(+) diff --git a/fs/richacl_compat.c b/fs/richacl_compat.c index 49af600..8ebe772 100644 --- a/fs/richacl_compat.c +++ b/fs/richacl_compat.c @@ -750,3 +750,41 @@ richacl_apply_masks(struct richacl **acl) return 0; } EXPORT_SYMBOL_GPL(richacl_apply_masks); + +/** + * richacl_from_mode_unmasked - create an acl which corresponds to @mode + * + * The resulting acl doesn't have the RICHACL_MASKED flag set. + * + * @mode: file mode including the file type + */ +struct richacl * +richacl_from_mode_unmasked(mode_t mode) +{ + struct richacl *acl; + struct richace *ace; + + acl = richacl_alloc(1, GFP_KERNEL); + if (!acl) + return NULL; + acl->a_flags = RICHACL_MASKED; + acl->a_owner_mask = richacl_mode_to_mask(mode >> 6) | + RICHACE_POSIX_OWNER_ALLOWED; + acl->a_group_mask = richacl_mode_to_mask(mode >> 3); + acl->a_other_mask = richacl_mode_to_mask(mode); + + ace = acl->a_entries; + ace->e_type = RICHACE_ACCESS_ALLOWED_ACE_TYPE; + ace->e_flags = RICHACE_SPECIAL_WHO; + ace->e_mask = RICHACE_POSIX_ALWAYS_ALLOWED | + RICHACE_POSIX_MODE_ALL | + RICHACE_POSIX_OWNER_ALLOWED; + /* RICHACE_DELETE_CHILD is meaningless for non-directories. */ + if (!S_ISDIR(mode)) + ace->e_mask &= ~RICHACE_DELETE_CHILD; + ace->e_id.special = RICHACE_EVERYONE_SPECIAL_ID; + + return acl; + +} +EXPORT_SYMBOL_GPL(richacl_from_mode_unmasked); diff --git a/include/linux/richacl.h b/include/linux/richacl.h index 6a97dca..25ff4df 100644 --- a/include/linux/richacl.h +++ b/include/linux/richacl.h @@ -327,5 +327,6 @@ extern struct richacl *richacl_create(struct inode *, struct inode *); /* richacl_compat.c */ extern int richacl_apply_masks(struct richacl **); +extern struct richacl *richacl_from_mode_unmasked(mode_t); #endif /* __RICHACL_H */