Changeset 75293 in vbox for trunk/src/VBox/Additions/darwin/VBoxSF
- Timestamp:
- Nov 6, 2018 4:15:09 PM (6 years ago)
- svn:sync-xref-src-repo-rev:
- 126398
- Location:
- trunk/src/VBox/Additions/darwin/VBoxSF
- Files:
-
- 1 edited
- 1 copied
- 6 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/darwin/VBoxSF/Makefile.kmk
r75292 r75293 1 1 # $Id$ 2 2 ## @file 3 # sub-makefile for the Mac OS addition file system driver.3 # sub-makefile for Darwin Shared Folders. 4 4 # 5 5 6 6 # 7 # Copyright (C) 2007-201 7Oracle Corporation7 # Copyright (C) 2007-2018 Oracle Corporation 8 8 # 9 9 # This file is part of VirtualBox Open Source Edition (OSE), as … … 29 29 VBoxSF_LIBS = $(VBOX_LIB_VBGL_R0) 30 30 VBoxSF_SOURCES = \ 31 VBox VFS.cpp \32 VBox VFS-VFSOps.cpp \33 VBox VFS-VNODEOps.cpp \34 VBox VFS-utils.cpp31 VBoxSF.cpp \ 32 VBoxSF-VfsOps.cpp \ 33 VBoxSF-VNodeOps.cpp \ 34 VBoxSF-Utils.cpp 35 35 36 36 … … 64 64 PROGRAMS += mount.vboxsf 65 65 mount.vboxsf_TEMPLATE = NewVBoxGuestR3Exe 66 mount.vboxsf_SOURCES = mount.vboxsf.c 66 mount.vboxsf_SOURCES = mount.vboxsf.cpp 67 67 mount.vboxsf_INST = $(INST_ADDITIONS)VBoxSF.kext/Contents/MacOS/ 68 68 -
trunk/src/VBox/Additions/darwin/VBoxSF/VBoxSF-Utils.cpp
r75292 r75293 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox VFS - helper functions.3 * VBoxSF - Darwin Shared Folders, Utility Functions. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2013-201 7Oracle Corporation7 * Copyright (C) 2013-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 #include <mach/kmod.h> 19 #include <libkern/libkern.h> 20 #include <mach/mach_types.h> 21 22 #include <sys/mount.h> 23 #include <sys/vnode.h> 24 #include <sys/errno.h> 25 #include <sys/fcntl.h> 18 19 /********************************************************************************************************************************* 20 * Header Files * 21 *********************************************************************************************************************************/ 22 #include "VBoxSFInternal.h" 26 23 27 24 #include <iprt/assert.h> 28 25 #include <iprt/mem.h> 29 26 30 #include "vboxvfs.h"31 27 32 28 /** -
trunk/src/VBox/Additions/darwin/VBoxSF/VBoxSF-VNodeOps.cpp
r75292 r75293 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox VFS - vnode operations.3 * VBoxSF - Darwin Shared Folders, VNode Operations. 4 4 */ 5 5 6 6 7 /* 7 * Copyright (C) 2013-201 7Oracle Corporation8 * Copyright (C) 2013-2018 Oracle Corporation 8 9 * 9 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 17 */ 17 18 18 #include <sys/mount.h> 19 #include <sys/vnode.h> 20 #include <sys/errno.h> 21 #include <sys/dirent.h> 19 20 /********************************************************************************************************************************* 21 * Header Files * 22 *********************************************************************************************************************************/ 23 #include "VBoxSFInternal.h" 22 24 23 25 #include <iprt/mem.h> 24 26 #include <iprt/assert.h> 25 27 26 #include "vboxvfs.h" 28 27 29 28 30 #define VNODEOPFUNC int(*)(void *) 31 29 32 30 33 static int vboxvfs_dfl_error() -
trunk/src/VBox/Additions/darwin/VBoxSF/VBoxSF-VfsOps.cpp
r75292 r75293 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox VFS - Filesystem operations.3 * VBoxFS - Darwin Shared Folders, Virtual File System Operations. 4 4 */ 5 5 … … 16 16 */ 17 17 18 #include <mach/kmod.h> 19 #include <libkern/libkern.h> 20 #include <mach/mach_types.h> 21 22 #include <sys/mount.h> 23 #include <sys/vnode.h> 18 19 /********************************************************************************************************************************* 20 * Header Files * 21 *********************************************************************************************************************************/ 22 #include "VBoxSFInternal.h" 24 23 25 24 #include <iprt/assert.h> … … 27 26 #include <iprt/asm.h> 28 27 29 #include "vboxvfs.h"30 28 31 29 /* States of VBoxVFS object used in atomic variables … … 46 44 */ 47 45 static int 48 vboxvfs_get_mount_info(user_addr_t pUserData, struct vboxvfs_mount_info *pKernelData)46 vboxvfs_get_mount_info(user_addr_t pUserData, PVBOXSFDRWNMOUNTINFO pKernelData) 49 47 { 50 48 AssertReturn(pKernelData, EINVAL); … … 52 50 53 51 /* Get mount parameters from user space */ 54 if (copyin(pUserData, pKernelData, sizeof( struct vboxvfs_mount_info)) != 0)52 if (copyin(pUserData, pKernelData, sizeof(*pKernelData)) != 0) 55 53 { 56 54 PERROR("Unable to copy mount parameters from user space"); … … 59 57 60 58 /* Validate data magic */ 61 if (pKernelData-> magic != VBOXVFS_MOUNTINFO_MAGIC)59 if (pKernelData->u32Magic != VBOXSFDRWNMOUNTINFO_MAGIC) 62 60 { 63 61 PERROR("Mount parameter magic mismatch"); … … 195 193 if (rc == 0) 196 194 { 197 PDEBUG("Mounting shared folder '%s'", mountInfo. name);195 PDEBUG("Mounting shared folder '%s'", mountInfo.szFolder); 198 196 199 197 /* Prepare for locking. We prepare locking group and attr data here, … … 203 201 if (rc == 0) 204 202 { 205 rc = vboxvfs_set_share_name(mp, (char *) &mountInfo.name, &cbShareName);203 rc = vboxvfs_set_share_name(mp, (char *)mountInfo.szFolder, &cbShareName); 206 204 if (rc == 0) 207 205 { 208 pMount->pShareName = vboxvfs_construct_shflstring( (char *)&mountInfo.name, cbShareName);206 pMount->pShareName = vboxvfs_construct_shflstring(mountInfo.szFolder, cbShareName); 209 207 if (pMount->pShareName) 210 208 { -
trunk/src/VBox/Additions/darwin/VBoxSF/VBoxSF.cpp
r75292 r75293 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox VFS - Guest Additions Shared Folders driver. KEXT entry point.3 * VBoxSF - Darwin Shared Folders, KEXT entry points. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2013-201 7Oracle Corporation7 * Copyright (C) 2013-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 #include <IOKit/IOLib.h> /* Assert as function */ 19 #include <IOKit/IOService.h> 20 #include <mach/mach_port.h> 21 22 23 #include <mach/kmod.h> 24 #include <libkern/libkern.h> 25 #include <mach/mach_types.h> 26 #include <sys/mount.h> 27 28 #include <iprt/cdefs.h> 29 #include <iprt/types.h> 30 #include <sys/param.h> 18 19 /********************************************************************************************************************************* 20 * Header Files * 21 *********************************************************************************************************************************/ 22 #define LOG_GROUP LOG_GROUP_DEFAULT 23 #include "VBoxSFInternal.h" 24 25 #include <iprt/asm.h> 26 #include <iprt/assert.h> 31 27 #include <VBox/version.h> 32 #include <iprt/asm.h>33 34 28 #include <VBox/log.h> 35 36 #include "vboxvfs.h"37 29 38 30 … … 40 32 * Structures and Typedefs * 41 33 *********************************************************************************************************************************/ 42 43 34 /** 44 35 * The service class for dealing with Share Folder filesystem. … … 150 141 VFS_TBLNOTYPENUM; 151 142 152 memcpy(oVFsEntry.vfe_fsname, VBOX VBFS_NAME, MFSNAMELEN);143 memcpy(oVFsEntry.vfe_fsname, VBOXSF_DARWIN_FS_NAME, MFSNAMELEN); 153 144 154 145 rc = vfs_fsadd(&oVFsEntry, &g_oVBoxVFSHandle); -
trunk/src/VBox/Additions/darwin/VBoxSF/VBoxSFInternal.h
r75292 r75293 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox VFS - common header used across all the driver source files.3 * VBoxSF - Darwin Shared Folders, internal header. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2013-201 7Oracle Corporation7 * Copyright (C) 2013-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 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 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> 34 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> 35 41 #undef PVM 36 #include <sys/vnode.h>37 42 38 43 #include <VBox/VBoxGuestLibSharedFolders.h> 39 44 40 45 41 /** Global refernce to host service connection */ 42 extern VBGLSFCLIENT g_vboxSFClient; 43 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 *********************************************************************************************************************************/ 44 58 /** Private data assigned to each mounted shared folder. Assigned to mp structure. */ 45 59 typedef struct vboxvfs_mount_data … … 64 78 } vboxvfs_vnode_t; 65 79 80 81 /********************************************************************************************************************************* 82 * Global Variables * 83 *********************************************************************************************************************************/ 84 /** Global refernce to host service connection */ 85 extern VBGLSFCLIENT g_vboxSFClient; 86 87 /* VFS options */ 88 extern struct vfsops g_oVBoxVFSOpts; 89 90 extern int (**g_VBoxVFSVnodeDirOpsVector)(void *); 91 extern int g_cVBoxVFSVnodeOpvDescListSize; 92 extern struct vnodeopv_desc *g_VBoxVFSVnodeOpvDescList[]; 93 94 95 /********************************************************************************************************************************* 96 * Functions * 97 *********************************************************************************************************************************/ 98 66 99 /** 67 100 * Helper function to create XNU VFS vnode object. … … 200 233 extern SHFLSTRING *vboxvfs_construct_shflstring(const char *pszName, size_t cchName); 201 234 202 #endif /* KERNEL */203 204 235 extern int vboxvfs_register_filesystem(void); 205 236 extern int vboxvfs_unregister_filesystem(void); 206 237 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 238 239 #endif 240 -
trunk/src/VBox/Additions/darwin/VBoxSF/VBoxSFMount.h
r75292 r75293 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox VFS - common header used across all the driver source files.3 * VBoxSF - Darwin Shared Folders, mount interface. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2013-201 7Oracle Corporation7 * Copyright (C) 2013-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 #define MODULE_NAME "VBoxSF" 18 #ifndef ___VBoxSFMount_h___ 19 #define ___VBoxSFMount_h___ 19 20 20 #ifdef KERNEL 21 # include <libkern/libkern.h> 22 # include <sys/lock.h> 21 #include <iprt/types.h> 22 23 /** The shared folders file system name. */ 24 #define VBOXSF_DARWIN_FS_NAME "vboxsf" 25 26 /** 27 * Mount information that gets passed from userland on mount. 28 */ 29 typedef struct vboxvfs_mount_info 30 { 31 /** Magic value (VBOXVFS_MOUNTINFO_MAGIC). */ 32 uint32_t u32Magic; 33 /** The shared folder name. */ 34 char szFolder[260]; 35 } VBOXSFDRWNMOUNTINFO; 36 typedef VBOXSFDRWNMOUNTINFO *PVBOXSFDRWNMOUNTINFO; 37 /** Magic value for VBOXSFDRWNMOUNTINFO::u32Magic. */ 38 #define VBOXSFDRWNMOUNTINFO_MAGIC UINT32_C(0xc001cafe) 39 23 40 #endif 24 41 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 KERNEL33 34 #include <iprt/types.h>35 #undef PVM36 #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_data46 {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_data59 {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 structure70 * @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 is73 * VBoxVFS root vnode (TRUE for VBoxVFS root vnode, FALSE74 * for all aother vnodes)75 * @param Path within Shared Folder76 * @param ret Returned newly created vnode77 *78 * @return 0 on success, error code otherwise79 */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 path84 * within mounted shared folder (returning it as a char *).85 *86 * @param mp Mount data structure87 * @param pszGuestPath Guest absolute VFS path (starting from VFS root)88 * @param cbGuestPath Size of pszGuestPath89 * @param pszHostPath Returned char * wich contains host path90 * @param cbHostPath Returned pszHostPath size91 *92 * @return 0 on success, error code otherwise93 */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 path98 * within mounted shared folder.99 *100 * @param mp Mount data structure101 * @param pszGuestPath Guest absolute VFS path (starting from VFS root)102 * @param cbGuestPath Size of pszGuestPath103 * @param ppResult Returned PSHFLSTRING object wich contains host path104 *105 * @return 0 on success, error code otherwise106 */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() which111 * converts guest path to host path using vnode object information.112 *113 * @param vnode Guest's VFS object114 * @param ppPath Allocated char * which contain a path115 * @param pcbPath Size of ppPath116 *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() which123 * converts guest path to host path using vnode object information.124 *125 * @param vnode Guest's VFS object126 * @param ppResult Allocated PSHFLSTRING object which contain a path127 *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 be145 * 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 data166 * @param pSHFLDPath Path to VFS object within mounted shared folder167 * @param Info Returned info168 *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 object177 *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 flags186 *187 * @return Guest flags188 */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 flags195 *196 * @return Host flags197 */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_info216 {217 uint32_t magic;218 char name[MAXPATHLEN]; /* share name */219 };220 -
trunk/src/VBox/Additions/darwin/VBoxSF/mount.vboxsf.cpp
r75292 r75293 1 1 /* $Id$ */ 2 2 /** @file 3 * VBox VFS - mount tool.3 * VBoxSF - Darwin Shared Folders, Mount Utility. 4 4 */ 5 5 6 6 /* 7 * Copyright (C) 2013-201 7Oracle Corporation7 * Copyright (C) 2013-2018 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 16 16 */ 17 17 18 19 /********************************************************************************************************************************* 20 * Header Files * 21 *********************************************************************************************************************************/ 22 #include <errno.h> 18 23 #include <stdio.h> 24 #include <stdlib.h> 19 25 #include <unistd.h> 20 #include <stdlib.h>21 26 #include <sys/mount.h> 22 #include <errno.h>23 #include <string.h>24 27 25 #include "vboxvfs.h" 28 #include "VBoxSFMount.h" 29 #include <iprt/string.h> 26 30 27 static char *progname;28 31 29 static void 30 usage(void) 32 static RTEXITCODE usage(const char *pszArg0) 31 33 { 32 fprintf(stderr, "usage: %s [OPTIONS] <shared folder name> " 33 "<mount point>\n", progname); 34 exit(1); 34 fprintf(stderr, "usage: %s [OPTIONS] <shared folder name> <mount point>\n", pszArg0); 35 return RTEXITCODE_SYNTAX; 35 36 } 36 37 37 int 38 main(int argc, char *argv[])38 39 int main(int argc, char **argv) 39 40 { 40 int rc; 41 int c; 42 char *sShareName; 43 char *sMountPoint; 44 struct vboxvfs_mount_info mnt_info; 45 46 /* Set program name */ 47 progname = argv[0]; 48 49 /* Parse command line */ 50 while((c = getopt(argc, argv, "o:")) != -1) 41 /* 42 * Skip past parameters. 43 */ 44 int c; 45 while ((c = getopt(argc, argv, "o:")) != -1) 51 46 { 52 switch (c)47 switch (c) 53 48 { 54 case 'o': break; 55 default : usage(); 49 case 'o': 50 break; 51 default: 52 return usage(argv[0]); 56 53 } 57 54 } 58 55 59 56 /* Two arguments are rquired: <share name> and <mount point> */ 60 if ((argc - optind) != 2) 61 usage(); 57 if (argc - optind != 2) 58 return usage(argv[0]); 59 const char * const pszFolder = argv[optind++]; 60 const char * const pszMountPoint = argv[optind]; 62 61 63 sShareName = argv[optind++]; 64 sMountPoint = argv[optind]; 65 66 if (strlen(sShareName) > MAXPATHLEN) 62 /* 63 * Check that the folder is within bounds and doesn't include any shady characters. 64 */ 65 size_t cchFolder = strlen(pszFolder); 66 if ( cchFolder < 1 67 || cchFolder >= RT_SIZEOFMEMB(VBOXSFDRWNMOUNTINFO, szFolder) 68 || strpbrk(pszFolder, "\\/") != NULL) 67 69 { 68 fprintf(stderr, " Specified Shared Folder name too long\n");69 return EINVAL;70 fprintf(stderr, "Invalid shared folder name '%s'!\n", pszFolder); 71 return RTEXITCODE_FAILURE; 70 72 } 71 73 72 mnt_info.magic = VBOXVFS_MOUNTINFO_MAGIC; 73 strcpy(mnt_info.name, sShareName); 74 /* 75 * Do the mounting. 76 */ 77 VBOXSFDRWNMOUNTINFO MntInfo; 78 RT_ZERO(MntInfo); 79 MntInfo.u32Magic = VBOXSFDRWNMOUNTINFO_MAGIC; 80 memcpy(MntInfo.szFolder, pszFolder, cchFolder); 81 int rc = mount(VBOXSF_DARWIN_FS_NAME, pszMountPoint, 0, &MntInfo); 82 if (rc == 0) 83 return 0; 74 84 75 rc = mount(VBOXVBFS_NAME, sMountPoint, 0, &mnt_info); 76 if (rc) 77 { 78 fprintf(stderr, 79 "Unable to mount shared folder (%s) '%s' to '%s': %s\n", 80 VBOXVBFS_NAME, 81 mnt_info.name, 82 sMountPoint, 83 strerror(errno)); 84 return 1; 85 } 86 87 return 0; 85 fprintf(stderr, "error mounting '%s' at '%s': %s (%d)\n", pszFolder, pszMountPoint, strerror(errno), errno); 86 return RTEXITCODE_FAILURE; 88 87 }
Note:
See TracChangeset
for help on using the changeset viewer.