VirtualBox

source: vbox/trunk/src/VBox/Additions/freebsd/vboxvfs/vboxvfs_vfsops.c@ 8170

Last change on this file since 8170 was 8155, checked in by vboxsync, 17 years ago

The Big Sun Rebranding Header Change

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.7 KB
Line 
1/* $Id: vboxvfs_vfsops.c 8155 2008-04-18 15:16:47Z vboxsync $ */
2/** @file
3 * Description.
4 */
5
6/*
7 * Copyright (C) 2008 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#include "vboxvfs.h"
23#include <sys/param.h>
24#include <sys/systm.h>
25#include <sys/proc.h>
26#include <sys/bio.h>
27#include <sys/buf.h>
28#include <sys/kernel.h>
29#include <sys/sysctl.h>
30#include <sys/vnode.h>
31#include <sys/mount.h>
32#include <sys/stat.h>
33#include <sys/malloc.h>
34#include <sys/module.h>
35
36#include <iprt/mem.h>
37
38#define VFSMP2SFGLOBINFO(mp) ((struct sf_glob_info *)mp->mnt_data)
39
40static int vboxvfs_version = VBOXVFS_VERSION;
41
42SYSCTL_NODE(_vfs, OID_AUTO, vboxvfs, CTLFLAG_RW, 0, "VirtualBox shared filesystem");
43SYSCTL_INT(_vfs_vboxvfs, OID_AUTO, version, CTLFLAG_RD, &vboxvfs_version, 0, "");
44
45/* global connection to the host service. */
46static VBSFCLIENT g_vboxSFClient;
47
48static vfs_init_t vboxvfs_init;
49static vfs_uninit_t vboxvfs_uninit;
50static vfs_cmount_t vboxvfs_cmount;
51static vfs_mount_t vboxvfs_mount;
52static vfs_root_t vboxvfs_root;
53static vfs_quotactl_t vboxvfs_quotactl;
54static vfs_statfs_t vboxvfs_statfs;
55static vfs_unmount_t vboxvfs_unmount;
56
57static struct vfsops vboxvfs_vfsops = {
58 .vfs_init = vboxvfs_init,
59 .vfs_cmount = vboxvfs_cmount,
60 .vfs_mount = vboxvfs_mount,
61 .vfs_quotactl = vboxvfs_quotactl,
62 .vfs_root = vboxvfs_root,
63 .vfs_statfs = vboxvfs_statfs,
64 .vfs_sync = vfs_stdsync,
65 .vfs_uninit = vboxvfs_uninit,
66 .vfs_unmount = vboxvfs_unmount,
67};
68
69
70VFS_SET(vboxvfs_vfsops, vboxvfs, VFCF_NETWORK);
71MODULE_DEPEND(vboxvfs, vboxguest, 1, 1, 1);
72
73static int
74vboxvfs_cmount(struct mntarg *ma, void * data, int flags, struct thread *td)
75{
76 struct vboxvfs_mount_info args;
77 int rc = 0;
78
79 printf("%s: Enter\n", __FUNCTION__);
80
81 rc = copyin(data, &args, sizeof(struct vboxvfs_mount_info));
82 if (rc)
83 return rc;
84
85 ma = mount_argf(ma, "uid", "%d", args.uid);
86 ma = mount_argf(ma, "gid", "%d", args.gid);
87 ma = mount_arg(ma, "from", args.name, -1);
88
89 rc = kernel_mount(ma, flags);
90
91 printf("%s: Leave rc=%d\n", __FUNCTION__, rc);
92
93 return rc;
94}
95
96static const char *vboxvfs_opts[] = {
97 "uid", "gid", "from", "fstype", "fspath", "errmsg", NULL
98};
99
100static int vboxvfs_mount(struct mount *mp, struct thread *td)
101{
102 int rc;
103 char *pszShare;
104 int cbShare, cbOption;
105 int uid = 0, gid = 0;
106 struct sf_glob_info *pShFlGlobalInfo;
107 SHFLSTRING *pShFlShareName = NULL;
108 int cbShFlShareName;
109
110 printf("%s: Enter\n", __FUNCTION__);
111
112 if (mp->mnt_flag & (MNT_UPDATE | MNT_ROOTFS))
113 return EOPNOTSUPP;
114
115 if (vfs_filteropt(mp->mnt_optnew, vboxvfs_opts))
116 {
117 vfs_mount_error(mp, "%s", "Invalid option");
118 return EINVAL;
119 }
120
121 rc = vfs_getopt(mp->mnt_optnew, "from", (void **)&pszShare, &cbShare);
122 if (rc || pszShare[cbShare-1] != '\0' || cbShare > 0xfffe)
123 return EINVAL;
124
125 rc = vfs_getopt(mp->mnt_optnew, "gid", (void **)&gid, &cbOption);
126 if ((rc != ENOENT) && (rc || cbOption != sizeof(gid)))
127 return EINVAL;
128
129 rc = vfs_getopt(mp->mnt_optnew, "uid", (void **)&uid, &cbOption);
130 if ((rc != ENOENT) && (rc || cbOption != sizeof(uid)))
131 return EINVAL;
132
133 pShFlGlobalInfo = RTMemAllocZ(sizeof(struct sf_glob_info));
134 if (!pShFlGlobalInfo)
135 return ENOMEM;
136
137 cbShFlShareName = offsetof (SHFLSTRING, String.utf8) + cbShare + 1;
138 pShFlShareName = RTMemAllocZ(cbShFlShareName);
139 if (!pShFlShareName)
140 return VERR_NO_MEMORY;
141
142 pShFlShareName->u16Length = cbShFlShareName;
143 pShFlShareName->u16Size = cbShFlShareName + 1;
144 memcpy (pShFlShareName->String.utf8, pszShare, cbShare + 1);
145
146 rc = vboxCallMapFolder (&g_vboxSFClient, pShFlShareName, &pShFlGlobalInfo->map);
147 RTMemFree(pShFlShareName);
148
149 if (VBOX_FAILURE (rc))
150 {
151 RTMemFree(pShFlGlobalInfo);
152 printf("vboxCallMapFolder failed rc=%d\n", rc);
153 return EPROTO;
154 }
155
156 pShFlGlobalInfo->uid = uid;
157 pShFlGlobalInfo->gid = gid;
158
159 mp->mnt_data = pShFlGlobalInfo;
160
161 /* @todo root vnode. */
162
163 vfs_getnewfsid(mp);
164 vfs_mountedfrom(mp, pszShare);
165
166 printf("%s: Leave rc=0\n", __FUNCTION__);
167
168 return 0;
169}
170
171static int vboxvfs_unmount(struct mount *mp, int mntflags, struct thread *td)
172{
173 struct sf_glob_info *pShFlGlobalInfo = VFSMP2SFGLOBINFO(mp);
174 int rc;
175 int flags = 0;
176
177 rc = vboxCallUnmapFolder(&g_vboxSFClient, &pShFlGlobalInfo->map);
178 if (VBOX_FAILURE(rc))
179 printf("Failed to unmap shared folder\n");
180
181 if (mntflags & MNT_FORCE)
182 flags |= FORCECLOSE;
183
184 /* There is 1 extra root vnode reference (vnode_root). */
185 rc = vflush(mp, 1, flags, td);
186 if (rc)
187 return rc;
188
189
190 RTMemFree(pShFlGlobalInfo);
191 mp->mnt_data = NULL;
192
193 return 0;
194}
195
196static int vboxvfs_root(struct mount *mp, int flags, struct vnode **vpp, struct thread *td)
197{
198 int rc = 0;
199 struct sf_glob_info *pShFlGlobalInfo = VFSMP2SFGLOBINFO(mp);
200 struct vnode *vp;
201
202 printf("%s: Enter\n", __FUNCTION__);
203
204 vp = pShFlGlobalInfo->vnode_root;
205 VREF(vp);
206
207 vn_lock(vp, flags | LK_RETRY, td);
208 *vpp = vp;
209
210 printf("%s: Leave\n", __FUNCTION__);
211
212 return rc;
213}
214
215static int vboxvfs_quotactl(mp, cmd, uid, arg, td)
216 struct mount *mp;
217 int cmd;
218 uid_t uid;
219 void *arg;
220 struct thread *td;
221{
222 return EOPNOTSUPP;
223}
224
225int vboxvfs_init(struct vfsconf *vfsp)
226{
227 int rc;
228
229 /* Initialize the R0 guest library. */
230 rc = vboxInit();
231 if (VBOX_FAILURE(rc))
232 return ENXIO;
233
234 /* Connect to the host service. */
235 rc = vboxConnect(&g_vboxSFClient);
236 if (VBOX_FAILURE(rc))
237 {
238 printf("Failed to get connection to host! rc=%d\n", rc);
239 vboxUninit();
240 return ENXIO;
241 }
242
243 rc = vboxCallSetUtf8 (&g_vboxSFClient);
244 if (VBOX_FAILURE (rc))
245 {
246 printf("vboxCallSetUtf8 failed, rc=%d\n", rc);
247 vboxDisconnect(&g_vboxSFClient);
248 vboxUninit();
249 return EPROTO;
250 }
251
252 printf("Successfully loaded shared folder module\n");
253
254 return 0;
255}
256
257int vboxvfs_uninit(struct vfsconf *vfsp)
258{
259 vboxDisconnect(&g_vboxSFClient);
260 vboxUninit();
261
262 return 0;
263}
264
265int vboxvfs_statfs(struct mount *mp, struct statfs *sbp, struct thread *td)
266{
267 return 0;
268}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette