]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
HGFS: Clean up server packet abstraction part IV
authorVMware, Inc <>
Wed, 18 Sep 2013 03:15:31 +0000 (20:15 -0700)
committerDmitry Torokhov <dmitry.torokhov@gmail.com>
Mon, 23 Sep 2013 05:01:53 +0000 (22:01 -0700)
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 <dtor@vmware.com>
open-vm-tools/lib/hgfsServer/hgfsServer.c
open-vm-tools/lib/hgfsServer/hgfsServerInt.h
open-vm-tools/lib/hgfsServer/hgfsServerLinux.c
open-vm-tools/lib/hgfsServer/hgfsServerParameters.c
open-vm-tools/lib/hgfsServer/hgfsServerParameters.h

index d3569a2bf4b70b708c12b108a9f5a97e03515cfa..942ab58a31eb37219457fc81172f39a81e5bc184 100644 (file)
 /* 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);
 }
 
index 29616a5cddad0d5e43c0fae324a7c3c617588303..8a69ef9163bdbc93584f4e165abeb17124a87924 100644 (file)
@@ -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
index de4c4a6ae96362f172ff72a30add6b219157c352..96a7ef3e538da41f152ce77853a1cf58ce420d94 100644 (file)
@@ -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;
index e4dced47637e914820ba57c3b95817f3d9dfecc8..2a52ec89f70f1c46386a27011ca8c74a682c6b8a 100644 (file)
@@ -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;
    }
index c2958d220898f93612d1ee0aa26d4822e0490517..57a2ab3c1b749f35d13bcf2410458a69ba46695f 100644 (file)
@@ -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