diff --git a/include/ntfs-3g/attrib.h b/include/ntfs-3g/attrib.h index a35d978a..9e4dd31b 100644 --- a/include/ntfs-3g/attrib.h +++ b/include/ntfs-3g/attrib.h @@ -330,7 +330,7 @@ extern int ntfs_attr_truncate(ntfs_attr *na, const s64 newsize); * * FIXME: Describe possible errnos. */ -s64 ntfs_get_attribute_value_length(const ATTR_RECORD *a); +extern s64 ntfs_get_attribute_value_length(const ATTR_RECORD *a); /** * get_attribute_value - return the attribute value of an attribute @@ -346,14 +346,15 @@ s64 ntfs_get_attribute_value_length(const ATTR_RECORD *a); * then nothing was read due to a zero-length attribute value, otherwise * errno describes the error. */ -s64 ntfs_get_attribute_value(const ntfs_volume *vol, const ATTR_RECORD *a, - u8 *b); +extern s64 ntfs_get_attribute_value(const ntfs_volume *vol, + const ATTR_RECORD *a, u8 *b); -void ntfs_attr_name_free(char **name); -char *ntfs_attr_name_get(const ntfschar *uname, const int uname_len); - -int ntfs_attr_exist(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name, - u32 name_len); +extern void ntfs_attr_name_free(char **name); +extern char *ntfs_attr_name_get(const ntfschar *uname, const int uname_len); +extern int ntfs_attr_exist(ntfs_inode *ni, const ATTR_TYPES type, + ntfschar *name, u32 name_len); +extern int ntfs_attr_remove(ntfs_inode *ni, const ATTR_TYPES type, + ntfschar *name, u32 name_len); #endif /* defined _NTFS_ATTRIB_H */ diff --git a/libntfs-3g/attrib.c b/libntfs-3g/attrib.c index 6325f307..c3c8c024 100644 --- a/libntfs-3g/attrib.c +++ b/libntfs-3g/attrib.c @@ -4876,6 +4876,8 @@ void *ntfs_attr_readall(ntfs_inode *ni, const ATTR_TYPES type, void *data, *ret = NULL; s64 size; + ntfs_log_trace("Entering\n"); + na = ntfs_attr_open(ni, type, name, name_len); if (!na) { ntfs_log_perror("ntfs_attr_open failed"); @@ -4921,3 +4923,33 @@ int ntfs_attr_exist(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name, return !ret; } +int ntfs_attr_remove(ntfs_inode *ni, const ATTR_TYPES type, ntfschar *name, + u32 name_len) +{ + ntfs_attr *na; + int ret; + + ntfs_log_trace("Entering\n"); + + if (!ni) { + ntfs_log_error("%s: NULL inode pointer", __FUNCTION__); + errno = EINVAL; + return -1; + } + + na = ntfs_attr_open(ni, type, name, name_len); + if (!na) { + ntfs_log_perror("Failed to open attribute 0x%02x of inode " + "0x%llx", type, (unsigned long long)ni->mft_no); + return -1; + } + + ret = ntfs_attr_rm(na); + if (ret) + ntfs_log_perror("Failed to remove attribute 0x%02x of inode " + "0x%llx", type, (unsigned long long)ni->mft_no); + ntfs_attr_close(na); + + return ret; +} + diff --git a/libntfs-3g/dir.c b/libntfs-3g/dir.c index dca17193..989bb3f3 100644 --- a/libntfs-3g/dir.c +++ b/libntfs-3g/dir.c @@ -1222,39 +1222,12 @@ static ntfs_inode *__ntfs_create(ntfs_inode *dir_ni, return ni; err_out: ntfs_log_trace("Failed.\n"); - if (rollback_sd) { - ntfs_attr *na; - na = ntfs_attr_open(ni, AT_SECURITY_DESCRIPTOR, AT_UNNAMED, 0); - if (!na) - ntfs_log_perror("Failed to open SD (0x50) attribute of " - " inode 0x%llx. Run chkdsk.\n", - (unsigned long long)ni->mft_no); - else { - if (ntfs_attr_rm(na)) - ntfs_log_perror("Failed to remove SD (0x50) " - "attribute of inode 0x%llx", - (unsigned long long)ni->mft_no); - ntfs_attr_close(na); - } - } - if (rollback_data) { - ntfs_attr *na; - - na = ntfs_attr_open(ni, AT_DATA, AT_UNNAMED, 0); - if (!na) - ntfs_log_perror("Failed to open data attribute of " - " inode 0x%llx. Run chkdsk.\n", - (unsigned long long)ni->mft_no); - else { - if (ntfs_attr_rm(na)) - ntfs_log_perror("Failed to remove data " - "attribute of inode 0x%llx", - (unsigned long long)ni->mft_no); - - ntfs_attr_close(na); - } - } + if (rollback_sd) + ntfs_attr_remove(ni, AT_SECURITY_DESCRIPTOR, AT_UNNAMED, 0); + + if (rollback_data) + ntfs_attr_remove(ni, AT_DATA, AT_UNNAMED, 0); /* * Free extent MFT records (should not exist any with current * ntfs_create implementation, but for any case if something will be diff --git a/src/ntfs-3g.c b/src/ntfs-3g.c index 45977dc9..f8c33b6a 100644 --- a/src/ntfs-3g.c +++ b/src/ntfs-3g.c @@ -1005,22 +1005,15 @@ static int ntfs_fuse_rm_stream(const char *path, ntfschar *stream_name, const int stream_name_len) { ntfs_inode *ni; - ntfs_attr *na; int res = 0; ni = ntfs_pathname_to_inode(ctx->vol, NULL, path); if (!ni) return -errno; - na = ntfs_attr_open(ni, AT_DATA, stream_name, stream_name_len); - if (!na) { - res = -errno; - goto exit; - } - if (ntfs_attr_rm(na)) - res = -errno; - ntfs_attr_close(na); -exit: + if (ntfs_attr_remove(ni, AT_DATA, stream_name, stream_name_len)) + res = -errno; + if (ntfs_inode_close(ni)) ntfs_log_perror("Failed to close inode"); return res; @@ -1449,7 +1442,6 @@ static int ntfs_fuse_removexattr(const char *path, const char *name) { ntfs_volume *vol; ntfs_inode *ni; - ntfs_attr *na = NULL; ntfschar *lename = NULL; int res = 0, lename_len; @@ -1470,15 +1462,11 @@ static int ntfs_fuse_removexattr(const char *path, const char *name) res = -errno; goto exit; } - na = ntfs_attr_open(ni, AT_DATA, lename, lename_len); - if (!na) { - res = -ENODATA; - goto exit; - } - if (ntfs_attr_rm(na)) + if (ntfs_attr_remove(ni, AT_DATA, lename, lename_len)) { + if (errno == ENOENT) + errno = ENODATA; res = -errno; - - ntfs_attr_close(na); + } ntfs_fuse_mark_free_space_outdated(); exit: