author | Ryan C. Gordon <icculus@icculus.org> |
Thu, 02 Aug 2012 02:57:55 -0400 | |
branch | stable-2.0 |
changeset 1294 | 184697ee7a77 |
parent 1132 | ff6943f29c3e |
permissions | -rw-r--r-- |
235 | 1 |
/* |
2 |
* BeOS platform-dependent support routines for PhysicsFS. |
|
3 |
* |
|
809
116b8fe30371
Renamed LICENSE to LICENSE.txt
Ryan C. Gordon <icculus@icculus.org>
parents:
808
diff
changeset
|
4 |
* Please see the file LICENSE.txt in the source's root directory. |
235 | 5 |
* |
6 |
* This file written by Ryan C. Gordon. |
|
7 |
*/ |
|
8 |
||
818
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
9 |
#define __PHYSICSFS_INTERNAL__ |
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
10 |
#include "physfs_platforms.h" |
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
11 |
|
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
12 |
#ifdef PHYSFS_PLATFORM_BEOS |
235 | 13 |
|
947 | 14 |
#ifdef PHYSFS_PLATFORM_HAIKU |
15 |
#include <os/kernel/OS.h> |
|
16 |
#include <os/app/Roster.h> |
|
17 |
#include <os/storage/Volume.h> |
|
18 |
#include <os/storage/VolumeRoster.h> |
|
19 |
#include <os/storage/Directory.h> |
|
20 |
#include <os/storage/Entry.h> |
|
21 |
#include <os/storage/Path.h> |
|
22 |
#include <os/kernel/fs_info.h> |
|
23 |
#include <os/device/scsi.h> |
|
24 |
#include <os/support/Locker.h> |
|
25 |
#else |
|
235 | 26 |
#include <be/kernel/OS.h> |
27 |
#include <be/app/Roster.h> |
|
28 |
#include <be/storage/Volume.h> |
|
29 |
#include <be/storage/VolumeRoster.h> |
|
30 |
#include <be/storage/Directory.h> |
|
31 |
#include <be/storage/Entry.h> |
|
32 |
#include <be/storage/Path.h> |
|
33 |
#include <be/kernel/fs_info.h> |
|
34 |
#include <be/device/scsi.h> |
|
854
6c3ebc2e627a
Replaced BeOS mutex implementation. Now all platforms have recursive mutexes.
Ryan C. Gordon <icculus@icculus.org>
parents:
847
diff
changeset
|
35 |
#include <be/support/Locker.h> |
947 | 36 |
#endif |
235 | 37 |
|
38 |
#include <stdio.h> |
|
39 |
#include <stdlib.h> |
|
40 |
#include <string.h> |
|
41 |
#include <errno.h> |
|
42 |
#include <unistd.h> |
|
43 |
||
44 |
#include "physfs_internal.h" |
|
45 |
||
46 |
||
47 |
int __PHYSFS_platformInit(void) |
|
48 |
{ |
|
49 |
return(1); /* always succeed. */ |
|
50 |
} /* __PHYSFS_platformInit */ |
|
51 |
||
52 |
||
53 |
int __PHYSFS_platformDeinit(void) |
|
54 |
{ |
|
55 |
return(1); /* always succeed. */ |
|
56 |
} /* __PHYSFS_platformDeinit */ |
|
57 |
||
58 |
||
59 |
static char *getMountPoint(const char *devname) |
|
60 |
{ |
|
61 |
BVolumeRoster mounts; |
|
62 |
BVolume vol; |
|
63 |
||
64 |
mounts.Rewind(); |
|
65 |
while (mounts.GetNextVolume(&vol) == B_NO_ERROR) |
|
66 |
{ |
|
67 |
fs_info fsinfo; |
|
68 |
fs_stat_dev(vol.Device(), &fsinfo); |
|
69 |
if (strcmp(devname, fsinfo.device_name) == 0) |
|
70 |
{ |
|
71 |
//char buf[B_FILE_NAME_LENGTH]; |
|
72 |
BDirectory directory; |
|
73 |
BEntry entry; |
|
74 |
BPath path; |
|
75 |
status_t rc; |
|
76 |
rc = vol.GetRootDirectory(&directory); |
|
393 | 77 |
BAIL_IF_MACRO(rc < B_OK, strerror(rc), NULL); |
235 | 78 |
rc = directory.GetEntry(&entry); |
393 | 79 |
BAIL_IF_MACRO(rc < B_OK, strerror(rc), NULL); |
235 | 80 |
rc = entry.GetPath(&path); |
393 | 81 |
BAIL_IF_MACRO(rc < B_OK, strerror(rc), NULL); |
235 | 82 |
const char *str = path.Path(); |
83 |
BAIL_IF_MACRO(str == NULL, ERR_OS_ERROR, NULL); /* ?! */ |
|
745
df04959950eb
Patched to compile again on BeOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
84 |
char *retval = (char *) allocator.Malloc(strlen(str) + 1); |
235 | 85 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
86 |
strcpy(retval, str); |
|
87 |
return(retval); |
|
88 |
} /* if */ |
|
89 |
} /* while */ |
|
90 |
||
91 |
return(NULL); |
|
92 |
} /* getMountPoint */ |
|
93 |
||
94 |
||
95 |
/* |
|
96 |
* This function is lifted from Simple Directmedia Layer (SDL): |
|
97 |
* http://www.libsdl.org/ |
|
98 |
*/ |
|
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
99 |
static void tryDir(const char *d, PHYSFS_StringCallback callback, void *data) |
235 | 100 |
{ |
101 |
BDirectory dir; |
|
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
102 |
dir.SetTo(d); |
235 | 103 |
if (dir.InitCheck() != B_NO_ERROR) |
104 |
return; |
|
105 |
||
106 |
dir.Rewind(); |
|
107 |
BEntry entry; |
|
108 |
while (dir.GetNextEntry(&entry) >= 0) |
|
109 |
{ |
|
110 |
BPath path; |
|
111 |
const char *name; |
|
112 |
entry_ref e; |
|
113 |
||
114 |
if (entry.GetPath(&path) != B_NO_ERROR) |
|
115 |
continue; |
|
116 |
||
117 |
name = path.Path(); |
|
118 |
||
119 |
if (entry.GetRef(&e) != B_NO_ERROR) |
|
120 |
continue; |
|
121 |
||
122 |
if (entry.IsDirectory()) |
|
123 |
{ |
|
124 |
if (strcmp(e.name, "floppy") != 0) |
|
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
125 |
tryDir(name, callback, data); |
235 | 126 |
} /* if */ |
127 |
||
128 |
else |
|
129 |
{ |
|
130 |
bool add_it = false; |
|
131 |
int devfd; |
|
132 |
device_geometry g; |
|
133 |
||
134 |
if (strcmp(e.name, "raw") == 0) /* ignore partitions. */ |
|
135 |
{ |
|
136 |
int devfd = open(name, O_RDONLY); |
|
137 |
if (devfd >= 0) |
|
138 |
{ |
|
139 |
if (ioctl(devfd, B_GET_GEOMETRY, &g, sizeof(g)) >= 0) |
|
140 |
{ |
|
141 |
if (g.device_type == B_CD) |
|
142 |
{ |
|
143 |
char *mntpnt = getMountPoint(name); |
|
144 |
if (mntpnt != NULL) |
|
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
145 |
{ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
146 |
callback(data, mntpnt); |
745
df04959950eb
Patched to compile again on BeOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
147 |
allocator.Free(mntpnt); /* !!! FIXME: lose this malloc! */ |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
148 |
} /* if */ |
235 | 149 |
} /* if */ |
150 |
} /* if */ |
|
151 |
} /* if */ |
|
152 |
} /* if */ |
|
153 |
||
154 |
close(devfd); |
|
155 |
} /* else */ |
|
156 |
} /* while */ |
|
157 |
} /* tryDir */ |
|
158 |
||
159 |
||
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
160 |
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data) |
235 | 161 |
{ |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
162 |
tryDir("/dev/disk", cb, data); |
235 | 163 |
} /* __PHYSFS_platformDetectAvailableCDs */ |
164 |
||
165 |
||
166 |
static team_id getTeamID(void) |
|
167 |
{ |
|
168 |
thread_info info; |
|
169 |
thread_id tid = find_thread(NULL); |
|
170 |
get_thread_info(tid, &info); |
|
171 |
return(info.team); |
|
847
5e5e6c067413
Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
172 |
} /* getTeamID */ |
235 | 173 |
|
174 |
||
175 |
char *__PHYSFS_platformCalcBaseDir(const char *argv0) |
|
176 |
{ |
|
1132
ff6943f29c3e
Fixes for Haiku support, compliments of Chris Roberts.
Ryan C. Gordon <icculus@icculus.org>
parents:
947
diff
changeset
|
177 |
image_info info; |
ff6943f29c3e
Fixes for Haiku support, compliments of Chris Roberts.
Ryan C. Gordon <icculus@icculus.org>
parents:
947
diff
changeset
|
178 |
int32 cookie = 0; |
ff6943f29c3e
Fixes for Haiku support, compliments of Chris Roberts.
Ryan C. Gordon <icculus@icculus.org>
parents:
947
diff
changeset
|
179 |
|
ff6943f29c3e
Fixes for Haiku support, compliments of Chris Roberts.
Ryan C. Gordon <icculus@icculus.org>
parents:
947
diff
changeset
|
180 |
while (get_next_image_info(0, &cookie, &info) == B_OK) { |
ff6943f29c3e
Fixes for Haiku support, compliments of Chris Roberts.
Ryan C. Gordon <icculus@icculus.org>
parents:
947
diff
changeset
|
181 |
if (info.type == B_APP_IMAGE) |
ff6943f29c3e
Fixes for Haiku support, compliments of Chris Roberts.
Ryan C. Gordon <icculus@icculus.org>
parents:
947
diff
changeset
|
182 |
break; |
ff6943f29c3e
Fixes for Haiku support, compliments of Chris Roberts.
Ryan C. Gordon <icculus@icculus.org>
parents:
947
diff
changeset
|
183 |
} |
ff6943f29c3e
Fixes for Haiku support, compliments of Chris Roberts.
Ryan C. Gordon <icculus@icculus.org>
parents:
947
diff
changeset
|
184 |
|
ff6943f29c3e
Fixes for Haiku support, compliments of Chris Roberts.
Ryan C. Gordon <icculus@icculus.org>
parents:
947
diff
changeset
|
185 |
BEntry entry(info.name, true); |
235 | 186 |
BPath path; |
1132
ff6943f29c3e
Fixes for Haiku support, compliments of Chris Roberts.
Ryan C. Gordon <icculus@icculus.org>
parents:
947
diff
changeset
|
187 |
status_t rc = entry.GetPath(&path); /* (path) now has binary's path. */ |
235 | 188 |
assert(rc == B_OK); |
189 |
rc = path.GetParent(&path); /* chop filename, keep directory. */ |
|
190 |
assert(rc == B_OK); |
|
191 |
const char *str = path.Path(); |
|
192 |
assert(str != NULL); |
|
745
df04959950eb
Patched to compile again on BeOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
193 |
char *retval = (char *) allocator.Malloc(strlen(str) + 1); |
235 | 194 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
195 |
strcpy(retval, str); |
|
196 |
return(retval); |
|
197 |
} /* __PHYSFS_platformCalcBaseDir */ |
|
198 |
||
199 |
||
1294
184697ee7a77
Backport from default branch: clean up the thread ID mess in platform_unix.
Ryan C. Gordon <icculus@icculus.org>
parents:
1132
diff
changeset
|
200 |
void *__PHYSFS_platformGetThreadID(void) |
235 | 201 |
{ |
1294
184697ee7a77
Backport from default branch: clean up the thread ID mess in platform_unix.
Ryan C. Gordon <icculus@icculus.org>
parents:
1132
diff
changeset
|
202 |
return((void *) find_thread(NULL)); |
235 | 203 |
} /* __PHYSFS_platformGetThreadID */ |
204 |
||
205 |
||
206 |
char *__PHYSFS_platformRealPath(const char *path) |
|
207 |
{ |
|
788
3df4f1b61339
Apparently BeOS's BPath constructor doesn't actually _need_ leaf to be
Ryan C. Gordon <icculus@icculus.org>
parents:
745
diff
changeset
|
208 |
BPath normalized(path, NULL, true); /* force normalization of path. */ |
235 | 209 |
const char *resolved_path = normalized.Path(); |
362
ac8c846a0a66
Changed enumeration code to use __PHYSFS_addToLinkedStringList().
Ryan C. Gordon <icculus@icculus.org>
parents:
327
diff
changeset
|
210 |
BAIL_IF_MACRO(resolved_path == NULL, ERR_NO_SUCH_FILE, NULL); |
745
df04959950eb
Patched to compile again on BeOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
211 |
char *retval = (char *) allocator.Malloc(strlen(resolved_path) + 1); |
235 | 212 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
213 |
strcpy(retval, resolved_path); |
|
214 |
return(retval); |
|
215 |
} /* __PHYSFS_platformRealPath */ |
|
216 |
||
217 |
||
847
5e5e6c067413
Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
218 |
char *__PHYSFS_platformCurrentDir(void) |
5e5e6c067413
Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
219 |
{ |
5e5e6c067413
Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
220 |
return(__PHYSFS_platformRealPath(".")); /* let BPath sort it out. */ |
5e5e6c067413
Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
221 |
} /* __PHYSFS_platformCurrentDir */ |
5e5e6c067413
Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
222 |
|
5e5e6c067413
Split out Mac OS X code from unix.c and added some Carbon-specific code...
Ryan C. Gordon <icculus@icculus.org>
parents:
845
diff
changeset
|
223 |
|
235 | 224 |
void *__PHYSFS_platformCreateMutex(void) |
225 |
{ |
|
854
6c3ebc2e627a
Replaced BeOS mutex implementation. Now all platforms have recursive mutexes.
Ryan C. Gordon <icculus@icculus.org>
parents:
847
diff
changeset
|
226 |
return(new BLocker("PhysicsFS lock", true)); |
235 | 227 |
} /* __PHYSFS_platformCreateMutex */ |
228 |
||
229 |
||
230 |
void __PHYSFS_platformDestroyMutex(void *mutex) |
|
231 |
{ |
|
854
6c3ebc2e627a
Replaced BeOS mutex implementation. Now all platforms have recursive mutexes.
Ryan C. Gordon <icculus@icculus.org>
parents:
847
diff
changeset
|
232 |
delete ((BLocker *) mutex); |
235 | 233 |
} /* __PHYSFS_platformDestroyMutex */ |
234 |
||
235 |
||
236 |
int __PHYSFS_platformGrabMutex(void *mutex) |
|
237 |
{ |
|
854
6c3ebc2e627a
Replaced BeOS mutex implementation. Now all platforms have recursive mutexes.
Ryan C. Gordon <icculus@icculus.org>
parents:
847
diff
changeset
|
238 |
return ((BLocker *) mutex)->Lock() ? 1 : 0; |
235 | 239 |
} /* __PHYSFS_platformGrabMutex */ |
240 |
||
241 |
||
242 |
void __PHYSFS_platformReleaseMutex(void *mutex) |
|
243 |
{ |
|
854
6c3ebc2e627a
Replaced BeOS mutex implementation. Now all platforms have recursive mutexes.
Ryan C. Gordon <icculus@icculus.org>
parents:
847
diff
changeset
|
244 |
((BLocker *) mutex)->Unlock(); |
235 | 245 |
} /* __PHYSFS_platformReleaseMutex */ |
246 |
||
845
3f150ffcf50c
Since all the platform layers were using the same cut-and-paste of the
Ryan C. Gordon <icculus@icculus.org>
parents:
844
diff
changeset
|
247 |
|
3f150ffcf50c
Since all the platform layers were using the same cut-and-paste of the
Ryan C. Gordon <icculus@icculus.org>
parents:
844
diff
changeset
|
248 |
int __PHYSFS_platformSetDefaultAllocator(PHYSFS_Allocator *a) |
3f150ffcf50c
Since all the platform layers were using the same cut-and-paste of the
Ryan C. Gordon <icculus@icculus.org>
parents:
844
diff
changeset
|
249 |
{ |
3f150ffcf50c
Since all the platform layers were using the same cut-and-paste of the
Ryan C. Gordon <icculus@icculus.org>
parents:
844
diff
changeset
|
250 |
return(0); /* just use malloc() and friends. */ |
3f150ffcf50c
Since all the platform layers were using the same cut-and-paste of the
Ryan C. Gordon <icculus@icculus.org>
parents:
844
diff
changeset
|
251 |
} /* __PHYSFS_platformSetDefaultAllocator */ |
3f150ffcf50c
Since all the platform layers were using the same cut-and-paste of the
Ryan C. Gordon <icculus@icculus.org>
parents:
844
diff
changeset
|
252 |
|
818
e36f23f49042
Now compiles everything whether we need it or not, removing whole files with
Ryan C. Gordon <icculus@icculus.org>
parents:
809
diff
changeset
|
253 |
#endif /* PHYSFS_PLATFORM_BEOS */ |
235 | 254 |
|
255 |
/* end of beos.cpp ... */ |
|
256 |