
                     ---------------------------------
                      PS2NETFS OPERATION AND PROTOCOL
                        Dan Peori (peori@oopo.net)
                       Current as of March 6th, 2004
                     ---------------------------------

  Communication with ps2netfs takes place on TCP socket 0x4713. A connection is
  opened then a request packet is sent. Soon afterwards, a response packet will
  be received and the connection closed. Through these simple request/response
  pairs more complex functions can be created to do things like copy files to
  and from the ps2 itself. For examples see ps2netfs.c in the ps2client source.

  ----------------------------
   0xBEEF8011 (open request)
   0xBEEF8012 (open response)
  ----------------------------

   PACKET STRUCTURES

    struct { int number; short length; int flags; char pathname[256]; } request;
    struct { int number; short length; int result; } response;

   FLAG VALUES

    #define OPEN_READ		0x0001
    #define OPEN_WRITE		0x0002
    #define OPEN_NONBLOCK	0x0010
    #define OPEN_APPEND		0x0100
    #define OPEN_CREATE		0x0200
    #define OPEN_TRUNCATE	0x0400

   REQUEST PACKET CONTENTS

    request.number = htonl(0xBEEF8011);
    request.length = htons(sizeof(request));
    request.flags  = htonl(mode);
    if (pathname) { strncpy(request.pathname, pathname, 256); }

  -----------------------------
   0xBEEF8021 (close request)
   0xBEEF8022 (close response)
  -----------------------------

   PACKET STRUCTURES

    struct { int number; short length; int fd; } request;
    struct { int number; short length; int result; } response;

   REQUEST PACKET CONTENTS

    request.number = htonl(0xBEEF8021);
    request.length = htons(sizeof(request));
    request.fd     = htonl(fd);

  ----------------------------
   0xBEEF8031 (read request)
   0xBEEF8032 (read response)
  ----------------------------

   PACKET STRUCTURES

    struct { int number; short length; int fd, size; } request;
    struct { int number; short length; int result, size; } response;

   REQUEST PACKET CONTENTS

    request.number = htonl(0xBEEF8031);
    request.length = htons(sizeof(request));
    request.fd     = htonl(fd);
    request.size   = htonl(size);

  -----------------------------
   0xBEEF8041 (write request)
   0xBEEF8042 (write response)
  -----------------------------

   PACKET STRUCTURES

    struct { int number; short length; int fd, size; } request;
    struct { int number; short length; int result; } response;

   REQUEST PACKET CONTENTS

    request.number = htonl(0xBEEF8041);
    request.length = htons(sizeof(request));
    request.fd     = htonl(fd);
    request.size   = htonl(size);

  -----------------------------
   0xBEEF8051 (lseek request)
   0xBEEF8052 (lseek response)
  -----------------------------

   PACKET STRUCTURES

    struct { int number; short length; int fd, offset, whence; } request;
    struct { int number; short length; int result; } response;

   WHENCE VALUES

    #define LSEEK_SET		0x0000
    #define LSEEK_CURRENT	0x0001
    #define LSEEK_END		0x0002

   REQUEST PACKET CONTENTS

    request.number = htonl(0xBEEF8051);
    request.length = htons(sizeof(request));
    request.fd     = htonl(fd);
    request.offset = htonl(offset);
    request.whence = htonl(whence);

  -----------------------------
   0xBEEF8061 (ioctl request)
   0xBEEF8062 (ioctl response)
  -----------------------------

  ------------------------------
   0xBEEF8071 (delete request)
   0xBEEF8072 (delete response)
  ------------------------------

   PACKET STRUCTURES

    struct { int number; short length; int flags; char pathname[256]; } request;
    struct { int number; short length; int result; } response;

   REQUEST PACKET CONTENTS

    request.number = htonl(0xBEEF8071);
    request.length = htons(sizeof(request));
    request.flags  = htonl(flags);
    if (pathname) { strncpy(request.pathname, pathname, 256); }

  -----------------------------
   0xBEEF8081 (mkdir request)
   0xBEEF8082 (mkdir response)
  -----------------------------

   PACKET STRUCTURES

    struct { int number; short length; int flags; char pathname[256]; } request;
    struct { int number; short length; int result; } response;

   REQUEST PACKET CONTENTS

    request.number = htonl(0xBEEF8081);
    request.length = htons(sizeof(request));
    request.flags  = htonl(flags);
    if (pathname) { strncpy(request.pathname, pathname, 256); }

  -----------------------------
   0xBEEF8091 (rmdir request)
   0xBEEF8092 (rmdir response)
  -----------------------------

   PACKET STRUCTURES

    struct { int number; short length; int flags; char pathname[256]; } request;
    struct { int number; short length; int result; } response;

   REQUEST PACKET CONTENTS

    request.number = htonl(0xBEEF8091);
    request.length = htons(sizeof(request));
    request.flags  = htonl(flags);
    if (pathname) { strncpy(request.pathname, pathname, 256); }

  ------------------------------
   0xBEEF80A1 (dopen request)
   0xBEEF80A2 (dopen response)
  ------------------------------

   PACKET STRUCTURES

    struct { int number; short length; int flags; char pathname[256]; } request;
    struct { int number; short length; int result; } response;

   REQUEST PACKET CONTENTS

    request.number = htonl(0xBEEF80A1);
    request.length = htons(sizeof(request));
    request.flags  = htonl(flags);
    if (pathname) { strncpy(request.pathname, pathname, 256); }

  ------------------------------
   0xBEEF80B1 (dclose request)
   0xBEEF80B2 (dclose response)
  ------------------------------

   PACKET STRUCTURES

    struct { int number; short length; int dd; } request;
    struct { int number; short length; int result; } response;

   REQUEST PACKET CONTENTS

    request.number = htonl(0xBEEF80B1);
    request.length = htons(sizeof(request));
    request.dd     = htonl(dd);

  -----------------------------
   0xBEEF80C1 (dread request)
   0xBEEF80C2 (dread response)
  -----------------------------

   PACKET STRUCTURES

    struct { int number; short length; int dd; } request;
    struct { int number; short length; int result; int mode, attr, size; char ctime[8], atime[8], mtime[8]; int hisize; char name[256]; } response;

   REQUEST PACKET CONTENTS

    request.number = htonl(0xBEEF80C1);
    request.length = htons(sizeof(request));
    request.dd     = htonl(dd);

  ------------------------------
   0xBEEF80F1 (format request)
   0xBEEF80F2 (format response)
  ------------------------------

   UNDOCUMENTED

  ------------------------------
   0xBEEF8111 (rename request)
   0xBEEF8112 (rename response)
  ------------------------------

   UNDOCUMENTED

  ----------------------------
   0xBEEF8131 (sync request)
   0xBEEF8132 (sync response)
  ----------------------------

   PACKET STRUCTURES

    struct { int number; short length; int flags; char device[256]; } request;
    struct { int number; short length; int result; } response;

   REQUEST PACKET CONTENTS

    request.number = htonl(0xBEEF8131);
    request.length = htons(sizeof(request));
    request.flags  = htonl(flags);
    if (device) { strncpy(request.device, device, 256); }

  -----------------------------
   0xBEEF8141 (mount request)
   0xBEEF8142 (mount response)
  -----------------------------

   PACKET STRUCTURES

    struct { int number; short length; char device[256], fsname[256]; int flags; char argv[256]; int argc; } request;
    struct { int number; short length; int result; } response;

   FLAG VALUES

    #define MOUNT_READWRITE	0x00
    #define MOUNT_READONLY	0x01

   REQUEST PACKET CONTENTS

    request.number = htonl(0xBEEF8141);
    request.length = htons(sizeof(request));
    request.flags  = htonl(flags);
    request.argc   = htonl(argc);
    if (device) { strncpy(request.device, device, 256); }
    if (fsname) { strncpy(request.fsname, fsname, 256); }
    if (argv) { strncpy(request.argv, argv, 256); }

  ------------------------------
   0xBEEF8151 (umount request)
   0xBEEF8152 (umount response)
  ------------------------------

   PACKET STRUCTURES

    struct { int number; short length; int flags; char device[256]; } request;
    struct { int number; short length; int result; } response;

   REQUEST PACKET CONTENTS

    request.number = htonl(0xBEEF8151);
    request.length = htons(sizeof(request));
    request.flags  = htonl(flags);
    if (device) { strncpy(request.device, device, 256); }

  -------------------------------
   0xBEEF8F21 (devlist request)
   0xBEEF8F22 (devlist response)
  -------------------------------

   PACKET STRUCTURES

    struct { int number; short length; int flags; char pathname[256]; } request;
    struct { int number; short length; int result; int count; char devlist[256]; } response;

   REQUEST PACKET CONTENTS

    request.number = htonl(0xBEEF8F21);
    request.length = htons(sizeof(request));
    request.flags  = htonl(flags);
    if (pathname) { strncpy(request.pathname, pathname, 256); }
