1 #ifndef _WIMLIB_XATTR_H
2 #define _WIMLIB_XATTR_H
6 #include "wimlib/endianness.h"
7 #include "wimlib/tagged_items.h"
8 #include "wimlib/util.h"
10 #undef HAVE_XATTR_SUPPORT
11 #if defined(HAVE_SYS_XATTR_H) && \
12 defined(HAVE_LLISTXATTR) && defined(HAVE_LGETXATTR) && \
13 defined(HAVE_FSETXATTR) && defined(HAVE_LSETXATTR)
14 # define HAVE_XATTR_SUPPORT 1
18 * On-disk format of an entry in an extended attributes tagged item (wimlib
19 * extension). An xattr item consists of a series of variable-length xattr
20 * name/value pairs, each of which begins with this header.
22 * Currently this is only used for Linux-style xattrs, but in the future we may
23 * use this for Windows-style xattrs too.
25 struct wimlib_xattr_entry {
27 /* length of xattr name in bytes */
30 /* reserved, must be 0 */
33 /* length of xattr value in bytes */
36 /* followed by the xattr name with no terminating null */
39 /* followed by the xattr value with no terminating null */
42 /* then zero-padded to a 4-byte boundary */
43 } _aligned_attribute(4);
46 xattr_entry_size(const struct wimlib_xattr_entry *entry)
48 STATIC_ASSERT(sizeof(*entry) == 8);
50 return ALIGN(sizeof(*entry) + le16_to_cpu(entry->name_len) +
51 le32_to_cpu(entry->value_len), 4);
54 static inline struct wimlib_xattr_entry *
55 xattr_entry_next(const struct wimlib_xattr_entry *entry)
57 return (void *)entry + xattr_entry_size(entry);
60 /* Currently we use the Linux limits when validating xattr names and values */
61 #define XATTR_NAME_MAX 255
62 #define XATTR_SIZE_MAX 65536
65 valid_xattr_entry(const struct wimlib_xattr_entry *entry, size_t avail)
67 if (avail < sizeof(*entry))
70 if (entry->name_len == 0 ||
71 le16_to_cpu(entry->name_len) > XATTR_NAME_MAX)
74 if (entry->reserved != 0)
77 if (le32_to_cpu(entry->value_len) > XATTR_SIZE_MAX)
80 if (avail < xattr_entry_size(entry))
83 if (memchr(entry->name, '\0', le16_to_cpu(entry->name_len)))
89 /* Is the xattr of the specified name security-related? */
91 is_security_xattr(const char *name)
93 #define XATTR_SECURITY_PREFIX "security."
94 #define XATTR_SYSTEM_PREFIX "system."
95 #define XATTR_POSIX_ACL_ACCESS "posix_acl_access"
96 #define XATTR_NAME_POSIX_ACL_ACCESS XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_ACCESS
97 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
98 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
100 return !strncmp(name, XATTR_SECURITY_PREFIX,
101 sizeof(XATTR_SECURITY_PREFIX) - 1) ||
102 !strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) ||
103 !strcmp(name, XATTR_NAME_POSIX_ACL_DEFAULT);
106 static inline const void *
107 inode_get_linux_xattrs(const struct wim_inode *inode, u32 *len_ret)
109 return inode_get_tagged_item(inode, TAG_WIMLIB_LINUX_XATTRS, 0,
114 inode_has_linux_xattrs(const struct wim_inode *inode)
116 return inode_get_linux_xattrs(inode, NULL) != NULL;
120 inode_set_linux_xattrs(struct wim_inode *inode, const void *entries, u32 len)
122 return inode_set_tagged_item(inode, TAG_WIMLIB_LINUX_XATTRS,
126 #endif /* _WIMLIB_XATTR_H */