attrlist.c revision 7e7bd3dccbfe8f79e25e5c1554b5bc3a9aaca321
/**
* attrlist.c - Attribute list attribute handling code. Part of the Linux-NTFS
* project.
*
* Copyright (c) 2004-2005 Anton Altaparmakov
* Copyright (c) 2004-2007 Yura Pakhuchiy
*
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program (in the main directory of the Linux-NTFS
* distribution in the file COPYING); if not, write to the Free Software
* Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include "compat.h"
#include "types.h"
#include "layout.h"
#include "attrib.h"
#include "attrlist.h"
#include "debug.h"
#include "unistr.h"
#include "logging.h"
/**
* ntfs_attrlist_need - check whether inode need attribute list
* @ni: opened ntfs inode for which perform check
*
* Check whether all are attributes belong to one MFT record, in that case
* attribute list is not needed.
*
* Return 1 if inode need attribute list, 0 if not, -1 on error with errno set
* to the error code. If function succeed errno set to 0. The following error
* codes are defined:
* EINVAL - Invalid arguments passed to function or attribute haven't got
* attribute list.
*/
{
if (!ni) {
ntfs_log_trace("Invalid arguments.\n");
return -1;
}
if (!NInoAttrList(ni)) {
ntfs_log_trace("Inode haven't got attribute list.\n");
return -1;
}
ntfs_log_trace("Corrupt in-memory struct.\n");
return -1;
}
errno = 0;
return 1;
}
return 0;
}
/**
* ntfs_attrlist_entry_add - add an attribute list attribute entry
* @ni: opened ntfs inode, which contains that attribute
* @attr: attribute record to add to attribute list
*
* Return 0 on success and -1 on error with errno set to the error code. The
* following error codes are defined:
* EINVAL - Invalid arguments passed to function.
* ENOMEM - Not enough memory to allocate necessary buffers.
* EIO - I/O error occurred or damaged filesystem.
* EEXIST - Such attribute already present in attribute list.
*/
{
ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n",
ntfs_log_trace("Invalid arguments.\n");
return -1;
}
if (!NInoAttrList(ni)) {
ntfs_log_trace("Attribute list isn't present.\n");
return -1;
}
/* Determine size and allocate memory for new attribute list. */
if (!new_al) {
ntfs_log_trace("Not enough memory.\n");
return -1;
}
/* Find place for the new entry. */
if (!ctx) {
ntfs_log_trace("Failed to obtain attribute search context.\n");
goto err_out;
}
/* Found some extent, check it to be before new extent. */
ntfs_log_trace("Such attribute already present in the "
"attribute list.\n");
goto err_out;
}
/* Add new entry after this extent. */
} else {
/* Check for real errors. */
ntfs_log_trace("Attribute lookup failed.\n");
goto err_out;
}
/* No previous extents found. */
}
/* Don't need it anymore, @ctx->al_entry points to @ni->attr_list. */
/* Determine new entry offset. */
/* Set pointer to new entry. */
/* Form new entry. */
if (attr->non_resident)
else
ale->lowest_vcn = 0;
/* Resize $ATTRIBUTE_LIST to new length. */
if (!na) {
ntfs_log_trace("Failed to open $ATTRIBUTE_LIST attribute.\n");
goto err_out;
}
ntfs_log_trace("$ATTRIBUTE_LIST resize failed.\n");
goto err_out;
}
/* Copy entries from old attribute list to new. */
/* Set new runlist. */
/* Done! */
return 0;
if (na)
return -1;
}
/**
* ntfs_attrlist_entry_rm - remove an attribute list attribute entry
* @ctx: attribute search context describing the attribute list entry
*
* Remove the attribute list entry @ctx->al_entry from the attribute list.
*
* Return 0 on success and -1 on error with errno set to the error code.
*/
{
int new_al_len;
int err;
ntfs_log_trace("Invalid arguments.\n");
return -1;
}
if (ctx->base_ntfs_ino)
else
ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, lowest_vcn %lld."
if (!NInoAttrList(base_ni)) {
ntfs_log_trace("Attribute list isn't present.\n");
return -1;
}
/* Allocate memory for new attribute list. */
if (!new_al) {
ntfs_log_trace("Not enough memory.\n");
return -1;
}
/* Reisze $ATTRIBUTE_LIST to new length. */
if (!na) {
ntfs_log_trace("Failed to open $ATTRIBUTE_LIST attribute.\n");
goto err_out;
}
ntfs_log_trace("$ATTRIBUTE_LIST resize failed.\n");
goto err_out;
}
/* Copy entries from old attribute list to new. */
/* Set new runlist. */
/* Done! */
return 0;
if (na)
return -1;
}