Commit bad71405 authored by Richard Russon's avatar Richard Russon

Merge ssh://linux-ntfs@bkbits.net/ntfs-2.6-devel

into flatcap.org:/home/flatcap/backup/bk/ntfs-2.6-devel
parents 55748633 c801720c
......@@ -38,6 +38,22 @@ ToDo/Notes:
- Rename {{re,}init,get,put}_attr_search_ctx() to
ntfs_attr_{{re,}init,get,put}_search_ctx() as well as the type
attr_search_context to ntfs_attr_search_ctx.
- Force use of ntfs_attr_find() in ntfs_attr_lookup() when searching
for the attribute list attribute itself.
- Fix endianness bug in ntfs_external_attr_find().
- Change ntfs_{external_,}attr_find() to return 0 on success, -ENOENT
if the attribute is not found, and -EIO on real error. In the case
of -ENOENT, the search context is updated to describe the attribute
before which the attribute being searched for would need to be
inserted if such an action were to be desired and in the case of
ntfs_external_attr_find() the search context is also updated to
indicate the attribute list entry before which the attribute list
entry of the attribute being searched for would need to be inserted
if such an action were to be desired. Also make ntfs_find_attr()
static and remove its prototype from attrib.h as it is not used
anywhere other than attrib.c. Update ntfs_attr_lookup() and all
callers of ntfs_{external,}attr_{find,lookup}() for the new return
values.
2.1.17 - Fix bugs in mount time error code paths and other updates.
......
......@@ -402,11 +402,10 @@ int ntfs_readpage(struct file *file, struct page *page)
err = -ENOMEM;
goto unm_err_out;
}
if (unlikely(!ntfs_attr_lookup(ni->type, ni->name, ni->name_len,
CASE_SENSITIVE, 0, NULL, 0, ctx))) {
err = -ENOENT;
err = ntfs_attr_lookup(ni->type, ni->name, ni->name_len,
CASE_SENSITIVE, 0, NULL, 0, ctx);
if (unlikely(err))
goto put_unm_err_out;
}
/* Starting position of the page within the attribute value. */
attr_pos = page->index << PAGE_CACHE_SHIFT;
......@@ -1122,11 +1121,10 @@ static int ntfs_writepage(struct page *page, struct writeback_control *wbc)
err = -ENOMEM;
goto err_out;
}
if (unlikely(!ntfs_attr_lookup(ni->type, ni->name, ni->name_len,
CASE_SENSITIVE, 0, NULL, 0, ctx))) {
err = -ENOENT;
err = ntfs_attr_lookup(ni->type, ni->name, ni->name_len,
CASE_SENSITIVE, 0, NULL, 0, ctx);
if (unlikely(err))
goto err_out;
}
/* Starting position of the page within the attribute value. */
attr_pos = page->index << PAGE_CACHE_SHIFT;
......@@ -1896,11 +1894,10 @@ static int ntfs_commit_write(struct file *file, struct page *page,
err = -ENOMEM;
goto err_out;
}
if (unlikely(!ntfs_attr_lookup(ni->type, ni->name, ni->name_len,
CASE_SENSITIVE, 0, NULL, 0, ctx))) {
err = -ENOENT;
err = ntfs_attr_lookup(ni->type, ni->name, ni->name_len,
CASE_SENSITIVE, 0, NULL, 0, ctx);
if (unlikely(err))
goto err_out;
}
/* Starting position of the page within the attribute value. */
attr_pos = page->index << PAGE_CACHE_SHIFT;
......
This diff is collapsed.
......@@ -81,11 +81,7 @@ extern LCN ntfs_vcn_to_lcn(const runlist_element *rl, const VCN vcn);
extern runlist_element *ntfs_find_vcn(ntfs_inode *ni, const VCN vcn,
const BOOL need_write);
extern BOOL ntfs_attr_find(const ATTR_TYPES type, const ntfschar *name,
const u32 name_len, const IGNORE_CASE_BOOL ic, const u8 *val,
const u32 val_len, ntfs_attr_search_ctx *ctx);
BOOL ntfs_attr_lookup(const ATTR_TYPES type, const ntfschar *name,
int ntfs_attr_lookup(const ATTR_TYPES type, const ntfschar *name,
const u32 name_len, const IGNORE_CASE_BOOL ic,
const VCN lowest_vcn, const u8 *val, const u32 val_len,
ntfs_attr_search_ctx *ctx);
......
......@@ -106,11 +106,15 @@ MFT_REF ntfs_lookup_inode_by_name(ntfs_inode *dir_ni, const ntfschar *uname,
goto err_out;
}
/* Find the index root attribute in the mft record. */
if (!ntfs_attr_lookup(AT_INDEX_ROOT, I30, 4, CASE_SENSITIVE, 0, NULL,
0, ctx)) {
ntfs_error(sb, "Index root attribute missing in directory "
"inode 0x%lx.", dir_ni->mft_no);
err = -EIO;
err = ntfs_attr_lookup(AT_INDEX_ROOT, I30, 4, CASE_SENSITIVE, 0, NULL,
0, ctx);
if (unlikely(err)) {
if (err == -ENOENT) {
ntfs_error(sb, "Index root attribute missing in "
"directory inode 0x%lx.",
dir_ni->mft_no);
err = -EIO;
}
goto err_out;
}
/* Get to the index root value (it's been verified in read_inode). */
......@@ -655,11 +659,15 @@ u64 ntfs_lookup_inode_by_name(ntfs_inode *dir_ni, const ntfschar *uname,
goto err_out;
}
/* Find the index root attribute in the mft record. */
if (!ntfs_attr_lookup(AT_INDEX_ROOT, I30, 4, CASE_SENSITIVE, 0, NULL,
0, ctx)) {
ntfs_error(sb, "Index root attribute missing in directory "
"inode 0x%lx.", dir_ni->mft_no);
err = -EIO;
err = ntfs_attr_lookup(AT_INDEX_ROOT, I30, 4, CASE_SENSITIVE, 0, NULL,
0, ctx);
if (unlikely(err)) {
if (err == -ENOENT) {
ntfs_error(sb, "Index root attribute missing in "
"directory inode 0x%lx.",
dir_ni->mft_no);
err = -EIO;
}
goto err_out;
}
/* Get to the index root value (it's been verified in read_inode). */
......@@ -1183,8 +1191,9 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
/* Get the offset into the index root attribute. */
ir_pos = (s64)fpos;
/* Find the index root attribute in the mft record. */
if (unlikely(!ntfs_attr_lookup(AT_INDEX_ROOT, I30, 4, CASE_SENSITIVE,
0, NULL, 0, ctx))) {
err = ntfs_attr_lookup(AT_INDEX_ROOT, I30, 4, CASE_SENSITIVE, 0, NULL,
0, ctx);
if (unlikely(err)) {
ntfs_error(sb, "Index root attribute missing in directory "
"inode 0x%lx.", vdir->i_ino);
goto err_out;
......
......@@ -125,6 +125,7 @@ void ntfs_index_ctx_put(ntfs_index_context *ictx)
int ntfs_index_lookup(const void *key, const int key_len,
ntfs_index_context *ictx)
{
VCN vcn, old_vcn;
ntfs_inode *idx_ni = ictx->idx_ni;
ntfs_volume *vol = idx_ni->vol;
struct super_block *sb = vol->sb;
......@@ -133,13 +134,11 @@ int ntfs_index_lookup(const void *key, const int key_len,
INDEX_ROOT *ir;
INDEX_ENTRY *ie;
INDEX_ALLOCATION *ia;
u8 *index_end;
u8 *index_end, *kaddr;
ntfs_attr_search_ctx *actx;
int rc, err = 0;
VCN vcn, old_vcn;
struct address_space *ia_mapping;
struct page *page;
u8 *kaddr;
int rc, err = 0;
ntfs_debug("Entering.");
BUG_ON(!NInoAttr(idx_ni));
......@@ -168,11 +167,14 @@ int ntfs_index_lookup(const void *key, const int key_len,
goto err_out;
}
/* Find the index root attribute in the mft record. */
if (!ntfs_attr_lookup(AT_INDEX_ROOT, idx_ni->name, idx_ni->name_len,
CASE_SENSITIVE, 0, NULL, 0, actx)) {
ntfs_error(sb, "Index root attribute missing in inode 0x%lx.",
idx_ni->mft_no);
err = -EIO;
err = ntfs_attr_lookup(AT_INDEX_ROOT, idx_ni->name, idx_ni->name_len,
CASE_SENSITIVE, 0, NULL, 0, actx);
if (unlikely(err)) {
if (err == -ENOENT) {
ntfs_error(sb, "Index root attribute missing in inode "
"0x%lx.", idx_ni->mft_no);
err = -EIO;
}
goto err_out;
}
/* Get to the index root value (it has been verified in read_inode). */
......
......@@ -428,11 +428,11 @@ inline ntfs_inode *ntfs_new_extent_inode(struct super_block *sb,
* Return values:
* 1: file is in $Extend directory
* 0: file is not in $Extend directory
* -EIO: file is corrupt
* -errno: failed to determine if the file is in the $Extend directory
*/
static int ntfs_is_extended_system_file(ntfs_attr_search_ctx *ctx)
{
int nr_links;
int nr_links, err;
/* Restart search. */
ntfs_attr_reinit_search_ctx(ctx);
......@@ -441,7 +441,8 @@ static int ntfs_is_extended_system_file(ntfs_attr_search_ctx *ctx)
nr_links = le16_to_cpu(ctx->mrec->link_count);
/* Loop through all hard links. */
while (ntfs_attr_lookup(AT_FILE_NAME, NULL, 0, 0, 0, NULL, 0, ctx)) {
while (!(err = ntfs_attr_lookup(AT_FILE_NAME, NULL, 0, 0, 0, NULL, 0,
ctx))) {
FILE_NAME_ATTR *file_name_attr;
ATTR_RECORD *attr = ctx->attr;
u8 *p, *p2;
......@@ -484,7 +485,9 @@ static int ntfs_is_extended_system_file(ntfs_attr_search_ctx *ctx)
if (MREF_LE(file_name_attr->parent_directory) == FILE_Extend)
return 1; /* YES, it's an extended system file. */
}
if (nr_links) {
if (unlikely(err != -ENOENT))
return err;
if (unlikely(nr_links)) {
ntfs_error(ctx->ntfs_ino->vol->sb, "Inode hard link count "
"doesn't match number of name attributes. You "
"should run chkdsk.");
......@@ -608,14 +611,18 @@ static int ntfs_read_locked_inode(struct inode *vi)
* in fact fail if the standard information is in an extent record, but
* I don't think this actually ever happens.
*/
if (!ntfs_attr_lookup(AT_STANDARD_INFORMATION, NULL, 0, 0, 0, NULL, 0,
ctx)) {
/*
* TODO: We should be performing a hot fix here (if the recover
* mount option is set) by creating a new attribute.
*/
ntfs_error(vi->i_sb, "$STANDARD_INFORMATION attribute is "
"missing.");
err = ntfs_attr_lookup(AT_STANDARD_INFORMATION, NULL, 0, 0, 0, NULL, 0,
ctx);
if (unlikely(err)) {
if (err == -ENOENT) {
/*
* TODO: We should be performing a hot fix here (if the
* recover mount option is set) by creating a new
* attribute.
*/
ntfs_error(vi->i_sb, "$STANDARD_INFORMATION attribute "
"is missing.");
}
goto unm_err_out;
}
/* Get the standard information attribute value. */
......@@ -647,7 +654,14 @@ static int ntfs_read_locked_inode(struct inode *vi)
/* Find the attribute list attribute if present. */
ntfs_attr_reinit_search_ctx(ctx);
if (ntfs_attr_lookup(AT_ATTRIBUTE_LIST, NULL, 0, 0, 0, NULL, 0, ctx)) {
err = ntfs_attr_lookup(AT_ATTRIBUTE_LIST, NULL, 0, 0, 0, NULL, 0, ctx);
if (err) {
if (unlikely(err != -ENOENT)) {
ntfs_error(vi->i_sb, "Failed to lookup attribute list "
"attribute. You should run chkdsk.");
goto unm_err_out;
}
} else /* if (!err) */ {
if (vi->i_ino == FILE_MFT)
goto skip_attr_list_load;
ntfs_debug("Attribute list found in inode 0x%lx.", vi->i_ino);
......@@ -734,12 +748,16 @@ static int ntfs_read_locked_inode(struct inode *vi)
/* It is a directory, find index root attribute. */
ntfs_attr_reinit_search_ctx(ctx);
if (!ntfs_attr_lookup(AT_INDEX_ROOT, I30, 4, CASE_SENSITIVE, 0,
NULL, 0, ctx)) {
// FIXME: File is corrupt! Hot-fix with empty index
// root attribute if recovery option is set.
ntfs_error(vi->i_sb, "$INDEX_ROOT attribute is "
"missing.");
err = ntfs_attr_lookup(AT_INDEX_ROOT, I30, 4, CASE_SENSITIVE,
0, NULL, 0, ctx);
if (unlikely(err)) {
if (err == -ENOENT) {
// FIXME: File is corrupt! Hot-fix with empty
// index root attribute if recovery option is
// set.
ntfs_error(vi->i_sb, "$INDEX_ROOT attribute "
"is missing.");
}
goto unm_err_out;
}
/* Set up the state. */
......@@ -850,11 +868,18 @@ static int ntfs_read_locked_inode(struct inode *vi)
NInoSetIndexAllocPresent(ni);
/* Find index allocation attribute. */
ntfs_attr_reinit_search_ctx(ctx);
if (!ntfs_attr_lookup(AT_INDEX_ALLOCATION, I30, 4,
CASE_SENSITIVE, 0, NULL, 0, ctx)) {
ntfs_error(vi->i_sb, "$INDEX_ALLOCATION attribute "
"is not present but $INDEX_ROOT "
"indicated it is.");
err = ntfs_attr_lookup(AT_INDEX_ALLOCATION, I30, 4,
CASE_SENSITIVE, 0, NULL, 0, ctx);
if (unlikely(err)) {
if (err == -ENOENT)
ntfs_error(vi->i_sb, "$INDEX_ALLOCATION "
"attribute is not present but "
"$INDEX_ROOT indicated it "
"is.");
else
ntfs_error(vi->i_sb, "Failed to lookup "
"$INDEX_ALLOCATION "
"attribute.");
goto unm_err_out;
}
if (!ctx->attr->non_resident) {
......@@ -946,9 +971,15 @@ static int ntfs_read_locked_inode(struct inode *vi)
ni->name_len = 0;
/* Find first extent of the unnamed data attribute. */
if (!ntfs_attr_lookup(AT_DATA, NULL, 0, 0, 0, NULL, 0, ctx)) {
err = ntfs_attr_lookup(AT_DATA, NULL, 0, 0, 0, NULL, 0, ctx);
if (unlikely(err)) {
vi->i_size = ni->initialized_size =
ni->allocated_size = 0LL;
ni->allocated_size = 0;
if (err != -ENOENT) {
ntfs_error(vi->i_sb, "Failed to lookup $DATA "
"attribute.");
goto unm_err_out;
}
/*
* FILE_Secure does not have an unnamed $DATA
* attribute, so we special case it here.
......@@ -1169,8 +1200,9 @@ static int ntfs_read_locked_attr_inode(struct inode *base_vi, struct inode *vi)
}
/* Find the attribute. */
if (!ntfs_attr_lookup(ni->type, ni->name, ni->name_len, CASE_SENSITIVE,
0, NULL, 0, ctx))
err = ntfs_attr_lookup(ni->type, ni->name, ni->name_len,
CASE_SENSITIVE, 0, NULL, 0, ctx);
if (unlikely(err))
goto unm_err_out;
if (!ctx->attr->non_resident) {
......@@ -1425,9 +1457,12 @@ static int ntfs_read_locked_index_inode(struct inode *base_vi, struct inode *vi)
goto unm_err_out;
}
/* Find the index root attribute. */
if (!ntfs_attr_lookup(AT_INDEX_ROOT, ni->name, ni->name_len,
CASE_SENSITIVE, 0, NULL, 0, ctx)) {
ntfs_error(vi->i_sb, "$INDEX_ROOT attribute is missing.");
err = ntfs_attr_lookup(AT_INDEX_ROOT, ni->name, ni->name_len,
CASE_SENSITIVE, 0, NULL, 0, ctx);
if (unlikely(err)) {
if (err == -ENOENT)
ntfs_error(vi->i_sb, "$INDEX_ROOT attribute is "
"missing.");
goto unm_err_out;
}
/* Set up the state. */
......@@ -1506,10 +1541,16 @@ static int ntfs_read_locked_index_inode(struct inode *base_vi, struct inode *vi)
NInoSetIndexAllocPresent(ni);
/* Find index allocation attribute. */
ntfs_attr_reinit_search_ctx(ctx);
if (!ntfs_attr_lookup(AT_INDEX_ALLOCATION, ni->name, ni->name_len,
CASE_SENSITIVE, 0, NULL, 0, ctx)) {
ntfs_error(vi->i_sb, "$INDEX_ALLOCATION attribute is not "
"present but $INDEX_ROOT indicated it is.");
err = ntfs_attr_lookup(AT_INDEX_ALLOCATION, ni->name, ni->name_len,
CASE_SENSITIVE, 0, NULL, 0, ctx);
if (unlikely(err)) {
if (err == -ENOENT)
ntfs_error(vi->i_sb, "$INDEX_ALLOCATION attribute is "
"not present but $INDEX_ROOT "
"indicated it is.");
else
ntfs_error(vi->i_sb, "Failed to lookup "
"$INDEX_ALLOCATION attribute.");
goto unm_err_out;
}
if (!ctx->attr->non_resident) {
......@@ -1726,7 +1767,14 @@ int ntfs_read_inode_mount(struct inode *vi)
}
/* Find the attribute list attribute if present. */
if (ntfs_attr_lookup(AT_ATTRIBUTE_LIST, NULL, 0, 0, 0, NULL, 0, ctx)) {
err = ntfs_attr_lookup(AT_ATTRIBUTE_LIST, NULL, 0, 0, 0, NULL, 0, ctx);
if (err) {
if (unlikely(err != -ENOENT)) {
ntfs_error(sb, "Failed to lookup attribute list "
"attribute. You should run chkdsk.");
goto put_err_out;
}
} else /* if (!err) */ {
ATTR_LIST_ENTRY *al_entry, *next_al_entry;
u8 *al_end;
......@@ -1860,7 +1908,8 @@ int ntfs_read_inode_mount(struct inode *vi)
/* Now load all attribute extents. */
attr = NULL;
next_vcn = last_vcn = highest_vcn = 0;
while (ntfs_attr_lookup(AT_DATA, NULL, 0, 0, next_vcn, NULL, 0, ctx)) {
while (!(err = ntfs_attr_lookup(AT_DATA, NULL, 0, 0, next_vcn, NULL, 0,
ctx))) {
runlist_element *nrl;
/* Cache the current attribute. */
......@@ -1991,15 +2040,20 @@ int ntfs_read_inode_mount(struct inode *vi)
goto put_err_out;
}
}
if (err != -ENOENT) {
ntfs_error(sb, "Failed to lookup $MFT/$DATA attribute extent. "
"$MFT is corrupt. Run chkdsk.");
goto put_err_out;
}
if (!attr) {
ntfs_error(sb, "$MFT/$DATA attribute not found. $MFT is "
"corrupt. Run chkdsk.");
goto put_err_out;
}
if (highest_vcn && highest_vcn != last_vcn - 1) {
ntfs_error(sb, "Failed to load the complete runlist "
"for $MFT/$DATA. Driver bug or "
"corrupt $MFT. Run chkdsk.");
ntfs_error(sb, "Failed to load the complete runlist for "
"$MFT/$DATA. Driver bug or corrupt $MFT. "
"Run chkdsk.");
ntfs_debug("highest_vcn = 0x%llx, last_vcn - 1 = 0x%llx",
(unsigned long long)highest_vcn,
(unsigned long long)last_vcn - 1);
......@@ -2347,10 +2401,10 @@ int ntfs_write_inode(struct inode *vi, int sync)
err = -ENOMEM;
goto unm_err_out;
}
if (unlikely(!ntfs_attr_lookup(AT_STANDARD_INFORMATION, NULL, 0,
CASE_SENSITIVE, 0, NULL, 0, ctx))) {
err = ntfs_attr_lookup(AT_STANDARD_INFORMATION, NULL, 0,
CASE_SENSITIVE, 0, NULL, 0, ctx);
if (unlikely(err)) {
ntfs_attr_put_search_ctx(ctx);
err = -ENOENT;
goto unm_err_out;
}
si = (STANDARD_INFORMATION*)((u8*)ctx->attr +
......
......@@ -197,7 +197,7 @@ static struct dentry *ntfs_lookup(struct inode *dir_ino, struct dentry *dent,
goto err_out;
}
ctx = ntfs_attr_get_search_ctx(ni, m);
if (!ctx) {
if (unlikely(!ctx)) {
err = -ENOMEM;
goto err_out;
}
......@@ -205,12 +205,14 @@ static struct dentry *ntfs_lookup(struct inode *dir_ino, struct dentry *dent,
ATTR_RECORD *a;
u32 val_len;
if (!ntfs_attr_lookup(AT_FILE_NAME, NULL, 0, 0, 0,
NULL, 0, ctx)) {
err = ntfs_attr_lookup(AT_FILE_NAME, NULL, 0, 0, 0,
NULL, 0, ctx);
if (unlikely(err)) {
ntfs_error(vol->sb, "Inode corrupt: No WIN32 "
"namespace counterpart to DOS "
"file name. Run chkdsk.");
err = -EIO;
if (err == -ENOENT)
err = -EIO;
goto err_out;
}
/* Consistency checks. */
......@@ -372,6 +374,7 @@ struct dentry *ntfs_get_parent(struct dentry *child_dent)
struct inode *parent_vi;
struct dentry *parent_dent;
unsigned long parent_ino;
int err;
ntfs_debug("Entering for inode 0x%lx.", vi->i_ino);
/* Get the mft record of the inode belonging to the child dentry. */
......@@ -385,13 +388,16 @@ struct dentry *ntfs_get_parent(struct dentry *child_dent)
return ERR_PTR(-ENOMEM);
}
try_next:
if (unlikely(!ntfs_attr_lookup(AT_FILE_NAME, NULL, 0, CASE_SENSITIVE,
0, NULL, 0, ctx))) {
err = ntfs_attr_lookup(AT_FILE_NAME, NULL, 0, CASE_SENSITIVE, 0, NULL,
0, ctx);
if (unlikely(err)) {
ntfs_attr_put_search_ctx(ctx);
unmap_mft_record(ni);
ntfs_error(vi->i_sb, "Inode 0x%lx does not have a file name "
"attribute. Run chkdsk.", vi->i_ino);
return ERR_PTR(-ENOENT);
if (err == -ENOENT)
ntfs_error(vi->i_sb, "Inode 0x%lx does not have a "
"file name attribute. Run chkdsk.",
vi->i_ino);
return ERR_PTR(err);
}
attr = ctx->attr;
if (unlikely(attr->non_resident))
......
......@@ -336,11 +336,10 @@ static int ntfs_write_volume_flags(ntfs_volume *vol, const VOLUME_FLAGS flags)
err = -ENOMEM;
goto put_unm_err_out;
}
if (!ntfs_attr_lookup(AT_VOLUME_INFORMATION, NULL, 0, 0, 0, NULL, 0,
ctx)) {
err = -EIO;
err = ntfs_attr_lookup(AT_VOLUME_INFORMATION, NULL, 0, 0, 0, NULL, 0,
ctx);
if (err)
goto put_unm_err_out;
}
vi = (VOLUME_INFORMATION*)((u8*)ctx->attr +
le16_to_cpu(ctx->attr->data.resident.value_offset));
vol->vol_flags = vi->flags = flags;
......@@ -1433,7 +1432,7 @@ static BOOL load_system_files(ntfs_volume *vol)
ntfs_error(sb, "Failed to get attribute search context.");
goto get_ctx_vol_failed;
}
if (!ntfs_attr_lookup(AT_VOLUME_INFORMATION, NULL, 0, 0, 0, NULL, 0,
if (ntfs_attr_lookup(AT_VOLUME_INFORMATION, NULL, 0, 0, 0, NULL, 0,
ctx) || ctx->attr->non_resident || ctx->attr->flags) {
err_put_vol:
ntfs_attr_put_search_ctx(ctx);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment