Commit ce06119a authored by Anton Altaparmakov's avatar Anton Altaparmakov

NTFS: Change attrib.c::get_attr_search_ctx() to return the search context

directly instead of taking the address of a pointer. A return value
of NULL means the allocation failed. Updated all callers
appropriately.
parent f2f4aaf9
...@@ -32,6 +32,10 @@ ToDo: ...@@ -32,6 +32,10 @@ ToDo:
- Cleanup: rename mst.c::__post_read_mst_fixup to post_write_mst_fixup - Cleanup: rename mst.c::__post_read_mst_fixup to post_write_mst_fixup
and cleanup the code a bit, removing the unused size parameter. and cleanup the code a bit, removing the unused size parameter.
- Change default fmask to 0177 and update documentation. - Change default fmask to 0177 and update documentation.
- Change attrib.c::get_attr_search_ctx() to return the search context
directly instead of taking the address of a pointer. A return value
of NULL means the allocation failed. Updated all callers
appropriately.
2.0.1 - Minor updates. 2.0.1 - Minor updates.
......
...@@ -265,9 +265,11 @@ static int ntfs_file_readpage(struct file *file, struct page *page) ...@@ -265,9 +265,11 @@ static int ntfs_file_readpage(struct file *file, struct page *page)
goto unl_err_out; goto unl_err_out;
} }
err = get_attr_search_ctx(&ctx, ni, mrec); ctx = get_attr_search_ctx(ni, mrec);
if (err) if (!ctx) {
err = -ENOMEM;
goto unm_unl_err_out; goto unm_unl_err_out;
}
/* Find the data attribute in the mft record. */ /* Find the data attribute in the mft record. */
if (!lookup_attr(AT_DATA, NULL, 0, 0, 0, NULL, 0, ctx)) { if (!lookup_attr(AT_DATA, NULL, 0, 0, 0, NULL, 0, ctx)) {
......
...@@ -797,7 +797,7 @@ int map_run_list(ntfs_inode *ni, VCN vcn) ...@@ -797,7 +797,7 @@ int map_run_list(ntfs_inode *ni, VCN vcn)
const uchar_t *name; const uchar_t *name;
u32 name_len; u32 name_len;
ATTR_TYPES at; ATTR_TYPES at;
int err; int err = 0;
ntfs_debug("Mapping run list part containing vcn 0x%Lx.", ntfs_debug("Mapping run list part containing vcn 0x%Lx.",
(long long)vcn); (long long)vcn);
...@@ -807,9 +807,11 @@ int map_run_list(ntfs_inode *ni, VCN vcn) ...@@ -807,9 +807,11 @@ int map_run_list(ntfs_inode *ni, VCN vcn)
if (IS_ERR(mrec)) if (IS_ERR(mrec))
return PTR_ERR(mrec); return PTR_ERR(mrec);
err = get_attr_search_ctx(&ctx, ni, mrec); ctx = get_attr_search_ctx(ni, mrec);
if (err) if (!ctx) {
err = -ENOMEM;
goto unm_err_out; goto unm_err_out;
}
/* The attribute type is determined from the inode type. */ /* The attribute type is determined from the inode type. */
if (S_ISDIR(VFS_I(ni)->i_mode)) { if (S_ISDIR(VFS_I(ni)->i_mode)) {
...@@ -1561,21 +1563,20 @@ void reinit_attr_search_ctx(attr_search_context *ctx) ...@@ -1561,21 +1563,20 @@ void reinit_attr_search_ctx(attr_search_context *ctx)
/** /**
* get_attr_search_ctx - allocate and initialize a new attribute search context * get_attr_search_ctx - allocate and initialize a new attribute search context
* @ctx: address of pointer in which to return the new search context
* @ni: ntfs inode with which to initialize the search context * @ni: ntfs inode with which to initialize the search context
* @mrec: mft record with which to initialize the search context * @mrec: mft record with which to initialize the search context
* *
* Allocate a new attribute search context, initialize it with @ni and @mrec, * Allocate a new attribute search context, initialize it with @ni and @mrec,
* and return it in *@ctx. Return 0 on success or -ENOMEM if allocation failed. * and return it. Return NULL if allocation failed.
*/ */
int get_attr_search_ctx(attr_search_context **ctx, ntfs_inode *ni, attr_search_context *get_attr_search_ctx(ntfs_inode *ni, MFT_RECORD *mrec)
MFT_RECORD *mrec)
{ {
*ctx = kmem_cache_alloc(ntfs_attr_ctx_cache, SLAB_NOFS); attr_search_context *ctx;
if (unlikely(!*ctx))
return -ENOMEM; ctx = kmem_cache_alloc(ntfs_attr_ctx_cache, SLAB_NOFS);
init_attr_search_ctx(*ctx, ni, mrec); if (ctx)
return 0; init_attr_search_ctx(ctx, ni, mrec);
return NULL;
} }
/** /**
...@@ -1583,7 +1584,7 @@ int get_attr_search_ctx(attr_search_context **ctx, ntfs_inode *ni, ...@@ -1583,7 +1584,7 @@ int get_attr_search_ctx(attr_search_context **ctx, ntfs_inode *ni,
* @ctx: attribute search context to free * @ctx: attribute search context to free
* *
* Release the attribute search context @ctx, unmapping an associated extent * Release the attribute search context @ctx, unmapping an associated extent
* mft record if prseent. * mft record if present.
*/ */
void put_attr_search_ctx(attr_search_context *ctx) void put_attr_search_ctx(attr_search_context *ctx)
{ {
......
...@@ -98,7 +98,7 @@ static inline s64 attribute_value_length(const ATTR_RECORD *a) ...@@ -98,7 +98,7 @@ static inline s64 attribute_value_length(const ATTR_RECORD *a)
} }
extern void reinit_attr_search_ctx(attr_search_context *ctx); extern void reinit_attr_search_ctx(attr_search_context *ctx);
extern int get_attr_search_ctx(attr_search_context **ctx, ntfs_inode *ni, extern attr_search_context *get_attr_search_ctx(ntfs_inode *ni,
MFT_RECORD *mrec); MFT_RECORD *mrec);
extern void put_attr_search_ctx(attr_search_context *ctx); extern void put_attr_search_ctx(attr_search_context *ctx);
......
...@@ -61,7 +61,7 @@ u64 ntfs_lookup_inode_by_name(ntfs_inode *dir_ni, const uchar_t *uname, ...@@ -61,7 +61,7 @@ u64 ntfs_lookup_inode_by_name(ntfs_inode *dir_ni, const uchar_t *uname,
u8 *index_end; u8 *index_end;
u64 mref; u64 mref;
attr_search_context *ctx; attr_search_context *ctx;
int err, rc; int err = 0, rc;
IGNORE_CASE_BOOL ic; IGNORE_CASE_BOOL ic;
VCN vcn, old_vcn; VCN vcn, old_vcn;
struct address_space *ia_mapping; struct address_space *ia_mapping;
...@@ -73,9 +73,11 @@ u64 ntfs_lookup_inode_by_name(ntfs_inode *dir_ni, const uchar_t *uname, ...@@ -73,9 +73,11 @@ u64 ntfs_lookup_inode_by_name(ntfs_inode *dir_ni, const uchar_t *uname,
if (IS_ERR(m)) if (IS_ERR(m))
goto map_err_out; goto map_err_out;
err = get_attr_search_ctx(&ctx, dir_ni, m); ctx = get_attr_search_ctx(dir_ni, m);
if (err) if (!ctx) {
err = -ENOMEM;
goto unm_err_out; goto unm_err_out;
}
/* Find the index root attribute in the mft record. */ /* Find the index root attribute in the mft record. */
if (!lookup_attr(AT_INDEX_ROOT, I30, 4, CASE_SENSITIVE, 0, NULL, 0, if (!lookup_attr(AT_INDEX_ROOT, I30, 4, CASE_SENSITIVE, 0, NULL, 0,
...@@ -555,9 +557,11 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir) ...@@ -555,9 +557,11 @@ static int ntfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
goto err_out; goto err_out;
} }
err = get_attr_search_ctx(&ctx, ndir, m); ctx = get_attr_search_ctx(ndir, m);
if (err) if (!ctx) {
err = -ENOMEM;
goto unm_err_out; goto unm_err_out;
}
/* /*
* Allocate a buffer to store the current name being processed * Allocate a buffer to store the current name being processed
......
...@@ -298,9 +298,11 @@ void ntfs_read_inode(struct inode *vi) ...@@ -298,9 +298,11 @@ void ntfs_read_inode(struct inode *vi)
} else } else
vi->i_mode |= S_IFREG; vi->i_mode |= S_IFREG;
err = get_attr_search_ctx(&ctx, ni, m); ctx = get_attr_search_ctx(ni, m);
if (err) if (!ctx) {
err = -ENOMEM;
goto unm_err_out; goto unm_err_out;
}
/* /*
* Find the standard information attribute in the mft record. At this * Find the standard information attribute in the mft record. At this
...@@ -915,9 +917,11 @@ void ntfs_read_inode_mount(struct inode *vi) ...@@ -915,9 +917,11 @@ void ntfs_read_inode_mount(struct inode *vi)
/* Provides readpage() and sync_page() for map_mft_record(READ). */ /* Provides readpage() and sync_page() for map_mft_record(READ). */
vi->i_mapping->a_ops = &ntfs_mft_aops; vi->i_mapping->a_ops = &ntfs_mft_aops;
err = get_attr_search_ctx(&ctx, ni, m); ctx = get_attr_search_ctx(ni, m);
if (err) if (!ctx) {
err = -ENOMEM;
goto err_out; goto err_out;
}
/* Find the attribute list attribute if present. */ /* Find the attribute list attribute if present. */
if (lookup_attr(AT_ATTRIBUTE_LIST, NULL, 0, 0, 0, NULL, 0, ctx)) { if (lookup_attr(AT_ATTRIBUTE_LIST, NULL, 0, 0, 0, NULL, 0, ctx)) {
......
...@@ -816,7 +816,7 @@ static BOOL load_system_files(ntfs_volume *vol) ...@@ -816,7 +816,7 @@ static BOOL load_system_files(ntfs_volume *vol)
ntfs_error(sb, "Failed to map $MFT."); ntfs_error(sb, "Failed to map $MFT.");
return FALSE; return FALSE;
} }
if (get_attr_search_ctx(&ctx, NTFS_I(vol->mft_ino), m)) { if (!(ctx = get_attr_search_ctx(NTFS_I(vol->mft_ino), m))) {
ntfs_error(sb, "Failed to get attribute search context."); ntfs_error(sb, "Failed to get attribute search context.");
goto unmap_err_out; goto unmap_err_out;
} }
...@@ -985,7 +985,7 @@ static BOOL load_system_files(ntfs_volume *vol) ...@@ -985,7 +985,7 @@ static BOOL load_system_files(ntfs_volume *vol)
iput(vol->vol_ino); iput(vol->vol_ino);
goto volume_failed; goto volume_failed;
} }
if (get_attr_search_ctx(&ctx, NTFS_I(vol->vol_ino), m)) { if (!(ctx = get_attr_search_ctx(NTFS_I(vol->vol_ino), m))) {
ntfs_error(sb, "Failed to get attribute search context."); ntfs_error(sb, "Failed to get attribute search context.");
goto get_ctx_vol_failed; goto get_ctx_vol_failed;
} }
......
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