VirtualBox

source: vbox/trunk/src/VBox/Additions/darwin/VBoxSF/VBoxSFInternal.h@ 75675

Last change on this file since 75675 was 75675, checked in by vboxsync, 6 years ago

darwin/VBoxSF: Started rewriting this...

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.5 KB
Line 
1/* $Id: VBoxSFInternal.h 75675 2018-11-22 21:16:48Z vboxsync $ */
2/** @file
3 * VBoxSF - Darwin Shared Folders, internal header.
4 */
5
6/*
7 * Copyright (C) 2013-2018 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#ifndef ___VBoxSFInternal_h___
19#define ___VBoxSFInternal_h___
20
21
22/*********************************************************************************************************************************
23* Header Files *
24*********************************************************************************************************************************/
25#include "VBoxSFMount.h"
26
27#include <libkern/libkern.h>
28#include <iprt/types.h>
29#include <IOKit/IOLib.h>
30#include <IOKit/IOService.h>
31#include <mach/mach_port.h>
32#include <mach/kmod.h>
33#include <mach/mach_types.h>
34#include <sys/errno.h>
35#include <sys/dirent.h>
36#include <sys/lock.h>
37#include <sys/fcntl.h>
38#include <sys/mount.h>
39#include <sys/param.h>
40#include <sys/vnode.h>
41#include <vfs/vfs_support.h>
42#undef PVM
43
44#include <iprt/mem.h>
45#include <VBox/VBoxGuest.h>
46#include <VBox/VBoxGuestLibSharedFolders.h>
47
48
49/*********************************************************************************************************************************
50* Defined Constants And Macros *
51*********************************************************************************************************************************/
52/** @todo misguided, should use Log() and LogRel. sigh... */
53#define PINFO(fmt, args...) printf(VBOXSF_DARWIN_FS_NAME ": INFO: " fmt "\n", ## args)
54#define PDEBUG(fmt, args...) printf(VBOXSF_DARWIN_FS_NAME ": %s(): DEBUG: " fmt "\n", __FUNCTION__, ## args)
55#define PERROR(fmt, args...) printf(VBOXSF_DARWIN_FS_NAME ": ERROR: " fmt "\n", ## args)
56
57
58/*********************************************************************************************************************************
59* Structures and Typedefs *
60*********************************************************************************************************************************/
61/** Private data assigned to each mounted shared folder. Assigned to mp structure. */
62typedef struct vboxvfs_mount_data
63{
64 /** The shared folder mapping */
65 VBGLSFMAP hHostFolder;
66 /** The root VNode. */
67 vnode_t pVnRoot;
68 /** User that mounted shared folder (anyone but root?). */
69 uid_t uidMounter;
70 /** The mount info from the mount() call. */
71 VBOXSFDRWNMOUNTINFO MntInfo;
72} vboxvfs_mount_t, VBOXSFMNT;
73typedef VBOXSFMNT *PVBOXSFMNT;
74
75/** Private data assigned to each vnode object. */
76typedef struct vboxvfs_vnode_data
77{
78 SHFLHANDLE hHandle; /** VBoxVFS object handle. */
79 ///PSHFLSTRING pPath; /** Path within shared folder */
80 ///lck_attr_t *pLockAttr; /** BSD locking stuff */
81 ///lck_rw_t *pLock; /** BSD locking stuff */
82} vboxvfs_vnode_t, VBOXSFDWNVNDATA;
83/** Private vnode data. */
84typedef VBOXSFDWNVNDATA *PVBOXSFDWNVNDATA;
85
86
87
88/*********************************************************************************************************************************
89* Global Variables *
90*********************************************************************************************************************************/
91extern VBGLSFCLIENT g_SfClientDarwin;
92extern uint32_t volatile g_cVBoxSfMounts;
93extern struct vfsops g_VBoxSfVfsOps;
94extern struct vnodeopv_desc g_VBoxSfVnodeOpvDesc;
95extern int (**g_papfnVBoxVFSVnodeDirOpsVector)(void *);
96
97
98/*********************************************************************************************************************************
99* Functions *
100*********************************************************************************************************************************/
101bool vboxSfDwnConnect(void);
102vnode_t vboxSfDwnVnAlloc(mount_t pMount, enum vtype enmType, vnode_t pParent, uint64_t cbFile);
103
104
105
106
107/**
108 * Helper function to create XNU VFS vnode object.
109 *
110 * @param mp Mount data structure
111 * @param type vnode type (directory, regular file, etc)
112 * @param pParent Parent vnode object (NULL for VBoxVFS root vnode)
113 * @param fIsRoot Flag that indicates if created vnode object is
114 * VBoxVFS root vnode (TRUE for VBoxVFS root vnode, FALSE
115 * for all aother vnodes)
116 * @param Path within Shared Folder
117 * @param ret Returned newly created vnode
118 *
119 * @return 0 on success, error code otherwise
120 */
121extern int vboxvfs_create_vnode_internal(struct mount *mp, enum vtype type, vnode_t pParent, int fIsRoot, PSHFLSTRING Path, vnode_t *ret);
122
123/**
124 * Convert guest absolute VFS path (starting from VFS root) to a host path
125 * within mounted shared folder (returning it as a char *).
126 *
127 * @param mp Mount data structure
128 * @param pszGuestPath Guest absolute VFS path (starting from VFS root)
129 * @param cbGuestPath Size of pszGuestPath
130 * @param pszHostPath Returned char * wich contains host path
131 * @param cbHostPath Returned pszHostPath size
132 *
133 * @return 0 on success, error code otherwise
134 */
135extern int vboxvfs_guest_path_to_char_path_internal(mount_t mp, char *pszGuestPath, int cbGuestPath, char **pszHostPath, int *cbHostPath);
136
137/**
138 * Convert guest absolute VFS path (starting from VFS root) to a host path
139 * within mounted shared folder.
140 *
141 * @param mp Mount data structure
142 * @param pszGuestPath Guest absolute VFS path (starting from VFS root)
143 * @param cbGuestPath Size of pszGuestPath
144 * @param ppResult Returned PSHFLSTRING object wich contains host path
145 *
146 * @return 0 on success, error code otherwise
147 */
148extern int vboxvfs_guest_path_to_shflstring_path_internal(mount_t mp, char *pszGuestPath, int cbGuestPath, PSHFLSTRING *ppResult);
149
150/**
151 * Wrapper function for vboxvfs_guest_path_to_char_path_internal() which
152 * converts guest path to host path using vnode object information.
153 *
154 * @param vnode Guest's VFS object
155 * @param ppPath Allocated char * which contain a path
156 * @param pcbPath Size of ppPath
157 *
158 * @return 0 on success, error code otherwise.
159 */
160extern int vboxvfs_guest_vnode_to_char_path_internal(vnode_t vnode, char **ppHostPath, int *pcbHostPath);
161
162/**
163 * Wrapper function for vboxvfs_guest_path_to_shflstring_path_internal() which
164 * converts guest path to host path using vnode object information.
165 *
166 * @param vnode Guest's VFS object
167 * @param ppResult Allocated PSHFLSTRING object which contain a path
168 *
169 * @return 0 on success, error code otherwise.
170 */
171extern int vboxvfs_guest_vnode_to_shflstring_path_internal(vnode_t vnode, PSHFLSTRING *ppResult);
172
173/**
174 * Free resources allocated by vboxvfs_path_internal() and vboxvfs_guest_vnode_to_shflstring_path_internal().
175 *
176 * @param ppHandle Reference to object to be freed.
177 */
178extern void vboxvfs_put_path_internal(void **ppHandle);
179
180/**
181 * Open existing VBoxVFS object and return its handle.
182 *
183 * @param pMount Mount session data.
184 * @param pPath VFS path to the object relative to mount point.
185 * @param fFlags For directory object it should be
186 * SHFL_CF_DIRECTORY and 0 for any other object.
187 * @param pHandle Returned handle.
188 *
189 * @return 0 on success, error code otherwise.
190 */
191extern int vboxvfs_open_internal(vboxvfs_mount_t *pMount, PSHFLSTRING pPath, uint32_t fFlags, SHFLHANDLE *pHandle);
192
193/**
194 * Release VBoxVFS object handle openned by vboxvfs_open_internal().
195 *
196 * @param pMount Mount session data.
197 * @param pHandle Handle to close.
198 *
199 * @return 0 on success, IPRT error code otherwise.
200 */
201extern int vboxvfs_close_internal(vboxvfs_mount_t *pMount, SHFLHANDLE pHandle);
202
203/**
204 * Get information about host VFS object.
205 *
206 * @param mp Mount point data
207 * @param pSHFLDPath Path to VFS object within mounted shared folder
208 * @param Info Returned info
209 *
210 * @return 0 on success, error code otherwise.
211 */
212extern int vboxvfs_get_info_internal(mount_t mp, PSHFLSTRING pSHFLDPath, PSHFLFSOBJINFO Info);
213
214/**
215 * Check if VFS object exists on a host side.
216 *
217 * @param vnode Guest VFS vnode that corresponds to host VFS object
218 *
219 * @return 1 if exists, 0 otherwise.
220 */
221extern int vboxvfs_exist_internal(vnode_t vnode);
222
223/**
224 * Convert host VFS object mode flags into guest ones.
225 *
226 * @param fHostMode Host flags
227 *
228 * @return Guest flags
229 */
230extern mode_t vboxvfs_h2g_mode_inernal(RTFMODE fHostMode);
231
232/**
233 * Convert guest VFS object mode flags into host ones.
234 *
235 * @param fGuestMode Host flags
236 *
237 * @return Host flags
238 */
239extern uint32_t vboxvfs_g2h_mode_inernal(mode_t fGuestMode);
240
241extern SHFLSTRING *vboxvfs_construct_shflstring(const char *pszName, size_t cchName);
242
243
244#endif
245
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