Skip to content

Latest commit

 

History

History
250 lines (202 loc) · 6.57 KB

platform_beos.cpp

File metadata and controls

250 lines (202 loc) · 6.57 KB
 
May 24, 2002
May 24, 2002
1
2
3
/*
* BeOS platform-dependent support routines for PhysicsFS.
*
Mar 11, 2007
Mar 11, 2007
4
* Please see the file LICENSE.txt in the source's root directory.
May 24, 2002
May 24, 2002
5
6
7
8
*
* This file written by Ryan C. Gordon.
*/
Mar 11, 2007
Mar 11, 2007
9
10
11
12
#define __PHYSICSFS_INTERNAL__
#include "physfs_platforms.h"
#ifdef PHYSFS_PLATFORM_BEOS
May 24, 2002
May 24, 2002
13
Nov 5, 2008
Nov 5, 2008
14
15
16
17
18
19
20
21
22
23
24
25
#ifdef PHYSFS_PLATFORM_HAIKU
#include <os/kernel/OS.h>
#include <os/app/Roster.h>
#include <os/storage/Volume.h>
#include <os/storage/VolumeRoster.h>
#include <os/storage/Directory.h>
#include <os/storage/Entry.h>
#include <os/storage/Path.h>
#include <os/kernel/fs_info.h>
#include <os/device/scsi.h>
#include <os/support/Locker.h>
#else
May 24, 2002
May 24, 2002
26
27
28
29
30
31
32
33
34
#include <be/kernel/OS.h>
#include <be/app/Roster.h>
#include <be/storage/Volume.h>
#include <be/storage/VolumeRoster.h>
#include <be/storage/Directory.h>
#include <be/storage/Entry.h>
#include <be/storage/Path.h>
#include <be/kernel/fs_info.h>
#include <be/device/scsi.h>
Mar 24, 2007
Mar 24, 2007
35
#include <be/support/Locker.h>
Nov 5, 2008
Nov 5, 2008
36
#endif
May 24, 2002
May 24, 2002
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <errno.h>
#include <unistd.h>
#include "physfs_internal.h"
int __PHYSFS_platformInit(void)
{
return(1); /* always succeed. */
} /* __PHYSFS_platformInit */
int __PHYSFS_platformDeinit(void)
{
return(1); /* always succeed. */
} /* __PHYSFS_platformDeinit */
static char *getMountPoint(const char *devname)
{
BVolumeRoster mounts;
BVolume vol;
mounts.Rewind();
while (mounts.GetNextVolume(&vol) == B_NO_ERROR)
{
fs_info fsinfo;
fs_stat_dev(vol.Device(), &fsinfo);
if (strcmp(devname, fsinfo.device_name) == 0)
{
//char buf[B_FILE_NAME_LENGTH];
BDirectory directory;
BEntry entry;
BPath path;
status_t rc;
rc = vol.GetRootDirectory(&directory);
Jul 25, 2002
Jul 25, 2002
74
BAIL_IF_MACRO(rc < B_OK, strerror(rc), NULL);
May 24, 2002
May 24, 2002
75
rc = directory.GetEntry(&entry);
Jul 25, 2002
Jul 25, 2002
76
BAIL_IF_MACRO(rc < B_OK, strerror(rc), NULL);
May 24, 2002
May 24, 2002
77
rc = entry.GetPath(&path);
Jul 25, 2002
Jul 25, 2002
78
BAIL_IF_MACRO(rc < B_OK, strerror(rc), NULL);
May 24, 2002
May 24, 2002
79
80
const char *str = path.Path();
BAIL_IF_MACRO(str == NULL, ERR_OS_ERROR, NULL); /* ?! */
Jul 25, 2005
Jul 25, 2005
81
char *retval = (char *) allocator.Malloc(strlen(str) + 1);
May 24, 2002
May 24, 2002
82
83
84
85
86
87
88
89
90
91
92
93
94
95
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
strcpy(retval, str);
return(retval);
} /* if */
} /* while */
return(NULL);
} /* getMountPoint */
/*
* This function is lifted from Simple Directmedia Layer (SDL):
* http://www.libsdl.org/
*/
Sep 29, 2004
Sep 29, 2004
96
static void tryDir(const char *d, PHYSFS_StringCallback callback, void *data)
May 24, 2002
May 24, 2002
97
98
{
BDirectory dir;
Sep 29, 2004
Sep 29, 2004
99
dir.SetTo(d);
May 24, 2002
May 24, 2002
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
if (dir.InitCheck() != B_NO_ERROR)
return;
dir.Rewind();
BEntry entry;
while (dir.GetNextEntry(&entry) >= 0)
{
BPath path;
const char *name;
entry_ref e;
if (entry.GetPath(&path) != B_NO_ERROR)
continue;
name = path.Path();
if (entry.GetRef(&e) != B_NO_ERROR)
continue;
if (entry.IsDirectory())
{
if (strcmp(e.name, "floppy") != 0)
Sep 29, 2004
Sep 29, 2004
122
tryDir(name, callback, data);
May 24, 2002
May 24, 2002
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
} /* if */
else
{
bool add_it = false;
int devfd;
device_geometry g;
if (strcmp(e.name, "raw") == 0) /* ignore partitions. */
{
int devfd = open(name, O_RDONLY);
if (devfd >= 0)
{
if (ioctl(devfd, B_GET_GEOMETRY, &g, sizeof(g)) >= 0)
{
if (g.device_type == B_CD)
{
char *mntpnt = getMountPoint(name);
if (mntpnt != NULL)
Sep 29, 2004
Sep 29, 2004
142
143
{
callback(data, mntpnt);
Jul 25, 2005
Jul 25, 2005
144
allocator.Free(mntpnt); /* !!! FIXME: lose this malloc! */
Sep 29, 2004
Sep 29, 2004
145
} /* if */
May 24, 2002
May 24, 2002
146
147
148
149
150
151
152
153
154
155
156
} /* if */
} /* if */
} /* if */
} /* if */
close(devfd);
} /* else */
} /* while */
} /* tryDir */
Sep 29, 2004
Sep 29, 2004
157
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
May 24, 2002
May 24, 2002
158
{
Sep 29, 2004
Sep 29, 2004
159
tryDir("/dev/disk", cb, data);
May 24, 2002
May 24, 2002
160
161
162
163
164
165
166
167
168
} /* __PHYSFS_platformDetectAvailableCDs */
static team_id getTeamID(void)
{
thread_info info;
thread_id tid = find_thread(NULL);
get_thread_info(tid, &info);
return(info.team);
Mar 21, 2007
Mar 21, 2007
169
} /* getTeamID */
May 24, 2002
May 24, 2002
170
171
172
173
174
175
176
177
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
{
/* in case there isn't a BApplication yet, we'll construct a roster. */
BRoster roster;
app_info info;
status_t rc = roster.GetRunningAppInfo(getTeamID(), &info);
Jul 25, 2002
Jul 25, 2002
178
BAIL_IF_MACRO(rc < B_OK, strerror(rc), NULL);
May 24, 2002
May 24, 2002
179
180
181
182
183
184
185
186
BEntry entry(&(info.ref), true);
BPath path;
rc = entry.GetPath(&path); /* (path) now has binary's path. */
assert(rc == B_OK);
rc = path.GetParent(&path); /* chop filename, keep directory. */
assert(rc == B_OK);
const char *str = path.Path();
assert(str != NULL);
Jul 25, 2005
Jul 25, 2005
187
char *retval = (char *) allocator.Malloc(strlen(str) + 1);
May 24, 2002
May 24, 2002
188
189
190
191
192
193
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
strcpy(retval, str);
return(retval);
} /* __PHYSFS_platformCalcBaseDir */
Sep 6, 2009
Sep 6, 2009
194
void *__PHYSFS_platformGetThreadID(void)
May 24, 2002
May 24, 2002
195
{
Sep 6, 2009
Sep 6, 2009
196
return((void *) find_thread(NULL));
May 24, 2002
May 24, 2002
197
198
199
200
201
} /* __PHYSFS_platformGetThreadID */
char *__PHYSFS_platformRealPath(const char *path)
{
Nov 5, 2006
Nov 5, 2006
202
BPath normalized(path, NULL, true); /* force normalization of path. */
May 24, 2002
May 24, 2002
203
const char *resolved_path = normalized.Path();
Jul 23, 2002
Jul 23, 2002
204
BAIL_IF_MACRO(resolved_path == NULL, ERR_NO_SUCH_FILE, NULL);
Jul 25, 2005
Jul 25, 2005
205
char *retval = (char *) allocator.Malloc(strlen(resolved_path) + 1);
May 24, 2002
May 24, 2002
206
207
208
209
210
211
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
strcpy(retval, resolved_path);
return(retval);
} /* __PHYSFS_platformRealPath */
Mar 21, 2007
Mar 21, 2007
212
213
214
215
216
217
char *__PHYSFS_platformCurrentDir(void)
{
return(__PHYSFS_platformRealPath(".")); /* let BPath sort it out. */
} /* __PHYSFS_platformCurrentDir */
May 24, 2002
May 24, 2002
218
219
void *__PHYSFS_platformCreateMutex(void)
{
Mar 24, 2007
Mar 24, 2007
220
return(new BLocker("PhysicsFS lock", true));
May 24, 2002
May 24, 2002
221
222
223
224
225
} /* __PHYSFS_platformCreateMutex */
void __PHYSFS_platformDestroyMutex(void *mutex)
{
Mar 24, 2007
Mar 24, 2007
226
delete ((BLocker *) mutex);
May 24, 2002
May 24, 2002
227
228
229
230
231
} /* __PHYSFS_platformDestroyMutex */
int __PHYSFS_platformGrabMutex(void *mutex)
{
Mar 24, 2007
Mar 24, 2007
232
return ((BLocker *) mutex)->Lock() ? 1 : 0;
May 24, 2002
May 24, 2002
233
234
235
236
237
} /* __PHYSFS_platformGrabMutex */
void __PHYSFS_platformReleaseMutex(void *mutex)
{
Mar 24, 2007
Mar 24, 2007
238
((BLocker *) mutex)->Unlock();
May 24, 2002
May 24, 2002
239
240
} /* __PHYSFS_platformReleaseMutex */
Mar 20, 2007
Mar 20, 2007
241
242
243
244
245
246
int __PHYSFS_platformSetDefaultAllocator(PHYSFS_Allocator *a)
{
return(0); /* just use malloc() and friends. */
} /* __PHYSFS_platformSetDefaultAllocator */
Mar 11, 2007
Mar 11, 2007
247
#endif /* PHYSFS_PLATFORM_BEOS */
May 24, 2002
May 24, 2002
248
249
/* end of beos.cpp ... */