xref: /haiku/src/add-ons/kernel/drivers/disk/virtual/remote_disk/RemoteDisk.h (revision 1214ef1b2100f2b3299fc9d8d6142e46f70a4c3f)
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 
6 #ifndef _BOOT_REMOTE_DISK_H
7 #define _BOOT_REMOTE_DISK_H
8 
9 #include <netinet/in.h>
10 
11 #include <SupportDefs.h>
12 
13 #include <socket_interface.h>
14 
15 #include <boot/net/RemoteDiskDefs.h>
16 
17 
18 class RemoteDisk {
19 public:
20 								RemoteDisk();
21 								~RemoteDisk();
22 
23 			status_t			Init(uint32 serverAddress, uint16 serverPort,
24 									off_t imageSize);
25 
26 			status_t			FindAnyRemoteDisk();
27 
28 			ssize_t				ReadAt(off_t pos, void *buffer,
29 									size_t bufferSize);
30 			ssize_t				WriteAt(off_t pos, const void *buffer,
31 									size_t bufferSize);
32 
33 			off_t				Size() const
34 									{ return fImageSize; }
35 
36 			bool				IsReadOnly() const
37 									{ return false; }
38 
39 // 			uint32				ServerIPAddress() const
40 // 									{ return fServerAddress; }
41 // 			uint16				ServerPort() const
42 // 									{ return fServerPort; }
43 
44 private:
45 			status_t			_Init();
46 
47 			ssize_t				_ReadFromPacket(off_t& pos, uint8*& buffer,
48 									size_t& bufferSize);
49 
50 			status_t			_SendRequest(remote_disk_header *request,
51 									size_t size, uint8 expectedReply,
52 									sockaddr_in* peerAddress = NULL);
53 			status_t			_SendRequest(remote_disk_header *request,
54 									size_t size, uint8 expectedReply,
55 									sockaddr_in* peerAddress,
56 									void* receiveBuffer,
57 									size_t receiveBufferSize,
58 									int32* bytesReceived);
59 
60 private:
61 			socket_module_info*	fSocketModule;
62 			sockaddr_in			fSocketAddress;
63 			sockaddr_in			fServerAddress;
64 			off_t				fImageSize;
65 			uint64				fRequestID;
66 			int					fSocket;
67 			void*				fPacket;
68 			int32				fPacketSize;
69 };
70 
71 #endif	// _BOOT_REMOTE_DISK_H
72