bitmap.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * bitmap.h - Defines for NTFS kernel bitmap handling. Part of the Linux-NTFS
  4. * project.
  5. *
  6. * Copyright (c) 2004 Anton Altaparmakov
  7. */
  8. #ifndef _LINUX_NTFS_BITMAP_H
  9. #define _LINUX_NTFS_BITMAP_H
  10. #ifdef NTFS_RW
  11. #include <linux/fs.h>
  12. #include "types.h"
  13. extern int __ntfs_bitmap_set_bits_in_run(struct inode *vi, const s64 start_bit,
  14. const s64 count, const u8 value, const bool is_rollback);
  15. /**
  16. * ntfs_bitmap_set_bits_in_run - set a run of bits in a bitmap to a value
  17. * @vi: vfs inode describing the bitmap
  18. * @start_bit: first bit to set
  19. * @count: number of bits to set
  20. * @value: value to set the bits to (i.e. 0 or 1)
  21. *
  22. * Set @count bits starting at bit @start_bit in the bitmap described by the
  23. * vfs inode @vi to @value, where @value is either 0 or 1.
  24. *
  25. * Return 0 on success and -errno on error.
  26. */
  27. static inline int ntfs_bitmap_set_bits_in_run(struct inode *vi,
  28. const s64 start_bit, const s64 count, const u8 value)
  29. {
  30. return __ntfs_bitmap_set_bits_in_run(vi, start_bit, count, value,
  31. false);
  32. }
  33. /**
  34. * ntfs_bitmap_set_run - set a run of bits in a bitmap
  35. * @vi: vfs inode describing the bitmap
  36. * @start_bit: first bit to set
  37. * @count: number of bits to set
  38. *
  39. * Set @count bits starting at bit @start_bit in the bitmap described by the
  40. * vfs inode @vi.
  41. *
  42. * Return 0 on success and -errno on error.
  43. */
  44. static inline int ntfs_bitmap_set_run(struct inode *vi, const s64 start_bit,
  45. const s64 count)
  46. {
  47. return ntfs_bitmap_set_bits_in_run(vi, start_bit, count, 1);
  48. }
  49. /**
  50. * ntfs_bitmap_clear_run - clear a run of bits in a bitmap
  51. * @vi: vfs inode describing the bitmap
  52. * @start_bit: first bit to clear
  53. * @count: number of bits to clear
  54. *
  55. * Clear @count bits starting at bit @start_bit in the bitmap described by the
  56. * vfs inode @vi.
  57. *
  58. * Return 0 on success and -errno on error.
  59. */
  60. static inline int ntfs_bitmap_clear_run(struct inode *vi, const s64 start_bit,
  61. const s64 count)
  62. {
  63. return ntfs_bitmap_set_bits_in_run(vi, start_bit, count, 0);
  64. }
  65. /**
  66. * ntfs_bitmap_set_bit - set a bit in a bitmap
  67. * @vi: vfs inode describing the bitmap
  68. * @bit: bit to set
  69. *
  70. * Set bit @bit in the bitmap described by the vfs inode @vi.
  71. *
  72. * Return 0 on success and -errno on error.
  73. */
  74. static inline int ntfs_bitmap_set_bit(struct inode *vi, const s64 bit)
  75. {
  76. return ntfs_bitmap_set_run(vi, bit, 1);
  77. }
  78. /**
  79. * ntfs_bitmap_clear_bit - clear a bit in a bitmap
  80. * @vi: vfs inode describing the bitmap
  81. * @bit: bit to clear
  82. *
  83. * Clear bit @bit in the bitmap described by the vfs inode @vi.
  84. *
  85. * Return 0 on success and -errno on error.
  86. */
  87. static inline int ntfs_bitmap_clear_bit(struct inode *vi, const s64 bit)
  88. {
  89. return ntfs_bitmap_clear_run(vi, bit, 1);
  90. }
  91. #endif /* NTFS_RW */
  92. #endif /* defined _LINUX_NTFS_BITMAP_H */