diff mbox

[18/23] richacl: Add helper function for creating richacl from mode values.

Message ID 1265002505-8387-19-git-send-email-aneesh.kumar@linux.vnet.ibm.com
State Not Applicable, archived
Headers show

Commit Message

Aneesh Kumar K.V Feb. 1, 2010, 5:35 a.m. UTC
When we don't have richacl stored on disk for permission check
we need to generate richacl from mode values. This patch adds
a helper function for doing that.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
---
 fs/richacl_base.c       |   29 +++++++++++++++++++++++++++++
 include/linux/richacl.h |    1 +
 2 files changed, 30 insertions(+), 0 deletions(-)
diff mbox

Patch

diff --git a/fs/richacl_base.c b/fs/richacl_base.c
index 4a340d7..5d61b30 100644
--- a/fs/richacl_base.c
+++ b/fs/richacl_base.c
@@ -640,3 +640,32 @@  richacl_inherit(const struct richacl *dir_acl, mode_t mode)
 	return acl;
 }
 EXPORT_SYMBOL_GPL(richacl_inherit);
+
+struct richacl *
+richacl_from_mode(mode_t mode)
+{
+	struct richacl *acl;
+	struct richace *ace;
+	int is_dir = S_ISDIR(mode);
+
+	acl = richacl_alloc(1);
+	if (!acl)
+		return NULL;
+	ace = acl->a_entries;
+
+	acl->a_owner_mask = richacl_mode_to_mask(mode >> 6, is_dir);
+	acl->a_group_mask = richacl_mode_to_mask(mode >> 3, is_dir);
+	acl->a_other_mask = richacl_mode_to_mask(mode, is_dir);
+
+	ace->e_type  = ACE4_ACCESS_ALLOWED_ACE_TYPE;
+	ace->e_flags = ACE4_SPECIAL_WHO;
+	ace->e_mask  = ACE4_VALID_MASK;
+	ace->u.e_who = richace_everyone_who;
+	if (richacl_apply_masks(&acl)) {
+		richacl_put(acl);
+		acl = NULL;
+	}
+	return acl;
+
+}
+EXPORT_SYMBOL_GPL(richacl_from_mode);
diff --git a/include/linux/richacl.h b/include/linux/richacl.h
index 705e061..ecb76bc 100644
--- a/include/linux/richacl.h
+++ b/include/linux/richacl.h
@@ -238,5 +238,6 @@  extern int richacl_apply_masks(struct richacl **acl);
 extern int richacl_write_through(struct richacl **acl);
 extern struct richacl *map_posix_to_richacl(struct inode *, struct posix_acl *,
 					struct posix_acl *);
+extern struct richacl *richacl_from_mode(mode_t);
 
 #endif /* __RICHACL_H */