[34456] | 1 | #! /bin/sh
|
---|
| 2 | # $Id: VBoxCreateUSBNode.sh 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
| 3 | ## @file
|
---|
| 4 | # VirtualBox USB Proxy Service, Linux Specialization.
|
---|
| 5 | # udev helper for creating and removing device nodes for VirtualBox USB devices
|
---|
| 6 | #
|
---|
| 7 |
|
---|
| 8 | #
|
---|
[98103] | 9 | # Copyright (C) 2010-2023 Oracle and/or its affiliates.
|
---|
[34456] | 10 | #
|
---|
[96407] | 11 | # This file is part of VirtualBox base platform packages, as
|
---|
| 12 | # available from https://www.virtualbox.org.
|
---|
[34456] | 13 | #
|
---|
[96407] | 14 | # This program is free software; you can redistribute it and/or
|
---|
| 15 | # modify it under the terms of the GNU General Public License
|
---|
| 16 | # as published by the Free Software Foundation, in version 3 of the
|
---|
| 17 | # License.
|
---|
| 18 | #
|
---|
| 19 | # This program is distributed in the hope that it will be useful, but
|
---|
| 20 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 22 | # General Public License for more details.
|
---|
| 23 | #
|
---|
| 24 | # You should have received a copy of the GNU General Public License
|
---|
| 25 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 26 | #
|
---|
| 27 | # SPDX-License-Identifier: GPL-3.0-only
|
---|
| 28 | #
|
---|
[34456] | 29 |
|
---|
[37339] | 30 | # Constant, from the USB specifications
|
---|
[38362] | 31 | usb_class_hub=09
|
---|
[37339] | 32 |
|
---|
[34456] | 33 | do_remove=0
|
---|
| 34 | case "$1" in "--remove")
|
---|
| 35 | do_remove=1; shift;;
|
---|
| 36 | esac
|
---|
| 37 | bus=`expr "$2" '/' 128 + 1`
|
---|
| 38 | device=`expr "$2" '%' 128 + 1`
|
---|
| 39 | class="$3"
|
---|
[34572] | 40 | group="$4"
|
---|
[34456] | 41 | devdir="`printf "/dev/vboxusb/%.3d" $bus`"
|
---|
| 42 | devpath="`printf "/dev/vboxusb/%.3d/%.3d" $bus $device`"
|
---|
[37339] | 43 | case "$do_remove" in
|
---|
| 44 | 0)
|
---|
[92881] | 45 | if test -n "$class" -a "$class" = "$usb_class_hub"
|
---|
[38362] | 46 | then
|
---|
| 47 | exit 0
|
---|
| 48 | fi
|
---|
[37339] | 49 | case "$group" in "") group="vboxusers";; esac
|
---|
[34456] | 50 | mkdir /dev/vboxusb -m 0750 2>/dev/null
|
---|
[34572] | 51 | chown root:$group /dev/vboxusb 2>/dev/null
|
---|
[34456] | 52 | mkdir "$devdir" -m 0750 2>/dev/null
|
---|
[34572] | 53 | chown root:$group "$devdir" 2>/dev/null
|
---|
[34456] | 54 | mknod "$devpath" c $1 $2 -m 0660 2>/dev/null
|
---|
[34572] | 55 | chown root:$group "$devpath" 2>/dev/null
|
---|
[37339] | 56 | ;;
|
---|
| 57 | 1)
|
---|
[34456] | 58 | rm -f "$devpath"
|
---|
[37339] | 59 | ;;
|
---|
| 60 | esac
|
---|
[34456] | 61 |
|
---|