Blame view

fs/ntfs/lcnalloc.h 4.93 KB
a1d312de7   Thomas Gleixner   treewide: Replace...
1
  /* SPDX-License-Identifier: GPL-2.0-or-later */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
  /*
   * lcnalloc.h - Exports for NTFS kernel cluster (de)allocation.  Part of the
   *		Linux-NTFS project.
   *
715dc636b   Anton Altaparmakov   NTFS: Change ntfs...
6
   * Copyright (c) 2004-2005 Anton Altaparmakov
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
7
8
9
10
11
12
13
14
   */
  
  #ifndef _LINUX_NTFS_LCNALLOC_H
  #define _LINUX_NTFS_LCNALLOC_H
  
  #ifdef NTFS_RW
  
  #include <linux/fs.h>
511bea5ea   Anton Altaparmakov   NTFS: - Change {_...
15
  #include "attrib.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
16
  #include "types.h"
715dc636b   Anton Altaparmakov   NTFS: Change ntfs...
17
  #include "inode.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
18
19
20
21
22
23
24
25
26
27
28
29
  #include "runlist.h"
  #include "volume.h"
  
  typedef enum {
  	FIRST_ZONE	= 0,	/* For sanity checking. */
  	MFT_ZONE	= 0,	/* Allocate from $MFT zone. */
  	DATA_ZONE	= 1,	/* Allocate from $DATA zone. */
  	LAST_ZONE	= 1,	/* For sanity checking. */
  } NTFS_CLUSTER_ALLOCATION_ZONES;
  
  extern runlist_element *ntfs_cluster_alloc(ntfs_volume *vol,
  		const VCN start_vcn, const s64 count, const LCN start_lcn,
fc0fa7dc7   Anton Altaparmakov   NTFS: - Change nt...
30
  		const NTFS_CLUSTER_ALLOCATION_ZONES zone,
c49c31115   Richard Knutsson   [PATCH] fs/ntfs: ...
31
  		const bool is_extension);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32

715dc636b   Anton Altaparmakov   NTFS: Change ntfs...
33
  extern s64 __ntfs_cluster_free(ntfs_inode *ni, const VCN start_vcn,
c49c31115   Richard Knutsson   [PATCH] fs/ntfs: ...
34
  		s64 count, ntfs_attr_search_ctx *ctx, const bool is_rollback);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
35
36
37
  
  /**
   * ntfs_cluster_free - free clusters on an ntfs volume
715dc636b   Anton Altaparmakov   NTFS: Change ntfs...
38
39
   * @ni:		ntfs inode whose runlist describes the clusters to free
   * @start_vcn:	vcn in the runlist of @ni at which to start freeing clusters
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
   * @count:	number of clusters to free or -1 for all clusters
511bea5ea   Anton Altaparmakov   NTFS: - Change {_...
41
   * @ctx:	active attribute search context if present or NULL if not
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
43
   *
   * Free @count clusters starting at the cluster @start_vcn in the runlist
715dc636b   Anton Altaparmakov   NTFS: Change ntfs...
44
   * described by the ntfs inode @ni.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
45
46
47
48
49
   *
   * If @count is -1, all clusters from @start_vcn to the end of the runlist are
   * deallocated.  Thus, to completely free all clusters in a runlist, use
   * @start_vcn = 0 and @count = -1.
   *
511bea5ea   Anton Altaparmakov   NTFS: - Change {_...
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
   * If @ctx is specified, it is an active search context of @ni and its base mft
   * record.  This is needed when ntfs_cluster_free() encounters unmapped runlist
   * fragments and allows their mapping.  If you do not have the mft record
   * mapped, you can specify @ctx as NULL and ntfs_cluster_free() will perform
   * the necessary mapping and unmapping.
   *
   * Note, ntfs_cluster_free() saves the state of @ctx on entry and restores it
   * before returning.  Thus, @ctx will be left pointing to the same attribute on
   * return as on entry.  However, the actual pointers in @ctx may point to
   * different memory locations on return, so you must remember to reset any
   * cached pointers from the @ctx, i.e. after the call to ntfs_cluster_free(),
   * you will probably want to do:
   *	m = ctx->mrec;
   *	a = ctx->attr;
   * Assuming you cache ctx->attr in a variable @a of type ATTR_RECORD * and that
   * you cache ctx->mrec in a variable @m of type MFT_RECORD *.
   *
   * Note, ntfs_cluster_free() does not modify the runlist, so you have to remove
   * from the runlist or mark sparse the freed runs later.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
69
70
71
72
   *
   * Return the number of deallocated clusters (not counting sparse ones) on
   * success and -errno on error.
   *
511bea5ea   Anton Altaparmakov   NTFS: - Change {_...
73
   * WARNING: If @ctx is supplied, regardless of whether success or failure is
c49c31115   Richard Knutsson   [PATCH] fs/ntfs: ...
74
   *	    returned, you need to check IS_ERR(@ctx->mrec) and if 'true' the @ctx
511bea5ea   Anton Altaparmakov   NTFS: - Change {_...
75
76
77
78
79
   *	    is no longer valid, i.e. you need to either call
   *	    ntfs_attr_reinit_search_ctx() or ntfs_attr_put_search_ctx() on it.
   *	    In that case PTR_ERR(@ctx->mrec) will give you the error code for
   *	    why the mapping of the old inode failed.
   *
715dc636b   Anton Altaparmakov   NTFS: Change ntfs...
80
81
82
   * Locking: - The runlist described by @ni must be locked for writing on entry
   *	      and is locked on return.  Note the runlist may be modified when
   *	      needed runlist fragments need to be mapped.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83
84
85
86
   *	    - The volume lcn bitmap must be unlocked on entry and is unlocked
   *	      on return.
   *	    - This function takes the volume lcn bitmap lock for writing and
   *	      modifies the bitmap contents.
511bea5ea   Anton Altaparmakov   NTFS: - Change {_...
87
88
89
90
   *	    - If @ctx is NULL, the base mft record of @ni must not be mapped on
   *	      entry and it will be left unmapped on return.
   *	    - If @ctx is not NULL, the base mft record must be mapped on entry
   *	      and it will be left mapped on return.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
91
   */
715dc636b   Anton Altaparmakov   NTFS: Change ntfs...
92
  static inline s64 ntfs_cluster_free(ntfs_inode *ni, const VCN start_vcn,
511bea5ea   Anton Altaparmakov   NTFS: - Change {_...
93
  		s64 count, ntfs_attr_search_ctx *ctx)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
94
  {
c49c31115   Richard Knutsson   [PATCH] fs/ntfs: ...
95
  	return __ntfs_cluster_free(ni, start_vcn, count, ctx, false);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  }
  
  extern int ntfs_cluster_free_from_rl_nolock(ntfs_volume *vol,
  		const runlist_element *rl);
  
  /**
   * ntfs_cluster_free_from_rl - free clusters from runlist
   * @vol:	mounted ntfs volume on which to free the clusters
   * @rl:		runlist describing the clusters to free
   *
   * Free all the clusters described by the runlist @rl on the volume @vol.  In
   * the case of an error being returned, at least some of the clusters were not
   * freed.
   *
   * Return 0 on success and -errno on error.
   *
bbf1813fb   Anton Altaparmakov   NTFS: Fix cluster...
112
113
114
115
   * Locking: - This function takes the volume lcn bitmap lock for writing and
   *	      modifies the bitmap contents.
   *	    - The caller must have locked the runlist @rl for reading or
   *	      writing.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
   */
  static inline int ntfs_cluster_free_from_rl(ntfs_volume *vol,
  		const runlist_element *rl)
  {
  	int ret;
  
  	down_write(&vol->lcnbmp_lock);
  	ret = ntfs_cluster_free_from_rl_nolock(vol, rl);
  	up_write(&vol->lcnbmp_lock);
  	return ret;
  }
  
  #endif /* NTFS_RW */
  
  #endif /* defined _LINUX_NTFS_LCNALLOC_H */