aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ntfs/lcnalloc.h
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ntfs/lcnalloc.h')
-rw-r--r--fs/ntfs/lcnalloc.h40
1 files changed, 35 insertions, 5 deletions
diff --git a/fs/ntfs/lcnalloc.h b/fs/ntfs/lcnalloc.h
index a6a8827882e7..aa0518509cd3 100644
--- a/fs/ntfs/lcnalloc.h
+++ b/fs/ntfs/lcnalloc.h
@@ -27,6 +27,7 @@
27 27
28#include <linux/fs.h> 28#include <linux/fs.h>
29 29
30#include "attrib.h"
30#include "types.h" 31#include "types.h"
31#include "inode.h" 32#include "inode.h"
32#include "runlist.h" 33#include "runlist.h"
@@ -44,13 +45,14 @@ extern runlist_element *ntfs_cluster_alloc(ntfs_volume *vol,
44 const NTFS_CLUSTER_ALLOCATION_ZONES zone); 45 const NTFS_CLUSTER_ALLOCATION_ZONES zone);
45 46
46extern s64 __ntfs_cluster_free(ntfs_inode *ni, const VCN start_vcn, 47extern s64 __ntfs_cluster_free(ntfs_inode *ni, const VCN start_vcn,
47 s64 count, const BOOL is_rollback); 48 s64 count, ntfs_attr_search_ctx *ctx, const BOOL is_rollback);
48 49
49/** 50/**
50 * ntfs_cluster_free - free clusters on an ntfs volume 51 * ntfs_cluster_free - free clusters on an ntfs volume
51 * @ni: ntfs inode whose runlist describes the clusters to free 52 * @ni: ntfs inode whose runlist describes the clusters to free
52 * @start_vcn: vcn in the runlist of @ni at which to start freeing clusters 53 * @start_vcn: vcn in the runlist of @ni at which to start freeing clusters
53 * @count: number of clusters to free or -1 for all clusters 54 * @count: number of clusters to free or -1 for all clusters
55 * @ctx: active attribute search context if present or NULL if not
54 * 56 *
55 * Free @count clusters starting at the cluster @start_vcn in the runlist 57 * Free @count clusters starting at the cluster @start_vcn in the runlist
56 * described by the ntfs inode @ni. 58 * described by the ntfs inode @ni.
@@ -59,12 +61,36 @@ extern s64 __ntfs_cluster_free(ntfs_inode *ni, const VCN start_vcn,
59 * deallocated. Thus, to completely free all clusters in a runlist, use 61 * deallocated. Thus, to completely free all clusters in a runlist, use
60 * @start_vcn = 0 and @count = -1. 62 * @start_vcn = 0 and @count = -1.
61 * 63 *
62 * Note, ntfs_cluster_free() does not modify the runlist at all, so the caller 64 * If @ctx is specified, it is an active search context of @ni and its base mft
63 * has to deal with it later. 65 * record. This is needed when ntfs_cluster_free() encounters unmapped runlist
66 * fragments and allows their mapping. If you do not have the mft record
67 * mapped, you can specify @ctx as NULL and ntfs_cluster_free() will perform
68 * the necessary mapping and unmapping.
69 *
70 * Note, ntfs_cluster_free() saves the state of @ctx on entry and restores it
71 * before returning. Thus, @ctx will be left pointing to the same attribute on
72 * return as on entry. However, the actual pointers in @ctx may point to
73 * different memory locations on return, so you must remember to reset any
74 * cached pointers from the @ctx, i.e. after the call to ntfs_cluster_free(),
75 * you will probably want to do:
76 * m = ctx->mrec;
77 * a = ctx->attr;
78 * Assuming you cache ctx->attr in a variable @a of type ATTR_RECORD * and that
79 * you cache ctx->mrec in a variable @m of type MFT_RECORD *.
80 *
81 * Note, ntfs_cluster_free() does not modify the runlist, so you have to remove
82 * from the runlist or mark sparse the freed runs later.
64 * 83 *
65 * Return the number of deallocated clusters (not counting sparse ones) on 84 * Return the number of deallocated clusters (not counting sparse ones) on
66 * success and -errno on error. 85 * success and -errno on error.
67 * 86 *
87 * WARNING: If @ctx is supplied, regardless of whether success or failure is
88 * returned, you need to check IS_ERR(@ctx->mrec) and if TRUE the @ctx
89 * is no longer valid, i.e. you need to either call
90 * ntfs_attr_reinit_search_ctx() or ntfs_attr_put_search_ctx() on it.
91 * In that case PTR_ERR(@ctx->mrec) will give you the error code for
92 * why the mapping of the old inode failed.
93 *
68 * Locking: - The runlist described by @ni must be locked for writing on entry 94 * Locking: - The runlist described by @ni must be locked for writing on entry
69 * and is locked on return. Note the runlist may be modified when 95 * and is locked on return. Note the runlist may be modified when
70 * needed runlist fragments need to be mapped. 96 * needed runlist fragments need to be mapped.
@@ -72,11 +98,15 @@ extern s64 __ntfs_cluster_free(ntfs_inode *ni, const VCN start_vcn,
72 * on return. 98 * on return.
73 * - This function takes the volume lcn bitmap lock for writing and 99 * - This function takes the volume lcn bitmap lock for writing and
74 * modifies the bitmap contents. 100 * modifies the bitmap contents.
101 * - If @ctx is NULL, the base mft record of @ni must not be mapped on
102 * entry and it will be left unmapped on return.
103 * - If @ctx is not NULL, the base mft record must be mapped on entry
104 * and it will be left mapped on return.
75 */ 105 */
76static inline s64 ntfs_cluster_free(ntfs_inode *ni, const VCN start_vcn, 106static inline s64 ntfs_cluster_free(ntfs_inode *ni, const VCN start_vcn,
77 s64 count) 107 s64 count, ntfs_attr_search_ctx *ctx)
78{ 108{
79 return __ntfs_cluster_free(ni, start_vcn, count, FALSE); 109 return __ntfs_cluster_free(ni, start_vcn, count, ctx, FALSE);
80} 110}
81 111
82extern int ntfs_cluster_free_from_rl_nolock(ntfs_volume *vol, 112extern int ntfs_cluster_free_from_rl_nolock(ntfs_volume *vol,