Changeset 75293 in vbox for trunk/src/VBox/Additions/darwin/VBoxSF/mount.vboxsf.cpp
- Timestamp:
- Nov 6, 2018 4:15:09 PM (7 years ago)
- svn:sync-xref-src-repo-rev:
- 126398
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
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.