PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
ps2_fio.c
Go to the documentation of this file.
1/*
2# _____ ___ ____ ___ ____
3# ____| | ____| | | |____|
4# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5#-----------------------------------------------------------------------
6# Copyright 2001-2004, ps2dev - http://www.ps2dev.org
7# Licenced under Academic Free License version 2.0
8# Review ps2sdk README & LICENSE files for further details.
9*/
10
16#include <types.h>
17#include <defs.h>
18#include <irx.h>
19
20#include <loadcore.h>
21#include <ioman_mod.h>
22#include <iomanX.h>
23#include <thbase.h>
24#include <thsemap.h>
25#include <stdio.h>
26#include <sysclib.h>
27#include <errno.h>
28#include <ps2ip.h>
29#include <iopmgr.h>
30
31#include "ps2_fio.h"
32#include "ps2fs.h"
33#include "byteorder.h"
34#include "devscan.h"
35#include "debug_printf.h"
36
38// How about a header file?..
39extern int fsysUnmount(void);
40
42#define PACKET_MAXSIZE 4096
43
44static char ps2netfs_send_packet[PACKET_MAXSIZE] __attribute__((aligned(16)));
45static char ps2netfs_recv_packet[PACKET_MAXSIZE] __attribute__((aligned(16)));
46
47static int ps2netfs_sock = -1;
48static int ps2netfs_active = 0;
49
50static int ps2netfs_sema;
51static int ps2netfs_pid = 0;
52
53#define FIOTRAN_MAXSIZE 65535
54static char ps2netfs_fiobuffer[FIOTRAN_MAXSIZE+1];
55
57
63typedef struct {
64 int used;
65 int realfd;
66 int devtype;
68
69#define FDH_MAX 50
70static fd_table_t fd_info_list[FDH_MAX+1]; /* one for padding */
71
79static inline void fdh_setup()
80{
81 memset(&fd_info_list,0,sizeof(fd_info_list));
82}
83
95static inline int fdh_getfd(int devtype,int fd)
96{
97 int count = 1;
98 while ((count < FDH_MAX))
99 {
100 if (fd_info_list[count].used == 0)
101 {
102 fd_info_list[count].used = 1;
103 fd_info_list[count].realfd = fd;
104 fd_info_list[count].devtype = devtype;
105 return count;
106 }
107 count++;
108 }
109 return -1;
110}
111
117static inline void fdh_freefd(int fd)
118{
119 if (fd < FDH_MAX)
120 {
121 fd_info_list[fd].used = 0;
122 fd_info_list[fd].realfd = 0;
123 fd_info_list[fd].devtype = 0;
124 }
125}
126
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)
135
136
140static inline int convmode_to_iomanx(int stat)
141{
142 int mode = 0;
143
144 if (FIO_SO_ISLNK(stat)) mode |= FIO_S_IFLNK; // Symbolic link
145 if (FIO_SO_ISREG(stat)) mode |= FIO_S_IFREG; // regular file
146 if (FIO_SO_ISDIR(stat)) mode |= FIO_S_IFDIR; // directory
147
148 if (((stat) & FIO_SO_IROTH) == FIO_SO_IROTH) // read
150 if (((stat) & FIO_SO_IWOTH) == FIO_SO_IWOTH) // write
152 if (((stat) & FIO_SO_IXOTH) == FIO_SO_IXOTH) // execute
154
155 return mode;
156}
157
161static inline int convmode_from_iomanx(int stat)
162{
163 return stat;
164}
165
172{
173 int ret;
174
175 ret = disconnect(ps2netfs_sock);
176 if (ret < 0)
177 DPRINTF("disconnect returned error %d\n", ret);
178 ps2netfs_sock = -1;
179 return ret;
180}
181
190{
191 if (ps2netfs_sock > 0)
192 disconnect(ps2netfs_sock);
193 ps2netfs_active = 0;
194 return;
195}
196
197//----------------------------------------------------------------------
198// XXX: Hm, this func should behave sorta like pko_recv_bytes imho..
199// i.e. check if it was able to send just a part of the packet etc..
200static inline int ps2netfs_lwip_send(int sock, void *buf, int len, int flag)
201{
202 int ret;
203 ret = send(sock, buf, len, flag);
204 if (ret < 0)
205 {
206 DPRINTF("ps2netfs: lwip_send() error %d\n", ret);
208 return -1;
209 }
210 else if (len == 0)
211 { // send is blocking, so 0 means error
212 DPRINTF("ps2netfs: lwip_send() - disconnected\n");
213 return -2;
214 }
215 else return ret;
216}
217
219int ps2netfs_recv_bytes(int sock, char *buf, int bytes)
220{
221 int left;
222
223 left = bytes;
224
225 while (left > 0) {
226 int len;
227
228 len = recv(sock, &buf[bytes - left], left, 0);
229 if (len < 0) {
230 DPRINTF("ps2netfs: recv_bytes error!! (%d)\n",len);
231 return -1;
232 }
233 if (len == 0)
234 { // recv is blocking, so 0 means error
235 DPRINTF("ps2netfs: recv_bytes - disconnected\n");
236 return -2;
237 }
238 left -= len;
239 }
240 return bytes;
241}
242
244int ps2netfs_accept_pktunknown(int sock, char *buf)
245{
246 int length;
247 ps2netfs_pkt_hdr *hdr;
248#ifdef DEBUG
249 unsigned int hcmd;
250#endif
251 unsigned short hlen;
252
253 DPRINTF("ps2netfs: accept_pkt\n");
254 length = ps2netfs_recv_bytes(sock, buf, sizeof(ps2netfs_pkt_hdr));
255 if (length == 0) return 0;
256 if (length < 0) {
257 DPRINTF("ps2netfs: accept_pkt recv error\n");
258 return -1;
259 }
260
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);
264 return -1;
265 }
266
267 hdr = (ps2netfs_pkt_hdr *)buf;
268#ifdef DEBUG
269 hcmd = ntohl(hdr->cmd);
270#endif
271 hlen = ntohs(hdr->len);
272
273 DPRINTF("ps2netfs: accept_pkt: got 0x%x , hlen: %d, length: %d\n", hcmd,hlen,length);
274
275 if ((length > PACKET_MAXSIZE) || (hlen > PACKET_MAXSIZE))
276 {
277 DPRINTF("ps2netfs: accept_pkt: hlen is too large!! "
278 "(%d,%d can only receive %d)\n", length,hlen, PACKET_MAXSIZE);
279 return -1;
280 }
281
282 // get the actual packet data
283 length = ps2netfs_recv_bytes(sock, buf + sizeof(ps2netfs_pkt_hdr),
284 hlen - sizeof(ps2netfs_pkt_hdr));
285
286 if (length < 0) {
287 DPRINTF("ps2netfs: accept recv2 error!!\n");
288 return -1;
289 }
290
291 if ((unsigned int)length < (hlen - sizeof(ps2netfs_pkt_hdr))) {
292 DPRINTF("ps2netfs: Did not receive full packet!!! "
293 "Fix this! (%d)\n", length);
294 }
295
296 return hlen;
297}
298
314static int ps2netfs_op_info(char *buf, int len)
315{
316// ps2netfs_pkt_open_req *cmd;
317 ps2netfs_pkt_info_rly *inforly;
318 int count;
319
320 (void)buf;
321
322// cmd = (ps2netfs_pkt_open_req *)buf;
323
324 DPRINTF("ps2netfs: info\n");
325
326 if (len != sizeof(ps2netfs_pkt_open_req))
327 {
328 DPRINTF("ps2netfs: got a broken packet (%d)!\n", len);
329 return -1;
330 }
331 inforly = (ps2netfs_pkt_info_rly *)&ps2netfs_send_packet[0];
332
333 // do the stuff here
334 count = 0;
335
336 // now build the response
337
338 // Build packet
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);
343
344 if (ps2netfs_lwip_send(ps2netfs_sock, inforly, sizeof(ps2netfs_pkt_info_rly), 0) < 0)
345 {
346 DPRINTF("ps2netfs: error sending reply!\n");
347 return -1;
348 }
349 return 0;
350}
351
367static int ps2netfs_op_fstype(char *buf, int len)
368{
369 ps2netfs_pkt_open_req *cmd;
370 ps2netfs_pkt_file_rly *openrly;
371 int devtype = -1;
372
373 cmd = (ps2netfs_pkt_open_req *)buf;
374
375 DPRINTF("ps2netfs: fstype\n");
376
377 if (len != sizeof(ps2netfs_pkt_open_req))
378 {
379 DPRINTF("ps2netfs: got a broken packet (%d)!\n", len);
380 return -1;
381 }
382 // do the stuff here
383 devtype = devscan_gettype(cmd->path);
384
385 // now build the response
386 openrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
387
388 // Build packet
389 openrly->cmd = htonl(PS2NETFS_OPEN_RLY);
390 openrly->len = htons((unsigned short)sizeof(ps2netfs_pkt_file_rly));
391 openrly->retval = htonl(devtype);
392
393 if (ps2netfs_lwip_send(ps2netfs_sock, openrly, sizeof(ps2netfs_pkt_file_rly), 0) < 0)
394 {
395 DPRINTF("ps2netfs: error sending reply!\n");
396 return -1;
397 }
398 return 0;
399}
400
416static int ps2netfs_op_devlist(char *buf, int len)
417{
418 ps2netfs_pkt_open_req *cmd;
419 ps2netfs_pkt_devlist_rly *devlistrly;
420 int count;
421
422 cmd = (ps2netfs_pkt_open_req *)buf;
423
424 DPRINTF("ps2netfs: devlist\n");
425
426 if (len != sizeof(ps2netfs_pkt_open_req))
427 {
428 DPRINTF("ps2netfs: got a broken packet (%d)!\n", len);
429 return -1;
430 }
431 devlistrly = (ps2netfs_pkt_devlist_rly *)&ps2netfs_send_packet[0];
432
433 // do the stuff here
434 count = devscan_getdevlist(devlistrly->list);
435
436 // first char of the path passed in is the delimiter
437 { // so fudge in the delimiters
438 int cnt; char *ptr = &devlistrly->list[0];
439 for(cnt=0;cnt<(count-1);cnt++)
440 {
441 int ptr_len;
442 ptr_len = strlen(ptr);
443 // ok, got a string, so replace the final 0, with delimiter
444 // move onto next string
445 *(ptr+ptr_len) = cmd->path[0];
446 ptr += ptr_len + 1;
447 }
448 }
449
450 // now build the response
451
452 // Build packet
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);
457
458 if (ps2netfs_lwip_send(ps2netfs_sock, devlistrly, sizeof(ps2netfs_pkt_devlist_rly), 0) < 0)
459 {
460 DPRINTF("ps2netfs: error sending reply!\n");
461 return -1;
462 }
463 return 0;
464}
465
466
483// int open(const char *name, int flags, ...);
484static int ps2netfs_op_open(char *buf, int len)
485{
486 ps2netfs_pkt_open_req *cmd;
487 ps2netfs_pkt_file_rly *openrly;
488 int retval = -ENODEV;
489 int devtype = 0;
490
491 cmd = (ps2netfs_pkt_open_req *)buf;
492
493 DPRINTF("ps2netfs: open\n");
494
495 if (len != sizeof(ps2netfs_pkt_open_req))
496 {
497 DPRINTF("ps2netfs: got a broken packet (%d)!\n", len);
498 return -1;
499 }
500 // do the stuff here
501 devtype = devscan_gettype(cmd->path);
502 if (devtype != IOPMGR_DEVTYPE_INVALID)
503 {
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);
508 if (retval > 0)
509 retval = fdh_getfd(devtype,retval);
510 }
511
512 // now build the response
513 openrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
514
515 // Build packet
516 openrly->cmd = htonl(PS2NETFS_OPEN_RLY);
517 openrly->len = htons((unsigned short)sizeof(ps2netfs_pkt_file_rly));
518 openrly->retval = htonl(retval);
519
520 if (ps2netfs_lwip_send(ps2netfs_sock, openrly, sizeof(ps2netfs_pkt_file_rly), 0) < 0)
521 {
522 DPRINTF("ps2netfs: error sending reply!\n");
523 return -1;
524 }
525 return 0;
526}
527
544// int close(int fd);
545static int ps2netfs_op_close(char *buf, int len)
546{
547 ps2netfs_pkt_close_req *cmd;
548 ps2netfs_pkt_file_rly *closerly;
549 int retval = -1;
550 fd_table_t *fdptr;
551 cmd = (ps2netfs_pkt_close_req *)buf;
552
553 DPRINTF("ps2netfs: close\n");
554
555 if (len != sizeof(ps2netfs_pkt_close_req))
556 {
557 DPRINTF("ps2netfs: got a broken packet (%d)!\n", len);
558 return -1;
559 }
560
561 // do the stuff here
562 fdptr = fdh_get(ntohl(cmd->fd));
563 if (fdptr != 0)
564 {
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);
569 fdh_freefd(ntohl(cmd->fd));
570 }
571
572 // now build the response
573 closerly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
574
575 // Build packet
576 closerly->cmd = htonl(PS2NETFS_CLOSE_RLY);
577 closerly->len = htons((unsigned short)sizeof(ps2netfs_pkt_file_rly));
578 closerly->retval = htonl(retval);
579
580 if (ps2netfs_lwip_send(ps2netfs_sock, closerly, sizeof(ps2netfs_pkt_file_rly), 0) < 0)
581 {
582 DPRINTF("ps2netfs: error sending reply!\n");
583 return -1;
584 }
585 return 0;
586}
587
604// int read(int fd, void *ptr, size_t size);
605static int ps2netfs_op_read(char *buf, int len)
606{
607 ps2netfs_pkt_read_req *cmd;
608 ps2netfs_pkt_read_rly *readrly;
609 int retval = -1;
610 int nbytes;
611 fd_table_t *fdptr;
612 cmd = (ps2netfs_pkt_read_req *)buf;
613
614 DPRINTF("ps2netfs: read\n");
615
616 if (len != sizeof(ps2netfs_pkt_read_req))
617 {
618 DPRINTF("ps2netfs: got a broken packet (%d)!\n", len);
619 return -1;
620 }
621 // limit read request to 64k
622 nbytes = ntohl(cmd->nbytes);
623 if (nbytes > FIOTRAN_MAXSIZE) nbytes = FIOTRAN_MAXSIZE;
624
625 // do the stuff here
626 fdptr = fdh_get(ntohl(cmd->fd));
627 if (fdptr != 0)
628 {
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);
633 }
634
635 // now build the response
636 readrly = (ps2netfs_pkt_read_rly *)&ps2netfs_send_packet[0];
637
638 // Build packet
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;
643
644 // send the response
645 if (ps2netfs_lwip_send(ps2netfs_sock, readrly, sizeof(ps2netfs_pkt_read_rly), 0) < 0)
646 {
647 DPRINTF("ps2netfs: error sending reply!\n");
648 return -1;
649 }
650 // now send the data
651 if (retval > 0)
652 if (ps2netfs_lwip_send(ps2netfs_sock, ps2netfs_fiobuffer, ntohl(readrly->retval), 0) < 0)
653 {
654 DPRINTF("ps2netfs: error sending data!\n");
655 return -1;
656 }
657 return 0;
658}
659
676// int write(int fd, void *ptr, size_t size);
677static int ps2netfs_op_write(char *buf, int len)
678{
679 ps2netfs_pkt_write_req *cmd;
680 ps2netfs_pkt_file_rly *writerly;
681 int retval = -1;
682 fd_table_t *fdptr;
683 cmd = (ps2netfs_pkt_write_req *)buf;
684
685 (void)len;
686
687 DPRINTF("ps2netfs: write\n");
688
689 // do the stuff here
690 fdptr = fdh_get(ntohl(cmd->fd));
691 if (fdptr != 0)
692 {
693 int left = ntohl(cmd->nbytes);
694 int written;
695 written = retval = 0;
696 while ((retval >= 0) && (left > 0))
697 {
698 int towrite;
699
700 towrite = left; if (towrite > FIOTRAN_MAXSIZE) towrite = FIOTRAN_MAXSIZE;
701 if (ps2netfs_recv_bytes(ps2netfs_sock, ps2netfs_fiobuffer, towrite) <=0 )
702 {
703 DPRINTF("ps2netfs: error reading data!\n");
704 return -1;
705 }
706
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);
711
712 if (retval > 0) { written += retval; left -= retval; }
713 }
714 if (retval > 0)
715 retval = written;
716 }
717
718 // now build the response
719 writerly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
720
721 // Build packet
722 writerly->cmd = htonl(PS2NETFS_WRITE_RLY);
723 writerly->len = htons((unsigned short)sizeof(ps2netfs_pkt_file_rly));
724 writerly->retval = htonl(retval);
725
726 if (ps2netfs_lwip_send(ps2netfs_sock, writerly, sizeof(ps2netfs_pkt_file_rly), 0) < 0)
727 {
728 DPRINTF("ps2netfs: error sending reply!\n");
729 return -1;
730 }
731 return 0;
732}
733
750// int lseek(int fd, int offset, int mode);
751static int ps2netfs_op_lseek(char *buf, int len)
752{
753 ps2netfs_pkt_lseek_req *cmd;
754 ps2netfs_pkt_file_rly *lseekrly;
755 fd_table_t *fdptr;
756 int retval = -ENODEV;
757 cmd = (ps2netfs_pkt_lseek_req *)buf;
758
759 DPRINTF("ps2netfs: lseek\n");
760
761 if (len != sizeof(ps2netfs_pkt_lseek_req))
762 {
763 DPRINTF("ps2netfs: got a broken packet (%d)!\n", len);
764 return -1;
765 }
766 // do the stuff here
767 fdptr = fdh_get(ntohl(cmd->fd));
768 if (fdptr != 0)
769 {
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));
774 }
775
776 // now build the response
777 lseekrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
778
779 // Build packet
780 lseekrly->cmd = htonl(PS2NETFS_LSEEK_RLY);
781 lseekrly->len = htons((unsigned short)sizeof(ps2netfs_pkt_file_rly));
782 lseekrly->retval = htonl(retval);
783
784 if (ps2netfs_lwip_send(ps2netfs_sock, lseekrly, sizeof(ps2netfs_pkt_file_rly), 0) < 0)
785 {
786 DPRINTF("ps2netfs: error sending reply!\n");
787 return -1;
788 }
789 return 0;
790}
791
808// int ioctl(int fd, unsigned long cmd, void *param);
809static int ps2netfs_op_ioctl(char *buf, int len)
810{
811 ps2netfs_pkt_ioctl_req *cmd;
812 ps2netfs_pkt_ioctl_rly *ioctlrly;
813 fd_table_t *fdptr;
814 int retval = -ENODEV;
815 cmd = (ps2netfs_pkt_ioctl_req *)buf;
816
817 DPRINTF("ps2netfs: ioctl\n");
818
819 if (len != sizeof(ps2netfs_pkt_ioctl_req))
820 {
821 DPRINTF("ps2netfs: got a broken packet (%d)!\n", len);
822 return -1;
823 }
824 // now build the response
825 ioctlrly = (ps2netfs_pkt_ioctl_rly *)&ps2netfs_send_packet[0];
826
827 // do the stuff here
828 fdptr = fdh_get(ntohl(cmd->fd));
829 if (fdptr != 0)
830 {
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);
835 }
836
837 // Build packet
838 ioctlrly->cmd = htonl(PS2NETFS_IOCTL_RLY);
839 ioctlrly->len = htons((unsigned short)sizeof(ps2netfs_pkt_ioctl_rly));
840 ioctlrly->retval = htonl(retval);
841
842 if (ps2netfs_lwip_send(ps2netfs_sock, ioctlrly, sizeof(ps2netfs_pkt_ioctl_rly), 0) < 0)
843 {
844 DPRINTF("ps2netfs: error sending reply!\n");
845 return -1;
846 }
847 return 0;
848}
849
866// int remove(const char *name);
867static int ps2netfs_op_remove(char *buf, int len)
868{
869 ps2netfs_pkt_open_req *cmd;
870 ps2netfs_pkt_file_rly *removerly;
871 int retval = -ENODEV;
872 int devtype;
873 cmd = (ps2netfs_pkt_open_req *)buf;
874
875 DPRINTF("ps2netfs: remove\n");
876
877 if (len != sizeof(ps2netfs_pkt_open_req))
878 {
879 DPRINTF("ps2netfs: got a broken packet (%d)!\n", len);
880 return -1;
881 }
882
883 // do the stuff here
884 devtype = devscan_gettype(cmd->path);
885 if (devtype != IOPMGR_DEVTYPE_INVALID)
886 {
887 if (devtype == IOPMGR_DEVTYPE_IOMAN)
888 retval = io_remove(cmd->path);
889 else if (devtype == IOPMGR_DEVTYPE_IOMANX)
890 retval = remove(cmd->path);
891 }
892
893 // now build the response
894 removerly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
895
896 // Build packet
897 removerly->cmd = htonl(PS2NETFS_REMOVE_RLY);
898 removerly->len = htons((unsigned short)sizeof(ps2netfs_pkt_file_rly));
899 removerly->retval = htonl(retval);
900
901 if (ps2netfs_lwip_send(ps2netfs_sock, removerly, sizeof(ps2netfs_pkt_file_rly), 0) < 0)
902 {
903 DPRINTF("ps2netfs: error sending reply!\n");
904 return -1;
905 }
906 return 0;
907}
908
925// int mkdir(const char *path, ...);
926static int ps2netfs_op_mkdir(char *buf, int len)
927{
928 ps2netfs_pkt_open_req *cmd;
929 ps2netfs_pkt_file_rly *mkdirrly;
930 int retval = -19;
931 int devtype;
932 cmd = (ps2netfs_pkt_open_req *)buf;
933
934 DPRINTF("ps2netfs: mkdir\n");
935
936 if (len != sizeof(ps2netfs_pkt_open_req))
937 {
938 DPRINTF("ps2netfs: got a broken packet (%d)!\n", len);
939 return -1;
940 }
941
942 // do the stuff here
943 devtype = devscan_gettype(cmd->path);
944 if (devtype != IOPMGR_DEVTYPE_INVALID)
945 {
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);
950 }
951
952 // now build the response
953 mkdirrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
954
955 // Build packet
956 mkdirrly->cmd = htonl(PS2NETFS_MKDIR_RLY);
957 mkdirrly->len = htons((unsigned short)sizeof(ps2netfs_pkt_file_rly));
958 mkdirrly->retval = htonl(retval);
959
960 if (ps2netfs_lwip_send(ps2netfs_sock, mkdirrly, sizeof(ps2netfs_pkt_file_rly), 0) < 0)
961 {
962 DPRINTF("ps2netfs: error sending reply!\n");
963 return -1;
964 }
965 return 0;
966}
967
984// int rmdir(const char *path);
985static int ps2netfs_op_rmdir(char *buf, int len)
986{
987 ps2netfs_pkt_open_req *cmd;
988 ps2netfs_pkt_file_rly *rmdirrly;
989 int retval = -ENODEV;
990 int devtype;
991 cmd = (ps2netfs_pkt_open_req *)buf;
992
993 DPRINTF("ps2netfs: remove\n");
994
995 if (len != sizeof(ps2netfs_pkt_open_req))
996 {
997 DPRINTF("ps2netfs: got a broken packet (%d)!\n", len);
998 return -1;
999 }
1000
1001 // do the stuff here
1002 devtype = devscan_gettype(cmd->path);
1003 if (devtype != IOPMGR_DEVTYPE_INVALID)
1004 {
1005 if (devtype == IOPMGR_DEVTYPE_IOMAN)
1006 retval = io_rmdir(cmd->path);
1007 else if (devtype == IOPMGR_DEVTYPE_IOMANX)
1008 retval = rmdir(cmd->path);
1009 }
1010
1011 // now build the response
1012 rmdirrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
1013
1014 // Build packet
1015 rmdirrly->cmd = htonl(PS2NETFS_RMDIR_RLY);
1016 rmdirrly->len = htons((unsigned short)sizeof(ps2netfs_pkt_file_rly));
1017 rmdirrly->retval = htonl(retval);
1018
1019 if (ps2netfs_lwip_send(ps2netfs_sock, rmdirrly, sizeof(ps2netfs_pkt_file_rly), 0) < 0)
1020 {
1021 DPRINTF("ps2netfs: error sending reply!\n");
1022 return -1;
1023 }
1024 return 0;
1025}
1026
1043// int dopen(const char *path);
1044static int ps2netfs_op_dopen(char *buf, int len)
1045{
1046 ps2netfs_pkt_open_req *cmd;
1047 ps2netfs_pkt_file_rly *dopenrly;
1048 int retval = -ENODEV;
1049 int devtype;
1050 cmd = (ps2netfs_pkt_open_req *)buf;
1051
1052 DPRINTF("ps2netfs: dopen\n");
1053
1054 if (len != sizeof(ps2netfs_pkt_open_req))
1055 {
1056 DPRINTF("ps2netfs: got a broken packet (%d)!\n", len);
1057 return -1;
1058 }
1059
1060 // do the stuff here
1061 devtype = devscan_gettype(cmd->path);
1062 if (devtype != IOPMGR_DEVTYPE_INVALID)
1063 {
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);
1068 if (retval > 0)
1069 retval = fdh_getfd(devtype,retval);
1070 }
1071
1072 // now build the response
1073 dopenrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
1074
1075 // Build packet
1076 dopenrly->cmd = htonl(PS2NETFS_DOPEN_RLY);
1077 dopenrly->len = htons((unsigned short)sizeof(ps2netfs_pkt_file_rly));
1078 dopenrly->retval = htonl(retval);
1079
1080 if (ps2netfs_lwip_send(ps2netfs_sock, dopenrly, sizeof(ps2netfs_pkt_file_rly), 0) < 0)
1081 {
1082 DPRINTF("ps2netfs: error sending reply!\n");
1083 return -1;
1084 }
1085 return 0;
1086}
1087
1104// int dclose(int fd);
1105static int ps2netfs_op_dclose(char *buf, int len)
1106{
1107 ps2netfs_pkt_close_req *cmd;
1108 ps2netfs_pkt_file_rly *closerly;
1109 fd_table_t *fdptr;
1110 int retval = -ENODEV;
1111 cmd = (ps2netfs_pkt_close_req *)buf;
1112
1113 DPRINTF("ps2netfs: dclose\n");
1114
1115 if (len != sizeof(ps2netfs_pkt_close_req))
1116 {
1117 DPRINTF("ps2netfs: got a broken packet (%d)!\n", len);
1118 return -1;
1119 }
1120
1121 // do the stuff here
1122 fdptr = fdh_get(ntohl(cmd->fd));
1123 if (fdptr != 0)
1124 {
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);
1129 if (retval == 0) fdh_freefd(ntohl(cmd->fd));
1130 }
1131
1132 // now build the response
1133 closerly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
1134
1135 // Build packet
1136 closerly->cmd = htonl(PS2NETFS_DCLOSE_RLY);
1137 closerly->len = htons((unsigned short)sizeof(ps2netfs_pkt_file_rly));
1138 closerly->retval = htonl(retval);
1139
1140 if (ps2netfs_lwip_send(ps2netfs_sock, closerly, sizeof(ps2netfs_pkt_file_rly), 0) < 0)
1141 {
1142 DPRINTF("ps2netfs: error sending reply!\n");
1143 return -1;
1144 }
1145 return 0;
1146}
1147
1164// int dread(int fd, void *buf);
1165static int ps2netfs_op_dread(char *buf, int len)
1166{
1167 ps2netfs_pkt_dread_req *cmd;
1168 ps2netfs_pkt_dread_rly *dreadrly;
1169 fd_table_t *fdptr;
1170 int retval = -ENODEV;
1171 cmd = (ps2netfs_pkt_dread_req *)buf;
1172
1173 DPRINTF("ps2netfs: dread\n");
1174
1175 if (len != sizeof(ps2netfs_pkt_dread_req))
1176 {
1177 DPRINTF("ps2netfs: got a broken packet (%d)!\n", len);
1178 return -1;
1179 }
1180
1181 // get response structure ready for filling
1182 dreadrly = (ps2netfs_pkt_dread_rly *)&ps2netfs_send_packet[0];
1183 memset(dreadrly,0,sizeof(ps2netfs_pkt_dread_rly));
1184
1185 // do the stuff here
1186 fdptr = fdh_get(ntohl(cmd->fd));
1187 if (fdptr != 0)
1188 {
1189 if (fdptr->devtype == IOPMGR_DEVTYPE_IOMAN)
1190 {
1191 io_dirent_t dirent;
1192 retval = io_dread(fdptr->realfd,&dirent);
1193 if (retval > 0)
1194 {
1195 dreadrly->mode = htonl(convmode_to_iomanx(dirent.stat.mode));
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';
1204 }
1205 }
1206 else if (fdptr->devtype == IOPMGR_DEVTYPE_IOMANX)
1207 {
1208 iox_dirent_t dirent;
1209 retval = dread(fdptr->realfd,&dirent);
1210 if (retval > 0)
1211 {
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';
1221 }
1222 }
1223 }
1224 DPRINTF("ps2netfs: dread '%s' %u\n",dreadrly->name,dreadrly->size);
1225 // Build packet
1226 dreadrly->cmd = htonl(PS2NETFS_DREAD_RLY);
1227 dreadrly->len = htons((unsigned short)sizeof(ps2netfs_pkt_dread_rly));
1228 dreadrly->retval = htonl(retval);
1229
1230 if (ps2netfs_lwip_send(ps2netfs_sock, dreadrly, sizeof(ps2netfs_pkt_dread_rly), 0) < 0)
1231 {
1232 DPRINTF("ps2netfs: error sending reply!\n");
1233 return -1;
1234 }
1235 return 0;
1236}
1237
1254// int getstat(const char *name, void *stat);
1255static int ps2netfs_op_getstat(char *buf, int len)
1256{
1257 (void)buf;
1258 (void)len;
1259 return -1;
1260}
1261
1278// int chstat(const char *name, void *stat, unsigned int statmask);
1279static int ps2netfs_op_chstat(char *buf, int len)
1280{
1281 (void)buf;
1282 (void)len;
1283 return -1;
1284}
1285
1302// int format(const char *dev, const char *blockdev, void *arg, size_t arglen);
1303// #define PFS_ZONE_SIZE 8192
1304// #define PFS_FRAGMENT 0x00000000
1305// int Arg[3] = { PFS_ZONE_SIZE, 0x2d66, PFS_FRAGMENT };
1306// retVal = fileXioFormat("pfs:", "hdd0:partition", (const char*)&Arg, sizeof(Arg));
1307
1308#define PFS_ZONE_SIZE 8192
1309#define PFS_FRAGMENT 0x00000000
1310static int ps2netfs_op_format(char *buf, int len)
1311{
1312 ps2netfs_pkt_format_req *cmd;
1313 ps2netfs_pkt_file_rly *formatrly;
1314 int retval = -ENODEV;
1315 int devtype = 0;
1316
1317 cmd = (ps2netfs_pkt_format_req *)buf;
1318
1319 DPRINTF("ps2netfs: format\n");
1320
1321 if (len != sizeof(ps2netfs_pkt_format_req))
1322 {
1323 DPRINTF("ps2netfs: got a broken packet (%d)!\n", len);
1324 return -1;
1325 }
1326 // do the stuff here
1327 devtype = devscan_gettype(cmd->dev);
1328 if (devtype == IOPMGR_DEVTYPE_IOMANX)
1329 { // if other end has not set args, add some standard ones (hdd use only for mo)
1330 if (ntohl(cmd->arglen) == 0)
1331 {
1332 int Arg[3] = { PFS_ZONE_SIZE, 0x2d66, PFS_FRAGMENT };
1333 retval = format(cmd->dev,cmd->blockdev,(char*)&Arg,sizeof(Arg));
1334 }
1335 else retval = format(cmd->dev,cmd->blockdev,cmd->arg,ntohl(cmd->arglen));
1336 }
1337
1338 // now build the response
1339 formatrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
1340
1341 // Build packet
1342 formatrly->cmd = htonl(PS2NETFS_FORMAT_RLY);
1343 formatrly->len = htons((unsigned short)sizeof(ps2netfs_pkt_file_rly));
1344 formatrly->retval = htonl(retval);
1345
1346 if (ps2netfs_lwip_send(ps2netfs_sock, formatrly, sizeof(ps2netfs_pkt_file_rly), 0) < 0)
1347 {
1348 DPRINTF("ps2netfs: error sending reply!\n");
1349 return -1;
1350 }
1351 return 0;
1352}
1353
1354// EXTENDED CALLS FROM HERE ON IN
1355
1372// int rename(const char *old, const char *new);
1373static int ps2netfs_op_rename(char *buf, int len)
1374{
1375 ps2netfs_pkt_symlink_req *cmd;
1376 ps2netfs_pkt_file_rly *renamerly;
1377 int retval = -ENODEV;
1378 int devtype;
1379 cmd = (ps2netfs_pkt_symlink_req *)buf;
1380
1381 DPRINTF("ps2netfs: rename\n");
1382
1383 if (len != sizeof(ps2netfs_pkt_symlink_req))
1384 {
1385 DPRINTF("ps2netfs: got a broken packet (%d)!\n", len);
1386 return -1;
1387 }
1388
1389 // check that both are iomanx devices
1390 devtype = devscan_gettype(cmd->oldpath);
1391 if (devtype == IOPMGR_DEVTYPE_IOMANX)
1392 {
1393 devtype = devscan_gettype(cmd->newpath);
1394 if (devtype == IOPMGR_DEVTYPE_IOMANX)
1395 retval = rename(cmd->oldpath,cmd->newpath);
1396 else retval = -1;
1397 }
1398 // now build the response
1399 renamerly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
1400
1401 // Build packet
1402 renamerly->cmd = htonl(PS2NETFS_SYMLINK_RLY);
1403 renamerly->len = htons((unsigned short)sizeof(ps2netfs_pkt_file_rly));
1404 renamerly->retval = htonl(retval);
1405
1406 if (ps2netfs_lwip_send(ps2netfs_sock, renamerly, sizeof(ps2netfs_pkt_file_rly), 0) < 0)
1407 {
1408 DPRINTF("ps2netfs: error sending reply!\n");
1409 return -1 ;
1410 }
1411 return 0;
1412}
1413
1430// int chdir(const char *name);
1431static int ps2netfs_op_chdir(char *buf, int len)
1432{
1433 ps2netfs_pkt_open_req *cmd;
1434 ps2netfs_pkt_file_rly *chdirrly;
1435 int retval = -ENODEV;
1436 int devtype;
1437 cmd = (ps2netfs_pkt_open_req *)buf;
1438
1439 DPRINTF("ps2netfs: chdir\n");
1440
1441 if (len != sizeof(ps2netfs_pkt_open_req))
1442 {
1443 DPRINTF("ps2netfs: got a broken packet (%d)!\n", len);
1444 return -1;
1445 }
1446
1447 // do the stuff here
1448 devtype = devscan_gettype(cmd->path);
1449 if (devtype == IOPMGR_DEVTYPE_IOMANX)
1450 retval = chdir(cmd->path);
1451
1452 // now build the response
1453 chdirrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
1454
1455 // Build packet
1456 chdirrly->cmd = htonl(PS2NETFS_CHDIR_RLY);
1457 chdirrly->len = htons((unsigned short)sizeof(ps2netfs_pkt_file_rly));
1458 chdirrly->retval = htonl(retval);
1459
1460 if (ps2netfs_lwip_send(ps2netfs_sock, chdirrly, sizeof(ps2netfs_pkt_file_rly), 0) < 0)
1461 {
1462 DPRINTF("ps2netfs: error sending reply!\n");
1463 return -1;
1464 }
1465 return 0;
1466}
1467
1484// int sync(const char *dev, int flag);
1485static int ps2netfs_op_sync(char *buf, int len)
1486{
1487 ps2netfs_pkt_open_req *cmd;
1488 ps2netfs_pkt_file_rly *syncrly;
1489 int retval = -ENODEV;
1490 int devtype;
1491 cmd = (ps2netfs_pkt_open_req *)buf;
1492
1493 DPRINTF("ps2netfs: sync\n");
1494
1495 if (len != sizeof(ps2netfs_pkt_open_req))
1496 {
1497 DPRINTF("ps2netfs: got a broken packet (%d)!\n", len);
1498 return -1;
1499 }
1500
1501 // do the stuff here
1502 devtype = devscan_gettype(cmd->path);
1503 if (devtype == IOPMGR_DEVTYPE_IOMANX)
1504 retval = sync(cmd->path,ntohl(cmd->flags));
1505
1506 // now build the response
1507 syncrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
1508
1509 // Build packet
1510 syncrly->cmd = htonl(PS2NETFS_SYNC_RLY);
1511 syncrly->len = htons((unsigned short)sizeof(ps2netfs_pkt_file_rly));
1512 syncrly->retval = htonl(retval);
1513
1514 if (ps2netfs_lwip_send(ps2netfs_sock, syncrly, sizeof(ps2netfs_pkt_file_rly), 0) < 0)
1515 {
1516 DPRINTF("ps2netfs: error sending reply!\n");
1517 return -1;
1518 }
1519 return 0;
1520}
1521
1538// int mount(const char *fsname, const char *devname, int flag, void *arg, size_t arglen);
1539static int ps2netfs_op_mount(char *buf, int len)
1540{
1541 ps2netfs_pkt_mount_req *cmd;
1542 ps2netfs_pkt_file_rly *mountrly;
1543 int retval = -ENODEV;
1544 int devtype;
1545 cmd = (ps2netfs_pkt_mount_req *)buf;
1546
1547 DPRINTF("ps2netfs: mount\n");
1548
1549 if (len != sizeof(ps2netfs_pkt_mount_req))
1550 {
1551 DPRINTF("ps2netfs: got a broken packet (%d)!\n", len);
1552 return -1;
1553 }
1554
1555 // do the stuff here
1556 devtype = devscan_gettype(cmd->fsname);
1557 if (devtype == IOPMGR_DEVTYPE_IOMANX)
1558 retval = mount(cmd->fsname,cmd->devname,ntohl(cmd->flag),cmd->arg,ntohl(cmd->arglen));
1559
1560 // now build the response
1561 mountrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
1562
1563 // Build packet
1564 mountrly->cmd = htonl(PS2NETFS_MOUNT_RLY);
1565 mountrly->len = htons((unsigned short)sizeof(ps2netfs_pkt_file_rly));
1566 mountrly->retval = htonl(retval);
1567
1568 if (ps2netfs_lwip_send(ps2netfs_sock, mountrly, sizeof(ps2netfs_pkt_file_rly), 0) < 0)
1569 {
1570 DPRINTF("ps2netfs: error sending reply!\n");
1571 return -1 ;
1572 }
1573 return 0;
1574}
1575
1592// int umount(const char *fsname);
1593static int ps2netfs_op_umount(char *buf, int len)
1594{
1595 ps2netfs_pkt_open_req *cmd;
1596 ps2netfs_pkt_file_rly *umountrly;
1597 int retval = -ENODEV;
1598 int devtype;
1599 cmd = (ps2netfs_pkt_open_req *)buf;
1600
1601 DPRINTF("ps2netfs: umount\n");
1602
1603 if (len != sizeof(ps2netfs_pkt_open_req))
1604 {
1605 DPRINTF("ps2netfs: got a broken packet (%d)!\n", len);
1606 return -1;
1607 }
1608
1609 // do the stuff here
1610 devtype = devscan_gettype(cmd->path);
1611 if (devtype == IOPMGR_DEVTYPE_IOMANX)
1612 retval = umount(cmd->path);
1613
1614 // now build the response
1615 umountrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
1616
1617 // Build packet
1618 umountrly->cmd = htonl(PS2NETFS_UMOUNT_RLY);
1619 umountrly->len = htons((unsigned short)sizeof(ps2netfs_pkt_file_rly));
1620 umountrly->retval = htonl(retval);
1621
1622 if (ps2netfs_lwip_send(ps2netfs_sock, umountrly, sizeof(ps2netfs_pkt_file_rly), 0) < 0)
1623 {
1624 DPRINTF("ps2netfs: error sending reply!\n");
1625 return -1 ;
1626 }
1627 return 0;
1628}
1629
1646// int lseek64(int fd, long long offset, int whence);
1647static int ps2netfs_op_lseek64(char *buf, int len)
1648{
1649 (void)buf;
1650 (void)len;
1651 return -1;
1652}
1653
1670// int devctl(const char *name, int cmd, void *arg, size_t arglen, void *buf, size_t buflen);
1671static int ps2netfs_op_devctl(char *buf, int len)
1672{
1673 (void)buf;
1674 (void)len;
1675 return -1;
1676}
1677
1694// int symlink(const char *old, const char *new);
1695static int ps2netfs_op_symlink(char *buf, int len)
1696{
1697 ps2netfs_pkt_symlink_req *cmd;
1698 ps2netfs_pkt_file_rly *symlinkrly;
1699 int retval = -ENODEV;
1700 int devtype;
1701 cmd = (ps2netfs_pkt_symlink_req *)buf;
1702
1703 DPRINTF("ps2netfs: symlink\n");
1704
1705 if (len != sizeof(ps2netfs_pkt_symlink_req))
1706 {
1707 DPRINTF("ps2netfs: got a broken packet (%d)!\n", len);
1708 return -1;
1709 }
1710
1711 // check that both are iomanx devices
1712 devtype = devscan_gettype(cmd->oldpath);
1713 if (devtype == IOPMGR_DEVTYPE_IOMANX)
1714 {
1715 devtype = devscan_gettype(cmd->newpath);
1716 if (devtype == IOPMGR_DEVTYPE_IOMANX)
1717 retval = symlink(cmd->oldpath,cmd->newpath);
1718 else retval = -1;
1719 }
1720 // now build the response
1721 symlinkrly = (ps2netfs_pkt_file_rly *)&ps2netfs_send_packet[0];
1722
1723 // Build packet
1724 symlinkrly->cmd = htonl(PS2NETFS_SYMLINK_RLY);
1725 symlinkrly->len = htons((unsigned short)sizeof(ps2netfs_pkt_file_rly));
1726 symlinkrly->retval = htonl(retval);
1727
1728 if (ps2netfs_lwip_send(ps2netfs_sock, symlinkrly, sizeof(ps2netfs_pkt_file_rly), 0) < 0)
1729 {
1730 DPRINTF("ps2netfs: error sending reply!\n");
1731 return -1 ;
1732 }
1733 return 0;
1734}
1735
1752// int readlink(const char *path, char *buf, size_t buflen);
1753static int ps2netfs_op_readlink(char *buf, int len)
1754{
1755 ps2netfs_pkt_open_req *cmd;
1756 ps2netfs_pkt_readlink_rly *readlinkrly;
1757 int retval = -ENODEV;
1758 int devtype;
1759 cmd = (ps2netfs_pkt_open_req *)buf;
1760
1761 DPRINTF("ps2netfs: readlink\n");
1762
1763 if (len != sizeof(ps2netfs_pkt_open_req))
1764 {
1765 DPRINTF("ps2netfs: got a broken packet (%d)!\n", len);
1766 return -1;
1767 }
1768
1769 // now build the response
1770 readlinkrly = (ps2netfs_pkt_readlink_rly *)&ps2netfs_send_packet[0];
1771
1772 // do the stuff here
1773 devtype = devscan_gettype(cmd->path);
1774 if (devtype == IOPMGR_DEVTYPE_IOMANX)
1775 retval = readlink(cmd->path,readlinkrly->path,cmd->flags);
1776
1777
1778 // Build packet
1779 readlinkrly->cmd = htonl(PS2NETFS_READLINK_RLY);
1780 readlinkrly->len = htons((unsigned short)sizeof(ps2netfs_pkt_readlink_rly));
1781 readlinkrly->retval = htonl(retval);
1782
1783 if (ps2netfs_lwip_send(ps2netfs_sock, readlinkrly, sizeof(ps2netfs_pkt_readlink_rly), 0) < 0)
1784 {
1785 DPRINTF("ps2netfs: error sending reply!\n");
1786 return -1 ;
1787 }
1788 return 0;
1789}
1790
1807// int ioctl2(int fd, int cmd, void *arg, size_t arglen, void *buf, size_t buflen);
1808static int ps2netfs_op_ioctl2(char *buf, int len)
1809{
1810 (void)buf;
1811 (void)len;
1812 return -1;
1813}
1814
1815
1825static void ps2netfs_Listener(int sock)
1826{
1827 unsigned int cmd;
1828 ps2netfs_pkt_hdr *header;
1829 int retval;
1830
1831 while(1) {
1832 int len;
1833
1834 len = ps2netfs_accept_pktunknown(sock, &ps2netfs_recv_packet[0]);
1835
1836 if (len > 0)
1837 DPRINTF("ps2netfs: received packet (%d)\n", len);
1838
1839 if (len < 0) {
1840 DPRINTF("ps2netfs_Listener: recvfrom error (%d)\n", len);
1841 return;
1842 }
1843 if ((unsigned int)len >= sizeof(ps2netfs_pkt_hdr))
1844 {
1845 header = (ps2netfs_pkt_hdr *)ps2netfs_recv_packet;
1846 cmd = ntohl(header->cmd);
1847 switch (cmd)
1848 {
1849 case PS2NETFS_OPEN_CMD:
1850 retval = ps2netfs_op_open(ps2netfs_recv_packet, len);
1851 break;
1852 case PS2NETFS_CLOSE_CMD:
1853 retval = ps2netfs_op_close(ps2netfs_recv_packet, len);
1854 break;
1855 case PS2NETFS_READ_CMD:
1856 retval = ps2netfs_op_read(ps2netfs_recv_packet, len);
1857 break;
1858 case PS2NETFS_WRITE_CMD:
1859 retval = ps2netfs_op_write(ps2netfs_recv_packet, len);
1860 break;
1861 case PS2NETFS_LSEEK_CMD:
1862 retval = ps2netfs_op_lseek(ps2netfs_recv_packet, len);
1863 break;
1864 case PS2NETFS_IOCTL_CMD:
1865 retval = ps2netfs_op_ioctl(ps2netfs_recv_packet, len);
1866 break;
1867 case PS2NETFS_REMOVE_CMD:
1868 retval = ps2netfs_op_remove(ps2netfs_recv_packet, len);
1869 break;
1870 case PS2NETFS_MKDIR_CMD:
1871 retval = ps2netfs_op_mkdir(ps2netfs_recv_packet, len);
1872 break;
1873 case PS2NETFS_RMDIR_CMD:
1874 retval = ps2netfs_op_rmdir(ps2netfs_recv_packet, len);
1875 break;
1876 case PS2NETFS_DOPEN_CMD:
1877 retval = ps2netfs_op_dopen(ps2netfs_recv_packet, len);
1878 break;
1879 case PS2NETFS_DCLOSE_CMD:
1880 retval = ps2netfs_op_dclose(ps2netfs_recv_packet, len);
1881 break;
1882 case PS2NETFS_DREAD_CMD:
1883 retval = ps2netfs_op_dread(ps2netfs_recv_packet, len);
1884 break;
1885 case PS2NETFS_GETSTAT_CMD:
1886 retval = ps2netfs_op_getstat(ps2netfs_recv_packet, len);
1887 break;
1888 case PS2NETFS_CHSTAT_CMD:
1889 retval = ps2netfs_op_chstat(ps2netfs_recv_packet, len);
1890 break;
1891 case PS2NETFS_FORMAT_CMD:
1892 retval = ps2netfs_op_format(ps2netfs_recv_packet, len);
1893 break;
1894 case PS2NETFS_RENAME_CMD:
1895 retval = ps2netfs_op_rename(ps2netfs_recv_packet, len);
1896 break;
1897 case PS2NETFS_CHDIR_CMD:
1898 retval = ps2netfs_op_chdir(ps2netfs_recv_packet, len);
1899 break;
1900 case PS2NETFS_SYNC_CMD:
1901 retval = ps2netfs_op_sync(ps2netfs_recv_packet, len);
1902 break;
1903 case PS2NETFS_MOUNT_CMD:
1904 retval = ps2netfs_op_mount(ps2netfs_recv_packet, len);
1905 break;
1906 case PS2NETFS_UMOUNT_CMD:
1907 retval = ps2netfs_op_umount(ps2netfs_recv_packet, len);
1908 break;
1909 case PS2NETFS_LSEEK64_CMD:
1910 retval = ps2netfs_op_lseek64(ps2netfs_recv_packet, len);
1911 break;
1912 case PS2NETFS_DEVCTL_CMD:
1913 retval = ps2netfs_op_devctl(ps2netfs_recv_packet, len);
1914 break;
1915 case PS2NETFS_SYMLINK_CMD:
1916 retval = ps2netfs_op_symlink(ps2netfs_recv_packet, len);
1917 break;
1918 case PS2NETFS_READLINK_CMD:
1919 retval = ps2netfs_op_readlink(ps2netfs_recv_packet, len);
1920 break;
1921 case PS2NETFS_IOCTL2_CMD:
1922 retval = ps2netfs_op_ioctl2(ps2netfs_recv_packet, len);
1923 break;
1924
1925 case PS2NETFS_INFO_CMD:
1926 retval = ps2netfs_op_info(ps2netfs_recv_packet, len);
1927 break;
1928 case PS2NETFS_FSTYPE_CMD:
1929 retval = ps2netfs_op_fstype(ps2netfs_recv_packet, len);
1930 break;
1931 case PS2NETFS_DEVLIST_CMD:
1932 retval = ps2netfs_op_devlist(ps2netfs_recv_packet, len);
1933 break;
1934
1935 default:
1936 DPRINTF("ps2netfs: Unknown cmd received\n");
1937 retval = 0;
1938 break;
1939 }
1940 if (retval == -1)
1941 return;
1942 }
1943 else
1944 {
1945 DPRINTF("ps2netfs: packet too small (%d)\n", len);
1946 return;
1947 }
1948 DPRINTF("ps2netfs: waiting for next pkt\n");
1949 }
1950}
1951
1967int
1968ps2netfs_serv(void *argv)
1969{
1970 struct sockaddr_in server_addr;
1971 struct sockaddr_in client_addr;
1972 int sock;
1973 int ret;
1974
1975 (void)argv;
1976
1977 DPRINTF(" - ps2netfs TCP Server -\n");
1978
1980 fdh_setup();
1981
1982 memset((void *)&server_addr, 0, sizeof(server_addr));
1983 // Should perhaps specify PC side ip..
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);
1987
1988 while ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
1989 {
1990 DPRINTF("ps2netfs: socket creation error (%d)\n", sock);
1991 return -1;
1992 }
1993
1994 ret = bind(sock, (struct sockaddr *)&server_addr,
1995 sizeof(server_addr));
1996 if (ret < 0)
1997 {
1998 DPRINTF("ps2netfs: bind error (%d)\n", ret);
2000 return -1;
2001 }
2002
2003 ret = listen(sock, 5);
2004
2005 if (ret < 0)
2006 {
2007 DPRINTF("ps2netfs: listen error (%d)\n", ret);
2008 disconnect(sock);
2009 return -1;
2010 }
2011
2012 // Active flag kinda sux, cause it wont be checked until a new client has
2013 // connected.. But it's better than nothing and good for now at least
2014 ps2netfs_active = 1;
2015
2016 // Connection loop
2017 while(ps2netfs_active)
2018 {
2019 int client_sock;
2020 int client_len;
2021
2022 DPRINTF("ps2netfs: Waiting for connection\n");
2023
2024 client_len = sizeof(client_addr);
2025 client_sock = accept(sock, (struct sockaddr *)&client_addr,
2026 &client_len);
2027 if (client_sock < 0)
2028 {
2029 DPRINTF("ps2netfs: accept error (%d)", client_sock);
2030 continue;
2031 }
2032
2033 DPRINTF("Client connected from %x\n",
2034 client_addr.sin_addr.s_addr);
2035
2036 if (ps2netfs_sock > 0)
2037 {
2038 DPRINTF("ps2netfs: Client reconnected\n");
2039 ret = ps2netfs_close_socket();
2040 DPRINTF("ps2netfs: close ret %d\n", ret);
2041 continue;
2042 }
2043 ps2netfs_sock = client_sock;
2044
2045 if (ps2netfs_sock > 0)
2046 {
2047 ps2netfs_Listener(ps2netfs_sock);
2048 ret = ps2netfs_close_socket();
2049 DPRINTF("ps2netfs: close2 ret %d\n", ret);
2050 continue;
2051 }
2052 }
2053
2054 if (ps2netfs_sock > 0)
2055 disconnect(ps2netfs_sock);
2056
2057 disconnect(sock);
2058
2059 ExitDeleteThread();
2060 return 0;
2061}
2062
2071{
2072 iop_thread_t mythread;
2073 int pid;
2074
2075 DPRINTF("initializing ps2netfs\n");
2076
2077 // Start socket server thread
2078
2079 mythread.attr = 0x02000000; // attr
2080 mythread.option = 0; // option
2081 mythread.thread = (void *)ps2netfs_serv; // entry
2082 mythread.stacksize = 0x800;
2083 mythread.priority = 0x43; // just above ps2link
2084
2085 pid = CreateThread(&mythread);
2086
2087 if (pid > 0)
2088 {
2089 int i;
2090
2091 if ((i=StartThread(pid, NULL)) < 0)
2092 {
2093 DPRINTF("StartThread failed (%d)\n", i);
2094 return -1;
2095 }
2096 }
2097 else
2098 {
2099 DPRINTF("CreateThread failed (%d)\n", pid);
2100 return -1;
2101 }
2102
2103 ps2netfs_pid = pid;
2104 DPRINTF("Thread id: %x\n", pid);
2105 return 0;
2106}
2107
2115{
2116 WaitSema(ps2netfs_sema);
2117 // ExitDeleteThread(ps2netfs_pid);
2118 SignalSema(ps2netfs_sema);
2119 DeleteSema(ps2netfs_sema);
2120 return 0;
2121}
2122
2123
#define ENODEV
Definition errno.h:57
int realfd(iop_io_file_t *f)
Definition fakehost.c:102
static int ps2netfs_op_sync(char *buf, int len)
Definition ps2_fio.c:1485
static void ps2netfs_Listener(int sock)
Definition ps2_fio.c:1825
static int ps2netfs_op_fstype(char *buf, int len)
Definition ps2_fio.c:367
int ps2netfs_serv(void *argv)
Definition ps2_fio.c:1968
void ps2netfs_close_fsys(void)
Definition ps2_fio.c:189
static int ps2netfs_op_chdir(char *buf, int len)
Definition ps2_fio.c:1431
#define DEVSCAN_MASK
Definition devscan.h:26
static int ps2netfs_op_open(char *buf, int len)
Definition ps2_fio.c:484
static int ps2netfs_op_devctl(char *buf, int len)
Definition ps2_fio.c:1671
static int convmode_from_iomanx(int stat)
Definition ps2_fio.c:161
static int ps2netfs_op_read(char *buf, int len)
Definition ps2_fio.c:605
static int ps2netfs_op_ioctl2(char *buf, int len)
Definition ps2_fio.c:1808
static int ps2netfs_op_lseek64(char *buf, int len)
Definition ps2_fio.c:1647
static int ps2netfs_op_umount(char *buf, int len)
Definition ps2_fio.c:1593
int devscan_gettype(char *name)
Definition devscan.c:141
static int ps2netfs_op_readlink(char *buf, int len)
Definition ps2_fio.c:1753
static int ps2netfs_op_dopen(char *buf, int len)
Definition ps2_fio.c:1044
int devscan_setup(int devtype)
Definition devscan.c:73
static int ps2netfs_op_mkdir(char *buf, int len)
Definition ps2_fio.c:926
static int ps2netfs_op_mount(char *buf, int len)
Definition ps2_fio.c:1539
static int ps2netfs_op_close(char *buf, int len)
Definition ps2_fio.c:545
static int fdh_getfd(int devtype, int fd)
Definition ps2_fio.c:95
static int ps2netfs_op_dread(char *buf, int len)
Definition ps2_fio.c:1165
static int convmode_to_iomanx(int stat)
Definition ps2_fio.c:140
static void fdh_setup()
Definition ps2_fio.c:79
static int ps2netfs_op_write(char *buf, int len)
Definition ps2_fio.c:677
static int ps2netfs_op_lseek(char *buf, int len)
Definition ps2_fio.c:751
static int ps2netfs_op_chstat(char *buf, int len)
Definition ps2_fio.c:1279
static int ps2netfs_op_rmdir(char *buf, int len)
Definition ps2_fio.c:985
static int ps2netfs_op_remove(char *buf, int len)
Definition ps2_fio.c:867
static int ps2netfs_op_info(char *buf, int len)
Definition ps2_fio.c:314
static int ps2netfs_op_dclose(char *buf, int len)
Definition ps2_fio.c:1105
int ps2fs_Destroy(void)
Definition ps2_fio.c:2114
#define PFS_ZONE_SIZE
Definition ps2_fio.c:1308
int devscan_getdevlist(char *buffer)
Definition devscan.c:162
static int ps2netfs_op_rename(char *buf, int len)
Definition ps2_fio.c:1373
static int ps2netfs_op_symlink(char *buf, int len)
Definition ps2_fio.c:1695
static void fdh_freefd(int fd)
Definition ps2_fio.c:117
static int ps2netfs_op_devlist(char *buf, int len)
Definition ps2_fio.c:416
int ps2netfs_close_socket(void)
Definition ps2_fio.c:171
static int ps2netfs_op_getstat(char *buf, int len)
Definition ps2_fio.c:1255
static int ps2netfs_op_ioctl(char *buf, int len)
Definition ps2_fio.c:809
int ps2netfs_Init(void)
Definition ps2_fio.c:2070
#define FIO_S_IXGRP
Definition iox_stat.h:71
#define FIO_S_IROTH
Definition iox_stat.h:76
#define FIO_SO_IXOTH
Definition iox_stat.h:135
#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_SO_IWOTH
Definition iox_stat.h:133
#define FIO_S_IFLNK
Definition iox_stat.h:41
#define FIO_S_IFDIR
Definition iox_stat.h:45
#define FIO_SO_IROTH
Definition iox_stat.h:131
#define FIO_S_IFREG
Definition iox_stat.h:43
#define FIO_S_IWUSR
Definition iox_stat.h:60
int ps2netfs_accept_pktunknown(int sock, char *buf)
Definition ps2_fio.c:244
int ps2netfs_recv_bytes(int sock, char *buf, int bytes)
Definition ps2_fio.c:219
#define fdh_get(a)
Definition ps2_fio.c:128
#define INADDR_ANY
Definition tcpip.h:1492
u32 count
start sector of fragmented bd/file