diff options
author | Kaho Ng <ngkaho1234@gmail.com> | 2016-05-21 06:03:48 +0300 |
---|---|---|
committer | Kaho Ng <ngkaho1234@gmail.com> | 2016-05-21 06:03:48 +0300 |
commit | f6ca6da116720b33e1a7561539d01ce739237b80 (patch) | |
tree | a97687d911add46b3bd5194bcda949e3f94c54d8 | |
parent | c73978e2e22f0936150cc2603d441533b50e895f (diff) |
ea: some cosmetic fixes
-rw-r--r-- | Ext3Fsd/ea.c | 402 |
1 files changed, 205 insertions, 197 deletions
diff --git a/Ext3Fsd/ea.c b/Ext3Fsd/ea.c index 6fb2639..391af57 100644 --- a/Ext3Fsd/ea.c +++ b/Ext3Fsd/ea.c @@ -12,34 +12,34 @@ #include "ext2fs.h" #include <linux/ext4_xattr.h> -PVOID
-Ext2MapUserBuffer(
- IN OUT PIRP Irp
-)
-{
- PAGED_CODE();
-
- //
- // If there is no Mdl, then we must be in the Fsd, and we can simply
- // return the UserBuffer field from the Irp.
- //
-
- if (Irp->MdlAddress == NULL) {
-
- return Irp->UserBuffer;
-
- }
- else {
-
- PVOID Address = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
-
- if (Address == NULL) {
-
- ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES);
- }
-
- return Address;
- }
+PVOID +Ext2MapUserBuffer( + IN OUT PIRP Irp +) +{ + PAGED_CODE(); + + // + // If there is no Mdl, then we must be in the Fsd, and we can simply + // return the UserBuffer field from the Irp. + // + + if (Irp->MdlAddress == NULL) { + + return Irp->UserBuffer; + + } + else { + + PVOID Address = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority); + + if (Address == NULL) { + + ExRaiseStatus(STATUS_INSUFFICIENT_RESOURCES); + } + + return Address; + } } // Ea iterator @@ -79,31 +79,31 @@ 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) {
- pEaIterator->OverFlow = TRUE;
- return EXT4_XATTR_ITERATE_STOP;
+ if ((ULONG)(4 + 1 + 1 + 2 + item->name_len + 1 + item->data_size) + > pEaIterator->RemainingUserBufferLength) { + pEaIterator->OverFlow = TRUE; + return EXT4_XATTR_ITERATE_STOP; } - pEaIterator->FullEa->NextEntryOffset = 0;
- pEaIterator->FullEa->Flags = 0;
- pEaIterator->FullEa->EaNameLength = item->name_len;
- pEaIterator->FullEa->EaValueLength = item->data_size;
- RtlCopyMemory(&pEaIterator->FullEa->EaName[0],
- item->name,
+ pEaIterator->FullEa->NextEntryOffset = 0; + pEaIterator->FullEa->Flags = 0; + pEaIterator->FullEa->EaNameLength = item->name_len; + pEaIterator->FullEa->EaValueLength = item->data_size; + RtlCopyMemory(&pEaIterator->FullEa->EaName[0], + item->name, item->name_len); - RtlCopyMemory(&pEaIterator->FullEa->EaName[0] + item->name_len + 1,
- item->data,
+ RtlCopyMemory(&pEaIterator->FullEa->EaName[0] + item->name_len + 1, + item->data, item->data_size); // Link FullEa and LastFullEa together - if (pEaIterator->LastFullEa) {
- pEaIterator->LastFullEa->NextEntryOffset =
- (PCHAR)pEaIterator->FullEa - (PCHAR)pEaIterator->LastFullEa;
- }
-
- pEaIterator->LastFullEa = pEaIterator->FullEa;
- pEaIterator->FullEa = (PFILE_FULL_EA_INFORMATION)
- (&pEaIterator->FullEa->EaName[0] + item->name_len + 1 + item->data_size);
+ if (pEaIterator->LastFullEa) { + pEaIterator->LastFullEa->NextEntryOffset = + (PCHAR)pEaIterator->FullEa - (PCHAR)pEaIterator->LastFullEa; + } + + 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; if (pEaIterator->ReturnSingleEntry) @@ -208,161 +208,169 @@ Ext2QueryEa ( __leave; } else { int i = 0; - PFILE_FULL_EA_INFORMATION FullEa = UserBuffer, + PFILE_FULL_EA_INFORMATION FullEa = (PFILE_FULL_EA_INFORMATION)UserBuffer, LastFullEa = NULL; if (RemainingUserBufferLength) RtlZeroMemory(FullEa, RemainingUserBufferLength); - if (UserEaList != NULL) {
- PFILE_GET_EA_INFORMATION GetEa;
- for (GetEa = (PFILE_GET_EA_INFORMATION)&UserEaList[0];
- GetEa < (PFILE_GET_EA_INFORMATION)((PUCHAR)UserEaList
- + UserEaListLength);
- GetEa = (GetEa->NextEntryOffset == 0
- ? (PFILE_GET_EA_INFORMATION)MAXUINT_PTR
- : (PFILE_GET_EA_INFORMATION)((PUCHAR)GetEa
- + GetEa->NextEntryOffset))) {
-
- size_t ItemSize;
- OEM_STRING Str;
- OEM_STRING OutputEaName;
-
- Str.MaximumLength = Str.Length = GetEa->EaNameLength;
- Str.Buffer = &GetEa->EaName[0];
-
- //
- // At the moment we only need to know whether the item exists
- // and its size.
- //
- Status = Ext2WinntError(ext4_fs_get_xattr(&xattr_ref,
- EXT4_XATTR_INDEX_USER,
- Str.Buffer,
- Str.Length,
- NULL,
- 0,
- &ItemSize));
- if (!NT_SUCCESS(Status))
- continue;
-
- //
- // We were not able to locate the name therefore we must
- // dummy up a entry for the query. The needed Ea size is
- // the size of the name + 4 (next entry offset) + 1 (flags)
- // + 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) {
-
- Status = i ? STATUS_BUFFER_OVERFLOW : STATUS_BUFFER_TOO_SMALL;
- __leave;
- }
- FullEa->NextEntryOffset = 0;
- FullEa->Flags = 0;
- FullEa->EaNameLength = GetEa->EaNameLength;
- FullEa->EaValueLength = ItemSize;
- RtlCopyMemory(&FullEa->EaName[0],
- &GetEa->EaName[0],
- GetEa->EaNameLength);
-
- //
- // This query must succeed, or is guarenteed to succeed
- // since we are only looking up
- // an EA entry in a in-memory tree structure.
- // Otherwise that means someone might be operating on
- // the xattr_ref without acquiring Inode lock.
- //
- ASSERT(NT_SUCCESS(Ext2WinntError(
- ext4_fs_get_xattr(&xattr_ref,
- EXT4_XATTR_INDEX_USER,
- Str.Buffer,
- Str.Length,
- &FullEa->EaName[0] + FullEa->EaNameLength + 1,
- ItemSize,
- &ItemSize
- ))));
- FullEa->EaValueLength = ItemSize;
-
- // Link FullEa and LastFullEa together
- if (LastFullEa)
- LastFullEa->NextEntryOffset = (PCHAR)FullEa - (PCHAR)LastFullEa;
-
- LastFullEa = FullEa;
- FullEa = (PFILE_FULL_EA_INFORMATION)
- (&FullEa->EaName[0] + FullEa->EaNameLength + 1 + ItemSize);
- RemainingUserBufferLength -= 4 + 1 + 1 + 2 + GetEa->EaNameLength + 1 + ItemSize;
- i++;
- }
- } else if (IndexSpecified) {
- struct EaIterator EaIterator;
- //
- // The user supplied an index into the Ea list.
- //
+ if (UserEaList != NULL) { + PFILE_GET_EA_INFORMATION GetEa; + for (GetEa = (PFILE_GET_EA_INFORMATION)&UserEaList[0]; + GetEa < (PFILE_GET_EA_INFORMATION)((PUCHAR)UserEaList + + UserEaListLength); + GetEa = (GetEa->NextEntryOffset == 0 + ? (PFILE_GET_EA_INFORMATION)MAXUINT_PTR + : (PFILE_GET_EA_INFORMATION)((PUCHAR)GetEa + + GetEa->NextEntryOffset))) { + + size_t ItemSize; + OEM_STRING Str; + + Str.MaximumLength = Str.Length = GetEa->EaNameLength; + Str.Buffer = &GetEa->EaName[0]; + + // + // At the moment we only need to know whether the item exists + // and its size. + // + Status = Ext2WinntError(ext4_fs_get_xattr(&xattr_ref, + EXT4_XATTR_INDEX_USER, + Str.Buffer, + Str.Length, + NULL, + 0, + &ItemSize)); + if (!NT_SUCCESS(Status)) + continue; + + // + // We were not able to locate the name therefore we must + // dummy up a entry for the query. The needed Ea size is + // the size of the name + 4 (next entry offset) + 1 (flags) + // + 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) { + + Status = i ? STATUS_BUFFER_OVERFLOW : STATUS_BUFFER_TOO_SMALL; + __leave; + } + FullEa->NextEntryOffset = 0; + FullEa->Flags = 0; + FullEa->EaNameLength = GetEa->EaNameLength; + FullEa->EaValueLength = ItemSize; + RtlCopyMemory(&FullEa->EaName[0], + &GetEa->EaName[0], + GetEa->EaNameLength); + + // + // This query must succeed, or is guarenteed to succeed + // since we are only looking up + // an EA entry in a in-memory tree structure. + // Otherwise that means someone might be operating on + // the xattr_ref without acquiring Inode lock. + // + ASSERT(NT_SUCCESS(Ext2WinntError( + ext4_fs_get_xattr(&xattr_ref, + EXT4_XATTR_INDEX_USER, + Str.Buffer, + Str.Length, + &FullEa->EaName[0] + FullEa->EaNameLength + 1, + ItemSize, + &ItemSize + )))); + FullEa->EaValueLength = ItemSize; + + // Link FullEa and LastFullEa together + if (LastFullEa) + LastFullEa->NextEntryOffset = (PCHAR)FullEa - (PCHAR)LastFullEa; + + LastFullEa = FullEa; + FullEa = (PFILE_FULL_EA_INFORMATION) + (&FullEa->EaName[0] + FullEa->EaNameLength + 1 + ItemSize); + RemainingUserBufferLength -= 4 + 1 + 1 + 2 + GetEa->EaNameLength + 1 + ItemSize; + i++; + } + } + else if (IndexSpecified) { + struct EaIterator EaIterator; + // + // The user supplied an index into the Ea list. + // if (RemainingUserBufferLength) - RtlZeroMemory(FullEa, RemainingUserBufferLength);
-
- EaIterator.OverFlow = FALSE;
- EaIterator.RemainingUserBufferLength = UserBufferLength;
- // In this case, return only an entry.
- EaIterator.ReturnSingleEntry = TRUE;
- EaIterator.FullEa = (PFILE_FULL_EA_INFORMATION)UserBuffer;
- EaIterator.LastFullEa = NULL;
- EaIterator.UserBufferLength = UserBufferLength;
- EaIterator.EaIndex = UserEaIndex;
- EaIterator.EaIndexCounter = 1;
-
- xattr_ref.iter_arg = &EaIterator;
- ext4_fs_xattr_iterate(&xattr_ref, Ext2IterateAllEa);
-
- RemainingUserBufferLength = EaIterator.RemainingUserBufferLength;
-
- Status = STATUS_SUCCESS;
-
- // It seems that the item isn't found
- if (RemainingUserBufferLength == UserBufferLength)
- Status = STATUS_OBJECTID_NOT_FOUND;
-
- if (EaIterator.OverFlow)
- Status = STATUS_BUFFER_OVERFLOW;
-
- } else {
- struct EaIterator EaIterator;
- //
- // Else perform a simple scan, taking into account the restart
- // flag and the position of the next Ea stored in the Ccb.
- //
- if (RestartScan)
- Ccb->EaIndex = 1;
-
+ RtlZeroMemory(FullEa, RemainingUserBufferLength); + + EaIterator.OverFlow = FALSE; + EaIterator.RemainingUserBufferLength = UserBufferLength; + // In this case, return only an entry. + EaIterator.ReturnSingleEntry = TRUE; + EaIterator.FullEa = (PFILE_FULL_EA_INFORMATION)UserBuffer; + EaIterator.LastFullEa = NULL; + EaIterator.UserBufferLength = UserBufferLength; + EaIterator.EaIndex = UserEaIndex; + EaIterator.EaIndexCounter = 1; + + xattr_ref.iter_arg = &EaIterator; + ext4_fs_xattr_iterate(&xattr_ref, Ext2IterateAllEa); + + RemainingUserBufferLength = EaIterator.RemainingUserBufferLength; + + Status = STATUS_SUCCESS; + + // It seems that the item isn't found + if (RemainingUserBufferLength == UserBufferLength) + Status = STATUS_OBJECTID_NOT_FOUND; + + if (EaIterator.OverFlow) { + if (RemainingUserBufferLength == UserBufferLength) + Status = STATUS_BUFFER_TOO_SMALL; + else + Status = STATUS_BUFFER_OVERFLOW; + } + + } else { + struct EaIterator EaIterator; + // + // Else perform a simple scan, taking into account the restart + // flag and the position of the next Ea stored in the Ccb. + // + if (RestartScan) + Ccb->EaIndex = 1; + if (RemainingUserBufferLength) - RtlZeroMemory(FullEa, RemainingUserBufferLength);
-
- EaIterator.OverFlow = FALSE;
- EaIterator.RemainingUserBufferLength = UserBufferLength;
- EaIterator.ReturnSingleEntry = ReturnSingleEntry;
- EaIterator.FullEa = (PFILE_FULL_EA_INFORMATION)UserBuffer;
- EaIterator.LastFullEa = NULL;
- EaIterator.UserBufferLength = UserBufferLength;
- EaIterator.EaIndex = Ccb->EaIndex;
- EaIterator.EaIndexCounter = 1;
-
- xattr_ref.iter_arg = &EaIterator;
- ext4_fs_xattr_iterate(&xattr_ref, Ext2IterateAllEa);
-
- RemainingUserBufferLength = EaIterator.RemainingUserBufferLength;
-
- if (Ccb->EaIndex < EaIterator.EaIndexCounter)
- Ccb->EaIndex = EaIterator.EaIndexCounter;
-
- // See if we reached the end of EA list
- if (!EaIterator.OverFlow && !EaIterator.ReturnSingleEntry)
- Ccb->EaIndex = 1;
-
- Status = STATUS_SUCCESS;
-
- if (EaIterator.OverFlow)
- Status = STATUS_BUFFER_OVERFLOW;
-
+ RtlZeroMemory(FullEa, RemainingUserBufferLength); + + EaIterator.OverFlow = FALSE; + EaIterator.RemainingUserBufferLength = UserBufferLength; + EaIterator.ReturnSingleEntry = ReturnSingleEntry; + EaIterator.FullEa = (PFILE_FULL_EA_INFORMATION)UserBuffer; + EaIterator.LastFullEa = NULL; + EaIterator.UserBufferLength = UserBufferLength; + EaIterator.EaIndex = Ccb->EaIndex; + EaIterator.EaIndexCounter = 1; + + xattr_ref.iter_arg = &EaIterator; + ext4_fs_xattr_iterate(&xattr_ref, Ext2IterateAllEa); + + RemainingUserBufferLength = EaIterator.RemainingUserBufferLength; + + if (Ccb->EaIndex < EaIterator.EaIndexCounter) + Ccb->EaIndex = EaIterator.EaIndexCounter; + + // See if we reached the end of EA list + if (!EaIterator.OverFlow && !EaIterator.ReturnSingleEntry) + Ccb->EaIndex = 1; + + Status = STATUS_SUCCESS; + + if (EaIterator.OverFlow) { + if (RemainingUserBufferLength == UserBufferLength) + Status = STATUS_BUFFER_TOO_SMALL; + else + Status = STATUS_BUFFER_OVERFLOW; + } + } } } |