ntfs_delete(): factor out ntfs_index_remove()
parent
34ad920d44
commit
23dfee4366
|
@ -115,7 +115,7 @@ extern int ntfs_index_lookup(const void *key, const int key_len,
|
|||
|
||||
extern int ntfs_index_add_filename(ntfs_inode *ni, FILE_NAME_ATTR *fn,
|
||||
MFT_REF mref);
|
||||
extern int ntfs_index_rm(ntfs_index_context *ictx);
|
||||
extern int ntfs_index_remove(ntfs_inode *ni, const void *key, const int keylen);
|
||||
|
||||
extern INDEX_ROOT *ntfs_index_root_get(ntfs_inode *ni, ATTR_RECORD *attr);
|
||||
|
||||
|
|
|
@ -1357,7 +1357,6 @@ no_hardlink:
|
|||
int ntfs_delete(ntfs_inode *ni, ntfs_inode *dir_ni, ntfschar *name, u8 name_len)
|
||||
{
|
||||
ntfs_attr_search_ctx *actx = NULL;
|
||||
ntfs_index_context *ictx = NULL;
|
||||
FILE_NAME_ATTR *fn = NULL;
|
||||
BOOL looking_for_dos_name = FALSE, looking_for_win32_name = FALSE;
|
||||
BOOL case_sensitive_match = TRUE;
|
||||
|
@ -1452,19 +1451,7 @@ search:
|
|||
if (ntfs_check_unlinkable_dir(ni, fn) < 0)
|
||||
goto err_out;
|
||||
|
||||
ictx = ntfs_index_ctx_get(dir_ni, NTFS_INDEX_I30, 4);
|
||||
if (!ictx)
|
||||
goto err_out;
|
||||
if (ntfs_index_lookup(fn, le32_to_cpu(actx->attr->value_length), ictx))
|
||||
goto err_out;
|
||||
|
||||
if (((FILE_NAME_ATTR*)ictx->data)->file_attributes &
|
||||
FILE_ATTR_REPARSE_POINT) {
|
||||
errno = EOPNOTSUPP;
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
if (ntfs_index_rm(ictx))
|
||||
if (ntfs_index_remove(dir_ni, fn, le32_to_cpu(actx->attr->value_length)))
|
||||
goto err_out;
|
||||
|
||||
if (ntfs_attr_record_rm(actx))
|
||||
|
@ -1535,8 +1522,6 @@ ok:
|
|||
out:
|
||||
if (actx)
|
||||
ntfs_attr_put_search_ctx(actx);
|
||||
if (ictx)
|
||||
ntfs_index_ctx_put(ictx);
|
||||
if (ntfs_inode_close(dir_ni) && !err)
|
||||
err = errno;
|
||||
if (ntfs_inode_close(ni) && !err)
|
||||
|
@ -1617,22 +1602,11 @@ int ntfs_link(ntfs_inode *ni, ntfs_inode *dir_ni, ntfschar *name, u8 name_len)
|
|||
}
|
||||
/* Add FILE_NAME attribute to inode. */
|
||||
if (ntfs_attr_add(ni, AT_FILE_NAME, AT_UNNAMED, 0, (u8*)fn, fn_len)) {
|
||||
ntfs_index_context *ictx;
|
||||
|
||||
err = errno;
|
||||
ntfs_log_error("Failed to add FILE_NAME attribute.\n");
|
||||
err = errno;
|
||||
/* Try to remove just added attribute from index. */
|
||||
ictx = ntfs_index_ctx_get(dir_ni, NTFS_INDEX_I30, 4);
|
||||
if (!ictx)
|
||||
if (ntfs_index_remove(dir_ni, fn, fn_len))
|
||||
goto rollback_failed;
|
||||
if (ntfs_index_lookup(fn, fn_len, ictx)) {
|
||||
ntfs_index_ctx_put(ictx);
|
||||
goto rollback_failed;
|
||||
}
|
||||
if (ntfs_index_rm(ictx)) {
|
||||
ntfs_index_ctx_put(ictx);
|
||||
goto rollback_failed;
|
||||
}
|
||||
goto err_out;
|
||||
}
|
||||
/* Increment hard links count. */
|
||||
|
|
|
@ -1828,6 +1828,33 @@ err_out:
|
|||
return -1;
|
||||
}
|
||||
|
||||
int ntfs_index_remove(ntfs_inode *ni, const void *key, const int keylen)
|
||||
{
|
||||
int ret = -1;
|
||||
ntfs_index_context *ctx;
|
||||
|
||||
ctx = ntfs_index_ctx_get(ni, NTFS_INDEX_I30, 4);
|
||||
if (!ctx)
|
||||
return -1;
|
||||
|
||||
if (ntfs_index_lookup(key, keylen, ctx))
|
||||
goto err_out;
|
||||
|
||||
if (((FILE_NAME_ATTR *)ctx->data)->file_attributes &
|
||||
FILE_ATTR_REPARSE_POINT) {
|
||||
errno = EOPNOTSUPP;
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
if (ntfs_index_rm(ctx))
|
||||
goto err_out;
|
||||
|
||||
ret = 0;
|
||||
err_out:
|
||||
ntfs_index_ctx_put(ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* ntfs_index_root_get - read the index root of an attribute
|
||||
* @ni: open ntfs inode in which the ntfs attribute resides
|
||||
|
|
Loading…
Reference in New Issue