2

当我收到错误 0x10 时,我希望能够理解该错误代码。查找 IOReturn.h 和 mach/error.h 并不是特别方便。当我得到 0x22 错误代码时,我迷路了。这真是个愚蠢的问题,但是有没有像 error2String 这样的函数可以将 IOReturn 错误代码映射到描述错误的字符串?

4

3 回答 3

11

您可以使用 mach_error_string 标准基础函数来执行此操作。

例如。在斯威夫特:

func krToString (_ kr: kern_return_t) -> String {
    if let cStr = mach_error_string(kr) {
        return String (cString: cStr)
    } else {
        return "Unknown kernel error \(kr)"
    }
}
于 2019-12-12T00:10:17.403 回答
2

在内核中运行的代码可以使用IOService::stringFromReturn(...)

于 2010-10-27T09:22:34.827 回答
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",
            };

    return [ioReturnMap objectForKey:[NSNumber numberWithInt:err_get_code(errorVal)]];
}
于 2013-11-01T09:43:40.687 回答