runlist.h 2.6 KB

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