[prev in list] [next in list] [prev in thread] [next in thread]
List: linux-fsdevel
Subject: [PATCH] JFS acls
From: David Kleikamp <shaggy () austin ! ibm ! com>
Date: 2002-09-06 15:01:31
[Download RAW message or body]
This patch adds ACL support for JFS.
Of course, it requires the JFS extended attribute patch.
It is built against a recent 2.4.19 Suse Beta kernel.
Against a stock kernel, it requires the xattr-0.8.50 and acl-08.50
kernel patches from http://acl.bestbits.at/
------------------------------------------------------------------
diff -Nur linux-jfs-xattr/fs/jfs/Makefile linux-jfs-acl/fs/jfs/Makefile
--- linux-jfs-xattr/fs/jfs/Makefile Fri Sep 6 09:14:32 2002
+++ linux-jfs-acl/fs/jfs/Makefile Fri Sep 6 09:22:58 2002
@@ -14,6 +14,7 @@
jfs_extent.o symlink.o jfs_metapage.o \
jfs_logmgr.o jfs_txnmgr.o jfs_uniupr.o resize.o xattr.o
obj-m := $(O_TARGET)
+obj-$(CONFIG_FS_POSIX_ACL) += acl.o
EXTRA_CFLAGS += -D_JFS_4K
diff -Nur linux-jfs-xattr/fs/jfs/acl.c linux-jfs-acl/fs/jfs/acl.c
--- linux-jfs-xattr/fs/jfs/acl.c Wed Dec 31 18:00:00 1969
+++ linux-jfs-acl/fs/jfs/acl.c Fri Sep 6 09:22:58 2002
@@ -0,0 +1,306 @@
+/*
+ * Copyright (c) International Business Machines Corp., 2002
+ * Copyright (c) Andreas Gruenbacher, 2001
+ * Copyright (c) Linus Torvalds, 1991, 1992
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <linux/fs.h>
+#include "jfs_incore.h"
+#include "jfs_xattr.h"
+#include "jfs_acl.h"
+
+struct posix_acl *jfs_get_acl(struct inode *inode, int type)
+{
+ struct posix_acl *acl;
+ char *ea_name;
+ struct jfs_inode_info *ji = JFS_IP(inode);
+ struct posix_acl **p_acl;
+ int size;
+ char *value = NULL;
+
+ switch(type) {
+ case ACL_TYPE_ACCESS:
+ ea_name = XATTR_NAME_ACL_ACCESS;
+ p_acl = &ji->i_acl;
+ break;
+ case ACL_TYPE_DEFAULT:
+ ea_name = XATTR_NAME_ACL_DEFAULT;
+ p_acl = &ji->i_default_acl;
+ break;
+ default:
+ return ERR_PTR(-EINVAL);
+ }
+
+ if (*p_acl != JFS_ACL_NOT_CACHED)
+ return posix_acl_dup(*p_acl);
+
+ size = __jfs_getxattr(inode, ea_name, NULL, 0);
+
+ if (size > 0) {
+ value = kmalloc(size, GFP_KERNEL);
+ if (!value)
+ return ERR_PTR(-ENOMEM);
+ size = __jfs_getxattr(inode, ea_name, value, size);
+ }
+
+ if (size < 0) {
+ if (size == -ENOATTR) {
+ *p_acl = NULL;
+ acl = NULL;
+ } else
+ acl = ERR_PTR(size);
+ } else {
+ acl = posix_acl_from_xattr(value, size);
+ if (!IS_ERR(acl))
+ *p_acl = posix_acl_dup(acl);
+ }
+ if (value)
+ kfree(value);
+ return acl;
+}
+
+int jfs_set_acl(struct inode *inode, int type, struct posix_acl *acl)
+{
+ char *ea_name;
+ struct jfs_inode_info *ji = JFS_IP(inode);
+ struct posix_acl **p_acl;
+ int rc;
+ int size = 0;
+ char *value = NULL;
+
+ if (S_ISLNK(inode->i_mode))
+ return -ENOTSUP;
+
+ switch(type) {
+ case ACL_TYPE_ACCESS:
+ ea_name = XATTR_NAME_ACL_ACCESS;
+ p_acl = &ji->i_acl;
+ if (acl) {
+ mode_t mode = inode->i_mode;
+ rc = posix_acl_equiv_mode(acl, &mode);
+ if (rc < 0)
+ return rc;
+ inode->i_mode = mode;
+ mark_inode_dirty(inode);
+ if (rc == 0)
+ acl = NULL;
+ }
+ break;
+ case ACL_TYPE_DEFAULT:
+ ea_name = XATTR_NAME_ACL_DEFAULT;
+ p_acl = &ji->i_default_acl;
+ if (!S_ISDIR(inode->i_mode))
+ return acl ? -EACCES : 0;
+ break;
+ default:
+ return -EINVAL;
+ }
+ if (acl) {
+ size = xattr_acl_size(acl->a_count);
+ value = kmalloc(size, GFP_KERNEL);
+ if (!value)
+ return -ENOMEM;
+ rc = posix_acl_to_xattr(acl, value, size);
+ if (rc < 0)
+ goto out;
+ }
+ rc = __jfs_setxattr(inode, ea_name, value, size, 0);
+out:
+ if (value)
+ kfree(value);
+
+ if (!rc) {
+ if (*p_acl && (*p_acl != JFS_ACL_NOT_CACHED))
+ posix_acl_release(*p_acl);
+ *p_acl = posix_acl_dup(acl);
+ }
+ return rc;
+}
+
+/*
+ * jfs_permission()
+ *
+ * modified vfs_permission to check posix acl
+ */
+int jfs_permission(struct inode * inode, int mask)
+{
+ umode_t mode = inode->i_mode;
+ struct jfs_inode_info *ji = JFS_IP(inode);
+
+ if (mask & MAY_WRITE) {
+ /*
+ * Nobody gets write access to a read-only fs.
+ */
+ if (IS_RDONLY(inode) &&
+ (S_ISREG(mode) || S_ISDIR(mode) || S_ISLNK(mode)))
+ return -EROFS;
+
+ /*
+ * Nobody gets write access to an immutable file.
+ */
+ if (IS_IMMUTABLE(inode))
+ return -EACCES;
+ }
+
+ if (current->fsuid == inode->i_uid) {
+ mode >>= 6;
+ goto check_mode;
+ }
+ /*
+ * ACL can't contain additional permissions if the ACL_MASK entry
+ * is zero.
+ */
+ if (!(mode & S_IRWXG))
+ goto check_mode;
+
+ if (ji->i_acl == JFS_ACL_NOT_CACHED) {
+ struct posix_acl *acl;
+
+ down(&inode->i_sem);
+ acl = jfs_get_acl(inode, ACL_TYPE_ACCESS);
+ up(&inode->i_sem);
+
+ if (IS_ERR(acl))
+ return PTR_ERR(acl);
+ posix_acl_release(acl);
+ }
+
+ if (ji->i_acl) {
+ int rc = posix_acl_permission(inode, ji->i_acl, mask);
+ if (rc == -EACCES)
+ goto check_capabilities;
+ return rc;
+ }
+
+ if (in_group_p(inode->i_gid))
+ mode >>= 3;
+
+check_mode:
+ /*
+ * If the DACs are ok we don't need any capability check.
+ */
+ if (((mode & mask & (MAY_READ|MAY_WRITE|MAY_EXEC)) == mask))
+ return 0;
+
+check_capabilities:
+ /*
+ * Read/write DACs are always overridable.
+ * Executable DACs are overridable if at least one exec bit is set.
+ */
+ if ((mask & (MAY_READ|MAY_WRITE)) || (inode->i_mode & S_IXUGO))
+ if (capable(CAP_DAC_OVERRIDE))
+ return 0;
+
+ /*
+ * Searching includes executable on directories, else just read.
+ */
+ if (mask == MAY_READ || (S_ISDIR(inode->i_mode) && !(mask & MAY_WRITE)))
+ if (capable(CAP_DAC_READ_SEARCH))
+ return 0;
+
+ return -EACCES;
+}
+
+int jfs_init_acl(struct inode *inode, struct inode *dir)
+{
+ struct posix_acl *acl = NULL;
+ struct posix_acl *clone;
+ mode_t mode;
+ int rc = 0;
+
+ if (S_ISLNK(inode->i_mode))
+ return 0;
+
+ acl = jfs_get_acl(dir, ACL_TYPE_DEFAULT);
+ if (IS_ERR(acl))
+ return PTR_ERR(acl);
+
+ if (acl) {
+ if (S_ISDIR(inode->i_mode)) {
+ rc = jfs_set_acl(inode, ACL_TYPE_DEFAULT, acl);
+ if (rc)
+ goto cleanup;
+ }
+ clone = posix_acl_clone(acl, GFP_KERNEL);
+ if (!clone) {
+ rc = -ENOMEM;
+ goto cleanup;
+ }
+ mode = inode->i_mode;
+ rc = posix_acl_create_masq(clone, &mode);
+ if (rc >= 0) {
+ inode->i_mode = mode;
+ if (rc > 0)
+ rc = jfs_set_acl(inode, ACL_TYPE_ACCESS, clone);
+ }
+ posix_acl_release(clone);
+cleanup:
+ posix_acl_release(acl);
+ } else
+ inode->i_mode &= ~current->fs->umask;
+
+ return rc;
+}
+
+int jfs_acl_chmod(struct inode *inode)
+{
+ struct posix_acl *acl, *clone;
+ int rc;
+
+ if (S_ISLNK(inode->i_mode))
+ return -ENOTSUP;
+
+ acl = jfs_get_acl(inode, ACL_TYPE_ACCESS);
+ if (IS_ERR(acl) || !acl)
+ return PTR_ERR(acl);
+
+ clone = posix_acl_clone(acl, GFP_KERNEL);
+ if (!clone)
+ return -ENOMEM;
+
+ rc = posix_acl_chmod_masq(clone, inode->i_mode);
+ if (!rc)
+ rc = jfs_set_acl(inode, ACL_TYPE_ACCESS, clone);
+
+ posix_acl_release(clone);
+ return rc;
+}
+
+int jfs_setattr(struct dentry *dentry, struct iattr *iattr)
+{
+ struct inode *inode = dentry->d_inode;
+ int rc;
+
+ rc = inode_change_ok(inode, iattr);
+ if (rc)
+ return rc;
+
+ inode_setattr(inode, iattr);
+
+ if (iattr->ia_valid & ATTR_MODE) {
+ /*
+ * Mode change may affect acl. i_sem already held by
+ * truncate (ia_valid & ATTR_SIZE)
+ */
+ if (!(iattr->ia_valid & ATTR_SIZE))
+ down(&inode->i_sem);
+ rc = jfs_acl_chmod(inode);
+ if (!(iattr->ia_valid & ATTR_SIZE))
+ up(&inode->i_sem);
+ }
+ return rc;
+}
diff -Nur linux-jfs-xattr/fs/jfs/file.c linux-jfs-acl/fs/jfs/file.c
--- linux-jfs-xattr/fs/jfs/file.c Fri Sep 6 09:14:32 2002
+++ linux-jfs-acl/fs/jfs/file.c Fri Sep 6 09:22:58 2002
@@ -22,6 +22,7 @@
#include "jfs_incore.h"
#include "jfs_txnmgr.h"
#include "jfs_xattr.h"
+#include "jfs_acl.h"
#include "jfs_debug.h"
@@ -106,6 +107,12 @@
.getxattr = jfs_getxattr,
.listxattr = jfs_listxattr,
.removexattr = jfs_removexattr,
+#ifdef CONFIG_FS_POSIX_ACL
+ .setattr = jfs_setattr,
+ .permission = jfs_permission,
+ .get_posix_acl = jfs_get_acl,
+ .set_posix_acl = jfs_set_acl,
+#endif
};
struct file_operations jfs_file_operations = {
@@ -122,5 +129,11 @@
.getxattr = jfs_getxattr,
.listxattr = jfs_listxattr,
.removexattr = jfs_removexattr,
+#ifdef CONFIG_FS_POSIX_ACL
+ .setattr = jfs_setattr,
+ .permission = jfs_permission,
+ .get_posix_acl = jfs_get_acl,
+ .set_posix_acl = jfs_set_acl,
+#endif
};
diff -Nur linux-jfs-xattr/fs/jfs/inode.c linux-jfs-acl/fs/jfs/inode.c
--- linux-jfs-xattr/fs/jfs/inode.c Fri Sep 6 09:14:32 2002
+++ linux-jfs-acl/fs/jfs/inode.c Fri Sep 6 09:22:58 2002
@@ -23,6 +23,7 @@
#include "jfs_filsys.h"
#include "jfs_imap.h"
#include "jfs_extent.h"
+#include "jfs_acl.h"
#include "jfs_unicode.h"
#include "jfs_debug.h"
@@ -45,6 +46,17 @@
ASSERT(list_empty(&ji->mp_list));
ASSERT(list_empty(&ji->anon_inode_list));
+#ifdef CONFIG_FS_POSIX_ACL
+ if (ji->i_acl && (ji->i_acl != JFS_ACL_NOT_CACHED)) {
+ posix_acl_release(ji->i_acl);
+ ji->i_acl = JFS_ACL_NOT_CACHED;
+ }
+ if (ji->i_default_acl && (ji->i_default_acl != JFS_ACL_NOT_CACHED)) {
+ posix_acl_release(ji->i_default_acl);
+ ji->i_default_acl = JFS_ACL_NOT_CACHED;
+ }
+#endif
+
if (ji->atlhead) {
jERROR(1, ("jfs_clear_inode: inode %p has anonymous tlocks\n",
inode));
diff -Nur linux-jfs-xattr/fs/jfs/jfs_acl.h linux-jfs-acl/fs/jfs/jfs_acl.h
--- linux-jfs-xattr/fs/jfs/jfs_acl.h Wed Dec 31 18:00:00 1969
+++ linux-jfs-acl/fs/jfs/jfs_acl.h Fri Sep 6 09:22:58 2002
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) International Business Machines Corp., 2002
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
+ * the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef _H_JFS_ACL
+#define _H_JFS_ACL
+
+#ifdef CONFIG_FS_POSIX_ACL
+
+#include <linux/xattr_acl.h>
+
+struct posix_acl *jfs_get_acl(struct inode *, int);
+int jfs_set_acl(struct inode *, int, struct posix_acl *);
+int jfs_permission(struct inode *, int);
+int jfs_init_acl(struct inode *, struct inode *);
+int jfs_setattr(struct dentry *, struct iattr *);
+
+#endif /* CONFIG_FS_POSIX_ACL */
+
+#endif /* _H_JFS_ACL */
diff -Nur linux-jfs-xattr/fs/jfs/jfs_imap.c linux-jfs-acl/fs/jfs/jfs_imap.c
--- linux-jfs-xattr/fs/jfs/jfs_imap.c Fri Sep 6 09:14:32 2002
+++ linux-jfs-acl/fs/jfs/jfs_imap.c Fri Sep 6 09:22:58 2002
@@ -3066,6 +3066,10 @@
jfs_ip->atlhead = 0;
jfs_ip->atltail = 0;
jfs_ip->xtlid = 0;
+#ifdef CONFIG_FS_POSIX_ACL
+ jfs_ip->i_acl = JFS_ACL_NOT_CACHED;
+ jfs_ip->i_default_acl = JFS_ACL_NOT_CACHED;
+#endif
return (0);
}
diff -Nur linux-jfs-xattr/fs/jfs/jfs_incore.h linux-jfs-acl/fs/jfs/jfs_incore.h
--- linux-jfs-xattr/fs/jfs/jfs_incore.h Fri Sep 6 09:14:32 2002
+++ linux-jfs-acl/fs/jfs/jfs_incore.h Fri Sep 6 09:22:58 2002
@@ -70,6 +70,10 @@
*/
struct semaphore commit_sem;
lid_t xtlid; /* lid of xtree lock on directory */
+#ifdef CONFIG_FS_POSIX_ACL
+ struct posix_acl *i_acl;
+ struct posix_acl *i_default_acl;
+#endif
union {
struct {
xtpage_t _xtroot; /* 288: xtree root */
@@ -97,6 +101,7 @@
#define i_inline u.link._inline
#define i_inline_ea u.link._inline_ea
+#define JFS_ACL_NOT_CACHED ((void *)-1)
#define IREAD_LOCK(ip) down_read(&JFS_IP(ip)->rdwrlock)
#define IREAD_UNLOCK(ip) up_read(&JFS_IP(ip)->rdwrlock)
diff -Nur linux-jfs-xattr/fs/jfs/jfs_inode.c linux-jfs-acl/fs/jfs/jfs_inode.c
--- linux-jfs-xattr/fs/jfs/jfs_inode.c Fri Sep 6 08:32:47 2002
+++ linux-jfs-acl/fs/jfs/jfs_inode.c Fri Sep 6 09:22:58 2002
@@ -23,6 +23,8 @@
#include "jfs_dinode.h"
#include "jfs_debug.h"
+extern int jfs_init_acl(struct inode *, struct inode *);
+
kmem_cache_t *jfs_inode_cachep;
/*
@@ -95,6 +97,11 @@
jfs_inode->atlhead = 0;
jfs_inode->atltail = 0;
jfs_inode->xtlid = 0;
+#ifdef CONFIG_FS_POSIX_ACL
+ jfs_inode->i_acl = JFS_ACL_NOT_CACHED;
+ jfs_inode->i_default_acl = JFS_ACL_NOT_CACHED;
+ jfs_init_acl(inode, parent);
+#endif
jFYI(1, ("ialloc returns inode = 0x%p\n", inode));
diff -Nur linux-jfs-xattr/fs/jfs/jfs_xattr.h linux-jfs-acl/fs/jfs/jfs_xattr.h
--- linux-jfs-xattr/fs/jfs/jfs_xattr.h Fri Sep 6 09:17:42 2002
+++ linux-jfs-acl/fs/jfs/jfs_xattr.h Fri Sep 6 09:27:43 2002
@@ -52,8 +52,11 @@
#define END_EALIST(ealist) \
((struct jfs_ea *) (((char *) (ealist)) + EALIST_SIZE(ealist)))
+extern int __jfs_setxattr(struct inode *, const char *, const void *, size_t,
+ int);
extern int jfs_setxattr(struct dentry *, const char *, const void *, size_t,
int);
+extern ssize_t __jfs_getxattr(struct inode *, const char *, void *, size_t);
extern ssize_t jfs_getxattr(struct dentry *, const char *, void *, size_t);
extern ssize_t jfs_listxattr(struct dentry *, char *, size_t);
extern int jfs_removexattr(struct dentry *, const char *);
diff -Nur linux-jfs-xattr/fs/jfs/namei.c linux-jfs-acl/fs/jfs/namei.c
--- linux-jfs-xattr/fs/jfs/namei.c Fri Sep 6 09:14:32 2002
+++ linux-jfs-acl/fs/jfs/namei.c Fri Sep 6 09:22:58 2002
@@ -26,6 +26,7 @@
#include "jfs_unicode.h"
#include "jfs_metapage.h"
#include "jfs_xattr.h"
+#include "jfs_acl.h"
#include "jfs_debug.h"
extern struct inode_operations jfs_file_inode_operations;
@@ -1434,6 +1435,12 @@
.getxattr = jfs_getxattr,
.listxattr = jfs_listxattr,
.removexattr = jfs_removexattr,
+#ifdef CONFIG_FS_POSIX_ACL
+ .setattr = jfs_setattr,
+ .permission = jfs_permission,
+ .get_posix_acl = jfs_get_acl,
+ .set_posix_acl = jfs_set_acl,
+#endif
};
struct file_operations jfs_dir_operations = {
diff -Nur linux-jfs-xattr/fs/jfs/xattr.c linux-jfs-acl/fs/jfs/xattr.c
--- linux-jfs-xattr/fs/jfs/xattr.c Fri Sep 6 09:36:12 2002
+++ linux-jfs-acl/fs/jfs/xattr.c Fri Sep 6 09:28:50 2002
@@ -581,10 +581,9 @@
return rc;
}
-int jfs_setxattr(struct dentry *dentry, const char *name,
- const void *value, size_t value_len, int flags)
+int __jfs_setxattr(struct inode *inode, const char *name, const void *value,
+ size_t value_len, int flags)
{
- struct inode *inode = dentry->d_inode;
struct jfs_ea_list *ealist;
struct jfs_ea *ea, *old_ea = NULL, *next_ea = NULL;
struct ea_buffer ea_buf;
@@ -700,10 +699,15 @@
return rc;
}
-ssize_t jfs_getxattr(struct dentry * dentry, const char *name,
- void *data, size_t buf_size)
+int jfs_setxattr(struct dentry *dentry, const char *name, const void *value,
+ size_t value_len, int flags)
+{
+ return __jfs_setxattr(dentry->d_inode, name, value, value_len, flags);
+}
+
+ssize_t __jfs_getxattr(struct inode *inode, const char *name, void *data,
+ size_t buf_size)
{
- struct inode *inode = dentry->d_inode;
struct jfs_ea_list *ealist;
struct jfs_ea *ea;
struct ea_buffer ea_buf;
@@ -748,6 +752,12 @@
return size;
}
+ssize_t jfs_getxattr(struct dentry *dentry, const char *name, void *data,
+ size_t buf_size)
+{
+ return __jfs_getxattr(dentry->d_inode, name, data, buf_size);
+}
+
ssize_t jfs_listxattr(struct dentry * dentry, char *data, size_t buf_size)
{
struct inode *inode = dentry->d_inode;
-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic