From patchwork Fri Mar 27 16:50:26 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: 6110051 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A7BEA9F2A9 for ; Fri, 27 Mar 2015 16:57:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DAB7D203AD for ; Fri, 27 Mar 2015 16:57:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E4649203F3 for ; Fri, 27 Mar 2015 16:57:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754291AbbC0Q4z (ORCPT ); Fri, 27 Mar 2015 12:56:55 -0400 Received: from mail-wg0-f42.google.com ([74.125.82.42]:36441 "EHLO mail-wg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752744AbbC0QwT (ORCPT ); Fri, 27 Mar 2015 12:52:19 -0400 Received: by wgra20 with SMTP id a20so105284726wgr.3; Fri, 27 Mar 2015 09:52:17 -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=TolhdJJxev6zsUDA2m20epyPzQL0oxF+JqBU/ybhYfo=; b=UCJGWHoKJlTUfEXTqnEaAckouRTSevsR52loLmmVWdNszDdryae2e8u+AIV0dHBQOx /OC5+v6SUGKlcs8MIrSSxGLIvU2Hc+nmsxyBFd67GCIZdhuJ0LGlYEv9shFuKethJHPk MTCYV8J4Wj8EllKXBJGrgYKmW4c0TH3/Q+DKUXJDum9MQupIVsrnWg5dDoKT1a3e9eyQ i/mEfGV2iJL31hkgTcrQtr0nWAjx7tl93IWXr10xfgz1XiAg3UBU7kAq7/6Rbqkg8NEw nYjwpzB42M99uzjndzpE4XWtnqY2Uh2DRFyzjmZYkIaEFDXjeNNHmIBEJrtDK5UZX6x1 lNxw== X-Received: by 10.194.170.193 with SMTP id ao1mr39819271wjc.52.1427475137890; Fri, 27 Mar 2015 09:52:17 -0700 (PDT) Received: from nuc.home.com (80-110-94-70.cgn.dynamic.surfer.at. [80.110.94.70]) by mx.google.com with ESMTPSA id j7sm3592306wix.4.2015.03.27.09.52.16 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 27 Mar 2015 09:52:17 -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 28/39] richacl: Create richacl from mode values Date: Fri, 27 Mar 2015 17:50:26 +0100 Message-Id: <12503bb14bb098b6b3ad7b1c0bf6de8d05b48d6b.1427471526.git.agruenba@redhat.com> 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 | 35 +++++++++++++++++++++++++++++++++++ include/linux/richacl.h | 1 + 2 files changed, 36 insertions(+) diff --git a/fs/richacl_compat.c b/fs/richacl_compat.c index 981bd49..8454621 100644 --- a/fs/richacl_compat.c +++ b/fs/richacl_compat.c @@ -747,3 +747,38 @@ richacl_apply_masks(struct richacl **acl) return retval; } EXPORT_SYMBOL_GPL(richacl_apply_masks); + +/** + * richacl_from_mode - create an acl which corresponds to @mode + * @mode: file mode including the file type + */ +struct richacl * +richacl_from_mode(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); diff --git a/include/linux/richacl.h b/include/linux/richacl.h index 1a07ea0..cda945a 100644 --- a/include/linux/richacl.h +++ b/include/linux/richacl.h @@ -325,5 +325,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(mode_t); #endif /* __RICHACL_H */