+/*
+ * Get the ntfs attributes from an inode
+ * The attributes are returned according to cpu endianness
+ *
+ * Returns the attributes if successful (cannot be zero)
+ * 0 if failed (errno to tell why)
+ */
+
+u32 ntfs_get_inode_attributes(ntfs_inode *ni)
+{
+ u32 attrib = -1;
+
+ if (ni) {
+ attrib = le32_to_cpu(ni->flags);
+ if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY)
+ attrib |= const_le32_to_cpu(FILE_ATTR_DIRECTORY);
+ else
+ attrib &= ~const_le32_to_cpu(FILE_ATTR_DIRECTORY);
+ if (!attrib)
+ attrib |= const_le32_to_cpu(FILE_ATTR_NORMAL);
+ } else
+ errno = EINVAL;
+ return (attrib);
+}
+
+/*
+ * Set the ntfs attributes on an inode
+ * The attribute is expected according to cpu endianness
+ *
+ * Returns 0 if successful
+ * -1 if failed (errno to tell why)
+ */
+
+int ntfs_set_inode_attributes(ntfs_inode *ni, u32 attrib)
+{
+ le32 settable;
+ ATTR_FLAGS dirflags;
+ int res;
+
+ res = -1;
+ if (ni) {
+ settable = FILE_ATTR_SETTABLE;
+ res = 0;
+ if (ni->mrec->flags & MFT_RECORD_IS_DIRECTORY) {
+ /*
+ * Accept changing compression for a directory
+ * and set index root accordingly
+ */
+ settable |= FILE_ATTR_COMPRESSED;
+ if ((ni->flags ^ cpu_to_le32(attrib))
+ & FILE_ATTR_COMPRESSED) {
+ if (ni->flags & FILE_ATTR_COMPRESSED)
+ dirflags = const_cpu_to_le16(0);
+ else
+ dirflags = ATTR_IS_COMPRESSED;
+ res = ntfs_attr_set_flags(ni, AT_INDEX_ROOT,
+ NTFS_INDEX_I30, 4, dirflags,
+ ATTR_COMPRESSION_MASK);
+ }
+ }
+ if (!res) {
+ ni->flags = (ni->flags & ~settable)
+ | (cpu_to_le32(attrib) & settable);
+ NInoFileNameSetDirty(ni);
+ NInoSetDirty(ni);
+ }
+ } else
+ errno = EINVAL;
+ return (res);
+}
+