Skip to content

Commit

Permalink
Have dirent return stat also
Browse files Browse the repository at this point in the history
  • Loading branch information
rickgaiser committed Jan 4, 2021
1 parent a744144 commit 1f478e9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 42 deletions.
41 changes: 20 additions & 21 deletions ee/libc/src/ps2sdkapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ static mode_t io_to_posix_mode(unsigned int ps2mode)
return posixmode;
}

static void fill_stat(struct stat *stat, const io_stat_t *fiostat)
{
stat->st_dev = 0;
stat->st_ino = 0;
stat->st_mode = io_to_posix_mode(fiostat->mode);
stat->st_nlink = 0;
stat->st_uid = 0;
stat->st_gid = 0;
stat->st_rdev = 0;
stat->st_size = ((off_t)fiostat->hisize << 32) | (off_t)fiostat->size;
stat->st_atime = io_to_posix_time(fiostat->atime);
stat->st_mtime = io_to_posix_time(fiostat->mtime);
stat->st_ctime = io_to_posix_time(fiostat->ctime);
stat->st_blksize = 16*1024;
stat->st_blocks = stat->st_size / 512;
}

static int fioGetstatHelper(const char *path, struct stat *buf) {
io_stat_t fiostat;

Expand All @@ -85,19 +102,7 @@ static int fioGetstatHelper(const char *path, struct stat *buf) {
return -1;
}

buf->st_dev = 0;
buf->st_ino = 0;
buf->st_mode = io_to_posix_mode(fiostat.mode);
buf->st_nlink = 0;
buf->st_uid = 0;
buf->st_gid = 0;
buf->st_rdev = 0;
buf->st_size = ((off_t)fiostat.hisize << 32) | (off_t)fiostat.size;
buf->st_atime = io_to_posix_time(fiostat.atime);
buf->st_mtime = io_to_posix_time(fiostat.mtime);
buf->st_ctime = io_to_posix_time(fiostat.ctime);
buf->st_blksize = 16*1024;
buf->st_blocks = buf->st_size / 512;
fill_stat(buf, &fiostat);

return 0;
}
Expand All @@ -115,11 +120,7 @@ static DIR *fioOpendirHelper(const char *path)

dir = malloc(sizeof(DIR));
dir->dd_fd = dd;
dir->dd_loc = 0;
dir->dd_size = 0;
dir->dd_buf = malloc(sizeof(struct dirent) + 255);
dir->dd_len = 0;
dir->dd_seek = 0;
dir->dd_buf = malloc(sizeof(struct dirent));

return dir;
}
Expand All @@ -141,9 +142,7 @@ static struct dirent *fioReaddirHelper(DIR *dir)
return NULL;
}

de->d_ino = 0;
de->d_off = 0;
de->d_reclen = 0;
fill_stat(&de->d_stat, &fiode.stat);
strncpy(de->d_name, fiode.name, 255);
de->d_name[255] = 0;

Expand Down
41 changes: 20 additions & 21 deletions ee/rpc/filexio/src/fileXio_rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,23 @@ static mode_t iox_to_posix_mode(unsigned int ps2mode)
return posixmode;
}

static void fill_stat(struct stat *stat, const iox_stat_t *fiostat)
{
stat->st_dev = 0;
stat->st_ino = 0;
stat->st_mode = iox_to_posix_mode(fiostat->mode);
stat->st_nlink = 0;
stat->st_uid = 0;
stat->st_gid = 0;
stat->st_rdev = 0;
stat->st_size = ((off_t)fiostat->hisize << 32) | (off_t)fiostat->size;
stat->st_atime = io_to_posix_time(fiostat->atime);
stat->st_mtime = io_to_posix_time(fiostat->mtime);
stat->st_ctime = io_to_posix_time(fiostat->ctime);
stat->st_blksize = 16*1024;
stat->st_blocks = stat->st_size / 512;
}

static int fileXioGetstatHelper(const char *path, struct stat *buf) {
iox_stat_t fiostat;

Expand All @@ -89,19 +106,7 @@ static int fileXioGetstatHelper(const char *path, struct stat *buf) {
return -1;
}

buf->st_dev = 0;
buf->st_ino = 0;
buf->st_mode = iox_to_posix_mode(fiostat.mode);
buf->st_nlink = 0;
buf->st_uid = 0;
buf->st_gid = 0;
buf->st_rdev = 0;
buf->st_size = ((off_t)fiostat.hisize << 32) | (off_t)fiostat.size;
buf->st_atime = io_to_posix_time(fiostat.atime);
buf->st_mtime = io_to_posix_time(fiostat.mtime);
buf->st_ctime = io_to_posix_time(fiostat.ctime);
buf->st_blksize = 16*1024;
buf->st_blocks = buf->st_size / 512;
fill_stat(buf, &fiostat);

return 0;
}
Expand All @@ -120,11 +125,7 @@ static DIR *fileXioOpendirHelper(const char *path)

dir = malloc(sizeof(DIR));
dir->dd_fd = dd;
dir->dd_loc = 0;
dir->dd_size = 0;
dir->dd_buf = malloc(sizeof(struct dirent) + 255);
dir->dd_len = 0;
dir->dd_seek = 0;
dir->dd_buf = malloc(sizeof(struct dirent));

return dir;
}
Expand All @@ -147,9 +148,7 @@ static struct dirent *fileXioReaddirHelper(DIR *dir)
return NULL;
}

de->d_ino = 0;
de->d_off = 0;
de->d_reclen = 0;
fill_stat(&de->d_stat, &fiode.stat);
strncpy(de->d_name, fiode.name, 255);
de->d_name[255] = 0;

Expand Down

0 comments on commit 1f478e9

Please sign in to comment.