Changeset 1265 in kBuild
- Timestamp:
- Nov 10, 2007 12:39:39 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/nt_fullpath.c
r1250 r1265 237 237 238 238 #define MY_FileNameInformation 9 239 240 239 typedef struct _MY_FILE_NAME_INFORMATION 241 240 { … … 243 242 WCHAR FileName[1]; 244 243 } MY_FILE_NAME_INFORMATION, *PMY_FILE_NAME_INFORMATION; 244 245 #define MY_FileInternalInformation 6 246 typedef struct _MY_FILE_INTERNAL_INFORMATION { 247 LARGE_INTEGER IndexNumber; 248 } MY_FILE_INTERNAL_INFORMATION, *PMY_FILE_INTERNAL_INFORMATION; 249 250 #define MY_FileFsVolumeInformation 1 251 typedef struct _MY_FILE_FS_VOLUME_INFORMATION 252 { 253 LARGE_INTEGER VolumeCreationTime; 254 ULONG VolumeSerialNumber; 255 ULONG VolumeLabelLength; 256 BOOLEAN SupportsObjects; 257 WCHAR VolumeLabel[/*1*/128]; 258 } MY_FILE_FS_VOLUME_INFORMATION, *PMY_FILE_FS_VOLUME_INFORMATION; 259 260 #define MY_FileFsAttributeInformation 5 261 typedef struct _MY_FILE_FS_ATTRIBUTE_INFORMATION 262 { 263 ULONG FileSystemAttributes; 264 LONG MaximumComponentNameLength; 265 ULONG FileSystemNameLength; 266 WCHAR FileSystemName[/*1*/64]; 267 } MY_FILE_FS_ATTRIBUTE_INFORMATION, *PMY_FILE_FS_ATTRIBUTE_INFORMATION; 245 268 246 269 typedef struct _IO_STATUS_BLOCK … … 254 277 } MY_IO_STATUS_BLOCK, *PMY_IO_STATUS_BLOCK; 255 278 256 static BOOL g_fInitialized = FALSE; 257 static int g_afNtfsDrives['Z' - 'A' + 1]; 279 static BOOL g_fInitialized = FALSE; 280 static int g_afNtfsDrives['Z' - 'A' + 1]; 281 static MY_FILE_FS_VOLUME_INFORMATION g_aVolumeInfo['Z' - 'A' + 1]; 282 258 283 static LONG (NTAPI *g_pfnNtQueryInformationFile)(HANDLE FileHandle, 259 284 PMY_IO_STATUS_BLOCK IoStatusBlock, PVOID FileInformation, 260 285 ULONG Length, ULONG FileInformationClass); 286 static LONG (NTAPI *g_pfnNtQueryVolumeInformationFile)(HANDLE FileHandle, 287 PMY_IO_STATUS_BLOCK IoStatusBlock, PVOID FsInformation, 288 ULONG Length, ULONG FsInformationClass); 261 289 262 290 … … 264 292 nt_get_filename_info(const char *pszPath, char *pszFull, size_t cchFull) 265 293 { 266 static char abBuf[8192]; 267 PMY_FILE_NAME_INFORMATION pFileNameInfo = (PMY_FILE_NAME_INFORMATION)abBuf; 268 MY_IO_STATUS_BLOCK Ios; 269 LONG rcNt; 294 static char abBuf[8192]; 295 PMY_FILE_NAME_INFORMATION pFileNameInfo = (PMY_FILE_NAME_INFORMATION)abBuf; 296 PMY_FILE_FS_VOLUME_INFORMATION pFsVolInfo = (PMY_FILE_FS_VOLUME_INFORMATION)abBuf; 297 MY_IO_STATUS_BLOCK Ios; 298 LONG rcNt; 270 299 HANDLE hFile; 271 int cchOut; 272 char *psz; 300 int cchOut; 301 char *psz; 302 int iDrv; 303 int rc; 273 304 274 305 /* … … 279 310 g_fInitialized = TRUE; 280 311 if (!getenv("KMK_DONT_USE_NT_QUERY_INFORMATION_FILE")) 312 { 281 313 *(FARPROC *)&g_pfnNtQueryInformationFile = 282 314 GetProcAddress(LoadLibrary("ntdll.dll"), "NtQueryInformationFile"); 283 if (g_pfnNtQueryInformationFile) 315 *(FARPROC *)&g_pfnNtQueryVolumeInformationFile = 316 GetProcAddress(LoadLibrary("ntdll.dll"), "NtQueryVolumeInformationFile"); 317 } 318 if ( g_pfnNtQueryInformationFile 319 && g_pfnNtQueryVolumeInformationFile) 284 320 { 285 321 unsigned i; 286 322 for (i = 0; i < sizeof(g_afNtfsDrives) / sizeof(g_afNtfsDrives[0]); i++ ) 287 323 g_afNtfsDrives[i] = -1; 324 } 325 else 326 { 327 g_pfnNtQueryVolumeInformationFile = NULL; 328 g_pfnNtQueryInformationFile = NULL; 288 329 } 289 330 } … … 326 367 *psz++ = ':'; 327 368 } 369 iDrv = *pszFull - 'A'; 328 370 329 371 /* … … 331 373 * to NTFS volumes for now. 332 374 */ 333 if (g_afNtfsDrives[ *pszFull - 'A'] == -1)334 { 335 char szFSName[32];336 375 if (g_afNtfsDrives[iDrv] == -1) 376 { 377 /* FSCTL_GET_REPARSE_POINT? Enumerate mount points? */ 378 g_afNtfsDrives[iDrv] = 0; 337 379 psz[0] = '\\'; 338 380 psz[1] = '\0'; 339 if ( GetVolumeInformation(pszFull, 340 NULL, 0, /* volume name */ 341 NULL, /* serial number */ 342 NULL, /* max component */ 343 NULL, /* volume attribs */ 344 szFSName, 345 sizeof(szFSName)) 346 && !strcmp(szFSName, "NTFS")) 347 g_afNtfsDrives[*pszFull - 'A'] = 1; 348 else 349 g_afNtfsDrives[*pszFull - 'A'] = 0; 350 } 351 if (!g_afNtfsDrives[*pszFull - 'A']) 381 #if 1 382 hFile = CreateFile(pszFull, 383 GENERIC_READ, 384 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 385 NULL, 386 OPEN_EXISTING, 387 FILE_FLAG_BACKUP_SEMANTICS, 388 NULL); 389 if (hFile != INVALID_HANDLE_VALUE) 390 { 391 PMY_FILE_FS_ATTRIBUTE_INFORMATION pFsAttrInfo = (PMY_FILE_FS_ATTRIBUTE_INFORMATION)abBuf; 392 393 memset(&Ios, 0, sizeof(Ios)); 394 rcNt = g_pfnNtQueryVolumeInformationFile(hFile, &Ios, abBuf, sizeof(abBuf), 395 MY_FileFsAttributeInformation); 396 if ( rcNt >= 0 397 //&& pFsAttrInfo->FileSystemNameLength == 4 398 && pFsAttrInfo->FileSystemName[0] == 'N' 399 && pFsAttrInfo->FileSystemName[1] == 'T' 400 && pFsAttrInfo->FileSystemName[2] == 'F' 401 && pFsAttrInfo->FileSystemName[3] == 'S' 402 && pFsAttrInfo->FileSystemName[4] == '\0') 403 { 404 memset(&Ios, 0, sizeof(Ios)); 405 rcNt = g_pfnNtQueryVolumeInformationFile(hFile, &Ios, &g_aVolumeInfo[iDrv], 406 sizeof(MY_FILE_FS_VOLUME_INFORMATION), 407 MY_FileFsVolumeInformation); 408 if (rcNt >= 0) 409 { 410 g_afNtfsDrives[iDrv] = 1; 411 } 412 } 413 CloseHandle(hFile); 414 } 415 #else 416 { 417 char szFSName[32]; 418 if ( GetVolumeInformation(pszFull, 419 NULL, 0, /* volume name */ 420 NULL, /* serial number */ 421 NULL, /* max component */ 422 NULL, /* volume attribs */ 423 szFSName, 424 sizeof(szFSName)) 425 && !strcmp(szFSName, "NTFS")) 426 { 427 g_afNtfsDrives[iDrv] = 1; 428 } 429 } 430 #endif 431 } 432 if (!g_afNtfsDrives[iDrv]) 352 433 return -1; 353 434 … … 362 443 FILE_FLAG_BACKUP_SEMANTICS, 363 444 NULL); 364 if (hFile) 365 { 445 if (hFile != INVALID_HANDLE_VALUE) 446 { 447 /* check that the driver letter is correct first (reparse / symlink issues). */ 366 448 memset(&Ios, 0, sizeof(Ios)); 367 rcNt = g_pfnNtQueryInformationFile(hFile, &Ios, abBuf, sizeof(abBuf), MY_FileNameInformation); 449 rcNt = g_pfnNtQueryVolumeInformationFile(hFile, &Ios, pFsVolInfo, sizeof(*pFsVolInfo), MY_FileFsVolumeInformation); 450 if (rcNt >= 0) 451 { 452 /** @todo do a quick search and try correct the drive letter? */ 453 if ( pFsVolInfo->VolumeCreationTime.QuadPart == g_aVolumeInfo[iDrv].VolumeCreationTime.QuadPart 454 && pFsVolInfo->VolumeSerialNumber == g_aVolumeInfo[iDrv].VolumeSerialNumber) 455 { 456 memset(&Ios, 0, sizeof(Ios)); 457 rcNt = g_pfnNtQueryInformationFile(hFile, &Ios, abBuf, sizeof(abBuf), MY_FileNameInformation); 458 if (rcNt >= 0) 459 { 460 cchOut = WideCharToMultiByte(CP_ACP, 0, 461 pFileNameInfo->FileName, pFileNameInfo->FileNameLength / sizeof(WCHAR), 462 psz, (int)(cchFull - (psz - pszFull) - 2), NULL, NULL); 463 if (cchOut > 0) 464 { 465 const char *pszEnd; 466 #if 0 467 /* upper case the server and share */ 468 if (fUnc) 469 { 470 for (psz++; *psz != '/' && *psz != '\\'; psz++) 471 *psz = toupper(*psz); 472 for (psz++; *psz != '/' && *psz != '\\'; psz++) 473 *psz = toupper(*psz); 474 } 475 #endif 476 /* add trailing slash on directories if input has it. */ 477 pszEnd = strchr(pszPath, '\0'); 478 if ( (pszEnd[-1] == '/' || pszEnd[-1] == '\\') 479 && psz[cchOut - 1] != '\\' 480 && psz[cchOut - 1] != '//') 481 psz[cchOut++] = '\\'; 482 483 /* make sure it's terminated */ 484 psz[cchOut] = '\0'; 485 rc = 0; 486 } 487 else 488 rc = -3; 489 } 490 else 491 rc = -4; 492 } 493 else 494 rc = -5; 495 } 496 else 497 rc = -6; 368 498 CloseHandle(hFile); 369 if (rcNt >= 0) 370 { 371 cchOut = WideCharToMultiByte(CP_ACP, 0, 372 pFileNameInfo->FileName, pFileNameInfo->FileNameLength / sizeof(WCHAR), 373 psz, (int)(cchFull - (psz - pszFull) - 2), NULL, NULL); 374 if (cchOut > 0) 375 { 376 const char *pszEnd; 377 #if 0 378 /* upper case the server and share */ 379 if (fUnc) 380 { 381 for (psz++; *psz != '/' && *psz != '\\'; psz++) 382 *psz = toupper(*psz); 383 for (psz++; *psz != '/' && *psz != '\\'; psz++) 384 *psz = toupper(*psz); 385 } 386 #endif 387 /* add trailing slash on directories if input has it. */ 388 pszEnd = strchr(pszPath, '\0'); 389 if ( (pszEnd[-1] == '/' || pszEnd[-1] == '\\') 390 && psz[cchOut - 1] != '\\' 391 && psz[cchOut - 1] != '//') 392 psz[cchOut++] = '\\'; 393 394 /* make sure it's terminated */ 395 psz[cchOut] = '\0'; 396 return 0; 397 } 398 return -3; 399 } 400 } 401 return -2; 499 } 500 else 501 rc = -7; 502 return rc; 402 503 } 403 504
Note:
See TracChangeset
for help on using the changeset viewer.