Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial sync of HostFS with RPCEmu #18

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
15 changes: 15 additions & 0 deletions arch/filecalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ typedef struct FileInfo
bool bIsDirectory;
} FileInfo;

typedef struct DiskInfo
{
uint64_t size; /**< Size of disk */
uint64_t free; /**< Free space on disk */
} DiskInfo;

/**
* Directory_Open
*
Expand Down Expand Up @@ -63,6 +69,15 @@ char *Directory_GetNextEntry(Directory *hDirectory, FileInfo *phFileInfo);
*/
char *Directory_GetFullPath(Directory *hDirectory, const char *leaf);

/**
* Return disk space information about a file system.
*
* @param path Pathname of object within file system
* @param d Pointer to disk_info structure that will be filled in
* @return On success 1 is returned, on error 0 is returned
*/
bool Disk_GetInfo(const char *path, DiskInfo *d);

/**
* File_OpenAppData
*
Expand Down
33 changes: 33 additions & 0 deletions arch/filero.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,37 @@ char *Directory_GetFullPath(Directory *hDirectory, const char *leaf) {
return path;
}

/**
* Return disk space information about a file system.
*
* @param path Pathname of object within file system
* @param d Pointer to disk_info structure that will be filled in
* @return On success true is returned, on error false is returned
*/
bool Disk_GetInfo(const char *path, DiskInfo *d)
{
_kernel_oserror *err;
unsigned int free_lsw, free_msw, size_lsw, size_msw;

assert(path);

err = _swix(OS_FSControl, _INR(0,1)|_OUTR(0,1)|_OUTR(3,4), 55, path,
&free_lsw, &free_msw, &size_lsw, &size_msw);
if(!err) {
d->size = size_lsw | ((uint64_t)size_msw << 32);
d->free = free_lsw | ((uint64_t)free_msw << 32);
return true;
}

err = _swix(OS_FSControl, _INR(0,1)|_OUT(0)|_OUT(2), 49, path,
&free_lsw, &size_lsw);
if(!err) {
d->size = size_lsw;
d->free = free_lsw;
return true;
}

return false;
}

#endif
26 changes: 26 additions & 0 deletions arch/fileunix.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

/* posix includes */
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <sys/types.h>
#include <dirent.h>

Expand Down Expand Up @@ -167,5 +168,30 @@ static bool File_GetInfo(const char *sPath, FileInfo *phFileInfo)
return true;
}

/**
* Return disk space information about a file system.
*
* @param path Pathname of object within file system
* @param d Pointer to disk_info structure that will be filled in
* @return On success true is returned, on error false is returned
*/
bool Disk_GetInfo(const char *path, DiskInfo *d)
{
struct statvfs s;
int ret;

assert(path != NULL);
assert(d != NULL);

if ((ret = statvfs(path, &s)) != 0) {
return false;
}

d->size = (uint64_t) s.f_blocks * (uint64_t) s.f_frsize;
d->free = (uint64_t) s.f_bavail * (uint64_t) s.f_frsize;

return true;
}

#endif

24 changes: 24 additions & 0 deletions arch/filewin.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,29 @@ char *Directory_GetFullPath(Directory *hDirectory, const char *leaf) {
return path;
}

/**
* Return disk space information about a file system.
*
* @param path Pathname of object within file system
* @param d Pointer to disk_info structure that will be filled in
* @return On success true is returned, on error false is returned
*/
bool Disk_GetInfo(const char *path, DiskInfo *d)
{
ULARGE_INTEGER free, total;

assert(path != NULL);
assert(d != NULL);

if (GetDiskFreeSpaceEx(path, &free, &total, NULL) == 0) {
return false;
}

d->size = (uint64_t) total.QuadPart;
d->free = (uint64_t) free.QuadPart;

return true;
}

#endif

Loading