Add posix acl (Access Control Lists) support for squashfs, which is
marked as a todo item in squashfs documentation. This patch implements
a squashfs_get_acl function to read the 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 | 31
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| 31 +++-
fs/squashfs/xattr.h| 8 +++
12 files changed, 171 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 ..0db28f5eacc6
--- /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 ret;
+
+ 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();
+ }
+
+ ret = squashfs_xattr_get(inode, name_index, name, NULL, 0);
+ if (ret > 0) {
+ value = kmalloc(ret, GFP_KERNEL);
+ if (!value)
+ return ERR_PTR(-ENOMEM);
+ ret = squashfs_xattr_get(inode, name_index, name, value, ret);
+ }
+ if (ret > 0)
+ acl = posix_acl_from_xattr(&init_user_ns, value, ret);
+ else if (ret == -ENODATA || ret == -ENOSYS)
+ acl = NULL;
+ else
+