fs/nfs_common/nfsacl.c
Source file repositories/reference/linux-study-clean/fs/nfs_common/nfsacl.c
File Facts
- System
- Linux kernel
- Corpus path
fs/nfs_common/nfsacl.c- Extension
.c- Size
- 11529 bytes
- Lines
- 424
- Domain
- Core OS
- Bucket
- VFS And Filesystem Core
- Inferred role
- Core OS: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/fs.hlinux/gfp.hlinux/sunrpc/xdr.hlinux/nfsacl.hlinux/nfs3.hlinux/sort.h
Detected Declarations
struct nfsacl_encode_descstruct nfsacl_simple_aclstruct nfsacl_decode_descfunction xdr_nfsace_encodefunction nfsacl_encodefunction nfs_stream_encode_aclfunction xdr_nfsace_decodefunction cmp_acl_entryfunction posix_acl_from_nfsaclfunction nfsacl_decodefunction nfs_stream_decode_aclexport nfsacl_encodeexport nfs_stream_encode_aclexport nfsacl_decodeexport nfs_stream_decode_acl
Annotated Snippet
struct nfsacl_encode_desc {
struct xdr_array2_desc desc;
unsigned int count;
struct posix_acl *acl;
int typeflag;
kuid_t uid;
kgid_t gid;
};
struct nfsacl_simple_acl {
struct posix_acl_hdr acl;
struct posix_acl_entry ace[4];
};
static int
xdr_nfsace_encode(struct xdr_array2_desc *desc, void *elem)
{
struct nfsacl_encode_desc *nfsacl_desc =
(struct nfsacl_encode_desc *) desc;
__be32 *p = elem;
struct posix_acl_entry *entry =
&nfsacl_desc->acl->a_entries[nfsacl_desc->count++];
*p++ = htonl(entry->e_tag | nfsacl_desc->typeflag);
switch(entry->e_tag) {
case ACL_USER_OBJ:
*p++ = htonl(from_kuid(&init_user_ns, nfsacl_desc->uid));
break;
case ACL_GROUP_OBJ:
*p++ = htonl(from_kgid(&init_user_ns, nfsacl_desc->gid));
break;
case ACL_USER:
*p++ = htonl(from_kuid(&init_user_ns, entry->e_uid));
break;
case ACL_GROUP:
*p++ = htonl(from_kgid(&init_user_ns, entry->e_gid));
break;
default: /* Solaris depends on that! */
*p++ = 0;
break;
}
*p++ = htonl(entry->e_perm & S_IRWXO);
return 0;
}
/**
* nfsacl_encode - Encode an NFSv3 ACL
*
* @buf: destination xdr_buf to contain XDR encoded ACL
* @base: byte offset in xdr_buf where XDR'd ACL begins
* @inode: inode of file whose ACL this is
* @acl: posix_acl to encode
* @encode_entries: whether to encode ACEs as well
* @typeflag: ACL type: NFS_ACL_DEFAULT or zero
*
* Returns size of encoded ACL in bytes or a negative errno value.
*/
int nfsacl_encode(struct xdr_buf *buf, unsigned int base, struct inode *inode,
struct posix_acl *acl, int encode_entries, int typeflag)
{
int entries = (acl && acl->a_count) ? max_t(int, acl->a_count, 4) : 0;
struct nfsacl_encode_desc nfsacl_desc = {
.desc = {
.elem_size = 12,
.array_len = encode_entries ? entries : 0,
.xcode = xdr_nfsace_encode,
},
.acl = acl,
.typeflag = typeflag,
.uid = inode->i_uid,
.gid = inode->i_gid,
};
struct nfsacl_simple_acl aclbuf;
int err;
if (entries > NFS_ACL_MAX_ENTRIES ||
xdr_encode_word(buf, base, entries))
return -EINVAL;
if (encode_entries && acl && acl->a_count == 3) {
struct posix_acl *acl2 =
container_of(&aclbuf.acl, struct posix_acl, hdr);
/* Avoid the use of posix_acl_alloc(). nfsacl_encode() is
* invoked in contexts where a memory allocation failure is
* fatal. Fortunately this fake ACL is small enough to
* construct on the stack. */
posix_acl_init(acl2, 4);
/* Insert entries in canonical order: other orders seem
Annotation
- Immediate include surface: `linux/module.h`, `linux/fs.h`, `linux/gfp.h`, `linux/sunrpc/xdr.h`, `linux/nfsacl.h`, `linux/nfs3.h`, `linux/sort.h`.
- Detected declarations: `struct nfsacl_encode_desc`, `struct nfsacl_simple_acl`, `struct nfsacl_decode_desc`, `function xdr_nfsace_encode`, `function nfsacl_encode`, `function nfs_stream_encode_acl`, `function xdr_nfsace_decode`, `function cmp_acl_entry`, `function posix_acl_from_nfsacl`, `function nfsacl_decode`.
- Atlas domain: Core OS / VFS And Filesystem Core.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.