From 6f9e265157ddbaa612ef1ab4b8242b3d08ab6758 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Thu, 10 Jan 2008 23:16:55 +0000 Subject: [PATCH] * Get rid of owner, BIOS devices don't need open/close. * split Handle class to CharHandle and BlockHandle. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23366 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../boot/platform/atari_m68k/Handle.cpp | 142 ++++++++++++++++-- src/system/boot/platform/atari_m68k/Handle.h | 21 ++- .../boot/platform/atari_m68k/console.cpp | 4 +- 3 files changed, 151 insertions(+), 16 deletions(-) diff --git a/src/system/boot/platform/atari_m68k/Handle.cpp b/src/system/boot/platform/atari_m68k/Handle.cpp index e7fdada96e..fdbc94552e 100644 --- a/src/system/boot/platform/atari_m68k/Handle.cpp +++ b/src/system/boot/platform/atari_m68k/Handle.cpp @@ -11,10 +11,20 @@ #include "Handle.h" #include "toscalls." -Handle::Handle(int handle, bool takeOwnership) +/* + * (X)BIOS supports char and block devices with a separate namespace + * for char devs handle is {DEV_PRINTER, ... DEV_CONSOLE, ...} + * for block devs handle is the drive number. + * BlockHandle is in devices.cpp + * + * XXX: handle network devices ? not sure how TOS net extensions do this + * not sure it'll ever be supported anyway. + * XXX: BIOSDrive/BIOSHandle : public BlockHandle ? + */ + +Handle::Handle(int handle) : fHandle((int16)handle), - fOwnHandle(takeOwnership) { } @@ -28,24 +38,61 @@ Handle::Handle(void) Handle::~Handle() { - //if (fOwnHandle) - // of_close(fHandle); } void -Handle::SetHandle(int handle, bool takeOwnership) +Handle::SetHandle(int handle) { - //if (fHandle && fOwnHandle) - // of_close(fHandle); - fHandle = (int16)handle; - fOwnHandle = takeOwnership; } ssize_t Handle::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize) +{ + return B_ERROR; +} + + +ssize_t +Handle::WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize) +{ + return B_ERROR; +} + + +off_t +Handle::Size() const +{ + // ToDo: fix this! + return 1024LL * 1024 * 1024 * 1024; + // 1024 GB +} + + +// #pragma mark - + + +CharHandle::CharHandle(int handle) + : Handle(handle) +{ +} + + +CharHandle::CharHandle(void) + : Handle() +{ +} + + +CharHandle::~CharHandle() +{ +} + + +ssize_t +CharHandle::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize) { const char *string = (const char *)buffer; @@ -61,7 +108,79 @@ Handle::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize) ssize_t -Handle::WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize) +CharHandle::WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize) +{ + const char *string = (const char *)buffer; + + // can't seek + + //XXX: check Bcostat ? + for (i = 0; i < bufferSize; i++) { + Bconout(fHandle, string[i]); + } + + return bufferSize; +} + + +off_t +CharHandle::Size() const +{ + // ToDo: fix this! + return 1024LL * 1024 * 1024 * 1024; + // 1024 GB +} + + +// #pragma mark - + + +BlockHandle::BlockHandle(int handle) + : Handle(handle) +{ +} + + +BlockHandle::BlockHandle(void) + : Handle() +{ +} + + +BlockHandle::~BlockHandle() +{ +} + + +status_t +BlockHandle::InitCheck() const +{ + uint32 map = Drvmap(); + if (!(map & (1 << fHandle))) + return ENODEV; + //XXX: check size + return B_OK; +} + + +ssize_t +BlockHandle::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize) +{ + const char *string = (const char *)buffer; + + // can't seek + for (i = 0; i < bufferSize; i++) { + if (Bconstat(fHandle) == 0) + return i; + string[i] = (char)Bconin(fHandle); + } + + return bufferSize; +} + + +ssize_t +BlockHandle::WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize) { const char *string = (const char *)buffer; @@ -75,10 +194,11 @@ Handle::WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize) off_t -Handle::Size() const +BlockHandle::Size() const { // ToDo: fix this! return 1024LL * 1024 * 1024 * 1024; // 1024 GB } + diff --git a/src/system/boot/platform/atari_m68k/Handle.h b/src/system/boot/platform/atari_m68k/Handle.h index 0832dfc63a..ee1ef917cc 100644 --- a/src/system/boot/platform/atari_m68k/Handle.h +++ b/src/system/boot/platform/atari_m68k/Handle.h @@ -13,11 +13,11 @@ class Handle : public ConsoleNode { public: - Handle(int handle, bool takeOwnership = true); + Handle(int handle); Handle(); virtual ~Handle(); - void SetHandle(int handle, bool takeOwnership = true); + void SetHandle(int handle); virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize); virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize); @@ -26,9 +26,24 @@ class Handle : public ConsoleNode { protected: int16 fHandle; - bool fOwnHandle; }; +/* character devices */ +class CharHandle : public Handle { + public: + CharHandle(int handle); + CharHandle(); + virtual ~CharHandle(); + + virtual ssize_t ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize); + virtual ssize_t WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize); + + protected: +}; + +/* block devices */ +/* cf. devices.cpp */ + #endif /* __cplusplus */ #endif /* HANDLE_H */ diff --git a/src/system/boot/platform/atari_m68k/console.cpp b/src/system/boot/platform/atari_m68k/console.cpp index beb7c908ae..d4f10c1365 100644 --- a/src/system/boot/platform/atari_m68k/console.cpp +++ b/src/system/boot/platform/atari_m68k/console.cpp @@ -18,7 +18,7 @@ // TOS emulates a VT52 -class ConsoleHandle : public Handle { +class ConsoleHandle : public CharHandle { public: ConsoleHandle(); @@ -54,7 +54,7 @@ FILE *stdin, *stdout, *stderr; ConsoleHandle::ConsoleHandle() - : Handle() + : CharHandle() { }