xref: /haiku/headers/private/kernel/boot/net/RemoteDisk.h (revision d3d8b26997fac34a84981e6d2b649521de2cc45a)
1 /*
2  * Copyright 2005, 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 <boot/vfs.h>
10 #include <boot/net/NetDefs.h>
11 #include <boot/net/RemoteDiskDefs.h>
12 
13 class UDPPacket;
14 class UDPSocket;
15 
16 class RemoteDisk : public Node {
17 public:
18 	RemoteDisk();
19 	~RemoteDisk();
20 
21 	status_t Init(ip_addr_t serverAddress, uint16 serverPort, off_t imageSize);
22 
23 	virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer,
24 		size_t bufferSize);
25 	virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer,
26 		size_t bufferSize);
27 
28 	virtual status_t GetName(char *nameBuffer, size_t bufferSize) const;
29 	virtual off_t Size() const;
30 
31 	static RemoteDisk *FindAnyRemoteDisk();
32 
33 private:
34 	ssize_t _ReadFromPacket(off_t &pos, uint8 *&buffer, size_t &bufferSize);
35 
36 	static status_t _SendRequest(UDPSocket *socket, ip_addr_t serverAddress,
37 		uint16 serverPort, remote_disk_header *request, size_t size,
38 		uint8 expectedReply, UDPPacket **packet);
39 	status_t _SendRequest(remote_disk_header *request, size_t size,
40 		uint8 expectedReply, UDPPacket **packet);
41 
42 private:
43 	ip_addr_t	fServerAddress;
44 	uint16		fServerPort;
45 	off_t		fImageSize;
46 	uint64		fRequestID;
47 	UDPSocket	*fSocket;
48 	UDPPacket	*fPacket;
49 };
50 
51 #endif	// _BOOT_REMOTE_DISK_H
52