1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * attrib.h - Defines for attribute handling in NTFS Linux kernel driver.
4*4882a593Smuzhiyun * Part of the Linux-NTFS project.
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Copyright (c) 2001-2005 Anton Altaparmakov
7*4882a593Smuzhiyun * Copyright (c) 2002 Richard Russon
8*4882a593Smuzhiyun */
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun #ifndef _LINUX_NTFS_ATTRIB_H
11*4882a593Smuzhiyun #define _LINUX_NTFS_ATTRIB_H
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #include "endian.h"
14*4882a593Smuzhiyun #include "types.h"
15*4882a593Smuzhiyun #include "layout.h"
16*4882a593Smuzhiyun #include "inode.h"
17*4882a593Smuzhiyun #include "runlist.h"
18*4882a593Smuzhiyun #include "volume.h"
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun /**
21*4882a593Smuzhiyun * ntfs_attr_search_ctx - used in attribute search functions
22*4882a593Smuzhiyun * @mrec: buffer containing mft record to search
23*4882a593Smuzhiyun * @attr: attribute record in @mrec where to begin/continue search
24*4882a593Smuzhiyun * @is_first: if true ntfs_attr_lookup() begins search with @attr, else after
25*4882a593Smuzhiyun *
26*4882a593Smuzhiyun * Structure must be initialized to zero before the first call to one of the
27*4882a593Smuzhiyun * attribute search functions. Initialize @mrec to point to the mft record to
28*4882a593Smuzhiyun * search, and @attr to point to the first attribute within @mrec (not necessary
29*4882a593Smuzhiyun * if calling the _first() functions), and set @is_first to 'true' (not necessary
30*4882a593Smuzhiyun * if calling the _first() functions).
31*4882a593Smuzhiyun *
32*4882a593Smuzhiyun * If @is_first is 'true', the search begins with @attr. If @is_first is 'false',
33*4882a593Smuzhiyun * the search begins after @attr. This is so that, after the first call to one
34*4882a593Smuzhiyun * of the search attribute functions, we can call the function again, without
35*4882a593Smuzhiyun * any modification of the search context, to automagically get the next
36*4882a593Smuzhiyun * matching attribute.
37*4882a593Smuzhiyun */
38*4882a593Smuzhiyun typedef struct {
39*4882a593Smuzhiyun MFT_RECORD *mrec;
40*4882a593Smuzhiyun ATTR_RECORD *attr;
41*4882a593Smuzhiyun bool is_first;
42*4882a593Smuzhiyun ntfs_inode *ntfs_ino;
43*4882a593Smuzhiyun ATTR_LIST_ENTRY *al_entry;
44*4882a593Smuzhiyun ntfs_inode *base_ntfs_ino;
45*4882a593Smuzhiyun MFT_RECORD *base_mrec;
46*4882a593Smuzhiyun ATTR_RECORD *base_attr;
47*4882a593Smuzhiyun } ntfs_attr_search_ctx;
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun extern int ntfs_map_runlist_nolock(ntfs_inode *ni, VCN vcn,
50*4882a593Smuzhiyun ntfs_attr_search_ctx *ctx);
51*4882a593Smuzhiyun extern int ntfs_map_runlist(ntfs_inode *ni, VCN vcn);
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun extern LCN ntfs_attr_vcn_to_lcn_nolock(ntfs_inode *ni, const VCN vcn,
54*4882a593Smuzhiyun const bool write_locked);
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun extern runlist_element *ntfs_attr_find_vcn_nolock(ntfs_inode *ni,
57*4882a593Smuzhiyun const VCN vcn, ntfs_attr_search_ctx *ctx);
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun int ntfs_attr_lookup(const ATTR_TYPE type, const ntfschar *name,
60*4882a593Smuzhiyun const u32 name_len, const IGNORE_CASE_BOOL ic,
61*4882a593Smuzhiyun const VCN lowest_vcn, const u8 *val, const u32 val_len,
62*4882a593Smuzhiyun ntfs_attr_search_ctx *ctx);
63*4882a593Smuzhiyun
64*4882a593Smuzhiyun extern int load_attribute_list(ntfs_volume *vol, runlist *rl, u8 *al_start,
65*4882a593Smuzhiyun const s64 size, const s64 initialized_size);
66*4882a593Smuzhiyun
ntfs_attr_size(const ATTR_RECORD * a)67*4882a593Smuzhiyun static inline s64 ntfs_attr_size(const ATTR_RECORD *a)
68*4882a593Smuzhiyun {
69*4882a593Smuzhiyun if (!a->non_resident)
70*4882a593Smuzhiyun return (s64)le32_to_cpu(a->data.resident.value_length);
71*4882a593Smuzhiyun return sle64_to_cpu(a->data.non_resident.data_size);
72*4882a593Smuzhiyun }
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun extern void ntfs_attr_reinit_search_ctx(ntfs_attr_search_ctx *ctx);
75*4882a593Smuzhiyun extern ntfs_attr_search_ctx *ntfs_attr_get_search_ctx(ntfs_inode *ni,
76*4882a593Smuzhiyun MFT_RECORD *mrec);
77*4882a593Smuzhiyun extern void ntfs_attr_put_search_ctx(ntfs_attr_search_ctx *ctx);
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun #ifdef NTFS_RW
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun extern int ntfs_attr_size_bounds_check(const ntfs_volume *vol,
82*4882a593Smuzhiyun const ATTR_TYPE type, const s64 size);
83*4882a593Smuzhiyun extern int ntfs_attr_can_be_non_resident(const ntfs_volume *vol,
84*4882a593Smuzhiyun const ATTR_TYPE type);
85*4882a593Smuzhiyun extern int ntfs_attr_can_be_resident(const ntfs_volume *vol,
86*4882a593Smuzhiyun const ATTR_TYPE type);
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun extern int ntfs_attr_record_resize(MFT_RECORD *m, ATTR_RECORD *a, u32 new_size);
89*4882a593Smuzhiyun extern int ntfs_resident_attr_value_resize(MFT_RECORD *m, ATTR_RECORD *a,
90*4882a593Smuzhiyun const u32 new_size);
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun extern int ntfs_attr_make_non_resident(ntfs_inode *ni, const u32 data_size);
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun extern s64 ntfs_attr_extend_allocation(ntfs_inode *ni, s64 new_alloc_size,
95*4882a593Smuzhiyun const s64 new_data_size, const s64 data_start);
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun extern int ntfs_attr_set(ntfs_inode *ni, const s64 ofs, const s64 cnt,
98*4882a593Smuzhiyun const u8 val);
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun #endif /* NTFS_RW */
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun #endif /* _LINUX_NTFS_ATTRIB_H */
103