MCPcopy Create free account
hub / github.com/bobranten/Ext4Fsd / Ext2Read

Function Ext2Read

Ext2Mgr/enumDisk.cpp:1161–1221  ·  view source on GitHub ↗

* Ext2Read * Read data from disk or file ... * * ARGUMENTS: * VolumeHandle: Volume Handle * Offset : Disk Offset * Length : Data Length to be read * Buffer : ... * * RETURNS: * Success: STATUS_SUCCESS * Fail: ... * * NOTES: * Both Length and Offset should be SECTOR_SIZE aligned. */

Source from the content-addressed store, hash-verified

1159 * Both Length and Offset should be SECTOR_SIZE aligned.
1160 */
1161NT::NTSTATUS
1162Ext2Read(
1163 IN HANDLE Handle,
1164 IN BOOL IsFile,
1165 IN ULONG SectorSize,
1166 IN ULONGLONG Offset,
1167 IN ULONG Length,
1168 IN PVOID Buffer
1169 )
1170{
1171 NT::NTSTATUS status;
1172 NT::IO_STATUS_BLOCK ioSb;
1173 LARGE_INTEGER address;
1174 ULONG aLength = 0;
1175 PVOID aBuffer = NULL;
1176
1177 if (SectorSize == 0 || SectorSize == 1)
1178 IsFile = TRUE;
1179
1180 ASSERT(Buffer != NULL);
1181
1182 if (IsFile) {
1183
1184 address.QuadPart = Offset;
1185 status = NT::ZwReadFile(
1186 Handle, 0, NULL, NULL, &ioSb,
1187 Buffer, Length, &address, NULL
1188 );
1189 } else {
1190
1191 address.QuadPart = Offset & (~((ULONGLONG)SectorSize - 1));
1192 aLength = (Length + SectorSize - 1)&(~(SectorSize - 1));
1193 aLength += ((ULONG)(Offset - address.QuadPart) + SectorSize - 1)
1194 & (~(SectorSize - 1));
1195
1196 aBuffer = malloc(aLength);
1197 if (!aBuffer) {
1198 status = STATUS_INSUFFICIENT_RESOURCES;
1199 goto errorout;
1200 }
1201
1202 status = NT::ZwReadFile(
1203 Handle, 0, NULL, NULL, &ioSb,
1204 aBuffer, aLength, &address, NULL
1205 );
1206
1207 if (!NT_SUCCESS(status)) {
1208 goto errorout;
1209 }
1210
1211 memmove( Buffer, (PUCHAR)aBuffer +
1212 (ULONG)(Offset - address.QuadPart), Length);
1213 }
1214
1215errorout:
1216
1217 if (aBuffer)
1218 free(aBuffer);

Callers 1

Ext2QueryVolumeFSFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected