-extern "C" boolean_t root_is_CF_drive;
-
-void
-IOOpenDebugDataFile(const char *fname, uint64_t size)
-{
- IOReturn err;
- OSData * imagePath = NULL;
- uint64_t padding;
-
- if (!gDebugImageLock) {
- gDebugImageLock = IOLockAlloc();
- }
-
- if (root_is_CF_drive) return;
-
- // Try to get a lock, but don't block for getting lock
- if (!IOLockTryLock(gDebugImageLock)) {
- HIBLOG("IOOpenDebugDataFile: Failed to get lock\n");
- return;
- }
-
- if (gDebugImageFileVars || !fname || !size) {
- HIBLOG("IOOpenDebugDataFile: conditions failed\n");
- goto exit;
- }
-
- padding = (PAGE_SIZE*2); // allocate couple more pages for header and fileextents
- err = IOPolledFileOpen(fname, size+padding, 32ULL*1024*1024*1024,
- NULL, 0,
- &gDebugImageFileVars, &imagePath, NULL, 0);
-
- if ((kIOReturnSuccess == err) && imagePath)
- {
- if ((gDebugImageFileVars->fileSize < (size+padding)) ||
- (gDebugImageFileVars->fileExtents->getLength() > PAGE_SIZE)) {
- // Can't use the file
- IOPolledFileClose(&gDebugImageFileVars, 0, 0, 0, 0, 0);
- HIBLOG("IOOpenDebugDataFile: too many file extents\n");
- goto exit;
- }
-
- // write extents for debug data usage in EFI
- IOWriteExtentsToFile(gDebugImageFileVars, kIOHibernateHeaderOpenSignature);
- IOSetBootImageNVRAM(imagePath);
- }
-
-exit:
- IOLockUnlock(gDebugImageLock);
-
- if (imagePath) imagePath->release();
- return;
-}
-
-void
-IOCloseDebugDataFile()
-{
- IOSetBootImageNVRAM(0);
-
- if (gDebugImageLock) {
- IOLockLock(gDebugImageLock);
- if (gDebugImageFileVars != 0) {
- IOPolledFileClose(&gDebugImageFileVars, 0, 0, 0, 0, 0);
- }
- IOLockUnlock(gDebugImageLock);
- }
-
-
-}
-