author | Ryan C. Gordon <icculus@icculus.org> |
Sun, 14 Nov 2010 00:43:47 -0500 | |
changeset 1131 | 267ac8c2eb6b |
parent 1129 | d81afe4b0a97 |
child 1133 | 958df28c5449 |
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 <errno.h> |
|
39 |
#include <unistd.h> |
|
40 |
||
41 |
#include "physfs_internal.h" |
|
42 |
||
43 |
||
44 |
int __PHYSFS_platformInit(void) |
|
45 |
{ |
|
46 |
return(1); /* always succeed. */ |
|
47 |
} /* __PHYSFS_platformInit */ |
|
48 |
||
49 |
||
50 |
int __PHYSFS_platformDeinit(void) |
|
51 |
{ |
|
52 |
return(1); /* always succeed. */ |
|
53 |
} /* __PHYSFS_platformDeinit */ |
|
54 |
||
55 |
||
56 |
static char *getMountPoint(const char *devname) |
|
57 |
{ |
|
58 |
BVolumeRoster mounts; |
|
59 |
BVolume vol; |
|
60 |
||
61 |
mounts.Rewind(); |
|
62 |
while (mounts.GetNextVolume(&vol) == B_NO_ERROR) |
|
63 |
{ |
|
64 |
fs_info fsinfo; |
|
65 |
fs_stat_dev(vol.Device(), &fsinfo); |
|
66 |
if (strcmp(devname, fsinfo.device_name) == 0) |
|
67 |
{ |
|
68 |
//char buf[B_FILE_NAME_LENGTH]; |
|
69 |
BDirectory directory; |
|
70 |
BEntry entry; |
|
71 |
BPath path; |
|
72 |
status_t rc; |
|
73 |
rc = vol.GetRootDirectory(&directory); |
|
393 | 74 |
BAIL_IF_MACRO(rc < B_OK, strerror(rc), NULL); |
235 | 75 |
rc = directory.GetEntry(&entry); |
393 | 76 |
BAIL_IF_MACRO(rc < B_OK, strerror(rc), NULL); |
235 | 77 |
rc = entry.GetPath(&path); |
393 | 78 |
BAIL_IF_MACRO(rc < B_OK, strerror(rc), NULL); |
235 | 79 |
const char *str = path.Path(); |
80 |
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
|
81 |
char *retval = (char *) allocator.Malloc(strlen(str) + 1); |
235 | 82 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
83 |
strcpy(retval, str); |
|
84 |
return(retval); |
|
85 |
} /* if */ |
|
86 |
} /* while */ |
|
87 |
||
88 |
return(NULL); |
|
89 |
} /* getMountPoint */ |
|
90 |
||
91 |
||
92 |
/* |
|
93 |
* This function is lifted from Simple Directmedia Layer (SDL): |
|
94 |
* http://www.libsdl.org/ |
|
95 |
*/ |
|
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
96 |
static void tryDir(const char *d, PHYSFS_StringCallback callback, void *data) |
235 | 97 |
{ |
98 |
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
|
99 |
dir.SetTo(d); |
235 | 100 |
if (dir.InitCheck() != B_NO_ERROR) |
101 |
return; |
|
102 |
||
103 |
dir.Rewind(); |
|
104 |
BEntry entry; |
|
105 |
while (dir.GetNextEntry(&entry) >= 0) |
|
106 |
{ |
|
107 |
BPath path; |
|
108 |
const char *name; |
|
109 |
entry_ref e; |
|
110 |
||
111 |
if (entry.GetPath(&path) != B_NO_ERROR) |
|
112 |
continue; |
|
113 |
||
114 |
name = path.Path(); |
|
115 |
||
116 |
if (entry.GetRef(&e) != B_NO_ERROR) |
|
117 |
continue; |
|
118 |
||
119 |
if (entry.IsDirectory()) |
|
120 |
{ |
|
121 |
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
|
122 |
tryDir(name, callback, data); |
235 | 123 |
} /* if */ |
124 |
||
125 |
else |
|
126 |
{ |
|
127 |
bool add_it = false; |
|
128 |
device_geometry g; |
|
129 |
||
130 |
if (strcmp(e.name, "raw") == 0) /* ignore partitions. */ |
|
131 |
{ |
|
1131
267ac8c2eb6b
Fixed leaking file handle on BeOS during CD-ROM detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
1129
diff
changeset
|
132 |
const int devfd = open(name, O_RDONLY); |
235 | 133 |
if (devfd >= 0) |
134 |
{ |
|
1131
267ac8c2eb6b
Fixed leaking file handle on BeOS during CD-ROM detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
1129
diff
changeset
|
135 |
const int rc = ioctl(devfd, B_GET_GEOMETRY, &g, sizeof(g)); |
267ac8c2eb6b
Fixed leaking file handle on BeOS during CD-ROM detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
1129
diff
changeset
|
136 |
close(devfd); |
267ac8c2eb6b
Fixed leaking file handle on BeOS during CD-ROM detection.
Ryan C. Gordon <icculus@icculus.org>
parents:
1129
diff
changeset
|
137 |
if (rc >= 0) |
235 | 138 |
{ |
139 |
if (g.device_type == B_CD) |
|
140 |
{ |
|
141 |
char *mntpnt = getMountPoint(name); |
|
142 |
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
|
143 |
{ |
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
144 |
callback(data, mntpnt); |
745
df04959950eb
Patched to compile again on BeOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
145 |
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
|
146 |
} /* if */ |
235 | 147 |
} /* if */ |
148 |
} /* if */ |
|
149 |
} /* if */ |
|
150 |
} /* if */ |
|
151 |
} /* else */ |
|
152 |
} /* while */ |
|
153 |
} /* tryDir */ |
|
154 |
||
155 |
||
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
156 |
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data) |
235 | 157 |
{ |
657
dad3b5c307a9
Added callback APIs and ripped up the internals everywhere to use them.
Ryan C. Gordon <icculus@icculus.org>
parents:
504
diff
changeset
|
158 |
tryDir("/dev/disk", cb, data); |
235 | 159 |
} /* __PHYSFS_platformDetectAvailableCDs */ |
160 |
||
161 |
||
162 |
static team_id getTeamID(void) |
|
163 |
{ |
|
164 |
thread_info info; |
|
165 |
thread_id tid = find_thread(NULL); |
|
166 |
get_thread_info(tid, &info); |
|
167 |
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
|
168 |
} /* getTeamID */ |
235 | 169 |
|
170 |
||
171 |
char *__PHYSFS_platformCalcBaseDir(const char *argv0) |
|
172 |
{ |
|
173 |
/* in case there isn't a BApplication yet, we'll construct a roster. */ |
|
174 |
BRoster roster; |
|
175 |
app_info info; |
|
176 |
status_t rc = roster.GetRunningAppInfo(getTeamID(), &info); |
|
393 | 177 |
BAIL_IF_MACRO(rc < B_OK, strerror(rc), NULL); |
235 | 178 |
BEntry entry(&(info.ref), true); |
179 |
BPath path; |
|
180 |
rc = entry.GetPath(&path); /* (path) now has binary's path. */ |
|
181 |
assert(rc == B_OK); |
|
182 |
rc = path.GetParent(&path); /* chop filename, keep directory. */ |
|
183 |
assert(rc == B_OK); |
|
184 |
const char *str = path.Path(); |
|
185 |
assert(str != NULL); |
|
745
df04959950eb
Patched to compile again on BeOS.
Ryan C. Gordon <icculus@icculus.org>
parents:
657
diff
changeset
|
186 |
char *retval = (char *) allocator.Malloc(strlen(str) + 1); |
235 | 187 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
188 |
strcpy(retval, str); |
|
189 |
return(retval); |
|
190 |
} /* __PHYSFS_platformCalcBaseDir */ |
|
191 |
||
192 |
||
1012
f254870dd7dd
Attempt to clean up the thread ID mess in platform_unix ...
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
193 |
void *__PHYSFS_platformGetThreadID(void) |
235 | 194 |
{ |
1012
f254870dd7dd
Attempt to clean up the thread ID mess in platform_unix ...
Ryan C. Gordon <icculus@icculus.org>
parents:
972
diff
changeset
|
195 |
return((void *) find_thread(NULL)); |
235 | 196 |
} /* __PHYSFS_platformGetThreadID */ |
197 |
||
198 |
||
199 |
char *__PHYSFS_platformRealPath(const char *path) |
|
200 |
{ |
|
788
3df4f1b61339
Apparently BeOS's BPath constructor doesn't actually _need_ leaf to be
Ryan C. Gordon <icculus@icculus.org>
parents:
745
diff
changeset
|
201 |
BPath normalized(path, NULL, true); /* force normalization of path. */ |
235 | 202 |
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
|
203 |
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
|
204 |
char *retval = (char *) allocator.Malloc(strlen(resolved_path) + 1); |
235 | 205 |
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL); |
206 |
strcpy(retval, resolved_path); |
|
207 |
return(retval); |
|
208 |
} /* __PHYSFS_platformRealPath */ |
|
209 |
||
210 |
||
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
|
211 |
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
|
212 |
{ |
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
|
213 |
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
|
214 |
} /* __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
|
215 |
|
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
|
216 |
|
235 | 217 |
void *__PHYSFS_platformCreateMutex(void) |
218 |
{ |
|
854
6c3ebc2e627a
Replaced BeOS mutex implementation. Now all platforms have recursive mutexes.
Ryan C. Gordon <icculus@icculus.org>
parents:
847
diff
changeset
|
219 |
return(new BLocker("PhysicsFS lock", true)); |
235 | 220 |
} /* __PHYSFS_platformCreateMutex */ |
221 |
||
222 |
||
223 |
void __PHYSFS_platformDestroyMutex(void *mutex) |
|
224 |
{ |
|
854
6c3ebc2e627a
Replaced BeOS mutex implementation. Now all platforms have recursive mutexes.
Ryan C. Gordon <icculus@icculus.org>
parents:
847
diff
changeset
|
225 |
delete ((BLocker *) mutex); |
235 | 226 |
} /* __PHYSFS_platformDestroyMutex */ |
227 |
||
228 |
||
229 |
int __PHYSFS_platformGrabMutex(void *mutex) |
|
230 |
{ |
|
854
6c3ebc2e627a
Replaced BeOS mutex implementation. Now all platforms have recursive mutexes.
Ryan C. Gordon <icculus@icculus.org>
parents:
847
diff
changeset
|
231 |
return ((BLocker *) mutex)->Lock() ? 1 : 0; |
235 | 232 |
} /* __PHYSFS_platformGrabMutex */ |
233 |
||
234 |
||
235 |
void __PHYSFS_platformReleaseMutex(void *mutex) |
|
236 |
{ |
|
854
6c3ebc2e627a
Replaced BeOS mutex implementation. Now all platforms have recursive mutexes.
Ryan C. Gordon <icculus@icculus.org>
parents:
847
diff
changeset
|
237 |
((BLocker *) mutex)->Unlock(); |
235 | 238 |
} /* __PHYSFS_platformReleaseMutex */ |
239 |
||
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
|
240 |
|
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
|
241 |
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
|
242 |
{ |
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
|
243 |
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
|
244 |
} /* __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
|
245 |
|
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
|
246 |
#endif /* PHYSFS_PLATFORM_BEOS */ |
235 | 247 |
|
248 |
/* end of beos.cpp ... */ |
|
249 |