Skip to content

Commit 0aaccea

Browse files
NTFS: Add fs/ntfs/attrib.[hc]::ntfs_resident_attr_value_resize().
Signed-off-by: Anton Altaparmakov <aia21@cantab.net>
1 parent f25dfb5 commit 0aaccea

3 files changed

Lines changed: 43 additions & 0 deletions

File tree

‎fs/ntfs/ChangeLog‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ ToDo/Notes:
5959
index entry is in the index root, we forgot to set the @ir pointer in
6060
the index context. Thanks to Yura Pakhuchiy for finding this bug.
6161
- Remove bogus setting of PageError in ntfs_read_compressed_block().
62+
- Add fs/ntfs/attrib.[hc]::ntfs_resident_attr_value_resize().
6263

6364
2.1.23 - Implement extension of resident files and make writing safe as well as
6465
many bug fixes, cleanups, and enhancements...

‎fs/ntfs/attrib.c‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,6 +1246,46 @@ int ntfs_attr_record_resize(MFT_RECORD *m, ATTR_RECORD *a, u32 new_size)
12461246
return 0;
12471247
}
12481248

1249+
/**
1250+
* ntfs_resident_attr_value_resize - resize the value of a resident attribute
1251+
* @m: mft record containing attribute record
1252+
* @a: attribute record whose value to resize
1253+
* @new_size: new size in bytes to which to resize the attribute value of @a
1254+
*
1255+
* Resize the value of the attribute @a in the mft record @m to @new_size bytes.
1256+
* If the value is made bigger, the newly allocated space is cleared.
1257+
*
1258+
* Return 0 on success and -errno on error. The following error codes are
1259+
* defined:
1260+
* -ENOSPC - Not enough space in the mft record @m to perform the resize.
1261+
*
1262+
* Note: On error, no modifications have been performed whatsoever.
1263+
*
1264+
* Warning: If you make a record smaller without having copied all the data you
1265+
* are interested in the data may be overwritten.
1266+
*/
1267+
int ntfs_resident_attr_value_resize(MFT_RECORD *m, ATTR_RECORD *a,
1268+
const u32 new_size)
1269+
{
1270+
u32 old_size;
1271+
1272+
/* Resize the resident part of the attribute record. */
1273+
if (ntfs_attr_record_resize(m, a,
1274+
le16_to_cpu(a->data.resident.value_offset) + new_size))
1275+
return -ENOSPC;
1276+
/*
1277+
* The resize succeeded! If we made the attribute value bigger, clear
1278+
* the area between the old size and @new_size.
1279+
*/
1280+
old_size = le32_to_cpu(a->data.resident.value_length);
1281+
if (new_size > old_size)
1282+
memset((u8*)a + le16_to_cpu(a->data.resident.value_offset) +
1283+
old_size, 0, new_size - old_size);
1284+
/* Finally update the length of the attribute value. */
1285+
a->data.resident.value_length = cpu_to_le32(new_size);
1286+
return 0;
1287+
}
1288+
12491289
/**
12501290
* ntfs_attr_make_non_resident - convert a resident to a non-resident attribute
12511291
* @ni: ntfs inode describing the attribute to convert

‎fs/ntfs/attrib.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ extern int ntfs_attr_can_be_resident(const ntfs_volume *vol,
9999
const ATTR_TYPE type);
100100

101101
extern int ntfs_attr_record_resize(MFT_RECORD *m, ATTR_RECORD *a, u32 new_size);
102+
extern int ntfs_resident_attr_value_resize(MFT_RECORD *m, ATTR_RECORD *a,
103+
const u32 new_size);
102104

103105
extern int ntfs_attr_make_non_resident(ntfs_inode *ni);
104106

0 commit comments

Comments
 (0)