VirtualBox

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

Last change on this file since 12474 was 8188, checked in by vboxsync, 17 years ago

Additions/FreeBSD: Cleanup, rename variables to follow coding guidlines, removed session hash table and use device cloning instead

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 6.7 KB
Line 
1/* $Id: vboxvfs_vfsops.c 8188 2008-04-19 20:27:39Z 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 vboxvfs_cmount(struct mntarg *ma, void * data, int flags, struct thread *td)
74{
75 struct vboxvfs_mount_info args;
76 int rc = 0;
77
78 printf("%s: Enter\n", __FUNCTION__);
79
80 rc = copyin(data, &args, sizeof(struct vboxvfs_mount_info));
81 if (rc)
82 return rc;
83
84 ma = mount_argf(ma, "uid", "%d", args.uid);
85 ma = mount_argf(ma, "gid", "%d", args.gid);
86 ma = mount_arg(ma, "from", args.name, -1);
87
88 rc = kernel_mount(ma, flags);
89
90 printf("%s: Leave rc=%d\n", __FUNCTION__, rc);
91
92 return rc;
93}
94
95static const char *vboxvfs_opts[] = {
96 "uid", "gid", "from", "fstype", "fspath", "errmsg", NULL
97};
98
99static int vboxvfs_mount(struct mount *mp, struct thread *td)
100{
101 int rc;
102 char *pszShare;
103 int cbShare, cbOption;
104 int uid = 0, gid = 0;
105 struct sf_glob_info *pShFlGlobalInfo;
106 SHFLSTRING *pShFlShareName = NULL;
107 int cbShFlShareName;
108
109 printf("%s: Enter\n", __FUNCTION__);
110
111 if (mp->mnt_flag & (MNT_UPDATE | MNT_ROOTFS))
112 return EOPNOTSUPP;
113
114 if (vfs_filteropt(mp->mnt_optnew, vboxvfs_opts))
115 {
116 vfs_mount_error(mp, "%s", "Invalid option");
117 return EINVAL;
118 }
119
120 rc = vfs_getopt(mp->mnt_optnew, "from", (void **)&pszShare, &cbShare);
121 if (rc || pszShare[cbShare-1] != '\0' || cbShare > 0xfffe)
122 return EINVAL;
123
124 rc = vfs_getopt(mp->mnt_optnew, "gid", (void **)&gid, &cbOption);
125 if ((rc != ENOENT) && (rc || cbOption != sizeof(gid)))
126 return EINVAL;
127
128 rc = vfs_getopt(mp->mnt_optnew, "uid", (void **)&uid, &cbOption);
129 if ((rc != ENOENT) && (rc || cbOption != sizeof(uid)))
130 return EINVAL;
131
132 pShFlGlobalInfo = RTMemAllocZ(sizeof(struct sf_glob_info));
133 if (!pShFlGlobalInfo)
134 return ENOMEM;
135
136 cbShFlShareName = offsetof (SHFLSTRING, String.utf8) + cbShare + 1;
137 pShFlShareName = RTMemAllocZ(cbShFlShareName);
138 if (!pShFlShareName)
139 return VERR_NO_MEMORY;
140
141 pShFlShareName->u16Length = cbShFlShareName;
142 pShFlShareName->u16Size = cbShFlShareName + 1;
143 memcpy (pShFlShareName->String.utf8, pszShare, cbShare + 1);
144
145 rc = vboxCallMapFolder (&g_vboxSFClient, pShFlShareName, &pShFlGlobalInfo->map);
146 RTMemFree(pShFlShareName);
147
148 if (VBOX_FAILURE (rc))
149 {
150 RTMemFree(pShFlGlobalInfo);
151 printf("vboxCallMapFolder failed rc=%d\n", rc);
152 return EPROTO;
153 }
154
155 pShFlGlobalInfo->uid = uid;
156 pShFlGlobalInfo->gid = gid;
157
158 mp->mnt_data = pShFlGlobalInfo;
159
160 /* @todo root vnode. */
161
162 vfs_getnewfsid(mp);
163 vfs_mountedfrom(mp, pszShare);
164
165 printf("%s: Leave rc=0\n", __FUNCTION__);
166
167 return 0;
168}
169
170static int vboxvfs_unmount(struct mount *mp, int mntflags, struct thread *td)
171{
172 struct sf_glob_info *pShFlGlobalInfo = VFSMP2SFGLOBINFO(mp);
173 int rc;
174 int flags = 0;
175
176 rc = vboxCallUnmapFolder(&g_vboxSFClient, &pShFlGlobalInfo->map);
177 if (VBOX_FAILURE(rc))
178 printf("Failed to unmap shared folder\n");
179
180 if (mntflags & MNT_FORCE)
181 flags |= FORCECLOSE;
182
183 /* There is 1 extra root vnode reference (vnode_root). */
184 rc = vflush(mp, 1, flags, td);
185 if (rc)
186 return rc;
187
188
189 RTMemFree(pShFlGlobalInfo);
190 mp->mnt_data = NULL;
191
192 return 0;
193}
194
195static int vboxvfs_root(struct mount *mp, int flags, struct vnode **vpp, struct thread *td)
196{
197 int rc = 0;
198 struct sf_glob_info *pShFlGlobalInfo = VFSMP2SFGLOBINFO(mp);
199 struct vnode *vp;
200
201 printf("%s: Enter\n", __FUNCTION__);
202
203 vp = pShFlGlobalInfo->vnode_root;
204 VREF(vp);
205
206 vn_lock(vp, flags | LK_RETRY, td);
207 *vpp = vp;
208
209 printf("%s: Leave\n", __FUNCTION__);
210
211 return rc;
212}
213
214static int vboxvfs_quotactl(struct mount *mp, int cmd, uid_t uid, void *arg, struct thread *td)
215{
216 return EOPNOTSUPP;
217}
218
219int vboxvfs_init(struct vfsconf *vfsp)
220{
221 int rc;
222
223 /* Initialize the R0 guest library. */
224 rc = vboxInit();
225 if (VBOX_FAILURE(rc))
226 return ENXIO;
227
228 /* Connect to the host service. */
229 rc = vboxConnect(&g_vboxSFClient);
230 if (VBOX_FAILURE(rc))
231 {
232 printf("Failed to get connection to host! rc=%d\n", rc);
233 vboxUninit();
234 return ENXIO;
235 }
236
237 rc = vboxCallSetUtf8 (&g_vboxSFClient);
238 if (VBOX_FAILURE (rc))
239 {
240 printf("vboxCallSetUtf8 failed, rc=%d\n", rc);
241 vboxDisconnect(&g_vboxSFClient);
242 vboxUninit();
243 return EPROTO;
244 }
245
246 printf("Successfully loaded shared folder module\n");
247
248 return 0;
249}
250
251int vboxvfs_uninit(struct vfsconf *vfsp)
252{
253 vboxDisconnect(&g_vboxSFClient);
254 vboxUninit();
255
256 return 0;
257}
258
259int vboxvfs_statfs(struct mount *mp, struct statfs *sbp, struct thread *td)
260{
261 return 0;
262}
Note: See TracBrowser for help on using the repository browser.

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