1 | /* $Id: vboxvfs.h 75292 2018-11-06 15:06:31Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxVFS - common header used across all the driver source files.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2013-2017 Oracle Corporation
|
---|
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 |
|
---|
18 | #define MODULE_NAME "VBoxSF"
|
---|
19 |
|
---|
20 | #ifdef KERNEL
|
---|
21 | # include <libkern/libkern.h>
|
---|
22 | # include <sys/lock.h>
|
---|
23 | #endif
|
---|
24 |
|
---|
25 | #define PINFO(fmt, args...) printf(MODULE_NAME ": INFO: " fmt "\n", ## args)
|
---|
26 | #define PDEBUG(fmt, args...) printf(MODULE_NAME ": %s(): DEBUG: " fmt "\n", __FUNCTION__, ## args)
|
---|
27 | #define PERROR(fmt, args...) printf(MODULE_NAME ": ERROR: " fmt "\n", ## args)
|
---|
28 |
|
---|
29 | #define VBOXVBFS_NAME "vboxsf"
|
---|
30 | #define VBOXVFS_MOUNTINFO_MAGIC (0xCAFE)
|
---|
31 |
|
---|
32 | #ifdef KERNEL
|
---|
33 |
|
---|
34 | #include <iprt/types.h>
|
---|
35 | #undef PVM
|
---|
36 | #include <sys/vnode.h>
|
---|
37 |
|
---|
38 | #include <VBox/VBoxGuestLibSharedFolders.h>
|
---|
39 |
|
---|
40 |
|
---|
41 | /** Global refernce to host service connection */
|
---|
42 | extern VBGLSFCLIENT g_vboxSFClient;
|
---|
43 |
|
---|
44 | /** Private data assigned to each mounted shared folder. Assigned to mp structure. */
|
---|
45 | typedef struct vboxvfs_mount_data
|
---|
46 | {
|
---|
47 | VBGLSFMAP pMap; /** Shared folder mapping */
|
---|
48 | SHFLSTRING *pShareName; /** VBoxVFS share name */
|
---|
49 | uint64_t cFileIdCounter; /** Counter that used in order to assign unique ID to each vnode within mounted share */
|
---|
50 | vnode_t pRootVnode; /** VFS object: vnode that corresponds shared folder root */
|
---|
51 | uint8_t volatile fRootVnodeState; /** Sync flag that used in order to safely allocate pRootVnode */
|
---|
52 | uid_t owner; /** User ID tha mounted shared folder */
|
---|
53 | lck_grp_t *pLockGroup; /** BSD locking stuff */
|
---|
54 | lck_grp_attr_t *pLockGroupAttr; /** BSD locking stuff */
|
---|
55 | } vboxvfs_mount_t;
|
---|
56 |
|
---|
57 | /** Private data assigned to each vnode object. */
|
---|
58 | typedef struct vboxvfs_vnode_data
|
---|
59 | {
|
---|
60 | SHFLHANDLE pHandle; /** VBoxVFS object handle. */
|
---|
61 | PSHFLSTRING pPath; /** Path within shared folder */
|
---|
62 | lck_attr_t *pLockAttr; /** BSD locking stuff */
|
---|
63 | lck_rw_t *pLock; /** BSD locking stuff */
|
---|
64 | } vboxvfs_vnode_t;
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * Helper function to create XNU VFS vnode object.
|
---|
68 | *
|
---|
69 | * @param mp Mount data structure
|
---|
70 | * @param type vnode type (directory, regular file, etc)
|
---|
71 | * @param pParent Parent vnode object (NULL for VBoxVFS root vnode)
|
---|
72 | * @param fIsRoot Flag that indicates if created vnode object is
|
---|
73 | * VBoxVFS root vnode (TRUE for VBoxVFS root vnode, FALSE
|
---|
74 | * for all aother vnodes)
|
---|
75 | * @param Path within Shared Folder
|
---|
76 | * @param ret Returned newly created vnode
|
---|
77 | *
|
---|
78 | * @return 0 on success, error code otherwise
|
---|
79 | */
|
---|
80 | extern int vboxvfs_create_vnode_internal(struct mount *mp, enum vtype type, vnode_t pParent, int fIsRoot, PSHFLSTRING Path, vnode_t *ret);
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Convert guest absolute VFS path (starting from VFS root) to a host path
|
---|
84 | * within mounted shared folder (returning it as a char *).
|
---|
85 | *
|
---|
86 | * @param mp Mount data structure
|
---|
87 | * @param pszGuestPath Guest absolute VFS path (starting from VFS root)
|
---|
88 | * @param cbGuestPath Size of pszGuestPath
|
---|
89 | * @param pszHostPath Returned char * wich contains host path
|
---|
90 | * @param cbHostPath Returned pszHostPath size
|
---|
91 | *
|
---|
92 | * @return 0 on success, error code otherwise
|
---|
93 | */
|
---|
94 | extern int vboxvfs_guest_path_to_char_path_internal(mount_t mp, char *pszGuestPath, int cbGuestPath, char **pszHostPath, int *cbHostPath);
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * Convert guest absolute VFS path (starting from VFS root) to a host path
|
---|
98 | * within mounted shared folder.
|
---|
99 | *
|
---|
100 | * @param mp Mount data structure
|
---|
101 | * @param pszGuestPath Guest absolute VFS path (starting from VFS root)
|
---|
102 | * @param cbGuestPath Size of pszGuestPath
|
---|
103 | * @param ppResult Returned PSHFLSTRING object wich contains host path
|
---|
104 | *
|
---|
105 | * @return 0 on success, error code otherwise
|
---|
106 | */
|
---|
107 | extern int vboxvfs_guest_path_to_shflstring_path_internal(mount_t mp, char *pszGuestPath, int cbGuestPath, PSHFLSTRING *ppResult);
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * Wrapper function for vboxvfs_guest_path_to_char_path_internal() which
|
---|
111 | * converts guest path to host path using vnode object information.
|
---|
112 | *
|
---|
113 | * @param vnode Guest's VFS object
|
---|
114 | * @param ppPath Allocated char * which contain a path
|
---|
115 | * @param pcbPath Size of ppPath
|
---|
116 | *
|
---|
117 | * @return 0 on success, error code otherwise.
|
---|
118 | */
|
---|
119 | extern int vboxvfs_guest_vnode_to_char_path_internal(vnode_t vnode, char **ppHostPath, int *pcbHostPath);
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * Wrapper function for vboxvfs_guest_path_to_shflstring_path_internal() which
|
---|
123 | * converts guest path to host path using vnode object information.
|
---|
124 | *
|
---|
125 | * @param vnode Guest's VFS object
|
---|
126 | * @param ppResult Allocated PSHFLSTRING object which contain a path
|
---|
127 | *
|
---|
128 | * @return 0 on success, error code otherwise.
|
---|
129 | */
|
---|
130 | extern int vboxvfs_guest_vnode_to_shflstring_path_internal(vnode_t vnode, PSHFLSTRING *ppResult);
|
---|
131 |
|
---|
132 | /**
|
---|
133 | * Free resources allocated by vboxvfs_path_internal() and vboxvfs_guest_vnode_to_shflstring_path_internal().
|
---|
134 | *
|
---|
135 | * @param ppHandle Reference to object to be freed.
|
---|
136 | */
|
---|
137 | extern void vboxvfs_put_path_internal(void **ppHandle);
|
---|
138 |
|
---|
139 | /**
|
---|
140 | * Open existing VBoxVFS object and return its handle.
|
---|
141 | *
|
---|
142 | * @param pMount Mount session data.
|
---|
143 | * @param pPath VFS path to the object relative to mount point.
|
---|
144 | * @param fFlags For directory object it should be
|
---|
145 | * SHFL_CF_DIRECTORY and 0 for any other object.
|
---|
146 | * @param pHandle Returned handle.
|
---|
147 | *
|
---|
148 | * @return 0 on success, error code otherwise.
|
---|
149 | */
|
---|
150 | extern int vboxvfs_open_internal(vboxvfs_mount_t *pMount, PSHFLSTRING pPath, uint32_t fFlags, SHFLHANDLE *pHandle);
|
---|
151 |
|
---|
152 | /**
|
---|
153 | * Release VBoxVFS object handle openned by vboxvfs_open_internal().
|
---|
154 | *
|
---|
155 | * @param pMount Mount session data.
|
---|
156 | * @param pHandle Handle to close.
|
---|
157 | *
|
---|
158 | * @return 0 on success, IPRT error code otherwise.
|
---|
159 | */
|
---|
160 | extern int vboxvfs_close_internal(vboxvfs_mount_t *pMount, SHFLHANDLE pHandle);
|
---|
161 |
|
---|
162 | /**
|
---|
163 | * Get information about host VFS object.
|
---|
164 | *
|
---|
165 | * @param mp Mount point data
|
---|
166 | * @param pSHFLDPath Path to VFS object within mounted shared folder
|
---|
167 | * @param Info Returned info
|
---|
168 | *
|
---|
169 | * @return 0 on success, error code otherwise.
|
---|
170 | */
|
---|
171 | extern int vboxvfs_get_info_internal(mount_t mp, PSHFLSTRING pSHFLDPath, PSHFLFSOBJINFO Info);
|
---|
172 |
|
---|
173 | /**
|
---|
174 | * Check if VFS object exists on a host side.
|
---|
175 | *
|
---|
176 | * @param vnode Guest VFS vnode that corresponds to host VFS object
|
---|
177 | *
|
---|
178 | * @return 1 if exists, 0 otherwise.
|
---|
179 | */
|
---|
180 | extern int vboxvfs_exist_internal(vnode_t vnode);
|
---|
181 |
|
---|
182 | /**
|
---|
183 | * Convert host VFS object mode flags into guest ones.
|
---|
184 | *
|
---|
185 | * @param fHostMode Host flags
|
---|
186 | *
|
---|
187 | * @return Guest flags
|
---|
188 | */
|
---|
189 | extern mode_t vboxvfs_h2g_mode_inernal(RTFMODE fHostMode);
|
---|
190 |
|
---|
191 | /**
|
---|
192 | * Convert guest VFS object mode flags into host ones.
|
---|
193 | *
|
---|
194 | * @param fGuestMode Host flags
|
---|
195 | *
|
---|
196 | * @return Host flags
|
---|
197 | */
|
---|
198 | extern uint32_t vboxvfs_g2h_mode_inernal(mode_t fGuestMode);
|
---|
199 |
|
---|
200 | extern SHFLSTRING *vboxvfs_construct_shflstring(const char *pszName, size_t cchName);
|
---|
201 |
|
---|
202 | #endif /* KERNEL */
|
---|
203 |
|
---|
204 | extern int vboxvfs_register_filesystem(void);
|
---|
205 | extern int vboxvfs_unregister_filesystem(void);
|
---|
206 |
|
---|
207 | /* VFS options */
|
---|
208 | extern struct vfsops g_oVBoxVFSOpts;
|
---|
209 |
|
---|
210 | extern int (**g_VBoxVFSVnodeDirOpsVector)(void *);
|
---|
211 | extern int g_cVBoxVFSVnodeOpvDescListSize;
|
---|
212 | extern struct vnodeopv_desc *g_VBoxVFSVnodeOpvDescList[];
|
---|
213 |
|
---|
214 | /* Mount info */
|
---|
215 | struct vboxvfs_mount_info
|
---|
216 | {
|
---|
217 | uint32_t magic;
|
---|
218 | char name[MAXPATHLEN]; /* share name */
|
---|
219 | };
|
---|
220 |
|
---|