ntfs_inode_free_space: factor out ntfs_attr_position
parent
8705583421
commit
fbc392830c
|
@ -92,6 +92,8 @@ extern int ntfs_attr_lookup(const ATTR_TYPES type, const ntfschar *name,
|
|||
const VCN lowest_vcn, const u8 *val, const u32 val_len,
|
||||
ntfs_attr_search_ctx *ctx);
|
||||
|
||||
extern int ntfs_attr_position(const ATTR_TYPES type, ntfs_attr_search_ctx *ctx);
|
||||
|
||||
extern ATTR_DEF *ntfs_attr_find_in_attrdef(const ntfs_volume *vol,
|
||||
const ATTR_TYPES type);
|
||||
|
||||
|
|
|
@ -2350,6 +2350,36 @@ out:
|
|||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* ntfs_attr_position - find given or next attribute type in an ntfs inode
|
||||
* @type: attribute type to start lookup
|
||||
* @ctx: search context with mft record and attribute to search from
|
||||
*
|
||||
* Find an attribute type in an ntfs inode or the next attribute which is not
|
||||
* the AT_END attribute. Please see more details at ntfs_attr_lookup.
|
||||
*
|
||||
* Return 0 if the search was successful and -1 if not, with errno set to the
|
||||
* error code.
|
||||
*
|
||||
* The following error codes are defined:
|
||||
* EINVAL Invalid arguments.
|
||||
* EIO I/O error or corrupt data structures found.
|
||||
* ENOMEM Not enough memory to allocate necessary buffers.
|
||||
* ENOSPC No attribute was found after 'type', only AT_END.
|
||||
*/
|
||||
int ntfs_attr_position(const ATTR_TYPES type, ntfs_attr_search_ctx *ctx)
|
||||
{
|
||||
if (ntfs_attr_lookup(type, NULL, 0, CASE_SENSITIVE, 0, NULL, 0, ctx)) {
|
||||
if (errno != ENOENT)
|
||||
return -1;
|
||||
if (ctx->attr->type == AT_END) {
|
||||
errno = ENOSPC;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* ntfs_attr_init_search_ctx - initialize an attribute search context
|
||||
* @ctx: attribute search context to initialize
|
||||
|
|
|
@ -1022,17 +1022,9 @@ int ntfs_inode_free_space(ntfs_inode *ni, int size)
|
|||
* $STANDARD_INFORMATION and $ATTRIBUTE_LIST must stay in the base MFT
|
||||
* record, so position search context on the first attribute after them.
|
||||
*/
|
||||
if (ntfs_attr_lookup(AT_FILE_NAME, NULL, 0, CASE_SENSITIVE, 0, NULL,
|
||||
0, ctx)) {
|
||||
if (errno != ENOENT) {
|
||||
err = errno;
|
||||
ntfs_log_perror("%s: attr lookup failed #2", __FUNCTION__);
|
||||
goto put_err_out;
|
||||
}
|
||||
if (ctx->attr->type == AT_END) {
|
||||
err = ENOSPC;
|
||||
goto put_err_out;
|
||||
}
|
||||
if (ntfs_attr_position(AT_FILE_NAME, ctx)) {
|
||||
err = errno;
|
||||
goto put_err_out;
|
||||
}
|
||||
|
||||
while (1) {
|
||||
|
@ -1081,17 +1073,9 @@ retry:
|
|||
* $ATTRIBUTE_LIST.
|
||||
*/
|
||||
ntfs_attr_reinit_search_ctx(ctx);
|
||||
if (ntfs_attr_lookup(AT_FILE_NAME, NULL, 0, CASE_SENSITIVE, 0,
|
||||
NULL, 0, ctx)) {
|
||||
if (errno != ENOENT) {
|
||||
err = errno;
|
||||
ntfs_log_perror("Attr lookup #2 failed");
|
||||
break;
|
||||
}
|
||||
if (ctx->attr->type == AT_END) {
|
||||
err = ENOSPC;
|
||||
break;
|
||||
}
|
||||
if (ntfs_attr_position(AT_FILE_NAME, ctx)) {
|
||||
err = errno;
|
||||
break;
|
||||
}
|
||||
}
|
||||
put_err_out:
|
||||
|
|
Loading…
Reference in New Issue