[PATCH v1 02/17] Add a new function to acquire the POSIX draft ACLs

rick.macklem
2025-12-31T02:22:08Z

This patch adds a function called nfsd4_get_posix_acl(),
which acquires the POSIX draft ACLs for a file. It
acquires a POSIX draft access ACL based on the file's
mode, if no POSIX draft ACL exists for the file.

Signed-off-by: Rick Macklem <rmacklem@uoguelph.ca>
---
fs/nfsd/acl.h | 2 ++
fs/nfsd/nfs4acl.c | 33 +++++++++++++++++++++++++++++++++
2 files changed, 35 insertions(+)

diff --git a/fs/nfsd/acl.h b/fs/nfsd/acl.h
index 4b7324458a94..213774cebeeb 100644
--- a/fs/nfsd/acl.h
+++ b/fs/nfsd/acl.h
@@ -47,6 +47,8 @@ __be32 nfs4_acl_write_who(struct xdr_stream *xdr, int who);

int nfsd4_get_nfs4_acl(struct svc_rqst *rqstp, struct dentry *dentry,
struct nfs4_acl **acl);
+int nfsd4_get_posix_acl(struct svc_rqst *rqstp, struct dentry *dentry,
+ struct posix_acl **pacl_ret, struct posix_acl **dpacl_ret);
__be32 nfsd4_acl_to_attr(enum nfs_ftype4 type, struct nfs4_acl *acl,
struct nfsd_attrs *attr);

diff --git a/fs/nfsd/nfs4acl.c b/fs/nfsd/nfs4acl.c
index 936ea1ad9586..0a184b345f8c 100644
--- a/fs/nfsd/nfs4acl.c
+++ b/fs/nfsd/nfs4acl.c
@@ -176,6 +176,39 @@ nfsd4_get_nfs4_acl(struct svc_rqst *rqstp, struct dentry *dentry,
return error;
}

+int
+nfsd4_get_posix_acl(struct svc_rqst *rqstp, struct dentry *dentry,
+ struct posix_acl **pacl_ret, struct posix_acl **dpacl_ret)
+{
+ struct inode *inode = d_inode(dentry);
+ int error = 0;
+ struct posix_acl *pacl = NULL, *dpacl = NULL;
+
+ *pacl_ret = NULL;
+ *dpacl_ret = NULL;
+ pacl = get_inode_acl(inode, ACL_TYPE_ACCESS);
+ if (!pacl)
+ pacl = posix_acl_from_mode(inode->i_mode, GFP_KERNEL);
+
+ if (IS_ERR(pacl))
+ return PTR_ERR(pacl);
+
+ *pacl_ret = pacl;
+
+ if (S_ISDIR(inode->i_mode)) {
+ dpacl = get_inode_acl(inode, ACL_TYPE_DEFAULT);
+ if (IS_ERR(dpacl)) {
+ error = PTR_ERR(dpacl);
+ goto out;
+ }
+
+ *dpacl_ret = dpacl;
+ }
+
+out:
+ return error;
+}
+
struct posix_acl_summary {
unsigned short owner;
unsigned short users;
--
2.49.0