1*9663SMark.Logan@Sun.COM /*
2*9663SMark.Logan@Sun.COM * attrib.h - Exports for attribute handling. Part of the Linux-NTFS project.
3*9663SMark.Logan@Sun.COM *
4*9663SMark.Logan@Sun.COM * Copyright (c) 2000-2004 Anton Altaparmakov
5*9663SMark.Logan@Sun.COM * Copyright (c) 2004-2007 Yura Pakhuchiy
6*9663SMark.Logan@Sun.COM *
7*9663SMark.Logan@Sun.COM * This program/include file is free software; you can redistribute it and/or
8*9663SMark.Logan@Sun.COM * modify it under the terms of the GNU General Public License as published
9*9663SMark.Logan@Sun.COM * by the Free Software Foundation; either version 2 of the License, or
10*9663SMark.Logan@Sun.COM * (at your option) any later version.
11*9663SMark.Logan@Sun.COM *
12*9663SMark.Logan@Sun.COM * This program/include file is distributed in the hope that it will be
13*9663SMark.Logan@Sun.COM * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
14*9663SMark.Logan@Sun.COM * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15*9663SMark.Logan@Sun.COM * GNU General Public License for more details.
16*9663SMark.Logan@Sun.COM *
17*9663SMark.Logan@Sun.COM * You should have received a copy of the GNU General Public License
18*9663SMark.Logan@Sun.COM * along with this program (in the main directory of the Linux-NTFS
19*9663SMark.Logan@Sun.COM * distribution in the file COPYING); if not, write to the Free Software
20*9663SMark.Logan@Sun.COM * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21*9663SMark.Logan@Sun.COM */
22*9663SMark.Logan@Sun.COM
23*9663SMark.Logan@Sun.COM #ifndef _NTFS_ATTRIB_H
24*9663SMark.Logan@Sun.COM #define _NTFS_ATTRIB_H
25*9663SMark.Logan@Sun.COM
26*9663SMark.Logan@Sun.COM /* Forward declarations */
27*9663SMark.Logan@Sun.COM typedef struct _ntfs_attr ntfs_attr;
28*9663SMark.Logan@Sun.COM typedef struct _ntfs_attr_search_ctx ntfs_attr_search_ctx;
29*9663SMark.Logan@Sun.COM
30*9663SMark.Logan@Sun.COM #include "list.h"
31*9663SMark.Logan@Sun.COM #include "types.h"
32*9663SMark.Logan@Sun.COM #include "inode.h"
33*9663SMark.Logan@Sun.COM #include "unistr.h"
34*9663SMark.Logan@Sun.COM #include "runlist.h"
35*9663SMark.Logan@Sun.COM #include "volume.h"
36*9663SMark.Logan@Sun.COM #include "debug.h"
37*9663SMark.Logan@Sun.COM #include "logging.h"
38*9663SMark.Logan@Sun.COM #include "crypto.h"
39*9663SMark.Logan@Sun.COM
40*9663SMark.Logan@Sun.COM extern ntfschar AT_UNNAMED[];
41*9663SMark.Logan@Sun.COM
42*9663SMark.Logan@Sun.COM /**
43*9663SMark.Logan@Sun.COM * enum ntfs_lcn_special_values - special return values for ntfs_*_vcn_to_lcn()
44*9663SMark.Logan@Sun.COM *
45*9663SMark.Logan@Sun.COM * Special return values for ntfs_rl_vcn_to_lcn() and ntfs_attr_vcn_to_lcn().
46*9663SMark.Logan@Sun.COM *
47*9663SMark.Logan@Sun.COM * TODO: Describe them.
48*9663SMark.Logan@Sun.COM */
49*9663SMark.Logan@Sun.COM typedef enum {
50*9663SMark.Logan@Sun.COM LCN_HOLE = -1, /* Keep this as highest value or die! */
51*9663SMark.Logan@Sun.COM LCN_RL_NOT_MAPPED = -2,
52*9663SMark.Logan@Sun.COM LCN_ENOENT = -3,
53*9663SMark.Logan@Sun.COM LCN_EINVAL = -4,
54*9663SMark.Logan@Sun.COM LCN_EIO = -5,
55*9663SMark.Logan@Sun.COM } ntfs_lcn_special_values;
56*9663SMark.Logan@Sun.COM
57*9663SMark.Logan@Sun.COM /**
58*9663SMark.Logan@Sun.COM * struct ntfs_attr_search_ctx - search context used in attribute search functions
59*9663SMark.Logan@Sun.COM * @mrec: buffer containing mft record to search
60*9663SMark.Logan@Sun.COM * @attr: attribute record in @mrec where to begin/continue search
61*9663SMark.Logan@Sun.COM * @is_first: if true lookup_attr() begins search with @attr, else after @attr
62*9663SMark.Logan@Sun.COM *
63*9663SMark.Logan@Sun.COM * Structure must be initialized to zero before the first call to one of the
64*9663SMark.Logan@Sun.COM * attribute search functions. Initialize @mrec to point to the mft record to
65*9663SMark.Logan@Sun.COM * search, and @attr to point to the first attribute within @mrec (not necessary
66*9663SMark.Logan@Sun.COM * if calling the _first() functions), and set @is_first to TRUE (not necessary
67*9663SMark.Logan@Sun.COM * if calling the _first() functions).
68*9663SMark.Logan@Sun.COM *
69*9663SMark.Logan@Sun.COM * If @is_first is TRUE, the search begins with @attr. If @is_first is FALSE,
70*9663SMark.Logan@Sun.COM * the search begins after @attr. This is so that, after the first call to one
71*9663SMark.Logan@Sun.COM * of the search attribute functions, we can call the function again, without
72*9663SMark.Logan@Sun.COM * any modification of the search context, to automagically get the next
73*9663SMark.Logan@Sun.COM * matching attribute.
74*9663SMark.Logan@Sun.COM */
75*9663SMark.Logan@Sun.COM struct _ntfs_attr_search_ctx {
76*9663SMark.Logan@Sun.COM MFT_RECORD *mrec;
77*9663SMark.Logan@Sun.COM ATTR_RECORD *attr;
78*9663SMark.Logan@Sun.COM BOOL is_first;
79*9663SMark.Logan@Sun.COM ntfs_inode *ntfs_ino;
80*9663SMark.Logan@Sun.COM ATTR_LIST_ENTRY *al_entry;
81*9663SMark.Logan@Sun.COM ntfs_inode *base_ntfs_ino;
82*9663SMark.Logan@Sun.COM MFT_RECORD *base_mrec;
83*9663SMark.Logan@Sun.COM ATTR_RECORD *base_attr;
84*9663SMark.Logan@Sun.COM };
85*9663SMark.Logan@Sun.COM
86*9663SMark.Logan@Sun.COM extern void ntfs_attr_reinit_search_ctx(ntfs_attr_search_ctx *ctx);
87*9663SMark.Logan@Sun.COM extern ntfs_attr_search_ctx *ntfs_attr_get_search_ctx(ntfs_inode *ni,
88*9663SMark.Logan@Sun.COM MFT_RECORD *mrec);
89*9663SMark.Logan@Sun.COM extern void ntfs_attr_put_search_ctx(ntfs_attr_search_ctx *ctx);
90*9663SMark.Logan@Sun.COM
91*9663SMark.Logan@Sun.COM extern int ntfs_attr_lookup(const ATTR_TYPES type, const ntfschar *name,
92*9663SMark.Logan@Sun.COM const u32 name_len, const IGNORE_CASE_BOOL ic,
93*9663SMark.Logan@Sun.COM const VCN lowest_vcn, const u8 *val, const u32 val_len,
94*9663SMark.Logan@Sun.COM ntfs_attr_search_ctx *ctx);
95*9663SMark.Logan@Sun.COM
96*9663SMark.Logan@Sun.COM extern ATTR_DEF *ntfs_attr_find_in_attrdef(const ntfs_volume *vol,
97*9663SMark.Logan@Sun.COM const ATTR_TYPES type);
98*9663SMark.Logan@Sun.COM
99*9663SMark.Logan@Sun.COM /**
100*9663SMark.Logan@Sun.COM * ntfs_attrs_walk - syntactic sugar for walking all attributes in an inode
101*9663SMark.Logan@Sun.COM * @ctx: initialised attribute search context
102*9663SMark.Logan@Sun.COM *
103*9663SMark.Logan@Sun.COM * Syntactic sugar for walking attributes in an inode.
104*9663SMark.Logan@Sun.COM *
105*9663SMark.Logan@Sun.COM * Return 0 on success and -1 on error with errno set to the error code from
106*9663SMark.Logan@Sun.COM * ntfs_attr_lookup().
107*9663SMark.Logan@Sun.COM *
108*9663SMark.Logan@Sun.COM * Example: When you want to enumerate all attributes in an open ntfs inode
109*9663SMark.Logan@Sun.COM * @ni, you can simply do:
110*9663SMark.Logan@Sun.COM *
111*9663SMark.Logan@Sun.COM * int err;
112*9663SMark.Logan@Sun.COM * ntfs_attr_search_ctx *ctx = ntfs_attr_get_search_ctx(ni, NULL);
113*9663SMark.Logan@Sun.COM * if (!ctx)
114*9663SMark.Logan@Sun.COM * // Error code is in errno. Handle this case.
115*9663SMark.Logan@Sun.COM * while (!(err = ntfs_attrs_walk(ctx))) {
116*9663SMark.Logan@Sun.COM * ATTR_RECORD *attr = ctx->attr;
117*9663SMark.Logan@Sun.COM * // attr now contains the next attribute. Do whatever you want
118*9663SMark.Logan@Sun.COM * // with it and then just continue with the while loop.
119*9663SMark.Logan@Sun.COM * }
120*9663SMark.Logan@Sun.COM * if (err && errno != ENOENT)
121*9663SMark.Logan@Sun.COM * // Ooops. An error occurred! You should handle this case.
122*9663SMark.Logan@Sun.COM * // Now finished with all attributes in the inode.
123*9663SMark.Logan@Sun.COM */
ntfs_attrs_walk(ntfs_attr_search_ctx * ctx)124*9663SMark.Logan@Sun.COM static __inline__ int ntfs_attrs_walk(ntfs_attr_search_ctx *ctx)
125*9663SMark.Logan@Sun.COM {
126*9663SMark.Logan@Sun.COM return ntfs_attr_lookup(AT_UNUSED, NULL, 0, CASE_SENSITIVE, 0,
127*9663SMark.Logan@Sun.COM NULL, 0, ctx);
128*9663SMark.Logan@Sun.COM }
129*9663SMark.Logan@Sun.COM
130*9663SMark.Logan@Sun.COM /**
131*9663SMark.Logan@Sun.COM * struct ntfs_attr - ntfs in memory non-resident attribute structure
132*9663SMark.Logan@Sun.COM * @rl: if not NULL, the decompressed runlist
133*9663SMark.Logan@Sun.COM * @ni: base ntfs inode to which this attribute belongs
134*9663SMark.Logan@Sun.COM * @type: attribute type
135*9663SMark.Logan@Sun.COM * @name: Unicode name of the attribute
136*9663SMark.Logan@Sun.COM * @name_len: length of @name in Unicode characters
137*9663SMark.Logan@Sun.COM * @state: NTFS attribute specific flags describing this attribute
138*9663SMark.Logan@Sun.COM * @allocated_size: copy from the attribute record
139*9663SMark.Logan@Sun.COM * @data_size: copy from the attribute record
140*9663SMark.Logan@Sun.COM * @initialized_size: copy from the attribute record
141*9663SMark.Logan@Sun.COM * @compressed_size: copy from the attribute record
142*9663SMark.Logan@Sun.COM * @compression_block_size: size of a compression block (cb)
143*9663SMark.Logan@Sun.COM * @compression_block_size_bits: log2 of the size of a cb
144*9663SMark.Logan@Sun.COM * @compression_block_clusters: number of clusters per cb
145*9663SMark.Logan@Sun.COM * @crypto: (valid only for encrypted) see description below
146*9663SMark.Logan@Sun.COM *
147*9663SMark.Logan@Sun.COM * This structure exists purely to provide a mechanism of caching the runlist
148*9663SMark.Logan@Sun.COM * of an attribute. If you want to operate on a particular attribute extent,
149*9663SMark.Logan@Sun.COM * you should not be using this structure at all. If you want to work with a
150*9663SMark.Logan@Sun.COM * resident attribute, you should not be using this structure at all. As a
151*9663SMark.Logan@Sun.COM * fail-safe check make sure to test NAttrNonResident() and if it is false, you
152*9663SMark.Logan@Sun.COM * know you shouldn't be using this structure.
153*9663SMark.Logan@Sun.COM *
154*9663SMark.Logan@Sun.COM * If you want to work on a resident attribute or on a specific attribute
155*9663SMark.Logan@Sun.COM * extent, you should use ntfs_lookup_attr() to retrieve the attribute (extent)
156*9663SMark.Logan@Sun.COM * record, edit that, and then write back the mft record (or set the
157*9663SMark.Logan@Sun.COM * corresponding ntfs inode dirty for delayed write back).
158*9663SMark.Logan@Sun.COM *
159*9663SMark.Logan@Sun.COM * @rl is the decompressed runlist of the attribute described by this
160*9663SMark.Logan@Sun.COM * structure. Obviously this only makes sense if the attribute is not resident,
161*9663SMark.Logan@Sun.COM * i.e. NAttrNonResident() is true. If the runlist hasn't been decompressed yet
162*9663SMark.Logan@Sun.COM * @rl is NULL, so be prepared to cope with @rl == NULL.
163*9663SMark.Logan@Sun.COM *
164*9663SMark.Logan@Sun.COM * @ni is the base ntfs inode of the attribute described by this structure.
165*9663SMark.Logan@Sun.COM *
166*9663SMark.Logan@Sun.COM * @type is the attribute type (see layout.h for the definition of ATTR_TYPES),
167*9663SMark.Logan@Sun.COM * @name and @name_len are the little endian Unicode name and the name length
168*9663SMark.Logan@Sun.COM * in Unicode characters of the attribute, respectively.
169*9663SMark.Logan@Sun.COM *
170*9663SMark.Logan@Sun.COM * @state contains NTFS attribute specific flags describing this attribute
171*9663SMark.Logan@Sun.COM * structure. See ntfs_attr_state_bits above.
172*9663SMark.Logan@Sun.COM *
173*9663SMark.Logan@Sun.COM * @crypto points to private structure of crypto code. You should not access
174*9663SMark.Logan@Sun.COM * fields of this structure, but you can check whether it is NULL or not. If it
175*9663SMark.Logan@Sun.COM * is not NULL, then we successfully obtained FEK (File Encryption Key) and
176*9663SMark.Logan@Sun.COM * ntfs_attr_p{read,write} calls probably would succeed. If it is NULL, then we
177*9663SMark.Logan@Sun.COM * failed to obtain FEK (do not have corresponding PFX file, wrong password,
178*9663SMark.Logan@Sun.COM * etc..) or library was compiled without crypto support. Attribute size can be
179*9663SMark.Logan@Sun.COM * changed without knowledge of FEK, so you can use ntfs_attr_truncate in any
180*9663SMark.Logan@Sun.COM * case.
181*9663SMark.Logan@Sun.COM * NOTE: This field valid only if attribute encrypted (eg., NAttrEncrypted
182*9663SMark.Logan@Sun.COM * returns non-zero).
183*9663SMark.Logan@Sun.COM */
184*9663SMark.Logan@Sun.COM struct _ntfs_attr {
185*9663SMark.Logan@Sun.COM runlist_element *rl;
186*9663SMark.Logan@Sun.COM ntfs_inode *ni;
187*9663SMark.Logan@Sun.COM ATTR_TYPES type;
188*9663SMark.Logan@Sun.COM ntfschar *name;
189*9663SMark.Logan@Sun.COM u32 name_len;
190*9663SMark.Logan@Sun.COM unsigned long state;
191*9663SMark.Logan@Sun.COM s64 allocated_size;
192*9663SMark.Logan@Sun.COM s64 data_size;
193*9663SMark.Logan@Sun.COM s64 initialized_size;
194*9663SMark.Logan@Sun.COM s64 compressed_size;
195*9663SMark.Logan@Sun.COM u32 compression_block_size;
196*9663SMark.Logan@Sun.COM u8 compression_block_size_bits;
197*9663SMark.Logan@Sun.COM u8 compression_block_clusters;
198*9663SMark.Logan@Sun.COM ntfs_crypto_attr *crypto;
199*9663SMark.Logan@Sun.COM struct list_head list_entry;
200*9663SMark.Logan@Sun.COM int nr_references;
201*9663SMark.Logan@Sun.COM };
202*9663SMark.Logan@Sun.COM
203*9663SMark.Logan@Sun.COM /**
204*9663SMark.Logan@Sun.COM * enum ntfs_attr_state_bits - bits for the state field in the ntfs_attr
205*9663SMark.Logan@Sun.COM * structure
206*9663SMark.Logan@Sun.COM */
207*9663SMark.Logan@Sun.COM typedef enum {
208*9663SMark.Logan@Sun.COM NA_Initialized, /* 1: structure is initialized. */
209*9663SMark.Logan@Sun.COM NA_NonResident, /* 1: Attribute is not resident. */
210*9663SMark.Logan@Sun.COM } ntfs_attr_state_bits;
211*9663SMark.Logan@Sun.COM
212*9663SMark.Logan@Sun.COM #define test_nattr_flag(na, flag) test_bit(NA_##flag, (na)->state)
213*9663SMark.Logan@Sun.COM #define set_nattr_flag(na, flag) set_bit(NA_##flag, (na)->state)
214*9663SMark.Logan@Sun.COM #define clear_nattr_flag(na, flag) clear_bit(NA_##flag, (na)->state)
215*9663SMark.Logan@Sun.COM
216*9663SMark.Logan@Sun.COM #define NAttrInitialized(na) test_nattr_flag(na, Initialized)
217*9663SMark.Logan@Sun.COM #define NAttrSetInitialized(na) set_nattr_flag(na, Initialized)
218*9663SMark.Logan@Sun.COM #define NAttrClearInitialized(na) clear_nattr_flag(na, Initialized)
219*9663SMark.Logan@Sun.COM
220*9663SMark.Logan@Sun.COM #define NAttrNonResident(na) test_nattr_flag(na, NonResident)
221*9663SMark.Logan@Sun.COM #define NAttrSetNonResident(na) set_nattr_flag(na, NonResident)
222*9663SMark.Logan@Sun.COM #define NAttrClearNonResident(na) clear_nattr_flag(na, NonResident)
223*9663SMark.Logan@Sun.COM
224*9663SMark.Logan@Sun.COM #define GenNAttrIno(func_name,flag) \
225*9663SMark.Logan@Sun.COM static inline int NAttr##func_name(ntfs_attr *na) \
226*9663SMark.Logan@Sun.COM { \
227*9663SMark.Logan@Sun.COM if (na->type == AT_DATA && na->name == AT_UNNAMED) \
228*9663SMark.Logan@Sun.COM return (na->ni->flags & FILE_ATTR_##flag) ? 1 : 0; \
229*9663SMark.Logan@Sun.COM return 0; \
230*9663SMark.Logan@Sun.COM } \
231*9663SMark.Logan@Sun.COM static inline void NAttrSet##func_name(ntfs_attr *na) \
232*9663SMark.Logan@Sun.COM { \
233*9663SMark.Logan@Sun.COM if (na->type == AT_DATA && na->name == AT_UNNAMED) \
234*9663SMark.Logan@Sun.COM na->ni->flags |= FILE_ATTR_##flag; \
235*9663SMark.Logan@Sun.COM else \
236*9663SMark.Logan@Sun.COM ntfs_log_trace("BUG! Should be called only for " \
237*9663SMark.Logan@Sun.COM "unnamed data attribute.\n"); \
238*9663SMark.Logan@Sun.COM } \
239*9663SMark.Logan@Sun.COM static inline void NAttrClear##func_name(ntfs_attr *na) \
240*9663SMark.Logan@Sun.COM { \
241*9663SMark.Logan@Sun.COM if (na->type == AT_DATA && na->name == AT_UNNAMED) \
242*9663SMark.Logan@Sun.COM na->ni->flags &= ~FILE_ATTR_##flag; \
243*9663SMark.Logan@Sun.COM }
244*9663SMark.Logan@Sun.COM
245*9663SMark.Logan@Sun.COM GenNAttrIno(Compressed, COMPRESSED)
246*9663SMark.Logan@Sun.COM GenNAttrIno(Encrypted, ENCRYPTED)
247*9663SMark.Logan@Sun.COM GenNAttrIno(Sparse, SPARSE_FILE)
248*9663SMark.Logan@Sun.COM
249*9663SMark.Logan@Sun.COM #ifndef __sun
250*9663SMark.Logan@Sun.COM /**
251*9663SMark.Logan@Sun.COM * union attr_val - Union of all known attribute values
252*9663SMark.Logan@Sun.COM *
253*9663SMark.Logan@Sun.COM * For convenience. Used in the attr structure.
254*9663SMark.Logan@Sun.COM */
255*9663SMark.Logan@Sun.COM typedef union {
256*9663SMark.Logan@Sun.COM u8 _default; /* Unnamed u8 to serve as default when just using
257*9663SMark.Logan@Sun.COM a_val without specifying any of the below. */
258*9663SMark.Logan@Sun.COM STANDARD_INFORMATION std_inf;
259*9663SMark.Logan@Sun.COM ATTR_LIST_ENTRY al_entry;
260*9663SMark.Logan@Sun.COM FILE_NAME_ATTR filename;
261*9663SMark.Logan@Sun.COM OBJECT_ID_ATTR obj_id;
262*9663SMark.Logan@Sun.COM SECURITY_DESCRIPTOR_ATTR sec_desc;
263*9663SMark.Logan@Sun.COM VOLUME_NAME vol_name;
264*9663SMark.Logan@Sun.COM VOLUME_INFORMATION vol_inf;
265*9663SMark.Logan@Sun.COM DATA_ATTR data;
266*9663SMark.Logan@Sun.COM INDEX_ROOT index_root;
267*9663SMark.Logan@Sun.COM INDEX_BLOCK index_blk;
268*9663SMark.Logan@Sun.COM BITMAP_ATTR bmp;
269*9663SMark.Logan@Sun.COM REPARSE_POINT reparse;
270*9663SMark.Logan@Sun.COM EA_INFORMATION ea_inf;
271*9663SMark.Logan@Sun.COM EA_ATTR ea;
272*9663SMark.Logan@Sun.COM PROPERTY_SET property_set;
273*9663SMark.Logan@Sun.COM LOGGED_UTILITY_STREAM logged_util_stream;
274*9663SMark.Logan@Sun.COM EFS_ATTR_HEADER efs;
275*9663SMark.Logan@Sun.COM } attr_val;
276*9663SMark.Logan@Sun.COM #endif /* __sun */
277*9663SMark.Logan@Sun.COM
278*9663SMark.Logan@Sun.COM extern void ntfs_attr_init(ntfs_attr *na, const BOOL non_resident,
279*9663SMark.Logan@Sun.COM const BOOL compressed, const BOOL encrypted, const BOOL sparse,
280*9663SMark.Logan@Sun.COM const s64 allocated_size, const s64 data_size,
281*9663SMark.Logan@Sun.COM const s64 initialized_size, const s64 compressed_size,
282*9663SMark.Logan@Sun.COM const u8 compression_unit);
283*9663SMark.Logan@Sun.COM
284*9663SMark.Logan@Sun.COM extern ntfs_attr *ntfs_attr_open(ntfs_inode *ni, const ATTR_TYPES type,
285*9663SMark.Logan@Sun.COM ntfschar *name, u32 name_len);
286*9663SMark.Logan@Sun.COM extern void ntfs_attr_close(ntfs_attr *na);
287*9663SMark.Logan@Sun.COM
288*9663SMark.Logan@Sun.COM extern s64 ntfs_attr_pread(ntfs_attr *na, const s64 pos, s64 count,
289*9663SMark.Logan@Sun.COM void *b);
290*9663SMark.Logan@Sun.COM extern s64 ntfs_attr_pwrite(ntfs_attr *na, const s64 pos, s64 count,
291*9663SMark.Logan@Sun.COM const void *b);
292*9663SMark.Logan@Sun.COM
293*9663SMark.Logan@Sun.COM extern void *ntfs_attr_readall(ntfs_inode *ni, const ATTR_TYPES type,
294*9663SMark.Logan@Sun.COM ntfschar *name, u32 name_len, s64 *data_size);
295*9663SMark.Logan@Sun.COM
296*9663SMark.Logan@Sun.COM extern s64 ntfs_attr_mst_pread(ntfs_attr *na, const s64 pos,
297*9663SMark.Logan@Sun.COM const s64 bk_cnt, const u32 bk_size, void *dst);
298*9663SMark.Logan@Sun.COM extern s64 ntfs_attr_mst_pwrite(ntfs_attr *na, const s64 pos,
299*9663SMark.Logan@Sun.COM s64 bk_cnt, const u32 bk_size, void *src);
300*9663SMark.Logan@Sun.COM
301*9663SMark.Logan@Sun.COM extern int ntfs_attr_map_runlist(ntfs_attr *na, VCN vcn);
302*9663SMark.Logan@Sun.COM extern int ntfs_attr_map_runlist_range(ntfs_attr *na, VCN from_vcn, VCN to_vcn);
303*9663SMark.Logan@Sun.COM extern int ntfs_attr_map_whole_runlist(ntfs_attr *na);
304*9663SMark.Logan@Sun.COM
305*9663SMark.Logan@Sun.COM extern LCN ntfs_attr_vcn_to_lcn(ntfs_attr *na, const VCN vcn);
306*9663SMark.Logan@Sun.COM extern runlist_element *ntfs_attr_find_vcn(ntfs_attr *na, const VCN vcn);
307*9663SMark.Logan@Sun.COM
308*9663SMark.Logan@Sun.COM extern int ntfs_attr_size_bounds_check(const ntfs_volume *vol,
309*9663SMark.Logan@Sun.COM const ATTR_TYPES type, const s64 size);
310*9663SMark.Logan@Sun.COM extern int ntfs_attr_can_be_non_resident(const ntfs_volume *vol,
311*9663SMark.Logan@Sun.COM const ATTR_TYPES type);
312*9663SMark.Logan@Sun.COM extern int ntfs_attr_can_be_resident(const ntfs_volume *vol,
313*9663SMark.Logan@Sun.COM const ATTR_TYPES type);
314*9663SMark.Logan@Sun.COM
315*9663SMark.Logan@Sun.COM extern int ntfs_make_room_for_attr(MFT_RECORD *m, u8 *pos, u32 size);
316*9663SMark.Logan@Sun.COM
317*9663SMark.Logan@Sun.COM extern int ntfs_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type,
318*9663SMark.Logan@Sun.COM ntfschar *name, u8 name_len, u8 *val, u32 size,
319*9663SMark.Logan@Sun.COM ATTR_FLAGS flags);
320*9663SMark.Logan@Sun.COM extern int ntfs_non_resident_attr_record_add(ntfs_inode *ni, ATTR_TYPES type,
321*9663SMark.Logan@Sun.COM ntfschar *name, u8 name_len, VCN lowest_vcn, int dataruns_size,
322*9663SMark.Logan@Sun.COM ATTR_FLAGS flags);
323*9663SMark.Logan@Sun.COM extern int ntfs_attr_record_rm(ntfs_attr_search_ctx *ctx);
324*9663SMark.Logan@Sun.COM
325*9663SMark.Logan@Sun.COM extern int ntfs_attr_add(ntfs_inode *ni, ATTR_TYPES type,
326*9663SMark.Logan@Sun.COM ntfschar *name, u8 name_len, u8 *val, s64 size);
327*9663SMark.Logan@Sun.COM extern int ntfs_attr_rm(ntfs_attr *na);
328*9663SMark.Logan@Sun.COM
329*9663SMark.Logan@Sun.COM extern int ntfs_attr_record_resize(MFT_RECORD *m, ATTR_RECORD *a, u32 new_size);
330*9663SMark.Logan@Sun.COM
331*9663SMark.Logan@Sun.COM extern int ntfs_resident_attr_value_resize(MFT_RECORD *m, ATTR_RECORD *a,
332*9663SMark.Logan@Sun.COM const u32 new_size);
333*9663SMark.Logan@Sun.COM
334*9663SMark.Logan@Sun.COM extern int ntfs_attr_record_move_to(ntfs_attr_search_ctx *ctx, ntfs_inode *ni);
335*9663SMark.Logan@Sun.COM extern int ntfs_attr_record_move_away(ntfs_attr_search_ctx *ctx, int extra);
336*9663SMark.Logan@Sun.COM
337*9663SMark.Logan@Sun.COM extern int ntfs_attr_update_mapping_pairs(ntfs_attr *na, VCN from_vcn);
338*9663SMark.Logan@Sun.COM
339*9663SMark.Logan@Sun.COM extern int __ntfs_attr_truncate(ntfs_attr *na, const s64 newsize, BOOL sparse);
340*9663SMark.Logan@Sun.COM extern int ntfs_attr_truncate(ntfs_attr *na, const s64 newsize);
341*9663SMark.Logan@Sun.COM
342*9663SMark.Logan@Sun.COM extern int ntfs_attr_exist(ntfs_inode *ni, const ATTR_TYPES type,
343*9663SMark.Logan@Sun.COM ntfschar *name, u32 name_len);
344*9663SMark.Logan@Sun.COM
ntfs_attr_get_name(ATTR_RECORD * attr)345*9663SMark.Logan@Sun.COM static __inline__ ntfschar *ntfs_attr_get_name(ATTR_RECORD *attr)
346*9663SMark.Logan@Sun.COM {
347*9663SMark.Logan@Sun.COM return (ntfschar*)((u8*)attr + le16_to_cpu(attr->name_offset));
348*9663SMark.Logan@Sun.COM }
349*9663SMark.Logan@Sun.COM
350*9663SMark.Logan@Sun.COM // FIXME / TODO: Above here the file is cleaned up. (AIA)
351*9663SMark.Logan@Sun.COM /**
352*9663SMark.Logan@Sun.COM * get_attribute_value_length - return the length of the value of an attribute
353*9663SMark.Logan@Sun.COM * @a: pointer to a buffer containing the attribute record
354*9663SMark.Logan@Sun.COM *
355*9663SMark.Logan@Sun.COM * Return the byte size of the attribute value of the attribute @a (as it
356*9663SMark.Logan@Sun.COM * would be after eventual decompression and filling in of holes if sparse).
357*9663SMark.Logan@Sun.COM * If we return 0, check errno. If errno is 0 the actual length was 0,
358*9663SMark.Logan@Sun.COM * otherwise errno describes the error.
359*9663SMark.Logan@Sun.COM *
360*9663SMark.Logan@Sun.COM * FIXME: Describe possible errnos.
361*9663SMark.Logan@Sun.COM */
362*9663SMark.Logan@Sun.COM s64 ntfs_get_attribute_value_length(const ATTR_RECORD *a);
363*9663SMark.Logan@Sun.COM
364*9663SMark.Logan@Sun.COM /**
365*9663SMark.Logan@Sun.COM * get_attribute_value - return the attribute value of an attribute
366*9663SMark.Logan@Sun.COM * @vol: volume on which the attribute is present
367*9663SMark.Logan@Sun.COM * @a: attribute to get the value of
368*9663SMark.Logan@Sun.COM * @b: destination buffer for the attribute value
369*9663SMark.Logan@Sun.COM *
370*9663SMark.Logan@Sun.COM * Make a copy of the attribute value of the attribute @a into the destination
371*9663SMark.Logan@Sun.COM * buffer @b. Note, that the size of @b has to be at least equal to the value
372*9663SMark.Logan@Sun.COM * returned by get_attribute_value_length(@a).
373*9663SMark.Logan@Sun.COM *
374*9663SMark.Logan@Sun.COM * Return number of bytes copied. If this is zero check errno. If errno is 0
375*9663SMark.Logan@Sun.COM * then nothing was read due to a zero-length attribute value, otherwise
376*9663SMark.Logan@Sun.COM * errno describes the error.
377*9663SMark.Logan@Sun.COM */
378*9663SMark.Logan@Sun.COM s64 ntfs_get_attribute_value(const ntfs_volume *vol, const ATTR_RECORD *a,
379*9663SMark.Logan@Sun.COM u8 *b);
380*9663SMark.Logan@Sun.COM
381*9663SMark.Logan@Sun.COM #endif /* defined _NTFS_ATTRIB_H */
382*9663SMark.Logan@Sun.COM
383