xref: /haiku/src/add-ons/kernel/drivers/disk/virtual/remote_disk/RemoteDisk.h (revision 7ba3142d971290297a1ca7d2d4751cfc9d5713fd)
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 true; }	// TODO:...
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 
54 private:
55 			socket_module_info*	fSocketModule;
56 			sockaddr_in			fSocketAddress;
57 			sockaddr_in			fServerAddress;
58 			off_t				fImageSize;
59 			uint64				fRequestID;
60 			int					fSocket;
61 			void*				fPacket;
62 			int32				fPacketSize;
63 };
64 
65 #endif	// _BOOT_REMOTE_DISK_H
66