VirtualBox

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

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

darwin/VBoxSF: updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.6 KB
Line 
1/* $Id: VBoxSFInternal.h 75666 2018-11-22 14:13:32Z 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#undef PVM
42
43#include <VBox/VBoxGuestLibSharedFolders.h>
44
45
46/*********************************************************************************************************************************
47* Defined Constants And Macros *
48*********************************************************************************************************************************/
49/** @todo misguided, should use Log() and LogRel. sigh... */
50#define PINFO(fmt, args...) printf(VBOXSF_DARWIN_FS_NAME ": INFO: " fmt "\n", ## args)
51#define PDEBUG(fmt, args...) printf(VBOXSF_DARWIN_FS_NAME ": %s(): DEBUG: " fmt "\n", __FUNCTION__, ## args)
52#define PERROR(fmt, args...) printf(VBOXSF_DARWIN_FS_NAME ": ERROR: " fmt "\n", ## args)
53
54
55/*********************************************************************************************************************************
56* Structures and Typedefs *
57*********************************************************************************************************************************/
58/** Private data assigned to each mounted shared folder. Assigned to mp structure. */
59typedef struct vboxvfs_mount_data
60{
61 VBGLSFMAP pMap; /** Shared folder mapping */
62 SHFLSTRING *pShareName; /** VBoxVFS share name */
63 uint64_t cFileIdCounter; /** Counter that used in order to assign unique ID to each vnode within mounted share */
64 vnode_t pRootVnode; /** VFS object: vnode that corresponds shared folder root */
65 uint8_t volatile fRootVnodeState; /** Sync flag that used in order to safely allocate pRootVnode */
66 uid_t owner; /** User ID tha mounted shared folder */
67 lck_grp_t *pLockGroup; /** BSD locking stuff */
68 lck_grp_attr_t *pLockGroupAttr; /** BSD locking stuff */
69} vboxvfs_mount_t;
70
71/** Private data assigned to each vnode object. */
72typedef struct vboxvfs_vnode_data
73{
74 SHFLHANDLE pHandle; /** VBoxVFS object handle. */
75 PSHFLSTRING pPath; /** Path within shared folder */
76 lck_attr_t *pLockAttr; /** BSD locking stuff */
77 lck_rw_t *pLock; /** BSD locking stuff */
78} vboxvfs_vnode_t;
79
80
81/*********************************************************************************************************************************
82* Global Variables *
83*********************************************************************************************************************************/
84extern VBGLSFCLIENT g_SfClient;
85extern struct vfsops g_VBoxSfVfsOps;
86extern struct vnodeopv_desc g_VBoxSfVnodeOpvDesc;
87extern int (**g_papfnVBoxVFSVnodeDirOpsVector)(void *);
88
89
90/*********************************************************************************************************************************
91* Functions *
92*********************************************************************************************************************************/
93
94/**
95 * Helper function to create XNU VFS vnode object.
96 *
97 * @param mp Mount data structure
98 * @param type vnode type (directory, regular file, etc)
99 * @param pParent Parent vnode object (NULL for VBoxVFS root vnode)
100 * @param fIsRoot Flag that indicates if created vnode object is
101 * VBoxVFS root vnode (TRUE for VBoxVFS root vnode, FALSE
102 * for all aother vnodes)
103 * @param Path within Shared Folder
104 * @param ret Returned newly created vnode
105 *
106 * @return 0 on success, error code otherwise
107 */
108extern int vboxvfs_create_vnode_internal(struct mount *mp, enum vtype type, vnode_t pParent, int fIsRoot, PSHFLSTRING Path, vnode_t *ret);
109
110/**
111 * Convert guest absolute VFS path (starting from VFS root) to a host path
112 * within mounted shared folder (returning it as a char *).
113 *
114 * @param mp Mount data structure
115 * @param pszGuestPath Guest absolute VFS path (starting from VFS root)
116 * @param cbGuestPath Size of pszGuestPath
117 * @param pszHostPath Returned char * wich contains host path
118 * @param cbHostPath Returned pszHostPath size
119 *
120 * @return 0 on success, error code otherwise
121 */
122extern int vboxvfs_guest_path_to_char_path_internal(mount_t mp, char *pszGuestPath, int cbGuestPath, char **pszHostPath, int *cbHostPath);
123
124/**
125 * Convert guest absolute VFS path (starting from VFS root) to a host path
126 * within mounted shared folder.
127 *
128 * @param mp Mount data structure
129 * @param pszGuestPath Guest absolute VFS path (starting from VFS root)
130 * @param cbGuestPath Size of pszGuestPath
131 * @param ppResult Returned PSHFLSTRING object wich contains host path
132 *
133 * @return 0 on success, error code otherwise
134 */
135extern int vboxvfs_guest_path_to_shflstring_path_internal(mount_t mp, char *pszGuestPath, int cbGuestPath, PSHFLSTRING *ppResult);
136
137/**
138 * Wrapper function for vboxvfs_guest_path_to_char_path_internal() which
139 * converts guest path to host path using vnode object information.
140 *
141 * @param vnode Guest's VFS object
142 * @param ppPath Allocated char * which contain a path
143 * @param pcbPath Size of ppPath
144 *
145 * @return 0 on success, error code otherwise.
146 */
147extern int vboxvfs_guest_vnode_to_char_path_internal(vnode_t vnode, char **ppHostPath, int *pcbHostPath);
148
149/**
150 * Wrapper function for vboxvfs_guest_path_to_shflstring_path_internal() which
151 * converts guest path to host path using vnode object information.
152 *
153 * @param vnode Guest's VFS object
154 * @param ppResult Allocated PSHFLSTRING object which contain a path
155 *
156 * @return 0 on success, error code otherwise.
157 */
158extern int vboxvfs_guest_vnode_to_shflstring_path_internal(vnode_t vnode, PSHFLSTRING *ppResult);
159
160/**
161 * Free resources allocated by vboxvfs_path_internal() and vboxvfs_guest_vnode_to_shflstring_path_internal().
162 *
163 * @param ppHandle Reference to object to be freed.
164 */
165extern void vboxvfs_put_path_internal(void **ppHandle);
166
167/**
168 * Open existing VBoxVFS object and return its handle.
169 *
170 * @param pMount Mount session data.
171 * @param pPath VFS path to the object relative to mount point.
172 * @param fFlags For directory object it should be
173 * SHFL_CF_DIRECTORY and 0 for any other object.
174 * @param pHandle Returned handle.
175 *
176 * @return 0 on success, error code otherwise.
177 */
178extern int vboxvfs_open_internal(vboxvfs_mount_t *pMount, PSHFLSTRING pPath, uint32_t fFlags, SHFLHANDLE *pHandle);
179
180/**
181 * Release VBoxVFS object handle openned by vboxvfs_open_internal().
182 *
183 * @param pMount Mount session data.
184 * @param pHandle Handle to close.
185 *
186 * @return 0 on success, IPRT error code otherwise.
187 */
188extern int vboxvfs_close_internal(vboxvfs_mount_t *pMount, SHFLHANDLE pHandle);
189
190/**
191 * Get information about host VFS object.
192 *
193 * @param mp Mount point data
194 * @param pSHFLDPath Path to VFS object within mounted shared folder
195 * @param Info Returned info
196 *
197 * @return 0 on success, error code otherwise.
198 */
199extern int vboxvfs_get_info_internal(mount_t mp, PSHFLSTRING pSHFLDPath, PSHFLFSOBJINFO Info);
200
201/**
202 * Check if VFS object exists on a host side.
203 *
204 * @param vnode Guest VFS vnode that corresponds to host VFS object
205 *
206 * @return 1 if exists, 0 otherwise.
207 */
208extern int vboxvfs_exist_internal(vnode_t vnode);
209
210/**
211 * Convert host VFS object mode flags into guest ones.
212 *
213 * @param fHostMode Host flags
214 *
215 * @return Guest flags
216 */
217extern mode_t vboxvfs_h2g_mode_inernal(RTFMODE fHostMode);
218
219/**
220 * Convert guest VFS object mode flags into host ones.
221 *
222 * @param fGuestMode Host flags
223 *
224 * @return Host flags
225 */
226extern uint32_t vboxvfs_g2h_mode_inernal(mode_t fGuestMode);
227
228extern SHFLSTRING *vboxvfs_construct_shflstring(const char *pszName, size_t cchName);
229
230extern int vboxvfs_register_filesystem(void);
231extern int vboxvfs_unregister_filesystem(void);
232
233
234#endif
235
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