From f215e02bf85f68d3a6106c2a1f4f7f063f819064 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Thu, 11 Apr 2024 10:17:27 +0200 Subject: Adding upstream version 7.0.14-dfsg. Signed-off-by: Daniel Baumann --- src/VBox/Additions/linux/sharedfolders/vbsfmount.c | 113 +++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/VBox/Additions/linux/sharedfolders/vbsfmount.c (limited to 'src/VBox/Additions/linux/sharedfolders/vbsfmount.c') diff --git a/src/VBox/Additions/linux/sharedfolders/vbsfmount.c b/src/VBox/Additions/linux/sharedfolders/vbsfmount.c new file mode 100644 index 00000000..72d9210e --- /dev/null +++ b/src/VBox/Additions/linux/sharedfolders/vbsfmount.c @@ -0,0 +1,113 @@ +/* $Id: vbsfmount.c $ */ +/** @file + * vbsfmount - Commonly used code to mount shared folders on Linux-based + * systems. Currently used by mount.vboxsf and VBoxService. + */ + +/* + * Copyright (C) 2010-2023 Oracle and/or its affiliates. + * + * This file is part of VirtualBox base platform packages, as + * available from https://www.virtualbox.org. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation, in version 3 of the + * License. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * + * SPDX-License-Identifier: GPL-3.0-only + */ + + +/********************************************************************************************************************************* +* Header Files * +*********************************************************************************************************************************/ +#ifndef _GNU_SOURCE +# define _GNU_SOURCE +#endif +#include +#include +#include +#include +#include +#include +#include +#include + +#include "vbsfmount.h" + + +/** @todo Use defines for return values! */ +int vbsfmount_complete(const char *pszSharedFolder, const char *pszMountPoint, + unsigned long fFlags, const char *pszOpts) +{ + /* + * Combine pszOpts and fFlags. + */ + int rc; + size_t const cchFlags = (fFlags & MS_NOSUID ? strlen(MNTOPT_NOSUID) + 1 : 0) + + (fFlags & MS_RDONLY ? strlen(MNTOPT_RO) : strlen(MNTOPT_RW)); + size_t const cchOpts = pszOpts ? 1 + strlen(pszOpts) : 0; + char *pszBuf = (char *)malloc(cchFlags + cchOpts + 8); + if (pszBuf) + { + char *psz = pszBuf; + FILE *pMTab; + + strcpy(psz, fFlags & MS_RDONLY ? MNTOPT_RO : MNTOPT_RW); + psz += strlen(psz); + + if (fFlags & MS_NOSUID) + { + *psz++ = ','; + strcpy(psz, MNTOPT_NOSUID); + psz += strlen(psz); + } + + if (cchOpts) + { + *psz++ = ','; + strcpy(psz, pszOpts); + } + + assert(strlen(pszBuf) <= cchFlags + cchOpts); + + /* + * Open the mtab and update it: + */ + pMTab = setmntent(MOUNTED, "a+"); + if (pMTab) + { + struct mntent Entry; + Entry.mnt_fsname = (char*)pszSharedFolder; + Entry.mnt_dir = (char *)pszMountPoint; + Entry.mnt_type = "vboxsf"; + Entry.mnt_opts = pszBuf; + Entry.mnt_freq = 0; + Entry.mnt_passno = 0; + + if (!addmntent(pMTab, &Entry)) + rc = 0; /* success. */ + else + rc = 3; /* Could not add an entry to the mount table. */ + + endmntent(pMTab); + } + else + rc = 2; /* Could not open mount table for update. */ + + free(pszBuf); + } + else + rc = 1; /* allocation error */ + return rc; +} + -- cgit v1.2.3