From: VMware, Inc <> Date: Wed, 18 Sep 2013 03:15:31 +0000 (-0700) Subject: HGFS: Clean up server packet abstraction part IV X-Git-Tag: 2013.09.16-1328054~108 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e8c800081d0339e10641e216e78ad9b47e4d5afa;p=thirdparty%2Fopen-vm-tools.git HGFS: Clean up server packet abstraction part IV Complete some tidy up of the input params created from the HgfsPacket. This can be contained to only the HgfsServer code and not required to be exposed beyond that. So this removes the one usage from the parameter pack and unpack code which was in the unpack write request. As I was modifying up the HGFS server write request I correct a couple of const char * to const void * for the write data. I removed a HSPU_PutPacket declaration as the function did not exist. Signed-off-by: Dmitry Torokhov --- diff --git a/open-vm-tools/lib/hgfsServer/hgfsServer.c b/open-vm-tools/lib/hgfsServer/hgfsServer.c index d3569a2bf..942ab58a3 100644 --- a/open-vm-tools/lib/hgfsServer/hgfsServer.c +++ b/open-vm-tools/lib/hgfsServer/hgfsServer.c @@ -129,6 +129,22 @@ /* Default maximun number of open nodes that have server locks. */ #define MAX_LOCKED_FILENODES 10 + +/* The input request paramaters object. */ +typedef struct HgfsInputParam { + const void *request; /* Hgfs header followed by operation request */ + size_t requestSize; /* Size of Hgfs header and operation request */ + HgfsSessionInfo *session; /* Hgfs session data */ + HgfsTransportSessionInfo *transportSession; + HgfsPacket *packet; /* Public (server/transport) Hgfs packet */ + void const *payload; /* Hgfs operation request */ + uint32 payloadOffset; /* Offset to start of Hgfs operation request */ + size_t payloadSize; /* Hgfs operation request size */ + HgfsOp op; /* Hgfs operation command code */ + uint32 id; /* Request ID to be matched with the reply */ + Bool sessionEnabled; /* Requests have session enabled headers */ +} HgfsInputParam; + /* * The HGFS server configurable settings. * (Note: the guest sets these to all defaults only modifiable from the VMX.) @@ -5866,28 +5882,44 @@ HgfsServerWrite(HgfsInputParam *input) // IN: Input params HgfsInternalStatus status; HgfsWriteFlags flags; uint64 offset; - const char *dataToWrite; + const void *dataToWrite; uint32 replyActualSize; size_t replyPayloadSize = 0; HgfsHandle file; HGFS_ASSERT_INPUT(input); - if (HgfsUnpackWriteRequest(input, &file, &offset, &numberBytesToWrite, - &flags, &dataToWrite)) { + if (!HgfsUnpackWriteRequest(input->payload, input->payloadSize, input->op, + &file, &offset, &numberBytesToWrite, &flags, + &dataToWrite)) { + LOG(4, ("%s: Error: Op %d unpack write request arguments\n", __FUNCTION__, input->op)); + status = HGFS_ERROR_PROTOCOL; + goto exit; + } - status = HgfsPlatformWriteFile(file, input->session, offset, numberBytesToWrite, - flags, (void *)dataToWrite, &replyActualSize); - if (HGFS_ERROR_SUCCESS == status) { - if (!HgfsPackWriteReply(input->packet, input->request, input->op, - replyActualSize, &replyPayloadSize, input->session)) { - status = HGFS_ERROR_INTERNAL; - } + if (NULL == dataToWrite) { + /* No inline data to write, get it from the transport shared memory. */ + dataToWrite = HSPU_GetDataPacketBuf(input->packet, BUF_READABLE, + input->transportSession); + if (NULL == dataToWrite) { + LOG(4, ("%s: Error: Op %d mapping write data buffer\n", __FUNCTION__, input->op)); + status = HGFS_ERROR_PROTOCOL; + goto exit; } - } else { - status = HGFS_ERROR_PROTOCOL; } + status = HgfsPlatformWriteFile(file, input->session, offset, numberBytesToWrite, + flags, dataToWrite, &replyActualSize); + if (HGFS_ERROR_SUCCESS != status) { + goto exit; + } + + if (!HgfsPackWriteReply(input->packet, input->request, input->op, + replyActualSize, &replyPayloadSize, input->session)) { + status = HGFS_ERROR_INTERNAL; + } + +exit: HgfsServerCompleteRequest(status, replyPayloadSize, input); } diff --git a/open-vm-tools/lib/hgfsServer/hgfsServerInt.h b/open-vm-tools/lib/hgfsServer/hgfsServerInt.h index 29616a5cd..8a69ef916 100644 --- a/open-vm-tools/lib/hgfsServer/hgfsServerInt.h +++ b/open-vm-tools/lib/hgfsServer/hgfsServerInt.h @@ -476,21 +476,6 @@ typedef struct HgfsCreateSessionInfo { HgfsSessionFlags flags; /* Session capability flags. */ } HgfsCreateSessionInfo; - -typedef struct HgfsInputParam { - const void *request; /* Hgfs header followed by operation request */ - size_t requestSize; /* Size of Hgfs header and operation request */ - HgfsSessionInfo *session; /* Hgfs session data */ - HgfsTransportSessionInfo *transportSession; - HgfsPacket *packet; /* Public (server/transport) Hgfs packet */ - void const *payload; /* Hgfs operation request */ - uint32 payloadOffset; /* Offset to start of Hgfs operation request */ - size_t payloadSize; /* Hgfs operation request size */ - HgfsOp op; /* Hgfs operation command code */ - uint32 id; /* Request ID to be matched with the reply */ - Bool sessionEnabled; /* Requests have session enabled headers */ -} HgfsInputParam; - Bool HgfsCreateAndCacheFileNode(HgfsFileOpenInfo *openInfo, // IN: Open info struct HgfsLocalId const *localId, // IN: Local unique file ID @@ -810,7 +795,7 @@ HgfsPlatformWriteFile(HgfsHandle file, // IN: Hgfs file handle uint64 offset, // IN: file offset to write to uint32 requiredSize, // IN: length of data to write HgfsWriteFlags flags, // IN: write flags - void* payload, // IN: data to be written + const void *payload, // IN: data to be written uint32 *actualSize); // OUT: actual length written HgfsInternalStatus HgfsPlatformWriteWin32Stream(HgfsHandle file, // IN: packet header @@ -898,10 +883,6 @@ HSPU_GetDataPacketBuf(HgfsPacket *packet, // IN/OUT: Hgfs Packet MappingType mappingType, // IN: Readable/ Writeable ? HgfsTransportSessionInfo *transportSession); // IN: Session Info -void -HSPU_PutPacket(HgfsPacket *packet, // IN/OUT: Hgfs Packet - HgfsTransportSessionInfo *transportSession); // IN: Session Info - void HSPU_PutDataPacketBuf(HgfsPacket *packet, // IN/OUT: Hgfs Packet HgfsTransportSessionInfo *transportSession); // IN: Session Info diff --git a/open-vm-tools/lib/hgfsServer/hgfsServerLinux.c b/open-vm-tools/lib/hgfsServer/hgfsServerLinux.c index de4c4a6ae..96a7ef3e5 100644 --- a/open-vm-tools/lib/hgfsServer/hgfsServerLinux.c +++ b/open-vm-tools/lib/hgfsServer/hgfsServerLinux.c @@ -4136,7 +4136,7 @@ HgfsPlatformWriteFile(HgfsHandle file, // IN: Hgfs file handle uint64 offset, // IN: file offset to write to uint32 requiredSize, // IN: length of data to write HgfsWriteFlags flags, // IN: write flags - void* payload, // IN: data to be written + const void *payload, // IN: data to be written uint32 *actualSize) // OUT: actual length written { HgfsInternalStatus status; diff --git a/open-vm-tools/lib/hgfsServer/hgfsServerParameters.c b/open-vm-tools/lib/hgfsServer/hgfsServerParameters.c index e4dced476..2a52ec89f 100644 --- a/open-vm-tools/lib/hgfsServer/hgfsServerParameters.c +++ b/open-vm-tools/lib/hgfsServer/hgfsServerParameters.c @@ -4287,7 +4287,7 @@ HgfsUnpackWritePayload(const HgfsRequestWrite *request, // IN: request payloa uint64 *offset, // OUT: offset to read from uint32 *length, // OUT: length of data to write HgfsWriteFlags *flags, // OUT: write flags - const char **data) // OUT: data to be written + const void **data) // OUT: data to be written { LOG(4, ("%s: HGFS_OP_WRITE\n", __FUNCTION__)); if (payloadSize >= sizeof *request) { @@ -4329,7 +4329,7 @@ HgfsUnpackWritePayloadV3(const HgfsRequestWriteV3 *requestV3, // IN: payload uint64 *offset, // OUT: offset to read from uint32 *length, // OUT: length of data to write HgfsWriteFlags *flags, // OUT: write flags - const char **data) // OUT: data to be written + const void **data) // OUT: data to be written { LOG(4, ("%s: HGFS_OP_WRITE_V3\n", __FUNCTION__)); if (payloadSize >= sizeof *requestV3) { @@ -4405,50 +4405,42 @@ HgfsUnpackWriteFastPayloadV4(const HgfsRequestWriteV3 *requestV3, // IN: payload */ Bool -HgfsUnpackWriteRequest(HgfsInputParam *input, // IN: Input params +HgfsUnpackWriteRequest(void const *writeRequest,// IN: write request params + size_t writeRequestSize, // IN: write request params size + HgfsOp writeOp, // IN: request version HgfsHandle *file, // OUT: Handle to write to uint64 *offset, // OUT: offset to write to uint32 *length, // OUT: length of data to write HgfsWriteFlags *flags, // OUT: write flags - const char **data) // OUT: data to be written + const void **data) // OUT: data to be written { Bool result; - ASSERT(input); - - switch (input->op) { + switch (writeOp) { case HGFS_OP_WRITE_FAST_V4: { - const HgfsRequestWriteV3 *requestV3 = input->payload; + const HgfsRequestWriteV3 *requestV3 = writeRequest; - result = HgfsUnpackWriteFastPayloadV4(requestV3, input->payloadSize, file, + *data = NULL; /* Write data is retrieved from shared memory. */ + result = HgfsUnpackWriteFastPayloadV4(requestV3, writeRequestSize, file, offset, length, flags); - if (result) { - *data = HSPU_GetDataPacketBuf(input->packet, - BUF_READABLE, - input->transportSession); - if (NULL == *data) { - LOG(4, ("%s: Failed to get data in guest memory\n", __FUNCTION__)); - result = FALSE; - } - } break; } case HGFS_OP_WRITE_V3: { - const HgfsRequestWriteV3 *requestV3 = input->payload; + const HgfsRequestWriteV3 *requestV3 = writeRequest; - result = HgfsUnpackWritePayloadV3(requestV3, input->payloadSize, file, offset, + result = HgfsUnpackWritePayloadV3(requestV3, writeRequestSize, file, offset, length, flags, data); break; } case HGFS_OP_WRITE: { - const HgfsRequestWrite *requestV1 = input->payload; + const HgfsRequestWrite *requestV1 = writeRequest; - result = HgfsUnpackWritePayload(requestV1, input->payloadSize, file, offset, + result = HgfsUnpackWritePayload(requestV1, writeRequestSize, file, offset, length, flags, data); break; } default: - LOG(4, ("%s: Incorrect opcode %d\n", __FUNCTION__, input->op)); + LOG(4, ("%s: Incorrect opcode %d\n", __FUNCTION__, writeOp)); NOT_REACHED(); result = FALSE; } diff --git a/open-vm-tools/lib/hgfsServer/hgfsServerParameters.h b/open-vm-tools/lib/hgfsServer/hgfsServerParameters.h index c2958d220..57a2ab3c1 100644 --- a/open-vm-tools/lib/hgfsServer/hgfsServerParameters.h +++ b/open-vm-tools/lib/hgfsServer/hgfsServerParameters.h @@ -288,12 +288,14 @@ HgfsUnpackReadRequest(void const *packet, // IN: HGFS request uint64 *offset, // OUT: offset to read from uint32 *length); // OUT: length of data to read Bool -HgfsUnpackWriteRequest(HgfsInputParam *input, // IN: Input params +HgfsUnpackWriteRequest(void const *writeRequest,// IN: HGFS write request params + size_t writeRequestSize, // IN: write request params size + HgfsOp writeOp, // IN: request version HgfsHandle *file, // OUT: Handle to write to uint64 *offset, // OUT: offset to write to uint32 *length, // OUT: length of data to write HgfsWriteFlags *flags, // OUT: write flags - const char **data); // OUT: data to be written + const void **data); // OUT: data to be written Bool HgfsPackCreateSessionReply(HgfsPacket *packet, // IN/OUT: Hgfs Packet void const *packetHeader, // IN: packet header