1*433d6423SLionel Sambuc /* Part of libhgfs - (c) 2009, D.C. van Moolenbroek */ 2*433d6423SLionel Sambuc 3*433d6423SLionel Sambuc /* Various macros used here and there */ 4*433d6423SLionel Sambuc #define MAKELONG(a,b) ((a) | ((b) << 16)) 5*433d6423SLionel Sambuc #define HIWORD(d) ((d) >> 16) 6*433d6423SLionel Sambuc #define LOWORD(d) ((d) & 0xffff) 7*433d6423SLionel Sambuc #define BYTES(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24)) 8*433d6423SLionel Sambuc 9*433d6423SLionel Sambuc /* Valid channel types for channel_open() */ 10*433d6423SLionel Sambuc #define CH_IN BYTES('T', 'C', 'L', 'O') 11*433d6423SLionel Sambuc #define CH_OUT BYTES('R', 'P', 'C', 'I') 12*433d6423SLionel Sambuc 13*433d6423SLionel Sambuc /* RPC constants */ 14*433d6423SLionel Sambuc #define RPC_BUF_SIZE 6134 /* max size of RPC request */ 15*433d6423SLionel Sambuc #define RPC_HDR_SIZE 10 /* RPC HGFS header size */ 16*433d6423SLionel Sambuc 17*433d6423SLionel Sambuc /* RPC macros. These NEED NOT be portable. VMware only does x86(-64) anyway. */ 18*433d6423SLionel Sambuc /* ..all this because ACK can't pack structures :( */ 19*433d6423SLionel Sambuc #define RPC_NEXT8 *(((u8_t*)(++rpc_ptr))-1) /* get/set next byte */ 20*433d6423SLionel Sambuc #define RPC_NEXT16 *(((u16_t*)(rpc_ptr+=2))-1) /* get/set next short */ 21*433d6423SLionel Sambuc #define RPC_NEXT32 *(((u32_t*)(rpc_ptr+=4))-1) /* get/set next long */ 22*433d6423SLionel Sambuc #define RPC_LEN (rpc_ptr - rpc_buf) /* request length thus far */ 23*433d6423SLionel Sambuc #define RPC_ADVANCE(n) rpc_ptr += n /* skip n bytes in buffer */ 24*433d6423SLionel Sambuc #define RPC_PTR (rpc_ptr) /* pointer to next data */ 25*433d6423SLionel Sambuc #define RPC_RESET rpc_ptr = rpc_buf /* start at beginning */ 26*433d6423SLionel Sambuc #define RPC_REQUEST(r) \ 27*433d6423SLionel Sambuc RPC_RESET; \ 28*433d6423SLionel Sambuc RPC_NEXT8 = 'f'; \ 29*433d6423SLionel Sambuc RPC_NEXT8 = ' '; \ 30*433d6423SLionel Sambuc RPC_NEXT32 = 0; \ 31*433d6423SLionel Sambuc RPC_NEXT32 = r; /* start a RPC request */ 32*433d6423SLionel Sambuc 33*433d6423SLionel Sambuc /* HGFS requests */ 34*433d6423SLionel Sambuc enum { 35*433d6423SLionel Sambuc HGFS_REQ_OPEN, 36*433d6423SLionel Sambuc HGFS_REQ_READ, 37*433d6423SLionel Sambuc HGFS_REQ_WRITE, 38*433d6423SLionel Sambuc HGFS_REQ_CLOSE, 39*433d6423SLionel Sambuc HGFS_REQ_OPENDIR, 40*433d6423SLionel Sambuc HGFS_REQ_READDIR, 41*433d6423SLionel Sambuc HGFS_REQ_CLOSEDIR, 42*433d6423SLionel Sambuc HGFS_REQ_GETATTR, 43*433d6423SLionel Sambuc HGFS_REQ_SETATTR, 44*433d6423SLionel Sambuc HGFS_REQ_MKDIR, 45*433d6423SLionel Sambuc HGFS_REQ_UNLINK, 46*433d6423SLionel Sambuc HGFS_REQ_RMDIR, 47*433d6423SLionel Sambuc HGFS_REQ_RENAME, 48*433d6423SLionel Sambuc HGFS_REQ_QUERYVOL 49*433d6423SLionel Sambuc }; 50*433d6423SLionel Sambuc 51*433d6423SLionel Sambuc /* HGFS open types */ 52*433d6423SLionel Sambuc enum { 53*433d6423SLionel Sambuc HGFS_OPEN_TYPE_O, 54*433d6423SLionel Sambuc HGFS_OPEN_TYPE_OT, 55*433d6423SLionel Sambuc HGFS_OPEN_TYPE_CO, 56*433d6423SLionel Sambuc HGFS_OPEN_TYPE_C, 57*433d6423SLionel Sambuc HGFS_OPEN_TYPE_COT 58*433d6423SLionel Sambuc }; 59*433d6423SLionel Sambuc 60*433d6423SLionel Sambuc /* HGFS mode/perms conversion macros */ 61*433d6423SLionel Sambuc #define HGFS_MODE_TO_PERM(m) (((m) & S_IRWXU) >> 6) 62*433d6423SLionel Sambuc #define HGFS_PERM_TO_MODE(p) (((p) << 6) & S_IRWXU) 63*433d6423SLionel Sambuc 64*433d6423SLionel Sambuc /* HGFS attribute flags */ 65*433d6423SLionel Sambuc #define HGFS_ATTR_SIZE 0x01 /* get/set file size */ 66*433d6423SLionel Sambuc #define HGFS_ATTR_CRTIME 0x02 /* get/set file creation time */ 67*433d6423SLionel Sambuc #define HGFS_ATTR_ATIME 0x04 /* get/set file access time */ 68*433d6423SLionel Sambuc #define HGFS_ATTR_MTIME 0x08 /* get/set file modification time */ 69*433d6423SLionel Sambuc #define HGFS_ATTR_CTIME 0x10 /* get/set file change time */ 70*433d6423SLionel Sambuc #define HGFS_ATTR_MODE 0x20 /* get/set file mode */ 71*433d6423SLionel Sambuc #define HGFS_ATTR_ATIME_SET 0x40 /* set specific file access time */ 72*433d6423SLionel Sambuc #define HGFS_ATTR_MTIME_SET 0x80 /* set specific file modify time */ 73