~henrix/ubuntu/precise/open-vm-dkms/lp-1416003

« back to all changes in this revision

Viewing changes to modules/freebsd/vmhgfs/vfsopscommon.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2008-10-23 15:32:00 UTC
  • mfrom: (1.1.2 upstream) (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20081023153200-gc1bfx89hj35c799
Tags: 2008.10.10-123053-2
* Correcting typo in dh_installinit call.
* Downgrading depends on module-assistant to recommends.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************
 
2
 * Copyright (C) 2008 VMware, Inc. All rights reserved.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify it
 
5
 * under the terms of the GNU General Public License as published by the
 
6
 * Free Software Foundation version 2 and no later version.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 
10
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 
11
 * for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License along
 
14
 * with this program; if not, write to the Free Software Foundation, Inc.,
 
15
 * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 
16
 *
 
17
 *********************************************************/
 
18
 
 
19
/*
 
20
 * vnopscommon.h --
 
21
 *
 
22
 * Common VFS vfsop implementations that are shared between both OS X and FreeBSD.
 
23
 */
 
24
 
 
25
#include <sys/param.h>          // for everything
 
26
#include <sys/vnode.h>          // for struct vnode
 
27
 
 
28
#include "fsutil.h"
 
29
#include "state.h"
 
30
#include "debug.h"
 
31
#include "request.h"
 
32
#include "vnopscommon.h"
 
33
#include "vfsopscommon.h"
 
34
 
 
35
/*
 
36
 *----------------------------------------------------------------------------
 
37
 *
 
38
 * HgfsStatfsInt --
 
39
 * 
 
40
 *      Hgfs statfs method. Called by HgfsVfsStatfs on FreeBSD and
 
41
 *      HgfsVfsGetattr on OS X.
 
42
 *
 
43
 * Results:
 
44
 *      Returns 0 on success and an error code on error.
 
45
 *
 
46
 * Side effects:
 
47
 *      None.
 
48
 *
 
49
 *----------------------------------------------------------------------------
 
50
 */
 
51
 
 
52
int
 
53
HgfsStatfsInt(struct vnode *vp,          // IN: vnode
 
54
              HgfsStatfs *stat)          // IN: statfs structure to fill in
 
55
{
 
56
   HgfsSuperInfo *sip;
 
57
   HgfsKReqHandle req;
 
58
   HgfsRequest *requestHeader;
 
59
   HgfsReply *replyHeader;
 
60
   HgfsRequestQueryVolumeV3 *request;
 
61
   HgfsReplyQueryVolumeV3 *reply;
 
62
   uint32 reqSize;
 
63
   uint32 reqBufferSize;
 
64
   uint32 repSize;
 
65
   char *fullPath = NULL;
 
66
   uint32 fullPathLen;
 
67
   int ret = 0;
 
68
 
 
69
   /* Get pointer to the superinfo. */
 
70
   sip = HGFS_VP_TO_SIP(vp);
 
71
   if (!sip) {
 
72
      DEBUG(VM_DEBUG_FAIL, "couldn't acquire superinfo\n");
 
73
      return ENOTSUP;
 
74
   }
 
75
 
 
76
   /* Prepare the request */
 
77
   req = HgfsKReq_AllocateRequest(sip->reqs);
 
78
   if (!req) {
 
79
      return ENOMEM;
 
80
   }
 
81
 
 
82
   requestHeader = (HgfsRequest *)HgfsKReq_GetPayload(req);
 
83
   request = (HgfsRequestQueryVolumeV3 *)HGFS_REQ_GET_PAYLOAD_V3(requestHeader);
 
84
 
 
85
   /* Initialize the request header */
 
86
   requestHeader->id = HgfsKReq_GetId(req);
 
87
   requestHeader->op = HGFS_OP_QUERY_VOLUME_INFO_V3;
 
88
 
 
89
   request->fileName.flags = 0;
 
90
   request->fileName.fid = HGFS_INVALID_HANDLE;
 
91
   request->fileName.caseType = HGFS_FILE_NAME_CASE_SENSITIVE;
 
92
   request->reserved = 0;
 
93
 
 
94
   reqSize = HGFS_REQ_PAYLOAD_SIZE_V3(request);
 
95
   reqBufferSize = HGFS_NAME_BUFFER_SIZET(reqSize);
 
96
 
 
97
   fullPath = HGFS_VP_TO_FILENAME(vp);
 
98
   fullPathLen = HGFS_VP_TO_FILENAME_LENGTH(vp);
 
99
 
 
100
   ret = HgfsNameToWireEncoding(fullPath, fullPathLen + 1,
 
101
                                request->fileName.name,
 
102
                                reqBufferSize);
 
103
   if (ret < 0) {
 
104
      DEBUG(VM_DEBUG_FAIL, "Could not encode to wire format");
 
105
      ret = -ret;
 
106
      goto destroyOut;
 
107
   }
 
108
   request->fileName.length = ret;
 
109
   reqSize += ret;
 
110
 
 
111
   /* The request size includes header, request and file length */
 
112
   HgfsKReq_SetPayloadSize(req, reqSize);
 
113
 
 
114
   ret = HgfsSubmitRequest(sip, req);
 
115
 
 
116
   if (ret) {
 
117
      /* HgfsSubmitRequest() destroys the request if necessary */
 
118
 
 
119
      goto out;
 
120
   }
 
121
 
 
122
   replyHeader = (HgfsReply *)HgfsKReq_GetPayload(req);
 
123
   reply = (HgfsReplyQueryVolumeV3 *)HGFS_REP_GET_PAYLOAD_V3(replyHeader);
 
124
   repSize = HGFS_REP_PAYLOAD_SIZE_V3(reply);
 
125
 
 
126
   ret = HgfsGetStatus(req, repSize);
 
127
   if (ret) {
 
128
      DEBUG(VM_DEBUG_FAIL, "reply was invalid");
 
129
      goto destroyOut;
 
130
   }
 
131
 
 
132
   ret = HgfsStatusToBSD(replyHeader->status);
 
133
 
 
134
   if (ret) {
 
135
      goto destroyOut;
 
136
   }
 
137
 
 
138
   stat->f_bsize = HGFS_BLOCKSIZE;
 
139
   stat->f_iosize = HGFS_BLOCKSIZE;
 
140
   stat->f_blocks = HGFS_CONVERT_TO_BLOCKS(reply->totalBytes);
 
141
   stat->f_bfree = HGFS_CONVERT_TO_BLOCKS(reply->freeBytes);
 
142
   stat->f_bavail = stat->f_bfree;
 
143
 
 
144
destroyOut:
 
145
   HgfsKReq_ReleaseRequest(sip->reqs, req);
 
146
out:
 
147
   return ret;
 
148
}