blob: a6a8827882e73c71705ebf9ec174805e0a75dc8e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * lcnalloc.h - Exports for NTFS kernel cluster (de)allocation. Part of the
3 * Linux-NTFS project.
4 *
Anton Altaparmakov715dc632005-09-23 11:24:28 +01005 * Copyright (c) 2004-2005 Anton Altaparmakov
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
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
23#ifndef _LINUX_NTFS_LCNALLOC_H
24#define _LINUX_NTFS_LCNALLOC_H
25
26#ifdef NTFS_RW
27
28#include <linux/fs.h>
29
30#include "types.h"
Anton Altaparmakov715dc632005-09-23 11:24:28 +010031#include "inode.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include "runlist.h"
33#include "volume.h"
34
35typedef enum {
36 FIRST_ZONE = 0, /* For sanity checking. */
37 MFT_ZONE = 0, /* Allocate from $MFT zone. */
38 DATA_ZONE = 1, /* Allocate from $DATA zone. */
39 LAST_ZONE = 1, /* For sanity checking. */
40} NTFS_CLUSTER_ALLOCATION_ZONES;
41
42extern runlist_element *ntfs_cluster_alloc(ntfs_volume *vol,
43 const VCN start_vcn, const s64 count, const LCN start_lcn,
44 const NTFS_CLUSTER_ALLOCATION_ZONES zone);
45
Anton Altaparmakov715dc632005-09-23 11:24:28 +010046extern s64 __ntfs_cluster_free(ntfs_inode *ni, const VCN start_vcn,
47 s64 count, const BOOL is_rollback);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49/**
50 * ntfs_cluster_free - free clusters on an ntfs volume
Anton Altaparmakov715dc632005-09-23 11:24:28 +010051 * @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
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 * @count: number of clusters to free or -1 for all clusters
54 *
55 * Free @count clusters starting at the cluster @start_vcn in the runlist
Anton Altaparmakov715dc632005-09-23 11:24:28 +010056 * described by the ntfs inode @ni.
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 *
58 * If @count is -1, all clusters from @start_vcn to the end of the runlist are
59 * deallocated. Thus, to completely free all clusters in a runlist, use
60 * @start_vcn = 0 and @count = -1.
61 *
62 * Note, ntfs_cluster_free() does not modify the runlist at all, so the caller
63 * has to deal with it later.
64 *
65 * Return the number of deallocated clusters (not counting sparse ones) on
66 * success and -errno on error.
67 *
Anton Altaparmakov715dc632005-09-23 11:24:28 +010068 * 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
70 * needed runlist fragments need to be mapped.
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 * - The volume lcn bitmap must be unlocked on entry and is unlocked
72 * on return.
73 * - This function takes the volume lcn bitmap lock for writing and
74 * modifies the bitmap contents.
75 */
Anton Altaparmakov715dc632005-09-23 11:24:28 +010076static inline s64 ntfs_cluster_free(ntfs_inode *ni, const VCN start_vcn,
77 s64 count)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
Anton Altaparmakov715dc632005-09-23 11:24:28 +010079 return __ntfs_cluster_free(ni, start_vcn, count, FALSE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
81
82extern int ntfs_cluster_free_from_rl_nolock(ntfs_volume *vol,
83 const runlist_element *rl);
84
85/**
86 * ntfs_cluster_free_from_rl - free clusters from runlist
87 * @vol: mounted ntfs volume on which to free the clusters
88 * @rl: runlist describing the clusters to free
89 *
90 * Free all the clusters described by the runlist @rl on the volume @vol. In
91 * the case of an error being returned, at least some of the clusters were not
92 * freed.
93 *
94 * Return 0 on success and -errno on error.
95 *
Anton Altaparmakovbbf18132005-09-08 21:09:06 +010096 * Locking: - This function takes the volume lcn bitmap lock for writing and
97 * modifies the bitmap contents.
98 * - The caller must have locked the runlist @rl for reading or
99 * writing.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 */
101static inline int ntfs_cluster_free_from_rl(ntfs_volume *vol,
102 const runlist_element *rl)
103{
104 int ret;
105
106 down_write(&vol->lcnbmp_lock);
107 ret = ntfs_cluster_free_from_rl_nolock(vol, rl);
108 up_write(&vol->lcnbmp_lock);
109 return ret;
110}
111
112#endif /* NTFS_RW */
113
114#endif /* defined _LINUX_NTFS_LCNALLOC_H */