Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Functions
attrib.h File Reference
#include "endian.h"
#include "types.h"
#include "layout.h"
#include "inode.h"
#include "runlist.h"
#include "volume.h"

Go to the source code of this file.

Data Structures

struct  ntfs_attr_search_ctx
 

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_elementntfs_attr_find_vcn_nolock (ntfs_inode *ni, const VCN vcn, ntfs_attr_search_ctx *ctx)
 
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)
 
int load_attribute_list (ntfs_volume *vol, runlist *rl, u8 *al_start, const s64 size, const s64 initialized_size)
 
void ntfs_attr_reinit_search_ctx (ntfs_attr_search_ctx *ctx)
 
ntfs_attr_search_ctxntfs_attr_get_search_ctx (ntfs_inode *ni, MFT_RECORD *mrec)
 
void ntfs_attr_put_search_ctx (ntfs_attr_search_ctx *ctx)
 

Function Documentation

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.

Definition at line 710 of file attrib.c.

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.

  • If is NULL, the base mft record of must not be mapped on entry and it will be left unmapped on return.
  • If is not NULL, the base mft record must be mapped on entry and it will be left mapped on return.

Definition at line 464 of file attrib.c.

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.

Definition at line 1269 of file attrib.c.

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 
)

Definition at line 1187 of file attrib.c.

void ntfs_attr_put_search_ctx ( ntfs_attr_search_ctx ctx)

ntfs_attr_put_search_ctx - release an attribute search context : attribute search context to free

Release the attribute search context , unmapping an associated extent mft record if present.

Definition at line 1286 of file attrib.c.

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.

Definition at line 1240 of file attrib.c.

LCN ntfs_attr_vcn_to_lcn_nolock ( ntfs_inode ni,
const VCN  vcn,
const bool  write_locked 
)

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:

Return code Meaning / Description

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.

  • If is 'false', i.e. the runlist is locked for reading, the lock may be dropped inside the function so you cannot rely on the runlist still being the same when this function returns.

Definition at line 341 of file attrib.c.

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.

  • This function takes the runlist lock for writing and may modify the runlist.

Definition at line 298 of file attrib.c.

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.

  • If is NULL, the base mft record of must not be mapped on entry and it will be left unmapped on return.
  • If is not NULL, the base mft record must be mapped on entry and it will be left mapped on return.

Definition at line 84 of file attrib.c.