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