Skip to content

Latest commit

 

History

History
237 lines (186 loc) · 5.76 KB

platform_beos.cpp

File metadata and controls

237 lines (186 loc) · 5.76 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
#include <errno.h>
#include <unistd.h>
#include "physfs_internal.h"
int __PHYSFS_platformInit(void)
{
Mar 19, 2012
Mar 19, 2012
45
return 1; /* always succeed. */
May 24, 2002
May 24, 2002
46
47
48
49
50
} /* __PHYSFS_platformInit */
int __PHYSFS_platformDeinit(void)
{
Mar 19, 2012
Mar 19, 2012
51
return 1; /* always succeed. */
May 24, 2002
May 24, 2002
52
53
54
} /* __PHYSFS_platformDeinit */
Mar 15, 2012
Mar 15, 2012
55
static char *getMountPoint(const char *devname, char *buf, size_t bufsize)
May 24, 2002
May 24, 2002
56
57
58
59
60
61
62
63
64
65
66
67
68
69
{
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)
{
BDirectory directory;
BEntry entry;
BPath path;
Mar 15, 2012
Mar 15, 2012
70
71
72
73
74
75
76
77
78
79
80
const char *str;
if ( (vol.GetRootDirectory(&directory) < B_OK) ||
(directory.GetEntry(&entry) < B_OK) ||
(entry.GetPath(&path) < B_OK) ||
( (str = path.Path()) == NULL) )
return NULL;
strncpy(buf, str, bufsize-1);
buf[bufsize-1] = '\0';
return buf;
May 24, 2002
May 24, 2002
81
82
83
} /* if */
} /* while */
Mar 15, 2012
Mar 15, 2012
84
return NULL;
May 24, 2002
May 24, 2002
85
86
87
88
89
} /* getMountPoint */
/*
* This function is lifted from Simple Directmedia Layer (SDL):
Mar 15, 2012
Mar 15, 2012
90
* http://www.libsdl.org/ ... this is zlib-licensed code, too.
May 24, 2002
May 24, 2002
91
*/
Sep 29, 2004
Sep 29, 2004
92
static void tryDir(const char *d, PHYSFS_StringCallback callback, void *data)
May 24, 2002
May 24, 2002
93
94
{
BDirectory dir;
Sep 29, 2004
Sep 29, 2004
95
dir.SetTo(d);
May 24, 2002
May 24, 2002
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
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
118
tryDir(name, callback, data);
Mar 15, 2012
Mar 15, 2012
119
continue;
May 24, 2002
May 24, 2002
120
121
} /* if */
Mar 15, 2012
Mar 15, 2012
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
if (strcmp(e.name, "raw") != 0) /* ignore partitions. */
continue;
const int devfd = open(name, O_RDONLY);
if (devfd < 0)
continue;
device_geometry g;
const int rc = ioctl(devfd, B_GET_GEOMETRY, &g, sizeof (g));
close(devfd);
if (rc < 0)
continue;
if (g.device_type != B_CD)
continue;
char mntpnt[B_FILE_NAME_LENGTH];
if (getMountPoint(name, mntpnt, sizeof (mntpnt)))
callback(data, mntpnt);
May 24, 2002
May 24, 2002
141
142
143
144
} /* while */
} /* tryDir */
Sep 29, 2004
Sep 29, 2004
145
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
May 24, 2002
May 24, 2002
146
{
Sep 29, 2004
Sep 29, 2004
147
tryDir("/dev/disk", cb, data);
May 24, 2002
May 24, 2002
148
149
150
151
152
153
154
155
} /* __PHYSFS_platformDetectAvailableCDs */
static team_id getTeamID(void)
{
thread_info info;
thread_id tid = find_thread(NULL);
get_thread_info(tid, &info);
Mar 19, 2012
Mar 19, 2012
156
return info.team;
Mar 21, 2007
Mar 21, 2007
157
} /* getTeamID */
May 24, 2002
May 24, 2002
158
159
160
161
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
{
Dec 31, 2010
Dec 31, 2010
162
163
164
165
166
167
168
169
170
171
image_info info;
int32 cookie = 0;
while (get_next_image_info(0, &cookie, &info) == B_OK)
{
if (info.type == B_APP_IMAGE)
break;
} /* while */
BEntry entry(info.name, true);
May 24, 2002
May 24, 2002
172
BPath path;
Dec 31, 2010
Dec 31, 2010
173
status_t rc = entry.GetPath(&path); /* (path) now has binary's path. */
May 24, 2002
May 24, 2002
174
175
176
177
178
assert(rc == B_OK);
rc = path.GetParent(&path); /* chop filename, keep directory. */
assert(rc == B_OK);
const char *str = path.Path();
assert(str != NULL);
Mar 23, 2012
Mar 23, 2012
179
char *retval = (char *) allocator.Malloc(strlen(str) + 2);
Mar 20, 2012
Mar 20, 2012
180
BAIL_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
May 24, 2002
May 24, 2002
181
strcpy(retval, str);
Mar 23, 2012
Mar 23, 2012
182
strcat(retval, "/");
Mar 19, 2012
Mar 19, 2012
183
return retval;
May 24, 2002
May 24, 2002
184
185
186
} /* __PHYSFS_platformCalcBaseDir */
Mar 22, 2012
Mar 22, 2012
187
188
189
190
char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app)
{
const char *userdir = __PHYSFS_getUserDir();
const char *append = "config/settings/";
Mar 22, 2012
Mar 22, 2012
191
const size_t len = strlen(userdir) + strlen(append) + strlen(app) + 2;
Mar 22, 2012
Mar 22, 2012
192
193
char *retval = allocator.Malloc(len);
BAIL_IF_MACRO(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
Mar 22, 2012
Mar 22, 2012
194
snprintf(retval, len, "%s%s%s/", userdir, append, app);
Mar 22, 2012
Mar 22, 2012
195
196
197
198
return retval;
} /* __PHYSFS_platformCalcPrefDir */
Sep 6, 2009
Sep 6, 2009
199
void *__PHYSFS_platformGetThreadID(void)
May 24, 2002
May 24, 2002
200
{
Mar 19, 2012
Mar 19, 2012
201
return (void *) find_thread(NULL);
May 24, 2002
May 24, 2002
202
203
204
205
206
} /* __PHYSFS_platformGetThreadID */
void *__PHYSFS_platformCreateMutex(void)
{
Mar 19, 2012
Mar 19, 2012
207
return new BLocker("PhysicsFS lock", true);
May 24, 2002
May 24, 2002
208
209
210
211
212
} /* __PHYSFS_platformCreateMutex */
void __PHYSFS_platformDestroyMutex(void *mutex)
{
Mar 24, 2007
Mar 24, 2007
213
delete ((BLocker *) mutex);
May 24, 2002
May 24, 2002
214
215
216
217
218
} /* __PHYSFS_platformDestroyMutex */
int __PHYSFS_platformGrabMutex(void *mutex)
{
Mar 24, 2007
Mar 24, 2007
219
return ((BLocker *) mutex)->Lock() ? 1 : 0;
May 24, 2002
May 24, 2002
220
221
222
223
224
} /* __PHYSFS_platformGrabMutex */
void __PHYSFS_platformReleaseMutex(void *mutex)
{
Mar 24, 2007
Mar 24, 2007
225
((BLocker *) mutex)->Unlock();
May 24, 2002
May 24, 2002
226
227
} /* __PHYSFS_platformReleaseMutex */
Mar 20, 2007
Mar 20, 2007
228
229
230
int __PHYSFS_platformSetDefaultAllocator(PHYSFS_Allocator *a)
{
Mar 19, 2012
Mar 19, 2012
231
return 0; /* just use malloc() and friends. */
Mar 20, 2007
Mar 20, 2007
232
233
} /* __PHYSFS_platformSetDefaultAllocator */
Mar 11, 2007
Mar 11, 2007
234
#endif /* PHYSFS_PLATFORM_BEOS */
May 24, 2002
May 24, 2002
235
236
/* end of beos.cpp ... */