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
13class UDPPacket;
14class UDPSocket;
15
16class RemoteDisk : public Node {
17public:
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	ip_addr_t ServerIPAddress() const;
32	uint16 ServerPort() const;
33
34	static RemoteDisk *FindAnyRemoteDisk();
35
36private:
37	ssize_t _ReadFromPacket(off_t &pos, uint8 *&buffer, size_t &bufferSize);
38
39	static status_t _SendRequest(UDPSocket *socket, ip_addr_t serverAddress,
40		uint16 serverPort, remote_disk_header *request, size_t size,
41		uint8 expectedReply, UDPPacket **packet);
42	status_t _SendRequest(remote_disk_header *request, size_t size,
43		uint8 expectedReply, UDPPacket **packet);
44
45private:
46	ip_addr_t	fServerAddress;
47	uint16		fServerPort;
48	off_t		fImageSize;
49	uint64		fRequestID;
50	UDPSocket	*fSocket;
51	UDPPacket	*fPacket;
52};
53
54#endif	// _BOOT_REMOTE_DISK_H
55