diff options
author | Kaho Ng <ngkaho1234@gmail.com> | 2016-05-30 09:12:52 +0300 |
---|---|---|
committer | Kaho Ng <ngkaho1234@gmail.com> | 2016-05-30 09:12:52 +0300 |
commit | b15d99951e2fdf09db288b2a9a195c860c1d9312 (patch) | |
tree | 12eb96fdf0863261788d3a44b6270ca5b5a942df /Ext3Fsd | |
parent | 4a4512eb171b6f926bb199060665df5213b68ced (diff) |
EA: takes alignment into account
Diffstat (limited to 'Ext3Fsd')
-rw-r--r-- | Ext3Fsd/ea.c | 27 | ||||
-rw-r--r-- | Ext3Fsd/ext4/ext4_xattr.c | 5 | ||||
-rw-r--r-- | Ext3Fsd/fileinfo.c | 18 | ||||
-rw-r--r-- | Ext3Fsd/include/linux/ext4_xattr.h | 5 |
4 files changed, 34 insertions, 21 deletions
diff --git a/Ext3Fsd/ea.c b/Ext3Fsd/ea.c index 2032aea..26e3654 100644 --- a/Ext3Fsd/ea.c +++ b/Ext3Fsd/ea.c @@ -65,10 +65,13 @@ struct EaIterator { ULONG EaIndexCounter; }; -static int Ext2IterateAllEa(struct ext4_xattr_ref *xattr_ref, struct ext4_xattr_item *item) +static int Ext2IterateAllEa(struct ext4_xattr_ref *xattr_ref, struct ext4_xattr_item *item, BOOL is_last) { struct EaIterator *pEaIterator = xattr_ref->iter_arg; + ULONG EaEntrySize = 4 + 1 + 1 + 2 + item->name_len + 1 + item->data_size; ASSERT(pEaIterator); + if (!is_last && !pEaIterator->ReturnSingleEntry) + EaEntrySize = ALIGN_UP(EaEntrySize, ULONG); // Start iteration from index specified if (pEaIterator->EaIndexCounter < pEaIterator->EaIndex) { @@ -77,8 +80,7 @@ static int Ext2IterateAllEa(struct ext4_xattr_ref *xattr_ref, struct ext4_xattr_ } pEaIterator->EaIndexCounter++; - if ((ULONG)(4 + 1 + 1 + 2 + item->name_len + 1 + item->data_size) - > pEaIterator->RemainingUserBufferLength) { + if (EaEntrySize > pEaIterator->RemainingUserBufferLength) { pEaIterator->OverFlow = TRUE; return EXT4_XATTR_ITERATE_STOP; } @@ -101,8 +103,8 @@ static int Ext2IterateAllEa(struct ext4_xattr_ref *xattr_ref, struct ext4_xattr_ pEaIterator->LastFullEa = pEaIterator->FullEa; pEaIterator->FullEa = (PFILE_FULL_EA_INFORMATION) - (&pEaIterator->FullEa->EaName[0] + item->name_len + 1 + item->data_size); - pEaIterator->RemainingUserBufferLength -= 4 + 1 + 1 + 2 + item->name_len + 1 + item->data_size; + ((PCHAR)pEaIterator->FullEa + EaEntrySize); + pEaIterator->RemainingUserBufferLength -= EaEntrySize; if (pEaIterator->ReturnSingleEntry) return EXT4_XATTR_ITERATE_STOP; @@ -220,6 +222,8 @@ Ext2QueryEa ( size_t ItemSize; OEM_STRING Str; + ULONG EaEntrySize; + BOOL is_last = !GetEa->NextEntryOffset; Str.MaximumLength = Str.Length = GetEa->EaNameLength; Str.Buffer = &GetEa->EaName[0]; @@ -245,8 +249,11 @@ Ext2QueryEa ( // + 1 (name length) + 2 (value length) + the name length + // 1 (null byte) + Data Size. // - if ((ULONG)(4 + 1 + 1 + 2 + GetEa->EaNameLength + 1 + ItemSize) - > RemainingUserBufferLength) { + EaEntrySize = 4 + 1 + 1 + 2 + GetEa->EaNameLength + 1 + ItemSize; + if (!is_last) + EaEntrySize = ALIGN_UP(EaEntrySize, ULONG); + + if (EaEntrySize > RemainingUserBufferLength) { Status = i ? STATUS_BUFFER_OVERFLOW : STATUS_BUFFER_TOO_SMALL; __leave; @@ -283,8 +290,8 @@ Ext2QueryEa ( LastFullEa = FullEa; FullEa = (PFILE_FULL_EA_INFORMATION) - (&FullEa->EaName[0] + FullEa->EaNameLength + 1 + ItemSize); - RemainingUserBufferLength -= 4 + 1 + 1 + 2 + GetEa->EaNameLength + 1 + ItemSize; + ((PCHAR)FullEa + EaEntrySize); + RemainingUserBufferLength -= EaEntrySize; i++; } } else if (IndexSpecified) { @@ -631,4 +638,4 @@ Ext2SetEa ( } } return Status; -}
\ No newline at end of file +} diff --git a/Ext3Fsd/ext4/ext4_xattr.c b/Ext3Fsd/ext4/ext4_xattr.c index 993e712..ef81b8a 100644 --- a/Ext3Fsd/ext4/ext4_xattr.c +++ b/Ext3Fsd/ext4/ext4_xattr.c @@ -927,7 +927,8 @@ Finish: void ext4_fs_xattr_iterate(struct ext4_xattr_ref *ref, int (*iter)(struct ext4_xattr_ref *ref, - struct ext4_xattr_item *item)) + struct ext4_xattr_item *item, + BOOL is_last)) { struct ext4_xattr_item *item; if (!ref->iter_from) { @@ -953,7 +954,7 @@ void ext4_fs_xattr_iterate(struct ext4_xattr_ref *ref, else next_item = NULL; if (iter) - ret = iter(ref, item); + ret = iter(ref, item, !next_item); if (ret != EXT4_XATTR_ITERATE_CONT) { if (ret == EXT4_XATTR_ITERATE_STOP) diff --git a/Ext3Fsd/fileinfo.c b/Ext3Fsd/fileinfo.c index 51ee17a..25e17a4 100644 --- a/Ext3Fsd/fileinfo.c +++ b/Ext3Fsd/fileinfo.c @@ -30,11 +30,15 @@ extern PEXT2_GLOBAL Ext2Global; #pragma alloc_text(PAGE, Ext2DeleteFile) #endif -static int Ext2IterateAllEa(struct ext4_xattr_ref *xattr_ref, struct ext4_xattr_item *item) +static int Ext2IterateAllEa(struct ext4_xattr_ref *xattr_ref, struct ext4_xattr_item *item, BOOL is_last) { - PULONG EaSize = xattr_ref->iter_arg; - *EaSize += 4 + 1 + 1 + 2 + item->name_len + 1 + item->data_size; - return EXT4_XATTR_ITERATE_CONT; + PULONG EaSize = xattr_ref->iter_arg; + ULONG EaEntrySize = 4 + 1 + 1 + 2 + item->name_len + 1 + item->data_size; + if (!is_last) + EaEntrySize = ALIGN_UP(EaEntrySize, ULONG); + + *EaSize += EaEntrySize; + return EXT4_XATTR_ITERATE_CONT; } NTSTATUS @@ -213,7 +217,7 @@ Ext2QueryFileInformation (IN PEXT2_IRP_CONTEXT IrpContext) case FileEaInformation: { - struct ext4_xattr_ref xattr_ref; + struct ext4_xattr_ref xattr_ref; PFILE_EA_INFORMATION FileEaInformation; if (Length < sizeof(FILE_EA_INFORMATION)) { @@ -229,7 +233,7 @@ Ext2QueryFileInformation (IN PEXT2_IRP_CONTEXT IrpContext) __leave; xattr_ref.iter_arg = &FileEaInformation->EaSize; - FileEaInformation->EaSize = xattr_ref.ea_size; + ext4_fs_xattr_iterate(&xattr_ref, Ext2IterateAllEa); ext4_fs_put_xattr_ref(&xattr_ref); Irp->IoStatus.Information = sizeof(FILE_EA_INFORMATION); @@ -2084,4 +2088,4 @@ Ext2DeleteFile( &Mcb->FullName, ext3_free_blocks_count(SUPER_BLOCK))); return Status; -}
\ No newline at end of file +} diff --git a/Ext3Fsd/include/linux/ext4_xattr.h b/Ext3Fsd/include/linux/ext4_xattr.h index 07e03e0..8eaae20 100644 --- a/Ext3Fsd/include/linux/ext4_xattr.h +++ b/Ext3Fsd/include/linux/ext4_xattr.h @@ -178,8 +178,9 @@ int ext4_fs_get_xattr(struct ext4_xattr_ref *ref, __u8 name_index, size_t buf_size, size_t *data_size); void ext4_fs_xattr_iterate(struct ext4_xattr_ref *ref, - int (*iter)(struct ext4_xattr_ref *ref, - struct ext4_xattr_item *item)); + int(*iter)(struct ext4_xattr_ref *ref, + struct ext4_xattr_item *item, + BOOL is_last)); void ext4_fs_xattr_iterate_reset(struct ext4_xattr_ref *ref); |