1/* 2 * Copyright 2008-2010, François Revol, revol@free.fr. All rights reserved. 3 * Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 4 * Distributed under the terms of the MIT License. 5 */ 6 7 8#include <SupportDefs.h> 9#include <platform/openfirmware/openfirmware.h> 10#include <util/kernel_cpp.h> 11 12#include "Handle.h" 13#include "toscalls.h" 14 15/* 16 * (X)BIOS supports char and block devices with a separate namespace 17 * for char devs handle is {DEV_PRINTER, ... DEV_CONSOLE, ...} 18 * for block devs handle is either: 19 * - the partition number {0=A:, 2=C:...} in logical mode. 20 * - the drive number {0=A:, 1=B:, 2=ACSI-0, 10=SCSI-0, ...} 21 * in phys mode (RW_NOTRANSLATE). 22 * BlockHandle is in devices.cpp 23 * 24 * XXX: handle network devices ? not sure how TOS net extensions do this 25 * not sure it'll ever be supported anyway. 26 * XXX: BIOSDrive/BIOSHandle : public BlockHandle ? 27 */ 28 29Handle::Handle(int handle) 30 : 31 fHandle((int16)handle) 32{ 33} 34 35 36Handle::Handle(void) 37 : 38 fHandle(DEV_CONSOLE) 39{ 40} 41 42 43Handle::~Handle() 44{ 45} 46 47 48void 49Handle::SetHandle(int handle) 50{ 51 fHandle = (int16)handle; 52} 53 54 55ssize_t 56Handle::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize) 57{ 58 return B_ERROR; 59} 60 61 62ssize_t 63Handle::WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize) 64{ 65 return B_ERROR; 66} 67 68 69off_t 70Handle::Size() const 71{ 72 // ToDo: fix this! 73 return 1024LL * 1024 * 1024 * 1024; 74 // 1024 GB 75} 76 77 78// #pragma mark - 79 80 81CharHandle::CharHandle(int handle) 82 : Handle(handle) 83{ 84} 85 86 87CharHandle::CharHandle(void) 88 : Handle() 89{ 90} 91 92 93CharHandle::~CharHandle() 94{ 95} 96 97 98ssize_t 99CharHandle::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize) 100{ 101 char *string = (char *)buffer; 102 int i; 103 104 // can't seek 105 for (i = 0; i < bufferSize; i++) { 106 if (Bconstat(fHandle) == 0) 107 return i; 108 string[i] = (char)Bconin(fHandle); 109 } 110 111 return bufferSize; 112} 113 114 115ssize_t 116CharHandle::WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize) 117{ 118 const char *string = (const char *)buffer; 119 int i; 120 121 // can't seek 122 123 //XXX: check Bcostat ? 124 for (i = 0; i < bufferSize; i++) { 125 Bconout(fHandle, string[i]); 126 } 127 128 return bufferSize; 129} 130 131 132