1 /* 2 * Copyright 2005-2007, Ingo Weinhold <bonefish@cs.tu-berlin.de>. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 #ifndef _BOOT_REMOTE_DISK_H 6 #define _BOOT_REMOTE_DISK_H 7 8 #include <netinet/in.h> 9 10 #include <SupportDefs.h> 11 12 #include <boot/net/RemoteDiskDefs.h> 13 14 15 class RemoteDisk { 16 public: 17 RemoteDisk(); 18 ~RemoteDisk(); 19 20 status_t Init(uint32 serverAddress, uint16 serverPort, 21 off_t imageSize); 22 23 status_t FindAnyRemoteDisk(); 24 25 ssize_t ReadAt(off_t pos, void *buffer, 26 size_t bufferSize); 27 ssize_t WriteAt(off_t pos, const void *buffer, 28 size_t bufferSize); 29 30 off_t Size() const 31 { return fImageSize; } 32 33 bool IsReadOnly() const 34 { return false; } 35 36 // uint32 ServerIPAddress() const 37 // { return fServerAddress; } 38 // uint16 ServerPort() const 39 // { return fServerPort; } 40 41 private: 42 status_t _Init(); 43 44 ssize_t _ReadFromPacket(off_t& pos, uint8*& buffer, 45 size_t& bufferSize); 46 47 status_t _SendRequest(remote_disk_header *request, 48 size_t size, uint8 expectedReply, 49 sockaddr_in* peerAddress = NULL); 50 status_t _SendRequest(remote_disk_header *request, 51 size_t size, uint8 expectedReply, 52 sockaddr_in* peerAddress, 53 void* receiveBuffer, 54 size_t receiveBufferSize, 55 int32* bytesReceived); 56 57 private: 58 sockaddr_in fSocketAddress; 59 sockaddr_in fServerAddress; 60 off_t fImageSize; 61 uint64 fRequestID; 62 int fSocket; 63 void* fPacket; 64 int32 fPacketSize; 65 }; 66 67 #endif // _BOOT_REMOTE_DISK_H 68