Skip to content

Commit fc0fa7d

Browse files
NTFS: - Change ntfs_cluster_alloc() to take an extra boolean parameter
specifying whether the cluster are being allocated to extend an attribute or to fill a hole. - Change ntfs_attr_make_non_resident() to call ntfs_cluster_alloc() with @is_extension set to TRUE and remove the runlist terminator fixup code as this is now done by ntfs_cluster_alloc(). Signed-off-by: Anton Altaparmakov <aia21@cantab.net>
1 parent 511bea5 commit fc0fa7d

5 files changed

Lines changed: 25 additions & 15 deletions

File tree

‎fs/ntfs/ChangeLog‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ ToDo/Notes:
3131
- Fix potential deadlock in ntfs_mft_data_extend_allocation_nolock()
3232
error handling by passing in the active search context when calling
3333
ntfs_cluster_free().
34+
- Change ntfs_cluster_alloc() to take an extra boolean parameter
35+
specifying whether the cluster are being allocated to extend an
36+
attribute or to fill a hole.
37+
- Change ntfs_attr_make_non_resident() to call ntfs_cluster_alloc()
38+
with @is_extension set to TRUE and remove the runlist terminator
39+
fixup code as this is now done by ntfs_cluster_alloc().
3440

3541
2.1.24 - Lots of bug fixes and support more clean journal states.
3642

‎fs/ntfs/attrib.c‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,8 +1566,6 @@ int ntfs_attr_make_non_resident(ntfs_inode *ni)
15661566
new_size = (i_size_read(vi) + vol->cluster_size - 1) &
15671567
~(vol->cluster_size - 1);
15681568
if (new_size > 0) {
1569-
runlist_element *rl2;
1570-
15711569
/*
15721570
* Will need the page later and since the page lock nests
15731571
* outside all ntfs locks, we need to get the page now.
@@ -1578,7 +1576,7 @@ int ntfs_attr_make_non_resident(ntfs_inode *ni)
15781576
return -ENOMEM;
15791577
/* Start by allocating clusters to hold the attribute value. */
15801578
rl = ntfs_cluster_alloc(vol, 0, new_size >>
1581-
vol->cluster_size_bits, -1, DATA_ZONE);
1579+
vol->cluster_size_bits, -1, DATA_ZONE, TRUE);
15821580
if (IS_ERR(rl)) {
15831581
err = PTR_ERR(rl);
15841582
ntfs_debug("Failed to allocate cluster%s, error code "
@@ -1587,12 +1585,6 @@ int ntfs_attr_make_non_resident(ntfs_inode *ni)
15871585
err);
15881586
goto page_err_out;
15891587
}
1590-
/* Change the runlist terminator to LCN_ENOENT. */
1591-
rl2 = rl;
1592-
while (rl2->length)
1593-
rl2++;
1594-
BUG_ON(rl2->lcn != LCN_RL_NOT_MAPPED);
1595-
rl2->lcn = LCN_ENOENT;
15961588
} else {
15971589
rl = NULL;
15981590
page = NULL;

‎fs/ntfs/lcnalloc.c‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ int ntfs_cluster_free_from_rl_nolock(ntfs_volume *vol,
7676
* @count: number of clusters to allocate
7777
* @start_lcn: starting lcn at which to allocate the clusters (or -1 if none)
7878
* @zone: zone from which to allocate the clusters
79+
* @is_extension: if TRUE, this is an attribute extension
7980
*
8081
* Allocate @count clusters preferably starting at cluster @start_lcn or at the
8182
* current allocator position if @start_lcn is -1, on the mounted ntfs volume
@@ -86,6 +87,13 @@ int ntfs_cluster_free_from_rl_nolock(ntfs_volume *vol,
8687
* @start_vcn specifies the vcn of the first allocated cluster. This makes
8788
* merging the resulting runlist with the old runlist easier.
8889
*
90+
* If @is_extension is TRUE, the caller is allocating clusters to extend an
91+
* attribute and if it is FALSE, the caller is allocating clusters to fill a
92+
* hole in an attribute. Practically the difference is that if @is_extension
93+
* is TRUE the returned runlist will be terminated with LCN_ENOENT and if
94+
* @is_extension is FALSE the runlist will be terminated with
95+
* LCN_RL_NOT_MAPPED.
96+
*
8997
* You need to check the return value with IS_ERR(). If this is false, the
9098
* function was successful and the return value is a runlist describing the
9199
* allocated cluster(s). If IS_ERR() is true, the function failed and
@@ -137,7 +145,8 @@ int ntfs_cluster_free_from_rl_nolock(ntfs_volume *vol,
137145
*/
138146
runlist_element *ntfs_cluster_alloc(ntfs_volume *vol, const VCN start_vcn,
139147
const s64 count, const LCN start_lcn,
140-
const NTFS_CLUSTER_ALLOCATION_ZONES zone)
148+
const NTFS_CLUSTER_ALLOCATION_ZONES zone,
149+
const BOOL is_extension)
141150
{
142151
LCN zone_start, zone_end, bmp_pos, bmp_initial_pos, last_read_pos, lcn;
143152
LCN prev_lcn = 0, prev_run_len = 0, mft_zone_size;
@@ -310,7 +319,7 @@ runlist_element *ntfs_cluster_alloc(ntfs_volume *vol, const VCN start_vcn,
310319
continue;
311320
}
312321
bit = 1 << (lcn & 7);
313-
ntfs_debug("bit %i.", bit);
322+
ntfs_debug("bit 0x%x.", bit);
314323
/* If the bit is already set, go onto the next one. */
315324
if (*byte & bit) {
316325
lcn++;
@@ -729,7 +738,7 @@ switch_to_data1_zone: search_zone = 2;
729738
/* Add runlist terminator element. */
730739
if (likely(rl)) {
731740
rl[rlpos].vcn = rl[rlpos - 1].vcn + rl[rlpos - 1].length;
732-
rl[rlpos].lcn = LCN_RL_NOT_MAPPED;
741+
rl[rlpos].lcn = is_extension ? LCN_ENOENT : LCN_RL_NOT_MAPPED;
733742
rl[rlpos].length = 0;
734743
}
735744
if (likely(page && !IS_ERR(page))) {

‎fs/ntfs/lcnalloc.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ typedef enum {
4242

4343
extern runlist_element *ntfs_cluster_alloc(ntfs_volume *vol,
4444
const VCN start_vcn, const s64 count, const LCN start_lcn,
45-
const NTFS_CLUSTER_ALLOCATION_ZONES zone);
45+
const NTFS_CLUSTER_ALLOCATION_ZONES zone,
46+
const BOOL is_extension);
4647

4748
extern s64 __ntfs_cluster_free(ntfs_inode *ni, const VCN start_vcn,
4849
s64 count, ntfs_attr_search_ctx *ctx, const BOOL is_rollback);

‎fs/ntfs/mft.c‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,8 @@ static int ntfs_mft_bitmap_extend_allocation_nolock(ntfs_volume *vol)
13551355
up_write(&vol->lcnbmp_lock);
13561356
ntfs_unmap_page(page);
13571357
/* Allocate a cluster from the DATA_ZONE. */
1358-
rl2 = ntfs_cluster_alloc(vol, rl[1].vcn, 1, lcn, DATA_ZONE);
1358+
rl2 = ntfs_cluster_alloc(vol, rl[1].vcn, 1, lcn, DATA_ZONE,
1359+
TRUE);
13591360
if (IS_ERR(rl2)) {
13601361
up_write(&mftbmp_ni->runlist.lock);
13611362
ntfs_error(vol->sb, "Failed to allocate a cluster for "
@@ -1780,7 +1781,8 @@ static int ntfs_mft_data_extend_allocation_nolock(ntfs_volume *vol)
17801781
nr > min_nr ? "default" : "minimal", (long long)nr);
17811782
old_last_vcn = rl[1].vcn;
17821783
do {
1783-
rl2 = ntfs_cluster_alloc(vol, old_last_vcn, nr, lcn, MFT_ZONE);
1784+
rl2 = ntfs_cluster_alloc(vol, old_last_vcn, nr, lcn, MFT_ZONE,
1785+
TRUE);
17841786
if (likely(!IS_ERR(rl2)))
17851787
break;
17861788
if (PTR_ERR(rl2) != -ENOSPC || nr == min_nr) {

0 commit comments

Comments
 (0)