From 6271663b4eb6a9b294c7a0ff05960af99c49c132 Mon Sep 17 00:00:00 2001 From: jpandre Date: Sat, 19 Dec 2009 09:20:59 +0000 Subject: [PATCH] Skip extended attribute related functions when not supported locally --- libntfs-3g/efs.c | 4 ++++ libntfs-3g/inode.c | 4 ++++ libntfs-3g/object_id.c | 15 +++++++++++++++ libntfs-3g/reparse.c | 12 ++++++++++++ libntfs-3g/security.c | 8 ++++++++ src/ntfs-3g.c | 29 +++++++++++++++++++++++++++-- 6 files changed, 70 insertions(+), 2 deletions(-) diff --git a/libntfs-3g/efs.c b/libntfs-3g/efs.c index 4155e85e..0af1a4df 100644 --- a/libntfs-3g/efs.c +++ b/libntfs-3g/efs.c @@ -58,6 +58,8 @@ #include "misc.h" #include "efs.h" +#ifdef HAVE_SETXATTR /* extended attributes interface required */ + static ntfschar logged_utility_stream_name[] = { const_cpu_to_le16('$'), const_cpu_to_le16('E'), @@ -340,3 +342,5 @@ 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 a45b6bc9..981fba9e 100644 --- a/libntfs-3g/inode.c +++ b/libntfs-3g/inode.c @@ -1389,6 +1389,8 @@ 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 * @@ -1545,3 +1547,5 @@ 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/object_id.c b/libntfs-3g/object_id.c index 9ee88123..522b4b2e 100644 --- a/libntfs-3g/object_id.c +++ b/libntfs-3g/object_id.c @@ -125,6 +125,7 @@ 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 @@ -170,6 +171,8 @@ 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 * @@ -195,6 +198,8 @@ 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 * a full object_id struct. @@ -243,6 +248,8 @@ static int merge_index_data(ntfs_inode *ni, return (res); } +#endif /* HAVE_SETXATTR */ + /* * Remove an object id index entry if attribute present * @@ -291,6 +298,8 @@ 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 * @@ -395,6 +404,8 @@ static int add_object_id(ntfs_inode *ni, int flags) return (res); } +#endif /* HAVE_SETXATTR */ + /* * Delete an object_id index entry * @@ -432,6 +443,8 @@ 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 * @@ -610,3 +623,5 @@ 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 a5a751b7..d959b98e 100644 --- a/libntfs-3g/reparse.c +++ b/libntfs-3g/reparse.c @@ -817,6 +817,8 @@ BOOL ntfs_possible_symlink(ntfs_inode *ni) return (possible); } +#ifdef HAVE_SETXATTR /* extended attributes interface required */ + /* * Set the index for new reparse data * @@ -854,6 +856,8 @@ 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 * @@ -919,6 +923,8 @@ 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 * @@ -983,6 +989,8 @@ static int update_reparse_data(ntfs_inode *ni, ntfs_index_context *xr, return (res); } +#endif /* HAVE_SETXATTR */ + /* * Delete a reparse index entry * @@ -1020,6 +1028,8 @@ 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 * @@ -1198,3 +1208,5 @@ int ntfs_remove_ntfs_reparse_data(ntfs_inode *ni) } return (res ? -1 : 0); } + +#endif /* HAVE_SETXATTR */ diff --git a/libntfs-3g/security.c b/libntfs-3g/security.c index c66999f7..c13c1808 100644 --- a/libntfs-3g/security.c +++ b/libntfs-3g/security.c @@ -2934,6 +2934,8 @@ BOOL ntfs_allowed_as_owner(struct SECURITY_CONTEXT *scx, ntfs_inode *ni) return (allowed); } +#ifdef HAVE_SETXATTR /* extended attributes interface required */ + #if POSIXACLS /* @@ -3112,6 +3114,8 @@ 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 * Checks user mapping has been defined before request for setting @@ -4141,6 +4145,8 @@ 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 * The attribute is returned according to cpu endianness @@ -4225,6 +4231,8 @@ int ntfs_set_ntfs_attrib(ntfs_inode *ni, return (res ? -1 : 0); } +#endif /* HAVE_SETXATTR */ + /* * Open $Secure once for all * returns zero if it succeeds diff --git a/src/ntfs-3g.c b/src/ntfs-3g.c index 184eba75..2cc5d929 100644 --- a/src/ntfs-3g.c +++ b/src/ntfs-3g.c @@ -177,7 +177,9 @@ typedef struct { BOOL no_detach; BOOL blkdev; BOOL mounted; +#ifdef HAVE_SETXATTR /* extended attributes interface required */ BOOL efs_raw; +#endif /* HAVE_SETXATTR */ struct fuse_chan *fc; BOOL inherit; unsigned int secure_flags; @@ -397,6 +399,8 @@ static int ntfs_allowed_dir_access(struct SECURITY_CONTEXT *scx, #endif +#ifdef HAVE_SETXATTR /* extended attributes interface required */ + /* * Check access to parent directory * @@ -441,6 +445,8 @@ static int ntfs_allowed_real_dir_access(struct SECURITY_CONTEXT *scx, return (allowed); } +#endif /* HAVE_SETXATTR */ + /** * ntfs_fuse_statfs - return information about mounted NTFS volume * @path: ignored (but fuse requires it) @@ -748,6 +754,7 @@ static int ntfs_fuse_getattr(const char *org_path, struct stat *stbuf) /* Regular or Interix (INTX) file. */ stbuf->st_mode = S_IFREG; stbuf->st_size = ni->data_size; +#ifdef HAVE_SETXATTR /* extended attributes interface required */ /* * return data size rounded to next 512 byte boundary for * encrypted files to include padding required for decryption @@ -755,7 +762,7 @@ static int ntfs_fuse_getattr(const char *org_path, struct stat *stbuf) */ if (ctx->efs_raw && ni->flags & FILE_ATTR_ENCRYPTED) stbuf->st_size = ((ni->data_size + 511) & ~511) + 2; - +#endif /* HAVE_SETXATTR */ /* * Temporary fix to make ActiveSync work via Samba 3.0. * See more on the ntfs-3g-devel list. @@ -784,12 +791,14 @@ static int ntfs_fuse_getattr(const char *org_path, struct stat *stbuf) if (na->data_size == 1) stbuf->st_mode = S_IFSOCK; } +#ifdef HAVE_SETXATTR /* extended attributes interface required */ /* encrypted named stream */ /* round size up to next 512 byte boundary */ if (ctx->efs_raw && stream_name_len && (na->data_flags & ATTR_IS_ENCRYPTED) && NAttrNonResident(na)) stbuf->st_size = ((na->data_size+511) & ~511)+2; +#endif /* HAVE_SETXATTR */ /* * Check whether it's Interix symbolic link, block or * character device. @@ -1133,11 +1142,13 @@ static int ntfs_fuse_open(const char *org_path, /* mark a future need to compress the last chunk */ if (na->data_flags & ATTR_COMPRESSION_MASK) fi->fh |= CLOSE_COMPRESSED; +#ifdef HAVE_SETXATTR /* extended attributes interface required */ /* mark a future need to fixup encrypted inode */ if (ctx->efs_raw && !(na->data_flags & ATTR_IS_ENCRYPTED) && (ni->flags & FILE_ATTR_ENCRYPTED)) fi->fh |= CLOSE_ENCRYPTED; +#endif /* HAVE_SETXATTR */ } ntfs_attr_close(na); } else @@ -1179,12 +1190,14 @@ static int ntfs_fuse_read(const char *org_path, char *buf, size_t size, res = -errno; goto exit; } - /* limit reads at next 512 byte boundary for encrypted attributes */ max_read = na->data_size; +#ifdef HAVE_SETXATTR /* extended attributes interface required */ + /* limit reads at next 512 byte boundary for encrypted attributes */ if (ctx->efs_raw && (na->data_flags & ATTR_IS_ENCRYPTED) && NAttrNonResident(na)) { max_read = ((na->data_size+511) & ~511) + 2; } +#endif /* HAVE_SETXATTR */ if (offset + (off_t)size > max_read) { if (max_read < offset) goto ok; @@ -1301,8 +1314,10 @@ static int ntfs_fuse_release(const char *org_path, res = 0; if (fi->fh & CLOSE_COMPRESSED) res = ntfs_attr_pclose(na); +#ifdef HAVE_SETXATTR /* extended attributes interface required */ if (fi->fh & CLOSE_ENCRYPTED) res = ntfs_efs_fixup_attribute(NULL, na); +#endif /* HAVE_SETXATTR */ exit: if (na) ntfs_attr_close(na); @@ -1666,11 +1681,13 @@ static int ntfs_fuse_create(const char *org_path, mode_t typemode, dev_t dev, if (fi && (ni->flags & FILE_ATTR_COMPRESSED)) { fi->fh |= CLOSE_COMPRESSED; } +#ifdef HAVE_SETXATTR /* extended attributes interface required */ /* mark a future need to fixup encrypted inode */ if (fi && ctx->efs_raw && (ni->flags & FILE_ATTR_ENCRYPTED)) fi->fh |= CLOSE_ENCRYPTED; +#endif /* HAVE_SETXATTR */ NInoSetDirty(ni); /* * closing ni requires access to dir_ni to @@ -1732,10 +1749,12 @@ static int ntfs_fuse_create_stream(const char *path, /* mark a future need to compress the last block */ if (ni->flags & FILE_ATTR_COMPRESSED) fi->fh |= CLOSE_COMPRESSED; +#ifdef HAVE_SETXATTR /* extended attributes interface required */ /* mark a future need to fixup encrypted inode */ if (ctx->efs_raw && (ni->flags & FILE_ATTR_ENCRYPTED)) fi->fh |= CLOSE_ENCRYPTED; +#endif /* HAVE_SETXATTR */ } if (ntfs_inode_close(ni)) @@ -3538,7 +3557,9 @@ static char *parse_mount_options(const char *orig_opts) int want_permissions = 0; ctx->secure_flags = 0; +#ifdef HAVE_SETXATTR /* extended attributes interface required */ ctx->efs_raw = FALSE; +#endif /* HAVE_SETXATTR */ options = strdup(orig_opts ? orig_opts : ""); if (!options) { ntfs_log_perror("%s: strdup failed", EXEC_NAME); @@ -3721,10 +3742,12 @@ static char *parse_mount_options(const char *orig_opts) "'usermapping' option.\n"); goto err_exit; } +#ifdef HAVE_SETXATTR /* extended attributes interface required */ } else if (!strcmp(opt, "efs_raw")) { if (bogus_option_value(val, "efs_raw")) goto err_exit; ctx->efs_raw = TRUE; +#endif /* HAVE_SETXATTR */ } else { /* Probably FUSE option. */ if (strappend(&ret, opt)) goto err_exit; @@ -4202,7 +4225,9 @@ int main(int argc, char *argv[]) ctx->security.vol = ctx->vol; ctx->vol->secure_flags = ctx->secure_flags; +#ifdef HAVE_SETXATTR /* extended attributes interface required */ ctx->vol->efs_raw = ctx->efs_raw; +#endif /* HAVE_SETXATTR */ /* JPA open $Secure, (whatever NTFS version !) */ /* to initialize security data */ if (ntfs_open_secure(ctx->vol) && (ctx->vol->major_ver >= 3))