lcnalloc.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * lcnalloc.h - Exports for NTFS kernel cluster (de)allocation. Part of the
  3. * Linux-NTFS project.
  4. *
  5. * Copyright (c) 2004 Anton Altaparmakov
  6. *
  7. * This program/include file is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as published
  9. * by the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program/include file is distributed in the hope that it will be
  13. * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
  14. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program (in the main directory of the Linux-NTFS
  19. * distribution in the file COPYING); if not, write to the Free Software
  20. * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #ifndef _LINUX_NTFS_LCNALLOC_H
  23. #define _LINUX_NTFS_LCNALLOC_H
  24. #ifdef NTFS_RW
  25. #include <linux/fs.h>
  26. #include "types.h"
  27. #include "runlist.h"
  28. #include "volume.h"
  29. typedef enum {
  30. FIRST_ZONE = 0, /* For sanity checking. */
  31. MFT_ZONE = 0, /* Allocate from $MFT zone. */
  32. DATA_ZONE = 1, /* Allocate from $DATA zone. */
  33. LAST_ZONE = 1, /* For sanity checking. */
  34. } NTFS_CLUSTER_ALLOCATION_ZONES;
  35. extern runlist_element *ntfs_cluster_alloc(ntfs_volume *vol,
  36. const VCN start_vcn, const s64 count, const LCN start_lcn,
  37. const NTFS_CLUSTER_ALLOCATION_ZONES zone);
  38. extern s64 __ntfs_cluster_free(struct inode *vi, const VCN start_vcn,
  39. s64 count, const BOOL write_locked, const BOOL is_rollback);
  40. /**
  41. * ntfs_cluster_free - free clusters on an ntfs volume
  42. * @vi: vfs inode whose runlist describes the clusters to free
  43. * @start_vcn: vcn in the runlist of @vi at which to start freeing clusters
  44. * @count: number of clusters to free or -1 for all clusters
  45. * @write_locked: true if the runlist is locked for writing
  46. *
  47. * Free @count clusters starting at the cluster @start_vcn in the runlist
  48. * described by the vfs inode @vi.
  49. *
  50. * If @count is -1, all clusters from @start_vcn to the end of the runlist are
  51. * deallocated. Thus, to completely free all clusters in a runlist, use
  52. * @start_vcn = 0 and @count = -1.
  53. *
  54. * Note, ntfs_cluster_free() does not modify the runlist at all, so the caller
  55. * has to deal with it later.
  56. *
  57. * Return the number of deallocated clusters (not counting sparse ones) on
  58. * success and -errno on error.
  59. *
  60. * Locking: - The runlist described by @vi must be locked on entry and is
  61. * locked on return. Note if the runlist is locked for reading the
  62. * lock may be dropped and reacquired. Note the runlist may be
  63. * modified when needed runlist fragments need to be mapped.
  64. * - The volume lcn bitmap must be unlocked on entry and is unlocked
  65. * on return.
  66. * - This function takes the volume lcn bitmap lock for writing and
  67. * modifies the bitmap contents.
  68. */
  69. static inline s64 ntfs_cluster_free(struct inode *vi, const VCN start_vcn,
  70. s64 count, const BOOL write_locked)
  71. {
  72. return __ntfs_cluster_free(vi, start_vcn, count, write_locked, FALSE);
  73. }
  74. extern int ntfs_cluster_free_from_rl_nolock(ntfs_volume *vol,
  75. const runlist_element *rl);
  76. /**
  77. * ntfs_cluster_free_from_rl - free clusters from runlist
  78. * @vol: mounted ntfs volume on which to free the clusters
  79. * @rl: runlist describing the clusters to free
  80. *
  81. * Free all the clusters described by the runlist @rl on the volume @vol. In
  82. * the case of an error being returned, at least some of the clusters were not
  83. * freed.
  84. *
  85. * Return 0 on success and -errno on error.
  86. *
  87. * Locking: - This function takes the volume lcn bitmap lock for writing and
  88. * modifies the bitmap contents.
  89. * - The caller must have locked the runlist @rl for reading or
  90. * writing.
  91. */
  92. static inline int ntfs_cluster_free_from_rl(ntfs_volume *vol,
  93. const runlist_element *rl)
  94. {
  95. int ret;
  96. down_write(&vol->lcnbmp_lock);
  97. ret = ntfs_cluster_free_from_rl_nolock(vol, rl);
  98. up_write(&vol->lcnbmp_lock);
  99. return ret;
  100. }
  101. #endif /* NTFS_RW */
  102. #endif /* defined _LINUX_NTFS_LCNALLOC_H */