Отображение кода ошибки IOKit IOReturn в строку - PullRequest
2 голосов
/ 08 октября 2010

Когда я получаю ошибку 0x10, я хочу иметь возможность понять этот код ошибки.Поиск IOReturn.h и mach / error.h не особенно удобен.Я был потерян, когда я получил код ошибки 0x22.Это действительно глупый вопрос, но есть ли такая функция, как error2String, которая может отобразить код ошибки IOReturn в строку, описывающую ошибку?

Ответы [ 2 ]

2 голосов
/ 27 октября 2010

Код работающий в ядре может использовать IOService::stringFromReturn(...)

1 голос
/ 01 ноября 2013

Я перенес это из 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)]];
}
...