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 | * runlist.h - Defines for runlist handling in NTFS Linux kernel driver. |
| 4 | * Part of the Linux-NTFS project. |
| 5 | * |
Anton Altaparmakov | 53d59aa | 2005-03-17 10:51:33 +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_RUNLIST_H |
| 11 | #define _LINUX_NTFS_RUNLIST_H |
| 12 | |
| 13 | #include "types.h" |
| 14 | #include "layout.h" |
| 15 | #include "volume.h" |
| 16 | |
| 17 | /** |
| 18 | * runlist_element - in memory vcn to lcn mapping array element |
| 19 | * @vcn: starting vcn of the current array element |
| 20 | * @lcn: starting lcn of the current array element |
| 21 | * @length: length in clusters of the current array element |
| 22 | * |
| 23 | * The last vcn (in fact the last vcn + 1) is reached when length == 0. |
| 24 | * |
| 25 | * When lcn == -1 this means that the count vcns starting at vcn are not |
| 26 | * physically allocated (i.e. this is a hole / data is sparse). |
| 27 | */ |
| 28 | typedef struct { /* In memory vcn to lcn mapping structure element. */ |
| 29 | VCN vcn; /* vcn = Starting virtual cluster number. */ |
| 30 | LCN lcn; /* lcn = Starting logical cluster number. */ |
| 31 | s64 length; /* Run length in clusters. */ |
| 32 | } runlist_element; |
| 33 | |
| 34 | /** |
| 35 | * runlist - in memory vcn to lcn mapping array including a read/write lock |
| 36 | * @rl: pointer to an array of runlist elements |
| 37 | * @lock: read/write spinlock for serializing access to @rl |
| 38 | * |
| 39 | */ |
| 40 | typedef struct { |
| 41 | runlist_element *rl; |
| 42 | struct rw_semaphore lock; |
| 43 | } runlist; |
| 44 | |
| 45 | static inline void ntfs_init_runlist(runlist *rl) |
| 46 | { |
| 47 | rl->rl = NULL; |
| 48 | init_rwsem(&rl->lock); |
| 49 | } |
| 50 | |
| 51 | typedef enum { |
| 52 | LCN_HOLE = -1, /* Keep this as highest value or die! */ |
| 53 | LCN_RL_NOT_MAPPED = -2, |
| 54 | LCN_ENOENT = -3, |
Anton Altaparmakov | c0c1cc0 | 2005-03-07 21:43:38 +0000 | [diff] [blame] | 55 | LCN_ENOMEM = -4, |
| 56 | LCN_EIO = -5, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | } LCN_SPECIAL_VALUES; |
| 58 | |
| 59 | extern runlist_element *ntfs_runlists_merge(runlist_element *drl, |
| 60 | runlist_element *srl); |
| 61 | |
| 62 | extern runlist_element *ntfs_mapping_pairs_decompress(const ntfs_volume *vol, |
| 63 | const ATTR_RECORD *attr, runlist_element *old_rl); |
| 64 | |
| 65 | extern LCN ntfs_rl_vcn_to_lcn(const runlist_element *rl, const VCN vcn); |
| 66 | |
Anton Altaparmakov | 53d59aa | 2005-03-17 10:51:33 +0000 | [diff] [blame] | 67 | #ifdef NTFS_RW |
| 68 | |
| 69 | extern runlist_element *ntfs_rl_find_vcn_nolock(runlist_element *rl, |
| 70 | const VCN vcn); |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | extern int ntfs_get_size_for_mapping_pairs(const ntfs_volume *vol, |
Anton Altaparmakov | fa3be923 | 2005-06-25 17:15:36 +0100 | [diff] [blame] | 73 | const runlist_element *rl, const VCN first_vcn, |
| 74 | const VCN last_vcn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | extern int ntfs_mapping_pairs_build(const ntfs_volume *vol, s8 *dst, |
| 77 | const int dst_len, const runlist_element *rl, |
Anton Altaparmakov | fa3be923 | 2005-06-25 17:15:36 +0100 | [diff] [blame] | 78 | const VCN first_vcn, const VCN last_vcn, VCN *const stop_vcn); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | extern int ntfs_rl_truncate_nolock(const ntfs_volume *vol, |
| 81 | runlist *const runlist, const s64 new_length); |
| 82 | |
Anton Altaparmakov | 6e48321 | 2005-09-08 20:26:34 +0100 | [diff] [blame] | 83 | int ntfs_rl_punch_nolock(const ntfs_volume *vol, runlist *const runlist, |
| 84 | const VCN start, const s64 length); |
| 85 | |
Anton Altaparmakov | 53d59aa | 2005-03-17 10:51:33 +0000 | [diff] [blame] | 86 | #endif /* NTFS_RW */ |
| 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #endif /* _LINUX_NTFS_RUNLIST_H */ |