| 1356 | |
| 1357 | |
| 1358 | BOOLEAN |
| 1359 | Ext2BuildName( |
| 1360 | IN OUT PUNICODE_STRING Target, |
| 1361 | IN PUNICODE_STRING File, |
| 1362 | IN PUNICODE_STRING Parent |
| 1363 | ) |
| 1364 | { |
| 1365 | USHORT Length = 0; |
| 1366 | USHORT ParentLen = 0; |
| 1367 | BOOLEAN bBackslash = TRUE; |
| 1368 | |
| 1369 | /* free the original buffer */ |
| 1370 | if (Target->Buffer) { |
| 1371 | DEC_MEM_COUNT(PS_MCB_NAME, Target->Buffer, Target->MaximumLength); |
| 1372 | Ext2FreePool(Target->Buffer, EXT2_FNAME_MAGIC); |
| 1373 | Target->Length = Target->MaximumLength = 0; |
| 1374 | } |
| 1375 | |
| 1376 | /* check the parent directory's name and backslash */ |
| 1377 | if (Parent && Parent->Buffer && Parent->Length > 0) { |
| 1378 | ParentLen = Parent->Length / sizeof(WCHAR); |
| 1379 | if (Parent->Buffer[ParentLen - 1] == L'\\') { |
| 1380 | bBackslash = FALSE; |
| 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | if (Parent == NULL || File->Buffer[0] == L'\\') { |
| 1385 | /* must be root inode */ |
| 1386 | ASSERT(ParentLen == 0); |
| 1387 | bBackslash = FALSE; |
| 1388 | } |
| 1389 | |
| 1390 | /* allocate and initialize new name buffer */ |
| 1391 | Length = File->Length; |
| 1392 | Length += (ParentLen + (bBackslash ? 1 : 0)) * sizeof(WCHAR); |
| 1393 | |
| 1394 | Target->Buffer = Ext2AllocatePool( |
| 1395 | PagedPool, |
| 1396 | Length + 2, |
| 1397 | EXT2_FNAME_MAGIC |
| 1398 | ); |
| 1399 | |
| 1400 | if (!Target->Buffer) { |
| 1401 | DEBUG(DL_ERR, ( "Ex2BuildName: failed to allocate name bufer.\n")); |
| 1402 | return FALSE; |
| 1403 | } |
| 1404 | RtlZeroMemory(Target->Buffer, Length + 2); |
| 1405 | |
| 1406 | if (ParentLen) { |
| 1407 | RtlCopyMemory(&Target->Buffer[0], |
| 1408 | Parent->Buffer, |
| 1409 | ParentLen * sizeof(WCHAR)); |
| 1410 | } |
| 1411 | |
| 1412 | if (bBackslash) { |
| 1413 | Target->Buffer[ParentLen++] = L'\\'; |
| 1414 | } |
| 1415 |
no test coverage detected