2002-05-24 11:46:43 +02:00
|
|
|
/*
|
2017-07-12 06:16:57 +02:00
|
|
|
* Haiku platform-dependent support routines for PhysicsFS.
|
2002-05-24 11:46:43 +02:00
|
|
|
*
|
2007-03-11 11:10:28 +01:00
|
|
|
* Please see the file LICENSE.txt in the source's root directory.
|
2002-05-24 11:46:43 +02:00
|
|
|
*
|
|
|
|
* This file written by Ryan C. Gordon.
|
|
|
|
*/
|
|
|
|
|
2007-03-11 23:50:53 +01:00
|
|
|
#define __PHYSICSFS_INTERNAL__
|
|
|
|
#include "physfs_platforms.h"
|
|
|
|
|
2008-11-05 20:42:48 +01:00
|
|
|
#ifdef PHYSFS_PLATFORM_HAIKU
|
2017-07-12 06:16:57 +02:00
|
|
|
|
2008-11-05 20:42:48 +01:00
|
|
|
#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>
|
2002-05-24 11:46:43 +02:00
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "physfs_internal.h"
|
|
|
|
|
|
|
|
int __PHYSFS_platformInit(void)
|
|
|
|
{
|
2012-03-19 07:58:41 +01:00
|
|
|
return 1; /* always succeed. */
|
2002-05-24 11:46:43 +02:00
|
|
|
} /* __PHYSFS_platformInit */
|
|
|
|
|
|
|
|
|
2017-08-06 07:30:58 +02:00
|
|
|
void __PHYSFS_platformDeinit(void)
|
2002-05-24 11:46:43 +02:00
|
|
|
{
|
2017-08-06 07:30:58 +02:00
|
|
|
/* no-op */
|
2002-05-24 11:46:43 +02:00
|
|
|
} /* __PHYSFS_platformDeinit */
|
|
|
|
|
|
|
|
|
2012-03-15 02:24:32 +01:00
|
|
|
static char *getMountPoint(const char *devname, char *buf, size_t bufsize)
|
2002-05-24 11:46:43 +02:00
|
|
|
{
|
|
|
|
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;
|
2012-03-15 02:24:32 +01:00
|
|
|
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;
|
2002-05-24 11:46:43 +02:00
|
|
|
} /* if */
|
|
|
|
} /* while */
|
|
|
|
|
2012-03-15 02:24:32 +01:00
|
|
|
return NULL;
|
2002-05-24 11:46:43 +02:00
|
|
|
} /* getMountPoint */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is lifted from Simple Directmedia Layer (SDL):
|
2016-02-25 08:51:28 +01:00
|
|
|
* https://www.libsdl.org/ ... this is zlib-licensed code, too.
|
2002-05-24 11:46:43 +02:00
|
|
|
*/
|
2004-09-29 08:09:29 +02:00
|
|
|
static void tryDir(const char *d, PHYSFS_StringCallback callback, void *data)
|
2002-05-24 11:46:43 +02:00
|
|
|
{
|
|
|
|
BDirectory dir;
|
2004-09-29 08:09:29 +02:00
|
|
|
dir.SetTo(d);
|
2002-05-24 11:46:43 +02:00
|
|
|
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)
|
2004-09-29 08:09:29 +02:00
|
|
|
tryDir(name, callback, data);
|
2012-03-15 02:24:32 +01:00
|
|
|
continue;
|
2002-05-24 11:46:43 +02:00
|
|
|
} /* if */
|
|
|
|
|
2012-03-15 02:24:32 +01:00
|
|
|
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);
|
2002-05-24 11:46:43 +02:00
|
|
|
} /* while */
|
|
|
|
} /* tryDir */
|
|
|
|
|
|
|
|
|
2004-09-29 08:09:29 +02:00
|
|
|
void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
|
2002-05-24 11:46:43 +02:00
|
|
|
{
|
2004-09-29 08:09:29 +02:00
|
|
|
tryDir("/dev/disk", cb, data);
|
2002-05-24 11:46:43 +02:00
|
|
|
} /* __PHYSFS_platformDetectAvailableCDs */
|
|
|
|
|
|
|
|
|
|
|
|
static team_id getTeamID(void)
|
|
|
|
{
|
|
|
|
thread_info info;
|
|
|
|
thread_id tid = find_thread(NULL);
|
|
|
|
get_thread_info(tid, &info);
|
2012-03-19 07:58:41 +01:00
|
|
|
return info.team;
|
2007-03-21 06:03:17 +01:00
|
|
|
} /* getTeamID */
|
2002-05-24 11:46:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
|
|
|
|
{
|
2010-12-31 01:50:58 +01:00
|
|
|
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);
|
2002-05-24 11:46:43 +02:00
|
|
|
BPath path;
|
2010-12-31 01:50:58 +01:00
|
|
|
status_t rc = entry.GetPath(&path); /* (path) now has binary's path. */
|
2002-05-24 11:46:43 +02:00
|
|
|
assert(rc == B_OK);
|
|
|
|
rc = path.GetParent(&path); /* chop filename, keep directory. */
|
|
|
|
assert(rc == B_OK);
|
|
|
|
const char *str = path.Path();
|
|
|
|
assert(str != NULL);
|
2012-03-24 05:26:04 +01:00
|
|
|
const size_t len = strlen(str);
|
|
|
|
char *retval = (char *) allocator.Malloc(len + 2);
|
2017-07-06 17:51:41 +02:00
|
|
|
BAIL_IF(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
|
2002-05-24 11:46:43 +02:00
|
|
|
strcpy(retval, str);
|
2012-03-24 05:26:04 +01:00
|
|
|
retval[len] = '/';
|
|
|
|
retval[len+1] = '\0';
|
2012-03-19 07:58:41 +01:00
|
|
|
return retval;
|
2002-05-24 11:46:43 +02:00
|
|
|
} /* __PHYSFS_platformCalcBaseDir */
|
|
|
|
|
|
|
|
|
2012-03-22 04:30:50 +01:00
|
|
|
char *__PHYSFS_platformCalcPrefDir(const char *org, const char *app)
|
|
|
|
{
|
|
|
|
const char *userdir = __PHYSFS_getUserDir();
|
|
|
|
const char *append = "config/settings/";
|
2012-03-22 04:59:43 +01:00
|
|
|
const size_t len = strlen(userdir) + strlen(append) + strlen(app) + 2;
|
2017-07-10 02:50:48 +02:00
|
|
|
char *retval = (char *) allocator.Malloc(len);
|
2017-07-06 17:51:41 +02:00
|
|
|
BAIL_IF(!retval, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
|
2012-03-22 04:59:43 +01:00
|
|
|
snprintf(retval, len, "%s%s%s/", userdir, append, app);
|
2012-03-22 04:30:50 +01:00
|
|
|
return retval;
|
|
|
|
} /* __PHYSFS_platformCalcPrefDir */
|
|
|
|
|
2017-07-12 06:16:57 +02:00
|
|
|
#endif /* PHYSFS_PLATFORM_HAIKU */
|
2002-05-24 11:46:43 +02:00
|
|
|
|
2017-07-22 19:19:57 +02:00
|
|
|
/* end of physfs_platform_haiku.cpp ... */
|
2002-05-24 11:46:43 +02:00
|
|
|
|