1 /* 2 * Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef HANDLE_H 6 #define HANDLE_H 7 8 9 #include <boot/vfs.h> 10 11 12 #ifdef __cplusplus 13 14 class Handle : public ConsoleNode { 15 public: 16 Handle(int handle); 17 Handle(); 18 virtual ~Handle(); 19 20 void SetHandle(int handle); 21 22 virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize); 23 virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize); 24 25 virtual off_t Size() const; 26 27 protected: 28 int fHandle; 29 }; 30 31 /* character devices */ 32 class CharHandle : public Handle { 33 public: 34 CharHandle(int handle); 35 CharHandle(); 36 virtual ~CharHandle(); 37 38 virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize); 39 virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize); 40 41 protected: 42 }; 43 44 /* block devices */ 45 /* cf. devices.cpp */ 46 47 class ExecDevice : public ConsoleNode { 48 public: 49 ExecDevice(struct IORequest *ioRequest); 50 ExecDevice(size_t requestSize); 51 ExecDevice(); 52 virtual ~ExecDevice(); 53 54 status_t AllocRequest(size_t requestSize); 55 56 status_t Open(const char *name, unsigned long unit = 0, 57 unsigned long flags = 0); 58 59 virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize); 60 virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize); 61 62 virtual off_t Size() const; 63 64 struct IORequest *Request() const { return fIORequest; }; 65 struct IOStdReq *StdRequest() const { return fIOStdReq; }; 66 67 // *IO() call helpers 68 status_t Do(void); 69 status_t Clear(void); 70 71 protected: 72 struct IORequest *fIORequest; 73 struct IOStdReq *fIOStdReq; 74 }; 75 76 77 #endif /* __cplusplus */ 78 79 #endif /* HANDLE_H */ 80