libntfs: add and ntfs_inode_badclus_bad() and convert all copy-pastes

to use them
edge.strict_endians
szaka 2006-04-05 02:53:40 +00:00
parent 6772bb4649
commit 134319ae80
4 changed files with 53 additions and 29 deletions

View File

@ -32,8 +32,9 @@ xx/xx/2006 - 1.13.1-WIP
- ntfsinfo: dump either a minimal (default) or the entire attribute
header (--verbose) for all attributes types. Also removed a lot of
redundant code and made some formatting corrections. (Szaka)
- libntfs: add ntfs_str2ucs(), ntfs_freeucs() and ntfs_mft_usn_dec()
functions, and convert all copy-pastes to use them. (Szaka)
- libntfs: add ntfs_str2ucs(), ntfs_freeucs(), ntfs_mft_usn_dec()
and ntfs_inode_badclus_bad() functions, and convert all copy-pastes
to use them. (Szaka)
27/02/2006 - 1.13.0 - Lots and lots and lots of fixes and enhancements.

View File

@ -185,6 +185,8 @@ extern int ntfs_inode_add_attrlist(ntfs_inode *ni);
extern int ntfs_inode_free_space(ntfs_inode *ni, int size);
extern int ntfs_inode_badclus_bad(u64 mft_no, ATTR_RECORD *a);
#ifdef NTFS_RICH
int ntfs_inode_close2(ntfs_inode *ni);

View File

@ -1105,6 +1105,50 @@ void ntfs_inode_update_time(ntfs_inode *ni)
}
}
/**
* ntfs_inode_badclus_bad - check for $Badclus:$Bad data attribute
* @mft_no: mft record number where @attr is present
* @attr: attribute record used to check for the $Bad attribute
*
* Check if the mft record given by @mft_no and @attr contains the bad sector
* list. Please note that mft record numbers describing $Badclus extent inodes
* will not match the current $Badclus:$Bad check.
*
* On success return 1 if the file is $Badclus:$Bad, otherwise return 0.
* On error return -1 with errno set to the error code.
*/
int ntfs_inode_badclus_bad(u64 mft_no, ATTR_RECORD *attr)
{
int len, ret = 0;
ntfschar *ustr;
if (!attr) {
ntfs_log_error("Invalid argument.\n");
errno = EINVAL;
return -1;
}
if (mft_no != FILE_BadClus)
return 0;
if (attr->type != AT_DATA)
return 0;
if ((ustr = ntfs_str2ucs("$Bad", &len)) == NULL) {
ntfs_log_perror("Couldn't convert '$Bad' to Unicode");
return -1;
}
if (ustr && ntfs_names_are_equal(ustr, len,
(ntfschar *)((u8 *)attr + le16_to_cpu(attr->name_offset)),
attr->name_length, 0, NULL, 0))
ret = 1;
ntfs_ucsfree(ustr);
return ret;
}
#ifdef NTFS_RICH
#include "rich.h"

View File

@ -638,29 +638,6 @@ static s64 nr_clusters_to_bitmap_byte_size(s64 nr_clusters)
return bm_bsize;
}
static int is_badclus_bad(u64 mft_no, ATTR_RECORD *a)
{
int len, ret = 0;
ntfschar *ustr;
if (mft_no != FILE_BadClus)
return 0;
if ((ustr = ntfs_str2ucs("$Bad", &len)) == NULL) {
perr_printf("Couldn't convert '$Bad' to Unicode");
return -1;
}
if (ustr && ntfs_names_are_equal(ustr, len,
(ntfschar *)((u8 *)a + le16_to_cpu(a->name_offset)),
a->name_length, 0, NULL, 0))
ret = 1;
ntfs_ucsfree(ustr);
return ret;
}
static void collect_resize_constraints(ntfs_resize_t *resize, runlist *rl)
{
s64 inode, last_lcn;
@ -675,9 +652,9 @@ static void collect_resize_constraints(ntfs_resize_t *resize, runlist *rl)
flags = resize->ctx->attr->flags;
atype = resize->ctx->attr->type;
if ((ret = is_badclus_bad(inode, resize->ctx->attr)) != 0) {
if ((ret = ntfs_inode_badclus_bad(inode, resize->ctx->attr)) != 0) {
if (ret == -1)
exit(1);
perr_exit("Bad sector list check failed");
return;
}
@ -1679,9 +1656,9 @@ static void relocate_attributes(ntfs_resize_t *resize, int do_mftdata)
if (handle_mftdata(resize, do_mftdata) == 0)
continue;
ret = is_badclus_bad(resize->mref, resize->ctx->attr);
ret = ntfs_inode_badclus_bad(resize->mref, resize->ctx->attr);
if (ret == -1)
exit(1);
perr_exit("Bad sector list check failed");
else if (ret == 1)
continue;