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