Add posix acl (Access Control Lists) support for squashfs, which is
marked as a todo item in squashfs' documentation. This patch implements
the squashfs_get_acl function to read file's acl information from its
xattr lists.
Signed-off-by: Geliang Tang
---
Documentation/filesystems/squashfs.txt | 2 -
fs/squashfs/Kconfig| 11 ++
fs/squashfs/Makefile | 1 +
fs/squashfs/acl.c | 69 ++
fs/squashfs/acl.h | 27 +
fs/squashfs/inode.c| 4 +-
fs/squashfs/namei.c| 6 ++-
fs/squashfs/squashfs_fs.h | 12 +++---
fs/squashfs/super.c| 3 ++
fs/squashfs/symlink.c | 6 ++-
fs/squashfs/xattr.c| 13 ++-
fs/squashfs/xattr.h| 8
12 files changed, 149 insertions(+), 13 deletions(-)
create mode 100644 fs/squashfs/acl.c
create mode 100644 fs/squashfs/acl.h
diff --git a/Documentation/filesystems/squashfs.txt
b/Documentation/filesystems/squashfs.txt
index e5274f84dc56..539fad6b4db0 100644
--- a/Documentation/filesystems/squashfs.txt
+++ b/Documentation/filesystems/squashfs.txt
@@ -235,8 +235,6 @@ list using a second xattr id lookup table.
4.1 Todo list
-
-Implement ACL support.
-
4.2 Squashfs internal cache
---
diff --git a/fs/squashfs/Kconfig b/fs/squashfs/Kconfig
index 1adb3346b9d6..f9587bcf9dd9 100644
--- a/fs/squashfs/Kconfig
+++ b/fs/squashfs/Kconfig
@@ -107,6 +107,17 @@ config SQUASHFS_XATTR
If unsure, say N.
+config SQUASHFS_POSIX_ACL
+ bool "Squashfs POSIX ACL support"
+ depends on SQUASHFS_XATTR
+ select FS_POSIX_ACL
+ help
+ Saying Y here includes support for Access Control Lists (acls).
+ Acls are used to define more fine-grained discretionary access
+ rights for files and directories (see the acl(5) manual page).
+
+ If unsure, say N.
+
config SQUASHFS_ZLIB
bool "Include support for ZLIB compressed file systems"
depends on SQUASHFS
diff --git a/fs/squashfs/Makefile b/fs/squashfs/Makefile
index 7bd9b8b856d0..73bc1c8a8df6 100644
--- a/fs/squashfs/Makefile
+++ b/fs/squashfs/Makefile
@@ -12,6 +12,7 @@ squashfs-$(CONFIG_SQUASHFS_DECOMP_SINGLE) +=
decompressor_single.o
squashfs-$(CONFIG_SQUASHFS_DECOMP_MULTI) += decompressor_multi.o
squashfs-$(CONFIG_SQUASHFS_DECOMP_MULTI_PERCPU) += decompressor_multi_percpu.o
squashfs-$(CONFIG_SQUASHFS_XATTR) += xattr.o xattr_id.o
+squashfs-$(CONFIG_SQUASHFS_POSIX_ACL) += acl.o
squashfs-$(CONFIG_SQUASHFS_LZ4) += lz4_wrapper.o
squashfs-$(CONFIG_SQUASHFS_LZO) += lzo_wrapper.o
squashfs-$(CONFIG_SQUASHFS_XZ) += xz_wrapper.o
diff --git a/fs/squashfs/acl.c b/fs/squashfs/acl.c
new file mode 100644
index ..1c9eb2d13c2b
--- /dev/null
+++ b/fs/squashfs/acl.c
@@ -0,0 +1,69 @@
+/*
+ * Squashfs - a compressed read only filesystem for Linux
+ *
+ * Copyright (c) 2018
+ * Phillip Lougher
+ *
+ * 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,
+ * 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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * acl.c
+ */
+
+#include
+#include
+#include
+#include "squashfs_fs.h"
+#include "xattr.h"
+#include "acl.h"
+
+struct posix_acl *squashfs_get_acl(struct inode *inode, int type)
+{
+ int name_index;
+ char *name;
+ struct posix_acl *acl = NULL;
+ char *value = NULL;
+ int retval;
+
+ switch (type) {
+ case ACL_TYPE_ACCESS:
+ name_index = SQUASHFS_XATTR_POSIX_ACL_ACCESS;
+ name = XATTR_POSIX_ACL_ACCESS;
+ break;
+ case ACL_TYPE_DEFAULT:
+ name_index = SQUASHFS_XATTR_POSIX_ACL_DEFAULT;
+ name = XATTR_POSIX_ACL_DEFAULT;
+ break;
+ default:
+ BUG();
+ }
+
+ retval = squashfs_xattr_get(inode, name_index, name, NULL, 0);
+ if (retval > 0) {
+ value = kmalloc(retval, GFP_KERNEL);
+ if (!value)
+ return ERR_PTR(-ENOMEM);
+ retval = squashfs_xattr_get(inode, name_index, name, value,
retval);
+ }
+ if (retval > 0)
+ acl = posix_acl_from_xattr(&init_user_ns, value, retval);
+ else if (retval == -ENODATA || retval == -ENOSYS)
+