A number of functions in libntfs-3g are generally useful, but are tied to extended attributes support and are not included when the library is built on platforms without extended attributes support.
This proposal updates libntfs-3g to always include these functions. The only tricky part is dealing with the XATTR_CREATE and XATTR_REPLACE flags. These flags are defined in <sys/xattr.h>, so they must be redefined on platforms without extended attributes support. Signed-off-by: Eric Biggers <ebigge...@gmail.com> --- include/ntfs-3g/xattrs.h | 27 ++++++++++++++++++++++++--- libntfs-3g/dir.c | 9 +-------- libntfs-3g/ea.c | 9 +-------- libntfs-3g/efs.c | 9 +-------- libntfs-3g/inode.c | 8 +------- libntfs-3g/ioctl.c | 5 ----- libntfs-3g/object_id.c | 16 +--------------- libntfs-3g/reparse.c | 12 +----------- libntfs-3g/security.c | 8 +------- libntfs-3g/xattrs.c | 4 ---- 10 files changed, 31 insertions(+), 76 deletions(-) diff --git a/include/ntfs-3g/xattrs.h b/include/ntfs-3g/xattrs.h index d4e43a3..c5faeac 100644 --- a/include/ntfs-3g/xattrs.h +++ b/include/ntfs-3g/xattrs.h @@ -19,8 +19,27 @@ * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#ifndef _NTFS_XATTR_H_ -#define _NTFS_XATTR_H_ +#ifndef _NTFS_XATTRS_H_ +#define _NTFS_XATTRS_H_ + +/* + * Flags that modify setxattr() semantics. These flags are also used by a + * number of libntfs-3g functions, such as ntfs_set_ntfs_acl(), which were + * originally tied to extended attributes support but now can be used by + * applications even if the platform does not support extended attributes. + * + * Careful: applications including this header should define HAVE_SETXATTR or + * HAVE_SYS_XATTR_H if the platform supports extended attributes. Otherwise the + * defined flags values may be incorrect (they will be correct for Linux but not + * necessarily for other platforms). + */ +#if defined(HAVE_SETXATTR) || defined(HAVE_SYS_XATTR_H) +#include <sys/xattr.h> +#else +#include "compat.h" /* may be needed for ENODATA definition */ +#define XATTR_CREATE 1 +#define XATTR_REPLACE 2 +#endif /* * Identification of data mapped to the system name space @@ -61,6 +80,8 @@ void ntfs_xattr_free_mapping(struct XATTRMAPPING*); enum SYSTEMXATTRS ntfs_xattr_system_type(const char *name, ntfs_volume *vol); +struct SECURITY_CONTEXT; + int ntfs_xattr_system_getxattr(struct SECURITY_CONTEXT *scx, enum SYSTEMXATTRS attr, ntfs_inode *ni, ntfs_inode *dir_ni, @@ -73,4 +94,4 @@ int ntfs_xattr_system_removexattr(struct SECURITY_CONTEXT *scx, enum SYSTEMXATTRS attr, ntfs_inode *ni, ntfs_inode *dir_ni); -#endif /* _NTFS_XATTR_H_ */ +#endif /* _NTFS_XATTRS_H_ */ diff --git a/libntfs-3g/dir.c b/libntfs-3g/dir.c index 6e97ee7..f818147 100644 --- a/libntfs-3g/dir.c +++ b/libntfs-3g/dir.c @@ -67,10 +67,7 @@ #include "security.h" #include "reparse.h" #include "object_id.h" - -#ifdef HAVE_SETXATTR -#include <sys/xattr.h> -#endif +#include "xattrs.h" /* * The little endian Unicode strings "$I30", "$SII", "$SDH", "$O" @@ -2283,8 +2280,6 @@ ntfs_inode *ntfs_dir_parent_inode(ntfs_inode *ni) return (dir_ni); } -#ifdef HAVE_SETXATTR - #define MAX_DOS_NAME_LENGTH 12 /* @@ -2793,5 +2788,3 @@ int ntfs_remove_ntfs_dos_name(ntfs_inode *ni, ntfs_inode *dir_ni) } return (res); } - -#endif diff --git a/libntfs-3g/ea.c b/libntfs-3g/ea.c index d07e111..0a7b20e 100644 --- a/libntfs-3g/ea.c +++ b/libntfs-3g/ea.c @@ -25,8 +25,6 @@ #include "config.h" #endif -#ifdef HAVE_SETXATTR /* extended attributes support required */ - #ifdef HAVE_STDIO_H #include <stdio.h> #endif @@ -46,10 +44,6 @@ #include <errno.h> #endif -#ifdef HAVE_SETXATTR -#include <sys/xattr.h> -#endif - #include "types.h" #include "param.h" #include "layout.h" @@ -59,6 +53,7 @@ #include "ea.h" #include "misc.h" #include "logging.h" +#include "xattrs.h" /* * Create a needed attribute (EA or EA_INFORMATION) @@ -398,5 +393,3 @@ int ntfs_remove_ntfs_ea(ntfs_inode *ni) } return (res ? -1 : 0); } - -#endif /* HAVE_SETXATTR */ diff --git a/libntfs-3g/efs.c b/libntfs-3g/efs.c index 443426c..7b87cfc 100644 --- a/libntfs-3g/efs.c +++ b/libntfs-3g/efs.c @@ -39,10 +39,6 @@ #include <sys/stat.h> #endif -#ifdef HAVE_SETXATTR -#include <sys/xattr.h> -#endif - #ifdef HAVE_SYS_SYSMACROS_H #include <sys/sysmacros.h> #endif @@ -57,8 +53,7 @@ #include "logging.h" #include "misc.h" #include "efs.h" - -#ifdef HAVE_SETXATTR /* extended attributes interface required */ +#include "xattrs.h" static ntfschar logged_utility_stream_name[] = { const_cpu_to_le16('$'), @@ -433,5 +428,3 @@ err_out: ntfs_attr_put_search_ctx(ctx); return (-1); } - -#endif /* HAVE_SETXATTR */ diff --git a/libntfs-3g/inode.c b/libntfs-3g/inode.c index a43714c..4c364b9 100644 --- a/libntfs-3g/inode.c +++ b/libntfs-3g/inode.c @@ -36,9 +36,6 @@ #ifdef HAVE_ERRNO_H #include <errno.h> #endif -#ifdef HAVE_SETXATTR -#include <sys/xattr.h> -#endif #include "param.h" #include "compat.h" @@ -57,6 +54,7 @@ #include "ntfstime.h" #include "logging.h" #include "misc.h" +#include "xattrs.h" ntfs_inode *ntfs_inode_base(ntfs_inode *ni) { @@ -1446,8 +1444,6 @@ int ntfs_inode_badclus_bad(u64 mft_no, ATTR_RECORD *attr) return ret; } -#ifdef HAVE_SETXATTR /* extended attributes interface required */ - /* * Get high precision NTFS times * @@ -1604,5 +1600,3 @@ int ntfs_inode_set_times(ntfs_inode *ni, const char *value, size_t size, errno = EEXIST; return (ret); } - -#endif /* HAVE_SETXATTR */ diff --git a/libntfs-3g/ioctl.c b/libntfs-3g/ioctl.c index 28532b2..2eef5a5 100644 --- a/libntfs-3g/ioctl.c +++ b/libntfs-3g/ioctl.c @@ -49,11 +49,6 @@ #include <limits.h> #endif #include <syslog.h> - -#ifdef HAVE_SETXATTR -#include <sys/xattr.h> -#endif - #ifdef HAVE_SYS_TYPES_H #include <sys/types.h> #endif diff --git a/libntfs-3g/object_id.c b/libntfs-3g/object_id.c index 299357e..bd72d02 100644 --- a/libntfs-3g/object_id.c +++ b/libntfs-3g/object_id.c @@ -37,11 +37,6 @@ #ifdef HAVE_SYS_STAT_H #include <sys/stat.h> #endif - -#ifdef HAVE_SETXATTR -#include <sys/xattr.h> -#endif - #ifdef HAVE_SYS_SYSMACROS_H #include <sys/sysmacros.h> #endif @@ -59,6 +54,7 @@ #include "object_id.h" #include "logging.h" #include "misc.h" +#include "xattrs.h" /* * Endianness considerations @@ -130,7 +126,6 @@ struct OBJECT_ID_INDEX { /* index entry in $Extend/$ObjId */ static ntfschar objid_index_name[] = { const_cpu_to_le16('$'), const_cpu_to_le16('O') }; -#ifdef HAVE_SETXATTR /* extended attributes interface required */ /* * Set the index for a new object id @@ -176,8 +171,6 @@ static int set_object_id_index(ntfs_inode *ni, ntfs_index_context *xo, return (ntfs_ie_add(xo,(INDEX_ENTRY*)&indx)); } -#endif /* HAVE_SETXATTR */ - /* * Open the $Extend/$ObjId file and its index * @@ -213,7 +206,6 @@ static ntfs_index_context *open_object_id_index(ntfs_volume *vol) return (xo); } -#ifdef HAVE_SETXATTR /* extended attributes interface required */ /* * Merge object_id data stored in the index into @@ -263,7 +255,6 @@ static int merge_index_data(ntfs_inode *ni, return (res); } -#endif /* HAVE_SETXATTR */ /* * Remove an object id index entry if attribute present @@ -311,7 +302,6 @@ static int remove_object_id_index(ntfs_attr *na, ntfs_index_context *xo, return (ret); } -#ifdef HAVE_SETXATTR /* extended attributes interface required */ /* * Update the object id and index @@ -417,7 +407,6 @@ static int add_object_id(ntfs_inode *ni, int flags) return (res); } -#endif /* HAVE_SETXATTR */ /* * Delete an object_id index entry @@ -456,7 +445,6 @@ int ntfs_delete_object_id_index(ntfs_inode *ni) return (res); } -#ifdef HAVE_SETXATTR /* extended attributes interface required */ /* * Get the ntfs object id into an extended attribute @@ -636,5 +624,3 @@ int ntfs_remove_ntfs_object_id(ntfs_inode *ni) } return (res ? -1 : 0); } - -#endif /* HAVE_SETXATTR */ diff --git a/libntfs-3g/reparse.c b/libntfs-3g/reparse.c index 5e2f403..354f7bb 100644 --- a/libntfs-3g/reparse.c +++ b/libntfs-3g/reparse.c @@ -37,11 +37,6 @@ #ifdef HAVE_SYS_STAT_H #include <sys/stat.h> #endif - -#ifdef HAVE_SETXATTR -#include <sys/xattr.h> -#endif - #ifdef HAVE_SYS_SYSMACROS_H #include <sys/sysmacros.h> #endif @@ -60,6 +55,7 @@ #include "logging.h" #include "misc.h" #include "reparse.h" +#include "xattrs.h" struct MOUNT_POINT_REPARSE_DATA { /* reparse data for junctions */ le16 subst_name_offset; @@ -849,7 +845,6 @@ BOOL ntfs_possible_symlink(ntfs_inode *ni) return (possible); } -#ifdef HAVE_SETXATTR /* extended attributes interface required */ /* * Set the index for new reparse data @@ -888,7 +883,6 @@ static int set_reparse_index(ntfs_inode *ni, ntfs_index_context *xr, return (ntfs_ie_add(xr,(INDEX_ENTRY*)&indx)); } -#endif /* HAVE_SETXATTR */ /* * Remove a reparse data index entry if attribute present @@ -965,7 +959,6 @@ static ntfs_index_context *open_reparse_index(ntfs_volume *vol) return (xr); } -#ifdef HAVE_SETXATTR /* extended attributes interface required */ /* * Update the reparse data and index @@ -1031,7 +1024,6 @@ static int update_reparse_data(ntfs_inode *ni, ntfs_index_context *xr, return (res); } -#endif /* HAVE_SETXATTR */ /* * Delete a reparse index entry @@ -1070,7 +1062,6 @@ int ntfs_delete_reparse_index(ntfs_inode *ni) return (res); } -#ifdef HAVE_SETXATTR /* extended attributes interface required */ /* * Get the ntfs reparse data into an extended attribute @@ -1255,7 +1246,6 @@ int ntfs_remove_ntfs_reparse_data(ntfs_inode *ni) return (res ? -1 : 0); } -#endif /* HAVE_SETXATTR */ /* * Get the reparse data into a buffer diff --git a/libntfs-3g/security.c b/libntfs-3g/security.c index e00bcf9..ef036af 100644 --- a/libntfs-3g/security.c +++ b/libntfs-3g/security.c @@ -41,9 +41,6 @@ #ifdef HAVE_FCNTL_H #include <fcntl.h> #endif -#ifdef HAVE_SETXATTR -#include <sys/xattr.h> -#endif #ifdef HAVE_SYS_STAT_H #include <sys/stat.h> #endif @@ -64,6 +61,7 @@ #include "acls.h" #include "cache.h" #include "misc.h" +#include "xattrs.h" /* * JPA NTFS constants or structs @@ -3063,7 +3061,6 @@ BOOL ntfs_allowed_as_owner(struct SECURITY_CONTEXT *scx, ntfs_inode *ni) return (allowed); } -#ifdef HAVE_SETXATTR /* extended attributes interface required */ #if POSIXACLS @@ -3242,7 +3239,6 @@ int ntfs_set_ntfs_acl(struct SECURITY_CONTEXT *scx, ntfs_inode *ni, return (res ? -1 : 0); } -#endif /* HAVE_SETXATTR */ /* * Set new permissions to a file @@ -4383,7 +4379,6 @@ int ntfs_build_mapping(struct SECURITY_CONTEXT *scx, const char *usermap_path, return (!scx->mapping[MAPUSERS] || link_group_members(scx)); } -#ifdef HAVE_SETXATTR /* extended attributes interface required */ /* * Get the ntfs attribute into an extended attribute @@ -4469,7 +4464,6 @@ int ntfs_set_ntfs_attrib(ntfs_inode *ni, return (res ? -1 : 0); } -#endif /* HAVE_SETXATTR */ /* * Open $Secure once for all diff --git a/libntfs-3g/xattrs.c b/libntfs-3g/xattrs.c index 6da8146..f17e4ca 100644 --- a/libntfs-3g/xattrs.c +++ b/libntfs-3g/xattrs.c @@ -23,8 +23,6 @@ #include "config.h" #endif -#ifdef HAVE_SETXATTR /* extended attributes support required */ - #ifdef HAVE_STDIO_H #include <stdio.h> #endif @@ -798,5 +796,3 @@ int ntfs_xattr_system_removexattr(struct SECURITY_CONTEXT *scx, } return (res); } - -#endif /* HAVE_SETXATTR */ -- 2.9.0 ------------------------------------------------------------------------------ What NetFlow Analyzer can do for you? Monitors network bandwidth and traffic patterns at an interface-level. Reveals which users, apps, and protocols are consuming the most bandwidth. Provides multi-vendor support for NetFlow, J-Flow, sFlow and other flows. Make informed decisions using capacity planning reports.http://sdm.link/zohodev2dev _______________________________________________ ntfs-3g-devel mailing list ntfs-3g-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ntfs-3g-devel