17ba3142dSIngo Weinhold /* 27ba3142dSIngo Weinhold * Copyright 2005-2007, Ingo Weinhold <bonefish@cs.tu-berlin.de>. 37ba3142dSIngo Weinhold * All rights reserved. Distributed under the terms of the MIT License. 47ba3142dSIngo Weinhold */ 57ba3142dSIngo Weinhold #ifndef _BOOT_REMOTE_DISK_H 67ba3142dSIngo Weinhold #define _BOOT_REMOTE_DISK_H 77ba3142dSIngo Weinhold 87ba3142dSIngo Weinhold #include <netinet/in.h> 97ba3142dSIngo Weinhold 107ba3142dSIngo Weinhold #include <SupportDefs.h> 117ba3142dSIngo Weinhold 127ba3142dSIngo Weinhold #include <boot/net/RemoteDiskDefs.h> 137ba3142dSIngo Weinhold 147ba3142dSIngo Weinhold 157ba3142dSIngo Weinhold class RemoteDisk { 167ba3142dSIngo Weinhold public: 177ba3142dSIngo Weinhold RemoteDisk(); 187ba3142dSIngo Weinhold ~RemoteDisk(); 197ba3142dSIngo Weinhold 207ba3142dSIngo Weinhold status_t Init(uint32 serverAddress, uint16 serverPort, 217ba3142dSIngo Weinhold off_t imageSize); 227ba3142dSIngo Weinhold 237ba3142dSIngo Weinhold status_t FindAnyRemoteDisk(); 247ba3142dSIngo Weinhold 257ba3142dSIngo Weinhold ssize_t ReadAt(off_t pos, void *buffer, 267ba3142dSIngo Weinhold size_t bufferSize); 277ba3142dSIngo Weinhold ssize_t WriteAt(off_t pos, const void *buffer, 287ba3142dSIngo Weinhold size_t bufferSize); 297ba3142dSIngo Weinhold Size()307ba3142dSIngo Weinhold off_t Size() const 317ba3142dSIngo Weinhold { return fImageSize; } 327ba3142dSIngo Weinhold IsReadOnly()337ba3142dSIngo Weinhold bool IsReadOnly() const 34*89369ed1SIngo Weinhold { return false; } 357ba3142dSIngo Weinhold 367ba3142dSIngo Weinhold // uint32 ServerIPAddress() const 377ba3142dSIngo Weinhold // { return fServerAddress; } 387ba3142dSIngo Weinhold // uint16 ServerPort() const 397ba3142dSIngo Weinhold // { return fServerPort; } 407ba3142dSIngo Weinhold 417ba3142dSIngo Weinhold private: 427ba3142dSIngo Weinhold status_t _Init(); 437ba3142dSIngo Weinhold 447ba3142dSIngo Weinhold ssize_t _ReadFromPacket(off_t& pos, uint8*& buffer, 457ba3142dSIngo Weinhold size_t& bufferSize); 467ba3142dSIngo Weinhold 477ba3142dSIngo Weinhold status_t _SendRequest(remote_disk_header *request, 487ba3142dSIngo Weinhold size_t size, uint8 expectedReply, 497ba3142dSIngo Weinhold sockaddr_in* peerAddress = NULL); 50*89369ed1SIngo Weinhold status_t _SendRequest(remote_disk_header *request, 51*89369ed1SIngo Weinhold size_t size, uint8 expectedReply, 52*89369ed1SIngo Weinhold sockaddr_in* peerAddress, 53*89369ed1SIngo Weinhold void* receiveBuffer, 54*89369ed1SIngo Weinhold size_t receiveBufferSize, 55*89369ed1SIngo Weinhold int32* bytesReceived); 567ba3142dSIngo Weinhold 577ba3142dSIngo Weinhold private: 587ba3142dSIngo Weinhold sockaddr_in fSocketAddress; 597ba3142dSIngo Weinhold sockaddr_in fServerAddress; 607ba3142dSIngo Weinhold off_t fImageSize; 617ba3142dSIngo Weinhold uint64 fRequestID; 627ba3142dSIngo Weinhold int fSocket; 637ba3142dSIngo Weinhold void* fPacket; 647ba3142dSIngo Weinhold int32 fPacketSize; 657ba3142dSIngo Weinhold }; 667ba3142dSIngo Weinhold 677ba3142dSIngo Weinhold #endif // _BOOT_REMOTE_DISK_H 68