2010-10-08 23 views
2

當我得到錯誤0x10時,我希望能夠理解該錯誤代碼。查找IOReturn.h和mach/error.h並不是特別方便。當我得到0x22錯誤代碼時,我迷失了方向。這真是一個很愚蠢的問題,但是有沒有像error2String這樣的函數可以將IOReturn錯誤代碼映射到描述錯誤的String?在內核中運行將IOKit IOReturn錯誤代碼映射到字符串

+0

那麼,什麼是錯誤代碼0x10? (我現在正在體驗它。)謝謝! – 2011-02-07 21:50:03

回答

2

代碼可以使用IOService::stringFromReturn(...)

+0

該文件明確表明這是要走的路......但我完全不瞭解如何從我的代碼中調用它。我所得到的是「未找到符號」錯誤。我需要鏈接什麼?導入/包括哪些內容?非常感謝。 – 2011-02-07 21:49:44

+1

您的代碼是內核擴展還是用戶模式應用程序/庫? IOService :: stringFromReturn(...)(不幸)只能用於在內核中運行的代碼。 – 2011-02-09 12:31:45

1

我從IOService.h移植過來,這應該做的工作。

-(NSString*)stringFromError:(unsigned int)errorVal 
{ 
    NSDictionary *ioReturnMap = 
      @{@kIOReturnSuccess:   @"success", 
      @kIOReturnError:   @"general error", 
      @kIOReturnNoMemory:   @"memory allocation error", 
      @kIOReturnNoResources:  @"resource shortage", 
      @kIOReturnIPCError:   @"Mach IPC failure", 
      @kIOReturnNoDevice:   @"no such device", 
      @kIOReturnNotPrivileged: @"privilege violation", 
      @kIOReturnBadArgument:  @"invalid argument", 
      @kIOReturnLockedRead:  @"device is read locked", 
      @kIOReturnLockedWrite:  @"device is write locked", 
      @kIOReturnExclusiveAccess: @"device is exclusive access", 
      @kIOReturnBadMessageID:  @"bad IPC message ID", 
      @kIOReturnUnsupported:  @"unsupported function", 
      @kIOReturnVMError:   @"virtual memory error", 
      @kIOReturnInternalError: @"internal driver error", 
      @kIOReturnIOError:   @"I/O error", 
      @kIOReturnCannotLock:  @"cannot acquire lock", 
      @kIOReturnNotOpen:   @"device is not open", 
      @kIOReturnNotReadable:  @"device is not readable", 
      @kIOReturnNotWritable:  @"device is not writeable", 
      @kIOReturnNotAligned:  @"alignment error", 
      @kIOReturnBadMedia:   @"media error", 
      @kIOReturnStillOpen:  @"device is still open", 
      @kIOReturnRLDError:   @"rld failure", 
      @kIOReturnDMAError:   @"DMA failure", 
      @kIOReturnBusy:    @"device is busy", 
      @kIOReturnTimeout:   @"I/O timeout", 
      @kIOReturnOffline:   @"device is offline", 
      @kIOReturnNotReady:   @"device is not ready", 
      @kIOReturnNotAttached:  @"device/channel is not attached", 
      @kIOReturnNoChannels:  @"no DMA channels available", 
      @kIOReturnNoSpace:   @"no space for data", 
      @kIOReturnPortExists:  @"device port already exists", 
      @kIOReturnCannotWire:  @"cannot wire physical memory", 
      @kIOReturnNoInterrupt:  @"no interrupt attached", 
      @kIOReturnNoFrames:   @"no DMA frames enqueued", 
      @kIOReturnMessageTooLarge: @"message is too large", 
      @kIOReturnNotPermitted:  @"operation is not permitted", 
      @kIOReturnNoPower:   @"device is without power", 
      @kIOReturnNoMedia:   @"media is not present", 
      @kIOReturnUnformattedMedia: @"media is not formatted", 
      @kIOReturnUnsupportedMode: @"unsupported mode", 
      @kIOReturnUnderrun:   @"data underrun", 
      @kIOReturnOverrun:   @"data overrun", 
      @kIOReturnDeviceError:  @"device error", 
      @kIOReturnNoCompletion:  @"no completion routine", 
      @kIOReturnAborted:   @"operation was aborted", 
      @kIOReturnNoBandwidth:  @"bus bandwidth would be exceeded", 
      @kIOReturnNotResponding: @"device is not responding", 
      @kIOReturnInvalid:   @"unanticipated driver error", 
      @0:       @"0"}; 

    return [ioReturnMap objectForKey:[NSNumber numberWithInt:err_get_code(errorVal)]]; 
} 
+1

根據[本頁](https://developer.apple.com/library/mac/documentation/DeviceDrivers/Conceptual/AccessingHardware/AH_Handling_Errors/AH_Handling_Errors.html),您應該使用'err_get_code()'宏來提取錯誤代碼第一。 – augurar 2014-01-30 20:23:21

相關問題