From 73474b68db45232f409a249700d519b0ddcc98e5 Mon Sep 17 00:00:00 2001 From: cha0smaster Date: Thu, 27 Oct 2005 21:20:30 +0000 Subject: [PATCH] Fix ntfs_non_resident_attr_expand bug, that occured if we enlarge sparse or compressed file, but do not need to allocate new clusters to perfrom this. --- ChangeLog | 5 ++++- libntfs/attrib.c | 32 ++++++++++++++++++-------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8c1f2974..e90b170f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -44,7 +44,10 @@ xx/xx/2005 - 1.12.2-WIP key after it is decrypted (this is ifdeffed out by default). (Anton) - fflush() ntfs_log_ streams. (Christophe) - Working with regular files needs no longer the --force option, - except for mkntfs. (Szaka) + except for mkntfs. (Szaka) + - Fix ntfs_non_resident_attr_expand bug, that occured if we enlarge + sparse or compressed file, but do not need to allocate new clusters to + perfrom this. (Yura) 10/10/2005 - 1.12.1 - Minor fix to location of mount.ntfs-fuse and mkfs.ntfs. diff --git a/libntfs/attrib.c b/libntfs/attrib.c index 6f80783f..ee09fc03 100644 --- a/libntfs/attrib.c +++ b/libntfs/attrib.c @@ -4619,8 +4619,10 @@ static int ntfs_non_resident_attr_expand(ntfs_attr *na, const s64 newsize) runlist *rl, *rln; int err; - ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x.\n", (unsigned long - long)na->ni->mft_no, na->type); + ntfs_log_trace("Entering for inode 0x%llx, attr 0x%x, new size %lld, " + "current size %lld.\n", + (unsigned long long)na->ni->mft_no, na->type, + (long long)newsize, (long long)na->data_size); vol = na->ni->vol; @@ -4761,24 +4763,26 @@ static int ntfs_non_resident_attr_expand(ntfs_attr *na, const s64 newsize) } a = ctx->attr; - /* Update allocated size only if it is changed. */ + /* Update allocated and compressed size only if we changed runlist. */ if ((na->allocated_size >> vol->cluster_size_bits) < first_free_vcn) { na->allocated_size = first_free_vcn << vol->cluster_size_bits; a->allocated_size = cpu_to_sle64(na->allocated_size); - } - /* Update compressed_size if present. */ - if (NAttrSparse(na) || NAttrCompressed(na)) { - s64 new_compr_size; + /* Update compressed_size if present. */ + if (NAttrSparse(na) || NAttrCompressed(na)) { + s64 new_compr_size; - new_compr_size = ntfs_rl_get_compressed_size(vol, na->rl); - if (new_compr_size == -1) { - err = errno; - ntfs_log_trace("BUG! Leaving inconstant metadata.\n"); - goto put_err_out; + new_compr_size = ntfs_rl_get_compressed_size(vol, + na->rl); + if (new_compr_size == -1) { + err = errno; + ntfs_log_trace("BUG! Leaving inconstant " + "metadata.\n"); + goto put_err_out; + } + na->compressed_size = new_compr_size; + a->compressed_size = cpu_to_sle64(new_compr_size); } - na->compressed_size = new_compr_size; - a->compressed_size = cpu_to_sle64(new_compr_size); } /* Update data size. */