1 /* 2 * Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <SupportDefs.h> 8 #include <platform/openfirmware/openfirmware.h> 9 #include <util/kernel_cpp.h> 10 11 #include "Handle.h" 12 13 14 Handle::Handle(int handle, bool takeOwnership) 15 : 16 fHandle(handle), 17 fOwnHandle(takeOwnership) 18 { 19 } 20 21 22 Handle::Handle(void) 23 : 24 fHandle(0) 25 { 26 } 27 28 29 Handle::~Handle() 30 { 31 if (fOwnHandle) 32 of_close(fHandle); 33 } 34 35 36 void 37 Handle::SetHandle(int handle, bool takeOwnership) 38 { 39 if (fHandle && fOwnHandle) 40 of_close(fHandle); 41 42 fHandle = handle; 43 fOwnHandle = takeOwnership; 44 } 45 46 47 ssize_t 48 Handle::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize) 49 { 50 if (pos == -1 || of_seek(fHandle, pos) != OF_FAILED) 51 return of_read(fHandle, buffer, bufferSize); 52 53 return B_ERROR; 54 } 55 56 57 ssize_t 58 Handle::WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize) 59 { 60 if (pos == -1 || of_seek(fHandle, pos) != OF_FAILED) 61 return of_write(fHandle, buffer, bufferSize); 62 63 return B_ERROR; 64 } 65 66 67 off_t 68 Handle::Size() const 69 { 70 // ToDo: fix this! 71 return 1024LL * 1024 * 1024 * 1024; 72 // 1024 GB 73 } 74 75