xref: /haiku/src/system/boot/platform/atari_m68k/Handle.cpp (revision 1214ef1b2100f2b3299fc9d8d6142e46f70a4c3f)
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 
6 
7 #include <SupportDefs.h>
8 #include <platform/openfirmware/openfirmware.h>
9 #include <util/kernel_cpp.h>
10 
11 #include "Handle.h"
12 #include "toscalls."
13 
14 /*
15  * (X)BIOS supports char and block devices with a separate namespace
16  * for char devs handle is {DEV_PRINTER, ... DEV_CONSOLE, ...}
17  * for block devs handle is either:
18  * 		 - the partition number {0=A:, 2=C:...} in logical mode.
19  * 		 - the drive number {0=A:, 1=B:, 2=ACSI-0, 10=SCSI-0, ...}
20  *			in phys mode (RW_NOTRANSLATE).
21  * BlockHandle is in devices.cpp
22  *
23  * XXX: handle network devices ? not sure how TOS net extensions do this
24  * not sure it'll ever be supported anyway.
25  * XXX: BIOSDrive/BIOSHandle : public BlockHandle ?
26  */
27 
28 Handle::Handle(int handle)
29 	:
30 	fHandle((int16)handle),
31 {
32 }
33 
34 
35 Handle::Handle(void)
36 	:
37 	fHandle(DEV_CONSOLE)
38 {
39 }
40 
41 
42 Handle::~Handle()
43 {
44 }
45 
46 
47 void
48 Handle::SetHandle(int handle)
49 {
50 	fHandle = (int16)handle;
51 }
52 
53 
54 ssize_t
55 Handle::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize)
56 {
57 	return B_ERROR;
58 }
59 
60 
61 ssize_t
62 Handle::WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize)
63 {
64 	return B_ERROR;
65 }
66 
67 
68 off_t
69 Handle::Size() const
70 {
71 	// ToDo: fix this!
72 	return 1024LL * 1024 * 1024 * 1024;
73 		// 1024 GB
74 }
75 
76 
77 // #pragma mark -
78 
79 
80 CharHandle::CharHandle(int handle)
81 	: Handle(handle)
82 {
83 }
84 
85 
86 CharHandle::CharHandle(void)
87 	: Handle()
88 {
89 }
90 
91 
92 CharHandle::~CharHandle()
93 {
94 }
95 
96 
97 ssize_t
98 CharHandle::ReadAt(void *cookie, off_t pos, void *buffer, size_t bufferSize)
99 {
100 	const char *string = (const char *)buffer;
101 
102 	// can't seek
103 	for (i = 0; i < bufferSize; i++) {
104 		if (Bconstat(fHandle) == 0)
105 			return i;
106 		string[i] = (char)Bconin(fHandle);
107 	}
108 
109 	return bufferSize;
110 }
111 
112 
113 ssize_t
114 CharHandle::WriteAt(void *cookie, off_t pos, const void *buffer, size_t bufferSize)
115 {
116 	const char *string = (const char *)buffer;
117 
118 	// can't seek
119 
120 	//XXX: check Bcostat ?
121 	for (i = 0; i < bufferSize; i++) {
122 		Bconout(fHandle, string[i]);
123 	}
124 
125 	return bufferSize;
126 }
127 
128 
129 off_t
130 CharHandle::Size() const
131 {
132 	// ToDo: fix this!
133 	return 1024LL * 1024 * 1024 * 1024;
134 		// 1024 GB
135 }
136 
137