From 0f12c3cd0ddb9b230f21187f7e8a48964cdaf744 Mon Sep 17 00:00:00 2001 From: Rick Macklem Date: Sun, 4 May 2025 15:06:01 -0700 Subject: [PATCH] vfs_default.c: Add _PC_HAS_NAMEDATTR pathconf name Commit f61844833ee8 changes the semantics of O_NAMEDATTR so that a named attribute directory will be created if it does not already exist. As such, an open(2) without O_CREAT cannot be used to test to see if one exists. This patch adds a new pathconf name _PC_HAS_NAMEDATTR, which returns 1 if one or more named attributes are associated with the file. This is similar to Solaris's _PC_XATTR_EXISTS. A return of 0 means that there are none, so there. is no need to open(2) the named attribute directory. This allows applications to avoid creating unnecessary named attribute directories when the application only wishes to read named attributes and not create them. It is also useful for the NFSv4 server, so that it can reply with a correct named_attr attribute. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D50140 Fixes: 2ec2ba7e232d ("vfs: Add VFS/syscall support for Solaris style extended attributes") --- sys/kern/vfs_default.c | 1 + sys/sys/unistd.h | 1 + 2 files changed, 2 insertions(+) diff --git a/sys/kern/vfs_default.c b/sys/kern/vfs_default.c index c76fc9f9dc5..be49c088760 100644 --- a/sys/kern/vfs_default.c +++ b/sys/kern/vfs_default.c @@ -452,6 +452,7 @@ vop_stdpathconf(struct vop_pathconf_args *ap) case _PC_INF_PRESENT: case _PC_MAC_PRESENT: case _PC_NAMEDATTR_ENABLED: + case _PC_HAS_NAMEDATTR: *ap->a_retval = 0; return (0); default: diff --git a/sys/sys/unistd.h b/sys/sys/unistd.h index 59cef241754..f5caea2e391 100644 --- a/sys/sys/unistd.h +++ b/sys/sys/unistd.h @@ -155,6 +155,7 @@ #define _PC_ACL_NFS4 64 #define _PC_DEALLOC_PRESENT 65 #define _PC_NAMEDATTR_ENABLED 66 +#define _PC_HAS_NAMEDATTR 67 #endif /* From OpenSolaris, used by SEEK_DATA/SEEK_HOLE. */