Linux Kernel
3.7.1
|
#include <linux/buffer_head.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/swap.h>
#include <linux/writeback.h>
#include "attrib.h"
#include "debug.h"
#include "layout.h"
#include "lcnalloc.h"
#include "malloc.h"
#include "mft.h"
#include "ntfs.h"
#include "types.h"
Go to the source code of this file.
Functions | |
int | ntfs_map_runlist_nolock (ntfs_inode *ni, VCN vcn, ntfs_attr_search_ctx *ctx) |
int | ntfs_map_runlist (ntfs_inode *ni, VCN vcn) |
LCN | ntfs_attr_vcn_to_lcn_nolock (ntfs_inode *ni, const VCN vcn, const bool write_locked) |
runlist_element * | ntfs_attr_find_vcn_nolock (ntfs_inode *ni, const VCN vcn, ntfs_attr_search_ctx *ctx) |
is not present (NULL), we assume that the unnamed attribute is | |
being searched for. Finally, the resident attribute value is looked for, if present. If is not present (NULL), is ignored. ntfs_attr_find() only searches the specified mft record and it ignores the presence of an attribute list attribute (unless it is the one being searched for, obviously). If you need to take attribute lists into consideration, use ntfs_attr_lookup() instead (see below). This also means that you cannot use ntfs_attr_find() to search for extent records of non-resident attributes, as extents with lowest_vcn != 0 are usually described by the attribute list attribute only. - Note that it is possible that the first extent is only in the attribute list while the last extent is in the base mft record, so do not rely on being able to find the first extent in the base mft record. Warning: Never use when looking for attribute types which can be non-resident as this most likely will result in a crash! | |
int | load_attribute_list (ntfs_volume *vol, runlist *runlist, u8 *al_start, const s64 size, const s64 initialized_size) |
not present) | |
: lowest vcn to find (optional, non-resident attributes only) : attribute value to find (optional, resident attributes only) : attribute value length : search context with mft record and attribute to search from Find an attribute in an ntfs inode. On first search ->ntfs_ino must be the base mft record and must have been obtained from a call to ntfs_attr_get_search_ctx(). This function transparently handles attribute lists and is used to continue searches where they were left off at. After finishing with the attribute/mft record you need to call ntfs_attr_put_search_ctx() to cleanup the search context (unmapping any mapped inodes, etc). Return 0 if the search was successful and -errno if not. When 0, ->attr is the found attribute and it is in mft record ->mrec. If an attribute list attribute is present, ->al_entry is the attribute list entry of the found attribute. When -ENOENT, ->attr is the attribute which collates just after the attribute being searched for, i.e. if one wants to add the attribute to the mft record this is the correct place to insert it into. If an attribute list attribute is present, ->al_entry is the attribute list entry which collates just after the attribute list entry of the attribute being searched for, i.e. if one wants to add the attribute to the mft record this is the correct place to insert its attribute list entry into. When -errno != -ENOENT, an error occurred during the lookup. ->attr is then undefined and in particular you should not rely on it not changing. | |
int | ntfs_attr_lookup (const ATTR_TYPE 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) |
void | ntfs_attr_reinit_search_ctx (ntfs_attr_search_ctx *ctx) |
ntfs_attr_search_ctx * | ntfs_attr_get_search_ctx (ntfs_inode *ni, MFT_RECORD *mrec) |
void | ntfs_attr_put_search_ctx (ntfs_attr_search_ctx *ctx) |
int load_attribute_list | ( | ntfs_volume * | vol, |
runlist * | runlist, | ||
u8 * | al_start, | ||
const s64 | size, | ||
const s64 | initialized_size | ||
) |
load_attribute_list - load an attribute list into memory : ntfs volume from which to read : runlist of the attribute list : destination buffer : size of the destination buffer in bytes : initialized size of the attribute list
Walk the runlist and load all clusters from it copying them into the linear buffer . The maximum number of bytes copied to is bytes. Note, does not need to be a multiple of the cluster size. If is less than , the region in between and will be zeroed and not read from disk.
Return 0 on success or -errno on error.
runlist_element* ntfs_attr_find_vcn_nolock | ( | ntfs_inode * | ni, |
const VCN | vcn, | ||
ntfs_attr_search_ctx * | ctx | ||
) |
ntfs_attr_find_vcn_nolock - find a vcn in the runlist of an ntfs inode : ntfs inode describing the runlist to search : vcn to find : active attribute search context if present or NULL if not
Find the virtual cluster number in the runlist described by the ntfs inode and return the address of the runlist element containing the .
If the is not mapped yet, the attempt is made to map the attribute extent containing the and the vcn to lcn conversion is retried.
If is specified, it is an active search context of and its base mft record. This is needed when ntfs_attr_find_vcn_nolock() encounters unmapped runlist fragments and allows their mapping. If you do not have the mft record mapped, you can specify as NULL and ntfs_attr_find_vcn_nolock() will perform the necessary mapping and unmapping.
Note, ntfs_attr_find_vcn_nolock() saves the state of on entry and restores it before returning. Thus, will be left pointing to the same attribute on return as on entry. However, the actual pointers in may point to different memory locations on return, so you must remember to reset any cached pointers from the , i.e. after the call to ntfs_attr_find_vcn_nolock(), you will probably want to do: m = ctx->mrec; a = ctx->attr; Assuming you cache ctx->attr in a variable of type ATTR_RECORD * and that you cache ctx->mrec in a variable of type MFT_RECORD *. Note you need to distinguish between the lcn of the returned runlist element being >= 0 and LCN_HOLE. In the later case you have to return zeroes on read and allocate clusters on write.
Return the runlist element containing the on success and ERR_PTR(-errno) on error. You need to test the return value with IS_ERR() to decide if the return is success or failure and PTR_ERR() to get to the error code if IS_ERR() is true.
The possible error return codes are: -ENOENT - No such vcn in the runlist, i.e. is out of bounds. -ENOMEM - Not enough memory to map runlist. -EIO - Critical error (runlist/file is corrupt, i/o error, etc).
WARNING: If is supplied, regardless of whether success or failure is returned, you need to check IS_ERR(->mrec) and if 'true' the is no longer valid, i.e. you need to either call ntfs_attr_reinit_search_ctx() or ntfs_attr_put_search_ctx() on it. In that case PTR_ERR(->mrec) will give you the error code for why the mapping of the old inode failed.
Locking: - The runlist described by must be locked for writing on entry and is locked on return. Note the runlist may be modified when needed runlist fragments need to be mapped.
ntfs_attr_search_ctx* ntfs_attr_get_search_ctx | ( | ntfs_inode * | ni, |
MFT_RECORD * | mrec | ||
) |
ntfs_attr_get_search_ctx - allocate/initialize a new attribute search context : ntfs inode with which to initialize the search context : mft record with which to initialize the search context
Allocate a new attribute search context, initialize it with and , and return it. Return NULL if allocation failed.
void ntfs_attr_put_search_ctx | ( | ntfs_attr_search_ctx * | ctx | ) |
void ntfs_attr_reinit_search_ctx | ( | ntfs_attr_search_ctx * | ctx | ) |
ntfs_attr_reinit_search_ctx - reinitialize an attribute search context : attribute search context to reinitialize
Reinitialize the attribute search context , unmapping an associated extent mft record if present, and initialize the search context again.
This is used when a search for a new attribute is being started to reset the search context to the beginning.
ntfs_attr_vcn_to_lcn_nolock - convert a vcn into a lcn given an ntfs inode : ntfs inode of the attribute whose runlist to search : vcn to convert : true if the runlist is locked for writing
Find the virtual cluster number in the runlist of the ntfs attribute described by the ntfs inode and return the corresponding logical cluster number (lcn).
If the is not mapped yet, the attempt is made to map the attribute extent containing the and the vcn to lcn conversion is retried.
If is true the caller has locked the runlist for writing and if false for reading.
Since lcns must be >= 0, we use negative return codes with special meaning:
LCN_HOLE Hole / not allocated on disk. LCN_ENOENT There is no such vcn in the runlist, i.e. is out of bounds. LCN_ENOMEM Not enough memory to map runlist. LCN_EIO Critical error (runlist/file is corrupt, i/o error, etc).
Locking: - The runlist must be locked on entry and is left locked on return.
int ntfs_map_runlist | ( | ntfs_inode * | ni, |
VCN | vcn | ||
) |
ntfs_map_runlist - map (a part of) a runlist of an ntfs inode : ntfs inode for which to map (part of) a runlist : map runlist part containing this vcn
Map the part of a runlist containing the of the ntfs inode .
Return 0 on success and -errno on error. There is one special error code which is not an error as such. This is -ENOENT. It means that is out of bounds of the runlist.
Locking: - The runlist must be unlocked on entry and is unlocked on return.
int ntfs_map_runlist_nolock | ( | ntfs_inode * | ni, |
VCN | vcn, | ||
ntfs_attr_search_ctx * | ctx | ||
) |
attrib.c - NTFS attribute operations. Part of the Linux-NTFS project.
Copyright (c) 2001-2012 Anton Altaparmakov and Tuxera Inc. Copyright (c) 2002 Richard Russon
This program/include file is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program/include file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program (in the main directory of the Linux-NTFS distribution in the file COPYING); if not, write to the Free Software Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ntfs_map_runlist_nolock - map (a part of) a runlist of an ntfs inode : ntfs inode for which to map (part of) a runlist : map runlist part containing this vcn : active attribute search context if present or NULL if not
Map the part of a runlist containing the of the ntfs inode .
If is specified, it is an active search context of and its base mft record. This is needed when ntfs_map_runlist_nolock() encounters unmapped runlist fragments and allows their mapping. If you do not have the mft record mapped, you can specify as NULL and ntfs_map_runlist_nolock() will perform the necessary mapping and unmapping.
Note, ntfs_map_runlist_nolock() saves the state of on entry and restores it before returning. Thus, will be left pointing to the same attribute on return as on entry. However, the actual pointers in may point to different memory locations on return, so you must remember to reset any cached pointers from the , i.e. after the call to ntfs_map_runlist_nolock(), you will probably want to do: m = ctx->mrec; a = ctx->attr; Assuming you cache ctx->attr in a variable of type ATTR_RECORD * and that you cache ctx->mrec in a variable of type MFT_RECORD *.
Return 0 on success and -errno on error. There is one special error code which is not an error as such. This is -ENOENT. It means that is out of bounds of the runlist.
Note the runlist can be NULL after this function returns if is zero and the attribute has zero allocated size, i.e. there simply is no runlist.
WARNING: If is supplied, regardless of whether success or failure is returned, you need to check IS_ERR(->mrec) and if 'true' the is no longer valid, i.e. you need to either call ntfs_attr_reinit_search_ctx() or ntfs_attr_put_search_ctx() on it. In that case PTR_ERR(->mrec) will give you the error code for why the mapping of the old inode failed.
Locking: - The runlist described by must be locked for writing on entry and is locked on return. Note the runlist will be modified.