MCPcopy Create free account
hub / github.com/cgsecurity/testdisk / file_pread_aux

Function file_pread_aux

src/hdaccess.c:1417–1531  ·  view source on GitHub ↗

@ @ requires \valid_read(disk); @ requires valid_disk(disk); @ requires \valid((char *)buf + (0 .. count - 1)); @*/

Source from the content-addressed store, hash-verified

1415 @ requires \valid((char *)buf + (0 .. count - 1));
1416 @*/
1417static int file_pread_aux(const disk_t *disk, void *buf, const unsigned int count, const uint64_t offset)
1418{
1419 long int ret;
1420 const int fd=((const struct info_file_struct *)disk->data)->handle;
1421#if defined(__CYGWIN__)
1422 if(lseek(fd,offset,SEEK_SET) < 0)
1423 {
1424 log_error("file_pread(%d,%u,buffer,%lu(%u/%u/%u)) lseek err %s\n",
1425 fd, (unsigned)(count/disk->sector_size),
1426 (long unsigned int)(offset/disk->sector_size),
1427 offset2cylinder(disk,offset),
1428 offset2head(disk,offset),
1429 offset2sector(disk,offset),
1430 strerror(errno));
1431 return -1;
1432 }
1433 {
1434 /* November 28, 2004, CGR: cygwin read function is about 10 times slower
1435 because it reads 60k each time, so lets call ReadFile directly */
1436 DWORD dwByteRead;
1437 HANDLE handle=(HANDLE)get_osfhandle(fd);
1438 if(ReadFile(handle, buf,count,&dwByteRead,NULL)==0)
1439 {
1440 LPVOID lpMsgBuf;
1441 DWORD dw = GetLastError();
1442 FormatMessage(
1443 FORMAT_MESSAGE_ALLOCATE_BUFFER |
1444 FORMAT_MESSAGE_FROM_SYSTEM,
1445 NULL,
1446 dw,
1447 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
1448 (LPTSTR) &lpMsgBuf,
1449 0, NULL );
1450 log_error("file_pread(%d,%u,buffer,%lu(%u/%u/%u)) ReadFile %s\n",
1451 fd, (unsigned)(count/disk->sector_size),
1452 (long unsigned int)(offset/disk->sector_size),
1453 offset2cylinder(disk, offset),
1454 offset2head(disk, offset),
1455 offset2sector(disk, offset),
1456 (char*)lpMsgBuf);
1457 LocalFree(lpMsgBuf);
1458 return -1;
1459 }
1460 return dwByteRead;
1461 }
1462#elif defined(__MINGW32__)
1463 if(_lseeki64(fd,offset,SEEK_SET) < 0)
1464 {
1465 log_error("file_pread(%d,%u,buffer,%lu(%u/%u/%u)) seek err %s\n",
1466 fd, (unsigned)(count/disk->sector_size),
1467 (long unsigned int)(offset/disk->sector_size),
1468 offset2cylinder(disk, offset),
1469 offset2head(disk, offset),
1470 offset2sector(disk, offset),
1471 strerror(errno));
1472 return -1;
1473 }
1474 ret=read(fd, buf, count);

Callers

nothing calls this directly

Calls 3

offset2cylinderFunction · 0.85
offset2headFunction · 0.85
offset2sectorFunction · 0.85

Tested by

no test coverage detected