1 #include "XDRInPacket.h" 2 #include <malloc.h> 3 #include <string.h> 4 #include <ByteOrder.h> 5 #include <KernelExport.h> 6 7 #include "nfs.h" 8 9 extern void 10 XDRInPacketInit(struct XDRInPacket *packet) 11 { 12 packet->fBuffer=NULL; 13 packet->fOffset=0; 14 } 15 16 extern void 17 XDRInPacketDestroy(struct XDRInPacket *packet) 18 { 19 free (packet->fBuffer); 20 } 21 22 extern int32 23 XDRInPacketGetInt32(struct XDRInPacket *packet) 24 { 25 int32 val=B_BENDIAN_TO_HOST_INT32(*((int32 *)&packet->fBuffer[packet->fOffset])); 26 27 packet->fOffset+=4; 28 29 return val; 30 } 31 32 extern int32 33 XDRInPacketGetFixed(struct XDRInPacket *packet, void *buffer, size_t len) 34 { 35 if (user_memcpy(buffer, &packet->fBuffer[packet->fOffset], len) 36 != B_OK) { 37 return NFSERR_IO; 38 } 39 40 packet->fOffset += (len + 3) & ~3; 41 return NFS_OK; 42 } 43 44 extern size_t 45 XDRInPacketGetDynamic(struct XDRInPacket *packet, void *buffer) 46 { 47 size_t size=XDRInPacketGetInt32(packet); 48 XDRInPacketGetFixed(packet,buffer,size); 49 return size; 50 } 51 52 extern char * 53 XDRInPacketGetString(struct XDRInPacket *packet) 54 { 55 int32 size=XDRInPacketGetInt32(packet); 56 char *string=(char *)malloc(size+1); 57 string[size]=0; 58 XDRInPacketGetFixed(packet,string,size); 59 60 return string; 61 } 62 63 extern void 64 XDRInPacketSetTo(struct XDRInPacket *packet, uint8 *buffer, size_t offset) 65 { 66 free (packet->fBuffer); 67 packet->fBuffer=buffer; 68 packet->fOffset=offset; 69 } 70