diff options
Diffstat (limited to 'fs/ntfs')
-rw-r--r-- | fs/ntfs/ChangeLog | 1 | ||||
-rw-r--r-- | fs/ntfs/attrib.c | 40 | ||||
-rw-r--r-- | fs/ntfs/attrib.h | 2 |
3 files changed, 43 insertions, 0 deletions
diff --git a/fs/ntfs/ChangeLog b/fs/ntfs/ChangeLog index 96224c020797..29841bf82264 100644 --- a/fs/ntfs/ChangeLog +++ b/fs/ntfs/ChangeLog | |||
@@ -59,6 +59,7 @@ ToDo/Notes: | |||
59 | index entry is in the index root, we forgot to set the @ir pointer in | 59 | index entry is in the index root, we forgot to set the @ir pointer in |
60 | the index context. Thanks to Yura Pakhuchiy for finding this bug. | 60 | the index context. Thanks to Yura Pakhuchiy for finding this bug. |
61 | - Remove bogus setting of PageError in ntfs_read_compressed_block(). | 61 | - Remove bogus setting of PageError in ntfs_read_compressed_block(). |
62 | - Add fs/ntfs/attrib.[hc]::ntfs_resident_attr_value_resize(). | ||
62 | 63 | ||
63 | 2.1.23 - Implement extension of resident files and make writing safe as well as | 64 | 2.1.23 - Implement extension of resident files and make writing safe as well as |
64 | many bug fixes, cleanups, and enhancements... | 65 | many bug fixes, cleanups, and enhancements... |
diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c index cd0f9e740b14..79dda3980684 100644 --- a/fs/ntfs/attrib.c +++ b/fs/ntfs/attrib.c | |||
@@ -1247,6 +1247,46 @@ int ntfs_attr_record_resize(MFT_RECORD *m, ATTR_RECORD *a, u32 new_size) | |||
1247 | } | 1247 | } |
1248 | 1248 | ||
1249 | /** | 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 | |||
1289 | /** | ||
1250 | * ntfs_attr_make_non_resident - convert a resident to a non-resident attribute | 1290 | * ntfs_attr_make_non_resident - convert a resident to a non-resident attribute |
1251 | * @ni: ntfs inode describing the attribute to convert | 1291 | * @ni: ntfs inode describing the attribute to convert |
1252 | * | 1292 | * |
diff --git a/fs/ntfs/attrib.h b/fs/ntfs/attrib.h index 0e4ac6d3c0e7..0618ed6fd7b3 100644 --- a/fs/ntfs/attrib.h +++ b/fs/ntfs/attrib.h | |||
@@ -99,6 +99,8 @@ extern int ntfs_attr_can_be_resident(const ntfs_volume *vol, | |||
99 | const ATTR_TYPE type); | 99 | const ATTR_TYPE type); |
100 | 100 | ||
101 | extern int ntfs_attr_record_resize(MFT_RECORD *m, ATTR_RECORD *a, u32 new_size); | 101 | 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); | ||
102 | 104 | ||
103 | extern int ntfs_attr_make_non_resident(ntfs_inode *ni); | 105 | extern int ntfs_attr_make_non_resident(ntfs_inode *ni); |
104 | 106 | ||