summaryrefslogtreecommitdiffstats
path: root/src/VBox/Additions/freebsd
diff options
context:
space:
mode:
Diffstat (limited to 'src/VBox/Additions/freebsd')
-rw-r--r--src/VBox/Additions/freebsd/.scm-settings30
-rw-r--r--src/VBox/Additions/freebsd/Installer/pkg-descr3
-rwxr-xr-xsrc/VBox/Additions/freebsd/Installer/vboxguest.sh149
-rw-r--r--src/VBox/Additions/freebsd/Makefile62
-rw-r--r--src/VBox/Additions/freebsd/Makefile.kmk195
-rw-r--r--src/VBox/Additions/freebsd/drm/Makefile36
-rw-r--r--src/VBox/Additions/freebsd/drm/Makefile.kmk82
-rwxr-xr-xsrc/VBox/Additions/freebsd/drm/files_vboxvideo_drm35
-rw-r--r--src/VBox/Additions/freebsd/drm/vboxvideo_drm.c173
-rw-r--r--src/VBox/Additions/freebsd/vboxvfs/Makefile.kmk74
-rw-r--r--src/VBox/Additions/freebsd/vboxvfs/vboxvfs.h105
-rw-r--r--src/VBox/Additions/freebsd/vboxvfs/vboxvfs_vfsops.c268
-rw-r--r--src/VBox/Additions/freebsd/vboxvfs/vboxvfs_vnops.c251
13 files changed, 1463 insertions, 0 deletions
diff --git a/src/VBox/Additions/freebsd/.scm-settings b/src/VBox/Additions/freebsd/.scm-settings
new file mode 100644
index 00000000..0d53f266
--- /dev/null
+++ b/src/VBox/Additions/freebsd/.scm-settings
@@ -0,0 +1,30 @@
+# $Id: .scm-settings $
+## @file
+# Source code massager settings for the FreeBSD guest additions.
+#
+
+#
+# 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 <https://www.gnu.org/licenses>.
+#
+# SPDX-License-Identifier: GPL-3.0-only
+#
+
+--filter-out-files /Installer/pkg-descr
+/drm/vboxvideo_drm.c: --no-convert-tabs
+
diff --git a/src/VBox/Additions/freebsd/Installer/pkg-descr b/src/VBox/Additions/freebsd/Installer/pkg-descr
new file mode 100644
index 00000000..49c9d066
--- /dev/null
+++ b/src/VBox/Additions/freebsd/Installer/pkg-descr
@@ -0,0 +1,3 @@
+VirtualBox guest additions for the FreeBSD operating system
+
+WWW: http://www.virtualbox.org
diff --git a/src/VBox/Additions/freebsd/Installer/vboxguest.sh b/src/VBox/Additions/freebsd/Installer/vboxguest.sh
new file mode 100755
index 00000000..503217f5
--- /dev/null
+++ b/src/VBox/Additions/freebsd/Installer/vboxguest.sh
@@ -0,0 +1,149 @@
+#!/bin/bash
+# $Id: vboxguest.sh $
+## @file
+# VirtualBox Guest Additions kernel module control script for FreeBSD.
+#
+
+#
+# Copyright (C) 2008-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 <https://www.gnu.org/licenses>.
+#
+# SPDX-License-Identifier: GPL-3.0-only
+#
+
+VBOXGUESTFILE=""
+SILENTUNLOAD=""
+
+abort()
+{
+ echo 1>&2 "$1"
+ exit 1
+}
+
+info()
+{
+ echo 1>&2 "$1"
+}
+
+get_module_path()
+{
+ moduledir="/boot/kernel";
+ modulepath=$moduledir/vboxguest.ko
+ if test -f "$modulepath"; then
+ VBOXGUESTFILE="$modulepath"
+ else
+ VBOXGUESTFILE=""
+ fi
+}
+
+check_if_installed()
+{
+ if test "$VBOXGUESTFILE" -a -f "$VBOXGUESTFILE"; then
+ return 0
+ fi
+ abort "VirtualBox kernel module (vboxguest) not installed."
+}
+
+module_loaded()
+{
+ loadentry=`kldstat | grep vboxguest`
+ if test -z "$loadentry"; then
+ return 1
+ fi
+ return 0
+}
+
+check_root()
+{
+ if test `id -u` -ne 0; then
+ abort "This program must be run with administrator privileges. Aborting"
+ fi
+}
+
+start()
+{
+ if module_loaded; then
+ info "vboxguest already loaded..."
+ else
+ /sbin/kldload vboxguest.ko
+ if ! module_loaded; then
+ abort "Failed to load vboxguest."
+ elif test -c "/dev/vboxguest"; then
+ info "Loaded vboxguest."
+ else
+ stop
+ abort "Aborting due to attach failure."
+ fi
+ fi
+}
+
+stop()
+{
+ if module_loaded; then
+ /sbin/kldunload vboxguest.ko
+ info "Unloaded vboxguest."
+ elif test -z "$SILENTUNLOAD"; then
+ info "vboxguest not loaded."
+ fi
+}
+
+restart()
+{
+ stop
+ sync
+ start
+ return 0
+}
+
+status()
+{
+ if module_loaded; then
+ info "vboxguest running."
+ else
+ info "vboxguest stopped."
+ fi
+}
+
+check_root
+get_module_path
+check_if_installed
+
+if test "$2" = "silentunload"; then
+ SILENTUNLOAD="$2"
+fi
+
+case "$1" in
+start)
+ start
+ ;;
+stop)
+ stop
+ ;;
+restart)
+ restart
+ ;;
+status)
+ status
+ ;;
+*)
+ echo "Usage: $0 {start|stop|restart|status}"
+ exit 1
+esac
+
+exit
+
diff --git a/src/VBox/Additions/freebsd/Makefile b/src/VBox/Additions/freebsd/Makefile
new file mode 100644
index 00000000..6ef49483
--- /dev/null
+++ b/src/VBox/Additions/freebsd/Makefile
@@ -0,0 +1,62 @@
+#
+# Makefile for the VirtualBox FreeBSD Guest Drivers.
+#
+
+#
+# Copyright (C) 2009-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 <https://www.gnu.org/licenses>.
+#
+# SPDX-License-Identifier: GPL-3.0-only
+#
+
+KBUILD_VERBOSE =
+
+all:
+ @echo "=== Building 'vboxguest' module ==="
+ @$(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxguest
+ @if [ -f vboxguest/vboxguest.ko ]; then \
+ cp vboxguest/vboxguest.ko .; \
+ fi
+ @echo
+ @if [ -d vboxvfs ]; then \
+ echo "=== Building 'vboxvfs' module ==="; \
+ $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxvfs; \
+ if [ -f vboxvfs/vboxvfs.ko ]; then \
+ cp vboxvfs/vboxvfs.ko .; \
+ fi; \
+ fi
+
+
+install:
+ @$(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxguest install
+ @if [ -d vboxvfs ]; then \
+ $(MAKE) KBUILD_VERBOSE=$(KBUILD_VERBOSE) -C vboxvfs install; \
+ fi
+
+clean:
+ @$(MAKE) -C vboxguest clean
+ @if [ -d vboxvfs ]; then \
+ $(MAKE) -C vboxvfs clean; \
+ fi
+ rm -f vboxguest.*o vboxvfs.*o
+
+load:
+ @/sbin/kldunload vboxvfs || true
+ @/sbin/kldunload vboxguest || true
+ @/sbin/kldload ./vboxguest.ko
+ @if [ -f vboxvfs.ko ]; then /sbin/kldload ./vboxvfs.ko; fi
diff --git a/src/VBox/Additions/freebsd/Makefile.kmk b/src/VBox/Additions/freebsd/Makefile.kmk
new file mode 100644
index 00000000..559554ea
--- /dev/null
+++ b/src/VBox/Additions/freebsd/Makefile.kmk
@@ -0,0 +1,195 @@
+# $Id: Makefile.kmk $
+## @file
+# Sub-Makefile for the FreeBSD guest additions base directory.
+#
+
+#
+# Copyright (C) 2008-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 <https://www.gnu.org/licenses>.
+#
+# SPDX-License-Identifier: GPL-3.0-only
+#
+
+SUB_DEPTH = ../../../..
+include $(KBUILD_PATH)/subheader.kmk
+
+ifneq ($(KBUILD_HOST),freebsd)
+ $(error "The FreeBSD guest additions installer can only be built on FreeBSD!")
+endif
+
+# Include sub-makefiles.
+#include $(PATH_SUB_CURRENT)/vboxvfs/Makefile.kmk
+include $(PATH_SUB_CURRENT)/drm/Makefile.kmk
+
+#
+# Globals
+#
+VBOX_FBSD_ADD_INS_OUT_DIR := $(PATH_TARGET)/Additions/Installer/freebsd
+BLDDIRS += \
+ $(VBOX_FBSD_ADD_INS_OUT_DIR) \
+ $(VBOX_FBSD_ADD_INS_OUT_DIR)/module
+VBOX_PATH_FREEBSD_ADDITION_INSTALLER := $(PATH_SUB_CURRENT)/Installer
+VBOX_PATH_X11_ADDITION_INSTALLER := $(PATH_ROOT)/src/VBox/Additions/x11/Installer
+
+
+#
+# Targets
+#
+ifndef VBOX_OSE
+ BLDDIRS += $(VBOX_FBSD_ADD_INS_OUT_DIR) $(VBOX_FBSD_ADD_INS_OUT_DIR)/module
+ PACKING += $(PATH_STAGE_BIN)/additions/VBoxFreeBSDAdditions.tbz
+ OTHER_CLEAN += $(PACKING)
+endif
+
+
+#
+# Files to install
+#
+VBOX_FBSD_ADD_STRIP_BIN = \
+ VBoxService \
+ VBoxClient \
+ VBoxControl \
+ vboxmouse_drv_70.so \
+ vboxmouse_drv_71.so \
+ vboxmouse_drv_14.so \
+ vboxmouse_drv_15.so \
+ vboxmouse_drv_16.so \
+ vboxmouse_drv_17.so \
+ vboxvideo_drv_70.so \
+ vboxvideo_drv_71.so \
+ vboxvideo_drv_13.so \
+ vboxvideo_drv_14.so \
+ vboxvideo_drv_15.so \
+ vboxvideo_drv_16.so \
+ vboxvideo_drv_17.so
+
+VBOX_FBSD_ADD_MODULES = \
+ vboxguest \
+ vboxvideo_drm
+
+#
+# All the bin files that go into the archives.
+#
+VBOX_FBSD_ADD_DBG_SYM_FILES := $(addsuffix .dbgsym,$(VBOX_FBSD_ADD_STRIP_BIN))
+VBOX_FBSD_ADD_INS_FILES := $(addprefix $(VBOX_FBSD_ADD_INS_OUT_DIR)/,$(VBOX_FBSD_ADD_STRIP_BIN) $(VBOX_FBSD_ADD_STRIP_OBJ) $(VBOX_FBSD_ADD_DBG_SYM_FILES))
+VBOX_FBSD_ADD_INS_MODULES := $(addprefix $(VBOX_FBSD_ADD_INS_OUT_DIR)/module/,$(VBOX_FBSD_ADD_MODULES))
+
+# Cleanup of the installer directory files
+OTHER_CLEAN += $(VBOX_FBSD_ADD_INS_FILES)) $(VBOX_FBSD_ADD_INS_MODULES)
+
+# pattern rule for copying the debug info from the VBOX_FBSD_ADD_STRIP_BIN files to the installation directory
+$(addprefix $(VBOX_FBSD_ADD_INS_OUT_DIR)/,$(VBOX_FBSD_ADD_DBG_SYM_FILES)): \
+ $(VBOX_FBSD_ADD_INS_OUT_DIR)/%.dbgsym : $(PATH_STAGE_BIN)/additions/% | $$(dir $$@)
+ $(call MSG_TOOL,copydbg,$<,$@)
+ $(QUIET)objcopy --only-keep-debug $< $@
+
+# pattern rule for stripping and copying the VBOX_FBSD_ADD_STRIP_BIN files to the installation directory
+$(addprefix $(VBOX_FBSD_ADD_INS_OUT_DIR)/,$(VBOX_FBSD_ADD_STRIP_BIN)): \
+ $(VBOX_FBSD_ADD_INS_OUT_DIR)/% : $(PATH_STAGE_BIN)/additions/% \
+ $(VBOX_FBSD_ADD_INS_OUT_DIR)/%.dbgsym \
+ | $$(dir $$@)
+ $(call MSG_INST_FILE,$<,$@)
+ $(QUIET)$(INSTALL) -m 0755 $(if $(VBOX_DO_STRIP),-s,) $< $@
+ $(QUIET)objcopy --add-gnu-debuglink=$(addsuffix .dbgsym,$@) $@
+
+# pattern rule for stripping and copying the VBOX_FBSD_ADD_STRIP_OBJ files to the installation directory
+$(addprefix $(VBOX_FBSD_ADD_INS_OUT_DIR)/,$(VBOX_FBSD_ADD_STRIP_OBJ)): \
+ $(VBOX_FBSD_ADD_INS_OUT_DIR)/% : $(PATH_STAGE_BIN)/additions/% | $$(dir $$@)
+ $(call MSG_INST_FILE,$<,$@)
+ifeq ($(VBOX_DO_STRIP),)
+ $(QUIET)$(INSTALL) -m 0644 $< $@
+else # strip to temp file because of umask.
+ $(QUIET)objcopy --strip-unneeded -R .comment $< $@.tmp
+ $(QUIET)$(INSTALL) -m 0644 $@.tmp $@
+ $(QUIET)$(RM) -f -- $@.tmp
+endif
+
+# pattern rule for copying the VBOX_FBSD_ADD_MODULES files to the installation directory
+$(VBOX_FBSD_ADD_INS_MODULES): \
+ $(VBOX_FBSD_ADD_INS_OUT_DIR)/module/% : $(PATH_STAGE_BIN)/additions/src/% | $(VBOX_FBSD_ADD_INS_OUT_DIR)/module/
+ $(call MSG_INST_FILE,$<,$@)
+# Remove target directories first, otherwise the behaviour of cp will not be
+# what we want if it already exists. See the cp manual page for more details.
+ $(QUIET)$(RM) -Rf $@
+ $(QUIET)cp -af $< $(VBOX_FBSD_ADD_INS_OUT_DIR)/module
+
+
+INSTALLS += $(if $(VBOX_OSE),, fbsd_add_inst-nobin)
+fbsd_add_inst-nobin_INST = obj/Additions/Installer/freebsd
+fbsd_add_inst-nobin_MODE = a+r,u+w
+fbsd_add_inst-nobin_SOURCES = \
+ ../x11/Installer/98vboxadd-xclient \
+ ../x11/Installer/vboxclient.desktop \
+ ../x11/Installer/vboxvideo.ids \
+ ../x11/Installer/x11config.pl \
+ ../x11/Installer/x11config15.pl
+
+
+INSTALLS += GuestDrivers-src
+GuestDrivers-src_INST = bin/additions/src/
+GuestDrivers-src_MODE = a+r,u+w
+GuestDrivers-src_SOURCES = Makefile
+
+# this file needs editing before it can be included in the generic installer.
+$(VBOX_FBSD_ADD_INS_OUT_DIR)/install.sh: \
+ $(VBOX_PATH_FREEBSD_ADDITION_INSTALLER)/install.sh | $$(dir $$@)
+ $(QUIET)$(SED) \
+ -e "s;_VERSION_;$(VBOX_VERSION_STRING);g" \
+ -e "s;_BUILD_;$(shell date);g" \
+ -e "s;_OSE_;$(VBOX_OSE);g" \
+ -e "s;_BUILDTYPE_;$(KBUILD_TYPE);g" \
+ -e "s;_ARCH_;$(KBUILD_TARGET_ARCH);g" \
+ --output $(VBOX_FBSD_ADD_INS_OUT_DIR)/install_.sh \
+ $<
+ $(QUIET)$(INSTALL) -m 0755 $(VBOX_FBSD_ADD_INS_OUT_DIR)/install_.sh $@
+ $(QUIET)$(RM) $(VBOX_FBSD_ADD_INS_OUT_DIR)/install_.sh
+OTHERS_CLEAN += $(VBOX_FBSD_ADD_INS_OUT_DIR)/install.sh
+
+
+include $(FILE_KBUILD_SUB_FOOTER)
+
+
+#
+# Build the FreeBSD Guest Additions installer package.
+#
+# Note that $(PATH_SUB_CURRENT) was changed by subfooter.kmk above and
+# any references should be made via variables assigned a know value via := .
+#
+# We need to depend on all source files for the additions and shared
+# folders kernel modules.
+## @todo Replace the wildcard stuff by the correct file lists now that
+# we've got everything included.
+#
+$(PATH_STAGE_BIN)/additions/VBoxFreeBSDAdditions.tbz: \
+ $$(fbsd_add_inst-nobin_2_STAGE_TARGETS) \
+ $$(fbsd_add_inst-bin_2_STAGE_TARGETS) \
+ $(VBOX_FBSD_ADD_INS_FILES) \
+ $(VBOX_FBSD_ADD_INS_MODULES) \
+ $(VBOX_FBSD_ADD_INS_OUT_DIR)/install.sh \
+ $(wildcard $(PATH_STAGE_BIN)/additions/src/*) \
+ $(wildcard $(PATH_STAGE_BIN)/additions/src/*/*) \
+ $(wildcard $(PATH_STAGE_BIN)/additions/src/*/*/*) \
+ $(wildcard $(PATH_STAGE_BIN)/additions/src/*/*/*/*) \
+ $(VBOX_VERSION_STAMP) $(VBOX_SVN_REV_HEADER)
+ pkg_create \
+ -I $(VBOX_PATH_FREEBSD_ADDITION_INSTALLER)/install.sh \
+ -c $(VBOX_PATH_FREEBSD_ADDITION_INSTALLER)/pkg-comment \
+ -d $(VBOX_PATH_FREEBSD_ADDITION_INSTALLER)/pkg-descr \
+ -f $(VBOX_PATH_FREEBSD_ADDITION_INSTALLER)/pkg-plist \
+ $@
+
diff --git a/src/VBox/Additions/freebsd/drm/Makefile b/src/VBox/Additions/freebsd/drm/Makefile
new file mode 100644
index 00000000..c2f9b4fe
--- /dev/null
+++ b/src/VBox/Additions/freebsd/drm/Makefile
@@ -0,0 +1,36 @@
+# $Id: Makefile $
+## @file
+# Makefile for the VirtualBox FreeBSD Host Driver.
+#
+
+#
+# Copyright (C) 2006-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 <https://www.gnu.org/licenses>.
+#
+# SPDX-License-Identifier: GPL-3.0-only
+#
+
+KMOD = vboxvideo
+
+SRCS = \
+ vboxvideo_drm.c
+
+SRCS += device_if.h bus_if.h pci_if.h opt_drm.h
+
+.include <bsd.kmod.mk>
+
diff --git a/src/VBox/Additions/freebsd/drm/Makefile.kmk b/src/VBox/Additions/freebsd/drm/Makefile.kmk
new file mode 100644
index 00000000..62b5e7e6
--- /dev/null
+++ b/src/VBox/Additions/freebsd/drm/Makefile.kmk
@@ -0,0 +1,82 @@
+# $Id: Makefile.kmk $
+## @file
+# Sub-Makefile for the vboxvideo DRM module (FreeBSD kernel OpenGL module).
+#
+
+#
+# Copyright (C) 2009-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 <https://www.gnu.org/licenses>.
+#
+# SPDX-License-Identifier: GPL-3.0-only
+#
+
+
+SUB_DEPTH = ../../../../..
+include $(KBUILD_PATH)/subheader.kmk
+
+INSTALLS += vboxvideo-mod
+
+ifdef VBOX_WITH_ADDITION_DRIVERS
+ SYSMODS += vboxvideo_drm
+endif
+ifneq ($(KBUILD_HOST),freebsd)
+ $(error "The FreeBSD guest additions can only be built on FreeBSD!")
+endif
+
+#
+# Populate FILES_VBOXVIDEO_DRM_NOBIN
+#
+include $(PATH_SUB_CURRENT)/files_vboxvideo_drm
+
+# vboxvideo source
+vboxvideo-mod_INST = $(INST_ADDITIONS)src/vboxvideo_drm/
+vboxvideo-mod_MODE = a+r,u+w
+vboxvideo-mod_SOURCES = $(subst ",,$(FILES_VBOXVIDEO_DRM_NOBIN))
+
+#
+# vboxvideo - The Video DRM (Direct Rendering Module) kernel module
+#
+# Note! Syntax checking only.
+#
+vboxvideo_drm_TEMPLATE = VBoxGuestR0Drv
+vboxvideo_drm_NAME = vboxvideo
+vboxvideo_drm_DEFS = VBOX_WITH_HGCM VBOX_SVN_REV=$(VBOX_SVN_REV)
+vboxvideo_drm_DEPS += $(VBOX_SVN_REV_KMK)
+vboxvideo_drm_INCS.freebsd = \
+ $(vboxvideo_drm_0_OUTDIR) \
+ $(PATH_STAGE)/gen-sys-hdrs
+vboxvideo_drm_SOURCES = vboxvideo_drm.c
+vboxvideo_drm_LIBS = \
+ $(VBOX_LIB_VBGL_R0) \
+ $(VBOX_LIB_IPRT_GUEST_R0)
+vboxvideo_drm_ORDERDEPS.freebsd = \
+ $(PATH_STAGE)/gen-sys-hdrs/pci_if.h \
+ $(PATH_STAGE)/gen-sys-hdrs/bus_if.h \
+ $(PATH_STAGE)/gen-sys-hdrs/device_if.h \
+ $(vboxvideo_drm_0_OUTDIR)/opt_drm.h
+vboxvideo_drm_CLEAN.freebsd = $(vboxvideo_drm_DEPS)
+
+#
+# Header for DRM not included by us.
+#
+$$(vboxvideo_drm_0_OUTDIR)/opt_drm.h:
+ $(QUIET)$(MKDIR) -p $(vboxvideo_drm_0_OUTDIR)
+ $(QUIET)touch $(vboxvideo_drm_0_OUTDIR)/opt_drm.h
+
+include $(FILE_KBUILD_SUB_FOOTER)
+
diff --git a/src/VBox/Additions/freebsd/drm/files_vboxvideo_drm b/src/VBox/Additions/freebsd/drm/files_vboxvideo_drm
new file mode 100755
index 00000000..8addd4b6
--- /dev/null
+++ b/src/VBox/Additions/freebsd/drm/files_vboxvideo_drm
@@ -0,0 +1,35 @@
+#!/bin/sh
+# $Id: files_vboxvideo_drm $
+## @file
+# Shared file between Makefile.kmk and export_modules.sh.
+#
+
+#
+# Copyright (C) 2007-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 <https://www.gnu.org/licenses>.
+#
+# SPDX-License-Identifier: GPL-3.0-only
+#
+
+FILES_VBOXVIDEO_DRM_NOBIN=" \
+ ${PATH_ROOT}/src/VBox/Additions/freebsd/drm/vboxvideo_drm.c=>vboxvideo_drm.c \
+ ${PATH_ROOT}/src/VBox/Additions/freebsd/drm/Makefile=>Makefile \
+"
+
+FILES_VBOXVIDEO_DRM_BIN=" \
+"
diff --git a/src/VBox/Additions/freebsd/drm/vboxvideo_drm.c b/src/VBox/Additions/freebsd/drm/vboxvideo_drm.c
new file mode 100644
index 00000000..de2678fe
--- /dev/null
+++ b/src/VBox/Additions/freebsd/drm/vboxvideo_drm.c
@@ -0,0 +1,173 @@
+/* $Id: vboxvideo_drm.c $ */
+/** @file
+ * VirtualBox Guest Additions - vboxvideo DRM module.
+ * FreeBSD kernel OpenGL module.
+ */
+
+/*
+ * Copyright (C) 2006-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 <https://www.gnu.org/licenses>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ * --------------------------------------------------------------------
+ *
+ * This code is based on:
+ *
+ * tdfx_drv.c -- tdfx driver -*- linux-c -*-
+ * Created: Thu Oct 7 10:38:32 1999 by faith@precisioninsight.com
+ *
+ * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
+ * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ * Rickard E. (Rik) Faith <faith@valinux.com>
+ * Daryll Strauss <daryll@valinux.com>
+ * Gareth Hughes <gareth@valinux.com>
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include "dev/drm/drmP.h"
+#include "dev/drm/drm_pciids.h"
+
+#define DRIVER_AUTHOR "Oracle Corporation"
+#define DRIVER_NAME "vboxvideo"
+#define DRIVER_DESC "VirtualBox DRM"
+#define DRIVER_DATE "20090317"
+#define DRIVER_MAJOR 1
+#define DRIVER_MINOR 0
+#define DRIVER_PATCHLEVEL 0
+
+/** @todo Take PCI IDs from VBox/param.h; VBOX_VESA_VENDORID,
+ * VBOX_VESA_DEVICEID. */
+#define vboxvideo_PCI_IDS { 0x80ee, 0xbeef, 0, "VirtualBox Video" }, \
+ { 0, 0, 0, NULL }
+
+static drm_pci_id_list_t vboxvideo_pciidlist[] = {
+ vboxvideo_PCI_IDS
+};
+
+static void vboxvideo_configure(struct drm_device *dev)
+{
+#if __FreeBSD_version >= 702000
+ dev->driver->buf_priv_size = 1; /* No dev_priv */
+
+ dev->driver->max_ioctl = 0;
+
+ dev->driver->name = DRIVER_NAME;
+ dev->driver->desc = DRIVER_DESC;
+ dev->driver->date = DRIVER_DATE;
+ dev->driver->major = DRIVER_MAJOR;
+ dev->driver->minor = DRIVER_MINOR;
+ dev->driver->patchlevel = DRIVER_PATCHLEVEL;
+#else
+ dev->driver.buf_priv_size = 1; /* No dev_priv */
+
+ dev->driver.max_ioctl = 0;
+
+ dev->driver.name = DRIVER_NAME;
+ dev->driver.desc = DRIVER_DESC;
+ dev->driver.date = DRIVER_DATE;
+ dev->driver.major = DRIVER_MAJOR;
+ dev->driver.minor = DRIVER_MINOR;
+ dev->driver.patchlevel = DRIVER_PATCHLEVEL;
+#endif
+}
+
+static int
+vboxvideo_probe(device_t kdev)
+{
+ return drm_probe(kdev, vboxvideo_pciidlist);
+}
+
+static int
+vboxvideo_attach(device_t kdev)
+{
+ struct drm_device *dev = device_get_softc(kdev);
+
+#if __FreeBSD_version >= 702000
+ dev->driver = malloc(sizeof(struct drm_driver_info), DRM_MEM_DRIVER,
+ M_WAITOK | M_ZERO);
+#else
+ bzero(&dev->driver, sizeof(struct drm_driver_info));
+#endif
+
+ vboxvideo_configure(dev);
+
+ return drm_attach(kdev, vboxvideo_pciidlist);
+}
+
+static int
+vboxvideo_detach(device_t kdev)
+{
+ struct drm_device *dev = device_get_softc(kdev);
+ int ret;
+
+ ret = drm_detach(kdev);
+
+#if __FreeBSD_version >= 702000
+ free(dev->driver, DRM_MEM_DRIVER);
+#endif
+
+ return ret;
+}
+
+static device_method_t vboxvideo_methods[] = {
+ /* Device interface */
+ DEVMETHOD(device_probe, vboxvideo_probe),
+ DEVMETHOD(device_attach, vboxvideo_attach),
+ DEVMETHOD(device_detach, vboxvideo_detach),
+
+ { 0, 0 }
+};
+
+static driver_t vboxvideo_driver = {
+ "drm",
+ vboxvideo_methods,
+ sizeof(struct drm_device)
+};
+
+extern devclass_t drm_devclass;
+#if __FreeBSD_version >= 700010
+DRIVER_MODULE(vboxvideo, vgapci, vboxvideo_driver, drm_devclass, 0, 0);
+#else
+DRIVER_MODULE(vboxvideo, pci, vboxvideo_driver, drm_devclass, 0, 0);
+#endif
+MODULE_DEPEND(vboxvideo, drm, 1, 1, 1);
diff --git a/src/VBox/Additions/freebsd/vboxvfs/Makefile.kmk b/src/VBox/Additions/freebsd/vboxvfs/Makefile.kmk
new file mode 100644
index 00000000..ee3619c0
--- /dev/null
+++ b/src/VBox/Additions/freebsd/vboxvfs/Makefile.kmk
@@ -0,0 +1,74 @@
+# $Id: Makefile.kmk $
+## @file
+# Sub-Makefile for the FreeBSD Shared folder kernel module.
+#
+
+#
+# Copyright (C) 2007-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 <https://www.gnu.org/licenses>.
+#
+# SPDX-License-Identifier: GPL-3.0-only
+#
+
+SUB_DEPTH = ../../../../..
+include $(KBUILD_PATH)/subheader.kmk
+
+ifneq ($(KBUILD_HOST),freebsd)
+ $(error "The FreeBSD guest additions can only be built on FreeBSD!")
+endif
+
+#
+# vboxvfs - The Shared Folder Driver
+#
+SYSMODS.freebsd += vboxvfs
+vboxvfs_TEMPLATE = VBoxGuestR0Drv
+vboxvfs_DEFS = VBOX_WITH_HGCM
+vboxvfs_INCS = \
+ . \
+ $(vboxvfs_0_OUTDIR)
+vboxvfs_SOURCES = \
+ vboxvfs_vfsops.c \
+ vboxvfs_vnops.c
+vboxvfs_LIBS = \
+ $(VBOX_LIB_VBGL_R0) \
+ $(VBOX_LIB_IPRT_GUEST_R0)
+vboxvfs_DEPS = \
+ $$(vboxvfs_0_OUTDIR)/vnode_if.h \
+ $$(vboxvfs_0_OUTDIR)/vnode_if_newproto.h \
+ $$(vboxvfs_0_OUTDIR)/vnode_if_typedef.h
+vboxvfs_CLEAN += $(vboxvfs_DEPS)
+
+VBOX_AWK := /usr/bin/awk
+
+$$(vboxvfs_0_OUTDIR)/vnode_if.h: $(VBOX_FREEBSD_SRC)/kern/vnode_if.src
+ $(call MSG_TOOL,awk,VBoxGuest,$<,$@)
+ $(QUIET)$(VBOX_AWK) -f $(VBOX_FREEBSD_SRC)/tools/vnode_if.awk $(VBOX_FREEBSD_SRC)/kern/vnode_if.src -h
+ $(QUIET)$(MV) $(vboxvfs_0_OUTDIR)/vnode_if.h $(vboxvfs_0_OUTDIR)/vnode_if.h
+
+$$(vboxvfs_0_OUTDIR)/vnode_if_newproto.h: $(VBOX_FREEBSD_SRC)/kern/vnode_if.src
+ $(call MSG_TOOL,awk,VBoxGuest,$<,$@)
+ $(QUIET)$(VBOX_AWK) -f $(VBOX_FREEBSD_SRC)/tools/vnode_if.awk $(VBOX_FREEBSD_SRC)/kern/vnode_if.src -p
+ $(QUIET)$(MV) $(vboxvfs_0_OUTDIR)/vnode_if_newproto.h $(vboxvfs_0_OUTDIR)/vnode_if_newproto.h
+
+$$(vboxvfs_0_OUTDIR)/vnode_if_typedef.h: $(VBOX_FREEBSD_SRC)/kern/vnode_if.src
+ $(call MSG_TOOL,awk,VBoxGuest,$<,$@)
+ $(QUIET)$(VBOX_AWK) -f $(VBOX_FREEBSD_SRC)/tools/vnode_if.awk $(VBOX_FREEBSD_SRC)/kern/vnode_if.src -q
+ $(QUIET)$(MV) $(vboxvfs_0_OUTDIR)/vnode_if_typedef.h $(vboxvfs_0_OUTDIR)/vnode_if_typedef.h
+
+include $(FILE_KBUILD_SUB_FOOTER)
+
diff --git a/src/VBox/Additions/freebsd/vboxvfs/vboxvfs.h b/src/VBox/Additions/freebsd/vboxvfs/vboxvfs.h
new file mode 100644
index 00000000..906e5a67
--- /dev/null
+++ b/src/VBox/Additions/freebsd/vboxvfs/vboxvfs.h
@@ -0,0 +1,105 @@
+/* $Id: vboxvfs.h $ */
+/** @file
+ * Description.
+ */
+
+/*
+ * 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 <https://www.gnu.org/licenses>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+#ifndef GA_INCLUDED_SRC_freebsd_vboxvfs_vboxvfs_h
+#define GA_INCLUDED_SRC_freebsd_vboxvfs_vboxvfs_h
+#ifndef RT_WITHOUT_PRAGMA_ONCE
+# pragma once
+#endif
+
+#define VBOXVFS_VFSNAME "vboxvfs"
+#define VBOXVFS_VERSION 1
+
+#define MAX_HOST_NAME 256
+#define MAX_NLS_NAME 32
+
+struct vboxvfs_mount_info {
+ char name[MAX_HOST_NAME];
+ char nls_name[MAX_NLS_NAME];
+ int uid;
+ int gid;
+ int ttl;
+};
+
+#ifdef _KERNEL
+
+#include <VBox/VBoxGuestLibSharedFolders.h>
+#include <sys/mount.h>
+#include <sys/vnode.h>
+
+struct vboxvfsmount {
+ uid_t uid;
+ gid_t gid;
+ mode_t file_mode;
+ mode_t dir_mode;
+ struct mount *mp;
+ struct ucred *owner;
+ u_int flags;
+ long nextino;
+ int caseopt;
+ int didrele;
+};
+
+/* structs - stolen from the linux shared module code */
+struct sf_glob_info {
+ VBGLSFMAP map;
+/* struct nls_table *nls;*/
+ int ttl;
+ int uid;
+ int gid;
+ struct vnode *vnode_root;
+};
+
+struct sf_inode_info {
+ SHFLSTRING *path;
+ int force_restat;
+};
+
+#if 0
+struct sf_dir_info {
+ struct list_head info_list;
+};
+#endif
+
+struct sf_dir_buf {
+ size_t nb_entries;
+ size_t free_bytes;
+ size_t used_bytes;
+ void *buf;
+#if 0
+ struct list_head head;
+#endif
+};
+
+struct sf_reg_info {
+ SHFLHANDLE handle;
+};
+
+#endif /* KERNEL */
+
+#endif /* !GA_INCLUDED_SRC_freebsd_vboxvfs_vboxvfs_h */
+
diff --git a/src/VBox/Additions/freebsd/vboxvfs/vboxvfs_vfsops.c b/src/VBox/Additions/freebsd/vboxvfs/vboxvfs_vfsops.c
new file mode 100644
index 00000000..43b9ec0b
--- /dev/null
+++ b/src/VBox/Additions/freebsd/vboxvfs/vboxvfs_vfsops.c
@@ -0,0 +1,268 @@
+/* $Id: vboxvfs_vfsops.c $ */
+/** @file
+ * Description.
+ */
+
+/*
+ * Copyright (C) 2008-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 <https://www.gnu.org/licenses>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+#include "vboxvfs.h"
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/bio.h>
+#include <sys/buf.h>
+#include <sys/kernel.h>
+#include <sys/sysctl.h>
+#include <sys/vnode.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/malloc.h>
+#include <sys/module.h>
+
+#include <iprt/mem.h>
+
+#define VFSMP2SFGLOBINFO(mp) ((struct sf_glob_info *)mp->mnt_data)
+
+static int vboxvfs_version = VBOXVFS_VERSION;
+
+SYSCTL_NODE(_vfs, OID_AUTO, vboxvfs, CTLFLAG_RW, 0, "VirtualBox shared filesystem");
+SYSCTL_INT(_vfs_vboxvfs, OID_AUTO, version, CTLFLAG_RD, &vboxvfs_version, 0, "");
+
+/* global connection to the host service. */
+static VBGLSFCLIENT g_vboxSFClient;
+
+static vfs_init_t vboxvfs_init;
+static vfs_uninit_t vboxvfs_uninit;
+static vfs_cmount_t vboxvfs_cmount;
+static vfs_mount_t vboxvfs_mount;
+static vfs_root_t vboxvfs_root;
+static vfs_quotactl_t vboxvfs_quotactl;
+static vfs_statfs_t vboxvfs_statfs;
+static vfs_unmount_t vboxvfs_unmount;
+
+static struct vfsops vboxvfs_vfsops = {
+ .vfs_init = vboxvfs_init,
+ .vfs_cmount = vboxvfs_cmount,
+ .vfs_mount = vboxvfs_mount,
+ .vfs_quotactl = vboxvfs_quotactl,
+ .vfs_root = vboxvfs_root,
+ .vfs_statfs = vboxvfs_statfs,
+ .vfs_sync = vfs_stdsync,
+ .vfs_uninit = vboxvfs_uninit,
+ .vfs_unmount = vboxvfs_unmount,
+};
+
+
+VFS_SET(vboxvfs_vfsops, vboxvfs, VFCF_NETWORK);
+MODULE_DEPEND(vboxvfs, vboxguest, 1, 1, 1);
+
+static int vboxvfs_cmount(struct mntarg *ma, void * data, int flags, struct thread *td)
+{
+ struct vboxvfs_mount_info args;
+ int rc = 0;
+
+ printf("%s: Enter\n", __FUNCTION__);
+
+ rc = copyin(data, &args, sizeof(struct vboxvfs_mount_info));
+ if (rc)
+ return rc;
+
+ ma = mount_argf(ma, "uid", "%d", args.uid);
+ ma = mount_argf(ma, "gid", "%d", args.gid);
+ ma = mount_arg(ma, "from", args.name, -1);
+
+ rc = kernel_mount(ma, flags);
+
+ printf("%s: Leave rc=%d\n", __FUNCTION__, rc);
+
+ return rc;
+}
+
+static const char *vboxvfs_opts[] = {
+ "uid", "gid", "from", "fstype", "fspath", "errmsg", NULL
+};
+
+static int vboxvfs_mount(struct mount *mp, struct thread *td)
+{
+ int rc;
+ char *pszShare;
+ int cbShare, cbOption;
+ int uid = 0, gid = 0;
+ struct sf_glob_info *pShFlGlobalInfo;
+ SHFLSTRING *pShFlShareName = NULL;
+ int cbShFlShareName;
+
+ printf("%s: Enter\n", __FUNCTION__);
+
+ if (mp->mnt_flag & (MNT_UPDATE | MNT_ROOTFS))
+ return EOPNOTSUPP;
+
+ if (vfs_filteropt(mp->mnt_optnew, vboxvfs_opts))
+ {
+ vfs_mount_error(mp, "%s", "Invalid option");
+ return EINVAL;
+ }
+
+ rc = vfs_getopt(mp->mnt_optnew, "from", (void **)&pszShare, &cbShare);
+ if (rc || pszShare[cbShare-1] != '\0' || cbShare > 0xfffe)
+ return EINVAL;
+
+ rc = vfs_getopt(mp->mnt_optnew, "gid", (void **)&gid, &cbOption);
+ if ((rc != ENOENT) && (rc || cbOption != sizeof(gid)))
+ return EINVAL;
+
+ rc = vfs_getopt(mp->mnt_optnew, "uid", (void **)&uid, &cbOption);
+ if ((rc != ENOENT) && (rc || cbOption != sizeof(uid)))
+ return EINVAL;
+
+ pShFlGlobalInfo = RTMemAllocZ(sizeof(struct sf_glob_info));
+ if (!pShFlGlobalInfo)
+ return ENOMEM;
+
+ cbShFlShareName = offsetof (SHFLSTRING, String.utf8) + cbShare + 1;
+ pShFlShareName = RTMemAllocZ(cbShFlShareName);
+ if (!pShFlShareName)
+ return VERR_NO_MEMORY;
+
+ pShFlShareName->u16Length = cbShare;
+ pShFlShareName->u16Size = cbShare + 1;
+ memcpy (pShFlShareName->String.utf8, pszShare, cbShare + 1);
+
+ rc = VbglR0SfMapFolder (&g_vboxSFClient, pShFlShareName, &pShFlGlobalInfo->map);
+ RTMemFree(pShFlShareName);
+
+ if (RT_FAILURE (rc))
+ {
+ RTMemFree(pShFlGlobalInfo);
+ printf("VbglR0SfMapFolder failed rc=%d\n", rc);
+ return EPROTO;
+ }
+
+ pShFlGlobalInfo->uid = uid;
+ pShFlGlobalInfo->gid = gid;
+
+ mp->mnt_data = pShFlGlobalInfo;
+
+ /** @todo root vnode. */
+
+ vfs_getnewfsid(mp);
+ vfs_mountedfrom(mp, pszShare);
+
+ printf("%s: Leave rc=0\n", __FUNCTION__);
+
+ return 0;
+}
+
+static int vboxvfs_unmount(struct mount *mp, int mntflags, struct thread *td)
+{
+ struct sf_glob_info *pShFlGlobalInfo = VFSMP2SFGLOBINFO(mp);
+ int rc;
+ int flags = 0;
+
+ rc = VbglR0SfUnmapFolder(&g_vboxSFClient, &pShFlGlobalInfo->map);
+ if (RT_FAILURE(rc))
+ printf("Failed to unmap shared folder\n");
+
+ if (mntflags & MNT_FORCE)
+ flags |= FORCECLOSE;
+
+ /* There is 1 extra root vnode reference (vnode_root). */
+ rc = vflush(mp, 1, flags, td);
+ if (rc)
+ return rc;
+
+
+ RTMemFree(pShFlGlobalInfo);
+ mp->mnt_data = NULL;
+
+ return 0;
+}
+
+static int vboxvfs_root(struct mount *mp, int flags, struct vnode **vpp, struct thread *td)
+{
+ int rc = 0;
+ struct sf_glob_info *pShFlGlobalInfo = VFSMP2SFGLOBINFO(mp);
+ struct vnode *vp;
+
+ printf("%s: Enter\n", __FUNCTION__);
+
+ vp = pShFlGlobalInfo->vnode_root;
+ VREF(vp);
+
+ vn_lock(vp, flags | LK_RETRY, td);
+ *vpp = vp;
+
+ printf("%s: Leave\n", __FUNCTION__);
+
+ return rc;
+}
+
+static int vboxvfs_quotactl(struct mount *mp, int cmd, uid_t uid, void *arg, struct thread *td)
+{
+ return EOPNOTSUPP;
+}
+
+int vboxvfs_init(struct vfsconf *vfsp)
+{
+ int rc;
+
+ /* Initialize the R0 guest library. */
+ rc = VbglR0SfInit();
+ if (RT_FAILURE(rc))
+ return ENXIO;
+
+ /* Connect to the host service. */
+ rc = VbglR0SfConnect(&g_vboxSFClient);
+ if (RT_FAILURE(rc))
+ {
+ printf("Failed to get connection to host! rc=%d\n", rc);
+ VbglR0SfTerm();
+ return ENXIO;
+ }
+
+ rc = VbglR0SfSetUtf8(&g_vboxSFClient);
+ if (RT_FAILURE (rc))
+ {
+ printf("VbglR0SfSetUtf8 failed, rc=%d\n", rc);
+ VbglR0SfDisconnect(&g_vboxSFClient);
+ VbglR0SfTerm();
+ return EPROTO;
+ }
+
+ printf("Successfully loaded shared folder module\n");
+
+ return 0;
+}
+
+int vboxvfs_uninit(struct vfsconf *vfsp)
+{
+ VbglR0SfDisconnect(&g_vboxSFClient);
+ VbglR0SfTerm();
+
+ return 0;
+}
+
+int vboxvfs_statfs(struct mount *mp, struct statfs *sbp, struct thread *td)
+{
+ return 0;
+}
diff --git a/src/VBox/Additions/freebsd/vboxvfs/vboxvfs_vnops.c b/src/VBox/Additions/freebsd/vboxvfs/vboxvfs_vnops.c
new file mode 100644
index 00000000..02652896
--- /dev/null
+++ b/src/VBox/Additions/freebsd/vboxvfs/vboxvfs_vnops.c
@@ -0,0 +1,251 @@
+/* $Id: vboxvfs_vnops.c $ */
+/** @file
+ * Description.
+ */
+
+/*
+ * Copyright (C) 2008-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 <https://www.gnu.org/licenses>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+#include "vboxvfs.h"
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/namei.h>
+#include <sys/kernel.h>
+#include <sys/proc.h>
+#include <sys/bio.h>
+#include <sys/buf.h>
+#include <sys/fcntl.h>
+#include <sys/mount.h>
+#include <sys/unistd.h>
+#include <sys/vnode.h>
+#include <sys/limits.h>
+#include <sys/lockf.h>
+#include <sys/stat.h>
+
+#include <vm/vm.h>
+#include <vm/vm_extern.h>
+
+/*
+ * Prototypes for VBOXVFS vnode operations
+ */
+static vop_create_t vboxvfs_create;
+static vop_mknod_t vboxvfs_mknod;
+static vop_open_t vboxvfs_open;
+static vop_close_t vboxvfs_close;
+static vop_access_t vboxvfs_access;
+static vop_getattr_t vboxvfs_getattr;
+static vop_setattr_t vboxvfs_setattr;
+static vop_read_t vboxvfs_read;
+static vop_write_t vboxvfs_write;
+static vop_fsync_t vboxvfs_fsync;
+static vop_remove_t vboxvfs_remove;
+static vop_link_t vboxvfs_link;
+static vop_lookup_t vboxvfs_lookup;
+static vop_rename_t vboxvfs_rename;
+static vop_mkdir_t vboxvfs_mkdir;
+static vop_rmdir_t vboxvfs_rmdir;
+static vop_symlink_t vboxvfs_symlink;
+static vop_readdir_t vboxvfs_readdir;
+static vop_strategy_t vboxvfs_strategy;
+static vop_print_t vboxvfs_print;
+static vop_pathconf_t vboxvfs_pathconf;
+static vop_advlock_t vboxvfs_advlock;
+static vop_getextattr_t vboxvfs_getextattr;
+static vop_ioctl_t vboxvfs_ioctl;
+static vop_getpages_t vboxvfs_getpages;
+static vop_inactive_t vboxvfs_inactive;
+static vop_putpages_t vboxvfs_putpages;
+static vop_reclaim_t vboxvfs_reclaim;
+
+struct vop_vector vboxvfs_vnodeops = {
+ .vop_default = &default_vnodeops,
+
+ .vop_access = vboxvfs_access,
+ .vop_advlock = vboxvfs_advlock,
+ .vop_close = vboxvfs_close,
+ .vop_create = vboxvfs_create,
+ .vop_fsync = vboxvfs_fsync,
+ .vop_getattr = vboxvfs_getattr,
+ .vop_getextattr = vboxvfs_getextattr,
+ .vop_getpages = vboxvfs_getpages,
+ .vop_inactive = vboxvfs_inactive,
+ .vop_ioctl = vboxvfs_ioctl,
+ .vop_link = vboxvfs_link,
+ .vop_lookup = vboxvfs_lookup,
+ .vop_mkdir = vboxvfs_mkdir,
+ .vop_mknod = vboxvfs_mknod,
+ .vop_open = vboxvfs_open,
+ .vop_pathconf = vboxvfs_pathconf,
+ .vop_print = vboxvfs_print,
+ .vop_putpages = vboxvfs_putpages,
+ .vop_read = vboxvfs_read,
+ .vop_readdir = vboxvfs_readdir,
+ .vop_reclaim = vboxvfs_reclaim,
+ .vop_remove = vboxvfs_remove,
+ .vop_rename = vboxvfs_rename,
+ .vop_rmdir = vboxvfs_rmdir,
+ .vop_setattr = vboxvfs_setattr,
+ .vop_strategy = vboxvfs_strategy,
+ .vop_symlink = vboxvfs_symlink,
+ .vop_write = vboxvfs_write,
+};
+
+static int vboxvfs_access(struct vop_access_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_open(struct vop_open_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_close(struct vop_close_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_getattr(struct vop_getattr_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_setattr(struct vop_setattr_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_read(struct vop_read_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_write(struct vop_write_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_create(struct vop_create_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_remove(struct vop_remove_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_rename(struct vop_rename_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_link(struct vop_link_args *ap)
+{
+ return EOPNOTSUPP;
+}
+
+static int vboxvfs_symlink(struct vop_symlink_args *ap)
+{
+ return EOPNOTSUPP;
+}
+
+static int vboxvfs_mknod(struct vop_mknod_args *ap)
+{
+ return EOPNOTSUPP;
+}
+
+static int vboxvfs_mkdir(struct vop_mkdir_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_rmdir(struct vop_rmdir_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_readdir(struct vop_readdir_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_fsync(struct vop_fsync_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_print (struct vop_print_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_pathconf (struct vop_pathconf_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_strategy (struct vop_strategy_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_ioctl(struct vop_ioctl_args *ap)
+{
+ return ENOTTY;
+}
+
+static int vboxvfs_getextattr(struct vop_getextattr_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_advlock(struct vop_advlock_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_lookup(struct vop_lookup_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_inactive(struct vop_inactive_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_reclaim(struct vop_reclaim_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_getpages(struct vop_getpages_args *ap)
+{
+ return 0;
+}
+
+static int vboxvfs_putpages(struct vop_putpages_args *ap)
+{
+ return 0;
+}
+