VirtualBox

Ignore:
Timestamp:
Nov 6, 2018 4:15:09 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
126398
Message:

add/darwin/VBoxSF: More renaming, header separation and cleaning up.

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  
    11# $Id$
    22## @file
    3 # sub-makefile for the Mac OS addition file system driver.
     3# sub-makefile for Darwin Shared Folders.
    44#
    55
    66#
    7 # Copyright (C) 2007-2017 Oracle Corporation
     7# Copyright (C) 2007-2018 Oracle Corporation
    88#
    99# This file is part of VirtualBox Open Source Edition (OSE), as
     
    2929VBoxSF_LIBS     = $(VBOX_LIB_VBGL_R0)
    3030VBoxSF_SOURCES  = \
    31         VBoxVFS.cpp \
    32         VBoxVFS-VFSOps.cpp \
    33         VBoxVFS-VNODEOps.cpp \
    34         VBoxVFS-utils.cpp
     31        VBoxSF.cpp \
     32        VBoxSF-VfsOps.cpp \
     33        VBoxSF-VNodeOps.cpp \
     34        VBoxSF-Utils.cpp
    3535
    3636
     
    6464PROGRAMS += mount.vboxsf
    6565mount.vboxsf_TEMPLATE = NewVBoxGuestR3Exe
    66 mount.vboxsf_SOURCES  = mount.vboxsf.c
     66mount.vboxsf_SOURCES  = mount.vboxsf.cpp
    6767mount.vboxsf_INST     = $(INST_ADDITIONS)VBoxSF.kext/Contents/MacOS/
    6868
  • trunk/src/VBox/Additions/darwin/VBoxSF/VBoxSF-Utils.cpp

    r75292 r75293  
    11/* $Id$ */
    22/** @file
    3  * VBoxVFS - helper functions.
     3 * VBoxSF - Darwin Shared Folders, Utility Functions.
    44 */
    55
    66/*
    7  * Copyright (C) 2013-2017 Oracle Corporation
     7 * Copyright (C) 2013-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    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"
    2623
    2724#include <iprt/assert.h>
    2825#include <iprt/mem.h>
    2926
    30 #include "vboxvfs.h"
    3127
    3228/**
  • trunk/src/VBox/Additions/darwin/VBoxSF/VBoxSF-VNodeOps.cpp

    r75292 r75293  
    11/* $Id$ */
    22/** @file
    3  * VBoxVFS - vnode operations.
     3 * VBoxSF - Darwin Shared Folders, VNode Operations.
    44 */
    55
     6
    67/*
    7  * Copyright (C) 2013-2017 Oracle Corporation
     8 * Copyright (C) 2013-2018 Oracle Corporation
    89 *
    910 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1617 */
    1718
    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"
    2224
    2325#include <iprt/mem.h>
    2426#include <iprt/assert.h>
    2527
    26 #include "vboxvfs.h"
     28
    2729
    2830#define VNODEOPFUNC int(*)(void *)
     31
    2932
    3033static int vboxvfs_dfl_error()
  • trunk/src/VBox/Additions/darwin/VBoxSF/VBoxSF-VfsOps.cpp

    r75292 r75293  
    11/* $Id$ */
    22/** @file
    3  * VBoxVFS - Filesystem operations.
     3 * VBoxFS - Darwin Shared Folders, Virtual File System Operations.
    44 */
    55
     
    1616 */
    1717
    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"
    2423
    2524#include <iprt/assert.h>
     
    2726#include <iprt/asm.h>
    2827
    29 #include "vboxvfs.h"
    3028
    3129/* States of VBoxVFS object used in atomic variables
     
    4644 */
    4745static int
    48 vboxvfs_get_mount_info(user_addr_t pUserData, struct vboxvfs_mount_info *pKernelData)
     46vboxvfs_get_mount_info(user_addr_t pUserData, PVBOXSFDRWNMOUNTINFO pKernelData)
    4947{
    5048    AssertReturn(pKernelData, EINVAL);
     
    5250
    5351    /* 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)
    5553    {
    5654        PERROR("Unable to copy mount parameters from user space");
     
    5957
    6058    /* Validate data magic */
    61     if (pKernelData->magic != VBOXVFS_MOUNTINFO_MAGIC)
     59    if (pKernelData->u32Magic != VBOXSFDRWNMOUNTINFO_MAGIC)
    6260    {
    6361        PERROR("Mount parameter magic mismatch");
     
    195193        if (rc == 0)
    196194        {
    197             PDEBUG("Mounting shared folder '%s'", mountInfo.name);
     195            PDEBUG("Mounting shared folder '%s'", mountInfo.szFolder);
    198196
    199197            /* Prepare for locking. We prepare locking group and attr data here,
     
    203201            if (rc == 0)
    204202            {
    205                 rc = vboxvfs_set_share_name(mp, (char *)&mountInfo.name, &cbShareName);
     203                rc = vboxvfs_set_share_name(mp, (char *)mountInfo.szFolder, &cbShareName);
    206204                if (rc == 0)
    207205                {
    208                     pMount->pShareName = vboxvfs_construct_shflstring((char *)&mountInfo.name, cbShareName);
     206                    pMount->pShareName = vboxvfs_construct_shflstring(mountInfo.szFolder, cbShareName);
    209207                    if (pMount->pShareName)
    210208                    {
  • trunk/src/VBox/Additions/darwin/VBoxSF/VBoxSF.cpp

    r75292 r75293  
    11/* $Id$ */
    22/** @file
    3  * VBoxVFS - Guest Additions Shared Folders driver. KEXT entry point.
     3 * VBoxSF - Darwin Shared Folders, KEXT entry points.
    44 */
    55
    66/*
    7  * Copyright (C) 2013-2017 Oracle Corporation
     7 * Copyright (C) 2013-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    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>
    3127#include <VBox/version.h>
    32 #include <iprt/asm.h>
    33 
    3428#include <VBox/log.h>
    35 
    36 #include "vboxvfs.h"
    3729
    3830
     
    4032*   Structures and Typedefs                                                                                                      *
    4133*********************************************************************************************************************************/
    42 
    4334/**
    4435 * The service class for dealing with Share Folder filesystem.
     
    150141            VFS_TBLNOTYPENUM;
    151142
    152     memcpy(oVFsEntry.vfe_fsname, VBOXVBFS_NAME, MFSNAMELEN);
     143    memcpy(oVFsEntry.vfe_fsname, VBOXSF_DARWIN_FS_NAME, MFSNAMELEN);
    153144
    154145    rc = vfs_fsadd(&oVFsEntry, &g_oVBoxVFSHandle);
  • trunk/src/VBox/Additions/darwin/VBoxSF/VBoxSFInternal.h

    r75292 r75293  
    11/* $Id$ */
    22/** @file
    3  * VBoxVFS - common header used across all the driver source files.
     3 * VBoxSF - Darwin Shared Folders, internal header.
    44 */
    55
    66/*
    7  * Copyright (C) 2013-2017 Oracle Corporation
     7 * Copyright (C) 2013-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    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>
    3428#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>
    3541#undef PVM
    36 #include <sys/vnode.h>
    3742
    3843#include <VBox/VBoxGuestLibSharedFolders.h>
    3944
    4045
    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*********************************************************************************************************************************/
    4458/** Private data assigned to each mounted shared folder. Assigned to mp structure. */
    4559typedef struct vboxvfs_mount_data
     
    6478} vboxvfs_vnode_t;
    6579
     80
     81/*********************************************************************************************************************************
     82*   Global Variables                                                                                                             *
     83*********************************************************************************************************************************/
     84/** Global refernce to host service connection */
     85extern VBGLSFCLIENT g_vboxSFClient;
     86
     87/* VFS options */
     88extern struct vfsops g_oVBoxVFSOpts;
     89
     90extern int (**g_VBoxVFSVnodeDirOpsVector)(void *);
     91extern int g_cVBoxVFSVnodeOpvDescListSize;
     92extern struct vnodeopv_desc *g_VBoxVFSVnodeOpvDescList[];
     93
     94
     95/*********************************************************************************************************************************
     96*   Functions                                                                                                                    *
     97*********************************************************************************************************************************/
     98
    6699/**
    67100 * Helper function to create XNU VFS vnode object.
     
    200233extern SHFLSTRING *vboxvfs_construct_shflstring(const char *pszName, size_t cchName);
    201234
    202 #endif /* KERNEL */
    203 
    204235extern int vboxvfs_register_filesystem(void);
    205236extern int vboxvfs_unregister_filesystem(void);
    206237
    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  
    11/* $Id$ */
    22/** @file
    3  * VBoxVFS - common header used across all the driver source files.
     3 * VBoxSF - Darwin Shared Folders, mount interface.
    44 */
    55
    66/*
    7  * Copyright (C) 2013-2017 Oracle Corporation
     7 * Copyright (C) 2013-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #define MODULE_NAME "VBoxSF"
     18#ifndef ___VBoxSFMount_h___
     19#define ___VBoxSFMount_h___
    1920
    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 */
     29typedef 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;
     36typedef VBOXSFDRWNMOUNTINFO *PVBOXSFDRWNMOUNTINFO;
     37/** Magic value for VBOXSFDRWNMOUNTINFO::u32Magic.   */
     38#define VBOXSFDRWNMOUNTINFO_MAGIC     UINT32_C(0xc001cafe)
     39
    2340#endif
    2441
    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 
  • trunk/src/VBox/Additions/darwin/VBoxSF/mount.vboxsf.cpp

    r75292 r75293  
    11/* $Id$ */
    22/** @file
    3  * VBoxVFS - mount tool.
     3 * VBoxSF - Darwin Shared Folders, Mount Utility.
    44 */
    55
    66/*
    7  * Copyright (C) 2013-2017 Oracle Corporation
     7 * Copyright (C) 2013-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
     18
     19/*********************************************************************************************************************************
     20*   Header Files                                                                                                                 *
     21*********************************************************************************************************************************/
     22#include <errno.h>
    1823#include <stdio.h>
     24#include <stdlib.h>
    1925#include <unistd.h>
    20 #include <stdlib.h>
    2126#include <sys/mount.h>
    22 #include <errno.h>
    23 #include <string.h>
    2427
    25 #include "vboxvfs.h"
     28#include "VBoxSFMount.h"
     29#include <iprt/string.h>
    2630
    27 static char *progname;
    2831
    29 static void
    30 usage(void)
     32static RTEXITCODE usage(const char *pszArg0)
    3133{
    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;
    3536}
    3637
    37 int
    38 main(int argc, char *argv[])
     38
     39int main(int argc, char **argv)
    3940{
    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)
    5146    {
    52         switch(c)
     47        switch (c)
    5348        {
    54             case 'o': break;
    55             default : usage();
     49            case 'o':
     50                break;
     51            default:
     52                return usage(argv[0]);
    5653        }
    5754    }
    5855
    5956    /* 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];
    6261
    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)
    6769    {
    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;
    7072    }
    7173
    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;
    7484
    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;
    8887}
Note: See TracChangeset for help on using the changeset viewer.

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