diff options
author | Anton Altaparmakov <aia21@cantab.net> | 2005-09-08 15:40:32 -0400 |
---|---|---|
committer | Anton Altaparmakov <aia21@cantab.net> | 2005-09-08 15:40:32 -0400 |
commit | 0aacceacf35451ffb771ec825555e98c5dce8b01 (patch) | |
tree | 91ee974bcc56bf4bb55352098fa1b69131a2fe89 /fs/ntfs/attrib.c | |
parent | f25dfb5e44fa8641961780d681bc1871abcfb861 (diff) |
NTFS: Add fs/ntfs/attrib.[hc]::ntfs_resident_attr_value_resize().
Signed-off-by: Anton Altaparmakov <aia21@cantab.net>
Diffstat (limited to 'fs/ntfs/attrib.c')
-rw-r--r-- | fs/ntfs/attrib.c | 40 |
1 files changed, 40 insertions, 0 deletions
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 | * |