ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
fileXio_rpc.c File Reference
#include <tamtypes.h>
#include <kernel.h>
#include <sifrpc.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <stdarg.h>
#include <sys/fcntl.h>
#include <sys/stat.h>
#include <ps2sdkapi.h>
#include <fileXio_rpc.h>
#include <errno.h>
+ Include dependency graph for fileXio_rpc.c:

Go to the source code of this file.

Macros

#define NEWLIB_PORT_AWARE
 

Functions

static void _fxio_intr (void)
 
static int _lock (void)
 
static int _unlock (void)
 
static time_t io_to_posix_time (const unsigned char *ps2time)
 
static mode_t iox_to_posix_mode (unsigned int ps2mode)
 
static void fill_stat (struct stat *stat, const iox_stat_t *fiostat)
 
static int fileXioGetstatHelper (const char *path, struct stat *buf)
 
static DIR * fileXioOpendirHelper (const char *path)
 
static struct dirent * fileXioReaddirHelper (DIR *dir)
 
static void fileXioRewinddirHelper (DIR *dir)
 
static int fileXioClosedirHelper (DIR *dir)
 
int fileXioInit (void)
 
void fileXioExit (void)
 
void fileXioStop (void)
 
int fileXioGetDeviceList (struct fileXioDevice deviceEntry[], unsigned int req_entries)
 
int fileXioGetdir (const char *pathname, struct fileXioDirEntry dirEntry[], unsigned int req_entries)
 
int fileXioMount (const char *mountpoint, const char *mountstring, int flag)
 
int fileXioUmount (const char *mountpoint)
 
int fileXioCopyfile (const char *source, const char *dest, int mode)
 
int fileXioMkdir (const char *pathname, int mode)
 
int fileXioRmdir (const char *pathname)
 
int fileXioRemove (const char *pathname)
 
int fileXioRename (const char *source, const char *dest)
 
int fileXioSymlink (const char *source, const char *dest)
 
int fileXioReadlink (const char *source, char *buf, int buflen)
 
int fileXioChdir (const char *pathname)
 
int fileXioOpen (const char *source, int flags,...)
 
int fileXioClose (int fd)
 
static void recv_intr (void *data_raw)
 
int fileXioRead (int fd, void *buf, int size)
 
int fileXioWrite (int fd, const void *buf, int size)
 
int fileXioLseek (int fd, int offset, int whence)
 
s64 fileXioLseek64 (int fd, s64 offset, int whence)
 
int fileXioChStat (const char *name, iox_stat_t *stat, int mask)
 
int fileXioGetStat (const char *name, iox_stat_t *stat)
 
int fileXioFormat (const char *dev, const char *blockdev, const void *args, int arglen)
 
int fileXioSync (const char *devname, int flag)
 
int fileXioDopen (const char *name)
 
int fileXioDclose (int fd)
 
int fileXioDread (int fd, iox_dirent_t *dirent)
 
static void fxio_ctl_intr (void *data_raw)
 
int fileXioDevctl (const char *name, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
 
int fileXioIoctl (int fd, int cmd, void *arg)
 
int fileXioIoctl2 (int fd, int command, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
 
int fileXioWaitAsync (int mode, int *retVal)
 
void fileXioSetBlockMode (int blocking)
 
int fileXioSetRWBufferSize (int size)
 

Variables

int _iop_reboot_count
 
static SifRpcClientData_t cd0
 
static unsigned int sbuff [0x1300]
 
static int _intr_data [0xC00]
 
static int fileXioInited = 0
 
static int fileXioBlockMode
 
static int fileXioCompletionSema = -1
 
static int _lock_sema_id = -1
 

Detailed Description

fileXio RPC client

Definition in file fileXio_rpc.c.

Macro Definition Documentation

◆ NEWLIB_PORT_AWARE

#define NEWLIB_PORT_AWARE

Definition at line 27 of file fileXio_rpc.c.

Function Documentation

◆ _fxio_intr()

◆ _lock()

◆ _unlock()

◆ fileXioChdir()

int fileXioChdir ( const char *  pathname)

Definition at line 556 of file fileXio_rpc.c.

557 {
558  int rv;
560 
561  if(fileXioInit() < 0)
562  return -ENOPKG;
563 
564  _lock();
566 
567  strncpy(packet->pathname, pathname, sizeof(packet->pathname));
568 
569  if((rv = SifCallRpc(&cd0, FILEXIO_CHDIR, fileXioBlockMode, sbuff, sizeof(struct fxio_pathsel_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
570  {
571  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
572  else { rv = sbuff[0]; }
573  }
574  else
576 
577  _unlock();
578  return(rv);
579 }
#define ENOPKG
Definition: errno.h:140
@ FILEXIO_CHDIR
Definition: fileXio.h:55
static SifRpcClientData_t cd0
Definition: fileXio_rpc.c:32
static void _fxio_intr(void)
Definition: fileXio_rpc.c:39
int fileXioInit(void)
Definition: fileXio_rpc.c:176
static unsigned int sbuff[0x1300]
Definition: fileXio_rpc.c:33
static int fileXioBlockMode
Definition: fileXio_rpc.c:36
static int _unlock(void)
Definition: fileXio_rpc.c:50
static int _lock(void)
Definition: fileXio_rpc.c:45
#define FXIO_NOWAIT
Definition: fileXio_rpc.h:28
packet_t packet
Definition: font.c:24
int SifCallRpc(SifRpcClientData_t *client, int rpc_number, int mode, void *send, int ssize, void *receive, int rsize, SifRpcEndFunc_t end_function, void *end_param)
char pathname[512]
Definition: fileXio.h:148
#define NULL
Definition: tamtypes.h:91

References _fxio_intr(), _lock(), _unlock(), cd0, ENOPKG, FILEXIO_CHDIR, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, NULL, packet, fxio_pathsel_packet::pathname, sbuff, SifCallRpc(), SignalSema(), and WaitSema().

◆ fileXioChStat()

int fileXioChStat ( const char *  name,
iox_stat_t stat,
int  mask 
)

Definition at line 784 of file fileXio_rpc.c.

785 {
786  int rv;
788 
789  if(fileXioInit() < 0)
790  return -ENOPKG;
791 
792  _lock();
794 
795  strncpy(packet->pathname, name, sizeof(packet->pathname));
796  packet->stat = stat;
797  packet->mask = mask;
798 
799  if(!IS_UNCACHED_SEG(stat))
801 
802  if((rv = SifCallRpc(&cd0, FILEXIO_CHSTAT, fileXioBlockMode, sbuff, sizeof(struct fxio_chstat_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
803  {
804  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
805  else { rv = sbuff[0]; }
806  }
807  else
809 
810  _unlock();
811  return(rv);
812 }
@ FILEXIO_CHSTAT
Definition: fileXio.h:50
#define IS_UNCACHED_SEG(x)
Definition: kernel.h:38
void SifWriteBackDCache(void *ptr, int size)
iox_stat_t * stat
Definition: fileXio.h:203

References _fxio_intr(), _lock(), _unlock(), cd0, ENOPKG, FILEXIO_CHSTAT, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, IS_UNCACHED_SEG, fxio_chstat_packet::mask, NULL, packet, sbuff, SifCallRpc(), SifWriteBackDCache(), SignalSema(), fxio_chstat_packet::stat, and WaitSema().

◆ fileXioClose()

int fileXioClose ( int  fd)

Definition at line 612 of file fileXio_rpc.c.

613 {
614  int rv;
616 
617  if(fileXioInit() < 0)
618  return -ENOPKG;
619 
620  _lock();
622 
623  packet->fd = fd;
624 
625  if((rv = SifCallRpc(&cd0, FILEXIO_CLOSE, fileXioBlockMode, sbuff, sizeof(struct fxio_close_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
626  {
627  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
628  else { rv = sbuff[0]; }
629  }
630  else
632 
633  _unlock();
634  return(rv);
635 }
@ FILEXIO_CLOSE
Definition: fileXio.h:43

References _fxio_intr(), _lock(), _unlock(), cd0, ENOPKG, fxio_close_packet::fd, FILEXIO_CLOSE, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, NULL, packet, sbuff, SifCallRpc(), SignalSema(), and WaitSema().

Referenced by fileXioInit(), hddExpandFilesystem(), hddGetFilesystemList(), and hddMakeFilesystem().

◆ fileXioClosedirHelper()

static int fileXioClosedirHelper ( DIR *  dir)
static

Definition at line 163 of file fileXio_rpc.c.

164 {
165  if(dir == NULL) {
166  // FIXME: set errno
167  return -1;
168  }
169 
170  fileXioDclose(dir->dd_fd); // Check return value?
171  free(dir->dd_buf);
172  free(dir);
173  return 0;
174 }
int fileXioDclose(int fd)
Definition: fileXio_rpc.c:924

References fileXioDclose(), and NULL.

Referenced by fileXioInit().

◆ fileXioCopyfile()

int fileXioCopyfile ( const char *  source,
const char *  dest,
int  mode 
)

Definition at line 371 of file fileXio_rpc.c.

372 {
373  int rv;
375 
376  if(fileXioInit() < 0)
377  return -ENOPKG;
378 
379  _lock();
381 
382  strncpy(packet->source, source, sizeof(packet->source));
383  strncpy(packet->dest, dest, sizeof(packet->dest));
384  packet->mode = mode;
385 
386  if((rv = SifCallRpc(&cd0, FILEXIO_COPYFILE, fileXioBlockMode, sbuff, sizeof(struct fxio_copyfile_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
387  {
388  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
389  else { rv = sbuff[0]; }
390  }
391  else
393 
394  _unlock();
395  return(rv);
396 }
@ FILEXIO_COPYFILE
Definition: fileXio.h:41
s32 mode
Definition: rpc_client.c:15
char source[512]
Definition: fileXio.h:136
char dest[512]
Definition: fileXio.h:137

References _fxio_intr(), _lock(), _unlock(), cd0, fxio_copyfile_packet::dest, ENOPKG, FILEXIO_COPYFILE, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, mode, NULL, packet, sbuff, SifCallRpc(), SignalSema(), fxio_copyfile_packet::source, and WaitSema().

◆ fileXioDclose()

int fileXioDclose ( int  fd)

Definition at line 924 of file fileXio_rpc.c.

925 {
926  int rv;
928 
929  if(fileXioInit() < 0)
930  return -ENOPKG;
931 
932  _lock();
934 
935  packet->fd = fd;
936  if((rv = SifCallRpc(&cd0, FILEXIO_DCLOSE, fileXioBlockMode, sbuff, sizeof(struct fxio_close_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
937  {
938  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
939  else { rv = sbuff[0]; }
940  }
941  else
943 
944  _unlock();
945  return(rv);
946 }
@ FILEXIO_DCLOSE
Definition: fileXio.h:36

References _fxio_intr(), _lock(), _unlock(), cd0, ENOPKG, fxio_close_packet::fd, FILEXIO_DCLOSE, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, NULL, packet, sbuff, SifCallRpc(), SignalSema(), and WaitSema().

Referenced by fileXioClosedirHelper(), hddGetFilesystemList(), and hddUpdateInfo().

◆ fileXioDevctl()

int fileXioDevctl ( const char *  name,
int  cmd,
void *  arg,
unsigned int  arglen,
void *  buf,
unsigned int  buflen 
)

Definition at line 986 of file fileXio_rpc.c.

987 {
989  int rv;
990 
991  if(fileXioInit() < 0)
992  return -ENOPKG;
993 
994  _lock();
996 
999  strncpy(packet->name, name, CTL_BUF_SIZE);
1000  packet->name[CTL_BUF_SIZE-1] = '\0';
1001  memcpy(packet->arg, arg, arglen);
1002 
1003  packet->cmd = cmd;
1004  packet->arglen = arglen;
1005  packet->buf = buf;
1006  packet->buflen = buflen;
1007  packet->intr_data = _intr_data;
1008 
1010 
1011  if(buflen)
1013  else
1014  rv = SifCallRpc(&cd0, FILEXIO_DEVCTL, fileXioBlockMode, packet, sizeof(struct fxio_devctl_packet), sbuff, 4, (void *)&_fxio_intr, NULL);
1015 
1016  if(rv >= 0)
1017  {
1018  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
1019  else { rv = sbuff[0]; }
1020  }
1021  else
1023 
1024  _unlock();
1025  return(rv);
1026 }
#define CTL_BUF_SIZE
Definition: fileXio.h:85
@ FILEXIO_DEVCTL
Definition: fileXio.h:57
static void fxio_ctl_intr(void *data_raw)
Definition: fileXio_rpc.c:977
static int _intr_data[0xC00]
Definition: fileXio_rpc.c:34
u8 arg[CTL_BUF_SIZE]
Definition: fileXio.h:231
char name[CTL_BUF_SIZE]
Definition: fileXio.h:230

References _fxio_intr(), _intr_data, _lock(), _unlock(), fxio_devctl_packet::arg, fxio_devctl_packet::arglen, fxio_devctl_packet::buf, fxio_devctl_packet::buflen, cd0, fxio_devctl_packet::cmd, CTL_BUF_SIZE, ENOPKG, FILEXIO_DEVCTL, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), fxio_ctl_intr(), FXIO_NOWAIT, fxio_devctl_packet::name, NULL, packet, sbuff, SifCallRpc(), SifWriteBackDCache(), SignalSema(), and WaitSema().

Referenced by hddCheckFormatted(), hddCheckPresent(), hddGetFilesystemList(), and hddUpdateInfo().

◆ fileXioDopen()

int fileXioDopen ( const char *  name)

Definition at line 900 of file fileXio_rpc.c.

901 {
902  int rv;
904 
905  if(fileXioInit() < 0)
906  return -ENOPKG;
907 
908  _lock();
910 
911  strncpy(packet->pathname, name, sizeof(packet->pathname));
912  if((rv = SifCallRpc(&cd0, FILEXIO_DOPEN, fileXioBlockMode, sbuff, sizeof(struct fxio_pathsel_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
913  {
914  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
915  else { rv = sbuff[0]; }
916  }
917  else
919 
920  _unlock();
921  return(rv);
922 }
@ FILEXIO_DOPEN
Definition: fileXio.h:34

References _fxio_intr(), _lock(), _unlock(), cd0, ENOPKG, FILEXIO_DOPEN, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, NULL, packet, sbuff, SifCallRpc(), SignalSema(), and WaitSema().

Referenced by fileXioOpendirHelper(), hddGetFilesystemList(), and hddUpdateInfo().

◆ fileXioDread()

int fileXioDread ( int  fd,
iox_dirent_t dirent 
)

Definition at line 948 of file fileXio_rpc.c.

949 {
950  int rv;
952 
953  if(fileXioInit() < 0)
954  return -ENOPKG;
955 
956  _lock();
958 
959  packet->fd = fd;
960  packet->dirent = dirent;
961 
962  if (!IS_UNCACHED_SEG(dirent))
964 
965  if((rv = SifCallRpc(&cd0, FILEXIO_DREAD, fileXioBlockMode, sbuff, sizeof(struct fxio_dread_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
966  {
967  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
968  else { rv = sbuff[0]; }
969  }
970  else
972 
973  _unlock();
974  return(rv);
975 }
@ FILEXIO_DREAD
Definition: fileXio.h:35
iox_dirent_t * dirent
Definition: fileXio.h:226

References _fxio_intr(), _lock(), _unlock(), cd0, fxio_dread_packet::dirent, ENOPKG, fxio_dread_packet::fd, FILEXIO_DREAD, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, IS_UNCACHED_SEG, NULL, packet, sbuff, SifCallRpc(), SifWriteBackDCache(), SignalSema(), and WaitSema().

Referenced by fileXioReaddirHelper(), hddGetFilesystemList(), and hddUpdateInfo().

◆ fileXioExit()

void fileXioExit ( void  )

Definition at line 237 of file fileXio_rpc.c.

238 {
239  if(fileXioInited)
240  {
243 
244  memset(&cd0, 0, sizeof(cd0));
245 
246  fileXioInited = 0;
247  }
248 }
static int fileXioInited
Definition: fileXio_rpc.c:35
s32 DeleteSema(s32 sema_id)

References _lock_sema_id, cd0, DeleteSema(), fileXioCompletionSema, and fileXioInited.

Referenced by fileXioInit().

◆ fileXioFormat()

int fileXioFormat ( const char *  dev,
const char *  blockdev,
const void *  args,
int  arglen 
)

Definition at line 843 of file fileXio_rpc.c.

844 {
845  int rv;
847 
848  if(fileXioInit() < 0)
849  return -ENOPKG;
850 
851  _lock();
853 
854  strncpy(packet->device, dev, sizeof(packet->device));
855  if(blockdev)
856  strncpy(packet->blockDevice, blockdev, sizeof(packet->blockDevice));
857 
858  if(arglen > sizeof(packet->args)) arglen = sizeof(packet->args);
859  memcpy(packet->args, args, arglen);
860  packet->arglen = arglen;
861 
862  if((rv = SifCallRpc(&cd0, FILEXIO_FORMAT, fileXioBlockMode, sbuff, sizeof(struct fxio_format_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
863  {
864  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
865  else { rv = sbuff[0]; }
866  }
867  else
869 
870  _unlock();
871  return(rv);
872 }
@ FILEXIO_FORMAT
Definition: fileXio.h:51
char args[512]
Definition: fileXio.h:215

References _fxio_intr(), _lock(), _unlock(), fxio_format_packet::arglen, fxio_format_packet::args, cd0, ENOPKG, FILEXIO_FORMAT, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, NULL, packet, sbuff, SifCallRpc(), SignalSema(), and WaitSema().

Referenced by hddFormat(), and hddMakeFilesystem().

◆ fileXioGetDeviceList()

int fileXioGetDeviceList ( struct fileXioDevice  deviceEntry[],
unsigned int  req_entries 
)

Definition at line 260 of file fileXio_rpc.c.

261 {
262  int rv;
264 
265  if(fileXioInit() < 0)
266  return -ENOPKG;
267 
268  _lock();
270 
271  packet->deviceEntry = deviceEntry;
272  packet->reqEntries = req_entries;
273 
274  // This will get the directory contents, and fill dirEntry via DMA
275  if((rv = SifCallRpc(&cd0, FILEXIO_GETDEVICELIST, fileXioBlockMode, sbuff, sizeof(struct fxio_devlist_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
276  {
277  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
278  else { rv = sbuff[0]; }
279  }
280  else
282 
283  _unlock();
284  return(rv);
285 }
@ FILEXIO_GETDEVICELIST
Definition: fileXio.h:64
struct fileXioDevice * deviceEntry
Definition: fileXio.h:115

References _fxio_intr(), _lock(), _unlock(), cd0, fxio_devlist_packet::deviceEntry, ENOPKG, FILEXIO_GETDEVICELIST, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, NULL, packet, sbuff, SifCallRpc(), SignalSema(), and WaitSema().

◆ fileXioGetdir()

int fileXioGetdir ( const char *  pathname,
struct fileXioDirEntry  dirEntry[],
unsigned int  req_entries 
)

Definition at line 287 of file fileXio_rpc.c.

288 {
289  int rv;
291 
292  if(fileXioInit() < 0)
293  return -ENOPKG;
294 
295  _lock();
297 
298  // copy the requested pathname to the rpc buffer
299  strncpy(packet->pathname, pathname, sizeof(packet->pathname));
300 
301  SifWriteBackDCache(dirEntry, (sizeof(struct fileXioDirEntry) * req_entries));
302 
303  packet->dirEntry = dirEntry;
304  packet->reqEntries = req_entries;
305 
306  // This will get the directory contents, and fill dirEntry via DMA
307  if((rv = SifCallRpc(&cd0, FILEXIO_GETDIR, fileXioBlockMode, sbuff, sizeof(struct fxio_getdir_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
308  {
309  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
310  else { rv = sbuff[0]; }
311  }
312  else
314 
315  _unlock();
316  return(rv);
317 }
@ FILEXIO_GETDIR
Definition: fileXio.h:39
char pathname[512]
Definition: fileXio.h:120
struct fileXioDirEntry * dirEntry
Definition: fileXio.h:121

References _fxio_intr(), _lock(), _unlock(), cd0, fxio_getdir_packet::dirEntry, ENOPKG, FILEXIO_GETDIR, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, NULL, packet, fxio_getdir_packet::pathname, sbuff, SifCallRpc(), SifWriteBackDCache(), SignalSema(), and WaitSema().

◆ fileXioGetStat()

int fileXioGetStat ( const char *  name,
iox_stat_t stat 
)

Definition at line 814 of file fileXio_rpc.c.

815 {
816  int rv;
818 
819  if(fileXioInit() < 0)
820  return -ENOPKG;
821 
822  _lock();
824 
825  strncpy(packet->pathname, name, sizeof(packet->pathname));
826  packet->stat = stat;
827 
828  if(!IS_UNCACHED_SEG(stat))
830 
831  if((rv = SifCallRpc(&cd0, FILEXIO_GETSTAT, fileXioBlockMode, sbuff, sizeof(struct fxio_getstat_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
832  {
833  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
834  else { rv = sbuff[0]; }
835  }
836  else
838 
839  _unlock();
840  return(rv);
841 }
@ FILEXIO_GETSTAT
Definition: fileXio.h:49
iox_stat_t * stat
Definition: fileXio.h:209

References _fxio_intr(), _lock(), _unlock(), cd0, ENOPKG, FILEXIO_GETSTAT, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, IS_UNCACHED_SEG, NULL, packet, sbuff, SifCallRpc(), SifWriteBackDCache(), SignalSema(), fxio_getstat_packet::stat, and WaitSema().

Referenced by fileXioGetstatHelper().

◆ fileXioGetstatHelper()

static int fileXioGetstatHelper ( const char *  path,
struct stat *  buf 
)
static

Definition at line 101 of file fileXio_rpc.c.

101  {
102  iox_stat_t fiostat;
103 
104  if (fileXioGetStat(path, &fiostat) < 0) {
105  // FIXME: set errno
106  return -1;
107  }
108 
109  fill_stat(buf, &fiostat);
110 
111  return 0;
112 }
static void fill_stat(struct stat *stat, const iox_stat_t *fiostat)
Definition: fileXio_rpc.c:84
int fileXioGetStat(const char *name, iox_stat_t *stat)
Definition: fileXio_rpc.c:814

References fileXioGetStat(), and fill_stat().

Referenced by fileXioInit().

◆ fileXioInit()

int fileXioInit ( void  )

Definition at line 176 of file fileXio_rpc.c.

177 {
178  int res;
179  ee_sema_t sp;
180  static int _rb_count = 0;
181 
182  if(_rb_count != _iop_reboot_count)
183  {
184  _rb_count = _iop_reboot_count;
185 
186  fileXioExit();
187  }
188 
189  if(fileXioInited)
190  {
191  return 0;
192  }
193 
194  sp.init_count = 1;
195  sp.max_count = 1;
196  sp.option = 0;
198 
199  while(((res = SifBindRpc(&cd0, FILEXIO_IRX, 0)) >= 0) && (cd0.server == NULL))
200  nopdelay();
201 
202  if(res < 0)
203  return res;
204 
205  sp.init_count = 1;
206  sp.max_count = 1;
207  sp.option = 0;
209  if (fileXioCompletionSema < 0)
210  return -1;
211 
212  fileXioInited = 1;
214 
226 
228 
233 
234  return 0;
235 }
#define sp
Definition: as_reg_compat.h:85
#define FILEXIO_IRX
Definition: fileXio.h:32
int fileXioMkdir(const char *pathname, int mode)
Definition: fileXio_rpc.c:398
static void fileXioRewinddirHelper(DIR *dir)
Definition: fileXio_rpc.c:158
void fileXioExit(void)
Definition: fileXio_rpc.c:237
int fileXioRename(const char *source, const char *dest)
Definition: fileXio_rpc.c:474
static int fileXioClosedirHelper(DIR *dir)
Definition: fileXio_rpc.c:163
static struct dirent * fileXioReaddirHelper(DIR *dir)
Definition: fileXio_rpc.c:133
int fileXioClose(int fd)
Definition: fileXio_rpc.c:612
static DIR * fileXioOpendirHelper(const char *path)
Definition: fileXio_rpc.c:114
int fileXioRead(int fd, void *buf, int size)
Definition: fileXio_rpc.c:647
int fileXioIoctl(int fd, int cmd, void *arg)
Definition: fileXio_rpc.c:1028
int fileXioRmdir(const char *pathname)
Definition: fileXio_rpc.c:424
int fileXioRemove(const char *pathname)
Definition: fileXio_rpc.c:449
static int fileXioGetstatHelper(const char *path, struct stat *buf)
Definition: fileXio_rpc.c:101
int _iop_reboot_count
s64 fileXioLseek64(int fd, s64 offset, int whence)
Definition: fileXio_rpc.c:750
int fileXioOpen(const char *source, int flags,...)
Definition: fileXio_rpc.c:581
int fileXioWrite(int fd, const void *buf, int size)
Definition: fileXio_rpc.c:678
int fileXioLseek(int fd, int offset, int whence)
Definition: fileXio_rpc.c:720
#define FXIO_WAIT
Definition: fileXio_rpc.h:27
s32 CreateSema(ee_sema_t *sema)
static void nopdelay(void)
Definition: kernel.h:141
DIR *(* _ps2sdk_opendir)(const char *path)
Definition: ps2sdkapi.c:185
int(* _ps2sdk_stat)(const char *path, struct stat *buf)
Definition: ps2sdkapi.c:183
void(* _ps2sdk_rewinddir)(DIR *dir)
Definition: ps2sdkapi.c:187
int64_t(* _ps2sdk_lseek64)(int, int64_t, int)
Definition: ps2sdkapi.c:175
int(* _ps2sdk_closedir)(DIR *dir)
Definition: ps2sdkapi.c:188
int(* _ps2sdk_lseek)(int, int, int)
Definition: ps2sdkapi.c:174
int(* _ps2sdk_write)(int, const void *, int)
Definition: ps2sdkapi.c:176
int(* _ps2sdk_close)(int)
Definition: ps2sdkapi.c:171
int(* _ps2sdk_ioctl)(int, int, void *)
Definition: ps2sdkapi.c:177
int(* _ps2sdk_remove)(const char *)
Definition: ps2sdkapi.c:178
int(* _ps2sdk_rename)(const char *, const char *)
Definition: ps2sdkapi.c:179
struct dirent *(* _ps2sdk_readdir)(DIR *dir)
Definition: ps2sdkapi.c:186
int(* _ps2sdk_read)(int, void *, int)
Definition: ps2sdkapi.c:173
int(* _ps2sdk_mkdir)(const char *, int)
Definition: ps2sdkapi.c:180
int(* _ps2sdk_rmdir)(const char *)
Definition: ps2sdkapi.c:181
int(* _ps2sdk_open)(const char *, int,...)
Definition: ps2sdkapi.c:172
int SifBindRpc(SifRpcClientData_t *client, int rpc_number, int mode)
struct t_SifRpcServerData * server
Definition: sifrpc.h:142

References _iop_reboot_count, _lock_sema_id, _ps2sdk_close, _ps2sdk_closedir, _ps2sdk_ioctl, _ps2sdk_lseek, _ps2sdk_lseek64, _ps2sdk_mkdir, _ps2sdk_open, _ps2sdk_opendir, _ps2sdk_read, _ps2sdk_readdir, _ps2sdk_remove, _ps2sdk_rename, _ps2sdk_rewinddir, _ps2sdk_rmdir, _ps2sdk_stat, _ps2sdk_write, cd0, CreateSema(), FILEXIO_IRX, fileXioBlockMode, fileXioClose(), fileXioClosedirHelper(), fileXioCompletionSema, fileXioExit(), fileXioGetstatHelper(), fileXioInited, fileXioIoctl(), fileXioLseek(), fileXioLseek64(), fileXioMkdir(), fileXioOpen(), fileXioOpendirHelper(), fileXioRead(), fileXioReaddirHelper(), fileXioRemove(), fileXioRename(), fileXioRewinddirHelper(), fileXioRmdir(), fileXioWrite(), FXIO_WAIT, nopdelay(), NULL, SifRpcClientData_t::server, SifBindRpc(), and sp.

Referenced by fileXioChdir(), fileXioChStat(), fileXioClose(), fileXioCopyfile(), fileXioDclose(), fileXioDevctl(), fileXioDopen(), fileXioDread(), fileXioFormat(), fileXioGetDeviceList(), fileXioGetdir(), fileXioGetStat(), fileXioIoctl(), fileXioIoctl2(), fileXioLseek(), fileXioLseek64(), fileXioMkdir(), fileXioMount(), fileXioOpen(), fileXioRead(), fileXioReadlink(), fileXioRemove(), fileXioRename(), fileXioRmdir(), fileXioSetRWBufferSize(), fileXioStop(), fileXioSymlink(), fileXioSync(), fileXioUmount(), fileXioWaitAsync(), and fileXioWrite().

◆ fileXioIoctl()

int fileXioIoctl ( int  fd,
int  cmd,
void *  arg 
)

Definition at line 1028 of file fileXio_rpc.c.

1028  {
1029  struct fxio_ioctl_packet *packet = (struct fxio_ioctl_packet *)sbuff;
1030  int rv;
1031 
1032  if(fileXioInit() < 0)
1033  return -ENOPKG;
1034 
1035  _lock();
1037 
1038  memcpy(packet->arg, arg, IOCTL_BUF_SIZE);
1039 
1040  packet->fd = fd;
1041  packet->cmd = cmd;
1042 
1043  if((rv = SifCallRpc(&cd0, FILEXIO_IOCTL, fileXioBlockMode, packet, sizeof(struct fxio_ioctl_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
1044  {
1045  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
1046  else { rv = sbuff[0]; }
1047  }
1048  else
1050 
1051  _unlock();
1052  return(rv);
1053 }
#define IOCTL_BUF_SIZE
Definition: fileXio.h:86
@ FILEXIO_IOCTL
Definition: fileXio.h:47
u8 arg[IOCTL_BUF_SIZE]
Definition: fileXio.h:241

References _fxio_intr(), _lock(), _unlock(), fxio_ioctl_packet::arg, cd0, fxio_ioctl_packet::cmd, ENOPKG, fxio_ioctl_packet::fd, FILEXIO_IOCTL, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, IOCTL_BUF_SIZE, NULL, packet, sbuff, SifCallRpc(), SignalSema(), and WaitSema().

Referenced by fileXioInit().

◆ fileXioIoctl2()

int fileXioIoctl2 ( int  fd,
int  command,
void *  arg,
unsigned int  arglen,
void *  buf,
unsigned int  buflen 
)

Definition at line 1055 of file fileXio_rpc.c.

1056 {
1057  struct fxio_ioctl2_packet *packet = (struct fxio_ioctl2_packet *)sbuff;
1058  int rv;
1059 
1060  if(fileXioInit() < 0)
1061  return -ENOPKG;
1062 
1063  _lock();
1065 
1068  memcpy(packet->arg, arg, arglen);
1069 
1070  packet->fd = fd;
1071  packet->cmd = command;
1072  packet->arglen = arglen;
1073  packet->buf = buf;
1074  packet->buflen = buflen;
1075  packet->intr_data = _intr_data;
1076 
1078 
1079  if(buflen)
1081  else
1082  rv = SifCallRpc(&cd0, FILEXIO_IOCTL2, fileXioBlockMode, packet, sizeof(struct fxio_ioctl2_packet), sbuff, 4, (void *)&_fxio_intr, NULL);
1083 
1084  if(rv >= 0)
1085  {
1086  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
1087  else { rv = sbuff[0]; }
1088  }
1089  else
1091 
1092  _unlock();
1093  return(rv);
1094 }
@ FILEXIO_IOCTL2
Definition: fileXio.h:60
s32 command
Definition: libpad.c:156
u8 arg[CTL_BUF_SIZE]
Definition: fileXio.h:247

References _fxio_intr(), _intr_data, _lock(), _unlock(), fxio_ioctl2_packet::arg, fxio_ioctl2_packet::arglen, fxio_ioctl2_packet::buf, fxio_ioctl2_packet::buflen, cd0, command, CTL_BUF_SIZE, ENOPKG, fxio_ioctl2_packet::fd, FILEXIO_IOCTL2, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), fxio_ctl_intr(), FXIO_NOWAIT, NULL, packet, sbuff, SifCallRpc(), SifWriteBackDCache(), SignalSema(), and WaitSema().

Referenced by hddExpandFilesystem(), hddGetFilesystemList(), and hddMakeFilesystem().

◆ fileXioLseek()

int fileXioLseek ( int  fd,
int  offset,
int  whence 
)

Definition at line 720 of file fileXio_rpc.c.

721 {
722  int rv;
724 
725  if(fileXioInit() < 0)
726  return -ENOPKG;
727 
728  _lock();
730 
731  packet->fd = fd;
732  packet->offset = (u32)offset;
733  packet->whence = whence;
734 
735  if((rv = SifCallRpc(&cd0, FILEXIO_LSEEK, fileXioBlockMode, sbuff, sizeof(struct fxio_lseek_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
736  {
737  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
738  else { rv = sbuff[0]; }
739  }
740  else
742 
743  _unlock();
744  return(rv);
745 }
@ FILEXIO_LSEEK
Definition: fileXio.h:46
unsigned int u32
Definition: tamtypes.h:30

References _fxio_intr(), _lock(), _unlock(), cd0, ENOPKG, fxio_lseek_packet::fd, FILEXIO_LSEEK, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, NULL, fxio_lseek_packet::offset, packet, sbuff, SifCallRpc(), SignalSema(), WaitSema(), and fxio_lseek_packet::whence.

Referenced by fileXioInit().

◆ fileXioLseek64()

s64 fileXioLseek64 ( int  fd,
s64  offset,
int  whence 
)

Definition at line 750 of file fileXio_rpc.c.

751 {
752  s64 rv;
754  struct fxio_lseek64_return_pkt *ret_packet=(struct fxio_lseek64_return_pkt*)sbuff;
755 
756  if(fileXioInit() < 0)
757  return -ENOPKG;
758 
759  _lock();
761 
762  packet->fd = fd;
763  packet->offset_lo = (u32)(offset & 0xffffffff);
764  packet->offset_hi = (u32)((offset >> 32) & 0xffffffff);
765  packet->whence = whence;
766 
767  if((rv = SifCallRpc(&cd0, FILEXIO_LSEEK64, fileXioBlockMode, sbuff, sizeof(struct fxio_lseek64_packet), sbuff, 8, (void *)&_fxio_intr, NULL)) >= 0)
768  {
769  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
770  else {
771  s64 rvHI = ret_packet->pos_hi;
772  rvHI = rvHI << 32;
773  rv = rvHI | ret_packet->pos_lo;
774  }
775  }
776  else
778 
779  _unlock();
780 
781  return(rv);
782 }
@ FILEXIO_LSEEK64
Definition: fileXio.h:61
signed long s64
Definition: tamtypes.h:62

References _fxio_intr(), _lock(), _unlock(), cd0, ENOPKG, FILEXIO_LSEEK64, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, NULL, packet, fxio_lseek64_return_pkt::pos_hi, fxio_lseek64_return_pkt::pos_lo, sbuff, SifCallRpc(), SignalSema(), and WaitSema().

Referenced by fileXioInit().

◆ fileXioMkdir()

int fileXioMkdir ( const char *  pathname,
int  mode 
)

Definition at line 398 of file fileXio_rpc.c.

399 {
400  int rv;
402 
403  if(fileXioInit() < 0)
404  return -ENOPKG;
405 
406  _lock();
408 
409  strncpy(packet->pathname, pathname, sizeof(packet->pathname));
410  packet->mode = mode;
411 
412  if((rv = SifCallRpc(&cd0, FILEXIO_MKDIR, fileXioBlockMode, sbuff, sizeof(struct fxio_mkdir_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
413  {
414  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
415  else { rv = sbuff[0]; }
416  }
417  else
419 
420  _unlock();
421  return(rv);
422 }
@ FILEXIO_MKDIR
Definition: fileXio.h:62
char pathname[512]
Definition: fileXio.h:142

References _fxio_intr(), _lock(), _unlock(), cd0, ENOPKG, FILEXIO_MKDIR, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, mode, NULL, packet, fxio_mkdir_packet::pathname, sbuff, SifCallRpc(), SignalSema(), and WaitSema().

Referenced by fileXioInit().

◆ fileXioMount()

int fileXioMount ( const char *  mountpoint,
const char *  mountstring,
int  flag 
)

Definition at line 319 of file fileXio_rpc.c.

320 {
321  int rv;
323 
324  if(fileXioInit() < 0)
325  return -ENOPKG;
326 
327  _lock();
329 
330  strncpy(packet->blockdevice, mountstring, sizeof(packet->blockdevice));
331  strncpy(packet->mountpoint, mountpoint, sizeof(packet->mountpoint));
332  packet->flags = flag;
333 
334  if((rv = SifCallRpc(&cd0, FILEXIO_MOUNT, fileXioBlockMode, sbuff, sizeof(struct fxio_mount_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
335  {
336  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
337  else { rv = sbuff[0]; }
338  }
339  else
341 
342  _unlock();
343  return(rv);
344 }
@ FILEXIO_MOUNT
Definition: fileXio.h:37
char mountpoint[512]
Definition: fileXio.h:127

References _fxio_intr(), _lock(), _unlock(), cd0, ENOPKG, FILEXIO_MOUNT, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, fxio_mount_packet::mountpoint, NULL, packet, sbuff, SifCallRpc(), SignalSema(), and WaitSema().

Referenced by hddGetFilesystemList().

◆ fileXioOpen()

int fileXioOpen ( const char *  source,
int  flags,
  ... 
)

Definition at line 581 of file fileXio_rpc.c.

582 {
583  int rv, mode;
585  va_list alist;
586 
587  va_start(alist, flags);
588  mode = va_arg(alist, int); //Retrieve the mode argument, regardless of whether it is expected or not.
589  va_end(alist);
590 
591  if(fileXioInit() < 0)
592  return -ENOPKG;
593 
594  _lock();
596 
597  strncpy(packet->pathname, source, sizeof(packet->pathname));
598  packet->flags = flags;
599  packet->mode = mode;
600  if((rv = SifCallRpc(&cd0, FILEXIO_OPEN, fileXioBlockMode, sbuff, sizeof(struct fxio_open_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
601  {
602  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
603  else { rv = sbuff[0]; }
604  }
605  else
607 
608  _unlock();
609  return(rv);
610 }
@ FILEXIO_OPEN
Definition: fileXio.h:42

References _fxio_intr(), _lock(), _unlock(), cd0, ENOPKG, FILEXIO_OPEN, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), fxio_open_packet::flags, FXIO_NOWAIT, mode, NULL, packet, sbuff, SifCallRpc(), SignalSema(), and WaitSema().

Referenced by fileXioInit(), hddExpandFilesystem(), hddGetFilesystemList(), and hddMakeFilesystem().

◆ fileXioOpendirHelper()

static DIR* fileXioOpendirHelper ( const char *  path)
static

Definition at line 114 of file fileXio_rpc.c.

115 {
116  int dd;
117  DIR *dir;
118 
119  dd = fileXioDopen(path);
120  if (dd < 0) {
121  // FIXME: set errno
122  //printf("%s: ERROR: fileXioDopen\n", __FUNCTION__);
123  return NULL;
124  }
125 
126  dir = malloc(sizeof(DIR));
127  dir->dd_fd = dd;
128  dir->dd_buf = malloc(sizeof(struct dirent));
129 
130  return dir;
131 }
int fileXioDopen(const char *name)
Definition: fileXio_rpc.c:900

References fileXioDopen(), and NULL.

Referenced by fileXioInit().

◆ fileXioRead()

int fileXioRead ( int  fd,
void *  buf,
int  size 
)

Definition at line 647 of file fileXio_rpc.c.

648 {
649  int rv;
651 
652  if(fileXioInit() < 0)
653  return -ENOPKG;
654 
655  _lock();
657 
658  packet->fd = fd;
659  packet->buffer = buf;
660  packet->size = size;
661  packet->intrData = _intr_data;
662 
663  if (!IS_UNCACHED_SEG(buf))
664  SifWriteBackDCache(buf, size);
665 
666  if((rv = SifCallRpc(&cd0, FILEXIO_READ, fileXioBlockMode, sbuff, sizeof(struct fxio_read_packet), sbuff, 4, &recv_intr, _intr_data)) >= 0)
667  {
668  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
669  else { rv = sbuff[0]; }
670  }
671  else
673 
674  _unlock();
675  return(rv);
676 }
@ FILEXIO_READ
Definition: fileXio.h:44
static void recv_intr(void *data_raw)
Definition: fileXio_rpc.c:637

References _intr_data, _lock(), _unlock(), cd0, ENOPKG, fxio_read_packet::fd, FILEXIO_READ, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, IS_UNCACHED_SEG, packet, recv_intr(), sbuff, SifCallRpc(), SifWriteBackDCache(), SignalSema(), fxio_read_packet::size, and WaitSema().

Referenced by fileXioInit().

◆ fileXioReaddirHelper()

static struct dirent* fileXioReaddirHelper ( DIR *  dir)
static

Definition at line 133 of file fileXio_rpc.c.

134 {
135  int rv;
136  struct dirent *de;
137  iox_dirent_t fiode;
138 
139  if(dir == NULL) {
140  // FIXME: set errno
141  return NULL;
142  }
143 
144  de = (struct dirent *)dir->dd_buf;
145  rv = fileXioDread(dir->dd_fd, &fiode);
146  if (rv <= 0) {
147  // FIXME: set errno
148  return NULL;
149  }
150 
151  fill_stat(&de->d_stat, &fiode.stat);
152  strncpy(de->d_name, fiode.name, 255);
153  de->d_name[255] = 0;
154 
155  return de;
156 }
int fileXioDread(int fd, iox_dirent_t *dirent)
Definition: fileXio_rpc.c:948
char name[256]
Definition: iox_stat.h:112
iox_stat_t stat
Definition: iox_stat.h:111

References fileXioDread(), fill_stat(), iox_dirent_t::name, NULL, and iox_dirent_t::stat.

Referenced by fileXioInit().

◆ fileXioReadlink()

int fileXioReadlink ( const char *  source,
char *  buf,
int  buflen 
)

Definition at line 526 of file fileXio_rpc.c.

527 {
528  int rv;
530 
531  if(fileXioInit() < 0)
532  return -ENOPKG;
533 
534  _lock();
536 
537  if( !IS_UNCACHED_SEG(buf))
539 
540  strncpy(packet->source, source, sizeof(packet->source));
541  packet->buffer = buf;
542  packet->buflen = buflen;
543 
544  if((rv = SifCallRpc(&cd0, FILEXIO_READLINK, fileXioBlockMode, sbuff, sizeof(struct fxio_readlink_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
545  {
546  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
547  else { rv = sbuff[0]; }
548  }
549  else
551 
552  _unlock();
553  return(rv);
554 }
@ FILEXIO_READLINK
Definition: fileXio.h:59

References _fxio_intr(), _lock(), _unlock(), fxio_readlink_packet::buflen, cd0, ENOPKG, FILEXIO_READLINK, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, IS_UNCACHED_SEG, NULL, packet, sbuff, SifCallRpc(), SifWriteBackDCache(), SignalSema(), fxio_readlink_packet::source, and WaitSema().

◆ fileXioRemove()

int fileXioRemove ( const char *  pathname)

Definition at line 449 of file fileXio_rpc.c.

450 {
451  int rv;
453 
454  if(fileXioInit() < 0)
455  return -ENOPKG;
456 
457  _lock();
459 
460  strncpy(packet->pathname, pathname, sizeof(packet->pathname));
461 
462  if((rv = SifCallRpc(&cd0, FILEXIO_REMOVE, fileXioBlockMode, sbuff, sizeof(struct fxio_pathsel_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
463  {
464  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
465  else { rv = sbuff[0]; }
466  }
467  else
469 
470  _unlock();
471  return(rv);
472 }
@ FILEXIO_REMOVE
Definition: fileXio.h:63

References _fxio_intr(), _lock(), _unlock(), cd0, ENOPKG, FILEXIO_REMOVE, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, NULL, packet, fxio_pathsel_packet::pathname, sbuff, SifCallRpc(), SignalSema(), and WaitSema().

Referenced by fileXioInit(), and hddRemoveFilesystem().

◆ fileXioRename()

int fileXioRename ( const char *  source,
const char *  dest 
)

Definition at line 474 of file fileXio_rpc.c.

475 {
476  int rv;
478 
479  if(fileXioInit() < 0)
480  return -ENOPKG;
481 
482  _lock();
484 
485  strncpy(packet->source, source, sizeof(packet->source));
486  strncpy(packet->dest, dest, sizeof(packet->dest));
487 
488  if((rv = SifCallRpc(&cd0, FILEXIO_RENAME, fileXioBlockMode, sbuff, sizeof(struct fxio_rename_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
489  {
490  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
491  else { rv = sbuff[0]; }
492  }
493  else
495 
496  _unlock();
497  return(rv);
498 }
@ FILEXIO_RENAME
Definition: fileXio.h:54
char source[512]
Definition: fileXio.h:153
char dest[512]
Definition: fileXio.h:154

References _fxio_intr(), _lock(), _unlock(), cd0, fxio_rename_packet::dest, ENOPKG, FILEXIO_RENAME, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, NULL, packet, sbuff, SifCallRpc(), SignalSema(), fxio_rename_packet::source, and WaitSema().

Referenced by fileXioInit().

◆ fileXioRewinddirHelper()

static void fileXioRewinddirHelper ( DIR *  dir)
static

Definition at line 158 of file fileXio_rpc.c.

159 {
160  printf("rewinddir not implemented\n");
161 }

Referenced by fileXioInit().

◆ fileXioRmdir()

int fileXioRmdir ( const char *  pathname)

Definition at line 424 of file fileXio_rpc.c.

425 {
426  int rv;
428 
429  if(fileXioInit() < 0)
430  return -ENOPKG;
431 
432  _lock();
434 
435  strncpy(packet->pathname, pathname, sizeof(packet->pathname));
436 
437  if((rv = SifCallRpc(&cd0, FILEXIO_RMDIR, fileXioBlockMode, sbuff, sizeof(struct fxio_pathsel_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
438  {
439  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
440  else { rv = sbuff[0]; }
441  }
442  else
444 
445  _unlock();
446  return(rv);
447 }
@ FILEXIO_RMDIR
Definition: fileXio.h:48

References _fxio_intr(), _lock(), _unlock(), cd0, ENOPKG, FILEXIO_RMDIR, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, NULL, packet, fxio_pathsel_packet::pathname, sbuff, SifCallRpc(), SignalSema(), and WaitSema().

Referenced by fileXioInit().

◆ fileXioSetBlockMode()

void fileXioSetBlockMode ( int  blocking)

Definition at line 1132 of file fileXio_rpc.c.

1133 {
1134  fileXioBlockMode = blocking;
1135 }

References fileXioBlockMode.

◆ fileXioSetRWBufferSize()

int fileXioSetRWBufferSize ( int  size)

Definition at line 1137 of file fileXio_rpc.c.

1137  {
1138  struct fxio_rwbuff *packet = (struct fxio_rwbuff *)sbuff;
1139  int rv;
1140 
1141  if(fileXioInit() < 0)
1142  return -ENOPKG;
1143 
1144  _lock();
1146 
1147  packet->size = size;
1148 
1149  if((rv = SifCallRpc(&cd0, FILEXIO_SETRWBUFFSIZE, 0, packet, sizeof(struct fxio_rwbuff), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
1150  {
1151  rv = sbuff[0];
1152  }
1153  else
1155 
1156  _unlock();
1157  return(rv);
1158 }
@ FILEXIO_SETRWBUFFSIZE
Definition: fileXio.h:65
int size
Definition: fileXio.h:267

References _fxio_intr(), _lock(), _unlock(), cd0, ENOPKG, FILEXIO_SETRWBUFFSIZE, fileXioCompletionSema, fileXioInit(), NULL, packet, sbuff, SifCallRpc(), SignalSema(), fxio_rwbuff::size, and WaitSema().

◆ fileXioStop()

void fileXioStop ( void  )

Definition at line 250 of file fileXio_rpc.c.

251 {
252  if(fileXioInit() < 0)
253  return;
254 
255  SifCallRpc(&cd0, FILEXIO_STOP, 0, sbuff, 0, sbuff, 0, 0, 0);
256 
257  return;
258 }
@ FILEXIO_STOP
Definition: fileXio.h:40

References cd0, FILEXIO_STOP, fileXioInit(), sbuff, and SifCallRpc().

◆ fileXioSymlink()

int fileXioSymlink ( const char *  source,
const char *  dest 
)

Definition at line 500 of file fileXio_rpc.c.

501 {
502  int rv;
504 
505  if(fileXioInit() < 0)
506  return -ENOPKG;
507 
508  _lock();
510 
511  strncpy(packet->source, source, sizeof(packet->source));
512  strncpy(packet->dest, dest, sizeof(packet->dest));
513 
514  if((rv = SifCallRpc(&cd0, FILEXIO_SYMLINK, fileXioBlockMode, sbuff, sizeof(struct fxio_rename_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
515  {
516  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
517  else { rv = sbuff[0]; }
518  }
519  else
521 
522  _unlock();
523  return(rv);
524 }
@ FILEXIO_SYMLINK
Definition: fileXio.h:58

References _fxio_intr(), _lock(), _unlock(), cd0, fxio_rename_packet::dest, ENOPKG, FILEXIO_SYMLINK, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, NULL, packet, sbuff, SifCallRpc(), SignalSema(), fxio_rename_packet::source, and WaitSema().

◆ fileXioSync()

int fileXioSync ( const char *  devname,
int  flag 
)

Definition at line 874 of file fileXio_rpc.c.

875 {
876  int rv;
878 
879  if(fileXioInit() < 0)
880  return -ENOPKG;
881 
882  _lock();
884 
885  strncpy(packet->device, devname, sizeof(packet->device));
886  packet->flags = flag;
887 
888  if((rv = SifCallRpc(&cd0, FILEXIO_SYNC, fileXioBlockMode, sbuff, sizeof(struct fxio_sync_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
889  {
890  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
891  else { rv = sbuff[0]; }
892  }
893  else
895 
896  _unlock();
897  return(rv);
898 }
@ FILEXIO_SYNC
Definition: fileXio.h:56

References _fxio_intr(), _lock(), _unlock(), cd0, ENOPKG, FILEXIO_SYNC, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, NULL, packet, sbuff, SifCallRpc(), SignalSema(), and WaitSema().

◆ fileXioUmount()

int fileXioUmount ( const char *  mountpoint)

Definition at line 346 of file fileXio_rpc.c.

347 {
348  int rv;
350 
351  if(fileXioInit() < 0)
352  return -ENOPKG;
353 
354  _lock();
356 
357  strncpy(packet->mountpoint, mountpoint, sizeof(packet->mountpoint));
358 
359  if((rv = SifCallRpc(&cd0, FILEXIO_UMOUNT, fileXioBlockMode, sbuff, sizeof(struct fxio_unmount_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
360  {
361  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
362  else { rv = sbuff[0]; }
363  }
364  else
366 
367  _unlock();
368  return(rv);
369 }
@ FILEXIO_UMOUNT
Definition: fileXio.h:38
char mountpoint[512]
Definition: fileXio.h:132

References _fxio_intr(), _lock(), _unlock(), cd0, ENOPKG, FILEXIO_UMOUNT, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, fxio_unmount_packet::mountpoint, NULL, packet, sbuff, SifCallRpc(), SignalSema(), and WaitSema().

Referenced by hddGetFilesystemList().

◆ fileXioWaitAsync()

int fileXioWaitAsync ( int  mode,
int *  retVal 
)

Definition at line 1096 of file fileXio_rpc.c.

1097 {
1098  if(fileXioInit() < 0)
1099  return -ENOPKG;
1100 
1101  if(fileXioBlockMode != FXIO_NOWAIT) return 0;
1102 
1103  switch(mode)
1104  {
1105  case FXIO_WAIT:
1106 
1109 
1110  if(retVal != NULL)
1111  *retVal = *(int *)UNCACHED_SEG(&sbuff[0]);
1112 
1113  return FXIO_COMPLETE;
1114 
1115  case FXIO_NOWAIT:
1116 
1118  return FXIO_INCOMPLETE;
1119 
1121 
1122  if(retVal != NULL)
1123  *retVal = *(int *)UNCACHED_SEG(&sbuff[0]);
1124 
1125  return FXIO_COMPLETE;
1126 
1127  default:
1128  return -1;
1129  }
1130 }
#define FXIO_COMPLETE
Definition: fileXio_rpc.h:30
#define FXIO_INCOMPLETE
Definition: fileXio_rpc.h:31
s32 PollSema(s32 sema_id)
#define UNCACHED_SEG(x)
Definition: kernel.h:35

References ENOPKG, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_COMPLETE, FXIO_INCOMPLETE, FXIO_NOWAIT, FXIO_WAIT, mode, NULL, PollSema(), sbuff, SignalSema(), UNCACHED_SEG, and WaitSema().

◆ fileXioWrite()

int fileXioWrite ( int  fd,
const void *  buf,
int  size 
)

Definition at line 678 of file fileXio_rpc.c.

679 {
680  unsigned int miss;
681  int rv;
683 
684  if(fileXioInit() < 0)
685  return -ENOPKG;
686 
687  _lock();
689 
690  if((unsigned int)buf & 0x3F)
691  {
692  miss = 64 - ((unsigned int)buf & 0x3F);
693  if(miss > size) miss = size;
694  } else {
695  miss = 0;
696  }
697 
698  packet->fd = fd;
699  packet->buffer = buf;
700  packet->size = size;
701  packet->unalignedDataLen = miss;
702 
703  memcpy(packet->unalignedData, buf, miss);
704 
705  if(!IS_UNCACHED_SEG(buf))
706  SifWriteBackDCache((void*)buf, size);
707 
708  if((rv = SifCallRpc(&cd0, FILEXIO_WRITE, fileXioBlockMode, sbuff, sizeof(struct fxio_write_packet), sbuff, 4, (void *)&_fxio_intr, NULL)) >= 0)
709  {
710  if(fileXioBlockMode == FXIO_NOWAIT) { rv = 0; }
711  else { rv = sbuff[0]; }
712  }
713  else
715 
716  _unlock();
717  return(rv);
718 }
@ FILEXIO_WRITE
Definition: fileXio.h:45

References _fxio_intr(), _lock(), _unlock(), cd0, ENOPKG, fxio_write_packet::fd, FILEXIO_WRITE, fileXioBlockMode, fileXioCompletionSema, fileXioInit(), FXIO_NOWAIT, IS_UNCACHED_SEG, NULL, packet, sbuff, SifCallRpc(), SifWriteBackDCache(), SignalSema(), fxio_write_packet::size, and WaitSema().

Referenced by fileXioInit().

◆ fill_stat()

static void fill_stat ( struct stat *  stat,
const iox_stat_t fiostat 
)
static

Definition at line 84 of file fileXio_rpc.c.

85 {
86  stat->st_dev = 0;
87  stat->st_ino = 0;
88  stat->st_mode = iox_to_posix_mode(fiostat->mode);
89  stat->st_nlink = 0;
90  stat->st_uid = 0;
91  stat->st_gid = 0;
92  stat->st_rdev = 0;
93  stat->st_size = ((off_t)fiostat->hisize << 32) | (off_t)fiostat->size;
94  stat->st_atime = io_to_posix_time(fiostat->atime);
95  stat->st_mtime = io_to_posix_time(fiostat->mtime);
96  stat->st_ctime = io_to_posix_time(fiostat->ctime);
97  stat->st_blksize = 16*1024;
98  stat->st_blocks = stat->st_size / 512;
99 }
static mode_t iox_to_posix_mode(unsigned int ps2mode)
Definition: fileXio_rpc.c:67
static time_t io_to_posix_time(const unsigned char *ps2time)
Definition: fileXio_rpc.c:55
unsigned char ctime[8]
Definition: iox_stat.h:96
unsigned char mtime[8]
Definition: iox_stat.h:98
unsigned int hisize
Definition: iox_stat.h:99
unsigned int size
Definition: iox_stat.h:95
unsigned int mode
Definition: iox_stat.h:93
unsigned char atime[8]
Definition: iox_stat.h:97

References iox_stat_t::atime, iox_stat_t::ctime, iox_stat_t::hisize, io_to_posix_time(), iox_to_posix_mode(), iox_stat_t::mode, iox_stat_t::mtime, and iox_stat_t::size.

Referenced by fileXioGetstatHelper(), and fileXioReaddirHelper().

◆ fxio_ctl_intr()

static void fxio_ctl_intr ( void *  data_raw)
static

Definition at line 977 of file fileXio_rpc.c.

978 {
979  struct fxio_ctl_return_pkt *pkt = UNCACHED_SEG(data_raw);
980 
981  memcpy(pkt->dest, pkt->buf, pkt->len);
982 
984 }
u8 buf[CTL_BUF_SIZE]
Definition: fileXio.h:258

References fxio_ctl_return_pkt::buf, fxio_ctl_return_pkt::dest, fileXioCompletionSema, iSignalSema(), fxio_ctl_return_pkt::len, and UNCACHED_SEG.

Referenced by fileXioDevctl(), and fileXioIoctl2().

◆ io_to_posix_time()

static time_t io_to_posix_time ( const unsigned char *  ps2time)
static

Definition at line 55 of file fileXio_rpc.c.

56 {
57  struct tm tim;
58  tim.tm_sec = ps2time[1];
59  tim.tm_min = ps2time[2];
60  tim.tm_hour = ps2time[3];
61  tim.tm_mday = ps2time[4];
62  tim.tm_mon = ps2time[5] - 1;
63  tim.tm_year = ((u16)ps2time[6] | ((u16)ps2time[7] << 8)) - 1900;
64  return mktime(&tim);
65 }
unsigned short u16
Definition: tamtypes.h:24

Referenced by fill_stat().

◆ iox_to_posix_mode()

static mode_t iox_to_posix_mode ( unsigned int  ps2mode)
static

Definition at line 67 of file fileXio_rpc.c.

68 {
69  mode_t posixmode = 0;
70  if (ps2mode & FIO_S_IFREG) posixmode |= S_IFREG;
71  if (ps2mode & FIO_S_IFDIR) posixmode |= S_IFDIR;
72  if (ps2mode & FIO_S_IRUSR) posixmode |= S_IRUSR;
73  if (ps2mode & FIO_S_IWUSR) posixmode |= S_IWUSR;
74  if (ps2mode & FIO_S_IXUSR) posixmode |= S_IXUSR;
75  if (ps2mode & FIO_S_IRGRP) posixmode |= S_IRGRP;
76  if (ps2mode & FIO_S_IWGRP) posixmode |= S_IWGRP;
77  if (ps2mode & FIO_S_IXGRP) posixmode |= S_IXGRP;
78  if (ps2mode & FIO_S_IROTH) posixmode |= S_IROTH;
79  if (ps2mode & FIO_S_IWOTH) posixmode |= S_IWOTH;
80  if (ps2mode & FIO_S_IXOTH) posixmode |= S_IXOTH;
81  return posixmode;
82 }
#define FIO_S_IXGRP
Definition: iox_stat.h:71
#define FIO_S_IROTH
Definition: iox_stat.h:76
#define FIO_S_IXUSR
Definition: iox_stat.h:62
#define FIO_S_IRGRP
Definition: iox_stat.h:67
#define FIO_S_IXOTH
Definition: iox_stat.h:80
#define FIO_S_IWOTH
Definition: iox_stat.h:78
#define FIO_S_IRUSR
Definition: iox_stat.h:58
#define FIO_S_IWGRP
Definition: iox_stat.h:69
#define FIO_S_IFDIR
Definition: iox_stat.h:45
#define FIO_S_IFREG
Definition: iox_stat.h:43
#define FIO_S_IWUSR
Definition: iox_stat.h:60

References FIO_S_IFDIR, FIO_S_IFREG, FIO_S_IRGRP, FIO_S_IROTH, FIO_S_IRUSR, FIO_S_IWGRP, FIO_S_IWOTH, FIO_S_IWUSR, FIO_S_IXGRP, FIO_S_IXOTH, and FIO_S_IXUSR.

Referenced by fill_stat().

◆ recv_intr()

static void recv_intr ( void *  data_raw)
static

Definition at line 637 of file fileXio_rpc.c.

638 {
639  rests_pkt *rests = UNCACHED_SEG(data_raw);
640 
641  if(rests->ssize) memcpy(rests->sbuf, rests->sbuffer, rests->ssize);
642  if(rests->esize) memcpy(rests->ebuf, rests->ebuffer, rests->esize);
643 
645 }
u8 sbuffer[64]
Definition: fileXio.h:74
void * sbuf
Definition: fileXio.h:72
int ssize
Definition: fileXio.h:70
u8 ebuffer[64]
Definition: fileXio.h:75
void * ebuf
Definition: fileXio.h:73
int esize
Definition: fileXio.h:71

References rests_pkt::ebuf, rests_pkt::ebuffer, rests_pkt::esize, fileXioCompletionSema, iSignalSema(), rests_pkt::sbuf, rests_pkt::sbuffer, rests_pkt::ssize, and UNCACHED_SEG.

Referenced by fileXioRead().

Variable Documentation

◆ _intr_data

int _intr_data[0xC00]
static

Definition at line 34 of file fileXio_rpc.c.

Referenced by fileXioDevctl(), fileXioIoctl2(), and fileXioRead().

◆ _iop_reboot_count

int _iop_reboot_count
extern

Referenced by fileXioInit().

◆ _lock_sema_id

int _lock_sema_id = -1
static

Definition at line 44 of file fileXio_rpc.c.

Referenced by _lock(), _unlock(), fileXioExit(), and fileXioInit().

◆ cd0

◆ fileXioBlockMode

◆ fileXioCompletionSema

◆ fileXioInited

int fileXioInited = 0
static

Definition at line 35 of file fileXio_rpc.c.

Referenced by fileXioExit(), and fileXioInit().

◆ sbuff