/usr/src/open-vm-tools-10.0.7/vmhgfs/request.c is in open-vm-tools-dkms 2:10.0.7-3227872-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | /*********************************************************
* Copyright (C) 2006-2015 VMware, Inc. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation version 2 and no later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*********************************************************/
/*
* request.c --
*
* Functions dealing with the creation, deletion, and sending of HGFS
* requests are defined here.
*/
/* Must come before any kernel header file. */
#include "driver-config.h"
#include <asm/atomic.h>
#include <linux/list.h>
#include <linux/signal.h>
#include "compat_kernel.h"
#include "compat_sched.h"
#include "compat_semaphore.h"
#include "compat_slab.h"
#include "compat_spinlock.h"
#include "module.h"
#include "request.h"
#include "transport.h"
#include "fsutil.h"
#include "vm_assert.h"
/*
*----------------------------------------------------------------------
*
* HgfsRequestInit --
*
* Initializes new request structure.
*
* Results:
* None
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
static void
HgfsRequestInit(HgfsReq *req, // IN: request to initialize
int requestId) // IN: ID assigned to the request
{
ASSERT(req);
kref_init(&req->kref);
INIT_LIST_HEAD(&req->list);
init_waitqueue_head(&req->queue);
req->id = requestId;
req->payloadSize = 0;
req->state = HGFS_REQ_STATE_ALLOCATED;
req->numEntries = 0;
}
/*
*----------------------------------------------------------------------
*
* HgfsGetNewRequest --
*
* Allocates and initializes new request structure.
*
* Results:
* On success the new struct is returned with all fields
* initialized. Returns NULL on failure.
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
HgfsReq *
HgfsGetNewRequest(void)
{
static atomic_t hgfsIdCounter = ATOMIC_INIT(0);
HgfsReq *req;
req = HgfsTransportAllocateRequest(HGFS_PACKET_MAX);
if (req == NULL) {
LOG(4, (KERN_DEBUG "VMware hgfs: %s: can't allocate memory\n", __func__));
return NULL;
}
HgfsRequestInit(req, atomic_inc_return(&hgfsIdCounter) - 1);
return req;
}
/*
*----------------------------------------------------------------------
*
* HgfsCopyRequest --
*
* Allocates and initializes new request structure and copies
* existing request into it.
*
* Results:
* On success the new struct is returned with all fields
* initialized. Returns NULL on failure.
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
HgfsReq *
HgfsCopyRequest(HgfsReq *req) // IN: request to be copied
{
HgfsReq *newReq;
ASSERT(req);
newReq = HgfsTransportAllocateRequest(req->bufferSize);
if (newReq == NULL) {
LOG(4, (KERN_DEBUG "VMware hgfs: %s: can't allocate memory\n", __func__));
return NULL;
}
HgfsRequestInit(newReq, req->id);
memcpy(newReq->dataPacket, req->dataPacket,
req->numEntries * sizeof (req->dataPacket[0]));
newReq->numEntries = req->numEntries;
newReq->payloadSize = req->payloadSize;
memcpy(newReq->payload, req->payload, req->payloadSize);
return newReq;
}
/*
*----------------------------------------------------------------------
*
* HgfsSendRequest --
*
* Send out an HGFS request via transport layer, and wait for the reply.
*
* Results:
* Returns zero on success, negative number on error.
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
int
HgfsSendRequest(HgfsReq *req) // IN/OUT: Outgoing request
{
int ret;
ASSERT(req);
ASSERT(req->payloadSize <= req->bufferSize);
req->state = HGFS_REQ_STATE_UNSENT;
LOG(10, (KERN_DEBUG "VMware hgfs: HgfsSendRequest: Sending request id %d\n",
req->id));
ret = HgfsTransportSendRequest(req);
LOG(10, (KERN_DEBUG "VMware hgfs: HgfsSendRequest: request finished, "
"return %d\n", ret));
return ret;
}
/*
*----------------------------------------------------------------------
*
* HgfsRequestFreeMemory --
*
* Frees memory allocated for a request.
*
* Results:
* None
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
static void HgfsRequestFreeMemory(struct kref *kref)
{
HgfsReq *req = container_of(kref, HgfsReq, kref);
LOG(10, (KERN_DEBUG "VMware hgfs: %s: freeing request %d\n",
__func__, req->id));
HgfsTransportFreeRequest(req);
}
/*
*----------------------------------------------------------------------
*
* HgfsRequestPutRef --
*
* Decrease reference count of HGFS request.
*
* Results:
* None
*
* Side effects:
* May cause request to be destroyed.
*
*----------------------------------------------------------------------
*/
void
HgfsRequestPutRef(HgfsReq *req) // IN: Request
{
if (req) {
LOG(10, (KERN_DEBUG "VMware hgfs: %s: request %d\n",
__func__, req->id));
kref_put(&req->kref, HgfsRequestFreeMemory);
}
}
/*
*----------------------------------------------------------------------
*
* HgfsRequestGetRef --
*
* Increment reference count of HGFS request.
*
* Results:
* Pointer to the same HGFS request.
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
HgfsReq *
HgfsRequestGetRef(HgfsReq *req) // IN: Request
{
if (req) {
LOG(10, (KERN_DEBUG "VMware hgfs: %s: request %d\n",
__func__, req->id));
kref_get(&req->kref);
}
return req;
}
/*
*----------------------------------------------------------------------
*
* HgfsReplyStatus --
*
* Return reply status.
*
* Results:
* Returns reply status as per the protocol.
* XXX: Needs changes when vmci headers are added.
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
HgfsStatus
HgfsReplyStatus(HgfsReq *req) // IN
{
HgfsReply *rep;
rep = (HgfsReply *)(HGFS_REQ_PAYLOAD(req));
return rep->status;
}
/*
*----------------------------------------------------------------------
*
* HgfsCompleteReq --
*
* Marks request as completed and wakes up sender.
*
* Results:
* None
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
void
HgfsCompleteReq(HgfsReq *req) // IN: Request
{
ASSERT(req);
req->state = HGFS_REQ_STATE_COMPLETED;
/* Wake up the client process waiting for the reply to this request. */
wake_up(&req->queue);
}
/*
*----------------------------------------------------------------------
*
* HgfsFailReq --
*
* Marks request as failed and calls HgfsCompleteReq to wake up
* sender.
*
* Results:
* None
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
void HgfsFailReq(HgfsReq *req, // IN: erequest to be marked failed
int error) // IN: error code
{
HgfsReply *reply = req->payload;
reply->id = req->id;
reply->status = error;
req->payloadSize = sizeof *reply;
HgfsCompleteReq(req);
}
|