patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / fs / ntfs / attrib.h
1 /*
2  * attrib.h - Defines for attribute handling in NTFS Linux kernel driver.
3  *            Part of the Linux-NTFS project.
4  *
5  * Copyright (c) 2001-2004 Anton Altaparmakov
6  * Copyright (c) 2002 Richard Russon
7  *
8  * This program/include file is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as published
10  * by the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program/include file is distributed in the hope that it will be
14  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
15  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program (in the main directory of the Linux-NTFS
20  * distribution in the file COPYING); if not, write to the Free Software
21  * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22  */
23
24 #ifndef _LINUX_NTFS_ATTRIB_H
25 #define _LINUX_NTFS_ATTRIB_H
26
27 #include <linux/fs.h>
28
29 #include "endian.h"
30 #include "types.h"
31 #include "layout.h"
32
33 static inline void init_run_list(run_list *rl)
34 {
35         rl->rl = NULL;
36         init_rwsem(&rl->lock);
37 }
38
39 typedef enum {
40         LCN_HOLE                = -1,   /* Keep this as highest value or die! */
41         LCN_RL_NOT_MAPPED       = -2,
42         LCN_ENOENT              = -3,
43         LCN_EINVAL              = -4,
44 } LCN_SPECIAL_VALUES;
45
46 /**
47  * attr_search_context - used in attribute search functions
48  * @mrec:       buffer containing mft record to search
49  * @attr:       attribute record in @mrec where to begin/continue search
50  * @is_first:   if true lookup_attr() begins search with @attr, else after @attr
51  *
52  * Structure must be initialized to zero before the first call to one of the
53  * attribute search functions. Initialize @mrec to point to the mft record to
54  * search, and @attr to point to the first attribute within @mrec (not necessary
55  * if calling the _first() functions), and set @is_first to TRUE (not necessary
56  * if calling the _first() functions).
57  *
58  * If @is_first is TRUE, the search begins with @attr. If @is_first is FALSE,
59  * the search begins after @attr. This is so that, after the first call to one
60  * of the search attribute functions, we can call the function again, without
61  * any modification of the search context, to automagically get the next
62  * matching attribute.
63  */
64 typedef struct {
65         MFT_RECORD *mrec;
66         ATTR_RECORD *attr;
67         BOOL is_first;
68         ntfs_inode *ntfs_ino;
69         ATTR_LIST_ENTRY *al_entry;
70         ntfs_inode *base_ntfs_ino;
71         MFT_RECORD *base_mrec;
72         ATTR_RECORD *base_attr;
73 } attr_search_context;
74
75 extern run_list_element *decompress_mapping_pairs(const ntfs_volume *vol,
76                 const ATTR_RECORD *attr, run_list_element *old_rl);
77
78 extern int map_run_list(ntfs_inode *ni, VCN vcn);
79
80 extern LCN vcn_to_lcn(const run_list_element *rl, const VCN vcn);
81
82 extern BOOL find_attr(const ATTR_TYPES type, const ntfschar *name,
83                 const u32 name_len, const IGNORE_CASE_BOOL ic, const u8 *val,
84                 const u32 val_len, attr_search_context *ctx);
85
86 BOOL lookup_attr(const ATTR_TYPES type, const ntfschar *name,
87                 const u32 name_len, const IGNORE_CASE_BOOL ic,
88                 const VCN lowest_vcn, const u8 *val, const u32 val_len,
89                 attr_search_context *ctx);
90
91 extern int load_attribute_list(ntfs_volume *vol, run_list *rl, u8 *al_start,
92                 const s64 size, const s64 initialized_size);
93
94 static inline s64 attribute_value_length(const ATTR_RECORD *a)
95 {
96         if (!a->non_resident)
97                 return (s64)le32_to_cpu(a->data.resident.value_length);
98         return sle64_to_cpu(a->data.non_resident.data_size);
99 }
100
101 extern void reinit_attr_search_ctx(attr_search_context *ctx);
102 extern attr_search_context *get_attr_search_ctx(ntfs_inode *ni,
103                 MFT_RECORD *mrec);
104 extern void put_attr_search_ctx(attr_search_context *ctx);
105
106 #endif /* _LINUX_NTFS_ATTRIB_H */