Skip to content

Commit

Permalink
io: use scefios for dirent
Browse files Browse the repository at this point in the history
  • Loading branch information
frangarcj committed Aug 25, 2022
1 parent e4b8cb3 commit 4bd9fe6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
30 changes: 23 additions & 7 deletions newlib/libc/sys/vita/dirent.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ DEALINGS IN THE SOFTWARE.
#include <psp2/types.h>
#include <psp2/io/dirent.h>
#include <psp2/kernel/threadmgr.h>
#include "fios2.h"
#include "vitadescriptor.h"
#include "vitaerror.h"

Expand Down Expand Up @@ -135,8 +136,8 @@ struct dirent *readdir(DIR *dirp)
return NULL;
}

int res = sceIoDread(fdmap->sce_uid, (SceIoDirent *)&dirp->dir);

SceFiosDirEntry fios_dir_entry = {0};
int res = sceFiosDHReadSync(NULL, fdmap->sce_uid, &fios_dir_entry);
__vita_fd_drop(fdmap);

if (res < 0)
Expand All @@ -145,12 +146,25 @@ struct dirent *readdir(DIR *dirp)
return NULL;
}

if (res == 0)
//TODO end of listing

SceFiosStat fios_stat = {0};
res = sceFiosStatSync(NULL, fios_dir_entry.fullPath, &fios_stat);

if (res < 0)
{
// end-of-listing shouldn't change errno
errno = __vita_sce_errno_to_errno(res, ERROR_GENERIC);
return NULL;
}

strncpy(dirp->dir.d_name, fios_dir_entry.fullPath + fios_dir_entry.offsetToName, 256);
dirp->dir.d_stat.st_mode = fios_stat.st_mode;
dirp->dir.d_stat.st_attr = fios_stat.statFlags;
dirp->dir.d_stat.st_size = fios_stat.st_size;
sceFiosDateToSceDateTime(fios_stat.st_ctime, &dirp->dir.d_stat.st_ctime);
sceFiosDateToSceDateTime(fios_stat.st_atime, &dirp->dir.d_stat.st_atime);
sceFiosDateToSceDateTime(fios_stat.st_mtime, &dirp->dir.d_stat.st_mtime);

struct dirent *dir = &dirp->dir;
dirp->index++;
return dir;
Expand All @@ -173,16 +187,18 @@ void rewinddir(DIR *dirp)
return;
}

SceUID dirfd = sceIoDopen(fdmap->filename); // filename contains full path, so it's okay to use in sce funcs
SceFiosDH dirfd;
SceFiosBuffer buf = SCE_FIOS_BUFFER_INITIALIZER;
int res = sceFiosDHOpenSync(NULL, fdmap->filename, &dirfd, buf); // filename contains full path, so it's okay to use in sce funcs

if (dirfd < 0)
if (res < 0)
{
__vita_fd_drop(fdmap);
errno = __vita_sce_errno_to_errno(dirfd, ERROR_GENERIC);
return;
}

sceIoDclose(fdmap->sce_uid);
sceFiosDHCloseSync(NULL, fdmap->sce_uid);
fdmap->sce_uid = dirfd;
__vita_fd_drop(fdmap);

Expand Down
12 changes: 11 additions & 1 deletion newlib/libc/sys/vita/fios2.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ typedef struct SceFiosStat {
int64_t st_mode;
} SceFiosStat;

typedef struct SceFiosDirEntry {
SceFiosOffset fileSize;
uint32_t statFlags;
uint16_t nameLength;
uint16_t fullPathLength;
uint16_t offsetToName;
uint16_t reserved[3];
char fullPath[1024];
} SceFiosDirEntry;

int sceFiosInitialize(const SceFiosParams *params);
void sceFiosTerminate();

Expand All @@ -151,7 +161,7 @@ int sceFiosDHStatSync(const SceFiosOpAttr *attr, SceFiosDH fh, SceFiosStat *stat

int sceFiosDirectoryCreateSync(const SceFiosOpAttr *attr, const char *path);
int sceFiosDHOpenSync(const SceFiosOpAttr *attr, SceFiosDH *dh, const char *path, SceFiosBuffer buffer);
int sceFiosDHOpenSync(const SceFiosOpAttr *attr, SceFiosDH *dh, const char *path, const void *params);
int sceFiosDHReadSync(const SceFiosOpAttr *attr, SceFiosDH dh, SceFiosDirEntry *dir);
int sceFiosDHCloseSync(const SceFiosOpAttr *attr, SceFiosDH fh);


Expand Down

0 comments on commit 4bd9fe6

Please sign in to comment.