vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / kernel / drivers / disk / virtual / remote_disk / RemoteDisk.h
blobd21496eeb55968b0cf83109f2a08ee7c26d1f924
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 #ifndef _BOOT_REMOTE_DISK_H
6 #define _BOOT_REMOTE_DISK_H
8 #include <netinet/in.h>
10 #include <SupportDefs.h>
12 #include <boot/net/RemoteDiskDefs.h>
15 class RemoteDisk {
16 public:
17 RemoteDisk();
18 ~RemoteDisk();
20 status_t Init(uint32 serverAddress, uint16 serverPort,
21 off_t imageSize);
23 status_t FindAnyRemoteDisk();
25 ssize_t ReadAt(off_t pos, void *buffer,
26 size_t bufferSize);
27 ssize_t WriteAt(off_t pos, const void *buffer,
28 size_t bufferSize);
30 off_t Size() const
31 { return fImageSize; }
33 bool IsReadOnly() const
34 { return false; }
36 // uint32 ServerIPAddress() const
37 // { return fServerAddress; }
38 // uint16 ServerPort() const
39 // { return fServerPort; }
41 private:
42 status_t _Init();
44 ssize_t _ReadFromPacket(off_t& pos, uint8*& buffer,
45 size_t& bufferSize);
47 status_t _SendRequest(remote_disk_header *request,
48 size_t size, uint8 expectedReply,
49 sockaddr_in* peerAddress = NULL);
50 status_t _SendRequest(remote_disk_header *request,
51 size_t size, uint8 expectedReply,
52 sockaddr_in* peerAddress,
53 void* receiveBuffer,
54 size_t receiveBufferSize,
55 int32* bytesReceived);
57 private:
58 sockaddr_in fSocketAddress;
59 sockaddr_in fServerAddress;
60 off_t fImageSize;
61 uint64 fRequestID;
62 int fSocket;
63 void* fPacket;
64 int32 fPacketSize;
67 #endif // _BOOT_REMOTE_DISK_H