35#include "debug_printf.h"
39extern int fsysUnmount(
void);
42#define PACKET_MAXSIZE 4096
47static int ps2netfs_sock = -1;
48static int ps2netfs_active = 0;
50static int ps2netfs_sema;
51static int ps2netfs_pid = 0;
53#define FIOTRAN_MAXSIZE 65535
54static char ps2netfs_fiobuffer[FIOTRAN_MAXSIZE+1];
81 memset(&fd_info_list,0,
sizeof(fd_info_list));
98 while ((
count < FDH_MAX))
100 if (fd_info_list[
count].used == 0)
102 fd_info_list[
count].used = 1;
103 fd_info_list[
count].realfd = fd;
104 fd_info_list[
count].devtype = devtype;
121 fd_info_list[fd].used = 0;
122 fd_info_list[fd].realfd = 0;
123 fd_info_list[fd].devtype = 0;
128#define fdh_get(a) (&fd_info_list[a])
130#define fdh_getused(a) (fd_info_list[a].used)
132#define fdh_getfdtype(a) (fd_info_list[a].devtype)
134#define fdh_getrealfd(a) (fd_info_list[a].realfd)
175 ret = disconnect(ps2netfs_sock);
177 DPRINTF(
"disconnect returned error %d\n", ret);
191 if (ps2netfs_sock > 0)
192 disconnect(ps2netfs_sock);
200static inline int ps2netfs_lwip_send(
int sock,
void *buf,
int len,
int flag)
203 ret = send(sock, buf, len, flag);
206 DPRINTF(
"ps2netfs: lwip_send() error %d\n", ret);
212 DPRINTF(
"ps2netfs: lwip_send() - disconnected\n");
228 len = recv(sock, &buf[bytes - left], left, 0);
230 DPRINTF(
"ps2netfs: recv_bytes error!! (%d)\n",len);
235 DPRINTF(
"ps2netfs: recv_bytes - disconnected\n");
247 ps2netfs_pkt_hdr *hdr;
253 DPRINTF(
"ps2netfs: accept_pkt\n");
255 if (length == 0)
return 0;
257 DPRINTF(
"ps2netfs: accept_pkt recv error\n");
261 if ((
unsigned int)length <
sizeof(ps2netfs_pkt_hdr)) {
262 DPRINTF(
"ps2netfs: XXX: did not receive a full header!!!! "
263 "Fix this! (%d)\n", length);
267 hdr = (ps2netfs_pkt_hdr *)buf;
269 hcmd = ntohl(hdr->cmd);
271 hlen = ntohs(hdr->len);
273 DPRINTF(
"ps2netfs: accept_pkt: got 0x%x , hlen: %d, length: %d\n", hcmd,hlen,length);
275 if ((length > PACKET_MAXSIZE) || (hlen > PACKET_MAXSIZE))
277 DPRINTF(
"ps2netfs: accept_pkt: hlen is too large!! "
278 "(%d,%d can only receive %d)\n", length,hlen, PACKET_MAXSIZE);
284 hlen -
sizeof(ps2netfs_pkt_hdr));
287 DPRINTF(
"ps2netfs: accept recv2 error!!\n");
291 if ((
unsigned int)length < (hlen -
sizeof(ps2netfs_pkt_hdr))) {
292 DPRINTF(
"ps2netfs: Did not receive full packet!!! "
293 "Fix this! (%d)\n", length);
317 ps2netfs_pkt_info_rly *inforly;
324 DPRINTF(
"ps2netfs: info\n");
326 if (len !=
sizeof(ps2netfs_pkt_open_req))
328 DPRINTF(
"ps2netfs: got a broken packet (%d)!\n", len);
331 inforly = (ps2netfs_pkt_info_rly *)&ps2netfs_send_packet[0];
339 inforly->cmd = htonl(PS2NETFS_INFO_RLY);
340 inforly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_info_rly));
341 inforly->retval = htonl(
count);
342 inforly->count = htonl(
count);
344 if (ps2netfs_lwip_send(ps2netfs_sock, inforly,
sizeof(ps2netfs_pkt_info_rly), 0) < 0)
346 DPRINTF(
"ps2netfs: error sending reply!\n");
369 ps2netfs_pkt_open_req *cmd;
370 ps2netfs_pkt_file_rly *openrly;
373 cmd = (ps2netfs_pkt_open_req *)buf;
375 DPRINTF(
"ps2netfs: fstype\n");
377 if (len !=
sizeof(ps2netfs_pkt_open_req))
379 DPRINTF(
"ps2netfs: got a broken packet (%d)!\n", len);
386 openrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
389 openrly->cmd = htonl(PS2NETFS_OPEN_RLY);
390 openrly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_file_rly));
391 openrly->retval = htonl(devtype);
393 if (ps2netfs_lwip_send(ps2netfs_sock, openrly,
sizeof(ps2netfs_pkt_file_rly), 0) < 0)
395 DPRINTF(
"ps2netfs: error sending reply!\n");
418 ps2netfs_pkt_open_req *cmd;
419 ps2netfs_pkt_devlist_rly *devlistrly;
422 cmd = (ps2netfs_pkt_open_req *)buf;
424 DPRINTF(
"ps2netfs: devlist\n");
426 if (len !=
sizeof(ps2netfs_pkt_open_req))
428 DPRINTF(
"ps2netfs: got a broken packet (%d)!\n", len);
431 devlistrly = (ps2netfs_pkt_devlist_rly *)&ps2netfs_send_packet[0];
438 int cnt;
char *ptr = &devlistrly->list[0];
439 for(cnt=0;cnt<(
count-1);cnt++)
442 ptr_len = strlen(ptr);
445 *(ptr+ptr_len) = cmd->path[0];
453 devlistrly->cmd = htonl(PS2NETFS_DEVLIST_RLY);
454 devlistrly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_devlist_rly));
455 devlistrly->retval = htonl(
count);
456 devlistrly->count = htonl(
count);
458 if (ps2netfs_lwip_send(ps2netfs_sock, devlistrly,
sizeof(ps2netfs_pkt_devlist_rly), 0) < 0)
460 DPRINTF(
"ps2netfs: error sending reply!\n");
486 ps2netfs_pkt_open_req *cmd;
487 ps2netfs_pkt_file_rly *openrly;
491 cmd = (ps2netfs_pkt_open_req *)buf;
493 DPRINTF(
"ps2netfs: open\n");
495 if (len !=
sizeof(ps2netfs_pkt_open_req))
497 DPRINTF(
"ps2netfs: got a broken packet (%d)!\n", len);
502 if (devtype != IOPMGR_DEVTYPE_INVALID)
504 if (devtype == IOPMGR_DEVTYPE_IOMAN)
505 retval = io_open(cmd->path,ntohl(cmd->flags));
506 else if (devtype == IOPMGR_DEVTYPE_IOMANX)
507 retval = open(cmd->path,ntohl(cmd->flags),0644);
513 openrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
516 openrly->cmd = htonl(PS2NETFS_OPEN_RLY);
517 openrly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_file_rly));
518 openrly->retval = htonl(retval);
520 if (ps2netfs_lwip_send(ps2netfs_sock, openrly,
sizeof(ps2netfs_pkt_file_rly), 0) < 0)
522 DPRINTF(
"ps2netfs: error sending reply!\n");
547 ps2netfs_pkt_close_req *cmd;
548 ps2netfs_pkt_file_rly *closerly;
551 cmd = (ps2netfs_pkt_close_req *)buf;
553 DPRINTF(
"ps2netfs: close\n");
555 if (len !=
sizeof(ps2netfs_pkt_close_req))
557 DPRINTF(
"ps2netfs: got a broken packet (%d)!\n", len);
562 fdptr =
fdh_get(ntohl(cmd->fd));
565 if (fdptr->devtype == IOPMGR_DEVTYPE_IOMAN)
566 retval = io_close(fdptr->realfd);
567 else if (fdptr->devtype == IOPMGR_DEVTYPE_IOMANX)
568 retval = close(fdptr->realfd);
573 closerly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
576 closerly->cmd = htonl(PS2NETFS_CLOSE_RLY);
577 closerly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_file_rly));
578 closerly->retval = htonl(retval);
580 if (ps2netfs_lwip_send(ps2netfs_sock, closerly,
sizeof(ps2netfs_pkt_file_rly), 0) < 0)
582 DPRINTF(
"ps2netfs: error sending reply!\n");
607 ps2netfs_pkt_read_req *cmd;
608 ps2netfs_pkt_read_rly *readrly;
612 cmd = (ps2netfs_pkt_read_req *)buf;
614 DPRINTF(
"ps2netfs: read\n");
616 if (len !=
sizeof(ps2netfs_pkt_read_req))
618 DPRINTF(
"ps2netfs: got a broken packet (%d)!\n", len);
622 nbytes = ntohl(cmd->nbytes);
623 if (nbytes > FIOTRAN_MAXSIZE) nbytes = FIOTRAN_MAXSIZE;
626 fdptr =
fdh_get(ntohl(cmd->fd));
629 if (fdptr->devtype == IOPMGR_DEVTYPE_IOMAN)
630 retval = io_read(fdptr->realfd,ps2netfs_fiobuffer,nbytes);
631 else if (fdptr->devtype == IOPMGR_DEVTYPE_IOMANX)
632 retval = read(fdptr->realfd,ps2netfs_fiobuffer,nbytes);
636 readrly = (ps2netfs_pkt_read_rly *)&ps2netfs_send_packet[0];
639 readrly->cmd = htonl(PS2NETFS_READ_RLY);
640 readrly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_read_rly));
641 readrly->retval = htonl(retval);
642 readrly->nbytes = readrly->retval;
645 if (ps2netfs_lwip_send(ps2netfs_sock, readrly,
sizeof(ps2netfs_pkt_read_rly), 0) < 0)
647 DPRINTF(
"ps2netfs: error sending reply!\n");
652 if (ps2netfs_lwip_send(ps2netfs_sock, ps2netfs_fiobuffer, ntohl(readrly->retval), 0) < 0)
654 DPRINTF(
"ps2netfs: error sending data!\n");
679 ps2netfs_pkt_write_req *cmd;
680 ps2netfs_pkt_file_rly *writerly;
683 cmd = (ps2netfs_pkt_write_req *)buf;
687 DPRINTF(
"ps2netfs: write\n");
690 fdptr =
fdh_get(ntohl(cmd->fd));
693 int left = ntohl(cmd->nbytes);
695 written = retval = 0;
696 while ((retval >= 0) && (left > 0))
700 towrite = left;
if (towrite > FIOTRAN_MAXSIZE) towrite = FIOTRAN_MAXSIZE;
703 DPRINTF(
"ps2netfs: error reading data!\n");
707 if (fdptr->devtype == IOPMGR_DEVTYPE_IOMAN)
708 retval = io_write(fdptr->realfd,ps2netfs_fiobuffer,towrite);
709 else if (fdptr->devtype == IOPMGR_DEVTYPE_IOMANX)
710 retval = write(fdptr->realfd,ps2netfs_fiobuffer,towrite);
712 if (retval > 0) { written += retval; left -= retval; }
719 writerly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
722 writerly->cmd = htonl(PS2NETFS_WRITE_RLY);
723 writerly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_file_rly));
724 writerly->retval = htonl(retval);
726 if (ps2netfs_lwip_send(ps2netfs_sock, writerly,
sizeof(ps2netfs_pkt_file_rly), 0) < 0)
728 DPRINTF(
"ps2netfs: error sending reply!\n");
753 ps2netfs_pkt_lseek_req *cmd;
754 ps2netfs_pkt_file_rly *lseekrly;
757 cmd = (ps2netfs_pkt_lseek_req *)buf;
759 DPRINTF(
"ps2netfs: lseek\n");
761 if (len !=
sizeof(ps2netfs_pkt_lseek_req))
763 DPRINTF(
"ps2netfs: got a broken packet (%d)!\n", len);
767 fdptr =
fdh_get(ntohl(cmd->fd));
770 if (fdptr->devtype == IOPMGR_DEVTYPE_IOMAN)
771 retval = io_lseek(fdptr->realfd,ntohl(cmd->offset),ntohl(cmd->whence));
772 else if (fdptr->devtype == IOPMGR_DEVTYPE_IOMANX)
773 retval = lseek(fdptr->realfd,ntohl(cmd->offset),ntohl(cmd->whence));
777 lseekrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
780 lseekrly->cmd = htonl(PS2NETFS_LSEEK_RLY);
781 lseekrly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_file_rly));
782 lseekrly->retval = htonl(retval);
784 if (ps2netfs_lwip_send(ps2netfs_sock, lseekrly,
sizeof(ps2netfs_pkt_file_rly), 0) < 0)
786 DPRINTF(
"ps2netfs: error sending reply!\n");
811 ps2netfs_pkt_ioctl_req *cmd;
812 ps2netfs_pkt_ioctl_rly *ioctlrly;
815 cmd = (ps2netfs_pkt_ioctl_req *)buf;
817 DPRINTF(
"ps2netfs: ioctl\n");
819 if (len !=
sizeof(ps2netfs_pkt_ioctl_req))
821 DPRINTF(
"ps2netfs: got a broken packet (%d)!\n", len);
825 ioctlrly = (ps2netfs_pkt_ioctl_rly *)&ps2netfs_send_packet[0];
828 fdptr =
fdh_get(ntohl(cmd->fd));
831 if (fdptr->devtype == IOPMGR_DEVTYPE_IOMAN)
832 retval = io_ioctl(fdptr->realfd,ntohl(cmd->command),(
void *)ioctlrly->buf);
833 else if (fdptr->devtype == IOPMGR_DEVTYPE_IOMANX)
834 retval = ioctl(fdptr->realfd,ntohl(cmd->command),(
void *)ioctlrly->buf);
838 ioctlrly->cmd = htonl(PS2NETFS_IOCTL_RLY);
839 ioctlrly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_ioctl_rly));
840 ioctlrly->retval = htonl(retval);
842 if (ps2netfs_lwip_send(ps2netfs_sock, ioctlrly,
sizeof(ps2netfs_pkt_ioctl_rly), 0) < 0)
844 DPRINTF(
"ps2netfs: error sending reply!\n");
869 ps2netfs_pkt_open_req *cmd;
870 ps2netfs_pkt_file_rly *removerly;
873 cmd = (ps2netfs_pkt_open_req *)buf;
875 DPRINTF(
"ps2netfs: remove\n");
877 if (len !=
sizeof(ps2netfs_pkt_open_req))
879 DPRINTF(
"ps2netfs: got a broken packet (%d)!\n", len);
885 if (devtype != IOPMGR_DEVTYPE_INVALID)
887 if (devtype == IOPMGR_DEVTYPE_IOMAN)
888 retval = io_remove(cmd->path);
889 else if (devtype == IOPMGR_DEVTYPE_IOMANX)
890 retval = remove(cmd->path);
894 removerly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
897 removerly->cmd = htonl(PS2NETFS_REMOVE_RLY);
898 removerly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_file_rly));
899 removerly->retval = htonl(retval);
901 if (ps2netfs_lwip_send(ps2netfs_sock, removerly,
sizeof(ps2netfs_pkt_file_rly), 0) < 0)
903 DPRINTF(
"ps2netfs: error sending reply!\n");
928 ps2netfs_pkt_open_req *cmd;
929 ps2netfs_pkt_file_rly *mkdirrly;
932 cmd = (ps2netfs_pkt_open_req *)buf;
934 DPRINTF(
"ps2netfs: mkdir\n");
936 if (len !=
sizeof(ps2netfs_pkt_open_req))
938 DPRINTF(
"ps2netfs: got a broken packet (%d)!\n", len);
944 if (devtype != IOPMGR_DEVTYPE_INVALID)
946 if (devtype == IOPMGR_DEVTYPE_IOMAN)
947 retval = io_mkdir(cmd->path);
948 else if (devtype == IOPMGR_DEVTYPE_IOMANX)
949 retval = mkdir(cmd->path,0644);
953 mkdirrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
956 mkdirrly->cmd = htonl(PS2NETFS_MKDIR_RLY);
957 mkdirrly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_file_rly));
958 mkdirrly->retval = htonl(retval);
960 if (ps2netfs_lwip_send(ps2netfs_sock, mkdirrly,
sizeof(ps2netfs_pkt_file_rly), 0) < 0)
962 DPRINTF(
"ps2netfs: error sending reply!\n");
987 ps2netfs_pkt_open_req *cmd;
988 ps2netfs_pkt_file_rly *rmdirrly;
991 cmd = (ps2netfs_pkt_open_req *)buf;
993 DPRINTF(
"ps2netfs: remove\n");
995 if (len !=
sizeof(ps2netfs_pkt_open_req))
997 DPRINTF(
"ps2netfs: got a broken packet (%d)!\n", len);
1003 if (devtype != IOPMGR_DEVTYPE_INVALID)
1005 if (devtype == IOPMGR_DEVTYPE_IOMAN)
1006 retval = io_rmdir(cmd->path);
1007 else if (devtype == IOPMGR_DEVTYPE_IOMANX)
1008 retval = rmdir(cmd->path);
1012 rmdirrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
1015 rmdirrly->cmd = htonl(PS2NETFS_RMDIR_RLY);
1016 rmdirrly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_file_rly));
1017 rmdirrly->retval = htonl(retval);
1019 if (ps2netfs_lwip_send(ps2netfs_sock, rmdirrly,
sizeof(ps2netfs_pkt_file_rly), 0) < 0)
1021 DPRINTF(
"ps2netfs: error sending reply!\n");
1046 ps2netfs_pkt_open_req *cmd;
1047 ps2netfs_pkt_file_rly *dopenrly;
1050 cmd = (ps2netfs_pkt_open_req *)buf;
1052 DPRINTF(
"ps2netfs: dopen\n");
1054 if (len !=
sizeof(ps2netfs_pkt_open_req))
1056 DPRINTF(
"ps2netfs: got a broken packet (%d)!\n", len);
1062 if (devtype != IOPMGR_DEVTYPE_INVALID)
1064 if (devtype == IOPMGR_DEVTYPE_IOMAN)
1065 retval = io_dopen(cmd->path,0);
1066 else if (devtype == IOPMGR_DEVTYPE_IOMANX)
1067 retval = dopen(cmd->path);
1073 dopenrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
1076 dopenrly->cmd = htonl(PS2NETFS_DOPEN_RLY);
1077 dopenrly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_file_rly));
1078 dopenrly->retval = htonl(retval);
1080 if (ps2netfs_lwip_send(ps2netfs_sock, dopenrly,
sizeof(ps2netfs_pkt_file_rly), 0) < 0)
1082 DPRINTF(
"ps2netfs: error sending reply!\n");
1107 ps2netfs_pkt_close_req *cmd;
1108 ps2netfs_pkt_file_rly *closerly;
1111 cmd = (ps2netfs_pkt_close_req *)buf;
1113 DPRINTF(
"ps2netfs: dclose\n");
1115 if (len !=
sizeof(ps2netfs_pkt_close_req))
1117 DPRINTF(
"ps2netfs: got a broken packet (%d)!\n", len);
1122 fdptr =
fdh_get(ntohl(cmd->fd));
1125 if (fdptr->devtype == IOPMGR_DEVTYPE_IOMAN)
1126 retval = io_dclose(fdptr->realfd);
1127 else if (fdptr->devtype == IOPMGR_DEVTYPE_IOMANX)
1128 retval = dclose(fdptr->realfd);
1133 closerly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
1136 closerly->cmd = htonl(PS2NETFS_DCLOSE_RLY);
1137 closerly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_file_rly));
1138 closerly->retval = htonl(retval);
1140 if (ps2netfs_lwip_send(ps2netfs_sock, closerly,
sizeof(ps2netfs_pkt_file_rly), 0) < 0)
1142 DPRINTF(
"ps2netfs: error sending reply!\n");
1167 ps2netfs_pkt_dread_req *cmd;
1168 ps2netfs_pkt_dread_rly *dreadrly;
1171 cmd = (ps2netfs_pkt_dread_req *)buf;
1173 DPRINTF(
"ps2netfs: dread\n");
1175 if (len !=
sizeof(ps2netfs_pkt_dread_req))
1177 DPRINTF(
"ps2netfs: got a broken packet (%d)!\n", len);
1182 dreadrly = (ps2netfs_pkt_dread_rly *)&ps2netfs_send_packet[0];
1183 memset(dreadrly,0,
sizeof(ps2netfs_pkt_dread_rly));
1186 fdptr =
fdh_get(ntohl(cmd->fd));
1189 if (fdptr->devtype == IOPMGR_DEVTYPE_IOMAN)
1192 retval = io_dread(fdptr->realfd,&dirent);
1196 dreadrly->attr = htonl(dirent.stat.attr);
1197 dreadrly->size = htonl(dirent.stat.size);
1198 dreadrly->hisize = htonl(0);
1199 memcpy(dreadrly->ctime,dirent.stat.ctime,8);
1200 memcpy(dreadrly->atime,dirent.stat.atime,8);
1201 memcpy(dreadrly->mtime,dirent.stat.mtime,8);
1202 strncpy(dreadrly->name,dirent.name,255);
1203 dreadrly->name[255] =
'\0';
1206 else if (fdptr->devtype == IOPMGR_DEVTYPE_IOMANX)
1209 retval = dread(fdptr->realfd,&dirent);
1212 dreadrly->mode = htonl(dirent.stat.mode);
1213 dreadrly->attr = htonl(dirent.stat.attr);
1214 dreadrly->size = htonl(dirent.stat.size);
1215 dreadrly->hisize = htonl(0);
1216 memcpy(dreadrly->ctime,dirent.stat.ctime,8);
1217 memcpy(dreadrly->atime,dirent.stat.atime,8);
1218 memcpy(dreadrly->mtime,dirent.stat.mtime,8);
1219 strncpy(dreadrly->name,dirent.name,255);
1220 dreadrly->name[255] =
'\0';
1224 DPRINTF(
"ps2netfs: dread '%s' %u\n",dreadrly->name,dreadrly->size);
1226 dreadrly->cmd = htonl(PS2NETFS_DREAD_RLY);
1227 dreadrly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_dread_rly));
1228 dreadrly->retval = htonl(retval);
1230 if (ps2netfs_lwip_send(ps2netfs_sock, dreadrly,
sizeof(ps2netfs_pkt_dread_rly), 0) < 0)
1232 DPRINTF(
"ps2netfs: error sending reply!\n");
1308#define PFS_ZONE_SIZE 8192
1309#define PFS_FRAGMENT 0x00000000
1310static int ps2netfs_op_format(
char *buf,
int len)
1312 ps2netfs_pkt_format_req *cmd;
1313 ps2netfs_pkt_file_rly *formatrly;
1317 cmd = (ps2netfs_pkt_format_req *)buf;
1319 DPRINTF(
"ps2netfs: format\n");
1321 if (len !=
sizeof(ps2netfs_pkt_format_req))
1323 DPRINTF(
"ps2netfs: got a broken packet (%d)!\n", len);
1328 if (devtype == IOPMGR_DEVTYPE_IOMANX)
1330 if (ntohl(cmd->arglen) == 0)
1333 retval = format(cmd->dev,cmd->blockdev,(
char*)&Arg,
sizeof(Arg));
1335 else retval = format(cmd->dev,cmd->blockdev,cmd->arg,ntohl(cmd->arglen));
1339 formatrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
1342 formatrly->cmd = htonl(PS2NETFS_FORMAT_RLY);
1343 formatrly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_file_rly));
1344 formatrly->retval = htonl(retval);
1346 if (ps2netfs_lwip_send(ps2netfs_sock, formatrly,
sizeof(ps2netfs_pkt_file_rly), 0) < 0)
1348 DPRINTF(
"ps2netfs: error sending reply!\n");
1375 ps2netfs_pkt_symlink_req *cmd;
1376 ps2netfs_pkt_file_rly *renamerly;
1379 cmd = (ps2netfs_pkt_symlink_req *)buf;
1381 DPRINTF(
"ps2netfs: rename\n");
1383 if (len !=
sizeof(ps2netfs_pkt_symlink_req))
1385 DPRINTF(
"ps2netfs: got a broken packet (%d)!\n", len);
1391 if (devtype == IOPMGR_DEVTYPE_IOMANX)
1394 if (devtype == IOPMGR_DEVTYPE_IOMANX)
1395 retval = rename(cmd->oldpath,cmd->newpath);
1399 renamerly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
1402 renamerly->cmd = htonl(PS2NETFS_SYMLINK_RLY);
1403 renamerly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_file_rly));
1404 renamerly->retval = htonl(retval);
1406 if (ps2netfs_lwip_send(ps2netfs_sock, renamerly,
sizeof(ps2netfs_pkt_file_rly), 0) < 0)
1408 DPRINTF(
"ps2netfs: error sending reply!\n");
1433 ps2netfs_pkt_open_req *cmd;
1434 ps2netfs_pkt_file_rly *chdirrly;
1437 cmd = (ps2netfs_pkt_open_req *)buf;
1439 DPRINTF(
"ps2netfs: chdir\n");
1441 if (len !=
sizeof(ps2netfs_pkt_open_req))
1443 DPRINTF(
"ps2netfs: got a broken packet (%d)!\n", len);
1449 if (devtype == IOPMGR_DEVTYPE_IOMANX)
1450 retval = chdir(cmd->path);
1453 chdirrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
1456 chdirrly->cmd = htonl(PS2NETFS_CHDIR_RLY);
1457 chdirrly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_file_rly));
1458 chdirrly->retval = htonl(retval);
1460 if (ps2netfs_lwip_send(ps2netfs_sock, chdirrly,
sizeof(ps2netfs_pkt_file_rly), 0) < 0)
1462 DPRINTF(
"ps2netfs: error sending reply!\n");
1487 ps2netfs_pkt_open_req *cmd;
1488 ps2netfs_pkt_file_rly *syncrly;
1491 cmd = (ps2netfs_pkt_open_req *)buf;
1493 DPRINTF(
"ps2netfs: sync\n");
1495 if (len !=
sizeof(ps2netfs_pkt_open_req))
1497 DPRINTF(
"ps2netfs: got a broken packet (%d)!\n", len);
1503 if (devtype == IOPMGR_DEVTYPE_IOMANX)
1504 retval = sync(cmd->path,ntohl(cmd->flags));
1507 syncrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
1510 syncrly->cmd = htonl(PS2NETFS_SYNC_RLY);
1511 syncrly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_file_rly));
1512 syncrly->retval = htonl(retval);
1514 if (ps2netfs_lwip_send(ps2netfs_sock, syncrly,
sizeof(ps2netfs_pkt_file_rly), 0) < 0)
1516 DPRINTF(
"ps2netfs: error sending reply!\n");
1541 ps2netfs_pkt_mount_req *cmd;
1542 ps2netfs_pkt_file_rly *mountrly;
1545 cmd = (ps2netfs_pkt_mount_req *)buf;
1547 DPRINTF(
"ps2netfs: mount\n");
1549 if (len !=
sizeof(ps2netfs_pkt_mount_req))
1551 DPRINTF(
"ps2netfs: got a broken packet (%d)!\n", len);
1557 if (devtype == IOPMGR_DEVTYPE_IOMANX)
1558 retval = mount(cmd->fsname,cmd->devname,ntohl(cmd->flag),cmd->arg,ntohl(cmd->arglen));
1561 mountrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
1564 mountrly->cmd = htonl(PS2NETFS_MOUNT_RLY);
1565 mountrly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_file_rly));
1566 mountrly->retval = htonl(retval);
1568 if (ps2netfs_lwip_send(ps2netfs_sock, mountrly,
sizeof(ps2netfs_pkt_file_rly), 0) < 0)
1570 DPRINTF(
"ps2netfs: error sending reply!\n");
1595 ps2netfs_pkt_open_req *cmd;
1596 ps2netfs_pkt_file_rly *umountrly;
1599 cmd = (ps2netfs_pkt_open_req *)buf;
1601 DPRINTF(
"ps2netfs: umount\n");
1603 if (len !=
sizeof(ps2netfs_pkt_open_req))
1605 DPRINTF(
"ps2netfs: got a broken packet (%d)!\n", len);
1611 if (devtype == IOPMGR_DEVTYPE_IOMANX)
1612 retval = umount(cmd->path);
1615 umountrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
1618 umountrly->cmd = htonl(PS2NETFS_UMOUNT_RLY);
1619 umountrly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_file_rly));
1620 umountrly->retval = htonl(retval);
1622 if (ps2netfs_lwip_send(ps2netfs_sock, umountrly,
sizeof(ps2netfs_pkt_file_rly), 0) < 0)
1624 DPRINTF(
"ps2netfs: error sending reply!\n");
1697 ps2netfs_pkt_symlink_req *cmd;
1698 ps2netfs_pkt_file_rly *symlinkrly;
1701 cmd = (ps2netfs_pkt_symlink_req *)buf;
1703 DPRINTF(
"ps2netfs: symlink\n");
1705 if (len !=
sizeof(ps2netfs_pkt_symlink_req))
1707 DPRINTF(
"ps2netfs: got a broken packet (%d)!\n", len);
1713 if (devtype == IOPMGR_DEVTYPE_IOMANX)
1716 if (devtype == IOPMGR_DEVTYPE_IOMANX)
1717 retval = symlink(cmd->oldpath,cmd->newpath);
1721 symlinkrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
1724 symlinkrly->cmd = htonl(PS2NETFS_SYMLINK_RLY);
1725 symlinkrly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_file_rly));
1726 symlinkrly->retval = htonl(retval);
1728 if (ps2netfs_lwip_send(ps2netfs_sock, symlinkrly,
sizeof(ps2netfs_pkt_file_rly), 0) < 0)
1730 DPRINTF(
"ps2netfs: error sending reply!\n");
1755 ps2netfs_pkt_open_req *cmd;
1756 ps2netfs_pkt_readlink_rly *readlinkrly;
1759 cmd = (ps2netfs_pkt_open_req *)buf;
1761 DPRINTF(
"ps2netfs: readlink\n");
1763 if (len !=
sizeof(ps2netfs_pkt_open_req))
1765 DPRINTF(
"ps2netfs: got a broken packet (%d)!\n", len);
1770 readlinkrly = (ps2netfs_pkt_readlink_rly *)&ps2netfs_send_packet[0];
1774 if (devtype == IOPMGR_DEVTYPE_IOMANX)
1775 retval = readlink(cmd->path,readlinkrly->path,cmd->flags);
1779 readlinkrly->cmd = htonl(PS2NETFS_READLINK_RLY);
1780 readlinkrly->len = htons((
unsigned short)
sizeof(ps2netfs_pkt_readlink_rly));
1781 readlinkrly->retval = htonl(retval);
1783 if (ps2netfs_lwip_send(ps2netfs_sock, readlinkrly,
sizeof(ps2netfs_pkt_readlink_rly), 0) < 0)
1785 DPRINTF(
"ps2netfs: error sending reply!\n");
1828 ps2netfs_pkt_hdr *header;
1837 DPRINTF(
"ps2netfs: received packet (%d)\n", len);
1840 DPRINTF(
"ps2netfs_Listener: recvfrom error (%d)\n", len);
1843 if ((
unsigned int)len >=
sizeof(ps2netfs_pkt_hdr))
1845 header = (ps2netfs_pkt_hdr *)ps2netfs_recv_packet;
1846 cmd = ntohl(header->cmd);
1849 case PS2NETFS_OPEN_CMD:
1852 case PS2NETFS_CLOSE_CMD:
1855 case PS2NETFS_READ_CMD:
1858 case PS2NETFS_WRITE_CMD:
1861 case PS2NETFS_LSEEK_CMD:
1864 case PS2NETFS_IOCTL_CMD:
1867 case PS2NETFS_REMOVE_CMD:
1870 case PS2NETFS_MKDIR_CMD:
1873 case PS2NETFS_RMDIR_CMD:
1876 case PS2NETFS_DOPEN_CMD:
1879 case PS2NETFS_DCLOSE_CMD:
1882 case PS2NETFS_DREAD_CMD:
1885 case PS2NETFS_GETSTAT_CMD:
1888 case PS2NETFS_CHSTAT_CMD:
1891 case PS2NETFS_FORMAT_CMD:
1892 retval = ps2netfs_op_format(ps2netfs_recv_packet, len);
1894 case PS2NETFS_RENAME_CMD:
1897 case PS2NETFS_CHDIR_CMD:
1900 case PS2NETFS_SYNC_CMD:
1903 case PS2NETFS_MOUNT_CMD:
1906 case PS2NETFS_UMOUNT_CMD:
1909 case PS2NETFS_LSEEK64_CMD:
1912 case PS2NETFS_DEVCTL_CMD:
1915 case PS2NETFS_SYMLINK_CMD:
1918 case PS2NETFS_READLINK_CMD:
1921 case PS2NETFS_IOCTL2_CMD:
1925 case PS2NETFS_INFO_CMD:
1928 case PS2NETFS_FSTYPE_CMD:
1931 case PS2NETFS_DEVLIST_CMD:
1936 DPRINTF(
"ps2netfs: Unknown cmd received\n");
1945 DPRINTF(
"ps2netfs: packet too small (%d)\n", len);
1948 DPRINTF(
"ps2netfs: waiting for next pkt\n");
1977 DPRINTF(
" - ps2netfs TCP Server -\n");
1982 memset((
void *)&server_addr, 0,
sizeof(server_addr));
1984 server_addr.sin_family = AF_INET;
1985 server_addr.sin_addr.s_addr = htonl(
INADDR_ANY);
1986 server_addr.sin_port = htons(PS2NETFS_LISTEN_PORT);
1988 while ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
1990 DPRINTF(
"ps2netfs: socket creation error (%d)\n", sock);
1994 ret = bind(sock, (
struct sockaddr *)&server_addr,
1995 sizeof(server_addr));
1998 DPRINTF(
"ps2netfs: bind error (%d)\n", ret);
2003 ret = listen(sock, 5);
2007 DPRINTF(
"ps2netfs: listen error (%d)\n", ret);
2014 ps2netfs_active = 1;
2017 while(ps2netfs_active)
2022 DPRINTF(
"ps2netfs: Waiting for connection\n");
2024 client_len =
sizeof(client_addr);
2025 client_sock = accept(sock, (
struct sockaddr *)&client_addr,
2027 if (client_sock < 0)
2029 DPRINTF(
"ps2netfs: accept error (%d)", client_sock);
2033 DPRINTF(
"Client connected from %x\n",
2034 client_addr.sin_addr.s_addr);
2036 if (ps2netfs_sock > 0)
2038 DPRINTF(
"ps2netfs: Client reconnected\n");
2040 DPRINTF(
"ps2netfs: close ret %d\n", ret);
2043 ps2netfs_sock = client_sock;
2045 if (ps2netfs_sock > 0)
2049 DPRINTF(
"ps2netfs: close2 ret %d\n", ret);
2054 if (ps2netfs_sock > 0)
2055 disconnect(ps2netfs_sock);
2075 DPRINTF(
"initializing ps2netfs\n");
2079 mythread.attr = 0x02000000;
2080 mythread.option = 0;
2082 mythread.stacksize = 0x800;
2083 mythread.priority = 0x43;
2085 pid = CreateThread(&mythread);
2091 if ((i=StartThread(pid, NULL)) < 0)
2093 DPRINTF(
"StartThread failed (%d)\n", i);
2099 DPRINTF(
"CreateThread failed (%d)\n", pid);
2104 DPRINTF(
"Thread id: %x\n", pid);
2116 WaitSema(ps2netfs_sema);
2118 SignalSema(ps2netfs_sema);
2119 DeleteSema(ps2netfs_sema);
int realfd(iop_io_file_t *f)
static int ps2netfs_op_sync(char *buf, int len)
static void ps2netfs_Listener(int sock)
static int ps2netfs_op_fstype(char *buf, int len)
int ps2netfs_serv(void *argv)
void ps2netfs_close_fsys(void)
static int ps2netfs_op_chdir(char *buf, int len)
static int ps2netfs_op_open(char *buf, int len)
static int ps2netfs_op_devctl(char *buf, int len)
static int convmode_from_iomanx(int stat)
static int ps2netfs_op_read(char *buf, int len)
static int ps2netfs_op_ioctl2(char *buf, int len)
static int ps2netfs_op_lseek64(char *buf, int len)
static int ps2netfs_op_umount(char *buf, int len)
int devscan_gettype(char *name)
static int ps2netfs_op_readlink(char *buf, int len)
static int ps2netfs_op_dopen(char *buf, int len)
int devscan_setup(int devtype)
static int ps2netfs_op_mkdir(char *buf, int len)
static int ps2netfs_op_mount(char *buf, int len)
static int ps2netfs_op_close(char *buf, int len)
static int fdh_getfd(int devtype, int fd)
static int ps2netfs_op_dread(char *buf, int len)
static int convmode_to_iomanx(int stat)
static int ps2netfs_op_write(char *buf, int len)
static int ps2netfs_op_lseek(char *buf, int len)
static int ps2netfs_op_chstat(char *buf, int len)
static int ps2netfs_op_rmdir(char *buf, int len)
static int ps2netfs_op_remove(char *buf, int len)
static int ps2netfs_op_info(char *buf, int len)
static int ps2netfs_op_dclose(char *buf, int len)
int devscan_getdevlist(char *buffer)
static int ps2netfs_op_rename(char *buf, int len)
static int ps2netfs_op_symlink(char *buf, int len)
static void fdh_freefd(int fd)
static int ps2netfs_op_devlist(char *buf, int len)
int ps2netfs_close_socket(void)
static int ps2netfs_op_getstat(char *buf, int len)
static int ps2netfs_op_ioctl(char *buf, int len)
int ps2netfs_accept_pktunknown(int sock, char *buf)
int ps2netfs_recv_bytes(int sock, char *buf, int bytes)
u32 count
start sector of fragmented bd/file